// Code generated by 'ccgo -DSQLITE_PRIVATE= -export-defines "" -export-enums "" -export-externs X -export-fields F -export-typedefs "" -ignore-unsupported-alignment -pkgname sqlite3 -volatile=sqlite3_io_error_pending,sqlite3_open_file_count,sqlite3_pager_readdb_count,sqlite3_pager_writedb_count,sqlite3_pager_writej_count,sqlite3_search_count,sqlite3_sort_count,saved_cnt,randomnessPid -o libtest/sqlite_linux_arm64.go -trace-translation-units -volatile=sqlite3_io_error_pending,sqlite3_open_file_count,sqlite3_pager_readdb_count,sqlite3_pager_writedb_count,sqlite3_pager_writej_count,sqlite3_search_count,sqlite3_sort_count,saved_cnt,randomnessPid testdata/sqlite-amalgamation-3410200/sqlite3.c -full-path-comments -DNDEBUG -DHAVE_USLEEP -DLONGDOUBLE_TYPE=double -DSQLITE_CKSUMVFS_STATIC -DSQLITE_CORE -DSQLITE_DEFAULT_MEMSTATUS=1 -DSQLITE_DEFAULT_PAGE_SIZE=1024 -DSQLITE_ENABLE_BYTECODE_VTAB -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_DBSTAT_VTAB -DSQLITE_ENABLE_DESERIALIZE -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_GEOPOLY -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_STAT4 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_MUTEX_APPDEF=1 -DSQLITE_MUTEX_NOOP -DSQLITE_SOUNDEX -DSQLITE_TEMP_STORE=1 -DSQLITE_TEST -DSQLITE_THREADSAFE=1', DO NOT EDIT.

package sqlite3

import (
	"math"
	"reflect"
	"sync/atomic"
	"unsafe"

	"modernc.org/libc"
	"modernc.org/libc/sys/types"
)

var _ = math.Pi
var _ reflect.Kind
var _ atomic.Value
var _ unsafe.Pointer
var _ *libc.TLS
var _ types.Size_t

const (
	ACCESSPERMS                           = 511
	ADJ_ESTERROR                          = 0x0008
	ADJ_FREQUENCY                         = 0x0002
	ADJ_MAXERROR                          = 0x0004
	ADJ_MICRO                             = 0x1000
	ADJ_NANO                              = 0x2000
	ADJ_OFFSET                            = 0x0001
	ADJ_OFFSET_SINGLESHOT                 = 0x8001
	ADJ_OFFSET_SS_READ                    = 0xa001
	ADJ_SETOFFSET                         = 0x0100
	ADJ_STATUS                            = 0x0010
	ADJ_TAI                               = 0x0080
	ADJ_TICK                              = 0x4000
	ADJ_TIMECONST                         = 0x0020
	ALLPERMS                              = 4095
	AT_EACCESS                            = 0x200
	AT_EMPTY_PATH                         = 0x1000
	AT_FDCWD                              = -100
	AT_NO_AUTOMOUNT                       = 0x800
	AT_RECURSIVE                          = 0x8000
	AT_REMOVEDIR                          = 0x200
	AT_STATX_DONT_SYNC                    = 0x4000
	AT_STATX_FORCE_SYNC                   = 0x2000
	AT_STATX_SYNC_AS_STAT                 = 0x0000
	AT_STATX_SYNC_TYPE                    = 0x6000
	AT_SYMLINK_FOLLOW                     = 0x400
	AT_SYMLINK_NOFOLLOW                   = 0x100
	BIG_ENDIAN                            = 4321
	BITVEC_SZ                             = 512
	BITVEC_SZELEM                         = 8
	BTALLOC_ANY                           = 0
	BTALLOC_EXACT                         = 1
	BTALLOC_LE                            = 2
	BTCF_AtLast                           = 0x08
	BTCF_Incrblob                         = 0x10
	BTCF_Multiple                         = 0x20
	BTCF_Pinned                           = 0x40
	BTCF_ValidNKey                        = 0x02
	BTCF_ValidOvfl                        = 0x04
	BTCF_WriteFlag                        = 0x01
	BTCURSOR_MAX_DEPTH                    = 20
	BTREE_APPEND                          = 0x08
	BTREE_APPLICATION_ID                  = 8
	BTREE_AUTOVACUUM_FULL                 = 1
	BTREE_AUTOVACUUM_INCR                 = 2
	BTREE_AUTOVACUUM_NONE                 = 0
	BTREE_AUXDELETE                       = 0x04
	BTREE_BLOBKEY                         = 2
	BTREE_BULKLOAD                        = 0x00000001
	BTREE_DATA_VERSION                    = 15
	BTREE_DEFAULT_CACHE_SIZE              = 3
	BTREE_FILE_FORMAT                     = 2
	BTREE_FORDELETE                       = 0x00000008
	BTREE_FREE_PAGE_COUNT                 = 0
	BTREE_HINT_RANGE                      = 0
	BTREE_INCR_VACUUM                     = 7
	BTREE_INTKEY                          = 1
	BTREE_LARGEST_ROOT_PAGE               = 4
	BTREE_MEMORY                          = 2
	BTREE_OMIT_JOURNAL                    = 1
	BTREE_PREFORMAT                       = 0x80
	BTREE_SAVEPOSITION                    = 0x02
	BTREE_SCHEMA_VERSION                  = 1
	BTREE_SEEK_EQ                         = 0x00000002
	BTREE_SINGLE                          = 4
	BTREE_TEXT_ENCODING                   = 5
	BTREE_UNORDERED                       = 8
	BTREE_USER_VERSION                    = 6
	BTREE_WRCSR                           = 0x00000004
	BTS_EXCLUSIVE                         = 0x0040
	BTS_FAST_SECURE                       = 0x000c
	BTS_INITIALLY_EMPTY                   = 0x0010
	BTS_NO_WAL                            = 0x0020
	BTS_OVERWRITE                         = 0x0008
	BTS_PAGESIZE_FIXED                    = 0x0002
	BTS_PENDING                           = 0x0080
	BTS_READ_ONLY                         = 0x0001
	BTS_SECURE_DELETE                     = 0x0004
	BUFSIZ                                = 8192
	BYTE_ORDER                            = 1234
	CACHE_STALE                           = 0
	CBRK                                  = 0
	CC_AND                                = 24
	CC_BANG                               = 15
	CC_BOM                                = 30
	CC_COMMA                              = 23
	CC_DIGIT                              = 3
	CC_DOLLAR                             = 4
	CC_DOT                                = 26
	CC_EQ                                 = 14
	CC_GT                                 = 13
	CC_ID                                 = 27
	CC_ILLEGAL                            = 28
	CC_KYWD                               = 2
	CC_KYWD0                              = 1
	CC_LP                                 = 17
	CC_LT                                 = 12
	CC_MINUS                              = 11
	CC_NUL                                = 29
	CC_PERCENT                            = 22
	CC_PIPE                               = 10
	CC_PLUS                               = 20
	CC_QUOTE                              = 8
	CC_QUOTE2                             = 9
	CC_RP                                 = 18
	CC_SEMI                               = 19
	CC_SLASH                              = 16
	CC_SPACE                              = 7
	CC_STAR                               = 21
	CC_TILDA                              = 25
	CC_VARALPHA                           = 5
	CC_VARNUM                             = 6
	CC_X                                  = 0
	CDISCARD                              = 15
	CDSUSP                                = 25
	CEOF                                  = 4
	CEOL                                  = 0
	CEOT                                  = 4
	CERASE                                = 0177
	CFLUSH                                = 15
	CINTR                                 = 3
	CKCNSTRNT_COLUMN                      = 0x01
	CKCNSTRNT_ROWID                       = 0x02
	CKILL                                 = 21
	CLNEXT                                = 22
	CLOCK_BOOTTIME                        = 7
	CLOCK_BOOTTIME_ALARM                  = 9
	CLOCK_MONOTONIC                       = 1
	CLOCK_MONOTONIC_COARSE                = 6
	CLOCK_MONOTONIC_RAW                   = 4
	CLOCK_PROCESS_CPUTIME_ID              = 2
	CLOCK_REALTIME                        = 0
	CLOCK_REALTIME_ALARM                  = 8
	CLOCK_REALTIME_COARSE                 = 5
	CLOCK_TAI                             = 11
	CLOCK_THREAD_CPUTIME_ID               = 3
	CMIN                                  = 1
	COLFLAG_BUSY                          = 0x0100
	COLFLAG_GENERATED                     = 0x0060
	COLFLAG_HASCOLL                       = 0x0200
	COLFLAG_HASTYPE                       = 0x0004
	COLFLAG_HIDDEN                        = 0x0002
	COLFLAG_NOEXPAND                      = 0x0400
	COLFLAG_NOINSERT                      = 0x0062
	COLFLAG_NOTAVAIL                      = 0x0080
	COLFLAG_PRIMKEY                       = 0x0001
	COLFLAG_SORTERREF                     = 0x0010
	COLFLAG_STORED                        = 0x0040
	COLFLAG_UNIQUE                        = 0x0008
	COLFLAG_VIRTUAL                       = 0x0020
	COLNAME_COLUMN                        = 4
	COLNAME_DATABASE                      = 2
	COLNAME_DECLTYPE                      = 1
	COLNAME_N                             = 5
	COLNAME_NAME                          = 0
	COLNAME_TABLE                         = 3
	COLTYPE_ANY                           = 1
	COLTYPE_BLOB                          = 2
	COLTYPE_CUSTOM                        = 0
	COLTYPE_INT                           = 3
	COLTYPE_INTEGER                       = 4
	COLTYPE_REAL                          = 5
	COLTYPE_TEXT                          = 6
	CQUIT                                 = 034
	CREPRINT                              = 18
	CRPRNT                                = 18
	CSTART                                = 17
	CSTATUS                               = 0
	CSTOP                                 = 19
	CSUSP                                 = 26
	CTIME                                 = 0
	CURSOR_FAULT                          = 4
	CURSOR_INVALID                        = 1
	CURSOR_REQUIRESEEK                    = 3
	CURSOR_SKIPNEXT                       = 2
	CURSOR_VALID                          = 0
	CURTYPE_BTREE                         = 0
	CURTYPE_PSEUDO                        = 3
	CURTYPE_SORTER                        = 1
	CURTYPE_VTAB                          = 2
	CWERASE                               = 23
	DBFLAG_EncodingFixed                  = 0x0040
	DBFLAG_InternalFunc                   = 0x0020
	DBFLAG_PreferBuiltin                  = 0x0002
	DBFLAG_SchemaChange                   = 0x0001
	DBFLAG_SchemaKnownOk                  = 0x0010
	DBFLAG_Vacuum                         = 0x0004
	DBFLAG_VacuumInto                     = 0x0008
	DBPAGE_COLUMN_DATA                    = 1
	DBPAGE_COLUMN_PGNO                    = 0
	DBPAGE_COLUMN_SCHEMA                  = 2
	DBSTAT_PAGE_PADDING_BYTES             = 256
	DB_ResetWanted                        = 0x0008
	DB_SchemaLoaded                       = 0x0001
	DB_UnresetViews                       = 0x0002
	DEFFILEMODE                           = 438
	DIRECT_MODE                           = 0
	DN_ACCESS                             = 0x00000001
	DN_ATTRIB                             = 0x00000020
	DN_CREATE                             = 0x00000004
	DN_DELETE                             = 0x00000008
	DN_MODIFY                             = 0x00000002
	DN_MULTISHOT                          = 0x80000000
	DN_RENAME                             = 0x00000010
	DOTLOCK_SUFFIX                        = ".lock"
	E2BIG                                 = 7
	EACCES                                = 13
	EADDRINUSE                            = 98
	EADDRNOTAVAIL                         = 99
	EADV                                  = 68
	EAFNOSUPPORT                          = 97
	EAGAIN                                = 11
	EALREADY                              = 114
	EBADE                                 = 52
	EBADF                                 = 9
	EBADFD                                = 77
	EBADMSG                               = 74
	EBADR                                 = 53
	EBADRQC                               = 56
	EBADSLT                               = 57
	EBFONT                                = 59
	EBUSY                                 = 16
	ECANCELED                             = 125
	ECHILD                                = 10
	ECHRNG                                = 44
	ECOMM                                 = 70
	ECONNABORTED                          = 103
	ECONNREFUSED                          = 111
	ECONNRESET                            = 104
	EDEADLK                               = 35
	EDEADLOCK                             = 35
	EDESTADDRREQ                          = 89
	EDOM                                  = 33
	EDOTDOT                               = 73
	EDQUOT                                = 122
	EEXIST                                = 17
	EFAULT                                = 14
	EFBIG                                 = 27
	EHOSTDOWN                             = 112
	EHOSTUNREACH                          = 113
	EHWPOISON                             = 133
	EIDRM                                 = 43
	EILSEQ                                = 84
	EINPROGRESS                           = 115
	EINTR                                 = 4
	EINVAL                                = 22
	EIO                                   = 5
	EISCONN                               = 106
	EISDIR                                = 21
	EISNAM                                = 120
	EKEYEXPIRED                           = 127
	EKEYREJECTED                          = 129
	EKEYREVOKED                           = 128
	EL2HLT                                = 51
	EL2NSYNC                              = 45
	EL3HLT                                = 46
	EL3RST                                = 47
	ELIBACC                               = 79
	ELIBBAD                               = 80
	ELIBEXEC                              = 83
	ELIBMAX                               = 82
	ELIBSCN                               = 81
	ELNRNG                                = 48
	ELOOP                                 = 40
	EMEDIUMTYPE                           = 124
	EMFILE                                = 24
	EMLINK                                = 31
	EMSGSIZE                              = 90
	EMULTIHOP                             = 72
	ENAMETOOLONG                          = 36
	ENAME_NAME                            = 0
	ENAME_SPAN                            = 1
	ENAME_TAB                             = 2
	ENAVAIL                               = 119
	ENETDOWN                              = 100
	ENETRESET                             = 102
	ENETUNREACH                           = 101
	ENFILE                                = 23
	ENOANO                                = 55
	ENOBUFS                               = 105
	ENOCSI                                = 50
	ENODATA                               = 61
	ENODEV                                = 19
	ENOENT                                = 2
	ENOEXEC                               = 8
	ENOKEY                                = 126
	ENOLCK                                = 37
	ENOLINK                               = 67
	ENOMEDIUM                             = 123
	ENOMEM                                = 12
	ENOMSG                                = 42
	ENONET                                = 64
	ENOPKG                                = 65
	ENOPROTOOPT                           = 92
	ENOSPC                                = 28
	ENOSR                                 = 63
	ENOSTR                                = 60
	ENOSYS                                = 38
	ENOTBLK                               = 15
	ENOTCONN                              = 107
	ENOTDIR                               = 20
	ENOTEMPTY                             = 39
	ENOTNAM                               = 118
	ENOTRECOVERABLE                       = 131
	ENOTSOCK                              = 88
	ENOTSUP                               = 95
	ENOTTY                                = 25
	ENOTUNIQ                              = 76
	ENXIO                                 = 6
	EOF                                   = -1
	EOPNOTSUPP                            = 95
	EOVERFLOW                             = 75
	EOWNERDEAD                            = 130
	EPERM                                 = 1
	EPFNOSUPPORT                          = 96
	EPIPE                                 = 32
	EPROTO                                = 71
	EPROTONOSUPPORT                       = 93
	EPROTOTYPE                            = 91
	EP_Agg                                = 0x000010
	EP_CanBeNull                          = 0x200000
	EP_Collate                            = 0x000200
	EP_Commuted                           = 0x000400
	EP_ConstFunc                          = 0x100000
	EP_DblQuoted                          = 0x000080
	EP_Distinct                           = 0x000004
	EP_FixedCol                           = 0x000020
	EP_FromDDL                            = 0x40000000
	EP_HasFunc                            = 0x000008
	EP_IfNullRow                          = 0x040000
	EP_Immutable                          = 0x02
	EP_InfixFunc                          = 0x000100
	EP_InnerON                            = 0x000002
	EP_IntValue                           = 0x000800
	EP_IsFalse                            = 0x20000000
	EP_IsTrue                             = 0x10000000
	EP_Leaf                               = 0x800000
	EP_NoReduce                           = 0x01
	EP_OuterON                            = 0x000001
	EP_Propagate                          = 4194824
	EP_Quoted                             = 0x4000000
	EP_Reduced                            = 0x004000
	EP_Skip                               = 0x002000
	EP_Static                             = 0x8000000
	EP_Subquery                           = 0x400000
	EP_Subrtn                             = 0x2000000
	EP_TokenOnly                          = 0x010000
	EP_Unlikely                           = 0x080000
	EP_VarSelect                          = 0x000040
	EP_Win                                = 0x008000
	EP_WinFunc                            = 0x1000000
	EP_xIsSelect                          = 0x001000
	ERANGE                                = 34
	EREMCHG                               = 78
	EREMOTE                               = 66
	EREMOTEIO                             = 121
	ERESTART                              = 85
	ERFKILL                               = 132
	EROFS                                 = 30
	ESHUTDOWN                             = 108
	ESOCKTNOSUPPORT                       = 94
	ESPIPE                                = 29
	ESRCH                                 = 3
	ESRMNT                                = 69
	ESTALE                                = 116
	ESTRPIPE                              = 86
	ETIME                                 = 62
	ETIMEDOUT                             = 110
	ETOOMANYREFS                          = 109
	ETXTBSY                               = 26
	EU4_EXPR                              = 2
	EU4_IDX                               = 1
	EU4_NONE                              = 0
	EUCLEAN                               = 117
	EUNATCH                               = 49
	EUSERS                                = 87
	EWOULDBLOCK                           = 11
	EXCLUDED_TABLE_NUMBER                 = 2
	EXCLUSIVE_LOCK                        = 4
	EXDEV                                 = 18
	EXFULL                                = 54
	EXIT_FAILURE                          = 1
	EXIT_SUCCESS                          = 0
	EXPRDUP_REDUCE                        = 0x0001
	F2FS_FEATURE_ATOMIC_WRITE             = 0x0004
	F2FS_IOCTL_MAGIC                      = 0xf5
	F2FS_IOC_ABORT_VOLATILE_WRITE         = 62725
	F2FS_IOC_COMMIT_ATOMIC_WRITE          = 62722
	F2FS_IOC_START_ATOMIC_WRITE           = 62721
	F2FS_IOC_START_VOLATILE_WRITE         = 62723
	FALLOC_FL_COLLAPSE_RANGE              = 0x08
	FALLOC_FL_INSERT_RANGE                = 0x20
	FALLOC_FL_KEEP_SIZE                   = 0x01
	FALLOC_FL_NO_HIDE_STALE               = 0x04
	FALLOC_FL_PUNCH_HOLE                  = 0x02
	FALLOC_FL_UNSHARE_RANGE               = 0x40
	FALLOC_FL_ZERO_RANGE                  = 0x10
	FAPPEND                               = 1024
	FASYNC                                = 8192
	FD_CLOEXEC                            = 1
	FD_SETSIZE                            = 1024
	FFSYNC                                = 1052672
	FILENAME_MAX                          = 4096
	FIOASYNC                              = 0x5452
	FIOCLEX                               = 0x5451
	FIONBIO                               = 0x5421
	FIONCLEX                              = 0x5450
	FIONREAD                              = 0x541B
	FIOQSIZE                              = 0x5460
	FLAG_SIGNED                           = 1
	FLAG_STRING                           = 4
	FNDELAY                               = 2048
	FNONBLOCK                             = 2048
	FOPEN_MAX                             = 16
	FP_FAST_FMA                           = 1
	FP_FAST_FMAF                          = 1
	FP_ILOGB0                             = -2147483647
	FP_ILOGBNAN                           = 2147483647
	FP_INFINITE1                          = 1
	FP_INT_DOWNWARD1                      = 1
	FP_INT_TONEAREST1                     = 4
	FP_INT_TONEARESTFROMZERO1             = 3
	FP_INT_TOWARDZERO1                    = 2
	FP_INT_UPWARD1                        = 0
	FP_LLOGB0                             = -9223372036854775807
	FP_LLOGBNAN                           = 9223372036854775807
	FP_NAN1                               = 0
	FP_NORMAL1                            = 4
	FP_SUBNORMAL1                         = 3
	FP_ZERO1                              = 2
	FTS5CSR_EOF                           = 0x01
	FTS5CSR_FREE_ZRANK                    = 0x10
	FTS5CSR_REQUIRE_CONTENT               = 0x02
	FTS5CSR_REQUIRE_DOCSIZE               = 0x04
	FTS5CSR_REQUIRE_INST                  = 0x08
	FTS5CSR_REQUIRE_POSLIST               = 0x40
	FTS5CSR_REQUIRE_RESEEK                = 0x20
	FTS5INDEX_QUERY_DESC                  = 0x0002
	FTS5INDEX_QUERY_NOOUTPUT              = 0x0020
	FTS5INDEX_QUERY_PREFIX                = 0x0001
	FTS5INDEX_QUERY_SCAN                  = 0x0008
	FTS5INDEX_QUERY_SKIPEMPTY             = 0x0010
	FTS5INDEX_QUERY_TEST_NOIDX            = 0x0004
	FTS5_AND                              = 2
	FTS5_AVERAGES_ROWID                   = 1
	FTS5_BI_MATCH                         = 0x0001
	FTS5_BI_ORDER_DESC                    = 0x0080
	FTS5_BI_ORDER_RANK                    = 0x0020
	FTS5_BI_ORDER_ROWID                   = 0x0040
	FTS5_BI_RANK                          = 0x0002
	FTS5_BI_ROWID_EQ                      = 0x0004
	FTS5_BI_ROWID_GE                      = 0x0010
	FTS5_BI_ROWID_LE                      = 0x0008
	FTS5_CARET                            = 12
	FTS5_COLON                            = 5
	FTS5_COMMA                            = 13
	FTS5_CONTENT_EXTERNAL                 = 2
	FTS5_CONTENT_NONE                     = 1
	FTS5_CONTENT_NORMAL                   = 0
	FTS5_CORRUPT                          = 267
	FTS5_CURRENT_VERSION                  = 4
	FTS5_DATA_DLI_B                       = 1
	FTS5_DATA_HEIGHT_B                    = 5
	FTS5_DATA_ID_B                        = 16
	FTS5_DATA_PADDING                     = 20
	FTS5_DATA_PAGE_B                      = 31
	FTS5_DATA_ZERO_PADDING                = 8
	FTS5_DEFAULT_AUTOMERGE                = 4
	FTS5_DEFAULT_CRISISMERGE              = 16
	FTS5_DEFAULT_HASHSIZE                 = 1048576
	FTS5_DEFAULT_NEARDIST                 = 10
	FTS5_DEFAULT_PAGE_SIZE                = 4050
	FTS5_DEFAULT_RANK                     = "bm25"
	FTS5_DEFAULT_USERMERGE                = 4
	FTS5_DETAIL_COLUMNS                   = 2
	FTS5_DETAIL_FULL                      = 0
	FTS5_DETAIL_NONE                      = 1
	FTS5_EOF                              = 0
	FTS5_LCP                              = 7
	FTS5_LP                               = 10
	FTS5_MAIN_PREFIX                      = 48
	FTS5_MAX_LEVEL                        = 64
	FTS5_MAX_PAGE_SIZE                    = 65536
	FTS5_MAX_PREFIX_INDEXES               = 31
	FTS5_MAX_SEGMENT                      = 2000
	FTS5_MAX_TOKEN_SIZE                   = 32768
	FTS5_MERGE_NLIST                      = 16
	FTS5_MINUS                            = 6
	FTS5_MIN_DLIDX_SIZE                   = 4
	FTS5_NOT                              = 3
	FTS5_OPT_WORK_UNIT                    = 1000
	FTS5_OR                               = 1
	FTS5_PATTERN_GLOB                     = 66
	FTS5_PATTERN_LIKE                     = 65
	FTS5_PATTERN_NONE                     = 0
	FTS5_PLAN_MATCH                       = 1
	FTS5_PLAN_ROWID                       = 6
	FTS5_PLAN_SCAN                        = 5
	FTS5_PLAN_SORTED_MATCH                = 4
	FTS5_PLAN_SOURCE                      = 2
	FTS5_PLAN_SPECIAL                     = 3
	FTS5_PLUS                             = 14
	FTS5_PORTER_MAX_TOKEN                 = 64
	FTS5_RANK_NAME                        = "rank"
	FTS5_RCP                              = 8
	FTS5_REMOVE_DIACRITICS_COMPLEX        = 2
	FTS5_REMOVE_DIACRITICS_NONE           = 0
	FTS5_REMOVE_DIACRITICS_SIMPLE         = 1
	FTS5_ROWID_NAME                       = "rowid"
	FTS5_RP                               = 11
	FTS5_SEGITER_ONETERM                  = 0x01
	FTS5_SEGITER_REVERSE                  = 0x02
	FTS5_STAR                             = 15
	FTS5_STMT_DELETE_CONTENT              = 5
	FTS5_STMT_DELETE_DOCSIZE              = 7
	FTS5_STMT_INSERT_CONTENT              = 3
	FTS5_STMT_LOOKUP                      = 2
	FTS5_STMT_LOOKUP_DOCSIZE              = 8
	FTS5_STMT_REPLACE_CONFIG              = 9
	FTS5_STMT_REPLACE_CONTENT             = 4
	FTS5_STMT_REPLACE_DOCSIZE             = 6
	FTS5_STMT_SCAN                        = 10
	FTS5_STMT_SCAN_ASC                    = 0
	FTS5_STMT_SCAN_DESC                   = 1
	FTS5_STRING                           = 9
	FTS5_STRUCTURE_ROWID                  = 10
	FTS5_TERM                             = 4
	FTS5_TOKENIZE_AUX                     = 0x0008
	FTS5_TOKENIZE_DOCUMENT                = 0x0004
	FTS5_TOKENIZE_PREFIX                  = 0x0002
	FTS5_TOKENIZE_QUERY                   = 0x0001
	FTS5_TOKEN_COLOCATED                  = 0x0001
	FTS5_VOCAB_COL                        = 0
	FTS5_VOCAB_COL_SCHEMA                 = "term, col, doc, cnt"
	FTS5_VOCAB_INSTANCE                   = 2
	FTS5_VOCAB_INST_SCHEMA                = "term, doc, col, offset"
	FTS5_VOCAB_ROW                        = 1
	FTS5_VOCAB_ROW_SCHEMA                 = "term, doc, cnt"
	FTS5_VOCAB_TERM_EQ                    = 0x01
	FTS5_VOCAB_TERM_GE                    = 0x02
	FTS5_VOCAB_TERM_LE                    = 0x04
	FTS5_WORK_UNIT                        = 64
	FULLY_WITHIN                          = 2
	FUNC_PERFECT_MATCH                    = 6
	F_ADD_SEALS                           = 1033
	F_DUPFD                               = 0
	F_DUPFD_CLOEXEC                       = 1030
	F_EXLCK                               = 4
	F_GETFD                               = 1
	F_GETFL                               = 3
	F_GETLEASE                            = 1025
	F_GETLK                               = 5
	F_GETLK64                             = 5
	F_GETOWN                              = 9
	F_GETOWN_EX                           = 16
	F_GETPIPE_SZ                          = 1032
	F_GETSIG                              = 11
	F_GET_FILE_RW_HINT                    = 1037
	F_GET_RW_HINT                         = 1035
	F_GET_SEALS                           = 1034
	F_LOCK                                = 1
	F_NOTIFY                              = 1026
	F_OFD_GETLK                           = 36
	F_OFD_SETLK                           = 37
	F_OFD_SETLKW                          = 38
	F_OK                                  = 0
	F_RDLCK                               = 0
	F_SEAL_FUTURE_WRITE                   = 0x0010
	F_SEAL_GROW                           = 0x0004
	F_SEAL_SEAL                           = 0x0001
	F_SEAL_SHRINK                         = 0x0002
	F_SEAL_WRITE                          = 0x0008
	F_SETFD                               = 2
	F_SETFL                               = 4
	F_SETLEASE                            = 1024
	F_SETLK                               = 6
	F_SETLK64                             = 6
	F_SETLKW                              = 7
	F_SETLKW64                            = 7
	F_SETOWN                              = 8
	F_SETOWN_EX                           = 15
	F_SETPIPE_SZ                          = 1031
	F_SETSIG                              = 10
	F_SET_FILE_RW_HINT                    = 1038
	F_SET_RW_HINT                         = 1036
	F_SHLCK                               = 8
	F_TEST                                = 3
	F_TLOCK                               = 2
	F_ULOCK                               = 0
	F_UNLCK                               = 2
	F_WRLCK                               = 1
	GCC_VERSION                           = 10002001
	GEOPOLY_PI                            = 3.1415926535897932385
	HASHSIZE                              = 97
	HASHTABLE_HASH_1                      = 383
	HASHTABLE_NPAGE                       = 4096
	HASHTABLE_NSLOT                       = 8192
	HAVE_FCHMOD                           = 0
	HAVE_FCHOWN                           = 1
	HAVE_FULLFSYNC                        = 0
	HAVE_GETHOSTUUID                      = 0
	HAVE_LSTAT                            = 1
	HAVE_MREMAP                           = 1
	HAVE_READLINK                         = 1
	HAVE_USLEEP                           = 1
	INCRINIT_NORMAL                       = 0
	INCRINIT_ROOT                         = 2
	INCRINIT_TASK                         = 1
	INITFLAG_AlterAdd                     = 0x0003
	INITFLAG_AlterDrop                    = 0x0002
	INITFLAG_AlterMask                    = 0x0003
	INITFLAG_AlterRename                  = 0x0001
	INLINEFUNC_affinity                   = 4
	INLINEFUNC_coalesce                   = 0
	INLINEFUNC_expr_compare               = 3
	INLINEFUNC_expr_implies_expr          = 2
	INLINEFUNC_iif                        = 5
	INLINEFUNC_implies_nonnull_row        = 1
	INLINEFUNC_sqlite_offset              = 6
	INLINEFUNC_unlikely                   = 99
	INTERFACE                             = 1
	IN_INDEX_EPH                          = 2
	IN_INDEX_INDEX_ASC                    = 3
	IN_INDEX_INDEX_DESC                   = 4
	IN_INDEX_LOOP                         = 0x0004
	IN_INDEX_MEMBERSHIP                   = 0x0002
	IN_INDEX_NOOP                         = 5
	IN_INDEX_NOOP_OK                      = 0x0001
	IN_INDEX_ROWID                        = 1
	IOCSIZE_MASK                          = 1073676288
	IOCSIZE_SHIFT                         = 16
	IOC_IN                                = 1073741824
	IOC_INOUT                             = 3221225472
	IOC_OUT                               = 2147483648
	IsStat4                               = 1
	JEACH_ATOM                            = 3
	JEACH_FULLKEY                         = 6
	JEACH_ID                              = 4
	JEACH_JSON                            = 8
	JEACH_KEY                             = 0
	JEACH_PARENT                          = 5
	JEACH_PATH                            = 7
	JEACH_ROOT                            = 9
	JEACH_TYPE                            = 2
	JEACH_VALUE                           = 1
	JNODE_APPEND                          = 0x20
	JNODE_ESCAPE                          = 0x02
	JNODE_LABEL                           = 0x40
	JNODE_PATCH                           = 0x10
	JNODE_RAW                             = 0x01
	JNODE_REMOVE                          = 0x04
	JNODE_REPLACE                         = 0x08
	JSON_ABPATH                           = 0x03
	JSON_ARRAY                            = 6
	JSON_CACHE_ID                         = -429938
	JSON_CACHE_SZ                         = 4
	JSON_FALSE                            = 2
	JSON_INT                              = 3
	JSON_ISSET                            = 0x04
	JSON_JSON                             = 0x01
	JSON_MAX_DEPTH                        = 2000
	JSON_NULL                             = 0
	JSON_OBJECT                           = 7
	JSON_REAL                             = 4
	JSON_SQL                              = 0x02
	JSON_STRING                           = 5
	JSON_SUBTYPE                          = 74
	JSON_TRUE                             = 1
	JT_CROSS                              = 0x02
	JT_ERROR                              = 0x80
	JT_INNER                              = 0x01
	JT_LEFT                               = 0x08
	JT_LTORJ                              = 0x40
	JT_NATURAL                            = 0x04
	JT_OUTER                              = 0x20
	JT_RIGHT                              = 0x10
	KEYINFO_ORDER_BIGNULL                 = 0x02
	KEYINFO_ORDER_DESC                    = 0x01
	LEGACY_SCHEMA_TABLE                   = "sqlite_master"
	LEGACY_TEMP_SCHEMA_TABLE              = "sqlite_temp_master"
	LITTLE_ENDIAN                         = 1234
	LM_ID_BASE                            = 0
	LM_ID_NEWLM                           = -1
	LOCATE_NOERR                          = 0x02
	LOCATE_VIEW                           = 0x01
	LOCK_EX                               = 2
	LOCK_MAND                             = 32
	LOCK_NB                               = 4
	LOCK_READ                             = 64
	LOCK_RW                               = 192
	LOCK_SH                               = 1
	LOCK_UN                               = 8
	LOCK_WRITE                            = 128
	LOOKASIDE_SMALL                       = 128
	L_INCR                                = 1
	L_SET                                 = 0
	L_XTND                                = 2
	L_ctermid                             = 9
	L_cuserid                             = 9
	L_tmpnam                              = 20
	M10d_Any                              = 1
	M10d_No                               = 2
	M10d_Yes                              = 0
	MADV_COLD                             = 20
	MADV_DODUMP                           = 17
	MADV_DOFORK                           = 11
	MADV_DONTDUMP                         = 16
	MADV_DONTFORK                         = 10
	MADV_DONTNEED                         = 4
	MADV_FREE                             = 8
	MADV_HUGEPAGE                         = 14
	MADV_HWPOISON                         = 100
	MADV_KEEPONFORK                       = 19
	MADV_MERGEABLE                        = 12
	MADV_NOHUGEPAGE                       = 15
	MADV_NORMAL                           = 0
	MADV_PAGEOUT                          = 21
	MADV_RANDOM                           = 1
	MADV_REMOVE                           = 9
	MADV_SEQUENTIAL                       = 2
	MADV_UNMERGEABLE                      = 13
	MADV_WILLNEED                         = 3
	MADV_WIPEONFORK                       = 18
	MAP_ANON                              = 32
	MAP_ANONYMOUS                         = 0x20
	MAP_DENYWRITE                         = 0x00800
	MAP_EXECUTABLE                        = 0x01000
	MAP_FILE                              = 0
	MAP_FIXED                             = 0x10
	MAP_FIXED_NOREPLACE                   = 0x100000
	MAP_GROWSDOWN                         = 0x00100
	MAP_HUGETLB                           = 0x40000
	MAP_HUGE_MASK                         = 0x3f
	MAP_HUGE_SHIFT                        = 26
	MAP_LOCKED                            = 0x02000
	MAP_NONBLOCK                          = 0x10000
	MAP_NORESERVE                         = 0x04000
	MAP_POPULATE                          = 0x08000
	MAP_PRIVATE                           = 0x02
	MAP_SHARED                            = 0x01
	MAP_SHARED_VALIDATE                   = 0x03
	MAP_STACK                             = 0x20000
	MAP_SYNC                              = 0x80000
	MAP_TYPE                              = 0x0f
	MATH_ERREXCEPT                        = 2
	MATH_ERRNO                            = 1
	MAXFLOAT                              = 3.40282347e+38
	MAX_HANDLE_SZ                         = 128
	MAX_PATHNAME                          = 512
	MAX_SECTOR_SIZE                       = 0x10000
	MCL_CURRENT                           = 1
	MCL_FUTURE                            = 2
	MCL_ONFAULT                           = 4
	MEMJOURNAL_DFLT_FILECHUNKSIZE         = 1024
	MEMTYPE_HEAP                          = 0x01
	MEMTYPE_LOOKASIDE                     = 0x02
	MEMTYPE_PCACHE                        = 0x04
	MEM_AffMask                           = 0x003f
	MEM_Agg                               = 0x8000
	MEM_Blob                              = 0x0010
	MEM_Cleared                           = 0x0100
	MEM_Dyn                               = 0x1000
	MEM_Ephem                             = 0x4000
	MEM_FromBind                          = 0x0040
	MEM_Int                               = 0x0004
	MEM_IntReal                           = 0x0020
	MEM_Null                              = 0x0001
	MEM_Real                              = 0x0008
	MEM_Static                            = 0x2000
	MEM_Str                               = 0x0002
	MEM_Subtype                           = 0x0800
	MEM_Term                              = 0x0200
	MEM_TypeMask                          = 0x0dbf
	MEM_Undefined                         = 0x0000
	MEM_Zero                              = 0x0400
	MFD_ALLOW_SEALING                     = 2
	MFD_CLOEXEC                           = 1
	MFD_HUGETLB                           = 4
	MLOCK_ONFAULT                         = 1
	MOD_CLKA                              = 32769
	MOD_CLKB                              = 16384
	MOD_ESTERROR                          = 8
	MOD_FREQUENCY                         = 2
	MOD_MAXERROR                          = 4
	MOD_MICRO                             = 4096
	MOD_NANO                              = 8192
	MOD_OFFSET                            = 1
	MOD_STATUS                            = 16
	MOD_TAI                               = 128
	MOD_TIMECONST                         = 32
	MREMAP_FIXED                          = 2
	MREMAP_MAYMOVE                        = 1
	MSVC_VERSION                          = 0
	MS_ASYNC                              = 1
	MS_INVALIDATE                         = 2
	MS_SYNC                               = 4
	M_1_PI                                = 0.31830988618379067154
	M_1_PIf128                            = 0
	M_1_PIf32                             = 0
	M_1_PIf32x                            = 0
	M_1_PIf64                             = 0
	M_1_PIf64x                            = 0
	M_1_PIl                               = 0.318309886183790671537767526745028724
	M_2_PI                                = 0.63661977236758134308
	M_2_PIf128                            = 0
	M_2_PIf32                             = 0
	M_2_PIf32x                            = 0
	M_2_PIf64                             = 0
	M_2_PIf64x                            = 0
	M_2_PIl                               = 0.636619772367581343075535053490057448
	M_2_SQRTPI                            = 1.12837916709551257390
	M_2_SQRTPIf128                        = 0
	M_2_SQRTPIf32                         = 0
	M_2_SQRTPIf32x                        = 0
	M_2_SQRTPIf64                         = 0
	M_2_SQRTPIf64x                        = 0
	M_2_SQRTPIl                           = 1.128379167095512573896158903121545172
	M_E                                   = 2.7182818284590452354
	M_Ef128                               = 0
	M_Ef32                                = 0
	M_Ef32x                               = 0
	M_Ef64                                = 0
	M_Ef64x                               = 0
	M_El                                  = 2.718281828459045235360287471352662498
	M_LN10                                = 2.30258509299404568402
	M_LN10f128                            = 0
	M_LN10f32                             = 0
	M_LN10f32x                            = 0
	M_LN10f64                             = 0
	M_LN10f64x                            = 0
	M_LN10l                               = 2.302585092994045684017991454684364208
	M_LN2                                 = 0.69314718055994530942
	M_LN2f128                             = 0
	M_LN2f32                              = 0
	M_LN2f32x                             = 0
	M_LN2f64                              = 0
	M_LN2f64x                             = 0
	M_LN2l                                = 0.693147180559945309417232121458176568
	M_LOG10E                              = 0.43429448190325182765
	M_LOG10Ef128                          = 0
	M_LOG10Ef32                           = 0
	M_LOG10Ef32x                          = 0
	M_LOG10Ef64                           = 0
	M_LOG10Ef64x                          = 0
	M_LOG10El                             = 0.434294481903251827651128918916605082
	M_LOG2E                               = 1.4426950408889634074
	M_LOG2Ef128                           = 0
	M_LOG2Ef32                            = 0
	M_LOG2Ef32x                           = 0
	M_LOG2Ef64                            = 0
	M_LOG2Ef64x                           = 0
	M_LOG2El                              = 1.442695040888963407359924681001892137
	M_PI                                  = 3.14159265358979323846
	M_PI_2                                = 1.57079632679489661923
	M_PI_2f128                            = 0
	M_PI_2f32                             = 0
	M_PI_2f32x                            = 0
	M_PI_2f64                             = 0
	M_PI_2f64x                            = 0
	M_PI_2l                               = 1.570796326794896619231321691639751442
	M_PI_4                                = 0.78539816339744830962
	M_PI_4f128                            = 0
	M_PI_4f32                             = 0
	M_PI_4f32x                            = 0
	M_PI_4f64                             = 0
	M_PI_4f64x                            = 0
	M_PI_4l                               = 0.785398163397448309615660845819875721
	M_PIf128                              = 0
	M_PIf32                               = 0
	M_PIf32x                              = 0
	M_PIf64                               = 0
	M_PIf64x                              = 0
	M_PIl                                 = 3.141592653589793238462643383279502884
	M_SQRT1_2                             = 0.70710678118654752440
	M_SQRT1_2f128                         = 0
	M_SQRT1_2f32                          = 0
	M_SQRT1_2f32x                         = 0
	M_SQRT1_2f64                          = 0
	M_SQRT1_2f64x                         = 0
	M_SQRT1_2l                            = 0.707106781186547524400844362104849039
	M_SQRT2                               = 1.41421356237309504880
	M_SQRT2f128                           = 0
	M_SQRT2f32                            = 0
	M_SQRT2f32x                           = 0
	M_SQRT2f64                            = 0
	M_SQRT2f64x                           = 0
	M_SQRT2l                              = 1.414213562373095048801688724209698079
	NB                                    = 3
	NCC                                   = 8
	NC_AllowAgg                           = 0x000001
	NC_AllowWin                           = 0x004000
	NC_Complex                            = 0x002000
	NC_FromDDL                            = 0x040000
	NC_GenCol                             = 0x000008
	NC_HasAgg                             = 0x000010
	NC_HasWin                             = 0x008000
	NC_IdxExpr                            = 0x000020
	NC_InAggFunc                          = 0x020000
	NC_IsCheck                            = 0x000004
	NC_IsDDL                              = 0x010000
	NC_MinMaxAgg                          = 0x001000
	NC_NoSelect                           = 0x080000
	NC_OrderAgg                           = 0x8000000
	NC_PartIdx                            = 0x000002
	NC_SelfRef                            = 0x00002e
	NC_Subquery                           = 0x000040
	NC_UAggInfo                           = 0x000100
	NC_UBaseReg                           = 0x000400
	NC_UEList                             = 0x000080
	NC_UUpsert                            = 0x000200
	NDEBUG                                = 1
	NN                                    = 1
	NOT_WITHIN                            = 0
	NO_LOCK                               = 0
	N_6PACK                               = 7
	N_AX25                                = 5
	N_HCI                                 = 15
	N_HDLC                                = 13
	N_IRDA                                = 11
	N_MASC                                = 8
	N_MOUSE                               = 2
	N_OR_COST                             = 3
	N_PPP                                 = 3
	N_PROFIBUS_FDL                        = 10
	N_R3964                               = 9
	N_SLIP                                = 1
	N_SMSBLOCK                            = 12
	N_SORT_BUCKET                         = 32
	N_STATEMENT                           = 8
	N_STRIP                               = 4
	N_SYNC_PPP                            = 14
	N_TTY                                 = 0
	N_X25                                 = 6
	OE_Abort                              = 2
	OE_Cascade                            = 10
	OE_Default                            = 11
	OE_Fail                               = 3
	OE_Ignore                             = 4
	OE_None                               = 0
	OE_Replace                            = 5
	OE_Restrict                           = 7
	OE_Rollback                           = 1
	OE_SetDflt                            = 9
	OE_SetNull                            = 8
	OE_Update                             = 6
	OMIT_TEMPDB                           = 0
	ONEPASS_MULTI                         = 2
	ONEPASS_OFF                           = 0
	ONEPASS_SINGLE                        = 1
	OPFLAG_APPEND                         = 0x08
	OPFLAG_AUXDELETE                      = 0x04
	OPFLAG_BULKCSR                        = 0x01
	OPFLAG_EPHEM                          = 0x01
	OPFLAG_FORDELETE                      = 0x08
	OPFLAG_ISNOOP                         = 0x40
	OPFLAG_ISUPDATE                       = 0x04
	OPFLAG_LASTROWID                      = 0x20
	OPFLAG_LENGTHARG                      = 0x40
	OPFLAG_NCHANGE                        = 0x01
	OPFLAG_NOCHNG                         = 0x01
	OPFLAG_NOCHNG_MAGIC                   = 0x6d
	OPFLAG_P2ISREG                        = 0x10
	OPFLAG_PERMUTE                        = 0x01
	OPFLAG_PREFORMAT                      = 0x80
	OPFLAG_SAVEPOSITION                   = 0x02
	OPFLAG_SEEKEQ                         = 0x02
	OPFLAG_TYPEOFARG                      = 0x80
	OPFLAG_USESEEKRESULT                  = 0x10
	OPFLG_IN1                             = 0x02
	OPFLG_IN2                             = 0x04
	OPFLG_IN3                             = 0x08
	OPFLG_JUMP                            = 0x01
	OPFLG_NCYCLE                          = 0x40
	OPFLG_OUT2                            = 0x10
	OPFLG_OUT3                            = 0x20
	OP_Abortable                          = 186
	OP_Add                                = 106
	OP_AddImm                             = 86
	OP_Affinity                           = 96
	OP_AggFinal                           = 165
	OP_AggInverse                         = 161
	OP_AggStep                            = 162
	OP_AggStep1                           = 163
	OP_AggValue                           = 164
	OP_And                                = 44
	OP_AutoCommit                         = 1
	OP_BeginSubrtn                        = 74
	OP_BitAnd                             = 102
	OP_BitNot                             = 114
	OP_BitOr                              = 103
	OP_Blob                               = 77
	OP_Cast                               = 88
	OP_Checkpoint                         = 3
	OP_Clear                              = 145
	OP_Close                              = 122
	OP_ClrSubtype                         = 179
	OP_CollSeq                            = 85
	OP_Column                             = 94
	OP_ColumnsUsed                        = 123
	OP_Compare                            = 90
	OP_Concat                             = 111
	OP_Copy                               = 80
	OP_Count                              = 98
	OP_CreateBtree                        = 147
	OP_CursorHint                         = 182
	OP_CursorLock                         = 167
	OP_CursorUnlock                       = 168
	OP_DecrJumpZero                       = 61
	OP_DeferredSeek                       = 141
	OP_Delete                             = 130
	OP_Destroy                            = 144
	OP_Divide                             = 109
	OP_DropIndex                          = 152
	OP_DropTable                          = 151
	OP_DropTrigger                        = 154
	OP_ElseEq                             = 58
	OP_EndCoroutine                       = 68
	OP_Eq                                 = 53
	OP_Expire                             = 166
	OP_Explain                            = 185
	OP_Filter                             = 64
	OP_FilterAdd                          = 180
	OP_FinishSeek                         = 143
	OP_FkCheck                            = 83
	OP_FkCounter                          = 158
	OP_FkIfZero                           = 49
	OP_Found                              = 29
	OP_Function                           = 66
	OP_Ge                                 = 57
	OP_Gosub                              = 10
	OP_Goto                               = 9
	OP_Gt                                 = 54
	OP_Halt                               = 70
	OP_HaltIfNull                         = 69
	OP_IdxDelete                          = 140
	OP_IdxGE                              = 45
	OP_IdxGT                              = 41
	OP_IdxInsert                          = 138
	OP_IdxLE                              = 40
	OP_IdxLT                              = 42
	OP_IdxRowid                           = 142
	OP_If                                 = 16
	OP_IfNoHope                           = 26
	OP_IfNot                              = 17
	OP_IfNotOpen                          = 25
	OP_IfNotZero                          = 60
	OP_IfNullRow                          = 20
	OP_IfPos                              = 59
	OP_IfSmaller                          = 33
	OP_IncrVacuum                         = 62
	OP_Init                               = 8
	OP_InitCoroutine                      = 11
	OP_Insert                             = 128
	OP_Int64                              = 72
	OP_IntCopy                            = 82
	OP_Integer                            = 71
	OP_IntegrityCk                        = 155
	OP_IsNull                             = 50
	OP_IsTrue                             = 91
	OP_IsType                             = 18
	OP_JournalMode                        = 4
	OP_Jump                               = 14
	OP_Last                               = 32
	OP_Le                                 = 55
	OP_LoadAnalysis                       = 150
	OP_Lt                                 = 56
	OP_MakeRecord                         = 97
	OP_MaxPgcnt                           = 178
	OP_MemMax                             = 159
	OP_Move                               = 79
	OP_Multiply                           = 108
	OP_MustBeInt                          = 13
	OP_Ne                                 = 52
	OP_NewRowid                           = 127
	OP_Next                               = 39
	OP_NoConflict                         = 27
	OP_Noop                               = 184
	OP_Not                                = 19
	OP_NotExists                          = 31
	OP_NotFound                           = 28
	OP_NotNull                            = 51
	OP_Null                               = 75
	OP_NullRow                            = 136
	OP_Offset                             = 93
	OP_OffsetLimit                        = 160
	OP_Once                               = 15
	OP_OpenAutoindex                      = 116
	OP_OpenDup                            = 115
	OP_OpenEphemeral                      = 118
	OP_OpenPseudo                         = 121
	OP_OpenRead                           = 112
	OP_OpenWrite                          = 113
	OP_Or                                 = 43
	OP_Pagecount                          = 177
	OP_Param                              = 157
	OP_ParseSchema                        = 149
	OP_Permutation                        = 89
	OP_Prev                               = 38
	OP_Program                            = 48
	OP_PureFunc                           = 65
	OP_ReadCookie                         = 99
	OP_Real                               = 153
	OP_RealAffinity                       = 87
	OP_ReleaseReg                         = 183
	OP_Remainder                          = 110
	OP_ReopenIdx                          = 101
	OP_ResetCount                         = 131
	OP_ResetSorter                        = 146
	OP_ResultRow                          = 84
	OP_Return                             = 67
	OP_Rewind                             = 36
	OP_RowCell                            = 129
	OP_RowData                            = 134
	OP_RowSetAdd                          = 156
	OP_RowSetRead                         = 46
	OP_RowSetTest                         = 47
	OP_Rowid                              = 135
	OP_SCopy                              = 81
	OP_Savepoint                          = 0
	OP_SeekEnd                            = 137
	OP_SeekGE                             = 23
	OP_SeekGT                             = 24
	OP_SeekHit                            = 125
	OP_SeekLE                             = 22
	OP_SeekLT                             = 21
	OP_SeekRowid                          = 30
	OP_SeekScan                           = 124
	OP_Sequence                           = 126
	OP_SequenceTest                       = 120
	OP_SetCookie                          = 100
	OP_ShiftLeft                          = 104
	OP_ShiftRight                         = 105
	OP_SoftNull                           = 76
	OP_Sort                               = 35
	OP_SorterCompare                      = 132
	OP_SorterData                         = 133
	OP_SorterInsert                       = 139
	OP_SorterNext                         = 37
	OP_SorterOpen                         = 119
	OP_SorterSort                         = 34
	OP_SqlExec                            = 148
	OP_String                             = 73
	OP_String8                            = 117
	OP_Subtract                           = 107
	OP_TableLock                          = 169
	OP_Trace                              = 181
	OP_Transaction                        = 2
	OP_TypeCheck                          = 95
	OP_VBegin                             = 170
	OP_VColumn                            = 175
	OP_VCreate                            = 171
	OP_VDestroy                           = 172
	OP_VFilter                            = 6
	OP_VInitIn                            = 174
	OP_VNext                              = 63
	OP_VOpen                              = 173
	OP_VRename                            = 176
	OP_VUpdate                            = 7
	OP_Vacuum                             = 5
	OP_Variable                           = 78
	OP_Yield                              = 12
	OP_ZeroOrNull                         = 92
	OS_VXWORKS                            = 0
	O_ACCMODE                             = 0003
	O_APPEND                              = 02000
	O_ASYNC                               = 020000
	O_BINARY                              = 0
	O_CLOEXEC                             = 524288
	O_CREAT                               = 0100
	O_DIRECT                              = 65536
	O_DIRECTORY                           = 16384
	O_DSYNC                               = 4096
	O_EXCL                                = 0200
	O_FSYNC                               = 1052672
	O_LARGEFILE                           = 0
	O_NDELAY                              = 2048
	O_NOATIME                             = 262144
	O_NOCTTY                              = 0400
	O_NOFOLLOW                            = 32768
	O_NONBLOCK                            = 04000
	O_PATH                                = 2097152
	O_RDONLY                              = 00
	O_RDWR                                = 02
	O_RSYNC                               = 1052672
	O_SYNC                                = 04010000
	O_TMPFILE                             = 4210688
	O_TRUNC                               = 01000
	O_WRONLY                              = 01
	P4_COLLSEQ                            = -2
	P4_DYNAMIC                            = -6
	P4_EXPR                               = -9
	P4_FREE_IF_LE                         = -6
	P4_FUNCCTX                            = -15
	P4_FUNCDEF                            = -7
	P4_INT32                              = -3
	P4_INT64                              = -13
	P4_INTARRAY                           = -14
	P4_KEYINFO                            = -8
	P4_MEM                                = -10
	P4_NOTUSED                            = 0
	P4_REAL                               = -12
	P4_STATIC                             = -1
	P4_SUBPROGRAM                         = -4
	P4_TABLE                              = -5
	P4_TRANSIENT                          = 0
	P4_VTAB                               = -11
	P5_ConstraintCheck                    = 3
	P5_ConstraintFK                       = 4
	P5_ConstraintNotNull                  = 1
	P5_ConstraintUnique                   = 2
	PAGER_CACHESPILL                      = 0x20
	PAGER_CKPT_FULLFSYNC                  = 0x10
	PAGER_ERROR                           = 6
	PAGER_FLAGS_MASK                      = 0x38
	PAGER_FULLFSYNC                       = 0x08
	PAGER_GET_NOCONTENT                   = 0x01
	PAGER_GET_READONLY                    = 0x02
	PAGER_JOURNALMODE_DELETE              = 0
	PAGER_JOURNALMODE_MEMORY              = 4
	PAGER_JOURNALMODE_OFF                 = 2
	PAGER_JOURNALMODE_PERSIST             = 1
	PAGER_JOURNALMODE_QUERY               = -1
	PAGER_JOURNALMODE_TRUNCATE            = 3
	PAGER_JOURNALMODE_WAL                 = 5
	PAGER_LOCKINGMODE_EXCLUSIVE           = 1
	PAGER_LOCKINGMODE_NORMAL              = 0
	PAGER_LOCKINGMODE_QUERY               = -1
	PAGER_MEMORY                          = 0x0002
	PAGER_OMIT_JOURNAL                    = 0x0001
	PAGER_OPEN                            = 0
	PAGER_READER                          = 1
	PAGER_STAT_HIT                        = 0
	PAGER_STAT_MISS                       = 1
	PAGER_STAT_SPILL                      = 3
	PAGER_STAT_WRITE                      = 2
	PAGER_SYNCHRONOUS_EXTRA               = 0x04
	PAGER_SYNCHRONOUS_FULL                = 0x03
	PAGER_SYNCHRONOUS_MASK                = 0x07
	PAGER_SYNCHRONOUS_NORMAL              = 0x02
	PAGER_SYNCHRONOUS_OFF                 = 0x01
	PAGER_WRITER_CACHEMOD                 = 3
	PAGER_WRITER_DBMOD                    = 4
	PAGER_WRITER_FINISHED                 = 5
	PAGER_WRITER_LOCKED                   = 2
	PARSE_MODE_DECLARE_VTAB               = 1
	PARSE_MODE_NORMAL                     = 0
	PARSE_MODE_RENAME                     = 2
	PARSE_MODE_UNMAP                      = 3
	PARTLY_WITHIN                         = 1
	PCACHE1_MIGHT_USE_GROUP_MUTEX         = 1
	PCACHE_DIRTYLIST_ADD                  = 2
	PCACHE_DIRTYLIST_FRONT                = 3
	PCACHE_DIRTYLIST_REMOVE               = 1
	PDP_ENDIAN                            = 3412
	PENDING_LOCK                          = 3
	PGHDR_CLEAN                           = 0x001
	PGHDR_DIRTY                           = 0x002
	PGHDR_DONT_WRITE                      = 0x010
	PGHDR_MMAP                            = 0x020
	PGHDR_NEED_SYNC                       = 0x008
	PGHDR_WAL_APPEND                      = 0x040
	PGHDR_WRITEABLE                       = 0x004
	PKEY_DISABLE_ACCESS                   = 0x1
	PKEY_DISABLE_WRITE                    = 0x2
	POSIX_FADV_DONTNEED                   = 4
	POSIX_FADV_NOREUSE                    = 5
	POSIX_FADV_NORMAL                     = 0
	POSIX_FADV_RANDOM                     = 1
	POSIX_FADV_SEQUENTIAL                 = 2
	POSIX_FADV_WILLNEED                   = 3
	POSIX_MADV_DONTNEED                   = 4
	POSIX_MADV_NORMAL                     = 0
	POSIX_MADV_RANDOM                     = 1
	POSIX_MADV_SEQUENTIAL                 = 2
	POSIX_MADV_WILLNEED                   = 3
	PREFERRED_SCHEMA_TABLE                = "sqlite_schema"
	PREFERRED_TEMP_SCHEMA_TABLE           = "sqlite_temp_schema"
	PROT_EXEC                             = 0x4
	PROT_GROWSDOWN                        = 0x01000000
	PROT_GROWSUP                          = 0x02000000
	PROT_NONE                             = 0x0
	PROT_READ                             = 0x1
	PROT_WRITE                            = 0x2
	PTF_INTKEY                            = 0x01
	PTF_LEAF                              = 0x08
	PTF_LEAFDATA                          = 0x04
	PTF_ZERODATA                          = 0x02
	PTRMAP_BTREE                          = 5
	PTRMAP_FREEPAGE                       = 2
	PTRMAP_OVERFLOW1                      = 3
	PTRMAP_OVERFLOW2                      = 4
	PTRMAP_ROOTPAGE                       = 1
	P_tmpdir                              = "/tmp"
	PragFlg_NeedSchema                    = 0x01
	PragFlg_NoColumns                     = 0x02
	PragFlg_NoColumns1                    = 0x04
	PragFlg_ReadOnly                      = 0x08
	PragFlg_Result0                       = 0x10
	PragFlg_Result1                       = 0x20
	PragFlg_SchemaOpt                     = 0x40
	PragFlg_SchemaReq                     = 0x80
	PragTyp_ACTIVATE_EXTENSIONS           = 0
	PragTyp_ANALYSIS_LIMIT                = 1
	PragTyp_AUTO_VACUUM                   = 3
	PragTyp_BUSY_TIMEOUT                  = 5
	PragTyp_CACHE_SIZE                    = 6
	PragTyp_CACHE_SPILL                   = 7
	PragTyp_CASE_SENSITIVE_LIKE           = 8
	PragTyp_COLLATION_LIST                = 9
	PragTyp_COMPILE_OPTIONS               = 10
	PragTyp_DATABASE_LIST                 = 12
	PragTyp_DATA_STORE_DIRECTORY          = 11
	PragTyp_DEFAULT_CACHE_SIZE            = 13
	PragTyp_ENCODING                      = 14
	PragTyp_FLAG                          = 4
	PragTyp_FOREIGN_KEY_CHECK             = 15
	PragTyp_FOREIGN_KEY_LIST              = 16
	PragTyp_FUNCTION_LIST                 = 17
	PragTyp_HARD_HEAP_LIMIT               = 18
	PragTyp_HEADER_VALUE                  = 2
	PragTyp_INCREMENTAL_VACUUM            = 19
	PragTyp_INDEX_INFO                    = 20
	PragTyp_INDEX_LIST                    = 21
	PragTyp_INTEGRITY_CHECK               = 22
	PragTyp_JOURNAL_MODE                  = 23
	PragTyp_JOURNAL_SIZE_LIMIT            = 24
	PragTyp_LOCKING_MODE                  = 26
	PragTyp_LOCK_PROXY_FILE               = 25
	PragTyp_LOCK_STATUS                   = 44
	PragTyp_MMAP_SIZE                     = 28
	PragTyp_MODULE_LIST                   = 29
	PragTyp_OPTIMIZE                      = 30
	PragTyp_PAGE_COUNT                    = 27
	PragTyp_PAGE_SIZE                     = 31
	PragTyp_PRAGMA_LIST                   = 32
	PragTyp_SECURE_DELETE                 = 33
	PragTyp_SHRINK_MEMORY                 = 34
	PragTyp_SOFT_HEAP_LIMIT               = 35
	PragTyp_STATS                         = 45
	PragTyp_SYNCHRONOUS                   = 36
	PragTyp_TABLE_INFO                    = 37
	PragTyp_TABLE_LIST                    = 38
	PragTyp_TEMP_STORE                    = 39
	PragTyp_TEMP_STORE_DIRECTORY          = 40
	PragTyp_THREADS                       = 41
	PragTyp_WAL_AUTOCHECKPOINT            = 42
	PragTyp_WAL_CHECKPOINT                = 43
	RAND_MAX                              = 2147483647
	RBU_CREATE_STATE                      = "CREATE TABLE IF NOT EXISTS %s.rbu_state(k INTEGER PRIMARY KEY, v)"
	RBU_DELETE                            = 2
	RBU_ENABLE_DELTA_CKSUM                = 0
	RBU_EXCLUSIVE_CHECKPOINT              = "rbu_exclusive_checkpoint"
	RBU_IDX_DELETE                        = 4
	RBU_IDX_INSERT                        = 5
	RBU_INSERT                            = 1
	RBU_PK_EXTERNAL                       = 3
	RBU_PK_IPK                            = 2
	RBU_PK_NONE                           = 1
	RBU_PK_NOTABLE                        = 0
	RBU_PK_VTAB                           = 5
	RBU_PK_WITHOUT_ROWID                  = 4
	RBU_REPLACE                           = 3
	RBU_STAGE_CAPTURE                     = 3
	RBU_STAGE_CKPT                        = 4
	RBU_STAGE_DONE                        = 5
	RBU_STAGE_MOVE                        = 2
	RBU_STAGE_OAL                         = 1
	RBU_STATE_CKPT                        = 6
	RBU_STATE_COOKIE                      = 7
	RBU_STATE_DATATBL                     = 10
	RBU_STATE_IDX                         = 3
	RBU_STATE_OALSZ                       = 8
	RBU_STATE_PHASEONESTEP                = 9
	RBU_STATE_PROGRESS                    = 5
	RBU_STATE_ROW                         = 4
	RBU_STATE_STAGE                       = 1
	RBU_STATE_TBL                         = 2
	RBU_UPDATE                            = 6
	READMARK_NOT_USED                     = 0xffffffff
	READ_LOCK                             = 1
	RENAME_EXCHANGE                       = 2
	RENAME_NOREPLACE                      = 1
	RENAME_WHITEOUT                       = 4
	RESERVED_LOCK                         = 2
	RETURNING_TRIGGER_NAME                = "sqlite_returning"
	RNDAWAY                               = 0
	RNDTOWARDS                            = 0
	ROWSET_ALLOCATION_SIZE                = 1024
	ROWSET_NEXT                           = 0x02
	ROWSET_SORTED                         = 0x01
	RTLD_BINDING_MASK                     = 0x3
	RTLD_DEEPBIND                         = 0x00008
	RTLD_GLOBAL                           = 0x00100
	RTLD_LAZY                             = 0x00001
	RTLD_LOCAL                            = 0
	RTLD_NODELETE                         = 0x01000
	RTLD_NOLOAD                           = 0x00004
	RTLD_NOW                              = 0x00002
	RTREE_CACHE_SZ                        = 5
	RTREE_CHECK_MAX_ERROR                 = 100
	RTREE_COORD_INT32                     = 1
	RTREE_COORD_REAL32                    = 0
	RTREE_DEFAULT_ROWEST                  = 1048576
	RTREE_EQ                              = 0x41
	RTREE_FALSE                           = 0x40
	RTREE_GE                              = 0x44
	RTREE_GT                              = 0x45
	RTREE_LE                              = 0x42
	RTREE_LT                              = 0x43
	RTREE_MATCH                           = 0x46
	RTREE_MAXCELLS                        = 51
	RTREE_MAX_AUX_COLUMN                  = 100
	RTREE_MAX_DEPTH                       = 40
	RTREE_MAX_DIMENSIONS                  = 5
	RTREE_MIN_ROWEST                      = 100
	RTREE_QUERY                           = 0x47
	RTREE_TRUE                            = 0x3f
	RTREE_ZERO                            = 0.0
	RWF_WRITE_LIFE_NOT_SET                = 0
	RWH_WRITE_LIFE_EXTREME                = 5
	RWH_WRITE_LIFE_LONG                   = 4
	RWH_WRITE_LIFE_MEDIUM                 = 3
	RWH_WRITE_LIFE_NONE                   = 1
	RWH_WRITE_LIFE_SHORT                  = 2
	R_OK                                  = 4
	SAVEPOINT_BEGIN                       = 0
	SAVEPOINT_RELEASE                     = 1
	SAVEPOINT_ROLLBACK                    = 2
	SCHEMA_ROOT                           = 1
	SEEK_CUR                              = 1
	SEEK_DATA                             = 3
	SEEK_END                              = 2
	SEEK_HOLE                             = 4
	SEEK_SET                              = 0
	SESSIONS_STRM_CHUNK_SIZE              = 64
	SESSION_MAX_BUFFER_SZ                 = 2147483391
	SESSION_UPDATE_CACHE_SZ               = 12
	SF_Aggregate                          = 0x0000008
	SF_All                                = 0x0000002
	SF_ComplexResult                      = 0x0040000
	SF_Compound                           = 0x0000100
	SF_Converted                          = 0x0010000
	SF_CopyCte                            = 0x4000000
	SF_Distinct                           = 0x0000001
	SF_Expanded                           = 0x0000040
	SF_FixedLimit                         = 0x0004000
	SF_HasAgg                             = 0x0000010
	SF_HasTypeInfo                        = 0x0000080
	SF_IncludeHidden                      = 0x0020000
	SF_MaybeConvert                       = 0x0008000
	SF_MinMaxAgg                          = 0x0001000
	SF_MultiPart                          = 0x2000000
	SF_MultiValue                         = 0x0000400
	SF_NestedFrom                         = 0x0000800
	SF_NoopOrderBy                        = 0x0400000
	SF_OrderByReqd                        = 0x8000000
	SF_PushDown                           = 0x1000000
	SF_Recursive                          = 0x0002000
	SF_Resolved                           = 0x0000004
	SF_UFSrcCheck                         = 0x0800000
	SF_UpdateFrom                         = 0x10000000
	SF_UsesEphemeral                      = 0x0000020
	SF_Values                             = 0x0000200
	SF_View                               = 0x0200000
	SF_WhereBegin                         = 0x0080000
	SF_WinRewrite                         = 0x0100000
	SHARED_LOCK                           = 1
	SHARED_SIZE                           = 510
	SIOCADDDLCI                           = 0x8980
	SIOCADDMULTI                          = 0x8931
	SIOCADDRT                             = 0x890B
	SIOCDARP                              = 0x8953
	SIOCDELDLCI                           = 0x8981
	SIOCDELMULTI                          = 0x8932
	SIOCDELRT                             = 0x890C
	SIOCDEVPRIVATE                        = 0x89F0
	SIOCDIFADDR                           = 0x8936
	SIOCDRARP                             = 0x8960
	SIOCGARP                              = 0x8954
	SIOCGIFADDR                           = 0x8915
	SIOCGIFBR                             = 0x8940
	SIOCGIFBRDADDR                        = 0x8919
	SIOCGIFCONF                           = 0x8912
	SIOCGIFCOUNT                          = 0x8938
	SIOCGIFDSTADDR                        = 0x8917
	SIOCGIFENCAP                          = 0x8925
	SIOCGIFFLAGS                          = 0x8913
	SIOCGIFHWADDR                         = 0x8927
	SIOCGIFINDEX                          = 0x8933
	SIOCGIFMAP                            = 0x8970
	SIOCGIFMEM                            = 0x891f
	SIOCGIFMETRIC                         = 0x891d
	SIOCGIFMTU                            = 0x8921
	SIOCGIFNAME                           = 0x8910
	SIOCGIFNETMASK                        = 0x891b
	SIOCGIFPFLAGS                         = 0x8935
	SIOCGIFSLAVE                          = 0x8929
	SIOCGIFTXQLEN                         = 0x8942
	SIOCGRARP                             = 0x8961
	SIOCPROTOPRIVATE                      = 0x89E0
	SIOCRTMSG                             = 0x890D
	SIOCSARP                              = 0x8955
	SIOCSIFADDR                           = 0x8916
	SIOCSIFBR                             = 0x8941
	SIOCSIFBRDADDR                        = 0x891a
	SIOCSIFDSTADDR                        = 0x8918
	SIOCSIFENCAP                          = 0x8926
	SIOCSIFFLAGS                          = 0x8914
	SIOCSIFHWADDR                         = 0x8924
	SIOCSIFHWBROADCAST                    = 0x8937
	SIOCSIFLINK                           = 0x8911
	SIOCSIFMAP                            = 0x8971
	SIOCSIFMEM                            = 0x8920
	SIOCSIFMETRIC                         = 0x891e
	SIOCSIFMTU                            = 0x8922
	SIOCSIFNAME                           = 0x8923
	SIOCSIFNETMASK                        = 0x891c
	SIOCSIFPFLAGS                         = 0x8934
	SIOCSIFSLAVE                          = 0x8930
	SIOCSIFTXQLEN                         = 0x8943
	SIOCSRARP                             = 0x8962
	SIOGIFINDEX                           = 35123
	SLOT_2_0                              = 0x001fc07f
	SLOT_4_2_0                            = 0xf01fc07f
	SORTER_MAX_MERGE_COUNT                = 16
	SORTER_TYPE_INTEGER                   = 0x01
	SORTER_TYPE_TEXT                      = 0x02
	SORTFLAG_UseSorter                    = 0x01
	SPILLFLAG_NOSYNC                      = 0x04
	SPILLFLAG_OFF                         = 0x01
	SPILLFLAG_ROLLBACK                    = 0x02
	SPLICE_F_GIFT                         = 8
	SPLICE_F_MORE                         = 4
	SPLICE_F_MOVE                         = 1
	SPLICE_F_NONBLOCK                     = 2
	SQLITE3EXT_H                          = 0
	SQLITE3_H                             = 0
	SQLITE3_TEXT                          = 3
	SQLITEINT_H                           = 0
	SQLITE_ABORT                          = 4
	SQLITE_ABORT_ROLLBACK                 = 516
	SQLITE_ACCESS_EXISTS                  = 0
	SQLITE_ACCESS_READ                    = 2
	SQLITE_ACCESS_READWRITE               = 1
	SQLITE_AFF_BLOB                       = 0x41
	SQLITE_AFF_FLEXNUM                    = 0x46
	SQLITE_AFF_INTEGER                    = 0x44
	SQLITE_AFF_MASK                       = 0x47
	SQLITE_AFF_NONE                       = 0x40
	SQLITE_AFF_NUMERIC                    = 0x43
	SQLITE_AFF_REAL                       = 0x45
	SQLITE_AFF_TEXT                       = 0x42
	SQLITE_ALLOW_COVERING_INDEX_SCAN      = 1
	SQLITE_ALTER_TABLE                    = 26
	SQLITE_AMALGAMATION                   = 1
	SQLITE_ANALYZE                        = 28
	SQLITE_ANY                            = 5
	SQLITE_API                            = 0
	SQLITE_APICALL                        = 0
	SQLITE_ASCII                          = 1
	SQLITE_ATOMIC_INTRINSICS              = 1
	SQLITE_ATTACH                         = 24
	SQLITE_AUTH                           = 23
	SQLITE_AUTH_USER                      = 279
	SQLITE_AllOpts                        = 0xffffffff
	SQLITE_AutoIndex                      = 0x00008000
	SQLITE_BIGENDIAN                      = 0
	SQLITE_BIG_DBL                        = 0
	SQLITE_BLDF1_INDEXED                  = 0x0001
	SQLITE_BLDF1_UNIQUE                   = 0x0002
	SQLITE_BLDF2_2NDPASS                  = 0x0004
	SQLITE_BLOB                           = 4
	SQLITE_BTREE_H                        = 0
	SQLITE_BUSY                           = 5
	SQLITE_BUSY_RECOVERY                  = 261
	SQLITE_BUSY_SNAPSHOT                  = 517
	SQLITE_BUSY_TIMEOUT                   = 773
	SQLITE_BYTEORDER                      = 1234
	SQLITE_BalancedMerge                  = 0x00200000
	SQLITE_BloomFilter                    = 0x00080000
	SQLITE_BloomPulldown                  = 0x00100000
	SQLITE_CALLBACK                       = 0
	SQLITE_CANTOPEN                       = 14
	SQLITE_CANTOPEN_CONVPATH              = 1038
	SQLITE_CANTOPEN_DIRTYWAL              = 1294
	SQLITE_CANTOPEN_FULLPATH              = 782
	SQLITE_CANTOPEN_ISDIR                 = 526
	SQLITE_CANTOPEN_NOTEMPDIR             = 270
	SQLITE_CANTOPEN_SYMLINK               = 1550
	SQLITE_CDECL                          = 0
	SQLITE_CHANGESETAPPLY_INVERT          = 0x0002
	SQLITE_CHANGESETAPPLY_NOSAVEPOINT     = 0x0001
	SQLITE_CHANGESETSTART_INVERT          = 0x0002
	SQLITE_CHANGESET_ABORT                = 2
	SQLITE_CHANGESET_CONFLICT             = 3
	SQLITE_CHANGESET_CONSTRAINT           = 4
	SQLITE_CHANGESET_DATA                 = 1
	SQLITE_CHANGESET_FOREIGN_KEY          = 5
	SQLITE_CHANGESET_NOTFOUND             = 2
	SQLITE_CHANGESET_OMIT                 = 0
	SQLITE_CHANGESET_REPLACE              = 1
	SQLITE_CHECKPOINT_FULL                = 1
	SQLITE_CHECKPOINT_PASSIVE             = 0
	SQLITE_CHECKPOINT_RESTART             = 2
	SQLITE_CHECKPOINT_TRUNCATE            = 3
	SQLITE_CKSUMVFS_STATIC                = 1
	SQLITE_CONFIG_COVERING_INDEX_SCAN     = 20
	SQLITE_CONFIG_GETMALLOC               = 5
	SQLITE_CONFIG_GETMUTEX                = 11
	SQLITE_CONFIG_GETPCACHE               = 15
	SQLITE_CONFIG_GETPCACHE2              = 19
	SQLITE_CONFIG_HEAP                    = 8
	SQLITE_CONFIG_LOG                     = 16
	SQLITE_CONFIG_LOOKASIDE               = 13
	SQLITE_CONFIG_MALLOC                  = 4
	SQLITE_CONFIG_MEMDB_MAXSIZE           = 29
	SQLITE_CONFIG_MEMSTATUS               = 9
	SQLITE_CONFIG_MMAP_SIZE               = 22
	SQLITE_CONFIG_MULTITHREAD             = 2
	SQLITE_CONFIG_MUTEX                   = 10
	SQLITE_CONFIG_PAGECACHE               = 7
	SQLITE_CONFIG_PCACHE                  = 14
	SQLITE_CONFIG_PCACHE2                 = 18
	SQLITE_CONFIG_PCACHE_HDRSZ            = 24
	SQLITE_CONFIG_PMASZ                   = 25
	SQLITE_CONFIG_SCRATCH                 = 6
	SQLITE_CONFIG_SERIALIZED              = 3
	SQLITE_CONFIG_SINGLETHREAD            = 1
	SQLITE_CONFIG_SMALL_MALLOC            = 27
	SQLITE_CONFIG_SORTERREF_SIZE          = 28
	SQLITE_CONFIG_SQLLOG                  = 21
	SQLITE_CONFIG_STMTJRNL_SPILL          = 26
	SQLITE_CONFIG_URI                     = 17
	SQLITE_CONFIG_WIN32_HEAPSIZE          = 23
	SQLITE_CONSTRAINT                     = 19
	SQLITE_CONSTRAINT_CHECK               = 275
	SQLITE_CONSTRAINT_COMMITHOOK          = 531
	SQLITE_CONSTRAINT_DATATYPE            = 3091
	SQLITE_CONSTRAINT_FOREIGNKEY          = 787
	SQLITE_CONSTRAINT_FUNCTION            = 1043
	SQLITE_CONSTRAINT_NOTNULL             = 1299
	SQLITE_CONSTRAINT_PINNED              = 2835
	SQLITE_CONSTRAINT_PRIMARYKEY          = 1555
	SQLITE_CONSTRAINT_ROWID               = 2579
	SQLITE_CONSTRAINT_TRIGGER             = 1811
	SQLITE_CONSTRAINT_UNIQUE              = 2067
	SQLITE_CONSTRAINT_VTAB                = 2323
	SQLITE_COPY                           = 0
	SQLITE_CORE                           = 1
	SQLITE_CORRUPT                        = 11
	SQLITE_CORRUPT_INDEX                  = 779
	SQLITE_CORRUPT_SEQUENCE               = 523
	SQLITE_CORRUPT_VTAB                   = 267
	SQLITE_CREATE_INDEX                   = 1
	SQLITE_CREATE_TABLE                   = 2
	SQLITE_CREATE_TEMP_INDEX              = 3
	SQLITE_CREATE_TEMP_TABLE              = 4
	SQLITE_CREATE_TEMP_TRIGGER            = 5
	SQLITE_CREATE_TEMP_VIEW               = 6
	SQLITE_CREATE_TRIGGER                 = 7
	SQLITE_CREATE_VIEW                    = 8
	SQLITE_CREATE_VTABLE                  = 29
	SQLITE_CacheSpill                     = 0x00000020
	SQLITE_CellSizeCk                     = 0x00200000
	SQLITE_CkptFullFSync                  = 0x00000010
	SQLITE_Coroutines                     = 0x02000000
	SQLITE_CountOfView                    = 0x00000200
	SQLITE_CoverIdxScan                   = 0x00000020
	SQLITE_CursorHints                    = 0x00000400
	SQLITE_DBCONFIG_DEFENSIVE             = 1010
	SQLITE_DBCONFIG_DQS_DDL               = 1014
	SQLITE_DBCONFIG_DQS_DML               = 1013
	SQLITE_DBCONFIG_ENABLE_FKEY           = 1002
	SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER = 1004
	SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005
	SQLITE_DBCONFIG_ENABLE_QPSG           = 1007
	SQLITE_DBCONFIG_ENABLE_TRIGGER        = 1003
	SQLITE_DBCONFIG_ENABLE_VIEW           = 1015
	SQLITE_DBCONFIG_LEGACY_ALTER_TABLE    = 1012
	SQLITE_DBCONFIG_LEGACY_FILE_FORMAT    = 1016
	SQLITE_DBCONFIG_LOOKASIDE             = 1001
	SQLITE_DBCONFIG_MAINDBNAME            = 1000
	SQLITE_DBCONFIG_MAX                   = 1017
	SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      = 1006
	SQLITE_DBCONFIG_RESET_DATABASE        = 1009
	SQLITE_DBCONFIG_TRIGGER_EQP           = 1008
	SQLITE_DBCONFIG_TRUSTED_SCHEMA        = 1017
	SQLITE_DBCONFIG_WRITABLE_SCHEMA       = 1011
	SQLITE_DBSTATUS_CACHE_HIT             = 7
	SQLITE_DBSTATUS_CACHE_MISS            = 8
	SQLITE_DBSTATUS_CACHE_SPILL           = 12
	SQLITE_DBSTATUS_CACHE_USED            = 1
	SQLITE_DBSTATUS_CACHE_USED_SHARED     = 11
	SQLITE_DBSTATUS_CACHE_WRITE           = 9
	SQLITE_DBSTATUS_DEFERRED_FKS          = 10
	SQLITE_DBSTATUS_LOOKASIDE_HIT         = 4
	SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL   = 6
	SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE   = 5
	SQLITE_DBSTATUS_LOOKASIDE_USED        = 0
	SQLITE_DBSTATUS_MAX                   = 12
	SQLITE_DBSTATUS_SCHEMA_USED           = 2
	SQLITE_DBSTATUS_STMT_USED             = 3
	SQLITE_DEBUG_OS_TRACE                 = 0
	SQLITE_DEFAULT_AUTOVACUUM             = 0
	SQLITE_DEFAULT_CACHE_SIZE             = -2000
	SQLITE_DEFAULT_FILE_FORMAT            = 4
	SQLITE_DEFAULT_FILE_PERMISSIONS       = 0644
	SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT     = -1
	SQLITE_DEFAULT_LOOKASIDE              = 40
	SQLITE_DEFAULT_MEMSTATUS              = 1
	SQLITE_DEFAULT_MMAP_SIZE              = 0
	SQLITE_DEFAULT_PAGE_SIZE              = 1024
	SQLITE_DEFAULT_PCACHE_INITSZ          = 20
	SQLITE_DEFAULT_PROXYDIR_PERMISSIONS   = 0755
	SQLITE_DEFAULT_RECURSIVE_TRIGGERS     = 0
	SQLITE_DEFAULT_SECTOR_SIZE            = 4096
	SQLITE_DEFAULT_SORTERREF_SIZE         = 0x7fffffff
	SQLITE_DEFAULT_SYNCHRONOUS            = 2
	SQLITE_DEFAULT_WAL_AUTOCHECKPOINT     = 1000
	SQLITE_DEFAULT_WAL_SYNCHRONOUS        = 2
	SQLITE_DEFAULT_WORKER_THREADS         = 0
	SQLITE_DELETE                         = 9
	SQLITE_DENY                           = 1
	SQLITE_DEPRECATED                     = 0
	SQLITE_DESERIALIZE_FREEONCLOSE        = 1
	SQLITE_DESERIALIZE_READONLY           = 4
	SQLITE_DESERIALIZE_RESIZEABLE         = 2
	SQLITE_DETACH                         = 25
	SQLITE_DETERMINISTIC                  = 0x000000800
	SQLITE_DIRECTONLY                     = 0x000080000
	SQLITE_DONE                           = 101
	SQLITE_DQS                            = 3
	SQLITE_DROP_INDEX                     = 10
	SQLITE_DROP_TABLE                     = 11
	SQLITE_DROP_TEMP_INDEX                = 12
	SQLITE_DROP_TEMP_TABLE                = 13
	SQLITE_DROP_TEMP_TRIGGER              = 14
	SQLITE_DROP_TEMP_VIEW                 = 15
	SQLITE_DROP_TRIGGER                   = 16
	SQLITE_DROP_VIEW                      = 17
	SQLITE_DROP_VTABLE                    = 30
	SQLITE_Defensive                      = 0x10000000
	SQLITE_DeferFKs                       = 0x00080000
	SQLITE_DistinctOpt                    = 0x00000010
	SQLITE_DqsDDL                         = 0x20000000
	SQLITE_DqsDML                         = 0x40000000
	SQLITE_ECEL_DUP                       = 0x01
	SQLITE_ECEL_FACTOR                    = 0x02
	SQLITE_ECEL_OMITREF                   = 0x08
	SQLITE_ECEL_REF                       = 0x04
	SQLITE_EMPTY                          = 16
	SQLITE_ENABLE_BYTECODE_VTAB           = 1
	SQLITE_ENABLE_COLUMN_METADATA         = 1
	SQLITE_ENABLE_DBPAGE_VTAB             = 1
	SQLITE_ENABLE_DBSTAT_VTAB             = 1
	SQLITE_ENABLE_DESERIALIZE             = 1
	SQLITE_ENABLE_EXPLAIN_COMMENTS        = 1
	SQLITE_ENABLE_FTS5                    = 1
	SQLITE_ENABLE_GEOPOLY                 = 1
	SQLITE_ENABLE_LOCKING_STYLE           = 0
	SQLITE_ENABLE_MATH_FUNCTIONS          = 1
	SQLITE_ENABLE_MEMORY_MANAGEMENT       = 1
	SQLITE_ENABLE_OFFSET_SQL_FUNC         = 1
	SQLITE_ENABLE_PREUPDATE_HOOK          = 1
	SQLITE_ENABLE_RBU                     = 1
	SQLITE_ENABLE_RTREE                   = 1
	SQLITE_ENABLE_SESSION                 = 1
	SQLITE_ENABLE_STAT4                   = 1
	SQLITE_ENABLE_STMTVTAB                = 1
	SQLITE_ENABLE_UNLOCK_NOTIFY           = 1
	SQLITE_ERROR                          = 1
	SQLITE_ERROR_MISSING_COLLSEQ          = 257
	SQLITE_ERROR_RETRY                    = 513
	SQLITE_ERROR_SNAPSHOT                 = 769
	SQLITE_EXPERIMENTAL                   = 0
	SQLITE_EXTENSION_INIT1                = 0
	SQLITE_EXTENSION_INIT3                = 0
	SQLITE_EnableQPSG                     = 0x00800000
	SQLITE_EnableTrigger                  = 0x00040000
	SQLITE_EnableView                     = 0x80000000
	SQLITE_FAIL                           = 3
	SQLITE_FAULTINJECTOR_COUNT            = 1
	SQLITE_FAULTINJECTOR_MALLOC           = 0
	SQLITE_FCNTL_BEGIN_ATOMIC_WRITE       = 31
	SQLITE_FCNTL_BUSYHANDLER              = 15
	SQLITE_FCNTL_CHUNK_SIZE               = 6
	SQLITE_FCNTL_CKPT_DONE                = 37
	SQLITE_FCNTL_CKPT_START               = 39
	SQLITE_FCNTL_CKSM_FILE                = 41
	SQLITE_FCNTL_COMMIT_ATOMIC_WRITE      = 32
	SQLITE_FCNTL_COMMIT_PHASETWO          = 22
	SQLITE_FCNTL_DATA_VERSION             = 35
	SQLITE_FCNTL_DB_UNCHANGED             = 0xca093fa0
	SQLITE_FCNTL_EXTERNAL_READER          = 40
	SQLITE_FCNTL_FILE_POINTER             = 7
	SQLITE_FCNTL_GET_LOCKPROXYFILE        = 2
	SQLITE_FCNTL_HAS_MOVED                = 20
	SQLITE_FCNTL_JOURNAL_POINTER          = 28
	SQLITE_FCNTL_LAST_ERRNO               = 4
	SQLITE_FCNTL_LOCKSTATE                = 1
	SQLITE_FCNTL_LOCK_TIMEOUT             = 34
	SQLITE_FCNTL_MMAP_SIZE                = 18
	SQLITE_FCNTL_OVERWRITE                = 11
	SQLITE_FCNTL_PDB                      = 30
	SQLITE_FCNTL_PERSIST_WAL              = 10
	SQLITE_FCNTL_POWERSAFE_OVERWRITE      = 13
	SQLITE_FCNTL_PRAGMA                   = 14
	SQLITE_FCNTL_RBU                      = 26
	SQLITE_FCNTL_RBUCNT                   = 5149216
	SQLITE_FCNTL_RESERVE_BYTES            = 38
	SQLITE_FCNTL_RESET_CACHE              = 42
	SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE    = 33
	SQLITE_FCNTL_SET_LOCKPROXYFILE        = 3
	SQLITE_FCNTL_SIZE_HINT                = 5
	SQLITE_FCNTL_SIZE_LIMIT               = 36
	SQLITE_FCNTL_SYNC                     = 21
	SQLITE_FCNTL_SYNC_OMITTED             = 8
	SQLITE_FCNTL_TEMPFILENAME             = 16
	SQLITE_FCNTL_TRACE                    = 19
	SQLITE_FCNTL_VFSNAME                  = 12
	SQLITE_FCNTL_VFS_POINTER              = 27
	SQLITE_FCNTL_WAL_BLOCK                = 24
	SQLITE_FCNTL_WIN32_AV_RETRY           = 9
	SQLITE_FCNTL_WIN32_GET_HANDLE         = 29
	SQLITE_FCNTL_WIN32_SET_HANDLE         = 23
	SQLITE_FCNTL_ZIPVFS                   = 25
	SQLITE_FILE_HEADER                    = "SQLite format 3"
	SQLITE_FLOAT                          = 2
	SQLITE_FORMAT                         = 24
	SQLITE_FP_PRECISION_LIMIT             = 100000000
	SQLITE_FRAME_MAGIC                    = 0x879fb71e
	SQLITE_FSFLAGS_IS_MSDOS               = 0x1
	SQLITE_FULL                           = 13
	SQLITE_FUNCTION                       = 31
	SQLITE_FUNC_ANYORDER                  = 0x08000000
	SQLITE_FUNC_BUILTIN                   = 0x00800000
	SQLITE_FUNC_CASE                      = 0x0008
	SQLITE_FUNC_CONSTANT                  = 0x0800
	SQLITE_FUNC_COUNT                     = 0x0100
	SQLITE_FUNC_DIRECT                    = 0x00080000
	SQLITE_FUNC_ENCMASK                   = 0x0003
	SQLITE_FUNC_EPHEM                     = 0x0010
	SQLITE_FUNC_HASH_SZ                   = 23
	SQLITE_FUNC_INLINE                    = 0x00400000
	SQLITE_FUNC_INTERNAL                  = 0x00040000
	SQLITE_FUNC_LENGTH                    = 0x0040
	SQLITE_FUNC_LIKE                      = 0x0004
	SQLITE_FUNC_MINMAX                    = 0x1000
	SQLITE_FUNC_NEEDCOLL                  = 0x0020
	SQLITE_FUNC_SLOCHNG                   = 0x2000
	SQLITE_FUNC_SUBTYPE                   = 0x00100000
	SQLITE_FUNC_TEST                      = 0x4000
	SQLITE_FUNC_TYPEOF                    = 0x0080
	SQLITE_FUNC_UNLIKELY                  = 0x0400
	SQLITE_FUNC_UNSAFE                    = 0x00200000
	SQLITE_FUNC_WINDOW                    = 0x00010000
	SQLITE_FactorOutConst                 = 0x00000008
	SQLITE_FlttnUnionAll                  = 0x00800000
	SQLITE_ForeignKeys                    = 0x00004000
	SQLITE_Fts3Tokenizer                  = 0x00400000
	SQLITE_FullColNames                   = 0x00000004
	SQLITE_FullFSync                      = 0x00000008
	SQLITE_GET_LOCKPROXYFILE              = 2
	SQLITE_GroupByOrder                   = 0x00000004
	SQLITE_HASH_H                         = 0
	SQLITE_HAVE_C99_MATH_FUNCS            = 1
	SQLITE_HAVE_OS_TRACE                  = 0
	SQLITE_IDXTYPE_APPDEF                 = 0
	SQLITE_IDXTYPE_IPK                    = 3
	SQLITE_IDXTYPE_PRIMARYKEY             = 2
	SQLITE_IDXTYPE_UNIQUE                 = 1
	SQLITE_IGNORE                         = 2
	SQLITE_INDEX_CONSTRAINT_EQ            = 2
	SQLITE_INDEX_CONSTRAINT_FUNCTION      = 150
	SQLITE_INDEX_CONSTRAINT_GE            = 32
	SQLITE_INDEX_CONSTRAINT_GLOB          = 66
	SQLITE_INDEX_CONSTRAINT_GT            = 4
	SQLITE_INDEX_CONSTRAINT_IS            = 72
	SQLITE_INDEX_CONSTRAINT_ISNOT         = 69
	SQLITE_INDEX_CONSTRAINT_ISNOTNULL     = 70
	SQLITE_INDEX_CONSTRAINT_ISNULL        = 71
	SQLITE_INDEX_CONSTRAINT_LE            = 8
	SQLITE_INDEX_CONSTRAINT_LIKE          = 65
	SQLITE_INDEX_CONSTRAINT_LIMIT         = 73
	SQLITE_INDEX_CONSTRAINT_LT            = 16
	SQLITE_INDEX_CONSTRAINT_MATCH         = 64
	SQLITE_INDEX_CONSTRAINT_NE            = 68
	SQLITE_INDEX_CONSTRAINT_OFFSET        = 74
	SQLITE_INDEX_CONSTRAINT_REGEXP        = 67
	SQLITE_INDEX_SCAN_UNIQUE              = 1
	SQLITE_INNOCUOUS                      = 0x000200000
	SQLITE_INSERT                         = 18
	SQLITE_INTEGER                        = 1
	SQLITE_INTEGRITY_CHECK_ERROR_MAX      = 100
	SQLITE_INTERNAL                       = 2
	SQLITE_INTERRUPT                      = 9
	SQLITE_IOCAP_ATOMIC                   = 0x00000001
	SQLITE_IOCAP_ATOMIC16K                = 0x00000040
	SQLITE_IOCAP_ATOMIC1K                 = 0x00000004
	SQLITE_IOCAP_ATOMIC2K                 = 0x00000008
	SQLITE_IOCAP_ATOMIC32K                = 0x00000080
	SQLITE_IOCAP_ATOMIC4K                 = 0x00000010
	SQLITE_IOCAP_ATOMIC512                = 0x00000002
	SQLITE_IOCAP_ATOMIC64K                = 0x00000100
	SQLITE_IOCAP_ATOMIC8K                 = 0x00000020
	SQLITE_IOCAP_BATCH_ATOMIC             = 0x00004000
	SQLITE_IOCAP_IMMUTABLE                = 0x00002000
	SQLITE_IOCAP_POWERSAFE_OVERWRITE      = 0x00001000
	SQLITE_IOCAP_SAFE_APPEND              = 0x00000200
	SQLITE_IOCAP_SEQUENTIAL               = 0x00000400
	SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN    = 0x00000800
	SQLITE_IOERR                          = 10
	SQLITE_IOERR_ACCESS                   = 3338
	SQLITE_IOERR_AUTH                     = 7178
	SQLITE_IOERR_BEGIN_ATOMIC             = 7434
	SQLITE_IOERR_BLOCKED                  = 2826
	SQLITE_IOERR_CHECKRESERVEDLOCK        = 3594
	SQLITE_IOERR_CLOSE                    = 4106
	SQLITE_IOERR_COMMIT_ATOMIC            = 7690
	SQLITE_IOERR_CONVPATH                 = 6666
	SQLITE_IOERR_CORRUPTFS                = 8458
	SQLITE_IOERR_DATA                     = 8202
	SQLITE_IOERR_DELETE                   = 2570
	SQLITE_IOERR_DELETE_NOENT             = 5898
	SQLITE_IOERR_DIR_CLOSE                = 4362
	SQLITE_IOERR_DIR_FSYNC                = 1290
	SQLITE_IOERR_FSTAT                    = 1802
	SQLITE_IOERR_FSYNC                    = 1034
	SQLITE_IOERR_GETTEMPPATH              = 6410
	SQLITE_IOERR_LOCK                     = 3850
	SQLITE_IOERR_MMAP                     = 6154
	SQLITE_IOERR_NOMEM                    = 3082
	SQLITE_IOERR_NOMEM_BKPT               = 3082
	SQLITE_IOERR_RDLOCK                   = 2314
	SQLITE_IOERR_READ                     = 266
	SQLITE_IOERR_ROLLBACK_ATOMIC          = 7946
	SQLITE_IOERR_SEEK                     = 5642
	SQLITE_IOERR_SHMLOCK                  = 5130
	SQLITE_IOERR_SHMMAP                   = 5386
	SQLITE_IOERR_SHMOPEN                  = 4618
	SQLITE_IOERR_SHMSIZE                  = 4874
	SQLITE_IOERR_SHORT_READ               = 522
	SQLITE_IOERR_TRUNCATE                 = 1546
	SQLITE_IOERR_UNLOCK                   = 2058
	SQLITE_IOERR_VNODE                    = 6922
	SQLITE_IOERR_WRITE                    = 778
	SQLITE_IgnoreChecks                   = 0x00000200
	SQLITE_IndexedExpr                    = 0x01000000
	SQLITE_JUMPIFNULL                     = 0x10
	SQLITE_LAST_ERRNO                     = 4
	SQLITE_LIKE_DOESNT_MATCH_BLOBS        = 1
	SQLITE_LIMIT_ATTACHED                 = 7
	SQLITE_LIMIT_COLUMN                   = 2
	SQLITE_LIMIT_COMPOUND_SELECT          = 4
	SQLITE_LIMIT_EXPR_DEPTH               = 3
	SQLITE_LIMIT_FUNCTION_ARG             = 6
	SQLITE_LIMIT_LENGTH                   = 0
	SQLITE_LIMIT_LIKE_PATTERN_LENGTH      = 8
	SQLITE_LIMIT_SQL_LENGTH               = 1
	SQLITE_LIMIT_TRIGGER_DEPTH            = 10
	SQLITE_LIMIT_VARIABLE_NUMBER          = 9
	SQLITE_LIMIT_VDBE_OP                  = 5
	SQLITE_LIMIT_WORKER_THREADS           = 11
	SQLITE_LITTLEENDIAN                   = 1
	SQLITE_LOCKED                         = 6
	SQLITE_LOCKED_SHAREDCACHE             = 262
	SQLITE_LOCKED_VTAB                    = 518
	SQLITE_LOCK_EXCLUSIVE                 = 4
	SQLITE_LOCK_NONE                      = 0
	SQLITE_LOCK_PENDING                   = 3
	SQLITE_LOCK_RESERVED                  = 2
	SQLITE_LOCK_SHARED                    = 1
	SQLITE_LegacyAlter                    = 0x04000000
	SQLITE_LegacyFileFmt                  = 0x00000002
	SQLITE_LoadExtFunc                    = 0x00020000
	SQLITE_LoadExtension                  = 0x00010000
	SQLITE_MALLOC_SOFT_LIMIT              = 1024
	SQLITE_MATCH                          = 0
	SQLITE_MAX_ALLOCATION_SIZE            = 2147483391
	SQLITE_MAX_ATTACHED                   = 10
	SQLITE_MAX_COLUMN                     = 2000
	SQLITE_MAX_COMPOUND_SELECT            = 500
	SQLITE_MAX_DB                         = 12
	SQLITE_MAX_DEFAULT_PAGE_SIZE          = 8192
	SQLITE_MAX_EXPR_DEPTH                 = 1000
	SQLITE_MAX_FILE_FORMAT                = 4
	SQLITE_MAX_FUNCTION_ARG               = 127
	SQLITE_MAX_LENGTH                     = 1000000000
	SQLITE_MAX_LIKE_PATTERN_LENGTH        = 50000
	SQLITE_MAX_MEMORY                     = 0
	SQLITE_MAX_MMAP_SIZE                  = 0x7fff0000
	SQLITE_MAX_PAGE_COUNT                 = 1073741823
	SQLITE_MAX_PAGE_SIZE                  = 65536
	SQLITE_MAX_PATHLEN                    = 4096
	SQLITE_MAX_PMASZ                      = 536870912
	SQLITE_MAX_PREPARE_RETRY              = 25
	SQLITE_MAX_SCHEMA_RETRY               = 50
	SQLITE_MAX_SQL_LENGTH                 = 1000000000
	SQLITE_MAX_SRCLIST                    = 200
	SQLITE_MAX_SYMLINK                    = 200
	SQLITE_MAX_SYMLINKS                   = 100
	SQLITE_MAX_TRIGGER_DEPTH              = 1000
	SQLITE_MAX_VARIABLE_NUMBER            = 32766
	SQLITE_MAX_VDBE_OP                    = 250000000
	SQLITE_MAX_WORKER_THREADS             = 8
	SQLITE_MEMDB_DEFAULT_MAXSIZE          = 1073741824
	SQLITE_MINIMUM_FILE_DESCRIPTOR        = 3
	SQLITE_MISMATCH                       = 20
	SQLITE_MISUSE                         = 21
	SQLITE_MSVC_H                         = 0
	SQLITE_MUTEX_APPDEF                   = 1
	SQLITE_MUTEX_FAST                     = 0
	SQLITE_MUTEX_NOOP                     = 1
	SQLITE_MUTEX_RECURSIVE                = 1
	SQLITE_MUTEX_STATIC_APP1              = 8
	SQLITE_MUTEX_STATIC_APP2              = 9
	SQLITE_MUTEX_STATIC_APP3              = 10
	SQLITE_MUTEX_STATIC_LRU               = 6
	SQLITE_MUTEX_STATIC_LRU2              = 7
	SQLITE_MUTEX_STATIC_MAIN              = 2
	SQLITE_MUTEX_STATIC_MASTER            = 2
	SQLITE_MUTEX_STATIC_MEM               = 3
	SQLITE_MUTEX_STATIC_MEM2              = 4
	SQLITE_MUTEX_STATIC_OPEN              = 4
	SQLITE_MUTEX_STATIC_PMEM              = 7
	SQLITE_MUTEX_STATIC_PRNG              = 5
	SQLITE_MUTEX_STATIC_TEMPDIR           = 11
	SQLITE_MUTEX_STATIC_VFS1              = 11
	SQLITE_MUTEX_STATIC_VFS2              = 12
	SQLITE_MUTEX_STATIC_VFS3              = 13
	SQLITE_MX_JUMP_OPCODE                 = 64
	SQLITE_MinMaxOpt                      = 0x00010000
	SQLITE_NEED_ERR_NAME                  = 0
	SQLITE_NOLFS                          = 22
	SQLITE_NOMATCH                        = 1
	SQLITE_NOMEM                          = 7
	SQLITE_NOMEM_BKPT                     = 7
	SQLITE_NOTADB                         = 26
	SQLITE_NOTFOUND                       = 12
	SQLITE_NOTICE                         = 27
	SQLITE_NOTICE_RBU                     = 795
	SQLITE_NOTICE_RECOVER_ROLLBACK        = 539
	SQLITE_NOTICE_RECOVER_WAL             = 283
	SQLITE_NOTNULL                        = 0x90
	SQLITE_NOWILDCARDMATCH                = 2
	SQLITE_NO_TSAN                        = 0
	SQLITE_NTUNE                          = 6
	SQLITE_NULL                           = 5
	SQLITE_NULLEQ                         = 0x80
	SQLITE_N_BTREE_META                   = 16
	SQLITE_N_KEYWORD                      = 147
	SQLITE_N_LIMIT                        = 12
	SQLITE_N_STDTYPE                      = 6
	SQLITE_NoCkptOnClose                  = 0x00000800
	SQLITE_NoSchemaError                  = 0x08000000
	SQLITE_NullCallback                   = 0x00000100
	SQLITE_OK                             = 0
	SQLITE_OK_LOAD_PERMANENTLY            = 256
	SQLITE_OK_SYMLINK                     = 512
	SQLITE_OPEN_AUTOPROXY                 = 0x00000020
	SQLITE_OPEN_CREATE                    = 0x00000004
	SQLITE_OPEN_DELETEONCLOSE             = 0x00000008
	SQLITE_OPEN_EXCLUSIVE                 = 0x00000010
	SQLITE_OPEN_EXRESCODE                 = 0x02000000
	SQLITE_OPEN_FULLMUTEX                 = 0x00010000
	SQLITE_OPEN_MAIN_DB                   = 0x00000100
	SQLITE_OPEN_MAIN_JOURNAL              = 0x00000800
	SQLITE_OPEN_MASTER_JOURNAL            = 0x00004000
	SQLITE_OPEN_MEMORY                    = 0x00000080
	SQLITE_OPEN_NOFOLLOW                  = 0x01000000
	SQLITE_OPEN_NOMUTEX                   = 0x00008000
	SQLITE_OPEN_PRIVATECACHE              = 0x00040000
	SQLITE_OPEN_READONLY                  = 0x00000001
	SQLITE_OPEN_READWRITE                 = 0x00000002
	SQLITE_OPEN_SHAREDCACHE               = 0x00020000
	SQLITE_OPEN_SUBJOURNAL                = 0x00002000
	SQLITE_OPEN_SUPER_JOURNAL             = 0x00004000
	SQLITE_OPEN_TEMP_DB                   = 0x00000200
	SQLITE_OPEN_TEMP_JOURNAL              = 0x00001000
	SQLITE_OPEN_TRANSIENT_DB              = 0x00000400
	SQLITE_OPEN_URI                       = 0x00000040
	SQLITE_OPEN_WAL                       = 0x00080000
	SQLITE_OS_KV                          = 0
	SQLITE_OS_OTHER                       = 0
	SQLITE_OS_SETUP_H                     = 0
	SQLITE_OS_UNIX                        = 1
	SQLITE_OS_WIN                         = 0
	SQLITE_OmitNoopJoin                   = 0x00000100
	SQLITE_OmitOrderBy                    = 0x00040000
	SQLITE_OrderByIdxJoin                 = 0x00000040
	SQLITE_PAGER_H                        = 0
	SQLITE_PERM                           = 3
	SQLITE_POWERSAFE_OVERWRITE            = 1
	SQLITE_PRAGMA                         = 19
	SQLITE_PREPARE_MASK                   = 0x0f
	SQLITE_PREPARE_NORMALIZE              = 0x02
	SQLITE_PREPARE_NO_VTAB                = 0x04
	SQLITE_PREPARE_PERSISTENT             = 0x01
	SQLITE_PREPARE_SAVESQL                = 0x80
	SQLITE_PRINTF_INTERNAL                = 0x01
	SQLITE_PRINTF_MALLOCED                = 0x04
	SQLITE_PRINTF_SQLFUNC                 = 0x02
	SQLITE_PRINT_BUF_SIZE                 = 70
	SQLITE_PRIVATE                        = 0
	SQLITE_PROTOCOL                       = 15
	SQLITE_PTRSIZE                        = 8
	SQLITE_PropagateConst                 = 0x00008000
	SQLITE_PushDown                       = 0x00001000
	SQLITE_QUERY_PLANNER_LIMIT            = 20000
	SQLITE_QUERY_PLANNER_LIMIT_INCR       = 1000
	SQLITE_QueryFlattener                 = 0x00000001
	SQLITE_QueryOnly                      = 0x00100000
	SQLITE_RANGE                          = 25
	SQLITE_RBU_STATE_CHECKPOINT           = 3
	SQLITE_RBU_STATE_DONE                 = 4
	SQLITE_RBU_STATE_ERROR                = 5
	SQLITE_RBU_STATE_MOVE                 = 2
	SQLITE_RBU_STATE_OAL                  = 1
	SQLITE_RBU_UPDATE_CACHESIZE           = 16
	SQLITE_READ                           = 20
	SQLITE_READONLY                       = 8
	SQLITE_READONLY_CANTINIT              = 1288
	SQLITE_READONLY_CANTLOCK              = 520
	SQLITE_READONLY_DBMOVED               = 1032
	SQLITE_READONLY_DIRECTORY             = 1544
	SQLITE_READONLY_RECOVERY              = 264
	SQLITE_READONLY_ROLLBACK              = 776
	SQLITE_RECURSIVE                      = 33
	SQLITE_REINDEX                        = 27
	SQLITE_REPLACE                        = 5
	SQLITE_ROLLBACK                       = 1
	SQLITE_ROW                            = 100
	SQLITE_ReadUncommit                   = 0x00000400
	SQLITE_RecTriggers                    = 0x00002000
	SQLITE_ReleaseReg                     = 0x00400000
	SQLITE_ResetDatabase                  = 0x02000000
	SQLITE_ReverseOrder                   = 0x00001000
	SQLITE_SAVEPOINT                      = 32
	SQLITE_SCANSTAT_COMPLEX               = 0x0001
	SQLITE_SCANSTAT_EST                   = 2
	SQLITE_SCANSTAT_EXPLAIN               = 4
	SQLITE_SCANSTAT_NAME                  = 3
	SQLITE_SCANSTAT_NCYCLE                = 7
	SQLITE_SCANSTAT_NLOOP                 = 0
	SQLITE_SCANSTAT_NVISIT                = 1
	SQLITE_SCANSTAT_PARENTID              = 6
	SQLITE_SCANSTAT_SELECTID              = 5
	SQLITE_SCHEMA                         = 17
	SQLITE_SELECT                         = 21
	SQLITE_SERIALIZE_NOCOPY               = 0x001
	SQLITE_SESSION_CONFIG_STRMSIZE        = 1
	SQLITE_SESSION_OBJCONFIG_SIZE         = 1
	SQLITE_SET_LOCKPROXYFILE              = 3
	SQLITE_SHM_EXCLUSIVE                  = 8
	SQLITE_SHM_LOCK                       = 2
	SQLITE_SHM_NLOCK                      = 8
	SQLITE_SHM_SHARED                     = 4
	SQLITE_SHM_UNLOCK                     = 1
	SQLITE_SORTER_PMASZ                   = 250
	SQLITE_SOUNDEX                        = 1
	SQLITE_SOURCE_ID                      = "2023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69cffde2924203304e8ffc4155597af0c191da"
	SQLITE_SO_ASC                         = 0
	SQLITE_SO_DESC                        = 1
	SQLITE_SO_UNDEFINED                   = -1
	SQLITE_STAT4_SAMPLES                  = 24
	SQLITE_STATE_BUSY                     = 0x6d
	SQLITE_STATE_CLOSED                   = 0xce
	SQLITE_STATE_ERROR                    = 0xd5
	SQLITE_STATE_OPEN                     = 0x76
	SQLITE_STATE_SICK                     = 0xba
	SQLITE_STATE_ZOMBIE                   = 0xa7
	SQLITE_STATUS_MALLOC_COUNT            = 9
	SQLITE_STATUS_MALLOC_SIZE             = 5
	SQLITE_STATUS_MEMORY_USED             = 0
	SQLITE_STATUS_PAGECACHE_OVERFLOW      = 2
	SQLITE_STATUS_PAGECACHE_SIZE          = 7
	SQLITE_STATUS_PAGECACHE_USED          = 1
	SQLITE_STATUS_PARSER_STACK            = 6
	SQLITE_STATUS_SCRATCH_OVERFLOW        = 4
	SQLITE_STATUS_SCRATCH_SIZE            = 8
	SQLITE_STATUS_SCRATCH_USED            = 3
	SQLITE_STDCALL                        = 0
	SQLITE_STMTJRNL_SPILL                 = 65536
	SQLITE_STMTSTATUS_AUTOINDEX           = 3
	SQLITE_STMTSTATUS_FILTER_HIT          = 8
	SQLITE_STMTSTATUS_FILTER_MISS         = 7
	SQLITE_STMTSTATUS_FULLSCAN_STEP       = 1
	SQLITE_STMTSTATUS_MEMUSED             = 99
	SQLITE_STMTSTATUS_REPREPARE           = 5
	SQLITE_STMTSTATUS_RUN                 = 6
	SQLITE_STMTSTATUS_SORT                = 2
	SQLITE_STMTSTATUS_VM_STEP             = 4
	SQLITE_SUBTYPE                        = 0x000100000
	SQLITE_SYNC_DATAONLY                  = 0x00010
	SQLITE_SYNC_FULL                      = 0x00003
	SQLITE_SYNC_NORMAL                    = 0x00002
	SQLITE_SYSAPI                         = 0
	SQLITE_SYSTEM_MALLOC                  = 1
	SQLITE_SeekScan                       = 0x00020000
	SQLITE_ShortColNames                  = 0x00000040
	SQLITE_SimplifyJoin                   = 0x00002000
	SQLITE_SkipScan                       = 0x00004000
	SQLITE_Stat4                          = 0x00000800
	SQLITE_TCLAPI                         = 0
	SQLITE_TEMP_FILE_PREFIX               = "etilqs_"
	SQLITE_TEMP_STORE                     = 1
	SQLITE_TEST                           = 1
	SQLITE_TESTCTRL_ALWAYS                = 13
	SQLITE_TESTCTRL_ASSERT                = 12
	SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS   = 10
	SQLITE_TESTCTRL_BITVEC_TEST           = 8
	SQLITE_TESTCTRL_BYTEORDER             = 22
	SQLITE_TESTCTRL_EXPLAIN_STMT          = 19
	SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS   = 29
	SQLITE_TESTCTRL_FAULT_INSTALL         = 9
	SQLITE_TESTCTRL_FIRST                 = 5
	SQLITE_TESTCTRL_IMPOSTER              = 25
	SQLITE_TESTCTRL_INTERNAL_FUNCTIONS    = 17
	SQLITE_TESTCTRL_ISINIT                = 23
	SQLITE_TESTCTRL_ISKEYWORD             = 16
	SQLITE_TESTCTRL_LAST                  = 33
	SQLITE_TESTCTRL_LOCALTIME_FAULT       = 18
	SQLITE_TESTCTRL_LOGEST                = 33
	SQLITE_TESTCTRL_NEVER_CORRUPT         = 20
	SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD  = 19
	SQLITE_TESTCTRL_OPTIMIZATIONS         = 15
	SQLITE_TESTCTRL_PARSER_COVERAGE       = 26
	SQLITE_TESTCTRL_PENDING_BYTE          = 11
	SQLITE_TESTCTRL_PRNG_RESET            = 7
	SQLITE_TESTCTRL_PRNG_RESTORE          = 6
	SQLITE_TESTCTRL_PRNG_SAVE             = 5
	SQLITE_TESTCTRL_PRNG_SEED             = 28
	SQLITE_TESTCTRL_RESERVE               = 14
	SQLITE_TESTCTRL_RESULT_INTREAL        = 27
	SQLITE_TESTCTRL_SCRATCHMALLOC         = 17
	SQLITE_TESTCTRL_SEEK_COUNT            = 30
	SQLITE_TESTCTRL_SORTER_MMAP           = 24
	SQLITE_TESTCTRL_TRACEFLAGS            = 31
	SQLITE_TESTCTRL_TUNE                  = 32
	SQLITE_TESTCTRL_VDBE_COVERAGE         = 21
	SQLITE_TEXT                           = 3
	SQLITE_THREADSAFE                     = 1
	SQLITE_TOKEN_KEYWORD                  = 0x2
	SQLITE_TOKEN_QUOTED                   = 0x1
	SQLITE_TOOBIG                         = 18
	SQLITE_TRACE_CLOSE                    = 0x08
	SQLITE_TRACE_LEGACY                   = 0x40
	SQLITE_TRACE_NONLEGACY_MASK           = 0x0f
	SQLITE_TRACE_PROFILE                  = 0x02
	SQLITE_TRACE_ROW                      = 0x04
	SQLITE_TRACE_STMT                     = 0x01
	SQLITE_TRACE_XPROFILE                 = 0x80
	SQLITE_TRANSACTION                    = 22
	SQLITE_TXN_NONE                       = 0
	SQLITE_TXN_READ                       = 1
	SQLITE_TXN_WRITE                      = 2
	SQLITE_Transitive                     = 0x00000080
	SQLITE_TriggerEQP                     = 0x01000000
	SQLITE_TrustedSchema                  = 0x00000080
	SQLITE_UPDATE                         = 23
	SQLITE_USE_URI                        = 0
	SQLITE_UTF16                          = 4
	SQLITE_UTF16BE                        = 3
	SQLITE_UTF16LE                        = 2
	SQLITE_UTF16NATIVE                    = 2
	SQLITE_UTF16_ALIGNED                  = 8
	SQLITE_UTF8                           = 1
	SQLITE_VDBEINT_H                      = 0
	SQLITE_VDBE_H                         = 0
	SQLITE_VERSION                        = "3.41.2"
	SQLITE_VERSION_NUMBER                 = 3041002
	SQLITE_VTABRISK_High                  = 2
	SQLITE_VTABRISK_Low                   = 0
	SQLITE_VTABRISK_Normal                = 1
	SQLITE_VTAB_CONSTRAINT_SUPPORT        = 1
	SQLITE_VTAB_DIRECTONLY                = 3
	SQLITE_VTAB_INNOCUOUS                 = 2
	SQLITE_WAL_H                          = 0
	SQLITE_WARNING                        = 28
	SQLITE_WARNING_AUTOINDEX              = 284
	SQLITE_WHEREINT_H                     = 0
	SQLITE_WIN32_DATA_DIRECTORY_TYPE      = 1
	SQLITE_WIN32_TEMP_DIRECTORY_TYPE      = 2
	SQLITE_WSD                            = 0
	SQLITE_WindowFunc                     = 0x00000002
	SQLITE_WriteSchema                    = 0x00000001
	SRT_Coroutine                         = 13
	SRT_Discard                           = 4
	SRT_DistFifo                          = 5
	SRT_DistQueue                         = 6
	SRT_EphemTab                          = 12
	SRT_Except                            = 2
	SRT_Exists                            = 3
	SRT_Fifo                              = 8
	SRT_Mem                               = 10
	SRT_Output                            = 9
	SRT_Queue                             = 7
	SRT_Set                               = 11
	SRT_Table                             = 14
	SRT_Union                             = 1
	SRT_Upfrom                            = 15
	STATX_ALL                             = 0x00000fff
	STATX_ATIME                           = 0x00000020
	STATX_ATTR_APPEND                     = 0x00000020
	STATX_ATTR_AUTOMOUNT                  = 0x00001000
	STATX_ATTR_COMPRESSED                 = 0x00000004
	STATX_ATTR_DAX                        = 0x00200000
	STATX_ATTR_ENCRYPTED                  = 0x00000800
	STATX_ATTR_IMMUTABLE                  = 0x00000010
	STATX_ATTR_MOUNT_ROOT                 = 0x00002000
	STATX_ATTR_NODUMP                     = 0x00000040
	STATX_ATTR_VERITY                     = 0x00100000
	STATX_BASIC_STATS                     = 0x000007ff
	STATX_BLOCKS                          = 0x00000400
	STATX_BTIME                           = 0x00000800
	STATX_CTIME                           = 0x00000080
	STATX_GID                             = 0x00000010
	STATX_INO                             = 0x00000100
	STATX_MNT_ID                          = 0x00001000
	STATX_MODE                            = 0x00000002
	STATX_MTIME                           = 0x00000040
	STATX_NLINK                           = 0x00000004
	STATX_SIZE                            = 0x00000200
	STATX_TYPE                            = 0x00000001
	STATX_UID                             = 0x00000008
	STATX__RESERVED                       = 0x80000000
	STAT_GET_NDLT                         = 4
	STAT_GET_NEQ                          = 2
	STAT_GET_NLT                          = 3
	STAT_GET_ROWID                        = 1
	STAT_GET_STAT1                        = 0
	STA_CLK                               = 0x8000
	STA_CLOCKERR                          = 0x1000
	STA_DEL                               = 0x0020
	STA_FLL                               = 0x0008
	STA_FREQHOLD                          = 0x0080
	STA_INS                               = 0x0010
	STA_MODE                              = 0x4000
	STA_NANO                              = 0x2000
	STA_PLL                               = 0x0001
	STA_PPSERROR                          = 0x0800
	STA_PPSFREQ                           = 0x0002
	STA_PPSJITTER                         = 0x0200
	STA_PPSSIGNAL                         = 0x0100
	STA_PPSTIME                           = 0x0004
	STA_PPSWANDER                         = 0x0400
	STA_RONLY                             = 65280
	STA_UNSYNC                            = 0x0040
	STDERR_FILENO                         = 2
	STDIN_FILENO                          = 0
	STDOUT_FILENO                         = 1
	STMT_COLUMN_BUSY                      = 3
	STMT_COLUMN_MEM                       = 10
	STMT_COLUMN_NAIDX                     = 6
	STMT_COLUMN_NCOL                      = 1
	STMT_COLUMN_NSCAN                     = 4
	STMT_COLUMN_NSORT                     = 5
	STMT_COLUMN_NSTEP                     = 7
	STMT_COLUMN_REPREP                    = 8
	STMT_COLUMN_RO                        = 2
	STMT_COLUMN_RUN                       = 9
	STMT_COLUMN_SQL                       = 0
	STMT_NUM_INTEGER_COLUMN               = 10
	SYNC_FILE_RANGE_WAIT_AFTER            = 4
	SYNC_FILE_RANGE_WAIT_BEFORE           = 1
	SYNC_FILE_RANGE_WRITE                 = 2
	SYNC_FILE_RANGE_WRITE_AND_WAIT        = 7
	S_BLKSIZE                             = 512
	S_IEXEC                               = 64
	S_IFBLK                               = 24576
	S_IFCHR                               = 8192
	S_IFDIR                               = 16384
	S_IFIFO                               = 4096
	S_IFLNK                               = 40960
	S_IFMT                                = 61440
	S_IFREG                               = 32768
	S_IFSOCK                              = 49152
	S_IREAD                               = 256
	S_IRGRP                               = 32
	S_IROTH                               = 4
	S_IRUSR                               = 256
	S_IRWXG                               = 56
	S_IRWXO                               = 7
	S_IRWXU                               = 448
	S_ISGID                               = 1024
	S_ISUID                               = 2048
	S_ISVTX                               = 512
	S_IWGRP                               = 16
	S_IWOTH                               = 2
	S_IWRITE                              = 128
	S_IWUSR                               = 128
	S_IXGRP                               = 8
	S_IXOTH                               = 1
	S_IXUSR                               = 64
	TABTYP_NORM                           = 0
	TABTYP_VIEW                           = 2
	TABTYP_VTAB                           = 1
	TCFLSH                                = 0x540B
	TCGETA                                = 0x5405
	TCGETS                                = 0x5401
	TCGETX                                = 0x5432
	TCSBRK                                = 0x5409
	TCSBRKP                               = 0x5425
	TCSETA                                = 0x5406
	TCSETAF                               = 0x5408
	TCSETAW                               = 0x5407
	TCSETS                                = 0x5402
	TCSETSF                               = 0x5404
	TCSETSW                               = 0x5403
	TCSETX                                = 0x5433
	TCSETXF                               = 0x5434
	TCSETXW                               = 0x5435
	TCXONC                                = 0x540A
	TERM_ANDINFO                          = 0x0020
	TERM_CODED                            = 0x0004
	TERM_COPIED                           = 0x0008
	TERM_DYNAMIC                          = 0x0001
	TERM_HEURTRUTH                        = 0x2000
	TERM_HIGHTRUTH                        = 0x4000
	TERM_IS                               = 0x0800
	TERM_LIKE                             = 0x0400
	TERM_LIKECOND                         = 0x0200
	TERM_LIKEOPT                          = 0x0100
	TERM_OK                               = 0x0040
	TERM_ORINFO                           = 0x0010
	TERM_SLICE                            = 0x8000
	TERM_VARSELECT                        = 0x1000
	TERM_VIRTUAL                          = 0x0002
	TERM_VNULL                            = 0x0080
	TF_Autoincrement                      = 0x00000008
	TF_Ephemeral                          = 0x00004000
	TF_Eponymous                          = 0x00008000
	TF_HasGenerated                       = 0x00000060
	TF_HasHidden                          = 0x00000002
	TF_HasNotNull                         = 0x00000800
	TF_HasPrimaryKey                      = 0x00000004
	TF_HasStat1                           = 0x00000010
	TF_HasStat4                           = 0x00002000
	TF_HasStored                          = 0x00000040
	TF_HasVirtual                         = 0x00000020
	TF_NoVisibleRowid                     = 0x00000200
	TF_OOOHidden                          = 0x00000400
	TF_Readonly                           = 0x00000001
	TF_Shadow                             = 0x00001000
	TF_StatsUsed                          = 0x00000100
	TF_Strict                             = 0x00010000
	TF_WithoutRowid                       = 0x00000080
	TIMER_ABSTIME                         = 1
	TIMER_END                             = 0
	TIMER_START                           = 0
	TIME_UTC                              = 1
	TIOCCBRK                              = 0x5428
	TIOCCONS                              = 0x541D
	TIOCEXCL                              = 0x540C
	TIOCGETD                              = 0x5424
	TIOCGICOUNT                           = 0x545D
	TIOCGLCKTRMIOS                        = 0x5456
	TIOCGPGRP                             = 0x540F
	TIOCGPTPEER                           = 21569
	TIOCGRS485                            = 0x542E
	TIOCGSERIAL                           = 0x541E
	TIOCGSID                              = 0x5429
	TIOCGSOFTCAR                          = 0x5419
	TIOCGWINSZ                            = 0x5413
	TIOCINQ                               = 21531
	TIOCLINUX                             = 0x541C
	TIOCMBIC                              = 0x5417
	TIOCMBIS                              = 0x5416
	TIOCMGET                              = 0x5415
	TIOCMIWAIT                            = 0x545C
	TIOCMSET                              = 0x5418
	TIOCM_CAR                             = 0x040
	TIOCM_CD                              = 64
	TIOCM_CTS                             = 0x020
	TIOCM_DSR                             = 0x100
	TIOCM_DTR                             = 0x002
	TIOCM_LE                              = 0x001
	TIOCM_RI                              = 128
	TIOCM_RNG                             = 0x080
	TIOCM_RTS                             = 0x004
	TIOCM_SR                              = 0x010
	TIOCM_ST                              = 0x008
	TIOCNOTTY                             = 0x5422
	TIOCNXCL                              = 0x540D
	TIOCOUTQ                              = 0x5411
	TIOCPKT                               = 0x5420
	TIOCPKT_DATA                          = 0
	TIOCPKT_DOSTOP                        = 32
	TIOCPKT_FLUSHREAD                     = 1
	TIOCPKT_FLUSHWRITE                    = 2
	TIOCPKT_IOCTL                         = 64
	TIOCPKT_NOSTOP                        = 16
	TIOCPKT_START                         = 8
	TIOCPKT_STOP                          = 4
	TIOCSBRK                              = 0x5427
	TIOCSCTTY                             = 0x540E
	TIOCSERCONFIG                         = 0x5453
	TIOCSERGETLSR                         = 0x5459
	TIOCSERGETMULTI                       = 0x545A
	TIOCSERGSTRUCT                        = 0x5458
	TIOCSERGWILD                          = 0x5454
	TIOCSERSETMULTI                       = 0x545B
	TIOCSERSWILD                          = 0x5455
	TIOCSER_TEMT                          = 0x01
	TIOCSETD                              = 0x5423
	TIOCSLCKTRMIOS                        = 0x5457
	TIOCSPGRP                             = 0x5410
	TIOCSRS485                            = 0x542F
	TIOCSSERIAL                           = 0x541F
	TIOCSSOFTCAR                          = 0x541A
	TIOCSTI                               = 0x5412
	TIOCSWINSZ                            = 0x5414
	TIOCVHANGUP                           = 0x5437
	TK_ABORT                              = 27
	TK_ACTION                             = 28
	TK_ADD                                = 163
	TK_AFTER                              = 29
	TK_AGG_COLUMN                         = 169
	TK_AGG_FUNCTION                       = 168
	TK_ALL                                = 135
	TK_ALTER                              = 162
	TK_ALWAYS                             = 96
	TK_ANALYZE                            = 30
	TK_AND                                = 44
	TK_ANY                                = 101
	TK_AS                                 = 24
	TK_ASC                                = 31
	TK_ASTERISK                           = 180
	TK_ATTACH                             = 32
	TK_AUTOINCR                           = 126
	TK_BEFORE                             = 33
	TK_BEGIN                              = 5
	TK_BETWEEN                            = 48
	TK_BITAND                             = 102
	TK_BITNOT                             = 114
	TK_BITOR                              = 103
	TK_BLOB                               = 154
	TK_BY                                 = 34
	TK_CASCADE                            = 35
	TK_CASE                               = 157
	TK_CAST                               = 36
	TK_CHECK                              = 124
	TK_COLLATE                            = 113
	TK_COLUMN                             = 167
	TK_COLUMNKW                           = 60
	TK_COMMA                              = 25
	TK_COMMIT                             = 10
	TK_CONCAT                             = 111
	TK_CONFLICT                           = 37
	TK_CONSTRAINT                         = 119
	TK_CREATE                             = 17
	TK_CTIME_KW                           = 100
	TK_CURRENT                            = 85
	TK_DATABASE                           = 38
	TK_DEFAULT                            = 120
	TK_DEFERRABLE                         = 131
	TK_DEFERRED                           = 7
	TK_DELETE                             = 128
	TK_DESC                               = 39
	TK_DETACH                             = 40
	TK_DISTINCT                           = 140
	TK_DO                                 = 61
	TK_DOT                                = 141
	TK_DROP                               = 133
	TK_EACH                               = 41
	TK_ELSE                               = 160
	TK_END                                = 11
	TK_EQ                                 = 53
	TK_ERROR                              = 182
	TK_ESCAPE                             = 58
	TK_EXCEPT                             = 136
	TK_EXCLUDE                            = 91
	TK_EXCLUSIVE                          = 9
	TK_EXISTS                             = 20
	TK_EXPLAIN                            = 2
	TK_FAIL                               = 42
	TK_FILTER                             = 166
	TK_FIRST                              = 83
	TK_FLOAT                              = 153
	TK_FOLLOWING                          = 86
	TK_FOR                                = 62
	TK_FOREIGN                            = 132
	TK_FROM                               = 142
	TK_FUNCTION                           = 172
	TK_GE                                 = 57
	TK_GENERATED                          = 95
	TK_GROUP                              = 146
	TK_GROUPS                             = 92
	TK_GT                                 = 54
	TK_HAVING                             = 147
	TK_ID                                 = 59
	TK_IF                                 = 18
	TK_IF_NULL_ROW                        = 179
	TK_IGNORE                             = 63
	TK_ILLEGAL                            = 184
	TK_IMMEDIATE                          = 8
	TK_IN                                 = 49
	TK_INDEX                              = 161
	TK_INDEXED                            = 116
	TK_INITIALLY                          = 64
	TK_INSERT                             = 127
	TK_INSTEAD                            = 65
	TK_INTEGER                            = 155
	TK_INTERSECT                          = 137
	TK_INTO                               = 151
	TK_IS                                 = 45
	TK_ISNOT                              = 171
	TK_ISNULL                             = 50
	TK_JOIN                               = 143
	TK_JOIN_KW                            = 118
	TK_KEY                                = 67
	TK_LAST                               = 84
	TK_LE                                 = 55
	TK_LIKE_KW                            = 47
	TK_LIMIT                              = 148
	TK_LP                                 = 22
	TK_LSHIFT                             = 104
	TK_LT                                 = 56
	TK_MATCH                              = 46
	TK_MATERIALIZED                       = 97
	TK_MINUS                              = 107
	TK_NE                                 = 52
	TK_NO                                 = 66
	TK_NOT                                = 19
	TK_NOTHING                            = 152
	TK_NOTNULL                            = 51
	TK_NULL                               = 121
	TK_NULLS                              = 82
	TK_OF                                 = 68
	TK_OFFSET                             = 69
	TK_ON                                 = 115
	TK_OR                                 = 43
	TK_ORDER                              = 145
	TK_OTHERS                             = 93
	TK_OVER                               = 165
	TK_PARTITION                          = 87
	TK_PLAN                               = 4
	TK_PLUS                               = 106
	TK_PRAGMA                             = 70
	TK_PRECEDING                          = 88
	TK_PRIMARY                            = 122
	TK_PTR                                = 112
	TK_QUERY                              = 3
	TK_RAISE                              = 71
	TK_RANGE                              = 89
	TK_RECURSIVE                          = 72
	TK_REFERENCES                         = 125
	TK_REGISTER                           = 176
	TK_REINDEX                            = 98
	TK_RELEASE                            = 14
	TK_REM                                = 110
	TK_RENAME                             = 99
	TK_REPLACE                            = 73
	TK_RESTRICT                           = 74
	TK_RETURNING                          = 150
	TK_ROLLBACK                           = 12
	TK_ROW                                = 75
	TK_ROWS                               = 76
	TK_RP                                 = 23
	TK_RSHIFT                             = 105
	TK_SAVEPOINT                          = 13
	TK_SELECT                             = 138
	TK_SELECT_COLUMN                      = 178
	TK_SEMI                               = 1
	TK_SET                                = 130
	TK_SLASH                              = 109
	TK_SPACE                              = 183
	TK_SPAN                               = 181
	TK_STAR                               = 108
	TK_STRING                             = 117
	TK_TABLE                              = 16
	TK_TEMP                               = 21
	TK_THEN                               = 159
	TK_TIES                               = 94
	TK_TO                                 = 15
	TK_TRANSACTION                        = 6
	TK_TRIGGER                            = 77
	TK_TRUEFALSE                          = 170
	TK_TRUTH                              = 175
	TK_UMINUS                             = 173
	TK_UNBOUNDED                          = 90
	TK_UNION                              = 134
	TK_UNIQUE                             = 123
	TK_UPDATE                             = 129
	TK_UPLUS                              = 174
	TK_USING                              = 144
	TK_VACUUM                             = 78
	TK_VALUES                             = 139
	TK_VARIABLE                           = 156
	TK_VECTOR                             = 177
	TK_VIEW                               = 79
	TK_VIRTUAL                            = 80
	TK_WHEN                               = 158
	TK_WHERE                              = 149
	TK_WINDOW                             = 164
	TK_WITH                               = 81
	TK_WITHOUT                            = 26
	TMP_MAX                               = 238328
	TRANS_NONE                            = 0
	TRANS_READ                            = 1
	TRANS_WRITE                           = 2
	TREETRACE_ENABLED                     = 0
	TRIGGER_AFTER                         = 2
	TRIGGER_BEFORE                        = 1
	UNIXFILE_DELETE                       = 0x20
	UNIXFILE_DIRSYNC                      = 0x08
	UNIXFILE_EXCL                         = 0x01
	UNIXFILE_NOLOCK                       = 0x80
	UNIXFILE_PERSIST_WAL                  = 0x04
	UNIXFILE_PSOW                         = 0x10
	UNIXFILE_RDONLY                       = 0x02
	UNIXFILE_URI                          = 0x40
	UNIX_SHM_BASE                         = 120
	UNIX_SHM_DMS                          = 128
	UNKNOWN_LOCK                          = 5
	UTIME_NOW                             = 1073741823
	UTIME_OMIT                            = 1073741822
	VDBE_DISPLAY_P4                       = 1
	VDBE_HALT_STATE                       = 3
	VDBE_INIT_STATE                       = 0
	VDBE_READY_STATE                      = 1
	VDBE_RUN_STATE                        = 2
	WALINDEX_MAX_VERSION                  = 3007000
	WAL_ALL_BUT_WRITE                     = 1
	WAL_CKPT_LOCK                         = 1
	WAL_EXCLUSIVE_MODE                    = 1
	WAL_FRAME_HDRSIZE                     = 24
	WAL_HDRSIZE                           = 32
	WAL_HEAPMEMORY_MODE                   = 2
	WAL_LOCK_CKPT                         = 1
	WAL_LOCK_READ0                        = 3
	WAL_LOCK_WRITE                        = 0
	WAL_MAGIC                             = 0x377f0682
	WAL_MAX_VERSION                       = 3007000
	WAL_NORMAL_MODE                       = 0
	WAL_NREADER                           = 5
	WAL_RDONLY                            = 1
	WAL_RDWR                              = 0
	WAL_RECOVER_LOCK                      = 2
	WAL_RETRY                             = -1
	WAL_SAVEPOINT_NDATA                   = 4
	WAL_SHM_RDONLY                        = 2
	WAL_WRITE_LOCK                        = 0
	WCONTINUED                            = 8
	WEXITED                               = 4
	WHERE_AGG_DISTINCT                    = 0x0400
	WHERE_AUTO_INDEX                      = 0x00004000
	WHERE_BIGNULL_SORT                    = 0x00080000
	WHERE_BLOOMFILTER                     = 0x00400000
	WHERE_BOTH_LIMIT                      = 0x00000030
	WHERE_BTM_LIMIT                       = 0x00000020
	WHERE_COLUMN_EQ                       = 0x00000001
	WHERE_COLUMN_IN                       = 0x00000004
	WHERE_COLUMN_NULL                     = 0x00000008
	WHERE_COLUMN_RANGE                    = 0x00000002
	WHERE_CONSTRAINT                      = 0x0000000f
	WHERE_DISTINCTBY                      = 0x0080
	WHERE_DISTINCT_NOOP                   = 0
	WHERE_DISTINCT_ORDERED                = 2
	WHERE_DISTINCT_UNIQUE                 = 1
	WHERE_DISTINCT_UNORDERED              = 3
	WHERE_DUPLICATES_OK                   = 0x0010
	WHERE_EXPRIDX                         = 0x04000000
	WHERE_GROUPBY                         = 0x0040
	WHERE_IDX_ONLY                        = 0x00000040
	WHERE_INDEXED                         = 0x00000200
	WHERE_IN_ABLE                         = 0x00000800
	WHERE_IN_EARLYOUT                     = 0x00040000
	WHERE_IN_SEEKSCAN                     = 0x00100000
	WHERE_IPK                             = 0x00000100
	WHERE_MULTI_OR                        = 0x00002000
	WHERE_OMIT_OFFSET                     = 0x01000000
	WHERE_ONEPASS_DESIRED                 = 0x0004
	WHERE_ONEPASS_MULTIROW                = 0x0008
	WHERE_ONEROW                          = 0x00001000
	WHERE_ORDERBY_LIMIT                   = 0x0800
	WHERE_ORDERBY_MAX                     = 0x0002
	WHERE_ORDERBY_MIN                     = 0x0001
	WHERE_ORDERBY_NORMAL                  = 0x0000
	WHERE_OR_SUBCLAUSE                    = 0x0020
	WHERE_PARTIALIDX                      = 0x00020000
	WHERE_RIGHT_JOIN                      = 0x1000
	WHERE_SELFCULL                        = 0x00800000
	WHERE_SKIPSCAN                        = 0x00008000
	WHERE_SORTBYGROUP                     = 0x0200
	WHERE_TOP_LIMIT                       = 0x00000010
	WHERE_TRANSCONS                       = 0x00200000
	WHERE_UNQ_WANTED                      = 0x00010000
	WHERE_USE_LIMIT                       = 0x4000
	WHERE_VIEWSCAN                        = 0x02000000
	WHERE_VIRTUALTABLE                    = 0x00000400
	WHERE_WANT_DISTINCT                   = 0x0100
	WINDOW_AGGINVERSE                     = 2
	WINDOW_AGGSTEP                        = 3
	WINDOW_ENDING_INT                     = 1
	WINDOW_ENDING_NUM                     = 4
	WINDOW_NTH_VALUE_INT                  = 2
	WINDOW_RETURN_ROW                     = 1
	WINDOW_STARTING_INT                   = 0
	WINDOW_STARTING_NUM                   = 3
	WNOHANG                               = 1
	WNOWAIT                               = 0x01000000
	WO_ALL                                = 0x3fff
	WO_AND                                = 0x0400
	WO_AUX                                = 0x0040
	WO_EQ                                 = 0x0002
	WO_EQUIV                              = 0x0800
	WO_GE                                 = 32
	WO_GT                                 = 4
	WO_IN                                 = 0x0001
	WO_IS                                 = 0x0080
	WO_ISNULL                             = 0x0100
	WO_LE                                 = 8
	WO_LT                                 = 16
	WO_NOOP                               = 0x1000
	WO_OR                                 = 0x0200
	WO_ROWVAL                             = 0x2000
	WO_SINGLE                             = 0x01ff
	WRC_Abort                             = 2
	WRC_Continue                          = 0
	WRC_Prune                             = 1
	WRITE_LOCK                            = 2
	WSTOPPED                              = 2
	WUNTRACED                             = 2
	W_OK                                  = 2
	XN_EXPR                               = -2
	XN_ROWID                              = -1
	X_OK                                  = 1
	YYFALLBACK                            = 1
	YYNOCODE                              = 319
	YYNOERRORRECOVERY                     = 1
	YYNRULE                               = 405
	YYNRULE_WITH_ACTION                   = 342
	YYNSTATE                              = 576
	YYNTOKEN                              = 185
	YYPARSEFREENEVERNULL                  = 1
	YYSTACKDEPTH                          = 100
	YYWILDCARD                            = 101
	YY_ACCEPT_ACTION                      = 1241
	YY_ACTTAB_COUNT                       = 2098
	YY_ERROR_ACTION                       = 1240
	YY_MAX_REDUCE                         = 1647
	YY_MAX_SHIFT                          = 575
	YY_MAX_SHIFTREDUCE                    = 1239
	YY_MIN_REDUCE                         = 1243
	YY_MIN_SHIFTREDUCE                    = 835
	YY_NO_ACTION                          = 1242
	YY_REDUCE_COUNT                       = 408
	YY_REDUCE_MAX                         = 1740
	YY_REDUCE_MIN                         = -271
	YY_SHIFT_COUNT                        = 575
	YY_SHIFT_MAX                          = 2074
	YY_SHIFT_MIN                          = 0
	X_ALLOCA_H                            = 1
	X_ANSI_STDARG_H_                      = 0
	X_ANSI_STDDEF_H                       = 0
	X_ASM_GENERIC_ERRNO_BASE_H            = 0
	X_ASM_GENERIC_ERRNO_H                 = 0
	X_ASM_GENERIC_INT_LL64_H              = 0
	X_ASM_GENERIC_IOCTL_H                 = 0
	X_ASM_GENERIC_TYPES_H                 = 0
	X_ASSERT_H                            = 1
	X_ATFILE_SOURCE                       = 1
	X_BITS_BYTESWAP_H                     = 1
	X_BITS_ENDIANNESS_H                   = 1
	X_BITS_ENDIAN_H                       = 1
	X_BITS_ERRNO_H                        = 1
	X_BITS_FLOATN_COMMON_H                = 0
	X_BITS_FLOATN_H                       = 0
	X_BITS_LIBM_SIMD_DECL_STUBS_H         = 1
	X_BITS_POSIX_OPT_H                    = 1
	X_BITS_PTHREADTYPES_ARCH_H            = 1
	X_BITS_PTHREADTYPES_COMMON_H          = 1
	X_BITS_STAT_H                         = 1
	X_BITS_STDINT_INTN_H                  = 1
	X_BITS_STDIO_LIM_H                    = 1
	X_BITS_TIME64_H                       = 1
	X_BITS_TIMEX_H                        = 1
	X_BITS_TIME_H                         = 1
	X_BITS_TYPESIZES_H                    = 1
	X_BITS_TYPES_H                        = 1
	X_BITS_TYPES_LOCALE_T_H               = 1
	X_BITS_TYPES___LOCALE_T_H             = 1
	X_BITS_UINTN_IDENTITY_H               = 1
	X_BSD_PTRDIFF_T_                      = 0
	X_BSD_SIZE_T_                         = 0
	X_BSD_SIZE_T_DEFINED_                 = 0
	X_DEFAULT_SOURCE                      = 1
	X_DLFCN_H                             = 1
	X_ENDIAN_H                            = 1
	X_ERRNO_H                             = 1
	X_FALLOC_H_                           = 0
	X_FCNTL_H                             = 1
	X_FEATURES_H                          = 1
	X_FILE_OFFSET_BITS                    = 64
	X_FTS5INT_H                           = 0
	X_FTS5_H                              = 0
	X_FTSINT_H                            = 0
	X_GCC_MAX_ALIGN_T                     = 0
	X_GCC_PTRDIFF_T                       = 0
	X_GCC_SIZE_T                          = 0
	X_GCC_WCHAR_T                         = 0
	X_GETOPT_CORE_H                       = 1
	X_GETOPT_POSIX_H                      = 1
	X_GNU_SOURCE                          = 0
	X_IOC_DIRBITS                         = 2
	X_IOC_DIRMASK                         = 3
	X_IOC_DIRSHIFT                        = 30
	X_IOC_NONE                            = 0
	X_IOC_NRBITS                          = 8
	X_IOC_NRMASK                          = 255
	X_IOC_NRSHIFT                         = 0
	X_IOC_READ                            = 2
	X_IOC_SIZEBITS                        = 14
	X_IOC_SIZEMASK                        = 16383
	X_IOC_SIZESHIFT                       = 16
	X_IOC_TYPEBITS                        = 8
	X_IOC_TYPEMASK                        = 255
	X_IOC_TYPESHIFT                       = 8
	X_IOC_WRITE                           = 1
	X_IOFBF                               = 0
	X_IOLBF                               = 1
	X_IONBF                               = 2
	X_IO_EOF_SEEN                         = 0x0010
	X_IO_ERR_SEEN                         = 0x0020
	X_IO_USER_LOCK                        = 0x8000
	X_ISOC11_SOURCE                       = 1
	X_ISOC2X_SOURCE                       = 1
	X_ISOC95_SOURCE                       = 1
	X_ISOC99_SOURCE                       = 1
	X_LARGEFILE64_SOURCE                  = 1
	X_LARGEFILE_SOURCE                    = 1
	X_LARGE_FILE                          = 1
	X_LFS64_ASYNCHRONOUS_IO               = 1
	X_LFS64_LARGEFILE                     = 1
	X_LFS64_STDIO                         = 1
	X_LFS_ASYNCHRONOUS_IO                 = 1
	X_LFS_LARGEFILE                       = 1
	X_LINUX_IOCTL_H                       = 0
	X_LINUX_POSIX_TYPES_H                 = 0
	X_LINUX_STAT_H                        = 0
	X_LINUX_TYPES_H                       = 0
	X_LP64                                = 1
	X_MATH_H                              = 1
	X_MKNOD_VER                           = 0
	X_MKNOD_VER_LINUX                     = 0
	X_OS_COMMON_H_                        = 0
	X_POSIX2_CHAR_TERM                    = 200809
	X_POSIX2_C_BIND                       = 200809
	X_POSIX2_C_DEV                        = 200809
	X_POSIX2_C_VERSION                    = 200809
	X_POSIX2_LOCALEDEF                    = 200809
	X_POSIX2_SW_DEV                       = 200809
	X_POSIX2_VERSION                      = 200809
	X_POSIX_ADVISORY_INFO                 = 200809
	X_POSIX_ASYNCHRONOUS_IO               = 200809
	X_POSIX_ASYNC_IO                      = 1
	X_POSIX_BARRIERS                      = 200809
	X_POSIX_CHOWN_RESTRICTED              = 0
	X_POSIX_CLOCK_SELECTION               = 200809
	X_POSIX_CPUTIME                       = 0
	X_POSIX_C_SOURCE                      = 200809
	X_POSIX_FSYNC                         = 200809
	X_POSIX_IPV6                          = 200809
	X_POSIX_JOB_CONTROL                   = 1
	X_POSIX_MAPPED_FILES                  = 200809
	X_POSIX_MEMLOCK                       = 200809
	X_POSIX_MEMLOCK_RANGE                 = 200809
	X_POSIX_MEMORY_PROTECTION             = 200809
	X_POSIX_MESSAGE_PASSING               = 200809
	X_POSIX_MONOTONIC_CLOCK               = 0
	X_POSIX_NO_TRUNC                      = 1
	X_POSIX_PRIORITIZED_IO                = 200809
	X_POSIX_PRIORITY_SCHEDULING           = 200809
	X_POSIX_RAW_SOCKETS                   = 200809
	X_POSIX_READER_WRITER_LOCKS           = 200809
	X_POSIX_REALTIME_SIGNALS              = 200809
	X_POSIX_REENTRANT_FUNCTIONS           = 1
	X_POSIX_REGEXP                        = 1
	X_POSIX_SAVED_IDS                     = 1
	X_POSIX_SEMAPHORES                    = 200809
	X_POSIX_SHARED_MEMORY_OBJECTS         = 200809
	X_POSIX_SHELL                         = 1
	X_POSIX_SOURCE                        = 1
	X_POSIX_SPAWN                         = 200809
	X_POSIX_SPIN_LOCKS                    = 200809
	X_POSIX_SPORADIC_SERVER               = -1
	X_POSIX_SYNCHRONIZED_IO               = 200809
	X_POSIX_THREADS                       = 200809
	X_POSIX_THREAD_ATTR_STACKADDR         = 200809
	X_POSIX_THREAD_ATTR_STACKSIZE         = 200809
	X_POSIX_THREAD_CPUTIME                = 0
	X_POSIX_THREAD_PRIORITY_SCHEDULING    = 200809
	X_POSIX_THREAD_PRIO_INHERIT           = 200809
	X_POSIX_THREAD_PRIO_PROTECT           = 200809
	X_POSIX_THREAD_PROCESS_SHARED         = 200809
	X_POSIX_THREAD_ROBUST_PRIO_INHERIT    = 200809
	X_POSIX_THREAD_ROBUST_PRIO_PROTECT    = -1
	X_POSIX_THREAD_SAFE_FUNCTIONS         = 200809
	X_POSIX_THREAD_SPORADIC_SERVER        = -1
	X_POSIX_TIMEOUTS                      = 200809
	X_POSIX_TIMERS                        = 200809
	X_POSIX_TRACE                         = -1
	X_POSIX_TRACE_EVENT_FILTER            = -1
	X_POSIX_TRACE_INHERIT                 = -1
	X_POSIX_TRACE_LOG                     = -1
	X_POSIX_TYPED_MEMORY_OBJECTS          = -1
	X_POSIX_V6_ILP32_OFF32                = -1
	X_POSIX_V6_ILP32_OFFBIG               = -1
	X_POSIX_V6_LP64_OFF64                 = 1
	X_POSIX_V6_LPBIG_OFFBIG               = -1
	X_POSIX_V7_ILP32_OFF32                = -1
	X_POSIX_V7_ILP32_OFFBIG               = -1
	X_POSIX_V7_LP64_OFF64                 = 1
	X_POSIX_V7_LPBIG_OFFBIG               = -1
	X_POSIX_VDISABLE                      = 0
	X_POSIX_VERSION                       = 200809
	X_PTRDIFF_T                           = 0
	X_PTRDIFF_T_                          = 0
	X_PTRDIFF_T_DECLARED                  = 0
	X_RWLOCK_INTERNAL_H                   = 0
	X_SIZET_                              = 0
	X_SIZE_T                              = 0
	X_SIZE_T_                             = 0
	X_SIZE_T_DECLARED                     = 0
	X_SIZE_T_DEFINED                      = 0
	X_SIZE_T_DEFINED_                     = 0
	X_SQLITE3RBU_H                        = 0
	X_SQLITE3RTREE_H_                     = 0
	X_SQLITE_OS_H_                        = 0
	X_STATBUF_ST_BLKSIZE                  = 0
	X_STATBUF_ST_NSEC                     = 0
	X_STATBUF_ST_RDEV                     = 0
	X_STAT_VER                            = 0
	X_STAT_VER_KERNEL                     = 0
	X_STAT_VER_LINUX                      = 0
	X_STDARG_H                            = 0
	X_STDC_PREDEF_H                       = 1
	X_STDDEF_H                            = 0
	X_STDDEF_H_                           = 0
	X_STDIO_H                             = 1
	X_STDLIB_H                            = 1
	X_STRINGS_H                           = 1
	X_STRING_H                            = 1
	X_STRUCT_TIMESPEC                     = 1
	X_SYS_CDEFS_H                         = 1
	X_SYS_IOCTL_H                         = 1
	X_SYS_MMAN_H                          = 1
	X_SYS_SELECT_H                        = 1
	X_SYS_SIZE_T_H                        = 0
	X_SYS_STAT_H                          = 1
	X_SYS_TIME_H                          = 1
	X_SYS_TTYDEFAULTS_H_                  = 0
	X_SYS_TYPES_H                         = 1
	X_THREAD_MUTEX_INTERNAL_H             = 1
	X_THREAD_SHARED_TYPES_H               = 1
	X_TIME_H                              = 1
	X_T_PTRDIFF                           = 0
	X_T_PTRDIFF_                          = 0
	X_T_SIZE                              = 0
	X_T_SIZE_                             = 0
	X_T_WCHAR                             = 0
	X_T_WCHAR_                            = 0
	X_UNISTD_H                            = 1
	X_VA_LIST                             = 0
	X_VA_LIST_                            = 0
	X_VA_LIST_DEFINED                     = 0
	X_VA_LIST_T_H                         = 0
	X_WCHAR_T                             = 0
	X_WCHAR_T_                            = 0
	X_WCHAR_T_DECLARED                    = 0
	X_WCHAR_T_DEFINED                     = 0
	X_WCHAR_T_DEFINED_                    = 0
	X_WCHAR_T_H                           = 0
	X_XBS5_ILP32_OFF32                    = -1
	X_XBS5_ILP32_OFFBIG                   = -1
	X_XBS5_LP64_OFF64                     = 1
	X_XBS5_LPBIG_OFFBIG                   = -1
	X_XOPEN_ENH_I18N                      = 1
	X_XOPEN_LEGACY                        = 1
	X_XOPEN_REALTIME                      = 1
	X_XOPEN_REALTIME_THREADS              = 1
	X_XOPEN_SHM                           = 1
	X_XOPEN_SOURCE                        = 700
	X_XOPEN_SOURCE_EXTENDED               = 1
	X_XOPEN_UNIX                          = 1
	X_XOPEN_VERSION                       = 700
	X_XOPEN_XCU_VERSION                   = 4
	X_XOPEN_XPG2                          = 1
	X_XOPEN_XPG3                          = 1
	X_XOPEN_XPG4                          = 1
	BBatch                                = 0
	EtBUFSIZE                             = 70
	EtCHARX                               = 8
	EtDECIMAL                             = 16
	EtDYNSTRING                           = 6
	EtEXP                                 = 2
	EtFLOAT                               = 1
	EtGENERIC                             = 3
	EtINVALID                             = 17
	EtORDINAL                             = 15
	EtPERCENT                             = 7
	EtPOINTER                             = 13
	EtRADIX                               = 0
	EtSIZE                                = 4
	EtSQLESCAPE                           = 9
	EtSQLESCAPE2                          = 10
	EtSQLESCAPE3                          = 14
	EtSRCITEM                             = 12
	EtSTRING                              = 5
	EtTOKEN                               = 11
	Fts5YYNFTS5TOKEN                      = 16
	Fts5YYNOCODE                          = 27
	Fts5YYNOERRORRECOVERY                 = 1
	Fts5YYNRULE                           = 28
	Fts5YYNRULE_WITH_ACTION               = 28
	Fts5YYNSTATE                          = 35
	Fts5YYPARSEFREENOTNULL                = 1
	Fts5YYSTACKDEPTH                      = 100
	Fts5YY_ACCEPT_ACTION                  = 81
	Fts5YY_ACTTAB_COUNT                   = 105
	Fts5YY_ERROR_ACTION                   = 80
	Fts5YY_MAX_REDUCE                     = 110
	Fts5YY_MAX_SHIFT                      = 34
	Fts5YY_MAX_SHIFTREDUCE                = 79
	Fts5YY_MIN_REDUCE                     = 83
	Fts5YY_MIN_SHIFTREDUCE                = 52
	Fts5YY_NO_ACTION                      = 82
	Fts5YY_REDUCE_COUNT                   = 17
	Fts5YY_REDUCE_MAX                     = 67
	Fts5YY_REDUCE_MIN                     = -17
	Fts5YY_SHIFT_COUNT                    = 34
	Fts5YY_SHIFT_MAX                      = 93
	Fts5YY_SHIFT_MIN                      = 0
	Linux                                 = 1
	Math_errhandling                      = 3
	Sqlite3Fts5ParserCTX_FETCH            = 0
	Sqlite3Fts5ParserCTX_PARAM            = 0
	Sqlite3Fts5ParserCTX_PDECL            = 0
	Sqlite3Fts5ParserCTX_SDECL            = 0
	Sqlite3Fts5ParserCTX_STORE            = 0
	Sqlite3ParserARG_FETCH                = 0
	Sqlite3ParserARG_PARAM                = 0
	Sqlite3ParserARG_PDECL                = 0
	Sqlite3ParserARG_SDECL                = 0
	Sqlite3ParserARG_STORE                = 0
	Sqlite3Parser_ENGINEALWAYSONSTACK     = 1
	TkCREATE                              = 4
	TkEND                                 = 7
	TkEXPLAIN                             = 3
	TkOTHER                               = 2
	TkSEMI                                = 0
	TkTEMP                                = 5
	TkTRIGGER                             = 6
	TkWS                                  = 1
	Unix                                  = 1
	WsdAutoextInit                        = 0
	WsdHooksInit                          = 0
	WsdStatInit                           = 0
)

const (
	X_PC_LINK_MAX           = 0
	X_PC_MAX_CANON          = 1
	X_PC_MAX_INPUT          = 2
	X_PC_NAME_MAX           = 3
	X_PC_PATH_MAX           = 4
	X_PC_PIPE_BUF           = 5
	X_PC_CHOWN_RESTRICTED   = 6
	X_PC_NO_TRUNC           = 7
	X_PC_VDISABLE           = 8
	X_PC_SYNC_IO            = 9
	X_PC_ASYNC_IO           = 10
	X_PC_PRIO_IO            = 11
	X_PC_SOCK_MAXBUF        = 12
	X_PC_FILESIZEBITS       = 13
	X_PC_REC_INCR_XFER_SIZE = 14
	X_PC_REC_MAX_XFER_SIZE  = 15
	X_PC_REC_MIN_XFER_SIZE  = 16
	X_PC_REC_XFER_ALIGN     = 17
	X_PC_ALLOC_SIZE_MIN     = 18
	X_PC_SYMLINK_MAX        = 19
	X_PC_2_SYMLINKS         = 20
)

const (
	X_CS_PATH = 0

	X_CS_V6_WIDTH_RESTRICTED_ENVS = 1

	X_CS_GNU_LIBC_VERSION       = 2
	X_CS_GNU_LIBPTHREAD_VERSION = 3

	X_CS_V5_WIDTH_RESTRICTED_ENVS = 4

	X_CS_V7_WIDTH_RESTRICTED_ENVS = 5

	X_CS_LFS_CFLAGS      = 1000
	X_CS_LFS_LDFLAGS     = 1001
	X_CS_LFS_LIBS        = 1002
	X_CS_LFS_LINTFLAGS   = 1003
	X_CS_LFS64_CFLAGS    = 1004
	X_CS_LFS64_LDFLAGS   = 1005
	X_CS_LFS64_LIBS      = 1006
	X_CS_LFS64_LINTFLAGS = 1007

	X_CS_XBS5_ILP32_OFF32_CFLAGS     = 1100
	X_CS_XBS5_ILP32_OFF32_LDFLAGS    = 1101
	X_CS_XBS5_ILP32_OFF32_LIBS       = 1102
	X_CS_XBS5_ILP32_OFF32_LINTFLAGS  = 1103
	X_CS_XBS5_ILP32_OFFBIG_CFLAGS    = 1104
	X_CS_XBS5_ILP32_OFFBIG_LDFLAGS   = 1105
	X_CS_XBS5_ILP32_OFFBIG_LIBS      = 1106
	X_CS_XBS5_ILP32_OFFBIG_LINTFLAGS = 1107
	X_CS_XBS5_LP64_OFF64_CFLAGS      = 1108
	X_CS_XBS5_LP64_OFF64_LDFLAGS     = 1109
	X_CS_XBS5_LP64_OFF64_LIBS        = 1110
	X_CS_XBS5_LP64_OFF64_LINTFLAGS   = 1111
	X_CS_XBS5_LPBIG_OFFBIG_CFLAGS    = 1112
	X_CS_XBS5_LPBIG_OFFBIG_LDFLAGS   = 1113
	X_CS_XBS5_LPBIG_OFFBIG_LIBS      = 1114
	X_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS = 1115

	X_CS_POSIX_V6_ILP32_OFF32_CFLAGS     = 1116
	X_CS_POSIX_V6_ILP32_OFF32_LDFLAGS    = 1117
	X_CS_POSIX_V6_ILP32_OFF32_LIBS       = 1118
	X_CS_POSIX_V6_ILP32_OFF32_LINTFLAGS  = 1119
	X_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS    = 1120
	X_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS   = 1121
	X_CS_POSIX_V6_ILP32_OFFBIG_LIBS      = 1122
	X_CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS = 1123
	X_CS_POSIX_V6_LP64_OFF64_CFLAGS      = 1124
	X_CS_POSIX_V6_LP64_OFF64_LDFLAGS     = 1125
	X_CS_POSIX_V6_LP64_OFF64_LIBS        = 1126
	X_CS_POSIX_V6_LP64_OFF64_LINTFLAGS   = 1127
	X_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS    = 1128
	X_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS   = 1129
	X_CS_POSIX_V6_LPBIG_OFFBIG_LIBS      = 1130
	X_CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS = 1131

	X_CS_POSIX_V7_ILP32_OFF32_CFLAGS     = 1132
	X_CS_POSIX_V7_ILP32_OFF32_LDFLAGS    = 1133
	X_CS_POSIX_V7_ILP32_OFF32_LIBS       = 1134
	X_CS_POSIX_V7_ILP32_OFF32_LINTFLAGS  = 1135
	X_CS_POSIX_V7_ILP32_OFFBIG_CFLAGS    = 1136
	X_CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS   = 1137
	X_CS_POSIX_V7_ILP32_OFFBIG_LIBS      = 1138
	X_CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS = 1139
	X_CS_POSIX_V7_LP64_OFF64_CFLAGS      = 1140
	X_CS_POSIX_V7_LP64_OFF64_LDFLAGS     = 1141
	X_CS_POSIX_V7_LP64_OFF64_LIBS        = 1142
	X_CS_POSIX_V7_LP64_OFF64_LINTFLAGS   = 1143
	X_CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS    = 1144
	X_CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS   = 1145
	X_CS_POSIX_V7_LPBIG_OFFBIG_LIBS      = 1146
	X_CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS = 1147

	X_CS_V6_ENV = 1148
	X_CS_V7_ENV = 1149
)

const (
	X_SC_ARG_MAX               = 0
	X_SC_CHILD_MAX             = 1
	X_SC_CLK_TCK               = 2
	X_SC_NGROUPS_MAX           = 3
	X_SC_OPEN_MAX              = 4
	X_SC_STREAM_MAX            = 5
	X_SC_TZNAME_MAX            = 6
	X_SC_JOB_CONTROL           = 7
	X_SC_SAVED_IDS             = 8
	X_SC_REALTIME_SIGNALS      = 9
	X_SC_PRIORITY_SCHEDULING   = 10
	X_SC_TIMERS                = 11
	X_SC_ASYNCHRONOUS_IO       = 12
	X_SC_PRIORITIZED_IO        = 13
	X_SC_SYNCHRONIZED_IO       = 14
	X_SC_FSYNC                 = 15
	X_SC_MAPPED_FILES          = 16
	X_SC_MEMLOCK               = 17
	X_SC_MEMLOCK_RANGE         = 18
	X_SC_MEMORY_PROTECTION     = 19
	X_SC_MESSAGE_PASSING       = 20
	X_SC_SEMAPHORES            = 21
	X_SC_SHARED_MEMORY_OBJECTS = 22
	X_SC_AIO_LISTIO_MAX        = 23
	X_SC_AIO_MAX               = 24
	X_SC_AIO_PRIO_DELTA_MAX    = 25
	X_SC_DELAYTIMER_MAX        = 26
	X_SC_MQ_OPEN_MAX           = 27
	X_SC_MQ_PRIO_MAX           = 28
	X_SC_VERSION               = 29
	X_SC_PAGESIZE              = 30
	X_SC_RTSIG_MAX             = 31
	X_SC_SEM_NSEMS_MAX         = 32
	X_SC_SEM_VALUE_MAX         = 33
	X_SC_SIGQUEUE_MAX          = 34
	X_SC_TIMER_MAX             = 35

	X_SC_BC_BASE_MAX        = 36
	X_SC_BC_DIM_MAX         = 37
	X_SC_BC_SCALE_MAX       = 38
	X_SC_BC_STRING_MAX      = 39
	X_SC_COLL_WEIGHTS_MAX   = 40
	X_SC_EQUIV_CLASS_MAX    = 41
	X_SC_EXPR_NEST_MAX      = 42
	X_SC_LINE_MAX           = 43
	X_SC_RE_DUP_MAX         = 44
	X_SC_CHARCLASS_NAME_MAX = 45

	X_SC_2_VERSION   = 46
	X_SC_2_C_BIND    = 47
	X_SC_2_C_DEV     = 48
	X_SC_2_FORT_DEV  = 49
	X_SC_2_FORT_RUN  = 50
	X_SC_2_SW_DEV    = 51
	X_SC_2_LOCALEDEF = 52

	X_SC_PII                 = 53
	X_SC_PII_XTI             = 54
	X_SC_PII_SOCKET          = 55
	X_SC_PII_INTERNET        = 56
	X_SC_PII_OSI             = 57
	X_SC_POLL                = 58
	X_SC_SELECT              = 59
	X_SC_UIO_MAXIOV          = 60
	X_SC_IOV_MAX             = 60
	X_SC_PII_INTERNET_STREAM = 61
	X_SC_PII_INTERNET_DGRAM  = 62
	X_SC_PII_OSI_COTS        = 63
	X_SC_PII_OSI_CLTS        = 64
	X_SC_PII_OSI_M           = 65
	X_SC_T_IOV_MAX           = 66

	X_SC_THREADS                      = 67
	X_SC_THREAD_SAFE_FUNCTIONS        = 68
	X_SC_GETGR_R_SIZE_MAX             = 69
	X_SC_GETPW_R_SIZE_MAX             = 70
	X_SC_LOGIN_NAME_MAX               = 71
	X_SC_TTY_NAME_MAX                 = 72
	X_SC_THREAD_DESTRUCTOR_ITERATIONS = 73
	X_SC_THREAD_KEYS_MAX              = 74
	X_SC_THREAD_STACK_MIN             = 75
	X_SC_THREAD_THREADS_MAX           = 76
	X_SC_THREAD_ATTR_STACKADDR        = 77
	X_SC_THREAD_ATTR_STACKSIZE        = 78
	X_SC_THREAD_PRIORITY_SCHEDULING   = 79
	X_SC_THREAD_PRIO_INHERIT          = 80
	X_SC_THREAD_PRIO_PROTECT          = 81
	X_SC_THREAD_PROCESS_SHARED        = 82

	X_SC_NPROCESSORS_CONF = 83
	X_SC_NPROCESSORS_ONLN = 84
	X_SC_PHYS_PAGES       = 85
	X_SC_AVPHYS_PAGES     = 86
	X_SC_ATEXIT_MAX       = 87
	X_SC_PASS_MAX         = 88

	X_SC_XOPEN_VERSION     = 89
	X_SC_XOPEN_XCU_VERSION = 90
	X_SC_XOPEN_UNIX        = 91
	X_SC_XOPEN_CRYPT       = 92
	X_SC_XOPEN_ENH_I18N    = 93
	X_SC_XOPEN_SHM         = 94

	X_SC_2_CHAR_TERM = 95
	X_SC_2_C_VERSION = 96
	X_SC_2_UPE       = 97

	X_SC_XOPEN_XPG2 = 98
	X_SC_XOPEN_XPG3 = 99
	X_SC_XOPEN_XPG4 = 100

	X_SC_CHAR_BIT   = 101
	X_SC_CHAR_MAX   = 102
	X_SC_CHAR_MIN   = 103
	X_SC_INT_MAX    = 104
	X_SC_INT_MIN    = 105
	X_SC_LONG_BIT   = 106
	X_SC_WORD_BIT   = 107
	X_SC_MB_LEN_MAX = 108
	X_SC_NZERO      = 109
	X_SC_SSIZE_MAX  = 110
	X_SC_SCHAR_MAX  = 111
	X_SC_SCHAR_MIN  = 112
	X_SC_SHRT_MAX   = 113
	X_SC_SHRT_MIN   = 114
	X_SC_UCHAR_MAX  = 115
	X_SC_UINT_MAX   = 116
	X_SC_ULONG_MAX  = 117
	X_SC_USHRT_MAX  = 118

	X_SC_NL_ARGMAX  = 119
	X_SC_NL_LANGMAX = 120
	X_SC_NL_MSGMAX  = 121
	X_SC_NL_NMAX    = 122
	X_SC_NL_SETMAX  = 123
	X_SC_NL_TEXTMAX = 124

	X_SC_XBS5_ILP32_OFF32  = 125
	X_SC_XBS5_ILP32_OFFBIG = 126
	X_SC_XBS5_LP64_OFF64   = 127
	X_SC_XBS5_LPBIG_OFFBIG = 128

	X_SC_XOPEN_LEGACY           = 129
	X_SC_XOPEN_REALTIME         = 130
	X_SC_XOPEN_REALTIME_THREADS = 131

	X_SC_ADVISORY_INFO          = 132
	X_SC_BARRIERS               = 133
	X_SC_BASE                   = 134
	X_SC_C_LANG_SUPPORT         = 135
	X_SC_C_LANG_SUPPORT_R       = 136
	X_SC_CLOCK_SELECTION        = 137
	X_SC_CPUTIME                = 138
	X_SC_THREAD_CPUTIME         = 139
	X_SC_DEVICE_IO              = 140
	X_SC_DEVICE_SPECIFIC        = 141
	X_SC_DEVICE_SPECIFIC_R      = 142
	X_SC_FD_MGMT                = 143
	X_SC_FIFO                   = 144
	X_SC_PIPE                   = 145
	X_SC_FILE_ATTRIBUTES        = 146
	X_SC_FILE_LOCKING           = 147
	X_SC_FILE_SYSTEM            = 148
	X_SC_MONOTONIC_CLOCK        = 149
	X_SC_MULTI_PROCESS          = 150
	X_SC_SINGLE_PROCESS         = 151
	X_SC_NETWORKING             = 152
	X_SC_READER_WRITER_LOCKS    = 153
	X_SC_SPIN_LOCKS             = 154
	X_SC_REGEXP                 = 155
	X_SC_REGEX_VERSION          = 156
	X_SC_SHELL                  = 157
	X_SC_SIGNALS                = 158
	X_SC_SPAWN                  = 159
	X_SC_SPORADIC_SERVER        = 160
	X_SC_THREAD_SPORADIC_SERVER = 161
	X_SC_SYSTEM_DATABASE        = 162
	X_SC_SYSTEM_DATABASE_R      = 163
	X_SC_TIMEOUTS               = 164
	X_SC_TYPED_MEMORY_OBJECTS   = 165
	X_SC_USER_GROUPS            = 166
	X_SC_USER_GROUPS_R          = 167
	X_SC_2_PBS                  = 168
	X_SC_2_PBS_ACCOUNTING       = 169
	X_SC_2_PBS_LOCATE           = 170
	X_SC_2_PBS_MESSAGE          = 171
	X_SC_2_PBS_TRACK            = 172
	X_SC_SYMLOOP_MAX            = 173
	X_SC_STREAMS                = 174
	X_SC_2_PBS_CHECKPOINT       = 175

	X_SC_V6_ILP32_OFF32  = 176
	X_SC_V6_ILP32_OFFBIG = 177
	X_SC_V6_LP64_OFF64   = 178
	X_SC_V6_LPBIG_OFFBIG = 179

	X_SC_HOST_NAME_MAX      = 180
	X_SC_TRACE              = 181
	X_SC_TRACE_EVENT_FILTER = 182
	X_SC_TRACE_INHERIT      = 183
	X_SC_TRACE_LOG          = 184

	X_SC_LEVEL1_ICACHE_SIZE     = 185
	X_SC_LEVEL1_ICACHE_ASSOC    = 186
	X_SC_LEVEL1_ICACHE_LINESIZE = 187
	X_SC_LEVEL1_DCACHE_SIZE     = 188
	X_SC_LEVEL1_DCACHE_ASSOC    = 189
	X_SC_LEVEL1_DCACHE_LINESIZE = 190
	X_SC_LEVEL2_CACHE_SIZE      = 191
	X_SC_LEVEL2_CACHE_ASSOC     = 192
	X_SC_LEVEL2_CACHE_LINESIZE  = 193
	X_SC_LEVEL3_CACHE_SIZE      = 194
	X_SC_LEVEL3_CACHE_ASSOC     = 195
	X_SC_LEVEL3_CACHE_LINESIZE  = 196
	X_SC_LEVEL4_CACHE_SIZE      = 197
	X_SC_LEVEL4_CACHE_ASSOC     = 198
	X_SC_LEVEL4_CACHE_LINESIZE  = 199

	X_SC_IPV6        = 235
	X_SC_RAW_SOCKETS = 236

	X_SC_V7_ILP32_OFF32  = 237
	X_SC_V7_ILP32_OFFBIG = 238
	X_SC_V7_LP64_OFF64   = 239
	X_SC_V7_LPBIG_OFFBIG = 240

	X_SC_SS_REPL_MAX = 241

	X_SC_TRACE_EVENT_NAME_MAX = 242
	X_SC_TRACE_NAME_MAX       = 243
	X_SC_TRACE_SYS_MAX        = 244
	X_SC_TRACE_USER_EVENT_MAX = 245

	X_SC_XOPEN_STREAMS = 246

	X_SC_THREAD_ROBUST_PRIO_INHERIT = 247
	X_SC_THREAD_ROBUST_PRIO_PROTECT = 248
)

const (
	F_OWNER_TID  = 0
	F_OWNER_PID  = 1
	F_OWNER_PGRP = 2
	F_OWNER_GID  = 2
)

const (
	P_ALL  = 0
	P_PID  = 1
	P_PGID = 2
)

const (
	RTLD_DL_SYMENT = 1

	RTLD_DL_LINKMAP = 2
)

const (
	RTLD_DI_LMID = 1

	RTLD_DI_LINKMAP = 2

	RTLD_DI_CONFIGADDR = 3

	RTLD_DI_SERINFO     = 4
	RTLD_DI_SERINFOSIZE = 5

	RTLD_DI_ORIGIN = 6

	RTLD_DI_PROFILENAME = 7
	RTLD_DI_PROFILEOUT  = 8

	RTLD_DI_TLS_MODID = 9

	RTLD_DI_TLS_DATA = 10

	RTLD_DI_MAX = 10
)

const (
	FP_INT_UPWARD            = 0
	FP_INT_DOWNWARD          = 1
	FP_INT_TOWARDZERO        = 2
	FP_INT_TONEARESTFROMZERO = 3
	FP_INT_TONEAREST         = 4
)

const (
	FP_NAN       = 0
	FP_INFINITE  = 1
	FP_ZERO      = 2
	FP_SUBNORMAL = 3
	FP_NORMAL    = 4
)

const (
	ITIMER_REAL = 0

	ITIMER_VIRTUAL = 1

	ITIMER_PROF = 2
)

type Ptrdiff_t = int64

type Size_t = uint64

type Wchar_t = uint32

type X__int128_t = struct {
	Flo int64
	Fhi int64
}
type X__uint128_t = struct {
	Flo uint64
	Fhi uint64
}

type X__builtin_va_list = uintptr
type X__float128 = float64

type X__gnuc_va_list = X__builtin_va_list

type Va_list = X__gnuc_va_list

var Xsqlite3_version = *(*[7]uint8)(unsafe.Pointer(ts))

type sqlite3 = struct {
	FpVfs                   uintptr
	FpVdbe                  uintptr
	FpDfltColl              uintptr
	Fmutex                  uintptr
	FaDb                    uintptr
	FnDb                    int32
	FmDbFlags               U32
	Fflags                  U64
	FlastRowid              I64
	FszMmap                 I64
	FnSchemaLock            U32
	FopenFlags              uint32
	FerrCode                int32
	FerrByteOffset          int32
	FerrMask                int32
	FiSysErrno              int32
	FdbOptFlags             U32
	Fenc                    U8
	FautoCommit             U8
	Ftemp_store             U8
	FmallocFailed           U8
	FbBenignMalloc          U8
	FdfltLockMode           U8
	FnextAutovac            int8
	FsuppressErr            U8
	FvtabOnConflict         U8
	FisTransactionSavepoint U8
	FmTrace                 U8
	FnoSharedCache          U8
	FnSqlExec               U8
	FeOpenState             U8
	F__ccgo_pad1            [2]byte
	FnextPagesize           int32
	FnChange                I64
	FnTotalChange           I64
	FaLimit                 [12]int32
	FnMaxSorterMmap         int32
	F__ccgo_pad2            [4]byte
	Finit                   struct {
		FnewTnum       Pgno
		FiDb           U8
		Fbusy          U8
		F__ccgo_pad1   [2]byte
		ForphanTrigger uint8
		F__ccgo_pad2   [7]byte
		FazInit        uintptr
	}
	FnVdbeActive        int32
	FnVdbeRead          int32
	FnVdbeWrite         int32
	FnVdbeExec          int32
	FnVDestroy          int32
	FnExtension         int32
	FaExtension         uintptr
	Ftrace              struct{ 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
	Fu1                 struct {
		F__ccgo_pad1   [0]uint64
		FisInterrupted int32
		F__ccgo_pad2   [4]byte
	}
	Flookaside           Lookaside
	FxAuth               Sqlite3_xauth
	FpAuthArg            uintptr
	FxProgress           uintptr
	FpProgressArg        uintptr
	FnProgressOps        uint32
	FnVTrans             int32
	FaModule             Hash
	FpVtabCtx            uintptr
	FaVTrans             uintptr
	FpDisconnect         uintptr
	FaFunc               Hash
	FaCollSeq            Hash
	FbusyHandler         BusyHandler
	FaDbStatic           [2]Db
	FpSavepoint          uintptr
	FnAnalysisLimit      int32
	FbusyTimeout         int32
	FnSavepoint          int32
	FnStatement          int32
	FnDeferredCons       I64
	FnDeferredImmCons    I64
	FpnBytesFreed        uintptr
	FpBlockingConnection uintptr
	FpUnlockConnection   uintptr
	FpUnlockArg          uintptr
	FxUnlockNotify       uintptr
	FpNextBlocked        uintptr
}

type Sqlite3 = sqlite3

type Sqlite_int64 = int64
type Sqlite_uint64 = uint64
type Sqlite3_int64 = Sqlite_int64
type Sqlite3_uint64 = Sqlite_uint64

type Sqlite3_callback = uintptr

type sqlite3_file = struct{ FpMethods uintptr }

type Sqlite3_file = sqlite3_file
type sqlite3_io_methods = struct {
	FiVersion               int32
	F__ccgo_pad1            [4]byte
	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 = sqlite3_io_methods

type sqlite3_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
	Fclose                  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
}

type Sqlite3_api_routines = sqlite3_api_routines

type Sqlite3_filename = uintptr

type sqlite3_vfs = struct {
	FiVersion          int32
	FszOsFile          int32
	FmxPathname        int32
	F__ccgo_pad1       [4]byte
	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 = sqlite3_vfs
type Sqlite3_syscall_ptr = uintptr

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

type Sqlite3_mem_methods = sqlite3_mem_methods

type sqlite3_value = struct {
	Fu        struct{ Fr float64 }
	Fz        uintptr
	Fn        int32
	Fflags    U16
	Fenc      U8
	FeSubtype U8
	Fdb       uintptr
	FszMalloc int32
	FuTemp    U32
	FzMalloc  uintptr
	FxDel     uintptr
}

type Sqlite3_value = sqlite3_value

type sqlite3_context = struct {
	FpOut        uintptr
	FpFunc       uintptr
	FpMem        uintptr
	FpVdbe       uintptr
	FiOp         int32
	FisError     int32
	Fenc         U8
	FskipFlag    U8
	Fargc        U8
	F__ccgo_pad1 [5]byte
	Fargv        [1]uintptr
}

type Sqlite3_context = sqlite3_context

type Sqlite3_destructor_type = uintptr

type sqlite3_vtab = struct {
	FpModule     uintptr
	FnRef        int32
	F__ccgo_pad1 [4]byte
	FzErrMsg     uintptr
}

type Sqlite3_vtab = sqlite3_vtab
type sqlite3_index_info = struct {
	FnConstraint      int32
	F__ccgo_pad1      [4]byte
	FaConstraint      uintptr
	FnOrderBy         int32
	F__ccgo_pad2      [4]byte
	FaOrderBy         uintptr
	FaConstraintUsage uintptr
	FidxNum           int32
	F__ccgo_pad3      [4]byte
	FidxStr           uintptr
	FneedToFreeIdxStr int32
	ForderByConsumed  int32
	FestimatedCost    float64
	FestimatedRows    Sqlite3_int64
	FidxFlags         int32
	F__ccgo_pad4      [4]byte
	FcolUsed          Sqlite3_uint64
}

type Sqlite3_index_info = sqlite3_index_info
type sqlite3_vtab_cursor = struct{ FpVtab uintptr }

type Sqlite3_vtab_cursor = sqlite3_vtab_cursor
type sqlite3_module = struct {
	FiVersion      int32
	F__ccgo_pad1   [4]byte
	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
}

type Sqlite3_module = sqlite3_module

type sqlite3_index_constraint = struct {
	FiColumn     int32
	Fop          uint8
	Fusable      uint8
	F__ccgo_pad1 [2]byte
	FiTermOffset int32
}

type sqlite3_index_orderby = struct {
	FiColumn     int32
	Fdesc        uint8
	F__ccgo_pad1 [3]byte
}

type sqlite3_index_constraint_usage = struct {
	FargvIndex   int32
	Fomit        uint8
	F__ccgo_pad1 [3]byte
}

type sqlite3_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 = sqlite3_mutex_methods

type sqlite3_str = struct {
	Fdb          uintptr
	FzText       uintptr
	FnAlloc      U32
	FmxAlloc     U32
	FnChar       U32
	FaccError    U8
	FprintfFlags U8
	F__ccgo_pad1 [2]byte
}

type Sqlite3_str = sqlite3_str

type sqlite3_pcache_page = struct {
	FpBuf   uintptr
	FpExtra uintptr
}

type Sqlite3_pcache_page = sqlite3_pcache_page

type sqlite3_pcache_methods2 = struct {
	FiVersion    int32
	F__ccgo_pad1 [4]byte
	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 = sqlite3_pcache_methods2

type sqlite3_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 = sqlite3_pcache_methods

type sqlite3_backup = struct {
	FpDestDb     uintptr
	FpDest       uintptr
	FiDestSchema U32
	FbDestLocked int32
	FiNext       Pgno
	F__ccgo_pad1 [4]byte
	FpSrcDb      uintptr
	FpSrc        uintptr
	Frc          int32
	FnRemaining  Pgno
	FnPagecount  Pgno
	FisAttached  int32
	FpNext       uintptr
}

type Sqlite3_backup = sqlite3_backup

type sqlite3_snapshot = struct{ Fhidden [48]uint8 }

type Sqlite3_snapshot = sqlite3_snapshot

type sqlite3_rtree_geometry = struct {
	FpContext    uintptr
	FnParam      int32
	F__ccgo_pad1 [4]byte
	FaParam      uintptr
	FpUser       uintptr
	FxDelUser    uintptr
}

type Sqlite3_rtree_geometry = sqlite3_rtree_geometry
type sqlite3_rtree_query_info = struct {
	FpContext      uintptr
	FnParam        int32
	F__ccgo_pad1   [4]byte
	FaParam        uintptr
	FpUser         uintptr
	FxDelUser      uintptr
	FaCoord        uintptr
	FanQueue       uintptr
	FnCoord        int32
	FiLevel        int32
	FmxLevel       int32
	F__ccgo_pad2   [4]byte
	FiRowid        Sqlite3_int64
	FrParentScore  Sqlite3_rtree_dbl
	FeParentWithin int32
	FeWithin       int32
	FrScore        Sqlite3_rtree_dbl
	FapSqlParam    uintptr
}

type Sqlite3_rtree_query_info = sqlite3_rtree_query_info

type Sqlite3_rtree_dbl = float64

type sqlite3_session = struct {
	Fdb                uintptr
	FzDb               uintptr
	FbEnableSize       int32
	FbEnable           int32
	FbIndirect         int32
	FbAutoAttach       int32
	Frc                int32
	F__ccgo_pad1       [4]byte
	FpFilterCtx        uintptr
	FxTableFilter      uintptr
	FnMalloc           I64
	FnMaxChangesetSize I64
	FpZeroBlob         uintptr
	FpNext             uintptr
	FpTable            uintptr
	Fhook              SessionHook
}

type Sqlite3_session = sqlite3_session

type sqlite3_changeset_iter = struct {
	Fin          SessionInput
	Ftblhdr      SessionBuffer
	FbPatchset   int32
	FbInvert     int32
	FbSkipEmpty  int32
	Frc          int32
	FpConflict   uintptr
	FzTab        uintptr
	FnCol        int32
	Fop          int32
	FbIndirect   int32
	F__ccgo_pad1 [4]byte
	FabPK        uintptr
	FapValue     uintptr
}

type Sqlite3_changeset_iter = sqlite3_changeset_iter

type sqlite3_changegroup = struct {
	Frc     int32
	FbPatch int32
	FpList  uintptr
}

type Sqlite3_changegroup = sqlite3_changegroup

type sqlite3_rebaser = struct{ Fgrp Sqlite3_changegroup }

type Sqlite3_rebaser = sqlite3_rebaser

type Fts5ExtensionApi1 = struct {
	FiVersion           int32
	F__ccgo_pad1        [4]byte
	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
}

type Fts5ExtensionApi = Fts5ExtensionApi1
type Fts5PhraseIter1 = struct {
	Fa uintptr
	Fb uintptr
}

type Fts5PhraseIter = Fts5PhraseIter1

type Fts5_extension_function = uintptr
type fts5_tokenizer = struct {
	FxCreate   uintptr
	FxDelete   uintptr
	FxTokenize uintptr
}

type Fts5_tokenizer = fts5_tokenizer

type fts5_api = struct {
	FiVersion         int32
	F__ccgo_pad1      [4]byte
	FxCreateTokenizer uintptr
	FxFindTokenizer   uintptr
	FxCreateFunction  uintptr
}

type Fts5_api = fts5_api

type Hash1 = struct {
	Fhtsize uint32
	Fcount  uint32
	Ffirst  uintptr
	Fht     uintptr
}

type Hash = Hash1
type HashElem1 = struct {
	Fnext uintptr
	Fprev uintptr
	Fdata uintptr
	FpKey uintptr
}

type HashElem = HashElem1

type _ht = struct {
	Fcount       uint32
	F__ccgo_pad1 [4]byte
	Fchain       uintptr
}

type X__u_char = uint8
type X__u_short = uint16
type X__u_int = uint32
type X__u_long = uint64

type X__int8_t = int8
type X__uint8_t = uint8
type X__int16_t = int16
type X__uint16_t = uint16
type X__int32_t = int32
type X__uint32_t = uint32
type X__int64_t = int64
type X__uint64_t = uint64

type X__int_least8_t = X__int8_t
type X__uint_least8_t = X__uint8_t
type X__int_least16_t = X__int16_t
type X__uint_least16_t = X__uint16_t
type X__int_least32_t = X__int32_t
type X__uint_least32_t = X__uint32_t
type X__int_least64_t = X__int64_t
type X__uint_least64_t = X__uint64_t

type X__quad_t = int64
type X__u_quad_t = uint64

type X__intmax_t = int64
type X__uintmax_t = uint64

type X__dev_t = uint64
type X__uid_t = uint32
type X__gid_t = uint32
type X__ino_t = uint64
type X__ino64_t = uint64
type X__mode_t = uint32
type X__nlink_t = uint32
type X__off_t = int64
type X__off64_t = int64
type X__pid_t = int32
type X__fsid_t = struct{ F__val [2]int32 }
type X__clock_t = int64
type X__rlim_t = uint64
type X__rlim64_t = uint64
type X__id_t = uint32
type X__time_t = int64
type X__useconds_t = uint32
type X__suseconds_t = int64

type X__daddr_t = int32
type X__key_t = int32

type X__clockid_t = int32

type X__timer_t = uintptr

type X__blksize_t = int32

type X__blkcnt_t = int64
type X__blkcnt64_t = int64

type X__fsblkcnt_t = uint64
type X__fsblkcnt64_t = uint64

type X__fsfilcnt_t = uint64
type X__fsfilcnt64_t = uint64

type X__fsword_t = int64

type X__ssize_t = int64

type X__syscall_slong_t = int64

type X__syscall_ulong_t = uint64

type X__loff_t = X__off64_t
type X__caddr_t = uintptr

type X__intptr_t = int64

type X__socklen_t = uint32

type X__sig_atomic_t = int32

type X__mbstate_t = struct {
	F__count int32
	F__value struct{ F__wch uint32 }
}

type _G_fpos_t = struct {
	F__pos   X__off_t
	F__state X__mbstate_t
}

type X__fpos_t = _G_fpos_t

type _G_fpos64_t = struct {
	F__pos   X__off64_t
	F__state X__mbstate_t
}

type X__fpos64_t = _G_fpos64_t

type _IO_FILE = struct {
	F_flags          int32
	F__ccgo_pad1     [4]byte
	F_IO_read_ptr    uintptr
	F_IO_read_end    uintptr
	F_IO_read_base   uintptr
	F_IO_write_base  uintptr
	F_IO_write_ptr   uintptr
	F_IO_write_end   uintptr
	F_IO_buf_base    uintptr
	F_IO_buf_end     uintptr
	F_IO_save_base   uintptr
	F_IO_backup_base uintptr
	F_IO_save_end    uintptr
	F_markers        uintptr
	F_chain          uintptr
	F_fileno         int32
	F_flags2         int32
	F_old_offset     X__off_t
	F_cur_column     uint16
	F_vtable_offset  int8
	F_shortbuf       [1]uint8
	F__ccgo_pad2     [4]byte
	F_lock           uintptr
	F_offset         X__off64_t
	F_codecvt        uintptr
	F_wide_data      uintptr
	F_freeres_list   uintptr
	F_freeres_buf    uintptr
	F__pad5          Size_t
	F_mode           int32
	F_unused2        [20]uint8
}

type X__FILE = _IO_FILE

type FILE = _IO_FILE

type _IO_cookie_io_functions_t = struct {
	Fread  uintptr
	Fwrite uintptr
	Fseek  uintptr
	Fclose uintptr
}

type Cookie_io_functions_t = _IO_cookie_io_functions_t

type Off_t = X__off64_t
type Off64_t = X__off64_t

type Ssize_t = X__ssize_t

type Fpos_t = X__fpos64_t
type Fpos64_t = X__fpos64_t

type Idtype_t = uint32

type Div_t = struct {
	Fquot int32
	Frem  int32
}

type Ldiv_t = struct {
	Fquot int64
	Frem  int64
}

type Lldiv_t = struct {
	Fquot int64
	Frem  int64
}

type __locale_struct = struct {
	F__locales       [13]uintptr
	F__ctype_b       uintptr
	F__ctype_tolower uintptr
	F__ctype_toupper uintptr
	F__names         [13]uintptr
}

type X__locale_t = uintptr

type Locale_t = X__locale_t

type U_char = X__u_char
type U_short = X__u_short
type U_int = X__u_int
type U_long = X__u_long
type Quad_t = X__quad_t
type U_quad_t = X__u_quad_t
type Fsid_t = X__fsid_t
type Loff_t = X__loff_t

type Ino_t = X__ino64_t
type Ino64_t = X__ino64_t

type Dev_t = X__dev_t

type Gid_t = X__gid_t

type Mode_t = X__mode_t

type Nlink_t = X__nlink_t

type Uid_t = X__uid_t

type Pid_t = X__pid_t

type Id_t = X__id_t

type Daddr_t = X__daddr_t
type Caddr_t = X__caddr_t

type Key_t = X__key_t

type Clock_t = X__clock_t

type Clockid_t = X__clockid_t

type Time_t = X__time_t

type Timer_t = X__timer_t

type Useconds_t = X__useconds_t
type Suseconds_t = X__suseconds_t

type Ulong = uint64
type Ushort = uint16
type Uint = uint32

type Int8_t = X__int8_t
type Int16_t = X__int16_t
type Int32_t = X__int32_t
type Int64_t = X__int64_t

type U_int8_t = X__uint8_t
type U_int16_t = X__uint16_t
type U_int32_t = X__uint32_t
type U_int64_t = X__uint64_t

type Register_t = int32

type X__sigset_t = struct{ F__val [16]uint64 }

type Sigset_t = X__sigset_t

type timeval = struct {
	Ftv_sec  X__time_t
	Ftv_usec X__suseconds_t
}

type timespec = struct {
	Ftv_sec  X__time_t
	Ftv_nsec X__syscall_slong_t
}

type X__fd_mask = int64

type Fd_set = struct{ Ffds_bits [16]X__fd_mask }

type Fd_mask = X__fd_mask

type Blksize_t = X__blksize_t

type Blkcnt_t = X__blkcnt64_t
type Fsblkcnt_t = X__fsblkcnt64_t
type Fsfilcnt_t = X__fsfilcnt64_t

type Blkcnt64_t = X__blkcnt64_t
type Fsblkcnt64_t = X__fsblkcnt64_t
type Fsfilcnt64_t = X__fsfilcnt64_t

type __pthread_internal_list = struct {
	F__prev uintptr
	F__next uintptr
}

type X__pthread_list_t = __pthread_internal_list

type __pthread_internal_slist = struct{ F__next uintptr }

type X__pthread_slist_t = __pthread_internal_slist

type __pthread_mutex_s = struct {
	F__lock   int32
	F__count  uint32
	F__owner  int32
	F__nusers uint32
	F__kind   int32
	F__spins  int32
	F__list   X__pthread_list_t
}

type __pthread_rwlock_arch_t = struct {
	F__readers       uint32
	F__writers       uint32
	F__wrphase_futex uint32
	F__writers_futex uint32
	F__pad3          uint32
	F__pad4          uint32
	F__cur_writer    int32
	F__shared        int32
	F__pad1          uint64
	F__pad2          uint64
	F__flags         uint32
	F__ccgo_pad1     [4]byte
}

type __pthread_cond_s = struct {
	F__0            struct{ F__wseq uint64 }
	F__8            struct{ F__g1_start uint64 }
	F__g_refs       [2]uint32
	F__g_size       [2]uint32
	F__g1_orig_size uint32
	F__wrefs        uint32
	F__g_signals    [2]uint32
}

type Pthread_t = uint64

type Pthread_mutexattr_t = struct {
	F__ccgo_pad1 [0]uint32
	F__size      [8]uint8
}

type Pthread_condattr_t = struct {
	F__ccgo_pad1 [0]uint32
	F__size      [8]uint8
}

type Pthread_key_t = uint32

type Pthread_once_t = int32

type pthread_attr_t = struct {
	F__ccgo_pad1 [0]uint64
	F__size      [64]uint8
}

type Pthread_attr_t = pthread_attr_t

type Pthread_mutex_t = struct {
	F__data      __pthread_mutex_s
	F__ccgo_pad1 [8]byte
}

type Pthread_cond_t = struct{ F__data __pthread_cond_s }

type Pthread_rwlock_t = struct{ F__data __pthread_rwlock_arch_t }

type Pthread_rwlockattr_t = struct {
	F__ccgo_pad1 [0]uint64
	F__size      [8]uint8
}

type Pthread_spinlock_t = int32

type Pthread_barrier_t = struct {
	F__ccgo_pad1 [0]uint64
	F__size      [32]uint8
}

type Pthread_barrierattr_t = struct {
	F__ccgo_pad1 [0]uint32
	F__size      [8]uint8
}

type random_data = struct {
	Ffptr        uintptr
	Frptr        uintptr
	Fstate       uintptr
	Frand_type   int32
	Frand_deg    int32
	Frand_sep    int32
	F__ccgo_pad1 [4]byte
	Fend_ptr     uintptr
}

type drand48_data = struct {
	F__x     [3]uint16
	F__old_x [3]uint16
	F__c     uint16
	F__init  uint16
	F__a     uint64
}

type X__compar_fn_t = uintptr

type Comparison_fn_t = X__compar_fn_t
type X__compar_d_fn_t = uintptr

type Max_align_t = struct {
	F__max_align_ll int64
	F__max_align_ld float64
}

type I64 = Sqlite_int64
type U64 = Sqlite_uint64
type U32 = uint32
type U16 = uint16
type I16 = int16
type U8 = uint8
type I8 = int8

type TRowcnt = U64

type LogEst = int16

type Uptr = U64

type BusyHandler1 = struct {
	FxBusyHandler uintptr
	FpBusyArg     uintptr
	FnBusy        int32
	F__ccgo_pad1  [4]byte
}

type BusyHandler = BusyHandler1

type AggInfo1 = struct {
	FdirectMode     U8
	FuseSortingIdx  U8
	FnSortingColumn U16
	FsortingIdx     int32
	FsortingIdxPTab int32
	FiFirstReg      int32
	FpGroupBy       uintptr
	FaCol           uintptr
	FnColumn        int32
	FnAccumulator   int32
	FaFunc          uintptr
	FnFunc          int32
	FselId          U32
}

type AggInfo = AggInfo1
type AuthContext1 = struct {
	FzAuthContext uintptr
	FpParse       uintptr
}

type AuthContext = AuthContext1
type AutoincInfo1 = struct {
	FpNext  uintptr
	FpTab   uintptr
	FiDb    int32
	FregCtr int32
}

type AutoincInfo = AutoincInfo1
type Bitvec1 = struct {
	FiSize       U32
	FnSet        U32
	FiDivisor    U32
	F__ccgo_pad1 [4]byte
	Fu           struct {
		F__ccgo_pad1 [0]uint64
		FaBitmap     [496]U8
	}
}

type Bitvec = Bitvec1
type CollSeq1 = struct {
	FzName       uintptr
	Fenc         U8
	F__ccgo_pad1 [7]byte
	FpUser       uintptr
	FxCmp        uintptr
	FxDel        uintptr
}

type CollSeq = CollSeq1
type Column1 = struct {
	FzCnName     uintptr
	FnotNull     uint8
	F__ccgo_pad1 [1]byte
	Faffinity    uint8
	FszEst       U8
	FhName       U8
	F__ccgo_pad2 [1]byte
	FiDflt       U16
	FcolFlags    U16
	F__ccgo_pad3 [6]byte
}

type Column = Column1
type Cte1 = struct {
	FzName       uintptr
	FpCols       uintptr
	FpSelect     uintptr
	FzCteErr     uintptr
	FpUse        uintptr
	FeM10d       U8
	F__ccgo_pad1 [7]byte
}

type Cte = Cte1
type CteUse1 = struct {
	FnUse        int32
	FaddrM9e     int32
	FregRtn      int32
	FiCur        int32
	FnRowEst     LogEst
	FeM10d       U8
	F__ccgo_pad1 [1]byte
}

type CteUse = CteUse1
type Db1 = struct {
	FzDbSName     uintptr
	FpBt          uintptr
	Fsafety_level U8
	FbSyncSet     U8
	F__ccgo_pad1  [6]byte
	FpSchema      uintptr
}

type Db = Db1
type DbFixer1 = struct {
	FpParse      uintptr
	Fw           Walker
	FpSchema     uintptr
	FbTemp       U8
	F__ccgo_pad1 [7]byte
	FzDb         uintptr
	FzType       uintptr
	FpName       uintptr
}

type DbFixer = DbFixer1
type Schema1 = struct {
	Fschema_cookie int32
	FiGeneration   int32
	FtblHash       Hash
	FidxHash       Hash
	FtrigHash      Hash
	FfkeyHash      Hash
	FpSeqTab       uintptr
	Ffile_format   U8
	Fenc           U8
	FschemaFlags   U16
	Fcache_size    int32
}

type Schema = Schema1
type Expr1 = struct {
	Fop          U8
	FaffExpr     uint8
	Fop2         U8
	F__ccgo_pad1 [1]byte
	Fflags       U32
	Fu           struct{ FzToken uintptr }
	FpLeft       uintptr
	FpRight      uintptr
	Fx           struct{ FpList uintptr }
	FnHeight     int32
	FiTable      int32
	FiColumn     YnVar
	FiAgg        I16
	Fw           struct{ FiJoin int32 }
	FpAggInfo    uintptr
	Fy           struct{ FpTab uintptr }
}

type Expr = Expr1
type ExprList1 = struct {
	FnExpr  int32
	FnAlloc int32
	Fa      [1]struct {
		FpExpr  uintptr
		FzEName uintptr
		Ffg     struct {
			F__ccgo_pad1 [0]uint32
			FsortFlags   U8
			F__ccgo_pad2 [3]byte
			FeEName      uint16
			F__ccgo_pad3 [2]byte
		}
		Fu struct {
			F__ccgo_pad1 [0]uint32
			Fx           struct {
				FiOrderByCol U16
				FiAlias      U16
			}
		}
		F__ccgo_pad1 [4]byte
	}
}

type ExprList = ExprList1
type FKey1 = struct {
	FpFrom       uintptr
	FpNextFrom   uintptr
	FzTo         uintptr
	FpNextTo     uintptr
	FpPrevTo     uintptr
	FnCol        int32
	FisDeferred  U8
	FaAction     [2]U8
	F__ccgo_pad1 [1]byte
	FapTrigger   [2]uintptr
	FaCol        [1]struct {
		FiFrom       int32
		F__ccgo_pad1 [4]byte
		FzCol        uintptr
	}
}

type FKey = FKey1
type FuncDestructor1 = struct {
	FnRef        int32
	F__ccgo_pad1 [4]byte
	FxDestroy    uintptr
	FpUserData   uintptr
}

type FuncDestructor = FuncDestructor1
type FuncDef1 = struct {
	FnArg        I8
	F__ccgo_pad1 [3]byte
	FfuncFlags   U32
	FpUserData   uintptr
	FpNext       uintptr
	FxSFunc      uintptr
	FxFinalize   uintptr
	FxValue      uintptr
	FxInverse    uintptr
	FzName       uintptr
	Fu           struct{ FpHash uintptr }
}

type FuncDef = FuncDef1
type FuncDefHash1 = struct{ Fa [23]uintptr }

type FuncDefHash = FuncDefHash1
type IdList1 = struct {
	FnId         int32
	FeU4         U8
	F__ccgo_pad1 [3]byte
	Fa           [1]struct {
		FzName uintptr
		Fu4    struct {
			F__ccgo_pad1 [0]uint64
			Fidx         int32
			F__ccgo_pad2 [4]byte
		}
	}
}

type IdList = IdList1
type Index1 = struct {
	FzName         uintptr
	FaiColumn      uintptr
	FaiRowLogEst   uintptr
	FpTable        uintptr
	FzColAff       uintptr
	FpNext         uintptr
	FpSchema       uintptr
	FaSortOrder    uintptr
	FazColl        uintptr
	FpPartIdxWhere uintptr
	FaColExpr      uintptr
	Ftnum          Pgno
	FszIdxRow      LogEst
	FnKeyCol       U16
	FnColumn       U16
	FonError       U8
	F__ccgo_pad1   [1]byte
	FidxType       uint16
	F__ccgo_pad2   [2]byte
	FnSample       int32
	FnSampleCol    int32
	FaAvgEq        uintptr
	FaSample       uintptr
	FaiRowEst      uintptr
	FnRowEst0      TRowcnt
	FcolNotIdxed   Bitmask
}

type Index = Index1
type IndexedExpr1 = struct {
	FpExpr         uintptr
	FiDataCur      int32
	FiIdxCur       int32
	FiIdxCol       int32
	FbMaybeNullRow U8
	Faff           U8
	F__ccgo_pad1   [2]byte
	FpIENext       uintptr
	FzIdxName      uintptr
}

type IndexedExpr = IndexedExpr1
type IndexSample1 = struct {
	Fp           uintptr
	Fn           int32
	F__ccgo_pad1 [4]byte
	FanEq        uintptr
	FanLt        uintptr
	FanDLt       uintptr
}

type IndexSample = IndexSample1
type KeyInfo1 = struct {
	FnRef        U32
	Fenc         U8
	F__ccgo_pad1 [1]byte
	FnKeyField   U16
	FnAllField   U16
	F__ccgo_pad2 [6]byte
	Fdb          uintptr
	FaSortFlags  uintptr
	FaColl       [1]uintptr
}

type KeyInfo = KeyInfo1
type Lookaside1 = struct {
	FbDisable    U32
	Fsz          U16
	FszTrue      U16
	FbMalloced   U8
	F__ccgo_pad1 [3]byte
	FnSlot       U32
	FanStat      [3]U32
	F__ccgo_pad2 [4]byte
	FpInit       uintptr
	FpFree       uintptr
	FpSmallInit  uintptr
	FpSmallFree  uintptr
	FpMiddle     uintptr
	FpStart      uintptr
	FpEnd        uintptr
	FpTrueEnd    uintptr
}

type Lookaside = Lookaside1
type LookasideSlot1 = struct{ FpNext uintptr }

type LookasideSlot = LookasideSlot1
type Module1 = struct {
	FpModule     uintptr
	FzName       uintptr
	FnRefModule  int32
	F__ccgo_pad1 [4]byte
	FpAux        uintptr
	FxDestroy    uintptr
	FpEpoTab     uintptr
}

type Module = Module1
type NameContext1 = struct {
	FpParse      uintptr
	FpSrcList    uintptr
	FuNC         struct{ FpEList uintptr }
	FpNext       uintptr
	FnRef        int32
	FnNcErr      int32
	FncFlags     int32
	F__ccgo_pad1 [4]byte
	FpWinSelect  uintptr
}

type NameContext = NameContext1
type OnOrUsing1 = struct {
	FpOn    uintptr
	FpUsing uintptr
}

type OnOrUsing = OnOrUsing1
type Parse1 = struct {
	Fdb               uintptr
	FzErrMsg          uintptr
	FpVdbe            uintptr
	Frc               int32
	FcolNamesSet      U8
	FcheckSchema      U8
	Fnested           U8
	FnTempReg         U8
	FisMultiWrite     U8
	FmayAbort         U8
	FhasCompound      U8
	FokConstFactor    U8
	FdisableLookaside U8
	FprepFlags        U8
	FwithinRJSubrtn   U8
	F__ccgo_pad1      [1]byte
	FnRangeReg        int32
	FiRangeReg        int32
	FnErr             int32
	FnTab             int32
	FnMem             int32
	FszOpAlloc        int32
	FiSelfTab         int32
	FnLabel           int32
	FnLabelAlloc      int32
	F__ccgo_pad2      [4]byte
	FaLabel           uintptr
	FpConstExpr       uintptr
	FpIdxEpr          uintptr
	FconstraintName   Token
	FwriteMask        YDbMask
	FcookieMask       YDbMask
	FregRowid         int32
	FregRoot          int32
	FnMaxArg          int32
	FnSelect          int32
	FnTableLock       int32
	F__ccgo_pad3      [4]byte
	FaTableLock       uintptr
	FpAinc            uintptr
	FpToplevel        uintptr
	FpTriggerTab      uintptr
	FpTriggerPrg      uintptr
	FpCleanup         uintptr
	Fu1               struct {
		F__ccgo_pad1 [0]uint64
		FaddrCrTab   int32
		F__ccgo_pad2 [4]byte
	}
	FnQueryLoop      U32
	Foldmask         U32
	Fnewmask         U32
	FnProgressSteps  U32
	FeTriggerOp      U8
	FbReturning      U8
	FeOrconf         U8
	FdisableTriggers U8
	FaTempReg        [8]int32
	F__ccgo_pad4     [4]byte
	FpOuterParse     uintptr
	FsNameToken      Token
	FsLastToken      Token
	FnVar            YnVar
	FiPkSortOrder    U8
	Fexplain         U8
	FeParseMode      U8
	F__ccgo_pad5     [3]byte
	FnVtabLock       int32
	FnHeight         int32
	FaddrExplain     int32
	F__ccgo_pad6     [4]byte
	FpVList          uintptr
	FpReprepare      uintptr
	FzTail           uintptr
	FpNewTable       uintptr
	FpNewIndex       uintptr
	FpNewTrigger     uintptr
	FzAuthContext    uintptr
	FsArg            Token
	FapVtabLock      uintptr
	FpWith           uintptr
	FpRename         uintptr
}

type Parse = Parse1
type ParseCleanup1 = struct {
	FpNext    uintptr
	FpPtr     uintptr
	FxCleanup uintptr
}

type ParseCleanup = ParseCleanup1
type PreUpdate1 = struct {
	Fv            uintptr
	FpCsr         uintptr
	Fop           int32
	F__ccgo_pad1  [4]byte
	FaRecord      uintptr
	Fkeyinfo      KeyInfo
	FpUnpacked    uintptr
	FpNewUnpacked uintptr
	FiNewReg      int32
	FiBlobWrite   int32
	FiKey1        I64
	FiKey2        I64
	FaNew         uintptr
	FpTab         uintptr
	FpPk          uintptr
}

type PreUpdate = PreUpdate1
type PrintfArguments1 = struct {
	FnArg  int32
	FnUsed int32
	FapArg uintptr
}

type PrintfArguments = PrintfArguments1
type RenameToken1 = struct {
	Fp     uintptr
	Ft     Token
	FpNext uintptr
}

type RenameToken = RenameToken1
type Returning1 = struct {
	FpParse      uintptr
	FpReturnEL   uintptr
	FretTrig     Trigger
	FretTStep    TriggerStep
	FiRetCur     int32
	FnRetCol     int32
	FiRetReg     int32
	F__ccgo_pad1 [4]byte
}

type Returning = Returning1
type RowSet1 = struct {
	FpChunk  uintptr
	Fdb      uintptr
	FpEntry  uintptr
	FpLast   uintptr
	FpFresh  uintptr
	FpForest uintptr
	FnFresh  U16
	FrsFlags U16
	FiBatch  int32
}

type RowSet = RowSet1
type Savepoint1 = struct {
	FzName            uintptr
	FnDeferredCons    I64
	FnDeferredImmCons I64
	FpNext            uintptr
}

type Savepoint = Savepoint1
type Select1 = struct {
	Fop           U8
	F__ccgo_pad1  [1]byte
	FnSelectRow   LogEst
	FselFlags     U32
	FiLimit       int32
	FiOffset      int32
	FselId        U32
	FaddrOpenEphm [2]int32
	F__ccgo_pad2  [4]byte
	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 = Select1
type SQLiteThread1 = struct {
	FxTask   uintptr
	FpIn     uintptr
	FpResult uintptr
}

type SQLiteThread = SQLiteThread1
type SelectDest1 = struct {
	FeDest       U8
	F__ccgo_pad1 [3]byte
	FiSDParm     int32
	FiSDParm2    int32
	FiSdst       int32
	FnSdst       int32
	F__ccgo_pad2 [4]byte
	FzAffSdst    uintptr
	FpOrderBy    uintptr
}

type SelectDest = SelectDest1
type SrcItem1 = struct {
	FpSchema     uintptr
	FzDatabase   uintptr
	FzName       uintptr
	FzAlias      uintptr
	FpTab        uintptr
	FpSelect     uintptr
	FaddrFillSub int32
	FregReturn   int32
	FregResult   int32
	Ffg          struct {
		F__ccgo_pad1 [0]uint32
		Fjointype    U8
		F__ccgo_pad2 [3]byte
		FnotIndexed  uint16
		F__ccgo_pad3 [2]byte
	}
	FiCursor int32
	Fu3      struct{ FpOn uintptr }
	FcolUsed Bitmask
	Fu1      struct{ FzIndexedBy uintptr }
	Fu2      struct{ FpIBIndex uintptr }
}

type SrcItem = SrcItem1
type SrcList1 = struct {
	FnSrc   int32
	FnAlloc U32
	Fa      [1]SrcItem
}

type SrcList = SrcList1
type StrAccum = sqlite3_str
type Table1 = struct {
	FzName      uintptr
	FaCol       uintptr
	FpIndex     uintptr
	FzColAff    uintptr
	FpCheck     uintptr
	Ftnum       Pgno
	FnTabRef    U32
	FtabFlags   U32
	FiPKey      I16
	FnCol       I16
	FnNVCol     I16
	FnRowLogEst LogEst
	FszTabRow   LogEst
	FkeyConf    U8
	FeTabType   U8
	Fu          struct {
		Ftab struct {
			FaddColOffset int32
			F__ccgo_pad1  [4]byte
			FpFKey        uintptr
			FpDfltList    uintptr
		}
	}
	FpTrigger uintptr
	FpSchema  uintptr
}

type Table = Table1
type TableLock1 = struct {
	FiDb         int32
	FiTab        Pgno
	FisWriteLock U8
	F__ccgo_pad1 [7]byte
	FzLockName   uintptr
}

type TableLock = TableLock1
type Token1 = struct {
	Fz           uintptr
	Fn           uint32
	F__ccgo_pad1 [4]byte
}

type Token = Token1
type Trigger1 = struct {
	FzName       uintptr
	Ftable       uintptr
	Fop          U8
	Ftr_tm       U8
	FbReturning  U8
	F__ccgo_pad1 [5]byte
	FpWhen       uintptr
	FpColumns    uintptr
	FpSchema     uintptr
	FpTabSchema  uintptr
	Fstep_list   uintptr
	FpNext       uintptr
}

type Trigger = Trigger1
type TriggerPrg1 = struct {
	FpTrigger    uintptr
	FpNext       uintptr
	FpProgram    uintptr
	Forconf      int32
	FaColmask    [2]U32
	F__ccgo_pad1 [4]byte
}

type TriggerPrg = TriggerPrg1
type TriggerStep1 = struct {
	Fop          U8
	Forconf      U8
	F__ccgo_pad1 [6]byte
	FpTrig       uintptr
	FpSelect     uintptr
	FzTarget     uintptr
	FpFrom       uintptr
	FpWhere      uintptr
	FpExprList   uintptr
	FpIdList     uintptr
	FpUpsert     uintptr
	FzSpan       uintptr
	FpNext       uintptr
	FpLast       uintptr
}

type TriggerStep = TriggerStep1
type UnpackedRecord1 = struct {
	FpKeyInfo    uintptr
	FaMem        uintptr
	Fu           struct{ Fz uintptr }
	Fn           int32
	FnField      U16
	Fdefault_rc  I8
	FerrCode     U8
	Fr1          I8
	Fr2          I8
	FeqSeen      U8
	F__ccgo_pad1 [5]byte
}

type UnpackedRecord = UnpackedRecord1
type Upsert1 = struct {
	FpUpsertTarget      uintptr
	FpUpsertTargetWhere uintptr
	FpUpsertSet         uintptr
	FpUpsertWhere       uintptr
	FpNextUpsert        uintptr
	FisDoUpdate         U8
	F__ccgo_pad1        [7]byte
	FpToFree            uintptr
	FpUpsertIdx         uintptr
	FpUpsertSrc         uintptr
	FregData            int32
	FiDataCur           int32
	FiIdxCur            int32
	F__ccgo_pad2        [4]byte
}

type Upsert = Upsert1
type VTable1 = struct {
	Fdb          uintptr
	FpMod        uintptr
	FpVtab       uintptr
	FnRef        int32
	FbConstraint U8
	FeVtabRisk   U8
	F__ccgo_pad1 [2]byte
	FiSavepoint  int32
	F__ccgo_pad2 [4]byte
	FpNext       uintptr
}

type VTable = VTable1
type VtabCtx1 = struct {
	FpVTable     uintptr
	FpTab        uintptr
	FpPrior      uintptr
	FbDeclared   int32
	F__ccgo_pad1 [4]byte
}

type VtabCtx = VtabCtx1
type Walker1 = struct {
	FpParse           uintptr
	FxExprCallback    uintptr
	FxSelectCallback  uintptr
	FxSelectCallback2 uintptr
	FwalkerDepth      int32
	FeCode            U16
	F__ccgo_pad1      [2]byte
	Fu                struct{ FpNC uintptr }
}

type Walker = Walker1
type WhereInfo1 = struct {
	FpParse          uintptr
	FpTabList        uintptr
	FpOrderBy        uintptr
	FpResultSet      uintptr
	FpSelect         uintptr
	FaiCurOnePass    [2]int32
	FiContinue       int32
	FiBreak          int32
	FsavedNQueryLoop int32
	FwctrlFlags      U16
	FiLimit          LogEst
	FnLevel          U8
	FnOBSat          I8
	FeOnePass        U8
	FeDistinct       U8
	FbDeferredSeek   uint8
	F__ccgo_pad1     [1]byte
	FnRowOut         LogEst
	FiTop            int32
	FiEndWhere       int32
	FpLoops          uintptr
	FpMemToFree      uintptr
	FrevMask         Bitmask
	FsWC             WhereClause
	FsMaskSet        WhereMaskSet
	Fa               [1]WhereLevel
}

type WhereInfo = WhereInfo1
type Window1 = struct {
	FzName          uintptr
	FzBase          uintptr
	FpPartition     uintptr
	FpOrderBy       uintptr
	FeFrmType       U8
	FeStart         U8
	FeEnd           U8
	FbImplicitFrame U8
	FeExclude       U8
	F__ccgo_pad1    [3]byte
	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      U8
	F__ccgo_pad2    [3]byte
}

type Window = Window1
type With1 = struct {
	FnCte   int32
	FbView  int32
	FpOuter uintptr
	Fa      [1]Cte
}

type With = With1

type Bitmask = U64

type VList = int32

type Pgno = U32

type Pager1 = struct {
	FpVfs              uintptr
	FexclusiveMode     U8
	FjournalMode       U8
	FuseJournal        U8
	FnoSync            U8
	FfullSync          U8
	FextraSync         U8
	FsyncFlags         U8
	FwalSyncFlags      U8
	FtempFile          U8
	FnoLock            U8
	FreadOnly          U8
	FmemDb             U8
	FmemVfs            U8
	FeState            U8
	FeLock             U8
	FchangeCountDone   U8
	FsetSuper          U8
	FdoNotSpill        U8
	FsubjInMemory      U8
	FbUseFetch         U8
	FhasHeldSharedLock U8
	F__ccgo_pad1       [3]byte
	FdbSize            Pgno
	FdbOrigSize        Pgno
	FdbFileSize        Pgno
	FdbHintSize        Pgno
	FerrCode           int32
	FnRec              int32
	FcksumInit         U32
	FnSubRec           U32
	FpInJournal        uintptr
	Ffd                uintptr
	Fjfd               uintptr
	Fsjfd              uintptr
	FjournalOff        I64
	FjournalHdr        I64
	FpBackup           uintptr
	FaSavepoint        uintptr
	FnSavepoint        int32
	FiDataVersion      U32
	FdbFileVers        [16]uint8
	FnMmapOut          int32
	F__ccgo_pad2       [4]byte
	FszMmap            Sqlite3_int64
	FpMmapFreelist     uintptr
	FnExtra            U16
	FnReserve          I16
	FvfsFlags          U32
	FsectorSize        U32
	FmxPgno            Pgno
	FlckPgno           Pgno
	F__ccgo_pad3       [4]byte
	FpageSize          I64
	FjournalSizeLimit  I64
	FzFilename         uintptr
	FzJournal          uintptr
	FxBusyHandler      uintptr
	FpBusyHandlerArg   uintptr
	FaStat             [4]int32
	FnRead             int32
	F__ccgo_pad4       [4]byte
	FxReiniter         uintptr
	FxGet              uintptr
	FpTmpSpace         uintptr
	FpPCache           uintptr
	FpWal              uintptr
	FzWal              uintptr
}

type Pager = Pager1

type PgHdr2 = struct {
	FpPage       uintptr
	FpData       uintptr
	FpExtra      uintptr
	FpCache      uintptr
	FpDirty      uintptr
	FpPager      uintptr
	Fpgno        Pgno
	Fflags       U16
	F__ccgo_pad1 [2]byte
	FnRef        I64
	FpDirtyNext  uintptr
	FpDirtyPrev  uintptr
}

type DbPage = PgHdr2

type Btree1 = struct {
	Fdb             uintptr
	FpBt            uintptr
	FinTrans        U8
	Fsharable       U8
	Flocked         U8
	FhasIncrblobCur U8
	FwantToLock     int32
	FnBackup        int32
	FiBDataVersion  U32
	FpNext          uintptr
	FpPrev          uintptr
	Flock           BtLock
}

type Btree = Btree1
type BtCursor1 = struct {
	FeState        U8
	FcurFlags      U8
	FcurPagerFlags U8
	Fhints         U8
	FskipNext      int32
	FpBtree        uintptr
	FaOverflow     uintptr
	FpKey          uintptr
	FpBt           uintptr
	FpNext         uintptr
	Finfo          CellInfo
	FnKey          I64
	FpgnoRoot      Pgno
	FiPage         I8
	FcurIntKey     U8
	Fix            U16
	FaiIdx         [19]U16
	F__ccgo_pad1   [2]byte
	FpKeyInfo      uintptr
	FpPage         uintptr
	FapPage        [19]uintptr
}

type BtCursor = BtCursor1
type BtShared1 = struct {
	FpPager          uintptr
	Fdb              uintptr
	FpCursor         uintptr
	FpPage1          uintptr
	FopenFlags       U8
	FautoVacuum      U8
	FincrVacuum      U8
	FbDoTruncate     U8
	FinTransaction   U8
	Fmax1bytePayload U8
	FnReserveWanted  U8
	F__ccgo_pad1     [1]byte
	FbtsFlags        U16
	FmaxLocal        U16
	FminLocal        U16
	FmaxLeaf         U16
	FminLeaf         U16
	F__ccgo_pad2     [2]byte
	FpageSize        U32
	FusableSize      U32
	FnTransaction    int32
	FnPage           U32
	F__ccgo_pad3     [4]byte
	FpSchema         uintptr
	FxFreeSchema     uintptr
	Fmutex           uintptr
	FpHasContent     uintptr
	FnRef            int32
	F__ccgo_pad4     [4]byte
	FpNext           uintptr
	FpLock           uintptr
	FpWriter         uintptr
	FpTmpSpace       uintptr
	FnPreformatSize  int32
	F__ccgo_pad5     [4]byte
}

type BtShared = BtShared1
type BtreePayload1 = struct {
	FpKey        uintptr
	FnKey        Sqlite3_int64
	FpData       uintptr
	FaMem        uintptr
	FnMem        U16
	F__ccgo_pad1 [2]byte
	FnData       int32
	FnZero       int32
	F__ccgo_pad2 [4]byte
}

type BtreePayload = BtreePayload1

type Vdbe1 = struct {
	Fdb                 uintptr
	FppVPrev            uintptr
	FpVNext             uintptr
	FpParse             uintptr
	FnVar               YnVar
	F__ccgo_pad1        [2]byte
	FnMem               int32
	FnCursor            int32
	FcacheCtr           U32
	Fpc                 int32
	Frc                 int32
	FnChange            I64
	FiStatement         int32
	F__ccgo_pad2        [4]byte
	FiCurrentTime       I64
	FnFkConstraint      I64
	FnStmtDefCons       I64
	FnStmtDefImmCons    I64
	FaMem               uintptr
	FapArg              uintptr
	FapCsr              uintptr
	FaVar               uintptr
	FaOp                uintptr
	FnOp                int32
	FnOpAlloc           int32
	FaColName           uintptr
	FpResultRow         uintptr
	FzErrMsg            uintptr
	FpVList             uintptr
	FstartTime          I64
	FnResColumn         U16
	FerrorAction        U8
	FminWriteFileFormat U8
	FprepFlags          U8
	FeVdbeState         U8
	F__ccgo_pad3        [2]byte
	Fexpired            uint8
	F__ccgo_pad4        [3]byte
	FbtreeMask          YDbMask
	FlockMask           YDbMask
	FaCounter           [9]U32
	FzSql               uintptr
	FpFree              uintptr
	FpFrame             uintptr
	FpDelFrame          uintptr
	FnFrame             int32
	Fexpmask            U32
	FpProgram           uintptr
	FpAuxData           uintptr
}

type Vdbe = Vdbe1

type Mem = sqlite3_value
type SubProgram1 = struct {
	FaOp         uintptr
	FnOp         int32
	FnMem        int32
	FnCsr        int32
	F__ccgo_pad1 [4]byte
	FaOnce       uintptr
	Ftoken       uintptr
	FpNext       uintptr
}

type SubProgram = SubProgram1

type VdbeOp1 = struct {
	Fopcode U8
	Fp4type int8
	Fp5     U16
	Fp1     int32
	Fp2     int32
	Fp3     int32
	Fp4     struct {
		F__ccgo_pad1 [0]uint64
		Fi           int32
		F__ccgo_pad2 [4]byte
	}
	FzComment uintptr
}

type p4union = struct {
	F__ccgo_pad1 [0]uint64
	Fi           int32
	F__ccgo_pad2 [4]byte
}

type VdbeOp = VdbeOp1

type VdbeOpList1 = struct {
	Fopcode U8
	Fp1     int8
	Fp2     int8
	Fp3     int8
}

type VdbeOpList = VdbeOpList1

type RecordCompare = uintptr

type PgHdr = PgHdr2
type PCache2 = struct {
	FpDirty      uintptr
	FpDirtyTail  uintptr
	FpSynced     uintptr
	FnRefSum     I64
	FszCache     int32
	FszSpill     int32
	FszPage      int32
	FszExtra     int32
	FbPurgeable  U8
	FeCreate     U8
	F__ccgo_pad1 [6]byte
	FxStress     uintptr
	FpStress     uintptr
	FpCache      uintptr
}

type PCache = PCache2

type Sqlite3_xauth = uintptr

type sqlite3InitInfo = struct {
	FnewTnum       Pgno
	FiDb           U8
	Fbusy          U8
	F__ccgo_pad1   [2]byte
	ForphanTrigger uint8
	F__ccgo_pad2   [7]byte
	FazInit        uintptr
}

type sColMap = struct {
	FiFrom       int32
	F__ccgo_pad1 [4]byte
	FzCol        uintptr
}

type AggInfo_col = struct {
	FpTab          uintptr
	FpCExpr        uintptr
	FiTable        int32
	FiColumn       I16
	FiSorterColumn I16
}

type AggInfo_func = struct {
	FpFExpr    uintptr
	FpFunc     uintptr
	FiDistinct int32
	FiDistAddr int32
}

type YnVar = I16

type ExprList_item = struct {
	FpExpr  uintptr
	FzEName uintptr
	Ffg     struct {
		F__ccgo_pad1 [0]uint32
		FsortFlags   U8
		F__ccgo_pad2 [3]byte
		FeEName      uint16
		F__ccgo_pad3 [2]byte
	}
	Fu struct {
		F__ccgo_pad1 [0]uint32
		Fx           struct {
			FiOrderByCol U16
			FiAlias      U16
		}
	}
	F__ccgo_pad1 [4]byte
}

type IdList_item = struct {
	FzName uintptr
	Fu4    struct {
		F__ccgo_pad1 [0]uint64
		Fidx         int32
		F__ccgo_pad2 [4]byte
	}
}

type YDbMask = uint32

type InitData = struct {
	Fdb          uintptr
	FpzErrMsg    uintptr
	FiDb         int32
	Frc          int32
	FmInitFlags  U32
	FnInitRow    U32
	FmxPage      Pgno
	F__ccgo_pad1 [4]byte
}

type Sqlite3Config = struct {
	FbMemstat            int32
	FbCoreMutex          U8
	FbFullMutex          U8
	FbOpenUri            U8
	FbUseCis             U8
	FbSmallMalloc        U8
	FbExtraSchemaChecks  U8
	F__ccgo_pad1         [2]byte
	FmxStrlen            int32
	FneverCorrupt        int32
	FszLookaside         int32
	FnLookaside          int32
	FnStmtSpill          int32
	Fm                   Sqlite3_mem_methods
	Fmutex               Sqlite3_mutex_methods
	Fpcache2             Sqlite3_pcache_methods2
	FpHeap               uintptr
	FnHeap               int32
	FmnReq               int32
	FmxReq               int32
	F__ccgo_pad2         [4]byte
	FszMmap              Sqlite3_int64
	FmxMmap              Sqlite3_int64
	FpPage               uintptr
	FszPage              int32
	FnPage               int32
	FmxParserStack       int32
	FsharedCacheEnabled  int32
	FszPma               U32
	FisInit              int32
	FinProgress          int32
	FisMutexInit         int32
	FisMallocInit        int32
	FisPCacheInit        int32
	FnRefInitMutex       int32
	F__ccgo_pad3         [4]byte
	FpInitMutex          uintptr
	FxLog                uintptr
	FpLogArg             uintptr
	FmxMemdbSize         Sqlite3_int64
	FxTestCallback       uintptr
	FbLocaltimeFault     int32
	F__ccgo_pad4         [4]byte
	FxAltLocaltime       uintptr
	FiOnceResetThreshold int32
	FszSorterRef         U32
	FiPrngSeed           uint32
	F__ccgo_pad5         [4]byte
}

type RefSrcList = struct {
	Fdb        uintptr
	FpRef      uintptr
	FnExclude  I64
	FaiExclude uintptr
}

type IdxCover = struct {
	FpIdx        uintptr
	FiCur        int32
	F__ccgo_pad1 [4]byte
}

type WindowRewrite1 = struct {
	FpWin       uintptr
	FpSrc       uintptr
	FpSub       uintptr
	FpTab       uintptr
	FpSubSelect uintptr
}

type WhereConst1 = struct {
	FpParse      uintptr
	FpOomFault   uintptr
	FnConst      int32
	FnChng       int32
	FbHasAffBlob int32
	FmExcludeOn  U32
	FapExpr      uintptr
}

type RenameCtx1 = struct {
	FpList uintptr
	FnList int32
	FiCol  int32
	FpTab  uintptr
	FzOld  uintptr
}

type CoveringIndexCheck1 = struct {
	FpIdx        uintptr
	FiTabCur     int32
	FbExpr       U8
	FbUnidx      U8
	F__ccgo_pad1 [2]byte
}

func local_ioerr(tls *libc.TLS) {
	Xsqlite3_io_error_hit++
	if !(Xsqlite3_io_error_benign != 0) {
		Xsqlite3_io_error_hardhit++
	}
}

var sqlite3azCompileOpt = [57]uintptr{
	ts + 7,
	ts + 27,
	ts + 56,
	ts + 75,
	ts + 100,
	ts + 122,
	ts + 152,
	ts + 172,
	ts + 195,
	ts + 220,
	ts + 247,
	ts + 272,
	ts + 294,
	ts + 326,
	ts + 352,
	ts + 377,
	ts + 398,
	ts + 421,
	ts + 440,
	ts + 459,
	ts + 483,
	ts + 495,
	ts + 510,
	ts + 532,
	ts + 557,
	ts + 580,
	ts + 602,
	ts + 613,
	ts + 626,
	ts + 641,
	ts + 654,
	ts + 670,
	ts + 691,
	ts + 715,
	ts + 738,
	ts + 754,
	ts + 770,
	ts + 794,
	ts + 821,
	ts + 841,
	ts + 862,
	ts + 884,
	ts + 914,
	ts + 939,
	ts + 965,
	ts + 985,
	ts + 1011,
	ts + 1034,
	ts + 1060,
	ts + 1082,
	ts + 1103,
	ts + 1114,
	ts + 1128,
	ts + 1136,
	ts + 1150,
	ts + 1163,
	ts + 1168,
}

func Xsqlite3CompileOptions(tls *libc.TLS, pnOpt uintptr) uintptr {
	*(*int32)(unsafe.Pointer(pnOpt)) = int32(uint64(unsafe.Sizeof(sqlite3azCompileOpt)) / uint64(unsafe.Sizeof(uintptr(0))))
	return uintptr(unsafe.Pointer(&sqlite3azCompileOpt))
}

var Xsqlite3UpperToLower = [274]uint8{
	uint8(0), uint8(1), uint8(2), uint8(3), uint8(4), uint8(5), uint8(6), uint8(7), uint8(8), uint8(9), uint8(10), uint8(11), uint8(12), uint8(13), uint8(14), uint8(15), uint8(16), uint8(17),
	uint8(18), uint8(19), uint8(20), uint8(21), uint8(22), uint8(23), uint8(24), uint8(25), uint8(26), uint8(27), uint8(28), uint8(29), uint8(30), uint8(31), uint8(32), uint8(33), uint8(34), uint8(35),
	uint8(36), uint8(37), uint8(38), uint8(39), uint8(40), uint8(41), uint8(42), uint8(43), uint8(44), uint8(45), uint8(46), uint8(47), uint8(48), uint8(49), uint8(50), uint8(51), uint8(52), uint8(53),
	uint8(54), uint8(55), uint8(56), uint8(57), uint8(58), uint8(59), uint8(60), uint8(61), uint8(62), uint8(63), uint8(64), uint8(97), uint8(98), uint8(99), uint8(100), uint8(101), uint8(102), uint8(103),
	uint8(104), uint8(105), uint8(106), uint8(107), uint8(108), uint8(109), uint8(110), uint8(111), uint8(112), uint8(113), uint8(114), uint8(115), uint8(116), uint8(117), uint8(118), uint8(119), uint8(120), uint8(121),
	uint8(122), uint8(91), uint8(92), uint8(93), uint8(94), uint8(95), uint8(96), uint8(97), uint8(98), uint8(99), uint8(100), uint8(101), uint8(102), uint8(103), uint8(104), uint8(105), uint8(106), uint8(107),
	uint8(108), uint8(109), uint8(110), uint8(111), uint8(112), uint8(113), uint8(114), uint8(115), uint8(116), uint8(117), uint8(118), uint8(119), uint8(120), uint8(121), uint8(122), uint8(123), uint8(124), uint8(125),
	uint8(126), uint8(127), uint8(128), uint8(129), uint8(130), uint8(131), uint8(132), uint8(133), uint8(134), uint8(135), uint8(136), uint8(137), uint8(138), uint8(139), uint8(140), uint8(141), uint8(142), uint8(143),
	uint8(144), uint8(145), uint8(146), uint8(147), uint8(148), uint8(149), uint8(150), uint8(151), uint8(152), uint8(153), uint8(154), uint8(155), uint8(156), uint8(157), uint8(158), uint8(159), uint8(160), uint8(161),
	uint8(162), uint8(163), uint8(164), uint8(165), uint8(166), uint8(167), uint8(168), uint8(169), uint8(170), uint8(171), uint8(172), uint8(173), uint8(174), uint8(175), uint8(176), uint8(177), uint8(178), uint8(179),
	uint8(180), uint8(181), uint8(182), uint8(183), uint8(184), uint8(185), uint8(186), uint8(187), uint8(188), uint8(189), uint8(190), uint8(191), uint8(192), uint8(193), uint8(194), uint8(195), uint8(196), uint8(197),
	uint8(198), uint8(199), uint8(200), uint8(201), uint8(202), uint8(203), uint8(204), uint8(205), uint8(206), uint8(207), uint8(208), uint8(209), uint8(210), uint8(211), uint8(212), uint8(213), uint8(214), uint8(215),
	uint8(216), uint8(217), uint8(218), uint8(219), uint8(220), uint8(221), uint8(222), uint8(223), uint8(224), uint8(225), uint8(226), uint8(227), uint8(228), uint8(229), uint8(230), uint8(231), uint8(232), uint8(233),
	uint8(234), uint8(235), uint8(236), uint8(237), uint8(238), uint8(239), uint8(240), uint8(241), uint8(242), uint8(243), uint8(244), uint8(245), uint8(246), uint8(247), uint8(248), uint8(249), uint8(250), uint8(251),
	uint8(252), uint8(253), uint8(254), uint8(255),
	uint8(1), uint8(0), uint8(0), uint8(1), uint8(1), uint8(0),
	uint8(0), uint8(1), uint8(0), uint8(1), uint8(0), uint8(1),
	uint8(1), uint8(0), uint8(1), uint8(0), uint8(0), uint8(1),
}
var Xsqlite3aLTb uintptr = 0
var Xsqlite3aEQb uintptr = 0
var Xsqlite3aGTb uintptr = 0

var Xsqlite3CtypeMap = [256]uint8{
	uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00),
	uint8(0x00), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x00), uint8(0x00),
	uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00),
	uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00),
	uint8(0x01), uint8(0x00), uint8(0x80), uint8(0x00), uint8(0x40), uint8(0x00), uint8(0x00), uint8(0x80),
	uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00),
	uint8(0x0c), uint8(0x0c), uint8(0x0c), uint8(0x0c), uint8(0x0c), uint8(0x0c), uint8(0x0c), uint8(0x0c),
	uint8(0x0c), uint8(0x0c), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00),
	uint8(0x00), uint8(0x0a), uint8(0x0a), uint8(0x0a), uint8(0x0a), uint8(0x0a), uint8(0x0a), uint8(0x02),
	uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02),
	uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x02),
	uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x80), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x40),
	uint8(0x80), uint8(0x2a), uint8(0x2a), uint8(0x2a), uint8(0x2a), uint8(0x2a), uint8(0x2a), uint8(0x22),
	uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22),
	uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x22),
	uint8(0x22), uint8(0x22), uint8(0x22), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
	uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40), uint8(0x40),
}

var Xsqlite3Config = Sqlite3Config{
	FbMemstat:           SQLITE_DEFAULT_MEMSTATUS,
	FbCoreMutex:         U8(1),
	FbFullMutex:         U8(libc.Bool32(SQLITE_THREADSAFE == 1)),
	FbUseCis:            U8(SQLITE_ALLOW_COVERING_INDEX_SCAN),
	FbExtraSchemaChecks: U8(1),
	FmxStrlen:           0x7ffffffe,
	FszLookaside:        1200, FnLookaside: 40,
	FnStmtSpill:          64 * 1024,
	FmxMmap:              int64(SQLITE_MAX_MMAP_SIZE),
	FnPage:               SQLITE_DEFAULT_PCACHE_INITSZ,
	FszPma:               U32(SQLITE_SORTER_PMASZ),
	FmxMemdbSize:         int64(SQLITE_MEMDB_DEFAULT_MAXSIZE),
	FiOnceResetThreshold: 0x7ffffffe,
	FszSorterRef:         U32(SQLITE_DEFAULT_SORTERREF_SIZE),
}

var Xsqlite3BuiltinFunctions FuncDefHash

var Xsqlite3PendingByte int32 = 0x40000000

var Xsqlite3TreeTrace U32 = U32(0)
var Xsqlite3WhereTrace U32 = U32(0)

var Xsqlite3OpcodeProperty = [187]uint8{uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x10), uint8(0x00), uint8(0x41), uint8(0x00), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x03), uint8(0x03), uint8(0x01), uint8(0x01), uint8(0x03), uint8(0x03), uint8(0x01), uint8(0x12), uint8(0x01), uint8(0x49), uint8(0x49), uint8(0x49), uint8(0x49), uint8(0x01), uint8(0x49), uint8(0x49), uint8(0x49), uint8(0x49), uint8(0x49), uint8(0x49), uint8(0x41), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x41), uint8(0x01), uint8(0x41), uint8(0x41), uint8(0x41), uint8(0x41), uint8(0x41), uint8(0x26), uint8(0x26), uint8(0x41), uint8(0x23), uint8(0x0b), uint8(0x01), uint8(0x01), uint8(0x03), uint8(0x03), uint8(0x0b), uint8(0x0b), uint8(0x0b), uint8(0x0b), uint8(0x0b), uint8(0x0b), uint8(0x01), uint8(0x03), uint8(0x03), uint8(0x03), uint8(0x01), uint8(0x41), uint8(0x01), uint8(0x00), uint8(0x00), uint8(0x02), uint8(0x02), uint8(0x08), uint8(0x00), uint8(0x10), uint8(0x10), uint8(0x10), uint8(0x00), uint8(0x10), uint8(0x00), uint8(0x10), uint8(0x10), uint8(0x00), uint8(0x00), uint8(0x10), uint8(0x10), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x02), uint8(0x02), uint8(0x02), uint8(0x00), uint8(0x00), uint8(0x12), uint8(0x1e), uint8(0x20), uint8(0x40), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x10), uint8(0x10), uint8(0x00), uint8(0x40), uint8(0x26), uint8(0x26), uint8(0x26), uint8(0x26), uint8(0x26), uint8(0x26), uint8(0x26), uint8(0x26), uint8(0x26), uint8(0x26), uint8(0x40), uint8(0x00), uint8(0x12), uint8(0x40), uint8(0x40), uint8(0x10), uint8(0x40), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x40), uint8(0x00), uint8(0x40), uint8(0x40), uint8(0x10), uint8(0x10), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x50), uint8(0x00), uint8(0x40), uint8(0x04), uint8(0x04), uint8(0x00), uint8(0x40), uint8(0x50), uint8(0x40), uint8(0x10), uint8(0x00), uint8(0x00), uint8(0x10), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x10), uint8(0x00), uint8(0x00), uint8(0x06), uint8(0x10), uint8(0x00), uint8(0x04), uint8(0x1a), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x40), uint8(0x50), uint8(0x40), uint8(0x00), uint8(0x10), uint8(0x10), uint8(0x02), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00), uint8(0x00)}

var Xsqlite3StrBINARY = *(*[7]uint8)(unsafe.Pointer(ts + 1181))

var Xsqlite3StdTypeLen = [6]uint8{uint8(3), uint8(4), uint8(3), uint8(7), uint8(4), uint8(4)}
var Xsqlite3StdTypeAffinity = [6]uint8{
	uint8(SQLITE_AFF_NUMERIC),
	uint8(SQLITE_AFF_BLOB),
	uint8(SQLITE_AFF_INTEGER),
	uint8(SQLITE_AFF_INTEGER),
	uint8(SQLITE_AFF_REAL),
	uint8(SQLITE_AFF_TEXT),
}
var Xsqlite3StdType = [6]uintptr{
	ts + 1188,
	ts + 1192,
	ts + 1197,
	ts + 1201,
	ts + 1209,
	ts + 1214,
}

type Op = VdbeOp1

type Bool = uint32

type VdbeSorter1 = struct {
	FmnPmaSize   int32
	FmxPmaSize   int32
	FmxKeysize   int32
	Fpgsz        int32
	FpReader     uintptr
	FpMerger     uintptr
	Fdb          uintptr
	FpKeyInfo    uintptr
	FpUnpacked   uintptr
	Flist        SorterList
	FiMemory     int32
	FnMemory     int32
	FbUsePMA     U8
	FbUseThreads U8
	FiPrev       U8
	FnTask       U8
	FtypeMask    U8
	F__ccgo_pad1 [3]byte
	FaTask       [1]SortSubtask
}

type VdbeSorter = VdbeSorter1

type AuxData1 = struct {
	FiAuxOp     int32
	FiAuxArg    int32
	FpAux       uintptr
	FxDeleteAux uintptr
	FpNextAux   uintptr
}

type AuxData = AuxData1

type VdbeCursor1 = struct {
	FeCurType       U8
	FiDb            I8
	FnullRow        U8
	FdeferredMoveto U8
	FisTable        U8
	F__ccgo_pad1    [3]byte
	FisEphemeral    uint8
	F__ccgo_pad2    [1]byte
	FseekHit        U16
	F__ccgo_pad3    [4]byte
	Fub             struct{ FpBtx uintptr }
	FseqCount       I64
	FcacheStatus    U32
	FseekResult     int32
	FpAltCursor     uintptr
	Fuc             struct{ FpCursor uintptr }
	FpKeyInfo       uintptr
	FiHdrOffset     U32
	FpgnoRoot       Pgno
	FnField         I16
	FnHdrParsed     U16
	F__ccgo_pad4    [4]byte
	FmovetoTarget   I64
	FaOffset        uintptr
	FaRow           uintptr
	FpayloadSize    U32
	FszRow          U32
	FaType          [1]U32
	F__ccgo_pad5    [4]byte
}

type VdbeCursor = VdbeCursor1

type VdbeFrame1 = struct {
	Fv         uintptr
	FpParent   uintptr
	FaOp       uintptr
	FaMem      uintptr
	FapCsr     uintptr
	FaOnce     uintptr
	Ftoken     uintptr
	FlastRowid I64
	FpAuxData  uintptr
	FnCursor   int32
	Fpc        int32
	FnOp       int32
	FnMem      int32
	FnChildMem int32
	FnChildCsr int32
	FnChange   I64
	FnDbChange I64
}

type VdbeFrame = VdbeFrame1

type MemValue = struct{ Fr float64 }

type Bft = uint32

type ScanStatus1 = struct {
	FaddrExplain int32
	FaAddrRange  [6]int32
	FaddrLoop    int32
	FaddrVisit   int32
	FiSelectID   int32
	FnEst        LogEst
	F__ccgo_pad1 [6]byte
	FzName       uintptr
}

type ScanStatus = ScanStatus1

type DblquoteStr1 = struct {
	FpNextStr uintptr
	Fz        [8]uint8
}

type DblquoteStr = DblquoteStr1

type ValueList1 = struct {
	FpCsr uintptr
	FpOut uintptr
}

type ValueList = ValueList1

type Sqlite3StatValueType = Sqlite3_int64
type sqlite3StatType = struct {
	FnowValue [10]Sqlite3StatValueType
	FmxValue  [10]Sqlite3StatValueType
}

type Sqlite3StatType = sqlite3StatType

var sqlite3Stat = sqlite3StatType{}

var statMutex = [10]uint8{
	uint8(0),
	uint8(1),
	uint8(1),
	uint8(0),
	uint8(0),
	uint8(0),
	uint8(0),
	uint8(1),
	uint8(0),
	uint8(0),
}

func Xsqlite3StatusValue(tls *libc.TLS, op int32) Sqlite3_int64 {
	return *(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + uintptr(op)*8))
}

func Xsqlite3StatusUp(tls *libc.TLS, op int32, N int32) {
	*(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + uintptr(op)*8)) += Sqlite3StatValueType(N)
	if *(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + uintptr(op)*8)) > *(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + 80 + uintptr(op)*8)) {
		*(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + 80 + uintptr(op)*8)) = *(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + uintptr(op)*8))
	}
}

func Xsqlite3StatusDown(tls *libc.TLS, op int32, N int32) {
	*(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + uintptr(op)*8)) -= Sqlite3StatValueType(N)
}

func Xsqlite3StatusHighwater(tls *libc.TLS, op int32, X int32) {
	var newValue Sqlite3StatValueType

	newValue = Sqlite3StatValueType(X)

	if newValue > *(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + 80 + uintptr(op)*8)) {
		*(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + 80 + uintptr(op)*8)) = newValue
	}
}

func Xsqlite3_status64(tls *libc.TLS, op int32, pCurrent uintptr, pHighwater uintptr, resetFlag int32) int32 {
	var pMutex uintptr
	_ = pMutex

	if op < 0 || op >= int32(uint64(unsafe.Sizeof([10]Sqlite3StatValueType{}))/uint64(unsafe.Sizeof(Sqlite3StatValueType(0)))) {
		return Xsqlite3MisuseError(tls, 23233)
	}
	if statMutex[op] != 0 {
		pMutex = Xsqlite3Pcache1Mutex(tls)
	} else {
		pMutex = Xsqlite3MallocMutex(tls)
	}
	Xsqlite3_mutex_enter(tls, pMutex)
	*(*Sqlite3_int64)(unsafe.Pointer(pCurrent)) = *(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + uintptr(op)*8))
	*(*Sqlite3_int64)(unsafe.Pointer(pHighwater)) = *(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + 80 + uintptr(op)*8))
	if resetFlag != 0 {
		*(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + 80 + uintptr(op)*8)) = *(*Sqlite3StatValueType)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Stat)) + uintptr(op)*8))
	}
	Xsqlite3_mutex_leave(tls, pMutex)
	_ = pMutex
	return SQLITE_OK
}

func Xsqlite3_status(tls *libc.TLS, op int32, pCurrent uintptr, pHighwater uintptr, resetFlag int32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	*(*Sqlite3_int64)(unsafe.Pointer(bp)) = int64(0)
	*(*Sqlite3_int64)(unsafe.Pointer(bp + 8)) = int64(0)
	var rc int32
	rc = Xsqlite3_status64(tls, op, bp, bp+8, resetFlag)
	if rc == 0 {
		*(*int32)(unsafe.Pointer(pCurrent)) = int32(*(*Sqlite3_int64)(unsafe.Pointer(bp)))
		*(*int32)(unsafe.Pointer(pHighwater)) = int32(*(*Sqlite3_int64)(unsafe.Pointer(bp + 8)))
	}
	return rc
}

func countLookasideSlots(tls *libc.TLS, p uintptr) U32 {
	var cnt U32 = U32(0)
	for p != 0 {
		p = (*LookasideSlot)(unsafe.Pointer(p)).FpNext
		cnt++
	}
	return cnt
}

func Xsqlite3LookasideUsed(tls *libc.TLS, db uintptr, pHighwater uintptr) int32 {
	var nInit U32 = countLookasideSlots(tls, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpInit)
	var nFree U32 = countLookasideSlots(tls, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree)
	nInit = nInit + countLookasideSlots(tls, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit)
	nFree = nFree + countLookasideSlots(tls, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree)
	if pHighwater != 0 {
		*(*int32)(unsafe.Pointer(pHighwater)) = int32((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FnSlot - nInit)
	}
	return int32((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FnSlot - (nInit + nFree))
}

func Xsqlite3_db_status(tls *libc.TLS, db uintptr, op int32, pCurrent uintptr, pHighwater uintptr, resetFlag int32) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var rc int32 = SQLITE_OK
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	{
		switch op {
		case SQLITE_DBSTATUS_LOOKASIDE_USED:
			{
				*(*int32)(unsafe.Pointer(pCurrent)) = Xsqlite3LookasideUsed(tls, db, pHighwater)
				if resetFlag != 0 {
					var p uintptr = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
					if p != 0 {
						for (*LookasideSlot)(unsafe.Pointer(p)).FpNext != 0 {
							p = (*LookasideSlot)(unsafe.Pointer(p)).FpNext
						}
						(*LookasideSlot)(unsafe.Pointer(p)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpInit
						(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpInit = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
						(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = uintptr(0)
					}
					p = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
					if p != 0 {
						for (*LookasideSlot)(unsafe.Pointer(p)).FpNext != 0 {
							p = (*LookasideSlot)(unsafe.Pointer(p)).FpNext
						}
						(*LookasideSlot)(unsafe.Pointer(p)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit
						(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
						(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = uintptr(0)
					}
				}
				break

			}

		case SQLITE_DBSTATUS_LOOKASIDE_HIT:
			fallthrough
		case SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE:
			fallthrough
		case SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL:
			{
				*(*int32)(unsafe.Pointer(pCurrent)) = 0
				*(*int32)(unsafe.Pointer(pHighwater)) = int32(*(*U32)(unsafe.Pointer(db + 440 + 16 + uintptr(op-SQLITE_DBSTATUS_LOOKASIDE_HIT)*4)))
				if resetFlag != 0 {
					*(*U32)(unsafe.Pointer(db + 440 + 16 + uintptr(op-SQLITE_DBSTATUS_LOOKASIDE_HIT)*4)) = U32(0)
				}
				break

			}

		case SQLITE_DBSTATUS_CACHE_USED_SHARED:
			fallthrough
		case SQLITE_DBSTATUS_CACHE_USED:
			{
				var totalUsed int32 = 0
				var i int32
				Xsqlite3BtreeEnterAll(tls, db)
				for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
					var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
					if pBt != 0 {
						var pPager uintptr = Xsqlite3BtreePager(tls, pBt)
						var nByte int32 = Xsqlite3PagerMemUsed(tls, pPager)
						if op == SQLITE_DBSTATUS_CACHE_USED_SHARED {
							nByte = nByte / Xsqlite3BtreeConnectionCount(tls, pBt)
						}
						totalUsed = totalUsed + nByte
					}
				}
				Xsqlite3BtreeLeaveAll(tls, db)
				*(*int32)(unsafe.Pointer(pCurrent)) = totalUsed
				*(*int32)(unsafe.Pointer(pHighwater)) = 0
				break

			}

		case SQLITE_DBSTATUS_SCHEMA_USED:
			{
				var i int32
				*(*int32)(unsafe.Pointer(bp)) = 0

				Xsqlite3BtreeEnterAll(tls, db)
				(*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed = bp

				(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart
				for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
					var pSchema uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpSchema
					if pSchema != uintptr(0) {
						var p uintptr

						*(*int32)(unsafe.Pointer(bp)) += int32(uint32((*struct{ f func(*libc.TLS, int32) int32 })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxRoundup})).f(tls, int32(unsafe.Sizeof(HashElem{})))) * ((*Schema)(unsafe.Pointer(pSchema)).FtblHash.Fcount +
							(*Schema)(unsafe.Pointer(pSchema)).FtrigHash.Fcount +
							(*Schema)(unsafe.Pointer(pSchema)).FidxHash.Fcount +
							(*Schema)(unsafe.Pointer(pSchema)).FfkeyHash.Fcount))
						*(*int32)(unsafe.Pointer(bp)) += int32(Xsqlite3_msize(tls, (*Schema)(unsafe.Pointer(pSchema)).FtblHash.Fht))
						*(*int32)(unsafe.Pointer(bp)) += int32(Xsqlite3_msize(tls, (*Schema)(unsafe.Pointer(pSchema)).FtrigHash.Fht))
						*(*int32)(unsafe.Pointer(bp)) += int32(Xsqlite3_msize(tls, (*Schema)(unsafe.Pointer(pSchema)).FidxHash.Fht))
						*(*int32)(unsafe.Pointer(bp)) += int32(Xsqlite3_msize(tls, (*Schema)(unsafe.Pointer(pSchema)).FfkeyHash.Fht))

						for p = (*Hash)(unsafe.Pointer(pSchema + 56)).Ffirst; p != 0; p = (*HashElem)(unsafe.Pointer(p)).Fnext {
							Xsqlite3DeleteTrigger(tls, db, (*HashElem)(unsafe.Pointer(p)).Fdata)
						}
						for p = (*Hash)(unsafe.Pointer(pSchema + 8)).Ffirst; p != 0; p = (*HashElem)(unsafe.Pointer(p)).Fnext {
							Xsqlite3DeleteTable(tls, db, (*HashElem)(unsafe.Pointer(p)).Fdata)
						}
					}
				}
				(*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed = uintptr(0)
				(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd
				Xsqlite3BtreeLeaveAll(tls, db)

				*(*int32)(unsafe.Pointer(pHighwater)) = 0
				*(*int32)(unsafe.Pointer(pCurrent)) = *(*int32)(unsafe.Pointer(bp))
				break

			}

		case SQLITE_DBSTATUS_STMT_USED:
			{
				var pVdbe uintptr
				*(*int32)(unsafe.Pointer(bp + 4)) = 0

				(*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed = bp + 4

				(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart
				for pVdbe = (*Sqlite3)(unsafe.Pointer(db)).FpVdbe; pVdbe != 0; pVdbe = (*Vdbe1)(unsafe.Pointer(pVdbe)).FpVNext {
					Xsqlite3VdbeDelete(tls, pVdbe)
				}
				(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd
				(*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed = uintptr(0)

				*(*int32)(unsafe.Pointer(pHighwater)) = 0
				*(*int32)(unsafe.Pointer(pCurrent)) = *(*int32)(unsafe.Pointer(bp + 4))

				break

			}

		case SQLITE_DBSTATUS_CACHE_SPILL:
			op = SQLITE_DBSTATUS_CACHE_WRITE + 1
			fallthrough
		case SQLITE_DBSTATUS_CACHE_HIT:
			fallthrough
		case SQLITE_DBSTATUS_CACHE_MISS:
			fallthrough
		case SQLITE_DBSTATUS_CACHE_WRITE:
			{
				var i int32
				*(*int32)(unsafe.Pointer(bp + 8)) = 0

				for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
					if (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpBt != 0 {
						var pPager uintptr = Xsqlite3BtreePager(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpBt)
						Xsqlite3PagerCacheStat(tls, pPager, op, resetFlag, bp+8)
					}
				}
				*(*int32)(unsafe.Pointer(pHighwater)) = 0

				*(*int32)(unsafe.Pointer(pCurrent)) = *(*int32)(unsafe.Pointer(bp + 8))
				break

			}

		case SQLITE_DBSTATUS_DEFERRED_FKS:
			{
				*(*int32)(unsafe.Pointer(pHighwater)) = 0
				*(*int32)(unsafe.Pointer(pCurrent)) = libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons > int64(0) || (*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons > int64(0))
				break

			}

		default:
			{
				rc = SQLITE_ERROR

			}
		}
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

type timex = struct {
	Fmodes       uint32
	F__ccgo_pad1 [4]byte
	Foffset      X__syscall_slong_t
	Ffreq        X__syscall_slong_t
	Fmaxerror    X__syscall_slong_t
	Festerror    X__syscall_slong_t
	Fstatus      int32
	F__ccgo_pad2 [4]byte
	Fconstant    X__syscall_slong_t
	Fprecision   X__syscall_slong_t
	Ftolerance   X__syscall_slong_t
	Ftime        struct {
		Ftv_sec  X__time_t
		Ftv_usec X__suseconds_t
	}
	Ftick        X__syscall_slong_t
	Fppsfreq     X__syscall_slong_t
	Fjitter      X__syscall_slong_t
	Fshift       int32
	F__ccgo_pad3 [4]byte
	Fstabil      X__syscall_slong_t
	Fjitcnt      X__syscall_slong_t
	Fcalcnt      X__syscall_slong_t
	Ferrcnt      X__syscall_slong_t
	Fstbcnt      X__syscall_slong_t
	Ftai         int32
	__164        uint32
	__168        uint32
	__172        uint32
	__176        uint32
	__180        uint32
	__184        uint32
	__188        uint32
	__192        uint32
	__196        uint32
	__200        uint32
	__204        uint32
}

type tm = 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
	F__ccgo_pad1 [4]byte
	Ftm_gmtoff   int64
	Ftm_zone     uintptr
}

type itimerspec = struct {
	Fit_interval struct {
		Ftv_sec  X__time_t
		Ftv_nsec X__syscall_slong_t
	}
	Fit_value struct {
		Ftv_sec  X__time_t
		Ftv_nsec X__syscall_slong_t
	}
}

type DateTime1 = struct {
	FiJD         Sqlite3_int64
	FY           int32
	FM           int32
	FD           int32
	Fh           int32
	Fm           int32
	Ftz          int32
	Fs           float64
	FvalidJD     uint8
	FrawS        uint8
	FvalidYMD    uint8
	FvalidHMS    uint8
	FvalidTZ     uint8
	FtzSet       uint8
	FisError     uint8
	F__ccgo_pad1 [1]byte
}

type DateTime = DateTime1

func getDigits(tls *libc.TLS, zDate uintptr, zFormat uintptr, va uintptr) int32 {
	var ap Va_list
	_ = ap
	var cnt int32
	var nextC uint8
	var N uint8
	var min uint8
	var val int32
	var max U16
	cnt = 0
	ap = va
__1:
	N = uint8(int32(*(*uint8)(unsafe.Pointer(zFormat))) - '0')
	min = uint8(int32(*(*uint8)(unsafe.Pointer(zFormat + 1))) - '0')
	val = 0

	max = aMx[int32(*(*uint8)(unsafe.Pointer(zFormat + 2)))-'a']
	nextC = *(*uint8)(unsafe.Pointer(zFormat + 3))
	val = 0
__4:
	if !(libc.PostDecUint8(&N, 1) != 0) {
		goto __5
	}
	if !!(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zDate))])&0x04 != 0) {
		goto __6
	}
	goto end_getDigits
__6:
	;
	val = val*10 + int32(*(*uint8)(unsafe.Pointer(zDate))) - '0'
	zDate++
	goto __4
__5:
	;
	if !(val < int32(min) || val > int32(max) || int32(nextC) != 0 && int32(nextC) != int32(*(*uint8)(unsafe.Pointer(zDate)))) {
		goto __7
	}
	goto end_getDigits
__7:
	;
	*(*int32)(unsafe.Pointer(libc.VaUintptr(&ap))) = val
	zDate++
	cnt++
	zFormat += uintptr(4)
	goto __2
__2:
	if nextC != 0 {
		goto __1
	}
	goto __3
__3:
	;
end_getDigits:
	_ = ap
	return cnt
}

var aMx = [6]U16{U16(12), U16(14), U16(24), U16(31), U16(59), U16(9999)}

func parseTimezone(tls *libc.TLS, zDate uintptr, p uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var sgn int32

	var c int32
	sgn = 0
__1:
	if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zDate))])&0x01 != 0) {
		goto __2
	}
	zDate++
	goto __1
__2:
	;
	(*DateTime)(unsafe.Pointer(p)).Ftz = 0
	c = int32(*(*uint8)(unsafe.Pointer(zDate)))
	if !(c == '-') {
		goto __3
	}
	sgn = -1
	goto __4
__3:
	if !(c == '+') {
		goto __5
	}
	sgn = +1
	goto __6
__5:
	if !(c == 'Z' || c == 'z') {
		goto __7
	}
	zDate++
	goto zulu_time
	goto __8
__7:
	return libc.Bool32(c != 0)
__8:
	;
__6:
	;
__4:
	;
	zDate++
	if !(getDigits(tls, zDate, ts+1219, libc.VaList(bp, bp+16, bp+20)) != 2) {
		goto __9
	}
	return 1
__9:
	;
	zDate += uintptr(5)
	(*DateTime)(unsafe.Pointer(p)).Ftz = sgn * (*(*int32)(unsafe.Pointer(bp + 20)) + *(*int32)(unsafe.Pointer(bp + 16))*60)
zulu_time:
__10:
	if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zDate))])&0x01 != 0) {
		goto __11
	}
	zDate++
	goto __10
__11:
	;
	(*DateTime)(unsafe.Pointer(p)).FtzSet = uint8(1)
	return libc.Bool32(int32(*(*uint8)(unsafe.Pointer(zDate))) != 0)
}

func parseHhMmSs(tls *libc.TLS, zDate uintptr, p uintptr) int32 {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var ms float64 = 0.0
	if getDigits(tls, zDate, ts+1227, libc.VaList(bp, bp+24, bp+28)) != 2 {
		return 1
	}
	zDate += uintptr(5)
	if int32(*(*uint8)(unsafe.Pointer(zDate))) == ':' {
		zDate++
		if getDigits(tls, zDate, ts+1235, libc.VaList(bp+16, bp+32)) != 1 {
			return 1
		}
		zDate += uintptr(2)
		if int32(*(*uint8)(unsafe.Pointer(zDate))) == '.' && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zDate + 1))])&0x04 != 0 {
			var rScale float64 = 1.0
			zDate++
			for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zDate))])&0x04 != 0 {
				ms = ms*10.0 + float64(*(*uint8)(unsafe.Pointer(zDate))) - float64('0')
				rScale = rScale * 10.0
				zDate++
			}
			ms = ms / rScale
		}
	} else {
		*(*int32)(unsafe.Pointer(bp + 32)) = 0
	}
	(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(1)
	(*DateTime)(unsafe.Pointer(p)).Fh = *(*int32)(unsafe.Pointer(bp + 24))
	(*DateTime)(unsafe.Pointer(p)).Fm = *(*int32)(unsafe.Pointer(bp + 28))
	(*DateTime)(unsafe.Pointer(p)).Fs = float64(*(*int32)(unsafe.Pointer(bp + 32))) + ms
	if parseTimezone(tls, zDate, p) != 0 {
		return 1
	}
	(*DateTime)(unsafe.Pointer(p)).FvalidTZ = func() uint8 {
		if (*DateTime)(unsafe.Pointer(p)).Ftz != 0 {
			return uint8(1)
		}
		return uint8(0)
	}()
	return 0
}

func datetimeError(tls *libc.TLS, p uintptr) {
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(DateTime{})))
	(*DateTime)(unsafe.Pointer(p)).FisError = uint8(1)
}

func computeJD(tls *libc.TLS, p uintptr) {
	var Y int32
	var M int32
	var D int32
	var A int32
	var B int32
	var X1 int32
	var X2 int32

	if (*DateTime)(unsafe.Pointer(p)).FvalidJD != 0 {
		return
	}
	if (*DateTime)(unsafe.Pointer(p)).FvalidYMD != 0 {
		Y = (*DateTime)(unsafe.Pointer(p)).FY
		M = (*DateTime)(unsafe.Pointer(p)).FM
		D = (*DateTime)(unsafe.Pointer(p)).FD
	} else {
		Y = 2000
		M = 1
		D = 1
	}
	if Y < -4713 || Y > 9999 || (*DateTime)(unsafe.Pointer(p)).FrawS != 0 {
		datetimeError(tls, p)
		return
	}
	if M <= 2 {
		Y--
		M = M + 12
	}
	A = Y / 100
	B = 2 - A + A/4
	X1 = 36525 * (Y + 4716) / 100
	X2 = 306001 * (M + 1) / 10000
	(*DateTime)(unsafe.Pointer(p)).FiJD = libc.Int64FromFloat64((float64(X1+X2+D+B) - 1524.5) * float64(86400000))
	(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
	if (*DateTime)(unsafe.Pointer(p)).FvalidHMS != 0 {
		*(*Sqlite3_int64)(unsafe.Pointer(p)) += Sqlite3_int64((*DateTime)(unsafe.Pointer(p)).Fh*3600000+(*DateTime)(unsafe.Pointer(p)).Fm*60000) + libc.Int64FromFloat64((*DateTime)(unsafe.Pointer(p)).Fs*float64(1000)+0.5)
		if (*DateTime)(unsafe.Pointer(p)).FvalidTZ != 0 {
			*(*Sqlite3_int64)(unsafe.Pointer(p)) -= Sqlite3_int64((*DateTime)(unsafe.Pointer(p)).Ftz * 60000)
			(*DateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(0)
			(*DateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(0)
			(*DateTime)(unsafe.Pointer(p)).FvalidTZ = uint8(0)
		}
	}
}

func parseYyyyMmDd(tls *libc.TLS, zDate uintptr, p uintptr) int32 {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var neg int32

	if int32(*(*uint8)(unsafe.Pointer(zDate))) == '-' {
		zDate++
		neg = 1
	} else {
		neg = 0
	}
	if getDigits(tls, zDate, ts+1239, libc.VaList(bp, bp+24, bp+28, bp+32)) != 3 {
		return 1
	}
	zDate += uintptr(10)
	for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zDate))])&0x01 != 0 || 'T' == int32(*(*U8)(unsafe.Pointer(zDate))) {
		zDate++
	}
	if parseHhMmSs(tls, zDate, p) == 0 {
	} else if int32(*(*uint8)(unsafe.Pointer(zDate))) == 0 {
		(*DateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(0)
	} else {
		return 1
	}
	(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(1)
	(*DateTime)(unsafe.Pointer(p)).FY = func() int32 {
		if neg != 0 {
			return -*(*int32)(unsafe.Pointer(bp + 24))
		}
		return *(*int32)(unsafe.Pointer(bp + 24))
	}()
	(*DateTime)(unsafe.Pointer(p)).FM = *(*int32)(unsafe.Pointer(bp + 28))
	(*DateTime)(unsafe.Pointer(p)).FD = *(*int32)(unsafe.Pointer(bp + 32))
	if (*DateTime)(unsafe.Pointer(p)).FvalidTZ != 0 {
		computeJD(tls, p)
	}
	return 0
}

func setDateTimeToCurrent(tls *libc.TLS, context uintptr, p uintptr) int32 {
	(*DateTime)(unsafe.Pointer(p)).FiJD = Xsqlite3StmtCurrentTime(tls, context)
	if (*DateTime)(unsafe.Pointer(p)).FiJD > int64(0) {
		(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
		return 0
	} else {
		return 1
	}
	return int32(0)
}

func setRawDateNumber(tls *libc.TLS, p uintptr, r float64) {
	(*DateTime)(unsafe.Pointer(p)).Fs = r
	(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(1)
	if r >= 0.0 && r < 5373484.5 {
		(*DateTime)(unsafe.Pointer(p)).FiJD = libc.Int64FromFloat64(r*86400000.0 + 0.5)
		(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
	}
}

func parseDateOrTime(tls *libc.TLS, context uintptr, zDate uintptr, p uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if parseYyyyMmDd(tls, zDate, p) == 0 {
		return 0
	} else if parseHhMmSs(tls, zDate, p) == 0 {
		return 0
	} else if Xsqlite3StrICmp(tls, zDate, ts+1251) == 0 && Xsqlite3NotPureFunc(tls, context) != 0 {
		return setDateTimeToCurrent(tls, context, p)
	} else if Xsqlite3AtoF(tls, zDate, bp, Xsqlite3Strlen30(tls, zDate), uint8(SQLITE_UTF8)) > 0 {
		setRawDateNumber(tls, p, *(*float64)(unsafe.Pointer(bp)))
		return 0
	}
	return 1
}

func validJulianDay(tls *libc.TLS, iJD Sqlite3_int64) int32 {
	return libc.Bool32(iJD >= int64(0) && iJD <= int64(0x1a640)<<32|int64(0x1072fdff))
}

func computeYMD(tls *libc.TLS, p uintptr) {
	var Z int32
	var A int32
	var B int32
	var C int32
	var D int32
	var E int32
	var X1 int32
	if (*DateTime)(unsafe.Pointer(p)).FvalidYMD != 0 {
		return
	}
	if !(int32((*DateTime)(unsafe.Pointer(p)).FvalidJD) != 0) {
		(*DateTime)(unsafe.Pointer(p)).FY = 2000
		(*DateTime)(unsafe.Pointer(p)).FM = 1
		(*DateTime)(unsafe.Pointer(p)).FD = 1
	} else if !(validJulianDay(tls, (*DateTime)(unsafe.Pointer(p)).FiJD) != 0) {
		datetimeError(tls, p)
		return
	} else {
		Z = int32(((*DateTime)(unsafe.Pointer(p)).FiJD + int64(43200000)) / int64(86400000))
		A = libc.Int32FromFloat64((float64(Z) - 1867216.25) / 36524.25)
		A = Z + 1 + A - A/4
		B = A + 1524
		C = libc.Int32FromFloat64((float64(B) - 122.1) / 365.25)
		D = 36525 * (C & 32767) / 100
		E = libc.Int32FromFloat64(float64(B-D) / 30.6001)
		X1 = libc.Int32FromFloat64(30.6001 * float64(E))
		(*DateTime)(unsafe.Pointer(p)).FD = B - D - X1
		(*DateTime)(unsafe.Pointer(p)).FM = func() int32 {
			if E < 14 {
				return E - 1
			}
			return E - 13
		}()
		(*DateTime)(unsafe.Pointer(p)).FY = func() int32 {
			if (*DateTime)(unsafe.Pointer(p)).FM > 2 {
				return C - 4716
			}
			return C - 4715
		}()
	}
	(*DateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(1)
}

func computeHMS(tls *libc.TLS, p uintptr) {
	var s int32
	if (*DateTime)(unsafe.Pointer(p)).FvalidHMS != 0 {
		return
	}
	computeJD(tls, p)
	s = int32(((*DateTime)(unsafe.Pointer(p)).FiJD + int64(43200000)) % int64(86400000))
	(*DateTime)(unsafe.Pointer(p)).Fs = float64(s) / 1000.0
	s = libc.Int32FromFloat64((*DateTime)(unsafe.Pointer(p)).Fs)
	*(*float64)(unsafe.Pointer(p + 32)) -= float64(s)
	(*DateTime)(unsafe.Pointer(p)).Fh = s / 3600
	s = s - (*DateTime)(unsafe.Pointer(p)).Fh*3600
	(*DateTime)(unsafe.Pointer(p)).Fm = s / 60
	*(*float64)(unsafe.Pointer(p + 32)) += float64(s - (*DateTime)(unsafe.Pointer(p)).Fm*60)
	(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(1)
}

func computeYMD_HMS(tls *libc.TLS, p uintptr) {
	computeYMD(tls, p)
	computeHMS(tls, p)
}

func clearYMD_HMS_TZ(tls *libc.TLS, p uintptr) {
	(*DateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FvalidTZ = uint8(0)
}

func osLocaltime(tls *libc.TLS, t uintptr, pTm uintptr) int32 {
	var rc int32
	var pX uintptr
	var mutex uintptr = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	Xsqlite3_mutex_enter(tls, mutex)
	pX = libc.Xlocaltime(tls, t)
	if Xsqlite3Config.FbLocaltimeFault != 0 {
		if Xsqlite3Config.FxAltLocaltime != uintptr(0) &&
			0 == (*struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.FxAltLocaltime})).f(tls, t, pTm) {
			pX = pTm
		} else {
			pX = uintptr(0)
		}
	}
	if pX != 0 {
		*(*tm)(unsafe.Pointer(pTm)) = *(*tm)(unsafe.Pointer(pX))
	}
	Xsqlite3_mutex_leave(tls, mutex)
	rc = libc.Bool32(pX == uintptr(0))
	return rc
}

func toLocaltime(tls *libc.TLS, p uintptr, pCtx uintptr) int32 {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	var iYearDiff int32

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(tm{})))

	computeJD(tls, p)
	if (*DateTime)(unsafe.Pointer(p)).FiJD < int64(2108667600)*int64(100000) ||
		(*DateTime)(unsafe.Pointer(p)).FiJD > int64(2130141456)*int64(100000) {
		*(*DateTime)(unsafe.Pointer(bp + 56)) = *(*DateTime)(unsafe.Pointer(p))
		computeYMD_HMS(tls, bp+56)
		iYearDiff = 2000 + (*DateTime)(unsafe.Pointer(bp+56)).FY%4 - (*DateTime)(unsafe.Pointer(bp+56)).FY
		*(*int32)(unsafe.Pointer(bp + 56 + 8)) += iYearDiff
		(*DateTime)(unsafe.Pointer(bp + 56)).FvalidJD = uint8(0)
		computeJD(tls, bp+56)
		*(*Time_t)(unsafe.Pointer(bp + 104)) = (*DateTime)(unsafe.Pointer(bp+56)).FiJD/int64(1000) - int64(21086676)*int64(10000)
	} else {
		iYearDiff = 0
		*(*Time_t)(unsafe.Pointer(bp + 104)) = (*DateTime)(unsafe.Pointer(p)).FiJD/int64(1000) - int64(21086676)*int64(10000)
	}
	if osLocaltime(tls, bp+104, bp) != 0 {
		Xsqlite3_result_error(tls, pCtx, ts+1255, -1)
		return SQLITE_ERROR
	}
	(*DateTime)(unsafe.Pointer(p)).FY = (*tm)(unsafe.Pointer(bp)).Ftm_year + 1900 - iYearDiff
	(*DateTime)(unsafe.Pointer(p)).FM = (*tm)(unsafe.Pointer(bp)).Ftm_mon + 1
	(*DateTime)(unsafe.Pointer(p)).FD = (*tm)(unsafe.Pointer(bp)).Ftm_mday
	(*DateTime)(unsafe.Pointer(p)).Fh = (*tm)(unsafe.Pointer(bp)).Ftm_hour
	(*DateTime)(unsafe.Pointer(p)).Fm = (*tm)(unsafe.Pointer(bp)).Ftm_min
	(*DateTime)(unsafe.Pointer(p)).Fs = float64((*tm)(unsafe.Pointer(bp)).Ftm_sec) + float64((*DateTime)(unsafe.Pointer(p)).FiJD%int64(1000))*0.001
	(*DateTime)(unsafe.Pointer(p)).FvalidYMD = uint8(1)
	(*DateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(1)
	(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FvalidTZ = uint8(0)
	(*DateTime)(unsafe.Pointer(p)).FisError = uint8(0)
	return SQLITE_OK
}

var aXformType = [6]struct {
	FnName  U8
	FzName  [7]uint8
	FrLimit float32
	FrXform float32
}{
	{FnName: U8(6), FzName: *(*[7]uint8)(unsafe.Pointer(ts + 1278)), FrLimit: 4.6427e+14, FrXform: 1.0},
	{FnName: U8(6), FzName: *(*[7]uint8)(unsafe.Pointer(ts + 1285)), FrLimit: 7.7379e+12, FrXform: 60.0},
	{FnName: U8(4), FzName: *(*[7]uint8)(unsafe.Pointer(ts + 1292)), FrLimit: 1.2897e+11, FrXform: 3600.0},
	{FnName: U8(3), FzName: *(*[7]uint8)(unsafe.Pointer(ts + 1299)), FrLimit: 5373485.0, FrXform: 86400.0},
	{FnName: U8(5), FzName: *(*[7]uint8)(unsafe.Pointer(ts + 1306)), FrLimit: 176546.0, FrXform: 2592000.0},
	{FnName: U8(4), FzName: *(*[7]uint8)(unsafe.Pointer(ts + 1313)), FrLimit: 14713.0, FrXform: 31536000.0},
}

func parseModifier(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, p uintptr, idx int32) int32 {
	bp := tls.Alloc(104)
	defer tls.Free(104)

	var rc int32 = 1

	switch int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(z))]) {
	case 'a':
		{
			if Xsqlite3_stricmp(tls, z, ts+1320) == 0 {
				if idx > 1 {
					return 1
				}
				if !(int32((*DateTime)(unsafe.Pointer(p)).FrawS) != 0) || (*DateTime)(unsafe.Pointer(p)).FvalidJD != 0 {
					rc = 0
					(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(0)
				} else if (*DateTime)(unsafe.Pointer(p)).Fs >= float64(int64(-21086676)*int64(10000)) &&
					(*DateTime)(unsafe.Pointer(p)).Fs <= float64(int64(25340230)*int64(10000)+int64(799)) {
					*(*float64)(unsafe.Pointer(bp + 48)) = (*DateTime)(unsafe.Pointer(p)).Fs*1000.0 + 210866760000000.0
					clearYMD_HMS_TZ(tls, p)
					(*DateTime)(unsafe.Pointer(p)).FiJD = libc.Int64FromFloat64(*(*float64)(unsafe.Pointer(bp + 48)) + 0.5)
					(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
					(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(0)
					rc = 0
				}
			}
			break

		}
	case 'j':
		{
			if Xsqlite3_stricmp(tls, z, ts+1325) == 0 {
				if idx > 1 {
					return 1
				}
				if (*DateTime)(unsafe.Pointer(p)).FvalidJD != 0 && (*DateTime)(unsafe.Pointer(p)).FrawS != 0 {
					rc = 0
					(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(0)
				}
			}
			break

		}
	case 'l':
		{
			if Xsqlite3_stricmp(tls, z, ts+1335) == 0 && Xsqlite3NotPureFunc(tls, pCtx) != 0 {
				rc = toLocaltime(tls, p, pCtx)
			}
			break

		}
	case 'u':
		{
			if Xsqlite3_stricmp(tls, z, ts+1345) == 0 && (*DateTime)(unsafe.Pointer(p)).FrawS != 0 {
				if idx > 1 {
					return 1
				}
				*(*float64)(unsafe.Pointer(bp + 48)) = (*DateTime)(unsafe.Pointer(p)).Fs*1000.0 + 210866760000000.0
				if *(*float64)(unsafe.Pointer(bp + 48)) >= 0.0 && *(*float64)(unsafe.Pointer(bp + 48)) < 464269060800000.0 {
					clearYMD_HMS_TZ(tls, p)
					(*DateTime)(unsafe.Pointer(p)).FiJD = libc.Int64FromFloat64(*(*float64)(unsafe.Pointer(bp + 48)) + 0.5)
					(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
					(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(0)
					rc = 0
				}
			} else if Xsqlite3_stricmp(tls, z, ts+1355) == 0 && Xsqlite3NotPureFunc(tls, pCtx) != 0 {
				if int32((*DateTime)(unsafe.Pointer(p)).FtzSet) == 0 {
					var iOrigJD I64
					var iGuess I64
					var cnt int32 = 0
					var iErr I64

					computeJD(tls, p)
					iGuess = libc.AssignInt64(&iOrigJD, (*DateTime)(unsafe.Pointer(p)).FiJD)
					iErr = int64(0)
					for __ccgo := true; __ccgo; __ccgo = iErr != 0 && libc.PostIncInt32(&cnt, 1) < 3 {
						libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(DateTime{})))
						iGuess = iGuess - iErr
						(*DateTime)(unsafe.Pointer(bp)).FiJD = iGuess
						(*DateTime)(unsafe.Pointer(bp)).FvalidJD = uint8(1)
						rc = toLocaltime(tls, bp, pCtx)
						if rc != 0 {
							return rc
						}
						computeJD(tls, bp)
						iErr = (*DateTime)(unsafe.Pointer(bp)).FiJD - iOrigJD
					}
					libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(DateTime{})))
					(*DateTime)(unsafe.Pointer(p)).FiJD = iGuess
					(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(1)
					(*DateTime)(unsafe.Pointer(p)).FtzSet = uint8(1)
				}
				rc = SQLITE_OK
			}
			break

		}
	case 'w':
		{
			if Xsqlite3_strnicmp(tls, z, ts+1359, 8) == 0 &&
				Xsqlite3AtoF(tls, z+8, bp+48, Xsqlite3Strlen30(tls, z+8), uint8(SQLITE_UTF8)) > 0 &&
				*(*float64)(unsafe.Pointer(bp + 48)) >= 0.0 && *(*float64)(unsafe.Pointer(bp + 48)) < 7.0 && float64(libc.AssignInt32(&n, int32(*(*float64)(unsafe.Pointer(bp + 48))))) == *(*float64)(unsafe.Pointer(bp + 48)) {
				var Z Sqlite3_int64
				computeYMD_HMS(tls, p)
				(*DateTime)(unsafe.Pointer(p)).FvalidTZ = uint8(0)
				(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
				computeJD(tls, p)
				Z = ((*DateTime)(unsafe.Pointer(p)).FiJD + int64(129600000)) / int64(86400000) % int64(7)
				if Z > Sqlite3_int64(n) {
					Z = Z - int64(7)
				}
				*(*Sqlite3_int64)(unsafe.Pointer(p)) += (Sqlite3_int64(n) - Z) * int64(86400000)
				clearYMD_HMS_TZ(tls, p)
				rc = 0
			}
			break

		}
	case 's':
		{
			if Xsqlite3_strnicmp(tls, z, ts+1368, 9) != 0 {
				break
			}
			if !(int32((*DateTime)(unsafe.Pointer(p)).FvalidJD) != 0) && !(int32((*DateTime)(unsafe.Pointer(p)).FvalidYMD) != 0) && !(int32((*DateTime)(unsafe.Pointer(p)).FvalidHMS) != 0) {
				break
			}
			z += uintptr(9)
			computeYMD(tls, p)
			(*DateTime)(unsafe.Pointer(p)).FvalidHMS = uint8(1)
			(*DateTime)(unsafe.Pointer(p)).Fh = libc.AssignPtrInt32(p+24, 0)
			(*DateTime)(unsafe.Pointer(p)).Fs = 0.0
			(*DateTime)(unsafe.Pointer(p)).FrawS = uint8(0)
			(*DateTime)(unsafe.Pointer(p)).FvalidTZ = uint8(0)
			(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
			if Xsqlite3_stricmp(tls, z, ts+1378) == 0 {
				(*DateTime)(unsafe.Pointer(p)).FD = 1
				rc = 0
			} else if Xsqlite3_stricmp(tls, z, ts+1384) == 0 {
				(*DateTime)(unsafe.Pointer(p)).FM = 1
				(*DateTime)(unsafe.Pointer(p)).FD = 1
				rc = 0
			} else if Xsqlite3_stricmp(tls, z, ts+1389) == 0 {
				rc = 0
			}
			break

		}
	case '+':
		fallthrough
	case '-':
		fallthrough
	case '0':
		fallthrough
	case '1':
		fallthrough
	case '2':
		fallthrough
	case '3':
		fallthrough
	case '4':
		fallthrough
	case '5':
		fallthrough
	case '6':
		fallthrough
	case '7':
		fallthrough
	case '8':
		fallthrough
	case '9':
		{
			var rRounder float64
			var i int32
			for n = 1; *(*uint8)(unsafe.Pointer(z + uintptr(n))) != 0 && int32(*(*uint8)(unsafe.Pointer(z + uintptr(n)))) != ':' && !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(n)))])&0x01 != 0); n++ {
			}
			if Xsqlite3AtoF(tls, z, bp+48, n, uint8(SQLITE_UTF8)) <= 0 {
				rc = 1
				break
			}
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(n)))) == ':' {
				var z2 uintptr = z

				var day Sqlite3_int64
				if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z2))])&0x04 != 0) {
					z2++
				}
				libc.Xmemset(tls, bp+56, 0, uint64(unsafe.Sizeof(DateTime{})))
				if parseHhMmSs(tls, z2, bp+56) != 0 {
					break
				}
				computeJD(tls, bp+56)
				*(*Sqlite3_int64)(unsafe.Pointer(bp + 56)) -= int64(43200000)
				day = (*DateTime)(unsafe.Pointer(bp+56)).FiJD / int64(86400000)
				*(*Sqlite3_int64)(unsafe.Pointer(bp + 56)) -= day * int64(86400000)
				if int32(*(*uint8)(unsafe.Pointer(z))) == '-' {
					(*DateTime)(unsafe.Pointer(bp + 56)).FiJD = -(*DateTime)(unsafe.Pointer(bp + 56)).FiJD
				}
				computeJD(tls, p)
				clearYMD_HMS_TZ(tls, p)
				*(*Sqlite3_int64)(unsafe.Pointer(p)) += (*DateTime)(unsafe.Pointer(bp + 56)).FiJD
				rc = 0
				break
			}

			z += uintptr(n)
			for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z))])&0x01 != 0 {
				z++
			}
			n = Xsqlite3Strlen30(tls, z)
			if n > 10 || n < 3 {
				break
			}
			if int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(z + uintptr(n-1)))]) == 's' {
				n--
			}
			computeJD(tls, p)
			rc = 1
			if *(*float64)(unsafe.Pointer(bp + 48)) < float64(0) {
				rRounder = -0.5
			} else {
				rRounder = +0.5
			}
			for i = 0; i < int32(uint64(unsafe.Sizeof(aXformType))/uint64(unsafe.Sizeof(struct {
				FnName  U8
				FzName  [7]uint8
				FrLimit float32
				FrXform float32
			}{}))); i++ {
				if int32(aXformType[i].FnName) == n &&
					Xsqlite3_strnicmp(tls, uintptr(unsafe.Pointer(&aXformType))+uintptr(i)*16+1, z, n) == 0 &&
					*(*float64)(unsafe.Pointer(bp + 48)) > float64(-aXformType[i].FrLimit) && *(*float64)(unsafe.Pointer(bp + 48)) < float64(aXformType[i].FrLimit) {
					switch i {
					case 4:
						{
							var x int32

							computeYMD_HMS(tls, p)
							*(*int32)(unsafe.Pointer(p + 12)) += int32(*(*float64)(unsafe.Pointer(bp + 48)))
							if (*DateTime)(unsafe.Pointer(p)).FM > 0 {
								x = ((*DateTime)(unsafe.Pointer(p)).FM - 1) / 12
							} else {
								x = ((*DateTime)(unsafe.Pointer(p)).FM - 12) / 12
							}
							*(*int32)(unsafe.Pointer(p + 8)) += x
							*(*int32)(unsafe.Pointer(p + 12)) -= x * 12
							(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
							*(*float64)(unsafe.Pointer(bp + 48)) -= float64(int32(*(*float64)(unsafe.Pointer(bp + 48))))
							break

						}
						fallthrough
					case 5:
						{
							var y int32 = int32(*(*float64)(unsafe.Pointer(bp + 48)))

							computeYMD_HMS(tls, p)
							*(*int32)(unsafe.Pointer(p + 8)) += y
							(*DateTime)(unsafe.Pointer(p)).FvalidJD = uint8(0)
							*(*float64)(unsafe.Pointer(bp + 48)) -= float64(int32(*(*float64)(unsafe.Pointer(bp + 48))))
							break

						}
					}
					computeJD(tls, p)
					*(*Sqlite3_int64)(unsafe.Pointer(p)) += libc.Int64FromFloat64(*(*float64)(unsafe.Pointer(bp + 48))*1000.0*float64(aXformType[i].FrXform) + rRounder)
					rc = 0
					break
				}
			}
			clearYMD_HMS_TZ(tls, p)
			break

		}
	default:
		{
			break

		}
	}
	return rc
}

func isDate(tls *libc.TLS, context uintptr, argc int32, argv uintptr, p uintptr) int32 {
	var i int32
	var n int32
	var z uintptr
	var eType int32
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(DateTime{})))
	if argc == 0 {
		if !(Xsqlite3NotPureFunc(tls, context) != 0) {
			return 1
		}
		return setDateTimeToCurrent(tls, context, p)
	}
	if libc.AssignInt32(&eType, Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))) == SQLITE_FLOAT ||
		eType == 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 1
		}
	}
	for i = 1; i < argc; i++ {
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
		n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
		if z == uintptr(0) || parseModifier(tls, context, z, n, p, i) != 0 {
			return 1
		}
	}
	computeJD(tls, p)
	if (*DateTime)(unsafe.Pointer(p)).FisError != 0 || !(validJulianDay(tls, (*DateTime)(unsafe.Pointer(p)).FiJD) != 0) {
		return 1
	}
	return 0
}

func juliandayFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if isDate(tls, context, argc, argv, bp) == 0 {
		computeJD(tls, bp)
		Xsqlite3_result_double(tls, context, float64((*DateTime)(unsafe.Pointer(bp)).FiJD)/86400000.0)
	}
}

func unixepochFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if isDate(tls, context, argc, argv, bp) == 0 {
		computeJD(tls, bp)
		Xsqlite3_result_int64(tls, context, (*DateTime)(unsafe.Pointer(bp)).FiJD/int64(1000)-int64(21086676)*int64(10000))
	}
}

func datetimeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	if isDate(tls, context, argc, argv, bp) == 0 {
		var Y int32
		var s int32

		computeYMD_HMS(tls, bp)
		Y = (*DateTime)(unsafe.Pointer(bp)).FY
		if Y < 0 {
			Y = -Y
		}
		*(*uint8)(unsafe.Pointer(bp + 48 + 1)) = uint8('0' + Y/1000%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 2)) = uint8('0' + Y/100%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 3)) = uint8('0' + Y/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 4)) = uint8('0' + Y%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 5)) = uint8('-')
		*(*uint8)(unsafe.Pointer(bp + 48 + 6)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).FM/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 7)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).FM%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 8)) = uint8('-')
		*(*uint8)(unsafe.Pointer(bp + 48 + 9)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).FD/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 10)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).FD%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 11)) = uint8(' ')
		*(*uint8)(unsafe.Pointer(bp + 48 + 12)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).Fh/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 13)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).Fh%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 14)) = uint8(':')
		*(*uint8)(unsafe.Pointer(bp + 48 + 15)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).Fm/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 16)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).Fm%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 17)) = uint8(':')
		s = libc.Int32FromFloat64((*DateTime)(unsafe.Pointer(bp)).Fs)
		*(*uint8)(unsafe.Pointer(bp + 48 + 18)) = uint8('0' + s/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 19)) = uint8('0' + s%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 20)) = uint8(0)
		if (*DateTime)(unsafe.Pointer(bp)).FY < 0 {
			*(*uint8)(unsafe.Pointer(bp + 48)) = uint8('-')
			Xsqlite3_result_text(tls, context, bp+48, 20, libc.UintptrFromInt32(-1))
		} else {
			Xsqlite3_result_text(tls, context, bp+48+1, 19, libc.UintptrFromInt32(-1))
		}
	}
}

func timeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	if isDate(tls, context, argc, argv, bp) == 0 {
		var s int32

		computeHMS(tls, bp)
		*(*uint8)(unsafe.Pointer(bp + 48)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).Fh/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 1)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).Fh%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 2)) = uint8(':')
		*(*uint8)(unsafe.Pointer(bp + 48 + 3)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).Fm/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 4)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).Fm%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 5)) = uint8(':')
		s = libc.Int32FromFloat64((*DateTime)(unsafe.Pointer(bp)).Fs)
		*(*uint8)(unsafe.Pointer(bp + 48 + 6)) = uint8('0' + s/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 7)) = uint8('0' + s%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 8)) = uint8(0)
		Xsqlite3_result_text(tls, context, bp+48, 8, libc.UintptrFromInt32(-1))
	}
}

func dateFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	if isDate(tls, context, argc, argv, bp) == 0 {
		var Y int32

		computeYMD(tls, bp)
		Y = (*DateTime)(unsafe.Pointer(bp)).FY
		if Y < 0 {
			Y = -Y
		}
		*(*uint8)(unsafe.Pointer(bp + 48 + 1)) = uint8('0' + Y/1000%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 2)) = uint8('0' + Y/100%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 3)) = uint8('0' + Y/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 4)) = uint8('0' + Y%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 5)) = uint8('-')
		*(*uint8)(unsafe.Pointer(bp + 48 + 6)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).FM/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 7)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).FM%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 8)) = uint8('-')
		*(*uint8)(unsafe.Pointer(bp + 48 + 9)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).FD/10%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 10)) = uint8('0' + (*DateTime)(unsafe.Pointer(bp)).FD%10)
		*(*uint8)(unsafe.Pointer(bp + 48 + 11)) = uint8(0)
		if (*DateTime)(unsafe.Pointer(bp)).FY < 0 {
			*(*uint8)(unsafe.Pointer(bp + 48)) = uint8('-')
			Xsqlite3_result_text(tls, context, bp+48, 11, libc.UintptrFromInt32(-1))
		} else {
			Xsqlite3_result_text(tls, context, bp+48+1, 10, libc.UintptrFromInt32(-1))
		}
	}
}

func strftimeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(216)
	defer tls.Free(216)

	var i Size_t
	var j Size_t
	var db uintptr
	var zFmt uintptr

	if argc == 0 {
		return
	}
	zFmt = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zFmt == uintptr(0) || isDate(tls, context, argc-1, argv+uintptr(1)*8, bp+88) != 0 {
		return
	}
	db = Xsqlite3_context_db_handle(tls, context)
	Xsqlite3StrAccumInit(tls, bp+136, uintptr(0), uintptr(0), 0, *(*int32)(unsafe.Pointer(db + 136)))

	computeJD(tls, bp+88)
	computeYMD_HMS(tls, bp+88)
	for i = libc.AssignUint64(&j, uint64(0)); *(*uint8)(unsafe.Pointer(zFmt + uintptr(i))) != 0; i++ {
		if int32(*(*uint8)(unsafe.Pointer(zFmt + uintptr(i)))) != '%' {
			continue
		}
		if j < i {
			Xsqlite3_str_append(tls, bp+136, zFmt+uintptr(j), int32(i-j))
		}
		i++
		j = i + uint64(1)
		switch int32(*(*uint8)(unsafe.Pointer(zFmt + uintptr(i)))) {
		case 'd':
			{
				Xsqlite3_str_appendf(tls, bp+136, ts+1393, libc.VaList(bp, (*DateTime)(unsafe.Pointer(bp+88)).FD))
				break

			}
		case 'f':
			{
				var s float64 = (*DateTime)(unsafe.Pointer(bp + 88)).Fs
				if s > 59.999 {
					s = 59.999
				}
				Xsqlite3_str_appendf(tls, bp+136, ts+1398, libc.VaList(bp+8, s))
				break

			}
		case 'H':
			{
				Xsqlite3_str_appendf(tls, bp+136, ts+1393, libc.VaList(bp+16, (*DateTime)(unsafe.Pointer(bp+88)).Fh))
				break

			}
		case 'W':
			fallthrough
		case 'j':
			{
				var nDay int32
				*(*DateTime)(unsafe.Pointer(bp + 168)) = *(*DateTime)(unsafe.Pointer(bp + 88))
				(*DateTime)(unsafe.Pointer(bp + 168)).FvalidJD = uint8(0)
				(*DateTime)(unsafe.Pointer(bp + 168)).FM = 1
				(*DateTime)(unsafe.Pointer(bp + 168)).FD = 1
				computeJD(tls, bp+168)
				nDay = int32(((*DateTime)(unsafe.Pointer(bp+88)).FiJD - (*DateTime)(unsafe.Pointer(bp+168)).FiJD + int64(43200000)) / int64(86400000))
				if int32(*(*uint8)(unsafe.Pointer(zFmt + uintptr(i)))) == 'W' {
					var wd int32
					wd = int32(((*DateTime)(unsafe.Pointer(bp+88)).FiJD + int64(43200000)) / int64(86400000) % int64(7))
					Xsqlite3_str_appendf(tls, bp+136, ts+1393, libc.VaList(bp+24, (nDay+7-wd)/7))
				} else {
					Xsqlite3_str_appendf(tls, bp+136, ts+1405, libc.VaList(bp+32, nDay+1))
				}
				break

			}
		case 'J':
			{
				Xsqlite3_str_appendf(tls, bp+136, ts+1410, libc.VaList(bp+40, float64((*DateTime)(unsafe.Pointer(bp+88)).FiJD)/86400000.0))
				break

			}
		case 'm':
			{
				Xsqlite3_str_appendf(tls, bp+136, ts+1393, libc.VaList(bp+48, (*DateTime)(unsafe.Pointer(bp+88)).FM))
				break

			}
		case 'M':
			{
				Xsqlite3_str_appendf(tls, bp+136, ts+1393, libc.VaList(bp+56, (*DateTime)(unsafe.Pointer(bp+88)).Fm))
				break

			}
		case 's':
			{
				var iS I64 = (*DateTime)(unsafe.Pointer(bp+88)).FiJD/int64(1000) - int64(21086676)*int64(10000)
				Xsqlite3_str_appendf(tls, bp+136, ts+1416, libc.VaList(bp+64, iS))
				break

			}
		case 'S':
			{
				Xsqlite3_str_appendf(tls, bp+136, ts+1393, libc.VaList(bp+72, libc.Int32FromFloat64((*DateTime)(unsafe.Pointer(bp+88)).Fs)))
				break

			}
		case 'w':
			{
				Xsqlite3_str_appendchar(tls, bp+136, 1,
					uint8(int32(uint8(((*DateTime)(unsafe.Pointer(bp+88)).FiJD+int64(129600000))/int64(86400000)%int64(7)))+'0'))
				break

			}
		case 'Y':
			{
				Xsqlite3_str_appendf(tls, bp+136, ts+1421, libc.VaList(bp+80, (*DateTime)(unsafe.Pointer(bp+88)).FY))
				break

			}
		case '%':
			{
				Xsqlite3_str_appendchar(tls, bp+136, 1, uint8('%'))
				break

			}
		default:
			{
				Xsqlite3_str_reset(tls, bp+136)
				return

			}
		}
	}
	if j < i {
		Xsqlite3_str_append(tls, bp+136, zFmt+uintptr(j), int32(i-j))
	}
	Xsqlite3ResultStrAccum(tls, context, bp+136)
}

func ctimeFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2
	timeFunc(tls, context, 0, uintptr(0))
}

func cdateFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2
	dateFunc(tls, context, 0, uintptr(0))
}

func ctimestampFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2
	datetimeFunc(tls, context, 0, uintptr(0))
}

func Xsqlite3RegisterDateTimeFunctions(tls *libc.TLS) {
	Xsqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&aDateTimeFuncs)), int32(uint64(unsafe.Sizeof(aDateTimeFuncs))/uint64(unsafe.Sizeof(FuncDef{}))))
}

var aDateTimeFuncs = [9]FuncDef{
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FpUserData: 0, FxSFunc: 0, FzName: ts + 1325},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FpUserData: 0, FxSFunc: 0, FzName: ts + 1345},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FpUserData: 0, FxSFunc: 0, FzName: ts + 1426},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FpUserData: 0, FxSFunc: 0, FzName: ts + 1431},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FpUserData: 0, FxSFunc: 0, FzName: ts + 1436},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FpUserData: 0, FxSFunc: 0, FzName: ts + 1445},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 1454},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 1467},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 1485}}

var Xsqlite3_io_error_hit int32 = 0
var Xsqlite3_io_error_hardhit int32 = 0
var Xsqlite3_io_error_pending int32 = 0
var Xsqlite3_io_error_persist int32 = 0
var Xsqlite3_io_error_benign int32 = 0
var Xsqlite3_diskfull_pending int32 = 0
var Xsqlite3_diskfull int32 = 0

var Xsqlite3_open_file_count int32 = 0

var Xsqlite3_memdebug_vfs_oom_test int32 = 1

func Xsqlite3OsClose(tls *libc.TLS, pId uintptr) {
	if (*Sqlite3_file)(unsafe.Pointer(pId)).FpMethods != 0 {
		(*struct {
			f func(*libc.TLS, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pId)).FpMethods)).FxClose})).f(tls, pId)
		(*Sqlite3_file)(unsafe.Pointer(pId)).FpMethods = uintptr(0)
	}
}

func Xsqlite3OsRead(tls *libc.TLS, id uintptr, pBuf uintptr, amt int32, offset I64) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxRead})).f(tls, id, pBuf, amt, offset)
}

func Xsqlite3OsWrite(tls *libc.TLS, id uintptr, pBuf uintptr, amt int32, offset I64) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxWrite})).f(tls, id, pBuf, amt, offset)
}

func Xsqlite3OsTruncate(tls *libc.TLS, id uintptr, size I64) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, Sqlite3_int64) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxTruncate})).f(tls, id, size)
}

func Xsqlite3OsSync(tls *libc.TLS, id uintptr, flags int32) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	if flags != 0 {
		return (*struct {
			f func(*libc.TLS, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxSync})).f(tls, id, flags)
	}
	return SQLITE_OK
}

func Xsqlite3OsFileSize(tls *libc.TLS, id uintptr, pSize uintptr) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxFileSize})).f(tls, id, pSize)
}

func Xsqlite3OsLock(tls *libc.TLS, id uintptr, lockType int32) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	return (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxLock})).f(tls, id, lockType)
}

func Xsqlite3OsUnlock(tls *libc.TLS, id uintptr, lockType int32) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxUnlock})).f(tls, id, lockType)
}

func Xsqlite3OsCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxCheckReservedLock})).f(tls, id, pResOut)
}

func Xsqlite3OsFileControl(tls *libc.TLS, id uintptr, op int32, pArg uintptr) int32 {
	if (*Sqlite3_file)(unsafe.Pointer(id)).FpMethods == uintptr(0) {
		return SQLITE_NOTFOUND
	}
	if op != SQLITE_FCNTL_COMMIT_PHASETWO &&
		op != SQLITE_FCNTL_LOCK_TIMEOUT &&
		op != SQLITE_FCNTL_CKPT_DONE &&
		op != SQLITE_FCNTL_CKPT_START {
		if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
			var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
			if !(pTstAlloc != 0) {
				return SQLITE_IOERR | int32(12)<<8
			}
			Xsqlite3_free(tls, pTstAlloc)
		}

	}
	return (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxFileControl})).f(tls, id, op, pArg)
}

func Xsqlite3OsFileControlHint(tls *libc.TLS, id uintptr, op int32, pArg uintptr) {
	if (*Sqlite3_file)(unsafe.Pointer(id)).FpMethods != 0 {
		(*struct {
			f func(*libc.TLS, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxFileControl})).f(tls, id, op, pArg)
	}
}

func Xsqlite3OsSectorSize(tls *libc.TLS, id uintptr) int32 {
	var xSectorSize uintptr = (*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxSectorSize
	return func() int32 {
		if xSectorSize != 0 {
			return (*struct {
				f func(*libc.TLS, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{xSectorSize})).f(tls, id)
		}
		return SQLITE_DEFAULT_SECTOR_SIZE
	}()
}

func Xsqlite3OsDeviceCharacteristics(tls *libc.TLS, id uintptr) int32 {
	if (*Sqlite3_file)(unsafe.Pointer(id)).FpMethods == uintptr(0) {
		return 0
	}
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxDeviceCharacteristics})).f(tls, id)
}

func Xsqlite3OsShmLock(tls *libc.TLS, id uintptr, offset int32, n int32, flags int32) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, int32, int32, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxShmLock})).f(tls, id, offset, n, flags)
}

func Xsqlite3OsShmBarrier(tls *libc.TLS, id uintptr) {
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxShmBarrier})).f(tls, id)
}

func Xsqlite3OsShmUnmap(tls *libc.TLS, id uintptr, deleteFlag int32) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxShmUnmap})).f(tls, id, deleteFlag)
}

func Xsqlite3OsShmMap(tls *libc.TLS, id uintptr, iPage int32, pgsz int32, bExtend int32, pp uintptr) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	return (*struct {
		f func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxShmMap})).f(tls, id, iPage, pgsz, bExtend, pp)
}

func Xsqlite3OsFetch(tls *libc.TLS, id uintptr, iOff I64, iAmt int32, pp uintptr) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(id != 0) || !(Xsqlite3JournalIsInMemory(tls, id) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	return (*struct {
		f func(*libc.TLS, uintptr, Sqlite3_int64, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxFetch})).f(tls, id, iOff, iAmt, pp)
}

func Xsqlite3OsUnfetch(tls *libc.TLS, id uintptr, iOff I64, p uintptr) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, Sqlite3_int64, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods)).FxUnfetch})).f(tls, id, iOff, p)
}

func Xsqlite3OsOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr, pFile uintptr, flags int32, pFlagsOut uintptr) int32 {
	var rc int32
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(0 != 0) || !(Xsqlite3JournalIsInMemory(tls, uintptr(0)) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	rc = (*struct {
		f func(*libc.TLS, uintptr, Sqlite3_filename, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxOpen})).f(tls, pVfs, zPath, pFile, flags&0x1087f7f, pFlagsOut)

	return rc
}

func Xsqlite3OsDelete(tls *libc.TLS, pVfs uintptr, zPath uintptr, dirSync int32) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(0 != 0) || !(Xsqlite3JournalIsInMemory(tls, uintptr(0)) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	if (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxDelete != uintptr(0) {
		return (*struct {
			f func(*libc.TLS, uintptr, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxDelete})).f(tls, pVfs, zPath, dirSync)
	}
	return SQLITE_OK
}

func Xsqlite3OsAccess(tls *libc.TLS, pVfs uintptr, zPath uintptr, flags int32, pResOut uintptr) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(0 != 0) || !(Xsqlite3JournalIsInMemory(tls, uintptr(0)) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

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

func Xsqlite3OsFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nPathOut int32, zPathOut uintptr) int32 {
	if Xsqlite3_memdebug_vfs_oom_test != 0 && (!(0 != 0) || !(Xsqlite3JournalIsInMemory(tls, uintptr(0)) != 0)) {
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_IOERR | int32(12)<<8
		}
		Xsqlite3_free(tls, pTstAlloc)
	}

	*(*uint8)(unsafe.Pointer(zPathOut)) = uint8(0)
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxFullPathname})).f(tls, pVfs, zPath, nPathOut, zPathOut)
}

func Xsqlite3OsDlOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr) uintptr {
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxDlOpen})).f(tls, pVfs, zPath)
}

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

func Xsqlite3OsDlSym(tls *libc.TLS, pVfs uintptr, pHdle uintptr, zSym uintptr) uintptr {
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxDlSym})).f(tls, pVfs, pHdle, zSym)
}

func Xsqlite3OsDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
	(*struct {
		f func(*libc.TLS, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxDlClose})).f(tls, pVfs, pHandle)
}

func Xsqlite3OsRandomness(tls *libc.TLS, pVfs uintptr, nByte int32, zBufOut uintptr) int32 {
	if Xsqlite3Config.FiPrngSeed != 0 {
		libc.Xmemset(tls, zBufOut, 0, uint64(nByte))
		if nByte > int32(unsafe.Sizeof(uint32(0))) {
			nByte = int32(unsafe.Sizeof(uint32(0)))
		}
		libc.Xmemcpy(tls, zBufOut, uintptr(unsafe.Pointer(&Xsqlite3Config))+432, uint64(nByte))
		return SQLITE_OK
	} else {
		return (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxRandomness})).f(tls, pVfs, nByte, zBufOut)
	}
	return int32(0)

}

func Xsqlite3OsSleep(tls *libc.TLS, pVfs uintptr, nMicro int32) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxSleep})).f(tls, pVfs, nMicro)
}

func Xsqlite3OsGetLastError(tls *libc.TLS, pVfs uintptr) int32 {
	if (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxGetLastError != 0 {
		return (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxGetLastError})).f(tls, pVfs, 0, uintptr(0))
	}
	return 0
}

func Xsqlite3OsCurrentTimeInt64(tls *libc.TLS, pVfs uintptr, pTimeOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	if (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FiVersion >= 2 && (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxCurrentTimeInt64 != 0 {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxCurrentTimeInt64})).f(tls, pVfs, pTimeOut)
	} else {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxCurrentTime})).f(tls, pVfs, bp)
		*(*Sqlite3_int64)(unsafe.Pointer(pTimeOut)) = libc.Int64FromFloat64(*(*float64)(unsafe.Pointer(bp)) * 86400000.0)
	}
	return rc
}

func Xsqlite3OsOpenMalloc(tls *libc.TLS, pVfs uintptr, zFile uintptr, ppFile uintptr, flags int32, pOutFlags uintptr) int32 {
	var rc int32
	var pFile uintptr
	pFile = Xsqlite3MallocZero(tls, uint64((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile))
	if pFile != 0 {
		rc = Xsqlite3OsOpen(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 = SQLITE_NOMEM
	}

	return rc
}

func Xsqlite3OsCloseFree(tls *libc.TLS, pFile uintptr) {
	Xsqlite3OsClose(tls, pFile)
	Xsqlite3_free(tls, pFile)
}

func Xsqlite3OsInit(tls *libc.TLS) int32 {
	var p uintptr = Xsqlite3_malloc(tls, 10)
	if p == uintptr(0) {
		return SQLITE_NOMEM
	}
	Xsqlite3_free(tls, p)
	return Xsqlite3_os_init(tls)
}

var vfsList uintptr = uintptr(0)

func Xsqlite3_vfs_find(tls *libc.TLS, zVfs uintptr) uintptr {
	var pVfs uintptr = uintptr(0)
	var mutex uintptr
	var rc int32 = Xsqlite3_initialize(tls)
	if rc != 0 {
		return uintptr(0)
	}
	mutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	Xsqlite3_mutex_enter(tls, mutex)
	for pVfs = vfsList; pVfs != 0; pVfs = (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext {
		if zVfs == uintptr(0) {
			break
		}
		if libc.Xstrcmp(tls, zVfs, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FzName) == 0 {
			break
		}
	}
	Xsqlite3_mutex_leave(tls, mutex)
	return pVfs
}

func vfsUnlink(tls *libc.TLS, pVfs uintptr) {
	if pVfs == uintptr(0) {
	} else if vfsList == pVfs {
		vfsList = (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext
	} else if vfsList != 0 {
		var p uintptr = vfsList
		for (*Sqlite3_vfs)(unsafe.Pointer(p)).FpNext != 0 && (*Sqlite3_vfs)(unsafe.Pointer(p)).FpNext != pVfs {
			p = (*Sqlite3_vfs)(unsafe.Pointer(p)).FpNext
		}
		if (*Sqlite3_vfs)(unsafe.Pointer(p)).FpNext == pVfs {
			(*Sqlite3_vfs)(unsafe.Pointer(p)).FpNext = (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext
		}
	}
}

func Xsqlite3_vfs_register(tls *libc.TLS, pVfs uintptr, makeDflt int32) int32 {
	var mutex uintptr
	var rc int32 = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}

	mutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	Xsqlite3_mutex_enter(tls, mutex)
	vfsUnlink(tls, pVfs)
	if makeDflt != 0 || vfsList == uintptr(0) {
		(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext = vfsList
		vfsList = pVfs
	} else {
		(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpNext = (*Sqlite3_vfs)(unsafe.Pointer(vfsList)).FpNext
		(*Sqlite3_vfs)(unsafe.Pointer(vfsList)).FpNext = pVfs
	}

	Xsqlite3_mutex_leave(tls, mutex)
	return SQLITE_OK
}

func Xsqlite3_vfs_unregister(tls *libc.TLS, pVfs uintptr) int32 {
	var mutex uintptr
	var rc int32 = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	mutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	Xsqlite3_mutex_enter(tls, mutex)
	vfsUnlink(tls, pVfs)
	Xsqlite3_mutex_leave(tls, mutex)
	return SQLITE_OK
}

type BenignMallocHooks1 = struct {
	FxBenignBegin uintptr
	FxBenignEnd   uintptr
}

type BenignMallocHooks = BenignMallocHooks1

var sqlite3Hooks = BenignMallocHooks1{}

func Xsqlite3BenignMallocHooks(tls *libc.TLS, xBenignBegin uintptr, xBenignEnd uintptr) {
	sqlite3Hooks.FxBenignBegin = xBenignBegin
	sqlite3Hooks.FxBenignEnd = xBenignEnd
}

func Xsqlite3BeginBenignMalloc(tls *libc.TLS) {
	if sqlite3Hooks.FxBenignBegin != 0 {
		(*struct{ f func(*libc.TLS) })(unsafe.Pointer(&struct{ uintptr }{sqlite3Hooks.FxBenignBegin})).f(tls)
	}
}

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

func sqlite3MemMalloc(tls *libc.TLS, nByte int32) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p uintptr

	p = libc.Xmalloc(tls, uint64(nByte+8))
	if p != 0 {
		*(*Sqlite3_int64)(unsafe.Pointer(p)) = Sqlite3_int64(nByte)
		p += 8
	} else {
		Xsqlite3_log(tls, SQLITE_NOMEM, ts+1498, libc.VaList(bp, nByte))
	}
	return p
}

func sqlite3MemFree(tls *libc.TLS, pPrior uintptr) {
	var p uintptr = pPrior

	p -= 8
	libc.Xfree(tls, p)
}

func sqlite3MemSize(tls *libc.TLS, pPrior uintptr) int32 {
	var p uintptr

	p = pPrior
	p -= 8
	return int32(*(*Sqlite3_int64)(unsafe.Pointer(p)))
}

func sqlite3MemRealloc(tls *libc.TLS, pPrior uintptr, nByte int32) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var p uintptr = pPrior

	p -= 8
	p = libc.Xrealloc(tls, p, uint64(nByte+8))
	if p != 0 {
		*(*Sqlite3_int64)(unsafe.Pointer(p)) = Sqlite3_int64(nByte)
		p += 8
	} else {
		Xsqlite3_log(tls, SQLITE_NOMEM,
			ts+1536,
			libc.VaList(bp, sqlite3MemSize(tls, pPrior), nByte))
	}
	return p
}

func sqlite3MemRoundup(tls *libc.TLS, n int32) int32 {
	return (n + 7) & libc.CplInt32(7)
}

func sqlite3MemInit(tls *libc.TLS, NotUsed uintptr) int32 {
	_ = NotUsed
	return SQLITE_OK
}

func sqlite3MemShutdown(tls *libc.TLS, NotUsed uintptr) {
	_ = NotUsed
	return
}

func Xsqlite3MemSetDefault(tls *libc.TLS) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	Xsqlite3_config(tls, SQLITE_CONFIG_MALLOC, libc.VaList(bp, uintptr(unsafe.Pointer(&defaultMethods))))
}

var defaultMethods = Sqlite3_mem_methods{
	FxMalloc:   0,
	FxFree:     0,
	FxRealloc:  0,
	FxSize:     0,
	FxRoundup:  0,
	FxInit:     0,
	FxShutdown: 0,
}

func Xsqlite3MutexInit(tls *libc.TLS) int32 {
	var rc int32 = SQLITE_OK
	if !(int32(Xsqlite3Config.Fmutex.FxMutexAlloc) != 0) {
		var pFrom uintptr
		var pTo uintptr = uintptr(unsafe.Pointer(&Xsqlite3Config)) + 96

		if Xsqlite3Config.FbCoreMutex != 0 {
			pFrom = Xsqlite3DefaultMutex(tls)
		} else {
			pFrom = Xsqlite3NoopMutex(tls)
		}
		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexInit = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexInit
		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexEnd = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexEnd
		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexFree = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexFree
		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexEnter = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexEnter
		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexTry = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexTry
		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexLeave = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexLeave
		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexHeld = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexHeld
		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexNotheld = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexNotheld

		(*Sqlite3_mutex_methods)(unsafe.Pointer(pTo)).FxMutexAlloc = (*Sqlite3_mutex_methods)(unsafe.Pointer(pFrom)).FxMutexAlloc
	}

	rc = (*struct{ f func(*libc.TLS) int32 })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fmutex.FxMutexInit})).f(tls)

	return rc
}

func Xsqlite3MutexEnd(tls *libc.TLS) int32 {
	var rc int32 = SQLITE_OK
	if Xsqlite3Config.Fmutex.FxMutexEnd != 0 {
		rc = (*struct{ f func(*libc.TLS) int32 })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fmutex.FxMutexEnd})).f(tls)
	}

	return rc
}

func Xsqlite3_mutex_alloc(tls *libc.TLS, id int32) uintptr {
	if id <= SQLITE_MUTEX_RECURSIVE && Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	if id > SQLITE_MUTEX_RECURSIVE && Xsqlite3MutexInit(tls) != 0 {
		return uintptr(0)
	}

	return (*struct {
		f func(*libc.TLS, int32) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fmutex.FxMutexAlloc})).f(tls, id)
}

func Xsqlite3MutexAlloc(tls *libc.TLS, id int32) uintptr {
	if !(int32(Xsqlite3Config.FbCoreMutex) != 0) {
		return uintptr(0)
	}

	return (*struct {
		f func(*libc.TLS, int32) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fmutex.FxMutexAlloc})).f(tls, id)
}

func Xsqlite3_mutex_free(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fmutex.FxMutexFree})).f(tls, p)
	}
}

func Xsqlite3_mutex_enter(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fmutex.FxMutexEnter})).f(tls, p)
	}
}

func Xsqlite3_mutex_try(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = SQLITE_OK
	if p != 0 {
		return (*struct {
			f func(*libc.TLS, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fmutex.FxMutexTry})).f(tls, p)
	}
	return rc
}

func Xsqlite3_mutex_leave(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fmutex.FxMutexLeave})).f(tls, p)
	}
}

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

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

func noopMutexAlloc(tls *libc.TLS, id int32) uintptr {
	_ = id
	return uintptr(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) int32 {
	_ = p
	return SQLITE_OK
}

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

func Xsqlite3NoopMutex(tls *libc.TLS) uintptr {
	return uintptr(unsafe.Pointer(&sMutex))
}

var sMutex = Sqlite3_mutex_methods{
	FxMutexInit:  0,
	FxMutexEnd:   0,
	FxMutexAlloc: 0,
	FxMutexFree:  0,
	FxMutexEnter: 0,
	FxMutexTry:   0,
	FxMutexLeave: 0,
}

func Xsqlite3DefaultMutex(tls *libc.TLS) uintptr {
	return Xsqlite3NoopMutex(tls)
}

func Xsqlite3_release_memory(tls *libc.TLS, n int32) int32 {
	return Xsqlite3PcacheReleaseMemory(tls, n)
}

type Mem0Global = struct {
	Fmutex          uintptr
	FalarmThreshold Sqlite3_int64
	FhardLimit      Sqlite3_int64
	FnearlyFull     int32
	F__ccgo_pad1    [4]byte
}

var mem0 = Mem0Global{}

func Xsqlite3MallocMutex(tls *libc.TLS) uintptr {
	return mem0.Fmutex
}

func Xsqlite3_memory_alarm(tls *libc.TLS, xCallback uintptr, pArg uintptr, iThreshold Sqlite3_int64) int32 {
	_ = xCallback
	_ = pArg
	_ = iThreshold
	return SQLITE_OK
}

func Xsqlite3_soft_heap_limit64(tls *libc.TLS, n Sqlite3_int64) Sqlite3_int64 {
	var priorLimit Sqlite3_int64
	var excess Sqlite3_int64
	var nUsed Sqlite3_int64
	var rc int32 = Xsqlite3_initialize(tls)
	if rc != 0 {
		return int64(-1)
	}
	Xsqlite3_mutex_enter(tls, mem0.Fmutex)
	priorLimit = mem0.FalarmThreshold
	if n < int64(0) {
		Xsqlite3_mutex_leave(tls, mem0.Fmutex)
		return priorLimit
	}
	if mem0.FhardLimit > int64(0) && (n > mem0.FhardLimit || n == int64(0)) {
		n = mem0.FhardLimit
	}
	mem0.FalarmThreshold = n
	nUsed = Xsqlite3StatusValue(tls, SQLITE_STATUS_MEMORY_USED)
	libc.AtomicStoreNInt32(uintptr(unsafe.Pointer(&mem0))+24, libc.Bool32(n > int64(0) && n <= nUsed), 0)
	Xsqlite3_mutex_leave(tls, mem0.Fmutex)
	excess = Xsqlite3_memory_used(tls) - n
	if excess > int64(0) {
		Xsqlite3_release_memory(tls, int32(excess&int64(0x7fffffff)))
	}
	return priorLimit
}

func Xsqlite3_soft_heap_limit(tls *libc.TLS, n int32) {
	if n < 0 {
		n = 0
	}
	Xsqlite3_soft_heap_limit64(tls, int64(n))
}

func Xsqlite3_hard_heap_limit64(tls *libc.TLS, n Sqlite3_int64) Sqlite3_int64 {
	var priorLimit Sqlite3_int64
	var rc int32 = Xsqlite3_initialize(tls)
	if rc != 0 {
		return int64(-1)
	}
	Xsqlite3_mutex_enter(tls, mem0.Fmutex)
	priorLimit = mem0.FhardLimit
	if n >= int64(0) {
		mem0.FhardLimit = n
		if n < mem0.FalarmThreshold || mem0.FalarmThreshold == int64(0) {
			mem0.FalarmThreshold = n
		}
	}
	Xsqlite3_mutex_leave(tls, mem0.Fmutex)
	return priorLimit
}

func Xsqlite3MallocInit(tls *libc.TLS) int32 {
	var rc int32
	if Xsqlite3Config.Fm.FxMalloc == uintptr(0) {
		Xsqlite3MemSetDefault(tls)
	}
	mem0.Fmutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MEM)
	if Xsqlite3Config.FpPage == uintptr(0) || Xsqlite3Config.FszPage < 512 ||
		Xsqlite3Config.FnPage <= 0 {
		Xsqlite3Config.FpPage = uintptr(0)
		Xsqlite3Config.FszPage = 0
	}
	rc = (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxInit})).f(tls, Xsqlite3Config.Fm.FpAppData)
	if rc != SQLITE_OK {
		libc.Xmemset(tls, uintptr(unsafe.Pointer(&mem0)), 0, uint64(unsafe.Sizeof(mem0)))
	}
	return rc
}

func Xsqlite3HeapNearlyFull(tls *libc.TLS) int32 {
	return libc.AtomicLoadNInt32(uintptr(unsafe.Pointer(&mem0))+24, 0)
}

func Xsqlite3MallocEnd(tls *libc.TLS) {
	if Xsqlite3Config.Fm.FxShutdown != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxShutdown})).f(tls, Xsqlite3Config.Fm.FpAppData)
	}
	libc.Xmemset(tls, uintptr(unsafe.Pointer(&mem0)), 0, uint64(unsafe.Sizeof(mem0)))
}

func Xsqlite3_memory_used(tls *libc.TLS) Sqlite3_int64 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	Xsqlite3_status64(tls, SQLITE_STATUS_MEMORY_USED, bp, bp+8, 0)
	return *(*Sqlite3_int64)(unsafe.Pointer(bp))
}

func Xsqlite3_memory_highwater(tls *libc.TLS, resetFlag int32) Sqlite3_int64 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	Xsqlite3_status64(tls, SQLITE_STATUS_MEMORY_USED, bp, bp+8, resetFlag)
	return *(*Sqlite3_int64)(unsafe.Pointer(bp + 8))
}

func sqlite3MallocAlarm(tls *libc.TLS, nByte int32) {
	if mem0.FalarmThreshold <= int64(0) {
		return
	}
	Xsqlite3_mutex_leave(tls, mem0.Fmutex)
	Xsqlite3_release_memory(tls, nByte)
	Xsqlite3_mutex_enter(tls, mem0.Fmutex)
}

func mallocWithAlarm(tls *libc.TLS, n int32, pp uintptr) {
	var p uintptr
	var nFull int32

	nFull = (*struct{ f func(*libc.TLS, int32) int32 })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxRoundup})).f(tls, n)

	Xsqlite3StatusHighwater(tls, SQLITE_STATUS_MALLOC_SIZE, n)
	if mem0.FalarmThreshold > int64(0) {
		var nUsed Sqlite3_int64 = Xsqlite3StatusValue(tls, SQLITE_STATUS_MEMORY_USED)
		if nUsed >= mem0.FalarmThreshold-Sqlite3_int64(nFull) {
			libc.AtomicStoreNInt32(uintptr(unsafe.Pointer(&mem0))+24, int32(1), 0)
			sqlite3MallocAlarm(tls, nFull)
			if mem0.FhardLimit != 0 {
				nUsed = Xsqlite3StatusValue(tls, SQLITE_STATUS_MEMORY_USED)
				if nUsed >= mem0.FhardLimit-Sqlite3_int64(nFull) {
					*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
					return
				}
			}
		} else {
			libc.AtomicStoreNInt32(uintptr(unsafe.Pointer(&mem0))+24, int32(0), 0)
		}
	}
	p = (*struct {
		f func(*libc.TLS, int32) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxMalloc})).f(tls, nFull)
	if p == uintptr(0) && mem0.FalarmThreshold > int64(0) {
		sqlite3MallocAlarm(tls, nFull)
		p = (*struct {
			f func(*libc.TLS, int32) uintptr
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxMalloc})).f(tls, nFull)
	}
	if p != 0 {
		nFull = Xsqlite3MallocSize(tls, p)
		Xsqlite3StatusUp(tls, SQLITE_STATUS_MEMORY_USED, nFull)
		Xsqlite3StatusUp(tls, SQLITE_STATUS_MALLOC_COUNT, 1)
	}
	*(*uintptr)(unsafe.Pointer(pp)) = p
}

func Xsqlite3Malloc(tls *libc.TLS, n U64) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if n == uint64(0) || n > uint64(SQLITE_MAX_ALLOCATION_SIZE) {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	} else if Xsqlite3Config.FbMemstat != 0 {
		Xsqlite3_mutex_enter(tls, mem0.Fmutex)
		mallocWithAlarm(tls, int32(n), bp)
		Xsqlite3_mutex_leave(tls, mem0.Fmutex)
	} else {
		*(*uintptr)(unsafe.Pointer(bp)) = (*struct {
			f func(*libc.TLS, int32) uintptr
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxMalloc})).f(tls, int32(n))
	}

	return *(*uintptr)(unsafe.Pointer(bp))
}

func Xsqlite3_malloc(tls *libc.TLS, n int32) uintptr {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	if n <= 0 {
		return uintptr(0)
	}
	return Xsqlite3Malloc(tls, uint64(n))
}

func Xsqlite3_malloc64(tls *libc.TLS, n Sqlite3_uint64) uintptr {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return Xsqlite3Malloc(tls, n)
}

func isLookaside(tls *libc.TLS, db uintptr, p uintptr) int32 {
	return libc.Bool32(Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) && Uptr(p) < Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd))
}

func Xsqlite3MallocSize(tls *libc.TLS, p uintptr) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxSize})).f(tls, p)
}

func lookasideMallocSize(tls *libc.TLS, db uintptr, p uintptr) int32 {
	if p < (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle {
		return int32((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
	}
	return LOOKASIDE_SMALL
}

func Xsqlite3DbMallocSize(tls *libc.TLS, db uintptr, p uintptr) int32 {
	if db != 0 {
		if Uptr(p) < Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd) {
			if Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
				return LOOKASIDE_SMALL
			}
			if Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
				return int32((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue)
			}
		}
	}
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxSize})).f(tls, p)
}

func Xsqlite3_msize(tls *libc.TLS, p uintptr) Sqlite3_uint64 {
	if p != 0 {
		return uint64((*struct {
			f func(*libc.TLS, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxSize})).f(tls, p))
	}
	return uint64(0)
}

func Xsqlite3_free(tls *libc.TLS, p uintptr) {
	if p == uintptr(0) {
		return
	}

	if Xsqlite3Config.FbMemstat != 0 {
		Xsqlite3_mutex_enter(tls, mem0.Fmutex)
		Xsqlite3StatusDown(tls, SQLITE_STATUS_MEMORY_USED, Xsqlite3MallocSize(tls, p))
		Xsqlite3StatusDown(tls, SQLITE_STATUS_MALLOC_COUNT, 1)
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxFree})).f(tls, p)
		Xsqlite3_mutex_leave(tls, mem0.Fmutex)
	} else {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxFree})).f(tls, p)
	}
}

func measureAllocationSize(tls *libc.TLS, db uintptr, p uintptr) {
	*(*int32)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed)) += Xsqlite3DbMallocSize(tls, db, p)
}

func Xsqlite3DbFreeNN(tls *libc.TLS, db uintptr, p uintptr) {
	if db != 0 {
		if Uptr(p) < Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
			if Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
				var pBuf uintptr = p

				(*LookasideSlot)(unsafe.Pointer(pBuf)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
				(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = pBuf
				return
			}
			if Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
				var pBuf uintptr = p

				(*LookasideSlot)(unsafe.Pointer(pBuf)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
				(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = pBuf
				return
			}
		}
		if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed != 0 {
			measureAllocationSize(tls, db, p)
			return
		}
	}

	Xsqlite3_free(tls, p)
}

func Xsqlite3DbNNFreeNN(tls *libc.TLS, db uintptr, p uintptr) {
	if Uptr(p) < Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
		if Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
			var pBuf uintptr = p

			(*LookasideSlot)(unsafe.Pointer(pBuf)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
			(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = pBuf
			return
		}
		if Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
			var pBuf uintptr = p

			(*LookasideSlot)(unsafe.Pointer(pBuf)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
			(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = pBuf
			return
		}
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed != 0 {
		measureAllocationSize(tls, db, p)
		return
	}

	Xsqlite3_free(tls, p)
}

func Xsqlite3DbFree(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		Xsqlite3DbFreeNN(tls, db, p)
	}
}

func Xsqlite3Realloc(tls *libc.TLS, pOld uintptr, nBytes U64) uintptr {
	var nOld int32
	var nNew int32
	var nDiff int32
	var pNew uintptr

	if pOld == uintptr(0) {
		return Xsqlite3Malloc(tls, nBytes)
	}
	if nBytes == uint64(0) {
		Xsqlite3_free(tls, pOld)
		return uintptr(0)
	}
	if nBytes >= uint64(0x7fffff00) {
		return uintptr(0)
	}
	nOld = Xsqlite3MallocSize(tls, pOld)

	nNew = (*struct{ f func(*libc.TLS, int32) int32 })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxRoundup})).f(tls, int32(nBytes))
	if nOld == nNew {
		pNew = pOld
	} else if Xsqlite3Config.FbMemstat != 0 {
		var nUsed Sqlite3_int64
		Xsqlite3_mutex_enter(tls, mem0.Fmutex)
		Xsqlite3StatusHighwater(tls, SQLITE_STATUS_MALLOC_SIZE, int32(nBytes))
		nDiff = nNew - nOld
		if nDiff > 0 && libc.AssignInt64(&nUsed, Xsqlite3StatusValue(tls, SQLITE_STATUS_MEMORY_USED)) >= mem0.FalarmThreshold-Sqlite3_int64(nDiff) {
			sqlite3MallocAlarm(tls, nDiff)
			if mem0.FhardLimit > int64(0) && nUsed >= mem0.FhardLimit-Sqlite3_int64(nDiff) {
				Xsqlite3_mutex_leave(tls, mem0.Fmutex)
				return uintptr(0)
			}
		}
		pNew = (*struct {
			f func(*libc.TLS, uintptr, int32) uintptr
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxRealloc})).f(tls, pOld, nNew)
		if pNew == uintptr(0) && mem0.FalarmThreshold > int64(0) {
			sqlite3MallocAlarm(tls, int32(nBytes))
			pNew = (*struct {
				f func(*libc.TLS, uintptr, int32) uintptr
			})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxRealloc})).f(tls, pOld, nNew)
		}
		if pNew != 0 {
			nNew = Xsqlite3MallocSize(tls, pNew)
			Xsqlite3StatusUp(tls, SQLITE_STATUS_MEMORY_USED, nNew-nOld)
		}
		Xsqlite3_mutex_leave(tls, mem0.Fmutex)
	} else {
		pNew = (*struct {
			f func(*libc.TLS, uintptr, int32) uintptr
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fm.FxRealloc})).f(tls, pOld, nNew)
	}

	return pNew
}

func Xsqlite3_realloc(tls *libc.TLS, pOld uintptr, n int32) uintptr {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	if n < 0 {
		n = 0
	}
	return Xsqlite3Realloc(tls, pOld, uint64(n))
}

func Xsqlite3_realloc64(tls *libc.TLS, pOld uintptr, n Sqlite3_uint64) uintptr {
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	return Xsqlite3Realloc(tls, pOld, n)
}

func Xsqlite3MallocZero(tls *libc.TLS, n U64) uintptr {
	var p uintptr = Xsqlite3Malloc(tls, n)
	if p != 0 {
		libc.Xmemset(tls, p, 0, n)
	}
	return p
}

func Xsqlite3DbMallocZero(tls *libc.TLS, db uintptr, n U64) uintptr {
	var p uintptr

	p = Xsqlite3DbMallocRaw(tls, db, n)
	if p != 0 {
		libc.Xmemset(tls, p, 0, n)
	}
	return p
}

func dbMallocRawFinish(tls *libc.TLS, db uintptr, n U64) uintptr {
	var p uintptr

	p = Xsqlite3Malloc(tls, n)
	if !(p != 0) {
		Xsqlite3OomFault(tls, db)
	}

	return p
}

func Xsqlite3DbMallocRaw(tls *libc.TLS, db uintptr, n U64) uintptr {
	var p uintptr
	if db != 0 {
		return Xsqlite3DbMallocRawNN(tls, db, n)
	}
	p = Xsqlite3Malloc(tls, n)

	return p
}

func Xsqlite3DbMallocRawNN(tls *libc.TLS, db uintptr, n U64) uintptr {
	var pBuf uintptr

	if n > U64((*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz) {
		if !(int32((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable) != 0) {
			*(*U32)(unsafe.Pointer(db + 440 + 16 + 1*4))++
		} else if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return uintptr(0)
		}
		return dbMallocRawFinish(tls, db, n)
	}
	if n <= uint64(LOOKASIDE_SMALL) {
		if libc.AssignUintptr(&pBuf, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree) != uintptr(0) {
			(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = (*LookasideSlot)(unsafe.Pointer(pBuf)).FpNext
			*(*U32)(unsafe.Pointer(db + 440 + 16))++
			return pBuf
		} else if libc.AssignUintptr(&pBuf, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit) != uintptr(0) {
			(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = (*LookasideSlot)(unsafe.Pointer(pBuf)).FpNext
			*(*U32)(unsafe.Pointer(db + 440 + 16))++
			return pBuf
		}
	}
	if libc.AssignUintptr(&pBuf, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree) != uintptr(0) {
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = (*LookasideSlot)(unsafe.Pointer(pBuf)).FpNext
		*(*U32)(unsafe.Pointer(db + 440 + 16))++
		return pBuf
	} else if libc.AssignUintptr(&pBuf, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpInit) != uintptr(0) {
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpInit = (*LookasideSlot)(unsafe.Pointer(pBuf)).FpNext
		*(*U32)(unsafe.Pointer(db + 440 + 16))++
		return pBuf
	} else {
		*(*U32)(unsafe.Pointer(db + 440 + 16 + 2*4))++
	}
	return dbMallocRawFinish(tls, db, n)
}

func Xsqlite3DbRealloc(tls *libc.TLS, db uintptr, p uintptr, n U64) uintptr {
	if p == uintptr(0) {
		return Xsqlite3DbMallocRawNN(tls, db, n)
	}

	if Uptr(p) < Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
		if Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
			if n <= uint64(LOOKASIDE_SMALL) {
				return p
			}
		} else if Uptr(p) >= Uptr((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
			if n <= U64((*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue) {
				return p
			}
		}
	}
	return dbReallocFinish(tls, db, p, n)
}

func dbReallocFinish(tls *libc.TLS, db uintptr, p uintptr, n U64) uintptr {
	var pNew uintptr = uintptr(0)

	if int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		if isLookaside(tls, db, p) != 0 {
			pNew = Xsqlite3DbMallocRawNN(tls, db, n)
			if pNew != 0 {
				libc.Xmemcpy(tls, pNew, p, uint64(lookasideMallocSize(tls, db, p)))
				Xsqlite3DbFree(tls, db, p)
			}
		} else {
			pNew = Xsqlite3Realloc(tls, p, n)
			if !(pNew != 0) {
				Xsqlite3OomFault(tls, db)
			}

		}
	}
	return pNew
}

func Xsqlite3DbReallocOrFree(tls *libc.TLS, db uintptr, p uintptr, n U64) uintptr {
	var pNew uintptr
	pNew = Xsqlite3DbRealloc(tls, db, p, n)
	if !(pNew != 0) {
		Xsqlite3DbFree(tls, db, p)
	}
	return pNew
}

func Xsqlite3DbStrDup(tls *libc.TLS, db uintptr, z uintptr) uintptr {
	var zNew uintptr
	var n Size_t
	if z == uintptr(0) {
		return uintptr(0)
	}
	n = libc.Xstrlen(tls, z) + uint64(1)
	zNew = Xsqlite3DbMallocRaw(tls, db, n)
	if zNew != 0 {
		libc.Xmemcpy(tls, zNew, z, n)
	}
	return zNew
}

func Xsqlite3DbStrNDup(tls *libc.TLS, db uintptr, z uintptr, n U64) uintptr {
	var zNew uintptr

	if z != 0 {
		zNew = Xsqlite3DbMallocRawNN(tls, db, n+uint64(1))
	} else {
		zNew = uintptr(0)
	}
	if zNew != 0 {
		libc.Xmemcpy(tls, zNew, z, n)
		*(*uint8)(unsafe.Pointer(zNew + uintptr(n))) = uint8(0)
	}
	return zNew
}

func Xsqlite3DbSpanDup(tls *libc.TLS, db uintptr, zStart uintptr, zEnd uintptr) uintptr {
	var n int32
	for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zStart))])&0x01 != 0 {
		zStart++
	}
	n = int32((int64(zEnd) - int64(zStart)) / 1)
	for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zStart + uintptr(n-1)))])&0x01 != 0 {
		n--
	}
	return Xsqlite3DbStrNDup(tls, db, zStart, uint64(n))
}

func Xsqlite3SetString(tls *libc.TLS, pz uintptr, db uintptr, zNew uintptr) {
	var z uintptr = Xsqlite3DbStrDup(tls, db, zNew)
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pz)))
	*(*uintptr)(unsafe.Pointer(pz)) = z
}

func Xsqlite3OomFault(tls *libc.TLS, db uintptr) uintptr {
	if int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && int32((*Sqlite3)(unsafe.Pointer(db)).FbBenignMalloc) == 0 {
		(*Sqlite3)(unsafe.Pointer(db)).FmallocFailed = U8(1)
		if (*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec > 0 {
			libc.AtomicStoreNInt32(db+432, int32(1), 0)
		}
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)
		if (*Sqlite3)(unsafe.Pointer(db)).FpParse != 0 {
			var pParse uintptr
			Xsqlite3ErrorMsg(tls, (*Sqlite3)(unsafe.Pointer(db)).FpParse, ts+1572, 0)
			(*Parse)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpParse)).Frc = SQLITE_NOMEM
			for pParse = (*Parse)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpParse)).FpOuterParse; pParse != 0; pParse = (*Parse)(unsafe.Pointer(pParse)).FpOuterParse {
				(*Parse)(unsafe.Pointer(pParse)).FnErr++
				(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
			}
		}
	}
	return uintptr(0)
}

func Xsqlite3OomClear(tls *libc.TLS, db uintptr) {
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 && (*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec == 0 {
		(*Sqlite3)(unsafe.Pointer(db)).FmallocFailed = U8(0)
		libc.AtomicStoreNInt32(db+432, int32(0), 0)

		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable--
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = func() uint16 {
			if (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
				return uint16(0)
			}
			return (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue
		}()
	}
}

func apiHandleError(tls *libc.TLS, db uintptr, rc int32) int32 {
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 || rc == SQLITE_IOERR|int32(12)<<8 {
		Xsqlite3OomClear(tls, db)
		Xsqlite3Error(tls, db, SQLITE_NOMEM)
		return SQLITE_NOMEM
	}
	return rc & (*Sqlite3)(unsafe.Pointer(db)).FerrMask
}

func Xsqlite3ApiExit(tls *libc.TLS, db uintptr, rc int32) int32 {
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 || rc != 0 {
		return apiHandleError(tls, db, rc)
	}
	return rc & (*Sqlite3)(unsafe.Pointer(db)).FerrMask
}

type EtByte = uint8

type et_info = struct {
	Ffmttype uint8
	Fbase    EtByte
	Fflags   EtByte
	Ftype    EtByte
	Fcharset EtByte
	Fprefix  EtByte
}

type Et_info = et_info

var aDigits = *(*[33]uint8)(unsafe.Pointer(ts + 1586))
var aPrefix = *(*[7]uint8)(unsafe.Pointer(ts + 1619))
var fmtinfo = [23]Et_info{
	{Ffmttype: uint8('d'), Fbase: EtByte(10), Fflags: EtByte(1), Ftype: EtByte(EtDECIMAL)},
	{Ffmttype: uint8('s'), Fflags: EtByte(4), Ftype: EtByte(EtSTRING)},
	{Ffmttype: uint8('g'), Fflags: EtByte(1), Ftype: EtByte(EtGENERIC), Fcharset: EtByte(30)},
	{Ffmttype: uint8('z'), Fflags: EtByte(4), Ftype: EtByte(EtDYNSTRING)},
	{Ffmttype: uint8('q'), Fflags: EtByte(4), Ftype: EtByte(EtSQLESCAPE)},
	{Ffmttype: uint8('Q'), Fflags: EtByte(4), Ftype: EtByte(EtSQLESCAPE2)},
	{Ffmttype: uint8('w'), Fflags: EtByte(4), Ftype: EtByte(EtSQLESCAPE3)},
	{Ffmttype: uint8('c'), Ftype: EtByte(EtCHARX)},
	{Ffmttype: uint8('o'), Fbase: EtByte(8), Fprefix: EtByte(2)},
	{Ffmttype: uint8('u'), Fbase: EtByte(10), Ftype: EtByte(EtDECIMAL)},
	{Ffmttype: uint8('x'), Fbase: EtByte(16), Fcharset: EtByte(16), Fprefix: EtByte(1)},
	{Ffmttype: uint8('X'), Fbase: EtByte(16), Fprefix: EtByte(4)},
	{Ffmttype: uint8('f'), Fflags: EtByte(1), Ftype: EtByte(EtFLOAT)},
	{Ffmttype: uint8('e'), Fflags: EtByte(1), Ftype: EtByte(EtEXP), Fcharset: EtByte(30)},
	{Ffmttype: uint8('E'), Fflags: EtByte(1), Ftype: EtByte(EtEXP), Fcharset: EtByte(14)},
	{Ffmttype: uint8('G'), Fflags: EtByte(1), Ftype: EtByte(EtGENERIC), Fcharset: EtByte(14)},
	{Ffmttype: uint8('i'), Fbase: EtByte(10), Fflags: EtByte(1), Ftype: EtByte(EtDECIMAL)},
	{Ffmttype: uint8('n'), Ftype: EtByte(EtSIZE)},
	{Ffmttype: uint8('%'), Ftype: EtByte(EtPERCENT)},
	{Ffmttype: uint8('p'), Fbase: EtByte(16), Ftype: EtByte(EtPOINTER), Fprefix: EtByte(1)},
	{Ffmttype: uint8('T'), Ftype: EtByte(EtTOKEN)},
	{Ffmttype: uint8('S'), Ftype: EtByte(EtSRCITEM)},
	{Ffmttype: uint8('r'), Fbase: EtByte(10), Fflags: EtByte(1), Ftype: EtByte(EtORDINAL)},
}

var arRound = [10]float64{
	5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
	5.0e-06, 5.0e-07, 5.0e-08, 5.0e-09, 5.0e-10,
}

func et_getdigit(tls *libc.TLS, val uintptr, cnt uintptr) uint8 {
	var digit int32
	var d float64
	if *(*int32)(unsafe.Pointer(cnt)) <= 0 {
		return uint8('0')
	}
	*(*int32)(unsafe.Pointer(cnt))--
	digit = int32(*(*float64)(unsafe.Pointer(val)))
	d = float64(digit)
	digit = digit + '0'
	*(*float64)(unsafe.Pointer(val)) = (*(*float64)(unsafe.Pointer(val)) - d) * 10.0
	return uint8(digit)
}

func Xsqlite3StrAccumSetError(tls *libc.TLS, p uintptr, eError U8) {
	(*StrAccum)(unsafe.Pointer(p)).FaccError = eError
	if (*StrAccum)(unsafe.Pointer(p)).FmxAlloc != 0 {
		Xsqlite3_str_reset(tls, p)
	}
	if int32(eError) == SQLITE_TOOBIG {
		Xsqlite3ErrorToParser(tls, (*StrAccum)(unsafe.Pointer(p)).Fdb, int32(eError))
	}
}

func getIntArg(tls *libc.TLS, p uintptr) Sqlite3_int64 {
	if (*PrintfArguments)(unsafe.Pointer(p)).FnArg <= (*PrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return int64(0)
	}
	return Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer((*PrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(libc.PostIncInt32(&(*PrintfArguments)(unsafe.Pointer(p)).FnUsed, 1))*8)))
}

func getDoubleArg(tls *libc.TLS, p uintptr) float64 {
	if (*PrintfArguments)(unsafe.Pointer(p)).FnArg <= (*PrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return 0.0
	}
	return Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer((*PrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(libc.PostIncInt32(&(*PrintfArguments)(unsafe.Pointer(p)).FnUsed, 1))*8)))
}

func getTextArg(tls *libc.TLS, p uintptr) uintptr {
	if (*PrintfArguments)(unsafe.Pointer(p)).FnArg <= (*PrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return uintptr(0)
	}
	return Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer((*PrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(libc.PostIncInt32(&(*PrintfArguments)(unsafe.Pointer(p)).FnUsed, 1))*8)))
}

func printfTempBuf(tls *libc.TLS, pAccum uintptr, n Sqlite3_int64) uintptr {
	var z uintptr
	if (*Sqlite3_str)(unsafe.Pointer(pAccum)).FaccError != 0 {
		return uintptr(0)
	}
	if n > Sqlite3_int64((*Sqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc) && n > Sqlite3_int64((*Sqlite3_str)(unsafe.Pointer(pAccum)).FmxAlloc) {
		Xsqlite3StrAccumSetError(tls, pAccum, uint8(SQLITE_TOOBIG))
		return uintptr(0)
	}
	z = Xsqlite3DbMallocRaw(tls, (*Sqlite3_str)(unsafe.Pointer(pAccum)).Fdb, uint64(n))
	if z == uintptr(0) {
		Xsqlite3StrAccumSetError(tls, pAccum, uint8(SQLITE_NOMEM))
	}
	return z
}

func Xsqlite3_str_vappendf(tls *libc.TLS, pAccum uintptr, fmt uintptr, ap Va_list) {
	bp := tls.Alloc(116)
	defer tls.Free(116)

	var c int32
	var bufpt uintptr
	var precision int32
	var length int32
	var idx int32
	var width int32
	var flag_leftjustify EtByte
	var flag_prefix EtByte
	var flag_alternateform EtByte
	var flag_altform2 EtByte
	var flag_zeropad EtByte
	var flag_long EtByte
	var done EtByte
	var cThousand EtByte
	var xtype EtByte
	var bArgList U8
	var prefix uint8
	var longvalue Sqlite_uint64

	var infop uintptr
	var zOut uintptr
	var nOut int32
	var zExtra uintptr
	var exp int32
	var e2 int32

	var rounder float64
	var flag_dp EtByte
	var flag_rtz EtByte
	var pArgList uintptr

	var wx uint32
	var px uint32
	var v I64
	var n U64
	var x int32
	var cset uintptr
	var base U8
	var nn int32
	var ix int32
	var pre uintptr
	var x1 uint8

	var ex int32
	var scale float64
	var szBufNeeded I64
	var i int32
	var nPad int32
	var ch uint32
	var nCopyBytes I64
	var nPrior I64

	var z uintptr

	var ii int32
	var i1 I64
	var j I64
	var k I64
	var n1 I64
	var needQuote int32
	var isnull int32
	var ch1 uint8
	var q uint8
	var escarg uintptr

	var pExpr uintptr

	var pToken uintptr
	var pSel uintptr
	var pItem uintptr
	xtype = EtByte(EtINVALID)
	zExtra = uintptr(0)
	pArgList = uintptr(0)

	bufpt = uintptr(0)
	if !(int32((*Sqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&SQLITE_PRINTF_SQLFUNC != 0) {
		goto __1
	}
	pArgList = libc.VaUintptr(&ap)
	bArgList = U8(1)
	goto __2
__1:
	bArgList = U8(0)
__2:
	;
__3:
	if !(libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(fmt)))) != 0) {
		goto __5
	}
	if !(c != '%') {
		goto __6
	}
	bufpt = fmt
__7:
	fmt++
	goto __8
__8:
	if *(*uint8)(unsafe.Pointer(fmt)) != 0 && int32(*(*uint8)(unsafe.Pointer(fmt))) != '%' {
		goto __7
	}
	goto __9
__9:
	;
	Xsqlite3_str_append(tls, pAccum, bufpt, int32((int64(fmt)-int64(bufpt))/1))
	if !(int32(*(*uint8)(unsafe.Pointer(fmt))) == 0) {
		goto __10
	}
	goto __5
__10:
	;
__6:
	;
	if !(libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))) == 0) {
		goto __11
	}
	Xsqlite3_str_append(tls, pAccum, ts+1626, 1)
	goto __5
__11:
	;
	flag_leftjustify = libc.AssignUint8(&flag_prefix, libc.AssignUint8(&cThousand, libc.AssignUint8(&flag_alternateform, libc.AssignUint8(&flag_altform2, libc.AssignUint8(&flag_zeropad, EtByte(0))))))
	done = EtByte(0)
	width = 0
	flag_long = EtByte(0)
	precision = -1
__12:
	switch c {
	case '-':
		goto __16
	case '+':
		goto __17
	case ' ':
		goto __18
	case '#':
		goto __19
	case '!':
		goto __20
	case '0':
		goto __21
	case ',':
		goto __22
	default:
		goto __23
	case 'l':
		goto __24
	case '1':
		goto __25
	case '2':
		goto __26
	case '3':
		goto __27
	case '4':
		goto __28
	case '5':
		goto __29
	case '6':
		goto __30
	case '7':
		goto __31
	case '8':
		goto __32
	case '9':
		goto __33
	case '*':
		goto __34
	case '.':
		goto __35
	}
	goto __15
__16:
	flag_leftjustify = EtByte(1)
	goto __15
__17:
	flag_prefix = EtByte('+')
	goto __15
__18:
	flag_prefix = EtByte(' ')
	goto __15
__19:
	flag_alternateform = EtByte(1)
	goto __15
__20:
	flag_altform2 = EtByte(1)
	goto __15
__21:
	flag_zeropad = EtByte(1)
	goto __15
__22:
	cThousand = EtByte(',')
	goto __15
__23:
	done = EtByte(1)
	goto __15
__24:
	flag_long = EtByte(1)
	c = int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))
	if !(c == 'l') {
		goto __36
	}
	c = int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))
	flag_long = EtByte(2)
__36:
	;
	done = EtByte(1)
	goto __15

__25:
__26:
__27:
__28:
__29:
__30:
__31:
__32:
__33:
	wx = uint32(c - '0')
__37:
	if !(libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))) >= '0' && c <= '9') {
		goto __38
	}
	wx = wx*uint32(10) + uint32(c) - uint32('0')
	goto __37
__38:
	;
	width = int32(wx & uint32(0x7fffffff))
	if !(c != '.' && c != 'l') {
		goto __39
	}
	done = EtByte(1)
	goto __40
__39:
	fmt--
__40:
	;
	goto __15

__34:
	if !(bArgList != 0) {
		goto __41
	}
	width = int32(getIntArg(tls, pArgList))
	goto __42
__41:
	width = libc.VaInt32(&ap)
__42:
	;
	if !(width < 0) {
		goto __43
	}
	flag_leftjustify = EtByte(1)
	if width >= -2147483647 {
		width = -width
	} else {
		width = 0
	}
__43:
	;
	if !(libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(fmt + 1)))) != '.' && c != 'l') {
		goto __44
	}
	c = int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))
	done = EtByte(1)
__44:
	;
	goto __15

__35:
	c = int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))
	if !(c == '*') {
		goto __45
	}
	if !(bArgList != 0) {
		goto __47
	}
	precision = int32(getIntArg(tls, pArgList))
	goto __48
__47:
	precision = libc.VaInt32(&ap)
__48:
	;
	if !(precision < 0) {
		goto __49
	}
	if precision >= -2147483647 {
		precision = -precision
	} else {
		precision = -1
	}
__49:
	;
	c = int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))
	goto __46
__45:
	px = uint32(0)
__50:
	if !(c >= '0' && c <= '9') {
		goto __51
	}
	px = px*uint32(10) + uint32(c) - uint32('0')
	c = int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))
	goto __50
__51:
	;
	precision = int32(px & uint32(0x7fffffff))
__46:
	;
	if !(c == 'l') {
		goto __52
	}
	fmt--
	goto __53
__52:
	done = EtByte(1)
__53:
	;
	goto __15

__15:
	;
	goto __13
__13:
	if !(done != 0) && libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(libc.PreIncUintptr(&fmt, 1))))) != 0 {
		goto __12
	}
	goto __14
__14:
	;
	infop = uintptr(unsafe.Pointer(&fmtinfo))
	xtype = EtByte(EtINVALID)
	idx = 0
__54:
	if !(idx < int32(uint64(unsafe.Sizeof(fmtinfo))/uint64(unsafe.Sizeof(Et_info{})))) {
		goto __56
	}
	if !(c == int32(fmtinfo[idx].Ffmttype)) {
		goto __57
	}
	infop = uintptr(unsafe.Pointer(&fmtinfo)) + uintptr(idx)*6
	xtype = (*Et_info)(unsafe.Pointer(infop)).Ftype
	goto __56
__57:
	;
	goto __55
__55:
	idx++
	goto __54
	goto __56
__56:
	;
	switch int32(xtype) {
	case EtPOINTER:
		goto __59
	case EtORDINAL:
		goto __60
	case EtRADIX:
		goto __61
	case EtDECIMAL:
		goto __62
	case EtFLOAT:
		goto __63
	case EtEXP:
		goto __64
	case EtGENERIC:
		goto __65
	case EtSIZE:
		goto __66
	case EtPERCENT:
		goto __67
	case EtCHARX:
		goto __68
	case EtSTRING:
		goto __69
	case EtDYNSTRING:
		goto __70
	case EtSQLESCAPE:
		goto __71
	case EtSQLESCAPE2:
		goto __72
	case EtSQLESCAPE3:
		goto __73
	case EtTOKEN:
		goto __74
	case EtSRCITEM:
		goto __75
	default:
		goto __76
	}
	goto __58
__59:
	if uint64(unsafe.Sizeof(uintptr(0))) == uint64(unsafe.Sizeof(I64(0))) {
		flag_long = uint8(2)
	} else {
		if uint64(unsafe.Sizeof(uintptr(0))) == uint64(unsafe.Sizeof(int64(0))) {
			flag_long = uint8(1)
		} else {
			flag_long = uint8(0)
		}
	}
__60:
__61:
	cThousand = EtByte(0)
__62:
	if !(int32((*Et_info)(unsafe.Pointer(infop)).Fflags)&FLAG_SIGNED != 0) {
		goto __77
	}
	if !(bArgList != 0) {
		goto __79
	}
	v = getIntArg(tls, pArgList)
	goto __80
__79:
	if !(flag_long != 0) {
		goto __81
	}
	if !(int32(flag_long) == 2) {
		goto __83
	}
	v = libc.VaInt64(&ap)
	goto __84
__83:
	v = libc.VaInt64(&ap)
__84:
	;
	goto __82
__81:
	v = I64(libc.VaInt32(&ap))
__82:
	;
__80:
	;
	if !(v < int64(0)) {
		goto __85
	}

	longvalue = Sqlite_uint64(^v)
	longvalue++
	prefix = uint8('-')
	goto __86
__85:
	longvalue = Sqlite_uint64(v)
	prefix = flag_prefix
__86:
	;
	goto __78
__77:
	if !(bArgList != 0) {
		goto __87
	}
	longvalue = U64(getIntArg(tls, pArgList))
	goto __88
__87:
	if !(flag_long != 0) {
		goto __89
	}
	if !(int32(flag_long) == 2) {
		goto __91
	}
	longvalue = libc.VaUint64(&ap)
	goto __92
__91:
	longvalue = libc.VaUint64(&ap)
__92:
	;
	goto __90
__89:
	longvalue = Sqlite_uint64(libc.VaUint32(&ap))
__90:
	;
__88:
	;
	prefix = uint8(0)
__78:
	;
	if !(longvalue == uint64(0)) {
		goto __93
	}
	flag_alternateform = EtByte(0)
__93:
	;
	if !(flag_zeropad != 0 && precision < width-libc.Bool32(int32(prefix) != 0)) {
		goto __94
	}
	precision = width - libc.Bool32(int32(prefix) != 0)
__94:
	;
	if !(precision < SQLITE_PRINT_BUF_SIZE-10-SQLITE_PRINT_BUF_SIZE/3) {
		goto __95
	}
	nOut = SQLITE_PRINT_BUF_SIZE
	zOut = bp + 16
	goto __96
__95:
	n = U64(precision) + uint64(10)
	if !(cThousand != 0) {
		goto __97
	}
	n = n + U64(precision/3)
__97:
	;
	zOut = libc.AssignUintptr(&zExtra, printfTempBuf(tls, pAccum, int64(n)))
	if !(zOut == uintptr(0)) {
		goto __98
	}
	return
__98:
	;
	nOut = int32(n)
__96:
	;
	bufpt = zOut + uintptr(nOut-1)
	if !(int32(xtype) == EtORDINAL) {
		goto __99
	}
	x = int32(longvalue % uint64(10))
	if !(x >= 4 || longvalue/uint64(10)%uint64(10) == uint64(1)) {
		goto __100
	}
	x = 0
__100:
	;
	*(*uint8)(unsafe.Pointer(libc.PreDecUintptr(&bufpt, 1))) = zOrd[x*2+1]
	*(*uint8)(unsafe.Pointer(libc.PreDecUintptr(&bufpt, 1))) = zOrd[x*2]
__99:
	;
	cset = uintptr(unsafe.Pointer(&aDigits)) + uintptr((*Et_info)(unsafe.Pointer(infop)).Fcharset)
	base = (*Et_info)(unsafe.Pointer(infop)).Fbase
__101:
	*(*uint8)(unsafe.Pointer(libc.PreDecUintptr(&bufpt, 1))) = *(*uint8)(unsafe.Pointer(cset + uintptr(longvalue%Sqlite_uint64(base))))
	longvalue = longvalue / Sqlite_uint64(base)
	goto __102
__102:
	if longvalue > uint64(0) {
		goto __101
	}
	goto __103
__103:
	;
	length = int32((int64(zOut+uintptr(nOut-1)) - int64(bufpt)) / 1)
__104:
	if !(precision > length) {
		goto __105
	}
	*(*uint8)(unsafe.Pointer(libc.PreDecUintptr(&bufpt, 1))) = uint8('0')
	length++
	goto __104
__105:
	;
	if !(cThousand != 0) {
		goto __106
	}
	nn = (length - 1) / 3
	ix = (length-1)%3 + 1
	bufpt -= uintptr(nn)
	idx = 0
__107:
	if !(nn > 0) {
		goto __109
	}
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(idx))) = *(*uint8)(unsafe.Pointer(bufpt + uintptr(idx+nn)))
	ix--
	if !(ix == 0) {
		goto __110
	}
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(libc.PreIncInt32(&idx, 1)))) = cThousand
	nn--
	ix = 3
__110:
	;
	goto __108
__108:
	idx++
	goto __107
	goto __109
__109:
	;
__106:
	;
	if !(prefix != 0) {
		goto __111
	}
	*(*uint8)(unsafe.Pointer(libc.PreDecUintptr(&bufpt, 1))) = prefix
__111:
	;
	if !(flag_alternateform != 0 && (*Et_info)(unsafe.Pointer(infop)).Fprefix != 0) {
		goto __112
	}
	pre = uintptr(unsafe.Pointer(&aPrefix)) + uintptr((*Et_info)(unsafe.Pointer(infop)).Fprefix)
__113:
	if !(int32(libc.AssignUint8(&x1, *(*uint8)(unsafe.Pointer(pre)))) != 0) {
		goto __115
	}
	*(*uint8)(unsafe.Pointer(libc.PreDecUintptr(&bufpt, 1))) = x1
	goto __114
__114:
	pre++
	goto __113
	goto __115
__115:
	;
__112:
	;
	length = int32((int64(zOut+uintptr(nOut-1)) - int64(bufpt)) / 1)
	goto __58
__63:
__64:
__65:
	if !(bArgList != 0) {
		goto __116
	}
	*(*float64)(unsafe.Pointer(bp + 104)) = getDoubleArg(tls, pArgList)
	goto __117
__116:
	*(*float64)(unsafe.Pointer(bp + 104)) = libc.VaFloat64(&ap)
__117:
	;
	if !(precision < 0) {
		goto __118
	}
	precision = 6
__118:
	;
	if !(precision > SQLITE_FP_PRECISION_LIMIT) {
		goto __119
	}
	precision = SQLITE_FP_PRECISION_LIMIT
__119:
	;
	if !(*(*float64)(unsafe.Pointer(bp + 104)) < 0.0) {
		goto __120
	}
	*(*float64)(unsafe.Pointer(bp + 104)) = -*(*float64)(unsafe.Pointer(bp + 104))
	prefix = uint8('-')
	goto __121
__120:
	prefix = flag_prefix
__121:
	;
	if !(int32(xtype) == EtGENERIC && precision > 0) {
		goto __122
	}
	precision--
__122:
	;
	idx = precision & 0xfff
	rounder = arRound[idx%10]
__123:
	if !(idx >= 10) {
		goto __124
	}
	rounder = rounder * 1.0e-10
	idx = idx - 10
	goto __123
__124:
	;
	if !(int32(xtype) == EtFLOAT) {
		goto __125
	}
	*(*float64)(unsafe.Pointer(bp + 96)) = *(*float64)(unsafe.Pointer(bp + 104))
	libc.Xmemcpy(tls, bp+88, bp+96, uint64(unsafe.Sizeof(Sqlite3_uint64(0))))
	ex = -1023 + int32(*(*Sqlite3_uint64)(unsafe.Pointer(bp + 88))>>52&uint64(0x7ff))
	if !(precision+ex/3 < 15) {
		goto __126
	}
	rounder = rounder + *(*float64)(unsafe.Pointer(bp + 104))*3e-16
__126:
	;
	*(*float64)(unsafe.Pointer(bp + 104)) += rounder
__125:
	;
	exp = 0
	if !(Xsqlite3IsNaN(tls, *(*float64)(unsafe.Pointer(bp + 104))) != 0) {
		goto __127
	}
	bufpt = ts + 1628
	length = 3
	goto __58
__127:
	;
	if !(*(*float64)(unsafe.Pointer(bp + 104)) > 0.0) {
		goto __128
	}
	scale = 1.0
__129:
	if !(*(*float64)(unsafe.Pointer(bp + 104)) >= 1e100*scale && exp <= 350) {
		goto __130
	}
	scale = scale * 1e100
	exp = exp + 100
	goto __129
__130:
	;
__131:
	if !(*(*float64)(unsafe.Pointer(bp + 104)) >= 1e10*scale && exp <= 350) {
		goto __132
	}
	scale = scale * 1e10
	exp = exp + 10
	goto __131
__132:
	;
__133:
	if !(*(*float64)(unsafe.Pointer(bp + 104)) >= 10.0*scale && exp <= 350) {
		goto __134
	}
	scale = scale * 10.0
	exp++
	goto __133
__134:
	;
	*(*float64)(unsafe.Pointer(bp + 104)) /= scale
__135:
	if !(*(*float64)(unsafe.Pointer(bp + 104)) < 1e-8) {
		goto __136
	}
	*(*float64)(unsafe.Pointer(bp + 104)) *= 1e8
	exp = exp - 8
	goto __135
__136:
	;
__137:
	if !(*(*float64)(unsafe.Pointer(bp + 104)) < 1.0) {
		goto __138
	}
	*(*float64)(unsafe.Pointer(bp + 104)) *= 10.0
	exp--
	goto __137
__138:
	;
	if !(exp > 350) {
		goto __139
	}
	bufpt = bp + 16
	*(*uint8)(unsafe.Pointer(bp + 16)) = prefix
	libc.Xmemcpy(tls, bp+16+uintptr(libc.Bool32(int32(prefix) != 0)), ts+1632, uint64(4))
	length = 3 + libc.Bool32(int32(prefix) != 0)
	goto __58
__139:
	;
__128:
	;
	bufpt = bp + 16

	if !(int32(xtype) != EtFLOAT) {
		goto __140
	}
	*(*float64)(unsafe.Pointer(bp + 104)) += rounder
	if !(*(*float64)(unsafe.Pointer(bp + 104)) >= 10.0) {
		goto __141
	}
	*(*float64)(unsafe.Pointer(bp + 104)) *= 0.1
	exp++
__141:
	;
__140:
	;
	if !(int32(xtype) == EtGENERIC) {
		goto __142
	}
	flag_rtz = libc.BoolUint8(!(flag_alternateform != 0))
	if !(exp < -4 || exp > precision) {
		goto __144
	}
	xtype = EtByte(EtEXP)
	goto __145
__144:
	precision = precision - exp
	xtype = EtByte(EtFLOAT)
__145:
	;
	goto __143
__142:
	flag_rtz = flag_altform2
__143:
	;
	if !(int32(xtype) == EtEXP) {
		goto __146
	}
	e2 = 0
	goto __147
__146:
	e2 = exp
__147:
	;
	szBufNeeded = func() int64 {
		if e2 > 0 {
			return int64(e2)
		}
		return int64(0)
	}() + I64(precision) + I64(width) + int64(15)
	if !(szBufNeeded > int64(SQLITE_PRINT_BUF_SIZE)) {
		goto __148
	}
	bufpt = libc.AssignUintptr(&zExtra, printfTempBuf(tls, pAccum, szBufNeeded))
	if !(bufpt == uintptr(0)) {
		goto __149
	}
	return
__149:
	;
__148:
	;
	zOut = bufpt
	*(*int32)(unsafe.Pointer(bp + 112)) = 16 + int32(flag_altform2)*10
	flag_dp = EtByte(func() int32 {
		if precision > 0 {
			return 1
		}
		return 0
	}() | int32(flag_alternateform) | int32(flag_altform2))

	if !(prefix != 0) {
		goto __150
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = prefix
__150:
	;
	if !(e2 < 0) {
		goto __151
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8('0')
	goto __152
__151:
	;
__153:
	if !(e2 >= 0) {
		goto __155
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = et_getdigit(tls, bp+104, bp+112)
	goto __154
__154:
	e2--
	goto __153
	goto __155
__155:
	;
__152:
	;
	if !(flag_dp != 0) {
		goto __156
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8('.')
__156:
	;
	e2++
__157:
	if !(e2 < 0) {
		goto __159
	}

	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8('0')
	goto __158
__158:
	precision--
	e2++
	goto __157
	goto __159
__159:
	;
__160:
	if !(libc.PostDecInt32(&precision, 1) > 0) {
		goto __161
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = et_getdigit(tls, bp+104, bp+112)
	goto __160
__161:
	;
	if !(flag_rtz != 0 && flag_dp != 0) {
		goto __162
	}
__163:
	if !(int32(*(*uint8)(unsafe.Pointer(bufpt + libc.UintptrFromInt32(-1)))) == '0') {
		goto __164
	}
	*(*uint8)(unsafe.Pointer(libc.PreDecUintptr(&bufpt, 1))) = uint8(0)
	goto __163
__164:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(bufpt + libc.UintptrFromInt32(-1)))) == '.') {
		goto __165
	}
	if !(flag_altform2 != 0) {
		goto __166
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8('0')
	goto __167
__166:
	*(*uint8)(unsafe.Pointer(libc.PreDecUintptr(&bufpt, 1))) = uint8(0)
__167:
	;
__165:
	;
__162:
	;
	if !(int32(xtype) == EtEXP) {
		goto __168
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = aDigits[(*Et_info)(unsafe.Pointer(infop)).Fcharset]
	if !(exp < 0) {
		goto __169
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8('-')
	exp = -exp
	goto __170
__169:
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8('+')
__170:
	;
	if !(exp >= 100) {
		goto __171
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8(exp/100 + '0')
	exp = exp % 100
__171:
	;
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8(exp/10 + '0')
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))) = uint8(exp%10 + '0')
__168:
	;
	*(*uint8)(unsafe.Pointer(bufpt)) = uint8(0)

	length = int32((int64(bufpt) - int64(zOut)) / 1)
	bufpt = zOut

	if !(flag_zeropad != 0 && !(flag_leftjustify != 0) && length < width) {
		goto __172
	}
	nPad = width - length
	i = width
__173:
	if !(i >= nPad) {
		goto __175
	}
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(i))) = *(*uint8)(unsafe.Pointer(bufpt + uintptr(i-nPad)))
	goto __174
__174:
	i--
	goto __173
	goto __175
__175:
	;
	i = libc.Bool32(int32(prefix) != 0)
__176:
	if !(libc.PostDecInt32(&nPad, 1) != 0) {
		goto __177
	}
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('0')
	goto __176
__177:
	;
	length = width
__172:
	;
	goto __58
__66:
	if !!(bArgList != 0) {
		goto __178
	}
	*(*int32)(unsafe.Pointer(libc.VaUintptr(&ap))) = int32((*Sqlite3_str)(unsafe.Pointer(pAccum)).FnChar)
__178:
	;
	length = libc.AssignInt32(&width, 0)
	goto __58
__67:
	*(*uint8)(unsafe.Pointer(bp + 16)) = uint8('%')
	bufpt = bp + 16
	length = 1
	goto __58
__68:
	if !(bArgList != 0) {
		goto __179
	}
	bufpt = getTextArg(tls, pArgList)
	length = 1
	if !(bufpt != 0) {
		goto __181
	}
	*(*uint8)(unsafe.Pointer(bp + 16)) = uint8(libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1))))))
	if !(c&0xc0 == 0xc0) {
		goto __183
	}
__184:
	if !(length < 4 && int32(*(*uint8)(unsafe.Pointer(bufpt)))&0xc0 == 0x80) {
		goto __185
	}
	*(*uint8)(unsafe.Pointer(bp + 16 + uintptr(libc.PostIncInt32(&length, 1)))) = *(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&bufpt, 1)))
	goto __184
__185:
	;
__183:
	;
	goto __182
__181:
	*(*uint8)(unsafe.Pointer(bp + 16)) = uint8(0)
__182:
	;
	goto __180
__179:
	ch = libc.VaUint32(&ap)
	if !(ch < uint32(0x00080)) {
		goto __186
	}
	*(*uint8)(unsafe.Pointer(bp + 16)) = uint8(ch & uint32(0xff))
	length = 1
	goto __187
__186:
	if !(ch < uint32(0x00800)) {
		goto __188
	}
	*(*uint8)(unsafe.Pointer(bp + 16)) = uint8(0xc0 + int32(U8(ch>>6&uint32(0x1f))))
	*(*uint8)(unsafe.Pointer(bp + 16 + 1)) = uint8(0x80 + int32(U8(ch&uint32(0x3f))))
	length = 2
	goto __189
__188:
	if !(ch < uint32(0x10000)) {
		goto __190
	}
	*(*uint8)(unsafe.Pointer(bp + 16)) = uint8(0xe0 + int32(U8(ch>>12&uint32(0x0f))))
	*(*uint8)(unsafe.Pointer(bp + 16 + 1)) = uint8(0x80 + int32(U8(ch>>6&uint32(0x3f))))
	*(*uint8)(unsafe.Pointer(bp + 16 + 2)) = uint8(0x80 + int32(U8(ch&uint32(0x3f))))
	length = 3
	goto __191
__190:
	*(*uint8)(unsafe.Pointer(bp + 16)) = uint8(0xf0 + int32(U8(ch>>18&uint32(0x07))))
	*(*uint8)(unsafe.Pointer(bp + 16 + 1)) = uint8(0x80 + int32(U8(ch>>12&uint32(0x3f))))
	*(*uint8)(unsafe.Pointer(bp + 16 + 2)) = uint8(0x80 + int32(U8(ch>>6&uint32(0x3f))))
	*(*uint8)(unsafe.Pointer(bp + 16 + 3)) = uint8(0x80 + int32(U8(ch&uint32(0x3f))))
	length = 4
__191:
	;
__189:
	;
__187:
	;
__180:
	;
	if !(precision > 1) {
		goto __192
	}
	nPrior = int64(1)
	width = width - (precision - 1)
	if !(width > 1 && !(flag_leftjustify != 0)) {
		goto __193
	}
	Xsqlite3_str_appendchar(tls, pAccum, width-1, uint8(' '))
	width = 0
__193:
	;
	Xsqlite3_str_append(tls, pAccum, bp+16, length)
	precision--
__194:
	if !(precision > 1) {
		goto __195
	}
	if !(nPrior > I64(precision-1)) {
		goto __196
	}
	nPrior = I64(precision - 1)
__196:
	;
	nCopyBytes = I64(length) * nPrior
	if !(nCopyBytes+I64((*Sqlite3_str)(unsafe.Pointer(pAccum)).FnChar) >= I64((*Sqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc)) {
		goto __197
	}
	Xsqlite3StrAccumEnlarge(tls, pAccum, nCopyBytes)
__197:
	;
	if !((*Sqlite3_str)(unsafe.Pointer(pAccum)).FaccError != 0) {
		goto __198
	}
	goto __195
__198:
	;
	Xsqlite3_str_append(tls, pAccum,
		(*Sqlite3_str)(unsafe.Pointer(pAccum)).FzText+uintptr(I64((*Sqlite3_str)(unsafe.Pointer(pAccum)).FnChar)-nCopyBytes), int32(nCopyBytes))
	precision = int32(I64(precision) - nPrior)
	nPrior = nPrior * int64(2)
	goto __194
__195:
	;
__192:
	;
	bufpt = bp + 16
	flag_altform2 = EtByte(1)
	goto adjust_width_for_utf8
__69:
__70:
	if !(bArgList != 0) {
		goto __199
	}
	bufpt = getTextArg(tls, pArgList)
	xtype = EtByte(EtSTRING)
	goto __200
__199:
	bufpt = libc.VaUintptr(&ap)
__200:
	;
	if !(bufpt == uintptr(0)) {
		goto __201
	}
	bufpt = ts + 1636
	goto __202
__201:
	if !(int32(xtype) == EtDYNSTRING) {
		goto __203
	}
	if !((*Sqlite3_str)(unsafe.Pointer(pAccum)).FnChar == U32(0) &&
		(*Sqlite3_str)(unsafe.Pointer(pAccum)).FmxAlloc != 0 &&
		width == 0 &&
		precision < 0 &&
		int32((*Sqlite3_str)(unsafe.Pointer(pAccum)).FaccError) == 0) {
		goto __204
	}

	(*Sqlite3_str)(unsafe.Pointer(pAccum)).FzText = bufpt
	(*Sqlite3_str)(unsafe.Pointer(pAccum)).FnAlloc = U32(Xsqlite3DbMallocSize(tls, (*Sqlite3_str)(unsafe.Pointer(pAccum)).Fdb, bufpt))
	(*Sqlite3_str)(unsafe.Pointer(pAccum)).FnChar = U32(0x7fffffff & int32(libc.Xstrlen(tls, bufpt)))
	*(*U8)(unsafe.Pointer(pAccum + 29)) |= U8(SQLITE_PRINTF_MALLOCED)
	length = 0
	goto __58
__204:
	;
	zExtra = bufpt
__203:
	;
__202:
	;
	if !(precision >= 0) {
		goto __205
	}
	if !(flag_altform2 != 0) {
		goto __207
	}

	z = bufpt
__209:
	if !(libc.PostDecInt32(&precision, 1) > 0 && *(*uint8)(unsafe.Pointer(z)) != 0) {
		goto __210
	}
	if !(int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1)))) >= 0xc0) {
		goto __211
	}
__212:
	if !(int32(*(*uint8)(unsafe.Pointer(z)))&0xc0 == 0x80) {
		goto __213
	}
	z++
	goto __212
__213:
	;
__211:
	;
	goto __209
__210:
	;
	length = int32((int64(z) - int64(bufpt)) / 1)
	goto __208
__207:
	length = 0
__214:
	if !(length < precision && *(*uint8)(unsafe.Pointer(bufpt + uintptr(length))) != 0) {
		goto __216
	}
	goto __215
__215:
	length++
	goto __214
	goto __216
__216:
	;
__208:
	;
	goto __206
__205:
	length = 0x7fffffff & int32(libc.Xstrlen(tls, bufpt))
__206:
	;
adjust_width_for_utf8:
	if !(flag_altform2 != 0 && width > 0) {
		goto __217
	}

	ii = length - 1
__218:
	if !(ii >= 0) {
		goto __219
	}
	if !(int32(*(*uint8)(unsafe.Pointer(bufpt + uintptr(libc.PostDecInt32(&ii, 1)))))&0xc0 == 0x80) {
		goto __220
	}
	width++
__220:
	;
	goto __218
__219:
	;
__217:
	;
	goto __58
__71:
__72:
__73:
	q = func() uint8 {
		if int32(xtype) == EtSQLESCAPE3 {
			return uint8('"')
		}
		return uint8('\'')
	}()

	if !(bArgList != 0) {
		goto __221
	}
	escarg = getTextArg(tls, pArgList)
	goto __222
__221:
	escarg = libc.VaUintptr(&ap)
__222:
	;
	isnull = libc.Bool32(escarg == uintptr(0))
	if !(isnull != 0) {
		goto __223
	}
	escarg = func() uintptr {
		if int32(xtype) == EtSQLESCAPE2 {
			return ts + 1637
		}
		return ts + 1642
	}()
__223:
	;
	k = I64(precision)
	i1 = libc.AssignInt64(&n1, int64(0))
__224:
	if !(k != int64(0) && int32(libc.AssignUint8(&ch1, *(*uint8)(unsafe.Pointer(escarg + uintptr(i1))))) != 0) {
		goto __226
	}
	if !(int32(ch1) == int32(q)) {
		goto __227
	}
	n1++
__227:
	;
	if !(flag_altform2 != 0 && int32(ch1)&0xc0 == 0xc0) {
		goto __228
	}
__229:
	if !(int32(*(*uint8)(unsafe.Pointer(escarg + uintptr(i1+int64(1)))))&0xc0 == 0x80) {
		goto __230
	}
	i1++
	goto __229
__230:
	;
__228:
	;
	goto __225
__225:
	i1++
	k--
	goto __224
	goto __226
__226:
	;
	needQuote = libc.Bool32(!(isnull != 0) && int32(xtype) == EtSQLESCAPE2)
	n1 = n1 + (i1 + int64(3))
	if !(n1 > int64(SQLITE_PRINT_BUF_SIZE)) {
		goto __231
	}
	bufpt = libc.AssignUintptr(&zExtra, printfTempBuf(tls, pAccum, n1))
	if !(bufpt == uintptr(0)) {
		goto __233
	}
	return
__233:
	;
	goto __232
__231:
	bufpt = bp + 16
__232:
	;
	j = int64(0)
	if !(needQuote != 0) {
		goto __234
	}
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(libc.PostIncInt64(&j, 1)))) = q
__234:
	;
	k = i1
	i1 = int64(0)
__235:
	if !(i1 < k) {
		goto __237
	}
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(libc.PostIncInt64(&j, 1)))) = libc.AssignUint8(&ch1, *(*uint8)(unsafe.Pointer(escarg + uintptr(i1))))
	if !(int32(ch1) == int32(q)) {
		goto __238
	}
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(libc.PostIncInt64(&j, 1)))) = ch1
__238:
	;
	goto __236
__236:
	i1++
	goto __235
	goto __237
__237:
	;
	if !(needQuote != 0) {
		goto __239
	}
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(libc.PostIncInt64(&j, 1)))) = q
__239:
	;
	*(*uint8)(unsafe.Pointer(bufpt + uintptr(j))) = uint8(0)
	length = int32(j)
	goto adjust_width_for_utf8

__74:
	if !(int32((*Sqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&SQLITE_PRINTF_INTERNAL == 0) {
		goto __240
	}
	return
__240:
	;
	if !(flag_alternateform != 0) {
		goto __241
	}

	pExpr = libc.VaUintptr(&ap)
	if !(pExpr != 0 && !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_IntValue) != U32(0))) {
		goto __243
	}
	Xsqlite3_str_appendall(tls, pAccum, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
	Xsqlite3RecordErrorOffsetOfExpr(tls, (*Sqlite3_str)(unsafe.Pointer(pAccum)).Fdb, pExpr)
__243:
	;
	goto __242
__241:
	pToken = libc.VaUintptr(&ap)

	if !(pToken != 0 && (*Token)(unsafe.Pointer(pToken)).Fn != 0) {
		goto __244
	}
	Xsqlite3_str_append(tls, pAccum, (*Token)(unsafe.Pointer(pToken)).Fz, int32((*Token)(unsafe.Pointer(pToken)).Fn))
	Xsqlite3RecordErrorByteOffset(tls, (*Sqlite3_str)(unsafe.Pointer(pAccum)).Fdb, (*Token)(unsafe.Pointer(pToken)).Fz)
__244:
	;
__242:
	;
	length = libc.AssignInt32(&width, 0)
	goto __58

__75:
	if !(int32((*Sqlite3_str)(unsafe.Pointer(pAccum)).FprintfFlags)&SQLITE_PRINTF_INTERNAL == 0) {
		goto __245
	}
	return
__245:
	;
	pItem = libc.VaUintptr(&ap)

	if !((*SrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 && !(flag_altform2 != 0)) {
		goto __246
	}
	Xsqlite3_str_appendall(tls, pAccum, (*SrcItem)(unsafe.Pointer(pItem)).FzAlias)
	goto __247
__246:
	if !((*SrcItem)(unsafe.Pointer(pItem)).FzName != 0) {
		goto __248
	}
	if !((*SrcItem)(unsafe.Pointer(pItem)).FzDatabase != 0) {
		goto __250
	}
	Xsqlite3_str_appendall(tls, pAccum, (*SrcItem)(unsafe.Pointer(pItem)).FzDatabase)
	Xsqlite3_str_append(tls, pAccum, ts+1649, 1)
__250:
	;
	Xsqlite3_str_appendall(tls, pAccum, (*SrcItem)(unsafe.Pointer(pItem)).FzName)
	goto __249
__248:
	if !((*SrcItem)(unsafe.Pointer(pItem)).FzAlias != 0) {
		goto __251
	}
	Xsqlite3_str_appendall(tls, pAccum, (*SrcItem)(unsafe.Pointer(pItem)).FzAlias)
	goto __252
__251:
	pSel = (*SrcItem)(unsafe.Pointer(pItem)).FpSelect

	if !((*Select)(unsafe.Pointer(pSel)).FselFlags&U32(SF_NestedFrom) != 0) {
		goto __253
	}
	Xsqlite3_str_appendf(tls, pAccum, ts+1651, libc.VaList(bp, (*Select)(unsafe.Pointer(pSel)).FselId))
	goto __254
__253:
	Xsqlite3_str_appendf(tls, pAccum, ts+1661, libc.VaList(bp+8, (*Select)(unsafe.Pointer(pSel)).FselId))
__254:
	;
__252:
	;
__249:
	;
__247:
	;
	length = libc.AssignInt32(&width, 0)
	goto __58

__76:
	;
	return

__58:
	;
	width = width - length
	if !(width > 0) {
		goto __255
	}
	if !!(flag_leftjustify != 0) {
		goto __257
	}
	Xsqlite3_str_appendchar(tls, pAccum, width, uint8(' '))
__257:
	;
	Xsqlite3_str_append(tls, pAccum, bufpt, length)
	if !(flag_leftjustify != 0) {
		goto __258
	}
	Xsqlite3_str_appendchar(tls, pAccum, width, uint8(' '))
__258:
	;
	goto __256
__255:
	Xsqlite3_str_append(tls, pAccum, bufpt, length)
__256:
	;
	if !(zExtra != 0) {
		goto __259
	}
	Xsqlite3DbFree(tls, (*Sqlite3_str)(unsafe.Pointer(pAccum)).Fdb, zExtra)
	zExtra = uintptr(0)
__259:
	;
	goto __4
__4:
	fmt++
	goto __3
	goto __5
__5:
}

var zOrd = *(*[9]uint8)(unsafe.Pointer(ts + 1675))

func Xsqlite3RecordErrorByteOffset(tls *libc.TLS, db uintptr, z uintptr) {
	var pParse uintptr
	var zText uintptr
	var zEnd uintptr

	if db == uintptr(0) {
		return
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset != -2 {
		return
	}
	pParse = (*Sqlite3)(unsafe.Pointer(db)).FpParse
	if pParse == uintptr(0) {
		return
	}
	zText = (*Parse)(unsafe.Pointer(pParse)).FzTail
	if zText == uintptr(0) {
		return
	}
	zEnd = zText + uintptr(libc.Xstrlen(tls, zText))
	if Uptr(z) >= Uptr(zText) && Uptr(z) < Uptr(zEnd) {
		(*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset = int32((int64(z) - int64(zText)) / 1)
	}
}

func Xsqlite3RecordErrorOffsetOfExpr(tls *libc.TLS, db uintptr, pExpr uintptr) {
	for pExpr != 0 &&
		((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_InnerON) != U32(0) || *(*int32)(unsafe.Pointer(pExpr + 52)) <= 0) {
		pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	}
	if pExpr == uintptr(0) {
		return
	}
	(*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset = *(*int32)(unsafe.Pointer(pExpr + 52))
}

func Xsqlite3StrAccumEnlarge(tls *libc.TLS, p uintptr, N I64) int32 {
	var zNew uintptr

	if (*StrAccum)(unsafe.Pointer(p)).FaccError != 0 {
		return 0
	}
	if (*StrAccum)(unsafe.Pointer(p)).FmxAlloc == U32(0) {
		Xsqlite3StrAccumSetError(tls, p, uint8(SQLITE_TOOBIG))
		return int32((*StrAccum)(unsafe.Pointer(p)).FnAlloc - (*StrAccum)(unsafe.Pointer(p)).FnChar - U32(1))
	} else {
		var zOld uintptr
		if int32((*StrAccum)(unsafe.Pointer(p)).FprintfFlags)&SQLITE_PRINTF_MALLOCED != 0 {
			zOld = (*StrAccum)(unsafe.Pointer(p)).FzText
		} else {
			zOld = uintptr(0)
		}
		var szNew I64 = I64((*StrAccum)(unsafe.Pointer(p)).FnChar) + N + int64(1)
		if szNew+I64((*StrAccum)(unsafe.Pointer(p)).FnChar) <= I64((*StrAccum)(unsafe.Pointer(p)).FmxAlloc) {
			szNew = szNew + I64((*StrAccum)(unsafe.Pointer(p)).FnChar)
		}
		if szNew > I64((*StrAccum)(unsafe.Pointer(p)).FmxAlloc) {
			Xsqlite3_str_reset(tls, p)
			Xsqlite3StrAccumSetError(tls, p, uint8(SQLITE_TOOBIG))
			return 0
		} else {
			(*StrAccum)(unsafe.Pointer(p)).FnAlloc = U32(int32(szNew))
		}
		if (*StrAccum)(unsafe.Pointer(p)).Fdb != 0 {
			zNew = Xsqlite3DbRealloc(tls, (*StrAccum)(unsafe.Pointer(p)).Fdb, zOld, uint64((*StrAccum)(unsafe.Pointer(p)).FnAlloc))
		} else {
			zNew = Xsqlite3Realloc(tls, zOld, uint64((*StrAccum)(unsafe.Pointer(p)).FnAlloc))
		}
		if zNew != 0 {
			if !(int32((*StrAccum)(unsafe.Pointer(p)).FprintfFlags)&SQLITE_PRINTF_MALLOCED != 0) && (*StrAccum)(unsafe.Pointer(p)).FnChar > U32(0) {
				libc.Xmemcpy(tls, zNew, (*StrAccum)(unsafe.Pointer(p)).FzText, uint64((*StrAccum)(unsafe.Pointer(p)).FnChar))
			}
			(*StrAccum)(unsafe.Pointer(p)).FzText = zNew
			(*StrAccum)(unsafe.Pointer(p)).FnAlloc = U32(Xsqlite3DbMallocSize(tls, (*StrAccum)(unsafe.Pointer(p)).Fdb, zNew))
			*(*U8)(unsafe.Pointer(p + 29)) |= U8(SQLITE_PRINTF_MALLOCED)
		} else {
			Xsqlite3_str_reset(tls, p)
			Xsqlite3StrAccumSetError(tls, p, uint8(SQLITE_NOMEM))
			return 0
		}
	}

	return int32(N)
}

func Xsqlite3_str_appendchar(tls *libc.TLS, p uintptr, N int32, c uint8) {
	if I64((*Sqlite3_str)(unsafe.Pointer(p)).FnChar)+I64(N) >= I64((*Sqlite3_str)(unsafe.Pointer(p)).FnAlloc) && libc.AssignInt32(&N, Xsqlite3StrAccumEnlarge(tls, p, int64(N))) <= 0 {
		return
	}
	for libc.PostDecInt32(&N, 1) > 0 {
		*(*uint8)(unsafe.Pointer((*Sqlite3_str)(unsafe.Pointer(p)).FzText + uintptr(libc.PostIncUint32(&(*Sqlite3_str)(unsafe.Pointer(p)).FnChar, 1)))) = c
	}
}

func enlargeAndAppend(tls *libc.TLS, p uintptr, z uintptr, N int32) {
	N = Xsqlite3StrAccumEnlarge(tls, p, int64(N))
	if N > 0 {
		libc.Xmemcpy(tls, (*StrAccum)(unsafe.Pointer(p)).FzText+uintptr((*StrAccum)(unsafe.Pointer(p)).FnChar), z, uint64(N))
		*(*U32)(unsafe.Pointer(p + 24)) += U32(N)
	}
}

func Xsqlite3_str_append(tls *libc.TLS, p uintptr, z uintptr, N int32) {
	if (*Sqlite3_str)(unsafe.Pointer(p)).FnChar+U32(N) >= (*Sqlite3_str)(unsafe.Pointer(p)).FnAlloc {
		enlargeAndAppend(tls, p, z, N)
	} else if N != 0 {
		*(*U32)(unsafe.Pointer(p + 24)) += U32(N)
		libc.Xmemcpy(tls, (*Sqlite3_str)(unsafe.Pointer(p)).FzText+uintptr((*Sqlite3_str)(unsafe.Pointer(p)).FnChar-U32(N)), z, uint64(N))
	}
}

func Xsqlite3_str_appendall(tls *libc.TLS, p uintptr, z uintptr) {
	Xsqlite3_str_append(tls, p, z, Xsqlite3Strlen30(tls, z))
}

func strAccumFinishRealloc(tls *libc.TLS, p uintptr) uintptr {
	var zText uintptr

	zText = Xsqlite3DbMallocRaw(tls, (*StrAccum)(unsafe.Pointer(p)).Fdb, uint64((*StrAccum)(unsafe.Pointer(p)).FnChar+U32(1)))
	if zText != 0 {
		libc.Xmemcpy(tls, zText, (*StrAccum)(unsafe.Pointer(p)).FzText, uint64((*StrAccum)(unsafe.Pointer(p)).FnChar+U32(1)))
		*(*U8)(unsafe.Pointer(p + 29)) |= U8(SQLITE_PRINTF_MALLOCED)
	} else {
		Xsqlite3StrAccumSetError(tls, p, uint8(SQLITE_NOMEM))
	}
	(*StrAccum)(unsafe.Pointer(p)).FzText = zText
	return zText
}

func Xsqlite3StrAccumFinish(tls *libc.TLS, p uintptr) uintptr {
	if (*StrAccum)(unsafe.Pointer(p)).FzText != 0 {
		*(*uint8)(unsafe.Pointer((*StrAccum)(unsafe.Pointer(p)).FzText + uintptr((*StrAccum)(unsafe.Pointer(p)).FnChar))) = uint8(0)
		if (*StrAccum)(unsafe.Pointer(p)).FmxAlloc > U32(0) && !(int32((*StrAccum)(unsafe.Pointer(p)).FprintfFlags)&SQLITE_PRINTF_MALLOCED != 0) {
			return strAccumFinishRealloc(tls, p)
		}
	}
	return (*StrAccum)(unsafe.Pointer(p)).FzText
}

func Xsqlite3ResultStrAccum(tls *libc.TLS, pCtx uintptr, p uintptr) {
	if (*StrAccum)(unsafe.Pointer(p)).FaccError != 0 {
		Xsqlite3_result_error_code(tls, pCtx, int32((*StrAccum)(unsafe.Pointer(p)).FaccError))
		Xsqlite3_str_reset(tls, p)
	} else if int32((*StrAccum)(unsafe.Pointer(p)).FprintfFlags)&SQLITE_PRINTF_MALLOCED != 0 {
		Xsqlite3_result_text(tls, pCtx, (*StrAccum)(unsafe.Pointer(p)).FzText, int32((*StrAccum)(unsafe.Pointer(p)).FnChar), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})))
	} else {
		Xsqlite3_result_text(tls, pCtx, ts+1636, 0, uintptr(0))
		Xsqlite3_str_reset(tls, p)
	}
}

var sqlite3OomStr = Sqlite3_str{FaccError: U8(SQLITE_NOMEM)}

func Xsqlite3_str_finish(tls *libc.TLS, p uintptr) uintptr {
	var z uintptr
	if p != uintptr(0) && p != uintptr(unsafe.Pointer(&sqlite3OomStr)) {
		z = Xsqlite3StrAccumFinish(tls, p)
		Xsqlite3_free(tls, p)
	} else {
		z = uintptr(0)
	}
	return z
}

func Xsqlite3_str_errcode(tls *libc.TLS, p uintptr) int32 {
	if p != 0 {
		return int32((*Sqlite3_str)(unsafe.Pointer(p)).FaccError)
	}
	return SQLITE_NOMEM
}

func Xsqlite3_str_length(tls *libc.TLS, p uintptr) int32 {
	if p != 0 {
		return int32((*Sqlite3_str)(unsafe.Pointer(p)).FnChar)
	}
	return 0
}

func Xsqlite3_str_value(tls *libc.TLS, p uintptr) uintptr {
	if p == uintptr(0) || (*Sqlite3_str)(unsafe.Pointer(p)).FnChar == U32(0) {
		return uintptr(0)
	}
	*(*uint8)(unsafe.Pointer((*Sqlite3_str)(unsafe.Pointer(p)).FzText + uintptr((*Sqlite3_str)(unsafe.Pointer(p)).FnChar))) = uint8(0)
	return (*Sqlite3_str)(unsafe.Pointer(p)).FzText
}

func Xsqlite3_str_reset(tls *libc.TLS, p uintptr) {
	if int32((*StrAccum)(unsafe.Pointer(p)).FprintfFlags)&SQLITE_PRINTF_MALLOCED != 0 {
		Xsqlite3DbFree(tls, (*StrAccum)(unsafe.Pointer(p)).Fdb, (*StrAccum)(unsafe.Pointer(p)).FzText)
		*(*U8)(unsafe.Pointer(p + 29)) &= libc.Uint8FromInt32(libc.CplInt32(SQLITE_PRINTF_MALLOCED))
	}
	(*StrAccum)(unsafe.Pointer(p)).FnAlloc = U32(0)
	(*StrAccum)(unsafe.Pointer(p)).FnChar = U32(0)
	(*StrAccum)(unsafe.Pointer(p)).FzText = uintptr(0)
}

func Xsqlite3StrAccumInit(tls *libc.TLS, p uintptr, db uintptr, zBase uintptr, n int32, mx int32) {
	(*StrAccum)(unsafe.Pointer(p)).FzText = zBase
	(*StrAccum)(unsafe.Pointer(p)).Fdb = db
	(*StrAccum)(unsafe.Pointer(p)).FnAlloc = U32(n)
	(*StrAccum)(unsafe.Pointer(p)).FmxAlloc = U32(mx)
	(*StrAccum)(unsafe.Pointer(p)).FnChar = U32(0)
	(*StrAccum)(unsafe.Pointer(p)).FaccError = U8(0)
	(*StrAccum)(unsafe.Pointer(p)).FprintfFlags = U8(0)
}

func Xsqlite3_str_new(tls *libc.TLS, db uintptr) uintptr {
	var p uintptr = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Sqlite3_str{})))
	if p != 0 {
		Xsqlite3StrAccumInit(tls, p, uintptr(0), uintptr(0), 0,
			func() int32 {
				if db != 0 {
					return *(*int32)(unsafe.Pointer(db + 136))
				}
				return SQLITE_MAX_LENGTH
			}())
	} else {
		p = uintptr(unsafe.Pointer(&sqlite3OomStr))
	}
	return p
}

func Xsqlite3VMPrintf(tls *libc.TLS, db uintptr, zFormat uintptr, ap Va_list) uintptr {
	bp := tls.Alloc(102)
	defer tls.Free(102)

	var z uintptr

	Xsqlite3StrAccumInit(tls, bp, db, bp+32, int32(unsafe.Sizeof([70]uint8{})),
		*(*int32)(unsafe.Pointer(db + 136)))
	(*StrAccum)(unsafe.Pointer(bp)).FprintfFlags = U8(SQLITE_PRINTF_INTERNAL)
	Xsqlite3_str_vappendf(tls, bp, zFormat, ap)
	z = Xsqlite3StrAccumFinish(tls, bp)
	if int32((*StrAccum)(unsafe.Pointer(bp)).FaccError) == SQLITE_NOMEM {
		Xsqlite3OomFault(tls, db)
	}
	return z
}

func Xsqlite3MPrintf(tls *libc.TLS, db uintptr, zFormat uintptr, va uintptr) uintptr {
	var ap Va_list
	_ = ap
	var z uintptr
	ap = va
	z = Xsqlite3VMPrintf(tls, db, zFormat, ap)
	_ = ap
	return z
}

func Xsqlite3_vmprintf(tls *libc.TLS, zFormat uintptr, ap Va_list) uintptr {
	bp := tls.Alloc(102)
	defer tls.Free(102)

	var z uintptr

	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	Xsqlite3StrAccumInit(tls, bp, uintptr(0), bp+32, int32(unsafe.Sizeof([70]uint8{})), SQLITE_MAX_LENGTH)
	Xsqlite3_str_vappendf(tls, bp, zFormat, ap)
	z = Xsqlite3StrAccumFinish(tls, bp)
	return z
}

func Xsqlite3_mprintf(tls *libc.TLS, zFormat uintptr, va uintptr) uintptr {
	var ap Va_list
	_ = ap
	var z uintptr
	if Xsqlite3_initialize(tls) != 0 {
		return uintptr(0)
	}
	ap = va
	z = Xsqlite3_vmprintf(tls, zFormat, ap)
	_ = ap
	return z
}

func Xsqlite3_vsnprintf(tls *libc.TLS, n int32, zBuf uintptr, zFormat uintptr, ap Va_list) uintptr {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	if n <= 0 {
		return zBuf
	}
	Xsqlite3StrAccumInit(tls, bp, uintptr(0), zBuf, n, 0)
	Xsqlite3_str_vappendf(tls, bp, zFormat, ap)
	*(*uint8)(unsafe.Pointer(zBuf + uintptr((*StrAccum)(unsafe.Pointer(bp)).FnChar))) = uint8(0)
	return zBuf
}

func Xsqlite3_snprintf(tls *libc.TLS, n int32, zBuf uintptr, zFormat uintptr, va uintptr) uintptr {
	var z uintptr
	var ap Va_list
	_ = ap
	ap = va
	z = Xsqlite3_vsnprintf(tls, n, zBuf, zFormat, ap)
	_ = ap
	return z
}

func renderLogMsg(tls *libc.TLS, iErrCode int32, zFormat uintptr, ap Va_list) {
	bp := tls.Alloc(242)
	defer tls.Free(242)

	Xsqlite3StrAccumInit(tls, bp, uintptr(0), bp+32, int32(unsafe.Sizeof([210]uint8{})), 0)
	Xsqlite3_str_vappendf(tls, bp, zFormat, ap)
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.FxLog})).f(tls, Xsqlite3Config.FpLogArg, iErrCode,
		Xsqlite3StrAccumFinish(tls, bp))
}

func Xsqlite3_log(tls *libc.TLS, iErrCode int32, zFormat uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	if Xsqlite3Config.FxLog != 0 {
		ap = va
		renderLogMsg(tls, iErrCode, zFormat, ap)
		_ = ap
	}
}

func Xsqlite3DebugPrintf(tls *libc.TLS, zFormat uintptr, va uintptr) {
	bp := tls.Alloc(740)
	defer tls.Free(740)

	var ap Va_list
	_ = ap

	Xsqlite3StrAccumInit(tls, bp+8, uintptr(0), bp+40, int32(unsafe.Sizeof([700]uint8{})), 0)
	ap = va
	Xsqlite3_str_vappendf(tls, bp+8, zFormat, ap)
	_ = ap
	Xsqlite3StrAccumFinish(tls, bp+8)
	libc.Xfprintf(tls, libc.Xstdout, ts+1684, libc.VaList(bp, bp+40))
	libc.Xfflush(tls, libc.Xstdout)
}

func Xsqlite3_str_appendf(tls *libc.TLS, p uintptr, zFormat uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	ap = va
	Xsqlite3_str_vappendf(tls, p, zFormat, ap)
	_ = ap
}

type sqlite3PrngType = struct {
	Fs           [16]U32
	Fout         [64]U8
	Fn           U8
	F__ccgo_pad1 [3]byte
}

var sqlite3Prng sqlite3PrngType

func chacha_block(tls *libc.TLS, out uintptr, in uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var i int32

	libc.Xmemcpy(tls, bp, in, uint64(64))
	for i = 0; i < 10; i++ {
		*(*U32)(unsafe.Pointer(bp)) += *(*U32)(unsafe.Pointer(bp + 4*4))
		*(*U32)(unsafe.Pointer(bp + 12*4)) ^= *(*U32)(unsafe.Pointer(bp))
		*(*U32)(unsafe.Pointer(bp + 12*4)) = *(*U32)(unsafe.Pointer(bp + 12*4))<<16 | *(*U32)(unsafe.Pointer(bp + 12*4))>>(32-16)
		*(*U32)(unsafe.Pointer(bp + 8*4)) += *(*U32)(unsafe.Pointer(bp + 12*4))
		*(*U32)(unsafe.Pointer(bp + 4*4)) ^= *(*U32)(unsafe.Pointer(bp + 8*4))
		*(*U32)(unsafe.Pointer(bp + 4*4)) = *(*U32)(unsafe.Pointer(bp + 4*4))<<12 | *(*U32)(unsafe.Pointer(bp + 4*4))>>(32-12)
		*(*U32)(unsafe.Pointer(bp)) += *(*U32)(unsafe.Pointer(bp + 4*4))
		*(*U32)(unsafe.Pointer(bp + 12*4)) ^= *(*U32)(unsafe.Pointer(bp))
		*(*U32)(unsafe.Pointer(bp + 12*4)) = *(*U32)(unsafe.Pointer(bp + 12*4))<<8 | *(*U32)(unsafe.Pointer(bp + 12*4))>>(32-8)
		*(*U32)(unsafe.Pointer(bp + 8*4)) += *(*U32)(unsafe.Pointer(bp + 12*4))
		*(*U32)(unsafe.Pointer(bp + 4*4)) ^= *(*U32)(unsafe.Pointer(bp + 8*4))
		*(*U32)(unsafe.Pointer(bp + 4*4)) = *(*U32)(unsafe.Pointer(bp + 4*4))<<7 | *(*U32)(unsafe.Pointer(bp + 4*4))>>(32-7)
		*(*U32)(unsafe.Pointer(bp + 1*4)) += *(*U32)(unsafe.Pointer(bp + 5*4))
		*(*U32)(unsafe.Pointer(bp + 13*4)) ^= *(*U32)(unsafe.Pointer(bp + 1*4))
		*(*U32)(unsafe.Pointer(bp + 13*4)) = *(*U32)(unsafe.Pointer(bp + 13*4))<<16 | *(*U32)(unsafe.Pointer(bp + 13*4))>>(32-16)
		*(*U32)(unsafe.Pointer(bp + 9*4)) += *(*U32)(unsafe.Pointer(bp + 13*4))
		*(*U32)(unsafe.Pointer(bp + 5*4)) ^= *(*U32)(unsafe.Pointer(bp + 9*4))
		*(*U32)(unsafe.Pointer(bp + 5*4)) = *(*U32)(unsafe.Pointer(bp + 5*4))<<12 | *(*U32)(unsafe.Pointer(bp + 5*4))>>(32-12)
		*(*U32)(unsafe.Pointer(bp + 1*4)) += *(*U32)(unsafe.Pointer(bp + 5*4))
		*(*U32)(unsafe.Pointer(bp + 13*4)) ^= *(*U32)(unsafe.Pointer(bp + 1*4))
		*(*U32)(unsafe.Pointer(bp + 13*4)) = *(*U32)(unsafe.Pointer(bp + 13*4))<<8 | *(*U32)(unsafe.Pointer(bp + 13*4))>>(32-8)
		*(*U32)(unsafe.Pointer(bp + 9*4)) += *(*U32)(unsafe.Pointer(bp + 13*4))
		*(*U32)(unsafe.Pointer(bp + 5*4)) ^= *(*U32)(unsafe.Pointer(bp + 9*4))
		*(*U32)(unsafe.Pointer(bp + 5*4)) = *(*U32)(unsafe.Pointer(bp + 5*4))<<7 | *(*U32)(unsafe.Pointer(bp + 5*4))>>(32-7)
		*(*U32)(unsafe.Pointer(bp + 2*4)) += *(*U32)(unsafe.Pointer(bp + 6*4))
		*(*U32)(unsafe.Pointer(bp + 14*4)) ^= *(*U32)(unsafe.Pointer(bp + 2*4))
		*(*U32)(unsafe.Pointer(bp + 14*4)) = *(*U32)(unsafe.Pointer(bp + 14*4))<<16 | *(*U32)(unsafe.Pointer(bp + 14*4))>>(32-16)
		*(*U32)(unsafe.Pointer(bp + 10*4)) += *(*U32)(unsafe.Pointer(bp + 14*4))
		*(*U32)(unsafe.Pointer(bp + 6*4)) ^= *(*U32)(unsafe.Pointer(bp + 10*4))
		*(*U32)(unsafe.Pointer(bp + 6*4)) = *(*U32)(unsafe.Pointer(bp + 6*4))<<12 | *(*U32)(unsafe.Pointer(bp + 6*4))>>(32-12)
		*(*U32)(unsafe.Pointer(bp + 2*4)) += *(*U32)(unsafe.Pointer(bp + 6*4))
		*(*U32)(unsafe.Pointer(bp + 14*4)) ^= *(*U32)(unsafe.Pointer(bp + 2*4))
		*(*U32)(unsafe.Pointer(bp + 14*4)) = *(*U32)(unsafe.Pointer(bp + 14*4))<<8 | *(*U32)(unsafe.Pointer(bp + 14*4))>>(32-8)
		*(*U32)(unsafe.Pointer(bp + 10*4)) += *(*U32)(unsafe.Pointer(bp + 14*4))
		*(*U32)(unsafe.Pointer(bp + 6*4)) ^= *(*U32)(unsafe.Pointer(bp + 10*4))
		*(*U32)(unsafe.Pointer(bp + 6*4)) = *(*U32)(unsafe.Pointer(bp + 6*4))<<7 | *(*U32)(unsafe.Pointer(bp + 6*4))>>(32-7)
		*(*U32)(unsafe.Pointer(bp + 3*4)) += *(*U32)(unsafe.Pointer(bp + 7*4))
		*(*U32)(unsafe.Pointer(bp + 15*4)) ^= *(*U32)(unsafe.Pointer(bp + 3*4))
		*(*U32)(unsafe.Pointer(bp + 15*4)) = *(*U32)(unsafe.Pointer(bp + 15*4))<<16 | *(*U32)(unsafe.Pointer(bp + 15*4))>>(32-16)
		*(*U32)(unsafe.Pointer(bp + 11*4)) += *(*U32)(unsafe.Pointer(bp + 15*4))
		*(*U32)(unsafe.Pointer(bp + 7*4)) ^= *(*U32)(unsafe.Pointer(bp + 11*4))
		*(*U32)(unsafe.Pointer(bp + 7*4)) = *(*U32)(unsafe.Pointer(bp + 7*4))<<12 | *(*U32)(unsafe.Pointer(bp + 7*4))>>(32-12)
		*(*U32)(unsafe.Pointer(bp + 3*4)) += *(*U32)(unsafe.Pointer(bp + 7*4))
		*(*U32)(unsafe.Pointer(bp + 15*4)) ^= *(*U32)(unsafe.Pointer(bp + 3*4))
		*(*U32)(unsafe.Pointer(bp + 15*4)) = *(*U32)(unsafe.Pointer(bp + 15*4))<<8 | *(*U32)(unsafe.Pointer(bp + 15*4))>>(32-8)
		*(*U32)(unsafe.Pointer(bp + 11*4)) += *(*U32)(unsafe.Pointer(bp + 15*4))
		*(*U32)(unsafe.Pointer(bp + 7*4)) ^= *(*U32)(unsafe.Pointer(bp + 11*4))
		*(*U32)(unsafe.Pointer(bp + 7*4)) = *(*U32)(unsafe.Pointer(bp + 7*4))<<7 | *(*U32)(unsafe.Pointer(bp + 7*4))>>(32-7)
		*(*U32)(unsafe.Pointer(bp)) += *(*U32)(unsafe.Pointer(bp + 5*4))
		*(*U32)(unsafe.Pointer(bp + 15*4)) ^= *(*U32)(unsafe.Pointer(bp))
		*(*U32)(unsafe.Pointer(bp + 15*4)) = *(*U32)(unsafe.Pointer(bp + 15*4))<<16 | *(*U32)(unsafe.Pointer(bp + 15*4))>>(32-16)
		*(*U32)(unsafe.Pointer(bp + 10*4)) += *(*U32)(unsafe.Pointer(bp + 15*4))
		*(*U32)(unsafe.Pointer(bp + 5*4)) ^= *(*U32)(unsafe.Pointer(bp + 10*4))
		*(*U32)(unsafe.Pointer(bp + 5*4)) = *(*U32)(unsafe.Pointer(bp + 5*4))<<12 | *(*U32)(unsafe.Pointer(bp + 5*4))>>(32-12)
		*(*U32)(unsafe.Pointer(bp)) += *(*U32)(unsafe.Pointer(bp + 5*4))
		*(*U32)(unsafe.Pointer(bp + 15*4)) ^= *(*U32)(unsafe.Pointer(bp))
		*(*U32)(unsafe.Pointer(bp + 15*4)) = *(*U32)(unsafe.Pointer(bp + 15*4))<<8 | *(*U32)(unsafe.Pointer(bp + 15*4))>>(32-8)
		*(*U32)(unsafe.Pointer(bp + 10*4)) += *(*U32)(unsafe.Pointer(bp + 15*4))
		*(*U32)(unsafe.Pointer(bp + 5*4)) ^= *(*U32)(unsafe.Pointer(bp + 10*4))
		*(*U32)(unsafe.Pointer(bp + 5*4)) = *(*U32)(unsafe.Pointer(bp + 5*4))<<7 | *(*U32)(unsafe.Pointer(bp + 5*4))>>(32-7)
		*(*U32)(unsafe.Pointer(bp + 1*4)) += *(*U32)(unsafe.Pointer(bp + 6*4))
		*(*U32)(unsafe.Pointer(bp + 12*4)) ^= *(*U32)(unsafe.Pointer(bp + 1*4))
		*(*U32)(unsafe.Pointer(bp + 12*4)) = *(*U32)(unsafe.Pointer(bp + 12*4))<<16 | *(*U32)(unsafe.Pointer(bp + 12*4))>>(32-16)
		*(*U32)(unsafe.Pointer(bp + 11*4)) += *(*U32)(unsafe.Pointer(bp + 12*4))
		*(*U32)(unsafe.Pointer(bp + 6*4)) ^= *(*U32)(unsafe.Pointer(bp + 11*4))
		*(*U32)(unsafe.Pointer(bp + 6*4)) = *(*U32)(unsafe.Pointer(bp + 6*4))<<12 | *(*U32)(unsafe.Pointer(bp + 6*4))>>(32-12)
		*(*U32)(unsafe.Pointer(bp + 1*4)) += *(*U32)(unsafe.Pointer(bp + 6*4))
		*(*U32)(unsafe.Pointer(bp + 12*4)) ^= *(*U32)(unsafe.Pointer(bp + 1*4))
		*(*U32)(unsafe.Pointer(bp + 12*4)) = *(*U32)(unsafe.Pointer(bp + 12*4))<<8 | *(*U32)(unsafe.Pointer(bp + 12*4))>>(32-8)
		*(*U32)(unsafe.Pointer(bp + 11*4)) += *(*U32)(unsafe.Pointer(bp + 12*4))
		*(*U32)(unsafe.Pointer(bp + 6*4)) ^= *(*U32)(unsafe.Pointer(bp + 11*4))
		*(*U32)(unsafe.Pointer(bp + 6*4)) = *(*U32)(unsafe.Pointer(bp + 6*4))<<7 | *(*U32)(unsafe.Pointer(bp + 6*4))>>(32-7)
		*(*U32)(unsafe.Pointer(bp + 2*4)) += *(*U32)(unsafe.Pointer(bp + 7*4))
		*(*U32)(unsafe.Pointer(bp + 13*4)) ^= *(*U32)(unsafe.Pointer(bp + 2*4))
		*(*U32)(unsafe.Pointer(bp + 13*4)) = *(*U32)(unsafe.Pointer(bp + 13*4))<<16 | *(*U32)(unsafe.Pointer(bp + 13*4))>>(32-16)
		*(*U32)(unsafe.Pointer(bp + 8*4)) += *(*U32)(unsafe.Pointer(bp + 13*4))
		*(*U32)(unsafe.Pointer(bp + 7*4)) ^= *(*U32)(unsafe.Pointer(bp + 8*4))
		*(*U32)(unsafe.Pointer(bp + 7*4)) = *(*U32)(unsafe.Pointer(bp + 7*4))<<12 | *(*U32)(unsafe.Pointer(bp + 7*4))>>(32-12)
		*(*U32)(unsafe.Pointer(bp + 2*4)) += *(*U32)(unsafe.Pointer(bp + 7*4))
		*(*U32)(unsafe.Pointer(bp + 13*4)) ^= *(*U32)(unsafe.Pointer(bp + 2*4))
		*(*U32)(unsafe.Pointer(bp + 13*4)) = *(*U32)(unsafe.Pointer(bp + 13*4))<<8 | *(*U32)(unsafe.Pointer(bp + 13*4))>>(32-8)
		*(*U32)(unsafe.Pointer(bp + 8*4)) += *(*U32)(unsafe.Pointer(bp + 13*4))
		*(*U32)(unsafe.Pointer(bp + 7*4)) ^= *(*U32)(unsafe.Pointer(bp + 8*4))
		*(*U32)(unsafe.Pointer(bp + 7*4)) = *(*U32)(unsafe.Pointer(bp + 7*4))<<7 | *(*U32)(unsafe.Pointer(bp + 7*4))>>(32-7)
		*(*U32)(unsafe.Pointer(bp + 3*4)) += *(*U32)(unsafe.Pointer(bp + 4*4))
		*(*U32)(unsafe.Pointer(bp + 14*4)) ^= *(*U32)(unsafe.Pointer(bp + 3*4))
		*(*U32)(unsafe.Pointer(bp + 14*4)) = *(*U32)(unsafe.Pointer(bp + 14*4))<<16 | *(*U32)(unsafe.Pointer(bp + 14*4))>>(32-16)
		*(*U32)(unsafe.Pointer(bp + 9*4)) += *(*U32)(unsafe.Pointer(bp + 14*4))
		*(*U32)(unsafe.Pointer(bp + 4*4)) ^= *(*U32)(unsafe.Pointer(bp + 9*4))
		*(*U32)(unsafe.Pointer(bp + 4*4)) = *(*U32)(unsafe.Pointer(bp + 4*4))<<12 | *(*U32)(unsafe.Pointer(bp + 4*4))>>(32-12)
		*(*U32)(unsafe.Pointer(bp + 3*4)) += *(*U32)(unsafe.Pointer(bp + 4*4))
		*(*U32)(unsafe.Pointer(bp + 14*4)) ^= *(*U32)(unsafe.Pointer(bp + 3*4))
		*(*U32)(unsafe.Pointer(bp + 14*4)) = *(*U32)(unsafe.Pointer(bp + 14*4))<<8 | *(*U32)(unsafe.Pointer(bp + 14*4))>>(32-8)
		*(*U32)(unsafe.Pointer(bp + 9*4)) += *(*U32)(unsafe.Pointer(bp + 14*4))
		*(*U32)(unsafe.Pointer(bp + 4*4)) ^= *(*U32)(unsafe.Pointer(bp + 9*4))
		*(*U32)(unsafe.Pointer(bp + 4*4)) = *(*U32)(unsafe.Pointer(bp + 4*4))<<7 | *(*U32)(unsafe.Pointer(bp + 4*4))>>(32-7)
	}
	for i = 0; i < 16; i++ {
		*(*U32)(unsafe.Pointer(out + uintptr(i)*4)) = *(*U32)(unsafe.Pointer(bp + uintptr(i)*4)) + *(*U32)(unsafe.Pointer(in + uintptr(i)*4))
	}
}

func Xsqlite3_randomness(tls *libc.TLS, N int32, pBuf uintptr) {
	var zBuf uintptr = pBuf

	var mutex uintptr

	if Xsqlite3_initialize(tls) != 0 {
		return
	}

	mutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_PRNG)

	Xsqlite3_mutex_enter(tls, mutex)
	if N <= 0 || pBuf == uintptr(0) {
		*(*U32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Prng)))) = U32(0)
		Xsqlite3_mutex_leave(tls, mutex)
		return
	}

	if *(*U32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Prng)))) == U32(0) {
		var pVfs uintptr = Xsqlite3_vfs_find(tls, uintptr(0))
		libc.Xmemcpy(tls, uintptr(unsafe.Pointer(&sqlite3Prng)), uintptr(unsafe.Pointer(&chacha20_init)), uint64(16))
		if pVfs == uintptr(0) {
			libc.Xmemset(tls, uintptr(unsafe.Pointer(&sqlite3Prng))+4*4, 0, uint64(44))
		} else {
			Xsqlite3OsRandomness(tls, pVfs, 44, uintptr(unsafe.Pointer(&sqlite3Prng))+4*4)
		}
		*(*U32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Prng)) + 15*4)) = *(*U32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Prng)) + 12*4))
		*(*U32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Prng)) + 12*4)) = U32(0)
		sqlite3Prng.Fn = U8(0)
	}

	for 1 != 0 {
		if N <= int32(sqlite3Prng.Fn) {
			libc.Xmemcpy(tls, zBuf, uintptr(unsafe.Pointer(&sqlite3Prng))+64+uintptr(int32(sqlite3Prng.Fn)-N), uint64(N))
			*(*U8)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Prng)) + 128)) -= U8(N)
			break
		}
		if int32(sqlite3Prng.Fn) > 0 {
			libc.Xmemcpy(tls, zBuf, uintptr(unsafe.Pointer(&sqlite3Prng))+64, uint64(sqlite3Prng.Fn))
			N = N - int32(sqlite3Prng.Fn)
			zBuf += uintptr(sqlite3Prng.Fn)
		}
		*(*U32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Prng)) + 12*4))++
		chacha_block(tls, uintptr(unsafe.Pointer(&sqlite3Prng))+64, uintptr(unsafe.Pointer(&sqlite3Prng)))
		sqlite3Prng.Fn = U8(64)
	}
	Xsqlite3_mutex_leave(tls, mutex)
}

var chacha20_init = [4]U32{
	U32(0x61707865), U32(0x3320646e), U32(0x79622d32), U32(0x6b206574),
}

var sqlite3SavedPrng sqlite3PrngType

func Xsqlite3PrngSaveState(tls *libc.TLS) {
	libc.Xmemcpy(tls,
		uintptr(unsafe.Pointer(&sqlite3SavedPrng)),
		uintptr(unsafe.Pointer(&sqlite3Prng)),
		uint64(unsafe.Sizeof(sqlite3Prng)))
}

func Xsqlite3PrngRestoreState(tls *libc.TLS) {
	libc.Xmemcpy(tls,
		uintptr(unsafe.Pointer(&sqlite3Prng)),
		uintptr(unsafe.Pointer(&sqlite3SavedPrng)),
		uint64(unsafe.Sizeof(sqlite3Prng)))
}

func Xsqlite3ThreadCreate(tls *libc.TLS, ppThread uintptr, xTask uintptr, pIn uintptr) int32 {
	var p uintptr

	*(*uintptr)(unsafe.Pointer(ppThread)) = uintptr(0)
	p = Xsqlite3Malloc(tls, uint64(unsafe.Sizeof(SQLiteThread{})))
	if p == uintptr(0) {
		return SQLITE_NOMEM
	}
	if int32(p)/17&1 != 0 {
		(*SQLiteThread)(unsafe.Pointer(p)).FxTask = xTask
		(*SQLiteThread)(unsafe.Pointer(p)).FpIn = pIn
	} else {
		(*SQLiteThread)(unsafe.Pointer(p)).FxTask = uintptr(0)
		(*SQLiteThread)(unsafe.Pointer(p)).FpResult = (*struct {
			f func(*libc.TLS, uintptr) uintptr
		})(unsafe.Pointer(&struct{ uintptr }{xTask})).f(tls, pIn)
	}
	*(*uintptr)(unsafe.Pointer(ppThread)) = p
	return SQLITE_OK
}

func Xsqlite3ThreadJoin(tls *libc.TLS, p uintptr, ppOut uintptr) int32 {
	if p == uintptr(0) {
		return SQLITE_NOMEM
	}
	if (*SQLiteThread)(unsafe.Pointer(p)).FxTask != 0 {
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*struct {
			f func(*libc.TLS, uintptr) uintptr
		})(unsafe.Pointer(&struct{ uintptr }{(*SQLiteThread)(unsafe.Pointer(p)).FxTask})).f(tls, (*SQLiteThread)(unsafe.Pointer(p)).FpIn)
	} else {
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*SQLiteThread)(unsafe.Pointer(p)).FpResult
	}
	Xsqlite3_free(tls, p)

	{
		var pTstAlloc uintptr = Xsqlite3Malloc(tls, uint64(10))
		if !(pTstAlloc != 0) {
			return SQLITE_NOMEM
		}
		Xsqlite3_free(tls, pTstAlloc)

	}

	return SQLITE_OK
}

var sqlite3Utf8Trans1 = [64]uint8{
	uint8(0x00), uint8(0x01), uint8(0x02), uint8(0x03), uint8(0x04), uint8(0x05), uint8(0x06), uint8(0x07),
	uint8(0x08), uint8(0x09), uint8(0x0a), uint8(0x0b), uint8(0x0c), uint8(0x0d), uint8(0x0e), uint8(0x0f),
	uint8(0x10), uint8(0x11), uint8(0x12), uint8(0x13), uint8(0x14), uint8(0x15), uint8(0x16), uint8(0x17),
	uint8(0x18), uint8(0x19), uint8(0x1a), uint8(0x1b), uint8(0x1c), uint8(0x1d), uint8(0x1e), uint8(0x1f),
	uint8(0x00), uint8(0x01), uint8(0x02), uint8(0x03), uint8(0x04), uint8(0x05), uint8(0x06), uint8(0x07),
	uint8(0x08), uint8(0x09), uint8(0x0a), uint8(0x0b), uint8(0x0c), uint8(0x0d), uint8(0x0e), uint8(0x0f),
	uint8(0x00), uint8(0x01), uint8(0x02), uint8(0x03), uint8(0x04), uint8(0x05), uint8(0x06), uint8(0x07),
	uint8(0x00), uint8(0x01), uint8(0x02), uint8(0x03), uint8(0x00), uint8(0x01), uint8(0x00), uint8(0x00),
}

func Xsqlite3Utf8Read(tls *libc.TLS, pz uintptr) U32 {
	var c uint32

	c = uint32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(pz)), 1))))
	if c >= uint32(0xc0) {
		c = uint32(sqlite3Utf8Trans1[c-uint32(0xc0)])
		for int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pz)))))&0xc0 == 0x80 {
			c = c<<6 + uint32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(pz)), 1)))))
		}
		if c < uint32(0x80) ||
			c&0xFFFFF800 == uint32(0xD800) ||
			c&0xFFFFFFFE == uint32(0xFFFE) {
			c = uint32(0xFFFD)
		}
	}
	return c
}

func Xsqlite3VdbeMemTranslate(tls *libc.TLS, pMem uintptr, desiredEnc U8) int32 {
	var len Sqlite3_int64
	var zOut uintptr
	var zIn uintptr
	var zTerm uintptr
	var z uintptr
	var c uint32
	var temp U8
	var rc int32
	var c2 int32
	var c21 int32

	if !(int32((*Mem)(unsafe.Pointer(pMem)).Fenc) != SQLITE_UTF8 && int32(desiredEnc) != SQLITE_UTF8) {
		goto __1
	}
	rc = Xsqlite3VdbeMemMakeWriteable(tls, pMem)
	if !(rc != SQLITE_OK) {
		goto __2
	}

	return SQLITE_NOMEM
__2:
	;
	zIn = (*Mem)(unsafe.Pointer(pMem)).Fz
	zTerm = zIn + uintptr((*Mem)(unsafe.Pointer(pMem)).Fn&libc.CplInt32(1))
__3:
	if !(zIn < zTerm) {
		goto __4
	}
	temp = *(*uint8)(unsafe.Pointer(zIn))
	*(*uint8)(unsafe.Pointer(zIn)) = *(*uint8)(unsafe.Pointer(zIn + uintptr(1)))
	zIn++
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))) = temp
	goto __3
__4:
	;
	(*Mem)(unsafe.Pointer(pMem)).Fenc = desiredEnc
	goto translate_out
__1:
	;
	if !(int32(desiredEnc) == SQLITE_UTF8) {
		goto __5
	}

	*(*int32)(unsafe.Pointer(pMem + 16)) &= libc.CplInt32(1)
	len = int64(2)*Sqlite3_int64((*Mem)(unsafe.Pointer(pMem)).Fn) + int64(1)
	goto __6
__5:
	len = int64(2)*Sqlite3_int64((*Mem)(unsafe.Pointer(pMem)).Fn) + int64(2)
__6:
	;
	zIn = (*Mem)(unsafe.Pointer(pMem)).Fz
	zTerm = zIn + uintptr((*Mem)(unsafe.Pointer(pMem)).Fn)
	zOut = Xsqlite3DbMallocRaw(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, uint64(len))
	if !!(zOut != 0) {
		goto __7
	}
	return SQLITE_NOMEM
__7:
	;
	z = zOut

	if !(int32((*Mem)(unsafe.Pointer(pMem)).Fenc) == SQLITE_UTF8) {
		goto __8
	}
	if !(int32(desiredEnc) == SQLITE_UTF16LE) {
		goto __10
	}

__12:
	if !(zIn < zTerm) {
		goto __13
	}
	c = uint32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
	if !(c >= uint32(0xc0)) {
		goto __14
	}
	c = uint32(sqlite3Utf8Trans1[c-uint32(0xc0)])
__15:
	if !(zIn != zTerm && int32(*(*uint8)(unsafe.Pointer(zIn)))&0xc0 == 0x80) {
		goto __16
	}
	c = c<<6 + uint32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))))
	goto __15
__16:
	;
	if !(c < uint32(0x80) || c&0xFFFFF800 == uint32(0xD800) || c&0xFFFFFFFE == uint32(0xFFFE)) {
		goto __17
	}
	c = uint32(0xFFFD)
__17:
	;
__14:
	;
	if !(c <= uint32(0xFFFF)) {
		goto __18
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c & uint32(0x00FF))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c >> 8 & uint32(0x00FF))
	goto __19
__18:
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c>>10&uint32(0x003F) + (c-uint32(0x10000))>>10&uint32(0x00C0))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(uint32(0x00D8) + (c-uint32(0x10000))>>18&uint32(0x03))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c & uint32(0x00FF))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(uint32(0x00DC) + c>>8&uint32(0x03))
__19:
	;
	goto __12
__13:
	;
	goto __11
__10:
	;
__20:
	if !(zIn < zTerm) {
		goto __21
	}
	c = uint32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
	if !(c >= uint32(0xc0)) {
		goto __22
	}
	c = uint32(sqlite3Utf8Trans1[c-uint32(0xc0)])
__23:
	if !(zIn != zTerm && int32(*(*uint8)(unsafe.Pointer(zIn)))&0xc0 == 0x80) {
		goto __24
	}
	c = c<<6 + uint32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))))
	goto __23
__24:
	;
	if !(c < uint32(0x80) || c&0xFFFFF800 == uint32(0xD800) || c&0xFFFFFFFE == uint32(0xFFFE)) {
		goto __25
	}
	c = uint32(0xFFFD)
__25:
	;
__22:
	;
	if !(c <= uint32(0xFFFF)) {
		goto __26
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c >> 8 & uint32(0x00FF))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c & uint32(0x00FF))
	goto __27
__26:
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(uint32(0x00D8) + (c-uint32(0x10000))>>18&uint32(0x03))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c>>10&uint32(0x003F) + (c-uint32(0x10000))>>10&uint32(0x00C0))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(uint32(0x00DC) + c>>8&uint32(0x03))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c & uint32(0x00FF))
__27:
	;
	goto __20
__21:
	;
__11:
	;
	(*Mem)(unsafe.Pointer(pMem)).Fn = int32((int64(z) - int64(zOut)) / 1)
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0)
	goto __9
__8:
	;
	if !(int32((*Mem)(unsafe.Pointer(pMem)).Fenc) == SQLITE_UTF16LE) {
		goto __28
	}

__30:
	if !(zIn < zTerm) {
		goto __31
	}
	c = uint32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
	c = c + uint32(int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))<<8)
	if !(c >= uint32(0xd800) && c < uint32(0xe000)) {
		goto __32
	}
	if !(zIn < zTerm) {
		goto __33
	}
	c2 = int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
	c2 = c2 + int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))<<8
	c = uint32(c2&0x03FF) + c&uint32(0x003F)<<10 + (c&uint32(0x03C0)+uint32(0x0040))<<10
__33:
	;
__32:
	;
	if !(c < uint32(0x00080)) {
		goto __34
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c & uint32(0xFF))
	goto __35
__34:
	if !(c < uint32(0x00800)) {
		goto __36
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0xC0 + int32(U8(c>>6&uint32(0x1F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
	goto __37
__36:
	if !(c < uint32(0x10000)) {
		goto __38
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0xE0 + int32(U8(c>>12&uint32(0x0F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c>>6&uint32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
	goto __39
__38:
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0xF0 + int32(U8(c>>18&uint32(0x07))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c>>12&uint32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c>>6&uint32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
__39:
	;
__37:
	;
__35:
	;
	goto __30
__31:
	;
	goto __29
__28:
__40:
	if !(zIn < zTerm) {
		goto __41
	}
	c = uint32(int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))) << 8)
	c = c + uint32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
	if !(c >= uint32(0xd800) && c < uint32(0xe000)) {
		goto __42
	}
	if !(zIn < zTerm) {
		goto __43
	}
	c21 = int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))) << 8
	c21 = c21 + int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
	c = uint32(c21&0x03FF) + c&uint32(0x003F)<<10 + (c&uint32(0x03C0)+uint32(0x0040))<<10
__43:
	;
__42:
	;
	if !(c < uint32(0x00080)) {
		goto __44
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = U8(c & uint32(0xFF))
	goto __45
__44:
	if !(c < uint32(0x00800)) {
		goto __46
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0xC0 + int32(U8(c>>6&uint32(0x1F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
	goto __47
__46:
	if !(c < uint32(0x10000)) {
		goto __48
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0xE0 + int32(U8(c>>12&uint32(0x0F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c>>6&uint32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
	goto __49
__48:
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0xF0 + int32(U8(c>>18&uint32(0x07))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c>>12&uint32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c>>6&uint32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
__49:
	;
__47:
	;
__45:
	;
	goto __40
__41:
	;
__29:
	;
	(*Mem)(unsafe.Pointer(pMem)).Fn = int32((int64(z) - int64(zOut)) / 1)
__9:
	;
	*(*uint8)(unsafe.Pointer(z)) = uint8(0)

	c = uint32(MEM_Str | MEM_Term | int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_AffMask|MEM_Subtype))
	Xsqlite3VdbeMemRelease(tls, pMem)
	(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(c)
	(*Mem)(unsafe.Pointer(pMem)).Fenc = desiredEnc
	(*Mem)(unsafe.Pointer(pMem)).Fz = zOut
	(*Mem)(unsafe.Pointer(pMem)).FzMalloc = (*Mem)(unsafe.Pointer(pMem)).Fz
	(*Mem)(unsafe.Pointer(pMem)).FszMalloc = Xsqlite3DbMallocSize(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, (*Mem)(unsafe.Pointer(pMem)).Fz)

translate_out:
	return SQLITE_OK
}

func Xsqlite3VdbeMemHandleBom(tls *libc.TLS, pMem uintptr) int32 {
	var rc int32 = SQLITE_OK
	var bom U8 = U8(0)

	if (*Mem)(unsafe.Pointer(pMem)).Fn > 1 {
		var b1 U8 = *(*U8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fz))
		var b2 U8 = *(*U8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fz + uintptr(1)))
		if int32(b1) == 0xFE && int32(b2) == 0xFF {
			bom = U8(SQLITE_UTF16BE)
		}
		if int32(b1) == 0xFF && int32(b2) == 0xFE {
			bom = U8(SQLITE_UTF16LE)
		}
	}

	if bom != 0 {
		rc = Xsqlite3VdbeMemMakeWriteable(tls, pMem)
		if rc == SQLITE_OK {
			*(*int32)(unsafe.Pointer(pMem + 16)) -= 2
			libc.Xmemmove(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, (*Mem)(unsafe.Pointer(pMem)).Fz+2, uint64((*Mem)(unsafe.Pointer(pMem)).Fn))
			*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fz + uintptr((*Mem)(unsafe.Pointer(pMem)).Fn))) = uint8(0)
			*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fz + uintptr((*Mem)(unsafe.Pointer(pMem)).Fn+1))) = uint8(0)
			*(*U16)(unsafe.Pointer(pMem + 20)) |= U16(MEM_Term)
			(*Mem)(unsafe.Pointer(pMem)).Fenc = bom
		}
	}
	return rc
}

func Xsqlite3Utf8CharLen(tls *libc.TLS, zIn uintptr, nByte int32) int32 {
	var r int32 = 0
	var z uintptr = zIn
	var zTerm uintptr
	if nByte >= 0 {
		zTerm = z + uintptr(nByte)
	} else {
		zTerm = libc.UintptrFromInt32(-1)
	}

	for int32(*(*U8)(unsafe.Pointer(z))) != 0 && z < zTerm {
		{
			if int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1)))) >= 0xc0 {
				for int32(*(*U8)(unsafe.Pointer(z)))&0xc0 == 0x80 {
					z++
				}
			}
		}

		r++
	}
	return r
}

func Xsqlite3Utf16to8(tls *libc.TLS, db uintptr, z uintptr, nByte int32, enc U8) uintptr {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Mem{})))
	(*Mem)(unsafe.Pointer(bp)).Fdb = db
	Xsqlite3VdbeMemSetStr(tls, bp, z, int64(nByte), enc, uintptr(0))
	Xsqlite3VdbeChangeEncoding(tls, bp, SQLITE_UTF8)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		Xsqlite3VdbeMemRelease(tls, bp)
		(*Mem)(unsafe.Pointer(bp)).Fz = uintptr(0)
	}

	return (*Mem)(unsafe.Pointer(bp)).Fz
}

func Xsqlite3Utf16ByteLen(tls *libc.TLS, zIn uintptr, nChar int32) int32 {
	var c int32
	var z uintptr = zIn
	var n int32 = 0

	if SQLITE_UTF16LE == SQLITE_UTF16LE {
		z++
	}
	for n < nChar {
		c = int32(*(*uint8)(unsafe.Pointer(z)))
		z += uintptr(2)
		if c >= 0xd8 && c < 0xdc && int32(*(*uint8)(unsafe.Pointer(z))) >= 0xdc && int32(*(*uint8)(unsafe.Pointer(z))) < 0xe0 {
			z += uintptr(2)
		}
		n++
	}
	return int32((int64(z)-int64(zIn))/1) -
		libc.Bool32(SQLITE_UTF16LE == SQLITE_UTF16LE)
}

func Xsqlite3UtfSelfTest(tls *libc.TLS) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var i uint32
	var t uint32
	_ = t

	var n int32
	_ = n
	var c uint32
	_ = c

	for i = uint32(0); i < uint32(0x00110000); i++ {
		*(*uintptr)(unsafe.Pointer(bp + 24)) = bp
		{
			if i < uint32(0x00080) {
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = U8(i & uint32(0xFF))
			} else if i < uint32(0x00800) {
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0xC0 + int32(U8(i>>6&uint32(0x1F))))
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0x80 + int32(U8(i&uint32(0x3F))))
			} else if i < uint32(0x10000) {
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0xE0 + int32(U8(i>>12&uint32(0x0F))))
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0x80 + int32(U8(i>>6&uint32(0x3F))))
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0x80 + int32(U8(i&uint32(0x3F))))
			} else {
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0xF0 + int32(U8(i>>18&uint32(0x07))))
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0x80 + int32(U8(i>>12&uint32(0x3F))))
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0x80 + int32(U8(i>>6&uint32(0x3F))))
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 24)), 1))) = uint8(0x80 + int32(U8(i&uint32(0x3F))))
			}
		}

		n = int32(int64((*(*uintptr)(unsafe.Pointer(bp + 24)) - bp) / 1))

		*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))) = uint8(0)
		*(*uintptr)(unsafe.Pointer(bp + 24)) = bp
		c = Xsqlite3Utf8Read(tls, bp+24)
		t = i
		if i >= uint32(0xD800) && i <= uint32(0xDFFF) {
			t = uint32(0xFFFD)
		}
		if i&0xFFFFFFFE == uint32(0xFFFE) {
			t = uint32(0xFFFD)
		}

	}
}

type Float_t = float32
type Double_t = float64

func Xsqlite3FaultSim(tls *libc.TLS, iTest int32) int32 {
	var xCallback uintptr = Xsqlite3Config.FxTestCallback
	if xCallback != 0 {
		return (*struct{ f func(*libc.TLS, int32) int32 })(unsafe.Pointer(&struct{ uintptr }{xCallback})).f(tls, iTest)
	}
	return SQLITE_OK
}

func Xsqlite3IsNaN(tls *libc.TLS, x float64) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp + 8)) = x

	var rc int32

	libc.Xmemcpy(tls, bp, bp+8, uint64(unsafe.Sizeof(U64(0))))
	rc = libc.Bool32(*(*U64)(unsafe.Pointer(bp))&(uint64(0x7ff)<<52) == uint64(0x7ff)<<52 && *(*U64)(unsafe.Pointer(bp))&(uint64(1)<<52-uint64(1)) != uint64(0))

	return rc
}

func Xsqlite3Strlen30(tls *libc.TLS, z uintptr) int32 {
	if z == uintptr(0) {
		return 0
	}
	return 0x3fffffff & int32(libc.Xstrlen(tls, z))
}

func Xsqlite3ColumnType(tls *libc.TLS, pCol uintptr, zDflt uintptr) uintptr {
	if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_HASTYPE != 0 {
		return (*Column)(unsafe.Pointer(pCol)).FzCnName + uintptr(libc.Xstrlen(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName)) + uintptr(1)
	} else if uint32(int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)) != 0 {
		return Xsqlite3StdType[(int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4)-1)&0xf<<28>>28]
	} else {
		return zDflt
	}
	return uintptr(0)
}

func sqlite3ErrorFinish(tls *libc.TLS, db uintptr, err_code int32) {
	if (*Sqlite3)(unsafe.Pointer(db)).FpErr != 0 {
		Xsqlite3ValueSetNull(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr)
	}
	Xsqlite3SystemError(tls, db, err_code)
}

func Xsqlite3Error(tls *libc.TLS, db uintptr, err_code int32) {
	(*Sqlite3)(unsafe.Pointer(db)).FerrCode = err_code
	if err_code != 0 || (*Sqlite3)(unsafe.Pointer(db)).FpErr != 0 {
		sqlite3ErrorFinish(tls, db, err_code)
	} else {
		(*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset = -1
	}
}

func Xsqlite3ErrorClear(tls *libc.TLS, db uintptr) {
	(*Sqlite3)(unsafe.Pointer(db)).FerrCode = SQLITE_OK
	(*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset = -1
	if (*Sqlite3)(unsafe.Pointer(db)).FpErr != 0 {
		Xsqlite3ValueSetNull(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr)
	}
}

func Xsqlite3SystemError(tls *libc.TLS, db uintptr, rc int32) {
	if rc == SQLITE_IOERR|int32(12)<<8 {
		return
	}
	rc = rc & 0xff
	if rc == SQLITE_CANTOPEN || rc == SQLITE_IOERR {
		(*Sqlite3)(unsafe.Pointer(db)).FiSysErrno = Xsqlite3OsGetLastError(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs)
	}
}

func Xsqlite3ErrorWithMsg(tls *libc.TLS, db uintptr, err_code int32, zFormat uintptr, va uintptr) {
	(*Sqlite3)(unsafe.Pointer(db)).FerrCode = err_code
	Xsqlite3SystemError(tls, db, err_code)
	if zFormat == uintptr(0) {
		Xsqlite3Error(tls, db, err_code)
	} else if (*Sqlite3)(unsafe.Pointer(db)).FpErr != 0 || libc.AssignPtrUintptr(db+424, Xsqlite3ValueNew(tls, db)) != uintptr(0) {
		var z uintptr
		var ap Va_list
		_ = ap
		ap = va
		z = Xsqlite3VMPrintf(tls, db, zFormat, ap)
		_ = ap
		Xsqlite3ValueSetStr(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr, -1, z, uint8(SQLITE_UTF8), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})))
	}
}

func Xsqlite3ProgressCheck(tls *libc.TLS, p uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer(p)).Fdb
	if libc.AtomicLoadNInt32(db+432, 0) != 0 {
		(*Parse)(unsafe.Pointer(p)).FnErr++
		(*Parse)(unsafe.Pointer(p)).Frc = SQLITE_INTERRUPT
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FxProgress != 0 && libc.PreIncUint32(&(*Parse)(unsafe.Pointer(p)).FnProgressSteps, 1) >= (*Sqlite3)(unsafe.Pointer(db)).FnProgressOps {
		if (*struct {
			f func(*libc.TLS, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxProgress})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0 {
			(*Parse)(unsafe.Pointer(p)).FnErr++
			(*Parse)(unsafe.Pointer(p)).Frc = SQLITE_INTERRUPT
		}
		(*Parse)(unsafe.Pointer(p)).FnProgressSteps = U32(0)
	}
}

func Xsqlite3ErrorMsg(tls *libc.TLS, pParse uintptr, zFormat uintptr, va uintptr) {
	var zMsg uintptr
	var ap Va_list
	_ = ap
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	(*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset = -2
	ap = va
	zMsg = Xsqlite3VMPrintf(tls, db, zFormat, ap)
	_ = ap
	if (*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset < -1 {
		(*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset = -1
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FsuppressErr != 0 {
		Xsqlite3DbFree(tls, db, zMsg)
		if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			(*Parse)(unsafe.Pointer(pParse)).FnErr++
			(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
		}
	} else {
		(*Parse)(unsafe.Pointer(pParse)).FnErr++
		Xsqlite3DbFree(tls, db, (*Parse)(unsafe.Pointer(pParse)).FzErrMsg)
		(*Parse)(unsafe.Pointer(pParse)).FzErrMsg = zMsg
		(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_ERROR
		(*Parse)(unsafe.Pointer(pParse)).FpWith = uintptr(0)
	}
}

func Xsqlite3ErrorToParser(tls *libc.TLS, db uintptr, errCode int32) int32 {
	var pParse uintptr
	if db == uintptr(0) || libc.AssignUintptr(&pParse, (*Sqlite3)(unsafe.Pointer(db)).FpParse) == uintptr(0) {
		return errCode
	}
	(*Parse)(unsafe.Pointer(pParse)).Frc = errCode
	(*Parse)(unsafe.Pointer(pParse)).FnErr++
	return errCode
}

func Xsqlite3Dequote(tls *libc.TLS, z uintptr) {
	var quote uint8
	var i int32
	var j int32
	if z == uintptr(0) {
		return
	}
	quote = *(*uint8)(unsafe.Pointer(z))
	if !(int32(Xsqlite3CtypeMap[quote])&0x80 != 0) {
		return
	}
	if int32(quote) == '[' {
		quote = uint8(']')
	}
	i = 1
	j = 0
	for ; ; i++ {
		if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == int32(quote) {
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+1)))) == int32(quote) {
				*(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&j, 1)))) = quote
				i++
			} else {
				break
			}
		} else {
			*(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&j, 1)))) = *(*uint8)(unsafe.Pointer(z + uintptr(i)))
		}
	}
	*(*uint8)(unsafe.Pointer(z + uintptr(j))) = uint8(0)
}

func Xsqlite3DequoteExpr(tls *libc.TLS, p uintptr) {
	*(*U32)(unsafe.Pointer(p + 4)) |= func() uint32 {
		if int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8))))) == '"' {
			return uint32(EP_Quoted | EP_DblQuoted)
		}
		return uint32(EP_Quoted)
	}()
	Xsqlite3Dequote(tls, *(*uintptr)(unsafe.Pointer(p + 8)))
}

func Xsqlite3DequoteToken(tls *libc.TLS, p uintptr) {
	var i uint32
	if (*Token)(unsafe.Pointer(p)).Fn < uint32(2) {
		return
	}
	if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(p)).Fz))])&0x80 != 0) {
		return
	}
	for i = uint32(1); i < (*Token)(unsafe.Pointer(p)).Fn-uint32(1); i++ {
		if int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(p)).Fz + uintptr(i)))])&0x80 != 0 {
			return
		}
	}
	*(*uint32)(unsafe.Pointer(p + 8)) -= uint32(2)
	(*Token)(unsafe.Pointer(p)).Fz++
}

func Xsqlite3TokenInit(tls *libc.TLS, p uintptr, z uintptr) {
	(*Token)(unsafe.Pointer(p)).Fz = z
	(*Token)(unsafe.Pointer(p)).Fn = uint32(Xsqlite3Strlen30(tls, z))
}

func Xsqlite3_stricmp(tls *libc.TLS, zLeft uintptr, zRight uintptr) int32 {
	if zLeft == uintptr(0) {
		if zRight != 0 {
			return -1
		}
		return 0
	} else if zRight == uintptr(0) {
		return 1
	}
	return Xsqlite3StrICmp(tls, zLeft, zRight)
}

func Xsqlite3StrICmp(tls *libc.TLS, zLeft uintptr, zRight uintptr) int32 {
	var a uintptr
	var b uintptr
	var c int32
	var x int32
	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(Xsqlite3UpperToLower[c]) - int32(Xsqlite3UpperToLower[x])
			if c != 0 {
				break
			}
		}
		a++
		b++
	}
	return c
}

func Xsqlite3_strnicmp(tls *libc.TLS, zLeft uintptr, zRight uintptr, N int32) int32 {
	var a uintptr
	var b uintptr
	if zLeft == uintptr(0) {
		if zRight != 0 {
			return -1
		}
		return 0
	} else if zRight == uintptr(0) {
		return 1
	}
	a = zLeft
	b = zRight
	for libc.PostDecInt32(&N, 1) > 0 && int32(*(*uint8)(unsafe.Pointer(a))) != 0 && int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(a))]) == int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(b))]) {
		a++
		b++
	}
	if N < 0 {
		return 0
	}
	return int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(a))]) - int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(b))])
}

func Xsqlite3StrIHash(tls *libc.TLS, z uintptr) U8 {
	var h U8 = U8(0)
	if z == uintptr(0) {
		return U8(0)
	}
	for *(*uint8)(unsafe.Pointer(z)) != 0 {
		h = U8(int32(h) + int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(z))]))
		z++
	}
	return h
}

func sqlite3Pow10(tls *libc.TLS, E int32) float64 {
	var x float64 = 10.0
	var r float64 = 1.0
	for 1 != 0 {
		if E&1 != 0 {
			r = r * x
		}
		E >>= 1
		if E == 0 {
			break
		}
		x = x * x
	}
	return r
}

func Xsqlite3AtoF(tls *libc.TLS, z uintptr, pResult uintptr, length int32, enc U8) int32 {
	var incr int32
	var zEnd uintptr

	var sign int32
	var s I64
	var d int32
	var esign int32
	var e int32
	var eValid int32
	var result float64
	var nDigit int32
	var eType int32
	var i int32
	var scale float64
	var scale1 float64
	sign = 1
	s = int64(0)
	d = 0
	esign = 1
	e = 0
	eValid = 1
	nDigit = 0
	eType = 1

	*(*float64)(unsafe.Pointer(pResult)) = 0.0
	if !(length == 0) {
		goto __1
	}
	return 0
__1:
	;
	if !(int32(enc) == SQLITE_UTF8) {
		goto __2
	}
	incr = 1
	zEnd = z + uintptr(length)
	goto __3
__2:
	incr = 2
	length = length & libc.CplInt32(1)

	i = 3 - int32(enc)
__4:
	if !(i < length && int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == 0) {
		goto __6
	}
	goto __5
__5:
	i = i + 2
	goto __4
	goto __6
__6:
	;
	if !(i < length) {
		goto __7
	}
	eType = -100
__7:
	;
	zEnd = z + uintptr(i^1)
	z += uintptr(int32(enc) & 1)
__3:
	;
__8:
	if !(z < zEnd && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z))])&0x01 != 0) {
		goto __9
	}
	z += uintptr(incr)
	goto __8
__9:
	;
	if !(z >= zEnd) {
		goto __10
	}
	return 0
__10:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(z))) == '-') {
		goto __11
	}
	sign = -1
	z += uintptr(incr)
	goto __12
__11:
	if !(int32(*(*uint8)(unsafe.Pointer(z))) == '+') {
		goto __13
	}
	z += uintptr(incr)
__13:
	;
__12:
	;
__14:
	if !(z < zEnd && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z))])&0x04 != 0) {
		goto __15
	}
	s = s*int64(10) + I64(int32(*(*uint8)(unsafe.Pointer(z)))-'0')
	z += uintptr(incr)
	nDigit++
	if !(s >= (int64(0xffffffff)|int64(0x7fffffff)<<32-int64(9))/int64(10)) {
		goto __16
	}

__17:
	if !(z < zEnd && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z))])&0x04 != 0) {
		goto __18
	}
	z += uintptr(incr)
	d++
	goto __17
__18:
	;
__16:
	;
	goto __14
__15:
	;
	if !(z >= zEnd) {
		goto __19
	}
	goto do_atof_calc
__19:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(z))) == '.') {
		goto __20
	}
	z += uintptr(incr)
	eType++

__21:
	if !(z < zEnd && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z))])&0x04 != 0) {
		goto __22
	}
	if !(s < (int64(0xffffffff)|int64(0x7fffffff)<<32-int64(9))/int64(10)) {
		goto __23
	}
	s = s*int64(10) + I64(int32(*(*uint8)(unsafe.Pointer(z)))-'0')
	d--
	nDigit++
__23:
	;
	z += uintptr(incr)
	goto __21
__22:
	;
__20:
	;
	if !(z >= zEnd) {
		goto __24
	}
	goto do_atof_calc
__24:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(z))) == 'e' || int32(*(*uint8)(unsafe.Pointer(z))) == 'E') {
		goto __25
	}
	z += uintptr(incr)
	eValid = 0
	eType++

	if !(z >= zEnd) {
		goto __26
	}
	goto do_atof_calc
__26:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(z))) == '-') {
		goto __27
	}
	esign = -1
	z += uintptr(incr)
	goto __28
__27:
	if !(int32(*(*uint8)(unsafe.Pointer(z))) == '+') {
		goto __29
	}
	z += uintptr(incr)
__29:
	;
__28:
	;
__30:
	if !(z < zEnd && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z))])&0x04 != 0) {
		goto __31
	}
	if e < 10000 {
		e = e*10 + (int32(*(*uint8)(unsafe.Pointer(z))) - '0')
	} else {
		e = 10000
	}
	z += uintptr(incr)
	eValid = 1
	goto __30
__31:
	;
__25:
	;
__32:
	if !(z < zEnd && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z))])&0x01 != 0) {
		goto __33
	}
	z += uintptr(incr)
	goto __32
__33:
	;
do_atof_calc:
	e = e*esign + d
	if !(e < 0) {
		goto __34
	}
	esign = -1
	e = e * -1
	goto __35
__34:
	esign = 1
__35:
	;
	if !(s == int64(0)) {
		goto __36
	}

	if sign < 0 {
		result = -libc.Float64FromFloat64(float64(0))
	} else {
		result = float64(0)
	}
	goto __37
__36:
__38:
	if !(e > 0) {
		goto __39
	}
	if !(esign > 0) {
		goto __40
	}
	if !(s >= (int64(0xffffffff)|int64(0x7fffffff)<<32)/int64(10)) {
		goto __42
	}
	goto __39
__42:
	;
	s = s * int64(10)
	goto __41
__40:
	if !(s%int64(10) != int64(0)) {
		goto __43
	}
	goto __39
__43:
	;
	s = s / int64(10)
__41:
	;
	e--
	goto __38
__39:
	;
	if sign < 0 {
		s = -s
	} else {
		s = s
	}

	if !(e == 0) {
		goto __44
	}
	result = float64(s)
	goto __45
__44:
	if !(e > 307) {
		goto __46
	}
	if !(e < 342) {
		goto __48
	}
	scale = sqlite3Pow10(tls, e-308)
	if !(esign < 0) {
		goto __50
	}
	result = float64(s) / scale
	result = result / 1.0e+308
	goto __51
__50:
	result = float64(s) * scale
	result = result * 1.0e+308
__51:
	;
	goto __49
__48:
	;
	if !(esign < 0) {
		goto __52
	}
	result = 0.0 * float64(s)
	goto __53
__52:
	result = float64(libc.X__builtin_inff(tls) * float32(s))
__53:
	;
__49:
	;
	goto __47
__46:
	scale1 = sqlite3Pow10(tls, e)
	if !(esign < 0) {
		goto __54
	}
	result = float64(s) / scale1
	goto __55
__54:
	result = float64(s) * scale1
__55:
	;
__47:
	;
__45:
	;
__37:
	;
	*(*float64)(unsafe.Pointer(pResult)) = result

	if !(z == zEnd && nDigit > 0 && eValid != 0 && eType > 0) {
		goto __56
	}
	return eType
	goto __57
__56:
	if !(eType >= 2 && (eType == 3 || eValid != 0) && nDigit > 0) {
		goto __58
	}
	return -1
	goto __59
__58:
	return 0
__59:
	;
__57:
	;
	return int32(0)
}

func Xsqlite3Int64ToText(tls *libc.TLS, v I64, zOut uintptr) int32 {
	bp := tls.Alloc(22)
	defer tls.Free(22)

	var i int32
	var x U64

	if v < int64(0) {
		if v == int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32) {
			x = uint64(1) << 63
		} else {
			x = U64(-v)
		}
	} else {
		x = U64(v)
	}
	i = int32(uint64(unsafe.Sizeof([22]uint8{})) - uint64(2))
	*(*uint8)(unsafe.Pointer(bp + 21)) = uint8(0)
	for __ccgo := true; __ccgo; __ccgo = x != 0 {
		*(*uint8)(unsafe.Pointer(bp + uintptr(libc.PostDecInt32(&i, 1)))) = uint8(x%uint64(10) + uint64('0'))
		x = x / uint64(10)
	}
	if v < int64(0) {
		*(*uint8)(unsafe.Pointer(bp + uintptr(libc.PostDecInt32(&i, 1)))) = uint8('-')
	}
	libc.Xmemcpy(tls, zOut, bp+uintptr(i+1), uint64(unsafe.Sizeof([22]uint8{}))-uint64(1)-uint64(i))
	return int32(uint64(unsafe.Sizeof([22]uint8{})) - uint64(2) - uint64(i))
}

func compare2pow63(tls *libc.TLS, zNum uintptr, incr int32) int32 {
	var c int32 = 0
	var i int32

	var pow63 uintptr = ts + 1687
	for i = 0; c == 0 && i < 18; i++ {
		c = (int32(*(*uint8)(unsafe.Pointer(zNum + uintptr(i*incr)))) - int32(*(*uint8)(unsafe.Pointer(pow63 + uintptr(i))))) * 10
	}
	if c == 0 {
		c = int32(*(*uint8)(unsafe.Pointer(zNum + uintptr(18*incr)))) - '8'

	}
	return c
}

func Xsqlite3Atoi64(tls *libc.TLS, zNum uintptr, pNum uintptr, length int32, enc U8) int32 {
	var incr int32
	var u U64 = uint64(0)
	var neg int32 = 0
	var i int32
	var c int32 = 0
	var nonNum int32 = 0
	var rc int32
	var zStart uintptr
	var zEnd uintptr = zNum + uintptr(length)

	if int32(enc) == SQLITE_UTF8 {
		incr = 1
	} else {
		incr = 2
		length = length & libc.CplInt32(1)

		for i = 3 - int32(enc); i < length && int32(*(*uint8)(unsafe.Pointer(zNum + uintptr(i)))) == 0; i = i + 2 {
		}
		nonNum = libc.Bool32(i < length)
		zEnd = zNum + uintptr(i^1)
		zNum += uintptr(int32(enc) & 1)
	}
	for zNum < zEnd && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zNum))])&0x01 != 0 {
		zNum += uintptr(incr)
	}
	if zNum < zEnd {
		if int32(*(*uint8)(unsafe.Pointer(zNum))) == '-' {
			neg = 1
			zNum += uintptr(incr)
		} else if int32(*(*uint8)(unsafe.Pointer(zNum))) == '+' {
			zNum += uintptr(incr)
		}
	}
	zStart = zNum
	for zNum < zEnd && int32(*(*uint8)(unsafe.Pointer(zNum))) == '0' {
		zNum += uintptr(incr)
	}
	for i = 0; zNum+uintptr(i) < zEnd && libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(zNum + uintptr(i))))) >= '0' && c <= '9'; i = i + incr {
		u = u*uint64(10) + U64(c) - uint64('0')
	}

	if u > uint64(int64(0xffffffff)|int64(0x7fffffff)<<32) {
		*(*I64)(unsafe.Pointer(pNum)) = func() int64 {
			if neg != 0 {
				return int64(-1) - (int64(0xffffffff) | int64(0x7fffffff)<<32)
			}
			return int64(0xffffffff) | int64(0x7fffffff)<<32
		}()
	} else if neg != 0 {
		*(*I64)(unsafe.Pointer(pNum)) = -I64(u)
	} else {
		*(*I64)(unsafe.Pointer(pNum)) = I64(u)
	}
	rc = 0
	if i == 0 && zStart == zNum {
		rc = -1
	} else if nonNum != 0 {
		rc = 1
	} else if zNum+uintptr(i) < zEnd {
		var jj int32 = i
		for __ccgo := true; __ccgo; __ccgo = zNum+uintptr(jj) < zEnd {
			if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zNum + uintptr(jj)))])&0x01 != 0) {
				rc = 1
				break
			}
			jj = jj + incr
		}
	}
	if i < 19*incr {
		return rc
	} else {
		if i > 19*incr {
			c = 1
		} else {
			c = compare2pow63(tls, zNum, incr)
		}
		if c < 0 {
			return rc
		} else {
			*(*I64)(unsafe.Pointer(pNum)) = func() int64 {
				if neg != 0 {
					return int64(-1) - (int64(0xffffffff) | int64(0x7fffffff)<<32)
				}
				return int64(0xffffffff) | int64(0x7fffffff)<<32
			}()
			if c > 0 {
				return 2
			} else {
				if neg != 0 {
					return rc
				}
				return 3
			}
		}
	}
	return int32(0)
}

func Xsqlite3DecOrHexToI64(tls *libc.TLS, z uintptr, pOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if int32(*(*uint8)(unsafe.Pointer(z))) == '0' &&
		(int32(*(*uint8)(unsafe.Pointer(z + 1))) == 'x' || int32(*(*uint8)(unsafe.Pointer(z + 1))) == 'X') {
		*(*U64)(unsafe.Pointer(bp)) = uint64(0)
		var i int32
		var k int32
		for i = 2; int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == '0'; i++ {
		}
		for k = i; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(k)))])&0x08 != 0; k++ {
			*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))*uint64(16) + U64(Xsqlite3HexToInt(tls, int32(*(*uint8)(unsafe.Pointer(z + uintptr(k))))))
		}
		libc.Xmemcpy(tls, pOut, bp, uint64(8))
		if int32(*(*uint8)(unsafe.Pointer(z + uintptr(k)))) == 0 && k-i <= 16 {
			return 0
		}
		return 2
	} else {
		return Xsqlite3Atoi64(tls, z, pOut, Xsqlite3Strlen30(tls, z), uint8(SQLITE_UTF8))
	}
	return int32(0)
}

func Xsqlite3GetInt32(tls *libc.TLS, zNum uintptr, pValue uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var v Sqlite_int64 = int64(0)
	var i int32
	var c int32
	var neg int32 = 0
	if int32(*(*uint8)(unsafe.Pointer(zNum))) == '-' {
		neg = 1
		zNum++
	} else if int32(*(*uint8)(unsafe.Pointer(zNum))) == '+' {
		zNum++
	} else if int32(*(*uint8)(unsafe.Pointer(zNum))) == '0' &&
		(int32(*(*uint8)(unsafe.Pointer(zNum + 1))) == 'x' || int32(*(*uint8)(unsafe.Pointer(zNum + 1))) == 'X') &&
		int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zNum + 2))])&0x08 != 0 {
		*(*U32)(unsafe.Pointer(bp)) = U32(0)
		zNum += uintptr(2)
		for int32(*(*uint8)(unsafe.Pointer(zNum))) == '0' {
			zNum++
		}
		for i = 0; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zNum + uintptr(i)))])&0x08 != 0 && i < 8; i++ {
			*(*U32)(unsafe.Pointer(bp)) = *(*U32)(unsafe.Pointer(bp))*U32(16) + U32(Xsqlite3HexToInt(tls, int32(*(*uint8)(unsafe.Pointer(zNum + uintptr(i))))))
		}
		if *(*U32)(unsafe.Pointer(bp))&0x80000000 == U32(0) && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zNum + uintptr(i)))])&0x08 == 0 {
			libc.Xmemcpy(tls, pValue, bp, uint64(4))
			return 1
		} else {
			return 0
		}
	}
	if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zNum))])&0x04 != 0) {
		return 0
	}
	for int32(*(*uint8)(unsafe.Pointer(zNum))) == '0' {
		zNum++
	}
	for i = 0; i < 11 && libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(zNum + uintptr(i))))-'0') >= 0 && c <= 9; i++ {
		v = v*int64(10) + Sqlite_int64(c)
	}

	if i > 10 {
		return 0
	}

	if v-Sqlite_int64(neg) > int64(2147483647) {
		return 0
	}
	if neg != 0 {
		v = -v
	}
	*(*int32)(unsafe.Pointer(pValue)) = int32(v)
	return 1
}

func Xsqlite3Atoi(tls *libc.TLS, z uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = 0
	Xsqlite3GetInt32(tls, z, bp)
	return *(*int32)(unsafe.Pointer(bp))
}

func Xsqlite3GetUInt32(tls *libc.TLS, z uintptr, pI uintptr) int32 {
	var v U64 = uint64(0)
	var i int32
	for i = 0; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x04 != 0; i++ {
		v = v*uint64(10) + U64(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) - uint64('0')
		if v > uint64(4294967296) {
			*(*U32)(unsafe.Pointer(pI)) = U32(0)
			return 0
		}
	}
	if i == 0 || int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) != 0 {
		*(*U32)(unsafe.Pointer(pI)) = U32(0)
		return 0
	}
	*(*U32)(unsafe.Pointer(pI)) = U32(v)
	return 1
}

func putVarint64(tls *libc.TLS, p uintptr, v U64) int32 {
	bp := tls.Alloc(10)
	defer tls.Free(10)

	var i int32
	var j int32
	var n int32

	if v&(uint64(0xff000000)<<32) != 0 {
		*(*uint8)(unsafe.Pointer(p + 8)) = U8(v)
		v >>= 8
		for i = 7; i >= 0; i-- {
			*(*uint8)(unsafe.Pointer(p + uintptr(i))) = U8(v&uint64(0x7f) | uint64(0x80))
			v >>= 7
		}
		return 9
	}
	n = 0
	for __ccgo := true; __ccgo; __ccgo = v != uint64(0) {
		*(*U8)(unsafe.Pointer(bp + uintptr(libc.PostIncInt32(&n, 1)))) = U8(v&uint64(0x7f) | uint64(0x80))
		v >>= 7
	}
	*(*U8)(unsafe.Pointer(bp)) &= U8(0x7f)

	i = 0
	j = n - 1
__1:
	if !(j >= 0) {
		goto __3
	}
	{
		*(*uint8)(unsafe.Pointer(p + uintptr(i))) = *(*U8)(unsafe.Pointer(bp + uintptr(j)))

	}
	goto __2
__2:
	j--
	i++
	goto __1
	goto __3
__3:
	;
	return n
}

func Xsqlite3PutVarint(tls *libc.TLS, p uintptr, v U64) int32 {
	if v <= uint64(0x7f) {
		*(*uint8)(unsafe.Pointer(p)) = uint8(v & uint64(0x7f))
		return 1
	}
	if v <= uint64(0x3fff) {
		*(*uint8)(unsafe.Pointer(p)) = uint8(v>>7&uint64(0x7f) | uint64(0x80))
		*(*uint8)(unsafe.Pointer(p + 1)) = uint8(v & uint64(0x7f))
		return 2
	}
	return putVarint64(tls, p, v)
}

func Xsqlite3GetVarint(tls *libc.TLS, p uintptr, v uintptr) U8 {
	var a U32
	var b U32
	var s U32

	if int32(*(*int8)(unsafe.Pointer(p))) >= 0 {
		*(*U64)(unsafe.Pointer(v)) = U64(*(*uint8)(unsafe.Pointer(p)))
		return U8(1)
	}
	if int32(*(*int8)(unsafe.Pointer(p + 1))) >= 0 {
		*(*U64)(unsafe.Pointer(v)) = U64(U32(int32(*(*uint8)(unsafe.Pointer(p)))&0x7f)<<7 | U32(*(*uint8)(unsafe.Pointer(p + 1))))
		return U8(2)
	}

	a = U32(*(*uint8)(unsafe.Pointer(p))) << 14
	b = U32(*(*uint8)(unsafe.Pointer(p + 1)))
	p += uintptr(2)
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		a = a & U32(SLOT_2_0)
		b = b & U32(0x7f)
		b = b << 7
		a = a | b
		*(*U64)(unsafe.Pointer(v)) = U64(a)
		return U8(3)
	}

	a = a & U32(SLOT_2_0)
	p++
	b = b << 14
	b = b | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		b = b & U32(SLOT_2_0)

		a = a << 7
		a = a | b
		*(*U64)(unsafe.Pointer(v)) = U64(a)
		return U8(4)
	}

	b = b & U32(SLOT_2_0)
	s = a

	p++
	a = a << 14
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		b = b << 7
		a = a | b
		s = s >> 18
		*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)
		return U8(5)
	}

	s = s << 7
	s = s | b

	p++
	b = b << 14
	b = b | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		a = a & U32(SLOT_2_0)
		a = a << 7
		a = a | b
		s = s >> 18
		*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)
		return U8(6)
	}

	p++
	a = a << 14
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		a = a & SLOT_4_2_0
		b = b & U32(SLOT_2_0)
		b = b << 7
		a = a | b
		s = s >> 11
		*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)
		return U8(7)
	}

	a = a & U32(SLOT_2_0)
	p++
	b = b << 14
	b = b | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		b = b & SLOT_4_2_0

		a = a << 7
		a = a | b
		s = s >> 4
		*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)
		return U8(8)
	}

	p++
	a = a << 15
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	b = b & U32(SLOT_2_0)
	b = b << 8
	a = a | b

	s = s << 4
	b = U32(*(*uint8)(unsafe.Pointer(p + libc.UintptrFromInt32(-4))))
	b = b & U32(0x7f)
	b = b >> 3
	s = s | b

	*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)

	return U8(9)
}

func Xsqlite3GetVarint32(tls *libc.TLS, p uintptr, v uintptr) U8 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var a U32
	var b U32

	a = U32(*(*uint8)(unsafe.Pointer(p)))

	p++
	b = U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		a = a & U32(0x7f)
		a = a << 7
		*(*U32)(unsafe.Pointer(v)) = a | b
		return U8(2)
	}

	p++
	a = a << 14
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		a = a & U32(int32(0x7f)<<14|0x7f)
		b = b & U32(0x7f)
		b = b << 7
		*(*U32)(unsafe.Pointer(v)) = a | b
		return U8(3)
	}

	{
		var n U8

		n = Xsqlite3GetVarint(tls, p-uintptr(2), bp)

		if *(*U64)(unsafe.Pointer(bp))&(uint64(1)<<32-uint64(1)) != *(*U64)(unsafe.Pointer(bp)) {
			*(*U32)(unsafe.Pointer(v)) = 0xffffffff
		} else {
			*(*U32)(unsafe.Pointer(v)) = U32(*(*U64)(unsafe.Pointer(bp)))
		}
		return n

	}
	return U8(0)

}

func Xsqlite3VarintLen(tls *libc.TLS, v U64) int32 {
	var i int32
	for i = 1; libc.AssignShrUint64(&v, int(uint64(7))) != uint64(0); i++ {
	}
	return i
}

func Xsqlite3Get4byte(tls *libc.TLS, p uintptr) U32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	libc.Xmemcpy(tls, bp, p, uint64(4))
	return libc.X__builtin_bswap32(tls, *(*U32)(unsafe.Pointer(bp)))
}

func Xsqlite3Put4byte(tls *libc.TLS, p uintptr, v U32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*U32)(unsafe.Pointer(bp)) = libc.X__builtin_bswap32(tls, v)
	libc.Xmemcpy(tls, p, bp, uint64(4))
}

func Xsqlite3HexToInt(tls *libc.TLS, h int32) U8 {
	h = h + 9*(1&(h>>6))
	return U8(h & 0xf)
}

func Xsqlite3HexToBlob(tls *libc.TLS, db uintptr, z uintptr, n int32) uintptr {
	var zBlob uintptr
	var i int32

	zBlob = Xsqlite3DbMallocRawNN(tls, db, uint64(n/2+1))
	n--
	if zBlob != 0 {
		for i = 0; i < n; i = i + 2 {
			*(*uint8)(unsafe.Pointer(zBlob + uintptr(i/2))) = uint8(int32(Xsqlite3HexToInt(tls, int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))))<<4 | int32(Xsqlite3HexToInt(tls, int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+1)))))))
		}
		*(*uint8)(unsafe.Pointer(zBlob + uintptr(i/2))) = uint8(0)
	}
	return zBlob
}

func logBadConnection(tls *libc.TLS, zType uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	Xsqlite3_log(tls, SQLITE_MISUSE,
		ts+1706,
		libc.VaList(bp, zType))
}

func Xsqlite3SafetyCheckOk(tls *libc.TLS, db uintptr) int32 {
	var eOpenState U8
	if db == uintptr(0) {
		logBadConnection(tls, ts+1637)
		return 0
	}
	eOpenState = (*Sqlite3)(unsafe.Pointer(db)).FeOpenState
	if int32(eOpenState) != SQLITE_STATE_OPEN {
		if Xsqlite3SafetyCheckSickOrOk(tls, db) != 0 {
			logBadConnection(tls, ts+1751)
		}
		return 0
	} else {
		return 1
	}
	return int32(0)
}

func Xsqlite3SafetyCheckSickOrOk(tls *libc.TLS, db uintptr) int32 {
	var eOpenState U8
	eOpenState = (*Sqlite3)(unsafe.Pointer(db)).FeOpenState
	if int32(eOpenState) != SQLITE_STATE_SICK && int32(eOpenState) != SQLITE_STATE_OPEN && int32(eOpenState) != SQLITE_STATE_BUSY {
		logBadConnection(tls, ts+1760)
		return 0
	} else {
		return 1
	}
	return int32(0)
}

func Xsqlite3AddInt64(tls *libc.TLS, pA uintptr, iB I64) int32 {
	return libc.X__builtin_add_overflowInt64(tls, *(*I64)(unsafe.Pointer(pA)), iB, pA)
}

func Xsqlite3SubInt64(tls *libc.TLS, pA uintptr, iB I64) int32 {
	return libc.X__builtin_sub_overflowInt64(tls, *(*I64)(unsafe.Pointer(pA)), iB, pA)
}

func Xsqlite3MulInt64(tls *libc.TLS, pA uintptr, iB I64) int32 {
	return libc.X__builtin_mul_overflowInt64(tls, *(*I64)(unsafe.Pointer(pA)), iB, pA)
}

func Xsqlite3AbsInt32(tls *libc.TLS, x int32) int32 {
	if x >= 0 {
		return x
	}
	if x == libc.Int32FromUint32(0x80000000) {
		return 0x7fffffff
	}
	return -x
}

func Xsqlite3LogEstAdd(tls *libc.TLS, a LogEst, b LogEst) LogEst {
	if int32(a) >= int32(b) {
		if int32(a) > int32(b)+49 {
			return a
		}
		if int32(a) > int32(b)+31 {
			return LogEst(int32(a) + 1)
		}
		return LogEst(int32(a) + int32(x[int32(a)-int32(b)]))
	} else {
		if int32(b) > int32(a)+49 {
			return b
		}
		if int32(b) > int32(a)+31 {
			return LogEst(int32(b) + 1)
		}
		return LogEst(int32(b) + int32(x[int32(b)-int32(a)]))
	}
	return LogEst(0)
}

var x = [32]uint8{
	uint8(10), uint8(10),
	uint8(9), uint8(9),
	uint8(8), uint8(8),
	uint8(7), uint8(7), uint8(7),
	uint8(6), uint8(6), uint8(6),
	uint8(5), uint8(5), uint8(5),
	uint8(4), uint8(4), uint8(4), uint8(4),
	uint8(3), uint8(3), uint8(3), uint8(3), uint8(3), uint8(3),
	uint8(2), uint8(2), uint8(2), uint8(2), uint8(2), uint8(2), uint8(2),
}

func Xsqlite3LogEst(tls *libc.TLS, x U64) LogEst {
	var y LogEst = int16(40)
	if x < uint64(8) {
		if x < uint64(2) {
			return int16(0)
		}
		for x < uint64(8) {
			y = int16(int32(y) - 10)
			x <<= 1
		}
	} else {
		var i int32 = 60 - libc.X__builtin_clzll(tls, x)
		y = LogEst(int32(y) + i*10)
		x >>= i
	}
	return LogEst(int32(a[x&uint64(7)]) + int32(y) - 10)
}

var a = [8]LogEst{int16(0), int16(2), int16(3), int16(5), int16(6), int16(7), int16(8), int16(9)}

func Xsqlite3LogEstFromDouble(tls *libc.TLS, x float64) LogEst {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp + 8)) = x

	var e LogEst

	if *(*float64)(unsafe.Pointer(bp + 8)) <= float64(1) {
		return int16(0)
	}
	if *(*float64)(unsafe.Pointer(bp + 8)) <= float64(2000000000) {
		return Xsqlite3LogEst(tls, U64(*(*float64)(unsafe.Pointer(bp + 8))))
	}
	libc.Xmemcpy(tls, bp, bp+8, uint64(8))
	e = LogEst(*(*U64)(unsafe.Pointer(bp))>>52 - uint64(1022))
	return LogEst(int32(e) * 10)
}

func Xsqlite3LogEstToInt(tls *libc.TLS, x LogEst) U64 {
	var n U64
	n = U64(int32(x) % 10)
	x = int16(int32(x) / 10)
	if n >= uint64(5) {
		n = n - uint64(2)
	} else if n >= uint64(1) {
		n = n - uint64(1)
	}
	if int32(x) > 60 {
		return uint64(int64(0xffffffff) | int64(0x7fffffff)<<32)
	}
	if int32(x) >= 3 {
		return (n + uint64(8)) << (int32(x) - 3)
	}
	return (n + uint64(8)) >> (3 - int32(x))
}

func Xsqlite3VListAdd(tls *libc.TLS, db uintptr, pIn uintptr, zName uintptr, nName int32, iVal int32) uintptr {
	var nInt int32
	var z uintptr
	var i int32

	nInt = nName/4 + 3

	if pIn == uintptr(0) || *(*VList)(unsafe.Pointer(pIn + 1*4))+nInt > *(*VList)(unsafe.Pointer(pIn)) {
		var nAlloc Sqlite3_int64 = func() int64 {
			if pIn != 0 {
				return int64(2) * Sqlite3_int64(*(*VList)(unsafe.Pointer(pIn)))
			}
			return int64(10)
		}() + Sqlite3_int64(nInt)
		var pOut uintptr = Xsqlite3DbRealloc(tls, db, pIn, uint64(nAlloc)*uint64(unsafe.Sizeof(int32(0))))
		if pOut == uintptr(0) {
			return pIn
		}
		if pIn == uintptr(0) {
			*(*VList)(unsafe.Pointer(pOut + 1*4)) = 2
		}
		pIn = pOut
		*(*VList)(unsafe.Pointer(pIn)) = VList(nAlloc)
	}
	i = *(*VList)(unsafe.Pointer(pIn + 1*4))
	*(*VList)(unsafe.Pointer(pIn + uintptr(i)*4)) = iVal
	*(*VList)(unsafe.Pointer(pIn + uintptr(i+1)*4)) = nInt
	z = pIn + uintptr(i+2)*4
	*(*VList)(unsafe.Pointer(pIn + 1*4)) = i + nInt

	libc.Xmemcpy(tls, z, zName, uint64(nName))
	*(*uint8)(unsafe.Pointer(z + uintptr(nName))) = uint8(0)
	return pIn
}

func Xsqlite3VListNumToName(tls *libc.TLS, pIn uintptr, iVal int32) uintptr {
	var i int32
	var mx int32
	if pIn == uintptr(0) {
		return uintptr(0)
	}
	mx = *(*VList)(unsafe.Pointer(pIn + 1*4))
	i = 2
	for __ccgo := true; __ccgo; __ccgo = i < mx {
		if *(*VList)(unsafe.Pointer(pIn + uintptr(i)*4)) == iVal {
			return pIn + uintptr(i+2)*4
		}
		i = i + *(*VList)(unsafe.Pointer(pIn + uintptr(i+1)*4))
	}
	return uintptr(0)
}

func Xsqlite3VListNameToNum(tls *libc.TLS, pIn uintptr, zName uintptr, nName int32) int32 {
	var i int32
	var mx int32
	if pIn == uintptr(0) {
		return 0
	}
	mx = *(*VList)(unsafe.Pointer(pIn + 1*4))
	i = 2
	for __ccgo := true; __ccgo; __ccgo = i < mx {
		var z uintptr = pIn + uintptr(i+2)*4
		if libc.Xstrncmp(tls, z, zName, uint64(nName)) == 0 && int32(*(*uint8)(unsafe.Pointer(z + uintptr(nName)))) == 0 {
			return *(*VList)(unsafe.Pointer(pIn + uintptr(i)*4))
		}
		i = i + *(*VList)(unsafe.Pointer(pIn + uintptr(i+1)*4))
	}
	return 0
}

func Xsqlite3HashInit(tls *libc.TLS, pNew uintptr) {
	(*Hash)(unsafe.Pointer(pNew)).Ffirst = uintptr(0)
	(*Hash)(unsafe.Pointer(pNew)).Fcount = uint32(0)
	(*Hash)(unsafe.Pointer(pNew)).Fhtsize = uint32(0)
	(*Hash)(unsafe.Pointer(pNew)).Fht = uintptr(0)
}

func Xsqlite3HashClear(tls *libc.TLS, pH uintptr) {
	var elem uintptr

	elem = (*Hash)(unsafe.Pointer(pH)).Ffirst
	(*Hash)(unsafe.Pointer(pH)).Ffirst = uintptr(0)
	Xsqlite3_free(tls, (*Hash)(unsafe.Pointer(pH)).Fht)
	(*Hash)(unsafe.Pointer(pH)).Fht = uintptr(0)
	(*Hash)(unsafe.Pointer(pH)).Fhtsize = uint32(0)
	for elem != 0 {
		var next_elem uintptr = (*HashElem)(unsafe.Pointer(elem)).Fnext
		Xsqlite3_free(tls, elem)
		elem = next_elem
	}
	(*Hash)(unsafe.Pointer(pH)).Fcount = uint32(0)
}

func strHash(tls *libc.TLS, z uintptr) uint32 {
	var h uint32 = uint32(0)
	var c uint8
	for int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))))) != 0 {
		h = h + uint32(Xsqlite3UpperToLower[c])
		h = h * 0x9e3779b1
	}
	return h
}

func insertElement(tls *libc.TLS, pH uintptr, pEntry uintptr, pNew uintptr) {
	var pHead uintptr
	if pEntry != 0 {
		if (*_ht)(unsafe.Pointer(pEntry)).Fcount != 0 {
			pHead = (*_ht)(unsafe.Pointer(pEntry)).Fchain
		} else {
			pHead = uintptr(0)
		}
		(*_ht)(unsafe.Pointer(pEntry)).Fcount++
		(*_ht)(unsafe.Pointer(pEntry)).Fchain = pNew
	} else {
		pHead = uintptr(0)
	}
	if pHead != 0 {
		(*HashElem)(unsafe.Pointer(pNew)).Fnext = pHead
		(*HashElem)(unsafe.Pointer(pNew)).Fprev = (*HashElem)(unsafe.Pointer(pHead)).Fprev
		if (*HashElem)(unsafe.Pointer(pHead)).Fprev != 0 {
			(*HashElem)(unsafe.Pointer((*HashElem)(unsafe.Pointer(pHead)).Fprev)).Fnext = pNew
		} else {
			(*Hash)(unsafe.Pointer(pH)).Ffirst = pNew
		}
		(*HashElem)(unsafe.Pointer(pHead)).Fprev = pNew
	} else {
		(*HashElem)(unsafe.Pointer(pNew)).Fnext = (*Hash)(unsafe.Pointer(pH)).Ffirst
		if (*Hash)(unsafe.Pointer(pH)).Ffirst != 0 {
			(*HashElem)(unsafe.Pointer((*Hash)(unsafe.Pointer(pH)).Ffirst)).Fprev = pNew
		}
		(*HashElem)(unsafe.Pointer(pNew)).Fprev = uintptr(0)
		(*Hash)(unsafe.Pointer(pH)).Ffirst = pNew
	}
}

func rehash(tls *libc.TLS, pH uintptr, new_size uint32) int32 {
	var new_ht uintptr
	var elem uintptr
	var next_elem uintptr

	if uint64(new_size)*uint64(unsafe.Sizeof(_ht{})) > uint64(SQLITE_MALLOC_SOFT_LIMIT) {
		new_size = uint32(uint64(SQLITE_MALLOC_SOFT_LIMIT) / uint64(unsafe.Sizeof(_ht{})))
	}
	if new_size == (*Hash)(unsafe.Pointer(pH)).Fhtsize {
		return 0
	}

	Xsqlite3BeginBenignMalloc(tls)
	new_ht = Xsqlite3Malloc(tls, uint64(new_size)*uint64(unsafe.Sizeof(_ht{})))
	Xsqlite3EndBenignMalloc(tls)

	if new_ht == uintptr(0) {
		return 0
	}
	Xsqlite3_free(tls, (*Hash)(unsafe.Pointer(pH)).Fht)
	(*Hash)(unsafe.Pointer(pH)).Fht = new_ht
	(*Hash)(unsafe.Pointer(pH)).Fhtsize = libc.AssignUint32(&new_size, uint32(uint64(Xsqlite3MallocSize(tls, new_ht))/uint64(unsafe.Sizeof(_ht{}))))
	libc.Xmemset(tls, new_ht, 0, uint64(new_size)*uint64(unsafe.Sizeof(_ht{})))
	elem = (*Hash)(unsafe.Pointer(pH)).Ffirst
	(*Hash)(unsafe.Pointer(pH)).Ffirst = uintptr(0)
	for ; elem != 0; elem = next_elem {
		var h uint32 = strHash(tls, (*HashElem)(unsafe.Pointer(elem)).FpKey) % new_size
		next_elem = (*HashElem)(unsafe.Pointer(elem)).Fnext
		insertElement(tls, pH, new_ht+uintptr(h)*16, elem)
	}
	return 1
}

func findElementWithHash(tls *libc.TLS, pH uintptr, pKey uintptr, pHash uintptr) uintptr {
	var elem uintptr
	var count uint32
	var h uint32

	if (*Hash)(unsafe.Pointer(pH)).Fht != 0 {
		var pEntry uintptr
		h = strHash(tls, pKey) % (*Hash)(unsafe.Pointer(pH)).Fhtsize
		pEntry = (*Hash)(unsafe.Pointer(pH)).Fht + uintptr(h)*16
		elem = (*_ht)(unsafe.Pointer(pEntry)).Fchain
		count = (*_ht)(unsafe.Pointer(pEntry)).Fcount
	} else {
		h = uint32(0)
		elem = (*Hash)(unsafe.Pointer(pH)).Ffirst
		count = (*Hash)(unsafe.Pointer(pH)).Fcount
	}
	if pHash != 0 {
		*(*uint32)(unsafe.Pointer(pHash)) = h
	}
	for count != 0 {
		if Xsqlite3StrICmp(tls, (*HashElem)(unsafe.Pointer(elem)).FpKey, pKey) == 0 {
			return elem
		}
		elem = (*HashElem)(unsafe.Pointer(elem)).Fnext
		count--
	}
	return uintptr(unsafe.Pointer(&nullElement))
}

var nullElement = HashElem{}

func removeElementGivenHash(tls *libc.TLS, pH uintptr, elem uintptr, h uint32) {
	var pEntry uintptr
	if (*HashElem)(unsafe.Pointer(elem)).Fprev != 0 {
		(*HashElem)(unsafe.Pointer((*HashElem)(unsafe.Pointer(elem)).Fprev)).Fnext = (*HashElem)(unsafe.Pointer(elem)).Fnext
	} else {
		(*Hash)(unsafe.Pointer(pH)).Ffirst = (*HashElem)(unsafe.Pointer(elem)).Fnext
	}
	if (*HashElem)(unsafe.Pointer(elem)).Fnext != 0 {
		(*HashElem)(unsafe.Pointer((*HashElem)(unsafe.Pointer(elem)).Fnext)).Fprev = (*HashElem)(unsafe.Pointer(elem)).Fprev
	}
	if (*Hash)(unsafe.Pointer(pH)).Fht != 0 {
		pEntry = (*Hash)(unsafe.Pointer(pH)).Fht + uintptr(h)*16
		if (*_ht)(unsafe.Pointer(pEntry)).Fchain == elem {
			(*_ht)(unsafe.Pointer(pEntry)).Fchain = (*HashElem)(unsafe.Pointer(elem)).Fnext
		}

		(*_ht)(unsafe.Pointer(pEntry)).Fcount--
	}
	Xsqlite3_free(tls, elem)
	(*Hash)(unsafe.Pointer(pH)).Fcount--
	if (*Hash)(unsafe.Pointer(pH)).Fcount == uint32(0) {
		Xsqlite3HashClear(tls, pH)
	}
}

func Xsqlite3HashFind(tls *libc.TLS, pH uintptr, pKey uintptr) uintptr {
	return (*HashElem)(unsafe.Pointer(findElementWithHash(tls, pH, pKey, uintptr(0)))).Fdata
}

func Xsqlite3HashInsert(tls *libc.TLS, pH uintptr, pKey uintptr, data uintptr) uintptr {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var elem uintptr
	var new_elem uintptr

	elem = findElementWithHash(tls, pH, pKey, bp)
	if (*HashElem)(unsafe.Pointer(elem)).Fdata != 0 {
		var old_data uintptr = (*HashElem)(unsafe.Pointer(elem)).Fdata
		if data == uintptr(0) {
			removeElementGivenHash(tls, pH, elem, *(*uint32)(unsafe.Pointer(bp)))
		} else {
			(*HashElem)(unsafe.Pointer(elem)).Fdata = data
			(*HashElem)(unsafe.Pointer(elem)).FpKey = pKey
		}
		return old_data
	}
	if data == uintptr(0) {
		return uintptr(0)
	}
	new_elem = Xsqlite3Malloc(tls, uint64(unsafe.Sizeof(HashElem{})))
	if new_elem == uintptr(0) {
		return data
	}
	(*HashElem)(unsafe.Pointer(new_elem)).FpKey = pKey
	(*HashElem)(unsafe.Pointer(new_elem)).Fdata = data
	(*Hash)(unsafe.Pointer(pH)).Fcount++
	if (*Hash)(unsafe.Pointer(pH)).Fcount >= uint32(10) && (*Hash)(unsafe.Pointer(pH)).Fcount > uint32(2)*(*Hash)(unsafe.Pointer(pH)).Fhtsize {
		if rehash(tls, pH, (*Hash)(unsafe.Pointer(pH)).Fcount*uint32(2)) != 0 {
			*(*uint32)(unsafe.Pointer(bp)) = strHash(tls, pKey) % (*Hash)(unsafe.Pointer(pH)).Fhtsize
		}
	}
	insertElement(tls, pH, func() uintptr {
		if (*Hash)(unsafe.Pointer(pH)).Fht != 0 {
			return (*Hash)(unsafe.Pointer(pH)).Fht + uintptr(*(*uint32)(unsafe.Pointer(bp)))*16
		}
		return uintptr(0)
	}(), new_elem)
	return uintptr(0)
}

func Xsqlite3OpcodeName(tls *libc.TLS, i int32) uintptr {
	return azName[i]
}

var azName = [187]uintptr{
	ts + 1768,
	ts + 1779,
	ts + 1791,
	ts + 1804,
	ts + 1816,
	ts + 1829,
	ts + 1837,
	ts + 1868,
	ts + 1890,
	ts + 1907,
	ts + 1913,
	ts + 1920,
	ts + 1935,
	ts + 1942,
	ts + 1953,
	ts + 1959,
	ts + 1965,
	ts + 1969,
	ts + 1976,
	ts + 2014,
	ts + 2032,
	ts + 2081,
	ts + 2101,
	ts + 2121,
	ts + 2141,
	ts + 2161,
	ts + 2194,
	ts + 2216,
	ts + 2240,
	ts + 2262,
	ts + 2281,
	ts + 2304,
	ts + 2327,
	ts + 2333,
	ts + 2344,
	ts + 2356,
	ts + 2362,
	ts + 2370,
	ts + 2382,
	ts + 2388,
	ts + 2394,
	ts + 2413,
	ts + 2432,
	ts + 2451,
	ts + 2477,
	ts + 2504,
	ts + 2523,
	ts + 2551,
	ts + 2593,
	ts + 2602,
	ts + 2635,
	ts + 2665,
	ts + 2696,
	ts + 2715,
	ts + 2734,
	ts + 2752,
	ts + 2771,
	ts + 2789,
	ts + 2808,
	ts + 2816,
	ts + 2857,
	ts + 2901,
	ts + 2938,
	ts + 2950,
	ts + 2957,
	ts + 3004,
	ts + 3034,
	ts + 3064,
	ts + 3072,
	ts + 3086,
	ts + 3116,
	ts + 3122,
	ts + 3139,
	ts + 3154,
	ts + 3181,
	ts + 3204,
	ts + 3224,
	ts + 3244,
	ts + 3267,
	ts + 3299,
	ts + 3322,
	ts + 3349,
	ts + 3367,
	ts + 3387,
	ts + 3396,
	ts + 3422,
	ts + 3431,
	ts + 3453,
	ts + 3467,
	ts + 3488,
	ts + 3501,
	ts + 3531,
	ts + 3576,
	ts + 3605,
	ts + 3638,
	ts + 3674,
	ts + 3704,
	ts + 3732,
	ts + 3765,
	ts + 3785,
	ts + 3797,
	ts + 3808,
	ts + 3833,
	ts + 3858,
	ts + 3882,
	ts + 3911,
	ts + 3941,
	ts + 3963,
	ts + 3990,
	ts + 4017,
	ts + 4042,
	ts + 4070,
	ts + 4095,
	ts + 4119,
	ts + 4144,
	ts + 4165,
	ts + 4174,
	ts + 4199,
	ts + 4218,
	ts + 4243,
	ts + 4255,
	ts + 4299,
	ts + 4330,
	ts + 4337,
	ts + 4350,
	ts + 4384,
	ts + 4412,
	ts + 4444,
	ts + 4465,
	ts + 4496,
	ts + 4505,
	ts + 4513,
	ts + 4525,
	ts + 4574,
	ts + 4596,
	ts + 4615,
	ts + 4642,
	ts + 4651,
	ts + 4660,
	ts + 4680,
	ts + 4703,
	ts + 4726,
	ts + 4769,
	ts + 4790,
	ts + 4802,
	ts + 4811,
	ts + 4818,
	ts + 4831,
	ts + 4870,
	ts + 4879,
	ts + 4892,
	ts + 4906,
	ts + 4917,
	ts + 4928,
	ts + 4942,
	ts + 4955,
	ts + 4968,
	ts + 4995,
	ts + 5002,
	ts + 5026,
	ts + 5056,
	ts + 5125,
	ts + 5166,
	ts + 5201,
	ts + 5237,
	ts + 5263,
	ts + 5289,
	ts + 5297,
	ts + 5309,
	ts + 5323,
	ts + 5357,
	ts + 5365,
	ts + 5374,
	ts + 5384,
	ts + 5391,
	ts + 5422,
	ts + 5448,
	ts + 5457,
	ts + 5468,
	ts + 5478,
	ts + 5507,
	ts + 5542,
	ts + 5549,
	ts + 5561,
	ts + 5597,
	ts + 5603,
	ts + 5612,
}

type stat = struct {
	Fst_dev     X__dev_t
	Fst_ino     X__ino64_t
	Fst_mode    X__mode_t
	Fst_nlink   X__nlink_t
	Fst_uid     X__uid_t
	Fst_gid     X__gid_t
	Fst_rdev    X__dev_t
	F__pad1     X__dev_t
	Fst_size    X__off64_t
	Fst_blksize X__blksize_t
	F__pad2     int32
	Fst_blocks  X__blkcnt64_t
	Fst_atim    struct {
		Ftv_sec  X__time_t
		Ftv_nsec X__syscall_slong_t
	}
	Fst_mtim struct {
		Ftv_sec  X__time_t
		Ftv_nsec X__syscall_slong_t
	}
	Fst_ctim struct {
		Ftv_sec  X__time_t
		Ftv_nsec X__syscall_slong_t
	}
	F__glibc_reserved [2]int32
}

type stat64 = struct {
	Fst_dev     X__dev_t
	Fst_ino     X__ino64_t
	Fst_mode    X__mode_t
	Fst_nlink   X__nlink_t
	Fst_uid     X__uid_t
	Fst_gid     X__gid_t
	Fst_rdev    X__dev_t
	F__pad1     X__dev_t
	Fst_size    X__off64_t
	Fst_blksize X__blksize_t
	F__pad2     int32
	Fst_blocks  X__blkcnt64_t
	Fst_atim    struct {
		Ftv_sec  X__time_t
		Ftv_nsec X__syscall_slong_t
	}
	Fst_mtim struct {
		Ftv_sec  X__time_t
		Ftv_nsec X__syscall_slong_t
	}
	Fst_ctim struct {
		Ftv_sec  X__time_t
		Ftv_nsec X__syscall_slong_t
	}
	F__glibc_reserved [2]int32
}

type X__s8 = int8
type X__u8 = uint8

type X__s16 = int16
type X__u16 = uint16

type X__s32 = int32
type X__u32 = uint32

type X__s64 = int64
type X__u64 = uint64

type X__kernel_fd_set = struct{ Ffds_bits [16]uint64 }

type X__kernel_sighandler_t = uintptr

type X__kernel_key_t = int32
type X__kernel_mqd_t = int32

type X__kernel_old_uid_t = uint16
type X__kernel_old_gid_t = uint16

type X__kernel_long_t = int64
type X__kernel_ulong_t = uint64

type X__kernel_ino_t = X__kernel_ulong_t

type X__kernel_mode_t = uint32

type X__kernel_pid_t = int32

type X__kernel_ipc_pid_t = int32

type X__kernel_uid_t = uint32
type X__kernel_gid_t = uint32

type X__kernel_suseconds_t = X__kernel_long_t

type X__kernel_daddr_t = int32

type X__kernel_uid32_t = uint32
type X__kernel_gid32_t = uint32

type X__kernel_old_dev_t = uint32

type X__kernel_size_t = X__kernel_ulong_t
type X__kernel_ssize_t = X__kernel_long_t
type X__kernel_ptrdiff_t = X__kernel_long_t

type X__kernel_fsid_t = struct{ Fval [2]int32 }

type X__kernel_off_t = X__kernel_long_t
type X__kernel_loff_t = int64
type X__kernel_old_time_t = X__kernel_long_t
type X__kernel_time_t = X__kernel_long_t
type X__kernel_time64_t = int64
type X__kernel_clock_t = X__kernel_long_t
type X__kernel_timer_t = int32
type X__kernel_clockid_t = int32
type X__kernel_caddr_t = uintptr
type X__kernel_uid16_t = uint16
type X__kernel_gid16_t = uint16

type X__le16 = X__u16
type X__be16 = X__u16
type X__le32 = X__u32
type X__be32 = X__u32
type X__le64 = X__u64
type X__be64 = X__u64

type X__sum16 = X__u16
type X__wsum = X__u32

type X__poll_t = uint32

type statx_timestamp = struct {
	Ftv_sec     X__s64
	Ftv_nsec    X__u32
	F__reserved X__s32
}

type statx = struct {
	Fstx_mask            X__u32
	Fstx_blksize         X__u32
	Fstx_attributes      X__u64
	Fstx_nlink           X__u32
	Fstx_uid             X__u32
	Fstx_gid             X__u32
	Fstx_mode            X__u16
	F__spare0            [1]X__u16
	Fstx_ino             X__u64
	Fstx_size            X__u64
	Fstx_blocks          X__u64
	Fstx_attributes_mask X__u64
	Fstx_atime           struct {
		Ftv_sec     X__s64
		Ftv_nsec    X__u32
		F__reserved X__s32
	}
	Fstx_btime struct {
		Ftv_sec     X__s64
		Ftv_nsec    X__u32
		F__reserved X__s32
	}
	Fstx_ctime struct {
		Ftv_sec     X__s64
		Ftv_nsec    X__u32
		F__reserved X__s32
	}
	Fstx_mtime struct {
		Ftv_sec     X__s64
		Ftv_nsec    X__u32
		F__reserved X__s32
	}
	Fstx_rdev_major X__u32
	Fstx_rdev_minor X__u32
	Fstx_dev_major  X__u32
	Fstx_dev_minor  X__u32
	Fstx_mnt_id     X__u64
	F__spare2       X__u64
	F__spare3       [12]X__u64
}

type flock = struct {
	Fl_type      int16
	Fl_whence    int16
	F__ccgo_pad1 [4]byte
	Fl_start     X__off_t
	Fl_len       X__off_t
	Fl_pid       X__pid_t
	F__ccgo_pad2 [4]byte
}

type flock64 = struct {
	Fl_type      int16
	Fl_whence    int16
	F__ccgo_pad1 [4]byte
	Fl_start     X__off64_t
	Fl_len       X__off64_t
	Fl_pid       X__pid_t
	F__ccgo_pad2 [4]byte
}

type iovec = struct {
	Fiov_base uintptr
	Fiov_len  Size_t
}

type f_owner_ex = struct {
	Ftype uint32
	Fpid  X__pid_t
}

type file_handle = struct {
	F__ccgo_pad1  [0]uint32
	Fhandle_bytes uint32
	Fhandle_type  int32
}

type winsize = struct {
	Fws_row    uint16
	Fws_col    uint16
	Fws_xpixel uint16
	Fws_ypixel uint16
}

type termio = struct {
	Fc_iflag     uint16
	Fc_oflag     uint16
	Fc_cflag     uint16
	Fc_lflag     uint16
	Fc_line      uint8
	Fc_cc        [8]uint8
	F__ccgo_pad1 [1]byte
}

type Intptr_t = X__intptr_t

type Socklen_t = X__socklen_t

type timezone = struct {
	Ftz_minuteswest int32
	Ftz_dsttime     int32
}

type itimerval = struct {
	Fit_interval struct {
		Ftv_sec  X__time_t
		Ftv_usec X__suseconds_t
	}
	Fit_value struct {
		Ftv_sec  X__time_t
		Ftv_usec X__suseconds_t
	}
}

type X__itimer_which_t = uint32

type Error_t = int32

type unixShm = struct {
	FpShmNode    uintptr
	FpNext       uintptr
	FhasMutex    U8
	Fid          U8
	FsharedMask  U16
	FexclMask    U16
	F__ccgo_pad1 [2]byte
}

type UnixShm = unixShm
type unixShmNode = struct {
	FpInode      uintptr
	FpShmMutex   uintptr
	FzFilename   uintptr
	FhShm        int32
	FszRegion    int32
	FnRegion     U16
	FisReadonly  U8
	FisUnlocked  U8
	F__ccgo_pad1 [4]byte
	FapRegion    uintptr
	FnRef        int32
	F__ccgo_pad2 [4]byte
	FpFirst      uintptr
	FaLock       [8]int32
}

type UnixShmNode = unixShmNode
type unixInodeInfo = struct {
	FfileId struct {
		Fdev Dev_t
		Fino U64
	}
	FpLockMutex   uintptr
	FnShared      int32
	FnLock        int32
	FeFileLock    uint8
	FbProcessLock uint8
	F__ccgo_pad1  [6]byte
	FpUnused      uintptr
	FnRef         int32
	F__ccgo_pad2  [4]byte
	FpShmNode     uintptr
	FpNext        uintptr
	FpPrev        uintptr
}

type UnixInodeInfo = unixInodeInfo
type UnixUnusedFd1 = struct {
	Ffd    int32
	Fflags int32
	FpNext uintptr
}

type UnixUnusedFd = UnixUnusedFd1

type unixFile = struct {
	FpMethod               uintptr
	FpVfs                  uintptr
	FpInode                uintptr
	Fh                     int32
	FeFileLock             uint8
	F__ccgo_pad1           [1]byte
	FctrlFlags             uint16
	FlastErrno             int32
	F__ccgo_pad2           [4]byte
	FlockingContext        uintptr
	FpPreallocatedUnused   uintptr
	FzPath                 uintptr
	FpShm                  uintptr
	FszChunk               int32
	FnFetchOut             int32
	FmmapSize              Sqlite3_int64
	FmmapSizeActual        Sqlite3_int64
	FmmapSizeMax           Sqlite3_int64
	FpMapRegion            uintptr
	FsectorSize            int32
	FdeviceCharacteristics int32
	FaPadding              [32]uint8
}

type UnixFile = unixFile

var randomnessPid Pid_t = 0

func posixOpen(tls *libc.TLS, zFile uintptr, flags int32, mode int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	return libc.Xopen(tls, zFile, flags, libc.VaList(bp, mode))
}

type unix_syscall = struct {
	FzName    uintptr
	FpCurrent Sqlite3_syscall_ptr
	FpDefault Sqlite3_syscall_ptr
}

var aSyscall = [29]unix_syscall{
	{FzName: ts + 5623, FpCurrent: 0},
	{FzName: ts + 5628, FpCurrent: 0},
	{FzName: ts + 5634, FpCurrent: 0},
	{FzName: ts + 5641, FpCurrent: 0},
	{FzName: ts + 5648, FpCurrent: 0},
	{FzName: ts + 5653, FpCurrent: 0},
	{FzName: ts + 5659, FpCurrent: 0},
	{FzName: ts + 5669, FpCurrent: 0},
	{FzName: ts + 5675, FpCurrent: 0},
	{FzName: ts + 5680},
	{FzName: ts + 5686},
	{FzName: ts + 5694, FpCurrent: 0},
	{FzName: ts + 5700},
	{FzName: ts + 5707},
	{FzName: ts + 5716, FpCurrent: 0},
	{FzName: ts + 5723},
	{FzName: ts + 5733, FpCurrent: 0},
	{FzName: ts + 5740, FpCurrent: 0},
	{FzName: ts + 5754, FpCurrent: 0},
	{FzName: ts + 5760, FpCurrent: 0},
	{FzName: ts + 5766, FpCurrent: 0},
	{FzName: ts + 5773, FpCurrent: 0},
	{FzName: ts + 5781, FpCurrent: 0},
	{FzName: ts + 5786, FpCurrent: 0},
	{FzName: ts + 5793, FpCurrent: 0},
	{FzName: ts + 5800, FpCurrent: 0},
	{FzName: ts + 5812, FpCurrent: 0},
	{FzName: ts + 5821, FpCurrent: 0},
	{FzName: ts + 5827},
}

func robustFchown(tls *libc.TLS, fd int32, uid Uid_t, gid Gid_t) int32 {
	if (*(*func(*libc.TLS) Uid_t)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 21*24 + 8)))(tls) != 0 {
		return 0
	}
	return (*(*func(*libc.TLS, int32, Uid_t, Gid_t) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 20*24 + 8)))(tls, fd, uid, gid)
}

func unixSetSystemCall(tls *libc.TLS, pNotUsed uintptr, zName uintptr, pNewFunc Sqlite3_syscall_ptr) int32 {
	var i uint32
	var rc int32 = SQLITE_NOTFOUND

	_ = pNotUsed
	if zName == uintptr(0) {
		rc = SQLITE_OK
		for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(aSyscall))/uint64(unsafe.Sizeof(unix_syscall{})); i++ {
			if aSyscall[i].FpDefault != 0 {
				aSyscall[i].FpCurrent = aSyscall[i].FpDefault
			}
		}
	} else {
		for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(aSyscall))/uint64(unsafe.Sizeof(unix_syscall{})); i++ {
			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
			}
		}
	}
	return rc
}

func unixGetSystemCall(tls *libc.TLS, pNotUsed uintptr, zName uintptr) Sqlite3_syscall_ptr {
	var i uint32

	_ = pNotUsed
	for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(aSyscall))/uint64(unsafe.Sizeof(unix_syscall{})); i++ {
		if libc.Xstrcmp(tls, zName, aSyscall[i].FzName) == 0 {
			return aSyscall[i].FpCurrent
		}
	}
	return uintptr(0)
}

func unixNextSystemCall(tls *libc.TLS, p uintptr, zName uintptr) uintptr {
	var i int32 = -1

	_ = p
	if zName != 0 {
		for i = 0; i < int32(uint64(unsafe.Sizeof(aSyscall))/uint64(unsafe.Sizeof(unix_syscall{})))-1; i++ {
			if libc.Xstrcmp(tls, zName, aSyscall[i].FzName) == 0 {
				break
			}
		}
	}
	for i++; i < int32(uint64(unsafe.Sizeof(aSyscall))/uint64(unsafe.Sizeof(unix_syscall{}))); i++ {
		if aSyscall[i].FpCurrent != uintptr(0) {
			return aSyscall[i].FzName
		}
	}
	return uintptr(0)
}

func robust_open(tls *libc.TLS, z uintptr, f int32, m Mode_t) int32 {
	bp := tls.Alloc(144)
	defer tls.Free(144)

	var fd int32
	var m2 Mode_t
	if m != 0 {
		m2 = m
	} else {
		m2 = uint32(SQLITE_DEFAULT_FILE_PERMISSIONS)
	}
	for 1 != 0 {
		fd = (*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 8)))(tls, z, f|02000000, int32(m2))
		if fd < 0 {
			if *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) == EINTR {
				continue
			}
			break
		}
		if fd >= SQLITE_MINIMUM_FILE_DESCRIPTOR {
			break
		}
		if f&(O_EXCL|O_CREAT) == O_EXCL|O_CREAT {
			(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 16*24 + 8)))(tls, z)
		}
		(*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 1*24 + 8)))(tls, fd)
		Xsqlite3_log(tls, SQLITE_WARNING,
			ts+5833, libc.VaList(bp, z, fd))
		fd = -1
		if (*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 8)))(tls, ts+5876, O_RDONLY, int32(m)) < 0 {
			break
		}
	}
	if fd >= 0 {
		if m != Mode_t(0) {
			if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 5*24 + 8)))(tls, fd, bp+16) == 0 &&
				(*stat)(unsafe.Pointer(bp+16)).Fst_size == int64(0) &&
				(*stat)(unsafe.Pointer(bp+16)).Fst_mode&X__mode_t(0777) != m {
				(*(*func(*libc.TLS, int32, Mode_t) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 14*24 + 8)))(tls, fd, m)
			}
		}
	}
	return fd
}

var unixBigLock uintptr = uintptr(0)

func unixEnterMutex(tls *libc.TLS) {
	Xsqlite3_mutex_enter(tls, unixBigLock)
}

func unixLeaveMutex(tls *libc.TLS) {
	Xsqlite3_mutex_leave(tls, unixBigLock)
}

func azFileLock(tls *libc.TLS, eFileLock int32) uintptr {
	switch eFileLock {
	case NO_LOCK:
		return ts + 5886
	case SHARED_LOCK:
		return ts + 5891
	case RESERVED_LOCK:
		return ts + 5898
	case PENDING_LOCK:
		return ts + 5907
	case EXCLUSIVE_LOCK:
		return ts + 5915
	}
	return ts + 5925
}

func robust_ftruncate(tls *libc.TLS, h int32, sz Sqlite3_int64) int32 {
	var rc int32
	for __ccgo := true; __ccgo; __ccgo = rc < 0 && *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) == EINTR {
		rc = (*(*func(*libc.TLS, int32, Off_t) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 6*24 + 8)))(tls, h, sz)
	}
	return rc
}

func sqliteErrorFromPosixError(tls *libc.TLS, posixError int32, sqliteIOErr int32) int32 {
	switch posixError {
	case EACCES:
		fallthrough
	case EAGAIN:
		fallthrough
	case ETIMEDOUT:
		fallthrough
	case EBUSY:
		fallthrough
	case EINTR:
		fallthrough
	case ENOLCK:
		return SQLITE_BUSY

	case EPERM:
		return SQLITE_PERM

	default:
		return sqliteIOErr
	}
	return int32(0)
}

type vxworksFileId = struct {
	FpNext          uintptr
	FnRef           int32
	FnName          int32
	FzCanonicalName uintptr
}

type unixFileId = struct {
	Fdev Dev_t
	Fino U64
}

var inodeList uintptr = uintptr(0)

func unixLogErrorAtLine(tls *libc.TLS, errcode int32, zFunc uintptr, zPath uintptr, iLine int32) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var zErr uintptr
	var iErrno int32 = *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))

	zErr = ts + 1636

	if zPath == uintptr(0) {
		zPath = ts + 1636
	}
	Xsqlite3_log(tls, errcode,
		ts+5931,
		libc.VaList(bp, iLine, iErrno, zFunc, zPath, zErr))

	return errcode
}

func robust_close(tls *libc.TLS, pFile uintptr, h int32, lineno int32) {
	if (*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 1*24 + 8)))(tls, h) != 0 {
		unixLogErrorAtLine(tls, SQLITE_IOERR|int32(16)<<8, ts+5628,
			func() uintptr {
				if pFile != 0 {
					return (*UnixFile)(unsafe.Pointer(pFile)).FzPath
				}
				return uintptr(0)
			}(), lineno)
	}
}

func storeLastErrno(tls *libc.TLS, pFile uintptr, error int32) {
	(*UnixFile)(unsafe.Pointer(pFile)).FlastErrno = error
}

func closePendingFds(tls *libc.TLS, pFile uintptr) {
	var pInode uintptr = (*UnixFile)(unsafe.Pointer(pFile)).FpInode
	var p uintptr
	var pNext uintptr

	for p = (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpUnused; p != 0; p = pNext {
		pNext = (*UnixUnusedFd)(unsafe.Pointer(p)).FpNext
		robust_close(tls, pFile, (*UnixUnusedFd)(unsafe.Pointer(p)).Ffd, 38275)
		Xsqlite3_free(tls, p)
	}
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FpUnused = uintptr(0)
}

func releaseInodeInfo(tls *libc.TLS, pFile uintptr) {
	var pInode uintptr = (*UnixFile)(unsafe.Pointer(pFile)).FpInode

	if pInode != 0 {
		(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnRef--
		if (*UnixInodeInfo)(unsafe.Pointer(pInode)).FnRef == 0 {
			Xsqlite3_mutex_enter(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
			closePendingFds(tls, pFile)
			Xsqlite3_mutex_leave(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
			if (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpPrev != 0 {
				(*UnixInodeInfo)(unsafe.Pointer((*UnixInodeInfo)(unsafe.Pointer(pInode)).FpPrev)).FpNext = (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpNext
			} else {
				inodeList = (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpNext
			}
			if (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpNext != 0 {
				(*UnixInodeInfo)(unsafe.Pointer((*UnixInodeInfo)(unsafe.Pointer(pInode)).FpNext)).FpPrev = (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpPrev
			}
			Xsqlite3_mutex_free(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
			Xsqlite3_free(tls, pInode)
		}
	}
}

func findInodeInfo(tls *libc.TLS, pFile uintptr, ppInode uintptr) int32 {
	bp := tls.Alloc(144)
	defer tls.Free(144)

	var rc int32
	var fd int32

	var pInode uintptr = uintptr(0)

	fd = (*UnixFile)(unsafe.Pointer(pFile)).Fh
	rc = (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 5*24 + 8)))(tls, fd, bp)
	if rc != 0 {
		storeLastErrno(tls, pFile, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
		return SQLITE_IOERR
	}

	libc.Xmemset(tls, bp+128, 0, uint64(unsafe.Sizeof(unixFileId{})))
	(*unixFileId)(unsafe.Pointer(bp + 128)).Fdev = (*stat)(unsafe.Pointer(bp)).Fst_dev
	(*unixFileId)(unsafe.Pointer(bp + 128)).Fino = (*stat)(unsafe.Pointer(bp)).Fst_ino

	pInode = inodeList
	for pInode != 0 && libc.Xmemcmp(tls, bp+128, pInode, uint64(unsafe.Sizeof(unixFileId{}))) != 0 {
		pInode = (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpNext
	}
	if pInode == uintptr(0) {
		pInode = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(UnixInodeInfo{})))
		if pInode == uintptr(0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, pInode, 0, uint64(unsafe.Sizeof(UnixInodeInfo{})))
		libc.Xmemcpy(tls, pInode, bp+128, uint64(unsafe.Sizeof(unixFileId{})))
		if Xsqlite3Config.FbCoreMutex != 0 {
			(*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_FAST)
			if (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex == uintptr(0) {
				Xsqlite3_free(tls, pInode)
				return SQLITE_NOMEM
			}
		}
		(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnRef = 1

		(*UnixInodeInfo)(unsafe.Pointer(pInode)).FpNext = inodeList
		(*UnixInodeInfo)(unsafe.Pointer(pInode)).FpPrev = uintptr(0)
		if inodeList != 0 {
			(*UnixInodeInfo)(unsafe.Pointer(inodeList)).FpPrev = pInode
		}
		inodeList = pInode
	} else {
		(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnRef++
	}
	*(*uintptr)(unsafe.Pointer(ppInode)) = pInode
	return SQLITE_OK
}

func fileHasMoved(tls *libc.TLS, pFile uintptr) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	return libc.Bool32((*UnixFile)(unsafe.Pointer(pFile)).FpInode != uintptr(0) && ((*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 4*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFile)).FzPath, bp) != 0 ||
		(*stat)(unsafe.Pointer(bp)).Fst_ino != (*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FfileId.Fino))
}

func verifyDbFile(tls *libc.TLS, pFile uintptr) {
	bp := tls.Alloc(160)
	defer tls.Free(160)

	var rc int32

	if int32((*UnixFile)(unsafe.Pointer(pFile)).FctrlFlags)&UNIXFILE_NOLOCK != 0 {
		return
	}

	rc = (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 5*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFile)).Fh, bp+32)
	if rc != 0 {
		Xsqlite3_log(tls, SQLITE_WARNING, ts+5962, libc.VaList(bp, (*UnixFile)(unsafe.Pointer(pFile)).FzPath))
		return
	}
	if (*stat)(unsafe.Pointer(bp+32)).Fst_nlink == X__nlink_t(0) {
		Xsqlite3_log(tls, SQLITE_WARNING, ts+5986, libc.VaList(bp+8, (*UnixFile)(unsafe.Pointer(pFile)).FzPath))
		return
	}
	if (*stat)(unsafe.Pointer(bp+32)).Fst_nlink > X__nlink_t(1) {
		Xsqlite3_log(tls, SQLITE_WARNING, ts+6015, libc.VaList(bp+16, (*UnixFile)(unsafe.Pointer(pFile)).FzPath))
		return
	}
	if fileHasMoved(tls, pFile) != 0 {
		Xsqlite3_log(tls, SQLITE_WARNING, ts+6042, libc.VaList(bp+24, (*UnixFile)(unsafe.Pointer(pFile)).FzPath))
		return
	}
}

func unixCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var rc int32 = SQLITE_OK
	var reserved int32 = 0
	var pFile uintptr = id

	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		return SQLITE_IOERR | int32(14)<<8
	}

	Xsqlite3_mutex_enter(tls, (*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FpLockMutex)

	if int32((*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FeFileLock) > SHARED_LOCK {
		reserved = 1
	}

	if !(reserved != 0) && !(int32((*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FbProcessLock) != 0) {
		(*flock)(unsafe.Pointer(bp + 32)).Fl_whence = int16(SEEK_SET)
		(*flock)(unsafe.Pointer(bp + 32)).Fl_start = X__off_t(Xsqlite3PendingByte + 1)
		(*flock)(unsafe.Pointer(bp + 32)).Fl_len = int64(1)
		(*flock)(unsafe.Pointer(bp + 32)).Fl_type = int16(F_WRLCK)
		if (*(*func(*libc.TLS, int32, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 7*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFile)).Fh, F_GETLK64, libc.VaList(bp, bp+32)) != 0 {
			rc = SQLITE_IOERR | int32(14)<<8
			storeLastErrno(tls, pFile, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
		} else if int32((*flock)(unsafe.Pointer(bp+32)).Fl_type) != F_UNLCK {
			reserved = 1
		}
	}

	Xsqlite3_mutex_leave(tls, (*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FpLockMutex)
	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6070, libc.VaList(bp+8, (*UnixFile)(unsafe.Pointer(pFile)).Fh, rc, reserved))
	}

	*(*int32)(unsafe.Pointer(pResOut)) = reserved
	return rc
}

func unixFileLock(tls *libc.TLS, pFile uintptr, pLock uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var rc int32
	var pInode uintptr = (*UnixFile)(unsafe.Pointer(pFile)).FpInode

	if int32((*UnixFile)(unsafe.Pointer(pFile)).FctrlFlags)&(UNIXFILE_EXCL|UNIXFILE_RDONLY) == UNIXFILE_EXCL {
		if int32((*UnixInodeInfo)(unsafe.Pointer(pInode)).FbProcessLock) == 0 {
			(*flock)(unsafe.Pointer(bp + 16)).Fl_whence = int16(SEEK_SET)
			(*flock)(unsafe.Pointer(bp + 16)).Fl_start = X__off_t(Xsqlite3PendingByte + 2)
			(*flock)(unsafe.Pointer(bp + 16)).Fl_len = int64(SHARED_SIZE)
			(*flock)(unsafe.Pointer(bp + 16)).Fl_type = int16(F_WRLCK)
			rc = (*(*func(*libc.TLS, int32, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 7*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFile)).Fh, F_SETLK64, libc.VaList(bp, bp+16))
			if rc < 0 {
				return rc
			}
			(*UnixInodeInfo)(unsafe.Pointer(pInode)).FbProcessLock = uint8(1)
			(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnLock++
		} else {
			rc = 0
		}
	} else {
		rc = (*(*func(*libc.TLS, int32, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 7*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFile)).Fh, F_SETLK64, libc.VaList(bp+8, pLock))
	}
	return rc
}

func unixLock(tls *libc.TLS, id uintptr, eFileLock int32) int32 {
	bp := tls.Alloc(120)
	defer tls.Free(120)

	var rc int32
	var pFile uintptr
	var pInode uintptr

	var tErrno int32
	rc = SQLITE_OK
	pFile = id
	tErrno = 0

	if !(Xsqlite3OSTrace != 0) {
		goto __1
	}
	Xsqlite3DebugPrintf(tls, ts+6100, libc.VaList(bp, (*UnixFile)(unsafe.Pointer(pFile)).Fh, azFileLock(tls, eFileLock), azFileLock(tls, int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock)), azFileLock(tls, int32((*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FeFileLock)), (*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FnShared, libc.Xgetpid(tls)))
__1:
	;
	if !(int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock) >= eFileLock) {
		goto __2
	}
	if !(Xsqlite3OSTrace != 0) {
		goto __3
	}
	Xsqlite3DebugPrintf(tls, ts+6143, libc.VaList(bp+48, (*UnixFile)(unsafe.Pointer(pFile)).Fh, azFileLock(tls, eFileLock)))
__3:
	;
	return SQLITE_OK
__2:
	;
	pInode = (*UnixFile)(unsafe.Pointer(pFile)).FpInode
	Xsqlite3_mutex_enter(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)

	if !(int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock) != int32((*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) && (int32((*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) >= PENDING_LOCK || eFileLock > SHARED_LOCK)) {
		goto __4
	}
	rc = SQLITE_BUSY
	goto end_lock
__4:
	;
	if !(eFileLock == SHARED_LOCK && (int32((*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) == SHARED_LOCK || int32((*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock) == RESERVED_LOCK)) {
		goto __5
	}

	(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(SHARED_LOCK)
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnShared++
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnLock++
	goto end_lock
__5:
	;
	(*flock)(unsafe.Pointer(bp + 88)).Fl_len = 1
	(*flock)(unsafe.Pointer(bp + 88)).Fl_whence = int16(SEEK_SET)
	if !(eFileLock == SHARED_LOCK ||
		eFileLock == EXCLUSIVE_LOCK && int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock) == RESERVED_LOCK) {
		goto __6
	}
	(*flock)(unsafe.Pointer(bp + 88)).Fl_type = func() int16 {
		if eFileLock == SHARED_LOCK {
			return int16(F_RDLCK)
		}
		return int16(F_WRLCK)
	}()
	(*flock)(unsafe.Pointer(bp + 88)).Fl_start = X__off_t(Xsqlite3PendingByte)
	if !(unixFileLock(tls, pFile, bp+88) != 0) {
		goto __7
	}
	tErrno = *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))
	rc = sqliteErrorFromPosixError(tls, tErrno, SQLITE_IOERR|int32(15)<<8)
	if !(rc != SQLITE_BUSY) {
		goto __9
	}
	storeLastErrno(tls, pFile, tErrno)
__9:
	;
	goto end_lock
	goto __8
__7:
	if !(eFileLock == EXCLUSIVE_LOCK) {
		goto __10
	}
	(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(PENDING_LOCK)
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(PENDING_LOCK)
__10:
	;
__8:
	;
__6:
	;
	if !(eFileLock == SHARED_LOCK) {
		goto __11
	}

	(*flock)(unsafe.Pointer(bp + 88)).Fl_start = X__off_t(Xsqlite3PendingByte + 2)
	(*flock)(unsafe.Pointer(bp + 88)).Fl_len = int64(SHARED_SIZE)
	if !(unixFileLock(tls, pFile, bp+88) != 0) {
		goto __13
	}
	tErrno = *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))
	rc = sqliteErrorFromPosixError(tls, tErrno, SQLITE_IOERR|int32(15)<<8)
__13:
	;
	(*flock)(unsafe.Pointer(bp + 88)).Fl_start = X__off_t(Xsqlite3PendingByte)
	(*flock)(unsafe.Pointer(bp + 88)).Fl_len = 1
	(*flock)(unsafe.Pointer(bp + 88)).Fl_type = int16(F_UNLCK)
	if !(unixFileLock(tls, pFile, bp+88) != 0 && rc == SQLITE_OK) {
		goto __14
	}

	tErrno = *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))
	rc = SQLITE_IOERR | int32(8)<<8
__14:
	;
	if !(rc != 0) {
		goto __15
	}
	if !(rc != SQLITE_BUSY) {
		goto __17
	}
	storeLastErrno(tls, pFile, tErrno)
__17:
	;
	goto end_lock
	goto __16
__15:
	(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(SHARED_LOCK)
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnLock++
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnShared = 1
__16:
	;
	goto __12
__11:
	if !(eFileLock == EXCLUSIVE_LOCK && (*UnixInodeInfo)(unsafe.Pointer(pInode)).FnShared > 1) {
		goto __18
	}

	rc = SQLITE_BUSY
	goto __19
__18:
	;
	(*flock)(unsafe.Pointer(bp + 88)).Fl_type = int16(F_WRLCK)

	if !(eFileLock == RESERVED_LOCK) {
		goto __20
	}
	(*flock)(unsafe.Pointer(bp + 88)).Fl_start = X__off_t(Xsqlite3PendingByte + 1)
	(*flock)(unsafe.Pointer(bp + 88)).Fl_len = 1
	goto __21
__20:
	(*flock)(unsafe.Pointer(bp + 88)).Fl_start = X__off_t(Xsqlite3PendingByte + 2)
	(*flock)(unsafe.Pointer(bp + 88)).Fl_len = int64(SHARED_SIZE)
__21:
	;
	if !(unixFileLock(tls, pFile, bp+88) != 0) {
		goto __22
	}
	tErrno = *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))
	rc = sqliteErrorFromPosixError(tls, tErrno, SQLITE_IOERR|int32(15)<<8)
	if !(rc != SQLITE_BUSY) {
		goto __23
	}
	storeLastErrno(tls, pFile, tErrno)
__23:
	;
__22:
	;
__19:
	;
__12:
	;
	if !(rc == SQLITE_OK) {
		goto __24
	}
	(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(eFileLock)
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(eFileLock)
__24:
	;
end_lock:
	Xsqlite3_mutex_leave(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
	if !(Xsqlite3OSTrace != 0) {
		goto __25
	}
	Xsqlite3DebugPrintf(tls, ts+6183, libc.VaList(bp+64, (*UnixFile)(unsafe.Pointer(pFile)).Fh, azFileLock(tls, eFileLock), func() uintptr {
		if rc == SQLITE_OK {
			return ts + 6208
		}
		return ts + 6211
	}()))
__25:
	;
	return rc
}

func setPendingFd(tls *libc.TLS, pFile uintptr) {
	var pInode uintptr = (*UnixFile)(unsafe.Pointer(pFile)).FpInode
	var p uintptr = (*UnixFile)(unsafe.Pointer(pFile)).FpPreallocatedUnused

	(*UnixUnusedFd)(unsafe.Pointer(p)).FpNext = (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpUnused
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FpUnused = p
	(*UnixFile)(unsafe.Pointer(pFile)).Fh = -1
	(*UnixFile)(unsafe.Pointer(pFile)).FpPreallocatedUnused = uintptr(0)
}

func posixUnlock(tls *libc.TLS, id uintptr, eFileLock int32, handleNFSUnlock int32) int32 {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var pFile uintptr
	var pInode uintptr

	var rc int32
	pFile = id
	rc = SQLITE_OK

	if !(Xsqlite3OSTrace != 0) {
		goto __1
	}
	Xsqlite3DebugPrintf(tls, ts+6218, libc.VaList(bp, (*UnixFile)(unsafe.Pointer(pFile)).Fh, eFileLock, int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock), int32((*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FeFileLock), (*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FnShared, libc.Xgetpid(tls)))
__1:
	;
	if !(int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock) <= eFileLock) {
		goto __2
	}
	return SQLITE_OK
__2:
	;
	pInode = (*UnixFile)(unsafe.Pointer(pFile)).FpInode
	Xsqlite3_mutex_enter(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)

	if !(int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock) > SHARED_LOCK) {
		goto __3
	}

	if !(eFileLock == SHARED_LOCK) {
		goto __4
	}
	_ = handleNFSUnlock

	(*flock)(unsafe.Pointer(bp + 48)).Fl_type = int16(F_RDLCK)
	(*flock)(unsafe.Pointer(bp + 48)).Fl_whence = int16(SEEK_SET)
	(*flock)(unsafe.Pointer(bp + 48)).Fl_start = X__off_t(Xsqlite3PendingByte + 2)
	(*flock)(unsafe.Pointer(bp + 48)).Fl_len = int64(SHARED_SIZE)
	if !(unixFileLock(tls, pFile, bp+48) != 0) {
		goto __5
	}

	rc = SQLITE_IOERR | int32(9)<<8
	storeLastErrno(tls, pFile, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
	goto end_unlock
__5:
	;
__4:
	;
	(*flock)(unsafe.Pointer(bp + 48)).Fl_type = int16(F_UNLCK)
	(*flock)(unsafe.Pointer(bp + 48)).Fl_whence = int16(SEEK_SET)
	(*flock)(unsafe.Pointer(bp + 48)).Fl_start = X__off_t(Xsqlite3PendingByte)
	(*flock)(unsafe.Pointer(bp + 48)).Fl_len = 2
	if !(unixFileLock(tls, pFile, bp+48) == 0) {
		goto __6
	}
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(SHARED_LOCK)
	goto __7
__6:
	rc = SQLITE_IOERR | int32(8)<<8
	storeLastErrno(tls, pFile, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
	goto end_unlock
__7:
	;
__3:
	;
	if !(eFileLock == NO_LOCK) {
		goto __8
	}

	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnShared--
	if !((*UnixInodeInfo)(unsafe.Pointer(pInode)).FnShared == 0) {
		goto __9
	}
	(*flock)(unsafe.Pointer(bp + 48)).Fl_type = int16(F_UNLCK)
	(*flock)(unsafe.Pointer(bp + 48)).Fl_whence = int16(SEEK_SET)
	(*flock)(unsafe.Pointer(bp + 48)).Fl_start = libc.AssignPtrInt64(bp+48+16, 0)
	if !(unixFileLock(tls, pFile, bp+48) == 0) {
		goto __10
	}
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(NO_LOCK)
	goto __11
__10:
	rc = SQLITE_IOERR | int32(8)<<8
	storeLastErrno(tls, pFile, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FeFileLock = uint8(NO_LOCK)
	(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(NO_LOCK)
__11:
	;
__9:
	;
	(*UnixInodeInfo)(unsafe.Pointer(pInode)).FnLock--

	if !((*UnixInodeInfo)(unsafe.Pointer(pInode)).FnLock == 0) {
		goto __12
	}
	closePendingFds(tls, pFile)
__12:
	;
__8:
	;
end_unlock:
	Xsqlite3_mutex_leave(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
	if !(rc == SQLITE_OK) {
		goto __13
	}
	(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(eFileLock)
__13:
	;
	return rc
}

func unixUnlock(tls *libc.TLS, id uintptr, eFileLock int32) int32 {
	return posixUnlock(tls, id, eFileLock, 0)
}

func closeUnixFile(tls *libc.TLS, id uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pFile uintptr = id
	unixUnmapfile(tls, pFile)
	if (*UnixFile)(unsafe.Pointer(pFile)).Fh >= 0 {
		robust_close(tls, pFile, (*UnixFile)(unsafe.Pointer(pFile)).Fh, 39059)
		(*UnixFile)(unsafe.Pointer(pFile)).Fh = -1
	}
	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6261, libc.VaList(bp, (*UnixFile)(unsafe.Pointer(pFile)).Fh))
	}
	libc.AtomicAddInt32(&Xsqlite3_open_file_count, int32(-1))
	Xsqlite3_free(tls, (*UnixFile)(unsafe.Pointer(pFile)).FpPreallocatedUnused)
	libc.Xmemset(tls, pFile, 0, uint64(unsafe.Sizeof(UnixFile{})))
	return SQLITE_OK
}

func unixClose(tls *libc.TLS, id uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pFile uintptr = id
	var pInode uintptr = (*UnixFile)(unsafe.Pointer(pFile)).FpInode

	verifyDbFile(tls, pFile)
	unixUnlock(tls, id, NO_LOCK)

	unixEnterMutex(tls)

	Xsqlite3_mutex_enter(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
	if (*UnixInodeInfo)(unsafe.Pointer(pInode)).FnLock != 0 {
		setPendingFd(tls, pFile)
	}
	Xsqlite3_mutex_leave(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
	releaseInodeInfo(tls, pFile)

	rc = closeUnixFile(tls, id)
	unixLeaveMutex(tls)
	return rc
}

func nolockCheckReservedLock(tls *libc.TLS, NotUsed uintptr, pResOut uintptr) int32 {
	_ = NotUsed
	*(*int32)(unsafe.Pointer(pResOut)) = 0
	return SQLITE_OK
}

func nolockLock(tls *libc.TLS, NotUsed uintptr, NotUsed2 int32) int32 {
	_ = NotUsed
	_ = NotUsed2
	return SQLITE_OK
}

func nolockUnlock(tls *libc.TLS, NotUsed uintptr, NotUsed2 int32) int32 {
	_ = NotUsed
	_ = NotUsed2
	return SQLITE_OK
}

func nolockClose(tls *libc.TLS, id uintptr) int32 {
	return closeUnixFile(tls, id)
}

func dotlockCheckReservedLock(tls *libc.TLS, id uintptr, pResOut uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32 = SQLITE_OK
	var reserved int32 = 0
	var pFile uintptr = id

	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		return SQLITE_IOERR | int32(14)<<8
	}

	reserved = libc.Bool32((*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 2*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFile)).FlockingContext, 0) == 0)
	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6275, libc.VaList(bp, (*UnixFile)(unsafe.Pointer(pFile)).Fh, rc, reserved))
	}
	*(*int32)(unsafe.Pointer(pResOut)) = reserved
	return rc
}

func dotlockLock(tls *libc.TLS, id uintptr, eFileLock int32) int32 {
	var pFile uintptr = id
	var zLockFile uintptr = (*UnixFile)(unsafe.Pointer(pFile)).FlockingContext
	var rc int32 = SQLITE_OK

	if int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock) > NO_LOCK {
		(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(eFileLock)

		libc.Xutimes(tls, zLockFile, uintptr(0))
		return SQLITE_OK
	}

	rc = (*(*func(*libc.TLS, uintptr, Mode_t) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 18*24 + 8)))(tls, zLockFile, uint32(0777))
	if rc < 0 {
		var tErrno int32 = *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))
		if EEXIST == tErrno {
			rc = SQLITE_BUSY
		} else {
			rc = sqliteErrorFromPosixError(tls, tErrno, SQLITE_IOERR|int32(15)<<8)
			if rc != SQLITE_BUSY {
				storeLastErrno(tls, pFile, tErrno)
			}
		}
		return rc
	}

	(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(eFileLock)
	return rc
}

func dotlockUnlock(tls *libc.TLS, id uintptr, eFileLock int32) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pFile uintptr = id
	var zLockFile uintptr = (*UnixFile)(unsafe.Pointer(pFile)).FlockingContext
	var rc int32

	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6308, libc.VaList(bp, (*UnixFile)(unsafe.Pointer(pFile)).Fh, eFileLock, int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock), libc.Xgetpid(tls)))
	}

	if int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock) == eFileLock {
		return SQLITE_OK
	}

	if eFileLock == SHARED_LOCK {
		(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(SHARED_LOCK)
		return SQLITE_OK
	}

	rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 19*24 + 8)))(tls, zLockFile)
	if rc < 0 {
		var tErrno int32 = *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))
		if tErrno == ENOENT {
			rc = SQLITE_OK
		} else {
			rc = SQLITE_IOERR | int32(8)<<8
			storeLastErrno(tls, pFile, tErrno)
		}
		return rc
	}
	(*UnixFile)(unsafe.Pointer(pFile)).FeFileLock = uint8(NO_LOCK)
	return SQLITE_OK
}

func dotlockClose(tls *libc.TLS, id uintptr) int32 {
	var pFile uintptr = id

	dotlockUnlock(tls, id, NO_LOCK)
	Xsqlite3_free(tls, (*UnixFile)(unsafe.Pointer(pFile)).FlockingContext)
	return closeUnixFile(tls, id)
}

func seekAndRead(tls *libc.TLS, id uintptr, offset Sqlite3_int64, pBuf uintptr, cnt int32) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var got int32
	var prior int32 = 0
	var newOffset I64

	for __ccgo := true; __ccgo; __ccgo = got > 0 {
		newOffset = libc.Xlseek(tls, (*UnixFile)(unsafe.Pointer(id)).Fh, offset, SEEK_SET)
		if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
			local_ioerr(tls)
			newOffset = int64(-1)
		}

		if newOffset < int64(0) {
			storeLastErrno(tls, id, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
			return -1
		}
		got = int32((*(*func(*libc.TLS, int32, uintptr, Size_t) Ssize_t)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 8*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(id)).Fh, pBuf, uint64(cnt)))
		if got == cnt {
			break
		}
		if got < 0 {
			if *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) == EINTR {
				got = 1
				continue
			}
			prior = 0
			storeLastErrno(tls, id, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
			break
		} else if got > 0 {
			cnt = cnt - got
			offset = offset + Sqlite3_int64(got)
			prior = prior + got
			pBuf = uintptr(got) + pBuf
		}
	}

	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6347, libc.VaList(bp, (*UnixFile)(unsafe.Pointer(id)).Fh, got+prior, offset-Sqlite3_int64(prior), uint64(0)))
	}
	return got + prior
}

func unixRead(tls *libc.TLS, id uintptr, pBuf uintptr, amt int32, offset Sqlite3_int64) int32 {
	var pFile uintptr = id
	var got int32

	if offset < (*UnixFile)(unsafe.Pointer(pFile)).FmmapSize {
		if offset+Sqlite3_int64(amt) <= (*UnixFile)(unsafe.Pointer(pFile)).FmmapSize {
			libc.Xmemcpy(tls, pBuf, (*UnixFile)(unsafe.Pointer(pFile)).FpMapRegion+uintptr(offset), uint64(amt))
			return SQLITE_OK
		} else {
			var nCopy int32 = int32((*UnixFile)(unsafe.Pointer(pFile)).FmmapSize - offset)
			libc.Xmemcpy(tls, pBuf, (*UnixFile)(unsafe.Pointer(pFile)).FpMapRegion+uintptr(offset), uint64(nCopy))
			pBuf = pBuf + uintptr(nCopy)
			amt = amt - nCopy
			offset = offset + Sqlite3_int64(nCopy)
		}
	}

	got = seekAndRead(tls, pFile, offset, pBuf, amt)
	if got == amt {
		return SQLITE_OK
	} else if got < 0 {
		switch (*UnixFile)(unsafe.Pointer(pFile)).FlastErrno {
		case ERANGE:
			fallthrough
		case EIO:
			fallthrough
		case ENXIO:
			return SQLITE_IOERR | int32(33)<<8
		}
		return SQLITE_IOERR | int32(1)<<8
	} else {
		storeLastErrno(tls, pFile, 0)

		libc.Xmemset(tls, pBuf+uintptr(got), 0, uint64(amt-got))
		return SQLITE_IOERR | int32(2)<<8
	}
	return int32(0)
}

func seekAndWriteFd(tls *libc.TLS, fd int32, iOff I64, pBuf uintptr, nBuf int32, piErrno uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var rc int32 = 0

	nBuf = nBuf & 0x1ffff

	for __ccgo := true; __ccgo; __ccgo = rc < 0 && *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) == EINTR {
		var iSeek I64 = libc.Xlseek(tls, fd, iOff, SEEK_SET)
		if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
			local_ioerr(tls)
			iSeek = int64(-1)
		}

		if iSeek < int64(0) {
			rc = -1
			break
		}
		rc = int32((*(*func(*libc.TLS, int32, uintptr, Size_t) Ssize_t)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 11*24 + 8)))(tls, fd, pBuf, uint64(nBuf)))
	}

	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6376, libc.VaList(bp, fd, rc, iOff, uint64(0)))
	}

	if rc < 0 {
		*(*int32)(unsafe.Pointer(piErrno)) = *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))
	}
	return rc
}

func seekAndWrite(tls *libc.TLS, id uintptr, offset I64, pBuf uintptr, cnt int32) int32 {
	return seekAndWriteFd(tls, (*UnixFile)(unsafe.Pointer(id)).Fh, offset, pBuf, cnt, id+32)
}

func unixWrite(tls *libc.TLS, id uintptr, pBuf uintptr, amt int32, offset Sqlite3_int64) int32 {
	var pFile uintptr = id
	var wrote int32 = 0

	for libc.AssignInt32(&wrote, seekAndWrite(tls, pFile, offset, pBuf, amt)) < amt && wrote > 0 {
		amt = amt - wrote
		offset = offset + Sqlite3_int64(wrote)
		pBuf = pBuf + uintptr(wrote)
	}
	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		wrote = -1
		amt = 1
	}

	if Xsqlite3_diskfull_pending != 0 {
		if Xsqlite3_diskfull_pending == 1 {
			local_ioerr(tls)
			Xsqlite3_diskfull = 1
			Xsqlite3_io_error_hit = 1
			wrote = 0
			amt = 1
		} else {
			Xsqlite3_diskfull_pending--
		}
	}

	if amt > wrote {
		if wrote < 0 && (*UnixFile)(unsafe.Pointer(pFile)).FlastErrno != ENOSPC {
			return SQLITE_IOERR | int32(3)<<8
		} else {
			storeLastErrno(tls, pFile, 0)
			return SQLITE_FULL
		}
	}

	return SQLITE_OK
}

var Xsqlite3_sync_count int32 = 0
var Xsqlite3_fullsync_count int32 = 0

func full_fsync(tls *libc.TLS, fd int32, fullSync int32, dataOnly int32) int32 {
	var rc int32

	_ = fullSync
	_ = dataOnly

	if fullSync != 0 {
		Xsqlite3_fullsync_count++
	}
	Xsqlite3_sync_count++

	rc = libc.Xfsync(tls, fd)

	if 0 != 0 && rc != -1 {
		rc = 0
	}
	return rc
}

func openDirectory(tls *libc.TLS, zFilename uintptr, pFd uintptr) int32 {
	bp := tls.Alloc(537)
	defer tls.Free(537)

	var ii int32
	var fd int32 = -1

	Xsqlite3_snprintf(tls, MAX_PATHNAME, bp+24, ts+1684, libc.VaList(bp, zFilename))
	for ii = int32(libc.Xstrlen(tls, bp+24)); ii > 0 && int32(*(*uint8)(unsafe.Pointer(bp + 24 + uintptr(ii)))) != '/'; ii-- {
	}
	if ii > 0 {
		*(*uint8)(unsafe.Pointer(bp + 24 + uintptr(ii))) = uint8(0)
	} else {
		if int32(*(*uint8)(unsafe.Pointer(bp + 24))) != '/' {
			*(*uint8)(unsafe.Pointer(bp + 24)) = uint8('.')
		}
		*(*uint8)(unsafe.Pointer(bp + 24 + 1)) = uint8(0)
	}
	fd = robust_open(tls, bp+24, O_RDONLY|O_BINARY, uint32(0))
	if fd >= 0 {
		if Xsqlite3OSTrace != 0 {
			Xsqlite3DebugPrintf(tls, ts+6405, libc.VaList(bp+8, fd, bp+24))
		}
	}
	*(*int32)(unsafe.Pointer(pFd)) = fd
	if fd >= 0 {
		return SQLITE_OK
	}
	return unixLogErrorAtLine(tls, Xsqlite3CantopenError(tls, 40680), ts+5740, bp+24, 40680)
}

func unixSync(tls *libc.TLS, id uintptr, flags int32) int32 {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var rc int32
	var pFile uintptr = id

	var isDataOnly int32 = flags & SQLITE_SYNC_DATAONLY
	var isFullsync int32 = libc.Bool32(flags&0x0F == SQLITE_SYNC_FULL)

	if Xsqlite3_diskfull_pending != 0 {
		if Xsqlite3_diskfull_pending == 1 {
			local_ioerr(tls)
			Xsqlite3_diskfull = 1
			Xsqlite3_io_error_hit = 1
			return SQLITE_FULL
		} else {
			Xsqlite3_diskfull_pending--
		}
	}

	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6422, libc.VaList(bp, (*UnixFile)(unsafe.Pointer(pFile)).Fh))
	}
	rc = full_fsync(tls, (*UnixFile)(unsafe.Pointer(pFile)).Fh, isFullsync, isDataOnly)
	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		rc = 1
	}

	if rc != 0 {
		storeLastErrno(tls, pFile, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
		return unixLogErrorAtLine(tls, SQLITE_IOERR|int32(4)<<8, ts+6436, (*UnixFile)(unsafe.Pointer(pFile)).FzPath, 40721)
	}

	if int32((*UnixFile)(unsafe.Pointer(pFile)).FctrlFlags)&UNIXFILE_DIRSYNC != 0 {
		if Xsqlite3OSTrace != 0 {
			Xsqlite3DebugPrintf(tls, ts+6447, libc.VaList(bp+8, (*UnixFile)(unsafe.Pointer(pFile)).FzPath, HAVE_FULLFSYNC, isFullsync))
		}
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 17*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFile)).FzPath, bp+32)
		if rc == SQLITE_OK {
			full_fsync(tls, *(*int32)(unsafe.Pointer(bp + 32)), 0, 0)
			robust_close(tls, pFile, *(*int32)(unsafe.Pointer(bp + 32)), 40735)
		} else {
			rc = SQLITE_OK
		}
		*(*uint16)(unsafe.Pointer(pFile + 30)) &= libc.Uint16FromInt32(libc.CplInt32(UNIXFILE_DIRSYNC))
	}
	return rc
}

func unixTruncate(tls *libc.TLS, id uintptr, nByte I64) int32 {
	var pFile uintptr = id
	var rc int32

	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		return SQLITE_IOERR | int32(6)<<8
	}

	if (*UnixFile)(unsafe.Pointer(pFile)).FszChunk > 0 {
		nByte = (nByte + I64((*UnixFile)(unsafe.Pointer(pFile)).FszChunk) - int64(1)) / I64((*UnixFile)(unsafe.Pointer(pFile)).FszChunk) * I64((*UnixFile)(unsafe.Pointer(pFile)).FszChunk)
	}

	rc = robust_ftruncate(tls, (*UnixFile)(unsafe.Pointer(pFile)).Fh, nByte)
	if rc != 0 {
		storeLastErrno(tls, pFile, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
		return unixLogErrorAtLine(tls, SQLITE_IOERR|int32(6)<<8, ts+5659, (*UnixFile)(unsafe.Pointer(pFile)).FzPath, 40766)
	} else {
		if nByte < (*UnixFile)(unsafe.Pointer(pFile)).FmmapSize {
			(*UnixFile)(unsafe.Pointer(pFile)).FmmapSize = nByte
		}

		return SQLITE_OK
	}
	return int32(0)
}

func unixFileSize(tls *libc.TLS, id uintptr, pSize uintptr) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	var rc int32

	rc = (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 5*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(id)).Fh, bp)
	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		rc = 1
	}

	if rc != 0 {
		storeLastErrno(tls, id, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
		return SQLITE_IOERR | int32(7)<<8
	}
	*(*I64)(unsafe.Pointer(pSize)) = (*stat)(unsafe.Pointer(bp)).Fst_size

	if *(*I64)(unsafe.Pointer(pSize)) == int64(1) {
		*(*I64)(unsafe.Pointer(pSize)) = int64(0)
	}

	return SQLITE_OK
}

func fcntlSizeHint(tls *libc.TLS, pFile uintptr, nByte I64) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	if (*UnixFile)(unsafe.Pointer(pFile)).FszChunk > 0 {
		var nSize I64

		if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 5*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFile)).Fh, bp) != 0 {
			return SQLITE_IOERR | int32(7)<<8
		}

		nSize = (nByte + I64((*UnixFile)(unsafe.Pointer(pFile)).FszChunk) - int64(1)) / I64((*UnixFile)(unsafe.Pointer(pFile)).FszChunk) * I64((*UnixFile)(unsafe.Pointer(pFile)).FszChunk)
		if nSize > (*stat)(unsafe.Pointer(bp)).Fst_size {
			var nBlk int32 = (*stat)(unsafe.Pointer(bp)).Fst_blksize
			var nWrite int32 = 0
			var iWrite I64

			iWrite = (*stat)(unsafe.Pointer(bp)).Fst_size/X__off64_t(nBlk)*X__off64_t(nBlk) + X__off64_t(nBlk) - int64(1)

			for ; iWrite < nSize+I64(nBlk)-int64(1); iWrite = iWrite + I64(nBlk) {
				if iWrite >= nSize {
					iWrite = nSize - int64(1)
				}
				nWrite = seekAndWrite(tls, pFile, iWrite, ts+1636, 1)
				if nWrite != 1 {
					return SQLITE_IOERR | int32(3)<<8
				}
			}
		}
	}

	if (*UnixFile)(unsafe.Pointer(pFile)).FmmapSizeMax > int64(0) && nByte > (*UnixFile)(unsafe.Pointer(pFile)).FmmapSize {
		var rc int32
		if (*UnixFile)(unsafe.Pointer(pFile)).FszChunk <= 0 {
			if robust_ftruncate(tls, (*UnixFile)(unsafe.Pointer(pFile)).Fh, nByte) != 0 {
				storeLastErrno(tls, pFile, *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))))
				return unixLogErrorAtLine(tls, SQLITE_IOERR|int32(6)<<8, ts+5659, (*UnixFile)(unsafe.Pointer(pFile)).FzPath, 40887)
			}
		}

		rc = unixMapfile(tls, pFile, nByte)
		return rc
	}

	return SQLITE_OK
}

func unixModeBit(tls *libc.TLS, pFile uintptr, mask uint8, pArg uintptr) {
	if *(*int32)(unsafe.Pointer(pArg)) < 0 {
		*(*int32)(unsafe.Pointer(pArg)) = libc.Bool32(int32((*UnixFile)(unsafe.Pointer(pFile)).FctrlFlags)&int32(mask) != 0)
	} else if *(*int32)(unsafe.Pointer(pArg)) == 0 {
		*(*uint16)(unsafe.Pointer(pFile + 30)) &= uint16(^int32(mask))
	} else {
		*(*uint16)(unsafe.Pointer(pFile + 30)) |= uint16(int32(mask))
	}
}

func unixFileControl(tls *libc.TLS, id uintptr, op int32, pArg uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pFile uintptr = id
	switch op {
	case SQLITE_FCNTL_LOCKSTATE:
		{
			*(*int32)(unsafe.Pointer(pArg)) = int32((*UnixFile)(unsafe.Pointer(pFile)).FeFileLock)
			return SQLITE_OK

		}
	case SQLITE_FCNTL_LAST_ERRNO:
		{
			*(*int32)(unsafe.Pointer(pArg)) = (*UnixFile)(unsafe.Pointer(pFile)).FlastErrno
			return SQLITE_OK

		}
	case SQLITE_FCNTL_CHUNK_SIZE:
		{
			(*UnixFile)(unsafe.Pointer(pFile)).FszChunk = *(*int32)(unsafe.Pointer(pArg))
			return SQLITE_OK

		}
	case SQLITE_FCNTL_SIZE_HINT:
		{
			var rc int32
			Xsqlite3_io_error_benign = 1
			rc = fcntlSizeHint(tls, pFile, *(*I64)(unsafe.Pointer(pArg)))
			Xsqlite3_io_error_benign = 0
			return rc

		}
	case SQLITE_FCNTL_PERSIST_WAL:
		{
			unixModeBit(tls, pFile, uint8(UNIXFILE_PERSIST_WAL), pArg)
			return SQLITE_OK

		}
	case SQLITE_FCNTL_POWERSAFE_OVERWRITE:
		{
			unixModeBit(tls, pFile, uint8(UNIXFILE_PSOW), pArg)
			return SQLITE_OK

		}
	case SQLITE_FCNTL_VFSNAME:
		{
			*(*uintptr)(unsafe.Pointer(pArg)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, (*Sqlite3_vfs)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpVfs)).FzName))
			return SQLITE_OK

		}
	case SQLITE_FCNTL_TEMPFILENAME:
		{
			var zTFile uintptr = Xsqlite3_malloc64(tls, uint64((*Sqlite3_vfs)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpVfs)).FmxPathname))
			if zTFile != 0 {
				unixGetTempname(tls, (*Sqlite3_vfs)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpVfs)).FmxPathname, zTFile)
				*(*uintptr)(unsafe.Pointer(pArg)) = zTFile
			}
			return SQLITE_OK

		}
	case SQLITE_FCNTL_HAS_MOVED:
		{
			*(*int32)(unsafe.Pointer(pArg)) = fileHasMoved(tls, pFile)
			return SQLITE_OK

		}
	case SQLITE_FCNTL_MMAP_SIZE:
		{
			var newLimit I64 = *(*I64)(unsafe.Pointer(pArg))
			var rc int32 = SQLITE_OK
			if newLimit > Xsqlite3Config.FmxMmap {
				newLimit = Xsqlite3Config.FmxMmap
			}

			if newLimit > int64(0) && uint64(unsafe.Sizeof(Size_t(0))) < uint64(8) {
				newLimit = newLimit & int64(0x7FFFFFFF)
			}

			*(*I64)(unsafe.Pointer(pArg)) = (*UnixFile)(unsafe.Pointer(pFile)).FmmapSizeMax
			if newLimit >= int64(0) && newLimit != (*UnixFile)(unsafe.Pointer(pFile)).FmmapSizeMax && (*UnixFile)(unsafe.Pointer(pFile)).FnFetchOut == 0 {
				(*UnixFile)(unsafe.Pointer(pFile)).FmmapSizeMax = newLimit
				if (*UnixFile)(unsafe.Pointer(pFile)).FmmapSize > int64(0) {
					unixUnmapfile(tls, pFile)
					rc = unixMapfile(tls, pFile, int64(-1))
				}
			}
			return rc

		}

	case SQLITE_FCNTL_EXTERNAL_READER:
		{
			return unixFcntlExternalReader(tls, id, pArg)

		}
	}
	return SQLITE_NOTFOUND
}

func setDeviceCharacteristics(tls *libc.TLS, pFd uintptr) {
	if (*UnixFile)(unsafe.Pointer(pFd)).FsectorSize == 0 {
		if int32((*UnixFile)(unsafe.Pointer(pFd)).FctrlFlags)&UNIXFILE_PSOW != 0 {
			*(*int32)(unsafe.Pointer(pFd + 116)) |= SQLITE_IOCAP_POWERSAFE_OVERWRITE
		}

		(*UnixFile)(unsafe.Pointer(pFd)).FsectorSize = SQLITE_DEFAULT_SECTOR_SIZE
	}
}

func unixSectorSize(tls *libc.TLS, id uintptr) int32 {
	var pFd uintptr = id
	setDeviceCharacteristics(tls, pFd)
	return (*UnixFile)(unsafe.Pointer(pFd)).FsectorSize
}

func unixDeviceCharacteristics(tls *libc.TLS, id uintptr) int32 {
	var pFd uintptr = id
	setDeviceCharacteristics(tls, pFd)
	return (*UnixFile)(unsafe.Pointer(pFd)).FdeviceCharacteristics
}

func unixGetpagesize(tls *libc.TLS) int32 {
	return int32(libc.Xsysconf(tls, X_SC_PAGESIZE))
}

func unixFcntlExternalReader(tls *libc.TLS, pFile uintptr, piOut uintptr) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var rc int32 = SQLITE_OK
	*(*int32)(unsafe.Pointer(piOut)) = 0
	if (*UnixFile)(unsafe.Pointer(pFile)).FpShm != 0 {
		var pShmNode uintptr = (*UnixShm)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpShm)).FpShmNode

		libc.Xmemset(tls, bp+8, 0, uint64(unsafe.Sizeof(flock{})))
		(*flock)(unsafe.Pointer(bp + 8)).Fl_type = int16(F_WRLCK)
		(*flock)(unsafe.Pointer(bp + 8)).Fl_whence = int16(SEEK_SET)
		(*flock)(unsafe.Pointer(bp + 8)).Fl_start = int64((22+SQLITE_SHM_NLOCK)*4 + 3)
		(*flock)(unsafe.Pointer(bp + 8)).Fl_len = int64(SQLITE_SHM_NLOCK - 3)

		Xsqlite3_mutex_enter(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
		if (*(*func(*libc.TLS, int32, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 7*24 + 8)))(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm, F_GETLK64, libc.VaList(bp, bp+8)) < 0 {
			rc = SQLITE_IOERR | int32(15)<<8
		} else {
			*(*int32)(unsafe.Pointer(piOut)) = libc.Bool32(int32((*flock)(unsafe.Pointer(bp+8)).Fl_type) != F_UNLCK)
		}
		Xsqlite3_mutex_leave(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	}

	return rc
}

func unixShmSystemLock(tls *libc.TLS, pFile uintptr, lockType int32, ofst int32, n int32) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var pShmNode uintptr

	var rc int32 = SQLITE_OK

	pShmNode = (*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFile)).FpInode)).FpShmNode

	if (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm >= 0 {
		var res int32

		(*flock)(unsafe.Pointer(bp + 8)).Fl_type = int16(lockType)
		(*flock)(unsafe.Pointer(bp + 8)).Fl_whence = int16(SEEK_SET)
		(*flock)(unsafe.Pointer(bp + 8)).Fl_start = X__off_t(ofst)
		(*flock)(unsafe.Pointer(bp + 8)).Fl_len = X__off_t(n)
		res = (*(*func(*libc.TLS, int32, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 7*24 + 8)))(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm, F_SETLK64, libc.VaList(bp, bp+8))
		if res == -1 {
			rc = SQLITE_BUSY
		}
	}

	return rc
}

func unixShmRegionPerMap(tls *libc.TLS) int32 {
	var shmsz int32 = 32 * 1024
	var pgsz int32 = (*(*func(*libc.TLS) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 25*24 + 8)))(tls)

	if pgsz < shmsz {
		return 1
	}
	return pgsz / shmsz
}

func unixShmPurge(tls *libc.TLS, pFd uintptr) {
	var p uintptr = (*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pFd)).FpInode)).FpShmNode

	if p != 0 && (*UnixShmNode)(unsafe.Pointer(p)).FnRef == 0 {
		var nShmPerMap int32 = unixShmRegionPerMap(tls)
		var i int32

		Xsqlite3_mutex_free(tls, (*UnixShmNode)(unsafe.Pointer(p)).FpShmMutex)
		for i = 0; i < int32((*UnixShmNode)(unsafe.Pointer(p)).FnRegion); i = i + nShmPerMap {
			if (*UnixShmNode)(unsafe.Pointer(p)).FhShm >= 0 {
				(*(*func(*libc.TLS, uintptr, Size_t) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 23*24 + 8)))(tls, *(*uintptr)(unsafe.Pointer((*UnixShmNode)(unsafe.Pointer(p)).FapRegion + uintptr(i)*8)), uint64((*UnixShmNode)(unsafe.Pointer(p)).FszRegion))
			} else {
				Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*UnixShmNode)(unsafe.Pointer(p)).FapRegion + uintptr(i)*8)))
			}
		}
		Xsqlite3_free(tls, (*UnixShmNode)(unsafe.Pointer(p)).FapRegion)
		if (*UnixShmNode)(unsafe.Pointer(p)).FhShm >= 0 {
			robust_close(tls, pFd, (*UnixShmNode)(unsafe.Pointer(p)).FhShm, 41446)
			(*UnixShmNode)(unsafe.Pointer(p)).FhShm = -1
		}
		(*UnixInodeInfo)(unsafe.Pointer((*UnixShmNode)(unsafe.Pointer(p)).FpInode)).FpShmNode = uintptr(0)
		Xsqlite3_free(tls, p)
	}
}

func unixLockSharedMemory(tls *libc.TLS, pDbFd uintptr, pShmNode uintptr) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var rc int32 = SQLITE_OK

	(*flock)(unsafe.Pointer(bp + 8)).Fl_whence = int16(SEEK_SET)
	(*flock)(unsafe.Pointer(bp + 8)).Fl_start = int64((22+SQLITE_SHM_NLOCK)*4 + SQLITE_SHM_NLOCK)
	(*flock)(unsafe.Pointer(bp + 8)).Fl_len = int64(1)
	(*flock)(unsafe.Pointer(bp + 8)).Fl_type = int16(F_WRLCK)
	if (*(*func(*libc.TLS, int32, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 7*24 + 8)))(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm, F_GETLK64, libc.VaList(bp, bp+8)) != 0 {
		rc = SQLITE_IOERR | int32(15)<<8
	} else if int32((*flock)(unsafe.Pointer(bp+8)).Fl_type) == F_UNLCK {
		if (*UnixShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 {
			(*UnixShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked = U8(1)
			rc = SQLITE_READONLY | int32(5)<<8
		} else {
			rc = unixShmSystemLock(tls, pDbFd, F_WRLCK, (22+SQLITE_SHM_NLOCK)*4+SQLITE_SHM_NLOCK, 1)

			if rc == SQLITE_OK && robust_ftruncate(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm, int64(3)) != 0 {
				rc = unixLogErrorAtLine(tls, SQLITE_IOERR|int32(18)<<8, ts+5659, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FzFilename, 41503)
			}
		}
	} else if int32((*flock)(unsafe.Pointer(bp+8)).Fl_type) == F_WRLCK {
		rc = SQLITE_BUSY
	}

	if rc == SQLITE_OK {
		rc = unixShmSystemLock(tls, pDbFd, F_RDLCK, (22+SQLITE_SHM_NLOCK)*4+SQLITE_SHM_NLOCK, 1)
	}
	return rc
}

func unixOpenSharedMemory(tls *libc.TLS, pDbFd uintptr) int32 {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var p uintptr
	var pShmNode uintptr
	var rc int32
	var pInode uintptr
	var zShm uintptr
	var nShmFilename int32

	var zBasePath uintptr
	p = uintptr(0)
	rc = SQLITE_OK

	p = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(unixShm{})))
	if !(p == uintptr(0)) {
		goto __1
	}
	return SQLITE_NOMEM
__1:
	;
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(unixShm{})))

	unixEnterMutex(tls)
	pInode = (*UnixFile)(unsafe.Pointer(pDbFd)).FpInode
	pShmNode = (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpShmNode
	if !(pShmNode == uintptr(0)) {
		goto __2
	}
	zBasePath = (*UnixFile)(unsafe.Pointer(pDbFd)).FzPath

	if !((*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 5*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pDbFd)).Fh, bp+8) != 0) {
		goto __3
	}
	rc = SQLITE_IOERR | int32(7)<<8
	goto shm_open_err
__3:
	;
	nShmFilename = 6 + int32(libc.Xstrlen(tls, zBasePath))
	pShmNode = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(unixShmNode{}))+uint64(nShmFilename))
	if !(pShmNode == uintptr(0)) {
		goto __4
	}
	rc = SQLITE_NOMEM
	goto shm_open_err
__4:
	;
	libc.Xmemset(tls, pShmNode, 0, uint64(unsafe.Sizeof(unixShmNode{}))+uint64(nShmFilename))
	zShm = libc.AssignPtrUintptr(pShmNode+16, pShmNode+1*96)
	Xsqlite3_snprintf(tls, nShmFilename, zShm, ts+6491, libc.VaList(bp, zBasePath))

	(*unixShmNode)(unsafe.Pointer(pShmNode)).FhShm = -1
	(*UnixInodeInfo)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(pDbFd)).FpInode)).FpShmNode = pShmNode
	(*unixShmNode)(unsafe.Pointer(pShmNode)).FpInode = (*UnixFile)(unsafe.Pointer(pDbFd)).FpInode
	if !(Xsqlite3Config.FbCoreMutex != 0) {
		goto __5
	}
	(*unixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_FAST)
	if !((*unixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex == uintptr(0)) {
		goto __6
	}
	rc = SQLITE_NOMEM
	goto shm_open_err
__6:
	;
__5:
	;
	if !(int32((*UnixInodeInfo)(unsafe.Pointer(pInode)).FbProcessLock) == 0) {
		goto __7
	}
	if !(0 == Xsqlite3_uri_boolean(tls, (*UnixFile)(unsafe.Pointer(pDbFd)).FzPath, ts+6498, 0)) {
		goto __8
	}
	(*unixShmNode)(unsafe.Pointer(pShmNode)).FhShm = robust_open(tls, zShm, O_RDWR|O_CREAT|0100000,
		(*stat)(unsafe.Pointer(bp+8)).Fst_mode&X__mode_t(0777))
__8:
	;
	if !((*unixShmNode)(unsafe.Pointer(pShmNode)).FhShm < 0) {
		goto __9
	}
	(*unixShmNode)(unsafe.Pointer(pShmNode)).FhShm = robust_open(tls, zShm, O_RDONLY|0100000,
		(*stat)(unsafe.Pointer(bp+8)).Fst_mode&X__mode_t(0777))
	if !((*unixShmNode)(unsafe.Pointer(pShmNode)).FhShm < 0) {
		goto __10
	}
	rc = unixLogErrorAtLine(tls, Xsqlite3CantopenError(tls, 41628), ts+5623, zShm, 41628)
	goto shm_open_err
__10:
	;
	(*unixShmNode)(unsafe.Pointer(pShmNode)).FisReadonly = U8(1)
__9:
	;
	robustFchown(tls, (*unixShmNode)(unsafe.Pointer(pShmNode)).FhShm, (*stat)(unsafe.Pointer(bp+8)).Fst_uid, (*stat)(unsafe.Pointer(bp+8)).Fst_gid)

	rc = unixLockSharedMemory(tls, pDbFd, pShmNode)
	if !(rc != SQLITE_OK && rc != SQLITE_READONLY|int32(5)<<8) {
		goto __11
	}
	goto shm_open_err
__11:
	;
__7:
	;
__2:
	;
	(*unixShm)(unsafe.Pointer(p)).FpShmNode = pShmNode
	(*unixShmNode)(unsafe.Pointer(pShmNode)).FnRef++
	(*UnixFile)(unsafe.Pointer(pDbFd)).FpShm = p
	unixLeaveMutex(tls)

	Xsqlite3_mutex_enter(tls, (*unixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	(*unixShm)(unsafe.Pointer(p)).FpNext = (*unixShmNode)(unsafe.Pointer(pShmNode)).FpFirst
	(*unixShmNode)(unsafe.Pointer(pShmNode)).FpFirst = p
	Xsqlite3_mutex_leave(tls, (*unixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	return rc

shm_open_err:
	unixShmPurge(tls, pDbFd)
	Xsqlite3_free(tls, p)
	unixLeaveMutex(tls)
	return rc
}

func unixShmMap(tls *libc.TLS, fd uintptr, iRegion int32, szRegion int32, bExtend int32, pp uintptr) int32 {
	bp := tls.Alloc(132)
	defer tls.Free(132)

	var pDbFd uintptr
	var p uintptr
	var pShmNode uintptr
	var rc int32
	var nShmPerMap int32
	var nReqRegion int32
	var zFile uintptr

	var iPg int32
	var nMap int32
	var i int32
	var pMem uintptr
	var apNew uintptr
	var nByte int32

	pDbFd = fd
	rc = SQLITE_OK
	nShmPerMap = unixShmRegionPerMap(tls)

	if !((*UnixFile)(unsafe.Pointer(pDbFd)).FpShm == uintptr(0)) {
		goto __1
	}
	rc = unixOpenSharedMemory(tls, pDbFd)
	if !(rc != SQLITE_OK) {
		goto __2
	}
	return rc
__2:
	;
__1:
	;
	p = (*UnixFile)(unsafe.Pointer(pDbFd)).FpShm
	pShmNode = (*UnixShm)(unsafe.Pointer(p)).FpShmNode
	Xsqlite3_mutex_enter(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	if !((*UnixShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked != 0) {
		goto __3
	}
	rc = unixLockSharedMemory(tls, pDbFd, pShmNode)
	if !(rc != SQLITE_OK) {
		goto __4
	}
	goto shmpage_out
__4:
	;
	(*UnixShmNode)(unsafe.Pointer(pShmNode)).FisUnlocked = U8(0)
__3:
	;
	nReqRegion = (iRegion + nShmPerMap) / nShmPerMap * nShmPerMap

	if !(int32((*UnixShmNode)(unsafe.Pointer(pShmNode)).FnRegion) < nReqRegion) {
		goto __5
	}
	nByte = nReqRegion * szRegion

	(*UnixShmNode)(unsafe.Pointer(pShmNode)).FszRegion = szRegion

	if !((*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm >= 0) {
		goto __6
	}

	if !((*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 5*24 + 8)))(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm, bp) != 0) {
		goto __7
	}
	rc = SQLITE_IOERR | int32(19)<<8
	goto shmpage_out
__7:
	;
	if !((*stat)(unsafe.Pointer(bp)).Fst_size < X__off64_t(nByte)) {
		goto __8
	}

	if !!(bExtend != 0) {
		goto __9
	}
	goto shmpage_out
	goto __10
__9:
	;
	iPg = int32((*stat)(unsafe.Pointer(bp)).Fst_size / X__off64_t(pgsz))
__11:
	if !(iPg < nByte/pgsz) {
		goto __13
	}
	*(*int32)(unsafe.Pointer(bp + 128)) = 0
	if !(seekAndWriteFd(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm, int64(iPg*pgsz+pgsz-1), ts+1636, 1, bp+128) != 1) {
		goto __14
	}
	zFile = (*UnixShmNode)(unsafe.Pointer(pShmNode)).FzFilename
	rc = unixLogErrorAtLine(tls, SQLITE_IOERR|int32(19)<<8, ts+5694, zFile, 41772)
	goto shmpage_out
__14:
	;
	goto __12
__12:
	iPg++
	goto __11
	goto __13
__13:
	;
__10:
	;
__8:
	;
__6:
	;
	apNew = Xsqlite3_realloc(tls,
		(*UnixShmNode)(unsafe.Pointer(pShmNode)).FapRegion, int32(uint64(nReqRegion)*uint64(unsafe.Sizeof(uintptr(0)))))
	if !!(apNew != 0) {
		goto __15
	}
	rc = SQLITE_IOERR | int32(12)<<8
	goto shmpage_out
__15:
	;
	(*UnixShmNode)(unsafe.Pointer(pShmNode)).FapRegion = apNew
__16:
	if !(int32((*UnixShmNode)(unsafe.Pointer(pShmNode)).FnRegion) < nReqRegion) {
		goto __17
	}
	nMap = szRegion * nShmPerMap
	if !((*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm >= 0) {
		goto __18
	}
	pMem = (*(*func(*libc.TLS, uintptr, Size_t, int32, int32, int32, Off_t) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 22*24 + 8)))(tls, uintptr(0), uint64(nMap),
		func() int32 {
			if (*UnixShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 {
				return PROT_READ
			}
			return PROT_READ | PROT_WRITE
		}(),
		MAP_SHARED, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm, I64(szRegion)*I64((*UnixShmNode)(unsafe.Pointer(pShmNode)).FnRegion))
	if !(pMem == libc.UintptrFromInt32(-1)) {
		goto __20
	}
	rc = unixLogErrorAtLine(tls, SQLITE_IOERR|int32(21)<<8, ts+5781, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FzFilename, 41799)
	goto shmpage_out
__20:
	;
	goto __19
__18:
	pMem = Xsqlite3_malloc64(tls, uint64(nMap))
	if !(pMem == uintptr(0)) {
		goto __21
	}
	rc = SQLITE_NOMEM
	goto shmpage_out
__21:
	;
	libc.Xmemset(tls, pMem, 0, uint64(nMap))
__19:
	;
	i = 0
__22:
	if !(i < nShmPerMap) {
		goto __24
	}
	*(*uintptr)(unsafe.Pointer((*UnixShmNode)(unsafe.Pointer(pShmNode)).FapRegion + uintptr(int32((*UnixShmNode)(unsafe.Pointer(pShmNode)).FnRegion)+i)*8)) = pMem + uintptr(szRegion*i)
	goto __23
__23:
	i++
	goto __22
	goto __24
__24:
	;
	*(*U16)(unsafe.Pointer(pShmNode + 32)) += U16(nShmPerMap)
	goto __16
__17:
	;
__5:
	;
shmpage_out:
	if !(int32((*UnixShmNode)(unsafe.Pointer(pShmNode)).FnRegion) > iRegion) {
		goto __25
	}
	*(*uintptr)(unsafe.Pointer(pp)) = *(*uintptr)(unsafe.Pointer((*UnixShmNode)(unsafe.Pointer(pShmNode)).FapRegion + uintptr(iRegion)*8))
	goto __26
__25:
	*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
__26:
	;
	if !((*UnixShmNode)(unsafe.Pointer(pShmNode)).FisReadonly != 0 && rc == SQLITE_OK) {
		goto __27
	}
	rc = SQLITE_READONLY
__27:
	;
	Xsqlite3_mutex_leave(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	return rc
}

var pgsz int32 = 4096

func unixShmLock(tls *libc.TLS, fd uintptr, ofst int32, n int32, flags int32) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pDbFd uintptr = fd
	var p uintptr
	var pShmNode uintptr
	var rc int32 = SQLITE_OK
	var mask U16
	var aLock uintptr

	p = (*UnixFile)(unsafe.Pointer(pDbFd)).FpShm
	if p == uintptr(0) {
		return SQLITE_IOERR | int32(20)<<8
	}
	pShmNode = (*UnixShm)(unsafe.Pointer(p)).FpShmNode
	if pShmNode == uintptr(0) {
		return SQLITE_IOERR | int32(20)<<8
	}
	aLock = pShmNode + 64

	mask = U16(int32(1)<<(ofst+n) - int32(1)<<ofst)

	Xsqlite3_mutex_enter(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)

	if flags&SQLITE_SHM_UNLOCK != 0 {
		if (int32((*UnixShm)(unsafe.Pointer(p)).FexclMask)|int32((*UnixShm)(unsafe.Pointer(p)).FsharedMask))&int32(mask) != 0 {
			var ii int32
			var bUnlock int32 = 1

			for ii = ofst; ii < ofst+n; ii++ {
				if *(*int32)(unsafe.Pointer(aLock + uintptr(ii)*4)) > func() int32 {
					if int32((*UnixShm)(unsafe.Pointer(p)).FsharedMask)&(int32(1)<<ii) != 0 {
						return 1
					}
					return 0
				}() {
					bUnlock = 0
				}
			}

			if bUnlock != 0 {
				rc = unixShmSystemLock(tls, pDbFd, F_UNLCK, ofst+(22+SQLITE_SHM_NLOCK)*4, n)
				if rc == SQLITE_OK {
					libc.Xmemset(tls, aLock+uintptr(ofst)*4, 0, uint64(unsafe.Sizeof(int32(0)))*uint64(n))
				}
			} else if int32((*UnixShm)(unsafe.Pointer(p)).FsharedMask)&(int32(1)<<ofst) != 0 {
				*(*int32)(unsafe.Pointer(aLock + uintptr(ofst)*4))--
			}

			if rc == SQLITE_OK {
				*(*U16)(unsafe.Pointer(p + 20)) &= U16(^int32(mask))
				*(*U16)(unsafe.Pointer(p + 18)) &= U16(^int32(mask))
			}
		}
	} else if flags&SQLITE_SHM_SHARED != 0 {
		if int32((*UnixShm)(unsafe.Pointer(p)).FsharedMask)&int32(mask) == 0 {
			if *(*int32)(unsafe.Pointer(aLock + uintptr(ofst)*4)) < 0 {
				rc = SQLITE_BUSY
			} else if *(*int32)(unsafe.Pointer(aLock + uintptr(ofst)*4)) == 0 {
				rc = unixShmSystemLock(tls, pDbFd, F_RDLCK, ofst+(22+SQLITE_SHM_NLOCK)*4, n)
			}

			if rc == SQLITE_OK {
				*(*U16)(unsafe.Pointer(p + 18)) |= U16(int32(mask))
				*(*int32)(unsafe.Pointer(aLock + uintptr(ofst)*4))++
			}
		}
	} else {
		var ii int32
		for ii = ofst; ii < ofst+n; ii++ {
			if int32((*UnixShm)(unsafe.Pointer(p)).FexclMask)&(int32(1)<<ii) == 0 && *(*int32)(unsafe.Pointer(aLock + uintptr(ii)*4)) != 0 {
				rc = SQLITE_BUSY
				break
			}
		}

		if rc == SQLITE_OK {
			rc = unixShmSystemLock(tls, pDbFd, F_WRLCK, ofst+(22+SQLITE_SHM_NLOCK)*4, n)
			if rc == SQLITE_OK {
				*(*U16)(unsafe.Pointer(p + 20)) |= U16(int32(mask))
				for ii = ofst; ii < ofst+n; ii++ {
					*(*int32)(unsafe.Pointer(aLock + uintptr(ii)*4)) = -1
				}
			}
		}
	}

	Xsqlite3_mutex_leave(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6511, libc.VaList(bp, int32((*UnixShm)(unsafe.Pointer(p)).Fid), libc.Xgetpid(tls), int32((*UnixShm)(unsafe.Pointer(p)).FsharedMask), int32((*UnixShm)(unsafe.Pointer(p)).FexclMask)))
	}
	return rc
}

func unixShmBarrier(tls *libc.TLS, fd uintptr) {
	_ = fd

	unixEnterMutex(tls)
	unixLeaveMutex(tls)
}

func unixShmUnmap(tls *libc.TLS, fd uintptr, deleteFlag int32) int32 {
	var p uintptr
	var pShmNode uintptr
	var pp uintptr
	var pDbFd uintptr

	pDbFd = fd
	p = (*UnixFile)(unsafe.Pointer(pDbFd)).FpShm
	if p == uintptr(0) {
		return SQLITE_OK
	}
	pShmNode = (*UnixShm)(unsafe.Pointer(p)).FpShmNode

	Xsqlite3_mutex_enter(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)
	for pp = pShmNode + 56; *(*uintptr)(unsafe.Pointer(pp)) != p; pp = *(*uintptr)(unsafe.Pointer(pp)) + 8 {
	}
	*(*uintptr)(unsafe.Pointer(pp)) = (*UnixShm)(unsafe.Pointer(p)).FpNext

	Xsqlite3_free(tls, p)
	(*UnixFile)(unsafe.Pointer(pDbFd)).FpShm = uintptr(0)
	Xsqlite3_mutex_leave(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FpShmMutex)

	unixEnterMutex(tls)

	(*UnixShmNode)(unsafe.Pointer(pShmNode)).FnRef--
	if (*UnixShmNode)(unsafe.Pointer(pShmNode)).FnRef == 0 {
		if deleteFlag != 0 && (*UnixShmNode)(unsafe.Pointer(pShmNode)).FhShm >= 0 {
			(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 16*24 + 8)))(tls, (*UnixShmNode)(unsafe.Pointer(pShmNode)).FzFilename)
		}
		unixShmPurge(tls, pDbFd)
	}
	unixLeaveMutex(tls)

	return SQLITE_OK
}

func unixUnmapfile(tls *libc.TLS, pFd uintptr) {
	if (*UnixFile)(unsafe.Pointer(pFd)).FpMapRegion != 0 {
		(*(*func(*libc.TLS, uintptr, Size_t) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 23*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFd)).FpMapRegion, uint64((*UnixFile)(unsafe.Pointer(pFd)).FmmapSizeActual))
		(*UnixFile)(unsafe.Pointer(pFd)).FpMapRegion = uintptr(0)
		(*UnixFile)(unsafe.Pointer(pFd)).FmmapSize = int64(0)
		(*UnixFile)(unsafe.Pointer(pFd)).FmmapSizeActual = int64(0)
	}
}

func unixRemapfile(tls *libc.TLS, pFd uintptr, nNew I64) {
	var zErr uintptr = ts + 5781
	var h int32 = (*UnixFile)(unsafe.Pointer(pFd)).Fh
	var pOrig uintptr = (*UnixFile)(unsafe.Pointer(pFd)).FpMapRegion
	var nOrig I64 = (*UnixFile)(unsafe.Pointer(pFd)).FmmapSizeActual
	var pNew uintptr = uintptr(0)
	var flags int32 = PROT_READ

	if pOrig != 0 {
		var nReuse I64 = (*UnixFile)(unsafe.Pointer(pFd)).FmmapSize
		var pReq uintptr = pOrig + uintptr(nReuse)

		if nReuse != nOrig {
			(*(*func(*libc.TLS, uintptr, Size_t) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 23*24 + 8)))(tls, pReq, uint64(nOrig-nReuse))
		}

		pNew = (*(*func(*libc.TLS, uintptr, Size_t, Size_t, int32, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 24*24 + 8)))(tls, pOrig, uint64(nReuse), uint64(nNew), MREMAP_MAYMOVE, 0)
		zErr = ts + 5793

		if pNew == libc.UintptrFromInt32(-1) || pNew == uintptr(0) {
			(*(*func(*libc.TLS, uintptr, Size_t) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 23*24 + 8)))(tls, pOrig, uint64(nReuse))
		}
	}

	if pNew == uintptr(0) {
		pNew = (*(*func(*libc.TLS, uintptr, Size_t, int32, int32, int32, Off_t) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 22*24 + 8)))(tls, uintptr(0), uint64(nNew), flags, MAP_SHARED, h, int64(0))
	}

	if pNew == libc.UintptrFromInt32(-1) {
		pNew = uintptr(0)
		nNew = int64(0)
		unixLogErrorAtLine(tls, SQLITE_OK, zErr, (*UnixFile)(unsafe.Pointer(pFd)).FzPath, 42173)

		(*UnixFile)(unsafe.Pointer(pFd)).FmmapSizeMax = int64(0)
	}
	(*UnixFile)(unsafe.Pointer(pFd)).FpMapRegion = pNew
	(*UnixFile)(unsafe.Pointer(pFd)).FmmapSize = libc.AssignPtrInt64(pFd+88, nNew)
}

func unixMapfile(tls *libc.TLS, pFd uintptr, nMap I64) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	if (*UnixFile)(unsafe.Pointer(pFd)).FnFetchOut > 0 {
		return SQLITE_OK
	}

	if nMap < int64(0) {
		if (*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 5*24 + 8)))(tls, (*UnixFile)(unsafe.Pointer(pFd)).Fh, bp) != 0 {
			return SQLITE_IOERR | int32(7)<<8
		}
		nMap = (*stat)(unsafe.Pointer(bp)).Fst_size
	}
	if nMap > (*UnixFile)(unsafe.Pointer(pFd)).FmmapSizeMax {
		nMap = (*UnixFile)(unsafe.Pointer(pFd)).FmmapSizeMax
	}

	if nMap != (*UnixFile)(unsafe.Pointer(pFd)).FmmapSize {
		unixRemapfile(tls, pFd, nMap)
	}

	return SQLITE_OK
}

func unixFetch(tls *libc.TLS, fd uintptr, iOff I64, nAmt int32, pp uintptr) int32 {
	var pFd uintptr = fd
	*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)

	if (*UnixFile)(unsafe.Pointer(pFd)).FmmapSizeMax > int64(0) {
		if (*UnixFile)(unsafe.Pointer(pFd)).FpMapRegion == uintptr(0) {
			var rc int32 = unixMapfile(tls, pFd, int64(-1))
			if rc != SQLITE_OK {
				return rc
			}
		}
		if (*UnixFile)(unsafe.Pointer(pFd)).FmmapSize >= iOff+I64(nAmt) {
			*(*uintptr)(unsafe.Pointer(pp)) = (*UnixFile)(unsafe.Pointer(pFd)).FpMapRegion + uintptr(iOff)
			(*UnixFile)(unsafe.Pointer(pFd)).FnFetchOut++
		}
	}
	return SQLITE_OK
}

func unixUnfetch(tls *libc.TLS, fd uintptr, iOff I64, p uintptr) int32 {
	var pFd uintptr = fd
	_ = iOff

	if p != 0 {
		(*UnixFile)(unsafe.Pointer(pFd)).FnFetchOut--
	} else {
		unixUnmapfile(tls, pFd)
	}

	return SQLITE_OK
}

var posixIoMethods = Sqlite3_io_methods{FiVersion: 3, FxClose: 0, FxRead: 0, FxWrite: 0, FxTruncate: 0, FxSync: 0, FxFileSize: 0, FxLock: 0, FxUnlock: 0, FxCheckReservedLock: 0, FxFileControl: 0, FxSectorSize: 0, FxDeviceCharacteristics: 0, FxShmMap: 0, FxShmLock: 0, FxShmBarrier: 0, FxShmUnmap: 0, FxFetch: 0, FxUnfetch: 0}

func posixIoFinderImpl(tls *libc.TLS, z uintptr, p uintptr) uintptr {
	_ = z
	_ = p
	return uintptr(unsafe.Pointer(&posixIoMethods))
}

var posixIoFinder uintptr = 0
var nolockIoMethods = Sqlite3_io_methods{FiVersion: 3, FxClose: 0, FxRead: 0, FxWrite: 0, FxTruncate: 0, FxSync: 0, FxFileSize: 0, FxLock: 0, FxUnlock: 0, FxCheckReservedLock: 0, FxFileControl: 0, FxSectorSize: 0, FxDeviceCharacteristics: 0, FxShmLock: 0, FxShmBarrier: 0, FxShmUnmap: 0, FxFetch: 0, FxUnfetch: 0}

func nolockIoFinderImpl(tls *libc.TLS, z uintptr, p uintptr) uintptr {
	_ = z
	_ = p
	return uintptr(unsafe.Pointer(&nolockIoMethods))
}

var nolockIoFinder uintptr = 0
var dotlockIoMethods = Sqlite3_io_methods{FiVersion: 1, FxClose: 0, FxRead: 0, FxWrite: 0, FxTruncate: 0, FxSync: 0, FxFileSize: 0, FxLock: 0, FxUnlock: 0, FxCheckReservedLock: 0, FxFileControl: 0, FxSectorSize: 0, FxDeviceCharacteristics: 0, FxShmLock: 0, FxShmBarrier: 0, FxShmUnmap: 0, FxFetch: 0, FxUnfetch: 0}

func dotlockIoFinderImpl(tls *libc.TLS, z uintptr, p uintptr) uintptr {
	_ = z
	_ = p
	return uintptr(unsafe.Pointer(&dotlockIoMethods))
}

var dotlockIoFinder uintptr = 0

type Finder_type = uintptr

func fillInUnixFile(tls *libc.TLS, pVfs uintptr, h int32, pId uintptr, zFilename uintptr, ctrlFlags int32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pLockingStyle uintptr
	var pNew uintptr = pId
	var rc int32 = SQLITE_OK

	if Xsqlite3OSTrace != 0 {
		Xsqlite3DebugPrintf(tls, ts+6552, libc.VaList(bp, h, zFilename))
	}
	(*UnixFile)(unsafe.Pointer(pNew)).Fh = h
	(*UnixFile)(unsafe.Pointer(pNew)).FpVfs = pVfs
	(*UnixFile)(unsafe.Pointer(pNew)).FzPath = zFilename
	(*UnixFile)(unsafe.Pointer(pNew)).FctrlFlags = uint16(U8(ctrlFlags))
	(*UnixFile)(unsafe.Pointer(pNew)).FmmapSizeMax = Xsqlite3Config.FszMmap
	if Xsqlite3_uri_boolean(tls, func() uintptr {
		if ctrlFlags&UNIXFILE_URI != 0 {
			return zFilename
		}
		return uintptr(0)
	}(),
		ts+6569, SQLITE_POWERSAFE_OVERWRITE) != 0 {
		*(*uint16)(unsafe.Pointer(pNew + 30)) |= uint16(UNIXFILE_PSOW)
	}
	if libc.Xstrcmp(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FzName, ts+6574) == 0 {
		*(*uint16)(unsafe.Pointer(pNew + 30)) |= uint16(UNIXFILE_EXCL)
	}

	if ctrlFlags&UNIXFILE_NOLOCK != 0 {
		pLockingStyle = uintptr(unsafe.Pointer(&nolockIoMethods))
	} else {
		pLockingStyle = (*(**struct {
			f func(*libc.TLS, uintptr, uintptr) uintptr
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData}))).f(tls, zFilename, pNew)
	}

	if pLockingStyle == uintptr(unsafe.Pointer(&posixIoMethods)) {
		unixEnterMutex(tls)
		rc = findInodeInfo(tls, pNew, pNew+16)
		if rc != SQLITE_OK {
			robust_close(tls, pNew, h, 42676)
			h = -1
		}
		unixLeaveMutex(tls)
	} else if pLockingStyle == uintptr(unsafe.Pointer(&dotlockIoMethods)) {
		var zLockFile uintptr
		var nFilename int32

		nFilename = int32(libc.Xstrlen(tls, zFilename)) + 6
		zLockFile = Xsqlite3_malloc64(tls, uint64(nFilename))
		if zLockFile == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			Xsqlite3_snprintf(tls, nFilename, zLockFile, ts+6584, libc.VaList(bp+16, zFilename))
		}
		(*UnixFile)(unsafe.Pointer(pNew)).FlockingContext = zLockFile
	}

	storeLastErrno(tls, pNew, 0)
	if rc != SQLITE_OK {
		if h >= 0 {
			robust_close(tls, pNew, h, 42761)
		}
	} else {
		(*Sqlite3_file)(unsafe.Pointer(pId)).FpMethods = pLockingStyle
		libc.AtomicAddInt32(&Xsqlite3_open_file_count, int32(+1))
		verifyDbFile(tls, pNew)
	}
	return rc
}

var azTempDirs = [6]uintptr{
	uintptr(0),
	uintptr(0),
	ts + 6592,
	ts + 6601,
	ts + 6610,
	ts + 1649,
}

func unixTempFileInit(tls *libc.TLS) {
	azTempDirs[0] = libc.Xgetenv(tls, ts+6615)
	azTempDirs[1] = libc.Xgetenv(tls, ts+6629)
}

func unixTempFileDir(tls *libc.TLS) uintptr {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	var i uint32 = uint32(0)

	var zDir uintptr = Xsqlite3_temp_directory

	for 1 != 0 {
		if zDir != uintptr(0) &&
			(*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 4*24 + 8)))(tls, zDir, bp) == 0 &&
			(*stat)(unsafe.Pointer(bp)).Fst_mode&X__mode_t(0170000) == X__mode_t(0040000) &&
			(*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 2*24 + 8)))(tls, zDir, 03) == 0 {
			return zDir
		}
		if uint64(i) >= uint64(unsafe.Sizeof(azTempDirs))/uint64(unsafe.Sizeof(uintptr(0))) {
			break
		}
		zDir = azTempDirs[libc.PostIncUint32(&i, 1)]
	}
	return uintptr(0)
}

func unixGetTempname(tls *libc.TLS, nBuf int32, zBuf uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var zDir uintptr
	var iLimit int32 = 0
	var rc int32 = SQLITE_OK

	*(*uint8)(unsafe.Pointer(zBuf)) = uint8(0)
	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		return SQLITE_IOERR
	}

	Xsqlite3_mutex_enter(tls, Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_VFS1))
	zDir = unixTempFileDir(tls)
	if zDir == uintptr(0) {
		rc = SQLITE_IOERR | int32(25)<<8
	} else {
		for __ccgo := true; __ccgo; __ccgo = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 2*24 + 8)))(tls, zBuf, 0) == 0 {
			Xsqlite3_randomness(tls, int32(unsafe.Sizeof(U64(0))), bp+24)

			*(*uint8)(unsafe.Pointer(zBuf + uintptr(nBuf-2))) = uint8(0)
			Xsqlite3_snprintf(tls, nBuf, zBuf, ts+6636,
				libc.VaList(bp, zDir, *(*U64)(unsafe.Pointer(bp + 24)), 0))
			if int32(*(*uint8)(unsafe.Pointer(zBuf + uintptr(nBuf-2)))) != 0 || libc.PostIncInt32(&iLimit, 1) > 10 {
				rc = SQLITE_ERROR
				break
			}
		}
	}
	Xsqlite3_mutex_leave(tls, Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_VFS1))
	return rc
}

func findReusableFd(tls *libc.TLS, zPath uintptr, flags int32) uintptr {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	var pUnused uintptr = uintptr(0)

	unixEnterMutex(tls)

	if inodeList != uintptr(0) && 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 4*24 + 8)))(tls, zPath, bp) {
		var pInode uintptr

		pInode = inodeList
		for pInode != 0 && ((*UnixInodeInfo)(unsafe.Pointer(pInode)).FfileId.Fdev != (*stat)(unsafe.Pointer(bp)).Fst_dev ||
			(*UnixInodeInfo)(unsafe.Pointer(pInode)).FfileId.Fino != (*stat)(unsafe.Pointer(bp)).Fst_ino) {
			pInode = (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpNext
		}
		if pInode != 0 {
			var pp uintptr

			Xsqlite3_mutex_enter(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
			flags = flags & (SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE)
			for pp = pInode + 40; *(*uintptr)(unsafe.Pointer(pp)) != 0 && (*UnixUnusedFd)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).Fflags != flags; pp = *(*uintptr)(unsafe.Pointer(pp)) + 8 {
			}
			pUnused = *(*uintptr)(unsafe.Pointer(pp))
			if pUnused != 0 {
				*(*uintptr)(unsafe.Pointer(pp)) = (*UnixUnusedFd)(unsafe.Pointer(pUnused)).FpNext
			}
			Xsqlite3_mutex_leave(tls, (*UnixInodeInfo)(unsafe.Pointer(pInode)).FpLockMutex)
		}
	}
	unixLeaveMutex(tls)
	return pUnused
}

func getFileMode(tls *libc.TLS, zFile uintptr, pMode uintptr, pUid uintptr, pGid uintptr) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	var rc int32 = SQLITE_OK
	if 0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 4*24 + 8)))(tls, zFile, bp) {
		*(*Mode_t)(unsafe.Pointer(pMode)) = (*stat)(unsafe.Pointer(bp)).Fst_mode & X__mode_t(0777)
		*(*Uid_t)(unsafe.Pointer(pUid)) = (*stat)(unsafe.Pointer(bp)).Fst_uid
		*(*Gid_t)(unsafe.Pointer(pGid)) = (*stat)(unsafe.Pointer(bp)).Fst_gid
	} else {
		rc = SQLITE_IOERR | int32(7)<<8
	}
	return rc
}

func findCreateFileMode(tls *libc.TLS, zPath uintptr, flags int32, pMode uintptr, pUid uintptr, pGid uintptr) int32 {
	bp := tls.Alloc(513)
	defer tls.Free(513)

	var rc int32 = SQLITE_OK
	*(*Mode_t)(unsafe.Pointer(pMode)) = Mode_t(0)
	*(*Uid_t)(unsafe.Pointer(pUid)) = Uid_t(0)
	*(*Gid_t)(unsafe.Pointer(pGid)) = Gid_t(0)
	if flags&(SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) != 0 {
		var nDb int32

		nDb = Xsqlite3Strlen30(tls, zPath) - 1
		for nDb > 0 && int32(*(*uint8)(unsafe.Pointer(zPath + uintptr(nDb)))) != '.' {
			if int32(*(*uint8)(unsafe.Pointer(zPath + uintptr(nDb)))) == '-' {
				libc.Xmemcpy(tls, bp, zPath, uint64(nDb))
				*(*uint8)(unsafe.Pointer(bp + uintptr(nDb))) = uint8(0)
				rc = getFileMode(tls, bp, pMode, pUid, pGid)
				break
			}
			nDb--
		}
	} else if flags&SQLITE_OPEN_DELETEONCLOSE != 0 {
		*(*Mode_t)(unsafe.Pointer(pMode)) = Mode_t(0600)
	} else if flags&SQLITE_OPEN_URI != 0 {
		var z uintptr = Xsqlite3_uri_parameter(tls, zPath, ts+6653)
		if z != 0 {
			rc = getFileMode(tls, z, pMode, pUid, pGid)
		}
	}
	return rc
}

func unixOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr, pFile uintptr, flags int32, pOutFlags uintptr) int32 {
	bp := tls.Alloc(552)
	defer tls.Free(552)

	var p uintptr
	var fd int32
	var openFlags int32
	var eType int32
	var noLock int32
	var rc int32
	var ctrlFlags int32

	var isExclusive int32
	var isDelete int32
	var isCreate int32
	var isReadonly int32
	var isReadWrite int32

	var isNewJrnl int32

	var zName uintptr
	var pUnused uintptr
	var rc2 int32

	p = pFile
	fd = -1
	openFlags = 0
	eType = flags & 0x0FFF00
	rc = SQLITE_OK
	ctrlFlags = 0
	isExclusive = flags & SQLITE_OPEN_EXCLUSIVE
	isDelete = flags & SQLITE_OPEN_DELETEONCLOSE
	isCreate = flags & SQLITE_OPEN_CREATE
	isReadonly = flags & SQLITE_OPEN_READONLY
	isReadWrite = flags & SQLITE_OPEN_READWRITE
	isNewJrnl = libc.Bool32(isCreate != 0 && (eType == SQLITE_OPEN_SUPER_JOURNAL ||
		eType == SQLITE_OPEN_MAIN_JOURNAL ||
		eType == SQLITE_OPEN_WAL))
	zName = zPath

	if !(libc.AtomicLoadInt32(&randomnessPid) != libc.Xgetpid(tls)) {
		goto __1
	}
	libc.AtomicStoreInt32(&randomnessPid, libc.Xgetpid(tls))
	Xsqlite3_randomness(tls, 0, uintptr(0))
__1:
	;
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(UnixFile{})))

	if !(eType == SQLITE_OPEN_MAIN_DB) {
		goto __2
	}
	pUnused = findReusableFd(tls, zName, flags)
	if !(pUnused != 0) {
		goto __4
	}
	fd = (*UnixUnusedFd)(unsafe.Pointer(pUnused)).Ffd
	goto __5
__4:
	pUnused = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(UnixUnusedFd{})))
	if !!(pUnused != 0) {
		goto __6
	}
	return SQLITE_NOMEM
__6:
	;
__5:
	;
	(*UnixFile)(unsafe.Pointer(p)).FpPreallocatedUnused = pUnused

	goto __3
__2:
	if !!(zName != 0) {
		goto __7
	}

	rc = unixGetTempname(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname, bp+24)
	if !(rc != SQLITE_OK) {
		goto __8
	}
	return rc
__8:
	;
	zName = bp + 24

__7:
	;
__3:
	;
	if !(isReadonly != 0) {
		goto __9
	}
	openFlags = openFlags | O_RDONLY
__9:
	;
	if !(isReadWrite != 0) {
		goto __10
	}
	openFlags = openFlags | O_RDWR
__10:
	;
	if !(isCreate != 0) {
		goto __11
	}
	openFlags = openFlags | O_CREAT
__11:
	;
	if !(isExclusive != 0) {
		goto __12
	}
	openFlags = openFlags | (O_EXCL | 0100000)
__12:
	;
	openFlags = openFlags | (0 | O_BINARY | 0100000)

	if !(fd < 0) {
		goto __13
	}
	rc = findCreateFileMode(tls, zName, flags, bp+540, bp+544, bp+548)
	if !(rc != SQLITE_OK) {
		goto __14
	}

	return rc
__14:
	;
	fd = robust_open(tls, zName, openFlags, *(*Mode_t)(unsafe.Pointer(bp + 540)))
	if !(Xsqlite3OSTrace != 0) {
		goto __15
	}
	Xsqlite3DebugPrintf(tls, ts+6660, libc.VaList(bp, fd, zName, openFlags))
__15:
	;
	if !(fd < 0) {
		goto __16
	}
	if !(isNewJrnl != 0 && *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) == EACCES && (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 2*24 + 8)))(tls, zName, F_OK) != 0) {
		goto __17
	}

	rc = SQLITE_READONLY | int32(6)<<8
	goto __18
__17:
	if !(*(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) != EISDIR && isReadWrite != 0) {
		goto __19
	}

	flags = flags & libc.CplInt32(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE)
	openFlags = openFlags & libc.CplInt32(O_RDWR|O_CREAT)
	flags = flags | SQLITE_OPEN_READONLY
	openFlags = openFlags | O_RDONLY
	isReadonly = 1
	fd = robust_open(tls, zName, openFlags, *(*Mode_t)(unsafe.Pointer(bp + 540)))
__19:
	;
__18:
	;
__16:
	;
	if !(fd < 0) {
		goto __20
	}
	rc2 = unixLogErrorAtLine(tls, Xsqlite3CantopenError(tls, 43202), ts+5623, zName, 43202)
	if !(rc == SQLITE_OK) {
		goto __21
	}
	rc = rc2
__21:
	;
	goto open_finished
__20:
	;
	if !(*(*Mode_t)(unsafe.Pointer(bp + 540)) != 0 && flags&(SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) != 0) {
		goto __22
	}
	robustFchown(tls, fd, *(*Uid_t)(unsafe.Pointer(bp + 544)), *(*Gid_t)(unsafe.Pointer(bp + 548)))
__22:
	;
__13:
	;
	if !(pOutFlags != 0) {
		goto __23
	}
	*(*int32)(unsafe.Pointer(pOutFlags)) = flags
__23:
	;
	if !((*UnixFile)(unsafe.Pointer(p)).FpPreallocatedUnused != 0) {
		goto __24
	}
	(*UnixUnusedFd)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(p)).FpPreallocatedUnused)).Ffd = fd
	(*UnixUnusedFd)(unsafe.Pointer((*UnixFile)(unsafe.Pointer(p)).FpPreallocatedUnused)).Fflags = flags & (SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE)
__24:
	;
	if !(isDelete != 0) {
		goto __25
	}
	(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 16*24 + 8)))(tls, zName)
__25:
	;
	if !(isDelete != 0) {
		goto __26
	}
	ctrlFlags = ctrlFlags | UNIXFILE_DELETE
__26:
	;
	if !(isReadonly != 0) {
		goto __27
	}
	ctrlFlags = ctrlFlags | UNIXFILE_RDONLY
__27:
	;
	noLock = libc.Bool32(eType != SQLITE_OPEN_MAIN_DB)
	if !(noLock != 0) {
		goto __28
	}
	ctrlFlags = ctrlFlags | UNIXFILE_NOLOCK
__28:
	;
	if !(isNewJrnl != 0) {
		goto __29
	}
	ctrlFlags = ctrlFlags | UNIXFILE_DIRSYNC
__29:
	;
	if !(flags&SQLITE_OPEN_URI != 0) {
		goto __30
	}
	ctrlFlags = ctrlFlags | UNIXFILE_URI
__30:
	;
	rc = fillInUnixFile(tls, pVfs, fd, pFile, zPath, ctrlFlags)

open_finished:
	if !(rc != SQLITE_OK) {
		goto __31
	}
	Xsqlite3_free(tls, (*UnixFile)(unsafe.Pointer(p)).FpPreallocatedUnused)
__31:
	;
	return rc
}

func unixDelete(tls *libc.TLS, NotUsed uintptr, zPath uintptr, dirSync int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32 = SQLITE_OK
	_ = NotUsed
	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		return SQLITE_IOERR | int32(10)<<8
	}

	if (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 16*24 + 8)))(tls, zPath) == -1 {
		if *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) == ENOENT {
			rc = SQLITE_IOERR | int32(23)<<8
		} else {
			rc = unixLogErrorAtLine(tls, SQLITE_IOERR|int32(10)<<8, ts+5733, zPath, 43341)
		}
		return rc
	}
	if dirSync&1 != 0 {
		rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 17*24 + 8)))(tls, zPath, bp)
		if rc == SQLITE_OK {
			if full_fsync(tls, *(*int32)(unsafe.Pointer(bp)), 0, 0) != 0 {
				rc = unixLogErrorAtLine(tls, SQLITE_IOERR|int32(5)<<8, ts+6681, zPath, 43351)
			}
			robust_close(tls, uintptr(0), *(*int32)(unsafe.Pointer(bp)), 43353)
		} else {
			rc = SQLITE_OK
		}
	}
	return rc
}

func unixAccess(tls *libc.TLS, NotUsed uintptr, zPath uintptr, flags int32, pResOut uintptr) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	_ = NotUsed
	if Xsqlite3_io_error_persist != 0 && Xsqlite3_io_error_hit != 0 || libc.PostDecAtomicInt32(&Xsqlite3_io_error_pending, 1) == 1 {
		local_ioerr(tls)
		return SQLITE_IOERR | int32(13)<<8
	}

	if flags == SQLITE_ACCESS_EXISTS {
		*(*int32)(unsafe.Pointer(pResOut)) = libc.Bool32(0 == (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 4*24 + 8)))(tls, zPath, bp) && (!((*stat)(unsafe.Pointer(bp)).Fst_mode&X__mode_t(0170000) == X__mode_t(0100000)) || (*stat)(unsafe.Pointer(bp)).Fst_size > int64(0)))
	} else {
		*(*int32)(unsafe.Pointer(pResOut)) = libc.Bool32((*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 2*24 + 8)))(tls, zPath, W_OK|R_OK) == 0)
	}
	return SQLITE_OK
}

type DbPath1 = struct {
	Frc       int32
	FnSymlink int32
	FzOut     uintptr
	FnOut     int32
	FnUsed    int32
}

type DbPath = DbPath1

func appendOnePathElement(tls *libc.TLS, pPath uintptr, zName uintptr, nName int32) {
	bp := tls.Alloc(4226)
	defer tls.Free(4226)

	if int32(*(*uint8)(unsafe.Pointer(zName))) == '.' {
		if nName == 1 {
			return
		}
		if int32(*(*uint8)(unsafe.Pointer(zName + 1))) == '.' && nName == 2 {
			if (*DbPath)(unsafe.Pointer(pPath)).FnUsed > 1 {
				for int32(*(*uint8)(unsafe.Pointer((*DbPath)(unsafe.Pointer(pPath)).FzOut + uintptr(libc.PreDecInt32(&(*DbPath)(unsafe.Pointer(pPath)).FnUsed, 1))))) != '/' {
				}
			}
			return
		}
	}
	if (*DbPath)(unsafe.Pointer(pPath)).FnUsed+nName+2 >= (*DbPath)(unsafe.Pointer(pPath)).FnOut {
		(*DbPath)(unsafe.Pointer(pPath)).Frc = SQLITE_ERROR
		return
	}
	*(*uint8)(unsafe.Pointer((*DbPath)(unsafe.Pointer(pPath)).FzOut + uintptr(libc.PostIncInt32(&(*DbPath)(unsafe.Pointer(pPath)).FnUsed, 1)))) = uint8('/')
	libc.Xmemcpy(tls, (*DbPath)(unsafe.Pointer(pPath)).FzOut+uintptr((*DbPath)(unsafe.Pointer(pPath)).FnUsed), zName, uint64(nName))
	*(*int32)(unsafe.Pointer(pPath + 20)) += nName
	if (*DbPath)(unsafe.Pointer(pPath)).Frc == SQLITE_OK {
		var zIn uintptr

		*(*uint8)(unsafe.Pointer((*DbPath)(unsafe.Pointer(pPath)).FzOut + uintptr((*DbPath)(unsafe.Pointer(pPath)).FnUsed))) = uint8(0)
		zIn = (*DbPath)(unsafe.Pointer(pPath)).FzOut
		if (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 27*24 + 8)))(tls, zIn, bp) != 0 {
			if *(*int32)(unsafe.Pointer(libc.X__errno_location(tls))) != ENOENT {
				(*DbPath)(unsafe.Pointer(pPath)).Frc = unixLogErrorAtLine(tls, Xsqlite3CantopenError(tls, 43447), ts+5821, zIn, 43447)
			}
		} else if (*stat)(unsafe.Pointer(bp)).Fst_mode&X__mode_t(0170000) == X__mode_t(0120000) {
			var got Ssize_t

			if libc.PostIncInt32(&(*DbPath)(unsafe.Pointer(pPath)).FnSymlink, 1) > SQLITE_MAX_SYMLINK {
				(*DbPath)(unsafe.Pointer(pPath)).Frc = Xsqlite3CantopenError(tls, 43453)
				return
			}
			got = (*(*func(*libc.TLS, uintptr, uintptr, Size_t) Ssize_t)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 26*24 + 8)))(tls, zIn, bp+128, uint64(unsafe.Sizeof([4098]uint8{}))-uint64(2))
			if got <= int64(0) || got >= Ssize_t(unsafe.Sizeof([4098]uint8{}))-int64(2) {
				(*DbPath)(unsafe.Pointer(pPath)).Frc = unixLogErrorAtLine(tls, Xsqlite3CantopenError(tls, 43458), ts+5812, zIn, 43458)
				return
			}
			*(*uint8)(unsafe.Pointer(bp + 128 + uintptr(got))) = uint8(0)
			if int32(*(*uint8)(unsafe.Pointer(bp + 128))) == '/' {
				(*DbPath)(unsafe.Pointer(pPath)).FnUsed = 0
			} else {
				*(*int32)(unsafe.Pointer(pPath + 20)) -= nName + 1
			}
			appendAllPathElements(tls, pPath, bp+128)
		}
	}
}

func appendAllPathElements(tls *libc.TLS, pPath uintptr, zPath uintptr) {
	var i int32 = 0
	var j int32 = 0
	for __ccgo := true; __ccgo; __ccgo = *(*uint8)(unsafe.Pointer(zPath + uintptr(libc.PostIncInt32(&i, 1)))) != 0 {
		for *(*uint8)(unsafe.Pointer(zPath + uintptr(i))) != 0 && int32(*(*uint8)(unsafe.Pointer(zPath + uintptr(i)))) != '/' {
			i++
		}
		if i > j {
			appendOnePathElement(tls, pPath, zPath+uintptr(j), i-j)
		}
		j = i + 1
	}
}

func unixFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nOut int32, zOut uintptr) int32 {
	bp := tls.Alloc(4128)
	defer tls.Free(4128)

	_ = pVfs
	(*DbPath)(unsafe.Pointer(bp + 4104)).Frc = 0
	(*DbPath)(unsafe.Pointer(bp + 4104)).FnUsed = 0
	(*DbPath)(unsafe.Pointer(bp + 4104)).FnSymlink = 0
	(*DbPath)(unsafe.Pointer(bp + 4104)).FnOut = nOut
	(*DbPath)(unsafe.Pointer(bp + 4104)).FzOut = zOut
	if int32(*(*uint8)(unsafe.Pointer(zPath))) != '/' {
		if (*(*func(*libc.TLS, uintptr, Size_t) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 3*24 + 8)))(tls, bp, uint64(unsafe.Sizeof([4098]uint8{}))-uint64(2)) == uintptr(0) {
			return unixLogErrorAtLine(tls, Xsqlite3CantopenError(tls, 43516), ts+5641, zPath, 43516)
		}
		appendAllPathElements(tls, bp+4104, bp)
	}
	appendAllPathElements(tls, bp+4104, zPath)
	*(*uint8)(unsafe.Pointer(zOut + uintptr((*DbPath)(unsafe.Pointer(bp+4104)).FnUsed))) = uint8(0)
	if (*DbPath)(unsafe.Pointer(bp+4104)).Frc != 0 || (*DbPath)(unsafe.Pointer(bp+4104)).FnUsed < 2 {
		return Xsqlite3CantopenError(tls, 43522)
	}
	if (*DbPath)(unsafe.Pointer(bp+4104)).FnSymlink != 0 {
		return SQLITE_OK | int32(2)<<8
	}
	return SQLITE_OK
}

type Lmid_t = int64

type Dl_info = struct {
	Fdli_fname uintptr
	Fdli_fbase uintptr
	Fdli_sname uintptr
	Fdli_saddr uintptr
}

type Dl_serpath = struct {
	Fdls_name    uintptr
	Fdls_flags   uint32
	F__ccgo_pad1 [4]byte
}

type Dl_serinfo = struct {
	Fdls_size    Size_t
	Fdls_cnt     uint32
	F__ccgo_pad1 [4]byte
	F__16        struct {
		F__ccgo_pad1 [0]uint64
		Fdls_serpath [0]Dl_serpath
		F__ccgo_pad2 [16]byte
	}
}

func unixDlOpen(tls *libc.TLS, NotUsed uintptr, zFilename uintptr) uintptr {
	_ = NotUsed
	return libc.Xdlopen(tls, zFilename, RTLD_NOW|RTLD_GLOBAL)
}

func unixDlError(tls *libc.TLS, NotUsed uintptr, nBuf int32, zBufOut uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zErr uintptr
	_ = NotUsed
	unixEnterMutex(tls)
	zErr = libc.Xdlerror(tls)
	if zErr != 0 {
		Xsqlite3_snprintf(tls, nBuf, zBufOut, ts+1684, libc.VaList(bp, zErr))
	}
	unixLeaveMutex(tls)
}

func unixDlSym(tls *libc.TLS, NotUsed uintptr, p uintptr, zSym uintptr) uintptr {
	var x uintptr
	_ = NotUsed
	x = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) uintptr
	}{libc.Xdlsym}))
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{x})).f(tls, p, zSym)
}

func unixDlClose(tls *libc.TLS, NotUsed uintptr, pHandle uintptr) {
	_ = NotUsed
	libc.Xdlclose(tls, pHandle)
}

func unixRandomness(tls *libc.TLS, NotUsed uintptr, nBuf int32, zBuf uintptr) int32 {
	_ = NotUsed

	libc.Xmemset(tls, zBuf, 0, uint64(nBuf))
	libc.AtomicStoreInt32(&randomnessPid, libc.Xgetpid(tls))
	return nBuf
}

func unixSleep(tls *libc.TLS, NotUsed uintptr, microseconds int32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	(*timespec)(unsafe.Pointer(bp)).Ftv_sec = X__time_t(microseconds / 1000000)
	(*timespec)(unsafe.Pointer(bp)).Ftv_nsec = X__syscall_slong_t(microseconds % 1000000 * 1000)
	libc.Xnanosleep(tls, bp, uintptr(0))
	_ = NotUsed
	return microseconds
}

var Xsqlite3_current_time int32 = 0

func unixCurrentTimeInt64(tls *libc.TLS, NotUsed uintptr, piNow uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32 = SQLITE_OK

	libc.Xgettimeofday(tls, bp, uintptr(0))
	*(*Sqlite3_int64)(unsafe.Pointer(piNow)) = unixEpoch + int64(1000)*(*timeval)(unsafe.Pointer(bp)).Ftv_sec + (*timeval)(unsafe.Pointer(bp)).Ftv_usec/int64(1000)

	if Xsqlite3_current_time != 0 {
		*(*Sqlite3_int64)(unsafe.Pointer(piNow)) = int64(1000)*Sqlite3_int64(Xsqlite3_current_time) + unixEpoch
	}
	_ = NotUsed
	return rc
}

var unixEpoch Sqlite3_int64 = int64(24405875) * int64(8640000)

func unixCurrentTime(tls *libc.TLS, NotUsed uintptr, prNow uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*Sqlite3_int64)(unsafe.Pointer(bp)) = int64(0)
	var rc int32
	_ = NotUsed
	rc = unixCurrentTimeInt64(tls, uintptr(0), bp)
	*(*float64)(unsafe.Pointer(prNow)) = float64(*(*Sqlite3_int64)(unsafe.Pointer(bp))) / 86400000.0
	return rc
}

func unixGetLastError(tls *libc.TLS, NotUsed uintptr, NotUsed2 int32, NotUsed3 uintptr) int32 {
	_ = NotUsed
	_ = NotUsed2
	_ = NotUsed3
	return *(*int32)(unsafe.Pointer(libc.X__errno_location(tls)))
}

func Xsqlite3_os_init(tls *libc.TLS) int32 {
	var i uint32

	for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(aVfs))/uint64(unsafe.Sizeof(Sqlite3_vfs{})); i++ {
		Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&aVfs))+uintptr(i)*168, libc.Bool32(i == uint32(0)))
	}
	unixBigLock = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_VFS1)

	unixTempFileInit(tls)

	return SQLITE_OK
}

var aVfs = [4]Sqlite3_vfs{
	{FiVersion: 3, FszOsFile: int32(unsafe.Sizeof(UnixFile{})), FmxPathname: MAX_PATHNAME, FzName: ts + 6687, FpAppData: 0, FxOpen: 0, FxDelete: 0, FxAccess: 0, FxFullPathname: 0, FxDlOpen: 0, FxDlError: 0, FxDlSym: 0, FxDlClose: 0, FxRandomness: 0, FxSleep: 0, FxCurrentTime: 0, FxGetLastError: 0, FxCurrentTimeInt64: 0, FxSetSystemCall: 0, FxGetSystemCall: 0, FxNextSystemCall: 0},
	{FiVersion: 3, FszOsFile: int32(unsafe.Sizeof(UnixFile{})), FmxPathname: MAX_PATHNAME, FzName: ts + 6692, FpAppData: 0, FxOpen: 0, FxDelete: 0, FxAccess: 0, FxFullPathname: 0, FxDlOpen: 0, FxDlError: 0, FxDlSym: 0, FxDlClose: 0, FxRandomness: 0, FxSleep: 0, FxCurrentTime: 0, FxGetLastError: 0, FxCurrentTimeInt64: 0, FxSetSystemCall: 0, FxGetSystemCall: 0, FxNextSystemCall: 0},
	{FiVersion: 3, FszOsFile: int32(unsafe.Sizeof(UnixFile{})), FmxPathname: MAX_PATHNAME, FzName: ts + 6702, FpAppData: 0, FxOpen: 0, FxDelete: 0, FxAccess: 0, FxFullPathname: 0, FxDlOpen: 0, FxDlError: 0, FxDlSym: 0, FxDlClose: 0, FxRandomness: 0, FxSleep: 0, FxCurrentTime: 0, FxGetLastError: 0, FxCurrentTimeInt64: 0, FxSetSystemCall: 0, FxGetSystemCall: 0, FxNextSystemCall: 0},
	{FiVersion: 3, FszOsFile: int32(unsafe.Sizeof(UnixFile{})), FmxPathname: MAX_PATHNAME, FzName: ts + 6574, FpAppData: 0, FxOpen: 0, FxDelete: 0, FxAccess: 0, FxFullPathname: 0, FxDlOpen: 0, FxDlError: 0, FxDlSym: 0, FxDlClose: 0, FxRandomness: 0, FxSleep: 0, FxCurrentTime: 0, FxGetLastError: 0, FxCurrentTimeInt64: 0, FxSetSystemCall: 0, FxGetSystemCall: 0, FxNextSystemCall: 0},
}

func Xsqlite3_os_end(tls *libc.TLS) int32 {
	unixBigLock = uintptr(0)
	return SQLITE_OK
}

type MemVfs = sqlite3_vfs
type MemFile1 = struct {
	Fbase        Sqlite3_file
	FpStore      uintptr
	FeLock       int32
	F__ccgo_pad1 [4]byte
}

type MemFile = MemFile1
type MemStore1 = struct {
	Fsz          Sqlite3_int64
	FszAlloc     Sqlite3_int64
	FszMax       Sqlite3_int64
	FaData       uintptr
	FpMutex      uintptr
	FnMmap       int32
	FmFlags      uint32
	FnRdLock     int32
	FnWrLock     int32
	FnRef        int32
	F__ccgo_pad1 [4]byte
	FzFName      uintptr
}

type MemStore = MemStore1

type MemFS = struct {
	FnMemStore   int32
	F__ccgo_pad1 [4]byte
	FapMemStore  uintptr
}

var memdb_g MemFS

var memdb_vfs = Sqlite3_vfs{
	FiVersion:          2,
	FmxPathname:        1024,
	FzName:             ts + 6715,
	FxOpen:             0,
	FxAccess:           0,
	FxFullPathname:     0,
	FxDlOpen:           0,
	FxDlError:          0,
	FxDlSym:            0,
	FxDlClose:          0,
	FxRandomness:       0,
	FxSleep:            0,
	FxGetLastError:     0,
	FxCurrentTimeInt64: 0,
}

var memdb_io_methods = Sqlite3_io_methods{
	FiVersion:               3,
	FxClose:                 0,
	FxRead:                  0,
	FxWrite:                 0,
	FxTruncate:              0,
	FxSync:                  0,
	FxFileSize:              0,
	FxLock:                  0,
	FxUnlock:                0,
	FxFileControl:           0,
	FxDeviceCharacteristics: 0,
	FxFetch:                 0,
	FxUnfetch:               0,
}

func memdbEnter(tls *libc.TLS, p uintptr) {
	Xsqlite3_mutex_enter(tls, (*MemStore)(unsafe.Pointer(p)).FpMutex)
}

func memdbLeave(tls *libc.TLS, p uintptr) {
	Xsqlite3_mutex_leave(tls, (*MemStore)(unsafe.Pointer(p)).FpMutex)
}

func memdbClose(tls *libc.TLS, pFile uintptr) int32 {
	var p uintptr = (*MemFile)(unsafe.Pointer(pFile)).FpStore
	if (*MemStore)(unsafe.Pointer(p)).FzFName != 0 {
		var i int32
		var pVfsMutex uintptr = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_VFS1)
		Xsqlite3_mutex_enter(tls, pVfsMutex)
		for i = 0; i < memdb_g.FnMemStore; i++ {
			if *(*uintptr)(unsafe.Pointer(memdb_g.FapMemStore + uintptr(i)*8)) == p {
				memdbEnter(tls, p)
				if (*MemStore)(unsafe.Pointer(p)).FnRef == 1 {
					*(*uintptr)(unsafe.Pointer(memdb_g.FapMemStore + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer(memdb_g.FapMemStore + uintptr(libc.PreDecInt32(&memdb_g.FnMemStore, 1))*8))
					if memdb_g.FnMemStore == 0 {
						Xsqlite3_free(tls, memdb_g.FapMemStore)
						memdb_g.FapMemStore = uintptr(0)
					}
				}
				break
			}
		}
		Xsqlite3_mutex_leave(tls, pVfsMutex)
	} else {
		memdbEnter(tls, p)
	}
	(*MemStore)(unsafe.Pointer(p)).FnRef--
	if (*MemStore)(unsafe.Pointer(p)).FnRef <= 0 {
		if (*MemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_FREEONCLOSE) != 0 {
			Xsqlite3_free(tls, (*MemStore)(unsafe.Pointer(p)).FaData)
		}
		memdbLeave(tls, p)
		Xsqlite3_mutex_free(tls, (*MemStore)(unsafe.Pointer(p)).FpMutex)
		Xsqlite3_free(tls, p)
	} else {
		memdbLeave(tls, p)
	}
	return SQLITE_OK
}

func memdbRead(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst Sqlite_int64) int32 {
	var p uintptr = (*MemFile)(unsafe.Pointer(pFile)).FpStore
	memdbEnter(tls, p)
	if iOfst+Sqlite_int64(iAmt) > (*MemStore)(unsafe.Pointer(p)).Fsz {
		libc.Xmemset(tls, zBuf, 0, uint64(iAmt))
		if iOfst < (*MemStore)(unsafe.Pointer(p)).Fsz {
			libc.Xmemcpy(tls, zBuf, (*MemStore)(unsafe.Pointer(p)).FaData+uintptr(iOfst), uint64((*MemStore)(unsafe.Pointer(p)).Fsz-iOfst))
		}
		memdbLeave(tls, p)
		return SQLITE_IOERR | int32(2)<<8
	}
	libc.Xmemcpy(tls, zBuf, (*MemStore)(unsafe.Pointer(p)).FaData+uintptr(iOfst), uint64(iAmt))
	memdbLeave(tls, p)
	return SQLITE_OK
}

func memdbEnlarge(tls *libc.TLS, p uintptr, newSz Sqlite3_int64) int32 {
	var pNew uintptr
	if (*MemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_RESIZEABLE) == uint32(0) || (*MemStore)(unsafe.Pointer(p)).FnMmap > 0 {
		return SQLITE_FULL
	}
	if newSz > (*MemStore)(unsafe.Pointer(p)).FszMax {
		return SQLITE_FULL
	}
	newSz = newSz * int64(2)
	if newSz > (*MemStore)(unsafe.Pointer(p)).FszMax {
		newSz = (*MemStore)(unsafe.Pointer(p)).FszMax
	}
	pNew = Xsqlite3Realloc(tls, (*MemStore)(unsafe.Pointer(p)).FaData, uint64(newSz))
	if pNew == uintptr(0) {
		return SQLITE_IOERR | int32(12)<<8
	}
	(*MemStore)(unsafe.Pointer(p)).FaData = pNew
	(*MemStore)(unsafe.Pointer(p)).FszAlloc = newSz
	return SQLITE_OK
}

func memdbWrite(tls *libc.TLS, pFile uintptr, z uintptr, iAmt int32, iOfst Sqlite_int64) int32 {
	var p uintptr = (*MemFile)(unsafe.Pointer(pFile)).FpStore
	memdbEnter(tls, p)
	if (*MemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_READONLY) != 0 {
		memdbLeave(tls, p)
		return SQLITE_IOERR | int32(3)<<8
	}
	if iOfst+Sqlite_int64(iAmt) > (*MemStore)(unsafe.Pointer(p)).Fsz {
		var rc int32
		if iOfst+Sqlite_int64(iAmt) > (*MemStore)(unsafe.Pointer(p)).FszAlloc &&
			libc.AssignInt32(&rc, memdbEnlarge(tls, p, iOfst+Sqlite_int64(iAmt))) != SQLITE_OK {
			memdbLeave(tls, p)
			return rc
		}
		if iOfst > (*MemStore)(unsafe.Pointer(p)).Fsz {
			libc.Xmemset(tls, (*MemStore)(unsafe.Pointer(p)).FaData+uintptr((*MemStore)(unsafe.Pointer(p)).Fsz), 0, uint64(iOfst-(*MemStore)(unsafe.Pointer(p)).Fsz))
		}
		(*MemStore)(unsafe.Pointer(p)).Fsz = iOfst + Sqlite_int64(iAmt)
	}
	libc.Xmemcpy(tls, (*MemStore)(unsafe.Pointer(p)).FaData+uintptr(iOfst), z, uint64(iAmt))
	memdbLeave(tls, p)
	return SQLITE_OK
}

func memdbTruncate(tls *libc.TLS, pFile uintptr, size Sqlite_int64) int32 {
	var p uintptr = (*MemFile)(unsafe.Pointer(pFile)).FpStore
	var rc int32 = SQLITE_OK
	memdbEnter(tls, p)
	if size > (*MemStore)(unsafe.Pointer(p)).Fsz {
		rc = SQLITE_CORRUPT
	} else {
		(*MemStore)(unsafe.Pointer(p)).Fsz = size
	}
	memdbLeave(tls, p)
	return rc
}

func memdbSync(tls *libc.TLS, pFile uintptr, flags int32) int32 {
	_ = pFile
	_ = flags
	return SQLITE_OK
}

func memdbFileSize(tls *libc.TLS, pFile uintptr, pSize uintptr) int32 {
	var p uintptr = (*MemFile)(unsafe.Pointer(pFile)).FpStore
	memdbEnter(tls, p)
	*(*Sqlite_int64)(unsafe.Pointer(pSize)) = (*MemStore)(unsafe.Pointer(p)).Fsz
	memdbLeave(tls, p)
	return SQLITE_OK
}

func memdbLock(tls *libc.TLS, pFile uintptr, eLock int32) int32 {
	var pThis uintptr = pFile
	var p uintptr = (*MemFile)(unsafe.Pointer(pThis)).FpStore
	var rc int32 = SQLITE_OK
	if eLock <= (*MemFile)(unsafe.Pointer(pThis)).FeLock {
		return SQLITE_OK
	}
	memdbEnter(tls, p)

	if eLock > SQLITE_LOCK_SHARED && (*MemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_READONLY) != 0 {
		rc = SQLITE_READONLY
	} else {
		switch eLock {
		case SQLITE_LOCK_SHARED:
			{
				if (*MemStore)(unsafe.Pointer(p)).FnWrLock > 0 {
					rc = SQLITE_BUSY
				} else {
					(*MemStore)(unsafe.Pointer(p)).FnRdLock++
				}
				break

			}

			fallthrough

		case SQLITE_LOCK_RESERVED:
			fallthrough
		case SQLITE_LOCK_PENDING:
			{
				if (*MemFile)(unsafe.Pointer(pThis)).FeLock == SQLITE_LOCK_SHARED {
					if (*MemStore)(unsafe.Pointer(p)).FnWrLock > 0 {
						rc = SQLITE_BUSY
					} else {
						(*MemStore)(unsafe.Pointer(p)).FnWrLock = 1
					}
				}
				break

			}
			fallthrough

		default:
			{
				if (*MemStore)(unsafe.Pointer(p)).FnRdLock > 1 {
					rc = SQLITE_BUSY
				} else if (*MemFile)(unsafe.Pointer(pThis)).FeLock == SQLITE_LOCK_SHARED {
					(*MemStore)(unsafe.Pointer(p)).FnWrLock = 1
				}
				break

			}
		}
	}
	if rc == SQLITE_OK {
		(*MemFile)(unsafe.Pointer(pThis)).FeLock = eLock
	}
	memdbLeave(tls, p)
	return rc
}

func memdbUnlock(tls *libc.TLS, pFile uintptr, eLock int32) int32 {
	var pThis uintptr = pFile
	var p uintptr = (*MemFile)(unsafe.Pointer(pThis)).FpStore
	if eLock >= (*MemFile)(unsafe.Pointer(pThis)).FeLock {
		return SQLITE_OK
	}
	memdbEnter(tls, p)

	if eLock == SQLITE_LOCK_SHARED {
		if (*MemFile)(unsafe.Pointer(pThis)).FeLock > SQLITE_LOCK_SHARED {
			(*MemStore)(unsafe.Pointer(p)).FnWrLock--
		}
	} else {
		if (*MemFile)(unsafe.Pointer(pThis)).FeLock > SQLITE_LOCK_SHARED {
			(*MemStore)(unsafe.Pointer(p)).FnWrLock--
		}
		(*MemStore)(unsafe.Pointer(p)).FnRdLock--
	}

	(*MemFile)(unsafe.Pointer(pThis)).FeLock = eLock
	memdbLeave(tls, p)
	return SQLITE_OK
}

func memdbFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var p uintptr = (*MemFile)(unsafe.Pointer(pFile)).FpStore
	var rc int32 = SQLITE_NOTFOUND
	memdbEnter(tls, p)
	if op == SQLITE_FCNTL_VFSNAME {
		*(*uintptr)(unsafe.Pointer(pArg)) = Xsqlite3_mprintf(tls, ts+6721, libc.VaList(bp, (*MemStore)(unsafe.Pointer(p)).FaData, (*MemStore)(unsafe.Pointer(p)).Fsz))
		rc = SQLITE_OK
	}
	if op == SQLITE_FCNTL_SIZE_LIMIT {
		var iLimit Sqlite3_int64 = *(*Sqlite3_int64)(unsafe.Pointer(pArg))
		if iLimit < (*MemStore)(unsafe.Pointer(p)).Fsz {
			if iLimit < int64(0) {
				iLimit = (*MemStore)(unsafe.Pointer(p)).FszMax
			} else {
				iLimit = (*MemStore)(unsafe.Pointer(p)).Fsz
			}
		}
		(*MemStore)(unsafe.Pointer(p)).FszMax = iLimit
		*(*Sqlite3_int64)(unsafe.Pointer(pArg)) = iLimit
		rc = SQLITE_OK
	}
	memdbLeave(tls, p)
	return rc
}

func memdbDeviceCharacteristics(tls *libc.TLS, pFile uintptr) int32 {
	_ = pFile
	return SQLITE_IOCAP_ATOMIC | SQLITE_IOCAP_POWERSAFE_OVERWRITE | SQLITE_IOCAP_SAFE_APPEND | SQLITE_IOCAP_SEQUENTIAL
}

func memdbFetch(tls *libc.TLS, pFile uintptr, iOfst Sqlite3_int64, iAmt int32, pp uintptr) int32 {
	var p uintptr = (*MemFile)(unsafe.Pointer(pFile)).FpStore
	memdbEnter(tls, p)
	if iOfst+Sqlite3_int64(iAmt) > (*MemStore)(unsafe.Pointer(p)).Fsz || (*MemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_RESIZEABLE) != uint32(0) {
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	} else {
		(*MemStore)(unsafe.Pointer(p)).FnMmap++
		*(*uintptr)(unsafe.Pointer(pp)) = (*MemStore)(unsafe.Pointer(p)).FaData + uintptr(iOfst)
	}
	memdbLeave(tls, p)
	return SQLITE_OK
}

func memdbUnfetch(tls *libc.TLS, pFile uintptr, iOfst Sqlite3_int64, pPage uintptr) int32 {
	var p uintptr = (*MemFile)(unsafe.Pointer(pFile)).FpStore
	_ = iOfst
	_ = pPage
	memdbEnter(tls, p)
	(*MemStore)(unsafe.Pointer(p)).FnMmap--
	memdbLeave(tls, p)
	return SQLITE_OK
}

func memdbOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pFd uintptr, flags int32, pOutFlags uintptr) int32 {
	var pFile uintptr = pFd
	var p uintptr = uintptr(0)
	var szName int32
	_ = pVfs

	libc.Xmemset(tls, pFile, 0, uint64(unsafe.Sizeof(MemFile{})))
	szName = Xsqlite3Strlen30(tls, zName)
	if szName > 1 && (int32(*(*uint8)(unsafe.Pointer(zName))) == '/' || int32(*(*uint8)(unsafe.Pointer(zName))) == '\\') {
		var i int32
		var pVfsMutex uintptr = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_VFS1)
		Xsqlite3_mutex_enter(tls, pVfsMutex)
		for i = 0; i < memdb_g.FnMemStore; i++ {
			if libc.Xstrcmp(tls, (*MemStore)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(memdb_g.FapMemStore + uintptr(i)*8)))).FzFName, zName) == 0 {
				p = *(*uintptr)(unsafe.Pointer(memdb_g.FapMemStore + uintptr(i)*8))
				break
			}
		}
		if p == uintptr(0) {
			var apNew uintptr
			p = Xsqlite3Malloc(tls, uint64(unsafe.Sizeof(MemStore{}))+uint64(szName)+uint64(3))
			if p == uintptr(0) {
				Xsqlite3_mutex_leave(tls, pVfsMutex)
				return SQLITE_NOMEM
			}
			apNew = Xsqlite3Realloc(tls, memdb_g.FapMemStore,
				uint64(unsafe.Sizeof(uintptr(0)))*uint64(memdb_g.FnMemStore+1))
			if apNew == uintptr(0) {
				Xsqlite3_free(tls, p)
				Xsqlite3_mutex_leave(tls, pVfsMutex)
				return SQLITE_NOMEM
			}
			*(*uintptr)(unsafe.Pointer(apNew + uintptr(libc.PostIncInt32(&memdb_g.FnMemStore, 1))*8)) = p
			memdb_g.FapMemStore = apNew
			libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(MemStore{})))
			(*MemStore)(unsafe.Pointer(p)).FmFlags = uint32(SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE)
			(*MemStore)(unsafe.Pointer(p)).FszMax = Xsqlite3Config.FmxMemdbSize
			(*MemStore)(unsafe.Pointer(p)).FzFName = p + 1*72
			libc.Xmemcpy(tls, (*MemStore)(unsafe.Pointer(p)).FzFName, zName, uint64(szName+1))
			(*MemStore)(unsafe.Pointer(p)).FpMutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_FAST)
			if (*MemStore)(unsafe.Pointer(p)).FpMutex == uintptr(0) {
				memdb_g.FnMemStore--
				Xsqlite3_free(tls, p)
				Xsqlite3_mutex_leave(tls, pVfsMutex)
				return SQLITE_NOMEM
			}
			(*MemStore)(unsafe.Pointer(p)).FnRef = 1
			memdbEnter(tls, p)
		} else {
			memdbEnter(tls, p)
			(*MemStore)(unsafe.Pointer(p)).FnRef++
		}
		Xsqlite3_mutex_leave(tls, pVfsMutex)
	} else {
		p = Xsqlite3Malloc(tls, uint64(unsafe.Sizeof(MemStore{})))
		if p == uintptr(0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(MemStore{})))
		(*MemStore)(unsafe.Pointer(p)).FmFlags = uint32(SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE)
		(*MemStore)(unsafe.Pointer(p)).FszMax = Xsqlite3Config.FmxMemdbSize
	}
	(*MemFile)(unsafe.Pointer(pFile)).FpStore = p
	if pOutFlags != uintptr(0) {
		*(*int32)(unsafe.Pointer(pOutFlags)) = flags | SQLITE_OPEN_MEMORY
	}
	(*Sqlite3_file)(unsafe.Pointer(pFd)).FpMethods = uintptr(unsafe.Pointer(&memdb_io_methods))
	memdbLeave(tls, p)
	return SQLITE_OK
}

func memdbAccess(tls *libc.TLS, pVfs uintptr, zPath uintptr, flags int32, pResOut uintptr) int32 {
	_ = pVfs
	_ = zPath
	_ = flags
	*(*int32)(unsafe.Pointer(pResOut)) = 0
	return SQLITE_OK
}

func memdbFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nOut int32, zOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	_ = pVfs
	Xsqlite3_snprintf(tls, nOut, zOut, ts+1684, libc.VaList(bp, zPath))
	return SQLITE_OK
}

func memdbDlOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr) uintptr {
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxDlOpen})).f(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, zPath)
}

func memdbDlError(tls *libc.TLS, pVfs uintptr, nByte int32, zErrMsg uintptr) {
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxDlError})).f(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, nByte, zErrMsg)
}

func memdbDlSym(tls *libc.TLS, pVfs uintptr, p uintptr, zSym uintptr) uintptr {
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxDlSym})).f(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, p, zSym)
}

func memdbDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
	(*struct {
		f func(*libc.TLS, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxDlClose})).f(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, pHandle)
}

func memdbRandomness(tls *libc.TLS, pVfs uintptr, nByte int32, zBufOut uintptr) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxRandomness})).f(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, nByte, zBufOut)
}

func memdbSleep(tls *libc.TLS, pVfs uintptr, nMicro int32) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxSleep})).f(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, nMicro)
}

func memdbGetLastError(tls *libc.TLS, pVfs uintptr, a int32, b uintptr) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxGetLastError})).f(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, a, b)
}

func memdbCurrentTimeInt64(tls *libc.TLS, pVfs uintptr, p uintptr) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData)).FxCurrentTimeInt64})).f(tls, (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FpAppData, p)
}

func memdbFromDbSchema(tls *libc.TLS, db uintptr, zSchema uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var pStore uintptr
	var rc int32 = Xsqlite3_file_control(tls, db, zSchema, SQLITE_FCNTL_FILE_POINTER, bp)
	if rc != 0 {
		return uintptr(0)
	}
	if (*MemFile)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FpMethods != uintptr(unsafe.Pointer(&memdb_io_methods)) {
		return uintptr(0)
	}
	pStore = (*MemFile)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpStore
	memdbEnter(tls, pStore)
	if (*MemStore)(unsafe.Pointer(pStore)).FzFName != uintptr(0) {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	}
	memdbLeave(tls, pStore)
	return *(*uintptr)(unsafe.Pointer(bp))
}

func Xsqlite3_serialize(tls *libc.TLS, db uintptr, zSchema uintptr, piSize uintptr, mFlags uint32) uintptr {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var p uintptr
	var iDb int32
	var pBt uintptr
	var sz Sqlite3_int64
	var szPage int32 = 0
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	var pOut uintptr
	var zSql uintptr
	var rc int32

	if zSchema == uintptr(0) {
		zSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FzDbSName
	}
	p = memdbFromDbSchema(tls, db, zSchema)
	iDb = Xsqlite3FindDbName(tls, db, zSchema)
	if piSize != 0 {
		*(*Sqlite3_int64)(unsafe.Pointer(piSize)) = int64(-1)
	}
	if iDb < 0 {
		return uintptr(0)
	}
	if p != 0 {
		var pStore uintptr = (*MemFile)(unsafe.Pointer(p)).FpStore

		if piSize != 0 {
			*(*Sqlite3_int64)(unsafe.Pointer(piSize)) = (*MemStore)(unsafe.Pointer(pStore)).Fsz
		}
		if mFlags&uint32(SQLITE_SERIALIZE_NOCOPY) != 0 {
			pOut = (*MemStore)(unsafe.Pointer(pStore)).FaData
		} else {
			pOut = Xsqlite3_malloc64(tls, uint64((*MemStore)(unsafe.Pointer(pStore)).Fsz))
			if pOut != 0 {
				libc.Xmemcpy(tls, pOut, (*MemStore)(unsafe.Pointer(pStore)).FaData, uint64((*MemStore)(unsafe.Pointer(pStore)).Fsz))
			}
		}
		return pOut
	}
	pBt = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpBt
	if pBt == uintptr(0) {
		return uintptr(0)
	}
	szPage = Xsqlite3BtreeGetPageSize(tls, pBt)
	zSql = Xsqlite3_mprintf(tls, ts+6736, libc.VaList(bp, zSchema))
	if zSql != 0 {
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -1, bp+8, uintptr(0))
	} else {
		rc = SQLITE_NOMEM
	}
	Xsqlite3_free(tls, zSql)
	if rc != 0 {
		return uintptr(0)
	}
	rc = Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	if rc != SQLITE_ROW {
		pOut = uintptr(0)
	} else {
		sz = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 0) * Sqlite_int64(szPage)
		if piSize != 0 {
			*(*Sqlite3_int64)(unsafe.Pointer(piSize)) = sz
		}
		if mFlags&uint32(SQLITE_SERIALIZE_NOCOPY) != 0 {
			pOut = uintptr(0)
		} else {
			pOut = Xsqlite3_malloc64(tls, uint64(sz))
			if pOut != 0 {
				var nPage int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 0)
				var pPager uintptr = Xsqlite3BtreePager(tls, pBt)
				var pgno int32
				for pgno = 1; pgno <= nPage; pgno++ {
					*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
					var pTo uintptr = pOut + uintptr(Sqlite3_int64(szPage)*Sqlite3_int64(pgno-1))
					rc = Xsqlite3PagerGet(tls, pPager, uint32(pgno), bp+16, 0)
					if rc == SQLITE_OK {
						libc.Xmemcpy(tls, pTo, Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 16))), uint64(szPage))
					} else {
						libc.Xmemset(tls, pTo, 0, uint64(szPage))
					}
					Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
				}
			}
		}
	}
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return pOut
}

func Xsqlite3_deserialize(tls *libc.TLS, db uintptr, zSchema uintptr, pData uintptr, szDb Sqlite3_int64, szBuf Sqlite3_int64, mFlags uint32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var p uintptr
	var zSql uintptr

	var rc int32
	var iDb int32
	var pStore uintptr
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if !(zSchema == uintptr(0)) {
		goto __1
	}
	zSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FzDbSName
__1:
	;
	iDb = Xsqlite3FindDbName(tls, db, zSchema)

	if !(iDb < 2 && iDb != 0) {
		goto __2
	}
	rc = SQLITE_ERROR
	goto end_deserialize
__2:
	;
	zSql = Xsqlite3_mprintf(tls, ts+6759, libc.VaList(bp, zSchema))
	if !(zSql == uintptr(0)) {
		goto __3
	}
	rc = SQLITE_NOMEM
	goto __4
__3:
	rc = Xsqlite3_prepare_v2(tls, db, zSql, -1, bp+8, uintptr(0))
	Xsqlite3_free(tls, zSql)
__4:
	;
	if !(rc != 0) {
		goto __5
	}
	goto end_deserialize
__5:
	;
	(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = U8(iDb)
	libc.SetBitFieldPtr8Uint32(db+192+8, uint32(1), 2, 0x4)
	rc = Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	libc.SetBitFieldPtr8Uint32(db+192+8, uint32(0), 2, 0x4)
	if !(rc != SQLITE_DONE) {
		goto __6
	}
	rc = SQLITE_ERROR
	goto end_deserialize
__6:
	;
	p = memdbFromDbSchema(tls, db, zSchema)
	if !(p == uintptr(0)) {
		goto __7
	}
	rc = SQLITE_ERROR
	goto __8
__7:
	pStore = (*MemFile)(unsafe.Pointer(p)).FpStore
	(*MemStore)(unsafe.Pointer(pStore)).FaData = pData
	pData = uintptr(0)
	(*MemStore)(unsafe.Pointer(pStore)).Fsz = szDb
	(*MemStore)(unsafe.Pointer(pStore)).FszAlloc = szBuf
	(*MemStore)(unsafe.Pointer(pStore)).FszMax = szBuf
	if !((*MemStore)(unsafe.Pointer(pStore)).FszMax < Xsqlite3Config.FmxMemdbSize) {
		goto __9
	}
	(*MemStore)(unsafe.Pointer(pStore)).FszMax = Xsqlite3Config.FmxMemdbSize
__9:
	;
	(*MemStore)(unsafe.Pointer(pStore)).FmFlags = mFlags
	rc = SQLITE_OK
__8:
	;
end_deserialize:
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	if !(pData != 0 && mFlags&uint32(SQLITE_DESERIALIZE_FREEONCLOSE) != uint32(0)) {
		goto __10
	}
	Xsqlite3_free(tls, pData)
__10:
	;
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3IsMemdb(tls *libc.TLS, pVfs uintptr) int32 {
	return libc.Bool32(pVfs == uintptr(unsafe.Pointer(&memdb_vfs)))
}

func Xsqlite3MemdbInit(tls *libc.TLS) int32 {
	var pLower uintptr = Xsqlite3_vfs_find(tls, uintptr(0))
	var sz uint32
	if pLower == uintptr(0) {
		return SQLITE_ERROR
	}
	sz = uint32((*Sqlite3_vfs)(unsafe.Pointer(pLower)).FszOsFile)
	memdb_vfs.FpAppData = pLower

	if uint64(sz) < uint64(unsafe.Sizeof(MemFile{})) {
		sz = uint32(unsafe.Sizeof(MemFile{}))
	}
	memdb_vfs.FszOsFile = int32(sz)
	return Xsqlite3_vfs_register(tls, uintptr(unsafe.Pointer(&memdb_vfs)), 0)
}

func Xsqlite3BitvecCreate(tls *libc.TLS, iSize U32) uintptr {
	var p uintptr

	p = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(Bitvec{})))
	if p != 0 {
		(*Bitvec)(unsafe.Pointer(p)).FiSize = iSize
	}
	return p
}

func Xsqlite3BitvecTestNotNull(tls *libc.TLS, p uintptr, i U32) int32 {
	i--
	if i >= (*Bitvec)(unsafe.Pointer(p)).FiSize {
		return 0
	}
	for (*Bitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
		var bin U32 = i / (*Bitvec)(unsafe.Pointer(p)).FiDivisor
		i = i % (*Bitvec)(unsafe.Pointer(p)).FiDivisor
		p = *(*uintptr)(unsafe.Pointer(p + 16 + uintptr(bin)*8))
		if !(p != 0) {
			return 0
		}
	}
	if uint64((*Bitvec)(unsafe.Pointer(p)).FiSize) <= (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U8(0)))*uint64(BITVEC_SZELEM) {
		return libc.Bool32(int32(*(*U8)(unsafe.Pointer(p + 16 + uintptr(i/U32(BITVEC_SZELEM)))))&(int32(1)<<(i&U32(BITVEC_SZELEM-1))) != 0)
	} else {
		var h U32 = U32(uint64(libc.PostIncUint32(&i, 1)*U32(1)) % ((uint64(BITVEC_SZ) - uint64(3)*uint64(unsafe.Sizeof(U32(0)))) / uint64(unsafe.Sizeof(uintptr(0))) * uint64(unsafe.Sizeof(uintptr(0))) / uint64(unsafe.Sizeof(U32(0)))))
		for *(*U32)(unsafe.Pointer(p + 16 + uintptr(h)*4)) != 0 {
			if *(*U32)(unsafe.Pointer(p + 16 + uintptr(h)*4)) == i {
				return 1
			}
			h = U32(uint64(h+U32(1)) % ((uint64(BITVEC_SZ) - uint64(3)*uint64(unsafe.Sizeof(U32(0)))) / uint64(unsafe.Sizeof(uintptr(0))) * uint64(unsafe.Sizeof(uintptr(0))) / uint64(unsafe.Sizeof(U32(0)))))
		}
		return 0
	}
	return int32(0)
}

func Xsqlite3BitvecTest(tls *libc.TLS, p uintptr, i U32) int32 {
	return libc.Bool32(p != uintptr(0) && Xsqlite3BitvecTestNotNull(tls, p, i) != 0)
}

func Xsqlite3BitvecSet(tls *libc.TLS, p uintptr, i U32) int32 {
	var h U32
	var bin U32
	var j uint32
	var rc int32
	var aiValues uintptr
	if !(p == uintptr(0)) {
		goto __1
	}
	return SQLITE_OK
__1:
	;
	i--
__2:
	if !(uint64((*Bitvec)(unsafe.Pointer(p)).FiSize) > (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U8(0)))*uint64(BITVEC_SZELEM) && (*Bitvec)(unsafe.Pointer(p)).FiDivisor != 0) {
		goto __3
	}
	bin = i / (*Bitvec)(unsafe.Pointer(p)).FiDivisor
	i = i % (*Bitvec)(unsafe.Pointer(p)).FiDivisor
	if !(*(*uintptr)(unsafe.Pointer(p + 16 + uintptr(bin)*8)) == uintptr(0)) {
		goto __4
	}
	*(*uintptr)(unsafe.Pointer(p + 16 + uintptr(bin)*8)) = Xsqlite3BitvecCreate(tls, (*Bitvec)(unsafe.Pointer(p)).FiDivisor)
	if !(*(*uintptr)(unsafe.Pointer(p + 16 + uintptr(bin)*8)) == uintptr(0)) {
		goto __5
	}
	return SQLITE_NOMEM
__5:
	;
__4:
	;
	p = *(*uintptr)(unsafe.Pointer(p + 16 + uintptr(bin)*8))
	goto __2
__3:
	;
	if !(uint64((*Bitvec)(unsafe.Pointer(p)).FiSize) <= (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U8(0)))*uint64(BITVEC_SZELEM)) {
		goto __6
	}
	*(*U8)(unsafe.Pointer(p + 16 + uintptr(i/U32(BITVEC_SZELEM)))) |= U8(int32(1) << (i & U32(BITVEC_SZELEM-1)))
	return SQLITE_OK
__6:
	;
	h = U32(uint64(libc.PostIncUint32(&i, 1)*U32(1)) % ((uint64(BITVEC_SZ) - uint64(3)*uint64(unsafe.Sizeof(U32(0)))) / uint64(unsafe.Sizeof(uintptr(0))) * uint64(unsafe.Sizeof(uintptr(0))) / uint64(unsafe.Sizeof(U32(0)))))

	if !!(int32(*(*U32)(unsafe.Pointer(p + 16 + uintptr(h)*4))) != 0) {
		goto __7
	}
	if !(uint64((*Bitvec)(unsafe.Pointer(p)).FnSet) < (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U32(0)))-uint64(1)) {
		goto __8
	}
	goto bitvec_set_end
	goto __9
__8:
	goto bitvec_set_rehash
__9:
	;
__7:
	;
__10:
	if !(*(*U32)(unsafe.Pointer(p + 16 + uintptr(h)*4)) == i) {
		goto __13
	}
	return SQLITE_OK
__13:
	;
	h++
	if !(uint64(h) >= (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U32(0)))) {
		goto __14
	}
	h = U32(0)
__14:
	;
	goto __11
__11:
	if *(*U32)(unsafe.Pointer(p + 16 + uintptr(h)*4)) != 0 {
		goto __10
	}
	goto __12
__12:
	;
bitvec_set_rehash:
	if !(uint64((*Bitvec)(unsafe.Pointer(p)).FnSet) >= (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U32(0)))/uint64(2)) {
		goto __15
	}
	aiValues = Xsqlite3DbMallocRaw(tls, uintptr(0), uint64(unsafe.Sizeof([124]U32{})))
	if !(aiValues == uintptr(0)) {
		goto __16
	}
	return SQLITE_NOMEM
	goto __17
__16:
	libc.Xmemcpy(tls, aiValues, p+16, uint64(unsafe.Sizeof([124]U32{})))
	libc.Xmemset(tls, p+16, 0, uint64(unsafe.Sizeof([62]uintptr{})))
	(*Bitvec)(unsafe.Pointer(p)).FiDivisor = U32((uint64((*Bitvec)(unsafe.Pointer(p)).FiSize) + (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(uintptr(0))) - uint64(1)) / ((uint64(BITVEC_SZ) - uint64(3)*uint64(unsafe.Sizeof(U32(0)))) / uint64(unsafe.Sizeof(uintptr(0))) * uint64(unsafe.Sizeof(uintptr(0))) / uint64(unsafe.Sizeof(uintptr(0)))))
	rc = Xsqlite3BitvecSet(tls, p, i)
	j = uint32(0)
__18:
	if !(uint64(j) < (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U32(0)))) {
		goto __20
	}
	if !(*(*U32)(unsafe.Pointer(aiValues + uintptr(j)*4)) != 0) {
		goto __21
	}
	rc = rc | Xsqlite3BitvecSet(tls, p, *(*U32)(unsafe.Pointer(aiValues + uintptr(j)*4)))
__21:
	;
	goto __19
__19:
	j++
	goto __18
	goto __20
__20:
	;
	Xsqlite3DbFree(tls, uintptr(0), aiValues)
	return rc
__17:
	;
__15:
	;
bitvec_set_end:
	(*Bitvec)(unsafe.Pointer(p)).FnSet++
	*(*U32)(unsafe.Pointer(p + 16 + uintptr(h)*4)) = i
	return SQLITE_OK
}

func Xsqlite3BitvecClear(tls *libc.TLS, p uintptr, i U32, pBuf uintptr) {
	if p == uintptr(0) {
		return
	}

	i--
	for (*Bitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
		var bin U32 = i / (*Bitvec)(unsafe.Pointer(p)).FiDivisor
		i = i % (*Bitvec)(unsafe.Pointer(p)).FiDivisor
		p = *(*uintptr)(unsafe.Pointer(p + 16 + uintptr(bin)*8))
		if !(p != 0) {
			return
		}
	}
	if uint64((*Bitvec)(unsafe.Pointer(p)).FiSize) <= (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U8(0)))*uint64(BITVEC_SZELEM) {
		*(*U8)(unsafe.Pointer(p + 16 + uintptr(i/U32(BITVEC_SZELEM)))) &= U8(^(int32(1) << (i & U32(BITVEC_SZELEM-1))))
	} else {
		var j uint32
		var aiValues uintptr = pBuf
		libc.Xmemcpy(tls, aiValues, p+16, uint64(unsafe.Sizeof([124]U32{})))
		libc.Xmemset(tls, p+16, 0, uint64(unsafe.Sizeof([124]U32{})))
		(*Bitvec)(unsafe.Pointer(p)).FnSet = U32(0)
		for j = uint32(0); uint64(j) < (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U32(0))); j++ {
			if *(*U32)(unsafe.Pointer(aiValues + uintptr(j)*4)) != 0 && *(*U32)(unsafe.Pointer(aiValues + uintptr(j)*4)) != i+U32(1) {
				var h U32 = U32(uint64((*(*U32)(unsafe.Pointer(aiValues + uintptr(j)*4))-U32(1))*U32(1)) % ((uint64(BITVEC_SZ) - uint64(3)*uint64(unsafe.Sizeof(U32(0)))) / uint64(unsafe.Sizeof(uintptr(0))) * uint64(unsafe.Sizeof(uintptr(0))) / uint64(unsafe.Sizeof(U32(0)))))
				(*Bitvec)(unsafe.Pointer(p)).FnSet++
				for *(*U32)(unsafe.Pointer(p + 16 + uintptr(h)*4)) != 0 {
					h++
					if uint64(h) >= (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(U32(0))) {
						h = U32(0)
					}
				}
				*(*U32)(unsafe.Pointer(p + 16 + uintptr(h)*4)) = *(*U32)(unsafe.Pointer(aiValues + uintptr(j)*4))
			}
		}
	}
}

func Xsqlite3BitvecDestroy(tls *libc.TLS, p uintptr) {
	if p == uintptr(0) {
		return
	}
	if (*Bitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
		var i uint32
		for i = uint32(0); uint64(i) < (uint64(BITVEC_SZ)-uint64(3)*uint64(unsafe.Sizeof(U32(0))))/uint64(unsafe.Sizeof(uintptr(0)))*uint64(unsafe.Sizeof(uintptr(0)))/uint64(unsafe.Sizeof(uintptr(0))); i++ {
			Xsqlite3BitvecDestroy(tls, *(*uintptr)(unsafe.Pointer(p + 16 + uintptr(i)*8)))
		}
	}
	Xsqlite3_free(tls, p)
}

func Xsqlite3BitvecSize(tls *libc.TLS, p uintptr) U32 {
	return (*Bitvec)(unsafe.Pointer(p)).FiSize
}

func Xsqlite3BitvecBuiltinTest(tls *libc.TLS, sz int32, aOp uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pBitvec uintptr
	var pV uintptr
	var rc int32

	var nx int32
	var pc int32
	var op int32
	var pTmpSpace uintptr
	pBitvec = uintptr(0)
	pV = uintptr(0)
	rc = -1

	pBitvec = Xsqlite3BitvecCreate(tls, uint32(sz))
	pV = Xsqlite3MallocZero(tls, uint64((sz+7)/8+1))
	pTmpSpace = Xsqlite3_malloc64(tls, uint64(BITVEC_SZ))
	if !(pBitvec == uintptr(0) || pV == uintptr(0) || pTmpSpace == uintptr(0)) {
		goto __1
	}
	goto bitvec_end
__1:
	;
	Xsqlite3BitvecSet(tls, uintptr(0), uint32(1))
	Xsqlite3BitvecClear(tls, uintptr(0), uint32(1), pTmpSpace)

	pc = libc.AssignPtrInt32(bp, 0)
__2:
	if !(libc.AssignInt32(&op, *(*int32)(unsafe.Pointer(aOp + uintptr(pc)*4))) != 0) {
		goto __3
	}
	switch op {
	case 1:
		goto __5
	case 2:
		goto __6
	case 5:
		goto __7
	case 3:
		goto __8
	case 4:
		goto __9
	default:
		goto __10
	}
	goto __4
__5:
__6:
__7:
	nx = 4
	*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(aOp + uintptr(pc+2)*4)) - 1
	*(*int32)(unsafe.Pointer(aOp + uintptr(pc+2)*4)) += *(*int32)(unsafe.Pointer(aOp + uintptr(pc+3)*4))
	goto __4

__8:
__9:
__10:
	nx = 2
	Xsqlite3_randomness(tls, int32(unsafe.Sizeof(int32(0))), bp)
	goto __4

__4:
	;
	if !(libc.PreDecInt32(&*(*int32)(unsafe.Pointer(aOp + uintptr(pc+1)*4)), 1) > 0) {
		goto __11
	}
	nx = 0
__11:
	;
	pc = pc + nx
	*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(bp)) & 0x7fffffff % sz
	if !(op&1 != 0) {
		goto __12
	}
	*(*uint8)(unsafe.Pointer(pV + uintptr((*(*int32)(unsafe.Pointer(bp))+1)>>3))) |= uint8(int32(1) << ((*(*int32)(unsafe.Pointer(bp)) + 1) & 7))
	if !(op != 5) {
		goto __14
	}
	if !(Xsqlite3BitvecSet(tls, pBitvec, uint32(*(*int32)(unsafe.Pointer(bp))+1)) != 0) {
		goto __15
	}
	goto bitvec_end
__15:
	;
__14:
	;
	goto __13
__12:
	*(*uint8)(unsafe.Pointer(pV + uintptr((*(*int32)(unsafe.Pointer(bp))+1)>>3))) &= uint8(^(int32(1) << ((*(*int32)(unsafe.Pointer(bp)) + 1) & 7)))
	Xsqlite3BitvecClear(tls, pBitvec, uint32(*(*int32)(unsafe.Pointer(bp))+1), pTmpSpace)
__13:
	;
	goto __2
__3:
	;
	rc = int32(U32(Xsqlite3BitvecTest(tls, uintptr(0), uint32(0))+Xsqlite3BitvecTest(tls, pBitvec, uint32(sz+1))+
		Xsqlite3BitvecTest(tls, pBitvec, uint32(0))) +
		(Xsqlite3BitvecSize(tls, pBitvec) - U32(sz)))
	*(*int32)(unsafe.Pointer(bp)) = 1
__16:
	if !(*(*int32)(unsafe.Pointer(bp)) <= sz) {
		goto __18
	}
	if !(libc.Bool32(int32(*(*uint8)(unsafe.Pointer(pV + uintptr(*(*int32)(unsafe.Pointer(bp))>>3))))&(int32(1)<<(*(*int32)(unsafe.Pointer(bp))&7)) != 0) != Xsqlite3BitvecTest(tls, pBitvec, uint32(*(*int32)(unsafe.Pointer(bp))))) {
		goto __19
	}
	rc = *(*int32)(unsafe.Pointer(bp))
	goto __18
__19:
	;
	goto __17
__17:
	*(*int32)(unsafe.Pointer(bp))++
	goto __16
	goto __18
__18:
	;
bitvec_end:
	Xsqlite3_free(tls, pTmpSpace)
	Xsqlite3_free(tls, pV)
	Xsqlite3BitvecDestroy(tls, pBitvec)
	return rc
}

func pcacheManageDirtyList(tls *libc.TLS, pPage uintptr, addRemove U8) {
	var p uintptr = (*PgHdr)(unsafe.Pointer(pPage)).FpCache

	if int32(addRemove)&PCACHE_DIRTYLIST_REMOVE != 0 {
		if (*PCache)(unsafe.Pointer(p)).FpSynced == pPage {
			(*PCache)(unsafe.Pointer(p)).FpSynced = (*PgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev
		}

		if (*PgHdr)(unsafe.Pointer(pPage)).FpDirtyNext != 0 {
			(*PgHdr)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(pPage)).FpDirtyNext)).FpDirtyPrev = (*PgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev
		} else {
			(*PCache)(unsafe.Pointer(p)).FpDirtyTail = (*PgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev
		}
		if (*PgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev != 0 {
			(*PgHdr)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev)).FpDirtyNext = (*PgHdr)(unsafe.Pointer(pPage)).FpDirtyNext
		} else {
			(*PCache)(unsafe.Pointer(p)).FpDirty = (*PgHdr)(unsafe.Pointer(pPage)).FpDirtyNext

			if (*PCache)(unsafe.Pointer(p)).FpDirty == uintptr(0) {
				(*PCache)(unsafe.Pointer(p)).FeCreate = U8(2)
			}
		}
	}
	if int32(addRemove)&PCACHE_DIRTYLIST_ADD != 0 {
		(*PgHdr)(unsafe.Pointer(pPage)).FpDirtyPrev = uintptr(0)
		(*PgHdr)(unsafe.Pointer(pPage)).FpDirtyNext = (*PCache)(unsafe.Pointer(p)).FpDirty
		if (*PgHdr)(unsafe.Pointer(pPage)).FpDirtyNext != 0 {
			(*PgHdr)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(pPage)).FpDirtyNext)).FpDirtyPrev = pPage
		} else {
			(*PCache)(unsafe.Pointer(p)).FpDirtyTail = pPage
			if (*PCache)(unsafe.Pointer(p)).FbPurgeable != 0 {
				(*PCache)(unsafe.Pointer(p)).FeCreate = U8(1)
			}
		}
		(*PCache)(unsafe.Pointer(p)).FpDirty = pPage

		if !(int32((*PCache)(unsafe.Pointer(p)).FpSynced) != 0) &&
			0 == int32((*PgHdr)(unsafe.Pointer(pPage)).Fflags)&PGHDR_NEED_SYNC {
			(*PCache)(unsafe.Pointer(p)).FpSynced = pPage
		}
	}

}

func pcacheUnpin(tls *libc.TLS, p uintptr) {
	if (*PCache)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(p)).FpCache)).FbPurgeable != 0 {
		(*struct {
			f func(*libc.TLS, uintptr, uintptr, int32)
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxUnpin})).f(tls, (*PCache)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(p)).FpCache)).FpCache, (*PgHdr)(unsafe.Pointer(p)).FpPage, 0)

	}
}

func numberOfCachePages(tls *libc.TLS, p uintptr) int32 {
	if (*PCache)(unsafe.Pointer(p)).FszCache >= 0 {
		return (*PCache)(unsafe.Pointer(p)).FszCache
	} else {
		var n I64

		n = int64(-1024) * I64((*PCache)(unsafe.Pointer(p)).FszCache) / I64((*PCache)(unsafe.Pointer(p)).FszPage+(*PCache)(unsafe.Pointer(p)).FszExtra)
		if n > int64(1000000000) {
			n = int64(1000000000)
		}
		return int32(n)
	}
	return int32(0)
}

func Xsqlite3PcacheInitialize(tls *libc.TLS) int32 {
	if Xsqlite3Config.Fpcache2.FxInit == uintptr(0) {
		Xsqlite3PCacheSetDefault(tls)

	}
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxInit})).f(tls, Xsqlite3Config.Fpcache2.FpArg)
}

func Xsqlite3PcacheShutdown(tls *libc.TLS) {
	if Xsqlite3Config.Fpcache2.FxShutdown != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxShutdown})).f(tls, Xsqlite3Config.Fpcache2.FpArg)
	}
}

func Xsqlite3PcacheSize(tls *libc.TLS) int32 {
	return int32(unsafe.Sizeof(PCache{}))
}

func Xsqlite3PcacheOpen(tls *libc.TLS, szPage int32, szExtra int32, bPurgeable int32, xStress uintptr, pStress uintptr, p uintptr) int32 {
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(PCache{})))
	(*PCache)(unsafe.Pointer(p)).FszPage = 1
	(*PCache)(unsafe.Pointer(p)).FszExtra = szExtra

	(*PCache)(unsafe.Pointer(p)).FbPurgeable = U8(bPurgeable)
	(*PCache)(unsafe.Pointer(p)).FeCreate = U8(2)
	(*PCache)(unsafe.Pointer(p)).FxStress = xStress
	(*PCache)(unsafe.Pointer(p)).FpStress = pStress
	(*PCache)(unsafe.Pointer(p)).FszCache = 100
	(*PCache)(unsafe.Pointer(p)).FszSpill = 1

	return Xsqlite3PcacheSetPageSize(tls, p, szPage)
}

func Xsqlite3PcacheSetPageSize(tls *libc.TLS, pCache uintptr, szPage int32) int32 {
	if (*PCache)(unsafe.Pointer(pCache)).FszPage != 0 {
		var pNew uintptr
		pNew = (*struct {
			f func(*libc.TLS, int32, int32, int32) uintptr
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxCreate})).f(tls,
			szPage, int32(uint64((*PCache)(unsafe.Pointer(pCache)).FszExtra)+(uint64(unsafe.Sizeof(PgHdr{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7))),
			int32((*PCache)(unsafe.Pointer(pCache)).FbPurgeable))
		if pNew == uintptr(0) {
			return SQLITE_NOMEM
		}
		(*struct {
			f func(*libc.TLS, uintptr, int32)
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxCachesize})).f(tls, pNew, numberOfCachePages(tls, pCache))
		if (*PCache)(unsafe.Pointer(pCache)).FpCache != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxDestroy})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache)
		}
		(*PCache)(unsafe.Pointer(pCache)).FpCache = pNew
		(*PCache)(unsafe.Pointer(pCache)).FszPage = szPage

	}
	return SQLITE_OK
}

func Xsqlite3PcacheFetch(tls *libc.TLS, pCache uintptr, pgno Pgno, createFlag int32) uintptr {
	var eCreate int32
	var pRes uintptr

	eCreate = createFlag & int32((*PCache)(unsafe.Pointer(pCache)).FeCreate)

	pRes = (*struct {
		f func(*libc.TLS, uintptr, uint32, int32) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxFetch})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache, pgno, eCreate)

	return pRes
}

func Xsqlite3PcacheFetchStress(tls *libc.TLS, pCache uintptr, pgno Pgno, ppPage uintptr) int32 {
	var pPg uintptr
	if int32((*PCache)(unsafe.Pointer(pCache)).FeCreate) == 2 {
		return 0
	}

	if Xsqlite3PcachePagecount(tls, pCache) > (*PCache)(unsafe.Pointer(pCache)).FszSpill {
		for pPg = (*PCache)(unsafe.Pointer(pCache)).FpSynced; pPg != 0 && ((*PgHdr)(unsafe.Pointer(pPg)).FnRef != 0 || int32((*PgHdr)(unsafe.Pointer(pPg)).Fflags)&PGHDR_NEED_SYNC != 0); pPg = (*PgHdr)(unsafe.Pointer(pPg)).FpDirtyPrev {
		}
		(*PCache)(unsafe.Pointer(pCache)).FpSynced = pPg
		if !(pPg != 0) {
			for pPg = (*PCache)(unsafe.Pointer(pCache)).FpDirtyTail; pPg != 0 && (*PgHdr)(unsafe.Pointer(pPg)).FnRef != 0; pPg = (*PgHdr)(unsafe.Pointer(pPg)).FpDirtyPrev {
			}
		}
		if pPg != 0 {
			var rc int32

			rc = (*struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*PCache)(unsafe.Pointer(pCache)).FxStress})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpStress, pPg)

			if rc != SQLITE_OK && rc != SQLITE_BUSY {
				return rc
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(ppPage)) = (*struct {
		f func(*libc.TLS, uintptr, uint32, int32) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxFetch})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache, pgno, 2)
	if *(*uintptr)(unsafe.Pointer(ppPage)) == uintptr(0) {
		return SQLITE_NOMEM
	}
	return SQLITE_OK
}

func pcacheFetchFinishWithInit(tls *libc.TLS, pCache uintptr, pgno Pgno, pPage uintptr) uintptr {
	var pPgHdr uintptr

	pPgHdr = (*Sqlite3_pcache_page)(unsafe.Pointer(pPage)).FpExtra

	libc.Xmemset(tls, pPgHdr+32, 0, uint64(unsafe.Sizeof(PgHdr{}))-uint64(uintptr(0)+32))
	(*PgHdr)(unsafe.Pointer(pPgHdr)).FpPage = pPage
	(*PgHdr)(unsafe.Pointer(pPgHdr)).FpData = (*Sqlite3_pcache_page)(unsafe.Pointer(pPage)).FpBuf
	(*PgHdr)(unsafe.Pointer(pPgHdr)).FpExtra = pPgHdr + 1*80
	libc.Xmemset(tls, (*PgHdr)(unsafe.Pointer(pPgHdr)).FpExtra, 0, uint64(8))
	(*PgHdr)(unsafe.Pointer(pPgHdr)).FpCache = pCache
	(*PgHdr)(unsafe.Pointer(pPgHdr)).Fpgno = pgno
	(*PgHdr)(unsafe.Pointer(pPgHdr)).Fflags = U16(PGHDR_CLEAN)
	return Xsqlite3PcacheFetchFinish(tls, pCache, pgno, pPage)
}

func Xsqlite3PcacheFetchFinish(tls *libc.TLS, pCache uintptr, pgno Pgno, pPage uintptr) uintptr {
	var pPgHdr uintptr

	pPgHdr = (*Sqlite3_pcache_page)(unsafe.Pointer(pPage)).FpExtra

	if !(int32((*PgHdr)(unsafe.Pointer(pPgHdr)).FpPage) != 0) {
		return pcacheFetchFinishWithInit(tls, pCache, pgno, pPage)
	}
	(*PCache)(unsafe.Pointer(pCache)).FnRefSum++
	(*PgHdr)(unsafe.Pointer(pPgHdr)).FnRef++

	return pPgHdr
}

func Xsqlite3PcacheRelease(tls *libc.TLS, p uintptr) {
	(*PCache)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(p)).FpCache)).FnRefSum--
	if libc.PreDecInt64(&(*PgHdr)(unsafe.Pointer(p)).FnRef, 1) == int64(0) {
		if int32((*PgHdr)(unsafe.Pointer(p)).Fflags)&PGHDR_CLEAN != 0 {
			pcacheUnpin(tls, p)
		} else {
			pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_FRONT))

		}
	}
}

func Xsqlite3PcacheRef(tls *libc.TLS, p uintptr) {
	(*PgHdr)(unsafe.Pointer(p)).FnRef++
	(*PCache)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(p)).FpCache)).FnRefSum++
}

func Xsqlite3PcacheDrop(tls *libc.TLS, p uintptr) {
	if int32((*PgHdr)(unsafe.Pointer(p)).Fflags)&PGHDR_DIRTY != 0 {
		pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_REMOVE))
	}
	(*PCache)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(p)).FpCache)).FnRefSum--
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, int32)
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxUnpin})).f(tls, (*PCache)(unsafe.Pointer((*PgHdr)(unsafe.Pointer(p)).FpCache)).FpCache, (*PgHdr)(unsafe.Pointer(p)).FpPage, 1)
}

func Xsqlite3PcacheMakeDirty(tls *libc.TLS, p uintptr) {
	if int32((*PgHdr)(unsafe.Pointer(p)).Fflags)&(PGHDR_CLEAN|PGHDR_DONT_WRITE) != 0 {
		*(*U16)(unsafe.Pointer(p + 52)) &= libc.Uint16FromInt32(libc.CplInt32(PGHDR_DONT_WRITE))
		if int32((*PgHdr)(unsafe.Pointer(p)).Fflags)&PGHDR_CLEAN != 0 {
			*(*U16)(unsafe.Pointer(p + 52)) ^= U16(PGHDR_DIRTY | PGHDR_CLEAN)

			pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_ADD))

		}

	}
}

func Xsqlite3PcacheMakeClean(tls *libc.TLS, p uintptr) {
	pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_REMOVE))
	*(*U16)(unsafe.Pointer(p + 52)) &= libc.Uint16FromInt32(libc.CplInt32(PGHDR_DIRTY | PGHDR_NEED_SYNC | PGHDR_WRITEABLE))
	*(*U16)(unsafe.Pointer(p + 52)) |= U16(PGHDR_CLEAN)

	if (*PgHdr)(unsafe.Pointer(p)).FnRef == int64(0) {
		pcacheUnpin(tls, p)
	}
}

func Xsqlite3PcacheCleanAll(tls *libc.TLS, pCache uintptr) {
	var p uintptr

	for libc.AssignUintptr(&p, (*PCache)(unsafe.Pointer(pCache)).FpDirty) != uintptr(0) {
		Xsqlite3PcacheMakeClean(tls, p)
	}
}

func Xsqlite3PcacheClearWritable(tls *libc.TLS, pCache uintptr) {
	var p uintptr

	for p = (*PCache)(unsafe.Pointer(pCache)).FpDirty; p != 0; p = (*PgHdr)(unsafe.Pointer(p)).FpDirtyNext {
		*(*U16)(unsafe.Pointer(p + 52)) &= libc.Uint16FromInt32(libc.CplInt32(PGHDR_NEED_SYNC | PGHDR_WRITEABLE))
	}
	(*PCache)(unsafe.Pointer(pCache)).FpSynced = (*PCache)(unsafe.Pointer(pCache)).FpDirtyTail
}

func Xsqlite3PcacheClearSyncFlags(tls *libc.TLS, pCache uintptr) {
	var p uintptr
	for p = (*PCache)(unsafe.Pointer(pCache)).FpDirty; p != 0; p = (*PgHdr)(unsafe.Pointer(p)).FpDirtyNext {
		*(*U16)(unsafe.Pointer(p + 52)) &= libc.Uint16FromInt32(libc.CplInt32(PGHDR_NEED_SYNC))
	}
	(*PCache)(unsafe.Pointer(pCache)).FpSynced = (*PCache)(unsafe.Pointer(pCache)).FpDirtyTail
}

func Xsqlite3PcacheMove(tls *libc.TLS, p uintptr, newPgno Pgno) {
	var pCache uintptr = (*PgHdr)(unsafe.Pointer(p)).FpCache
	var pOther uintptr

	pOther = (*struct {
		f func(*libc.TLS, uintptr, uint32, int32) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxFetch})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache, newPgno, 0)
	if pOther != 0 {
		var pXPage uintptr = (*Sqlite3_pcache_page)(unsafe.Pointer(pOther)).FpExtra

		(*PgHdr)(unsafe.Pointer(pXPage)).FnRef++
		(*PCache)(unsafe.Pointer(pCache)).FnRefSum++
		Xsqlite3PcacheDrop(tls, pXPage)
	}
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uint32, uint32)
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxRekey})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache, (*PgHdr)(unsafe.Pointer(p)).FpPage, (*PgHdr)(unsafe.Pointer(p)).Fpgno, newPgno)
	(*PgHdr)(unsafe.Pointer(p)).Fpgno = newPgno
	if int32((*PgHdr)(unsafe.Pointer(p)).Fflags)&PGHDR_DIRTY != 0 && int32((*PgHdr)(unsafe.Pointer(p)).Fflags)&PGHDR_NEED_SYNC != 0 {
		pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_FRONT))

	}
}

func Xsqlite3PcacheTruncate(tls *libc.TLS, pCache uintptr, pgno Pgno) {
	if (*PCache)(unsafe.Pointer(pCache)).FpCache != 0 {
		var p uintptr
		var pNext uintptr

		for p = (*PCache)(unsafe.Pointer(pCache)).FpDirty; p != 0; p = pNext {
			pNext = (*PgHdr)(unsafe.Pointer(p)).FpDirtyNext

			if (*PgHdr)(unsafe.Pointer(p)).Fpgno > pgno {
				Xsqlite3PcacheMakeClean(tls, p)
			}
		}
		if pgno == Pgno(0) && (*PCache)(unsafe.Pointer(pCache)).FnRefSum != 0 {
			var pPage1 uintptr
			pPage1 = (*struct {
				f func(*libc.TLS, uintptr, uint32, int32) uintptr
			})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxFetch})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache, uint32(1), 0)
			if pPage1 != 0 {
				libc.Xmemset(tls, (*Sqlite3_pcache_page)(unsafe.Pointer(pPage1)).FpBuf, 0, uint64((*PCache)(unsafe.Pointer(pCache)).FszPage))
				pgno = Pgno(1)
			}
		}
		(*struct {
			f func(*libc.TLS, uintptr, uint32)
		})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxTruncate})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache, pgno+Pgno(1))
	}
}

func Xsqlite3PcacheClose(tls *libc.TLS, pCache uintptr) {
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxDestroy})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache)
}

func Xsqlite3PcacheClear(tls *libc.TLS, pCache uintptr) {
	Xsqlite3PcacheTruncate(tls, pCache, uint32(0))
}

func pcacheMergeDirtyList(tls *libc.TLS, pA uintptr, pB uintptr) uintptr {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var pTail uintptr
	pTail = bp

	for {
		if (*PgHdr)(unsafe.Pointer(pA)).Fpgno < (*PgHdr)(unsafe.Pointer(pB)).Fpgno {
			(*PgHdr)(unsafe.Pointer(pTail)).FpDirty = pA
			pTail = pA
			pA = (*PgHdr)(unsafe.Pointer(pA)).FpDirty
			if pA == uintptr(0) {
				(*PgHdr)(unsafe.Pointer(pTail)).FpDirty = pB
				break
			}
		} else {
			(*PgHdr)(unsafe.Pointer(pTail)).FpDirty = pB
			pTail = pB
			pB = (*PgHdr)(unsafe.Pointer(pB)).FpDirty
			if pB == uintptr(0) {
				(*PgHdr)(unsafe.Pointer(pTail)).FpDirty = pA
				break
			}
		}
	}
	return (*PgHdr)(unsafe.Pointer(bp)).FpDirty
}

func pcacheSortDirtyList(tls *libc.TLS, pIn uintptr) uintptr {
	bp := tls.Alloc(256)
	defer tls.Free(256)

	var p uintptr
	var i int32
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([32]uintptr{})))
	for pIn != 0 {
		p = pIn
		pIn = (*PgHdr)(unsafe.Pointer(p)).FpDirty
		(*PgHdr)(unsafe.Pointer(p)).FpDirty = uintptr(0)
		for i = 0; i < N_SORT_BUCKET-1; i++ {
			if *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = p
				break
			} else {
				p = pcacheMergeDirtyList(tls, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)), p)
				*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = uintptr(0)
			}
		}
		if i == N_SORT_BUCKET-1 {
			*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = pcacheMergeDirtyList(tls, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)), p)
		}
	}
	p = *(*uintptr)(unsafe.Pointer(bp))
	for i = 1; i < N_SORT_BUCKET; i++ {
		if *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) == uintptr(0) {
			continue
		}
		if p != 0 {
			p = pcacheMergeDirtyList(tls, p, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)))
		} else {
			p = *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8))
		}
	}
	return p
}

func Xsqlite3PcacheDirtyList(tls *libc.TLS, pCache uintptr) uintptr {
	var p uintptr
	for p = (*PCache)(unsafe.Pointer(pCache)).FpDirty; p != 0; p = (*PgHdr)(unsafe.Pointer(p)).FpDirtyNext {
		(*PgHdr)(unsafe.Pointer(p)).FpDirty = (*PgHdr)(unsafe.Pointer(p)).FpDirtyNext
	}
	return pcacheSortDirtyList(tls, (*PCache)(unsafe.Pointer(pCache)).FpDirty)
}

func Xsqlite3PcacheRefCount(tls *libc.TLS, pCache uintptr) I64 {
	return (*PCache)(unsafe.Pointer(pCache)).FnRefSum
}

func Xsqlite3PcachePageRefcount(tls *libc.TLS, p uintptr) I64 {
	return (*PgHdr)(unsafe.Pointer(p)).FnRef
}

func Xsqlite3PcachePagecount(tls *libc.TLS, pCache uintptr) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxPagecount})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache)
}

func Xsqlite3PcacheGetCachesize(tls *libc.TLS, pCache uintptr) int32 {
	return numberOfCachePages(tls, pCache)
}

func Xsqlite3PcacheSetCachesize(tls *libc.TLS, pCache uintptr, mxPage int32) {
	(*PCache)(unsafe.Pointer(pCache)).FszCache = mxPage
	(*struct {
		f func(*libc.TLS, uintptr, int32)
	})(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxCachesize})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache,
		numberOfCachePages(tls, pCache))
}

func Xsqlite3PcacheSetSpillsize(tls *libc.TLS, p uintptr, mxPage int32) int32 {
	var res int32

	if mxPage != 0 {
		if mxPage < 0 {
			mxPage = int32(int64(-1024) * I64(mxPage) / I64((*PCache)(unsafe.Pointer(p)).FszPage+(*PCache)(unsafe.Pointer(p)).FszExtra))
		}
		(*PCache)(unsafe.Pointer(p)).FszSpill = mxPage
	}
	res = numberOfCachePages(tls, p)
	if res < (*PCache)(unsafe.Pointer(p)).FszSpill {
		res = (*PCache)(unsafe.Pointer(p)).FszSpill
	}
	return res
}

func Xsqlite3PcacheShrink(tls *libc.TLS, pCache uintptr) {
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{Xsqlite3Config.Fpcache2.FxShrink})).f(tls, (*PCache)(unsafe.Pointer(pCache)).FpCache)
}

func Xsqlite3HeaderSizePcache(tls *libc.TLS) int32 {
	return int32((uint64(unsafe.Sizeof(PgHdr{})) + uint64(7)) & libc.Uint64FromInt32(libc.CplInt32(7)))
}

func Xsqlite3PCachePercentDirty(tls *libc.TLS, pCache uintptr) int32 {
	var pDirty uintptr
	var nDirty int32 = 0
	var nCache int32 = numberOfCachePages(tls, pCache)
	for pDirty = (*PCache)(unsafe.Pointer(pCache)).FpDirty; pDirty != 0; pDirty = (*PgHdr)(unsafe.Pointer(pDirty)).FpDirtyNext {
		nDirty++
	}
	if nCache != 0 {
		return int32(I64(nDirty) * int64(100) / I64(nCache))
	}
	return 0
}

type PCache11 = 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 = PCache11
type PgHdr11 = struct {
	Fpage        Sqlite3_pcache_page
	FiKey        uint32
	FisBulkLocal U16
	FisAnchor    U16
	FpNext       uintptr
	FpCache      uintptr
	FpLruNext    uintptr
	FpLruPrev    uintptr
}

type PgHdr1 = PgHdr11
type PgFreeslot1 = struct{ FpNext uintptr }

type PgFreeslot = PgFreeslot1
type PGroup1 = struct {
	Fmutex      uintptr
	FnMaxPage   uint32
	FnMinPage   uint32
	FmxPinned   uint32
	FnPurgeable uint32
	Flru        PgHdr1
}

type PGroup = PGroup1

type PCacheGlobal = struct {
	Fgrp            PGroup
	FisInit         int32
	FseparateCache  int32
	FnInitPage      int32
	FszSlot         int32
	FnSlot          int32
	FnReserve       int32
	FpStart         uintptr
	FpEnd           uintptr
	Fmutex          uintptr
	FpFree          uintptr
	FnFreeSlot      int32
	FbUnderPressure int32
}

var pcache1_g PCacheGlobal

func Xsqlite3PCacheBufferSetup(tls *libc.TLS, pBuf uintptr, sz int32, n int32) {
	if pcache1_g.FisInit != 0 {
		var p uintptr
		if pBuf == uintptr(0) {
			sz = libc.AssignInt32(&n, 0)
		}
		if n == 0 {
			sz = 0
		}
		sz = sz & libc.CplInt32(7)
		pcache1_g.FszSlot = sz
		pcache1_g.FnSlot = libc.AssignPtrInt32(uintptr(unsafe.Pointer(&pcache1_g))+136, n)
		pcache1_g.FnReserve = func() int32 {
			if n > 90 {
				return 10
			}
			return n/10 + 1
		}()
		pcache1_g.FpStart = pBuf
		pcache1_g.FpFree = uintptr(0)
		pcache1_g.FbUnderPressure = 0
		for libc.PostDecInt32(&n, 1) != 0 {
			p = pBuf
			(*PgFreeslot)(unsafe.Pointer(p)).FpNext = pcache1_g.FpFree
			pcache1_g.FpFree = p
			pBuf = pBuf + uintptr(sz)
		}
		pcache1_g.FpEnd = pBuf
	}
}

func pcache1InitBulk(tls *libc.TLS, pCache uintptr) int32 {
	var szBulk I64
	var zBulk uintptr
	if pcache1_g.FnInitPage == 0 {
		return 0
	}

	if (*PCache1)(unsafe.Pointer(pCache)).FnMax < uint32(3) {
		return 0
	}
	Xsqlite3BeginBenignMalloc(tls)
	if pcache1_g.FnInitPage > 0 {
		szBulk = I64((*PCache1)(unsafe.Pointer(pCache)).FszAlloc) * I64(pcache1_g.FnInitPage)
	} else {
		szBulk = int64(-1024) * I64(pcache1_g.FnInitPage)
	}
	if szBulk > I64((*PCache1)(unsafe.Pointer(pCache)).FszAlloc)*I64((*PCache1)(unsafe.Pointer(pCache)).FnMax) {
		szBulk = I64((*PCache1)(unsafe.Pointer(pCache)).FszAlloc) * I64((*PCache1)(unsafe.Pointer(pCache)).FnMax)
	}
	zBulk = libc.AssignPtrUintptr(pCache+80, Xsqlite3Malloc(tls, uint64(szBulk)))
	Xsqlite3EndBenignMalloc(tls)
	if zBulk != 0 {
		var nBulk int32 = Xsqlite3MallocSize(tls, zBulk) / (*PCache1)(unsafe.Pointer(pCache)).FszAlloc
		for __ccgo := true; __ccgo; __ccgo = libc.PreDecInt32(&nBulk, 1) != 0 {
			var pX uintptr = zBulk + uintptr((*PCache1)(unsafe.Pointer(pCache)).FszPage)
			(*PgHdr1)(unsafe.Pointer(pX)).Fpage.FpBuf = zBulk
			(*PgHdr1)(unsafe.Pointer(pX)).Fpage.FpExtra = pX + 1*56
			(*PgHdr1)(unsafe.Pointer(pX)).FisBulkLocal = U16(1)
			(*PgHdr1)(unsafe.Pointer(pX)).FisAnchor = U16(0)
			(*PgHdr1)(unsafe.Pointer(pX)).FpNext = (*PCache1)(unsafe.Pointer(pCache)).FpFree
			(*PgHdr1)(unsafe.Pointer(pX)).FpLruPrev = uintptr(0)
			(*PCache1)(unsafe.Pointer(pCache)).FpFree = pX
			zBulk += uintptr((*PCache1)(unsafe.Pointer(pCache)).FszAlloc)
		}
	}
	return libc.Bool32((*PCache1)(unsafe.Pointer(pCache)).FpFree != uintptr(0))
}

func pcache1Alloc(tls *libc.TLS, nByte int32) uintptr {
	var p uintptr = uintptr(0)

	if nByte <= pcache1_g.FszSlot {
		Xsqlite3_mutex_enter(tls, pcache1_g.Fmutex)
		p = pcache1_g.FpFree
		if p != 0 {
			pcache1_g.FpFree = (*PgFreeslot)(unsafe.Pointer(pcache1_g.FpFree)).FpNext
			pcache1_g.FnFreeSlot--
			pcache1_g.FbUnderPressure = libc.Bool32(pcache1_g.FnFreeSlot < pcache1_g.FnReserve)

			Xsqlite3StatusHighwater(tls, SQLITE_STATUS_PAGECACHE_SIZE, nByte)
			Xsqlite3StatusUp(tls, SQLITE_STATUS_PAGECACHE_USED, 1)
		}
		Xsqlite3_mutex_leave(tls, pcache1_g.Fmutex)
	}
	if p == uintptr(0) {
		p = Xsqlite3Malloc(tls, uint64(nByte))
		if p != 0 {
			var sz int32 = Xsqlite3MallocSize(tls, p)
			Xsqlite3_mutex_enter(tls, pcache1_g.Fmutex)
			Xsqlite3StatusHighwater(tls, SQLITE_STATUS_PAGECACHE_SIZE, nByte)
			Xsqlite3StatusUp(tls, SQLITE_STATUS_PAGECACHE_OVERFLOW, sz)
			Xsqlite3_mutex_leave(tls, pcache1_g.Fmutex)
		}

	}
	return p
}

func pcache1Free(tls *libc.TLS, p uintptr) {
	if p == uintptr(0) {
		return
	}
	if Uptr(p) >= Uptr(pcache1_g.FpStart) && Uptr(p) < Uptr(pcache1_g.FpEnd) {
		var pSlot uintptr
		Xsqlite3_mutex_enter(tls, pcache1_g.Fmutex)
		Xsqlite3StatusDown(tls, SQLITE_STATUS_PAGECACHE_USED, 1)
		pSlot = p
		(*PgFreeslot)(unsafe.Pointer(pSlot)).FpNext = pcache1_g.FpFree
		pcache1_g.FpFree = pSlot
		pcache1_g.FnFreeSlot++
		pcache1_g.FbUnderPressure = libc.Bool32(pcache1_g.FnFreeSlot < pcache1_g.FnReserve)

		Xsqlite3_mutex_leave(tls, pcache1_g.Fmutex)
	} else {
		{
			var nFreed int32 = 0
			nFreed = Xsqlite3MallocSize(tls, p)
			Xsqlite3_mutex_enter(tls, pcache1_g.Fmutex)
			Xsqlite3StatusDown(tls, SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed)
			Xsqlite3_mutex_leave(tls, pcache1_g.Fmutex)

		}
		Xsqlite3_free(tls, p)
	}
}

func pcache1MemSize(tls *libc.TLS, p uintptr) int32 {
	if p >= pcache1_g.FpStart && p < pcache1_g.FpEnd {
		return pcache1_g.FszSlot
	} else {
		var iSize int32

		iSize = Xsqlite3MallocSize(tls, p)

		return iSize
	}
	return int32(0)
}

func pcache1AllocPage(tls *libc.TLS, pCache uintptr, benignMalloc int32) uintptr {
	var p uintptr = uintptr(0)
	var pPg uintptr

	if (*PCache1)(unsafe.Pointer(pCache)).FpFree != 0 || (*PCache1)(unsafe.Pointer(pCache)).FnPage == uint32(0) && pcache1InitBulk(tls, pCache) != 0 {
		p = (*PCache1)(unsafe.Pointer(pCache)).FpFree
		(*PCache1)(unsafe.Pointer(pCache)).FpFree = (*PgHdr1)(unsafe.Pointer(p)).FpNext
		(*PgHdr1)(unsafe.Pointer(p)).FpNext = uintptr(0)
	} else {
		Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
		if benignMalloc != 0 {
			Xsqlite3BeginBenignMalloc(tls)
		}
		pPg = pcache1Alloc(tls, (*PCache1)(unsafe.Pointer(pCache)).FszAlloc)
		if benignMalloc != 0 {
			Xsqlite3EndBenignMalloc(tls)
		}
		Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
		if pPg == uintptr(0) {
			return uintptr(0)
		}
		p = pPg + uintptr((*PCache1)(unsafe.Pointer(pCache)).FszPage)
		(*PgHdr1)(unsafe.Pointer(p)).Fpage.FpBuf = pPg
		(*PgHdr1)(unsafe.Pointer(p)).Fpage.FpExtra = p + 1*56
		(*PgHdr1)(unsafe.Pointer(p)).FisBulkLocal = U16(0)
		(*PgHdr1)(unsafe.Pointer(p)).FisAnchor = U16(0)
		(*PgHdr1)(unsafe.Pointer(p)).FpLruPrev = uintptr(0)
	}
	*(*uint32)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpnPurgeable))++
	return p
}

func pcache1FreePage(tls *libc.TLS, p uintptr) {
	var pCache uintptr

	pCache = (*PgHdr1)(unsafe.Pointer(p)).FpCache

	if (*PgHdr1)(unsafe.Pointer(p)).FisBulkLocal != 0 {
		(*PgHdr1)(unsafe.Pointer(p)).FpNext = (*PCache1)(unsafe.Pointer(pCache)).FpFree
		(*PCache1)(unsafe.Pointer(pCache)).FpFree = p
	} else {
		pcache1Free(tls, (*PgHdr1)(unsafe.Pointer(p)).Fpage.FpBuf)
	}
	*(*uint32)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpnPurgeable))--
}

func Xsqlite3PageMalloc(tls *libc.TLS, sz int32) uintptr {
	return pcache1Alloc(tls, sz)
}

func Xsqlite3PageFree(tls *libc.TLS, p uintptr) {
	pcache1Free(tls, p)
}

func pcache1UnderMemoryPressure(tls *libc.TLS, pCache uintptr) int32 {
	if pcache1_g.FnSlot != 0 && (*PCache1)(unsafe.Pointer(pCache)).FszPage+(*PCache1)(unsafe.Pointer(pCache)).FszExtra <= pcache1_g.FszSlot {
		return pcache1_g.FbUnderPressure
	} else {
		return Xsqlite3HeapNearlyFull(tls)
	}
	return int32(0)
}

func pcache1ResizeHash(tls *libc.TLS, p uintptr) {
	var apNew uintptr
	var nNew uint32
	var i uint32

	nNew = (*PCache1)(unsafe.Pointer(p)).FnHash * uint32(2)
	if nNew < uint32(256) {
		nNew = uint32(256)
	}

	Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(p)).FpGroup)).Fmutex)
	if (*PCache1)(unsafe.Pointer(p)).FnHash != 0 {
		Xsqlite3BeginBenignMalloc(tls)
	}
	apNew = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(uintptr(0)))*uint64(nNew))
	if (*PCache1)(unsafe.Pointer(p)).FnHash != 0 {
		Xsqlite3EndBenignMalloc(tls)
	}
	Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(p)).FpGroup)).Fmutex)
	if apNew != 0 {
		for i = uint32(0); i < (*PCache1)(unsafe.Pointer(p)).FnHash; i++ {
			var pPage uintptr
			var pNext uintptr = *(*uintptr)(unsafe.Pointer((*PCache1)(unsafe.Pointer(p)).FapHash + uintptr(i)*8))
			for libc.AssignUintptr(&pPage, pNext) != uintptr(0) {
				var h uint32 = (*PgHdr1)(unsafe.Pointer(pPage)).FiKey % nNew
				pNext = (*PgHdr1)(unsafe.Pointer(pPage)).FpNext
				(*PgHdr1)(unsafe.Pointer(pPage)).FpNext = *(*uintptr)(unsafe.Pointer(apNew + uintptr(h)*8))
				*(*uintptr)(unsafe.Pointer(apNew + uintptr(h)*8)) = pPage
			}
		}
		Xsqlite3_free(tls, (*PCache1)(unsafe.Pointer(p)).FapHash)
		(*PCache1)(unsafe.Pointer(p)).FapHash = apNew
		(*PCache1)(unsafe.Pointer(p)).FnHash = nNew
	}
}

func pcache1PinPage(tls *libc.TLS, pPage uintptr) uintptr {
	(*PgHdr1)(unsafe.Pointer((*PgHdr1)(unsafe.Pointer(pPage)).FpLruPrev)).FpLruNext = (*PgHdr1)(unsafe.Pointer(pPage)).FpLruNext
	(*PgHdr1)(unsafe.Pointer((*PgHdr1)(unsafe.Pointer(pPage)).FpLruNext)).FpLruPrev = (*PgHdr1)(unsafe.Pointer(pPage)).FpLruPrev
	(*PgHdr1)(unsafe.Pointer(pPage)).FpLruNext = uintptr(0)

	(*PCache1)(unsafe.Pointer((*PgHdr1)(unsafe.Pointer(pPage)).FpCache)).FnRecyclable--
	return pPage
}

func pcache1RemoveFromHash(tls *libc.TLS, pPage uintptr, freeFlag int32) {
	var h uint32
	var pCache uintptr = (*PgHdr1)(unsafe.Pointer(pPage)).FpCache
	var pp uintptr

	h = (*PgHdr1)(unsafe.Pointer(pPage)).FiKey % (*PCache1)(unsafe.Pointer(pCache)).FnHash
	for pp = (*PCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*8; *(*uintptr)(unsafe.Pointer(pp)) != pPage; pp = *(*uintptr)(unsafe.Pointer(pp)) + 24 {
	}
	*(*uintptr)(unsafe.Pointer(pp)) = (*PgHdr1)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext

	(*PCache1)(unsafe.Pointer(pCache)).FnPage--
	if freeFlag != 0 {
		pcache1FreePage(tls, pPage)
	}
}

func pcache1EnforceMaxPage(tls *libc.TLS, pCache uintptr) {
	var pGroup uintptr = (*PCache1)(unsafe.Pointer(pCache)).FpGroup
	var p uintptr

	for (*PGroup)(unsafe.Pointer(pGroup)).FnPurgeable > (*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage &&
		int32((*PgHdr1)(unsafe.Pointer(libc.AssignUintptr(&p, (*PGroup)(unsafe.Pointer(pGroup)).Flru.FpLruPrev))).FisAnchor) == 0 {
		pcache1PinPage(tls, p)
		pcache1RemoveFromHash(tls, p, 1)
	}
	if (*PCache1)(unsafe.Pointer(pCache)).FnPage == uint32(0) && (*PCache1)(unsafe.Pointer(pCache)).FpBulk != 0 {
		Xsqlite3_free(tls, (*PCache1)(unsafe.Pointer(pCache)).FpBulk)
		(*PCache1)(unsafe.Pointer(pCache)).FpBulk = libc.AssignPtrUintptr(pCache+72, uintptr(0))
	}
}

func pcache1TruncateUnsafe(tls *libc.TLS, pCache uintptr, iLimit uint32) {
	var h uint32
	var iStop uint32

	if (*PCache1)(unsafe.Pointer(pCache)).FiMaxKey-iLimit < (*PCache1)(unsafe.Pointer(pCache)).FnHash {
		h = iLimit % (*PCache1)(unsafe.Pointer(pCache)).FnHash
		iStop = (*PCache1)(unsafe.Pointer(pCache)).FiMaxKey % (*PCache1)(unsafe.Pointer(pCache)).FnHash

	} else {
		h = (*PCache1)(unsafe.Pointer(pCache)).FnHash / uint32(2)
		iStop = h - uint32(1)
	}
	for {
		var pp uintptr
		var pPage uintptr

		pp = (*PCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*8
		for libc.AssignUintptr(&pPage, *(*uintptr)(unsafe.Pointer(pp))) != uintptr(0) {
			if (*PgHdr1)(unsafe.Pointer(pPage)).FiKey >= iLimit {
				(*PCache1)(unsafe.Pointer(pCache)).FnPage--
				*(*uintptr)(unsafe.Pointer(pp)) = (*PgHdr1)(unsafe.Pointer(pPage)).FpNext
				if (*PgHdr1)(unsafe.Pointer(pPage)).FpLruNext != uintptr(0) {
					pcache1PinPage(tls, pPage)
				}
				pcache1FreePage(tls, pPage)
			} else {
				pp = pPage + 24

			}
		}
		if h == iStop {
			break
		}
		h = (h + uint32(1)) % (*PCache1)(unsafe.Pointer(pCache)).FnHash
	}

}

func pcache1Init(tls *libc.TLS, NotUsed uintptr) int32 {
	_ = NotUsed

	libc.Xmemset(tls, uintptr(unsafe.Pointer(&pcache1_g)), 0, uint64(unsafe.Sizeof(pcache1_g)))

	pcache1_g.FseparateCache = 0

	if Xsqlite3Config.FbCoreMutex != 0 {
		pcache1_g.Fgrp.Fmutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_LRU)
		pcache1_g.Fmutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_PMEM)
	}
	if pcache1_g.FseparateCache != 0 &&
		Xsqlite3Config.FnPage != 0 &&
		Xsqlite3Config.FpPage == uintptr(0) {
		pcache1_g.FnInitPage = Xsqlite3Config.FnPage
	} else {
		pcache1_g.FnInitPage = 0
	}
	pcache1_g.Fgrp.FmxPinned = uint32(10)
	pcache1_g.FisInit = 1
	return SQLITE_OK
}

func pcache1Shutdown(tls *libc.TLS, NotUsed uintptr) {
	_ = NotUsed

	libc.Xmemset(tls, uintptr(unsafe.Pointer(&pcache1_g)), 0, uint64(unsafe.Sizeof(pcache1_g)))
}

func pcache1Create(tls *libc.TLS, szPage int32, szExtra int32, bPurgeable int32) uintptr {
	var pCache uintptr
	var pGroup uintptr
	var sz int32

	sz = int32(uint64(unsafe.Sizeof(PCache1{})) + uint64(unsafe.Sizeof(PGroup{}))*uint64(pcache1_g.FseparateCache))
	pCache = Xsqlite3MallocZero(tls, uint64(sz))
	if pCache != 0 {
		if pcache1_g.FseparateCache != 0 {
			pGroup = pCache + 1*88
			(*PGroup)(unsafe.Pointer(pGroup)).FmxPinned = uint32(10)
		} else {
			pGroup = uintptr(unsafe.Pointer(&pcache1_g))
		}
		Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)
		if int32((*PGroup)(unsafe.Pointer(pGroup)).Flru.FisAnchor) == 0 {
			(*PGroup)(unsafe.Pointer(pGroup)).Flru.FisAnchor = U16(1)
			(*PGroup)(unsafe.Pointer(pGroup)).Flru.FpLruPrev = libc.AssignPtrUintptr(pGroup+24+40, pGroup+24)
		}
		(*PCache1)(unsafe.Pointer(pCache)).FpGroup = pGroup
		(*PCache1)(unsafe.Pointer(pCache)).FszPage = szPage
		(*PCache1)(unsafe.Pointer(pCache)).FszExtra = szExtra
		(*PCache1)(unsafe.Pointer(pCache)).FszAlloc = int32(uint64(szPage+szExtra) + (uint64(unsafe.Sizeof(PgHdr1{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7)))
		(*PCache1)(unsafe.Pointer(pCache)).FbPurgeable = func() int32 {
			if bPurgeable != 0 {
				return 1
			}
			return 0
		}()
		pcache1ResizeHash(tls, pCache)
		if bPurgeable != 0 {
			(*PCache1)(unsafe.Pointer(pCache)).FnMin = uint32(10)
			*(*uint32)(unsafe.Pointer(pGroup + 12)) += (*PCache1)(unsafe.Pointer(pCache)).FnMin
			(*PGroup)(unsafe.Pointer(pGroup)).FmxPinned = (*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage + uint32(10) - (*PGroup)(unsafe.Pointer(pGroup)).FnMinPage
			(*PCache1)(unsafe.Pointer(pCache)).FpnPurgeable = pGroup + 20
		} else {
			(*PCache1)(unsafe.Pointer(pCache)).FpnPurgeable = pCache + 48
		}
		Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)
		if (*PCache1)(unsafe.Pointer(pCache)).FnHash == uint32(0) {
			pcache1Destroy(tls, pCache)
			pCache = uintptr(0)
		}
	}
	return pCache
}

func pcache1Cachesize(tls *libc.TLS, p uintptr, nMax int32) {
	var pCache uintptr = p
	var n U32

	if (*PCache1)(unsafe.Pointer(pCache)).FbPurgeable != 0 {
		var pGroup uintptr = (*PCache1)(unsafe.Pointer(pCache)).FpGroup
		Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)
		n = U32(nMax)
		if n > uint32(0x7fff0000)-(*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage+(*PCache1)(unsafe.Pointer(pCache)).FnMax {
			n = uint32(0x7fff0000) - (*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage + (*PCache1)(unsafe.Pointer(pCache)).FnMax
		}
		*(*uint32)(unsafe.Pointer(pGroup + 8)) += n - (*PCache1)(unsafe.Pointer(pCache)).FnMax
		(*PGroup)(unsafe.Pointer(pGroup)).FmxPinned = (*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage + uint32(10) - (*PGroup)(unsafe.Pointer(pGroup)).FnMinPage
		(*PCache1)(unsafe.Pointer(pCache)).FnMax = n
		(*PCache1)(unsafe.Pointer(pCache)).Fn90pct = (*PCache1)(unsafe.Pointer(pCache)).FnMax * uint32(9) / uint32(10)
		pcache1EnforceMaxPage(tls, pCache)
		Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)
	}
}

func pcache1Shrink(tls *libc.TLS, p uintptr) {
	var pCache uintptr = p
	if (*PCache1)(unsafe.Pointer(pCache)).FbPurgeable != 0 {
		var pGroup uintptr = (*PCache1)(unsafe.Pointer(pCache)).FpGroup
		var savedMaxPage uint32
		Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)
		savedMaxPage = (*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage
		(*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage = uint32(0)
		pcache1EnforceMaxPage(tls, pCache)
		(*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage = savedMaxPage
		Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)
	}
}

func pcache1Pagecount(tls *libc.TLS, p uintptr) int32 {
	var n int32
	var pCache uintptr = p
	Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	n = int32((*PCache1)(unsafe.Pointer(pCache)).FnPage)
	Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	return n
}

func pcache1FetchStage2(tls *libc.TLS, pCache uintptr, iKey uint32, createFlag int32) uintptr {
	var nPinned uint32
	var pGroup uintptr = (*PCache1)(unsafe.Pointer(pCache)).FpGroup
	var pPage uintptr = uintptr(0)

	nPinned = (*PCache1)(unsafe.Pointer(pCache)).FnPage - (*PCache1)(unsafe.Pointer(pCache)).FnRecyclable

	if createFlag == 1 && (nPinned >= (*PGroup)(unsafe.Pointer(pGroup)).FmxPinned ||
		nPinned >= (*PCache1)(unsafe.Pointer(pCache)).Fn90pct ||
		pcache1UnderMemoryPressure(tls, pCache) != 0 && (*PCache1)(unsafe.Pointer(pCache)).FnRecyclable < nPinned) {
		return uintptr(0)
	}

	if (*PCache1)(unsafe.Pointer(pCache)).FnPage >= (*PCache1)(unsafe.Pointer(pCache)).FnHash {
		pcache1ResizeHash(tls, pCache)
	}

	if (*PCache1)(unsafe.Pointer(pCache)).FbPurgeable != 0 &&
		!(int32((*PgHdr1)(unsafe.Pointer((*PGroup)(unsafe.Pointer(pGroup)).Flru.FpLruPrev)).FisAnchor) != 0) &&
		((*PCache1)(unsafe.Pointer(pCache)).FnPage+uint32(1) >= (*PCache1)(unsafe.Pointer(pCache)).FnMax || pcache1UnderMemoryPressure(tls, pCache) != 0) {
		var pOther uintptr
		pPage = (*PGroup)(unsafe.Pointer(pGroup)).Flru.FpLruPrev

		pcache1RemoveFromHash(tls, pPage, 0)
		pcache1PinPage(tls, pPage)
		pOther = (*PgHdr1)(unsafe.Pointer(pPage)).FpCache
		if (*PCache1)(unsafe.Pointer(pOther)).FszAlloc != (*PCache1)(unsafe.Pointer(pCache)).FszAlloc {
			pcache1FreePage(tls, pPage)
			pPage = uintptr(0)
		} else {
			*(*uint32)(unsafe.Pointer(pGroup + 20)) -= uint32((*PCache1)(unsafe.Pointer(pOther)).FbPurgeable - (*PCache1)(unsafe.Pointer(pCache)).FbPurgeable)
		}
	}

	if !(pPage != 0) {
		pPage = pcache1AllocPage(tls, pCache, libc.Bool32(createFlag == 1))
	}

	if pPage != 0 {
		var h uint32 = iKey % (*PCache1)(unsafe.Pointer(pCache)).FnHash
		(*PCache1)(unsafe.Pointer(pCache)).FnPage++
		(*PgHdr1)(unsafe.Pointer(pPage)).FiKey = iKey
		(*PgHdr1)(unsafe.Pointer(pPage)).FpNext = *(*uintptr)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*8))
		(*PgHdr1)(unsafe.Pointer(pPage)).FpCache = pCache
		(*PgHdr1)(unsafe.Pointer(pPage)).FpLruNext = uintptr(0)

		*(*uintptr)(unsafe.Pointer((*PgHdr1)(unsafe.Pointer(pPage)).Fpage.FpExtra)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*8)) = pPage
		if iKey > (*PCache1)(unsafe.Pointer(pCache)).FiMaxKey {
			(*PCache1)(unsafe.Pointer(pCache)).FiMaxKey = iKey
		}
	}
	return pPage
}

func pcache1FetchNoMutex(tls *libc.TLS, p uintptr, iKey uint32, createFlag int32) uintptr {
	var pCache uintptr = p
	var pPage uintptr = uintptr(0)

	pPage = *(*uintptr)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(iKey%(*PCache1)(unsafe.Pointer(pCache)).FnHash)*8))
	for pPage != 0 && (*PgHdr1)(unsafe.Pointer(pPage)).FiKey != iKey {
		pPage = (*PgHdr1)(unsafe.Pointer(pPage)).FpNext
	}

	if pPage != 0 {
		if (*PgHdr1)(unsafe.Pointer(pPage)).FpLruNext != uintptr(0) {
			return pcache1PinPage(tls, pPage)
		} else {
			return pPage
		}
	} else if createFlag != 0 {
		return pcache1FetchStage2(tls, pCache, iKey, createFlag)
	} else {
		return uintptr(0)
	}
	return uintptr(0)
}

func pcache1FetchWithMutex(tls *libc.TLS, p uintptr, iKey uint32, createFlag int32) uintptr {
	var pCache uintptr = p
	var pPage uintptr

	Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	pPage = pcache1FetchNoMutex(tls, p, iKey, createFlag)

	Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	return pPage
}

func pcache1Fetch(tls *libc.TLS, p uintptr, iKey uint32, createFlag int32) uintptr {
	var pCache uintptr = p

	if (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex != 0 {
		return pcache1FetchWithMutex(tls, p, iKey, createFlag)
	} else {
		return pcache1FetchNoMutex(tls, p, iKey, createFlag)
	}
	return uintptr(0)
}

func pcache1Unpin(tls *libc.TLS, p uintptr, pPg uintptr, reuseUnlikely int32) {
	var pCache uintptr = p
	var pPage uintptr = pPg
	var pGroup uintptr = (*PCache1)(unsafe.Pointer(pCache)).FpGroup

	Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)

	if reuseUnlikely != 0 || (*PGroup)(unsafe.Pointer(pGroup)).FnPurgeable > (*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage {
		pcache1RemoveFromHash(tls, pPage, 1)
	} else {
		var ppFirst uintptr = pGroup + 24 + 40
		(*PgHdr1)(unsafe.Pointer(pPage)).FpLruPrev = pGroup + 24
		(*PgHdr1)(unsafe.Pointer(libc.AssignPtrUintptr(pPage+40, *(*uintptr)(unsafe.Pointer(ppFirst))))).FpLruPrev = pPage
		*(*uintptr)(unsafe.Pointer(ppFirst)) = pPage
		(*PCache1)(unsafe.Pointer(pCache)).FnRecyclable++
	}

	Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
}

func pcache1Rekey(tls *libc.TLS, p uintptr, pPg uintptr, iOld uint32, iNew uint32) {
	var pCache uintptr = p
	var pPage uintptr = pPg
	var pp uintptr
	var hOld uint32
	var hNew uint32

	Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)

	hOld = iOld % (*PCache1)(unsafe.Pointer(pCache)).FnHash
	pp = (*PCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hOld)*8
	for *(*uintptr)(unsafe.Pointer(pp)) != pPage {
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 24
	}
	*(*uintptr)(unsafe.Pointer(pp)) = (*PgHdr1)(unsafe.Pointer(pPage)).FpNext

	hNew = iNew % (*PCache1)(unsafe.Pointer(pCache)).FnHash
	(*PgHdr1)(unsafe.Pointer(pPage)).FiKey = iNew
	(*PgHdr1)(unsafe.Pointer(pPage)).FpNext = *(*uintptr)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hNew)*8))
	*(*uintptr)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hNew)*8)) = pPage
	if iNew > (*PCache1)(unsafe.Pointer(pCache)).FiMaxKey {
		(*PCache1)(unsafe.Pointer(pCache)).FiMaxKey = iNew
	}

	Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
}

func pcache1Truncate(tls *libc.TLS, p uintptr, iLimit uint32) {
	var pCache uintptr = p
	Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	if iLimit <= (*PCache1)(unsafe.Pointer(pCache)).FiMaxKey {
		pcache1TruncateUnsafe(tls, pCache, iLimit)
		(*PCache1)(unsafe.Pointer(pCache)).FiMaxKey = iLimit - uint32(1)
	}
	Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer((*PCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
}

func pcache1Destroy(tls *libc.TLS, p uintptr) {
	var pCache uintptr = p
	var pGroup uintptr = (*PCache1)(unsafe.Pointer(pCache)).FpGroup

	Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)
	if (*PCache1)(unsafe.Pointer(pCache)).FnPage != 0 {
		pcache1TruncateUnsafe(tls, pCache, uint32(0))
	}

	*(*uint32)(unsafe.Pointer(pGroup + 8)) -= (*PCache1)(unsafe.Pointer(pCache)).FnMax

	*(*uint32)(unsafe.Pointer(pGroup + 12)) -= (*PCache1)(unsafe.Pointer(pCache)).FnMin
	(*PGroup)(unsafe.Pointer(pGroup)).FmxPinned = (*PGroup)(unsafe.Pointer(pGroup)).FnMaxPage + uint32(10) - (*PGroup)(unsafe.Pointer(pGroup)).FnMinPage
	pcache1EnforceMaxPage(tls, pCache)
	Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer(pGroup)).Fmutex)
	Xsqlite3_free(tls, (*PCache1)(unsafe.Pointer(pCache)).FpBulk)
	Xsqlite3_free(tls, (*PCache1)(unsafe.Pointer(pCache)).FapHash)
	Xsqlite3_free(tls, pCache)
}

func Xsqlite3PCacheSetDefault(tls *libc.TLS) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	Xsqlite3_config(tls, SQLITE_CONFIG_PCACHE2, libc.VaList(bp, uintptr(unsafe.Pointer(&defaultMethods1))))
}

var defaultMethods1 = Sqlite3_pcache_methods2{
	FiVersion:   1,
	FxInit:      0,
	FxShutdown:  0,
	FxCreate:    0,
	FxCachesize: 0,
	FxPagecount: 0,
	FxFetch:     0,
	FxUnpin:     0,
	FxRekey:     0,
	FxTruncate:  0,
	FxDestroy:   0,
	FxShrink:    0,
}

func Xsqlite3HeaderSizePcache1(tls *libc.TLS) int32 {
	return int32((uint64(unsafe.Sizeof(PgHdr1{})) + uint64(7)) & libc.Uint64FromInt32(libc.CplInt32(7)))
}

func Xsqlite3Pcache1Mutex(tls *libc.TLS) uintptr {
	return pcache1_g.Fmutex
}

func Xsqlite3PcacheReleaseMemory(tls *libc.TLS, nReq int32) int32 {
	var nFree int32 = 0

	if Xsqlite3Config.FpPage == uintptr(0) {
		var p uintptr
		Xsqlite3_mutex_enter(tls, (*PGroup)(unsafe.Pointer(uintptr(unsafe.Pointer(&pcache1_g)))).Fmutex)
		for (nReq < 0 || nFree < nReq) &&
			libc.AssignUintptr(&p, pcache1_g.Fgrp.Flru.FpLruPrev) != uintptr(0) &&
			int32((*PgHdr1)(unsafe.Pointer(p)).FisAnchor) == 0 {
			nFree = nFree + pcache1MemSize(tls, (*PgHdr1)(unsafe.Pointer(p)).Fpage.FpBuf)

			pcache1PinPage(tls, p)
			pcache1RemoveFromHash(tls, p, 1)
		}
		Xsqlite3_mutex_leave(tls, (*PGroup)(unsafe.Pointer(uintptr(unsafe.Pointer(&pcache1_g)))).Fmutex)
	}
	return nFree
}

func Xsqlite3PcacheStats(tls *libc.TLS, pnCurrent uintptr, pnMax uintptr, pnMin uintptr, pnRecyclable uintptr) {
	var p uintptr
	var nRecyclable int32 = 0
	for p = pcache1_g.Fgrp.Flru.FpLruNext; p != 0 && !(int32((*PgHdr1)(unsafe.Pointer(p)).FisAnchor) != 0); p = (*PgHdr1)(unsafe.Pointer(p)).FpLruNext {
		nRecyclable++
	}
	*(*int32)(unsafe.Pointer(pnCurrent)) = int32(pcache1_g.Fgrp.FnPurgeable)
	*(*int32)(unsafe.Pointer(pnMax)) = int32(pcache1_g.Fgrp.FnMaxPage)
	*(*int32)(unsafe.Pointer(pnMin)) = int32(pcache1_g.Fgrp.FnMinPage)
	*(*int32)(unsafe.Pointer(pnRecyclable)) = nRecyclable
}

type RowSetEntry = struct {
	Fv      I64
	FpRight uintptr
	FpLeft  uintptr
}

type RowSetChunk = struct {
	FpNextChunk uintptr
	FaEntry     [42]struct {
		Fv      I64
		FpRight uintptr
		FpLeft  uintptr
	}
}

func Xsqlite3RowSetInit(tls *libc.TLS, db uintptr) uintptr {
	var p uintptr = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(RowSet{})))
	if p != 0 {
		var N int32 = Xsqlite3DbMallocSize(tls, db, p)
		(*RowSet)(unsafe.Pointer(p)).FpChunk = uintptr(0)
		(*RowSet)(unsafe.Pointer(p)).Fdb = db
		(*RowSet)(unsafe.Pointer(p)).FpEntry = uintptr(0)
		(*RowSet)(unsafe.Pointer(p)).FpLast = uintptr(0)
		(*RowSet)(unsafe.Pointer(p)).FpForest = uintptr(0)
		(*RowSet)(unsafe.Pointer(p)).FpFresh = uintptr((uint64(unsafe.Sizeof(RowSet{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7))) + p
		(*RowSet)(unsafe.Pointer(p)).FnFresh = U16((uint64(N) - (uint64(unsafe.Sizeof(RowSet{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7))) / uint64(unsafe.Sizeof(RowSetEntry{})))
		(*RowSet)(unsafe.Pointer(p)).FrsFlags = U16(ROWSET_SORTED)
		(*RowSet)(unsafe.Pointer(p)).FiBatch = 0
	}
	return p
}

func Xsqlite3RowSetClear(tls *libc.TLS, pArg uintptr) {
	var p uintptr = pArg
	var pChunk uintptr
	var pNextChunk uintptr
	for pChunk = (*RowSet)(unsafe.Pointer(p)).FpChunk; pChunk != 0; pChunk = pNextChunk {
		pNextChunk = (*RowSetChunk)(unsafe.Pointer(pChunk)).FpNextChunk
		Xsqlite3DbFree(tls, (*RowSet)(unsafe.Pointer(p)).Fdb, pChunk)
	}
	(*RowSet)(unsafe.Pointer(p)).FpChunk = uintptr(0)
	(*RowSet)(unsafe.Pointer(p)).FnFresh = U16(0)
	(*RowSet)(unsafe.Pointer(p)).FpEntry = uintptr(0)
	(*RowSet)(unsafe.Pointer(p)).FpLast = uintptr(0)
	(*RowSet)(unsafe.Pointer(p)).FpForest = uintptr(0)
	(*RowSet)(unsafe.Pointer(p)).FrsFlags = U16(ROWSET_SORTED)
}

func Xsqlite3RowSetDelete(tls *libc.TLS, pArg uintptr) {
	Xsqlite3RowSetClear(tls, pArg)
	Xsqlite3DbFree(tls, (*RowSet)(unsafe.Pointer(pArg)).Fdb, pArg)
}

func rowSetEntryAlloc(tls *libc.TLS, p uintptr) uintptr {
	if int32((*RowSet)(unsafe.Pointer(p)).FnFresh) == 0 {
		var pNew uintptr
		pNew = Xsqlite3DbMallocRawNN(tls, (*RowSet)(unsafe.Pointer(p)).Fdb, uint64(unsafe.Sizeof(RowSetChunk{})))
		if pNew == uintptr(0) {
			return uintptr(0)
		}
		(*RowSetChunk)(unsafe.Pointer(pNew)).FpNextChunk = (*RowSet)(unsafe.Pointer(p)).FpChunk
		(*RowSet)(unsafe.Pointer(p)).FpChunk = pNew
		(*RowSet)(unsafe.Pointer(p)).FpFresh = pNew + 8
		(*RowSet)(unsafe.Pointer(p)).FnFresh = uint16(uint64(ROWSET_ALLOCATION_SIZE-8) / uint64(unsafe.Sizeof(RowSetEntry{})))
	}
	(*RowSet)(unsafe.Pointer(p)).FnFresh--
	return libc.PostIncUintptr(&(*RowSet)(unsafe.Pointer(p)).FpFresh, 24)
}

func Xsqlite3RowSetInsert(tls *libc.TLS, p uintptr, rowid I64) {
	var pEntry uintptr
	var pLast uintptr

	pEntry = rowSetEntryAlloc(tls, p)
	if pEntry == uintptr(0) {
		return
	}
	(*RowSetEntry)(unsafe.Pointer(pEntry)).Fv = rowid
	(*RowSetEntry)(unsafe.Pointer(pEntry)).FpRight = uintptr(0)
	pLast = (*RowSet)(unsafe.Pointer(p)).FpLast
	if pLast != 0 {
		if rowid <= (*RowSetEntry)(unsafe.Pointer(pLast)).Fv {
			*(*U16)(unsafe.Pointer(p + 50)) &= libc.Uint16FromInt32(libc.CplInt32(ROWSET_SORTED))
		}
		(*RowSetEntry)(unsafe.Pointer(pLast)).FpRight = pEntry
	} else {
		(*RowSet)(unsafe.Pointer(p)).FpEntry = pEntry
	}
	(*RowSet)(unsafe.Pointer(p)).FpLast = pEntry
}

func rowSetEntryMerge(tls *libc.TLS, pA uintptr, pB uintptr) uintptr {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pTail uintptr

	pTail = bp

	for {
		if (*RowSetEntry)(unsafe.Pointer(pA)).Fv <= (*RowSetEntry)(unsafe.Pointer(pB)).Fv {
			if (*RowSetEntry)(unsafe.Pointer(pA)).Fv < (*RowSetEntry)(unsafe.Pointer(pB)).Fv {
				pTail = libc.AssignPtrUintptr(pTail+8, pA)
			}
			pA = (*RowSetEntry)(unsafe.Pointer(pA)).FpRight
			if pA == uintptr(0) {
				(*RowSetEntry)(unsafe.Pointer(pTail)).FpRight = pB
				break
			}
		} else {
			pTail = libc.AssignPtrUintptr(pTail+8, pB)
			pB = (*RowSetEntry)(unsafe.Pointer(pB)).FpRight
			if pB == uintptr(0) {
				(*RowSetEntry)(unsafe.Pointer(pTail)).FpRight = pA
				break
			}
		}
	}
	return (*RowSetEntry)(unsafe.Pointer(bp)).FpRight
}

func rowSetEntrySort(tls *libc.TLS, pIn uintptr) uintptr {
	bp := tls.Alloc(320)
	defer tls.Free(320)

	var i uint32
	var pNext uintptr

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([40]uintptr{})))
	for pIn != 0 {
		pNext = (*RowSetEntry)(unsafe.Pointer(pIn)).FpRight
		(*RowSetEntry)(unsafe.Pointer(pIn)).FpRight = uintptr(0)
		for i = uint32(0); *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) != 0; i++ {
			pIn = rowSetEntryMerge(tls, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)), pIn)
			*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = uintptr(0)
		}
		*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = pIn
		pIn = pNext
	}
	pIn = *(*uintptr)(unsafe.Pointer(bp))
	for i = uint32(1); uint64(i) < uint64(unsafe.Sizeof([40]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0))); i++ {
		if *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) == uintptr(0) {
			continue
		}
		if pIn != 0 {
			pIn = rowSetEntryMerge(tls, pIn, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)))
		} else {
			pIn = *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8))
		}
	}
	return pIn
}

func rowSetTreeToList(tls *libc.TLS, pIn uintptr, ppFirst uintptr, ppLast uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if (*RowSetEntry)(unsafe.Pointer(pIn)).FpLeft != 0 {
		rowSetTreeToList(tls, (*RowSetEntry)(unsafe.Pointer(pIn)).FpLeft, ppFirst, bp)
		(*RowSetEntry)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpRight = pIn
	} else {
		*(*uintptr)(unsafe.Pointer(ppFirst)) = pIn
	}
	if (*RowSetEntry)(unsafe.Pointer(pIn)).FpRight != 0 {
		rowSetTreeToList(tls, (*RowSetEntry)(unsafe.Pointer(pIn)).FpRight, pIn+8, ppLast)
	} else {
		*(*uintptr)(unsafe.Pointer(ppLast)) = pIn
	}

}

func rowSetNDeepTree(tls *libc.TLS, ppList uintptr, iDepth int32) uintptr {
	var p uintptr
	var pLeft uintptr
	if *(*uintptr)(unsafe.Pointer(ppList)) == uintptr(0) {
		return uintptr(0)
	}
	if iDepth > 1 {
		pLeft = rowSetNDeepTree(tls, ppList, iDepth-1)
		p = *(*uintptr)(unsafe.Pointer(ppList))
		if p == uintptr(0) {
			return pLeft
		}
		(*RowSetEntry)(unsafe.Pointer(p)).FpLeft = pLeft
		*(*uintptr)(unsafe.Pointer(ppList)) = (*RowSetEntry)(unsafe.Pointer(p)).FpRight
		(*RowSetEntry)(unsafe.Pointer(p)).FpRight = rowSetNDeepTree(tls, ppList, iDepth-1)
	} else {
		p = *(*uintptr)(unsafe.Pointer(ppList))
		*(*uintptr)(unsafe.Pointer(ppList)) = (*RowSetEntry)(unsafe.Pointer(p)).FpRight
		(*RowSetEntry)(unsafe.Pointer(p)).FpLeft = libc.AssignPtrUintptr(p+8, uintptr(0))
	}
	return p
}

func rowSetListToTree(tls *libc.TLS, pList uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = pList

	var iDepth int32
	var p uintptr
	var pLeft uintptr

	p = *(*uintptr)(unsafe.Pointer(bp))
	*(*uintptr)(unsafe.Pointer(bp)) = (*RowSetEntry)(unsafe.Pointer(p)).FpRight
	(*RowSetEntry)(unsafe.Pointer(p)).FpLeft = libc.AssignPtrUintptr(p+8, uintptr(0))
	for iDepth = 1; *(*uintptr)(unsafe.Pointer(bp)) != 0; iDepth++ {
		pLeft = p
		p = *(*uintptr)(unsafe.Pointer(bp))
		*(*uintptr)(unsafe.Pointer(bp)) = (*RowSetEntry)(unsafe.Pointer(p)).FpRight
		(*RowSetEntry)(unsafe.Pointer(p)).FpLeft = pLeft
		(*RowSetEntry)(unsafe.Pointer(p)).FpRight = rowSetNDeepTree(tls, bp, iDepth)
	}
	return p
}

func Xsqlite3RowSetNext(tls *libc.TLS, p uintptr, pRowid uintptr) int32 {
	if int32((*RowSet)(unsafe.Pointer(p)).FrsFlags)&ROWSET_NEXT == 0 {
		if int32((*RowSet)(unsafe.Pointer(p)).FrsFlags)&ROWSET_SORTED == 0 {
			(*RowSet)(unsafe.Pointer(p)).FpEntry = rowSetEntrySort(tls, (*RowSet)(unsafe.Pointer(p)).FpEntry)
		}
		*(*U16)(unsafe.Pointer(p + 50)) |= U16(ROWSET_SORTED | ROWSET_NEXT)
	}

	if (*RowSet)(unsafe.Pointer(p)).FpEntry != 0 {
		*(*I64)(unsafe.Pointer(pRowid)) = (*RowSetEntry)(unsafe.Pointer((*RowSet)(unsafe.Pointer(p)).FpEntry)).Fv
		(*RowSet)(unsafe.Pointer(p)).FpEntry = (*RowSetEntry)(unsafe.Pointer((*RowSet)(unsafe.Pointer(p)).FpEntry)).FpRight
		if (*RowSet)(unsafe.Pointer(p)).FpEntry == uintptr(0) {
			Xsqlite3RowSetClear(tls, p)
		}
		return 1
	} else {
		return 0
	}
	return int32(0)
}

func Xsqlite3RowSetTest(tls *libc.TLS, pRowSet uintptr, iBatch int32, iRowid Sqlite3_int64) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var p uintptr
	var pTree uintptr

	if iBatch != (*RowSet)(unsafe.Pointer(pRowSet)).FiBatch {
		p = (*RowSet)(unsafe.Pointer(pRowSet)).FpEntry
		if p != 0 {
			var ppPrevTree uintptr = pRowSet + 40
			if int32((*RowSet)(unsafe.Pointer(pRowSet)).FrsFlags)&ROWSET_SORTED == 0 {
				p = rowSetEntrySort(tls, p)
			}
			for pTree = (*RowSet)(unsafe.Pointer(pRowSet)).FpForest; pTree != 0; pTree = (*RowSetEntry)(unsafe.Pointer(pTree)).FpRight {
				ppPrevTree = pTree + 8
				if (*RowSetEntry)(unsafe.Pointer(pTree)).FpLeft == uintptr(0) {
					(*RowSetEntry)(unsafe.Pointer(pTree)).FpLeft = rowSetListToTree(tls, p)
					break
				} else {
					rowSetTreeToList(tls, (*RowSetEntry)(unsafe.Pointer(pTree)).FpLeft, bp, bp+8)
					(*RowSetEntry)(unsafe.Pointer(pTree)).FpLeft = uintptr(0)
					p = rowSetEntryMerge(tls, *(*uintptr)(unsafe.Pointer(bp)), p)
				}
			}
			if pTree == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(ppPrevTree)) = libc.AssignUintptr(&pTree, rowSetEntryAlloc(tls, pRowSet))
				if pTree != 0 {
					(*RowSetEntry)(unsafe.Pointer(pTree)).Fv = int64(0)
					(*RowSetEntry)(unsafe.Pointer(pTree)).FpRight = uintptr(0)
					(*RowSetEntry)(unsafe.Pointer(pTree)).FpLeft = rowSetListToTree(tls, p)
				}
			}
			(*RowSet)(unsafe.Pointer(pRowSet)).FpEntry = uintptr(0)
			(*RowSet)(unsafe.Pointer(pRowSet)).FpLast = uintptr(0)
			*(*U16)(unsafe.Pointer(pRowSet + 50)) |= U16(ROWSET_SORTED)
		}
		(*RowSet)(unsafe.Pointer(pRowSet)).FiBatch = iBatch
	}

	for pTree = (*RowSet)(unsafe.Pointer(pRowSet)).FpForest; pTree != 0; pTree = (*RowSetEntry)(unsafe.Pointer(pTree)).FpRight {
		p = (*RowSetEntry)(unsafe.Pointer(pTree)).FpLeft
		for p != 0 {
			if (*RowSetEntry)(unsafe.Pointer(p)).Fv < iRowid {
				p = (*RowSetEntry)(unsafe.Pointer(p)).FpRight
			} else if (*RowSetEntry)(unsafe.Pointer(p)).Fv > iRowid {
				p = (*RowSetEntry)(unsafe.Pointer(p)).FpLeft
			} else {
				return 1
			}
		}
	}
	return 0
}

type Wal1 = struct {
	FpVfs                uintptr
	FpDbFd               uintptr
	FpWalFd              uintptr
	FiCallback           U32
	F__ccgo_pad1         [4]byte
	FmxWalSize           I64
	FnWiData             int32
	FszFirstBlock        int32
	FapWiData            uintptr
	FszPage              U32
	FreadLock            I16
	FsyncFlags           U8
	FexclusiveMode       U8
	FwriteLock           U8
	FckptLock            U8
	FreadOnly            U8
	FtruncateOnCommit    U8
	FsyncHeader          U8
	FpadToSectorBoundary U8
	FbShmUnreliable      U8
	F__ccgo_pad2         [1]byte
	Fhdr                 WalIndexHdr
	FminFrame            U32
	FiReCksum            U32
	FzWalName            uintptr
	FnCkpt               U32
	F__ccgo_pad3         [4]byte
}

type Wal = Wal1

type PagerSavepoint1 = struct {
	FiOffset            I64
	FiHdrOffset         I64
	FpInSavepoint       uintptr
	FnOrig              Pgno
	FiSubRec            Pgno
	FbTruncateOnRelease int32
	FaWalData           [4]U32
	F__ccgo_pad1        [4]byte
}

type PagerSavepoint = PagerSavepoint1

var Xsqlite3_pager_readdb_count int32 = 0
var Xsqlite3_pager_writedb_count int32 = 0
var Xsqlite3_pager_writej_count int32 = 0

var aJournalMagic = [8]uint8{
	uint8(0xd9), uint8(0xd5), uint8(0x05), uint8(0xf9), uint8(0x20), uint8(0xa1), uint8(0x63), uint8(0xd7),
}

func setGetterMethod(tls *libc.TLS, pPager uintptr) {
	if (*Pager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		(*Pager)(unsafe.Pointer(pPager)).FxGet = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, Pgno, uintptr, int32) int32
		}{getPageError}))
	} else if (*Pager)(unsafe.Pointer(pPager)).FbUseFetch != 0 {
		(*Pager)(unsafe.Pointer(pPager)).FxGet = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, Pgno, uintptr, int32) int32
		}{getPageMMap}))
	} else {
		(*Pager)(unsafe.Pointer(pPager)).FxGet = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, Pgno, uintptr, int32) int32
		}{getPageNormal}))
	}
}

func subjRequiresPage(tls *libc.TLS, pPg uintptr) int32 {
	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager
	var p uintptr
	var pgno Pgno = (*PgHdr)(unsafe.Pointer(pPg)).Fpgno
	var i int32
	for i = 0; i < (*Pager)(unsafe.Pointer(pPager)).FnSavepoint; i++ {
		p = (*Pager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(i)*56
		if (*PagerSavepoint)(unsafe.Pointer(p)).FnOrig >= pgno && 0 == Xsqlite3BitvecTestNotNull(tls, (*PagerSavepoint)(unsafe.Pointer(p)).FpInSavepoint, pgno) {
			for i = i + 1; i < (*Pager)(unsafe.Pointer(pPager)).FnSavepoint; i++ {
				(*PagerSavepoint)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(i)*56)).FbTruncateOnRelease = 0
			}
			return 1
		}
	}
	return 0
}

func read32bits(tls *libc.TLS, fd uintptr, offset I64, pRes uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32 = Xsqlite3OsRead(tls, fd, bp, int32(unsafe.Sizeof([4]uint8{})), offset)
	if rc == SQLITE_OK {
		*(*U32)(unsafe.Pointer(pRes)) = Xsqlite3Get4byte(tls, bp)
	}
	return rc
}

func write32bits(tls *libc.TLS, fd uintptr, offset I64, val U32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	Xsqlite3Put4byte(tls, bp, val)
	return Xsqlite3OsWrite(tls, fd, bp, 4, offset)
}

func pagerUnlockDb(tls *libc.TLS, pPager uintptr, eLock int32) int32 {
	var rc int32 = SQLITE_OK

	if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
		if (*Pager)(unsafe.Pointer(pPager)).FnoLock != 0 {
			rc = SQLITE_OK
		} else {
			rc = Xsqlite3OsUnlock(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, eLock)
		}
		if int32((*Pager)(unsafe.Pointer(pPager)).FeLock) != EXCLUSIVE_LOCK+1 {
			(*Pager)(unsafe.Pointer(pPager)).FeLock = U8(eLock)
		}

	}
	(*Pager)(unsafe.Pointer(pPager)).FchangeCountDone = (*Pager)(unsafe.Pointer(pPager)).FtempFile
	return rc
}

func pagerLockDb(tls *libc.TLS, pPager uintptr, eLock int32) int32 {
	var rc int32 = SQLITE_OK

	if int32((*Pager)(unsafe.Pointer(pPager)).FeLock) < eLock || int32((*Pager)(unsafe.Pointer(pPager)).FeLock) == EXCLUSIVE_LOCK+1 {
		if (*Pager)(unsafe.Pointer(pPager)).FnoLock != 0 {
			rc = SQLITE_OK
		} else {
			rc = Xsqlite3OsLock(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, eLock)
		}
		if rc == SQLITE_OK && (int32((*Pager)(unsafe.Pointer(pPager)).FeLock) != EXCLUSIVE_LOCK+1 || eLock == EXCLUSIVE_LOCK) {
			(*Pager)(unsafe.Pointer(pPager)).FeLock = U8(eLock)

		}
	}
	return rc
}

func jrnlBufferSize(tls *libc.TLS, pPager uintptr) int32 {
	_ = pPager

	return 0
}

func readSuperJournal(tls *libc.TLS, pJrnl uintptr, zSuper uintptr, nSuper U32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32

	var u U32

	*(*uint8)(unsafe.Pointer(zSuper)) = uint8(0)

	if SQLITE_OK != libc.AssignInt32(&rc, Xsqlite3OsFileSize(tls, pJrnl, bp)) ||
		*(*I64)(unsafe.Pointer(bp)) < int64(16) ||
		SQLITE_OK != libc.AssignInt32(&rc, read32bits(tls, pJrnl, *(*I64)(unsafe.Pointer(bp))-int64(16), bp+8)) ||
		*(*U32)(unsafe.Pointer(bp + 8)) >= nSuper ||
		I64(*(*U32)(unsafe.Pointer(bp + 8))) > *(*I64)(unsafe.Pointer(bp))-int64(16) ||
		*(*U32)(unsafe.Pointer(bp + 8)) == U32(0) ||
		SQLITE_OK != libc.AssignInt32(&rc, read32bits(tls, pJrnl, *(*I64)(unsafe.Pointer(bp))-int64(12), bp+12)) ||
		SQLITE_OK != libc.AssignInt32(&rc, Xsqlite3OsRead(tls, pJrnl, bp+16, 8, *(*I64)(unsafe.Pointer(bp))-int64(8))) ||
		libc.Xmemcmp(tls, bp+16, uintptr(unsafe.Pointer(&aJournalMagic)), uint64(8)) != 0 ||
		SQLITE_OK != libc.AssignInt32(&rc, Xsqlite3OsRead(tls, pJrnl, zSuper, int32(*(*U32)(unsafe.Pointer(bp + 8))), *(*I64)(unsafe.Pointer(bp))-int64(16)-I64(*(*U32)(unsafe.Pointer(bp + 8))))) {
		return rc
	}

	for u = U32(0); u < *(*U32)(unsafe.Pointer(bp + 8)); u++ {
		*(*U32)(unsafe.Pointer(bp + 12)) -= U32(*(*uint8)(unsafe.Pointer(zSuper + uintptr(u))))
	}
	if *(*U32)(unsafe.Pointer(bp + 12)) != 0 {
		*(*U32)(unsafe.Pointer(bp + 8)) = U32(0)
	}
	*(*uint8)(unsafe.Pointer(zSuper + uintptr(*(*U32)(unsafe.Pointer(bp + 8))))) = uint8(0)
	*(*uint8)(unsafe.Pointer(zSuper + uintptr(*(*U32)(unsafe.Pointer(bp + 8))+U32(1)))) = uint8(0)

	return SQLITE_OK
}

func journalHdrOffset(tls *libc.TLS, pPager uintptr) I64 {
	var offset I64 = int64(0)
	var c I64 = (*Pager)(unsafe.Pointer(pPager)).FjournalOff
	if c != 0 {
		offset = ((c-int64(1))/I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize) + int64(1)) * I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize)
	}

	return offset
}

func zeroJournalHdr(tls *libc.TLS, pPager uintptr, doTruncate int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK

	if (*Pager)(unsafe.Pointer(pPager)).FjournalOff != 0 {
		var iLimit I64 = (*Pager)(unsafe.Pointer(pPager)).FjournalSizeLimit

		if doTruncate != 0 || iLimit == int64(0) {
			rc = Xsqlite3OsTruncate(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, int64(0))
		} else {
			rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, uintptr(unsafe.Pointer(&zeroHdr)), int32(unsafe.Sizeof(zeroHdr)), int64(0))
		}
		if rc == SQLITE_OK && !(int32((*Pager)(unsafe.Pointer(pPager)).FnoSync) != 0) {
			rc = Xsqlite3OsSync(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, SQLITE_SYNC_DATAONLY|int32((*Pager)(unsafe.Pointer(pPager)).FsyncFlags))
		}

		if rc == SQLITE_OK && iLimit > int64(0) {
			rc = Xsqlite3OsFileSize(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, bp)
			if rc == SQLITE_OK && *(*I64)(unsafe.Pointer(bp)) > iLimit {
				rc = Xsqlite3OsTruncate(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iLimit)
			}
		}
	}
	return rc
}

var zeroHdr = [28]uint8{0: uint8(0)}

func writeJournalHdr(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = SQLITE_OK
	var zHeader uintptr = (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace
	var nHeader U32 = U32((*Pager)(unsafe.Pointer(pPager)).FpageSize)
	var nWrite U32
	var ii int32

	if nHeader > (*Pager)(unsafe.Pointer(pPager)).FsectorSize {
		nHeader = (*Pager)(unsafe.Pointer(pPager)).FsectorSize
	}

	for ii = 0; ii < (*Pager)(unsafe.Pointer(pPager)).FnSavepoint; ii++ {
		if (*PagerSavepoint)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).FaSavepoint+uintptr(ii)*56)).FiHdrOffset == int64(0) {
			(*PagerSavepoint)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*56)).FiHdrOffset = (*Pager)(unsafe.Pointer(pPager)).FjournalOff
		}
	}

	(*Pager)(unsafe.Pointer(pPager)).FjournalHdr = libc.AssignPtrInt64(pPager+96, journalHdrOffset(tls, pPager))

	if (*Pager)(unsafe.Pointer(pPager)).FnoSync != 0 || int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_MEMORY ||
		Xsqlite3OsDeviceCharacteristics(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd)&SQLITE_IOCAP_SAFE_APPEND != 0 {
		libc.Xmemcpy(tls, zHeader, uintptr(unsafe.Pointer(&aJournalMagic)), uint64(unsafe.Sizeof(aJournalMagic)))
		Xsqlite3Put4byte(tls, zHeader+8, 0xffffffff)
	} else {
		libc.Xmemset(tls, zHeader, 0, uint64(unsafe.Sizeof(aJournalMagic))+uint64(4))
	}

	Xsqlite3_randomness(tls, int32(unsafe.Sizeof(U32(0))), pPager+56)
	Xsqlite3Put4byte(tls, zHeader+12, (*Pager)(unsafe.Pointer(pPager)).FcksumInit)

	Xsqlite3Put4byte(tls, zHeader+16, (*Pager)(unsafe.Pointer(pPager)).FdbOrigSize)

	Xsqlite3Put4byte(tls, zHeader+20, (*Pager)(unsafe.Pointer(pPager)).FsectorSize)

	Xsqlite3Put4byte(tls, zHeader+24, uint32((*Pager)(unsafe.Pointer(pPager)).FpageSize))

	libc.Xmemset(tls, zHeader+28, 0,
		uint64(nHeader)-(uint64(unsafe.Sizeof(aJournalMagic))+uint64(20)))

	for nWrite = U32(0); rc == SQLITE_OK && nWrite < (*Pager)(unsafe.Pointer(pPager)).FsectorSize; nWrite = nWrite + nHeader {
		rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, zHeader, int32(nHeader), (*Pager)(unsafe.Pointer(pPager)).FjournalOff)

		*(*I64)(unsafe.Pointer(pPager + 96)) += I64(nHeader)
	}

	return rc
}

func readJournalHdr(tls *libc.TLS, pPager uintptr, isHot int32, journalSize I64, pNRec uintptr, pDbSize uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32

	var iHdrOff I64

	(*Pager)(unsafe.Pointer(pPager)).FjournalOff = journalHdrOffset(tls, pPager)
	if (*Pager)(unsafe.Pointer(pPager)).FjournalOff+I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize) > journalSize {
		return SQLITE_DONE
	}
	iHdrOff = (*Pager)(unsafe.Pointer(pPager)).FjournalOff

	if isHot != 0 || iHdrOff != (*Pager)(unsafe.Pointer(pPager)).FjournalHdr {
		rc = Xsqlite3OsRead(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, bp, int32(unsafe.Sizeof([8]uint8{})), iHdrOff)
		if rc != 0 {
			return rc
		}
		if libc.Xmemcmp(tls, bp, uintptr(unsafe.Pointer(&aJournalMagic)), uint64(unsafe.Sizeof([8]uint8{}))) != 0 {
			return SQLITE_DONE
		}
	}

	if SQLITE_OK != libc.AssignInt32(&rc, read32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(8), pNRec)) ||
		SQLITE_OK != libc.AssignInt32(&rc, read32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(12), pPager+56)) ||
		SQLITE_OK != libc.AssignInt32(&rc, read32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(16), pDbSize)) {
		return rc
	}

	if (*Pager)(unsafe.Pointer(pPager)).FjournalOff == int64(0) {
		if SQLITE_OK != libc.AssignInt32(&rc, read32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(20), bp+8)) ||
			SQLITE_OK != libc.AssignInt32(&rc, read32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(24), bp+12)) {
			return rc
		}

		if *(*U32)(unsafe.Pointer(bp + 12)) == U32(0) {
			*(*U32)(unsafe.Pointer(bp + 12)) = U32((*Pager)(unsafe.Pointer(pPager)).FpageSize)
		}

		if *(*U32)(unsafe.Pointer(bp + 12)) < U32(512) || *(*U32)(unsafe.Pointer(bp + 8)) < U32(32) ||
			*(*U32)(unsafe.Pointer(bp + 12)) > U32(SQLITE_MAX_PAGE_SIZE) || *(*U32)(unsafe.Pointer(bp + 8)) > U32(MAX_SECTOR_SIZE) ||
			(*(*U32)(unsafe.Pointer(bp + 12))-U32(1))&*(*U32)(unsafe.Pointer(bp + 12)) != U32(0) || (*(*U32)(unsafe.Pointer(bp + 8))-U32(1))&*(*U32)(unsafe.Pointer(bp + 8)) != U32(0) {
			return SQLITE_DONE
		}

		rc = Xsqlite3PagerSetPagesize(tls, pPager, bp+12, -1)

		(*Pager)(unsafe.Pointer(pPager)).FsectorSize = *(*U32)(unsafe.Pointer(bp + 8))
	}

	*(*I64)(unsafe.Pointer(pPager + 96)) += I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize)
	return rc
}

func writeSuperJournal(tls *libc.TLS, pPager uintptr, zSuper uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	var nSuper int32
	var iHdrOff I64

	var cksum U32 = U32(0)

	if !(zSuper != 0) ||
		int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_MEMORY ||
		!((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0)) {
		return SQLITE_OK
	}
	(*Pager)(unsafe.Pointer(pPager)).FsetSuper = U8(1)

	for nSuper = 0; *(*uint8)(unsafe.Pointer(zSuper + uintptr(nSuper))) != 0; nSuper++ {
		cksum = cksum + U32(*(*uint8)(unsafe.Pointer(zSuper + uintptr(nSuper))))
	}

	if (*Pager)(unsafe.Pointer(pPager)).FfullSync != 0 {
		(*Pager)(unsafe.Pointer(pPager)).FjournalOff = journalHdrOffset(tls, pPager)
	}
	iHdrOff = (*Pager)(unsafe.Pointer(pPager)).FjournalOff

	if 0 != libc.AssignInt32(&rc, write32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff, (*Pager)(unsafe.Pointer(pPager)).FlckPgno)) ||
		0 != libc.AssignInt32(&rc, Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, zSuper, nSuper, iHdrOff+int64(4))) ||
		0 != libc.AssignInt32(&rc, write32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(4)+I64(nSuper), uint32(nSuper))) ||
		0 != libc.AssignInt32(&rc, write32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iHdrOff+int64(4)+I64(nSuper)+int64(4), cksum)) ||
		0 != libc.AssignInt32(&rc, Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, uintptr(unsafe.Pointer(&aJournalMagic)), 8,
			iHdrOff+int64(4)+I64(nSuper)+int64(8))) {
		return rc
	}
	*(*I64)(unsafe.Pointer(pPager + 96)) += I64(nSuper + 20)

	if SQLITE_OK == libc.AssignInt32(&rc, Xsqlite3OsFileSize(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, bp)) &&
		*(*I64)(unsafe.Pointer(bp)) > (*Pager)(unsafe.Pointer(pPager)).FjournalOff {
		rc = Xsqlite3OsTruncate(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, (*Pager)(unsafe.Pointer(pPager)).FjournalOff)
	}
	return rc
}

func pager_reset(tls *libc.TLS, pPager uintptr) {
	(*Pager)(unsafe.Pointer(pPager)).FiDataVersion++
	Xsqlite3BackupRestart(tls, (*Pager)(unsafe.Pointer(pPager)).FpBackup)
	Xsqlite3PcacheClear(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
}

func Xsqlite3PagerDataVersion(tls *libc.TLS, pPager uintptr) U32 {
	return (*Pager)(unsafe.Pointer(pPager)).FiDataVersion
}

func releaseAllSavepoints(tls *libc.TLS, pPager uintptr) {
	var ii int32
	for ii = 0; ii < (*Pager)(unsafe.Pointer(pPager)).FnSavepoint; ii++ {
		Xsqlite3BitvecDestroy(tls, (*PagerSavepoint)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).FaSavepoint+uintptr(ii)*56)).FpInSavepoint)
	}
	if !(int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode) != 0) || Xsqlite3JournalIsInMemory(tls, (*Pager)(unsafe.Pointer(pPager)).Fsjfd) != 0 {
		Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fsjfd)
	}
	Xsqlite3_free(tls, (*Pager)(unsafe.Pointer(pPager)).FaSavepoint)
	(*Pager)(unsafe.Pointer(pPager)).FaSavepoint = uintptr(0)
	(*Pager)(unsafe.Pointer(pPager)).FnSavepoint = 0
	(*Pager)(unsafe.Pointer(pPager)).FnSubRec = U32(0)
}

func addToSavepointBitvecs(tls *libc.TLS, pPager uintptr, pgno Pgno) int32 {
	var ii int32
	var rc int32 = SQLITE_OK

	for ii = 0; ii < (*Pager)(unsafe.Pointer(pPager)).FnSavepoint; ii++ {
		var p uintptr = (*Pager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*56
		if pgno <= (*PagerSavepoint)(unsafe.Pointer(p)).FnOrig {
			rc = rc | Xsqlite3BitvecSet(tls, (*PagerSavepoint)(unsafe.Pointer(p)).FpInSavepoint, pgno)

		}
	}
	return rc
}

func pager_unlock(tls *libc.TLS, pPager uintptr) {
	Xsqlite3BitvecDestroy(tls, (*Pager)(unsafe.Pointer(pPager)).FpInJournal)
	(*Pager)(unsafe.Pointer(pPager)).FpInJournal = uintptr(0)
	releaseAllSavepoints(tls, pPager)

	if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		Xsqlite3WalEndReadTransaction(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal)
		(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_OPEN)
	} else if !(int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode) != 0) {
		var rc int32
		var iDc int32
		if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
			iDc = Xsqlite3OsDeviceCharacteristics(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd)
		} else {
			iDc = 0
		}

		if 0 == iDc&SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN ||
			1 != int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode)&5 {
			Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
		}

		rc = pagerUnlockDb(tls, pPager, NO_LOCK)
		if rc != SQLITE_OK && int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_ERROR {
			(*Pager)(unsafe.Pointer(pPager)).FeLock = U8(EXCLUSIVE_LOCK + 1)
		}

		(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_OPEN)
	}

	if (*Pager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		if int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) == 0 {
			pager_reset(tls, pPager)
			(*Pager)(unsafe.Pointer(pPager)).FchangeCountDone = U8(0)
			(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_OPEN)
		} else {
			(*Pager)(unsafe.Pointer(pPager)).FeState = func() uint8 {
				if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
					return uint8(PAGER_OPEN)
				}
				return uint8(PAGER_READER)
			}()
		}
		if (*Pager)(unsafe.Pointer(pPager)).FbUseFetch != 0 {
			Xsqlite3OsUnfetch(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, int64(0), uintptr(0))
		}
		(*Pager)(unsafe.Pointer(pPager)).FerrCode = SQLITE_OK
		setGetterMethod(tls, pPager)
	}

	(*Pager)(unsafe.Pointer(pPager)).FjournalOff = int64(0)
	(*Pager)(unsafe.Pointer(pPager)).FjournalHdr = int64(0)
	(*Pager)(unsafe.Pointer(pPager)).FsetSuper = U8(0)
}

func pager_error(tls *libc.TLS, pPager uintptr, rc int32) int32 {
	var rc2 int32 = rc & 0xff

	if rc2 == SQLITE_FULL || rc2 == SQLITE_IOERR {
		(*Pager)(unsafe.Pointer(pPager)).FerrCode = rc
		(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_ERROR)
		setGetterMethod(tls, pPager)
	}
	return rc
}

func pagerFlushOnCommit(tls *libc.TLS, pPager uintptr, bCommit int32) int32 {
	if int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) == 0 {
		return 1
	}
	if !(bCommit != 0) {
		return 0
	}
	if !((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0)) {
		return 0
	}
	return libc.Bool32(Xsqlite3PCachePercentDirty(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache) >= 25)
}

func pager_end_transaction(tls *libc.TLS, pPager uintptr, hasSuper int32, bCommit int32) int32 {
	var rc int32 = SQLITE_OK
	var rc2 int32 = SQLITE_OK

	if int32((*Pager)(unsafe.Pointer(pPager)).FeState) < PAGER_WRITER_LOCKED && int32((*Pager)(unsafe.Pointer(pPager)).FeLock) < RESERVED_LOCK {
		return SQLITE_OK
	}

	releaseAllSavepoints(tls, pPager)

	if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
		if Xsqlite3JournalIsInMemory(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd) != 0 {
			Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
		} else if int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_TRUNCATE {
			if (*Pager)(unsafe.Pointer(pPager)).FjournalOff == int64(0) {
				rc = SQLITE_OK
			} else {
				rc = Xsqlite3OsTruncate(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, int64(0))
				if rc == SQLITE_OK && (*Pager)(unsafe.Pointer(pPager)).FfullSync != 0 {
					rc = Xsqlite3OsSync(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, int32((*Pager)(unsafe.Pointer(pPager)).FsyncFlags))
				}
			}
			(*Pager)(unsafe.Pointer(pPager)).FjournalOff = int64(0)
		} else if int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_PERSIST ||
			(*Pager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 && int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) != PAGER_JOURNALMODE_WAL {
			rc = zeroJournalHdr(tls, pPager, libc.Bool32(hasSuper != 0 || (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0))
			(*Pager)(unsafe.Pointer(pPager)).FjournalOff = int64(0)
		} else {
			var bDelete int32 = libc.BoolInt32(!((*Pager)(unsafe.Pointer(pPager)).FtempFile != 0))

			Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
			if bDelete != 0 {
				rc = Xsqlite3OsDelete(tls, (*Pager)(unsafe.Pointer(pPager)).FpVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, int32((*Pager)(unsafe.Pointer(pPager)).FextraSync))
			}
		}
	}

	Xsqlite3BitvecDestroy(tls, (*Pager)(unsafe.Pointer(pPager)).FpInJournal)
	(*Pager)(unsafe.Pointer(pPager)).FpInJournal = uintptr(0)
	(*Pager)(unsafe.Pointer(pPager)).FnRec = 0
	if rc == SQLITE_OK {
		if (*Pager)(unsafe.Pointer(pPager)).FmemDb != 0 || pagerFlushOnCommit(tls, pPager, bCommit) != 0 {
			Xsqlite3PcacheCleanAll(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
		} else {
			Xsqlite3PcacheClearWritable(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
		}
		Xsqlite3PcacheTruncate(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, (*Pager)(unsafe.Pointer(pPager)).FdbSize)
	}

	if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		rc2 = Xsqlite3WalEndWriteTransaction(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal)

	} else if rc == SQLITE_OK && bCommit != 0 && (*Pager)(unsafe.Pointer(pPager)).FdbFileSize > (*Pager)(unsafe.Pointer(pPager)).FdbSize {
		rc = pager_truncate(tls, pPager, (*Pager)(unsafe.Pointer(pPager)).FdbSize)
	}

	if rc == SQLITE_OK && bCommit != 0 {
		rc = Xsqlite3OsFileControl(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, SQLITE_FCNTL_COMMIT_PHASETWO, uintptr(0))
		if rc == SQLITE_NOTFOUND {
			rc = SQLITE_OK
		}
	}

	if !(int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode) != 0) &&
		(!((*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0)) || Xsqlite3WalExclusiveMode(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, 0) != 0) {
		rc2 = pagerUnlockDb(tls, pPager, SHARED_LOCK)
	}
	(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_READER)
	(*Pager)(unsafe.Pointer(pPager)).FsetSuper = U8(0)

	return func() int32 {
		if rc == SQLITE_OK {
			return rc2
		}
		return rc
	}()
}

func pagerUnlockAndRollback(tls *libc.TLS, pPager uintptr) {
	if int32((*Pager)(unsafe.Pointer(pPager)).FeState) != PAGER_ERROR && int32((*Pager)(unsafe.Pointer(pPager)).FeState) != PAGER_OPEN {
		if int32((*Pager)(unsafe.Pointer(pPager)).FeState) >= PAGER_WRITER_LOCKED {
			Xsqlite3BeginBenignMalloc(tls)
			Xsqlite3PagerRollback(tls, pPager)
			Xsqlite3EndBenignMalloc(tls)
		} else if !(int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode) != 0) {
			pager_end_transaction(tls, pPager, 0, 0)
		}
	}
	pager_unlock(tls, pPager)
}

func pager_cksum(tls *libc.TLS, pPager uintptr, aData uintptr) U32 {
	var cksum U32 = (*Pager)(unsafe.Pointer(pPager)).FcksumInit
	var i int32 = int32((*Pager)(unsafe.Pointer(pPager)).FpageSize - int64(200))
	for i > 0 {
		cksum = cksum + U32(*(*U8)(unsafe.Pointer(aData + uintptr(i))))
		i = i - 200
	}
	return cksum
}

func pager_playback_one_page(tls *libc.TLS, pPager uintptr, pOffset uintptr, pDone uintptr, isMainJrnl int32, isSavepnt int32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32

	var aData uintptr
	var jfd uintptr
	var isSynced int32

	aData = (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace

	if isMainJrnl != 0 {
		jfd = (*Pager)(unsafe.Pointer(pPager)).Fjfd
	} else {
		jfd = (*Pager)(unsafe.Pointer(pPager)).Fsjfd
	}
	rc = read32bits(tls, jfd, *(*I64)(unsafe.Pointer(pOffset)), bp)
	if rc != SQLITE_OK {
		return rc
	}
	rc = Xsqlite3OsRead(tls, jfd, aData, int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), *(*I64)(unsafe.Pointer(pOffset))+int64(4))
	if rc != SQLITE_OK {
		return rc
	}
	*(*I64)(unsafe.Pointer(pOffset)) += (*Pager)(unsafe.Pointer(pPager)).FpageSize + int64(4) + I64(isMainJrnl*4)

	if *(*Pgno)(unsafe.Pointer(bp)) == Pgno(0) || *(*Pgno)(unsafe.Pointer(bp)) == (*Pager)(unsafe.Pointer(pPager)).FlckPgno {
		return SQLITE_DONE
	}
	if *(*Pgno)(unsafe.Pointer(bp)) > (*Pager)(unsafe.Pointer(pPager)).FdbSize || Xsqlite3BitvecTest(tls, pDone, *(*Pgno)(unsafe.Pointer(bp))) != 0 {
		return SQLITE_OK
	}
	if isMainJrnl != 0 {
		rc = read32bits(tls, jfd, *(*I64)(unsafe.Pointer(pOffset))-int64(4), bp+4)
		if rc != 0 {
			return rc
		}
		if !(isSavepnt != 0) && pager_cksum(tls, pPager, aData) != *(*U32)(unsafe.Pointer(bp + 4)) {
			return SQLITE_DONE
		}
	}

	if pDone != 0 && libc.AssignInt32(&rc, Xsqlite3BitvecSet(tls, pDone, *(*Pgno)(unsafe.Pointer(bp)))) != SQLITE_OK {
		return rc
	}

	if *(*Pgno)(unsafe.Pointer(bp)) == Pgno(1) && int32((*Pager)(unsafe.Pointer(pPager)).FnReserve) != int32(*(*U8)(unsafe.Pointer(aData + 20))) {
		(*Pager)(unsafe.Pointer(pPager)).FnReserve = I16(*(*U8)(unsafe.Pointer(aData + 20)))
	}

	if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	} else {
		*(*uintptr)(unsafe.Pointer(bp + 8)) = Xsqlite3PagerLookup(tls, pPager, *(*Pgno)(unsafe.Pointer(bp)))
	}

	if isMainJrnl != 0 {
		isSynced = libc.Bool32((*Pager)(unsafe.Pointer(pPager)).FnoSync != 0 || *(*I64)(unsafe.Pointer(pOffset)) <= (*Pager)(unsafe.Pointer(pPager)).FjournalHdr)
	} else {
		isSynced = libc.Bool32(*(*uintptr)(unsafe.Pointer(bp + 8)) == uintptr(0) || 0 == int32((*PgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).Fflags)&PGHDR_NEED_SYNC)
	}
	if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) &&
		(int32((*Pager)(unsafe.Pointer(pPager)).FeState) >= PAGER_WRITER_DBMOD || int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) &&
		isSynced != 0 {
		var ofst I64 = I64(*(*Pgno)(unsafe.Pointer(bp))-Pgno(1)) * (*Pager)(unsafe.Pointer(pPager)).FpageSize

		rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, aData, int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), ofst)

		if *(*Pgno)(unsafe.Pointer(bp)) > (*Pager)(unsafe.Pointer(pPager)).FdbFileSize {
			(*Pager)(unsafe.Pointer(pPager)).FdbFileSize = *(*Pgno)(unsafe.Pointer(bp))
		}
		if (*Pager)(unsafe.Pointer(pPager)).FpBackup != 0 {
			Xsqlite3BackupUpdate(tls, (*Pager)(unsafe.Pointer(pPager)).FpBackup, *(*Pgno)(unsafe.Pointer(bp)), aData)
		}
	} else if !(isMainJrnl != 0) && *(*uintptr)(unsafe.Pointer(bp + 8)) == uintptr(0) {
		*(*U8)(unsafe.Pointer(pPager + 25)) |= U8(SPILLFLAG_ROLLBACK)
		rc = Xsqlite3PagerGet(tls, pPager, *(*Pgno)(unsafe.Pointer(bp)), bp+8, 1)

		*(*U8)(unsafe.Pointer(pPager + 25)) &= libc.Uint8FromInt32(libc.CplInt32(SPILLFLAG_ROLLBACK))
		if rc != SQLITE_OK {
			return rc
		}
		Xsqlite3PcacheMakeDirty(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}
	if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
		var pData uintptr
		pData = (*PgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpData
		libc.Xmemcpy(tls, pData, aData, uint64((*Pager)(unsafe.Pointer(pPager)).FpageSize))
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Pager)(unsafe.Pointer(pPager)).FxReiniter})).f(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))

		if *(*Pgno)(unsafe.Pointer(bp)) == Pgno(1) {
			libc.Xmemcpy(tls, pPager+136, pData+24, uint64(unsafe.Sizeof([16]uint8{})))
		}
		Xsqlite3PcacheRelease(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}
	return rc
}

func pager_delsuper(tls *libc.TLS, pPager uintptr, zSuper uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var pVfs uintptr
	var rc int32
	var pSuper uintptr
	var pJournal uintptr
	var zSuperJournal uintptr

	var zJournal uintptr
	var zSuperPtr uintptr
	var zFree uintptr
	var nSuperPtr int32
	var flags int32

	var c int32
	var flags1 int32

	pVfs = (*Pager)(unsafe.Pointer(pPager)).FpVfs
	zSuperJournal = uintptr(0)
	zFree = uintptr(0)

	pSuper = Xsqlite3MallocZero(tls, uint64((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile*2))
	if !!(pSuper != 0) {
		goto __1
	}
	rc = SQLITE_NOMEM
	pJournal = uintptr(0)
	goto __2
__1:
	flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_SUPER_JOURNAL
	rc = Xsqlite3OsOpen(tls, pVfs, zSuper, pSuper, flags, uintptr(0))
	pJournal = pSuper + uintptr((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile)
__2:
	;
	if !(rc != SQLITE_OK) {
		goto __3
	}
	goto delsuper_out
__3:
	;
	rc = Xsqlite3OsFileSize(tls, pSuper, bp)
	if !(rc != SQLITE_OK) {
		goto __4
	}
	goto delsuper_out
__4:
	;
	nSuperPtr = (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname + 1
	zFree = Xsqlite3Malloc(tls, uint64(int64(4)+*(*I64)(unsafe.Pointer(bp))+I64(nSuperPtr)+int64(2)))
	if !!(zFree != 0) {
		goto __5
	}
	rc = SQLITE_NOMEM
	goto delsuper_out
__5:
	;
	*(*uint8)(unsafe.Pointer(zFree)) = libc.AssignPtrUint8(zFree+1, libc.AssignPtrUint8(zFree+2, libc.AssignPtrUint8(zFree+3, uint8(0))))
	zSuperJournal = zFree + 4
	zSuperPtr = zSuperJournal + uintptr(*(*I64)(unsafe.Pointer(bp))+int64(2))
	rc = Xsqlite3OsRead(tls, pSuper, zSuperJournal, int32(*(*I64)(unsafe.Pointer(bp))), int64(0))
	if !(rc != SQLITE_OK) {
		goto __6
	}
	goto delsuper_out
__6:
	;
	*(*uint8)(unsafe.Pointer(zSuperJournal + uintptr(*(*I64)(unsafe.Pointer(bp))))) = uint8(0)
	*(*uint8)(unsafe.Pointer(zSuperJournal + uintptr(*(*I64)(unsafe.Pointer(bp))+int64(1)))) = uint8(0)

	zJournal = zSuperJournal
__7:
	if !((int64(zJournal)-int64(zSuperJournal))/1 < *(*I64)(unsafe.Pointer(bp))) {
		goto __8
	}
	rc = Xsqlite3OsAccess(tls, pVfs, zJournal, SQLITE_ACCESS_EXISTS, bp+8)
	if !(rc != SQLITE_OK) {
		goto __9
	}
	goto delsuper_out
__9:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 8)) != 0) {
		goto __10
	}
	flags1 = SQLITE_OPEN_READONLY | SQLITE_OPEN_SUPER_JOURNAL
	rc = Xsqlite3OsOpen(tls, pVfs, zJournal, pJournal, flags1, uintptr(0))
	if !(rc != SQLITE_OK) {
		goto __11
	}
	goto delsuper_out
__11:
	;
	rc = readSuperJournal(tls, pJournal, zSuperPtr, uint32(nSuperPtr))
	Xsqlite3OsClose(tls, pJournal)
	if !(rc != SQLITE_OK) {
		goto __12
	}
	goto delsuper_out
__12:
	;
	c = libc.Bool32(int32(*(*uint8)(unsafe.Pointer(zSuperPtr))) != 0 && libc.Xstrcmp(tls, zSuperPtr, zSuper) == 0)
	if !(c != 0) {
		goto __13
	}

	goto delsuper_out
__13:
	;
__10:
	;
	zJournal += uintptr(Xsqlite3Strlen30(tls, zJournal) + 1)
	goto __7
__8:
	;
	Xsqlite3OsClose(tls, pSuper)
	rc = Xsqlite3OsDelete(tls, pVfs, zSuper, 0)

delsuper_out:
	Xsqlite3_free(tls, zFree)
	if !(pSuper != 0) {
		goto __14
	}
	Xsqlite3OsClose(tls, pSuper)

	Xsqlite3_free(tls, pSuper)
__14:
	;
	return rc
}

func pager_truncate(tls *libc.TLS, pPager uintptr, nPage Pgno) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32 = SQLITE_OK

	if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) &&
		(int32((*Pager)(unsafe.Pointer(pPager)).FeState) >= PAGER_WRITER_DBMOD || int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) {
		var szPage int32 = int32((*Pager)(unsafe.Pointer(pPager)).FpageSize)

		rc = Xsqlite3OsFileSize(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, bp)
		*(*I64)(unsafe.Pointer(bp + 8)) = I64(szPage) * I64(nPage)
		if rc == SQLITE_OK && *(*I64)(unsafe.Pointer(bp)) != *(*I64)(unsafe.Pointer(bp + 8)) {
			if *(*I64)(unsafe.Pointer(bp)) > *(*I64)(unsafe.Pointer(bp + 8)) {
				rc = Xsqlite3OsTruncate(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, *(*I64)(unsafe.Pointer(bp + 8)))
			} else if *(*I64)(unsafe.Pointer(bp))+I64(szPage) <= *(*I64)(unsafe.Pointer(bp + 8)) {
				var pTmp uintptr = (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace
				libc.Xmemset(tls, pTmp, 0, uint64(szPage))

				Xsqlite3OsFileControlHint(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, SQLITE_FCNTL_SIZE_HINT, bp+8)
				rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, pTmp, szPage, *(*I64)(unsafe.Pointer(bp + 8))-I64(szPage))
			}
			if rc == SQLITE_OK {
				(*Pager)(unsafe.Pointer(pPager)).FdbFileSize = nPage
			}
		}
	}
	return rc
}

func Xsqlite3SectorSize(tls *libc.TLS, pFile uintptr) int32 {
	var iRet int32 = Xsqlite3OsSectorSize(tls, pFile)
	if iRet < 32 {
		iRet = 512
	} else if iRet > MAX_SECTOR_SIZE {
		iRet = MAX_SECTOR_SIZE
	}
	return iRet
}

func setSectorSize(tls *libc.TLS, pPager uintptr) {
	if (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 ||
		Xsqlite3OsDeviceCharacteristics(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd)&SQLITE_IOCAP_POWERSAFE_OVERWRITE != 0 {
		(*Pager)(unsafe.Pointer(pPager)).FsectorSize = U32(512)
	} else {
		(*Pager)(unsafe.Pointer(pPager)).FsectorSize = U32(Xsqlite3SectorSize(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd))
	}
}

func pager_playback(tls *libc.TLS, pPager uintptr, isHot int32) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var pVfs uintptr

	var u U32

	var rc int32

	var zSuper uintptr
	var needPagerReset int32
	var nPlayback int32

	pVfs = (*Pager)(unsafe.Pointer(pPager)).FpVfs
	*(*Pgno)(unsafe.Pointer(bp + 32)) = Pgno(0)
	*(*int32)(unsafe.Pointer(bp + 24)) = 1
	zSuper = uintptr(0)
	nPlayback = 0
	*(*U32)(unsafe.Pointer(bp + 36)) = U32((*Pager)(unsafe.Pointer(pPager)).FpageSize)

	rc = Xsqlite3OsFileSize(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, bp+16)
	if !(rc != SQLITE_OK) {
		goto __1
	}
	goto end_playback
__1:
	;
	zSuper = (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace
	rc = readSuperJournal(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, zSuper, uint32((*Sqlite3_vfs)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).FpVfs)).FmxPathname+1))
	if !(rc == SQLITE_OK && *(*uint8)(unsafe.Pointer(zSuper)) != 0) {
		goto __2
	}
	rc = Xsqlite3OsAccess(tls, pVfs, zSuper, SQLITE_ACCESS_EXISTS, bp+24)
__2:
	;
	zSuper = uintptr(0)
	if !(rc != SQLITE_OK || !(*(*int32)(unsafe.Pointer(bp + 24)) != 0)) {
		goto __3
	}
	goto end_playback
__3:
	;
	(*Pager)(unsafe.Pointer(pPager)).FjournalOff = int64(0)
	needPagerReset = isHot

__4:
	if !(1 != 0) {
		goto __5
	}

	rc = readJournalHdr(tls, pPager, isHot, *(*I64)(unsafe.Pointer(bp + 16)), bp+28, bp+32)
	if !(rc != SQLITE_OK) {
		goto __6
	}
	if !(rc == SQLITE_DONE) {
		goto __7
	}
	rc = SQLITE_OK
__7:
	;
	goto end_playback
__6:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 28)) == 0xffffffff) {
		goto __8
	}

	*(*U32)(unsafe.Pointer(bp + 28)) = U32(int32((*(*I64)(unsafe.Pointer(bp + 16)) - I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize)) / ((*Pager)(unsafe.Pointer(pPager)).FpageSize + int64(8))))
__8:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 28)) == U32(0) && !(isHot != 0) && (*Pager)(unsafe.Pointer(pPager)).FjournalHdr+I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize) == (*Pager)(unsafe.Pointer(pPager)).FjournalOff) {
		goto __9
	}
	*(*U32)(unsafe.Pointer(bp + 28)) = U32(int32((*(*I64)(unsafe.Pointer(bp + 16)) - (*Pager)(unsafe.Pointer(pPager)).FjournalOff) / ((*Pager)(unsafe.Pointer(pPager)).FpageSize + int64(8))))
__9:
	;
	if !((*Pager)(unsafe.Pointer(pPager)).FjournalOff == I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize)) {
		goto __10
	}
	rc = pager_truncate(tls, pPager, *(*Pgno)(unsafe.Pointer(bp + 32)))
	if !(rc != SQLITE_OK) {
		goto __11
	}
	goto end_playback
__11:
	;
	(*Pager)(unsafe.Pointer(pPager)).FdbSize = *(*Pgno)(unsafe.Pointer(bp + 32))
	if !((*Pager)(unsafe.Pointer(pPager)).FmxPgno < *(*Pgno)(unsafe.Pointer(bp + 32))) {
		goto __12
	}
	(*Pager)(unsafe.Pointer(pPager)).FmxPgno = *(*Pgno)(unsafe.Pointer(bp + 32))
__12:
	;
__10:
	;
	u = U32(0)
__13:
	if !(u < *(*U32)(unsafe.Pointer(bp + 28))) {
		goto __15
	}
	if !(needPagerReset != 0) {
		goto __16
	}
	pager_reset(tls, pPager)
	needPagerReset = 0
__16:
	;
	rc = pager_playback_one_page(tls, pPager, pPager+96, uintptr(0), 1, 0)
	if !(rc == SQLITE_OK) {
		goto __17
	}
	nPlayback++
	goto __18
__17:
	if !(rc == SQLITE_DONE) {
		goto __19
	}
	(*Pager)(unsafe.Pointer(pPager)).FjournalOff = *(*I64)(unsafe.Pointer(bp + 16))
	goto __15
	goto __20
__19:
	if !(rc == SQLITE_IOERR|int32(2)<<8) {
		goto __21
	}

	rc = SQLITE_OK
	goto end_playback
	goto __22
__21:
	goto end_playback
__22:
	;
__20:
	;
__18:
	;
	goto __14
__14:
	u++
	goto __13
	goto __15
__15:
	;
	goto __4
__5:
	;
end_playback:
	if !(rc == SQLITE_OK) {
		goto __23
	}
	rc = Xsqlite3PagerSetPagesize(tls, pPager, bp+36, -1)
__23:
	;
	(*Pager)(unsafe.Pointer(pPager)).FchangeCountDone = (*Pager)(unsafe.Pointer(pPager)).FtempFile

	if !(rc == SQLITE_OK) {
		goto __24
	}

	zSuper = (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace + 4
	rc = readSuperJournal(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, zSuper, uint32((*Sqlite3_vfs)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).FpVfs)).FmxPathname+1))

__24:
	;
	if !(rc == SQLITE_OK &&
		(int32((*Pager)(unsafe.Pointer(pPager)).FeState) >= PAGER_WRITER_DBMOD || int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN)) {
		goto __25
	}
	rc = Xsqlite3PagerSync(tls, pPager, uintptr(0))
__25:
	;
	if !(rc == SQLITE_OK) {
		goto __26
	}
	rc = pager_end_transaction(tls, pPager, libc.Bool32(int32(*(*uint8)(unsafe.Pointer(zSuper))) != 0), 0)

__26:
	;
	if !(rc == SQLITE_OK && *(*uint8)(unsafe.Pointer(zSuper)) != 0 && *(*int32)(unsafe.Pointer(bp + 24)) != 0) {
		goto __27
	}

	libc.Xmemset(tls, (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace, 0, uint64(4))
	rc = pager_delsuper(tls, pPager, zSuper)

__27:
	;
	if !(isHot != 0 && nPlayback != 0) {
		goto __28
	}
	Xsqlite3_log(tls, SQLITE_NOTICE|int32(2)<<8, ts+6774,
		libc.VaList(bp, nPlayback, (*Pager)(unsafe.Pointer(pPager)).FzJournal))
__28:
	;
	setSectorSize(tls, pPager)
	return rc
}

func readDbPage(tls *libc.TLS, pPg uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager
	var rc int32 = SQLITE_OK

	*(*U32)(unsafe.Pointer(bp)) = U32(0)

	if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		rc = Xsqlite3WalFindFrame(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, (*PgHdr)(unsafe.Pointer(pPg)).Fpgno, bp)
		if rc != 0 {
			return rc
		}
	}
	if *(*U32)(unsafe.Pointer(bp)) != 0 {
		rc = Xsqlite3WalReadFrame(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, *(*U32)(unsafe.Pointer(bp)), int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), (*PgHdr)(unsafe.Pointer(pPg)).FpData)
	} else {
		var iOffset I64 = I64((*PgHdr)(unsafe.Pointer(pPg)).Fpgno-Pgno(1)) * (*Pager)(unsafe.Pointer(pPager)).FpageSize
		rc = Xsqlite3OsRead(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, (*PgHdr)(unsafe.Pointer(pPg)).FpData, int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), iOffset)
		if rc == SQLITE_IOERR|int32(2)<<8 {
			rc = SQLITE_OK
		}
	}

	if (*PgHdr)(unsafe.Pointer(pPg)).Fpgno == Pgno(1) {
		if rc != 0 {
			libc.Xmemset(tls, pPager+136, 0xff, uint64(unsafe.Sizeof([16]uint8{})))
		} else {
			var dbFileVers uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpData + 24
			libc.Xmemcpy(tls, pPager+136, dbFileVers, uint64(unsafe.Sizeof([16]uint8{})))
		}
	}
	atomic.AddInt32(&Xsqlite3_pager_readdb_count, 1)
	(*Pager)(unsafe.Pointer(pPager)).FnRead++

	return rc
}

func pager_write_changecounter(tls *libc.TLS, pPg uintptr) {
	var change_counter U32
	if pPg == uintptr(0) {
		return
	}

	change_counter = Xsqlite3Get4byte(tls, (*PgHdr)(unsafe.Pointer(pPg)).FpPager+136) + U32(1)
	Xsqlite3Put4byte(tls, (*PgHdr)(unsafe.Pointer(pPg)).FpData+uintptr(24), change_counter)

	Xsqlite3Put4byte(tls, (*PgHdr)(unsafe.Pointer(pPg)).FpData+uintptr(92), change_counter)
	Xsqlite3Put4byte(tls, (*PgHdr)(unsafe.Pointer(pPg)).FpData+uintptr(96), uint32(SQLITE_VERSION_NUMBER))
}

func pagerUndoCallback(tls *libc.TLS, pCtx uintptr, iPg Pgno) int32 {
	var rc int32 = SQLITE_OK
	var pPager uintptr = pCtx
	var pPg uintptr

	pPg = Xsqlite3PagerLookup(tls, pPager, iPg)
	if pPg != 0 {
		if Xsqlite3PcachePageRefcount(tls, pPg) == int64(1) {
			Xsqlite3PcacheDrop(tls, pPg)
		} else {
			rc = readDbPage(tls, pPg)
			if rc == SQLITE_OK {
				(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Pager)(unsafe.Pointer(pPager)).FxReiniter})).f(tls, pPg)
			}
			Xsqlite3PagerUnrefNotNull(tls, pPg)
		}
	}

	Xsqlite3BackupRestart(tls, (*Pager)(unsafe.Pointer(pPager)).FpBackup)

	return rc
}

func pagerRollbackWal(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32
	var pList uintptr

	(*Pager)(unsafe.Pointer(pPager)).FdbSize = (*Pager)(unsafe.Pointer(pPager)).FdbOrigSize
	rc = Xsqlite3WalUndo(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, Pgno) int32
	}{pagerUndoCallback})), pPager)
	pList = Xsqlite3PcacheDirtyList(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
	for pList != 0 && rc == SQLITE_OK {
		var pNext uintptr = (*PgHdr)(unsafe.Pointer(pList)).FpDirty
		rc = pagerUndoCallback(tls, pPager, (*PgHdr)(unsafe.Pointer(pList)).Fpgno)
		pList = pNext
	}

	return rc
}

func pagerWalFrames(tls *libc.TLS, pPager uintptr, pList uintptr, nTruncate Pgno, isCommit int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = pList

	var rc int32
	var nList int32
	var p uintptr

	if isCommit != 0 {
		var ppNext uintptr = bp
		nList = 0
		for p = *(*uintptr)(unsafe.Pointer(bp)); libc.AssignPtrUintptr(ppNext, p) != uintptr(0); p = (*PgHdr)(unsafe.Pointer(p)).FpDirty {
			if (*PgHdr)(unsafe.Pointer(p)).Fpgno <= nTruncate {
				ppNext = p + 32
				nList++
			}
		}

	} else {
		nList = 1
	}
	*(*int32)(unsafe.Pointer(pPager + 248 + 2*4)) += nList

	if (*PgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fpgno == Pgno(1) {
		pager_write_changecounter(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	rc = Xsqlite3WalFrames(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal,
		int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), *(*uintptr)(unsafe.Pointer(bp)), nTruncate, isCommit, int32((*Pager)(unsafe.Pointer(pPager)).FwalSyncFlags))
	if rc == SQLITE_OK && (*Pager)(unsafe.Pointer(pPager)).FpBackup != 0 {
		for p = *(*uintptr)(unsafe.Pointer(bp)); p != 0; p = (*PgHdr)(unsafe.Pointer(p)).FpDirty {
			Xsqlite3BackupUpdate(tls, (*Pager)(unsafe.Pointer(pPager)).FpBackup, (*PgHdr)(unsafe.Pointer(p)).Fpgno, (*PgHdr)(unsafe.Pointer(p)).FpData)
		}
	}

	return rc
}

func pagerBeginReadTransaction(tls *libc.TLS, pPager uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32
	*(*int32)(unsafe.Pointer(bp)) = 0

	Xsqlite3WalEndReadTransaction(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal)

	rc = Xsqlite3WalBeginReadTransaction(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, bp)
	if rc != SQLITE_OK || *(*int32)(unsafe.Pointer(bp)) != 0 {
		pager_reset(tls, pPager)
		if (*Pager)(unsafe.Pointer(pPager)).FbUseFetch != 0 {
			Xsqlite3OsUnfetch(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, int64(0), uintptr(0))
		}
	}

	return rc
}

func pagerPagecount(tls *libc.TLS, pPager uintptr, pnPage uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var nPage Pgno

	nPage = Xsqlite3WalDbsize(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal)

	if nPage == Pgno(0) && (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
		*(*I64)(unsafe.Pointer(bp)) = int64(0)
		var rc int32 = Xsqlite3OsFileSize(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, bp)
		if rc != SQLITE_OK {
			return rc
		}
		nPage = Pgno((*(*I64)(unsafe.Pointer(bp)) + (*Pager)(unsafe.Pointer(pPager)).FpageSize - int64(1)) / (*Pager)(unsafe.Pointer(pPager)).FpageSize)
	}

	if nPage > (*Pager)(unsafe.Pointer(pPager)).FmxPgno {
		(*Pager)(unsafe.Pointer(pPager)).FmxPgno = nPage
	}

	*(*Pgno)(unsafe.Pointer(pnPage)) = nPage
	return SQLITE_OK
}

func pagerOpenWalIfPresent(tls *libc.TLS, pPager uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK

	if !(int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) != 0) {
		rc = Xsqlite3OsAccess(tls,
			(*Pager)(unsafe.Pointer(pPager)).FpVfs, (*Pager)(unsafe.Pointer(pPager)).FzWal, SQLITE_ACCESS_EXISTS, bp)
		if rc == SQLITE_OK {
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				rc = pagerPagecount(tls, pPager, bp+4)
				if rc != 0 {
					return rc
				}
				if *(*Pgno)(unsafe.Pointer(bp + 4)) == Pgno(0) {
					rc = Xsqlite3OsDelete(tls, (*Pager)(unsafe.Pointer(pPager)).FpVfs, (*Pager)(unsafe.Pointer(pPager)).FzWal, 0)
				} else {
					rc = Xsqlite3PagerOpenWal(tls, pPager, uintptr(0))
				}
			} else if int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_WAL {
				(*Pager)(unsafe.Pointer(pPager)).FjournalMode = U8(PAGER_JOURNALMODE_DELETE)
			}
		}
	}
	return rc
}

func pagerPlaybackSavepoint(tls *libc.TLS, pPager uintptr, pSavepoint uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var szJ I64
	var iHdrOff I64
	var rc int32 = SQLITE_OK
	var pDone uintptr = uintptr(0)

	if pSavepoint != 0 {
		pDone = Xsqlite3BitvecCreate(tls, (*PagerSavepoint)(unsafe.Pointer(pSavepoint)).FnOrig)
		if !(pDone != 0) {
			return SQLITE_NOMEM
		}
	}

	(*Pager)(unsafe.Pointer(pPager)).FdbSize = func() uint32 {
		if pSavepoint != 0 {
			return (*PagerSavepoint)(unsafe.Pointer(pSavepoint)).FnOrig
		}
		return (*Pager)(unsafe.Pointer(pPager)).FdbOrigSize
	}()
	(*Pager)(unsafe.Pointer(pPager)).FchangeCountDone = (*Pager)(unsafe.Pointer(pPager)).FtempFile

	if !(pSavepoint != 0) && (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		return pagerRollbackWal(tls, pPager)
	}

	szJ = (*Pager)(unsafe.Pointer(pPager)).FjournalOff

	if pSavepoint != 0 && !((*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0)) {
		if (*PagerSavepoint)(unsafe.Pointer(pSavepoint)).FiHdrOffset != 0 {
			iHdrOff = (*PagerSavepoint)(unsafe.Pointer(pSavepoint)).FiHdrOffset
		} else {
			iHdrOff = szJ
		}
		(*Pager)(unsafe.Pointer(pPager)).FjournalOff = (*PagerSavepoint)(unsafe.Pointer(pSavepoint)).FiOffset
		for rc == SQLITE_OK && (*Pager)(unsafe.Pointer(pPager)).FjournalOff < iHdrOff {
			rc = pager_playback_one_page(tls, pPager, pPager+96, pDone, 1, 1)
		}

	} else {
		(*Pager)(unsafe.Pointer(pPager)).FjournalOff = int64(0)
	}

	for rc == SQLITE_OK && (*Pager)(unsafe.Pointer(pPager)).FjournalOff < szJ {
		var ii U32
		*(*U32)(unsafe.Pointer(bp)) = U32(0)

		rc = readJournalHdr(tls, pPager, 0, szJ, bp, bp+4)

		if *(*U32)(unsafe.Pointer(bp)) == U32(0) &&
			(*Pager)(unsafe.Pointer(pPager)).FjournalHdr+I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize) == (*Pager)(unsafe.Pointer(pPager)).FjournalOff {
			*(*U32)(unsafe.Pointer(bp)) = U32((szJ - (*Pager)(unsafe.Pointer(pPager)).FjournalOff) / ((*Pager)(unsafe.Pointer(pPager)).FpageSize + int64(8)))
		}
		for ii = U32(0); rc == SQLITE_OK && ii < *(*U32)(unsafe.Pointer(bp)) && (*Pager)(unsafe.Pointer(pPager)).FjournalOff < szJ; ii++ {
			rc = pager_playback_one_page(tls, pPager, pPager+96, pDone, 1, 1)
		}

	}

	if pSavepoint != 0 {
		var ii U32
		*(*I64)(unsafe.Pointer(bp + 8)) = I64((*PagerSavepoint)(unsafe.Pointer(pSavepoint)).FiSubRec) * (int64(4) + (*Pager)(unsafe.Pointer(pPager)).FpageSize)

		if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
			rc = Xsqlite3WalSavepointUndo(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, pSavepoint+36)
		}
		for ii = (*PagerSavepoint)(unsafe.Pointer(pSavepoint)).FiSubRec; rc == SQLITE_OK && ii < (*Pager)(unsafe.Pointer(pPager)).FnSubRec; ii++ {
			rc = pager_playback_one_page(tls, pPager, bp+8, pDone, 0, 1)
		}

	}

	Xsqlite3BitvecDestroy(tls, pDone)
	if rc == SQLITE_OK {
		(*Pager)(unsafe.Pointer(pPager)).FjournalOff = szJ
	}

	return rc
}

func Xsqlite3PagerSetCachesize(tls *libc.TLS, pPager uintptr, mxPage int32) {
	Xsqlite3PcacheSetCachesize(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, mxPage)
}

func Xsqlite3PagerSetSpillsize(tls *libc.TLS, pPager uintptr, mxPage int32) int32 {
	return Xsqlite3PcacheSetSpillsize(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, mxPage)
}

func pagerFixMaplimit(tls *libc.TLS, pPager uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var fd uintptr = (*Pager)(unsafe.Pointer(pPager)).Ffd
	if (*Sqlite3_file)(unsafe.Pointer(fd)).FpMethods != uintptr(0) && (*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(fd)).FpMethods)).FiVersion >= 3 {
		*(*Sqlite3_int64)(unsafe.Pointer(bp)) = (*Pager)(unsafe.Pointer(pPager)).FszMmap
		(*Pager)(unsafe.Pointer(pPager)).FbUseFetch = U8(libc.Bool32(*(*Sqlite3_int64)(unsafe.Pointer(bp)) > int64(0)))
		setGetterMethod(tls, pPager)
		Xsqlite3OsFileControlHint(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, SQLITE_FCNTL_MMAP_SIZE, bp)
	}
}

func Xsqlite3PagerSetMmapLimit(tls *libc.TLS, pPager uintptr, szMmap Sqlite3_int64) {
	(*Pager)(unsafe.Pointer(pPager)).FszMmap = szMmap
	pagerFixMaplimit(tls, pPager)
}

func Xsqlite3PagerShrink(tls *libc.TLS, pPager uintptr) {
	Xsqlite3PcacheShrink(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
}

func Xsqlite3PagerSetFlags(tls *libc.TLS, pPager uintptr, pgFlags uint32) {
	var level uint32 = pgFlags & uint32(PAGER_SYNCHRONOUS_MASK)
	if (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 {
		(*Pager)(unsafe.Pointer(pPager)).FnoSync = U8(1)
		(*Pager)(unsafe.Pointer(pPager)).FfullSync = U8(0)
		(*Pager)(unsafe.Pointer(pPager)).FextraSync = U8(0)
	} else {
		(*Pager)(unsafe.Pointer(pPager)).FnoSync = func() uint8 {
			if level == uint32(PAGER_SYNCHRONOUS_OFF) {
				return uint8(1)
			}
			return uint8(0)
		}()
		(*Pager)(unsafe.Pointer(pPager)).FfullSync = func() uint8 {
			if level >= uint32(PAGER_SYNCHRONOUS_FULL) {
				return uint8(1)
			}
			return uint8(0)
		}()
		(*Pager)(unsafe.Pointer(pPager)).FextraSync = func() uint8 {
			if level == uint32(PAGER_SYNCHRONOUS_EXTRA) {
				return uint8(1)
			}
			return uint8(0)
		}()
	}
	if (*Pager)(unsafe.Pointer(pPager)).FnoSync != 0 {
		(*Pager)(unsafe.Pointer(pPager)).FsyncFlags = U8(0)
	} else if pgFlags&uint32(PAGER_FULLFSYNC) != 0 {
		(*Pager)(unsafe.Pointer(pPager)).FsyncFlags = U8(SQLITE_SYNC_FULL)
	} else {
		(*Pager)(unsafe.Pointer(pPager)).FsyncFlags = U8(SQLITE_SYNC_NORMAL)
	}
	(*Pager)(unsafe.Pointer(pPager)).FwalSyncFlags = U8(int32((*Pager)(unsafe.Pointer(pPager)).FsyncFlags) << 2)
	if (*Pager)(unsafe.Pointer(pPager)).FfullSync != 0 {
		*(*U8)(unsafe.Pointer(pPager + 15)) |= U8(int32((*Pager)(unsafe.Pointer(pPager)).FsyncFlags))
	}
	if pgFlags&uint32(PAGER_CKPT_FULLFSYNC) != 0 && !(int32((*Pager)(unsafe.Pointer(pPager)).FnoSync) != 0) {
		*(*U8)(unsafe.Pointer(pPager + 15)) |= U8(int32(SQLITE_SYNC_FULL) << 2)
	}
	if pgFlags&uint32(PAGER_CACHESPILL) != 0 {
		*(*U8)(unsafe.Pointer(pPager + 25)) &= libc.Uint8FromInt32(libc.CplInt32(SPILLFLAG_OFF))
	} else {
		*(*U8)(unsafe.Pointer(pPager + 25)) |= U8(SPILLFLAG_OFF)
	}
}

var Xsqlite3_opentemp_count int32 = 0

func pagerOpentemp(tls *libc.TLS, pPager uintptr, pFile uintptr, vfsFlags int32) int32 {
	var rc int32

	Xsqlite3_opentemp_count++

	vfsFlags = vfsFlags | (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE)
	rc = Xsqlite3OsOpen(tls, (*Pager)(unsafe.Pointer(pPager)).FpVfs, uintptr(0), pFile, vfsFlags, uintptr(0))

	return rc
}

func Xsqlite3PagerSetBusyHandler(tls *libc.TLS, pPager uintptr, xBusyHandler uintptr, pBusyHandlerArg uintptr) {
	var ap uintptr
	(*Pager)(unsafe.Pointer(pPager)).FxBusyHandler = xBusyHandler
	(*Pager)(unsafe.Pointer(pPager)).FpBusyHandlerArg = pBusyHandlerArg
	ap = pPager + 232

	Xsqlite3OsFileControlHint(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, SQLITE_FCNTL_BUSYHANDLER, ap)
}

func Xsqlite3PagerSetPagesize(tls *libc.TLS, pPager uintptr, pPageSize uintptr, nReserve int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK

	var pageSize U32 = *(*U32)(unsafe.Pointer(pPageSize))

	if (int32((*Pager)(unsafe.Pointer(pPager)).FmemDb) == 0 || (*Pager)(unsafe.Pointer(pPager)).FdbSize == Pgno(0)) &&
		Xsqlite3PcacheRefCount(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache) == int64(0) &&
		pageSize != 0 && pageSize != U32((*Pager)(unsafe.Pointer(pPager)).FpageSize) {
		var pNew uintptr = uintptr(0)
		*(*I64)(unsafe.Pointer(bp)) = int64(0)

		if int32((*Pager)(unsafe.Pointer(pPager)).FeState) > PAGER_OPEN && (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
			rc = Xsqlite3OsFileSize(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, bp)
		}
		if rc == SQLITE_OK {
			pNew = Xsqlite3PageMalloc(tls, int32(pageSize+U32(8)))
			if !(pNew != 0) {
				rc = SQLITE_NOMEM
			} else {
				libc.Xmemset(tls, pNew+uintptr(pageSize), 0, uint64(8))
			}
		}

		if rc == SQLITE_OK {
			pager_reset(tls, pPager)
			rc = Xsqlite3PcacheSetPageSize(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, int32(pageSize))
		}
		if rc == SQLITE_OK {
			Xsqlite3PageFree(tls, (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace)
			(*Pager)(unsafe.Pointer(pPager)).FpTmpSpace = pNew
			(*Pager)(unsafe.Pointer(pPager)).FdbSize = Pgno((*(*I64)(unsafe.Pointer(bp)) + I64(pageSize) - int64(1)) / I64(pageSize))
			(*Pager)(unsafe.Pointer(pPager)).FpageSize = I64(pageSize)
			(*Pager)(unsafe.Pointer(pPager)).FlckPgno = U32(Xsqlite3PendingByte)/pageSize + Pgno(1)
		} else {
			Xsqlite3PageFree(tls, pNew)
		}
	}

	*(*U32)(unsafe.Pointer(pPageSize)) = U32((*Pager)(unsafe.Pointer(pPager)).FpageSize)
	if rc == SQLITE_OK {
		if nReserve < 0 {
			nReserve = int32((*Pager)(unsafe.Pointer(pPager)).FnReserve)
		}

		(*Pager)(unsafe.Pointer(pPager)).FnReserve = I16(nReserve)
		pagerFixMaplimit(tls, pPager)
	}
	return rc
}

func Xsqlite3PagerTempSpace(tls *libc.TLS, pPager uintptr) uintptr {
	return (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace
}

func Xsqlite3PagerMaxPageCount(tls *libc.TLS, pPager uintptr, mxPage Pgno) Pgno {
	if mxPage > Pgno(0) {
		(*Pager)(unsafe.Pointer(pPager)).FmxPgno = mxPage
	}

	return (*Pager)(unsafe.Pointer(pPager)).FmxPgno
}

var saved_cnt int32

func Xdisable_simulated_io_errors(tls *libc.TLS) {
	libc.AtomicStoreInt32(&saved_cnt, libc.AtomicLoadInt32(&Xsqlite3_io_error_pending))
	libc.AtomicStoreInt32(&Xsqlite3_io_error_pending, int32(-1))
}

func Xenable_simulated_io_errors(tls *libc.TLS) {
	libc.AtomicStoreInt32(&Xsqlite3_io_error_pending, libc.AtomicLoadInt32(&saved_cnt))
}

func Xsqlite3PagerReadFileheader(tls *libc.TLS, pPager uintptr, N int32, pDest uintptr) int32 {
	var rc int32 = SQLITE_OK
	libc.Xmemset(tls, pDest, 0, uint64(N))

	if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0) {
		rc = Xsqlite3OsRead(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, pDest, N, int64(0))
		if rc == SQLITE_IOERR|int32(2)<<8 {
			rc = SQLITE_OK
		}
	}
	return rc
}

func Xsqlite3PagerPagecount(tls *libc.TLS, pPager uintptr, pnPage uintptr) {
	*(*int32)(unsafe.Pointer(pnPage)) = int32((*Pager)(unsafe.Pointer(pPager)).FdbSize)
}

func pager_wait_on_lock(tls *libc.TLS, pPager uintptr, locktype int32) int32 {
	var rc int32

	for __ccgo := true; __ccgo; __ccgo = rc == SQLITE_BUSY && (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Pager)(unsafe.Pointer(pPager)).FxBusyHandler})).f(tls, (*Pager)(unsafe.Pointer(pPager)).FpBusyHandlerArg) != 0 {
		rc = pagerLockDb(tls, pPager, locktype)
	}
	return rc
}

func Xsqlite3PagerTruncateImage(tls *libc.TLS, pPager uintptr, nPage Pgno) {
	(*Pager)(unsafe.Pointer(pPager)).FdbSize = nPage

}

func pagerSyncHotJournal(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = SQLITE_OK
	if !(int32((*Pager)(unsafe.Pointer(pPager)).FnoSync) != 0) {
		rc = Xsqlite3OsSync(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, SQLITE_SYNC_NORMAL)
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3OsFileSize(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, pPager+104)
	}
	return rc
}

func pagerAcquireMapPage(tls *libc.TLS, pPager uintptr, pgno Pgno, pData uintptr, ppPage uintptr) int32 {
	var p uintptr

	if (*Pager)(unsafe.Pointer(pPager)).FpMmapFreelist != 0 {
		*(*uintptr)(unsafe.Pointer(ppPage)) = libc.AssignUintptr(&p, (*Pager)(unsafe.Pointer(pPager)).FpMmapFreelist)
		(*Pager)(unsafe.Pointer(pPager)).FpMmapFreelist = (*PgHdr)(unsafe.Pointer(p)).FpDirty
		(*PgHdr)(unsafe.Pointer(p)).FpDirty = uintptr(0)

		libc.Xmemset(tls, (*PgHdr)(unsafe.Pointer(p)).FpExtra, 0, uint64(8))
	} else {
		*(*uintptr)(unsafe.Pointer(ppPage)) = libc.AssignUintptr(&p, Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(PgHdr{}))+uint64((*Pager)(unsafe.Pointer(pPager)).FnExtra)))
		if p == uintptr(0) {
			Xsqlite3OsUnfetch(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, I64(pgno-Pgno(1))*(*Pager)(unsafe.Pointer(pPager)).FpageSize, pData)
			return SQLITE_NOMEM
		}
		(*PgHdr)(unsafe.Pointer(p)).FpExtra = p + 1*80
		(*PgHdr)(unsafe.Pointer(p)).Fflags = U16(PGHDR_MMAP)
		(*PgHdr)(unsafe.Pointer(p)).FnRef = int64(1)
		(*PgHdr)(unsafe.Pointer(p)).FpPager = pPager
	}

	(*PgHdr)(unsafe.Pointer(p)).Fpgno = pgno
	(*PgHdr)(unsafe.Pointer(p)).FpData = pData
	(*Pager)(unsafe.Pointer(pPager)).FnMmapOut++

	return SQLITE_OK
}

func pagerReleaseMapPage(tls *libc.TLS, pPg uintptr) {
	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager
	(*Pager)(unsafe.Pointer(pPager)).FnMmapOut--
	(*PgHdr)(unsafe.Pointer(pPg)).FpDirty = (*Pager)(unsafe.Pointer(pPager)).FpMmapFreelist
	(*Pager)(unsafe.Pointer(pPager)).FpMmapFreelist = pPg

	Xsqlite3OsUnfetch(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, I64((*PgHdr)(unsafe.Pointer(pPg)).Fpgno-Pgno(1))*(*Pager)(unsafe.Pointer(pPager)).FpageSize, (*PgHdr)(unsafe.Pointer(pPg)).FpData)
}

func pagerFreeMapHdrs(tls *libc.TLS, pPager uintptr) {
	var p uintptr
	var pNext uintptr
	for p = (*Pager)(unsafe.Pointer(pPager)).FpMmapFreelist; p != 0; p = pNext {
		pNext = (*PgHdr)(unsafe.Pointer(p)).FpDirty
		Xsqlite3_free(tls, p)
	}
}

func databaseIsUnmoved(tls *libc.TLS, pPager uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = 0
	var rc int32

	if (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 {
		return SQLITE_OK
	}
	if (*Pager)(unsafe.Pointer(pPager)).FdbSize == Pgno(0) {
		return SQLITE_OK
	}

	rc = Xsqlite3OsFileControl(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, SQLITE_FCNTL_HAS_MOVED, bp)
	if rc == SQLITE_NOTFOUND {
		rc = SQLITE_OK
	} else if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) != 0 {
		rc = SQLITE_READONLY | int32(4)<<8
	}
	return rc
}

func Xsqlite3PagerClose(tls *libc.TLS, pPager uintptr, db uintptr) int32 {
	var pTmp uintptr = (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace

	Xdisable_simulated_io_errors(tls)
	Xsqlite3BeginBenignMalloc(tls)
	pagerFreeMapHdrs(tls, pPager)

	(*Pager)(unsafe.Pointer(pPager)).FexclusiveMode = U8(0)
	{
		var a uintptr = uintptr(0)

		if db != 0 && uint64(0) == (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NoCkptOnClose) &&
			SQLITE_OK == databaseIsUnmoved(tls, pPager) {
			a = pTmp
		}
		Xsqlite3WalClose(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, db, int32((*Pager)(unsafe.Pointer(pPager)).FwalSyncFlags), int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), a)
		(*Pager)(unsafe.Pointer(pPager)).FpWal = uintptr(0)

	}
	pager_reset(tls, pPager)
	if (*Pager)(unsafe.Pointer(pPager)).FmemDb != 0 {
		pager_unlock(tls, pPager)
	} else {
		if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
			pager_error(tls, pPager, pagerSyncHotJournal(tls, pPager))
		}
		pagerUnlockAndRollback(tls, pPager)
	}
	Xsqlite3EndBenignMalloc(tls)
	Xenable_simulated_io_errors(tls)

	Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
	Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd)
	Xsqlite3PageFree(tls, pTmp)
	Xsqlite3PcacheClose(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)

	Xsqlite3_free(tls, pPager)
	return SQLITE_OK
}

func Xsqlite3PagerPagenumber(tls *libc.TLS, pPg uintptr) Pgno {
	return (*DbPage)(unsafe.Pointer(pPg)).Fpgno
}

func Xsqlite3PagerRef(tls *libc.TLS, pPg uintptr) {
	Xsqlite3PcacheRef(tls, pPg)
}

func syncJournal(tls *libc.TLS, pPager uintptr, newHdr int32) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var rc int32

	rc = Xsqlite3PagerExclusiveLock(tls, pPager)
	if rc != SQLITE_OK {
		return rc
	}

	if !(int32((*Pager)(unsafe.Pointer(pPager)).FnoSync) != 0) {
		if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) && int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) != PAGER_JOURNALMODE_MEMORY {
			var iDc int32 = Xsqlite3OsDeviceCharacteristics(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd)

			if 0 == iDc&SQLITE_IOCAP_SAFE_APPEND {
				var iNextHdrOffset I64

				libc.Xmemcpy(tls, bp, uintptr(unsafe.Pointer(&aJournalMagic)), uint64(unsafe.Sizeof(aJournalMagic)))
				Xsqlite3Put4byte(tls, bp+8, uint32((*Pager)(unsafe.Pointer(pPager)).FnRec))

				iNextHdrOffset = journalHdrOffset(tls, pPager)
				rc = Xsqlite3OsRead(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, bp+12, 8, iNextHdrOffset)
				if rc == SQLITE_OK && 0 == libc.Xmemcmp(tls, bp+12, uintptr(unsafe.Pointer(&aJournalMagic)), uint64(8)) {
					rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, uintptr(unsafe.Pointer(&zerobyte)), 1, iNextHdrOffset)
				}
				if rc != SQLITE_OK && rc != SQLITE_IOERR|int32(2)<<8 {
					return rc
				}

				if (*Pager)(unsafe.Pointer(pPager)).FfullSync != 0 && 0 == iDc&SQLITE_IOCAP_SEQUENTIAL {
					rc = Xsqlite3OsSync(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, int32((*Pager)(unsafe.Pointer(pPager)).FsyncFlags))
					if rc != SQLITE_OK {
						return rc
					}
				}

				rc = Xsqlite3OsWrite(tls,
					(*Pager)(unsafe.Pointer(pPager)).Fjfd, bp, int32(unsafe.Sizeof([12]U8{})), (*Pager)(unsafe.Pointer(pPager)).FjournalHdr)
				if rc != SQLITE_OK {
					return rc
				}
			}
			if 0 == iDc&SQLITE_IOCAP_SEQUENTIAL {
				rc = Xsqlite3OsSync(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, int32((*Pager)(unsafe.Pointer(pPager)).FsyncFlags)|func() int32 {
					if int32((*Pager)(unsafe.Pointer(pPager)).FsyncFlags) == SQLITE_SYNC_FULL {
						return SQLITE_SYNC_DATAONLY
					}
					return 0
				}())
				if rc != SQLITE_OK {
					return rc
				}
			}

			(*Pager)(unsafe.Pointer(pPager)).FjournalHdr = (*Pager)(unsafe.Pointer(pPager)).FjournalOff
			if newHdr != 0 && 0 == iDc&SQLITE_IOCAP_SAFE_APPEND {
				(*Pager)(unsafe.Pointer(pPager)).FnRec = 0
				rc = writeJournalHdr(tls, pPager)
				if rc != SQLITE_OK {
					return rc
				}
			}
		} else {
			(*Pager)(unsafe.Pointer(pPager)).FjournalHdr = (*Pager)(unsafe.Pointer(pPager)).FjournalOff
		}
	}

	Xsqlite3PcacheClearSyncFlags(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
	(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_WRITER_DBMOD)

	return SQLITE_OK
}

var zerobyte U8 = U8(0)

func pager_write_pagelist(tls *libc.TLS, pPager uintptr, pList uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK

	if !((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0)) {
		rc = pagerOpentemp(tls, pPager, (*Pager)(unsafe.Pointer(pPager)).Ffd, int32((*Pager)(unsafe.Pointer(pPager)).FvfsFlags))
	}

	if rc == SQLITE_OK &&
		(*Pager)(unsafe.Pointer(pPager)).FdbHintSize < (*Pager)(unsafe.Pointer(pPager)).FdbSize &&
		((*PgHdr)(unsafe.Pointer(pList)).FpDirty != 0 || (*PgHdr)(unsafe.Pointer(pList)).Fpgno > (*Pager)(unsafe.Pointer(pPager)).FdbHintSize) {
		*(*Sqlite3_int64)(unsafe.Pointer(bp)) = (*Pager)(unsafe.Pointer(pPager)).FpageSize * Sqlite3_int64((*Pager)(unsafe.Pointer(pPager)).FdbSize)
		Xsqlite3OsFileControlHint(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, SQLITE_FCNTL_SIZE_HINT, bp)
		(*Pager)(unsafe.Pointer(pPager)).FdbHintSize = (*Pager)(unsafe.Pointer(pPager)).FdbSize
	}

	for rc == SQLITE_OK && pList != 0 {
		var pgno Pgno = (*PgHdr)(unsafe.Pointer(pList)).Fpgno

		if pgno <= (*Pager)(unsafe.Pointer(pPager)).FdbSize && 0 == int32((*PgHdr)(unsafe.Pointer(pList)).Fflags)&PGHDR_DONT_WRITE {
			var offset I64 = I64(pgno-Pgno(1)) * (*Pager)(unsafe.Pointer(pPager)).FpageSize
			var pData uintptr

			if (*PgHdr)(unsafe.Pointer(pList)).Fpgno == Pgno(1) {
				pager_write_changecounter(tls, pList)
			}

			pData = (*PgHdr)(unsafe.Pointer(pList)).FpData

			rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, pData, int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), offset)

			if pgno == Pgno(1) {
				libc.Xmemcpy(tls, pPager+136, pData+24, uint64(unsafe.Sizeof([16]uint8{})))
			}
			if pgno > (*Pager)(unsafe.Pointer(pPager)).FdbFileSize {
				(*Pager)(unsafe.Pointer(pPager)).FdbFileSize = pgno
			}
			*(*int32)(unsafe.Pointer(pPager + 248 + 2*4))++

			Xsqlite3BackupUpdate(tls, (*Pager)(unsafe.Pointer(pPager)).FpBackup, pgno, (*PgHdr)(unsafe.Pointer(pList)).FpData)

			atomic.AddInt32(&Xsqlite3_pager_writedb_count, 1)
		} else {
		}

		pList = (*PgHdr)(unsafe.Pointer(pList)).FpDirty
	}

	return rc
}

func openSubJournal(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = SQLITE_OK
	if !((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fsjfd)).FpMethods != uintptr(0)) {
		var flags int32 = SQLITE_OPEN_SUBJOURNAL | SQLITE_OPEN_READWRITE |
			SQLITE_OPEN_CREATE | SQLITE_OPEN_EXCLUSIVE |
			SQLITE_OPEN_DELETEONCLOSE
		var nStmtSpill int32 = Xsqlite3Config.FnStmtSpill
		if int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_MEMORY || (*Pager)(unsafe.Pointer(pPager)).FsubjInMemory != 0 {
			nStmtSpill = -1
		}
		rc = Xsqlite3JournalOpen(tls, (*Pager)(unsafe.Pointer(pPager)).FpVfs, uintptr(0), (*Pager)(unsafe.Pointer(pPager)).Fsjfd, flags, nStmtSpill)
	}
	return rc
}

func subjournalPage(tls *libc.TLS, pPg uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager
	if int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) != PAGER_JOURNALMODE_OFF {
		rc = openSubJournal(tls, pPager)

		if rc == SQLITE_OK {
			var pData uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpData
			var offset I64 = I64((*Pager)(unsafe.Pointer(pPager)).FnSubRec) * (int64(4) + (*Pager)(unsafe.Pointer(pPager)).FpageSize)
			var pData2 uintptr
			pData2 = pData

			rc = write32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fsjfd, offset, (*PgHdr)(unsafe.Pointer(pPg)).Fpgno)
			if rc == SQLITE_OK {
				rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Fsjfd, pData2, int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), offset+int64(4))
			}
		}
	}
	if rc == SQLITE_OK {
		(*Pager)(unsafe.Pointer(pPager)).FnSubRec++

		rc = addToSavepointBitvecs(tls, pPager, (*PgHdr)(unsafe.Pointer(pPg)).Fpgno)
	}
	return rc
}

func subjournalPageIfRequired(tls *libc.TLS, pPg uintptr) int32 {
	if subjRequiresPage(tls, pPg) != 0 {
		return subjournalPage(tls, pPg)
	} else {
		return SQLITE_OK
	}
	return int32(0)
}

func pagerStress(tls *libc.TLS, p uintptr, pPg uintptr) int32 {
	var pPager uintptr = p
	var rc int32 = SQLITE_OK

	if (*Pager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return SQLITE_OK
	}

	if (*Pager)(unsafe.Pointer(pPager)).FdoNotSpill != 0 &&
		(int32((*Pager)(unsafe.Pointer(pPager)).FdoNotSpill)&(SPILLFLAG_ROLLBACK|SPILLFLAG_OFF) != 0 ||
			int32((*PgHdr)(unsafe.Pointer(pPg)).Fflags)&PGHDR_NEED_SYNC != 0) {
		return SQLITE_OK
	}

	*(*int32)(unsafe.Pointer(pPager + 248 + 3*4))++
	(*PgHdr)(unsafe.Pointer(pPg)).FpDirty = uintptr(0)
	if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		rc = subjournalPageIfRequired(tls, pPg)
		if rc == SQLITE_OK {
			rc = pagerWalFrames(tls, pPager, pPg, uint32(0), 0)
		}
	} else {
		if int32((*PgHdr)(unsafe.Pointer(pPg)).Fflags)&PGHDR_NEED_SYNC != 0 ||
			int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_WRITER_CACHEMOD {
			rc = syncJournal(tls, pPager, 1)
		}

		if rc == SQLITE_OK {
			rc = pager_write_pagelist(tls, pPager, pPg)
		}
	}

	if rc == SQLITE_OK {
		Xsqlite3PcacheMakeClean(tls, pPg)
	}

	return pager_error(tls, pPager, rc)
}

func Xsqlite3PagerFlush(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = (*Pager)(unsafe.Pointer(pPager)).FerrCode
	if !(int32((*Pager)(unsafe.Pointer(pPager)).FmemDb) != 0) {
		var pList uintptr = Xsqlite3PcacheDirtyList(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)

		for rc == SQLITE_OK && pList != 0 {
			var pNext uintptr = (*PgHdr)(unsafe.Pointer(pList)).FpDirty
			if (*PgHdr)(unsafe.Pointer(pList)).FnRef == int64(0) {
				rc = pagerStress(tls, pPager, pList)
			}
			pList = pNext
		}
	}

	return rc
}

func Xsqlite3PagerOpen(tls *libc.TLS, pVfs uintptr, ppPager uintptr, zFilename uintptr, nExtra int32, flags int32, vfsFlags int32, xReinit uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pPtr uintptr
	_ = pPtr

	var rc int32
	var tempFile int32
	var memDb int32
	var memJM int32
	var readOnly int32
	var journalFileSize int32
	var zPathname uintptr
	var nPathname int32
	var useJournal int32
	var pcacheSize int32

	var zUri uintptr
	var nUriByte int32
	var z uintptr
	var iDc int32

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = SQLITE_OK
	tempFile = 0
	memDb = 0
	memJM = 0
	readOnly = 0
	zPathname = uintptr(0)
	nPathname = 0
	useJournal = libc.Bool32(flags&PAGER_OMIT_JOURNAL == 0)
	pcacheSize = Xsqlite3PcacheSize(tls)
	*(*U32)(unsafe.Pointer(bp + 12)) = U32(SQLITE_DEFAULT_PAGE_SIZE)
	zUri = uintptr(0)
	nUriByte = 1

	journalFileSize = (Xsqlite3JournalSize(tls, pVfs) + 7) & libc.CplInt32(7)

	*(*uintptr)(unsafe.Pointer(ppPager)) = uintptr(0)

	if !(flags&PAGER_MEMORY != 0) {
		goto __1
	}
	memDb = 1
	if !(zFilename != 0 && *(*uint8)(unsafe.Pointer(zFilename)) != 0) {
		goto __2
	}
	zPathname = Xsqlite3DbStrDup(tls, uintptr(0), zFilename)
	if !(zPathname == uintptr(0)) {
		goto __3
	}
	return SQLITE_NOMEM
__3:
	;
	nPathname = Xsqlite3Strlen30(tls, zPathname)
	zFilename = uintptr(0)
__2:
	;
__1:
	;
	if !(zFilename != 0 && *(*uint8)(unsafe.Pointer(zFilename)) != 0) {
		goto __4
	}
	nPathname = (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname + 1
	zPathname = Xsqlite3DbMallocRaw(tls, uintptr(0), uint64(nPathname*2))
	if !(zPathname == uintptr(0)) {
		goto __5
	}
	return SQLITE_NOMEM
__5:
	;
	*(*uint8)(unsafe.Pointer(zPathname)) = uint8(0)
	rc = Xsqlite3OsFullPathname(tls, pVfs, zFilename, nPathname, zPathname)
	if !(rc != SQLITE_OK) {
		goto __6
	}
	if !(rc == SQLITE_OK|int32(2)<<8) {
		goto __7
	}
	if !(vfsFlags&SQLITE_OPEN_NOFOLLOW != 0) {
		goto __8
	}
	rc = SQLITE_CANTOPEN | int32(6)<<8
	goto __9
__8:
	rc = SQLITE_OK
__9:
	;
__7:
	;
__6:
	;
	nPathname = Xsqlite3Strlen30(tls, zPathname)
	z = libc.AssignUintptr(&zUri, zFilename+uintptr(Xsqlite3Strlen30(tls, zFilename)+1))
__10:
	if !(*(*uint8)(unsafe.Pointer(z)) != 0) {
		goto __11
	}
	z += uintptr(libc.Xstrlen(tls, z) + uint64(1))
	z += uintptr(libc.Xstrlen(tls, z) + uint64(1))
	goto __10
__11:
	;
	nUriByte = int32((int64(z+1) - int64(zUri)) / 1)

	if !(rc == SQLITE_OK && nPathname+8 > (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname) {
		goto __12
	}

	rc = Xsqlite3CantopenError(tls, 60239)
__12:
	;
	if !(rc != SQLITE_OK) {
		goto __13
	}
	Xsqlite3DbFree(tls, uintptr(0), zPathname)
	return rc
__13:
	;
__4:
	;
	pPtr = Xsqlite3MallocZero(tls,
		(uint64(unsafe.Sizeof(Pager{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7))+uint64((pcacheSize+7)&libc.CplInt32(7))+uint64(((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile+7)&libc.CplInt32(7))+uint64(journalFileSize*2)+uint64(unsafe.Sizeof(uintptr(0)))+uint64(4)+uint64(nPathname)+uint64(1)+uint64(nUriByte)+uint64(nPathname)+uint64(8)+uint64(1)+uint64(nPathname)+uint64(4)+uint64(1)+uint64(3))

	if !!(pPtr != 0) {
		goto __14
	}
	Xsqlite3DbFree(tls, uintptr(0), zPathname)
	return SQLITE_NOMEM
__14:
	;
	*(*uintptr)(unsafe.Pointer(bp)) = pPtr
	pPtr += uintptr((uint64(unsafe.Sizeof(Pager{})) + uint64(7)) & libc.Uint64FromInt32(libc.CplInt32(7)))
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpPCache = pPtr
	pPtr += uintptr((pcacheSize + 7) & libc.CplInt32(7))
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ffd = pPtr
	pPtr += uintptr(((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile + 7) & libc.CplInt32(7))
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fsjfd = pPtr
	pPtr += uintptr(journalFileSize)
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fjfd = pPtr
	pPtr += uintptr(journalFileSize)

	libc.Xmemcpy(tls, pPtr, bp, uint64(unsafe.Sizeof(uintptr(0))))
	pPtr += unsafe.Sizeof(uintptr(0))

	pPtr += uintptr(4)
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzFilename = pPtr
	if !(nPathname > 0) {
		goto __15
	}
	libc.Xmemcpy(tls, pPtr, zPathname, uint64(nPathname))
	pPtr += uintptr(nPathname + 1)
	if !(zUri != 0) {
		goto __16
	}
	libc.Xmemcpy(tls, pPtr, zUri, uint64(nUriByte))
	pPtr += uintptr(nUriByte)
	goto __17
__16:
	pPtr++
__17:
	;
__15:
	;
	if !(nPathname > 0) {
		goto __18
	}
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzJournal = pPtr
	libc.Xmemcpy(tls, pPtr, zPathname, uint64(nPathname))
	pPtr += uintptr(nPathname)
	libc.Xmemcpy(tls, pPtr, ts+6801, uint64(8))
	pPtr += uintptr(8 + 1)
	goto __19
__18:
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzJournal = uintptr(0)
__19:
	;
	if !(nPathname > 0) {
		goto __20
	}
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzWal = pPtr
	libc.Xmemcpy(tls, pPtr, zPathname, uint64(nPathname))
	pPtr += uintptr(nPathname)
	libc.Xmemcpy(tls, pPtr, ts+6810, uint64(4))
	pPtr += uintptr(4 + 1)
	goto __21
__20:
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzWal = uintptr(0)
__21:
	;
	_ = pPtr

	if !(nPathname != 0) {
		goto __22
	}
	Xsqlite3DbFree(tls, uintptr(0), zPathname)
__22:
	;
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpVfs = pVfs
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FvfsFlags = U32(vfsFlags)

	if !(zFilename != 0 && *(*uint8)(unsafe.Pointer(zFilename)) != 0) {
		goto __23
	}
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	rc = Xsqlite3OsOpen(tls, pVfs, (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzFilename, (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ffd, vfsFlags, bp+8)

	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FmemVfs = U8(libc.AssignInt32(&memJM, libc.Bool32(*(*int32)(unsafe.Pointer(bp + 8))&SQLITE_OPEN_MEMORY != 0)))
	readOnly = libc.Bool32(*(*int32)(unsafe.Pointer(bp + 8))&SQLITE_OPEN_READONLY != 0)

	if !(rc == SQLITE_OK) {
		goto __25
	}
	iDc = Xsqlite3OsDeviceCharacteristics(tls, (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ffd)
	if !!(readOnly != 0) {
		goto __26
	}
	setSectorSize(tls, *(*uintptr)(unsafe.Pointer(bp)))

	if !(*(*U32)(unsafe.Pointer(bp + 12)) < (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FsectorSize) {
		goto __27
	}
	if !((*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FsectorSize > U32(SQLITE_MAX_DEFAULT_PAGE_SIZE)) {
		goto __28
	}
	*(*U32)(unsafe.Pointer(bp + 12)) = U32(SQLITE_MAX_DEFAULT_PAGE_SIZE)
	goto __29
__28:
	*(*U32)(unsafe.Pointer(bp + 12)) = (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FsectorSize
__29:
	;
__27:
	;
__26:
	;
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnoLock = U8(Xsqlite3_uri_boolean(tls, (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzFilename, ts+6815, 0))
	if !(iDc&SQLITE_IOCAP_IMMUTABLE != 0 ||
		Xsqlite3_uri_boolean(tls, (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzFilename, ts+6822, 0) != 0) {
		goto __30
	}
	vfsFlags = vfsFlags | SQLITE_OPEN_READONLY
	goto act_like_temp_file
__30:
	;
__25:
	;
	goto __24
__23:
act_like_temp_file:
	tempFile = 1
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FeState = U8(PAGER_READER)
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FeLock = U8(EXCLUSIVE_LOCK)
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnoLock = U8(1)
	readOnly = vfsFlags & SQLITE_OPEN_READONLY
__24:
	;
	if !(rc == SQLITE_OK) {
		goto __31
	}

	rc = Xsqlite3PagerSetPagesize(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+12, -1)

__31:
	;
	if !(rc == SQLITE_OK) {
		goto __32
	}
	nExtra = (nExtra + 7) & libc.CplInt32(7)

	rc = Xsqlite3PcacheOpen(tls, int32(*(*U32)(unsafe.Pointer(bp + 12))), nExtra, libc.BoolInt32(!(memDb != 0)),
		func() uintptr {
			if !(memDb != 0) {
				return *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr) int32
				}{pagerStress}))
			}
			return uintptr(0)
		}(), *(*uintptr)(unsafe.Pointer(bp)), (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpPCache)
__32:
	;
	if !(rc != SQLITE_OK) {
		goto __33
	}
	Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ffd)
	Xsqlite3PageFree(tls, (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpTmpSpace)
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
__33:
	;
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FuseJournal = U8(useJournal)

	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FmxPgno = Pgno(SQLITE_MAX_PAGE_COUNT)

	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FtempFile = U8(tempFile)

	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FexclusiveMode = U8(tempFile)
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FchangeCountDone = (*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FtempFile
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FmemDb = U8(memDb)
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FreadOnly = U8(readOnly)

	Xsqlite3PagerSetFlags(tls, *(*uintptr)(unsafe.Pointer(bp)), uint32(SQLITE_DEFAULT_SYNCHRONOUS+1|PAGER_CACHESPILL))

	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnExtra = U16(nExtra)
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FjournalSizeLimit = int64(-1)

	setSectorSize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if !!(useJournal != 0) {
		goto __34
	}
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FjournalMode = U8(PAGER_JOURNALMODE_OFF)
	goto __35
__34:
	if !(memDb != 0 || memJM != 0) {
		goto __36
	}
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FjournalMode = U8(PAGER_JOURNALMODE_MEMORY)
__36:
	;
__35:
	;
	(*Pager)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxReiniter = xReinit
	setGetterMethod(tls, *(*uintptr)(unsafe.Pointer(bp)))

	*(*uintptr)(unsafe.Pointer(ppPager)) = *(*uintptr)(unsafe.Pointer(bp))
	return SQLITE_OK
}

func Xsqlite3_database_file_object(tls *libc.TLS, zName uintptr) uintptr {
	var pPager uintptr
	for int32(*(*uint8)(unsafe.Pointer(zName + libc.UintptrFromInt32(-1)))) != 0 || int32(*(*uint8)(unsafe.Pointer(zName + libc.UintptrFromInt32(-2)))) != 0 || int32(*(*uint8)(unsafe.Pointer(zName + libc.UintptrFromInt32(-3)))) != 0 || int32(*(*uint8)(unsafe.Pointer(zName + libc.UintptrFromInt32(-4)))) != 0 {
		zName--
	}
	pPager = *(*uintptr)(unsafe.Pointer(zName - uintptr(4) - uintptr(uint64(unsafe.Sizeof(uintptr(0))))))
	return (*Pager)(unsafe.Pointer(pPager)).Ffd
}

func hasHotJournal(tls *libc.TLS, pPager uintptr, pExists uintptr) int32 {
	bp := tls.Alloc(17)
	defer tls.Free(17)

	var pVfs uintptr = (*Pager)(unsafe.Pointer(pPager)).FpVfs
	var rc int32 = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp)) = 1
	var jrnlOpen int32 = libc.BoolInt32(!!((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0)))

	*(*int32)(unsafe.Pointer(pExists)) = 0
	if !(jrnlOpen != 0) {
		rc = Xsqlite3OsAccess(tls, pVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, SQLITE_ACCESS_EXISTS, bp)
	}
	if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) != 0 {
		*(*int32)(unsafe.Pointer(bp + 4)) = 0

		rc = Xsqlite3OsCheckReservedLock(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, bp+4)
		if rc == SQLITE_OK && !(*(*int32)(unsafe.Pointer(bp + 4)) != 0) {
			rc = pagerPagecount(tls, pPager, bp+8)
			if rc == SQLITE_OK {
				if *(*Pgno)(unsafe.Pointer(bp + 8)) == Pgno(0) && !(jrnlOpen != 0) {
					Xsqlite3BeginBenignMalloc(tls)
					if pagerLockDb(tls, pPager, RESERVED_LOCK) == SQLITE_OK {
						Xsqlite3OsDelete(tls, pVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, 0)
						if !(int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode) != 0) {
							pagerUnlockDb(tls, pPager, SHARED_LOCK)
						}
					}
					Xsqlite3EndBenignMalloc(tls)
				} else {
					if !(jrnlOpen != 0) {
						*(*int32)(unsafe.Pointer(bp + 12)) = SQLITE_OPEN_READONLY | SQLITE_OPEN_MAIN_JOURNAL
						rc = Xsqlite3OsOpen(tls, pVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, (*Pager)(unsafe.Pointer(pPager)).Fjfd, *(*int32)(unsafe.Pointer(bp + 12)), bp+12)
					}
					if rc == SQLITE_OK {
						*(*U8)(unsafe.Pointer(bp + 16)) = U8(0)
						rc = Xsqlite3OsRead(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, bp+16, 1, int64(0))
						if rc == SQLITE_IOERR|int32(2)<<8 {
							rc = SQLITE_OK
						}
						if !(jrnlOpen != 0) {
							Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
						}
						*(*int32)(unsafe.Pointer(pExists)) = libc.Bool32(int32(*(*U8)(unsafe.Pointer(bp + 16))) != 0)
					} else if rc == SQLITE_CANTOPEN {
						*(*int32)(unsafe.Pointer(pExists)) = 1
						rc = SQLITE_OK
					}
				}
			}
		}
	}

	return rc
}

func Xsqlite3PagerSharedLock(tls *libc.TLS, pPager uintptr) int32 {
	bp := tls.Alloc(28)
	defer tls.Free(28)

	var rc int32

	var f int32
	var pVfs uintptr

	rc = SQLITE_OK

	if !(!((*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0)) && int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN) {
		goto __1
	}
	*(*int32)(unsafe.Pointer(bp)) = 1

	rc = pager_wait_on_lock(tls, pPager, SHARED_LOCK)
	if !(rc != SQLITE_OK) {
		goto __2
	}

	goto failed
__2:
	;
	if !(int32((*Pager)(unsafe.Pointer(pPager)).FeLock) <= SHARED_LOCK) {
		goto __3
	}
	rc = hasHotJournal(tls, pPager, bp)
__3:
	;
	if !(rc != SQLITE_OK) {
		goto __4
	}
	goto failed
__4:
	;
	if !(*(*int32)(unsafe.Pointer(bp)) != 0) {
		goto __5
	}
	if !((*Pager)(unsafe.Pointer(pPager)).FreadOnly != 0) {
		goto __6
	}
	rc = SQLITE_READONLY | int32(3)<<8
	goto failed
__6:
	;
	rc = pagerLockDb(tls, pPager, EXCLUSIVE_LOCK)
	if !(rc != SQLITE_OK) {
		goto __7
	}
	goto failed
__7:
	;
	if !(!((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0)) && int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) != PAGER_JOURNALMODE_OFF) {
		goto __8
	}
	pVfs = (*Pager)(unsafe.Pointer(pPager)).FpVfs
	rc = Xsqlite3OsAccess(tls,
		pVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, SQLITE_ACCESS_EXISTS, bp+4)
	if !(rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 4)) != 0) {
		goto __9
	}
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	f = SQLITE_OPEN_READWRITE | SQLITE_OPEN_MAIN_JOURNAL

	rc = Xsqlite3OsOpen(tls, pVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, (*Pager)(unsafe.Pointer(pPager)).Fjfd, f, bp+8)

	if !(rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 8))&SQLITE_OPEN_READONLY != 0) {
		goto __10
	}
	rc = Xsqlite3CantopenError(tls, 60758)
	Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
__10:
	;
__9:
	;
__8:
	;
	if !((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0)) {
		goto __11
	}

	rc = pagerSyncHotJournal(tls, pPager)
	if !(rc == SQLITE_OK) {
		goto __13
	}
	rc = pager_playback(tls, pPager, libc.BoolInt32(!((*Pager)(unsafe.Pointer(pPager)).FtempFile != 0)))
	(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_OPEN)
__13:
	;
	goto __12
__11:
	if !!(int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode) != 0) {
		goto __14
	}
	pagerUnlockDb(tls, pPager, SHARED_LOCK)
__14:
	;
__12:
	;
	if !(rc != SQLITE_OK) {
		goto __15
	}

	pager_error(tls, pPager, rc)
	goto failed
__15:
	;
__5:
	;
	if !(!(int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) != 0) && (*Pager)(unsafe.Pointer(pPager)).FhasHeldSharedLock != 0) {
		goto __16
	}

	rc = Xsqlite3OsRead(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, bp+12, int32(unsafe.Sizeof([16]uint8{})), int64(24))
	if !(rc != SQLITE_OK) {
		goto __17
	}
	if !(rc != SQLITE_IOERR|int32(2)<<8) {
		goto __18
	}
	goto failed
__18:
	;
	libc.Xmemset(tls, bp+12, 0, uint64(unsafe.Sizeof([16]uint8{})))
__17:
	;
	if !(libc.Xmemcmp(tls, pPager+136, bp+12, uint64(unsafe.Sizeof([16]uint8{}))) != 0) {
		goto __19
	}
	pager_reset(tls, pPager)

	if !((*Pager)(unsafe.Pointer(pPager)).FbUseFetch != 0) {
		goto __20
	}
	Xsqlite3OsUnfetch(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, int64(0), uintptr(0))
__20:
	;
__19:
	;
__16:
	;
	rc = pagerOpenWalIfPresent(tls, pPager)

__1:
	;
	if !((*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0)) {
		goto __21
	}

	rc = pagerBeginReadTransaction(tls, pPager)
__21:
	;
	if !(int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) == 0 && int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN && rc == SQLITE_OK) {
		goto __22
	}
	rc = pagerPagecount(tls, pPager, pPager+32)
__22:
	;
failed:
	if !(rc != SQLITE_OK) {
		goto __23
	}

	pager_unlock(tls, pPager)

	goto __24
__23:
	(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_READER)
	(*Pager)(unsafe.Pointer(pPager)).FhasHeldSharedLock = U8(1)
__24:
	;
	return rc
}

func pagerUnlockIfUnused(tls *libc.TLS, pPager uintptr) {
	if Xsqlite3PcacheRefCount(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache) == int64(0) {
		pagerUnlockAndRollback(tls, pPager)
	}
}

func getPageNormal(tls *libc.TLS, pPager uintptr, pgno Pgno, ppPage uintptr, flags int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	var pPg uintptr
	var noContent U8

	rc = SQLITE_OK

	if !(pgno == Pgno(0)) {
		goto __1
	}
	return Xsqlite3CorruptError(tls, 60971)
__1:
	;
	*(*uintptr)(unsafe.Pointer(bp)) = Xsqlite3PcacheFetch(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, pgno, 3)
	if !(*(*uintptr)(unsafe.Pointer(bp)) == uintptr(0)) {
		goto __2
	}
	pPg = uintptr(0)
	rc = Xsqlite3PcacheFetchStress(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, pgno, bp)
	if !(rc != SQLITE_OK) {
		goto __3
	}
	goto pager_acquire_err
__3:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp)) == uintptr(0)) {
		goto __4
	}
	rc = SQLITE_NOMEM
	goto pager_acquire_err
__4:
	;
__2:
	;
	pPg = libc.AssignPtrUintptr(ppPage, Xsqlite3PcacheFetchFinish(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, pgno, *(*uintptr)(unsafe.Pointer(bp))))

	noContent = U8(libc.Bool32(flags&PAGER_GET_NOCONTENT != 0))
	if !((*PgHdr)(unsafe.Pointer(pPg)).FpPager != 0 && !(noContent != 0)) {
		goto __5
	}

	*(*int32)(unsafe.Pointer(pPager + 248))++
	return SQLITE_OK

	goto __6
__5:
	if !(pgno == (*Pager)(unsafe.Pointer(pPager)).FlckPgno) {
		goto __7
	}
	rc = Xsqlite3CorruptError(tls, 61003)
	goto pager_acquire_err
__7:
	;
	(*PgHdr)(unsafe.Pointer(pPg)).FpPager = pPager

	if !(!((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods != uintptr(0)) || (*Pager)(unsafe.Pointer(pPager)).FdbSize < pgno || noContent != 0) {
		goto __8
	}
	if !(pgno > (*Pager)(unsafe.Pointer(pPager)).FmxPgno) {
		goto __10
	}
	rc = SQLITE_FULL
	goto pager_acquire_err
__10:
	;
	if !(noContent != 0) {
		goto __11
	}

	Xsqlite3BeginBenignMalloc(tls)
	if !(pgno <= (*Pager)(unsafe.Pointer(pPager)).FdbOrigSize) {
		goto __12
	}
	Xsqlite3BitvecSet(tls, (*Pager)(unsafe.Pointer(pPager)).FpInJournal, pgno)

__12:
	;
	addToSavepointBitvecs(tls, pPager, pgno)

	Xsqlite3EndBenignMalloc(tls)
__11:
	;
	libc.Xmemset(tls, (*PgHdr)(unsafe.Pointer(pPg)).FpData, 0, uint64((*Pager)(unsafe.Pointer(pPager)).FpageSize))

	goto __9
__8:
	;
	*(*int32)(unsafe.Pointer(pPager + 248 + 1*4))++
	rc = readDbPage(tls, pPg)
	if !(rc != SQLITE_OK) {
		goto __13
	}
	goto pager_acquire_err
__13:
	;
__9:
	;
__6:
	;
	return SQLITE_OK

pager_acquire_err:
	;
	if !(pPg != 0) {
		goto __14
	}
	Xsqlite3PcacheDrop(tls, pPg)
__14:
	;
	pagerUnlockIfUnused(tls, pPager)
	*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
	return rc
}

func getPageMMap(tls *libc.TLS, pPager uintptr, pgno Pgno, ppPage uintptr, flags int32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32 = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	*(*U32)(unsafe.Pointer(bp)) = U32(0)

	var bMmapOk int32 = libc.Bool32(pgno > Pgno(1) &&
		(int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_READER || flags&PAGER_GET_READONLY != 0))

	if pgno <= Pgno(1) && pgno == Pgno(0) {
		return Xsqlite3CorruptError(tls, 61082)
	}

	if bMmapOk != 0 && (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		rc = Xsqlite3WalFindFrame(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, pgno, bp)
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return rc
		}
	}
	if bMmapOk != 0 && *(*U32)(unsafe.Pointer(bp)) == U32(0) {
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		rc = Xsqlite3OsFetch(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd,
			I64(pgno-Pgno(1))*(*Pager)(unsafe.Pointer(pPager)).FpageSize, int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), bp+8)
		if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
			if int32((*Pager)(unsafe.Pointer(pPager)).FeState) > PAGER_READER || (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 {
				*(*uintptr)(unsafe.Pointer(bp + 16)) = Xsqlite3PagerLookup(tls, pPager, pgno)
			}
			if *(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0) {
				rc = pagerAcquireMapPage(tls, pPager, pgno, *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16)
			} else {
				Xsqlite3OsUnfetch(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, I64(pgno-Pgno(1))*(*Pager)(unsafe.Pointer(pPager)).FpageSize, *(*uintptr)(unsafe.Pointer(bp + 8)))
			}
			if *(*uintptr)(unsafe.Pointer(bp + 16)) != 0 {
				*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer(bp + 16))
				return SQLITE_OK
			}
		}
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return rc
		}
	}
	return getPageNormal(tls, pPager, pgno, ppPage, flags)
}

func getPageError(tls *libc.TLS, pPager uintptr, pgno Pgno, ppPage uintptr, flags int32) int32 {
	_ = pgno
	_ = flags

	*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
	return (*Pager)(unsafe.Pointer(pPager)).FerrCode
}

func Xsqlite3PagerGet(tls *libc.TLS, pPager uintptr, pgno Pgno, ppPage uintptr, flags int32) int32 {
	return (*struct {
		f func(*libc.TLS, uintptr, Pgno, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Pager)(unsafe.Pointer(pPager)).FxGet})).f(tls, pPager, pgno, ppPage, flags)
}

func Xsqlite3PagerLookup(tls *libc.TLS, pPager uintptr, pgno Pgno) uintptr {
	var pPage uintptr

	pPage = Xsqlite3PcacheFetch(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, pgno, 0)

	if pPage == uintptr(0) {
		return uintptr(0)
	}
	return Xsqlite3PcacheFetchFinish(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache, pgno, pPage)
}

func Xsqlite3PagerUnrefNotNull(tls *libc.TLS, pPg uintptr) {
	if int32((*DbPage)(unsafe.Pointer(pPg)).Fflags)&PGHDR_MMAP != 0 {
		pagerReleaseMapPage(tls, pPg)
	} else {
		Xsqlite3PcacheRelease(tls, pPg)
	}

}

func Xsqlite3PagerUnref(tls *libc.TLS, pPg uintptr) {
	if pPg != 0 {
		Xsqlite3PagerUnrefNotNull(tls, pPg)
	}
}

func Xsqlite3PagerUnrefPageOne(tls *libc.TLS, pPg uintptr) {
	var pPager uintptr

	pPager = (*DbPage)(unsafe.Pointer(pPg)).FpPager
	Xsqlite3PcacheRelease(tls, pPg)
	pagerUnlockIfUnused(tls, pPager)
}

func pager_open_journal(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pVfs uintptr = (*Pager)(unsafe.Pointer(pPager)).FpVfs

	if (*Pager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return (*Pager)(unsafe.Pointer(pPager)).FerrCode
	}

	if !((*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0)) && int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) != PAGER_JOURNALMODE_OFF {
		(*Pager)(unsafe.Pointer(pPager)).FpInJournal = Xsqlite3BitvecCreate(tls, (*Pager)(unsafe.Pointer(pPager)).FdbSize)
		if (*Pager)(unsafe.Pointer(pPager)).FpInJournal == uintptr(0) {
			return SQLITE_NOMEM
		}

		if !((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0)) {
			if int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_MEMORY {
				Xsqlite3MemJournalOpen(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
			} else {
				var flags int32 = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
				var nSpill int32

				if (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 {
					flags = flags | (SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_TEMP_JOURNAL)
					flags = flags | SQLITE_OPEN_EXCLUSIVE
					nSpill = Xsqlite3Config.FnStmtSpill
				} else {
					flags = flags | SQLITE_OPEN_MAIN_JOURNAL
					nSpill = jrnlBufferSize(tls, pPager)
				}

				rc = databaseIsUnmoved(tls, pPager)
				if rc == SQLITE_OK {
					rc = Xsqlite3JournalOpen(tls,
						pVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, (*Pager)(unsafe.Pointer(pPager)).Fjfd, flags, nSpill)
				}
			}

		}

		if rc == SQLITE_OK {
			(*Pager)(unsafe.Pointer(pPager)).FnRec = 0
			(*Pager)(unsafe.Pointer(pPager)).FjournalOff = int64(0)
			(*Pager)(unsafe.Pointer(pPager)).FsetSuper = U8(0)
			(*Pager)(unsafe.Pointer(pPager)).FjournalHdr = int64(0)
			rc = writeJournalHdr(tls, pPager)
		}
	}

	if rc != SQLITE_OK {
		Xsqlite3BitvecDestroy(tls, (*Pager)(unsafe.Pointer(pPager)).FpInJournal)
		(*Pager)(unsafe.Pointer(pPager)).FpInJournal = uintptr(0)
		(*Pager)(unsafe.Pointer(pPager)).FjournalOff = int64(0)
	} else {
		(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_WRITER_CACHEMOD)
	}

	return rc
}

func Xsqlite3PagerBegin(tls *libc.TLS, pPager uintptr, exFlag int32, subjInMemory int32) int32 {
	var rc int32 = SQLITE_OK

	if (*Pager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return (*Pager)(unsafe.Pointer(pPager)).FerrCode
	}

	(*Pager)(unsafe.Pointer(pPager)).FsubjInMemory = U8(subjInMemory)

	if int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_READER {
		if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
			if (*Pager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 && Xsqlite3WalExclusiveMode(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, -1) != 0 {
				rc = pagerLockDb(tls, pPager, EXCLUSIVE_LOCK)
				if rc != SQLITE_OK {
					return rc
				}
				Xsqlite3WalExclusiveMode(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, 1)
			}

			rc = Xsqlite3WalBeginWriteTransaction(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal)
		} else {
			rc = pagerLockDb(tls, pPager, RESERVED_LOCK)
			if rc == SQLITE_OK && exFlag != 0 {
				rc = pager_wait_on_lock(tls, pPager, EXCLUSIVE_LOCK)
			}
		}

		if rc == SQLITE_OK {
			(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_WRITER_LOCKED)
			(*Pager)(unsafe.Pointer(pPager)).FdbHintSize = (*Pager)(unsafe.Pointer(pPager)).FdbSize
			(*Pager)(unsafe.Pointer(pPager)).FdbFileSize = (*Pager)(unsafe.Pointer(pPager)).FdbSize
			(*Pager)(unsafe.Pointer(pPager)).FdbOrigSize = (*Pager)(unsafe.Pointer(pPager)).FdbSize
			(*Pager)(unsafe.Pointer(pPager)).FjournalOff = int64(0)
		}

	}

	return rc
}

func pagerAddPageToRollbackJournal(tls *libc.TLS, pPg uintptr) int32 {
	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager
	var rc int32
	var cksum U32
	var pData2 uintptr
	var iOff I64 = (*Pager)(unsafe.Pointer(pPager)).FjournalOff

	pData2 = (*PgHdr)(unsafe.Pointer(pPg)).FpData
	cksum = pager_cksum(tls, pPager, pData2)

	*(*U16)(unsafe.Pointer(pPg + 52)) |= U16(PGHDR_NEED_SYNC)

	rc = write32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iOff, (*PgHdr)(unsafe.Pointer(pPg)).Fpgno)
	if rc != SQLITE_OK {
		return rc
	}
	rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, pData2, int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), iOff+int64(4))
	if rc != SQLITE_OK {
		return rc
	}
	rc = write32bits(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd, iOff+(*Pager)(unsafe.Pointer(pPager)).FpageSize+int64(4), cksum)
	if rc != SQLITE_OK {
		return rc
	}

	atomic.AddInt32(&Xsqlite3_pager_writej_count, 1)

	*(*I64)(unsafe.Pointer(pPager + 96)) += int64(8) + (*Pager)(unsafe.Pointer(pPager)).FpageSize
	(*Pager)(unsafe.Pointer(pPager)).FnRec++

	rc = Xsqlite3BitvecSet(tls, (*Pager)(unsafe.Pointer(pPager)).FpInJournal, (*PgHdr)(unsafe.Pointer(pPg)).Fpgno)

	rc = rc | addToSavepointBitvecs(tls, pPager, (*PgHdr)(unsafe.Pointer(pPg)).Fpgno)

	return rc
}

func pager_write(tls *libc.TLS, pPg uintptr) int32 {
	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager
	var rc int32 = SQLITE_OK

	if int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_WRITER_LOCKED {
		rc = pager_open_journal(tls, pPager)
		if rc != SQLITE_OK {
			return rc
		}
	}

	Xsqlite3PcacheMakeDirty(tls, pPg)

	if (*Pager)(unsafe.Pointer(pPager)).FpInJournal != uintptr(0) &&
		Xsqlite3BitvecTestNotNull(tls, (*Pager)(unsafe.Pointer(pPager)).FpInJournal, (*PgHdr)(unsafe.Pointer(pPg)).Fpgno) == 0 {
		if (*PgHdr)(unsafe.Pointer(pPg)).Fpgno <= (*Pager)(unsafe.Pointer(pPager)).FdbOrigSize {
			rc = pagerAddPageToRollbackJournal(tls, pPg)
			if rc != SQLITE_OK {
				return rc
			}
		} else {
			if int32((*Pager)(unsafe.Pointer(pPager)).FeState) != PAGER_WRITER_DBMOD {
				*(*U16)(unsafe.Pointer(pPg + 52)) |= U16(PGHDR_NEED_SYNC)
			}

		}
	}

	*(*U16)(unsafe.Pointer(pPg + 52)) |= U16(PGHDR_WRITEABLE)

	if (*Pager)(unsafe.Pointer(pPager)).FnSavepoint > 0 {
		rc = subjournalPageIfRequired(tls, pPg)
	}

	if (*Pager)(unsafe.Pointer(pPager)).FdbSize < (*PgHdr)(unsafe.Pointer(pPg)).Fpgno {
		(*Pager)(unsafe.Pointer(pPager)).FdbSize = (*PgHdr)(unsafe.Pointer(pPg)).Fpgno
	}
	return rc
}

func pagerWriteLargeSector(tls *libc.TLS, pPg uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var nPageCount Pgno
	var pg1 Pgno
	var nPage int32 = 0
	var ii int32
	var needSync int32 = 0
	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager
	var nPagePerSector Pgno = Pgno(I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize) / (*Pager)(unsafe.Pointer(pPager)).FpageSize)

	*(*U8)(unsafe.Pointer(pPager + 25)) |= U8(SPILLFLAG_NOSYNC)

	pg1 = ((*PgHdr)(unsafe.Pointer(pPg)).Fpgno-Pgno(1)) & ^(nPagePerSector-Pgno(1)) + Pgno(1)

	nPageCount = (*Pager)(unsafe.Pointer(pPager)).FdbSize
	if (*PgHdr)(unsafe.Pointer(pPg)).Fpgno > nPageCount {
		nPage = int32((*PgHdr)(unsafe.Pointer(pPg)).Fpgno - pg1 + Pgno(1))
	} else if pg1+nPagePerSector-Pgno(1) > nPageCount {
		nPage = int32(nPageCount + Pgno(1) - pg1)
	} else {
		nPage = int32(nPagePerSector)
	}

	for ii = 0; ii < nPage && rc == SQLITE_OK; ii++ {
		var pg Pgno = pg1 + Pgno(ii)

		if pg == (*PgHdr)(unsafe.Pointer(pPg)).Fpgno || !(Xsqlite3BitvecTest(tls, (*Pager)(unsafe.Pointer(pPager)).FpInJournal, pg) != 0) {
			if pg != (*Pager)(unsafe.Pointer(pPager)).FlckPgno {
				rc = Xsqlite3PagerGet(tls, pPager, pg, bp, 0)
				if rc == SQLITE_OK {
					rc = pager_write(tls, *(*uintptr)(unsafe.Pointer(bp)))
					if int32((*PgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags)&PGHDR_NEED_SYNC != 0 {
						needSync = 1
					}
					Xsqlite3PagerUnrefNotNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
				}
			}
		} else if libc.AssignPtrUintptr(bp, Xsqlite3PagerLookup(tls, pPager, pg)) != uintptr(0) {
			if int32((*PgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fflags)&PGHDR_NEED_SYNC != 0 {
				needSync = 1
			}
			Xsqlite3PagerUnrefNotNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}

	if rc == SQLITE_OK && needSync != 0 {
		for ii = 0; ii < nPage; ii++ {
			var pPage uintptr = Xsqlite3PagerLookup(tls, pPager, pg1+Pgno(ii))
			if pPage != 0 {
				*(*U16)(unsafe.Pointer(pPage + 52)) |= U16(PGHDR_NEED_SYNC)
				Xsqlite3PagerUnrefNotNull(tls, pPage)
			}
		}
	}

	*(*U8)(unsafe.Pointer(pPager + 25)) &= libc.Uint8FromInt32(libc.CplInt32(SPILLFLAG_NOSYNC))
	return rc
}

func Xsqlite3PagerWrite(tls *libc.TLS, pPg uintptr) int32 {
	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager

	if int32((*PgHdr)(unsafe.Pointer(pPg)).Fflags)&PGHDR_WRITEABLE != 0 && (*Pager)(unsafe.Pointer(pPager)).FdbSize >= (*PgHdr)(unsafe.Pointer(pPg)).Fpgno {
		if (*Pager)(unsafe.Pointer(pPager)).FnSavepoint != 0 {
			return subjournalPageIfRequired(tls, pPg)
		}
		return SQLITE_OK
	} else if (*Pager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return (*Pager)(unsafe.Pointer(pPager)).FerrCode
	} else if (*Pager)(unsafe.Pointer(pPager)).FsectorSize > U32((*Pager)(unsafe.Pointer(pPager)).FpageSize) {
		return pagerWriteLargeSector(tls, pPg)
	} else {
		return pager_write(tls, pPg)
	}
	return int32(0)
}

func Xsqlite3PagerDontWrite(tls *libc.TLS, pPg uintptr) {
	var pPager uintptr = (*PgHdr)(unsafe.Pointer(pPg)).FpPager
	if !(int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) != 0) && int32((*PgHdr)(unsafe.Pointer(pPg)).Fflags)&PGHDR_DIRTY != 0 && (*Pager)(unsafe.Pointer(pPager)).FnSavepoint == 0 {
		*(*U16)(unsafe.Pointer(pPg + 52)) |= U16(PGHDR_DONT_WRITE)
		*(*U16)(unsafe.Pointer(pPg + 52)) &= libc.Uint16FromInt32(libc.CplInt32(PGHDR_WRITEABLE))

	}
}

func pager_incr_changecounter(tls *libc.TLS, pPager uintptr, isDirectMode int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK

	_ = isDirectMode

	if !(int32((*Pager)(unsafe.Pointer(pPager)).FchangeCountDone) != 0) && (*Pager)(unsafe.Pointer(pPager)).FdbSize > Pgno(0) {
		rc = Xsqlite3PagerGet(tls, pPager, uint32(1), bp, 0)

		if !(0 != 0) && rc == SQLITE_OK {
			rc = Xsqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}

		if rc == SQLITE_OK {
			pager_write_changecounter(tls, *(*uintptr)(unsafe.Pointer(bp)))

			if 0 != 0 {
				var zBuf uintptr

				zBuf = (*PgHdr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpData
				if rc == SQLITE_OK {
					rc = Xsqlite3OsWrite(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, zBuf, int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), int64(0))
					*(*int32)(unsafe.Pointer(pPager + 248 + 2*4))++
				}
				if rc == SQLITE_OK {
					var pCopy uintptr = zBuf + 24
					libc.Xmemcpy(tls, pPager+136, pCopy, uint64(unsafe.Sizeof([16]uint8{})))
					(*Pager)(unsafe.Pointer(pPager)).FchangeCountDone = U8(1)
				}
			} else {
				(*Pager)(unsafe.Pointer(pPager)).FchangeCountDone = U8(1)
			}
		}

		Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

func Xsqlite3PagerSync(tls *libc.TLS, pPager uintptr, zSuper uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pArg uintptr = zSuper
	rc = Xsqlite3OsFileControl(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, SQLITE_FCNTL_SYNC, pArg)
	if rc == SQLITE_NOTFOUND {
		rc = SQLITE_OK
	}
	if rc == SQLITE_OK && !(int32((*Pager)(unsafe.Pointer(pPager)).FnoSync) != 0) {
		rc = Xsqlite3OsSync(tls, (*Pager)(unsafe.Pointer(pPager)).Ffd, int32((*Pager)(unsafe.Pointer(pPager)).FsyncFlags))
	}
	return rc
}

func Xsqlite3PagerExclusiveLock(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = (*Pager)(unsafe.Pointer(pPager)).FerrCode

	if rc == SQLITE_OK {
		if 0 == libc.Bool32((*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0)) {
			rc = pager_wait_on_lock(tls, pPager, EXCLUSIVE_LOCK)
		}
	}
	return rc
}

func Xsqlite3PagerCommitPhaseOne(tls *libc.TLS, pPager uintptr, zSuper uintptr, noSync int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	var nNew Pgno
	var pList uintptr
	rc = SQLITE_OK

	if !((*Pager)(unsafe.Pointer(pPager)).FerrCode != 0) {
		goto __1
	}
	return (*Pager)(unsafe.Pointer(pPager)).FerrCode
__1:
	;
	if !(Xsqlite3FaultSim(tls, 400) != 0) {
		goto __2
	}
	return SQLITE_IOERR
__2:
	;
	if !(int32((*Pager)(unsafe.Pointer(pPager)).FeState) < PAGER_WRITER_CACHEMOD) {
		goto __3
	}
	return SQLITE_OK
__3:
	;
	if !(0 == pagerFlushOnCommit(tls, pPager, 1)) {
		goto __4
	}

	Xsqlite3BackupRestart(tls, (*Pager)(unsafe.Pointer(pPager)).FpBackup)
	goto __5
__4:
	if !((*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0)) {
		goto __6
	}
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pList = Xsqlite3PcacheDirtyList(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
	if !(pList == uintptr(0)) {
		goto __8
	}

	rc = Xsqlite3PagerGet(tls, pPager, uint32(1), bp, 0)
	pList = *(*uintptr)(unsafe.Pointer(bp))
	(*PgHdr)(unsafe.Pointer(pList)).FpDirty = uintptr(0)
__8:
	;
	if !(pList != 0) {
		goto __9
	}
	rc = pagerWalFrames(tls, pPager, pList, (*Pager)(unsafe.Pointer(pPager)).FdbSize, 1)
__9:
	;
	Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if !(rc == SQLITE_OK) {
		goto __10
	}
	Xsqlite3PcacheCleanAll(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
__10:
	;
	goto __7
__6:
	rc = pager_incr_changecounter(tls, pPager, 0)
	if !(rc != SQLITE_OK) {
		goto __11
	}
	goto commit_phase_one_exit
__11:
	;
	rc = writeSuperJournal(tls, pPager, zSuper)
	if !(rc != SQLITE_OK) {
		goto __12
	}
	goto commit_phase_one_exit
__12:
	;
	rc = syncJournal(tls, pPager, 0)
	if !(rc != SQLITE_OK) {
		goto __13
	}
	goto commit_phase_one_exit
__13:
	;
	pList = Xsqlite3PcacheDirtyList(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)

	if !(BBatch == 0) {
		goto __14
	}
	rc = pager_write_pagelist(tls, pPager, pList)
__14:
	;
	if !(rc != SQLITE_OK) {
		goto __15
	}

	goto commit_phase_one_exit
__15:
	;
	Xsqlite3PcacheCleanAll(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)

	if !((*Pager)(unsafe.Pointer(pPager)).FdbSize > (*Pager)(unsafe.Pointer(pPager)).FdbFileSize) {
		goto __16
	}
	nNew = (*Pager)(unsafe.Pointer(pPager)).FdbSize - Pgno(libc.Bool32((*Pager)(unsafe.Pointer(pPager)).FdbSize == (*Pager)(unsafe.Pointer(pPager)).FlckPgno))

	rc = pager_truncate(tls, pPager, nNew)
	if !(rc != SQLITE_OK) {
		goto __17
	}
	goto commit_phase_one_exit
__17:
	;
__16:
	;
	if !!(noSync != 0) {
		goto __18
	}
	rc = Xsqlite3PagerSync(tls, pPager, zSuper)
__18:
	;
__7:
	;
__5:
	;
commit_phase_one_exit:
	if !(rc == SQLITE_OK && !((*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0))) {
		goto __19
	}
	(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_WRITER_FINISHED)
__19:
	;
	return rc
}

func Xsqlite3PagerCommitPhaseTwo(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = SQLITE_OK

	if (*Pager)(unsafe.Pointer(pPager)).FerrCode != 0 {
		return (*Pager)(unsafe.Pointer(pPager)).FerrCode
	}
	(*Pager)(unsafe.Pointer(pPager)).FiDataVersion++

	if int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_WRITER_LOCKED &&
		(*Pager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 &&
		int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_PERSIST {
		(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_READER)
		return SQLITE_OK
	}

	rc = pager_end_transaction(tls, pPager, int32((*Pager)(unsafe.Pointer(pPager)).FsetSuper), 1)
	return pager_error(tls, pPager, rc)
}

func Xsqlite3PagerRollback(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = SQLITE_OK

	if int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_ERROR {
		return (*Pager)(unsafe.Pointer(pPager)).FerrCode
	}
	if int32((*Pager)(unsafe.Pointer(pPager)).FeState) <= PAGER_READER {
		return SQLITE_OK
	}

	if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
		var rc2 int32
		rc = Xsqlite3PagerSavepoint(tls, pPager, SAVEPOINT_ROLLBACK, -1)
		rc2 = pager_end_transaction(tls, pPager, int32((*Pager)(unsafe.Pointer(pPager)).FsetSuper), 0)
		if rc == SQLITE_OK {
			rc = rc2
		}
	} else if !((*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0)) || int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_WRITER_LOCKED {
		var eState int32 = int32((*Pager)(unsafe.Pointer(pPager)).FeState)
		rc = pager_end_transaction(tls, pPager, 0, 0)
		if !(int32((*Pager)(unsafe.Pointer(pPager)).FmemDb) != 0) && eState > PAGER_WRITER_LOCKED {
			(*Pager)(unsafe.Pointer(pPager)).FerrCode = SQLITE_ABORT
			(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_ERROR)
			setGetterMethod(tls, pPager)
			return rc
		}
	} else {
		rc = pager_playback(tls, pPager, 0)
	}

	return pager_error(tls, pPager, rc)
}

func Xsqlite3PagerIsreadonly(tls *libc.TLS, pPager uintptr) U8 {
	return (*Pager)(unsafe.Pointer(pPager)).FreadOnly
}

func Xsqlite3PagerMemUsed(tls *libc.TLS, pPager uintptr) int32 {
	var perPageSize int32 = int32((*Pager)(unsafe.Pointer(pPager)).FpageSize + I64((*Pager)(unsafe.Pointer(pPager)).FnExtra) +
		I64(int32(uint64(unsafe.Sizeof(PgHdr{}))+uint64(5)*uint64(unsafe.Sizeof(uintptr(0))))))
	return int32(I64(perPageSize*Xsqlite3PcachePagecount(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)+
		Xsqlite3MallocSize(tls, pPager)) +
		(*Pager)(unsafe.Pointer(pPager)).FpageSize)
}

func Xsqlite3PagerPageRefcount(tls *libc.TLS, pPage uintptr) int32 {
	return int32(Xsqlite3PcachePageRefcount(tls, pPage))
}

func Xsqlite3PagerStats(tls *libc.TLS, pPager uintptr) uintptr {
	a1[0] = int32(Xsqlite3PcacheRefCount(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache))
	a1[1] = Xsqlite3PcachePagecount(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
	a1[2] = Xsqlite3PcacheGetCachesize(tls, (*Pager)(unsafe.Pointer(pPager)).FpPCache)
	a1[3] = func() int32 {
		if int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_OPEN {
			return -1
		}
		return int32((*Pager)(unsafe.Pointer(pPager)).FdbSize)
	}()
	a1[4] = int32((*Pager)(unsafe.Pointer(pPager)).FeState)
	a1[5] = (*Pager)(unsafe.Pointer(pPager)).FerrCode
	a1[6] = *(*int32)(unsafe.Pointer(pPager + 248))
	a1[7] = *(*int32)(unsafe.Pointer(pPager + 248 + 1*4))
	a1[8] = 0
	a1[9] = (*Pager)(unsafe.Pointer(pPager)).FnRead
	a1[10] = *(*int32)(unsafe.Pointer(pPager + 248 + 2*4))
	return uintptr(unsafe.Pointer(&a1))
}

var a1 [11]int32

func Xsqlite3PagerCacheStat(tls *libc.TLS, pPager uintptr, eStat int32, reset int32, pnVal uintptr) {
	eStat = eStat - SQLITE_DBSTATUS_CACHE_HIT
	*(*int32)(unsafe.Pointer(pnVal)) += *(*int32)(unsafe.Pointer(pPager + 248 + uintptr(eStat)*4))
	if reset != 0 {
		*(*int32)(unsafe.Pointer(pPager + 248 + uintptr(eStat)*4)) = 0
	}
}

func Xsqlite3PagerIsMemdb(tls *libc.TLS, pPager uintptr) int32 {
	return libc.Bool32((*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 || (*Pager)(unsafe.Pointer(pPager)).FmemVfs != 0)
}

func pagerOpenSavepoint(tls *libc.TLS, pPager uintptr, nSavepoint int32) int32 {
	var rc int32 = SQLITE_OK
	var nCurrent int32 = (*Pager)(unsafe.Pointer(pPager)).FnSavepoint
	var ii int32
	var aNew uintptr

	aNew = Xsqlite3Realloc(tls,
		(*Pager)(unsafe.Pointer(pPager)).FaSavepoint, uint64(unsafe.Sizeof(PagerSavepoint{}))*uint64(nSavepoint))
	if !(aNew != 0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, aNew+uintptr(nCurrent)*56, 0, uint64(nSavepoint-nCurrent)*uint64(unsafe.Sizeof(PagerSavepoint{})))
	(*Pager)(unsafe.Pointer(pPager)).FaSavepoint = aNew

	for ii = nCurrent; ii < nSavepoint; ii++ {
		(*PagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*56)).FnOrig = (*Pager)(unsafe.Pointer(pPager)).FdbSize
		if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) && (*Pager)(unsafe.Pointer(pPager)).FjournalOff > int64(0) {
			(*PagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*56)).FiOffset = (*Pager)(unsafe.Pointer(pPager)).FjournalOff
		} else {
			(*PagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*56)).FiOffset = I64((*Pager)(unsafe.Pointer(pPager)).FsectorSize)
		}
		(*PagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*56)).FiSubRec = (*Pager)(unsafe.Pointer(pPager)).FnSubRec
		(*PagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*56)).FpInSavepoint = Xsqlite3BitvecCreate(tls, (*Pager)(unsafe.Pointer(pPager)).FdbSize)
		(*PagerSavepoint)(unsafe.Pointer(aNew + uintptr(ii)*56)).FbTruncateOnRelease = 1
		if !(int32((*PagerSavepoint)(unsafe.Pointer(aNew+uintptr(ii)*56)).FpInSavepoint) != 0) {
			return SQLITE_NOMEM
		}
		if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) {
			Xsqlite3WalSavepoint(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, aNew+uintptr(ii)*56+36)
		}
		(*Pager)(unsafe.Pointer(pPager)).FnSavepoint = ii + 1
	}

	return rc
}

func Xsqlite3PagerOpenSavepoint(tls *libc.TLS, pPager uintptr, nSavepoint int32) int32 {
	if nSavepoint > (*Pager)(unsafe.Pointer(pPager)).FnSavepoint && (*Pager)(unsafe.Pointer(pPager)).FuseJournal != 0 {
		return pagerOpenSavepoint(tls, pPager, nSavepoint)
	} else {
		return SQLITE_OK
	}
	return int32(0)
}

func Xsqlite3PagerSavepoint(tls *libc.TLS, pPager uintptr, op int32, iSavepoint int32) int32 {
	var rc int32 = (*Pager)(unsafe.Pointer(pPager)).FerrCode

	if rc == SQLITE_OK && iSavepoint < (*Pager)(unsafe.Pointer(pPager)).FnSavepoint {
		var ii int32
		var nNew int32

		nNew = iSavepoint + func() int32 {
			if op == SAVEPOINT_RELEASE {
				return 0
			}
			return 1
		}()
		for ii = nNew; ii < (*Pager)(unsafe.Pointer(pPager)).FnSavepoint; ii++ {
			Xsqlite3BitvecDestroy(tls, (*PagerSavepoint)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).FaSavepoint+uintptr(ii)*56)).FpInSavepoint)
		}
		(*Pager)(unsafe.Pointer(pPager)).FnSavepoint = nNew

		if op == SAVEPOINT_RELEASE {
			var pRel uintptr = (*Pager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(nNew)*56
			if (*PagerSavepoint)(unsafe.Pointer(pRel)).FbTruncateOnRelease != 0 && (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fsjfd)).FpMethods != uintptr(0) {
				if Xsqlite3JournalIsInMemory(tls, (*Pager)(unsafe.Pointer(pPager)).Fsjfd) != 0 {
					var sz I64 = ((*Pager)(unsafe.Pointer(pPager)).FpageSize + int64(4)) * I64((*PagerSavepoint)(unsafe.Pointer(pRel)).FiSubRec)
					rc = Xsqlite3OsTruncate(tls, (*Pager)(unsafe.Pointer(pPager)).Fsjfd, sz)

				}
				(*Pager)(unsafe.Pointer(pPager)).FnSubRec = (*PagerSavepoint)(unsafe.Pointer(pRel)).FiSubRec
			}
		} else if (*Pager)(unsafe.Pointer(pPager)).FpWal != uintptr(0) || (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) {
			var pSavepoint uintptr
			if nNew == 0 {
				pSavepoint = uintptr(0)
			} else {
				pSavepoint = (*Pager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(nNew-1)*56
			}
			rc = pagerPlaybackSavepoint(tls, pPager, pSavepoint)

		}

	}

	return rc
}

func Xsqlite3PagerFilename(tls *libc.TLS, pPager uintptr, nullIfMemDb int32) uintptr {
	if nullIfMemDb != 0 && ((*Pager)(unsafe.Pointer(pPager)).FmemDb != 0 || Xsqlite3IsMemdb(tls, (*Pager)(unsafe.Pointer(pPager)).FpVfs) != 0) {
		return uintptr(unsafe.Pointer(&zFake)) + 4
	} else {
		return (*Pager)(unsafe.Pointer(pPager)).FzFilename
	}
	return uintptr(0)
}

var zFake = [8]uint8{uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0)}

func Xsqlite3PagerVfs(tls *libc.TLS, pPager uintptr) uintptr {
	return (*Pager)(unsafe.Pointer(pPager)).FpVfs
}

func Xsqlite3PagerFile(tls *libc.TLS, pPager uintptr) uintptr {
	return (*Pager)(unsafe.Pointer(pPager)).Ffd
}

func Xsqlite3PagerJrnlFile(tls *libc.TLS, pPager uintptr) uintptr {
	if (*Pager)(unsafe.Pointer(pPager)).FpWal != 0 {
		return Xsqlite3WalFile(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal)
	}
	return (*Pager)(unsafe.Pointer(pPager)).Fjfd
}

func Xsqlite3PagerJournalname(tls *libc.TLS, pPager uintptr) uintptr {
	return (*Pager)(unsafe.Pointer(pPager)).FzJournal
}

func Xsqlite3PagerMovepage(tls *libc.TLS, pPager uintptr, pPg uintptr, pgno Pgno, isCommit int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pPgOld uintptr
	var needSyncPgno Pgno = Pgno(0)
	var rc int32
	var origPgno Pgno

	if (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 {
		rc = Xsqlite3PagerWrite(tls, pPg)
		if rc != 0 {
			return rc
		}
	}

	if int32((*DbPage)(unsafe.Pointer(pPg)).Fflags)&PGHDR_DIRTY != 0 &&
		SQLITE_OK != libc.AssignInt32(&rc, subjournalPageIfRequired(tls, pPg)) {
		return rc
	}

	if int32((*DbPage)(unsafe.Pointer(pPg)).Fflags)&PGHDR_NEED_SYNC != 0 && !(isCommit != 0) {
		needSyncPgno = (*DbPage)(unsafe.Pointer(pPg)).Fpgno

	}

	*(*U16)(unsafe.Pointer(pPg + 52)) &= libc.Uint16FromInt32(libc.CplInt32(PGHDR_NEED_SYNC))
	pPgOld = Xsqlite3PagerLookup(tls, pPager, pgno)

	if pPgOld != 0 {
		if (*PgHdr)(unsafe.Pointer(pPgOld)).FnRef > int64(1) {
			Xsqlite3PagerUnrefNotNull(tls, pPgOld)
			return Xsqlite3CorruptError(tls, 62627)
		}
		*(*U16)(unsafe.Pointer(pPg + 52)) |= U16(int32((*PgHdr)(unsafe.Pointer(pPgOld)).Fflags) & PGHDR_NEED_SYNC)
		if (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 {
			Xsqlite3PcacheMove(tls, pPgOld, (*Pager)(unsafe.Pointer(pPager)).FdbSize+Pgno(1))
		} else {
			Xsqlite3PcacheDrop(tls, pPgOld)
		}
	}

	origPgno = (*DbPage)(unsafe.Pointer(pPg)).Fpgno
	Xsqlite3PcacheMove(tls, pPg, pgno)
	Xsqlite3PcacheMakeDirty(tls, pPg)

	if (*Pager)(unsafe.Pointer(pPager)).FtempFile != 0 && pPgOld != 0 {
		Xsqlite3PcacheMove(tls, pPgOld, origPgno)
		Xsqlite3PagerUnrefNotNull(tls, pPgOld)
	}

	if needSyncPgno != 0 {
		rc = Xsqlite3PagerGet(tls, pPager, needSyncPgno, bp, 0)
		if rc != SQLITE_OK {
			if needSyncPgno <= (*Pager)(unsafe.Pointer(pPager)).FdbOrigSize {
				Xsqlite3BitvecClear(tls, (*Pager)(unsafe.Pointer(pPager)).FpInJournal, needSyncPgno, (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace)
			}
			return rc
		}
		*(*U16)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 52)) |= U16(PGHDR_NEED_SYNC)
		Xsqlite3PcacheMakeDirty(tls, *(*uintptr)(unsafe.Pointer(bp)))
		Xsqlite3PagerUnrefNotNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}

	return SQLITE_OK
}

func Xsqlite3PagerRekey(tls *libc.TLS, pPg uintptr, iNew Pgno, flags U16) {
	(*DbPage)(unsafe.Pointer(pPg)).Fflags = flags
	Xsqlite3PcacheMove(tls, pPg, iNew)
}

func Xsqlite3PagerGetData(tls *libc.TLS, pPg uintptr) uintptr {
	return (*DbPage)(unsafe.Pointer(pPg)).FpData
}

func Xsqlite3PagerGetExtra(tls *libc.TLS, pPg uintptr) uintptr {
	return (*DbPage)(unsafe.Pointer(pPg)).FpExtra
}

func Xsqlite3PagerLockingMode(tls *libc.TLS, pPager uintptr, eMode int32) int32 {
	if eMode >= 0 && !(int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) != 0) && !(Xsqlite3WalHeapMemory(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal) != 0) {
		(*Pager)(unsafe.Pointer(pPager)).FexclusiveMode = U8(eMode)
	}
	return int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode)
}

func Xsqlite3PagerSetJournalMode(tls *libc.TLS, pPager uintptr, eMode int32) int32 {
	var eOld U8 = (*Pager)(unsafe.Pointer(pPager)).FjournalMode

	if (*Pager)(unsafe.Pointer(pPager)).FmemDb != 0 {
		if eMode != PAGER_JOURNALMODE_MEMORY && eMode != PAGER_JOURNALMODE_OFF {
			eMode = int32(eOld)
		}
	}

	if eMode != int32(eOld) {
		(*Pager)(unsafe.Pointer(pPager)).FjournalMode = U8(eMode)

		if !(int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode) != 0) && int32(eOld)&5 == 1 && eMode&1 == 0 {
			Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
			if int32((*Pager)(unsafe.Pointer(pPager)).FeLock) >= RESERVED_LOCK {
				Xsqlite3OsDelete(tls, (*Pager)(unsafe.Pointer(pPager)).FpVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, 0)
			} else {
				var rc int32 = SQLITE_OK
				var state int32 = int32((*Pager)(unsafe.Pointer(pPager)).FeState)

				if state == PAGER_OPEN {
					rc = Xsqlite3PagerSharedLock(tls, pPager)
				}
				if int32((*Pager)(unsafe.Pointer(pPager)).FeState) == PAGER_READER {
					rc = pagerLockDb(tls, pPager, RESERVED_LOCK)
				}
				if rc == SQLITE_OK {
					Xsqlite3OsDelete(tls, (*Pager)(unsafe.Pointer(pPager)).FpVfs, (*Pager)(unsafe.Pointer(pPager)).FzJournal, 0)
				}
				if rc == SQLITE_OK && state == PAGER_READER {
					pagerUnlockDb(tls, pPager, SHARED_LOCK)
				} else if state == PAGER_OPEN {
					pager_unlock(tls, pPager)
				}

			}
		} else if eMode == PAGER_JOURNALMODE_OFF {
			Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)
		}
	}

	return int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode)
}

func Xsqlite3PagerGetJournalMode(tls *libc.TLS, pPager uintptr) int32 {
	return int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode)
}

func Xsqlite3PagerOkToChangeJournalMode(tls *libc.TLS, pPager uintptr) int32 {
	if int32((*Pager)(unsafe.Pointer(pPager)).FeState) >= PAGER_WRITER_CACHEMOD {
		return 0
	}
	if (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Fjfd)).FpMethods != uintptr(0) && (*Pager)(unsafe.Pointer(pPager)).FjournalOff > int64(0) {
		return 0
	}
	return 1
}

func Xsqlite3PagerJournalSizeLimit(tls *libc.TLS, pPager uintptr, iLimit I64) I64 {
	if iLimit >= int64(-1) {
		(*Pager)(unsafe.Pointer(pPager)).FjournalSizeLimit = iLimit
		Xsqlite3WalLimit(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, iLimit)
	}
	return (*Pager)(unsafe.Pointer(pPager)).FjournalSizeLimit
}

func Xsqlite3PagerBackupPtr(tls *libc.TLS, pPager uintptr) uintptr {
	return pPager + 112
}

func Xsqlite3PagerClearCache(tls *libc.TLS, pPager uintptr) {
	if int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) == 0 {
		pager_reset(tls, pPager)
	}
}

func Xsqlite3PagerCheckpoint(tls *libc.TLS, pPager uintptr, db uintptr, eMode int32, pnLog uintptr, pnCkpt uintptr) int32 {
	var rc int32 = SQLITE_OK
	if (*Pager)(unsafe.Pointer(pPager)).FpWal == uintptr(0) && int32((*Pager)(unsafe.Pointer(pPager)).FjournalMode) == PAGER_JOURNALMODE_WAL {
		Xsqlite3_exec(tls, db, ts+6832, uintptr(0), uintptr(0), uintptr(0))
	}
	if (*Pager)(unsafe.Pointer(pPager)).FpWal != 0 {
		rc = Xsqlite3WalCheckpoint(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, db, eMode,
			func() uintptr {
				if eMode == SQLITE_CHECKPOINT_PASSIVE {
					return uintptr(0)
				}
				return (*Pager)(unsafe.Pointer(pPager)).FxBusyHandler
			}(),
			(*Pager)(unsafe.Pointer(pPager)).FpBusyHandlerArg,
			int32((*Pager)(unsafe.Pointer(pPager)).FwalSyncFlags), int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace,
			pnLog, pnCkpt)
	}
	return rc
}

func Xsqlite3PagerWalCallback(tls *libc.TLS, pPager uintptr) int32 {
	return Xsqlite3WalCallback(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal)
}

func Xsqlite3PagerWalSupported(tls *libc.TLS, pPager uintptr) int32 {
	var pMethods uintptr = (*Sqlite3_file)(unsafe.Pointer((*Pager)(unsafe.Pointer(pPager)).Ffd)).FpMethods
	if (*Pager)(unsafe.Pointer(pPager)).FnoLock != 0 {
		return 0
	}
	return libc.Bool32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 || (*Sqlite3_io_methods)(unsafe.Pointer(pMethods)).FiVersion >= 2 && (*Sqlite3_io_methods)(unsafe.Pointer(pMethods)).FxShmMap != 0)
}

func pagerExclusiveLock(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32

	rc = pagerLockDb(tls, pPager, EXCLUSIVE_LOCK)
	if rc != SQLITE_OK {
		pagerUnlockDb(tls, pPager, SHARED_LOCK)
	}

	return rc
}

func pagerOpenWal(tls *libc.TLS, pPager uintptr) int32 {
	var rc int32 = SQLITE_OK

	if (*Pager)(unsafe.Pointer(pPager)).FexclusiveMode != 0 {
		rc = pagerExclusiveLock(tls, pPager)
	}

	if rc == SQLITE_OK {
		rc = Xsqlite3WalOpen(tls, (*Pager)(unsafe.Pointer(pPager)).FpVfs,
			(*Pager)(unsafe.Pointer(pPager)).Ffd, (*Pager)(unsafe.Pointer(pPager)).FzWal, int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode),
			(*Pager)(unsafe.Pointer(pPager)).FjournalSizeLimit, pPager+304)
	}
	pagerFixMaplimit(tls, pPager)

	return rc
}

func Xsqlite3PagerOpenWal(tls *libc.TLS, pPager uintptr, pbOpen uintptr) int32 {
	var rc int32 = SQLITE_OK

	if !(int32((*Pager)(unsafe.Pointer(pPager)).FtempFile) != 0) && !(int32((*Pager)(unsafe.Pointer(pPager)).FpWal) != 0) {
		if !(Xsqlite3PagerWalSupported(tls, pPager) != 0) {
			return SQLITE_CANTOPEN
		}

		Xsqlite3OsClose(tls, (*Pager)(unsafe.Pointer(pPager)).Fjfd)

		rc = pagerOpenWal(tls, pPager)
		if rc == SQLITE_OK {
			(*Pager)(unsafe.Pointer(pPager)).FjournalMode = U8(PAGER_JOURNALMODE_WAL)
			(*Pager)(unsafe.Pointer(pPager)).FeState = U8(PAGER_OPEN)
		}
	} else {
		*(*int32)(unsafe.Pointer(pbOpen)) = 1
	}

	return rc
}

func Xsqlite3PagerCloseWal(tls *libc.TLS, pPager uintptr, db uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32 = SQLITE_OK

	if !(int32((*Pager)(unsafe.Pointer(pPager)).FpWal) != 0) {
		*(*int32)(unsafe.Pointer(bp)) = 0
		rc = pagerLockDb(tls, pPager, SHARED_LOCK)
		if rc == SQLITE_OK {
			rc = Xsqlite3OsAccess(tls,
				(*Pager)(unsafe.Pointer(pPager)).FpVfs, (*Pager)(unsafe.Pointer(pPager)).FzWal, SQLITE_ACCESS_EXISTS, bp)
		}
		if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) != 0 {
			rc = pagerOpenWal(tls, pPager)
		}
	}

	if rc == SQLITE_OK && (*Pager)(unsafe.Pointer(pPager)).FpWal != 0 {
		rc = pagerExclusiveLock(tls, pPager)
		if rc == SQLITE_OK {
			rc = Xsqlite3WalClose(tls, (*Pager)(unsafe.Pointer(pPager)).FpWal, db, int32((*Pager)(unsafe.Pointer(pPager)).FwalSyncFlags),
				int32((*Pager)(unsafe.Pointer(pPager)).FpageSize), (*Pager)(unsafe.Pointer(pPager)).FpTmpSpace)
			(*Pager)(unsafe.Pointer(pPager)).FpWal = uintptr(0)
			pagerFixMaplimit(tls, pPager)
			if rc != 0 && !(int32((*Pager)(unsafe.Pointer(pPager)).FexclusiveMode) != 0) {
				pagerUnlockDb(tls, pPager, SHARED_LOCK)
			}
		}
	}
	return rc
}

type WalIndexHdr1 = struct {
	FiVersion    U32
	Funused      U32
	FiChange     U32
	FisInit      U8
	FbigEndCksum U8
	FszPage      U16
	FmxFrame     U32
	FnPage       U32
	FaFrameCksum [2]U32
	FaSalt       [2]U32
	FaCksum      [2]U32
}

type WalIndexHdr = WalIndexHdr1
type WalIterator1 = struct {
	FiPrior   U32
	FnSegment int32
	FaSegment [1]struct {
		FiNext       int32
		F__ccgo_pad1 [4]byte
		FaIndex      uintptr
		FaPgno       uintptr
		FnEntry      int32
		FiZero       int32
	}
}

type WalIterator = WalIterator1
type WalCkptInfo1 = struct {
	FnBackfill          U32
	FaReadMark          [5]U32
	FaLock              [8]U8
	FnBackfillAttempted U32
	FnotUsed0           U32
}

type WalCkptInfo = WalCkptInfo1

type Ht_slot = U16

type WalSegment = struct {
	FiNext       int32
	F__ccgo_pad1 [4]byte
	FaIndex      uintptr
	FaPgno       uintptr
	FnEntry      int32
	FiZero       int32
}

func walIndexPageRealloc(tls *libc.TLS, pWal uintptr, iPage int32, ppPage uintptr) int32 {
	var rc int32 = SQLITE_OK

	if (*Wal)(unsafe.Pointer(pWal)).FnWiData <= iPage {
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(uintptr(0))) * uint64(iPage+1))
		var apNew uintptr
		libc.AtomicStoreUintptr(&apNew, Xsqlite3Realloc(tls, (*Wal)(unsafe.Pointer(pWal)).FapWiData, uint64(nByte)))
		if !(apNew != 0) {
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, apNew+uintptr((*Wal)(unsafe.Pointer(pWal)).FnWiData)*8, 0,
			uint64(unsafe.Sizeof(uintptr(0)))*uint64(iPage+1-(*Wal)(unsafe.Pointer(pWal)).FnWiData))
		(*Wal)(unsafe.Pointer(pWal)).FapWiData = apNew
		(*Wal)(unsafe.Pointer(pWal)).FnWiData = iPage + 1
	}

	if int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_HEAPMEMORY_MODE {
		*(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*8)) = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(Ht_slot(0)))*uint64(HASHTABLE_NPAGE*2)+uint64(HASHTABLE_NPAGE)*uint64(unsafe.Sizeof(U32(0))))
		if !(int32(*(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*8))) != 0) {
			rc = SQLITE_NOMEM
		}
	} else {
		rc = Xsqlite3OsShmMap(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, iPage, int32(uint64(unsafe.Sizeof(Ht_slot(0)))*uint64(HASHTABLE_NPAGE*2)+uint64(HASHTABLE_NPAGE)*uint64(unsafe.Sizeof(U32(0)))),
			int32((*Wal)(unsafe.Pointer(pWal)).FwriteLock), (*Wal)(unsafe.Pointer(pWal)).FapWiData+uintptr(iPage)*8)

		if rc == SQLITE_OK {
			if iPage > 0 && Xsqlite3FaultSim(tls, 600) != 0 {
				rc = SQLITE_NOMEM
			}
		} else if rc&0xff == SQLITE_READONLY {
			*(*U8)(unsafe.Pointer(pWal + 66)) |= U8(WAL_SHM_RDONLY)
			if rc == SQLITE_READONLY {
				rc = SQLITE_OK
			}
		}
	}

	*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*8))

	return rc
}

func walIndexPage(tls *libc.TLS, pWal uintptr, iPage int32, ppPage uintptr) int32 {
	if (*Wal)(unsafe.Pointer(pWal)).FnWiData <= iPage || libc.AssignPtrUintptr(ppPage, *(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*8))) == uintptr(0) {
		return walIndexPageRealloc(tls, pWal, iPage, ppPage)
	}
	return SQLITE_OK
}

func walCkptInfo(tls *libc.TLS, pWal uintptr) uintptr {
	return *(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData)) + 24*4
}

func walIndexHdr(tls *libc.TLS, pWal uintptr) uintptr {
	return *(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData))
}

func walChecksumBytes(tls *libc.TLS, nativeCksum int32, a uintptr, nByte int32, aIn uintptr, aOut uintptr) {
	var s1 U32
	var s2 U32
	var aData uintptr = a
	var aEnd uintptr = a + uintptr(nByte)

	if aIn != 0 {
		s1 = *(*U32)(unsafe.Pointer(aIn))
		s2 = *(*U32)(unsafe.Pointer(aIn + 1*4))
	} else {
		s1 = libc.AssignUint32(&s2, U32(0))
	}

	if nativeCksum != 0 {
		for __ccgo := true; __ccgo; __ccgo = aData < aEnd {
			s1 = s1 + (*(*U32)(unsafe.Pointer(libc.PostIncUintptr(&aData, 4))) + s2)
			s2 = s2 + (*(*U32)(unsafe.Pointer(libc.PostIncUintptr(&aData, 4))) + s1)
		}
	} else {
		for __ccgo1 := true; __ccgo1; __ccgo1 = aData < aEnd {
			s1 = s1 + (*(*U32)(unsafe.Pointer(aData))&U32(0x000000FF)<<24 + *(*U32)(unsafe.Pointer(aData))&U32(0x0000FF00)<<8 + *(*U32)(unsafe.Pointer(aData))&U32(0x00FF0000)>>8 + *(*U32)(unsafe.Pointer(aData))&0xFF000000>>24 + s2)
			s2 = s2 + (*(*U32)(unsafe.Pointer(aData + 1*4))&U32(0x000000FF)<<24 + *(*U32)(unsafe.Pointer(aData + 1*4))&U32(0x0000FF00)<<8 + *(*U32)(unsafe.Pointer(aData + 1*4))&U32(0x00FF0000)>>8 + *(*U32)(unsafe.Pointer(aData + 1*4))&0xFF000000>>24 + s1)
			aData += 4 * uintptr(2)
		}
	}

	*(*U32)(unsafe.Pointer(aOut)) = s1
	*(*U32)(unsafe.Pointer(aOut + 1*4)) = s2
}

func walShmBarrier(tls *libc.TLS, pWal uintptr) {
	if int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) != WAL_HEAPMEMORY_MODE {
		Xsqlite3OsShmBarrier(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd)
	}
}

func walIndexWriteHdr(tls *libc.TLS, pWal uintptr) {
	var aHdr uintptr = walIndexHdr(tls, pWal)
	var nCksum int32 = int32(uintptr(0) + 40)

	(*Wal)(unsafe.Pointer(pWal)).Fhdr.FisInit = U8(1)
	(*Wal)(unsafe.Pointer(pWal)).Fhdr.FiVersion = U32(WALINDEX_MAX_VERSION)
	walChecksumBytes(tls, 1, pWal+72, nCksum, uintptr(0), pWal+72+40)

	libc.Xmemcpy(tls, aHdr+1*48, pWal+72, uint64(unsafe.Sizeof(WalIndexHdr{})))
	walShmBarrier(tls, pWal)
	libc.Xmemcpy(tls, aHdr, pWal+72, uint64(unsafe.Sizeof(WalIndexHdr{})))
}

func walEncodeFrame(tls *libc.TLS, pWal uintptr, iPage U32, nTruncate U32, aData uintptr, aFrame uintptr) {
	var nativeCksum int32
	var aCksum uintptr = pWal + 72 + 24

	Xsqlite3Put4byte(tls, aFrame, iPage)
	Xsqlite3Put4byte(tls, aFrame+4, nTruncate)
	if (*Wal)(unsafe.Pointer(pWal)).FiReCksum == U32(0) {
		libc.Xmemcpy(tls, aFrame+8, pWal+72+32, uint64(8))

		nativeCksum = libc.Bool32(int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == SQLITE_BIGENDIAN)
		walChecksumBytes(tls, nativeCksum, aFrame, 8, aCksum, aCksum)
		walChecksumBytes(tls, nativeCksum, aData, int32((*Wal)(unsafe.Pointer(pWal)).FszPage), aCksum, aCksum)

		Xsqlite3Put4byte(tls, aFrame+16, *(*U32)(unsafe.Pointer(aCksum)))
		Xsqlite3Put4byte(tls, aFrame+20, *(*U32)(unsafe.Pointer(aCksum + 1*4)))
	} else {
		libc.Xmemset(tls, aFrame+8, 0, uint64(16))
	}
}

func walDecodeFrame(tls *libc.TLS, pWal uintptr, piPage uintptr, pnTruncate uintptr, aData uintptr, aFrame uintptr) int32 {
	var nativeCksum int32
	var aCksum uintptr = pWal + 72 + 24
	var pgno U32

	if libc.Xmemcmp(tls, pWal+72+32, aFrame+8, uint64(8)) != 0 {
		return 0
	}

	pgno = Xsqlite3Get4byte(tls, aFrame)
	if pgno == U32(0) {
		return 0
	}

	nativeCksum = libc.Bool32(int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == SQLITE_BIGENDIAN)
	walChecksumBytes(tls, nativeCksum, aFrame, 8, aCksum, aCksum)
	walChecksumBytes(tls, nativeCksum, aData, int32((*Wal)(unsafe.Pointer(pWal)).FszPage), aCksum, aCksum)
	if *(*U32)(unsafe.Pointer(aCksum)) != Xsqlite3Get4byte(tls, aFrame+16) ||
		*(*U32)(unsafe.Pointer(aCksum + 1*4)) != Xsqlite3Get4byte(tls, aFrame+20) {
		return 0
	}

	*(*U32)(unsafe.Pointer(piPage)) = pgno
	*(*U32)(unsafe.Pointer(pnTruncate)) = Xsqlite3Get4byte(tls, aFrame+4)
	return 1
}

func walLockShared(tls *libc.TLS, pWal uintptr, lockIdx int32) int32 {
	var rc int32
	if (*Wal)(unsafe.Pointer(pWal)).FexclusiveMode != 0 {
		return SQLITE_OK
	}
	rc = Xsqlite3OsShmLock(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, lockIdx, 1,
		SQLITE_SHM_LOCK|SQLITE_SHM_SHARED)

	return rc
}

func walUnlockShared(tls *libc.TLS, pWal uintptr, lockIdx int32) {
	if (*Wal)(unsafe.Pointer(pWal)).FexclusiveMode != 0 {
		return
	}
	Xsqlite3OsShmLock(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, lockIdx, 1,
		SQLITE_SHM_UNLOCK|SQLITE_SHM_SHARED)

}

func walLockExclusive(tls *libc.TLS, pWal uintptr, lockIdx int32, n int32) int32 {
	var rc int32
	if (*Wal)(unsafe.Pointer(pWal)).FexclusiveMode != 0 {
		return SQLITE_OK
	}
	rc = Xsqlite3OsShmLock(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, lockIdx, n,
		SQLITE_SHM_LOCK|SQLITE_SHM_EXCLUSIVE)

	return rc
}

func walUnlockExclusive(tls *libc.TLS, pWal uintptr, lockIdx int32, n int32) {
	if (*Wal)(unsafe.Pointer(pWal)).FexclusiveMode != 0 {
		return
	}
	Xsqlite3OsShmLock(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, lockIdx, n,
		SQLITE_SHM_UNLOCK|SQLITE_SHM_EXCLUSIVE)

}

func walHash(tls *libc.TLS, iPage U32) int32 {
	return int32(iPage * U32(HASHTABLE_HASH_1) & U32(HASHTABLE_NPAGE*2-1))
}

func walNextHash(tls *libc.TLS, iPriorHash int32) int32 {
	return (iPriorHash + 1) & (HASHTABLE_NPAGE*2 - 1)
}

type WalHashLoc1 = struct {
	FaHash       uintptr
	FaPgno       uintptr
	FiZero       U32
	F__ccgo_pad1 [4]byte
}

type WalHashLoc = WalHashLoc1

func walHashGet(tls *libc.TLS, pWal uintptr, iHash int32, pLoc uintptr) int32 {
	var rc int32

	rc = walIndexPage(tls, pWal, iHash, pLoc+8)

	if (*WalHashLoc)(unsafe.Pointer(pLoc)).FaPgno != 0 {
		(*WalHashLoc)(unsafe.Pointer(pLoc)).FaHash = (*WalHashLoc)(unsafe.Pointer(pLoc)).FaPgno + 4096*4
		if iHash == 0 {
			(*WalHashLoc)(unsafe.Pointer(pLoc)).FaPgno = (*WalHashLoc)(unsafe.Pointer(pLoc)).FaPgno + 34*4
			(*WalHashLoc)(unsafe.Pointer(pLoc)).FiZero = U32(0)
		} else {
			(*WalHashLoc)(unsafe.Pointer(pLoc)).FiZero = U32(uint64(HASHTABLE_NPAGE) - (uint64(unsafe.Sizeof(WalIndexHdr{}))*uint64(2)+uint64(unsafe.Sizeof(WalCkptInfo{})))/uint64(unsafe.Sizeof(U32(0))) + uint64((iHash-1)*HASHTABLE_NPAGE))
		}
	} else if rc == SQLITE_OK {
		rc = SQLITE_ERROR
	}
	return rc
}

func walFramePage(tls *libc.TLS, iFrame U32) int32 {
	var iHash int32 = int32((uint64(iFrame+U32(HASHTABLE_NPAGE)) - (uint64(HASHTABLE_NPAGE) - (uint64(unsafe.Sizeof(WalIndexHdr{}))*uint64(2)+uint64(unsafe.Sizeof(WalCkptInfo{})))/uint64(unsafe.Sizeof(U32(0)))) - uint64(1)) / uint64(HASHTABLE_NPAGE))

	return iHash
}

func walFramePgno(tls *libc.TLS, pWal uintptr, iFrame U32) U32 {
	var iHash int32 = walFramePage(tls, iFrame)
	if iHash == 0 {
		return *(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData)) + uintptr((uint64(unsafe.Sizeof(WalIndexHdr{}))*uint64(2)+uint64(unsafe.Sizeof(WalCkptInfo{})))/uint64(unsafe.Sizeof(U32(0)))+uint64(iFrame)-uint64(1))*4))
	}
	return *(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iHash)*8)) + uintptr((uint64(iFrame-U32(1))-(uint64(HASHTABLE_NPAGE)-(uint64(unsafe.Sizeof(WalIndexHdr{}))*uint64(2)+uint64(unsafe.Sizeof(WalCkptInfo{})))/uint64(unsafe.Sizeof(U32(0)))))%uint64(HASHTABLE_NPAGE))*4))
}

func walCleanupHash(tls *libc.TLS, pWal uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var iLimit int32 = 0
	var nByte int32
	var i int32

	if (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame == U32(0) {
		return
	}

	i = walHashGet(tls, pWal, walFramePage(tls, (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame), bp)
	if i != 0 {
		return
	}

	iLimit = int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame - (*WalHashLoc)(unsafe.Pointer(bp)).FiZero)

	for i = 0; i < HASHTABLE_NPAGE*2; i++ {
		if int32(*(*Ht_slot)(unsafe.Pointer((*WalHashLoc)(unsafe.Pointer(bp)).FaHash + uintptr(i)*2))) > iLimit {
			*(*Ht_slot)(unsafe.Pointer((*WalHashLoc)(unsafe.Pointer(bp)).FaHash + uintptr(i)*2)) = Ht_slot(0)
		}
	}

	nByte = int32((int64((*WalHashLoc)(unsafe.Pointer(bp)).FaHash) - int64((*WalHashLoc)(unsafe.Pointer(bp)).FaPgno+uintptr(iLimit)*4)) / 1)

	libc.Xmemset(tls, (*WalHashLoc)(unsafe.Pointer(bp)).FaPgno+uintptr(iLimit)*4, 0, uint64(nByte))

}

func walIndexAppend(tls *libc.TLS, pWal uintptr, iFrame U32, iPage U32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32

	rc = walHashGet(tls, pWal, walFramePage(tls, iFrame), bp)

	if rc == SQLITE_OK {
		var iKey int32
		var idx int32
		var nCollide int32

		idx = int32(iFrame - (*WalHashLoc)(unsafe.Pointer(bp)).FiZero)

		if idx == 1 {
			var nByte int32 = int32((int64((*WalHashLoc)(unsafe.Pointer(bp)).FaHash+8192*2) - int64((*WalHashLoc)(unsafe.Pointer(bp)).FaPgno)) / 1)

			libc.Xmemset(tls, (*WalHashLoc)(unsafe.Pointer(bp)).FaPgno, 0, uint64(nByte))
		}

		if *(*U32)(unsafe.Pointer((*WalHashLoc)(unsafe.Pointer(bp)).FaPgno + uintptr(idx-1)*4)) != 0 {
			walCleanupHash(tls, pWal)

		}

		nCollide = idx
		for iKey = walHash(tls, iPage); *(*Ht_slot)(unsafe.Pointer((*WalHashLoc)(unsafe.Pointer(bp)).FaHash + uintptr(iKey)*2)) != 0; iKey = walNextHash(tls, iKey) {
			if libc.PostDecInt32(&nCollide, 1) == 0 {
				return Xsqlite3CorruptError(tls, 64391)
			}
		}
		*(*U32)(unsafe.Pointer((*WalHashLoc)(unsafe.Pointer(bp)).FaPgno + uintptr(idx-1)*4)) = iPage
		libc.AtomicStoreNUint16((*WalHashLoc)(unsafe.Pointer(bp)).FaHash+uintptr(iKey)*2, Ht_slot(idx), 0)

	}

	return rc
}

func walIndexRecover(tls *libc.TLS, pWal uintptr) int32 {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var rc int32

	var iLock int32
	var iOffset I64

	var iFrame U32
	var iLast U32
	var iFirst U32
	var nHdr U32
	var nHdr32 U32

	var aPrivate uintptr
	var aFrame uintptr
	var szFrame int32
	var aData uintptr
	var szPage int32
	var magic U32
	var version U32
	var isValid int32
	var iPg U32
	var iLastFrame U32
	var pInfo uintptr
	var i int32
	*(*[2]U32)(unsafe.Pointer(bp + 72)) = [2]U32{U32(0), U32(0)}

	iLock = WAL_ALL_BUT_WRITE + int32((*Wal)(unsafe.Pointer(pWal)).FckptLock)
	rc = walLockExclusive(tls, pWal, iLock, 3+0-iLock)
	if !(rc != 0) {
		goto __1
	}
	return rc
__1:
	;
	libc.Xmemset(tls, pWal+72, 0, uint64(unsafe.Sizeof(WalIndexHdr{})))

	rc = Xsqlite3OsFileSize(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, bp+16)
	if !(rc != SQLITE_OK) {
		goto __2
	}
	goto recovery_error
__2:
	;
	if !(*(*I64)(unsafe.Pointer(bp + 16)) > int64(WAL_HDRSIZE)) {
		goto __3
	}
	aPrivate = uintptr(0)
	aFrame = uintptr(0)

	rc = Xsqlite3OsRead(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, bp+24, WAL_HDRSIZE, int64(0))
	if !(rc != SQLITE_OK) {
		goto __4
	}
	goto recovery_error
__4:
	;
	magic = Xsqlite3Get4byte(tls, bp+24)
	szPage = int32(Xsqlite3Get4byte(tls, bp+24+8))
	if !(magic&0xFFFFFFFE != U32(WAL_MAGIC) ||
		szPage&(szPage-1) != 0 ||
		szPage > SQLITE_MAX_PAGE_SIZE ||
		szPage < 512) {
		goto __5
	}
	goto finished
__5:
	;
	(*Wal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum = U8(magic & U32(0x00000001))
	(*Wal)(unsafe.Pointer(pWal)).FszPage = U32(szPage)
	(*Wal)(unsafe.Pointer(pWal)).FnCkpt = Xsqlite3Get4byte(tls, bp+24+12)
	libc.Xmemcpy(tls, pWal+72+32, bp+24+16, uint64(8))

	walChecksumBytes(tls, libc.Bool32(int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum) == SQLITE_BIGENDIAN),
		bp+24, WAL_HDRSIZE-2*4, uintptr(0), pWal+72+24)
	if !(*(*U32)(unsafe.Pointer(pWal + 72 + 24)) != Xsqlite3Get4byte(tls, bp+24+24) ||
		*(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4)) != Xsqlite3Get4byte(tls, bp+24+28)) {
		goto __6
	}
	goto finished
__6:
	;
	version = Xsqlite3Get4byte(tls, bp+24+4)
	if !(version != U32(WAL_MAX_VERSION)) {
		goto __7
	}
	rc = Xsqlite3CantopenError(tls, 64523)
	goto finished
__7:
	;
	szFrame = szPage + WAL_FRAME_HDRSIZE
	aFrame = Xsqlite3_malloc64(tls, uint64(szFrame)+(uint64(unsafe.Sizeof(Ht_slot(0)))*uint64(HASHTABLE_NPAGE*2)+uint64(HASHTABLE_NPAGE)*uint64(unsafe.Sizeof(U32(0)))))
	if !!(aFrame != 0) {
		goto __8
	}
	rc = SQLITE_NOMEM
	goto recovery_error
__8:
	;
	aData = aFrame + 24
	aPrivate = aData + uintptr(szPage)

	iLastFrame = U32((*(*I64)(unsafe.Pointer(bp + 16)) - int64(WAL_HDRSIZE)) / I64(szFrame))
	iPg = U32(0)
__9:
	if !(iPg <= U32(walFramePage(tls, iLastFrame))) {
		goto __11
	}
	iLast = func() uint32 {
		if uint64(iLastFrame) < uint64(HASHTABLE_NPAGE)-(uint64(unsafe.Sizeof(WalIndexHdr{}))*uint64(2)+uint64(unsafe.Sizeof(WalCkptInfo{})))/uint64(unsafe.Sizeof(U32(0)))+uint64(iPg*U32(HASHTABLE_NPAGE)) {
			return iLastFrame
		}
		return uint32(uint64(HASHTABLE_NPAGE) - (uint64(unsafe.Sizeof(WalIndexHdr{}))*uint64(2)+uint64(unsafe.Sizeof(WalCkptInfo{})))/uint64(unsafe.Sizeof(U32(0))) + uint64(iPg*U32(HASHTABLE_NPAGE)))
	}()
	iFirst = U32(uint64(1) + func() uint64 {
		if iPg == U32(0) {
			return uint64(0)
		}
		return uint64(HASHTABLE_NPAGE) - (uint64(unsafe.Sizeof(WalIndexHdr{}))*uint64(2)+uint64(unsafe.Sizeof(WalCkptInfo{})))/uint64(unsafe.Sizeof(U32(0))) + uint64((iPg-U32(1))*U32(HASHTABLE_NPAGE))
	}())
	rc = walIndexPage(tls, pWal, int32(iPg), bp+56)

	if !(*(*uintptr)(unsafe.Pointer(bp + 56)) == uintptr(0)) {
		goto __12
	}
	goto __11
__12:
	;
	*(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPg)*8)) = aPrivate

	iFrame = iFirst
__13:
	if !(iFrame <= iLast) {
		goto __15
	}
	iOffset = int64(WAL_HDRSIZE) + I64(iFrame-U32(1))*I64(szPage+WAL_FRAME_HDRSIZE)

	rc = Xsqlite3OsRead(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, aFrame, szFrame, iOffset)
	if !(rc != SQLITE_OK) {
		goto __16
	}
	goto __15
__16:
	;
	isValid = walDecodeFrame(tls, pWal, bp+64, bp+68, aData, aFrame)
	if !!(isValid != 0) {
		goto __17
	}
	goto __15
__17:
	;
	rc = walIndexAppend(tls, pWal, iFrame, *(*U32)(unsafe.Pointer(bp + 64)))
	if !(rc != SQLITE_OK) {
		goto __18
	}
	goto __15
__18:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 68)) != 0) {
		goto __19
	}
	(*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = iFrame
	(*Wal)(unsafe.Pointer(pWal)).Fhdr.FnPage = *(*U32)(unsafe.Pointer(bp + 68))
	(*Wal)(unsafe.Pointer(pWal)).Fhdr.FszPage = U16(szPage&0xff00 | szPage>>16)

	*(*U32)(unsafe.Pointer(bp + 72)) = *(*U32)(unsafe.Pointer(pWal + 72 + 24))
	*(*U32)(unsafe.Pointer(bp + 72 + 1*4)) = *(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4))
__19:
	;
	goto __14
__14:
	iFrame++
	goto __13
	goto __15
__15:
	;
	*(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPg)*8)) = *(*uintptr)(unsafe.Pointer(bp + 56))
	nHdr = func() uint32 {
		if iPg == U32(0) {
			return uint32(uint64(unsafe.Sizeof(WalIndexHdr{}))*uint64(2) + uint64(unsafe.Sizeof(WalCkptInfo{})))
		}
		return uint32(0)
	}()
	nHdr32 = U32(uint64(nHdr) / uint64(unsafe.Sizeof(U32(0))))

	libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp + 56))+uintptr(nHdr32)*4, aPrivate+uintptr(nHdr32)*4, uint64(unsafe.Sizeof(Ht_slot(0)))*uint64(HASHTABLE_NPAGE*2)+uint64(HASHTABLE_NPAGE)*uint64(unsafe.Sizeof(U32(0)))-uint64(nHdr))
	if !(iFrame <= iLast) {
		goto __20
	}
	goto __11
__20:
	;
	goto __10
__10:
	iPg++
	goto __9
	goto __11
__11:
	;
	Xsqlite3_free(tls, aFrame)
__3:
	;
finished:
	if !(rc == SQLITE_OK) {
		goto __21
	}
	*(*U32)(unsafe.Pointer(pWal + 72 + 24)) = *(*U32)(unsafe.Pointer(bp + 72))
	*(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4)) = *(*U32)(unsafe.Pointer(bp + 72 + 1*4))
	walIndexWriteHdr(tls, pWal)

	libc.AtomicStoreUintptr(&pInfo, walCkptInfo(tls, pWal))
	(*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill = U32(0)
	(*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	*(*U32)(unsafe.Pointer(pInfo + 4)) = U32(0)
	i = 1
__22:
	if !(i < SQLITE_SHM_NLOCK-3) {
		goto __24
	}
	rc = walLockExclusive(tls, pWal, 3+i, 1)
	if !(rc == SQLITE_OK) {
		goto __25
	}
	if !(i == 1 && (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame != 0) {
		goto __27
	}
	*(*U32)(unsafe.Pointer(pInfo + 4 + uintptr(i)*4)) = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	goto __28
__27:
	*(*U32)(unsafe.Pointer(pInfo + 4 + uintptr(i)*4)) = READMARK_NOT_USED
__28:
	;
	walUnlockExclusive(tls, pWal, 3+i, 1)
	goto __26
__25:
	if !(rc != SQLITE_BUSY) {
		goto __29
	}
	goto recovery_error
__29:
	;
__26:
	;
	goto __23
__23:
	i++
	goto __22
	goto __24
__24:
	;
	if !((*Wal)(unsafe.Pointer(pWal)).Fhdr.FnPage != 0) {
		goto __30
	}
	Xsqlite3_log(tls, SQLITE_NOTICE|int32(1)<<8,
		ts+6850,
		libc.VaList(bp, (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame, (*Wal)(unsafe.Pointer(pWal)).FzWalName))
__30:
	;
__21:
	;
recovery_error:
	;
	walUnlockExclusive(tls, pWal, iLock, 3+0-iLock)
	return rc
}

func walIndexClose(tls *libc.TLS, pWal uintptr, isDelete int32) {
	if int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_HEAPMEMORY_MODE || (*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable != 0 {
		var i int32
		for i = 0; i < (*Wal)(unsafe.Pointer(pWal)).FnWiData; i++ {
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(i)*8)))
			*(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(i)*8)) = uintptr(0)
		}
	}
	if int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) != WAL_HEAPMEMORY_MODE {
		Xsqlite3OsShmUnmap(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, isDelete)
	}
}

func Xsqlite3WalOpen(tls *libc.TLS, pVfs uintptr, pDbFd uintptr, zWalName uintptr, bNoShm int32, mxWalSize I64, ppWal uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32
	var pRet uintptr

	*(*uintptr)(unsafe.Pointer(ppWal)) = uintptr(0)
	pRet = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(Wal{}))+uint64((*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile))
	if !(pRet != 0) {
		return SQLITE_NOMEM
	}

	(*Wal)(unsafe.Pointer(pRet)).FpVfs = pVfs
	(*Wal)(unsafe.Pointer(pRet)).FpWalFd = pRet + 1*144
	(*Wal)(unsafe.Pointer(pRet)).FpDbFd = pDbFd
	(*Wal)(unsafe.Pointer(pRet)).FreadLock = int16(-1)
	(*Wal)(unsafe.Pointer(pRet)).FmxWalSize = mxWalSize
	(*Wal)(unsafe.Pointer(pRet)).FzWalName = zWalName
	(*Wal)(unsafe.Pointer(pRet)).FsyncHeader = U8(1)
	(*Wal)(unsafe.Pointer(pRet)).FpadToSectorBoundary = U8(1)
	(*Wal)(unsafe.Pointer(pRet)).FexclusiveMode = func() uint8 {
		if bNoShm != 0 {
			return uint8(WAL_HEAPMEMORY_MODE)
		}
		return uint8(WAL_NORMAL_MODE)
	}()

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_WAL
	rc = Xsqlite3OsOpen(tls, pVfs, zWalName, (*Wal)(unsafe.Pointer(pRet)).FpWalFd, *(*int32)(unsafe.Pointer(bp)), bp)
	if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp))&SQLITE_OPEN_READONLY != 0 {
		(*Wal)(unsafe.Pointer(pRet)).FreadOnly = U8(WAL_RDONLY)
	}

	if rc != SQLITE_OK {
		walIndexClose(tls, pRet, 0)
		Xsqlite3OsClose(tls, (*Wal)(unsafe.Pointer(pRet)).FpWalFd)
		Xsqlite3_free(tls, pRet)
	} else {
		var iDC int32 = Xsqlite3OsDeviceCharacteristics(tls, pDbFd)
		if iDC&SQLITE_IOCAP_SEQUENTIAL != 0 {
			(*Wal)(unsafe.Pointer(pRet)).FsyncHeader = U8(0)
		}
		if iDC&SQLITE_IOCAP_POWERSAFE_OVERWRITE != 0 {
			(*Wal)(unsafe.Pointer(pRet)).FpadToSectorBoundary = U8(0)
		}
		*(*uintptr)(unsafe.Pointer(ppWal)) = pRet

	}
	return rc
}

func Xsqlite3WalLimit(tls *libc.TLS, pWal uintptr, iLimit I64) {
	if pWal != 0 {
		(*Wal)(unsafe.Pointer(pWal)).FmxWalSize = iLimit
	}
}

func walIteratorNext(tls *libc.TLS, p uintptr, piPage uintptr, piFrame uintptr) int32 {
	var iMin U32
	var iRet U32 = 0xFFFFFFFF
	var i int32

	iMin = (*WalIterator)(unsafe.Pointer(p)).FiPrior

	for i = (*WalIterator)(unsafe.Pointer(p)).FnSegment - 1; i >= 0; i-- {
		var pSegment uintptr = p + 8 + uintptr(i)*32
		for (*WalSegment)(unsafe.Pointer(pSegment)).FiNext < (*WalSegment)(unsafe.Pointer(pSegment)).FnEntry {
			var iPg U32 = *(*U32)(unsafe.Pointer((*WalSegment)(unsafe.Pointer(pSegment)).FaPgno + uintptr(*(*Ht_slot)(unsafe.Pointer((*WalSegment)(unsafe.Pointer(pSegment)).FaIndex + uintptr((*WalSegment)(unsafe.Pointer(pSegment)).FiNext)*2)))*4))
			if iPg > iMin {
				if iPg < iRet {
					iRet = iPg
					*(*U32)(unsafe.Pointer(piFrame)) = U32((*WalSegment)(unsafe.Pointer(pSegment)).FiZero + int32(*(*Ht_slot)(unsafe.Pointer((*WalSegment)(unsafe.Pointer(pSegment)).FaIndex + uintptr((*WalSegment)(unsafe.Pointer(pSegment)).FiNext)*2))))
				}
				break
			}
			(*WalSegment)(unsafe.Pointer(pSegment)).FiNext++
		}
	}

	*(*U32)(unsafe.Pointer(piPage)) = libc.AssignPtrUint32(p, iRet)
	return libc.Bool32(iRet == 0xFFFFFFFF)
}

func walMerge(tls *libc.TLS, aContent uintptr, aLeft uintptr, nLeft int32, paRight uintptr, pnRight uintptr, aTmp uintptr) {
	var iLeft int32 = 0
	var iRight int32 = 0
	var iOut int32 = 0
	var nRight int32 = *(*int32)(unsafe.Pointer(pnRight))
	var aRight uintptr = *(*uintptr)(unsafe.Pointer(paRight))

	for iRight < nRight || iLeft < nLeft {
		var logpage Ht_slot
		var dbpage Pgno

		if iLeft < nLeft &&
			(iRight >= nRight || *(*U32)(unsafe.Pointer(aContent + uintptr(*(*Ht_slot)(unsafe.Pointer(aLeft + uintptr(iLeft)*2)))*4)) < *(*U32)(unsafe.Pointer(aContent + uintptr(*(*Ht_slot)(unsafe.Pointer(aRight + uintptr(iRight)*2)))*4))) {
			logpage = *(*Ht_slot)(unsafe.Pointer(aLeft + uintptr(libc.PostIncInt32(&iLeft, 1))*2))
		} else {
			logpage = *(*Ht_slot)(unsafe.Pointer(aRight + uintptr(libc.PostIncInt32(&iRight, 1))*2))
		}
		dbpage = *(*U32)(unsafe.Pointer(aContent + uintptr(logpage)*4))

		*(*Ht_slot)(unsafe.Pointer(aTmp + uintptr(libc.PostIncInt32(&iOut, 1))*2)) = logpage
		if iLeft < nLeft && *(*U32)(unsafe.Pointer(aContent + uintptr(*(*Ht_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, uint64(unsafe.Sizeof(Ht_slot(0)))*uint64(iOut))
}

func walMergesort(tls *libc.TLS, aContent uintptr, aBuffer uintptr, aList uintptr, pnList uintptr) {
	bp := tls.Alloc(220)
	defer tls.Free(220)

	var nList int32 = *(*int32)(unsafe.Pointer(pnList))
	*(*int32)(unsafe.Pointer(bp + 216)) = 0
	*(*uintptr)(unsafe.Pointer(bp + 208)) = uintptr(0)
	var iList int32
	var iSub U32 = U32(0)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([13]Sublist{})))

	for iList = 0; iList < nList; iList++ {
		*(*int32)(unsafe.Pointer(bp + 216)) = 1
		*(*uintptr)(unsafe.Pointer(bp + 208)) = aList + uintptr(iList)*2
		for iSub = U32(0); iList&(int32(1)<<iSub) != 0; iSub++ {
			var p uintptr

			p = bp + uintptr(iSub)*16

			walMerge(tls, aContent, (*Sublist)(unsafe.Pointer(p)).FaList, (*Sublist)(unsafe.Pointer(p)).FnList, bp+208, bp+216, aBuffer)
		}
		(*Sublist)(unsafe.Pointer(bp + uintptr(iSub)*16)).FaList = *(*uintptr)(unsafe.Pointer(bp + 208))
		(*Sublist)(unsafe.Pointer(bp + uintptr(iSub)*16)).FnList = *(*int32)(unsafe.Pointer(bp + 216))
	}

	for iSub++; iSub < U32(int32(uint64(unsafe.Sizeof([13]Sublist{}))/uint64(unsafe.Sizeof(Sublist{})))); iSub++ {
		if nList&(int32(1)<<iSub) != 0 {
			var p uintptr

			p = bp + uintptr(iSub)*16

			walMerge(tls, aContent, (*Sublist)(unsafe.Pointer(p)).FaList, (*Sublist)(unsafe.Pointer(p)).FnList, bp+208, bp+216, aBuffer)
		}
	}

	*(*int32)(unsafe.Pointer(pnList)) = *(*int32)(unsafe.Pointer(bp + 216))

}

type Sublist = struct {
	FnList       int32
	F__ccgo_pad1 [4]byte
	FaList       uintptr
}

func walIteratorFree(tls *libc.TLS, p uintptr) {
	Xsqlite3_free(tls, p)
}

func walIteratorInit(tls *libc.TLS, pWal uintptr, nBackfill U32, pp uintptr) int32 {
	bp := tls.Alloc(28)
	defer tls.Free(28)

	var p uintptr
	var nSegment int32
	var iLast U32
	var nByte Sqlite3_int64
	var i int32
	var aTmp uintptr
	var rc int32 = SQLITE_OK

	iLast = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame

	nSegment = walFramePage(tls, iLast) + 1
	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(WalIterator{})) +
		uint64(nSegment-1)*uint64(unsafe.Sizeof(WalSegment{})) +
		uint64(iLast)*uint64(unsafe.Sizeof(Ht_slot(0))))
	p = Xsqlite3_malloc64(tls, uint64(nByte))
	if !(p != 0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, p, 0, uint64(nByte))
	(*WalIterator)(unsafe.Pointer(p)).FnSegment = nSegment

	aTmp = Xsqlite3_malloc64(tls,
		uint64(unsafe.Sizeof(Ht_slot(0)))*func() uint64 {
			if iLast > U32(HASHTABLE_NPAGE) {
				return uint64(HASHTABLE_NPAGE)
			}
			return uint64(iLast)
		}())
	if !(aTmp != 0) {
		rc = SQLITE_NOMEM
	}

	for i = walFramePage(tls, nBackfill+U32(1)); rc == SQLITE_OK && i < nSegment; i++ {
		rc = walHashGet(tls, pWal, i, bp)
		if rc == SQLITE_OK {
			var j int32

			var aIndex uintptr

			if i+1 == nSegment {
				*(*int32)(unsafe.Pointer(bp + 24)) = int32(iLast - (*WalHashLoc)(unsafe.Pointer(bp)).FiZero)
			} else {
				*(*int32)(unsafe.Pointer(bp + 24)) = int32((int64((*WalHashLoc)(unsafe.Pointer(bp)).FaHash) - int64((*WalHashLoc)(unsafe.Pointer(bp)).FaPgno)) / 4)
			}
			aIndex = p + 8 + uintptr((*WalIterator)(unsafe.Pointer(p)).FnSegment)*32 + uintptr((*WalHashLoc)(unsafe.Pointer(bp)).FiZero)*2
			(*WalHashLoc)(unsafe.Pointer(bp)).FiZero++

			for j = 0; j < *(*int32)(unsafe.Pointer(bp + 24)); j++ {
				*(*Ht_slot)(unsafe.Pointer(aIndex + uintptr(j)*2)) = Ht_slot(j)
			}
			walMergesort(tls, (*WalHashLoc)(unsafe.Pointer(bp)).FaPgno, aTmp, aIndex, bp+24)
			(*WalSegment)(unsafe.Pointer(p + 8 + uintptr(i)*32)).FiZero = int32((*WalHashLoc)(unsafe.Pointer(bp)).FiZero)
			(*WalSegment)(unsafe.Pointer(p + 8 + uintptr(i)*32)).FnEntry = *(*int32)(unsafe.Pointer(bp + 24))
			(*WalSegment)(unsafe.Pointer(p + 8 + uintptr(i)*32)).FaIndex = aIndex
			(*WalSegment)(unsafe.Pointer(p + 8 + uintptr(i)*32)).FaPgno = (*WalHashLoc)(unsafe.Pointer(bp)).FaPgno
		}
	}
	Xsqlite3_free(tls, aTmp)

	if rc != SQLITE_OK {
		walIteratorFree(tls, p)
		p = uintptr(0)
	}
	*(*uintptr)(unsafe.Pointer(pp)) = p
	return rc
}

func walBusyLock(tls *libc.TLS, pWal uintptr, xBusy uintptr, pBusyArg uintptr, lockIdx int32, n int32) int32 {
	var rc int32
	for __ccgo := true; __ccgo; __ccgo = xBusy != 0 && rc == SQLITE_BUSY && (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{xBusy})).f(tls, pBusyArg) != 0 {
		rc = walLockExclusive(tls, pWal, lockIdx, n)
	}
	return rc
}

func walPagesize(tls *libc.TLS, pWal uintptr) int32 {
	return int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FszPage)&0xfe00 + int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FszPage)&0x0001<<16
}

func walRestartHdr(tls *libc.TLS, pWal uintptr, salt1 U32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)
	*(*U32)(unsafe.Pointer(bp)) = salt1

	var pInfo uintptr = walCkptInfo(tls, pWal)
	var i int32
	var aSalt uintptr = pWal + 72 + 32
	(*Wal)(unsafe.Pointer(pWal)).FnCkpt++
	(*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = U32(0)
	Xsqlite3Put4byte(tls, aSalt, U32(1)+Xsqlite3Get4byte(tls, aSalt))
	libc.Xmemcpy(tls, pWal+72+32+1*4, bp, uint64(4))
	walIndexWriteHdr(tls, pWal)
	libc.AtomicStoreNInt32(pInfo, int32(0), 0)
	(*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted = U32(0)
	*(*U32)(unsafe.Pointer(pInfo + 4 + 1*4)) = U32(0)
	for i = 2; i < SQLITE_SHM_NLOCK-3; i++ {
		*(*U32)(unsafe.Pointer(pInfo + 4 + uintptr(i)*4)) = READMARK_NOT_USED
	}

}

func walCheckpoint(tls *libc.TLS, pWal uintptr, db uintptr, eMode int32, xBusy uintptr, pBusyArg uintptr, sync_flags int32, zBuf uintptr) int32 {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var rc int32
	var szPage int32

	var mxSafeFrame U32
	var mxPage U32
	var i int32
	var pInfo uintptr
	var iMark U32
	var y U32

	var iOffset I64
	var szDb I64
	var nBackfill U32

	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*U32)(unsafe.Pointer(bp + 24)) = U32(0)
	*(*U32)(unsafe.Pointer(bp + 28)) = U32(0)

	szPage = walPagesize(tls, pWal)

	libc.AtomicStoreUintptr(&pInfo, walCkptInfo(tls, pWal))
	if !((*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill < (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame) {
		goto __1
	}

	mxSafeFrame = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	mxPage = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FnPage
	i = 1
__2:
	if !(i < SQLITE_SHM_NLOCK-3) {
		goto __4
	}
	y = libc.AtomicLoadNUint32(pInfo+4+uintptr(i)*4, 0)
	if !(mxSafeFrame > y) {
		goto __5
	}

	rc = walBusyLock(tls, pWal, xBusy, pBusyArg, 3+i, 1)
	if !(rc == SQLITE_OK) {
		goto __6
	}
	iMark = func() uint32 {
		if i == 1 {
			return mxSafeFrame
		}
		return READMARK_NOT_USED
	}()
	libc.AtomicStoreNUint32(pInfo+4+uintptr(i)*4, iMark, 0)
	walUnlockExclusive(tls, pWal, 3+i, 1)
	goto __7
__6:
	if !(rc == SQLITE_BUSY) {
		goto __8
	}
	mxSafeFrame = y
	xBusy = uintptr(0)
	goto __9
__8:
	goto walcheckpoint_out
__9:
	;
__7:
	;
__5:
	;
	goto __3
__3:
	i++
	goto __2
	goto __4
__4:
	;
	if !((*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill < mxSafeFrame) {
		goto __10
	}
	rc = walIteratorInit(tls, pWal, (*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill, bp)

__10:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp)) != 0 &&
		libc.AssignInt32(&rc, walBusyLock(tls, pWal, xBusy, pBusyArg, 3+0, 1)) == SQLITE_OK) {
		goto __11
	}
	nBackfill = (*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill

	(*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted = mxSafeFrame

	rc = Xsqlite3OsSync(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, sync_flags>>2&0x03)

	if !(rc == SQLITE_OK) {
		goto __12
	}
	*(*I64)(unsafe.Pointer(bp + 16)) = I64(mxPage) * I64(szPage)
	Xsqlite3OsFileControl(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, SQLITE_FCNTL_CKPT_START, uintptr(0))
	rc = Xsqlite3OsFileSize(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, bp+8)
	if !(rc == SQLITE_OK && *(*I64)(unsafe.Pointer(bp + 8)) < *(*I64)(unsafe.Pointer(bp + 16))) {
		goto __13
	}
	if !(*(*I64)(unsafe.Pointer(bp + 8))+int64(65536)+I64((*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame)*I64(szPage) < *(*I64)(unsafe.Pointer(bp + 16))) {
		goto __14
	}

	rc = Xsqlite3CorruptError(tls, 65337)
	goto __15
__14:
	Xsqlite3OsFileControlHint(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, SQLITE_FCNTL_SIZE_HINT, bp+16)
__15:
	;
__13:
	;
__12:
	;
__16:
	if !(rc == SQLITE_OK && 0 == walIteratorNext(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+24, bp+28)) {
		goto __17
	}

	if !(libc.AtomicLoadNInt32(db+432, 0) != 0) {
		goto __18
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		rc = SQLITE_NOMEM
	} else {
		rc = SQLITE_INTERRUPT
	}
	goto __17
__18:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 28)) <= nBackfill || *(*U32)(unsafe.Pointer(bp + 28)) > mxSafeFrame || *(*U32)(unsafe.Pointer(bp + 24)) > mxPage) {
		goto __19
	}
	goto __16
__19:
	;
	iOffset = int64(WAL_HDRSIZE) + I64(*(*U32)(unsafe.Pointer(bp + 28))-U32(1))*I64(szPage+WAL_FRAME_HDRSIZE) + int64(WAL_FRAME_HDRSIZE)

	rc = Xsqlite3OsRead(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, zBuf, szPage, iOffset)
	if !(rc != SQLITE_OK) {
		goto __20
	}
	goto __17
__20:
	;
	iOffset = I64(*(*U32)(unsafe.Pointer(bp + 24))-U32(1)) * I64(szPage)

	rc = Xsqlite3OsWrite(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, zBuf, szPage, iOffset)
	if !(rc != SQLITE_OK) {
		goto __21
	}
	goto __17
__21:
	;
	goto __16
__17:
	;
	Xsqlite3OsFileControl(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, SQLITE_FCNTL_CKPT_DONE, uintptr(0))

	if !(rc == SQLITE_OK) {
		goto __22
	}
	if !(mxSafeFrame == (*WalIndexHdr)(unsafe.Pointer(walIndexHdr(tls, pWal))).FmxFrame) {
		goto __23
	}
	szDb = I64((*Wal)(unsafe.Pointer(pWal)).Fhdr.FnPage) * I64(szPage)

	rc = Xsqlite3OsTruncate(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, szDb)
	if !(rc == SQLITE_OK) {
		goto __24
	}
	rc = Xsqlite3OsSync(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, sync_flags>>2&0x03)
__24:
	;
__23:
	;
	if !(rc == SQLITE_OK) {
		goto __25
	}
	libc.AtomicStoreNUint32(pInfo, mxSafeFrame, 0)
__25:
	;
__22:
	;
	walUnlockExclusive(tls, pWal, 3+0, 1)
__11:
	;
	if !(rc == SQLITE_BUSY) {
		goto __26
	}

	rc = SQLITE_OK
__26:
	;
__1:
	;
	if !(rc == SQLITE_OK && eMode != SQLITE_CHECKPOINT_PASSIVE) {
		goto __27
	}

	if !((*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill < (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame) {
		goto __28
	}
	rc = SQLITE_BUSY
	goto __29
__28:
	if !(eMode >= SQLITE_CHECKPOINT_RESTART) {
		goto __30
	}
	Xsqlite3_randomness(tls, 4, bp+32)

	rc = walBusyLock(tls, pWal, xBusy, pBusyArg, 3+1, SQLITE_SHM_NLOCK-3-1)
	if !(rc == SQLITE_OK) {
		goto __31
	}
	if !(eMode == SQLITE_CHECKPOINT_TRUNCATE) {
		goto __32
	}

	walRestartHdr(tls, pWal, *(*U32)(unsafe.Pointer(bp + 32)))
	rc = Xsqlite3OsTruncate(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, int64(0))
__32:
	;
	walUnlockExclusive(tls, pWal, 3+1, SQLITE_SHM_NLOCK-3-1)
__31:
	;
__30:
	;
__29:
	;
__27:
	;
walcheckpoint_out:
	walIteratorFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func walLimitSize(tls *libc.TLS, pWal uintptr, nMax I64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rx int32
	Xsqlite3BeginBenignMalloc(tls)
	rx = Xsqlite3OsFileSize(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, bp+8)
	if rx == SQLITE_OK && *(*I64)(unsafe.Pointer(bp + 8)) > nMax {
		rx = Xsqlite3OsTruncate(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, nMax)
	}
	Xsqlite3EndBenignMalloc(tls)
	if rx != 0 {
		Xsqlite3_log(tls, rx, ts+6887, libc.VaList(bp, (*Wal)(unsafe.Pointer(pWal)).FzWalName))
	}
}

func Xsqlite3WalClose(tls *libc.TLS, pWal uintptr, db uintptr, sync_flags int32, nBuf int32, zBuf uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32 = SQLITE_OK
	if pWal != 0 {
		var isDelete int32 = 0

		if zBuf != uintptr(0) &&
			SQLITE_OK == libc.AssignInt32(&rc, Xsqlite3OsLock(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, SQLITE_LOCK_EXCLUSIVE)) {
			if int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_NORMAL_MODE {
				(*Wal)(unsafe.Pointer(pWal)).FexclusiveMode = U8(WAL_EXCLUSIVE_MODE)
			}
			rc = Xsqlite3WalCheckpoint(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)) = -1
				Xsqlite3OsFileControlHint(tls,
					(*Wal)(unsafe.Pointer(pWal)).FpDbFd, SQLITE_FCNTL_PERSIST_WAL, bp)
				if *(*int32)(unsafe.Pointer(bp)) != 1 {
					isDelete = 1
				} else if (*Wal)(unsafe.Pointer(pWal)).FmxWalSize >= int64(0) {
					walLimitSize(tls, pWal, int64(0))
				}
			}
		}

		walIndexClose(tls, pWal, isDelete)
		Xsqlite3OsClose(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd)
		if isDelete != 0 {
			Xsqlite3BeginBenignMalloc(tls)
			Xsqlite3OsDelete(tls, (*Wal)(unsafe.Pointer(pWal)).FpVfs, (*Wal)(unsafe.Pointer(pWal)).FzWalName, 0)
			Xsqlite3EndBenignMalloc(tls)
		}

		Xsqlite3_free(tls, (*Wal)(unsafe.Pointer(pWal)).FapWiData)
		Xsqlite3_free(tls, pWal)
	}
	return rc
}

func walIndexTryHdr(tls *libc.TLS, pWal uintptr, pChanged uintptr) int32 {
	bp := tls.Alloc(104)
	defer tls.Free(104)

	var aHdr uintptr

	libc.AtomicStoreUintptr(&aHdr, walIndexHdr(tls, pWal))
	libc.Xmemcpy(tls, bp, aHdr, uint64(unsafe.Sizeof(WalIndexHdr{})))
	walShmBarrier(tls, pWal)
	libc.Xmemcpy(tls, bp+48, aHdr+1*48, uint64(unsafe.Sizeof(WalIndexHdr{})))

	if libc.Xmemcmp(tls, bp, bp+48, uint64(unsafe.Sizeof(WalIndexHdr{}))) != 0 {
		return 1
	}
	if int32((*WalIndexHdr)(unsafe.Pointer(bp)).FisInit) == 0 {
		return 1
	}
	walChecksumBytes(tls, 1, bp, int32(uint64(unsafe.Sizeof(WalIndexHdr{}))-uint64(unsafe.Sizeof([2]U32{}))), uintptr(0), bp+96)
	if *(*U32)(unsafe.Pointer(bp + 96)) != *(*U32)(unsafe.Pointer(bp + 40)) || *(*U32)(unsafe.Pointer(bp + 96 + 1*4)) != *(*U32)(unsafe.Pointer(bp + 40 + 1*4)) {
		return 1
	}

	if libc.Xmemcmp(tls, pWal+72, bp, uint64(unsafe.Sizeof(WalIndexHdr{}))) != 0 {
		*(*int32)(unsafe.Pointer(pChanged)) = 1
		libc.Xmemcpy(tls, pWal+72, bp, uint64(unsafe.Sizeof(WalIndexHdr{})))
		(*Wal)(unsafe.Pointer(pWal)).FszPage = U32(int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FszPage)&0xfe00 + int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FszPage)&0x0001<<16)

	}

	return 0
}

func walIndexReadHdr(tls *libc.TLS, pWal uintptr, pChanged uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	var badHdr int32

	rc = walIndexPage(tls, pWal, 0, bp)
	if rc != SQLITE_OK {
		if rc == SQLITE_READONLY|int32(5)<<8 {
			(*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable = U8(1)
			(*Wal)(unsafe.Pointer(pWal)).FexclusiveMode = U8(WAL_HEAPMEMORY_MODE)
			*(*int32)(unsafe.Pointer(pChanged)) = 1
		} else {
			return rc
		}
	} else {
	}

	badHdr = func() int32 {
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
			return walIndexTryHdr(tls, pWal, pChanged)
		}
		return 1
	}()

	if badHdr != 0 {
		if int32((*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable) == 0 && int32((*Wal)(unsafe.Pointer(pWal)).FreadOnly)&WAL_SHM_RDONLY != 0 {
			if SQLITE_OK == libc.AssignInt32(&rc, walLockShared(tls, pWal, WAL_WRITE_LOCK)) {
				walUnlockShared(tls, pWal, WAL_WRITE_LOCK)
				rc = SQLITE_READONLY | int32(1)<<8
			}
		} else {
			var bWriteLock int32 = int32((*Wal)(unsafe.Pointer(pWal)).FwriteLock)
			if bWriteLock != 0 || SQLITE_OK == libc.AssignInt32(&rc, walLockExclusive(tls, pWal, WAL_WRITE_LOCK, 1)) {
				(*Wal)(unsafe.Pointer(pWal)).FwriteLock = U8(1)
				if SQLITE_OK == libc.AssignInt32(&rc, walIndexPage(tls, pWal, 0, bp)) {
					badHdr = walIndexTryHdr(tls, pWal, pChanged)
					if badHdr != 0 {
						rc = walIndexRecover(tls, pWal)
						*(*int32)(unsafe.Pointer(pChanged)) = 1
					}
				}
				if bWriteLock == 0 {
					(*Wal)(unsafe.Pointer(pWal)).FwriteLock = U8(0)
					walUnlockExclusive(tls, pWal, WAL_WRITE_LOCK, 1)
				}
			}
		}
	}

	if badHdr == 0 && (*Wal)(unsafe.Pointer(pWal)).Fhdr.FiVersion != U32(WALINDEX_MAX_VERSION) {
		rc = Xsqlite3CantopenError(tls, 65686)
	}
	if (*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable != 0 {
		if rc != SQLITE_OK {
			walIndexClose(tls, pWal, 0)
			(*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable = U8(0)

			if rc == SQLITE_IOERR|int32(2)<<8 {
				rc = -1
			}
		}
		(*Wal)(unsafe.Pointer(pWal)).FexclusiveMode = U8(WAL_NORMAL_MODE)
	}

	return rc
}

func walBeginShmUnreliable(tls *libc.TLS, pWal uintptr, pChanged uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var iOffset I64

	var aFrame uintptr
	var szFrame int32
	var aData uintptr

	var rc int32

	var i int32
	aFrame = uintptr(0)

	rc = walLockShared(tls, pWal, 3+0)
	if !(rc != SQLITE_OK) {
		goto __1
	}
	if !(rc == SQLITE_BUSY) {
		goto __2
	}
	rc = -1
__2:
	;
	goto begin_unreliable_shm_out
__1:
	;
	(*Wal)(unsafe.Pointer(pWal)).FreadLock = int16(0)

	rc = Xsqlite3OsShmMap(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, 0, int32(uint64(unsafe.Sizeof(Ht_slot(0)))*uint64(HASHTABLE_NPAGE*2)+uint64(HASHTABLE_NPAGE)*uint64(unsafe.Sizeof(U32(0)))), 0, bp)

	if !(rc != SQLITE_READONLY|int32(5)<<8) {
		goto __3
	}
	rc = func() int32 {
		if rc == SQLITE_READONLY {
			return -1
		}
		return rc
	}()
	goto begin_unreliable_shm_out
__3:
	;
	libc.Xmemcpy(tls, pWal+72, walIndexHdr(tls, pWal), uint64(unsafe.Sizeof(WalIndexHdr{})))

	rc = Xsqlite3OsFileSize(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, bp+8)
	if !(rc != SQLITE_OK) {
		goto __4
	}
	goto begin_unreliable_shm_out
__4:
	;
	if !(*(*I64)(unsafe.Pointer(bp + 8)) < int64(WAL_HDRSIZE)) {
		goto __5
	}

	*(*int32)(unsafe.Pointer(pChanged)) = 1
	rc = func() int32 {
		if (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame == U32(0) {
			return SQLITE_OK
		}
		return -1
	}()
	goto begin_unreliable_shm_out
__5:
	;
	rc = Xsqlite3OsRead(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, bp+16, WAL_HDRSIZE, int64(0))
	if !(rc != SQLITE_OK) {
		goto __6
	}
	goto begin_unreliable_shm_out
__6:
	;
	if !(libc.Xmemcmp(tls, pWal+72+32, bp+16+16, uint64(8)) != 0) {
		goto __7
	}

	rc = -1
	goto begin_unreliable_shm_out
__7:
	;
	szFrame = int32((*Wal)(unsafe.Pointer(pWal)).FszPage + U32(WAL_FRAME_HDRSIZE))
	aFrame = Xsqlite3_malloc64(tls, uint64(szFrame))
	if !(aFrame == uintptr(0)) {
		goto __8
	}
	rc = SQLITE_NOMEM
	goto begin_unreliable_shm_out
__8:
	;
	aData = aFrame + 24

	*(*U32)(unsafe.Pointer(bp + 48)) = *(*U32)(unsafe.Pointer(pWal + 72 + 24))
	*(*U32)(unsafe.Pointer(bp + 48 + 1*4)) = *(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4))
	iOffset = int64(WAL_HDRSIZE) + I64((*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame+U32(1)-U32(1))*I64((*Wal)(unsafe.Pointer(pWal)).FszPage+U32(WAL_FRAME_HDRSIZE))
__9:
	if !(iOffset+I64(szFrame) <= *(*I64)(unsafe.Pointer(bp + 8))) {
		goto __11
	}

	rc = Xsqlite3OsRead(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, aFrame, szFrame, iOffset)
	if !(rc != SQLITE_OK) {
		goto __12
	}
	goto __11
__12:
	;
	if !!(walDecodeFrame(tls, pWal, bp+56, bp+60, aData, aFrame) != 0) {
		goto __13
	}
	goto __11
__13:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 60)) != 0) {
		goto __14
	}
	rc = -1
	goto __11
__14:
	;
	goto __10
__10:
	iOffset = iOffset + I64(szFrame)
	goto __9
	goto __11
__11:
	;
	*(*U32)(unsafe.Pointer(pWal + 72 + 24)) = *(*U32)(unsafe.Pointer(bp + 48))
	*(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4)) = *(*U32)(unsafe.Pointer(bp + 48 + 1*4))

begin_unreliable_shm_out:
	Xsqlite3_free(tls, aFrame)
	if !(rc != SQLITE_OK) {
		goto __15
	}
	i = 0
__16:
	if !(i < (*Wal)(unsafe.Pointer(pWal)).FnWiData) {
		goto __18
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(i)*8)))
	*(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData + uintptr(i)*8)) = uintptr(0)
	goto __17
__17:
	i++
	goto __16
	goto __18
__18:
	;
	(*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable = U8(0)
	Xsqlite3WalEndReadTransaction(tls, pWal)
	*(*int32)(unsafe.Pointer(pChanged)) = 1
__15:
	;
	return rc
}

func walTryBeginRead(tls *libc.TLS, pWal uintptr, pChanged uintptr, useWal int32, cnt int32) int32 {
	var pInfo uintptr
	var mxReadMark U32
	var mxI int32
	var i int32
	var rc int32 = SQLITE_OK
	var mxFrame U32

	if cnt > 5 {
		var nDelay int32 = 1
		if cnt > 100 {
			return SQLITE_PROTOCOL
		}
		if cnt >= 10 {
			nDelay = (cnt - 9) * (cnt - 9) * 39
		}
		Xsqlite3OsSleep(tls, (*Wal)(unsafe.Pointer(pWal)).FpVfs, nDelay)
	}

	if !(useWal != 0) {
		if int32((*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable) == 0 {
			rc = walIndexReadHdr(tls, pWal, pChanged)
		}
		if rc == SQLITE_BUSY {
			if *(*uintptr)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FapWiData)) == uintptr(0) {
				rc = -1
			} else if SQLITE_OK == libc.AssignInt32(&rc, walLockShared(tls, pWal, WAL_RECOVER_LOCK)) {
				walUnlockShared(tls, pWal, WAL_RECOVER_LOCK)
				rc = -1
			} else if rc == SQLITE_BUSY {
				rc = SQLITE_BUSY | int32(1)<<8
			}
		}
		if rc != SQLITE_OK {
			return rc
		} else if (*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable != 0 {
			return walBeginShmUnreliable(tls, pWal, pChanged)
		}
	}

	libc.AtomicStoreUintptr(&pInfo, walCkptInfo(tls, pWal))
	if !(useWal != 0) && libc.AtomicLoadNUint32(pInfo, 0) == (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
		rc = walLockShared(tls, pWal, 3+0)
		walShmBarrier(tls, pWal)
		if rc == SQLITE_OK {
			if libc.Xmemcmp(tls, walIndexHdr(tls, pWal), pWal+72, uint64(unsafe.Sizeof(WalIndexHdr{}))) != 0 {
				walUnlockShared(tls, pWal, 3+0)
				return -1
			}
			(*Wal)(unsafe.Pointer(pWal)).FreadLock = int16(0)
			return SQLITE_OK
		} else if rc != SQLITE_BUSY {
			return rc
		}
	}

	mxReadMark = U32(0)
	mxI = 0
	mxFrame = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	for i = 1; i < SQLITE_SHM_NLOCK-3; i++ {
		var thisMark U32 = libc.AtomicLoadNUint32(pInfo+4+uintptr(i)*4, 0)
		if mxReadMark <= thisMark && thisMark <= mxFrame {
			mxReadMark = thisMark
			mxI = i
		}
	}
	if int32((*Wal)(unsafe.Pointer(pWal)).FreadOnly)&WAL_SHM_RDONLY == 0 &&
		(mxReadMark < mxFrame || mxI == 0) {
		for i = 1; i < SQLITE_SHM_NLOCK-3; i++ {
			rc = walLockExclusive(tls, pWal, 3+i, 1)
			if rc == SQLITE_OK {
				libc.AtomicStoreNUint32(pInfo+4+uintptr(i)*4, mxFrame, 0)
				mxReadMark = mxFrame
				mxI = i
				walUnlockExclusive(tls, pWal, 3+i, 1)
				break
			} else if rc != SQLITE_BUSY {
				return rc
			}
		}
	}
	if mxI == 0 {
		if rc == SQLITE_BUSY {
			return -1
		}
		return SQLITE_READONLY | int32(5)<<8
	}

	rc = walLockShared(tls, pWal, 3+mxI)
	if rc != 0 {
		if rc == SQLITE_BUSY {
			return -1
		}
		return rc
	}

	(*Wal)(unsafe.Pointer(pWal)).FminFrame = libc.AtomicLoadNUint32(pInfo, 0) + 1
	walShmBarrier(tls, pWal)
	if libc.AtomicLoadNUint32(pInfo+4+uintptr(mxI)*4, 0) != mxReadMark ||
		libc.Xmemcmp(tls, walIndexHdr(tls, pWal), pWal+72, uint64(unsafe.Sizeof(WalIndexHdr{}))) != 0 {
		walUnlockShared(tls, pWal, 3+mxI)
		return -1
	} else {
		(*Wal)(unsafe.Pointer(pWal)).FreadLock = I16(mxI)
	}
	return rc
}

func Xsqlite3WalBeginReadTransaction(tls *libc.TLS, pWal uintptr, pChanged uintptr) int32 {
	var rc int32
	var cnt int32 = 0

	for __ccgo := true; __ccgo; __ccgo = rc == -1 {
		rc = walTryBeginRead(tls, pWal, pChanged, 0, libc.PreIncInt32(&cnt, 1))
	}

	return rc
}

func Xsqlite3WalEndReadTransaction(tls *libc.TLS, pWal uintptr) {
	Xsqlite3WalEndWriteTransaction(tls, pWal)
	if int32((*Wal)(unsafe.Pointer(pWal)).FreadLock) >= 0 {
		walUnlockShared(tls, pWal, 3+int32((*Wal)(unsafe.Pointer(pWal)).FreadLock))
		(*Wal)(unsafe.Pointer(pWal)).FreadLock = int16(-1)
	}
}

func Xsqlite3WalFindFrame(tls *libc.TLS, pWal uintptr, pgno Pgno, piRead uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var iRead U32 = U32(0)
	var iLast U32 = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	var iHash int32
	var iMinHash int32

	if iLast == U32(0) || int32((*Wal)(unsafe.Pointer(pWal)).FreadLock) == 0 && int32((*Wal)(unsafe.Pointer(pWal)).FbShmUnreliable) == 0 {
		*(*U32)(unsafe.Pointer(piRead)) = U32(0)
		return SQLITE_OK
	}

	iMinHash = walFramePage(tls, (*Wal)(unsafe.Pointer(pWal)).FminFrame)
	for iHash = walFramePage(tls, iLast); iHash >= iMinHash; iHash-- {
		var iKey int32
		var nCollide int32
		var rc int32
		var iH U32

		rc = walHashGet(tls, pWal, iHash, bp)
		if rc != SQLITE_OK {
			return rc
		}
		nCollide = HASHTABLE_NPAGE * 2
		iKey = walHash(tls, pgno)
		for libc.AssignUint32(&iH, U32(libc.AtomicLoadNUint16((*WalHashLoc)(unsafe.Pointer(bp)).FaHash+uintptr(iKey)*2, 0))) != U32(0) {
			var iFrame U32 = iH + (*WalHashLoc)(unsafe.Pointer(bp)).FiZero
			if iFrame <= iLast && iFrame >= (*Wal)(unsafe.Pointer(pWal)).FminFrame && *(*U32)(unsafe.Pointer((*WalHashLoc)(unsafe.Pointer(bp)).FaPgno + uintptr(iH-U32(1))*4)) == pgno {
				iRead = iFrame
			}
			if libc.PostDecInt32(&nCollide, 1) == 0 {
				return Xsqlite3CorruptError(tls, 66423)
			}
			iKey = walNextHash(tls, iKey)
		}
		if iRead != 0 {
			break
		}
	}

	*(*U32)(unsafe.Pointer(piRead)) = iRead
	return SQLITE_OK
}

func Xsqlite3WalReadFrame(tls *libc.TLS, pWal uintptr, iRead U32, nOut int32, pOut uintptr) int32 {
	var sz int32
	var iOffset I64
	sz = int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FszPage)
	sz = sz&0xfe00 + sz&0x0001<<16

	iOffset = int64(WAL_HDRSIZE) + I64(iRead-U32(1))*I64(sz+WAL_FRAME_HDRSIZE) + int64(WAL_FRAME_HDRSIZE)

	return Xsqlite3OsRead(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, pOut, func() int32 {
		if nOut > sz {
			return sz
		}
		return nOut
	}(), iOffset)
}

func Xsqlite3WalDbsize(tls *libc.TLS, pWal uintptr) Pgno {
	if pWal != 0 && int32((*Wal)(unsafe.Pointer(pWal)).FreadLock) >= 0 {
		return (*Wal)(unsafe.Pointer(pWal)).Fhdr.FnPage
	}
	return Pgno(0)
}

func Xsqlite3WalBeginWriteTransaction(tls *libc.TLS, pWal uintptr) int32 {
	var rc int32

	if (*Wal)(unsafe.Pointer(pWal)).FreadOnly != 0 {
		return SQLITE_READONLY
	}

	rc = walLockExclusive(tls, pWal, WAL_WRITE_LOCK, 1)
	if rc != 0 {
		return rc
	}
	(*Wal)(unsafe.Pointer(pWal)).FwriteLock = U8(1)

	if libc.Xmemcmp(tls, pWal+72, walIndexHdr(tls, pWal), uint64(unsafe.Sizeof(WalIndexHdr{}))) != 0 {
		walUnlockExclusive(tls, pWal, WAL_WRITE_LOCK, 1)
		(*Wal)(unsafe.Pointer(pWal)).FwriteLock = U8(0)
		rc = SQLITE_BUSY | int32(2)<<8
	}

	return rc
}

func Xsqlite3WalEndWriteTransaction(tls *libc.TLS, pWal uintptr) int32 {
	if (*Wal)(unsafe.Pointer(pWal)).FwriteLock != 0 {
		walUnlockExclusive(tls, pWal, WAL_WRITE_LOCK, 1)
		(*Wal)(unsafe.Pointer(pWal)).FwriteLock = U8(0)
		(*Wal)(unsafe.Pointer(pWal)).FiReCksum = U32(0)
		(*Wal)(unsafe.Pointer(pWal)).FtruncateOnCommit = U8(0)
	}
	return SQLITE_OK
}

func Xsqlite3WalUndo(tls *libc.TLS, pWal uintptr, xUndo uintptr, pUndoCtx uintptr) int32 {
	var rc int32 = SQLITE_OK
	if (*Wal)(unsafe.Pointer(pWal)).FwriteLock != 0 {
		var iMax Pgno = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
		var iFrame Pgno

		libc.Xmemcpy(tls, pWal+72, walIndexHdr(tls, pWal), uint64(unsafe.Sizeof(WalIndexHdr{})))

		for iFrame = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame + U32(1); rc == SQLITE_OK && iFrame <= iMax; iFrame++ {
			rc = (*struct {
				f func(*libc.TLS, uintptr, Pgno) int32
			})(unsafe.Pointer(&struct{ uintptr }{xUndo})).f(tls, pUndoCtx, walFramePgno(tls, pWal, iFrame))
		}
		if iMax != (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
			walCleanupHash(tls, pWal)
		}
	}
	return rc
}

func Xsqlite3WalSavepoint(tls *libc.TLS, pWal uintptr, aWalData uintptr) {
	*(*U32)(unsafe.Pointer(aWalData)) = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	*(*U32)(unsafe.Pointer(aWalData + 1*4)) = *(*U32)(unsafe.Pointer(pWal + 72 + 24))
	*(*U32)(unsafe.Pointer(aWalData + 2*4)) = *(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4))
	*(*U32)(unsafe.Pointer(aWalData + 3*4)) = (*Wal)(unsafe.Pointer(pWal)).FnCkpt
}

func Xsqlite3WalSavepointUndo(tls *libc.TLS, pWal uintptr, aWalData uintptr) int32 {
	var rc int32 = SQLITE_OK

	if *(*U32)(unsafe.Pointer(aWalData + 3*4)) != (*Wal)(unsafe.Pointer(pWal)).FnCkpt {
		*(*U32)(unsafe.Pointer(aWalData)) = U32(0)
		*(*U32)(unsafe.Pointer(aWalData + 3*4)) = (*Wal)(unsafe.Pointer(pWal)).FnCkpt
	}

	if *(*U32)(unsafe.Pointer(aWalData)) < (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
		(*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = *(*U32)(unsafe.Pointer(aWalData))
		*(*U32)(unsafe.Pointer(pWal + 72 + 24)) = *(*U32)(unsafe.Pointer(aWalData + 1*4))
		*(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4)) = *(*U32)(unsafe.Pointer(aWalData + 2*4))
		walCleanupHash(tls, pWal)
	}

	return rc
}

func walRestartLog(tls *libc.TLS, pWal uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var cnt int32

	if int32((*Wal)(unsafe.Pointer(pWal)).FreadLock) == 0 {
		var pInfo uintptr = walCkptInfo(tls, pWal)

		if (*WalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfill > U32(0) {
			Xsqlite3_randomness(tls, 4, bp)
			rc = walLockExclusive(tls, pWal, 3+1, SQLITE_SHM_NLOCK-3-1)
			if rc == SQLITE_OK {
				walRestartHdr(tls, pWal, *(*U32)(unsafe.Pointer(bp)))
				walUnlockExclusive(tls, pWal, 3+1, SQLITE_SHM_NLOCK-3-1)
			} else if rc != SQLITE_BUSY {
				return rc
			}
		}
		walUnlockShared(tls, pWal, 3+0)
		(*Wal)(unsafe.Pointer(pWal)).FreadLock = int16(-1)
		cnt = 0
		for __ccgo := true; __ccgo; __ccgo = rc == -1 {
			rc = walTryBeginRead(tls, pWal, bp+4, 1, libc.PreIncInt32(&cnt, 1))
		}

	}
	return rc
}

type WalWriter1 = struct {
	FpWal       uintptr
	FpFd        uintptr
	FiSyncPoint Sqlite3_int64
	FsyncFlags  int32
	FszPage     int32
}

type WalWriter = WalWriter1

func walWriteToLog(tls *libc.TLS, p uintptr, pContent uintptr, iAmt int32, iOffset Sqlite3_int64) int32 {
	var rc int32
	if iOffset < (*WalWriter)(unsafe.Pointer(p)).FiSyncPoint && iOffset+Sqlite3_int64(iAmt) >= (*WalWriter)(unsafe.Pointer(p)).FiSyncPoint {
		var iFirstAmt int32 = int32((*WalWriter)(unsafe.Pointer(p)).FiSyncPoint - iOffset)
		rc = Xsqlite3OsWrite(tls, (*WalWriter)(unsafe.Pointer(p)).FpFd, pContent, iFirstAmt, iOffset)
		if rc != 0 {
			return rc
		}
		iOffset = iOffset + Sqlite3_int64(iFirstAmt)
		iAmt = iAmt - iFirstAmt
		pContent = uintptr(iFirstAmt) + pContent

		rc = Xsqlite3OsSync(tls, (*WalWriter)(unsafe.Pointer(p)).FpFd, (*WalWriter)(unsafe.Pointer(p)).FsyncFlags&0x03)
		if iAmt == 0 || rc != 0 {
			return rc
		}
	}
	rc = Xsqlite3OsWrite(tls, (*WalWriter)(unsafe.Pointer(p)).FpFd, pContent, iAmt, iOffset)
	return rc
}

func walWriteOneFrame(tls *libc.TLS, p uintptr, pPage uintptr, nTruncate int32, iOffset Sqlite3_int64) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32
	var pData uintptr

	pData = (*PgHdr)(unsafe.Pointer(pPage)).FpData
	walEncodeFrame(tls, (*WalWriter)(unsafe.Pointer(p)).FpWal, (*PgHdr)(unsafe.Pointer(pPage)).Fpgno, uint32(nTruncate), pData, bp)
	rc = walWriteToLog(tls, p, bp, int32(unsafe.Sizeof([24]U8{})), iOffset)
	if rc != 0 {
		return rc
	}

	rc = walWriteToLog(tls, p, pData, (*WalWriter)(unsafe.Pointer(p)).FszPage, int64(uint64(iOffset)+uint64(unsafe.Sizeof([24]U8{}))))
	return rc
}

func walRewriteChecksums(tls *libc.TLS, pWal uintptr, iLast U32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var szPage int32 = int32((*Wal)(unsafe.Pointer(pWal)).FszPage)
	var rc int32 = SQLITE_OK
	var aBuf uintptr

	var iRead U32
	var iCksumOff I64

	aBuf = Xsqlite3_malloc(tls, szPage+WAL_FRAME_HDRSIZE)
	if aBuf == uintptr(0) {
		return SQLITE_NOMEM
	}

	if (*Wal)(unsafe.Pointer(pWal)).FiReCksum == U32(1) {
		iCksumOff = int64(24)
	} else {
		iCksumOff = int64(WAL_HDRSIZE) + I64((*Wal)(unsafe.Pointer(pWal)).FiReCksum-U32(1)-U32(1))*I64(szPage+WAL_FRAME_HDRSIZE) + int64(16)
	}
	rc = Xsqlite3OsRead(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, aBuf, int32(uint64(unsafe.Sizeof(U32(0)))*uint64(2)), iCksumOff)
	*(*U32)(unsafe.Pointer(pWal + 72 + 24)) = Xsqlite3Get4byte(tls, aBuf)
	*(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4)) = Xsqlite3Get4byte(tls, aBuf+4)

	iRead = (*Wal)(unsafe.Pointer(pWal)).FiReCksum
	(*Wal)(unsafe.Pointer(pWal)).FiReCksum = U32(0)
	for ; rc == SQLITE_OK && iRead <= iLast; iRead++ {
		var iOff I64 = int64(WAL_HDRSIZE) + I64(iRead-U32(1))*I64(szPage+WAL_FRAME_HDRSIZE)
		rc = Xsqlite3OsRead(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, aBuf, szPage+WAL_FRAME_HDRSIZE, iOff)
		if rc == SQLITE_OK {
			var iPgno U32
			var nDbSize U32
			iPgno = Xsqlite3Get4byte(tls, aBuf)
			nDbSize = Xsqlite3Get4byte(tls, aBuf+4)

			walEncodeFrame(tls, pWal, iPgno, nDbSize, aBuf+24, bp)
			rc = Xsqlite3OsWrite(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, bp, int32(unsafe.Sizeof([24]U8{})), iOff)
		}
	}

	Xsqlite3_free(tls, aBuf)
	return rc
}

func Xsqlite3WalFrames(tls *libc.TLS, pWal uintptr, szPage int32, pList uintptr, nTruncate Pgno, isCommit int32, sync_flags int32) int32 {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var rc int32
	var iFrame U32
	var p uintptr
	var pLast uintptr = uintptr(0)
	var nExtra int32 = 0
	var szFrame int32
	var iOffset I64

	var iFirst U32 = U32(0)
	var pLive uintptr

	pLive = walIndexHdr(tls, pWal)
	if libc.Xmemcmp(tls, pWal+72, pLive, uint64(unsafe.Sizeof(WalIndexHdr{}))) != 0 {
		iFirst = (*WalIndexHdr)(unsafe.Pointer(pLive)).FmxFrame + U32(1)
	}

	if SQLITE_OK != libc.AssignInt32(&rc, walRestartLog(tls, pWal)) {
		return rc
	}

	iFrame = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	if iFrame == U32(0) {
		Xsqlite3Put4byte(tls, bp, uint32(WAL_MAGIC|SQLITE_BIGENDIAN))
		Xsqlite3Put4byte(tls, bp+4, uint32(WAL_MAX_VERSION))
		Xsqlite3Put4byte(tls, bp+8, uint32(szPage))
		Xsqlite3Put4byte(tls, bp+12, (*Wal)(unsafe.Pointer(pWal)).FnCkpt)
		if (*Wal)(unsafe.Pointer(pWal)).FnCkpt == U32(0) {
			Xsqlite3_randomness(tls, 8, pWal+72+32)
		}
		libc.Xmemcpy(tls, bp+16, pWal+72+32, uint64(8))
		walChecksumBytes(tls, 1, bp, WAL_HDRSIZE-2*4, uintptr(0), bp+32)
		Xsqlite3Put4byte(tls, bp+24, *(*U32)(unsafe.Pointer(bp + 32)))
		Xsqlite3Put4byte(tls, bp+28, *(*U32)(unsafe.Pointer(bp + 32 + 1*4)))

		(*Wal)(unsafe.Pointer(pWal)).FszPage = U32(szPage)
		(*Wal)(unsafe.Pointer(pWal)).Fhdr.FbigEndCksum = U8(SQLITE_BIGENDIAN)
		*(*U32)(unsafe.Pointer(pWal + 72 + 24)) = *(*U32)(unsafe.Pointer(bp + 32))
		*(*U32)(unsafe.Pointer(pWal + 72 + 24 + 1*4)) = *(*U32)(unsafe.Pointer(bp + 32 + 1*4))
		(*Wal)(unsafe.Pointer(pWal)).FtruncateOnCommit = U8(1)

		rc = Xsqlite3OsWrite(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, bp, int32(unsafe.Sizeof([32]U8{})), int64(0))

		if rc != SQLITE_OK {
			return rc
		}

		if (*Wal)(unsafe.Pointer(pWal)).FsyncHeader != 0 {
			rc = Xsqlite3OsSync(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, sync_flags>>2&0x03)
			if rc != 0 {
				return rc
			}
		}
	}

	(*WalWriter)(unsafe.Pointer(bp + 48)).FpWal = pWal
	(*WalWriter)(unsafe.Pointer(bp + 48)).FpFd = (*Wal)(unsafe.Pointer(pWal)).FpWalFd
	(*WalWriter)(unsafe.Pointer(bp + 48)).FiSyncPoint = int64(0)
	(*WalWriter)(unsafe.Pointer(bp + 48)).FsyncFlags = sync_flags
	(*WalWriter)(unsafe.Pointer(bp + 48)).FszPage = szPage
	iOffset = int64(WAL_HDRSIZE) + I64(iFrame+U32(1)-U32(1))*I64(szPage+WAL_FRAME_HDRSIZE)
	szFrame = szPage + WAL_FRAME_HDRSIZE

	for p = pList; p != 0; p = (*PgHdr)(unsafe.Pointer(p)).FpDirty {
		var nDbSize int32

		if iFirst != 0 && ((*PgHdr)(unsafe.Pointer(p)).FpDirty != 0 || isCommit == 0) {
			*(*U32)(unsafe.Pointer(bp + 40)) = U32(0)
			Xsqlite3WalFindFrame(tls, pWal, (*PgHdr)(unsafe.Pointer(p)).Fpgno, bp+40)

			if *(*U32)(unsafe.Pointer(bp + 40)) >= iFirst {
				var iOff I64 = int64(WAL_HDRSIZE) + I64(*(*U32)(unsafe.Pointer(bp + 40))-U32(1))*I64(szPage+WAL_FRAME_HDRSIZE) + int64(WAL_FRAME_HDRSIZE)
				var pData uintptr
				if (*Wal)(unsafe.Pointer(pWal)).FiReCksum == U32(0) || *(*U32)(unsafe.Pointer(bp + 40)) < (*Wal)(unsafe.Pointer(pWal)).FiReCksum {
					(*Wal)(unsafe.Pointer(pWal)).FiReCksum = *(*U32)(unsafe.Pointer(bp + 40))
				}
				pData = (*PgHdr)(unsafe.Pointer(p)).FpData
				rc = Xsqlite3OsWrite(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd, pData, szPage, iOff)
				if rc != 0 {
					return rc
				}
				*(*U16)(unsafe.Pointer(p + 52)) &= libc.Uint16FromInt32(libc.CplInt32(PGHDR_WAL_APPEND))
				continue
			}
		}

		iFrame++

		if isCommit != 0 && (*PgHdr)(unsafe.Pointer(p)).FpDirty == uintptr(0) {
			nDbSize = int32(nTruncate)
		} else {
			nDbSize = 0
		}
		rc = walWriteOneFrame(tls, bp+48, p, nDbSize, iOffset)
		if rc != 0 {
			return rc
		}
		pLast = p
		iOffset = iOffset + I64(szFrame)
		*(*U16)(unsafe.Pointer(p + 52)) |= U16(PGHDR_WAL_APPEND)
	}

	if isCommit != 0 && (*Wal)(unsafe.Pointer(pWal)).FiReCksum != 0 {
		rc = walRewriteChecksums(tls, pWal, iFrame)
		if rc != 0 {
			return rc
		}
	}

	if isCommit != 0 && sync_flags&0x03 != 0 {
		var bSync int32 = 1
		if (*Wal)(unsafe.Pointer(pWal)).FpadToSectorBoundary != 0 {
			var sectorSize int32 = Xsqlite3SectorSize(tls, (*Wal)(unsafe.Pointer(pWal)).FpWalFd)
			(*WalWriter)(unsafe.Pointer(bp + 48)).FiSyncPoint = (iOffset + I64(sectorSize) - int64(1)) / I64(sectorSize) * I64(sectorSize)
			bSync = libc.Bool32((*WalWriter)(unsafe.Pointer(bp+48)).FiSyncPoint == iOffset)

			for iOffset < (*WalWriter)(unsafe.Pointer(bp+48)).FiSyncPoint {
				rc = walWriteOneFrame(tls, bp+48, pLast, int32(nTruncate), iOffset)
				if rc != 0 {
					return rc
				}
				iOffset = iOffset + I64(szFrame)
				nExtra++

			}
		}
		if bSync != 0 {
			rc = Xsqlite3OsSync(tls, (*WalWriter)(unsafe.Pointer(bp+48)).FpFd, sync_flags&0x03)
		}
	}

	if isCommit != 0 && (*Wal)(unsafe.Pointer(pWal)).FtruncateOnCommit != 0 && (*Wal)(unsafe.Pointer(pWal)).FmxWalSize >= int64(0) {
		var sz I64 = (*Wal)(unsafe.Pointer(pWal)).FmxWalSize
		if int64(WAL_HDRSIZE)+I64(iFrame+U32(nExtra)+U32(1)-U32(1))*I64(szPage+WAL_FRAME_HDRSIZE) > (*Wal)(unsafe.Pointer(pWal)).FmxWalSize {
			sz = int64(WAL_HDRSIZE) + I64(iFrame+U32(nExtra)+U32(1)-U32(1))*I64(szPage+WAL_FRAME_HDRSIZE)
		}
		walLimitSize(tls, pWal, sz)
		(*Wal)(unsafe.Pointer(pWal)).FtruncateOnCommit = U8(0)
	}

	iFrame = (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	for p = pList; p != 0 && rc == SQLITE_OK; p = (*PgHdr)(unsafe.Pointer(p)).FpDirty {
		if int32((*PgHdr)(unsafe.Pointer(p)).Fflags)&PGHDR_WAL_APPEND == 0 {
			continue
		}
		iFrame++
		rc = walIndexAppend(tls, pWal, iFrame, (*PgHdr)(unsafe.Pointer(p)).Fpgno)
	}

	for rc == SQLITE_OK && nExtra > 0 {
		iFrame++
		nExtra--
		rc = walIndexAppend(tls, pWal, iFrame, (*PgHdr)(unsafe.Pointer(pLast)).Fpgno)
	}

	if rc == SQLITE_OK {
		(*Wal)(unsafe.Pointer(pWal)).Fhdr.FszPage = U16(szPage&0xff00 | szPage>>16)

		(*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = iFrame
		if isCommit != 0 {
			(*Wal)(unsafe.Pointer(pWal)).Fhdr.FiChange++
			(*Wal)(unsafe.Pointer(pWal)).Fhdr.FnPage = nTruncate
		}

		if isCommit != 0 {
			walIndexWriteHdr(tls, pWal)
			(*Wal)(unsafe.Pointer(pWal)).FiCallback = iFrame
		}
	}

	return rc
}

func Xsqlite3WalCheckpoint(tls *libc.TLS, pWal uintptr, db uintptr, eMode int32, xBusy uintptr, pBusyArg uintptr, sync_flags int32, nBuf int32, zBuf uintptr, pnLog uintptr, pnCkpt uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32
	*(*int32)(unsafe.Pointer(bp)) = 0
	var eMode2 int32 = eMode
	var xBusy2 uintptr = xBusy

	if (*Wal)(unsafe.Pointer(pWal)).FreadOnly != 0 {
		return SQLITE_READONLY
	}

	rc = walLockExclusive(tls, pWal, WAL_CKPT_LOCK, 1)

	if rc == SQLITE_OK {
		(*Wal)(unsafe.Pointer(pWal)).FckptLock = U8(1)

		if eMode != SQLITE_CHECKPOINT_PASSIVE {
			rc = walBusyLock(tls, pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1)
			if rc == SQLITE_OK {
				(*Wal)(unsafe.Pointer(pWal)).FwriteLock = U8(1)
			} else if rc == SQLITE_BUSY {
				eMode2 = SQLITE_CHECKPOINT_PASSIVE
				xBusy2 = uintptr(0)
				rc = SQLITE_OK
			}
		}
	}

	if rc == SQLITE_OK {
		rc = walIndexReadHdr(tls, pWal, bp)

		if *(*int32)(unsafe.Pointer(bp)) != 0 && (*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Wal)(unsafe.Pointer(pWal)).FpDbFd)).FpMethods)).FiVersion >= 3 {
			Xsqlite3OsUnfetch(tls, (*Wal)(unsafe.Pointer(pWal)).FpDbFd, int64(0), uintptr(0))
		}
	}

	if rc == SQLITE_OK {
		if (*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame != 0 && walPagesize(tls, pWal) != nBuf {
			rc = Xsqlite3CorruptError(tls, 67142)
		} else {
			rc = walCheckpoint(tls, pWal, db, eMode2, xBusy2, pBusyArg, sync_flags, zBuf)
		}

		if rc == SQLITE_OK || rc == SQLITE_BUSY {
			if pnLog != 0 {
				*(*int32)(unsafe.Pointer(pnLog)) = int32((*Wal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame)
			}
			if pnCkpt != 0 {
				*(*int32)(unsafe.Pointer(pnCkpt)) = int32((*WalCkptInfo)(unsafe.Pointer(walCkptInfo(tls, pWal))).FnBackfill)
			}
		}
	}

	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		libc.Xmemset(tls, pWal+72, 0, uint64(unsafe.Sizeof(WalIndexHdr{})))
	}

	Xsqlite3WalEndWriteTransaction(tls, pWal)
	if (*Wal)(unsafe.Pointer(pWal)).FckptLock != 0 {
		walUnlockExclusive(tls, pWal, WAL_CKPT_LOCK, 1)
		(*Wal)(unsafe.Pointer(pWal)).FckptLock = U8(0)
	}

	return func() int32 {
		if rc == SQLITE_OK && eMode != eMode2 {
			return SQLITE_BUSY
		}
		return rc
	}()
}

func Xsqlite3WalCallback(tls *libc.TLS, pWal uintptr) int32 {
	var ret U32 = U32(0)
	if pWal != 0 {
		ret = (*Wal)(unsafe.Pointer(pWal)).FiCallback
		(*Wal)(unsafe.Pointer(pWal)).FiCallback = U32(0)
	}
	return int32(ret)
}

func Xsqlite3WalExclusiveMode(tls *libc.TLS, pWal uintptr, op int32) int32 {
	var rc int32

	if op == 0 {
		if int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) != WAL_NORMAL_MODE {
			(*Wal)(unsafe.Pointer(pWal)).FexclusiveMode = U8(WAL_NORMAL_MODE)
			if walLockShared(tls, pWal, 3+int32((*Wal)(unsafe.Pointer(pWal)).FreadLock)) != SQLITE_OK {
				(*Wal)(unsafe.Pointer(pWal)).FexclusiveMode = U8(WAL_EXCLUSIVE_MODE)
			}
			rc = libc.Bool32(int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_NORMAL_MODE)
		} else {
			rc = 0
		}
	} else if op > 0 {
		walUnlockShared(tls, pWal, 3+int32((*Wal)(unsafe.Pointer(pWal)).FreadLock))
		(*Wal)(unsafe.Pointer(pWal)).FexclusiveMode = U8(WAL_EXCLUSIVE_MODE)
		rc = 1
	} else {
		rc = libc.Bool32(int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_NORMAL_MODE)
	}
	return rc
}

func Xsqlite3WalHeapMemory(tls *libc.TLS, pWal uintptr) int32 {
	return libc.Bool32(pWal != 0 && int32((*Wal)(unsafe.Pointer(pWal)).FexclusiveMode) == WAL_HEAPMEMORY_MODE)
}

func Xsqlite3WalFile(tls *libc.TLS, pWal uintptr) uintptr {
	return (*Wal)(unsafe.Pointer(pWal)).FpWalFd
}

type MemPage1 = struct {
	FisInit          U8
	FintKey          U8
	FintKeyLeaf      U8
	F__ccgo_pad1     [1]byte
	Fpgno            Pgno
	Fleaf            U8
	FhdrOffset       U8
	FchildPtrSize    U8
	Fmax1bytePayload U8
	FnOverflow       U8
	F__ccgo_pad2     [1]byte
	FmaxLocal        U16
	FminLocal        U16
	FcellOffset      U16
	FnFree           int32
	FnCell           U16
	FmaskPage        U16
	FaiOvfl          [4]U16
	F__ccgo_pad3     [4]byte
	FapOvfl          [4]uintptr
	FpBt             uintptr
	FaData           uintptr
	FaDataEnd        uintptr
	FaCellIdx        uintptr
	FaDataOfst       uintptr
	FpDbPage         uintptr
	FxCellSize       uintptr
	FxParseCell      uintptr
}

type MemPage = MemPage1
type BtLock1 = struct {
	FpBtree      uintptr
	FiTable      Pgno
	FeLock       U8
	F__ccgo_pad1 [3]byte
	FpNext       uintptr
}

type BtLock = BtLock1
type CellInfo1 = struct {
	FnKey     I64
	FpPayload uintptr
	FnPayload U32
	FnLocal   U16
	FnSize    U16
}

type CellInfo = CellInfo1

type IntegrityCk1 = struct {
	FpBt         uintptr
	FpPager      uintptr
	FaPgRef      uintptr
	FnPage       Pgno
	FmxErr       int32
	FnErr        int32
	Frc          int32
	FnStep       U32
	F__ccgo_pad1 [4]byte
	FzPfx        uintptr
	Fv1          Pgno
	Fv2          int32
	FerrMsg      StrAccum
	Fheap        uintptr
	Fdb          uintptr
}

type IntegrityCk = IntegrityCk1

func lockBtreeMutex(tls *libc.TLS, p uintptr) {
	Xsqlite3_mutex_enter(tls, (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).Fmutex)
	(*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).Fdb = (*Btree)(unsafe.Pointer(p)).Fdb
	(*Btree)(unsafe.Pointer(p)).Flocked = U8(1)
}

func unlockBtreeMutex(tls *libc.TLS, p uintptr) {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3_mutex_leave(tls, (*BtShared)(unsafe.Pointer(pBt)).Fmutex)
	(*Btree)(unsafe.Pointer(p)).Flocked = U8(0)
}

func Xsqlite3BtreeEnter(tls *libc.TLS, p uintptr) {
	if !(int32((*Btree)(unsafe.Pointer(p)).Fsharable) != 0) {
		return
	}
	(*Btree)(unsafe.Pointer(p)).FwantToLock++
	if (*Btree)(unsafe.Pointer(p)).Flocked != 0 {
		return
	}
	btreeLockCarefully(tls, p)
}

func btreeLockCarefully(tls *libc.TLS, p uintptr) {
	var pLater uintptr

	if Xsqlite3_mutex_try(tls, (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).Fmutex) == SQLITE_OK {
		(*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).Fdb = (*Btree)(unsafe.Pointer(p)).Fdb
		(*Btree)(unsafe.Pointer(p)).Flocked = U8(1)
		return
	}

	for pLater = (*Btree)(unsafe.Pointer(p)).FpNext; pLater != 0; pLater = (*Btree)(unsafe.Pointer(pLater)).FpNext {
		if (*Btree)(unsafe.Pointer(pLater)).Flocked != 0 {
			unlockBtreeMutex(tls, pLater)
		}
	}
	lockBtreeMutex(tls, p)
	for pLater = (*Btree)(unsafe.Pointer(p)).FpNext; pLater != 0; pLater = (*Btree)(unsafe.Pointer(pLater)).FpNext {
		if (*Btree)(unsafe.Pointer(pLater)).FwantToLock != 0 {
			lockBtreeMutex(tls, pLater)
		}
	}
}

func Xsqlite3BtreeLeave(tls *libc.TLS, p uintptr) {
	if (*Btree)(unsafe.Pointer(p)).Fsharable != 0 {
		(*Btree)(unsafe.Pointer(p)).FwantToLock--
		if (*Btree)(unsafe.Pointer(p)).FwantToLock == 0 {
			unlockBtreeMutex(tls, p)
		}
	}
}

func btreeEnterAll(tls *libc.TLS, db uintptr) {
	var i int32
	var skipOk int32 = 1
	var p uintptr

	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		p = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if p != 0 && (*Btree)(unsafe.Pointer(p)).Fsharable != 0 {
			Xsqlite3BtreeEnter(tls, p)
			skipOk = 0
		}
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnoSharedCache = U8(skipOk)
}

func Xsqlite3BtreeEnterAll(tls *libc.TLS, db uintptr) {
	if int32((*Sqlite3)(unsafe.Pointer(db)).FnoSharedCache) == 0 {
		btreeEnterAll(tls, db)
	}
}

func btreeLeaveAll(tls *libc.TLS, db uintptr) {
	var i int32
	var p uintptr

	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		p = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if p != 0 {
			Xsqlite3BtreeLeave(tls, p)
		}
	}
}

func Xsqlite3BtreeLeaveAll(tls *libc.TLS, db uintptr) {
	if int32((*Sqlite3)(unsafe.Pointer(db)).FnoSharedCache) == 0 {
		btreeLeaveAll(tls, db)
	}
}

func Xsqlite3BtreeEnterCursor(tls *libc.TLS, pCur uintptr) {
	Xsqlite3BtreeEnter(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpBtree)
}

func Xsqlite3BtreeLeaveCursor(tls *libc.TLS, pCur uintptr) {
	Xsqlite3BtreeLeave(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpBtree)
}

var zMagicHeader = *(*[16]uint8)(unsafe.Pointer(ts + 6913))

var Xsqlite3SharedCacheList uintptr = uintptr(0)

func Xsqlite3_enable_shared_cache(tls *libc.TLS, enable int32) int32 {
	Xsqlite3Config.FsharedCacheEnabled = enable
	return SQLITE_OK
}

func querySharedCacheTableLock(tls *libc.TLS, p uintptr, iTab Pgno, eLock U8) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	var pIter uintptr

	if !(int32((*Btree)(unsafe.Pointer(p)).Fsharable) != 0) {
		return SQLITE_OK
	}

	if (*BtShared)(unsafe.Pointer(pBt)).FpWriter != p && int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_EXCLUSIVE != 0 {
		Xsqlite3ConnectionBlocked(tls, (*Btree)(unsafe.Pointer(p)).Fdb, (*Btree)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpWriter)).Fdb)
		return SQLITE_LOCKED | int32(1)<<8
	}

	for pIter = (*BtShared)(unsafe.Pointer(pBt)).FpLock; pIter != 0; pIter = (*BtLock)(unsafe.Pointer(pIter)).FpNext {
		if (*BtLock)(unsafe.Pointer(pIter)).FpBtree != p && (*BtLock)(unsafe.Pointer(pIter)).FiTable == iTab && int32((*BtLock)(unsafe.Pointer(pIter)).FeLock) != int32(eLock) {
			Xsqlite3ConnectionBlocked(tls, (*Btree)(unsafe.Pointer(p)).Fdb, (*Btree)(unsafe.Pointer((*BtLock)(unsafe.Pointer(pIter)).FpBtree)).Fdb)
			if int32(eLock) == WRITE_LOCK {
				*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_PENDING)
			}
			return SQLITE_LOCKED | int32(1)<<8
		}
	}
	return SQLITE_OK
}

func setSharedCacheTableLock(tls *libc.TLS, p uintptr, iTable Pgno, eLock U8) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	var pLock uintptr = uintptr(0)
	var pIter uintptr

	for pIter = (*BtShared)(unsafe.Pointer(pBt)).FpLock; pIter != 0; pIter = (*BtLock)(unsafe.Pointer(pIter)).FpNext {
		if (*BtLock)(unsafe.Pointer(pIter)).FiTable == iTable && (*BtLock)(unsafe.Pointer(pIter)).FpBtree == p {
			pLock = pIter
			break
		}
	}

	if !(pLock != 0) {
		pLock = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(BtLock{})))
		if !(pLock != 0) {
			return SQLITE_NOMEM
		}
		(*BtLock)(unsafe.Pointer(pLock)).FiTable = iTable
		(*BtLock)(unsafe.Pointer(pLock)).FpBtree = p
		(*BtLock)(unsafe.Pointer(pLock)).FpNext = (*BtShared)(unsafe.Pointer(pBt)).FpLock
		(*BtShared)(unsafe.Pointer(pBt)).FpLock = pLock
	}

	if int32(eLock) > int32((*BtLock)(unsafe.Pointer(pLock)).FeLock) {
		(*BtLock)(unsafe.Pointer(pLock)).FeLock = eLock
	}

	return SQLITE_OK
}

func clearAllSharedCacheTableLocks(tls *libc.TLS, p uintptr) {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	var ppIter uintptr = pBt + 120

	for *(*uintptr)(unsafe.Pointer(ppIter)) != 0 {
		var pLock uintptr = *(*uintptr)(unsafe.Pointer(ppIter))

		if (*BtLock)(unsafe.Pointer(pLock)).FpBtree == p {
			*(*uintptr)(unsafe.Pointer(ppIter)) = (*BtLock)(unsafe.Pointer(pLock)).FpNext

			if (*BtLock)(unsafe.Pointer(pLock)).FiTable != Pgno(1) {
				Xsqlite3_free(tls, pLock)
			}
		} else {
			ppIter = pLock + 16
		}
	}

	if (*BtShared)(unsafe.Pointer(pBt)).FpWriter == p {
		(*BtShared)(unsafe.Pointer(pBt)).FpWriter = uintptr(0)
		*(*U16)(unsafe.Pointer(pBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_EXCLUSIVE | BTS_PENDING))
	} else if (*BtShared)(unsafe.Pointer(pBt)).FnTransaction == 2 {
		*(*U16)(unsafe.Pointer(pBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_PENDING))
	}
}

func downgradeAllSharedCacheTableLocks(tls *libc.TLS, p uintptr) {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	if (*BtShared)(unsafe.Pointer(pBt)).FpWriter == p {
		var pLock uintptr
		(*BtShared)(unsafe.Pointer(pBt)).FpWriter = uintptr(0)
		*(*U16)(unsafe.Pointer(pBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_EXCLUSIVE | BTS_PENDING))
		for pLock = (*BtShared)(unsafe.Pointer(pBt)).FpLock; pLock != 0; pLock = (*BtLock)(unsafe.Pointer(pLock)).FpNext {
			(*BtLock)(unsafe.Pointer(pLock)).FeLock = U8(READ_LOCK)
		}
	}
}

func invalidateAllOverflowCache(tls *libc.TLS, pBt uintptr) {
	var p uintptr

	for p = (*BtShared)(unsafe.Pointer(pBt)).FpCursor; p != 0; p = (*BtCursor)(unsafe.Pointer(p)).FpNext {
		*(*U8)(unsafe.Pointer(p + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidOvfl))
	}
}

func invalidateIncrblobCursors(tls *libc.TLS, pBtree uintptr, pgnoRoot Pgno, iRow I64, isClearTable int32) {
	var p uintptr

	(*Btree)(unsafe.Pointer(pBtree)).FhasIncrblobCur = U8(0)
	for p = (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(pBtree)).FpBt)).FpCursor; p != 0; p = (*BtCursor)(unsafe.Pointer(p)).FpNext {
		if int32((*BtCursor)(unsafe.Pointer(p)).FcurFlags)&BTCF_Incrblob != 0 {
			(*Btree)(unsafe.Pointer(pBtree)).FhasIncrblobCur = U8(1)
			if (*BtCursor)(unsafe.Pointer(p)).FpgnoRoot == pgnoRoot && (isClearTable != 0 || (*BtCursor)(unsafe.Pointer(p)).Finfo.FnKey == iRow) {
				(*BtCursor)(unsafe.Pointer(p)).FeState = U8(CURSOR_INVALID)
			}
		}
	}
}

func btreeSetHasContent(tls *libc.TLS, pBt uintptr, pgno Pgno) int32 {
	var rc int32 = SQLITE_OK
	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FpHasContent) != 0) {
		(*BtShared)(unsafe.Pointer(pBt)).FpHasContent = Xsqlite3BitvecCreate(tls, (*BtShared)(unsafe.Pointer(pBt)).FnPage)
		if !(int32((*BtShared)(unsafe.Pointer(pBt)).FpHasContent) != 0) {
			rc = SQLITE_NOMEM
		}
	}
	if rc == SQLITE_OK && pgno <= Xsqlite3BitvecSize(tls, (*BtShared)(unsafe.Pointer(pBt)).FpHasContent) {
		rc = Xsqlite3BitvecSet(tls, (*BtShared)(unsafe.Pointer(pBt)).FpHasContent, pgno)
	}
	return rc
}

func btreeGetHasContent(tls *libc.TLS, pBt uintptr, pgno Pgno) int32 {
	var p uintptr = (*BtShared)(unsafe.Pointer(pBt)).FpHasContent
	return libc.Bool32(p != 0 && (pgno > Xsqlite3BitvecSize(tls, p) || Xsqlite3BitvecTestNotNull(tls, p, pgno) != 0))
}

func btreeClearHasContent(tls *libc.TLS, pBt uintptr) {
	Xsqlite3BitvecDestroy(tls, (*BtShared)(unsafe.Pointer(pBt)).FpHasContent)
	(*BtShared)(unsafe.Pointer(pBt)).FpHasContent = uintptr(0)
}

func btreeReleaseAllCursorPages(tls *libc.TLS, pCur uintptr) {
	var i int32
	if int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) >= 0 {
		for i = 0; i < int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage); i++ {
			releasePageNotNull(tls, *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr(i)*8)))
		}
		releasePageNotNull(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpPage)
		(*BtCursor)(unsafe.Pointer(pCur)).FiPage = int8(-1)
	}
}

func saveCursorKey(tls *libc.TLS, pCur uintptr) int32 {
	var rc int32 = SQLITE_OK

	if (*BtCursor)(unsafe.Pointer(pCur)).FcurIntKey != 0 {
		(*BtCursor)(unsafe.Pointer(pCur)).FnKey = Xsqlite3BtreeIntegerKey(tls, pCur)
	} else {
		var pKey uintptr
		(*BtCursor)(unsafe.Pointer(pCur)).FnKey = I64(Xsqlite3BtreePayloadSize(tls, pCur))
		pKey = Xsqlite3Malloc(tls, uint64((*BtCursor)(unsafe.Pointer(pCur)).FnKey+int64(9)+int64(8)))
		if pKey != 0 {
			rc = Xsqlite3BtreePayload(tls, pCur, uint32(0), uint32(int32((*BtCursor)(unsafe.Pointer(pCur)).FnKey)), pKey)
			if rc == SQLITE_OK {
				libc.Xmemset(tls, pKey+uintptr((*BtCursor)(unsafe.Pointer(pCur)).FnKey), 0, uint64(9+8))
				(*BtCursor)(unsafe.Pointer(pCur)).FpKey = pKey
			} else {
				Xsqlite3_free(tls, pKey)
			}
		} else {
			rc = SQLITE_NOMEM
		}
	}

	return rc
}

func saveCursorPosition(tls *libc.TLS, pCur uintptr) int32 {
	var rc int32

	if int32((*BtCursor)(unsafe.Pointer(pCur)).FcurFlags)&BTCF_Pinned != 0 {
		return SQLITE_CONSTRAINT | int32(11)<<8
	}
	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_SKIPNEXT {
		(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_VALID)
	} else {
		(*BtCursor)(unsafe.Pointer(pCur)).FskipNext = 0
	}

	rc = saveCursorKey(tls, pCur)
	if rc == SQLITE_OK {
		btreeReleaseAllCursorPages(tls, pCur)
		(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_REQUIRESEEK)
	}

	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidNKey | BTCF_ValidOvfl | BTCF_AtLast))
	return rc
}

func saveAllCursors(tls *libc.TLS, pBt uintptr, iRoot Pgno, pExcept uintptr) int32 {
	var p uintptr

	for p = (*BtShared)(unsafe.Pointer(pBt)).FpCursor; p != 0; p = (*BtCursor)(unsafe.Pointer(p)).FpNext {
		if p != pExcept && (Pgno(0) == iRoot || (*BtCursor)(unsafe.Pointer(p)).FpgnoRoot == iRoot) {
			break
		}
	}
	if p != 0 {
		return saveCursorsOnList(tls, p, iRoot, pExcept)
	}
	if pExcept != 0 {
		*(*U8)(unsafe.Pointer(pExcept + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_Multiple))
	}
	return SQLITE_OK
}

func saveCursorsOnList(tls *libc.TLS, p uintptr, iRoot Pgno, pExcept uintptr) int32 {
	for __ccgo := true; __ccgo; __ccgo = p != 0 {
		if p != pExcept && (Pgno(0) == iRoot || (*BtCursor)(unsafe.Pointer(p)).FpgnoRoot == iRoot) {
			if int32((*BtCursor)(unsafe.Pointer(p)).FeState) == CURSOR_VALID || int32((*BtCursor)(unsafe.Pointer(p)).FeState) == CURSOR_SKIPNEXT {
				var rc int32 = saveCursorPosition(tls, p)
				if SQLITE_OK != rc {
					return rc
				}
			} else {
				btreeReleaseAllCursorPages(tls, p)
			}
		}
		p = (*BtCursor)(unsafe.Pointer(p)).FpNext
	}
	return SQLITE_OK
}

func Xsqlite3BtreeClearCursor(tls *libc.TLS, pCur uintptr) {
	Xsqlite3_free(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpKey)
	(*BtCursor)(unsafe.Pointer(pCur)).FpKey = uintptr(0)
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
}

func btreeMoveto(tls *libc.TLS, pCur uintptr, pKey uintptr, nKey I64, bias int32, pRes uintptr) int32 {
	var rc int32
	var pIdxKey uintptr

	if pKey != 0 {
		var pKeyInfo uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpKeyInfo

		pIdxKey = Xsqlite3VdbeAllocUnpackedRecord(tls, pKeyInfo)
		if pIdxKey == uintptr(0) {
			return SQLITE_NOMEM
		}
		Xsqlite3VdbeRecordUnpack(tls, pKeyInfo, int32(nKey), pKey, pIdxKey)
		if int32((*UnpackedRecord)(unsafe.Pointer(pIdxKey)).FnField) == 0 || int32((*UnpackedRecord)(unsafe.Pointer(pIdxKey)).FnField) > int32((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnAllField) {
			rc = Xsqlite3CorruptError(tls, 69253)
		} else {
			rc = Xsqlite3BtreeIndexMoveto(tls, pCur, pIdxKey, pRes)
		}
		Xsqlite3DbFree(tls, (*KeyInfo1)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpKeyInfo)).Fdb, pIdxKey)
	} else {
		pIdxKey = uintptr(0)
		rc = Xsqlite3BtreeTableMoveto(tls, pCur, nKey, bias, pRes)
	}
	return rc
}

func btreeRestoreCursorPosition(tls *libc.TLS, pCur uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32
	*(*int32)(unsafe.Pointer(bp)) = 0

	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_FAULT {
		return (*BtCursor)(unsafe.Pointer(pCur)).FskipNext
	}
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
	if Xsqlite3FaultSim(tls, 410) != 0 {
		rc = SQLITE_IOERR
	} else {
		rc = btreeMoveto(tls, pCur, (*BtCursor)(unsafe.Pointer(pCur)).FpKey, (*BtCursor)(unsafe.Pointer(pCur)).FnKey, 0, bp)
	}
	if rc == SQLITE_OK {
		Xsqlite3_free(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpKey)
		(*BtCursor)(unsafe.Pointer(pCur)).FpKey = uintptr(0)

		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			(*BtCursor)(unsafe.Pointer(pCur)).FskipNext = *(*int32)(unsafe.Pointer(bp))
		}
		if (*BtCursor)(unsafe.Pointer(pCur)).FskipNext != 0 && int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID {
			(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_SKIPNEXT)
		}
	}
	return rc
}

func Xsqlite3BtreeCursorHasMoved(tls *libc.TLS, pCur uintptr) int32 {
	return libc.Bool32(CURSOR_VALID != int32(*(*U8)(unsafe.Pointer(pCur))))
}

func Xsqlite3BtreeFakeValidCursor(tls *libc.TLS) uintptr {
	return uintptr(unsafe.Pointer(&fakeCursor))
}

var fakeCursor U8 = U8(CURSOR_VALID)

func Xsqlite3BtreeCursorRestore(tls *libc.TLS, pCur uintptr, pDifferentRow uintptr) int32 {
	var rc int32

	rc = func() int32 {
		if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) >= CURSOR_REQUIRESEEK {
			return btreeRestoreCursorPosition(tls, pCur)
		}
		return SQLITE_OK
	}()
	if rc != 0 {
		*(*int32)(unsafe.Pointer(pDifferentRow)) = 1
		return rc
	}
	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		*(*int32)(unsafe.Pointer(pDifferentRow)) = 1
	} else {
		*(*int32)(unsafe.Pointer(pDifferentRow)) = 0
	}
	return SQLITE_OK
}

func Xsqlite3BtreeCursorHintFlags(tls *libc.TLS, pCur uintptr, x uint32) {
	(*BtCursor)(unsafe.Pointer(pCur)).Fhints = U8(x)
}

func ptrmapPageno(tls *libc.TLS, pBt uintptr, pgno Pgno) Pgno {
	var nPagesPerMapPage int32
	var iPtrMap Pgno
	var ret Pgno

	if pgno < Pgno(2) {
		return Pgno(0)
	}
	nPagesPerMapPage = int32((*BtShared)(unsafe.Pointer(pBt)).FusableSize/U32(5) + U32(1))
	iPtrMap = (pgno - Pgno(2)) / Pgno(nPagesPerMapPage)
	ret = iPtrMap*Pgno(nPagesPerMapPage) + Pgno(2)
	if ret == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) {
		ret++
	}
	return ret
}

func ptrmapPut(tls *libc.TLS, pBt uintptr, key Pgno, eType U8, parent Pgno, pRC uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pPtrmap uintptr
	var iPtrmap Pgno
	var offset int32
	var rc int32

	if !(*(*int32)(unsafe.Pointer(pRC)) != 0) {
		goto __1
	}
	return
__1:
	;
	if !(key == Pgno(0)) {
		goto __2
	}
	*(*int32)(unsafe.Pointer(pRC)) = Xsqlite3CorruptError(tls, 69434)
	return
__2:
	;
	iPtrmap = ptrmapPageno(tls, pBt, key)
	rc = Xsqlite3PagerGet(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, iPtrmap, bp, 0)
	if !(rc != SQLITE_OK) {
		goto __3
	}
	*(*int32)(unsafe.Pointer(pRC)) = rc
	return
__3:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(Xsqlite3PagerGetExtra(tls, *(*uintptr)(unsafe.Pointer(bp)))))) != 0) {
		goto __4
	}

	*(*int32)(unsafe.Pointer(pRC)) = Xsqlite3CorruptError(tls, 69447)
	goto ptrmap_exit
__4:
	;
	offset = int32(Pgno(5) * (key - iPtrmap - Pgno(1)))
	if !(offset < 0) {
		goto __5
	}
	*(*int32)(unsafe.Pointer(pRC)) = Xsqlite3CorruptError(tls, 69452)
	goto ptrmap_exit
__5:
	;
	pPtrmap = Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))

	if !(int32(eType) != int32(*(*U8)(unsafe.Pointer(pPtrmap + uintptr(offset)))) || Xsqlite3Get4byte(tls, pPtrmap+uintptr(offset+1)) != parent) {
		goto __6
	}

	*(*int32)(unsafe.Pointer(pRC)) = libc.AssignInt32(&rc, Xsqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp))))
	if !(rc == SQLITE_OK) {
		goto __7
	}
	*(*U8)(unsafe.Pointer(pPtrmap + uintptr(offset))) = eType
	Xsqlite3Put4byte(tls, pPtrmap+uintptr(offset+1), parent)
__7:
	;
__6:
	;
ptrmap_exit:
	Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func ptrmapGet(tls *libc.TLS, pBt uintptr, key Pgno, pEType uintptr, pPgno uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var iPtrmap int32
	var pPtrmap uintptr
	var offset int32
	var rc int32

	iPtrmap = int32(ptrmapPageno(tls, pBt, key))
	rc = Xsqlite3PagerGet(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, uint32(iPtrmap), bp, 0)
	if rc != 0 {
		return rc
	}
	pPtrmap = Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))

	offset = int32(Pgno(5) * (key - Pgno(iPtrmap) - Pgno(1)))
	if offset < 0 {
		Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return Xsqlite3CorruptError(tls, 69497)
	}

	*(*U8)(unsafe.Pointer(pEType)) = *(*U8)(unsafe.Pointer(pPtrmap + uintptr(offset)))
	if pPgno != 0 {
		*(*Pgno)(unsafe.Pointer(pPgno)) = Xsqlite3Get4byte(tls, pPtrmap+uintptr(offset+1))
	}

	Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if int32(*(*U8)(unsafe.Pointer(pEType))) < 1 || int32(*(*U8)(unsafe.Pointer(pEType))) > 5 {
		return Xsqlite3CorruptError(tls, 69505)
	}
	return SQLITE_OK
}

func btreeParseCellAdjustSizeForOverflow(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) {
	var minLocal int32
	var maxLocal int32
	var surplus int32

	minLocal = int32((*MemPage)(unsafe.Pointer(pPage)).FminLocal)
	maxLocal = int32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal)
	surplus = int32(U32(minLocal) + ((*CellInfo)(unsafe.Pointer(pInfo)).FnPayload-U32(minLocal))%((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-U32(4)))

	if surplus <= maxLocal {
		(*CellInfo)(unsafe.Pointer(pInfo)).FnLocal = U16(surplus)
	} else {
		(*CellInfo)(unsafe.Pointer(pInfo)).FnLocal = U16(minLocal)
	}
	(*CellInfo)(unsafe.Pointer(pInfo)).FnSize = U16(int32(U16((int64((*CellInfo)(unsafe.Pointer(pInfo)).FpPayload+uintptr((*CellInfo)(unsafe.Pointer(pInfo)).FnLocal))-int64(pCell))/1)) + 4)
}

func btreePayloadToLocal(tls *libc.TLS, pPage uintptr, nPayload I64) int32 {
	var maxLocal int32
	maxLocal = int32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal)
	if nPayload <= I64(maxLocal) {
		return int32(nPayload)
	} else {
		var minLocal int32
		var surplus int32
		minLocal = int32((*MemPage)(unsafe.Pointer(pPage)).FminLocal)
		surplus = int32(I64(minLocal) + (nPayload-I64(minLocal))%I64((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-U32(4)))
		if surplus <= maxLocal {
			return surplus
		}
		return minLocal
	}
	return int32(0)
}

func btreeParseCellPtrNoPayload(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) {
	_ = pPage
	(*CellInfo)(unsafe.Pointer(pInfo)).FnSize = U16(4 + int32(Xsqlite3GetVarint(tls, pCell+4, pInfo)))
	(*CellInfo)(unsafe.Pointer(pInfo)).FnPayload = U32(0)
	(*CellInfo)(unsafe.Pointer(pInfo)).FnLocal = U16(0)
	(*CellInfo)(unsafe.Pointer(pInfo)).FpPayload = uintptr(0)
	return
}

func btreeParseCellPtr(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pIter uintptr
	var nPayload U32

	pIter = pCell

	nPayload = U32(*(*U8)(unsafe.Pointer(pIter)))
	if nPayload >= U32(0x80) {
		var pEnd uintptr = pIter + 8
		nPayload = nPayload & U32(0x7f)
		for __ccgo := true; __ccgo; __ccgo = int32(*(*U8)(unsafe.Pointer(pIter))) >= 0x80 && pIter < pEnd {
			nPayload = nPayload<<7 | U32(int32(*(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1))))&0x7f)
		}
	}
	pIter++

	*(*U64)(unsafe.Pointer(bp)) = U64(*(*U8)(unsafe.Pointer(pIter)))
	if *(*U64)(unsafe.Pointer(bp)) >= uint64(0x80) {
		var x U8
		*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))&uint64(0x7f)<<7 | U64(int32(libc.AssignUint8(&x, *(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1)))))&0x7f)
		if int32(x) >= 0x80 {
			*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))<<7 | U64(int32(libc.AssignUint8(&x, *(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1)))))&0x7f)
			if int32(x) >= 0x80 {
				*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))<<7 | U64(int32(libc.AssignUint8(&x, *(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1)))))&0x7f)
				if int32(x) >= 0x80 {
					*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))<<7 | U64(int32(libc.AssignUint8(&x, *(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1)))))&0x7f)
					if int32(x) >= 0x80 {
						*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))<<7 | U64(int32(libc.AssignUint8(&x, *(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1)))))&0x7f)
						if int32(x) >= 0x80 {
							*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))<<7 | U64(int32(libc.AssignUint8(&x, *(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1)))))&0x7f)
							if int32(x) >= 0x80 {
								*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))<<7 | U64(int32(libc.AssignUint8(&x, *(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1)))))&0x7f)
								if int32(x) >= 0x80 {
									*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))<<8 | U64(*(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1))))
								}
							}
						}
					}
				}
			}
		}
	}
	pIter++

	(*CellInfo)(unsafe.Pointer(pInfo)).FnKey = *(*I64)(unsafe.Pointer(bp))
	(*CellInfo)(unsafe.Pointer(pInfo)).FnPayload = nPayload
	(*CellInfo)(unsafe.Pointer(pInfo)).FpPayload = pIter

	if nPayload <= U32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		(*CellInfo)(unsafe.Pointer(pInfo)).FnSize = U16(nPayload + U32(U16((int64(pIter)-int64(pCell))/1)))
		if int32((*CellInfo)(unsafe.Pointer(pInfo)).FnSize) < 4 {
			(*CellInfo)(unsafe.Pointer(pInfo)).FnSize = U16(4)
		}
		(*CellInfo)(unsafe.Pointer(pInfo)).FnLocal = U16(nPayload)
	} else {
		btreeParseCellAdjustSizeForOverflow(tls, pPage, pCell, pInfo)
	}
}

func btreeParseCellPtrIndex(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) {
	var pIter uintptr
	var nPayload U32

	pIter = pCell + uintptr((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	nPayload = U32(*(*U8)(unsafe.Pointer(pIter)))
	if nPayload >= U32(0x80) {
		var pEnd uintptr = pIter + 8
		nPayload = nPayload & U32(0x7f)
		for __ccgo := true; __ccgo; __ccgo = int32(*(*U8)(unsafe.Pointer(pIter))) >= 0x80 && pIter < pEnd {
			nPayload = nPayload<<7 | U32(int32(*(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1))))&0x7f)
		}
	}
	pIter++
	(*CellInfo)(unsafe.Pointer(pInfo)).FnKey = I64(nPayload)
	(*CellInfo)(unsafe.Pointer(pInfo)).FnPayload = nPayload
	(*CellInfo)(unsafe.Pointer(pInfo)).FpPayload = pIter

	if nPayload <= U32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		(*CellInfo)(unsafe.Pointer(pInfo)).FnSize = U16(nPayload + U32(U16((int64(pIter)-int64(pCell))/1)))
		if int32((*CellInfo)(unsafe.Pointer(pInfo)).FnSize) < 4 {
			(*CellInfo)(unsafe.Pointer(pInfo)).FnSize = U16(4)
		}
		(*CellInfo)(unsafe.Pointer(pInfo)).FnLocal = U16(nPayload)
	} else {
		btreeParseCellAdjustSizeForOverflow(tls, pPage, pCell, pInfo)
	}
}

func btreeParseCell(tls *libc.TLS, pPage uintptr, iCell int32, pInfo uintptr) {
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxParseCell})).f(tls, pPage, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*iCell)))))), pInfo)
}

func cellSizePtr(tls *libc.TLS, pPage uintptr, pCell uintptr) U16 {
	var pIter uintptr = pCell + uintptr((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	var pEnd uintptr
	var nSize U32

	nSize = U32(*(*U8)(unsafe.Pointer(pIter)))
	if nSize >= U32(0x80) {
		pEnd = pIter + 8
		nSize = nSize & U32(0x7f)
		for __ccgo := true; __ccgo; __ccgo = int32(*(*U8)(unsafe.Pointer(pIter))) >= 0x80 && pIter < pEnd {
			nSize = nSize<<7 | U32(int32(*(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1))))&0x7f)
		}
	}
	pIter++

	if nSize <= U32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		nSize = nSize + U32((int64(pIter)-int64(pCell))/1)
		if nSize < U32(4) {
			nSize = U32(4)
		}
	} else {
		var minLocal int32 = int32((*MemPage)(unsafe.Pointer(pPage)).FminLocal)
		nSize = U32(minLocal) + (nSize-U32(minLocal))%((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-U32(4))

		if nSize > U32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
			nSize = U32(minLocal)
		}
		nSize = nSize + U32(4+int32(U16((int64(pIter)-int64(pCell))/1)))
	}

	return U16(nSize)
}

func cellSizePtrNoPayload(tls *libc.TLS, pPage uintptr, pCell uintptr) U16 {
	var pIter uintptr = pCell + uintptr(4)
	var pEnd uintptr

	_ = pPage

	pEnd = pIter + uintptr(9)
	for int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 && pIter < pEnd {
	}

	return U16((int64(pIter) - int64(pCell)) / 1)
}

func cellSizePtrTableLeaf(tls *libc.TLS, pPage uintptr, pCell uintptr) U16 {
	var pIter uintptr = pCell
	var pEnd uintptr
	var nSize U32

	nSize = U32(*(*U8)(unsafe.Pointer(pIter)))
	if nSize >= U32(0x80) {
		pEnd = pIter + 8
		nSize = nSize & U32(0x7f)
		for __ccgo := true; __ccgo; __ccgo = int32(*(*U8)(unsafe.Pointer(pIter))) >= 0x80 && pIter < pEnd {
			nSize = nSize<<7 | U32(int32(*(*U8)(unsafe.Pointer(libc.PreIncUintptr(&pIter, 1))))&0x7f)
		}
	}
	pIter++

	if int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 &&
		int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 &&
		int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 &&
		int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 &&
		int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 &&
		int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 &&
		int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 &&
		int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pIter, 1))))&0x80 != 0 {
		pIter++
	}

	if nSize <= U32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		nSize = nSize + U32((int64(pIter)-int64(pCell))/1)
		if nSize < U32(4) {
			nSize = U32(4)
		}
	} else {
		var minLocal int32 = int32((*MemPage)(unsafe.Pointer(pPage)).FminLocal)
		nSize = U32(minLocal) + (nSize-U32(minLocal))%((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-U32(4))

		if nSize > U32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
			nSize = U32(minLocal)
		}
		nSize = nSize + U32(4+int32(U16((int64(pIter)-int64(pCell))/1)))
	}

	return U16(nSize)
}

func ptrmapPutOvflPtr(tls *libc.TLS, pPage uintptr, pSrc uintptr, pCell uintptr, pRC uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	if *(*int32)(unsafe.Pointer(pRC)) != 0 {
		return
	}

	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxParseCell})).f(tls, pPage, pCell, bp)
	if U32((*CellInfo)(unsafe.Pointer(bp)).FnLocal) < (*CellInfo)(unsafe.Pointer(bp)).FnPayload {
		var ovfl Pgno
		if Uptr((*MemPage)(unsafe.Pointer(pSrc)).FaDataEnd) >= Uptr(pCell) && Uptr((*MemPage)(unsafe.Pointer(pSrc)).FaDataEnd) < Uptr(pCell+uintptr((*CellInfo)(unsafe.Pointer(bp)).FnLocal)) {
			*(*int32)(unsafe.Pointer(pRC)) = Xsqlite3CorruptError(tls, 69897)
			return
		}
		ovfl = Xsqlite3Get4byte(tls, pCell+uintptr(int32((*CellInfo)(unsafe.Pointer(bp)).FnSize)-4))
		ptrmapPut(tls, (*MemPage)(unsafe.Pointer(pPage)).FpBt, ovfl, uint8(PTRMAP_OVERFLOW1), (*MemPage)(unsafe.Pointer(pPage)).Fpgno, pRC)
	}
}

func defragmentPage(tls *libc.TLS, pPage uintptr, nMaxFrag int32) int32 {
	var i int32
	var pc int32
	var hdr int32
	var size int32
	var usableSize int32
	var cellOffset int32
	var cbrk int32
	var nCell int32
	var data uintptr
	var temp uintptr
	var src uintptr
	var iCellFirst int32
	var iCellLast int32
	var iCellStart int32
	var pEnd uintptr
	var pAddr uintptr
	var sz2 int32
	var sz int32
	var top int32
	var iFree2 int32
	var iFree int32
	var pAddr1 uintptr

	data = (*MemPage)(unsafe.Pointer(pPage)).FaData
	hdr = int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)
	cellOffset = int32((*MemPage)(unsafe.Pointer(pPage)).FcellOffset)
	nCell = int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)

	iCellFirst = cellOffset + 2*nCell
	usableSize = int32((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)

	if !(int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+7)))) <= nMaxFrag) {
		goto __1
	}
	iFree = int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+1))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+1) + 1)))
	if !(iFree > usableSize-4) {
		goto __2
	}
	return Xsqlite3CorruptError(tls, 69955)
__2:
	;
	if !(iFree != 0) {
		goto __3
	}
	iFree2 = int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree) + 1)))
	if !(iFree2 > usableSize-4) {
		goto __4
	}
	return Xsqlite3CorruptError(tls, 69958)
__4:
	;
	if !(0 == iFree2 || int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree2)))) == 0 && int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree2+1)))) == 0) {
		goto __5
	}
	pEnd = data + uintptr(cellOffset+nCell*2)
	sz2 = 0
	sz = int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree+2))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree+2) + 1)))
	top = int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+5))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+5) + 1)))
	if !(top >= iFree) {
		goto __6
	}
	return Xsqlite3CorruptError(tls, 69966)
__6:
	;
	if !(iFree2 != 0) {
		goto __7
	}
	if !(iFree+sz > iFree2) {
		goto __9
	}
	return Xsqlite3CorruptError(tls, 69969)
__9:
	;
	sz2 = int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree2+2))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFree2+2) + 1)))
	if !(iFree2+sz2 > usableSize) {
		goto __10
	}
	return Xsqlite3CorruptError(tls, 69971)
__10:
	;
	libc.Xmemmove(tls, data+uintptr(iFree+sz+sz2), data+uintptr(iFree+sz), uint64(iFree2-(iFree+sz)))
	sz = sz + sz2
	goto __8
__7:
	if !(iFree+sz > usableSize) {
		goto __11
	}
	return Xsqlite3CorruptError(tls, 69975)
__11:
	;
__8:
	;
	cbrk = top + sz

	libc.Xmemmove(tls, data+uintptr(cbrk), data+uintptr(top), uint64(iFree-top))
	pAddr = data + uintptr(cellOffset)
__12:
	if !(pAddr < pEnd) {
		goto __14
	}
	pc = int32(*(*U8)(unsafe.Pointer(pAddr)))<<8 | int32(*(*U8)(unsafe.Pointer(pAddr + 1)))
	if !(pc < iFree) {
		goto __15
	}
	*(*U8)(unsafe.Pointer(pAddr)) = U8((pc + sz) >> 8)
	*(*U8)(unsafe.Pointer(pAddr + 1)) = U8(pc + sz)
	goto __16
__15:
	if !(pc < iFree2) {
		goto __17
	}
	*(*U8)(unsafe.Pointer(pAddr)) = U8((pc + sz2) >> 8)
	*(*U8)(unsafe.Pointer(pAddr + 1)) = U8(pc + sz2)
__17:
	;
__16:
	;
	goto __13
__13:
	pAddr += uintptr(2)
	goto __12
	goto __14
__14:
	;
	goto defragment_out
__5:
	;
__3:
	;
__1:
	;
	cbrk = usableSize
	iCellLast = usableSize - 4
	iCellStart = int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+5))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+5) + 1)))
	if !(nCell > 0) {
		goto __18
	}
	temp = Xsqlite3PagerTempSpace(tls, (*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FpPager)
	libc.Xmemcpy(tls, temp+uintptr(iCellStart), data+uintptr(iCellStart), uint64(usableSize-iCellStart))
	src = temp
	i = 0
__19:
	if !(i < nCell) {
		goto __21
	}
	pAddr1 = data + uintptr(cellOffset+i*2)
	pc = int32(*(*U8)(unsafe.Pointer(pAddr1)))<<8 | int32(*(*U8)(unsafe.Pointer(pAddr1 + 1)))

	if !(pc < iCellStart || pc > iCellLast) {
		goto __22
	}
	return Xsqlite3CorruptError(tls, 70008)
__22:
	;
	size = int32((*struct {
		f func(*libc.TLS, uintptr, uintptr) U16
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxCellSize})).f(tls, pPage, src+uintptr(pc)))
	cbrk = cbrk - size
	if !(cbrk < iCellStart || pc+size > usableSize) {
		goto __23
	}
	return Xsqlite3CorruptError(tls, 70014)
__23:
	;
	*(*U8)(unsafe.Pointer(pAddr1)) = U8(cbrk >> 8)
	*(*U8)(unsafe.Pointer(pAddr1 + 1)) = U8(cbrk)
	libc.Xmemcpy(tls, data+uintptr(cbrk), src+uintptr(pc), uint64(size))
	goto __20
__20:
	i++
	goto __19
	goto __21
__21:
	;
__18:
	;
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+7))) = uint8(0)

defragment_out:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(data + uintptr(hdr+7))))+cbrk-iCellFirst != (*MemPage)(unsafe.Pointer(pPage)).FnFree) {
		goto __24
	}
	return Xsqlite3CorruptError(tls, 70028)
__24:
	;
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+5))) = U8(cbrk >> 8)
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+5) + 1)) = U8(cbrk)
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+1))) = uint8(0)
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr+2))) = uint8(0)
	libc.Xmemset(tls, data+uintptr(iCellFirst), 0, uint64(cbrk-iCellFirst))

	return SQLITE_OK
}

func pageFindSlot(tls *libc.TLS, pPg uintptr, nByte int32, pRc uintptr) uintptr {
	var hdr int32 = int32((*MemPage)(unsafe.Pointer(pPg)).FhdrOffset)
	var aData uintptr = (*MemPage)(unsafe.Pointer(pPg)).FaData
	var iAddr int32 = hdr + 1
	var pTmp uintptr = aData + uintptr(iAddr)
	var pc int32 = int32(*(*U8)(unsafe.Pointer(pTmp)))<<8 | int32(*(*U8)(unsafe.Pointer(pTmp + 1)))
	var x int32
	var maxPC int32 = int32((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPg)).FpBt)).FusableSize - U32(nByte))
	var size int32

	for pc <= maxPC {
		pTmp = aData + uintptr(pc+2)
		size = int32(*(*U8)(unsafe.Pointer(pTmp)))<<8 | int32(*(*U8)(unsafe.Pointer(pTmp + 1)))
		if libc.AssignInt32(&x, size-nByte) >= 0 {
			if x < 4 {
				if int32(*(*U8)(unsafe.Pointer(aData + uintptr(hdr+7)))) > 57 {
					return uintptr(0)
				}

				libc.Xmemcpy(tls, aData+uintptr(iAddr), aData+uintptr(pc), uint64(2))
				*(*U8)(unsafe.Pointer(aData + uintptr(hdr+7))) += U8(int32(U8(x)))
				return aData + uintptr(pc)
			} else if x+pc > maxPC {
				*(*int32)(unsafe.Pointer(pRc)) = Xsqlite3CorruptError(tls, 70085)
				return uintptr(0)
			} else {
				*(*U8)(unsafe.Pointer(aData + uintptr(pc+2))) = U8(x >> 8)
				*(*U8)(unsafe.Pointer(aData + uintptr(pc+2) + 1)) = U8(x)
			}
			return aData + uintptr(pc+x)
		}
		iAddr = pc
		pTmp = aData + uintptr(pc)
		pc = int32(*(*U8)(unsafe.Pointer(pTmp)))<<8 | int32(*(*U8)(unsafe.Pointer(pTmp + 1)))
		if pc <= iAddr {
			if pc != 0 {
				*(*int32)(unsafe.Pointer(pRc)) = Xsqlite3CorruptError(tls, 70100)
			}
			return uintptr(0)
		}
	}
	if pc > maxPC+nByte-4 {
		*(*int32)(unsafe.Pointer(pRc)) = Xsqlite3CorruptError(tls, 70107)
	}
	return uintptr(0)
}

func allocateSpace(tls *libc.TLS, pPage uintptr, nByte int32, pIdx uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var hdr int32 = int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)
	var data uintptr = (*MemPage)(unsafe.Pointer(pPage)).FaData
	var top int32
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var pTmp uintptr
	var gap int32

	gap = int32((*MemPage)(unsafe.Pointer(pPage)).FcellOffset) + 2*int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)

	pTmp = data + uintptr(hdr+5)
	top = int32(*(*U8)(unsafe.Pointer(pTmp)))<<8 | int32(*(*U8)(unsafe.Pointer(pTmp + 1)))

	if gap > top {
		if top == 0 && (*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize == U32(65536) {
			top = 65536
		} else {
			return Xsqlite3CorruptError(tls, 70156)
		}
	}

	if (*(*U8)(unsafe.Pointer(data + uintptr(hdr+2))) != 0 || *(*U8)(unsafe.Pointer(data + uintptr(hdr+1))) != 0) && gap+2 <= top {
		var pSpace uintptr = pageFindSlot(tls, pPage, nByte, bp)
		if pSpace != 0 {
			var g2 int32

			*(*int32)(unsafe.Pointer(pIdx)) = libc.AssignInt32(&g2, int32((int64(pSpace)-int64(data))/1))
			if g2 <= gap {
				return Xsqlite3CorruptError(tls, 70174)
			} else {
				return SQLITE_OK
			}
		} else if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(bp))
		}
	}

	if gap+2+nByte > top {
		*(*int32)(unsafe.Pointer(bp)) = defragmentPage(tls, pPage, func() int32 {
			if 4 < (*MemPage)(unsafe.Pointer(pPage)).FnFree-(2+nByte) {
				return 4
			}
			return (*MemPage)(unsafe.Pointer(pPage)).FnFree - (2 + nByte)
		}())
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(bp))
		}
		top = (int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+5))))<<8|int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+5) + 1)))-1)&0xffff + 1

	}

	top = top - nByte
	*(*U8)(unsafe.Pointer(data + uintptr(hdr+5))) = U8(top >> 8)
	*(*U8)(unsafe.Pointer(data + uintptr(hdr+5) + 1)) = U8(top)

	*(*int32)(unsafe.Pointer(pIdx)) = top
	return SQLITE_OK
}

func freeSpace(tls *libc.TLS, pPage uintptr, iStart U16, iSize U16) int32 {
	var iPtr U16
	var iFreeBlk U16
	var hdr U8
	var nFrag U8 = U8(0)
	var iOrigSize U16 = iSize
	var x U16
	var iEnd U32 = U32(int32(iStart) + int32(iSize))
	var data uintptr = (*MemPage)(unsafe.Pointer(pPage)).FaData
	var pTmp uintptr

	hdr = (*MemPage)(unsafe.Pointer(pPage)).FhdrOffset
	iPtr = U16(int32(hdr) + 1)
	if int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(iPtr)+1)))) == 0 && int32(*(*uint8)(unsafe.Pointer(data + uintptr(iPtr)))) == 0 {
		iFreeBlk = U16(0)
	} else {
		for int32(libc.AssignUint16(&iFreeBlk, U16(int32(*(*uint8)(unsafe.Pointer(data + uintptr(iPtr))))<<8|int32(*(*uint8)(unsafe.Pointer(data + uintptr(iPtr) + 1)))))) < int32(iStart) {
			if int32(iFreeBlk) <= int32(iPtr) {
				if int32(iFreeBlk) == 0 {
					break
				}
				return Xsqlite3CorruptError(tls, 70253)
			}
			iPtr = iFreeBlk
		}
		if U32(iFreeBlk) > (*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-U32(4) {
			return Xsqlite3CorruptError(tls, 70258)
		}

		if iFreeBlk != 0 && iEnd+U32(3) >= U32(iFreeBlk) {
			nFrag = U8(U32(iFreeBlk) - iEnd)
			if iEnd > U32(iFreeBlk) {
				return Xsqlite3CorruptError(tls, 70270)
			}
			iEnd = U32(int32(iFreeBlk) + (int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(iFreeBlk)+2))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(iFreeBlk)+2) + 1)))))
			if iEnd > (*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize {
				return Xsqlite3CorruptError(tls, 70273)
			}
			iSize = U16(iEnd - U32(iStart))
			iFreeBlk = U16(int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFreeBlk))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(iFreeBlk) + 1))))
		}

		if int32(iPtr) > int32(hdr)+1 {
			var iPtrEnd int32 = int32(iPtr) + (int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(iPtr)+2))))<<8 | int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(iPtr)+2) + 1))))
			if iPtrEnd+3 >= int32(iStart) {
				if iPtrEnd > int32(iStart) {
					return Xsqlite3CorruptError(tls, 70286)
				}
				nFrag = U8(int32(nFrag) + (int32(iStart) - iPtrEnd))
				iSize = U16(iEnd - U32(iPtr))
				iStart = iPtr
			}
		}
		if int32(nFrag) > int32(*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+7)))) {
			return Xsqlite3CorruptError(tls, 70292)
		}
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+7))) -= uint8(int32(nFrag))
	}
	pTmp = data + uintptr(int32(hdr)+5)
	x = U16(int32(*(*U8)(unsafe.Pointer(pTmp)))<<8 | int32(*(*U8)(unsafe.Pointer(pTmp + 1))))
	if int32(iStart) <= int32(x) {
		if int32(iStart) < int32(x) {
			return Xsqlite3CorruptError(tls, 70301)
		}
		if int32(iPtr) != int32(hdr)+1 {
			return Xsqlite3CorruptError(tls, 70302)
		}
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+1))) = U8(int32(iFreeBlk) >> 8)
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+1) + 1)) = U8(iFreeBlk)
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+5))) = U8(iEnd >> 8)
		*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+5) + 1)) = U8(iEnd)
	} else {
		*(*uint8)(unsafe.Pointer(data + uintptr(iPtr))) = U8(int32(iStart) >> 8)
		*(*uint8)(unsafe.Pointer(data + uintptr(iPtr) + 1)) = U8(iStart)
	}
	if int32((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FbtsFlags)&BTS_FAST_SECURE != 0 {
		libc.Xmemset(tls, data+uintptr(iStart), 0, uint64(iSize))
	}
	*(*uint8)(unsafe.Pointer(data + uintptr(iStart))) = U8(int32(iFreeBlk) >> 8)
	*(*uint8)(unsafe.Pointer(data + uintptr(iStart) + 1)) = U8(iFreeBlk)
	*(*uint8)(unsafe.Pointer(data + uintptr(int32(iStart)+2))) = U8(int32(iSize) >> 8)
	*(*uint8)(unsafe.Pointer(data + uintptr(int32(iStart)+2) + 1)) = U8(iSize)
	*(*int32)(unsafe.Pointer(pPage + 20)) += int32(iOrigSize)
	return SQLITE_OK
}

func decodeFlags(tls *libc.TLS, pPage uintptr, flagByte int32) int32 {
	var pBt uintptr

	pBt = (*MemPage)(unsafe.Pointer(pPage)).FpBt
	(*MemPage)(unsafe.Pointer(pPage)).Fmax1bytePayload = (*BtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload
	if flagByte >= PTF_ZERODATA|PTF_LEAF {
		(*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize = U8(0)
		(*MemPage)(unsafe.Pointer(pPage)).Fleaf = U8(1)
		if flagByte == PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF {
			(*MemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = U8(1)
			(*MemPage)(unsafe.Pointer(pPage)).FxCellSize = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) U16
			}{cellSizePtrTableLeaf}))
			(*MemPage)(unsafe.Pointer(pPage)).FxParseCell = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			}{btreeParseCellPtr}))
			(*MemPage)(unsafe.Pointer(pPage)).FintKey = U8(1)
			(*MemPage)(unsafe.Pointer(pPage)).FmaxLocal = (*BtShared)(unsafe.Pointer(pBt)).FmaxLeaf
			(*MemPage)(unsafe.Pointer(pPage)).FminLocal = (*BtShared)(unsafe.Pointer(pBt)).FminLeaf
		} else if flagByte == PTF_ZERODATA|PTF_LEAF {
			(*MemPage)(unsafe.Pointer(pPage)).FintKey = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FxCellSize = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) U16
			}{cellSizePtr}))
			(*MemPage)(unsafe.Pointer(pPage)).FxParseCell = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			}{btreeParseCellPtrIndex}))
			(*MemPage)(unsafe.Pointer(pPage)).FmaxLocal = (*BtShared)(unsafe.Pointer(pBt)).FmaxLocal
			(*MemPage)(unsafe.Pointer(pPage)).FminLocal = (*BtShared)(unsafe.Pointer(pBt)).FminLocal
		} else {
			(*MemPage)(unsafe.Pointer(pPage)).FintKey = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FxCellSize = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) U16
			}{cellSizePtr}))
			(*MemPage)(unsafe.Pointer(pPage)).FxParseCell = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			}{btreeParseCellPtrIndex}))
			return Xsqlite3CorruptError(tls, 70361)
		}
	} else {
		(*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize = U8(4)
		(*MemPage)(unsafe.Pointer(pPage)).Fleaf = U8(0)
		if flagByte == PTF_ZERODATA {
			(*MemPage)(unsafe.Pointer(pPage)).FintKey = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FxCellSize = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) U16
			}{cellSizePtr}))
			(*MemPage)(unsafe.Pointer(pPage)).FxParseCell = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			}{btreeParseCellPtrIndex}))
			(*MemPage)(unsafe.Pointer(pPage)).FmaxLocal = (*BtShared)(unsafe.Pointer(pBt)).FmaxLocal
			(*MemPage)(unsafe.Pointer(pPage)).FminLocal = (*BtShared)(unsafe.Pointer(pBt)).FminLocal
		} else if flagByte == PTF_LEAFDATA|PTF_INTKEY {
			(*MemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FxCellSize = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) U16
			}{cellSizePtrNoPayload}))
			(*MemPage)(unsafe.Pointer(pPage)).FxParseCell = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			}{btreeParseCellPtrNoPayload}))
			(*MemPage)(unsafe.Pointer(pPage)).FintKey = U8(1)
			(*MemPage)(unsafe.Pointer(pPage)).FmaxLocal = (*BtShared)(unsafe.Pointer(pBt)).FmaxLeaf
			(*MemPage)(unsafe.Pointer(pPage)).FminLocal = (*BtShared)(unsafe.Pointer(pBt)).FminLeaf
		} else {
			(*MemPage)(unsafe.Pointer(pPage)).FintKey = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FintKeyLeaf = U8(0)
			(*MemPage)(unsafe.Pointer(pPage)).FxCellSize = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) U16
			}{cellSizePtr}))
			(*MemPage)(unsafe.Pointer(pPage)).FxParseCell = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			}{btreeParseCellPtrIndex}))
			return Xsqlite3CorruptError(tls, 70385)
		}
	}
	return SQLITE_OK
}

func btreeComputeFreeSpace(tls *libc.TLS, pPage uintptr) int32 {
	var pc int32
	var hdr U8
	var data uintptr
	var usableSize int32
	var nFree int32
	var top int32
	var iCellFirst int32
	var iCellLast int32

	usableSize = int32((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
	hdr = (*MemPage)(unsafe.Pointer(pPage)).FhdrOffset
	data = (*MemPage)(unsafe.Pointer(pPage)).FaData

	top = (int32(*(*U8)(unsafe.Pointer(data + uintptr(int32(hdr)+5))))<<8|int32(*(*U8)(unsafe.Pointer(data + uintptr(int32(hdr)+5) + 1)))-1)&0xffff + 1
	iCellFirst = int32(hdr) + 8 + int32((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize) + 2*int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)
	iCellLast = usableSize - 4

	pc = int32(*(*U8)(unsafe.Pointer(data + uintptr(int32(hdr)+1))))<<8 | int32(*(*U8)(unsafe.Pointer(data + uintptr(int32(hdr)+1) + 1)))
	nFree = int32(*(*U8)(unsafe.Pointer(data + uintptr(int32(hdr)+7)))) + top
	if pc > 0 {
		var next U32
		var size U32
		if pc < top {
			return Xsqlite3CorruptError(tls, 70436)
		}
		for 1 != 0 {
			if pc > iCellLast {
				return Xsqlite3CorruptError(tls, 70441)
			}
			next = U32(int32(*(*U8)(unsafe.Pointer(data + uintptr(pc))))<<8 | int32(*(*U8)(unsafe.Pointer(data + uintptr(pc) + 1))))
			size = U32(int32(*(*U8)(unsafe.Pointer(data + uintptr(pc+2))))<<8 | int32(*(*U8)(unsafe.Pointer(data + uintptr(pc+2) + 1))))
			nFree = int32(U32(nFree) + size)
			if next <= U32(pc)+size+U32(3) {
				break
			}
			pc = int32(next)
		}
		if next > U32(0) {
			return Xsqlite3CorruptError(tls, 70451)
		}
		if U32(pc)+size > uint32(usableSize) {
			return Xsqlite3CorruptError(tls, 70455)
		}
	}

	if nFree > usableSize || nFree < iCellFirst {
		return Xsqlite3CorruptError(tls, 70467)
	}
	(*MemPage)(unsafe.Pointer(pPage)).FnFree = int32(U16(nFree - iCellFirst))
	return SQLITE_OK
}

func btreeCellSizeCheck(tls *libc.TLS, pPage uintptr) int32 {
	var iCellFirst int32
	var iCellLast int32
	var i int32
	var sz int32
	var pc int32
	var data uintptr
	var usableSize int32
	var cellOffset int32

	iCellFirst = int32((*MemPage)(unsafe.Pointer(pPage)).FcellOffset) + 2*int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)
	usableSize = int32((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
	iCellLast = usableSize - 4
	data = (*MemPage)(unsafe.Pointer(pPage)).FaData
	cellOffset = int32((*MemPage)(unsafe.Pointer(pPage)).FcellOffset)
	if !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
		iCellLast--
	}
	for i = 0; i < int32((*MemPage)(unsafe.Pointer(pPage)).FnCell); i++ {
		pc = int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer(data + uintptr(cellOffset+i*2)))))

		if pc < iCellFirst || pc > iCellLast {
			return Xsqlite3CorruptError(tls, 70498)
		}
		sz = int32((*struct {
			f func(*libc.TLS, uintptr, uintptr) U16
		})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxCellSize})).f(tls, pPage, data+uintptr(pc)))

		if pc+sz > usableSize {
			return Xsqlite3CorruptError(tls, 70503)
		}
	}
	return SQLITE_OK
}

func btreeInitPage(tls *libc.TLS, pPage uintptr) int32 {
	var data uintptr
	var pBt uintptr

	pBt = (*MemPage)(unsafe.Pointer(pPage)).FpBt
	data = (*MemPage)(unsafe.Pointer(pPage)).FaData + uintptr((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)

	if decodeFlags(tls, pPage, int32(*(*U8)(unsafe.Pointer(data)))) != 0 {
		return Xsqlite3CorruptError(tls, 70535)
	}

	(*MemPage)(unsafe.Pointer(pPage)).FmaskPage = U16((*BtShared)(unsafe.Pointer(pBt)).FpageSize - U32(1))
	(*MemPage)(unsafe.Pointer(pPage)).FnOverflow = U8(0)
	(*MemPage)(unsafe.Pointer(pPage)).FcellOffset = U16(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset) + 8 + int32((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize))
	(*MemPage)(unsafe.Pointer(pPage)).FaCellIdx = data + uintptr((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize) + uintptr(8)
	(*MemPage)(unsafe.Pointer(pPage)).FaDataEnd = (*MemPage)(unsafe.Pointer(pPage)).FaData + uintptr((*BtShared)(unsafe.Pointer(pBt)).FpageSize)
	(*MemPage)(unsafe.Pointer(pPage)).FaDataOfst = (*MemPage)(unsafe.Pointer(pPage)).FaData + uintptr((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize)

	(*MemPage)(unsafe.Pointer(pPage)).FnCell = U16(int32(*(*U8)(unsafe.Pointer(data + 3)))<<8 | int32(*(*U8)(unsafe.Pointer(data + 3 + 1))))
	if U32((*MemPage)(unsafe.Pointer(pPage)).FnCell) > ((*BtShared)(unsafe.Pointer(pBt)).FpageSize-U32(8))/U32(6) {
		return Xsqlite3CorruptError(tls, 70549)
	}

	(*MemPage)(unsafe.Pointer(pPage)).FnFree = -1
	(*MemPage)(unsafe.Pointer(pPage)).FisInit = U8(1)
	if (*Sqlite3)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags&uint64(SQLITE_CellSizeCk) != 0 {
		return btreeCellSizeCheck(tls, pPage)
	}
	return SQLITE_OK
}

func zeroPage(tls *libc.TLS, pPage uintptr, flags int32) {
	var data uintptr = (*MemPage)(unsafe.Pointer(pPage)).FaData
	var pBt uintptr = (*MemPage)(unsafe.Pointer(pPage)).FpBt
	var hdr U8 = (*MemPage)(unsafe.Pointer(pPage)).FhdrOffset
	var first U16

	if int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_FAST_SECURE != 0 {
		libc.Xmemset(tls, data+uintptr(hdr), 0, uint64((*BtShared)(unsafe.Pointer(pBt)).FusableSize-U32(hdr)))
	}
	*(*uint8)(unsafe.Pointer(data + uintptr(hdr))) = uint8(flags)
	first = U16(int32(hdr) + func() int32 {
		if flags&PTF_LEAF == 0 {
			return 12
		}
		return 8
	}())
	libc.Xmemset(tls, data+uintptr(int32(hdr)+1), 0, uint64(4))
	*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+7))) = uint8(0)
	*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+5))) = U8((*BtShared)(unsafe.Pointer(pBt)).FusableSize >> 8)
	*(*uint8)(unsafe.Pointer(data + uintptr(int32(hdr)+5) + 1)) = U8((*BtShared)(unsafe.Pointer(pBt)).FusableSize)
	(*MemPage)(unsafe.Pointer(pPage)).FnFree = int32(U16((*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32(first)))
	decodeFlags(tls, pPage, flags)
	(*MemPage)(unsafe.Pointer(pPage)).FcellOffset = first
	(*MemPage)(unsafe.Pointer(pPage)).FaDataEnd = data + uintptr((*BtShared)(unsafe.Pointer(pBt)).FpageSize)
	(*MemPage)(unsafe.Pointer(pPage)).FaCellIdx = data + uintptr(first)
	(*MemPage)(unsafe.Pointer(pPage)).FaDataOfst = data + uintptr((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	(*MemPage)(unsafe.Pointer(pPage)).FnOverflow = U8(0)

	(*MemPage)(unsafe.Pointer(pPage)).FmaskPage = U16((*BtShared)(unsafe.Pointer(pBt)).FpageSize - U32(1))
	(*MemPage)(unsafe.Pointer(pPage)).FnCell = U16(0)
	(*MemPage)(unsafe.Pointer(pPage)).FisInit = U8(1)
}

func btreePageFromDbPage(tls *libc.TLS, pDbPage uintptr, pgno Pgno, pBt uintptr) uintptr {
	var pPage uintptr = Xsqlite3PagerGetExtra(tls, pDbPage)
	if pgno != (*MemPage)(unsafe.Pointer(pPage)).Fpgno {
		(*MemPage)(unsafe.Pointer(pPage)).FaData = Xsqlite3PagerGetData(tls, pDbPage)
		(*MemPage)(unsafe.Pointer(pPage)).FpDbPage = pDbPage
		(*MemPage)(unsafe.Pointer(pPage)).FpBt = pBt
		(*MemPage)(unsafe.Pointer(pPage)).Fpgno = pgno
		(*MemPage)(unsafe.Pointer(pPage)).FhdrOffset = func() uint8 {
			if pgno == Pgno(1) {
				return uint8(100)
			}
			return uint8(0)
		}()
	}

	return pPage
}

func btreeGetPage(tls *libc.TLS, pBt uintptr, pgno Pgno, ppPage uintptr, flags int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	rc = Xsqlite3PagerGet(tls, (*BtShared)(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
}

func btreePageLookup(tls *libc.TLS, pBt uintptr, pgno Pgno) uintptr {
	var pDbPage uintptr

	pDbPage = Xsqlite3PagerLookup(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, pgno)
	if pDbPage != 0 {
		return btreePageFromDbPage(tls, pDbPage, pgno, pBt)
	}
	return uintptr(0)
}

func btreePagecount(tls *libc.TLS, pBt uintptr) Pgno {
	return (*BtShared)(unsafe.Pointer(pBt)).FnPage
}

func Xsqlite3BtreeLastPage(tls *libc.TLS, p uintptr) Pgno {
	return btreePagecount(tls, (*Btree)(unsafe.Pointer(p)).FpBt)
}

func getAndInitPage(tls *libc.TLS, pBt uintptr, pgno Pgno, ppPage uintptr, pCur uintptr, bReadOnly int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	if !(pgno > btreePagecount(tls, pBt)) {
		goto __1
	}
	rc = Xsqlite3CorruptError(tls, 70704)
	goto getAndInitPage_error1
__1:
	;
	rc = Xsqlite3PagerGet(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, pgno, bp, bReadOnly)
	if !(rc != 0) {
		goto __2
	}
	goto getAndInitPage_error1
__2:
	;
	*(*uintptr)(unsafe.Pointer(ppPage)) = Xsqlite3PagerGetExtra(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if !(int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FisInit) == 0) {
		goto __3
	}
	btreePageFromDbPage(tls, *(*uintptr)(unsafe.Pointer(bp)), pgno, pBt)
	rc = btreeInitPage(tls, *(*uintptr)(unsafe.Pointer(ppPage)))
	if !(rc != SQLITE_OK) {
		goto __4
	}
	goto getAndInitPage_error2
__4:
	;
__3:
	;
	if !(pCur != 0 && (int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FnCell) < 1 || int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FintKey) != int32((*BtCursor)(unsafe.Pointer(pCur)).FcurIntKey))) {
		goto __5
	}
	rc = Xsqlite3CorruptError(tls, 70725)
	goto getAndInitPage_error2
__5:
	;
	return SQLITE_OK

getAndInitPage_error2:
	releasePage(tls, *(*uintptr)(unsafe.Pointer(ppPage)))
getAndInitPage_error1:
	if !(pCur != 0) {
		goto __6
	}
	(*BtCursor)(unsafe.Pointer(pCur)).FiPage--
	(*BtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr((*BtCursor)(unsafe.Pointer(pCur)).FiPage)*8))
__6:
	;
	return rc
}

func releasePageNotNull(tls *libc.TLS, pPage uintptr) {
	Xsqlite3PagerUnrefNotNull(tls, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage)
}

func releasePage(tls *libc.TLS, pPage uintptr) {
	if pPage != 0 {
		releasePageNotNull(tls, pPage)
	}
}

func releasePageOne(tls *libc.TLS, pPage uintptr) {
	Xsqlite3PagerUnrefPageOne(tls, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage)
}

func btreeGetUnusedPage(tls *libc.TLS, pBt uintptr, pgno Pgno, ppPage uintptr, flags int32) int32 {
	var rc int32 = btreeGetPage(tls, pBt, pgno, ppPage, flags)
	if rc == SQLITE_OK {
		if Xsqlite3PagerPageRefcount(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FpDbPage) > 1 {
			releasePage(tls, *(*uintptr)(unsafe.Pointer(ppPage)))
			*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
			return Xsqlite3CorruptError(tls, 70791)
		}
		(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FisInit = U8(0)
	} else {
		*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
	}
	return rc
}

func pageReinit(tls *libc.TLS, pData uintptr) {
	var pPage uintptr
	pPage = Xsqlite3PagerGetExtra(tls, pData)

	if (*MemPage)(unsafe.Pointer(pPage)).FisInit != 0 {
		(*MemPage)(unsafe.Pointer(pPage)).FisInit = U8(0)
		if Xsqlite3PagerPageRefcount(tls, pData) > 1 {
			btreeInitPage(tls, pPage)
		}
	}
}

func btreeInvokeBusyHandler(tls *libc.TLS, pArg uintptr) int32 {
	var pBt uintptr = pArg

	return Xsqlite3InvokeBusyHandler(tls, (*BtShared)(unsafe.Pointer(pBt)).Fdb+672)
}

func Xsqlite3BtreeOpen(tls *libc.TLS, pVfs uintptr, zFilename uintptr, db uintptr, ppBtree uintptr, flags int32, vfsFlags int32) int32 {
	bp := tls.Alloc(100)
	defer tls.Free(100)

	var pBt uintptr
	var p uintptr
	var mutexOpen uintptr
	var rc int32
	var nReserve U8

	var isTempDb int32

	var isMemdb int32
	var pExisting uintptr
	var iDb int32
	var nFilename int32
	var nFullPathname int32
	var zFullPathname uintptr
	var mutexShared uintptr
	var mutexShared1 uintptr
	var i int32
	var pSib uintptr
	var pFile uintptr
	pBt = uintptr(0)
	mutexOpen = uintptr(0)
	rc = SQLITE_OK
	isTempDb = libc.Bool32(zFilename == uintptr(0) || int32(*(*uint8)(unsafe.Pointer(zFilename))) == 0)
	isMemdb = libc.Bool32(zFilename != 0 && libc.Xstrcmp(tls, zFilename, ts+6929) == 0 ||
		isTempDb != 0 && Xsqlite3TempInMemory(tls, db) != 0 ||
		vfsFlags&SQLITE_OPEN_MEMORY != 0)

	if !(isMemdb != 0) {
		goto __1
	}
	flags = flags | BTREE_MEMORY
__1:
	;
	if !(vfsFlags&SQLITE_OPEN_MAIN_DB != 0 && (isMemdb != 0 || isTempDb != 0)) {
		goto __2
	}
	vfsFlags = vfsFlags&libc.CplInt32(SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB
__2:
	;
	p = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(Btree{})))
	if !!(p != 0) {
		goto __3
	}
	return SQLITE_NOMEM
__3:
	;
	(*Btree)(unsafe.Pointer(p)).FinTrans = U8(TRANS_NONE)
	(*Btree)(unsafe.Pointer(p)).Fdb = db
	(*Btree)(unsafe.Pointer(p)).Flock.FpBtree = p
	(*Btree)(unsafe.Pointer(p)).Flock.FiTable = Pgno(1)

	if !(isTempDb == 0 && (isMemdb == 0 || vfsFlags&SQLITE_OPEN_URI != 0)) {
		goto __4
	}
	if !(vfsFlags&SQLITE_OPEN_SHAREDCACHE != 0) {
		goto __5
	}
	nFilename = Xsqlite3Strlen30(tls, zFilename) + 1
	nFullPathname = (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FmxPathname + 1
	zFullPathname = Xsqlite3Malloc(tls, func() uint64 {
		if nFullPathname > nFilename {
			return uint64(nFullPathname)
		}
		return uint64(nFilename)
	}())

	(*Btree)(unsafe.Pointer(p)).Fsharable = U8(1)
	if !!(zFullPathname != 0) {
		goto __6
	}
	Xsqlite3_free(tls, p)
	return SQLITE_NOMEM
__6:
	;
	if !(isMemdb != 0) {
		goto __7
	}
	libc.Xmemcpy(tls, zFullPathname, zFilename, uint64(nFilename))
	goto __8
__7:
	rc = Xsqlite3OsFullPathname(tls, pVfs, zFilename,
		nFullPathname, zFullPathname)
	if !(rc != 0) {
		goto __9
	}
	if !(rc == SQLITE_OK|int32(2)<<8) {
		goto __10
	}
	rc = SQLITE_OK
	goto __11
__10:
	Xsqlite3_free(tls, zFullPathname)
	Xsqlite3_free(tls, p)
	return rc
__11:
	;
__9:
	;
__8:
	;
	mutexOpen = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_OPEN)
	Xsqlite3_mutex_enter(tls, mutexOpen)
	mutexShared = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	Xsqlite3_mutex_enter(tls, mutexShared)
	pBt = Xsqlite3SharedCacheList
__12:
	if !(pBt != 0) {
		goto __14
	}

	if !(0 == libc.Xstrcmp(tls, zFullPathname, Xsqlite3PagerFilename(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, 0)) &&
		Xsqlite3PagerVfs(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager) == pVfs) {
		goto __15
	}
	iDb = (*Sqlite3)(unsafe.Pointer(db)).FnDb - 1
__16:
	if !(iDb >= 0) {
		goto __18
	}
	pExisting = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpBt
	if !(pExisting != 0 && (*Btree)(unsafe.Pointer(pExisting)).FpBt == pBt) {
		goto __19
	}
	Xsqlite3_mutex_leave(tls, mutexShared)
	Xsqlite3_mutex_leave(tls, mutexOpen)
	Xsqlite3_free(tls, zFullPathname)
	Xsqlite3_free(tls, p)
	return SQLITE_CONSTRAINT
__19:
	;
	goto __17
__17:
	iDb--
	goto __16
	goto __18
__18:
	;
	(*Btree)(unsafe.Pointer(p)).FpBt = pBt
	(*BtShared)(unsafe.Pointer(pBt)).FnRef++
	goto __14
__15:
	;
	goto __13
__13:
	pBt = (*BtShared)(unsafe.Pointer(pBt)).FpNext
	goto __12
	goto __14
__14:
	;
	Xsqlite3_mutex_leave(tls, mutexShared)
	Xsqlite3_free(tls, zFullPathname)
__5:
	;
__4:
	;
	if !(pBt == uintptr(0)) {
		goto __20
	}

	pBt = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(BtShared{})))
	if !(pBt == uintptr(0)) {
		goto __21
	}
	rc = SQLITE_NOMEM
	goto btree_open_out
__21:
	;
	rc = Xsqlite3PagerOpen(tls, pVfs, pBt, zFilename,
		int32(unsafe.Sizeof(MemPage{})), flags, vfsFlags, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{pageReinit})))
	if !(rc == SQLITE_OK) {
		goto __22
	}
	Xsqlite3PagerSetMmapLimit(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, (*Sqlite3)(unsafe.Pointer(db)).FszMmap)
	rc = Xsqlite3PagerReadFileheader(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, int32(unsafe.Sizeof([100]uint8{})), bp)
__22:
	;
	if !(rc != SQLITE_OK) {
		goto __23
	}
	goto btree_open_out
__23:
	;
	(*BtShared)(unsafe.Pointer(pBt)).FopenFlags = U8(flags)
	(*BtShared)(unsafe.Pointer(pBt)).Fdb = db
	Xsqlite3PagerSetBusyHandler(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{btreeInvokeBusyHandler})), pBt)
	(*Btree)(unsafe.Pointer(p)).FpBt = pBt

	(*BtShared)(unsafe.Pointer(pBt)).FpCursor = uintptr(0)
	(*BtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
	if !(Xsqlite3PagerIsreadonly(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager) != 0) {
		goto __24
	}
	*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_READ_ONLY)
__24:
	;
	(*BtShared)(unsafe.Pointer(pBt)).FpageSize = U32(int32(*(*uint8)(unsafe.Pointer(bp + 16)))<<8 | int32(*(*uint8)(unsafe.Pointer(bp + 17)))<<16)
	if !((*BtShared)(unsafe.Pointer(pBt)).FpageSize < U32(512) || (*BtShared)(unsafe.Pointer(pBt)).FpageSize > U32(SQLITE_MAX_PAGE_SIZE) ||
		((*BtShared)(unsafe.Pointer(pBt)).FpageSize-U32(1))&(*BtShared)(unsafe.Pointer(pBt)).FpageSize != U32(0)) {
		goto __25
	}
	(*BtShared)(unsafe.Pointer(pBt)).FpageSize = U32(0)

	if !(zFilename != 0 && !(isMemdb != 0)) {
		goto __27
	}
	(*BtShared)(unsafe.Pointer(pBt)).FautoVacuum = func() uint8 {
		if 0 != 0 {
			return uint8(1)
		}
		return uint8(0)
	}()
	(*BtShared)(unsafe.Pointer(pBt)).FincrVacuum = func() uint8 {
		if SQLITE_DEFAULT_AUTOVACUUM == 2 {
			return uint8(1)
		}
		return uint8(0)
	}()
__27:
	;
	nReserve = U8(0)
	goto __26
__25:
	nReserve = *(*uint8)(unsafe.Pointer(bp + 20))
	*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_PAGESIZE_FIXED)
	(*BtShared)(unsafe.Pointer(pBt)).FautoVacuum = func() uint8 {
		if Xsqlite3Get4byte(tls, bp+52) != 0 {
			return uint8(1)
		}
		return uint8(0)
	}()
	(*BtShared)(unsafe.Pointer(pBt)).FincrVacuum = func() uint8 {
		if Xsqlite3Get4byte(tls, bp+64) != 0 {
			return uint8(1)
		}
		return uint8(0)
	}()
__26:
	;
	rc = Xsqlite3PagerSetPagesize(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, pBt+52, int32(nReserve))
	if !(rc != 0) {
		goto __28
	}
	goto btree_open_out
__28:
	;
	(*BtShared)(unsafe.Pointer(pBt)).FusableSize = (*BtShared)(unsafe.Pointer(pBt)).FpageSize - U32(nReserve)

	(*BtShared)(unsafe.Pointer(pBt)).FnRef = 1
	if !((*Btree)(unsafe.Pointer(p)).Fsharable != 0) {
		goto __29
	}
	mutexShared1 = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	if !(1 != 0 && Xsqlite3Config.FbCoreMutex != 0) {
		goto __30
	}
	(*BtShared)(unsafe.Pointer(pBt)).Fmutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_FAST)
	if !((*BtShared)(unsafe.Pointer(pBt)).Fmutex == uintptr(0)) {
		goto __31
	}
	rc = SQLITE_NOMEM
	goto btree_open_out
__31:
	;
__30:
	;
	Xsqlite3_mutex_enter(tls, mutexShared1)
	(*BtShared)(unsafe.Pointer(pBt)).FpNext = Xsqlite3SharedCacheList
	Xsqlite3SharedCacheList = pBt
	Xsqlite3_mutex_leave(tls, mutexShared1)
__29:
	;
__20:
	;
	if !((*Btree)(unsafe.Pointer(p)).Fsharable != 0) {
		goto __32
	}
	i = 0
__33:
	if !(i < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __35
	}
	if !(libc.AssignUintptr(&pSib, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpBt) != uintptr(0) && (*Btree)(unsafe.Pointer(pSib)).Fsharable != 0) {
		goto __36
	}
__37:
	if !((*Btree)(unsafe.Pointer(pSib)).FpPrev != 0) {
		goto __38
	}
	pSib = (*Btree)(unsafe.Pointer(pSib)).FpPrev
	goto __37
__38:
	;
	if !(Uptr((*Btree)(unsafe.Pointer(p)).FpBt) < Uptr((*Btree)(unsafe.Pointer(pSib)).FpBt)) {
		goto __39
	}
	(*Btree)(unsafe.Pointer(p)).FpNext = pSib
	(*Btree)(unsafe.Pointer(p)).FpPrev = uintptr(0)
	(*Btree)(unsafe.Pointer(pSib)).FpPrev = p
	goto __40
__39:
__41:
	if !((*Btree)(unsafe.Pointer(pSib)).FpNext != 0 && Uptr((*Btree)(unsafe.Pointer((*Btree)(unsafe.Pointer(pSib)).FpNext)).FpBt) < Uptr((*Btree)(unsafe.Pointer(p)).FpBt)) {
		goto __42
	}
	pSib = (*Btree)(unsafe.Pointer(pSib)).FpNext
	goto __41
__42:
	;
	(*Btree)(unsafe.Pointer(p)).FpNext = (*Btree)(unsafe.Pointer(pSib)).FpNext
	(*Btree)(unsafe.Pointer(p)).FpPrev = pSib
	if !((*Btree)(unsafe.Pointer(p)).FpNext != 0) {
		goto __43
	}
	(*Btree)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpNext)).FpPrev = p
__43:
	;
	(*Btree)(unsafe.Pointer(pSib)).FpNext = p
__40:
	;
	goto __35
__36:
	;
	goto __34
__34:
	i++
	goto __33
	goto __35
__35:
	;
__32:
	;
	*(*uintptr)(unsafe.Pointer(ppBtree)) = p

btree_open_out:
	if !(rc != SQLITE_OK) {
		goto __44
	}
	if !(pBt != 0 && (*BtShared)(unsafe.Pointer(pBt)).FpPager != 0) {
		goto __46
	}
	Xsqlite3PagerClose(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, uintptr(0))
__46:
	;
	Xsqlite3_free(tls, pBt)
	Xsqlite3_free(tls, p)
	*(*uintptr)(unsafe.Pointer(ppBtree)) = uintptr(0)
	goto __45
__44:
	if !(Xsqlite3BtreeSchema(tls, p, 0, uintptr(0)) == uintptr(0)) {
		goto __47
	}
	Xsqlite3BtreeSetCacheSize(tls, p, -2000)
__47:
	;
	pFile = Xsqlite3PagerFile(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager)
	if !((*Sqlite3_file)(unsafe.Pointer(pFile)).FpMethods != 0) {
		goto __48
	}
	Xsqlite3OsFileControlHint(tls, pFile, SQLITE_FCNTL_PDB, pBt+8)
__48:
	;
__45:
	;
	if !(mutexOpen != 0) {
		goto __49
	}

	Xsqlite3_mutex_leave(tls, mutexOpen)
__49:
	;
	return rc
}

func removeFromSharingList(tls *libc.TLS, pBt uintptr) int32 {
	var pMainMtx uintptr
	var pList uintptr
	var removed int32 = 0

	pMainMtx = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	Xsqlite3_mutex_enter(tls, pMainMtx)
	(*BtShared)(unsafe.Pointer(pBt)).FnRef--
	if (*BtShared)(unsafe.Pointer(pBt)).FnRef <= 0 {
		if Xsqlite3SharedCacheList == pBt {
			Xsqlite3SharedCacheList = (*BtShared)(unsafe.Pointer(pBt)).FpNext
		} else {
			pList = Xsqlite3SharedCacheList
			for pList != 0 && (*BtShared)(unsafe.Pointer(pList)).FpNext != pBt {
				pList = (*BtShared)(unsafe.Pointer(pList)).FpNext
			}
			if pList != 0 {
				(*BtShared)(unsafe.Pointer(pList)).FpNext = (*BtShared)(unsafe.Pointer(pBt)).FpNext
			}
		}
		if 1 != 0 {
			Xsqlite3_mutex_free(tls, (*BtShared)(unsafe.Pointer(pBt)).Fmutex)
		}
		removed = 1
	}
	Xsqlite3_mutex_leave(tls, pMainMtx)
	return removed
}

func allocateTempSpace(tls *libc.TLS, pBt uintptr) int32 {
	(*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace = Xsqlite3PageMalloc(tls, int32((*BtShared)(unsafe.Pointer(pBt)).FpageSize))
	if (*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace == uintptr(0) {
		var pCur uintptr = (*BtShared)(unsafe.Pointer(pBt)).FpCursor
		(*BtShared)(unsafe.Pointer(pBt)).FpCursor = (*BtCursor)(unsafe.Pointer(pCur)).FpNext
		libc.Xmemset(tls, pCur, 0, uint64(unsafe.Sizeof(BtCursor{})))
		return SQLITE_NOMEM
	}

	libc.Xmemset(tls, (*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace, 0, uint64(8))
	*(*uintptr)(unsafe.Pointer(pBt + 136)) += uintptr(4)
	return SQLITE_OK
}

func freeTempSpace(tls *libc.TLS, pBt uintptr) {
	if (*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace != 0 {
		*(*uintptr)(unsafe.Pointer(pBt + 136)) -= uintptr(4)
		Xsqlite3PageFree(tls, (*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace)
		(*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace = uintptr(0)
	}
}

func Xsqlite3BtreeClose(tls *libc.TLS, p uintptr) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3BtreeEnter(tls, p)

	Xsqlite3BtreeRollback(tls, p, SQLITE_OK, 0)
	Xsqlite3BtreeLeave(tls, p)

	if !(int32((*Btree)(unsafe.Pointer(p)).Fsharable) != 0) || removeFromSharingList(tls, pBt) != 0 {
		Xsqlite3PagerClose(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, (*Btree)(unsafe.Pointer(p)).Fdb)
		if (*BtShared)(unsafe.Pointer(pBt)).FxFreeSchema != 0 && (*BtShared)(unsafe.Pointer(pBt)).FpSchema != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*BtShared)(unsafe.Pointer(pBt)).FxFreeSchema})).f(tls, (*BtShared)(unsafe.Pointer(pBt)).FpSchema)
		}
		Xsqlite3DbFree(tls, uintptr(0), (*BtShared)(unsafe.Pointer(pBt)).FpSchema)
		freeTempSpace(tls, pBt)
		Xsqlite3_free(tls, pBt)
	}

	if (*Btree)(unsafe.Pointer(p)).FpPrev != 0 {
		(*Btree)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpPrev)).FpNext = (*Btree)(unsafe.Pointer(p)).FpNext
	}
	if (*Btree)(unsafe.Pointer(p)).FpNext != 0 {
		(*Btree)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpNext)).FpPrev = (*Btree)(unsafe.Pointer(p)).FpPrev
	}

	Xsqlite3_free(tls, p)
	return SQLITE_OK
}

func Xsqlite3BtreeSetCacheSize(tls *libc.TLS, p uintptr, mxPage int32) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3BtreeEnter(tls, p)
	Xsqlite3PagerSetCachesize(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, mxPage)
	Xsqlite3BtreeLeave(tls, p)
	return SQLITE_OK
}

func Xsqlite3BtreeSetSpillSize(tls *libc.TLS, p uintptr, mxPage int32) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	var res int32

	Xsqlite3BtreeEnter(tls, p)
	res = Xsqlite3PagerSetSpillsize(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, mxPage)
	Xsqlite3BtreeLeave(tls, p)
	return res
}

func Xsqlite3BtreeSetMmapLimit(tls *libc.TLS, p uintptr, szMmap Sqlite3_int64) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3BtreeEnter(tls, p)
	Xsqlite3PagerSetMmapLimit(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, szMmap)
	Xsqlite3BtreeLeave(tls, p)
	return SQLITE_OK
}

func Xsqlite3BtreeSetPagerFlags(tls *libc.TLS, p uintptr, pgFlags uint32) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3BtreeEnter(tls, p)
	Xsqlite3PagerSetFlags(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, pgFlags)
	Xsqlite3BtreeLeave(tls, p)
	return SQLITE_OK
}

func Xsqlite3BtreeSetPageSize(tls *libc.TLS, p uintptr, pageSize int32, nReserve int32, iFix int32) int32 {
	var rc int32 = SQLITE_OK
	var x int32
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3BtreeEnter(tls, p)
	(*BtShared)(unsafe.Pointer(pBt)).FnReserveWanted = U8(nReserve)
	x = int32((*BtShared)(unsafe.Pointer(pBt)).FpageSize - (*BtShared)(unsafe.Pointer(pBt)).FusableSize)
	if nReserve < x {
		nReserve = x
	}
	if int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_PAGESIZE_FIXED != 0 {
		Xsqlite3BtreeLeave(tls, p)
		return SQLITE_READONLY
	}

	if pageSize >= 512 && pageSize <= SQLITE_MAX_PAGE_SIZE && (pageSize-1)&pageSize == 0 {
		if nReserve > 32 && pageSize == 512 {
			pageSize = 1024
		}
		(*BtShared)(unsafe.Pointer(pBt)).FpageSize = U32(pageSize)
		freeTempSpace(tls, pBt)
	}
	rc = Xsqlite3PagerSetPagesize(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, pBt+52, nReserve)
	(*BtShared)(unsafe.Pointer(pBt)).FusableSize = (*BtShared)(unsafe.Pointer(pBt)).FpageSize - U32(U16(nReserve))
	if iFix != 0 {
		*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_PAGESIZE_FIXED)
	}
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeGetPageSize(tls *libc.TLS, p uintptr) int32 {
	return int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FpageSize)
}

func Xsqlite3BtreeGetReserveNoMutex(tls *libc.TLS, p uintptr) int32 {
	var n int32

	n = int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FpageSize - (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FusableSize)
	return n
}

func Xsqlite3BtreeGetRequestedReserve(tls *libc.TLS, p uintptr) int32 {
	var n1 int32
	var n2 int32
	Xsqlite3BtreeEnter(tls, p)
	n1 = int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FnReserveWanted)
	n2 = Xsqlite3BtreeGetReserveNoMutex(tls, p)
	Xsqlite3BtreeLeave(tls, p)
	if n1 > n2 {
		return n1
	}
	return n2
}

func Xsqlite3BtreeMaxPageCount(tls *libc.TLS, p uintptr, mxPage Pgno) Pgno {
	var n Pgno
	Xsqlite3BtreeEnter(tls, p)
	n = Xsqlite3PagerMaxPageCount(tls, (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FpPager, mxPage)
	Xsqlite3BtreeLeave(tls, p)
	return n
}

func Xsqlite3BtreeSecureDelete(tls *libc.TLS, p uintptr, newFlag int32) int32 {
	var b int32
	if p == uintptr(0) {
		return 0
	}
	Xsqlite3BtreeEnter(tls, p)

	if newFlag >= 0 {
		*(*U16)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_FAST_SECURE))
		*(*U16)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt + 40)) |= U16(BTS_SECURE_DELETE * newFlag)
	}
	b = int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FbtsFlags) & BTS_FAST_SECURE / BTS_SECURE_DELETE
	Xsqlite3BtreeLeave(tls, p)
	return b
}

func Xsqlite3BtreeSetAutoVacuum(tls *libc.TLS, p uintptr, autoVacuum int32) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	var rc int32 = SQLITE_OK
	var av U8 = U8(autoVacuum)

	Xsqlite3BtreeEnter(tls, p)
	if int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_PAGESIZE_FIXED != 0 && func() int32 {
		if av != 0 {
			return 1
		}
		return 0
	}() != int32((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum) {
		rc = SQLITE_READONLY
	} else {
		(*BtShared)(unsafe.Pointer(pBt)).FautoVacuum = func() uint8 {
			if av != 0 {
				return uint8(1)
			}
			return uint8(0)
		}()
		(*BtShared)(unsafe.Pointer(pBt)).FincrVacuum = func() uint8 {
			if int32(av) == 2 {
				return uint8(1)
			}
			return uint8(0)
		}()
	}
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeGetAutoVacuum(tls *libc.TLS, p uintptr) int32 {
	var rc int32
	Xsqlite3BtreeEnter(tls, p)
	rc = func() int32 {
		if !(int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FautoVacuum) != 0) {
			return BTREE_AUTOVACUUM_NONE
		}
		return func() int32 {
			if !(int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FincrVacuum) != 0) {
				return BTREE_AUTOVACUUM_FULL
			}
			return BTREE_AUTOVACUUM_INCR
		}()
	}()
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func lockBtree(tls *libc.TLS, pBt uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32

	var nPage U32

	var pageSize U32
	var usableSize U32
	var page1 uintptr
	*(*U32)(unsafe.Pointer(bp + 8)) = U32(0)

	rc = Xsqlite3PagerSharedLock(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager)
	if !(rc != SQLITE_OK) {
		goto __1
	}
	return rc
__1:
	;
	rc = btreeGetPage(tls, pBt, uint32(1), bp, 0)
	if !(rc != SQLITE_OK) {
		goto __2
	}
	return rc
__2:
	;
	nPage = Xsqlite3Get4byte(tls, uintptr(28)+(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData)
	Xsqlite3PagerPagecount(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, bp+8)
	if !(nPage == U32(0) || libc.Xmemcmp(tls, uintptr(24)+(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, uintptr(92)+(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, uint64(4)) != 0) {
		goto __3
	}
	nPage = *(*U32)(unsafe.Pointer(bp + 8))
__3:
	;
	if !((*Sqlite3)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0)) {
		goto __4
	}
	nPage = U32(0)
__4:
	;
	if !(nPage > U32(0)) {
		goto __5
	}
	page1 = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData
	rc = SQLITE_NOTADB

	if !(libc.Xmemcmp(tls, page1, uintptr(unsafe.Pointer(&zMagicHeader)), uint64(16)) != 0) {
		goto __6
	}
	goto page1_init_failed
__6:
	;
	if !(int32(*(*U8)(unsafe.Pointer(page1 + 18))) > 2) {
		goto __7
	}
	*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_READ_ONLY)
__7:
	;
	if !(int32(*(*U8)(unsafe.Pointer(page1 + 19))) > 2) {
		goto __8
	}
	goto page1_init_failed
__8:
	;
	if !(int32(*(*U8)(unsafe.Pointer(page1 + 19))) == 2 && int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_NO_WAL == 0) {
		goto __9
	}
	*(*int32)(unsafe.Pointer(bp + 12)) = 0
	rc = Xsqlite3PagerOpenWal(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, bp+12)
	if !(rc != SQLITE_OK) {
		goto __11
	}
	goto page1_init_failed
	goto __12
__11:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 12)) == 0) {
		goto __13
	}
	releasePageOne(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return SQLITE_OK
__13:
	;
__12:
	;
	rc = SQLITE_NOTADB
	goto __10
__9:
	;
__10:
	;
	if !(libc.Xmemcmp(tls, page1+21, ts+6938, uint64(3)) != 0) {
		goto __14
	}
	goto page1_init_failed
__14:
	;
	pageSize = U32(int32(*(*U8)(unsafe.Pointer(page1 + 16)))<<8 | int32(*(*U8)(unsafe.Pointer(page1 + 17)))<<16)

	if !((pageSize-U32(1))&pageSize != U32(0) ||
		pageSize > U32(SQLITE_MAX_PAGE_SIZE) ||
		pageSize <= U32(256)) {
		goto __15
	}
	goto page1_init_failed
__15:
	;
	*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_PAGESIZE_FIXED)

	usableSize = pageSize - U32(*(*U8)(unsafe.Pointer(page1 + 20)))
	if !(pageSize != (*BtShared)(unsafe.Pointer(pBt)).FpageSize) {
		goto __16
	}

	releasePageOne(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*BtShared)(unsafe.Pointer(pBt)).FusableSize = usableSize
	(*BtShared)(unsafe.Pointer(pBt)).FpageSize = pageSize
	freeTempSpace(tls, pBt)
	rc = Xsqlite3PagerSetPagesize(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, pBt+52,
		int32(pageSize-usableSize))
	return rc
__16:
	;
	if !(nPage > *(*U32)(unsafe.Pointer(bp + 8))) {
		goto __17
	}
	if !(Xsqlite3WritableSchema(tls, (*BtShared)(unsafe.Pointer(pBt)).Fdb) == 0) {
		goto __18
	}
	rc = Xsqlite3CorruptError(tls, 71726)
	goto page1_init_failed
	goto __19
__18:
	nPage = *(*U32)(unsafe.Pointer(bp + 8))
__19:
	;
__17:
	;
	if !(usableSize < U32(480)) {
		goto __20
	}
	goto page1_init_failed
__20:
	;
	(*BtShared)(unsafe.Pointer(pBt)).FpageSize = pageSize
	(*BtShared)(unsafe.Pointer(pBt)).FusableSize = usableSize
	(*BtShared)(unsafe.Pointer(pBt)).FautoVacuum = func() uint8 {
		if Xsqlite3Get4byte(tls, page1+52) != 0 {
			return uint8(1)
		}
		return uint8(0)
	}()
	(*BtShared)(unsafe.Pointer(pBt)).FincrVacuum = func() uint8 {
		if Xsqlite3Get4byte(tls, page1+64) != 0 {
			return uint8(1)
		}
		return uint8(0)
	}()
__5:
	;
	(*BtShared)(unsafe.Pointer(pBt)).FmaxLocal = U16(((*BtShared)(unsafe.Pointer(pBt)).FusableSize-U32(12))*U32(64)/U32(255) - U32(23))
	(*BtShared)(unsafe.Pointer(pBt)).FminLocal = U16(((*BtShared)(unsafe.Pointer(pBt)).FusableSize-U32(12))*U32(32)/U32(255) - U32(23))
	(*BtShared)(unsafe.Pointer(pBt)).FmaxLeaf = U16((*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32(35))
	(*BtShared)(unsafe.Pointer(pBt)).FminLeaf = U16(((*BtShared)(unsafe.Pointer(pBt)).FusableSize-U32(12))*U32(32)/U32(255) - U32(23))
	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FmaxLocal) > 127) {
		goto __21
	}
	(*BtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload = U8(127)
	goto __22
__21:
	(*BtShared)(unsafe.Pointer(pBt)).Fmax1bytePayload = U8((*BtShared)(unsafe.Pointer(pBt)).FmaxLocal)
__22:
	;
	(*BtShared)(unsafe.Pointer(pBt)).FpPage1 = *(*uintptr)(unsafe.Pointer(bp))
	(*BtShared)(unsafe.Pointer(pBt)).FnPage = nPage
	return SQLITE_OK

page1_init_failed:
	releasePageOne(tls, *(*uintptr)(unsafe.Pointer(bp)))
	(*BtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
	return rc
}

func unlockBtreeIfUnused(tls *libc.TLS, pBt uintptr) {
	if int32((*BtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_NONE && (*BtShared)(unsafe.Pointer(pBt)).FpPage1 != uintptr(0) {
		var pPage1 uintptr = (*BtShared)(unsafe.Pointer(pBt)).FpPage1

		(*BtShared)(unsafe.Pointer(pBt)).FpPage1 = uintptr(0)
		releasePageOne(tls, pPage1)
	}
}

func newDatabase(tls *libc.TLS, pBt uintptr) int32 {
	var pP1 uintptr
	var data uintptr
	var rc int32

	if (*BtShared)(unsafe.Pointer(pBt)).FnPage > U32(0) {
		return SQLITE_OK
	}
	pP1 = (*BtShared)(unsafe.Pointer(pBt)).FpPage1

	data = (*MemPage)(unsafe.Pointer(pP1)).FaData
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pP1)).FpDbPage)
	if rc != 0 {
		return rc
	}
	libc.Xmemcpy(tls, data, uintptr(unsafe.Pointer(&zMagicHeader)), uint64(unsafe.Sizeof(zMagicHeader)))

	*(*uint8)(unsafe.Pointer(data + 16)) = U8((*BtShared)(unsafe.Pointer(pBt)).FpageSize >> 8 & U32(0xff))
	*(*uint8)(unsafe.Pointer(data + 17)) = U8((*BtShared)(unsafe.Pointer(pBt)).FpageSize >> 16 & U32(0xff))
	*(*uint8)(unsafe.Pointer(data + 18)) = uint8(1)
	*(*uint8)(unsafe.Pointer(data + 19)) = uint8(1)

	*(*uint8)(unsafe.Pointer(data + 20)) = U8((*BtShared)(unsafe.Pointer(pBt)).FpageSize - (*BtShared)(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, uint64(100-24))
	zeroPage(tls, pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA)
	*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_PAGESIZE_FIXED)

	Xsqlite3Put4byte(tls, data+52, uint32((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum))
	Xsqlite3Put4byte(tls, data+64, uint32((*BtShared)(unsafe.Pointer(pBt)).FincrVacuum))
	(*BtShared)(unsafe.Pointer(pBt)).FnPage = U32(1)
	*(*uint8)(unsafe.Pointer(data + 31)) = uint8(1)
	return SQLITE_OK
}

func Xsqlite3BtreeNewDb(tls *libc.TLS, p uintptr) int32 {
	var rc int32
	Xsqlite3BtreeEnter(tls, p)
	(*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FnPage = U32(0)
	rc = newDatabase(tls, (*Btree)(unsafe.Pointer(p)).FpBt)
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeBeginTrans(tls *libc.TLS, p uintptr, wrflag int32, pSchemaVersion uintptr) int32 {
	var pBt uintptr
	var pPager uintptr
	var rc int32
	var pIter uintptr
	var pBlock uintptr
	var pPage1 uintptr
	pBt = (*Btree)(unsafe.Pointer(p)).FpBt
	pPager = (*BtShared)(unsafe.Pointer(pBt)).FpPager
	rc = SQLITE_OK

	Xsqlite3BtreeEnter(tls, p)

	if !(int32((*Btree)(unsafe.Pointer(p)).FinTrans) == TRANS_WRITE || int32((*Btree)(unsafe.Pointer(p)).FinTrans) == TRANS_READ && !(wrflag != 0)) {
		goto __1
	}
	goto trans_begun
__1:
	;
	if !((*Sqlite3)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).Fdb)).Fflags&uint64(SQLITE_ResetDatabase) != 0 &&
		int32(Xsqlite3PagerIsreadonly(tls, pPager)) == 0) {
		goto __2
	}
	*(*U16)(unsafe.Pointer(pBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_READ_ONLY))
__2:
	;
	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_READ_ONLY != 0 && wrflag != 0) {
		goto __3
	}
	rc = SQLITE_READONLY
	goto trans_begun
__3:
	;
	pBlock = uintptr(0)

	if !(wrflag != 0 && int32((*BtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_WRITE ||
		int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_PENDING != 0) {
		goto __4
	}
	pBlock = (*Btree)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpWriter)).Fdb
	goto __5
__4:
	if !(wrflag > 1) {
		goto __6
	}
	pIter = (*BtShared)(unsafe.Pointer(pBt)).FpLock
__7:
	if !(pIter != 0) {
		goto __9
	}
	if !((*BtLock)(unsafe.Pointer(pIter)).FpBtree != p) {
		goto __10
	}
	pBlock = (*Btree)(unsafe.Pointer((*BtLock)(unsafe.Pointer(pIter)).FpBtree)).Fdb
	goto __9
__10:
	;
	goto __8
__8:
	pIter = (*BtLock)(unsafe.Pointer(pIter)).FpNext
	goto __7
	goto __9
__9:
	;
__6:
	;
__5:
	;
	if !(pBlock != 0) {
		goto __11
	}
	Xsqlite3ConnectionBlocked(tls, (*Btree)(unsafe.Pointer(p)).Fdb, pBlock)
	rc = SQLITE_LOCKED | int32(1)<<8
	goto trans_begun
__11:
	;
	rc = querySharedCacheTableLock(tls, p, uint32(SCHEMA_ROOT), uint8(READ_LOCK))
	if !(SQLITE_OK != rc) {
		goto __12
	}
	goto trans_begun
__12:
	;
	*(*U16)(unsafe.Pointer(pBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_INITIALLY_EMPTY))
	if !((*BtShared)(unsafe.Pointer(pBt)).FnPage == U32(0)) {
		goto __13
	}
	*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_INITIALLY_EMPTY)
__13:
	;
__14:
	;
__17:
	if !((*BtShared)(unsafe.Pointer(pBt)).FpPage1 == uintptr(0) && SQLITE_OK == libc.AssignInt32(&rc, lockBtree(tls, pBt))) {
		goto __18
	}
	goto __17
__18:
	;
	if !(rc == SQLITE_OK && wrflag != 0) {
		goto __19
	}
	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_READ_ONLY != 0) {
		goto __20
	}
	rc = SQLITE_READONLY
	goto __21
__20:
	rc = Xsqlite3PagerBegin(tls, pPager, libc.Bool32(wrflag > 1), Xsqlite3TempInMemory(tls, (*Btree)(unsafe.Pointer(p)).Fdb))
	if !(rc == SQLITE_OK) {
		goto __22
	}
	rc = newDatabase(tls, pBt)
	goto __23
__22:
	if !(rc == SQLITE_BUSY|int32(2)<<8 && int32((*BtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_NONE) {
		goto __24
	}

	rc = SQLITE_BUSY
__24:
	;
__23:
	;
__21:
	;
__19:
	;
	if !(rc != SQLITE_OK) {
		goto __25
	}

	unlockBtreeIfUnused(tls, pBt)
__25:
	;
	goto __15
__15:
	if rc&0xFF == SQLITE_BUSY && int32((*BtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_NONE && btreeInvokeBusyHandler(tls, pBt) != 0 {
		goto __14
	}
	goto __16
__16:
	;
	if !(rc == SQLITE_OK) {
		goto __26
	}
	if !(int32((*Btree)(unsafe.Pointer(p)).FinTrans) == TRANS_NONE) {
		goto __27
	}
	(*BtShared)(unsafe.Pointer(pBt)).FnTransaction++
	if !((*Btree)(unsafe.Pointer(p)).Fsharable != 0) {
		goto __28
	}

	(*Btree)(unsafe.Pointer(p)).Flock.FeLock = U8(READ_LOCK)
	(*Btree)(unsafe.Pointer(p)).Flock.FpNext = (*BtShared)(unsafe.Pointer(pBt)).FpLock
	(*BtShared)(unsafe.Pointer(pBt)).FpLock = p + 48
__28:
	;
__27:
	;
	(*Btree)(unsafe.Pointer(p)).FinTrans = func() uint8 {
		if wrflag != 0 {
			return uint8(TRANS_WRITE)
		}
		return uint8(TRANS_READ)
	}()
	if !(int32((*Btree)(unsafe.Pointer(p)).FinTrans) > int32((*BtShared)(unsafe.Pointer(pBt)).FinTransaction)) {
		goto __29
	}
	(*BtShared)(unsafe.Pointer(pBt)).FinTransaction = (*Btree)(unsafe.Pointer(p)).FinTrans
__29:
	;
	if !(wrflag != 0) {
		goto __30
	}
	pPage1 = (*BtShared)(unsafe.Pointer(pBt)).FpPage1

	(*BtShared)(unsafe.Pointer(pBt)).FpWriter = p
	*(*U16)(unsafe.Pointer(pBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_EXCLUSIVE))
	if !(wrflag > 1) {
		goto __31
	}
	*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_EXCLUSIVE)
__31:
	;
	if !((*BtShared)(unsafe.Pointer(pBt)).FnPage != Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+28)) {
		goto __32
	}
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPage1)).FpDbPage)
	if !(rc == SQLITE_OK) {
		goto __33
	}
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+28, (*BtShared)(unsafe.Pointer(pBt)).FnPage)
__33:
	;
__32:
	;
__30:
	;
__26:
	;
trans_begun:
	if !(rc == SQLITE_OK) {
		goto __34
	}
	if !(pSchemaVersion != 0) {
		goto __35
	}
	*(*int32)(unsafe.Pointer(pSchemaVersion)) = int32(Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+40))
__35:
	;
	if !(wrflag != 0) {
		goto __36
	}

	rc = Xsqlite3PagerOpenSavepoint(tls, pPager, (*Sqlite3)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).Fdb)).FnSavepoint)
__36:
	;
__34:
	;
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func setChildPtrmaps(tls *libc.TLS, pPage uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var i int32
	var nCell int32

	var pBt uintptr = (*MemPage)(unsafe.Pointer(pPage)).FpBt
	var pgno Pgno = (*MemPage)(unsafe.Pointer(pPage)).Fpgno

	if (*MemPage)(unsafe.Pointer(pPage)).FisInit != 0 {
		*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	} else {
		*(*int32)(unsafe.Pointer(bp)) = btreeInitPage(tls, pPage)
	}
	if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
		return *(*int32)(unsafe.Pointer(bp))
	}
	nCell = int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)

	for i = 0; i < nCell; i++ {
		var pCell uintptr = (*MemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*i))))))

		ptrmapPutOvflPtr(tls, pPage, pPage, pCell, bp)

		if !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
			var childPgno Pgno = Xsqlite3Get4byte(tls, pCell)
			ptrmapPut(tls, pBt, childPgno, uint8(PTRMAP_BTREE), pgno, bp)
		}
	}

	if !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
		var childPgno Pgno = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+8))
		ptrmapPut(tls, pBt, childPgno, uint8(PTRMAP_BTREE), pgno, bp)
	}

	return *(*int32)(unsafe.Pointer(bp))
}

func modifyPagePointer(tls *libc.TLS, pPage uintptr, iFrom Pgno, iTo Pgno, eType U8) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	if int32(eType) == PTRMAP_OVERFLOW2 {
		if Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData) != iFrom {
			return Xsqlite3CorruptError(tls, 72147)
		}
		Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData, iTo)
	} else {
		var i int32
		var nCell int32
		var rc int32

		if (*MemPage)(unsafe.Pointer(pPage)).FisInit != 0 {
			rc = SQLITE_OK
		} else {
			rc = btreeInitPage(tls, pPage)
		}
		if rc != 0 {
			return rc
		}
		nCell = int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)

		for i = 0; i < nCell; i++ {
			var pCell uintptr = (*MemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*i))))))
			if int32(eType) == PTRMAP_OVERFLOW1 {
				(*struct {
					f func(*libc.TLS, uintptr, uintptr, uintptr)
				})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxParseCell})).f(tls, pPage, pCell, bp)
				if U32((*CellInfo)(unsafe.Pointer(bp)).FnLocal) < (*CellInfo)(unsafe.Pointer(bp)).FnPayload {
					if pCell+uintptr((*CellInfo)(unsafe.Pointer(bp)).FnSize) > (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) {
						return Xsqlite3CorruptError(tls, 72166)
					}
					if iFrom == Xsqlite3Get4byte(tls, pCell+uintptr((*CellInfo)(unsafe.Pointer(bp)).FnSize)-uintptr(4)) {
						Xsqlite3Put4byte(tls, pCell+uintptr((*CellInfo)(unsafe.Pointer(bp)).FnSize)-uintptr(4), iTo)
						break
					}
				}
			} else {
				if pCell+uintptr(4) > (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize) {
					return Xsqlite3CorruptError(tls, 72175)
				}
				if Xsqlite3Get4byte(tls, pCell) == iFrom {
					Xsqlite3Put4byte(tls, pCell, iTo)
					break
				}
			}
		}

		if i == nCell {
			if int32(eType) != PTRMAP_BTREE || Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+8)) != iFrom {
				return Xsqlite3CorruptError(tls, 72187)
			}
			Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+8), iTo)
		}
	}
	return SQLITE_OK
}

func relocatePage(tls *libc.TLS, pBt uintptr, pDbPage uintptr, eType U8, iPtrPage Pgno, iFreePage Pgno, isCommit int32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var iDbPage Pgno = (*MemPage)(unsafe.Pointer(pDbPage)).Fpgno
	var pPager uintptr = (*BtShared)(unsafe.Pointer(pBt)).FpPager

	if iDbPage < Pgno(3) {
		return Xsqlite3CorruptError(tls, 72222)
	}

	*(*int32)(unsafe.Pointer(bp)) = Xsqlite3PagerMovepage(tls, pPager, (*MemPage)(unsafe.Pointer(pDbPage)).FpDbPage, iFreePage, isCommit)
	if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
		return *(*int32)(unsafe.Pointer(bp))
	}
	(*MemPage)(unsafe.Pointer(pDbPage)).Fpgno = iFreePage

	if int32(eType) == PTRMAP_BTREE || int32(eType) == PTRMAP_ROOTPAGE {
		*(*int32)(unsafe.Pointer(bp)) = setChildPtrmaps(tls, pDbPage)
		if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
			return *(*int32)(unsafe.Pointer(bp))
		}
	} else {
		var nextOvfl Pgno = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pDbPage)).FaData)
		if nextOvfl != Pgno(0) {
			ptrmapPut(tls, pBt, nextOvfl, uint8(PTRMAP_OVERFLOW2), iFreePage, bp)
			if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp))
			}
		}
	}

	if int32(eType) != PTRMAP_ROOTPAGE {
		*(*int32)(unsafe.Pointer(bp)) = btreeGetPage(tls, pBt, iPtrPage, bp+8, 0)
		if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
			return *(*int32)(unsafe.Pointer(bp))
		}
		*(*int32)(unsafe.Pointer(bp)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpDbPage)
		if *(*int32)(unsafe.Pointer(bp)) != SQLITE_OK {
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
			return *(*int32)(unsafe.Pointer(bp))
		}
		*(*int32)(unsafe.Pointer(bp)) = modifyPagePointer(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), iDbPage, iFreePage, eType)
		releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			ptrmapPut(tls, pBt, iFreePage, eType, iPtrPage, bp)
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func incrVacuumStep(tls *libc.TLS, pBt uintptr, nFin Pgno, iLastPg Pgno, bCommit int32) int32 {
	bp := tls.Alloc(44)
	defer tls.Free(44)

	var nFreeList Pgno
	var rc int32

	if !(ptrmapPageno(tls, pBt, iLastPg) == iLastPg) && iLastPg != U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) {
		nFreeList = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36)
		if nFreeList == Pgno(0) {
			return SQLITE_DONE
		}

		rc = ptrmapGet(tls, pBt, iLastPg, bp, bp+4)
		if rc != SQLITE_OK {
			return rc
		}
		if int32(*(*U8)(unsafe.Pointer(bp))) == PTRMAP_ROOTPAGE {
			return Xsqlite3CorruptError(tls, 72320)
		}

		if int32(*(*U8)(unsafe.Pointer(bp))) == PTRMAP_FREEPAGE {
			if bCommit == 0 {
				rc = allocateBtreePage(tls, pBt, bp+8, bp+16, iLastPg, uint8(BTALLOC_EXACT))
				if rc != SQLITE_OK {
					return rc
				}

				releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
			}
		} else {
			var eMode U8 = U8(BTALLOC_ANY)
			var iNear Pgno = Pgno(0)

			rc = btreeGetPage(tls, pBt, iLastPg, bp+24, 0)
			if rc != SQLITE_OK {
				return rc
			}

			if bCommit == 0 {
				eMode = U8(BTALLOC_LE)
				iNear = nFin
			}
			for __ccgo := true; __ccgo; __ccgo = bCommit != 0 && *(*Pgno)(unsafe.Pointer(bp + 40)) > nFin {
				var dbSize Pgno = btreePagecount(tls, pBt)
				rc = allocateBtreePage(tls, pBt, bp+32, bp+40, iNear, eMode)
				if rc != SQLITE_OK {
					releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
					return rc
				}
				releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 32)))
				if *(*Pgno)(unsafe.Pointer(bp + 40)) > dbSize {
					releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
					return Xsqlite3CorruptError(tls, 72372)
				}
			}

			rc = relocatePage(tls, pBt, *(*uintptr)(unsafe.Pointer(bp + 24)), *(*U8)(unsafe.Pointer(bp)), *(*Pgno)(unsafe.Pointer(bp + 4)), *(*Pgno)(unsafe.Pointer(bp + 40)), bCommit)
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
			if rc != SQLITE_OK {
				return rc
			}
		}
	}

	if bCommit == 0 {
		for __ccgo1 := true; __ccgo1; __ccgo1 = iLastPg == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) || ptrmapPageno(tls, pBt, iLastPg) == iLastPg {
			iLastPg--
		}
		(*BtShared)(unsafe.Pointer(pBt)).FbDoTruncate = U8(1)
		(*BtShared)(unsafe.Pointer(pBt)).FnPage = iLastPg
	}
	return SQLITE_OK
}

func finalDbSize(tls *libc.TLS, pBt uintptr, nOrig Pgno, nFree Pgno) Pgno {
	var nEntry int32
	var nPtrmap Pgno
	var nFin Pgno

	nEntry = int32((*BtShared)(unsafe.Pointer(pBt)).FusableSize / U32(5))
	nPtrmap = (nFree - nOrig + ptrmapPageno(tls, pBt, nOrig) + Pgno(nEntry)) / Pgno(nEntry)
	nFin = nOrig - nFree - nPtrmap
	if nOrig > U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) && nFin < U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) {
		nFin--
	}
	for ptrmapPageno(tls, pBt, nFin) == nFin || nFin == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) {
		nFin--
	}

	return nFin
}

func Xsqlite3BtreeIncrVacuum(tls *libc.TLS, p uintptr) int32 {
	var rc int32
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3BtreeEnter(tls, p)

	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum) != 0) {
		rc = SQLITE_DONE
	} else {
		var nOrig Pgno = btreePagecount(tls, pBt)
		var nFree Pgno = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36)
		var nFin Pgno = finalDbSize(tls, pBt, nOrig, nFree)

		if nOrig < nFin || nFree >= nOrig {
			rc = Xsqlite3CorruptError(tls, 72440)
		} else if nFree > Pgno(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 = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
				Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+28, (*BtShared)(unsafe.Pointer(pBt)).FnPage)
			}
		} else {
			rc = SQLITE_DONE
		}
	}
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func autoVacuumCommit(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pPager uintptr
	var pBt uintptr
	var db uintptr

	pBt = (*Btree)(unsafe.Pointer(p)).FpBt
	pPager = (*BtShared)(unsafe.Pointer(pBt)).FpPager

	invalidateAllOverflowCache(tls, pBt)

	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FincrVacuum) != 0) {
		var nFin Pgno
		var nFree Pgno
		var nVac Pgno
		var iFree Pgno
		var nOrig Pgno

		nOrig = btreePagecount(tls, pBt)
		if ptrmapPageno(tls, pBt, nOrig) == nOrig || nOrig == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) {
			return Xsqlite3CorruptError(tls, 72491)
		}

		nFree = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36)
		db = (*Btree)(unsafe.Pointer(p)).Fdb
		if (*Sqlite3)(unsafe.Pointer(db)).FxAutovacPages != 0 {
			var iDb int32
			for iDb = 0; iDb < (*Sqlite3)(unsafe.Pointer(db)).FnDb; iDb++ {
				if (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpBt == p {
					break
				}
			}
			nVac = (*struct {
				f func(*libc.TLS, uintptr, uintptr, U32, U32, U32) uint32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxAutovacPages})).f(tls,
				(*Sqlite3)(unsafe.Pointer(db)).FpAutovacPagesArg,
				(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName,
				nOrig,
				nFree,
				(*BtShared)(unsafe.Pointer(pBt)).FpageSize)
			if nVac > nFree {
				nVac = nFree
			}
			if nVac == Pgno(0) {
				return SQLITE_OK
			}
		} else {
			nVac = nFree
		}
		nFin = finalDbSize(tls, pBt, nOrig, nVac)
		if nFin > nOrig {
			return Xsqlite3CorruptError(tls, 72518)
		}
		if nFin < nOrig {
			rc = saveAllCursors(tls, pBt, uint32(0), uintptr(0))
		}
		for iFree = nOrig; iFree > nFin && rc == SQLITE_OK; iFree-- {
			rc = incrVacuumStep(tls, pBt, nFin, iFree, libc.Bool32(nVac == nFree))
		}
		if (rc == SQLITE_DONE || rc == SQLITE_OK) && nFree > Pgno(0) {
			rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
			if nVac == nFree {
				Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+32, uint32(0))
				Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36, uint32(0))
			}
			Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+28, nFin)
			(*BtShared)(unsafe.Pointer(pBt)).FbDoTruncate = U8(1)
			(*BtShared)(unsafe.Pointer(pBt)).FnPage = nFin
		}
		if rc != SQLITE_OK {
			Xsqlite3PagerRollback(tls, pPager)
		}
	}

	return rc
}

func Xsqlite3BtreeCommitPhaseOne(tls *libc.TLS, p uintptr, zSuperJrnl uintptr) int32 {
	var rc int32 = SQLITE_OK
	if int32((*Btree)(unsafe.Pointer(p)).FinTrans) == TRANS_WRITE {
		var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
		Xsqlite3BtreeEnter(tls, p)
		if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			rc = autoVacuumCommit(tls, p)
			if rc != SQLITE_OK {
				Xsqlite3BtreeLeave(tls, p)
				return rc
			}
		}
		if (*BtShared)(unsafe.Pointer(pBt)).FbDoTruncate != 0 {
			Xsqlite3PagerTruncateImage(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, (*BtShared)(unsafe.Pointer(pBt)).FnPage)
		}
		rc = Xsqlite3PagerCommitPhaseOne(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, zSuperJrnl, 0)
		Xsqlite3BtreeLeave(tls, p)
	}
	return rc
}

func btreeEndTransaction(tls *libc.TLS, p uintptr) {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	var db uintptr = (*Btree)(unsafe.Pointer(p)).Fdb

	(*BtShared)(unsafe.Pointer(pBt)).FbDoTruncate = U8(0)
	if int32((*Btree)(unsafe.Pointer(p)).FinTrans) > TRANS_NONE && (*Sqlite3)(unsafe.Pointer(db)).FnVdbeRead > 1 {
		downgradeAllSharedCacheTableLocks(tls, p)
		(*Btree)(unsafe.Pointer(p)).FinTrans = U8(TRANS_READ)
	} else {
		if int32((*Btree)(unsafe.Pointer(p)).FinTrans) != TRANS_NONE {
			clearAllSharedCacheTableLocks(tls, p)
			(*BtShared)(unsafe.Pointer(pBt)).FnTransaction--
			if 0 == (*BtShared)(unsafe.Pointer(pBt)).FnTransaction {
				(*BtShared)(unsafe.Pointer(pBt)).FinTransaction = U8(TRANS_NONE)
			}
		}

		(*Btree)(unsafe.Pointer(p)).FinTrans = U8(TRANS_NONE)
		unlockBtreeIfUnused(tls, pBt)
	}

}

func Xsqlite3BtreeCommitPhaseTwo(tls *libc.TLS, p uintptr, bCleanup int32) int32 {
	if int32((*Btree)(unsafe.Pointer(p)).FinTrans) == TRANS_NONE {
		return SQLITE_OK
	}
	Xsqlite3BtreeEnter(tls, p)

	if int32((*Btree)(unsafe.Pointer(p)).FinTrans) == TRANS_WRITE {
		var rc int32
		var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

		rc = Xsqlite3PagerCommitPhaseTwo(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager)
		if rc != SQLITE_OK && bCleanup == 0 {
			Xsqlite3BtreeLeave(tls, p)
			return rc
		}
		(*Btree)(unsafe.Pointer(p)).FiBDataVersion--
		(*BtShared)(unsafe.Pointer(pBt)).FinTransaction = U8(TRANS_READ)
		btreeClearHasContent(tls, pBt)
	}

	btreeEndTransaction(tls, p)
	Xsqlite3BtreeLeave(tls, p)
	return SQLITE_OK
}

func Xsqlite3BtreeCommit(tls *libc.TLS, p uintptr) int32 {
	var rc int32
	Xsqlite3BtreeEnter(tls, p)
	rc = Xsqlite3BtreeCommitPhaseOne(tls, p, uintptr(0))
	if rc == SQLITE_OK {
		rc = Xsqlite3BtreeCommitPhaseTwo(tls, p, 0)
	}
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeTripAllCursors(tls *libc.TLS, pBtree uintptr, errCode int32, writeOnly int32) int32 {
	var p uintptr
	var rc int32 = SQLITE_OK

	if pBtree != 0 {
		Xsqlite3BtreeEnter(tls, pBtree)
		for p = (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(pBtree)).FpBt)).FpCursor; p != 0; p = (*BtCursor)(unsafe.Pointer(p)).FpNext {
			if writeOnly != 0 && int32((*BtCursor)(unsafe.Pointer(p)).FcurFlags)&BTCF_WriteFlag == 0 {
				if int32((*BtCursor)(unsafe.Pointer(p)).FeState) == CURSOR_VALID || int32((*BtCursor)(unsafe.Pointer(p)).FeState) == CURSOR_SKIPNEXT {
					rc = saveCursorPosition(tls, p)
					if rc != SQLITE_OK {
						Xsqlite3BtreeTripAllCursors(tls, pBtree, rc, 0)
						break
					}
				}
			} else {
				Xsqlite3BtreeClearCursor(tls, p)
				(*BtCursor)(unsafe.Pointer(p)).FeState = U8(CURSOR_FAULT)
				(*BtCursor)(unsafe.Pointer(p)).FskipNext = errCode
			}
			btreeReleaseAllCursorPages(tls, p)
		}
		Xsqlite3BtreeLeave(tls, pBtree)
	}
	return rc
}

func btreeSetNPage(tls *libc.TLS, pBt uintptr, pPage1 uintptr) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = int32(Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+28))

	if *(*int32)(unsafe.Pointer(bp)) == 0 {
		Xsqlite3PagerPagecount(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, bp)
	}

	(*BtShared)(unsafe.Pointer(pBt)).FnPage = U32(*(*int32)(unsafe.Pointer(bp)))
}

func Xsqlite3BtreeRollback(tls *libc.TLS, p uintptr, tripCode int32, writeOnly int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3BtreeEnter(tls, p)
	if tripCode == SQLITE_OK {
		rc = libc.AssignInt32(&tripCode, saveAllCursors(tls, pBt, uint32(0), uintptr(0)))
		if rc != 0 {
			writeOnly = 0
		}
	} else {
		rc = SQLITE_OK
	}
	if tripCode != 0 {
		var rc2 int32 = Xsqlite3BtreeTripAllCursors(tls, p, tripCode, writeOnly)

		if rc2 != SQLITE_OK {
			rc = rc2
		}
	}

	if int32((*Btree)(unsafe.Pointer(p)).FinTrans) == TRANS_WRITE {
		var rc2 int32

		rc2 = Xsqlite3PagerRollback(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager)
		if rc2 != SQLITE_OK {
			rc = rc2
		}

		if btreeGetPage(tls, pBt, uint32(1), bp, 0) == SQLITE_OK {
			btreeSetNPage(tls, pBt, *(*uintptr)(unsafe.Pointer(bp)))
			releasePageOne(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}

		(*BtShared)(unsafe.Pointer(pBt)).FinTransaction = U8(TRANS_READ)
		btreeClearHasContent(tls, pBt)
	}

	btreeEndTransaction(tls, p)
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeBeginStmt(tls *libc.TLS, p uintptr, iStatement int32) int32 {
	var rc int32
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	Xsqlite3BtreeEnter(tls, p)

	rc = Xsqlite3PagerOpenSavepoint(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, iStatement)
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeSavepoint(tls *libc.TLS, p uintptr, op int32, iSavepoint int32) int32 {
	var rc int32 = SQLITE_OK
	if p != 0 && int32((*Btree)(unsafe.Pointer(p)).FinTrans) == TRANS_WRITE {
		var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

		Xsqlite3BtreeEnter(tls, p)
		if op == SAVEPOINT_ROLLBACK {
			rc = saveAllCursors(tls, pBt, uint32(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3PagerSavepoint(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, op, iSavepoint)
		}
		if rc == SQLITE_OK {
			if iSavepoint < 0 && int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_INITIALLY_EMPTY != 0 {
				(*BtShared)(unsafe.Pointer(pBt)).FnPage = U32(0)
			}
			rc = newDatabase(tls, pBt)
			btreeSetNPage(tls, pBt, (*BtShared)(unsafe.Pointer(pBt)).FpPage1)

		}
		Xsqlite3BtreeLeave(tls, p)
	}
	return rc
}

func btreeCursor(tls *libc.TLS, p uintptr, iTable Pgno, wrFlag int32, pKeyInfo uintptr, pCur uintptr) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	var pX uintptr

	if iTable <= Pgno(1) {
		if iTable < Pgno(1) {
			return Xsqlite3CorruptError(tls, 72982)
		} else if btreePagecount(tls, pBt) == Pgno(0) {
			iTable = Pgno(0)
		}
	}

	(*BtCursor)(unsafe.Pointer(pCur)).FpgnoRoot = iTable
	(*BtCursor)(unsafe.Pointer(pCur)).FiPage = int8(-1)
	(*BtCursor)(unsafe.Pointer(pCur)).FpKeyInfo = pKeyInfo
	(*BtCursor)(unsafe.Pointer(pCur)).FpBtree = p
	(*BtCursor)(unsafe.Pointer(pCur)).FpBt = pBt
	(*BtCursor)(unsafe.Pointer(pCur)).FcurFlags = U8(0)

	for pX = (*BtShared)(unsafe.Pointer(pBt)).FpCursor; pX != 0; pX = (*BtCursor)(unsafe.Pointer(pX)).FpNext {
		if (*BtCursor)(unsafe.Pointer(pX)).FpgnoRoot == iTable {
			*(*U8)(unsafe.Pointer(pX + 1)) |= U8(BTCF_Multiple)
			(*BtCursor)(unsafe.Pointer(pCur)).FcurFlags = U8(BTCF_Multiple)
		}
	}
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
	(*BtCursor)(unsafe.Pointer(pCur)).FpNext = (*BtShared)(unsafe.Pointer(pBt)).FpCursor
	(*BtShared)(unsafe.Pointer(pBt)).FpCursor = pCur
	if wrFlag != 0 {
		*(*U8)(unsafe.Pointer(pCur + 1)) |= U8(BTCF_WriteFlag)
		(*BtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags = U8(0)
		if (*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace == uintptr(0) {
			return allocateTempSpace(tls, pBt)
		}
	} else {
		(*BtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags = U8(PAGER_GET_READONLY)
	}
	return SQLITE_OK
}

func btreeCursorWithLock(tls *libc.TLS, p uintptr, iTable Pgno, wrFlag int32, pKeyInfo uintptr, pCur uintptr) int32 {
	var rc int32
	Xsqlite3BtreeEnter(tls, p)
	rc = btreeCursor(tls, p, iTable, wrFlag, pKeyInfo, pCur)
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeCursor(tls *libc.TLS, p uintptr, iTable Pgno, wrFlag int32, pKeyInfo uintptr, pCur uintptr) int32 {
	if (*Btree)(unsafe.Pointer(p)).Fsharable != 0 {
		return btreeCursorWithLock(tls, p, iTable, wrFlag, pKeyInfo, pCur)
	} else {
		return btreeCursor(tls, p, iTable, wrFlag, pKeyInfo, pCur)
	}
	return int32(0)
}

func Xsqlite3BtreeCursorSize(tls *libc.TLS) int32 {
	return int32((uint64(unsafe.Sizeof(BtCursor{})) + uint64(7)) & libc.Uint64FromInt32(libc.CplInt32(7)))
}

func Xsqlite3BtreeCursorZero(tls *libc.TLS, p uintptr) {
	libc.Xmemset(tls, p, 0, uint64(uintptr(0)+32))
}

func Xsqlite3BtreeCloseCursor(tls *libc.TLS, pCur uintptr) int32 {
	var pBtree uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpBtree
	if pBtree != 0 {
		var pBt uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpBt
		Xsqlite3BtreeEnter(tls, pBtree)

		if (*BtShared)(unsafe.Pointer(pBt)).FpCursor == pCur {
			(*BtShared)(unsafe.Pointer(pBt)).FpCursor = (*BtCursor)(unsafe.Pointer(pCur)).FpNext
		} else {
			var pPrev uintptr = (*BtShared)(unsafe.Pointer(pBt)).FpCursor
			for __ccgo := true; __ccgo; __ccgo = pPrev != 0 {
				if (*BtCursor)(unsafe.Pointer(pPrev)).FpNext == pCur {
					(*BtCursor)(unsafe.Pointer(pPrev)).FpNext = (*BtCursor)(unsafe.Pointer(pCur)).FpNext
					break
				}
				pPrev = (*BtCursor)(unsafe.Pointer(pPrev)).FpNext
			}
		}
		btreeReleaseAllCursorPages(tls, pCur)
		unlockBtreeIfUnused(tls, pBt)
		Xsqlite3_free(tls, (*BtCursor)(unsafe.Pointer(pCur)).FaOverflow)
		Xsqlite3_free(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpKey)
		if int32((*BtShared)(unsafe.Pointer(pBt)).FopenFlags)&BTREE_SINGLE != 0 && (*BtShared)(unsafe.Pointer(pBt)).FpCursor == uintptr(0) {
			Xsqlite3BtreeClose(tls, pBtree)
		} else {
			Xsqlite3BtreeLeave(tls, pBtree)
		}
		(*BtCursor)(unsafe.Pointer(pCur)).FpBtree = uintptr(0)
	}
	return SQLITE_OK
}

func getCellInfo(tls *libc.TLS, pCur uintptr) {
	if int32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize) == 0 {
		*(*U8)(unsafe.Pointer(pCur + 1)) |= U8(BTCF_ValidNKey)
		btreeParseCell(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpPage, int32((*BtCursor)(unsafe.Pointer(pCur)).Fix), pCur+48)
	} else {
	}
}

func Xsqlite3BtreeCursorIsValidNN(tls *libc.TLS, pCur uintptr) int32 {
	return libc.Bool32(int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID)
}

func Xsqlite3BtreeIntegerKey(tls *libc.TLS, pCur uintptr) I64 {
	getCellInfo(tls, pCur)
	return (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey
}

func Xsqlite3BtreeCursorPin(tls *libc.TLS, pCur uintptr) {
	*(*U8)(unsafe.Pointer(pCur + 1)) |= U8(BTCF_Pinned)
}

func Xsqlite3BtreeCursorUnpin(tls *libc.TLS, pCur uintptr) {
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_Pinned))
}

func Xsqlite3BtreeOffset(tls *libc.TLS, pCur uintptr) I64 {
	getCellInfo(tls, pCur)
	return I64((*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FpageSize)*(I64((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).Fpgno)-int64(1)) + (int64((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload)-int64((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FaData))/1
}

func Xsqlite3BtreePayloadSize(tls *libc.TLS, pCur uintptr) U32 {
	getCellInfo(tls, pCur)
	return (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload
}

func Xsqlite3BtreeMaxRecordSize(tls *libc.TLS, pCur uintptr) Sqlite3_int64 {
	return Sqlite3_int64((*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FpageSize) * Sqlite3_int64((*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FnPage)
}

func getOverflowPage(tls *libc.TLS, pBt uintptr, ovfl Pgno, ppPage uintptr, pPgnoNext uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var next Pgno = Pgno(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	var rc int32 = SQLITE_OK

	if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
		var iGuess Pgno = ovfl + Pgno(1)

		for ptrmapPageno(tls, pBt, iGuess) == iGuess || iGuess == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) {
			iGuess++
		}

		if iGuess <= btreePagecount(tls, pBt) {
			rc = ptrmapGet(tls, pBt, iGuess, bp, bp+4)
			if rc == SQLITE_OK && int32(*(*U8)(unsafe.Pointer(bp))) == PTRMAP_OVERFLOW2 && *(*Pgno)(unsafe.Pointer(bp + 4)) == ovfl {
				next = iGuess
				rc = SQLITE_DONE
			}
		}
	}

	if rc == SQLITE_OK {
		rc = btreeGetPage(tls, pBt, ovfl, bp+8, func() int32 {
			if ppPage == uintptr(0) {
				return PAGER_GET_READONLY
			}
			return 0
		}())

		if rc == SQLITE_OK {
			next = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData)
		}
	}

	*(*Pgno)(unsafe.Pointer(pPgnoNext)) = next
	if ppPage != 0 {
		*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer(bp + 8))
	} else {
		releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}
	return func() int32 {
		if rc == SQLITE_DONE {
			return SQLITE_OK
		}
		return rc
	}()
}

func copyPayload(tls *libc.TLS, pPayload uintptr, pBuf uintptr, nByte int32, eOp int32, pDbPage uintptr) int32 {
	if eOp != 0 {
		var rc int32 = Xsqlite3PagerWrite(tls, pDbPage)
		if rc != SQLITE_OK {
			return rc
		}
		libc.Xmemcpy(tls, pPayload, pBuf, uint64(nByte))
	} else {
		libc.Xmemcpy(tls, pBuf, pPayload, uint64(nByte))
	}
	return SQLITE_OK
}

func accessPayload(tls *libc.TLS, pCur uintptr, offset U32, amt U32, pBuf uintptr, eOp int32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var aPayload uintptr
	var rc int32 = SQLITE_OK
	var iIdx int32 = 0
	var pPage uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
	var pBt uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpBt

	if int32((*BtCursor)(unsafe.Pointer(pCur)).Fix) >= int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) {
		return Xsqlite3CorruptError(tls, 73389)
	}

	getCellInfo(tls, pCur)
	aPayload = (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload

	if Uptr((int64(aPayload)-int64((*MemPage)(unsafe.Pointer(pPage)).FaData))/1) > Uptr((*BtShared)(unsafe.Pointer(pBt)).FusableSize-U32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)) {
		return Xsqlite3CorruptError(tls, 73404)
	}

	if offset < U32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) {
		var a int32 = int32(amt)
		if U32(a)+offset > U32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) {
			a = int32(U32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) - offset)
		}
		rc = copyPayload(tls, aPayload+uintptr(offset), pBuf, a, eOp, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage)
		offset = U32(0)
		pBuf += uintptr(a)
		amt = amt - U32(a)
	} else {
		offset = offset - U32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)
	}

	if rc == SQLITE_OK && amt > U32(0) {
		var ovflSize U32 = (*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32(4)

		*(*Pgno)(unsafe.Pointer(bp)) = Xsqlite3Get4byte(tls, aPayload+uintptr((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal))

		if int32((*BtCursor)(unsafe.Pointer(pCur)).FcurFlags)&BTCF_ValidOvfl == 0 {
			var nOvfl int32 = int32(((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload - U32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) + ovflSize - U32(1)) / ovflSize)
			if (*BtCursor)(unsafe.Pointer(pCur)).FaOverflow == uintptr(0) ||
				nOvfl*int32(unsafe.Sizeof(Pgno(0))) > Xsqlite3MallocSize(tls, (*BtCursor)(unsafe.Pointer(pCur)).FaOverflow) {
				var aNew uintptr = Xsqlite3Realloc(tls,
					(*BtCursor)(unsafe.Pointer(pCur)).FaOverflow, uint64(nOvfl*2)*uint64(unsafe.Sizeof(Pgno(0))))
				if aNew == uintptr(0) {
					return SQLITE_NOMEM
				} else {
					(*BtCursor)(unsafe.Pointer(pCur)).FaOverflow = aNew
				}
			}
			libc.Xmemset(tls, (*BtCursor)(unsafe.Pointer(pCur)).FaOverflow, 0, uint64(nOvfl)*uint64(unsafe.Sizeof(Pgno(0))))
			*(*U8)(unsafe.Pointer(pCur + 1)) |= U8(BTCF_ValidOvfl)
		} else {
			if *(*Pgno)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(offset/ovflSize)*4)) != 0 {
				iIdx = int32(offset / ovflSize)
				*(*Pgno)(unsafe.Pointer(bp)) = *(*Pgno)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx)*4))
				offset = offset % ovflSize
			}
		}

		for *(*Pgno)(unsafe.Pointer(bp)) != 0 {
			if *(*Pgno)(unsafe.Pointer(bp)) > (*BtShared)(unsafe.Pointer(pBt)).FnPage {
				return Xsqlite3CorruptError(tls, 73466)
			}

			*(*Pgno)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx)*4)) = *(*Pgno)(unsafe.Pointer(bp))

			if offset >= ovflSize {
				if *(*Pgno)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx+1)*4)) != 0 {
					*(*Pgno)(unsafe.Pointer(bp)) = *(*Pgno)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FaOverflow + uintptr(iIdx+1)*4))
				} else {
					rc = getOverflowPage(tls, pBt, *(*Pgno)(unsafe.Pointer(bp)), uintptr(0), bp)
				}
				offset = offset - ovflSize
			} else {
				var a int32 = int32(amt)
				if U32(a)+offset > ovflSize {
					a = int32(ovflSize - offset)
				}

				{
					rc = Xsqlite3PagerGet(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, *(*Pgno)(unsafe.Pointer(bp)), bp+8,
						func() int32 {
							if eOp == 0 {
								return PAGER_GET_READONLY
							}
							return 0
						}())
					if rc == SQLITE_OK {
						aPayload = Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
						*(*Pgno)(unsafe.Pointer(bp)) = Xsqlite3Get4byte(tls, aPayload)
						rc = copyPayload(tls, aPayload+uintptr(offset+U32(4)), pBuf, a, eOp, *(*uintptr)(unsafe.Pointer(bp + 8)))
						Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
						offset = U32(0)
					}

				}
				amt = amt - U32(a)
				if amt == U32(0) {
					return rc
				}
				pBuf += uintptr(a)
			}
			if rc != 0 {
				break
			}
			iIdx++
		}
	}

	if rc == SQLITE_OK && amt > U32(0) {
		return Xsqlite3CorruptError(tls, 73551)
	}
	return rc
}

func Xsqlite3BtreePayload(tls *libc.TLS, pCur uintptr, offset U32, amt U32, pBuf uintptr) int32 {
	return accessPayload(tls, pCur, offset, amt, pBuf, 0)
}

func accessPayloadChecked(tls *libc.TLS, pCur uintptr, offset U32, amt U32, pBuf uintptr) int32 {
	var rc int32
	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_INVALID {
		return SQLITE_ABORT
	}

	rc = btreeRestoreCursorPosition(tls, pCur)
	if rc != 0 {
		return rc
	}
	return accessPayload(tls, pCur, offset, amt, pBuf, 0)
}

func Xsqlite3BtreePayloadChecked(tls *libc.TLS, pCur uintptr, offset U32, amt U32, pBuf uintptr) int32 {
	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID {
		return accessPayload(tls, pCur, offset, amt, pBuf, 0)
	} else {
		return accessPayloadChecked(tls, pCur, offset, amt, pBuf)
	}
	return int32(0)
}

func fetchPayload(tls *libc.TLS, pCur uintptr, pAmt uintptr) uintptr {
	var amt int32

	amt = int32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)
	if amt > int32((int64((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FaDataEnd)-int64((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload))/1) {
		amt = func() int32 {
			if 0 > int32((int64((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FaDataEnd)-int64((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload))/1) {
				return 0
			}
			return int32((int64((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FaDataEnd) - int64((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload)) / 1)
		}()
	}
	*(*U32)(unsafe.Pointer(pAmt)) = U32(amt)
	return (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload
}

func Xsqlite3BtreePayloadFetch(tls *libc.TLS, pCur uintptr, pAmt uintptr) uintptr {
	return fetchPayload(tls, pCur, pAmt)
}

func moveToChild(tls *libc.TLS, pCur uintptr, newPgno U32) int32 {
	if int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) >= BTCURSOR_MAX_DEPTH-1 {
		return Xsqlite3CorruptError(tls, 73688)
	}
	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidNKey | BTCF_ValidOvfl))
	*(*U16)(unsafe.Pointer(pCur + 88 + uintptr((*BtCursor)(unsafe.Pointer(pCur)).FiPage)*2)) = (*BtCursor)(unsafe.Pointer(pCur)).Fix
	*(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr((*BtCursor)(unsafe.Pointer(pCur)).FiPage)*8)) = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(0)
	(*BtCursor)(unsafe.Pointer(pCur)).FiPage++
	return getAndInitPage(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpBt, newPgno, pCur+136, pCur,
		int32((*BtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags))
}

func moveToParent(tls *libc.TLS, pCur uintptr) {
	var pLeaf uintptr

	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidNKey | BTCF_ValidOvfl))
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = *(*U16)(unsafe.Pointer(pCur + 88 + uintptr(int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage)-1)*2))
	pLeaf = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
	(*BtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr(libc.PreDecInt8(&(*BtCursor)(unsafe.Pointer(pCur)).FiPage, 1))*8))
	releasePageNotNull(tls, pLeaf)
}

func moveToRoot(tls *libc.TLS, pCur uintptr) int32 {
	var pRoot uintptr
	var rc int32
	var subpage Pgno
	rc = SQLITE_OK

	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) >= 0) {
		goto __1
	}
	if !((*BtCursor)(unsafe.Pointer(pCur)).FiPage != 0) {
		goto __3
	}
	releasePageNotNull(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpPage)
__4:
	if !(libc.PreDecInt8(&(*BtCursor)(unsafe.Pointer(pCur)).FiPage, 1) != 0) {
		goto __5
	}
	releasePageNotNull(tls, *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr((*BtCursor)(unsafe.Pointer(pCur)).FiPage)*8)))
	goto __4
__5:
	;
	pRoot = libc.AssignPtrUintptr(pCur+136, *(*uintptr)(unsafe.Pointer(pCur + 144)))
	goto skip_init
__3:
	;
	goto __2
__1:
	if !((*BtCursor)(unsafe.Pointer(pCur)).FpgnoRoot == Pgno(0)) {
		goto __6
	}
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
	return SQLITE_EMPTY
	goto __7
__6:
	;
	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) >= CURSOR_REQUIRESEEK) {
		goto __8
	}
	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_FAULT) {
		goto __9
	}

	return (*BtCursor)(unsafe.Pointer(pCur)).FskipNext
__9:
	;
	Xsqlite3BtreeClearCursor(tls, pCur)
__8:
	;
	rc = getAndInitPage(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpBt, (*BtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur+136,
		uintptr(0), int32((*BtCursor)(unsafe.Pointer(pCur)).FcurPagerFlags))
	if !(rc != SQLITE_OK) {
		goto __10
	}
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
	return rc
__10:
	;
	(*BtCursor)(unsafe.Pointer(pCur)).FiPage = int8(0)
	(*BtCursor)(unsafe.Pointer(pCur)).FcurIntKey = (*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FintKey
__7:
	;
__2:
	;
	pRoot = (*BtCursor)(unsafe.Pointer(pCur)).FpPage

	if !(int32((*MemPage)(unsafe.Pointer(pRoot)).FisInit) == 0 || libc.Bool32((*BtCursor)(unsafe.Pointer(pCur)).FpKeyInfo == uintptr(0)) != int32((*MemPage)(unsafe.Pointer(pRoot)).FintKey)) {
		goto __11
	}
	return Xsqlite3CorruptError(tls, 73827)
__11:
	;
skip_init:
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(0)
	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_AtLast | BTCF_ValidNKey | BTCF_ValidOvfl))

	if !(int32((*MemPage)(unsafe.Pointer(pRoot)).FnCell) > 0) {
		goto __12
	}
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_VALID)
	goto __13
__12:
	if !!(int32((*MemPage)(unsafe.Pointer(pRoot)).Fleaf) != 0) {
		goto __14
	}
	if !((*MemPage)(unsafe.Pointer(pRoot)).Fpgno != Pgno(1)) {
		goto __16
	}
	return Xsqlite3CorruptError(tls, 73839)
__16:
	;
	subpage = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pRoot)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pRoot)).FhdrOffset)+8))
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_VALID)
	rc = moveToChild(tls, pCur, subpage)
	goto __15
__14:
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
	rc = SQLITE_EMPTY
__15:
	;
__13:
	;
	return rc
}

func moveToLeftmost(tls *libc.TLS, pCur uintptr) int32 {
	var pgno Pgno
	var rc int32 = SQLITE_OK
	var pPage uintptr

	for rc == SQLITE_OK && !(int32((*MemPage)(unsafe.Pointer(libc.AssignUintptr(&pPage, (*BtCursor)(unsafe.Pointer(pCur)).FpPage))).Fleaf) != 0) {
		pgno = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*int32((*BtCursor)(unsafe.Pointer(pCur)).Fix))))))))
		rc = moveToChild(tls, pCur, pgno)
	}
	return rc
}

func moveToRightmost(tls *libc.TLS, pCur uintptr) int32 {
	var pgno Pgno
	var rc int32 = SQLITE_OK
	var pPage uintptr = uintptr(0)

	for !(int32((*MemPage)(unsafe.Pointer(libc.AssignUintptr(&pPage, (*BtCursor)(unsafe.Pointer(pCur)).FpPage))).Fleaf) != 0) {
		pgno = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+8))
		(*BtCursor)(unsafe.Pointer(pCur)).Fix = (*MemPage)(unsafe.Pointer(pPage)).FnCell
		rc = moveToChild(tls, pCur, pgno)
		if rc != 0 {
			return rc
		}
	}
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) - 1)

	return SQLITE_OK
}

func Xsqlite3BtreeFirst(tls *libc.TLS, pCur uintptr, pRes uintptr) int32 {
	var rc int32

	rc = moveToRoot(tls, pCur)
	if rc == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRes)) = 0
		rc = moveToLeftmost(tls, pCur)
	} else if rc == SQLITE_EMPTY {
		*(*int32)(unsafe.Pointer(pRes)) = 1
		rc = SQLITE_OK
	}
	return rc
}

func btreeLast(tls *libc.TLS, pCur uintptr, pRes uintptr) int32 {
	var rc int32 = moveToRoot(tls, pCur)
	if rc == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRes)) = 0
		rc = moveToRightmost(tls, pCur)
		if rc == SQLITE_OK {
			*(*U8)(unsafe.Pointer(pCur + 1)) |= U8(BTCF_AtLast)
		} else {
			*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_AtLast))
		}
	} else if rc == SQLITE_EMPTY {
		*(*int32)(unsafe.Pointer(pRes)) = 1
		rc = SQLITE_OK
	}
	return rc
}

func Xsqlite3BtreeLast(tls *libc.TLS, pCur uintptr, pRes uintptr) int32 {
	if CURSOR_VALID == int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) && int32((*BtCursor)(unsafe.Pointer(pCur)).FcurFlags)&BTCF_AtLast != 0 {
		*(*int32)(unsafe.Pointer(pRes)) = 0
		return SQLITE_OK
	}
	return btreeLast(tls, pCur, pRes)
}

func Xsqlite3BtreeTableMoveto(tls *libc.TLS, pCur uintptr, intKey I64, biasRight int32, pRes uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	var lwr int32
	var upr int32
	var idx int32
	var c int32
	var chldPg Pgno
	var pPage uintptr
	var pCell uintptr

	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID && int32((*BtCursor)(unsafe.Pointer(pCur)).FcurFlags)&BTCF_ValidNKey != 0) {
		goto __1
	}
	if !((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == intKey) {
		goto __2
	}
	*(*int32)(unsafe.Pointer(pRes)) = 0
	return SQLITE_OK
__2:
	;
	if !((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey < intKey) {
		goto __3
	}
	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FcurFlags)&BTCF_AtLast != 0) {
		goto __4
	}
	*(*int32)(unsafe.Pointer(pRes)) = -1
	return SQLITE_OK
__4:
	;
	if !((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey+int64(1) == intKey) {
		goto __5
	}
	*(*int32)(unsafe.Pointer(pRes)) = 0
	rc = Xsqlite3BtreeNext(tls, pCur, 0)
	if !(rc == SQLITE_OK) {
		goto __6
	}
	getCellInfo(tls, pCur)
	if !((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == intKey) {
		goto __8
	}
	return SQLITE_OK
__8:
	;
	goto __7
__6:
	if !(rc != SQLITE_DONE) {
		goto __9
	}
	return rc
__9:
	;
__7:
	;
__5:
	;
__3:
	;
__1:
	;
	rc = moveToRoot(tls, pCur)
	if !(rc != 0) {
		goto __10
	}
	if !(rc == SQLITE_EMPTY) {
		goto __11
	}

	*(*int32)(unsafe.Pointer(pRes)) = -1
	return SQLITE_OK
__11:
	;
	return rc
__10:
	;
__12:
	pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage

	lwr = 0
	upr = int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) - 1

	idx = upr >> (1 - biasRight)
__15:
	pCell = (*MemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*idx))))))
	if !((*MemPage)(unsafe.Pointer(pPage)).FintKeyLeaf != 0) {
		goto __18
	}
__19:
	if !(0x80 <= int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pCell, 1))))) {
		goto __20
	}
	if !(pCell >= (*MemPage)(unsafe.Pointer(pPage)).FaDataEnd) {
		goto __21
	}
	return Xsqlite3CorruptError(tls, 74081)
__21:
	;
	goto __19
__20:
	;
__18:
	;
	Xsqlite3GetVarint(tls, pCell, bp)
	if !(*(*I64)(unsafe.Pointer(bp)) < intKey) {
		goto __22
	}
	lwr = idx + 1
	if !(lwr > upr) {
		goto __24
	}
	c = -1
	goto __17
__24:
	;
	goto __23
__22:
	if !(*(*I64)(unsafe.Pointer(bp)) > intKey) {
		goto __25
	}
	upr = idx - 1
	if !(lwr > upr) {
		goto __27
	}
	c = +1
	goto __17
__27:
	;
	goto __26
__25:
	;
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(idx)
	if !!(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
		goto __28
	}
	lwr = idx
	goto moveto_table_next_layer
	goto __29
__28:
	*(*U8)(unsafe.Pointer(pCur + 1)) |= U8(BTCF_ValidNKey)
	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey = *(*I64)(unsafe.Pointer(bp))
	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)
	*(*int32)(unsafe.Pointer(pRes)) = 0
	return SQLITE_OK
__29:
	;
__26:
	;
__23:
	;
	idx = (lwr + upr) >> 1
	goto __16
__16:
	goto __15
	goto __17
__17:
	;
	if !((*MemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		goto __30
	}

	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(idx)
	*(*int32)(unsafe.Pointer(pRes)) = c
	rc = SQLITE_OK
	goto moveto_table_finish
__30:
	;
moveto_table_next_layer:
	if !(lwr >= int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)) {
		goto __31
	}
	chldPg = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+8))
	goto __32
__31:
	chldPg = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*lwr)))))))
__32:
	;
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(lwr)
	rc = moveToChild(tls, pCur, chldPg)
	if !(rc != 0) {
		goto __33
	}
	goto __14
__33:
	;
	goto __13
__13:
	goto __12
	goto __14
__14:
	;
moveto_table_finish:
	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)

	return rc
}

func indexCellCompare(tls *libc.TLS, pCur uintptr, idx int32, pIdxKey uintptr, xRecordCompare RecordCompare) int32 {
	var pPage uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
	var c int32
	var nCell int32
	var pCell uintptr = (*MemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*idx))))))

	nCell = int32(*(*U8)(unsafe.Pointer(pCell)))
	if nCell <= int32((*MemPage)(unsafe.Pointer(pPage)).Fmax1bytePayload) {
		c = (*struct {
			f func(*libc.TLS, int32, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})).f(tls, nCell, pCell+1, pIdxKey)
	} else if !(int32(*(*U8)(unsafe.Pointer(pCell + 1)))&0x80 != 0) &&
		libc.AssignInt32(&nCell, nCell&0x7f<<7+int32(*(*U8)(unsafe.Pointer(pCell + 1)))) <= int32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		c = (*struct {
			f func(*libc.TLS, int32, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})).f(tls, nCell, pCell+2, pIdxKey)
	} else {
		c = 99
	}
	return c
}

func cursorOnLastPage(tls *libc.TLS, pCur uintptr) int32 {
	var i int32

	for i = 0; i < int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage); i++ {
		var pPage uintptr = *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr(i)*8))
		if int32(*(*U16)(unsafe.Pointer(pCur + 88 + uintptr(i)*2))) < int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) {
			return 0
		}
	}
	return 1
}

func Xsqlite3BtreeIndexMoveto(tls *libc.TLS, pCur uintptr, pIdxKey uintptr, pRes uintptr) int32 {
	var rc int32
	var xRecordCompare RecordCompare
	var c int32

	var pCellKey uintptr
	var pCellBody uintptr
	var nOverrun int32
	var nCell int32
	var lwr int32
	var upr int32
	var idx int32
	var c1 int32
	var chldPg Pgno
	var pPage uintptr
	var pCell uintptr

	xRecordCompare = Xsqlite3VdbeFindCompare(tls, pIdxKey)
	(*UnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode = U8(0)

	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_VALID &&
		(*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).Fleaf != 0 &&
		cursorOnLastPage(tls, pCur) != 0) {
		goto __1
	}
	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).Fix) == int32((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell)-1 &&
		libc.AssignInt32(&c, indexCellCompare(tls, pCur, int32((*BtCursor)(unsafe.Pointer(pCur)).Fix), pIdxKey, xRecordCompare)) <= 0 &&
		int32((*UnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode) == SQLITE_OK) {
		goto __2
	}
	*(*int32)(unsafe.Pointer(pRes)) = c
	return SQLITE_OK
__2:
	;
	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) > 0 &&
		indexCellCompare(tls, pCur, 0, pIdxKey, xRecordCompare) <= 0 &&
		int32((*UnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode) == SQLITE_OK) {
		goto __3
	}
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidOvfl))
	if !!(int32((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FisInit) != 0) {
		goto __4
	}
	return Xsqlite3CorruptError(tls, 74277)
__4:
	;
	goto bypass_moveto_root
__3:
	;
	(*UnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode = U8(SQLITE_OK)
__1:
	;
	rc = moveToRoot(tls, pCur)
	if !(rc != 0) {
		goto __5
	}
	if !(rc == SQLITE_EMPTY) {
		goto __6
	}

	*(*int32)(unsafe.Pointer(pRes)) = -1
	return SQLITE_OK
__6:
	;
	return rc
__5:
	;
bypass_moveto_root:
	;
__7:
	pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage

	lwr = 0
	upr = int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) - 1
	idx = upr >> 1
__10:
	pCell = (*MemPage)(unsafe.Pointer(pPage)).FaDataOfst + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*idx))))))

	nCell = int32(*(*U8)(unsafe.Pointer(pCell)))
	if !(nCell <= int32((*MemPage)(unsafe.Pointer(pPage)).Fmax1bytePayload)) {
		goto __13
	}

	c1 = (*struct {
		f func(*libc.TLS, int32, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})).f(tls, nCell, pCell+1, pIdxKey)
	goto __14
__13:
	if !(!(int32(*(*U8)(unsafe.Pointer(pCell + 1)))&0x80 != 0) &&
		libc.AssignInt32(&nCell, nCell&0x7f<<7+int32(*(*U8)(unsafe.Pointer(pCell + 1)))) <= int32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal)) {
		goto __15
	}

	c1 = (*struct {
		f func(*libc.TLS, int32, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{xRecordCompare})).f(tls, nCell, pCell+2, pIdxKey)
	goto __16
__15:
	pCellBody = pCell - uintptr((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	nOverrun = 18
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxParseCell})).f(tls, pPage, pCellBody, pCur+48)
	nCell = int32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey)

	if !(nCell < 2 || U32(nCell)/(*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FusableSize > (*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FnPage) {
		goto __17
	}
	rc = Xsqlite3CorruptError(tls, 74364)
	goto moveto_index_finish
__17:
	;
	pCellKey = Xsqlite3Malloc(tls, uint64(nCell+nOverrun))
	if !(pCellKey == uintptr(0)) {
		goto __18
	}
	rc = SQLITE_NOMEM
	goto moveto_index_finish
__18:
	;
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(idx)
	rc = accessPayload(tls, pCur, uint32(0), uint32(nCell), pCellKey, 0)
	libc.Xmemset(tls, pCellKey+uintptr(nCell), 0, uint64(nOverrun))
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidOvfl))
	if !(rc != 0) {
		goto __19
	}
	Xsqlite3_free(tls, pCellKey)
	goto moveto_index_finish
__19:
	;
	c1 = Xsqlite3VdbeRecordCompare(tls, nCell, pCellKey, pIdxKey)
	Xsqlite3_free(tls, pCellKey)
__16:
	;
__14:
	;
	if !(c1 < 0) {
		goto __20
	}
	lwr = idx + 1
	goto __21
__20:
	if !(c1 > 0) {
		goto __22
	}
	upr = idx - 1
	goto __23
__22:
	;
	*(*int32)(unsafe.Pointer(pRes)) = 0
	rc = SQLITE_OK
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(idx)
	if !((*UnpackedRecord)(unsafe.Pointer(pIdxKey)).FerrCode != 0) {
		goto __24
	}
	rc = Xsqlite3CorruptError(tls, 74396)
__24:
	;
	goto moveto_index_finish
__23:
	;
__21:
	;
	if !(lwr > upr) {
		goto __25
	}
	goto __12
__25:
	;
	idx = (lwr + upr) >> 1
	goto __11
__11:
	goto __10
	goto __12
__12:
	;
	if !((*MemPage)(unsafe.Pointer(pPage)).Fleaf != 0) {
		goto __26
	}

	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(idx)
	*(*int32)(unsafe.Pointer(pRes)) = c1
	rc = SQLITE_OK
	goto moveto_index_finish
__26:
	;
	if !(lwr >= int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)) {
		goto __27
	}
	chldPg = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+8))
	goto __28
__27:
	chldPg = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*lwr)))))))
__28:
	;
	(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(lwr)
	rc = moveToChild(tls, pCur, chldPg)
	if !(rc != 0) {
		goto __29
	}
	goto __9
__29:
	;
	goto __8
__8:
	goto __7
	goto __9
__9:
	;
moveto_index_finish:
	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)

	return rc
}

func Xsqlite3BtreeEof(tls *libc.TLS, pCur uintptr) int32 {
	return libc.Bool32(CURSOR_VALID != int32((*BtCursor)(unsafe.Pointer(pCur)).FeState))
}

func Xsqlite3BtreeRowCountEst(tls *libc.TLS, pCur uintptr) I64 {
	var n I64
	var i U8

	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		return int64(-1)
	}
	if int32((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).Fleaf) == 0 {
		return int64(-1)
	}

	n = I64((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell)
	for i = U8(0); int32(i) < int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage); i++ {
		n = n * I64((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr(i)*8)))).FnCell)
	}
	return n
}

func btreeNext(tls *libc.TLS, pCur uintptr) int32 {
	var rc int32
	var idx int32
	var pPage uintptr

	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		rc = func() int32 {
			if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) >= CURSOR_REQUIRESEEK {
				return btreeRestoreCursorPosition(tls, pCur)
			}
			return SQLITE_OK
		}()
		if rc != SQLITE_OK {
			return rc
		}
		if CURSOR_INVALID == int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) {
			return SQLITE_DONE
		}
		if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) == CURSOR_SKIPNEXT {
			(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_VALID)
			if (*BtCursor)(unsafe.Pointer(pCur)).FskipNext > 0 {
				return SQLITE_OK
			}
		}
	}

	pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
	idx = int32(libc.PreIncUint16(&(*BtCursor)(unsafe.Pointer(pCur)).Fix, 1))
	if !(int32((*MemPage)(unsafe.Pointer(pPage)).FisInit) != 0) || Xsqlite3FaultSim(tls, 412) != 0 {
		return Xsqlite3CorruptError(tls, 74512)
	}

	if idx >= int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) {
		if !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
			rc = moveToChild(tls, pCur, Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+8)))
			if rc != 0 {
				return rc
			}
			return moveToLeftmost(tls, pCur)
		}
		for __ccgo := true; __ccgo; __ccgo = int32((*BtCursor)(unsafe.Pointer(pCur)).Fix) >= int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) {
			if int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) == 0 {
				(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
				return SQLITE_DONE
			}
			moveToParent(tls, pCur)
			pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
		}
		if (*MemPage)(unsafe.Pointer(pPage)).FintKey != 0 {
			return Xsqlite3BtreeNext(tls, pCur, 0)
		} else {
			return SQLITE_OK
		}
	}
	if (*MemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
		return SQLITE_OK
	} else {
		return moveToLeftmost(tls, pCur)
	}
	return int32(0)
}

func Xsqlite3BtreeNext(tls *libc.TLS, pCur uintptr, flags int32) int32 {
	var pPage uintptr
	_ = flags

	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidNKey | BTCF_ValidOvfl))
	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		return btreeNext(tls, pCur)
	}
	pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
	if int32(libc.PreIncUint16(&(*BtCursor)(unsafe.Pointer(pCur)).Fix, 1)) >= int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) {
		(*BtCursor)(unsafe.Pointer(pCur)).Fix--
		return btreeNext(tls, pCur)
	}
	if (*MemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
		return SQLITE_OK
	} else {
		return moveToLeftmost(tls, pCur)
	}
	return int32(0)
}

func btreePrevious(tls *libc.TLS, pCur uintptr) int32 {
	var rc int32
	var pPage uintptr

	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		rc = func() int32 {
			if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) >= CURSOR_REQUIRESEEK {
				return btreeRestoreCursorPosition(tls, pCur)
			}
			return SQLITE_OK
		}()
		if rc != SQLITE_OK {
			return rc
		}
		if CURSOR_INVALID == int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) {
			return SQLITE_DONE
		}
		if CURSOR_SKIPNEXT == int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) {
			(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_VALID)
			if (*BtCursor)(unsafe.Pointer(pCur)).FskipNext < 0 {
				return SQLITE_OK
			}
		}
	}

	pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage

	if !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
		var idx int32 = int32((*BtCursor)(unsafe.Pointer(pCur)).Fix)
		rc = moveToChild(tls, pCur, Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*idx))))))))
		if rc != 0 {
			return rc
		}
		rc = moveToRightmost(tls, pCur)
	} else {
		for int32((*BtCursor)(unsafe.Pointer(pCur)).Fix) == 0 {
			if int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) == 0 {
				(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
				return SQLITE_DONE
			}
			moveToParent(tls, pCur)
		}

		(*BtCursor)(unsafe.Pointer(pCur)).Fix--
		pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
		if (*MemPage)(unsafe.Pointer(pPage)).FintKey != 0 && !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
			rc = Xsqlite3BtreePrevious(tls, pCur, 0)
		} else {
			rc = SQLITE_OK
		}
	}
	return rc
}

func Xsqlite3BtreePrevious(tls *libc.TLS, pCur uintptr, flags int32) int32 {
	_ = flags
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_AtLast | BTCF_ValidOvfl | BTCF_ValidNKey))
	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)
	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID ||
		int32((*BtCursor)(unsafe.Pointer(pCur)).Fix) == 0 ||
		int32((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).Fleaf) == 0 {
		return btreePrevious(tls, pCur)
	}
	(*BtCursor)(unsafe.Pointer(pCur)).Fix--
	return SQLITE_OK
}

func allocateBtreePage(tls *libc.TLS, pBt uintptr, ppPage uintptr, pPgno uintptr, nearby Pgno, eMode U8) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pPage1 uintptr
	var rc int32
	var n U32
	var k U32

	var pPrevTrunk uintptr
	var mxPage Pgno

	var iNewTrunk Pgno
	var d2 int32
	var dist int32
	var i U32
	var noContent int32

	var closest U32
	var iPage Pgno
	var aData uintptr

	var iTrunk Pgno
	var searchList U8
	var nSearch U32

	var bNoContent int32
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	pPrevTrunk = uintptr(0)

	pPage1 = (*BtShared)(unsafe.Pointer(pBt)).FpPage1
	mxPage = btreePagecount(tls, pBt)

	n = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+36)

	if !(n >= mxPage) {
		goto __1
	}
	return Xsqlite3CorruptError(tls, 74692)
__1:
	;
	if !(n > U32(0)) {
		goto __2
	}
	searchList = U8(0)
	nSearch = U32(0)

	if !(int32(eMode) == BTALLOC_EXACT) {
		goto __4
	}
	if !(nearby <= mxPage) {
		goto __6
	}

	rc = ptrmapGet(tls, pBt, nearby, bp, uintptr(0))
	if !(rc != 0) {
		goto __7
	}
	return rc
__7:
	;
	if !(int32(*(*U8)(unsafe.Pointer(bp))) == PTRMAP_FREEPAGE) {
		goto __8
	}
	searchList = U8(1)
__8:
	;
__6:
	;
	goto __5
__4:
	if !(int32(eMode) == BTALLOC_LE) {
		goto __9
	}
	searchList = U8(1)
__9:
	;
__5:
	;
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPage1)).FpDbPage)
	if !(rc != 0) {
		goto __10
	}
	return rc
__10:
	;
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+36, n-U32(1))

__11:
	pPrevTrunk = *(*uintptr)(unsafe.Pointer(bp + 8))
	if !(pPrevTrunk != 0) {
		goto __14
	}

	iTrunk = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPrevTrunk)).FaData)
	goto __15
__14:
	iTrunk = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+32)
__15:
	;
	if !(iTrunk > mxPage || libc.PostIncUint32(&nSearch, 1) > n) {
		goto __16
	}
	rc = Xsqlite3CorruptError(tls, 74748)
	goto __17
__16:
	rc = btreeGetUnusedPage(tls, pBt, iTrunk, bp+8, 0)
__17:
	;
	if !(rc != 0) {
		goto __18
	}
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	goto end_allocate_page
__18:
	;
	k = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData+4)
	if !(k == U32(0) && !(searchList != 0)) {
		goto __19
	}

	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpDbPage)
	if !(rc != 0) {
		goto __21
	}
	goto end_allocate_page
__21:
	;
	*(*Pgno)(unsafe.Pointer(pPgno)) = iTrunk
	libc.Xmemcpy(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+32, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData, uint64(4))
	*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer(bp + 8))
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

	goto __20
__19:
	if !(k > (*BtShared)(unsafe.Pointer(pBt)).FusableSize/U32(4)-U32(2)) {
		goto __22
	}

	rc = Xsqlite3CorruptError(tls, 74777)
	goto end_allocate_page
	goto __23
__22:
	if !(searchList != 0 &&
		(nearby == iTrunk || iTrunk < nearby && int32(eMode) == BTALLOC_LE)) {
		goto __24
	}

	*(*Pgno)(unsafe.Pointer(pPgno)) = iTrunk
	*(*uintptr)(unsafe.Pointer(ppPage)) = *(*uintptr)(unsafe.Pointer(bp + 8))
	searchList = U8(0)
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpDbPage)
	if !(rc != 0) {
		goto __26
	}
	goto end_allocate_page
__26:
	;
	if !(k == U32(0)) {
		goto __27
	}
	if !!(pPrevTrunk != 0) {
		goto __29
	}
	libc.Xmemcpy(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+32, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData, uint64(4))
	goto __30
__29:
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPrevTrunk)).FpDbPage)
	if !(rc != SQLITE_OK) {
		goto __31
	}
	goto end_allocate_page
__31:
	;
	libc.Xmemcpy(tls, (*MemPage)(unsafe.Pointer(pPrevTrunk)).FaData, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData, uint64(4))
__30:
	;
	goto __28
__27:
	iNewTrunk = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData+8)
	if !(iNewTrunk > mxPage) {
		goto __32
	}
	rc = Xsqlite3CorruptError(tls, 74811)
	goto end_allocate_page
__32:
	;
	rc = btreeGetUnusedPage(tls, pBt, iNewTrunk, bp+16, 0)
	if !(rc != SQLITE_OK) {
		goto __33
	}
	goto end_allocate_page
__33:
	;
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FpDbPage)
	if !(rc != SQLITE_OK) {
		goto __34
	}
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	goto end_allocate_page
__34:
	;
	libc.Xmemcpy(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaData, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData, uint64(4))
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaData+4, k-U32(1))
	libc.Xmemcpy(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaData+8, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData+12, uint64((k-U32(1))*U32(4)))
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if !!(pPrevTrunk != 0) {
		goto __35
	}

	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+32, iNewTrunk)
	goto __36
__35:
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPrevTrunk)).FpDbPage)
	if !(rc != 0) {
		goto __37
	}
	goto end_allocate_page
__37:
	;
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pPrevTrunk)).FaData, iNewTrunk)
__36:
	;
__28:
	;
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

	goto __25
__24:
	if !(k > U32(0)) {
		goto __38
	}
	aData = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FaData
	if !(nearby > Pgno(0)) {
		goto __39
	}
	closest = U32(0)
	if !(int32(eMode) == BTALLOC_LE) {
		goto __41
	}
	i = U32(0)
__43:
	if !(i < k) {
		goto __45
	}
	iPage = Xsqlite3Get4byte(tls, aData+uintptr(U32(8)+i*U32(4)))
	if !(iPage <= nearby) {
		goto __46
	}
	closest = i
	goto __45
__46:
	;
	goto __44
__44:
	i++
	goto __43
	goto __45
__45:
	;
	goto __42
__41:
	dist = Xsqlite3AbsInt32(tls, int32(Xsqlite3Get4byte(tls, aData+8)-nearby))
	i = U32(1)
__47:
	if !(i < k) {
		goto __49
	}
	d2 = Xsqlite3AbsInt32(tls, int32(Xsqlite3Get4byte(tls, aData+uintptr(U32(8)+i*U32(4)))-nearby))
	if !(d2 < dist) {
		goto __50
	}
	closest = i
	dist = d2
__50:
	;
	goto __48
__48:
	i++
	goto __47
	goto __49
__49:
	;
__42:
	;
	goto __40
__39:
	closest = U32(0)
__40:
	;
	iPage = Xsqlite3Get4byte(tls, aData+uintptr(U32(8)+closest*U32(4)))

	if !(iPage > mxPage || iPage < Pgno(2)) {
		goto __51
	}
	rc = Xsqlite3CorruptError(tls, 74876)
	goto end_allocate_page
__51:
	;
	if !(!(searchList != 0) ||
		(iPage == nearby || iPage < nearby && int32(eMode) == BTALLOC_LE)) {
		goto __52
	}
	*(*Pgno)(unsafe.Pointer(pPgno)) = iPage

	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpDbPage)
	if !(rc != 0) {
		goto __53
	}
	goto end_allocate_page
__53:
	;
	if !(closest < k-U32(1)) {
		goto __54
	}
	libc.Xmemcpy(tls, aData+uintptr(U32(8)+closest*U32(4)), aData+uintptr(U32(4)+k*U32(4)), uint64(4))
__54:
	;
	Xsqlite3Put4byte(tls, aData+4, k-U32(1))
	if !(btreeGetHasContent(tls, pBt, *(*Pgno)(unsafe.Pointer(pPgno))) != 0) {
		noContent = PAGER_GET_NOCONTENT
	} else {
		noContent = 0
	}
	rc = btreeGetUnusedPage(tls, pBt, *(*Pgno)(unsafe.Pointer(pPgno)), ppPage, noContent)
	if !(rc == SQLITE_OK) {
		goto __55
	}
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FpDbPage)
	if !(rc != SQLITE_OK) {
		goto __56
	}
	releasePage(tls, *(*uintptr)(unsafe.Pointer(ppPage)))
	*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
__56:
	;
__55:
	;
	searchList = U8(0)
__52:
	;
__38:
	;
__25:
	;
__23:
	;
__20:
	;
	releasePage(tls, pPrevTrunk)
	pPrevTrunk = uintptr(0)
	goto __12
__12:
	if searchList != 0 {
		goto __11
	}
	goto __13
__13:
	;
	goto __3
__2:
	if 0 == int32((*BtShared)(unsafe.Pointer(pBt)).FbDoTruncate) {
		bNoContent = PAGER_GET_NOCONTENT
	} else {
		bNoContent = 0
	}

	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
	if !(rc != 0) {
		goto __57
	}
	return rc
__57:
	;
	(*BtShared)(unsafe.Pointer(pBt)).FnPage++
	if !((*BtShared)(unsafe.Pointer(pBt)).FnPage == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1)) {
		goto __58
	}
	(*BtShared)(unsafe.Pointer(pBt)).FnPage++
__58:
	;
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && ptrmapPageno(tls, pBt, (*BtShared)(unsafe.Pointer(pBt)).FnPage) == (*BtShared)(unsafe.Pointer(pBt)).FnPage) {
		goto __59
	}

	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)

	rc = btreeGetUnusedPage(tls, pBt, (*BtShared)(unsafe.Pointer(pBt)).FnPage, bp+24, bNoContent)
	if !(rc == SQLITE_OK) {
		goto __60
	}
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).FpDbPage)
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
__60:
	;
	if !(rc != 0) {
		goto __61
	}
	return rc
__61:
	;
	(*BtShared)(unsafe.Pointer(pBt)).FnPage++
	if !((*BtShared)(unsafe.Pointer(pBt)).FnPage == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1)) {
		goto __62
	}
	(*BtShared)(unsafe.Pointer(pBt)).FnPage++
__62:
	;
__59:
	;
	Xsqlite3Put4byte(tls, uintptr(28)+(*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData, (*BtShared)(unsafe.Pointer(pBt)).FnPage)
	*(*Pgno)(unsafe.Pointer(pPgno)) = (*BtShared)(unsafe.Pointer(pBt)).FnPage

	rc = btreeGetUnusedPage(tls, pBt, *(*Pgno)(unsafe.Pointer(pPgno)), ppPage, bNoContent)
	if !(rc != 0) {
		goto __63
	}
	return rc
__63:
	;
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppPage)))).FpDbPage)
	if !(rc != SQLITE_OK) {
		goto __64
	}
	releasePage(tls, *(*uintptr)(unsafe.Pointer(ppPage)))
	*(*uintptr)(unsafe.Pointer(ppPage)) = uintptr(0)
__64:
	;
__3:
	;
end_allocate_page:
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	releasePage(tls, pPrevTrunk)

	return rc
}

func freePage2(tls *libc.TLS, pBt uintptr, pMemPage uintptr, iPage Pgno) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var iTrunk Pgno
	var pPage1 uintptr

	var nFree U32
	var nLeaf U32
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	iTrunk = Pgno(0)
	pPage1 = (*BtShared)(unsafe.Pointer(pBt)).FpPage1

	if !(iPage < Pgno(2) || iPage > (*BtShared)(unsafe.Pointer(pBt)).FnPage) {
		goto __1
	}
	return Xsqlite3CorruptError(tls, 75003)
__1:
	;
	if !(pMemPage != 0) {
		goto __2
	}
	*(*uintptr)(unsafe.Pointer(bp)) = pMemPage
	Xsqlite3PagerRef(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
	goto __3
__2:
	*(*uintptr)(unsafe.Pointer(bp)) = btreePageLookup(tls, pBt, iPage)
__3:
	;
	*(*int32)(unsafe.Pointer(bp + 8)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPage1)).FpDbPage)
	if !(*(*int32)(unsafe.Pointer(bp + 8)) != 0) {
		goto __4
	}
	goto freepage_out
__4:
	;
	nFree = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+36)
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+36, nFree+U32(1))

	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_SECURE_DELETE != 0) {
		goto __5
	}

	if !(!(*(*uintptr)(unsafe.Pointer(bp)) != 0) && libc.AssignPtrInt32(bp+8, btreeGetPage(tls, pBt, iPage, bp, 0)) != 0 ||
		libc.AssignPtrInt32(bp+8, Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)) != 0) {
		goto __6
	}
	goto freepage_out
__6:
	;
	libc.Xmemset(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, 0, uint64((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpBt)).FpageSize))
__5:
	;
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
		goto __7
	}
	ptrmapPut(tls, pBt, iPage, uint8(PTRMAP_FREEPAGE), uint32(0), bp+8)
	if !(*(*int32)(unsafe.Pointer(bp + 8)) != 0) {
		goto __8
	}
	goto freepage_out
__8:
	;
__7:
	;
	if !(nFree != U32(0)) {
		goto __9
	}

	iTrunk = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+32)
	if !(iTrunk > btreePagecount(tls, pBt)) {
		goto __10
	}
	*(*int32)(unsafe.Pointer(bp + 8)) = Xsqlite3CorruptError(tls, 75050)
	goto freepage_out
__10:
	;
	*(*int32)(unsafe.Pointer(bp + 8)) = btreeGetPage(tls, pBt, iTrunk, bp+16, 0)
	if !(*(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK) {
		goto __11
	}
	goto freepage_out
__11:
	;
	nLeaf = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaData+4)

	if !(nLeaf > (*BtShared)(unsafe.Pointer(pBt)).FusableSize/U32(4)-U32(2)) {
		goto __12
	}
	*(*int32)(unsafe.Pointer(bp + 8)) = Xsqlite3CorruptError(tls, 75061)
	goto freepage_out
__12:
	;
	if !(nLeaf < (*BtShared)(unsafe.Pointer(pBt)).FusableSize/U32(4)-U32(8)) {
		goto __13
	}

	*(*int32)(unsafe.Pointer(bp + 8)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FpDbPage)
	if !(*(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK) {
		goto __14
	}
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaData+4, nLeaf+U32(1))
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaData+uintptr(U32(8)+nLeaf*U32(4)), iPage)
	if !(*(*uintptr)(unsafe.Pointer(bp)) != 0 && int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_SECURE_DELETE == 0) {
		goto __15
	}
	Xsqlite3PagerDontWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
__15:
	;
	*(*int32)(unsafe.Pointer(bp + 8)) = btreeSetHasContent(tls, pBt, iPage)
__14:
	;
	goto freepage_out
__13:
	;
__9:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) && SQLITE_OK != libc.AssignPtrInt32(bp+8, btreeGetPage(tls, pBt, iPage, bp, 0))) {
		goto __16
	}
	goto freepage_out
__16:
	;
	*(*int32)(unsafe.Pointer(bp + 8)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
	if !(*(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK) {
		goto __17
	}
	goto freepage_out
__17:
	;
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData, iTrunk)
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+4, uint32(0))
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pPage1)).FaData+32, iPage)

freepage_out:
	if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
		goto __18
	}
	(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FisInit = U8(0)
__18:
	;
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	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, (*MemPage)(unsafe.Pointer(pPage)).FpBt, pPage, (*MemPage)(unsafe.Pointer(pPage)).Fpgno)
	}
}

func clearCellOverflow(tls *libc.TLS, pPage uintptr, pCell uintptr, pInfo uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var pBt uintptr
	var ovflPgno Pgno
	var rc int32
	var nOvfl int32
	var ovflPageSize U32

	if pCell+uintptr((*CellInfo)(unsafe.Pointer(pInfo)).FnSize) > (*MemPage)(unsafe.Pointer(pPage)).FaDataEnd {
		return Xsqlite3CorruptError(tls, 75150)
	}
	ovflPgno = Xsqlite3Get4byte(tls, pCell+uintptr((*CellInfo)(unsafe.Pointer(pInfo)).FnSize)-uintptr(4))
	pBt = (*MemPage)(unsafe.Pointer(pPage)).FpBt

	ovflPageSize = (*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32(4)
	nOvfl = int32(((*CellInfo)(unsafe.Pointer(pInfo)).FnPayload - U32((*CellInfo)(unsafe.Pointer(pInfo)).FnLocal) + ovflPageSize - U32(1)) / ovflPageSize)

	for libc.PostDecInt32(&nOvfl, 1) != 0 {
		*(*Pgno)(unsafe.Pointer(bp + 8)) = Pgno(0)
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		if ovflPgno < Pgno(2) || ovflPgno > btreePagecount(tls, pBt) {
			return Xsqlite3CorruptError(tls, 75167)
		}
		if nOvfl != 0 {
			rc = getOverflowPage(tls, pBt, ovflPgno, bp, bp+8)
			if rc != 0 {
				return rc
			}
		}

		if (*(*uintptr)(unsafe.Pointer(bp)) != 0 || libc.AssignPtrUintptr(bp, btreePageLookup(tls, pBt, ovflPgno)) != uintptr(0)) &&
			Xsqlite3PagerPageRefcount(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage) != 1 {
			rc = Xsqlite3CorruptError(tls, 75187)
		} else {
			rc = freePage2(tls, pBt, *(*uintptr)(unsafe.Pointer(bp)), ovflPgno)
		}

		if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
			Xsqlite3PagerUnref(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
		}
		if rc != 0 {
			return rc
		}
		ovflPgno = *(*Pgno)(unsafe.Pointer(bp + 8))
	}
	return SQLITE_OK
}

func fillInCell(tls *libc.TLS, pPage uintptr, pCell uintptr, pX uintptr, pnSize uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var nPayload int32
	var pSrc uintptr
	var nSrc int32
	var n int32

	var mn int32
	var spaceLeft int32
	var pToRelease uintptr
	var pPrior uintptr
	var pPayload uintptr
	var pBt uintptr

	var nHeader int32

	nHeader = int32((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize)
	if (*MemPage)(unsafe.Pointer(pPage)).FintKey != 0 {
		nPayload = (*BtreePayload)(unsafe.Pointer(pX)).FnData + (*BtreePayload)(unsafe.Pointer(pX)).FnZero
		pSrc = (*BtreePayload)(unsafe.Pointer(pX)).FpData
		nSrc = (*BtreePayload)(unsafe.Pointer(pX)).FnData

		nHeader = nHeader + int32(func() uint8 {
			if U32(nPayload) < U32(0x80) {
				return uint8(func() int32 { *(*uint8)(unsafe.Pointer(pCell + uintptr(nHeader))) = uint8(nPayload); return 1 }())
			}
			return uint8(Xsqlite3PutVarint(tls, pCell+uintptr(nHeader), uint64(nPayload)))
		}())
		nHeader = nHeader + Xsqlite3PutVarint(tls, pCell+uintptr(nHeader), *(*U64)(unsafe.Pointer(pX + 8)))
	} else {
		nSrc = libc.AssignInt32(&nPayload, int32((*BtreePayload)(unsafe.Pointer(pX)).FnKey))
		pSrc = (*BtreePayload)(unsafe.Pointer(pX)).FpKey
		nHeader = nHeader + int32(func() uint8 {
			if U32(nPayload) < U32(0x80) {
				return uint8(func() int32 { *(*uint8)(unsafe.Pointer(pCell + uintptr(nHeader))) = uint8(nPayload); return 1 }())
			}
			return uint8(Xsqlite3PutVarint(tls, pCell+uintptr(nHeader), uint64(nPayload)))
		}())
	}

	pPayload = pCell + uintptr(nHeader)
	if nPayload <= int32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		n = nHeader + nPayload

		if n < 4 {
			n = 4
		}
		*(*int32)(unsafe.Pointer(pnSize)) = n

		libc.Xmemcpy(tls, pPayload, pSrc, uint64(nSrc))
		libc.Xmemset(tls, pPayload+uintptr(nSrc), 0, uint64(nPayload-nSrc))
		return SQLITE_OK
	}

	mn = int32((*MemPage)(unsafe.Pointer(pPage)).FminLocal)
	n = int32(U32(mn) + U32(nPayload-mn)%((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize-U32(4)))

	if n > int32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal) {
		n = mn
	}
	spaceLeft = n
	*(*int32)(unsafe.Pointer(pnSize)) = n + nHeader + 4
	pPrior = pCell + uintptr(nHeader+n)
	pToRelease = uintptr(0)
	*(*Pgno)(unsafe.Pointer(bp + 8)) = Pgno(0)
	pBt = (*MemPage)(unsafe.Pointer(pPage)).FpBt

	for 1 != 0 {
		n = nPayload
		if n > spaceLeft {
			n = spaceLeft
		}

		if nSrc >= n {
			libc.Xmemcpy(tls, pPayload, pSrc, uint64(n))
		} else if nSrc > 0 {
			n = nSrc
			libc.Xmemcpy(tls, pPayload, pSrc, uint64(n))
		} else {
			libc.Xmemset(tls, pPayload, 0, uint64(n))
		}
		nPayload = nPayload - n
		if nPayload <= 0 {
			break
		}
		pPayload += uintptr(n)
		pSrc += uintptr(n)
		nSrc = nSrc - n
		spaceLeft = spaceLeft - n
		if spaceLeft == 0 {
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			var pgnoPtrmap Pgno = *(*Pgno)(unsafe.Pointer(bp + 8))
			if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
				for __ccgo := true; __ccgo; __ccgo = ptrmapPageno(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 8))) == *(*Pgno)(unsafe.Pointer(bp + 8)) || *(*Pgno)(unsafe.Pointer(bp + 8)) == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) {
					*(*Pgno)(unsafe.Pointer(bp + 8))++
				}
			}
			*(*int32)(unsafe.Pointer(bp + 12)) = allocateBtreePage(tls, pBt, bp, bp+8, *(*Pgno)(unsafe.Pointer(bp + 8)), uint8(0))

			if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK {
				var eType U8 = func() uint8 {
					if pgnoPtrmap != 0 {
						return uint8(PTRMAP_OVERFLOW2)
					}
					return uint8(PTRMAP_OVERFLOW1)
				}()
				ptrmapPut(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 8)), eType, pgnoPtrmap, bp+12)
				if *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
					releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
				}
			}
			if *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
				releasePage(tls, pToRelease)
				return *(*int32)(unsafe.Pointer(bp + 12))
			}

			Xsqlite3Put4byte(tls, pPrior, *(*Pgno)(unsafe.Pointer(bp + 8)))
			releasePage(tls, pToRelease)
			pToRelease = *(*uintptr)(unsafe.Pointer(bp))
			pPrior = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData
			Xsqlite3Put4byte(tls, pPrior, uint32(0))
			pPayload = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData + 4
			spaceLeft = int32((*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32(4))
		}
	}
	releasePage(tls, pToRelease)
	return SQLITE_OK
}

func dropCell(tls *libc.TLS, pPage uintptr, idx int32, sz int32, pRC uintptr) {
	var pc U32
	var data uintptr
	var ptr uintptr
	var rc int32
	var hdr int32

	if *(*int32)(unsafe.Pointer(pRC)) != 0 {
		return
	}

	data = (*MemPage)(unsafe.Pointer(pPage)).FaData
	ptr = (*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*idx)

	pc = U32(int32(*(*U8)(unsafe.Pointer(ptr)))<<8 | int32(*(*U8)(unsafe.Pointer(ptr + 1))))
	hdr = int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)

	if pc+U32(sz) > (*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize {
		*(*int32)(unsafe.Pointer(pRC)) = Xsqlite3CorruptError(tls, 75440)
		return
	}
	rc = freeSpace(tls, pPage, uint16(pc), uint16(sz))
	if rc != 0 {
		*(*int32)(unsafe.Pointer(pRC)) = rc
		return
	}
	(*MemPage)(unsafe.Pointer(pPage)).FnCell--
	if int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) == 0 {
		libc.Xmemset(tls, data+uintptr(hdr+1), 0, uint64(4))
		*(*U8)(unsafe.Pointer(data + uintptr(hdr+7))) = U8(0)
		*(*U8)(unsafe.Pointer(data + uintptr(hdr+5))) = U8((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize >> 8)
		*(*U8)(unsafe.Pointer(data + uintptr(hdr+5) + 1)) = U8((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize)
		(*MemPage)(unsafe.Pointer(pPage)).FnFree = int32((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FusableSize - U32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset) -
			U32((*MemPage)(unsafe.Pointer(pPage)).FchildPtrSize) - U32(8))
	} else {
		libc.Xmemmove(tls, ptr, ptr+uintptr(2), uint64(2*(int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)-idx)))
		*(*U8)(unsafe.Pointer(data + uintptr(hdr+3))) = U8(int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) >> 8)
		*(*U8)(unsafe.Pointer(data + uintptr(hdr+3) + 1)) = U8((*MemPage)(unsafe.Pointer(pPage)).FnCell)
		*(*int32)(unsafe.Pointer(pPage + 20)) += 2
	}
}

func insertCell(tls *libc.TLS, pPage uintptr, i int32, pCell uintptr, sz int32, pTemp uintptr, iChild Pgno) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*int32)(unsafe.Pointer(bp)) = 0
	var j int32
	var data uintptr
	var pIns uintptr

	if (*MemPage)(unsafe.Pointer(pPage)).FnOverflow != 0 || sz+2 > (*MemPage)(unsafe.Pointer(pPage)).FnFree {
		if pTemp != 0 {
			libc.Xmemcpy(tls, pTemp, pCell, uint64(sz))
			pCell = pTemp
		}
		if iChild != 0 {
			Xsqlite3Put4byte(tls, pCell, iChild)
		}
		j = int32(libc.PostIncUint8(&(*MemPage)(unsafe.Pointer(pPage)).FnOverflow, 1))

		*(*uintptr)(unsafe.Pointer(pPage + 40 + uintptr(j)*8)) = pCell
		*(*U16)(unsafe.Pointer(pPage + 28 + uintptr(j)*2)) = U16(i)

	} else {
		var rc int32 = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage)
		if rc != SQLITE_OK {
			return rc
		}

		data = (*MemPage)(unsafe.Pointer(pPage)).FaData

		rc = allocateSpace(tls, pPage, sz, bp)
		if rc != 0 {
			return rc
		}

		*(*int32)(unsafe.Pointer(pPage + 20)) -= int32(U16(2 + sz))
		if iChild != 0 {
			libc.Xmemcpy(tls, data+uintptr(*(*int32)(unsafe.Pointer(bp))+4), pCell+uintptr(4), uint64(sz-4))
			Xsqlite3Put4byte(tls, data+uintptr(*(*int32)(unsafe.Pointer(bp))), iChild)
		} else {
			libc.Xmemcpy(tls, data+uintptr(*(*int32)(unsafe.Pointer(bp))), pCell, uint64(sz))
		}
		pIns = (*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(i*2)
		libc.Xmemmove(tls, pIns+uintptr(2), pIns, uint64(2*(int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)-i)))
		*(*U8)(unsafe.Pointer(pIns)) = U8(*(*int32)(unsafe.Pointer(bp)) >> 8)
		*(*U8)(unsafe.Pointer(pIns + 1)) = U8(*(*int32)(unsafe.Pointer(bp)))
		(*MemPage)(unsafe.Pointer(pPage)).FnCell++

		if int32(libc.PreIncUint8(&*(*U8)(unsafe.Pointer(data + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+4))), 1)) == 0 {
			*(*U8)(unsafe.Pointer(data + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+3)))++
		}

		if (*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FpBt)).FautoVacuum != 0 {
			*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK

			ptrmapPutOvflPtr(tls, pPage, pPage, pCell, bp+4)
			if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
				return *(*int32)(unsafe.Pointer(bp + 4))
			}
		}
	}
	return SQLITE_OK
}

type CellArray1 = struct {
	FnCell       int32
	F__ccgo_pad1 [4]byte
	FpRef        uintptr
	FapCell      uintptr
	FszCell      uintptr
	FapEnd       [6]uintptr
	FixNx        [6]int32
}

type CellArray = CellArray1

func populateCellCache(tls *libc.TLS, p uintptr, idx int32, N int32) {
	var pRef uintptr = (*CellArray)(unsafe.Pointer(p)).FpRef
	var szCell uintptr = (*CellArray)(unsafe.Pointer(p)).FszCell

	for N > 0 {
		if int32(*(*U16)(unsafe.Pointer(szCell + uintptr(idx)*2))) == 0 {
			*(*U16)(unsafe.Pointer(szCell + uintptr(idx)*2)) = (*struct {
				f func(*libc.TLS, uintptr, uintptr) U16
			})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pRef)).FxCellSize})).f(tls, pRef, *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(p)).FapCell + uintptr(idx)*8)))
		} else {
		}
		idx++
		N--
	}
}

func computeCellSize(tls *libc.TLS, p uintptr, N int32) U16 {
	*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2)) = (*struct {
		f func(*libc.TLS, uintptr, uintptr) U16
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer((*CellArray)(unsafe.Pointer(p)).FpRef)).FxCellSize})).f(tls, (*CellArray)(unsafe.Pointer(p)).FpRef, *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(p)).FapCell + uintptr(N)*8)))
	return *(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2))
}

func cachedCellSize(tls *libc.TLS, p uintptr, N int32) U16 {
	if *(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2)) != 0 {
		return *(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2))
	}
	return computeCellSize(tls, p, N)
}

func rebuildPage(tls *libc.TLS, pCArray uintptr, iFirst int32, nCell int32, pPg uintptr) int32 {
	var hdr int32 = int32((*MemPage)(unsafe.Pointer(pPg)).FhdrOffset)
	var aData uintptr = (*MemPage)(unsafe.Pointer(pPg)).FaData
	var usableSize int32 = int32((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPg)).FpBt)).FusableSize)
	var pEnd uintptr = aData + uintptr(usableSize)
	var i int32 = iFirst
	var j U32
	var iEnd int32 = i + nCell
	var pCellptr uintptr = (*MemPage)(unsafe.Pointer(pPg)).FaCellIdx
	var pTmp uintptr = Xsqlite3PagerTempSpace(tls, (*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPg)).FpBt)).FpPager)
	var pData uintptr
	var k int32
	var pSrcEnd uintptr

	j = U32(int32(*(*U8)(unsafe.Pointer(aData + uintptr(hdr+5))))<<8 | int32(*(*U8)(unsafe.Pointer(aData + uintptr(hdr+5) + 1))))
	if j > U32(usableSize) {
		j = U32(0)
	}
	libc.Xmemcpy(tls, pTmp+uintptr(j), aData+uintptr(j), uint64(U32(usableSize)-j))

	for k = 0; *(*int32)(unsafe.Pointer(pCArray + 80 + uintptr(k)*4)) <= i && k < NB*2; k++ {
	}
	pSrcEnd = *(*uintptr)(unsafe.Pointer(pCArray + 32 + uintptr(k)*8))

	pData = pEnd
	for 1 != 0 {
		var pCell uintptr = *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8))
		var sz U16 = *(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(pCArray)).FszCell + uintptr(i)*2))

		if Uptr(pCell) >= Uptr(aData+uintptr(j)) && Uptr(pCell) < Uptr(pEnd) {
			if Uptr(pCell+uintptr(sz)) > Uptr(pEnd) {
				return Xsqlite3CorruptError(tls, 75741)
			}
			pCell = pTmp + uintptr((int64(pCell)-int64(aData))/1)
		} else if Uptr(pCell+uintptr(sz)) > Uptr(pSrcEnd) &&
			Uptr(pCell) < Uptr(pSrcEnd) {
			return Xsqlite3CorruptError(tls, 75746)
		}

		pData -= uintptr(sz)
		*(*U8)(unsafe.Pointer(pCellptr)) = U8((int64(pData) - int64(aData)) / 1 >> 8)
		*(*U8)(unsafe.Pointer(pCellptr + 1)) = U8((int64(pData) - int64(aData)) / 1)
		pCellptr += uintptr(2)
		if pData < pCellptr {
			return Xsqlite3CorruptError(tls, 75752)
		}
		libc.Xmemmove(tls, pData, pCell, uint64(sz))

		i++
		if i >= iEnd {
			break
		}
		if *(*int32)(unsafe.Pointer(pCArray + 80 + uintptr(k)*4)) <= i {
			k++
			pSrcEnd = *(*uintptr)(unsafe.Pointer(pCArray + 32 + uintptr(k)*8))
		}
	}

	(*MemPage)(unsafe.Pointer(pPg)).FnCell = U16(nCell)
	(*MemPage)(unsafe.Pointer(pPg)).FnOverflow = U8(0)

	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+1))) = U8(int32(0) >> 8)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+1) + 1)) = U8(0)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+3))) = U8(int32((*MemPage)(unsafe.Pointer(pPg)).FnCell) >> 8)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+3) + 1)) = U8((*MemPage)(unsafe.Pointer(pPg)).FnCell)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+5))) = U8((int64(pData) - int64(aData)) / 1 >> 8)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+5) + 1)) = U8((int64(pData) - int64(aData)) / 1)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+7))) = U8(0x00)
	return SQLITE_OK
}

func pageInsertArray(tls *libc.TLS, pPg uintptr, pBegin uintptr, ppData uintptr, pCellptr uintptr, iFirst int32, nCell int32, pCArray uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var i int32 = iFirst
	var aData uintptr = (*MemPage)(unsafe.Pointer(pPg)).FaData
	var pData uintptr = *(*uintptr)(unsafe.Pointer(ppData))
	var iEnd int32 = iFirst + nCell
	var k int32
	var pEnd uintptr

	if iEnd <= iFirst {
		return 0
	}
	for k = 0; *(*int32)(unsafe.Pointer(pCArray + 80 + uintptr(k)*4)) <= i && k < NB*2; k++ {
	}
	pEnd = *(*uintptr)(unsafe.Pointer(pCArray + 32 + uintptr(k)*8))
	for 1 != 0 {
		var sz int32

		var pSlot uintptr

		sz = int32(*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(pCArray)).FszCell + uintptr(i)*2)))
		if int32(*(*U8)(unsafe.Pointer(aData + 1))) == 0 && int32(*(*U8)(unsafe.Pointer(aData + 2))) == 0 || libc.AssignUintptr(&pSlot, pageFindSlot(tls, pPg, sz, bp)) == uintptr(0) {
			if (int64(pData)-int64(pBegin))/1 < int64(sz) {
				return 1
			}
			pData -= uintptr(sz)
			pSlot = pData
		}

		if Uptr(*(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8))+uintptr(sz)) > Uptr(pEnd) &&
			Uptr(*(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8))) < Uptr(pEnd) {
			Xsqlite3CorruptError(tls, 75837)
			return 1
		}
		libc.Xmemmove(tls, pSlot, *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8)), uint64(sz))
		*(*U8)(unsafe.Pointer(pCellptr)) = U8((int64(pSlot) - int64(aData)) / 1 >> 8)
		*(*U8)(unsafe.Pointer(pCellptr + 1)) = U8((int64(pSlot) - int64(aData)) / 1)
		pCellptr += uintptr(2)
		i++
		if i >= iEnd {
			break
		}
		if *(*int32)(unsafe.Pointer(pCArray + 80 + uintptr(k)*4)) <= i {
			k++
			pEnd = *(*uintptr)(unsafe.Pointer(pCArray + 32 + uintptr(k)*8))
		}
	}
	*(*uintptr)(unsafe.Pointer(ppData)) = pData
	return 0
}

func pageFreeArray(tls *libc.TLS, pPg uintptr, iFirst int32, nCell int32, pCArray uintptr) int32 {
	var aData uintptr = (*MemPage)(unsafe.Pointer(pPg)).FaData
	var pEnd uintptr = aData + uintptr((*BtShared)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPg)).FpBt)).FusableSize)
	var pStart uintptr = aData + uintptr(int32((*MemPage)(unsafe.Pointer(pPg)).FhdrOffset)+8+int32((*MemPage)(unsafe.Pointer(pPg)).FchildPtrSize))
	var nRet int32 = 0
	var i int32
	var iEnd int32 = iFirst + nCell
	var pFree uintptr = uintptr(0)
	var szFree int32 = 0

	for i = iFirst; i < iEnd; i++ {
		var pCell uintptr = *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(pCArray)).FapCell + uintptr(i)*8))
		if Uptr(pCell) >= Uptr(pStart) && Uptr(pCell) < Uptr(pEnd) {
			var sz int32

			sz = int32(*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(pCArray)).FszCell + uintptr(i)*2)))
			if pFree != pCell+uintptr(sz) {
				if pFree != 0 {
					freeSpace(tls, pPg, U16((int64(pFree)-int64(aData))/1), uint16(szFree))
				}
				pFree = pCell
				szFree = sz
				if pFree+uintptr(sz) > pEnd {
					return 0
				}
			} else {
				pFree = pCell
				szFree = szFree + sz
			}
			nRet++
		}
	}
	if pFree != 0 {
		freeSpace(tls, pPg, U16((int64(pFree)-int64(aData))/1), uint16(szFree))
	}
	return nRet
}

func editPage(tls *libc.TLS, pPg uintptr, iOld int32, iNew int32, nNew int32, pCArray uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var aData uintptr
	var hdr int32
	var pBegin uintptr
	var nCell int32

	var pCellptr uintptr
	var i int32
	var iOldEnd int32
	var iNewEnd int32
	var nShift int32
	var nTail int32
	var nAdd int32
	var iCell int32
	aData = (*MemPage)(unsafe.Pointer(pPg)).FaData
	hdr = int32((*MemPage)(unsafe.Pointer(pPg)).FhdrOffset)
	pBegin = (*MemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(nNew*2)
	nCell = int32((*MemPage)(unsafe.Pointer(pPg)).FnCell)
	iOldEnd = iOld + int32((*MemPage)(unsafe.Pointer(pPg)).FnCell) + int32((*MemPage)(unsafe.Pointer(pPg)).FnOverflow)
	iNewEnd = iNew + nNew

	if !(iOld < iNew) {
		goto __1
	}
	nShift = pageFreeArray(tls, pPg, iOld, iNew-iOld, pCArray)
	if !(nShift > nCell) {
		goto __2
	}
	return Xsqlite3CorruptError(tls, 75951)
__2:
	;
	libc.Xmemmove(tls, (*MemPage)(unsafe.Pointer(pPg)).FaCellIdx, (*MemPage)(unsafe.Pointer(pPg)).FaCellIdx+uintptr(nShift*2), uint64(nCell*2))
	nCell = nCell - nShift
__1:
	;
	if !(iNewEnd < iOldEnd) {
		goto __3
	}
	nTail = pageFreeArray(tls, pPg, iNewEnd, iOldEnd-iNewEnd, pCArray)

	nCell = nCell - nTail
__3:
	;
	*(*uintptr)(unsafe.Pointer(bp)) = aData + uintptr((int32(*(*U8)(unsafe.Pointer(aData + uintptr(hdr+5))))<<8|int32(*(*U8)(unsafe.Pointer(aData + uintptr(hdr+5) + 1)))-1)&0xffff+1)
	if !(*(*uintptr)(unsafe.Pointer(bp)) < pBegin) {
		goto __4
	}
	goto editpage_fail
__4:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp)) > (*MemPage)(unsafe.Pointer(pPg)).FaDataEnd) {
		goto __5
	}
	goto editpage_fail
__5:
	;
	if !(iNew < iOld) {
		goto __6
	}
	nAdd = func() int32 {
		if nNew < iOld-iNew {
			return nNew
		}
		return iOld - iNew
	}()

	pCellptr = (*MemPage)(unsafe.Pointer(pPg)).FaCellIdx
	libc.Xmemmove(tls, pCellptr+uintptr(nAdd*2), pCellptr, uint64(nCell*2))
	if !(pageInsertArray(tls,
		pPg, pBegin, bp, pCellptr,
		iNew, nAdd, pCArray) != 0) {
		goto __7
	}
	goto editpage_fail
__7:
	;
	nCell = nCell + nAdd
__6:
	;
	i = 0
__8:
	if !(i < int32((*MemPage)(unsafe.Pointer(pPg)).FnOverflow)) {
		goto __10
	}
	iCell = iOld + int32(*(*U16)(unsafe.Pointer(pPg + 28 + uintptr(i)*2))) - iNew
	if !(iCell >= 0 && iCell < nNew) {
		goto __11
	}
	pCellptr = (*MemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(iCell*2)
	if !(nCell > iCell) {
		goto __12
	}
	libc.Xmemmove(tls, pCellptr+2, pCellptr, uint64((nCell-iCell)*2))
__12:
	;
	nCell++
	cachedCellSize(tls, pCArray, iCell+iNew)
	if !(pageInsertArray(tls,
		pPg, pBegin, bp, pCellptr,
		iCell+iNew, 1, pCArray) != 0) {
		goto __13
	}
	goto editpage_fail
__13:
	;
__11:
	;
	goto __9
__9:
	i++
	goto __8
	goto __10
__10:
	;
	pCellptr = (*MemPage)(unsafe.Pointer(pPg)).FaCellIdx + uintptr(nCell*2)
	if !(pageInsertArray(tls,
		pPg, pBegin, bp, pCellptr,
		iNew+nCell, nNew-nCell, pCArray) != 0) {
		goto __14
	}
	goto editpage_fail
__14:
	;
	(*MemPage)(unsafe.Pointer(pPg)).FnCell = U16(nNew)
	(*MemPage)(unsafe.Pointer(pPg)).FnOverflow = U8(0)

	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+3))) = U8(int32((*MemPage)(unsafe.Pointer(pPg)).FnCell) >> 8)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+3) + 1)) = U8((*MemPage)(unsafe.Pointer(pPg)).FnCell)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+5))) = U8((int64(*(*uintptr)(unsafe.Pointer(bp))) - int64(aData)) / 1 >> 8)
	*(*U8)(unsafe.Pointer(aData + uintptr(hdr+5) + 1)) = U8((int64(*(*uintptr)(unsafe.Pointer(bp))) - int64(aData)) / 1)

	return SQLITE_OK
editpage_fail:
	populateCellCache(tls, pCArray, iNew, nNew)
	return rebuildPage(tls, pCArray, iNew, nNew, pPg)
}

func balance_quick(tls *libc.TLS, pParent uintptr, pPage uintptr, pSpace uintptr) int32 {
	bp := tls.Alloc(140)
	defer tls.Free(140)

	var pBt uintptr = (*MemPage)(unsafe.Pointer(pPage)).FpBt

	if int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) == 0 {
		return Xsqlite3CorruptError(tls, 76064)
	}

	*(*int32)(unsafe.Pointer(bp + 136)) = allocateBtreePage(tls, pBt, bp, bp+8, uint32(0), uint8(0))

	if *(*int32)(unsafe.Pointer(bp + 136)) == SQLITE_OK {
		var pOut uintptr = pSpace + 4
		*(*uintptr)(unsafe.Pointer(bp + 16)) = *(*uintptr)(unsafe.Pointer(pPage + 40))
		*(*U16)(unsafe.Pointer(bp + 24)) = (*struct {
			f func(*libc.TLS, uintptr, uintptr) U16
		})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxCellSize})).f(tls, pPage, *(*uintptr)(unsafe.Pointer(bp + 16)))
		var pStop uintptr

		zeroPage(tls, *(*uintptr)(unsafe.Pointer(bp)), PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF)
		(*CellArray)(unsafe.Pointer(bp + 32)).FnCell = 1
		(*CellArray)(unsafe.Pointer(bp + 32)).FpRef = pPage
		(*CellArray)(unsafe.Pointer(bp + 32)).FapCell = bp + 16
		(*CellArray)(unsafe.Pointer(bp + 32)).FszCell = bp + 24
		*(*uintptr)(unsafe.Pointer(bp + 32 + 32)) = (*MemPage)(unsafe.Pointer(pPage)).FaDataEnd
		*(*int32)(unsafe.Pointer(bp + 32 + 80)) = 2
		*(*int32)(unsafe.Pointer(bp + 136)) = rebuildPage(tls, bp+32, 0, 1, *(*uintptr)(unsafe.Pointer(bp)))
		if *(*int32)(unsafe.Pointer(bp + 136)) != 0 {
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
			return *(*int32)(unsafe.Pointer(bp + 136))
		}
		(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnFree = int32((*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FcellOffset) - U32(2) - U32(*(*U16)(unsafe.Pointer(bp + 24))))

		if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			ptrmapPut(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 8)), uint8(PTRMAP_BTREE), (*MemPage)(unsafe.Pointer(pParent)).Fpgno, bp+136)
			if int32(*(*U16)(unsafe.Pointer(bp + 24))) > int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FminLocal) {
				ptrmapPutOvflPtr(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 16)), bp+136)
			}
		}

		*(*uintptr)(unsafe.Pointer(bp + 16)) = (*MemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*(int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)-1)))))))
		pStop = *(*uintptr)(unsafe.Pointer(bp + 16)) + 9
		for int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 16)), 1))))&0x80 != 0 && *(*uintptr)(unsafe.Pointer(bp + 16)) < pStop {
		}
		pStop = *(*uintptr)(unsafe.Pointer(bp + 16)) + 9
		for int32(libc.AssignPtrUint8(libc.PostIncUintptr(&pOut, 1), *(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 16)), 1)))))&0x80 != 0 && *(*uintptr)(unsafe.Pointer(bp + 16)) < pStop {
		}

		if *(*int32)(unsafe.Pointer(bp + 136)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 136)) = insertCell(tls, pParent, int32((*MemPage)(unsafe.Pointer(pParent)).FnCell), pSpace, int32((int64(pOut)-int64(pSpace))/1),
				uintptr(0), (*MemPage)(unsafe.Pointer(pPage)).Fpgno)
		}

		Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pParent)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pParent)).FhdrOffset)+8), *(*Pgno)(unsafe.Pointer(bp + 8)))

		releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}

	return *(*int32)(unsafe.Pointer(bp + 136))
}

func copyNodeContent(tls *libc.TLS, pFrom uintptr, pTo uintptr, pRC uintptr) {
	if *(*int32)(unsafe.Pointer(pRC)) == SQLITE_OK {
		var pBt uintptr = (*MemPage)(unsafe.Pointer(pFrom)).FpBt
		var aFrom uintptr = (*MemPage)(unsafe.Pointer(pFrom)).FaData
		var aTo uintptr = (*MemPage)(unsafe.Pointer(pTo)).FaData
		var iFromHdr int32 = int32((*MemPage)(unsafe.Pointer(pFrom)).FhdrOffset)
		var iToHdr int32 = func() int32 {
			if (*MemPage)(unsafe.Pointer(pTo)).Fpgno == Pgno(1) {
				return 100
			}
			return 0
		}()
		var rc int32
		var iData int32

		iData = int32(*(*U8)(unsafe.Pointer(aFrom + uintptr(iFromHdr+5))))<<8 | int32(*(*U8)(unsafe.Pointer(aFrom + uintptr(iFromHdr+5) + 1)))
		libc.Xmemcpy(tls, aTo+uintptr(iData), aFrom+uintptr(iData), uint64((*BtShared)(unsafe.Pointer(pBt)).FusableSize-U32(iData)))
		libc.Xmemcpy(tls, aTo+uintptr(iToHdr), aFrom+uintptr(iFromHdr), uint64(int32((*MemPage)(unsafe.Pointer(pFrom)).FcellOffset)+2*int32((*MemPage)(unsafe.Pointer(pFrom)).FnCell)))

		(*MemPage)(unsafe.Pointer(pTo)).FisInit = U8(0)
		rc = btreeInitPage(tls, pTo)
		if rc == SQLITE_OK {
			rc = btreeComputeFreeSpace(tls, pTo)
		}
		if rc != SQLITE_OK {
			*(*int32)(unsafe.Pointer(pRC)) = rc
			return
		}

		if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			*(*int32)(unsafe.Pointer(pRC)) = setChildPtrmaps(tls, pTo)
		}
	}
}

func balance_nonroot(tls *libc.TLS, pParent uintptr, iParentIdx int32, aOvflSpace uintptr, isRoot int32, bBulk int32) int32 {
	bp := tls.Alloc(312)
	defer tls.Free(312)

	var pBt uintptr
	var nMaxCells int32
	var nNew int32
	var nOld int32
	var i int32
	var j int32
	var k int32
	var nxDiv int32

	var leafCorrection U16
	var leafData int32
	var usableSpace int32
	var pageFlags int32
	var iSpace1 int32
	var iOvflSpace int32
	var szScratch int32

	var pRight uintptr

	var aSpace1 uintptr

	var iOff int32
	var sz U16
	var pTemp uintptr
	var pOld uintptr
	var limit int32
	var aData uintptr
	var maskPage U16
	var piCell uintptr
	var piEnd uintptr
	var p uintptr
	var sz1 int32
	var szR int32
	var szD int32
	var szRight int32
	var szLeft int32
	var r int32
	var d int32

	var pgnoA Pgno
	var pgnoB Pgno
	var pgnoTemp Pgno
	var fgA U16
	var fgB U16
	var iB int32
	var pOld1 uintptr
	var pCell uintptr
	var pOld2 uintptr
	var pNew1 uintptr
	var cntOldNext int32
	var iNew int32
	var iOld int32

	var pCell1 uintptr
	var pTemp1 uintptr
	var sz2 int32
	var pSrcEnd uintptr
	var pNew2 uintptr
	var iNew1 int32
	var iOld1 int32
	var nNewCell int32
	var iPg int32
	var key U32
	nMaxCells = 0
	nNew = 0
	*(*int32)(unsafe.Pointer(bp + 172)) = SQLITE_OK
	iSpace1 = 0
	iOvflSpace = 0

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([5]U8{})))
	libc.Xmemset(tls, bp+8, 0, uint64(unsafe.Sizeof(CellArray{})))
	pBt = (*MemPage)(unsafe.Pointer(pParent)).FpBt

	if !!(aOvflSpace != 0) {
		goto __1
	}
	return SQLITE_NOMEM
__1:
	;
	i = int32((*MemPage)(unsafe.Pointer(pParent)).FnOverflow) + int32((*MemPage)(unsafe.Pointer(pParent)).FnCell)
	if !(i < 2) {
		goto __2
	}
	nxDiv = 0
	goto __3
__2:
	;
	if !(iParentIdx == 0) {
		goto __4
	}
	nxDiv = 0
	goto __5
__4:
	if !(iParentIdx == i) {
		goto __6
	}
	nxDiv = i - 2 + bBulk
	goto __7
__6:
	nxDiv = iParentIdx - 1
__7:
	;
__5:
	;
	i = 2 - bBulk
__3:
	;
	nOld = i + 1
	if !(i+nxDiv-int32((*MemPage)(unsafe.Pointer(pParent)).FnOverflow) == int32((*MemPage)(unsafe.Pointer(pParent)).FnCell)) {
		goto __8
	}
	pRight = (*MemPage)(unsafe.Pointer(pParent)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pParent)).FhdrOffset)+8)
	goto __9
__8:
	pRight = (*MemPage)(unsafe.Pointer(pParent)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pParent)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pParent)).FaCellIdx + uintptr(2*(i+nxDiv-int32((*MemPage)(unsafe.Pointer(pParent)).FnOverflow))))))))
__9:
	;
	*(*Pgno)(unsafe.Pointer(bp + 264)) = Xsqlite3Get4byte(tls, pRight)
__10:
	if !(1 != 0) {
		goto __11
	}
	if !(*(*int32)(unsafe.Pointer(bp + 172)) == SQLITE_OK) {
		goto __12
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = getAndInitPage(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 264)), bp+112+uintptr(i)*8, uintptr(0), 0)
__12:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 172)) != 0) {
		goto __13
	}
	libc.Xmemset(tls, bp+112, 0, uint64(i+1)*uint64(unsafe.Sizeof(uintptr(0))))
	goto balance_cleanup
__13:
	;
	if !((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8)))).FnFree < 0) {
		goto __14
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = btreeComputeFreeSpace(tls, *(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8)))
	if !(*(*int32)(unsafe.Pointer(bp + 172)) != 0) {
		goto __15
	}
	libc.Xmemset(tls, bp+112, 0, uint64(i)*uint64(unsafe.Sizeof(uintptr(0))))
	goto balance_cleanup
__15:
	;
__14:
	;
	nMaxCells = nMaxCells + (int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8)))).FnCell) + int32(uint64(unsafe.Sizeof([4]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0)))))
	if !(libc.PostDecInt32(&i, 1) == 0) {
		goto __16
	}
	goto __11
__16:
	;
	if !((*MemPage)(unsafe.Pointer(pParent)).FnOverflow != 0 && i+nxDiv == int32(*(*U16)(unsafe.Pointer(pParent + 28)))) {
		goto __17
	}
	*(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer(pParent + 40))
	*(*Pgno)(unsafe.Pointer(bp + 264)) = Xsqlite3Get4byte(tls, *(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8)))
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) = int32((*struct {
		f func(*libc.TLS, uintptr, uintptr) U16
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pParent)).FxCellSize})).f(tls, pParent, *(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8))))
	(*MemPage)(unsafe.Pointer(pParent)).FnOverflow = U8(0)
	goto __18
__17:
	*(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8)) = (*MemPage)(unsafe.Pointer(pParent)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pParent)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pParent)).FaCellIdx + uintptr(2*(i+nxDiv-int32((*MemPage)(unsafe.Pointer(pParent)).FnOverflow))))))))
	*(*Pgno)(unsafe.Pointer(bp + 264)) = Xsqlite3Get4byte(tls, *(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8)))
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) = int32((*struct {
		f func(*libc.TLS, uintptr, uintptr) U16
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pParent)).FxCellSize})).f(tls, pParent, *(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8))))

	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FbtsFlags)&BTS_FAST_SECURE != 0) {
		goto __19
	}

	iOff = int32(*(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8))) - int32((*MemPage)(unsafe.Pointer(pParent)).FaData)
	if !(iOff+*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) <= int32((*BtShared)(unsafe.Pointer(pBt)).FusableSize)) {
		goto __20
	}
	libc.Xmemcpy(tls, aOvflSpace+uintptr(iOff), *(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8)), uint64(*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4))))
	*(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8)) = aOvflSpace + uintptr((int64(*(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8)))-int64((*MemPage)(unsafe.Pointer(pParent)).FaData))/1)
__20:
	;
__19:
	;
	dropCell(tls, pParent, i+nxDiv-int32((*MemPage)(unsafe.Pointer(pParent)).FnOverflow), *(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)), bp+172)
__18:
	;
	goto __10
__11:
	;
	nMaxCells = (nMaxCells + 3) & libc.CplInt32(3)

	szScratch = int32(uint64(nMaxCells)*uint64(unsafe.Sizeof(uintptr(0))) +
		uint64(nMaxCells)*uint64(unsafe.Sizeof(U16(0))) +
		uint64((*BtShared)(unsafe.Pointer(pBt)).FpageSize))

	(*CellArray)(unsafe.Pointer(bp + 8)).FapCell = Xsqlite3DbMallocRaw(tls, uintptr(0), uint64(szScratch))
	if !((*CellArray)(unsafe.Pointer(bp+8)).FapCell == uintptr(0)) {
		goto __21
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = SQLITE_NOMEM
	goto balance_cleanup
__21:
	;
	(*CellArray)(unsafe.Pointer(bp + 8)).FszCell = (*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr(nMaxCells)*8
	aSpace1 = (*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr(nMaxCells)*2

	(*CellArray)(unsafe.Pointer(bp + 8)).FpRef = *(*uintptr)(unsafe.Pointer(bp + 112))
	leafCorrection = U16(int32((*MemPage)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FpRef)).Fleaf) * 4)
	leafData = int32((*MemPage)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp + 8)).FpRef)).FintKeyLeaf)
	i = 0
__22:
	if !(i < nOld) {
		goto __24
	}
	pOld = *(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8))
	limit = int32((*MemPage)(unsafe.Pointer(pOld)).FnCell)
	aData = (*MemPage)(unsafe.Pointer(pOld)).FaData
	maskPage = (*MemPage)(unsafe.Pointer(pOld)).FmaskPage
	piCell = aData + uintptr((*MemPage)(unsafe.Pointer(pOld)).FcellOffset)

	if !(int32(*(*U8)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pOld)).FaData))) != int32(*(*U8)(unsafe.Pointer((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112)))).FaData)))) {
		goto __25
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = Xsqlite3CorruptError(tls, 76485)
	goto balance_cleanup
__25:
	;
	libc.Xmemset(tls, (*CellArray)(unsafe.Pointer(bp+8)).FszCell+uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*2, 0, uint64(unsafe.Sizeof(U16(0)))*uint64(limit+int32((*MemPage)(unsafe.Pointer(pOld)).FnOverflow)))
	if !(int32((*MemPage)(unsafe.Pointer(pOld)).FnOverflow) > 0) {
		goto __26
	}
	if !(limit < int32(*(*U16)(unsafe.Pointer(pOld + 28)))) {
		goto __27
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = Xsqlite3CorruptError(tls, 76509)
	goto balance_cleanup
__27:
	;
	limit = int32(*(*U16)(unsafe.Pointer(pOld + 28)))
	j = 0
__28:
	if !(j < limit) {
		goto __30
	}
	*(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*8)) = aData + uintptr(int32(maskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer(piCell)))))
	piCell += uintptr(2)
	(*CellArray)(unsafe.Pointer(bp+8)).FnCell++
	goto __29
__29:
	j++
	goto __28
	goto __30
__30:
	;
	k = 0
__31:
	if !(k < int32((*MemPage)(unsafe.Pointer(pOld)).FnOverflow)) {
		goto __33
	}

	*(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*8)) = *(*uintptr)(unsafe.Pointer(pOld + 40 + uintptr(k)*8))
	(*CellArray)(unsafe.Pointer(bp+8)).FnCell++
	goto __32
__32:
	k++
	goto __31
	goto __33
__33:
	;
__26:
	;
	piEnd = aData + uintptr((*MemPage)(unsafe.Pointer(pOld)).FcellOffset) + uintptr(2*int32((*MemPage)(unsafe.Pointer(pOld)).FnCell))
__34:
	if !(piCell < piEnd) {
		goto __35
	}

	*(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*8)) = aData + uintptr(int32(maskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer(piCell)))))
	piCell += uintptr(2)
	(*CellArray)(unsafe.Pointer(bp+8)).FnCell++
	goto __34
__35:
	;
	*(*int32)(unsafe.Pointer(bp + 176 + uintptr(i)*4)) = (*CellArray)(unsafe.Pointer(bp + 8)).FnCell
	if !(i < nOld-1 && !(leafData != 0)) {
		goto __36
	}
	sz = U16(*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)))

	*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*2)) = sz
	pTemp = aSpace1 + uintptr(iSpace1)
	iSpace1 = iSpace1 + int32(sz)

	libc.Xmemcpy(tls, pTemp, *(*uintptr)(unsafe.Pointer(bp + 136 + uintptr(i)*8)), uint64(sz))
	*(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*8)) = pTemp + uintptr(leafCorrection)

	*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*2)) = U16(int32(*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*2))) - int32(leafCorrection))
	if !!(int32((*MemPage)(unsafe.Pointer(pOld)).Fleaf) != 0) {
		goto __37
	}

	libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*8)), (*MemPage)(unsafe.Pointer(pOld)).FaData+8, uint64(4))
	goto __38
__37:
	;
__39:
	if !(int32(*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*2))) < 4) {
		goto __40
	}

	*(*U8)(unsafe.Pointer(aSpace1 + uintptr(libc.PostIncInt32(&iSpace1, 1)))) = U8(0x00)
	*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr((*CellArray)(unsafe.Pointer(bp+8)).FnCell)*2))++
	goto __39
__40:
	;
__38:
	;
	(*CellArray)(unsafe.Pointer(bp+8)).FnCell++
__36:
	;
	goto __23
__23:
	i++
	goto __22
	goto __24
__24:
	;
	usableSpace = int32((*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32(12) + U32(leafCorrection))
	i = libc.AssignInt32(&k, 0)
__41:
	if !(i < nOld) {
		goto __43
	}
	p = *(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8))
	*(*uintptr)(unsafe.Pointer(bp + 8 + 32 + uintptr(k)*8)) = (*MemPage)(unsafe.Pointer(p)).FaDataEnd
	*(*int32)(unsafe.Pointer(bp + 8 + 80 + uintptr(k)*4)) = *(*int32)(unsafe.Pointer(bp + 176 + uintptr(i)*4))
	if !(k != 0 && *(*int32)(unsafe.Pointer(bp + 8 + 80 + uintptr(k)*4)) == *(*int32)(unsafe.Pointer(bp + 8 + 80 + uintptr(k-1)*4))) {
		goto __44
	}
	k--
__44:
	;
	if !!(leafData != 0) {
		goto __45
	}
	k++
	*(*uintptr)(unsafe.Pointer(bp + 8 + 32 + uintptr(k)*8)) = (*MemPage)(unsafe.Pointer(pParent)).FaDataEnd
	*(*int32)(unsafe.Pointer(bp + 8 + 80 + uintptr(k)*4)) = *(*int32)(unsafe.Pointer(bp + 176 + uintptr(i)*4)) + 1
__45:
	;
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) = usableSpace - (*MemPage)(unsafe.Pointer(p)).FnFree
	j = 0
__46:
	if !(j < int32((*MemPage)(unsafe.Pointer(p)).FnOverflow)) {
		goto __48
	}
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) += 2 + int32((*struct {
		f func(*libc.TLS, uintptr, uintptr) U16
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(p)).FxCellSize})).f(tls, p, *(*uintptr)(unsafe.Pointer(p + 40 + uintptr(j)*8))))
	goto __47
__47:
	j++
	goto __46
	goto __48
__48:
	;
	*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4)) = *(*int32)(unsafe.Pointer(bp + 176 + uintptr(i)*4))
	goto __42
__42:
	i++
	k++
	goto __41
	goto __43
__43:
	;
	k = nOld
	i = 0
__49:
	if !(i < k) {
		goto __51
	}
__52:
	if !(*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) > usableSpace) {
		goto __53
	}
	if !(i+1 >= k) {
		goto __54
	}
	k = i + 2
	if !(k > NB+2) {
		goto __55
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = Xsqlite3CorruptError(tls, 76610)
	goto balance_cleanup
__55:
	;
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(k-1)*4)) = 0
	*(*int32)(unsafe.Pointer(bp + 196 + uintptr(k-1)*4)) = (*CellArray)(unsafe.Pointer(bp + 8)).FnCell
__54:
	;
	sz1 = 2 + int32(cachedCellSize(tls, bp+8, *(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4))-1))
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) -= sz1
	if !!(leafData != 0) {
		goto __56
	}
	if !(*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4)) < (*CellArray)(unsafe.Pointer(bp+8)).FnCell) {
		goto __57
	}
	sz1 = 2 + int32(cachedCellSize(tls, bp+8, *(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4))))
	goto __58
__57:
	sz1 = 0
__58:
	;
__56:
	;
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i+1)*4)) += sz1
	*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4))--
	goto __52
__53:
	;
__59:
	if !(*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4)) < (*CellArray)(unsafe.Pointer(bp+8)).FnCell) {
		goto __60
	}
	sz1 = 2 + int32(cachedCellSize(tls, bp+8, *(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4))))
	if !(*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4))+sz1 > usableSpace) {
		goto __61
	}
	goto __60
__61:
	;
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) += sz1
	*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4))++
	if !!(leafData != 0) {
		goto __62
	}
	if !(*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4)) < (*CellArray)(unsafe.Pointer(bp+8)).FnCell) {
		goto __63
	}
	sz1 = 2 + int32(cachedCellSize(tls, bp+8, *(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4))))
	goto __64
__63:
	sz1 = 0
__64:
	;
__62:
	;
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i+1)*4)) -= sz1
	goto __59
__60:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4)) >= (*CellArray)(unsafe.Pointer(bp+8)).FnCell) {
		goto __65
	}
	k = i + 1
	goto __66
__65:
	if !(*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4)) <= func() int32 {
		if i > 0 {
			return *(*int32)(unsafe.Pointer(bp + 196 + uintptr(i-1)*4))
		}
		return 0
	}()) {
		goto __67
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = Xsqlite3CorruptError(tls, 76643)
	goto balance_cleanup
__67:
	;
__66:
	;
	goto __50
__50:
	i++
	goto __49
	goto __51
__51:
	;
	i = k - 1
__68:
	if !(i > 0) {
		goto __70
	}
	szRight = *(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4))
	szLeft = *(*int32)(unsafe.Pointer(bp + 152 + uintptr(i-1)*4))

	r = *(*int32)(unsafe.Pointer(bp + 196 + uintptr(i-1)*4)) - 1
	d = r + 1 - leafData
	cachedCellSize(tls, bp+8, d)
__71:
	;
	szR = int32(cachedCellSize(tls, bp+8, r))
	szD = int32(*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr(d)*2)))
	if !(szRight != 0 &&
		(bBulk != 0 || szRight+szD+2 > szLeft-(szR+func() int32 {
			if i == k-1 {
				return 0
			}
			return 2
		}()))) {
		goto __74
	}
	goto __73
__74:
	;
	szRight = szRight + (szD + 2)
	szLeft = szLeft - (szR + 2)
	*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i-1)*4)) = r
	r--
	d--
	goto __72
__72:
	if r >= 0 {
		goto __71
	}
	goto __73
__73:
	;
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i)*4)) = szRight
	*(*int32)(unsafe.Pointer(bp + 152 + uintptr(i-1)*4)) = szLeft
	if !(*(*int32)(unsafe.Pointer(bp + 196 + uintptr(i-1)*4)) <= func() int32 {
		if i > 1 {
			return *(*int32)(unsafe.Pointer(bp + 196 + uintptr(i-2)*4))
		}
		return 0
	}()) {
		goto __75
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = Xsqlite3CorruptError(tls, 76687)
	goto balance_cleanup
__75:
	;
	goto __69
__69:
	i--
	goto __68
	goto __70
__70:
	;
	pageFlags = int32(*(*U8)(unsafe.Pointer((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 112)))).FaData)))
	i = 0
__76:
	if !(i < k) {
		goto __78
	}
	if !(i < nOld) {
		goto __79
	}
	*(*uintptr)(unsafe.Pointer(bp + 256)) = libc.AssignPtrUintptr(bp+216+uintptr(i)*8, *(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8)))
	*(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 172)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 256)))).FpDbPage)
	nNew++
	if !(Xsqlite3PagerPageRefcount(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 256)))).FpDbPage) != 1+libc.Bool32(i == iParentIdx-nxDiv) &&
		*(*int32)(unsafe.Pointer(bp + 172)) == SQLITE_OK) {
		goto __81
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = Xsqlite3CorruptError(tls, 76720)
__81:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 172)) != 0) {
		goto __82
	}
	goto balance_cleanup
__82:
	;
	goto __80
__79:
	;
	*(*int32)(unsafe.Pointer(bp + 172)) = allocateBtreePage(tls, pBt, bp+256, bp+264, func() uint32 {
		if bBulk != 0 {
			return uint32(1)
		}
		return *(*Pgno)(unsafe.Pointer(bp + 264))
	}(), uint8(0))
	if !(*(*int32)(unsafe.Pointer(bp + 172)) != 0) {
		goto __83
	}
	goto balance_cleanup
__83:
	;
	zeroPage(tls, *(*uintptr)(unsafe.Pointer(bp + 256)), pageFlags)
	*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer(bp + 256))
	nNew++
	*(*int32)(unsafe.Pointer(bp + 176 + uintptr(i)*4)) = (*CellArray)(unsafe.Pointer(bp + 8)).FnCell

	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
		goto __84
	}
	ptrmapPut(tls, pBt, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 256)))).Fpgno, uint8(PTRMAP_BTREE), (*MemPage)(unsafe.Pointer(pParent)).Fpgno, bp+172)
	if !(*(*int32)(unsafe.Pointer(bp + 172)) != SQLITE_OK) {
		goto __85
	}
	goto balance_cleanup
__85:
	;
__84:
	;
__80:
	;
	goto __77
__77:
	i++
	goto __76
	goto __78
__78:
	;
	i = 0
__86:
	if !(i < nNew) {
		goto __88
	}
	*(*Pgno)(unsafe.Pointer(bp + 268 + uintptr(i)*4)) = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))).Fpgno

	goto __87
__87:
	i++
	goto __86
	goto __88
__88:
	;
	i = 0
__89:
	if !(i < nNew-1) {
		goto __91
	}
	iB = i
	j = i + 1
__92:
	if !(j < nNew) {
		goto __94
	}
	if !((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(j)*8)))).Fpgno < (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(iB)*8)))).Fpgno) {
		goto __95
	}
	iB = j
__95:
	;
	goto __93
__93:
	j++
	goto __92
	goto __94
__94:
	;
	if !(iB != i) {
		goto __96
	}
	pgnoA = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))).Fpgno
	pgnoB = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(iB)*8)))).Fpgno
	pgnoTemp = U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize + U32(1)
	fgA = (*DbPage)(unsafe.Pointer((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))).FpDbPage)).Fflags
	fgB = (*DbPage)(unsafe.Pointer((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(iB)*8)))).FpDbPage)).Fflags
	Xsqlite3PagerRekey(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))).FpDbPage, pgnoTemp, fgB)
	Xsqlite3PagerRekey(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(iB)*8)))).FpDbPage, pgnoA, fgA)
	Xsqlite3PagerRekey(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))).FpDbPage, pgnoB, fgB)
	(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))).Fpgno = pgnoB
	(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(iB)*8)))).Fpgno = pgnoA
__96:
	;
	goto __90
__90:
	i++
	goto __89
	goto __91
__91:
	;
	Xsqlite3Put4byte(tls, pRight, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(nNew-1)*8)))).Fpgno)

	if !(pageFlags&PTF_LEAF == 0 && nOld != nNew) {
		goto __97
	}
	pOld1 = *(*uintptr)(unsafe.Pointer(func() uintptr {
		if nNew > nOld {
			return bp + 216
		}
		return bp + 112
	}() + uintptr(nOld-1)*8))
	libc.Xmemcpy(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(nNew-1)*8)))).FaData+8, (*MemPage)(unsafe.Pointer(pOld1)).FaData+8, uint64(4))
__97:
	;
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
		goto __98
	}
	pNew1 = libc.AssignUintptr(&pOld2, *(*uintptr)(unsafe.Pointer(bp + 216)))
	cntOldNext = int32((*MemPage)(unsafe.Pointer(pNew1)).FnCell) + int32((*MemPage)(unsafe.Pointer(pNew1)).FnOverflow)
	iNew = 0
	iOld = 0

	i = 0
__99:
	if !(i < (*CellArray)(unsafe.Pointer(bp+8)).FnCell) {
		goto __101
	}
	pCell = *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr(i)*8))
__102:
	if !(i == cntOldNext) {
		goto __103
	}
	iOld++

	if iOld < nNew {
		pOld2 = *(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(iOld)*8))
	} else {
		pOld2 = *(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(iOld)*8))
	}
	cntOldNext = cntOldNext + (int32((*MemPage)(unsafe.Pointer(pOld2)).FnCell) + int32((*MemPage)(unsafe.Pointer(pOld2)).FnOverflow) + libc.BoolInt32(!(leafData != 0)))
	goto __102
__103:
	;
	if !(i == *(*int32)(unsafe.Pointer(bp + 196 + uintptr(iNew)*4))) {
		goto __104
	}
	pNew1 = *(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(libc.PreIncInt32(&iNew, 1))*8))
	if !!(leafData != 0) {
		goto __105
	}
	goto __100
__105:
	;
__104:
	;
	if !(iOld >= nNew ||
		(*MemPage)(unsafe.Pointer(pNew1)).Fpgno != *(*Pgno)(unsafe.Pointer(bp + 268 + uintptr(iOld)*4)) ||
		!(Uptr(pCell) >= Uptr((*MemPage)(unsafe.Pointer(pOld2)).FaData) && Uptr(pCell) < Uptr((*MemPage)(unsafe.Pointer(pOld2)).FaDataEnd))) {
		goto __106
	}
	if !!(leafCorrection != 0) {
		goto __107
	}
	ptrmapPut(tls, pBt, Xsqlite3Get4byte(tls, pCell), uint8(PTRMAP_BTREE), (*MemPage)(unsafe.Pointer(pNew1)).Fpgno, bp+172)
__107:
	;
	if !(int32(cachedCellSize(tls, bp+8, i)) > int32((*MemPage)(unsafe.Pointer(pNew1)).FminLocal)) {
		goto __108
	}
	ptrmapPutOvflPtr(tls, pNew1, pOld2, pCell, bp+172)
__108:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 172)) != 0) {
		goto __109
	}
	goto balance_cleanup
__109:
	;
__106:
	;
	goto __100
__100:
	i++
	goto __99
	goto __101
__101:
	;
__98:
	;
	i = 0
__110:
	if !(i < nNew-1) {
		goto __112
	}
	pNew2 = *(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8))
	j = *(*int32)(unsafe.Pointer(bp + 196 + uintptr(i)*4))

	pCell1 = *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr(j)*8))
	sz2 = int32(*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr(j)*2))) + int32(leafCorrection)
	pTemp1 = aOvflSpace + uintptr(iOvflSpace)
	if !!(int32((*MemPage)(unsafe.Pointer(pNew2)).Fleaf) != 0) {
		goto __113
	}
	libc.Xmemcpy(tls, (*MemPage)(unsafe.Pointer(pNew2)).FaData+8, pCell1, uint64(4))
	goto __114
__113:
	if !(leafData != 0) {
		goto __115
	}
	j--
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pNew2)).FxParseCell})).f(tls, pNew2, *(*uintptr)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FapCell + uintptr(j)*8)), bp+288)
	pCell1 = pTemp1
	sz2 = 4 + Xsqlite3PutVarint(tls, pCell1+4, uint64((*CellInfo)(unsafe.Pointer(bp+288)).FnKey))
	pTemp1 = uintptr(0)
	goto __116
__115:
	pCell1 -= uintptr(4)

	if !(int32(*(*U16)(unsafe.Pointer((*CellArray)(unsafe.Pointer(bp+8)).FszCell + uintptr(j)*2))) == 4) {
		goto __117
	}

	sz2 = int32((*struct {
		f func(*libc.TLS, uintptr, uintptr) U16
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pParent)).FxCellSize})).f(tls, pParent, pCell1))
__117:
	;
__116:
	;
__114:
	;
	iOvflSpace = iOvflSpace + sz2

	k = 0
__118:
	if !(*(*int32)(unsafe.Pointer(bp + 8 + 80 + uintptr(k)*4)) <= j && k < NB*2) {
		goto __120
	}
	goto __119
__119:
	k++
	goto __118
	goto __120
__120:
	;
	pSrcEnd = *(*uintptr)(unsafe.Pointer(bp + 8 + 32 + uintptr(k)*8))
	if !(Uptr(pSrcEnd) >= Uptr(pCell1) && Uptr(pSrcEnd) < Uptr(pCell1+uintptr(sz2))) {
		goto __121
	}
	*(*int32)(unsafe.Pointer(bp + 172)) = Xsqlite3CorruptError(tls, 76920)
	goto balance_cleanup
__121:
	;
	*(*int32)(unsafe.Pointer(bp + 172)) = insertCell(tls, pParent, nxDiv+i, pCell1, sz2, pTemp1, (*MemPage)(unsafe.Pointer(pNew2)).Fpgno)
	if !(*(*int32)(unsafe.Pointer(bp + 172)) != SQLITE_OK) {
		goto __122
	}
	goto balance_cleanup
__122:
	;
	goto __111
__111:
	i++
	goto __110
	goto __112
__112:
	;
	i = 1 - nNew
__123:
	if !(i < nNew) {
		goto __125
	}
	if i < 0 {
		iPg = -i
	} else {
		iPg = i
	}

	if !(*(*U8)(unsafe.Pointer(bp + uintptr(iPg))) != 0) {
		goto __126
	}
	goto __124
__126:
	;
	if !(i >= 0 ||
		*(*int32)(unsafe.Pointer(bp + 176 + uintptr(iPg-1)*4)) >= *(*int32)(unsafe.Pointer(bp + 196 + uintptr(iPg-1)*4))) {
		goto __127
	}

	if !(iPg == 0) {
		goto __128
	}
	iNew1 = libc.AssignInt32(&iOld1, 0)
	nNewCell = *(*int32)(unsafe.Pointer(bp + 196))
	goto __129
__128:
	if iPg < nOld {
		iOld1 = *(*int32)(unsafe.Pointer(bp + 176 + uintptr(iPg-1)*4)) + libc.BoolInt32(!(leafData != 0))
	} else {
		iOld1 = (*CellArray)(unsafe.Pointer(bp + 8)).FnCell
	}
	iNew1 = *(*int32)(unsafe.Pointer(bp + 196 + uintptr(iPg-1)*4)) + libc.BoolInt32(!(leafData != 0))
	nNewCell = *(*int32)(unsafe.Pointer(bp + 196 + uintptr(iPg)*4)) - iNew1
__129:
	;
	*(*int32)(unsafe.Pointer(bp + 172)) = editPage(tls, *(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(iPg)*8)), iOld1, iNew1, nNewCell, bp+8)
	if !(*(*int32)(unsafe.Pointer(bp + 172)) != 0) {
		goto __130
	}
	goto balance_cleanup
__130:
	;
	*(*U8)(unsafe.Pointer(bp + uintptr(iPg)))++
	(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(iPg)*8)))).FnFree = usableSpace - *(*int32)(unsafe.Pointer(bp + 152 + uintptr(iPg)*4))

__127:
	;
	goto __124
__124:
	i++
	goto __123
	goto __125
__125:
	;
	if !(isRoot != 0 && int32((*MemPage)(unsafe.Pointer(pParent)).FnCell) == 0 && int32((*MemPage)(unsafe.Pointer(pParent)).FhdrOffset) <= (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216)))).FnFree) {
		goto __131
	}

	*(*int32)(unsafe.Pointer(bp + 172)) = defragmentPage(tls, *(*uintptr)(unsafe.Pointer(bp + 216)), -1)

	copyNodeContent(tls, *(*uintptr)(unsafe.Pointer(bp + 216)), pParent, bp+172)
	freePage(tls, *(*uintptr)(unsafe.Pointer(bp + 216)), bp+172)
	goto __132
__131:
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && !(leafCorrection != 0)) {
		goto __133
	}

	i = 0
__134:
	if !(i < nNew) {
		goto __136
	}
	key = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))).FaData+8)
	ptrmapPut(tls, pBt, key, uint8(PTRMAP_BTREE), (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))).Fpgno, bp+172)
	goto __135
__135:
	i++
	goto __134
	goto __136
__136:
	;
__133:
	;
__132:
	;
	i = nNew
__137:
	if !(i < nOld) {
		goto __139
	}
	freePage(tls, *(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8)), bp+172)
	goto __138
__138:
	i++
	goto __137
	goto __139
__139:
	;
balance_cleanup:
	Xsqlite3DbFree(tls, uintptr(0), (*CellArray)(unsafe.Pointer(bp+8)).FapCell)
	i = 0
__140:
	if !(i < nOld) {
		goto __142
	}
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 112 + uintptr(i)*8)))
	goto __141
__141:
	i++
	goto __140
	goto __142
__142:
	;
	i = 0
__143:
	if !(i < nNew) {
		goto __145
	}
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 216 + uintptr(i)*8)))
	goto __144
__144:
	i++
	goto __143
	goto __145
__145:
	;
	return *(*int32)(unsafe.Pointer(bp + 172))
}

func balance_deeper(tls *libc.TLS, pRoot uintptr, ppChild uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*Pgno)(unsafe.Pointer(bp + 8)) = Pgno(0)
	var pBt uintptr = (*MemPage)(unsafe.Pointer(pRoot)).FpBt

	*(*int32)(unsafe.Pointer(bp + 12)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pRoot)).FpDbPage)
	if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 12)) = allocateBtreePage(tls, pBt, bp, bp+8, (*MemPage)(unsafe.Pointer(pRoot)).Fpgno, uint8(0))
		copyNodeContent(tls, pRoot, *(*uintptr)(unsafe.Pointer(bp)), bp+12)
		if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
			ptrmapPut(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 8)), uint8(PTRMAP_BTREE), (*MemPage)(unsafe.Pointer(pRoot)).Fpgno, bp+12)
		}
	}
	if *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
		*(*uintptr)(unsafe.Pointer(ppChild)) = uintptr(0)
		releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return *(*int32)(unsafe.Pointer(bp + 12))
	}

	libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp))+28, pRoot+28,
		uint64((*MemPage)(unsafe.Pointer(pRoot)).FnOverflow)*uint64(unsafe.Sizeof(U16(0))))
	libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp))+40, pRoot+40,
		uint64((*MemPage)(unsafe.Pointer(pRoot)).FnOverflow)*uint64(unsafe.Sizeof(uintptr(0))))
	(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnOverflow = (*MemPage)(unsafe.Pointer(pRoot)).FnOverflow

	zeroPage(tls, pRoot, int32(*(*U8)(unsafe.Pointer((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData)))&libc.CplInt32(PTF_LEAF))
	Xsqlite3Put4byte(tls, (*MemPage)(unsafe.Pointer(pRoot)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pRoot)).FhdrOffset)+8), *(*Pgno)(unsafe.Pointer(bp + 8)))

	*(*uintptr)(unsafe.Pointer(ppChild)) = *(*uintptr)(unsafe.Pointer(bp))
	return SQLITE_OK
}

func anotherValidCursor(tls *libc.TLS, pCur uintptr) int32 {
	var pOther uintptr
	for pOther = (*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FpCursor; pOther != 0; pOther = (*BtCursor)(unsafe.Pointer(pOther)).FpNext {
		if pOther != pCur &&
			int32((*BtCursor)(unsafe.Pointer(pOther)).FeState) == CURSOR_VALID &&
			(*BtCursor)(unsafe.Pointer(pOther)).FpPage == (*BtCursor)(unsafe.Pointer(pCur)).FpPage {
			return Xsqlite3CorruptError(tls, 77150)
		}
	}
	return SQLITE_OK
}

func balance(tls *libc.TLS, pCur uintptr) int32 {
	bp := tls.Alloc(13)
	defer tls.Free(13)

	var rc int32 = SQLITE_OK

	var pFree uintptr = uintptr(0)

	for __ccgo := true; __ccgo; __ccgo = rc == SQLITE_OK {
		var iPage int32
		var pPage uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpPage

		if (*MemPage)(unsafe.Pointer(pPage)).FnFree < 0 && btreeComputeFreeSpace(tls, pPage) != 0 {
			break
		}
		if int32((*MemPage)(unsafe.Pointer(pPage)).FnOverflow) == 0 && (*MemPage)(unsafe.Pointer(pPage)).FnFree*3 <= int32((*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FusableSize)*2 {
			break
		} else if libc.AssignInt32(&iPage, int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage)) == 0 {
			if (*MemPage)(unsafe.Pointer(pPage)).FnOverflow != 0 && libc.AssignInt32(&rc, anotherValidCursor(tls, pCur)) == SQLITE_OK {
				rc = balance_deeper(tls, pPage, pCur+144+1*8)
				if rc == SQLITE_OK {
					(*BtCursor)(unsafe.Pointer(pCur)).FiPage = int8(1)
					(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(0)
					*(*U16)(unsafe.Pointer(pCur + 88)) = U16(0)
					*(*uintptr)(unsafe.Pointer(pCur + 144)) = pPage
					(*BtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 144 + 1*8))

				}
			} else {
				break
			}
		} else if Xsqlite3PagerPageRefcount(tls, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage) > 1 {
			rc = Xsqlite3CorruptError(tls, 77210)
		} else {
			var pParent uintptr = *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr(iPage-1)*8))
			var iIdx int32 = int32(*(*U16)(unsafe.Pointer(pCur + 88 + uintptr(iPage-1)*2)))

			rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pParent)).FpDbPage)
			if rc == SQLITE_OK && (*MemPage)(unsafe.Pointer(pParent)).FnFree < 0 {
				rc = btreeComputeFreeSpace(tls, pParent)
			}
			if rc == SQLITE_OK {
				if (*MemPage)(unsafe.Pointer(pPage)).FintKeyLeaf != 0 &&
					int32((*MemPage)(unsafe.Pointer(pPage)).FnOverflow) == 1 &&
					int32(*(*U16)(unsafe.Pointer(pPage + 28))) == int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) &&
					(*MemPage)(unsafe.Pointer(pParent)).Fpgno != Pgno(1) &&
					int32((*MemPage)(unsafe.Pointer(pParent)).FnCell) == iIdx {
					rc = balance_quick(tls, pParent, pPage, bp)
				} else {
					var pSpace uintptr = Xsqlite3PageMalloc(tls, int32((*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FpageSize))
					rc = balance_nonroot(tls, pParent, iIdx, pSpace, libc.Bool32(iPage == 1),
						int32((*BtCursor)(unsafe.Pointer(pCur)).Fhints)&BTREE_BULKLOAD)
					if pFree != 0 {
						Xsqlite3PageFree(tls, pFree)
					}

					pFree = pSpace
				}
			}

			(*MemPage)(unsafe.Pointer(pPage)).FnOverflow = U8(0)

			releasePage(tls, pPage)
			(*BtCursor)(unsafe.Pointer(pCur)).FiPage--

			(*BtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr((*BtCursor)(unsafe.Pointer(pCur)).FiPage)*8))
		}
	}

	if pFree != 0 {
		Xsqlite3PageFree(tls, pFree)
	}
	return rc
}

func btreeOverwriteContent(tls *libc.TLS, pPage uintptr, pDest uintptr, pX uintptr, iOffset int32, iAmt int32) int32 {
	var nData int32 = (*BtreePayload)(unsafe.Pointer(pX)).FnData - iOffset
	if nData <= 0 {
		var i int32
		for i = 0; i < iAmt && int32(*(*U8)(unsafe.Pointer(pDest + uintptr(i)))) == 0; i++ {
		}
		if i < iAmt {
			var rc int32 = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage)
			if rc != 0 {
				return rc
			}
			libc.Xmemset(tls, pDest+uintptr(i), 0, uint64(iAmt-i))
		}
	} else {
		if nData < iAmt {
			var rc int32 = btreeOverwriteContent(tls, pPage, pDest+uintptr(nData), pX, iOffset+nData,
				iAmt-nData)
			if rc != 0 {
				return rc
			}
			iAmt = nData
		}
		if libc.Xmemcmp(tls, pDest, (*BtreePayload)(unsafe.Pointer(pX)).FpData+uintptr(iOffset), uint64(iAmt)) != 0 {
			var rc int32 = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage)
			if rc != 0 {
				return rc
			}

			libc.Xmemmove(tls, pDest, (*BtreePayload)(unsafe.Pointer(pX)).FpData+uintptr(iOffset), uint64(iAmt))
		}
	}
	return SQLITE_OK
}

func btreeOverwriteOverflowCell(tls *libc.TLS, pCur uintptr, pX uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var iOffset int32
	var nTotal int32 = (*BtreePayload)(unsafe.Pointer(pX)).FnData + (*BtreePayload)(unsafe.Pointer(pX)).FnZero
	var rc int32
	*(*uintptr)(unsafe.Pointer(bp)) = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
	var pBt uintptr
	var ovflPgno Pgno
	var ovflPageSize U32

	rc = btreeOverwriteContent(tls, *(*uintptr)(unsafe.Pointer(bp)), (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload, pX,
		0, int32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal))
	if rc != 0 {
		return rc
	}

	iOffset = int32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal)

	ovflPgno = Xsqlite3Get4byte(tls, (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload+uintptr(iOffset))
	pBt = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpBt
	ovflPageSize = (*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32(4)
	for __ccgo := true; __ccgo; __ccgo = iOffset < nTotal {
		rc = btreeGetPage(tls, pBt, ovflPgno, bp, 0)
		if rc != 0 {
			return rc
		}
		if Xsqlite3PagerPageRefcount(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage) != 1 || (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FisInit != 0 {
			rc = Xsqlite3CorruptError(tls, 77374)
		} else {
			if U32(iOffset)+ovflPageSize < U32(nTotal) {
				ovflPgno = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData)
			} else {
				ovflPageSize = U32(nTotal - iOffset)
			}
			rc = btreeOverwriteContent(tls, *(*uintptr)(unsafe.Pointer(bp)), (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+uintptr(4), pX,
				iOffset, int32(ovflPageSize))
		}
		Xsqlite3PagerUnref(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)
		if rc != 0 {
			return rc
		}
		iOffset = int32(U32(iOffset) + ovflPageSize)
	}
	return SQLITE_OK
}

func btreeOverwriteCell(tls *libc.TLS, pCur uintptr, pX uintptr) int32 {
	var nTotal int32 = (*BtreePayload)(unsafe.Pointer(pX)).FnData + (*BtreePayload)(unsafe.Pointer(pX)).FnZero
	var pPage uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpPage

	if (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload+uintptr((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) > (*MemPage)(unsafe.Pointer(pPage)).FaDataEnd ||
		(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload < (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*MemPage)(unsafe.Pointer(pPage)).FcellOffset) {
		return Xsqlite3CorruptError(tls, 77402)
	}
	if int32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal) == nTotal {
		return btreeOverwriteContent(tls, pPage, (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FpPayload, pX,
			0, int32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnLocal))
	} else {
		return btreeOverwriteOverflowCell(tls, pCur, pX)
	}
	return int32(0)
}

func Xsqlite3BtreeInsert(tls *libc.TLS, pCur uintptr, pX uintptr, flags int32, seekResult int32) int32 {
	bp := tls.Alloc(152)
	defer tls.Free(152)

	var idx int32
	var pPage uintptr
	var p uintptr
	var oldCell uintptr
	var newCell uintptr

	var ovfl Pgno

	*(*int32)(unsafe.Pointer(bp)) = seekResult
	*(*int32)(unsafe.Pointer(bp + 124)) = 0
	p = (*BtCursor)(unsafe.Pointer(pCur)).FpBtree
	newCell = uintptr(0)

	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FcurFlags)&BTCF_Multiple != 0) {
		goto __1
	}
	*(*int32)(unsafe.Pointer(bp + 120)) = saveAllCursors(tls, (*Btree)(unsafe.Pointer(p)).FpBt, (*BtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur)
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0) {
		goto __2
	}
	return *(*int32)(unsafe.Pointer(bp + 120))
__2:
	;
	if !(*(*int32)(unsafe.Pointer(bp)) != 0 && int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) < 0) {
		goto __3
	}

	return Xsqlite3CorruptError(tls, 77483)
__3:
	;
__1:
	;
	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) >= CURSOR_REQUIRESEEK) {
		goto __4
	}

	*(*int32)(unsafe.Pointer(bp + 120)) = moveToRoot(tls, pCur)
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0 && *(*int32)(unsafe.Pointer(bp + 120)) != SQLITE_EMPTY) {
		goto __5
	}
	return *(*int32)(unsafe.Pointer(bp + 120))
__5:
	;
__4:
	;
	if !((*BtCursor)(unsafe.Pointer(pCur)).FpKeyInfo == uintptr(0)) {
		goto __6
	}

	if !((*Btree)(unsafe.Pointer(p)).FhasIncrblobCur != 0) {
		goto __8
	}
	invalidateIncrblobCursors(tls, p, (*BtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, (*BtreePayload)(unsafe.Pointer(pX)).FnKey, 0)
__8:
	;
	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FcurFlags)&BTCF_ValidNKey != 0 && (*BtreePayload)(unsafe.Pointer(pX)).FnKey == (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey) {
		goto __9
	}

	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize) != 0 &&
		(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnPayload == U32((*BtreePayload)(unsafe.Pointer(pX)).FnData)+U32((*BtreePayload)(unsafe.Pointer(pX)).FnZero)) {
		goto __11
	}

	return btreeOverwriteCell(tls, pCur, pX)
__11:
	;
	goto __10
__9:
	if !(*(*int32)(unsafe.Pointer(bp)) == 0) {
		goto __12
	}

	*(*int32)(unsafe.Pointer(bp + 120)) = Xsqlite3BtreeTableMoveto(tls, pCur, (*BtreePayload)(unsafe.Pointer(pX)).FnKey,
		libc.Bool32(flags&BTREE_APPEND != 0), bp)
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0) {
		goto __13
	}
	return *(*int32)(unsafe.Pointer(bp + 120))
__13:
	;
__12:
	;
__10:
	;
	goto __7
__6:
	;
	if !(*(*int32)(unsafe.Pointer(bp)) == 0 && flags&BTREE_SAVEPOSITION == 0) {
		goto __14
	}
	if !((*BtreePayload)(unsafe.Pointer(pX)).FnMem != 0) {
		goto __15
	}
	(*UnpackedRecord)(unsafe.Pointer(bp + 8)).FpKeyInfo = (*BtCursor)(unsafe.Pointer(pCur)).FpKeyInfo
	(*UnpackedRecord)(unsafe.Pointer(bp + 8)).FaMem = (*BtreePayload)(unsafe.Pointer(pX)).FaMem
	(*UnpackedRecord)(unsafe.Pointer(bp + 8)).FnField = (*BtreePayload)(unsafe.Pointer(pX)).FnMem
	(*UnpackedRecord)(unsafe.Pointer(bp + 8)).Fdefault_rc = int8(0)
	(*UnpackedRecord)(unsafe.Pointer(bp + 8)).FeqSeen = U8(0)
	*(*int32)(unsafe.Pointer(bp + 120)) = Xsqlite3BtreeIndexMoveto(tls, pCur, bp+8, bp)
	goto __16
__15:
	*(*int32)(unsafe.Pointer(bp + 120)) = btreeMoveto(tls, pCur, (*BtreePayload)(unsafe.Pointer(pX)).FpKey, (*BtreePayload)(unsafe.Pointer(pX)).FnKey,
		libc.Bool32(flags&BTREE_APPEND != 0), bp)
__16:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0) {
		goto __17
	}
	return *(*int32)(unsafe.Pointer(bp + 120))
__17:
	;
__14:
	;
	if !(*(*int32)(unsafe.Pointer(bp)) == 0) {
		goto __18
	}
	getCellInfo(tls, pCur)
	if !((*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey == (*BtreePayload)(unsafe.Pointer(pX)).FnKey) {
		goto __19
	}
	(*BtreePayload)(unsafe.Pointer(bp + 48)).FpData = (*BtreePayload)(unsafe.Pointer(pX)).FpKey
	(*BtreePayload)(unsafe.Pointer(bp + 48)).FnData = int32((*BtreePayload)(unsafe.Pointer(pX)).FnKey)
	(*BtreePayload)(unsafe.Pointer(bp + 48)).FnZero = 0
	return btreeOverwriteCell(tls, pCur, bp+48)
__19:
	;
__18:
	;
__7:
	;
	pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage

	if !((*MemPage)(unsafe.Pointer(pPage)).FnFree < 0) {
		goto __20
	}
	if !(int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) > CURSOR_INVALID) {
		goto __21
	}

	*(*int32)(unsafe.Pointer(bp + 120)) = Xsqlite3CorruptError(tls, 77606)
	goto __22
__21:
	*(*int32)(unsafe.Pointer(bp + 120)) = btreeComputeFreeSpace(tls, pPage)
__22:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0) {
		goto __23
	}
	return *(*int32)(unsafe.Pointer(bp + 120))
__23:
	;
__20:
	;
	newCell = (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FpTmpSpace

	if !(flags&BTREE_PREFORMAT != 0) {
		goto __24
	}
	*(*int32)(unsafe.Pointer(bp + 120)) = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 124)) = (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FnPreformatSize
	if !(*(*int32)(unsafe.Pointer(bp + 124)) < 4) {
		goto __26
	}
	*(*int32)(unsafe.Pointer(bp + 124)) = 4
__26:
	;
	if !((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FautoVacuum != 0 && *(*int32)(unsafe.Pointer(bp + 124)) > int32((*MemPage)(unsafe.Pointer(pPage)).FmaxLocal)) {
		goto __27
	}
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxParseCell})).f(tls, pPage, newCell, bp+96)
	if !((*CellInfo)(unsafe.Pointer(bp+96)).FnPayload != U32((*CellInfo)(unsafe.Pointer(bp+96)).FnLocal)) {
		goto __28
	}
	ovfl = Xsqlite3Get4byte(tls, newCell+uintptr(*(*int32)(unsafe.Pointer(bp + 124))-4))
	ptrmapPut(tls, (*Btree)(unsafe.Pointer(p)).FpBt, ovfl, uint8(PTRMAP_OVERFLOW1), (*MemPage)(unsafe.Pointer(pPage)).Fpgno, bp+120)
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0) {
		goto __29
	}
	goto end_insert
__29:
	;
__28:
	;
__27:
	;
	goto __25
__24:
	*(*int32)(unsafe.Pointer(bp + 120)) = fillInCell(tls, pPage, newCell, pX, bp+124)
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0) {
		goto __30
	}
	goto end_insert
__30:
	;
__25:
	;
	idx = int32((*BtCursor)(unsafe.Pointer(pCur)).Fix)
	(*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnSize = U16(0)
	if !(*(*int32)(unsafe.Pointer(bp)) == 0) {
		goto __31
	}

	if !(idx >= int32((*MemPage)(unsafe.Pointer(pPage)).FnCell)) {
		goto __33
	}
	return Xsqlite3CorruptError(tls, 77645)
__33:
	;
	*(*int32)(unsafe.Pointer(bp + 120)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage)
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0) {
		goto __34
	}
	goto end_insert
__34:
	;
	oldCell = (*MemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*idx))))))
	if !!(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
		goto __35
	}
	libc.Xmemcpy(tls, newCell, oldCell, uint64(4))
__35:
	;
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxParseCell})).f(tls, pPage, oldCell, bp+128)
	if !(U32((*CellInfo)(unsafe.Pointer(bp+128)).FnLocal) != (*CellInfo)(unsafe.Pointer(bp+128)).FnPayload) {
		goto __36
	}
	*(*int32)(unsafe.Pointer(bp + 120)) = clearCellOverflow(tls, pPage, oldCell, bp+128)
	goto __37
__36:
	*(*int32)(unsafe.Pointer(bp + 120)) = SQLITE_OK
__37:
	;
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidOvfl))
	if !(int32((*CellInfo)(unsafe.Pointer(bp+128)).FnSize) == *(*int32)(unsafe.Pointer(bp + 124)) && U32((*CellInfo)(unsafe.Pointer(bp+128)).FnLocal) == (*CellInfo)(unsafe.Pointer(bp+128)).FnPayload &&
		(!(int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FautoVacuum) != 0) || *(*int32)(unsafe.Pointer(bp + 124)) < int32((*MemPage)(unsafe.Pointer(pPage)).FminLocal))) {
		goto __38
	}

	if !(oldCell < (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+uintptr(10)) {
		goto __39
	}
	return Xsqlite3CorruptError(tls, 77672)
__39:
	;
	if !(oldCell+uintptr(*(*int32)(unsafe.Pointer(bp + 124))) > (*MemPage)(unsafe.Pointer(pPage)).FaDataEnd) {
		goto __40
	}
	return Xsqlite3CorruptError(tls, 77675)
__40:
	;
	libc.Xmemcpy(tls, oldCell, newCell, uint64(*(*int32)(unsafe.Pointer(bp + 124))))
	return SQLITE_OK
__38:
	;
	dropCell(tls, pPage, idx, int32((*CellInfo)(unsafe.Pointer(bp+128)).FnSize), bp+120)
	if !(*(*int32)(unsafe.Pointer(bp + 120)) != 0) {
		goto __41
	}
	goto end_insert
__41:
	;
	goto __32
__31:
	if !(*(*int32)(unsafe.Pointer(bp)) < 0 && int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) > 0) {
		goto __42
	}

	idx = int32(libc.PreIncUint16(&(*BtCursor)(unsafe.Pointer(pCur)).Fix, 1))
	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidNKey))
	goto __43
__42:
	;
__43:
	;
__32:
	;
	*(*int32)(unsafe.Pointer(bp + 120)) = insertCell(tls, pPage, idx, newCell, *(*int32)(unsafe.Pointer(bp + 124)), uintptr(0), uint32(0))

	if !((*MemPage)(unsafe.Pointer(pPage)).FnOverflow != 0) {
		goto __44
	}

	*(*U8)(unsafe.Pointer(pCur + 1)) &= libc.Uint8FromInt32(libc.CplInt32(BTCF_ValidNKey))
	*(*int32)(unsafe.Pointer(bp + 120)) = balance(tls, pCur)

	(*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FnOverflow = U8(0)
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_INVALID)
	if !(flags&BTREE_SAVEPOSITION != 0 && *(*int32)(unsafe.Pointer(bp + 120)) == SQLITE_OK) {
		goto __45
	}
	btreeReleaseAllCursorPages(tls, pCur)
	if !((*BtCursor)(unsafe.Pointer(pCur)).FpKeyInfo != 0) {
		goto __46
	}

	(*BtCursor)(unsafe.Pointer(pCur)).FpKey = Xsqlite3Malloc(tls, uint64((*BtreePayload)(unsafe.Pointer(pX)).FnKey))
	if !((*BtCursor)(unsafe.Pointer(pCur)).FpKey == uintptr(0)) {
		goto __47
	}
	*(*int32)(unsafe.Pointer(bp + 120)) = SQLITE_NOMEM
	goto __48
__47:
	libc.Xmemcpy(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpKey, (*BtreePayload)(unsafe.Pointer(pX)).FpKey, uint64((*BtreePayload)(unsafe.Pointer(pX)).FnKey))
__48:
	;
__46:
	;
	(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_REQUIRESEEK)
	(*BtCursor)(unsafe.Pointer(pCur)).FnKey = (*BtreePayload)(unsafe.Pointer(pX)).FnKey
__45:
	;
__44:
	;
end_insert:
	return *(*int32)(unsafe.Pointer(bp + 120))
}

func Xsqlite3BtreeTransferRow(tls *libc.TLS, pDest uintptr, pSrc uintptr, iKey I64) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pBt uintptr = (*BtCursor)(unsafe.Pointer(pDest)).FpBt
	var aOut uintptr = (*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace
	var aIn uintptr
	var nIn U32
	var nRem U32

	getCellInfo(tls, pSrc)
	if (*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload < U32(0x80) {
		*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&aOut, 1))) = U8((*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)
	} else {
		aOut += uintptr(Xsqlite3PutVarint(tls, aOut, uint64((*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)))
	}
	if (*BtCursor)(unsafe.Pointer(pDest)).FpKeyInfo == uintptr(0) {
		aOut += uintptr(Xsqlite3PutVarint(tls, aOut, uint64(iKey)))
	}
	nIn = U32((*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FnLocal)
	aIn = (*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FpPayload
	if aIn+uintptr(nIn) > (*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pSrc)).FpPage)).FaDataEnd {
		return Xsqlite3CorruptError(tls, 77777)
	}
	nRem = (*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload
	if nIn == nRem && nIn < U32((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pDest)).FpPage)).FmaxLocal) {
		libc.Xmemcpy(tls, aOut, aIn, uint64(nIn))
		(*BtShared)(unsafe.Pointer(pBt)).FnPreformatSize = int32(int64(nIn) + (int64(aOut)-int64((*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace))/1)
		return SQLITE_OK
	} else {
		*(*int32)(unsafe.Pointer(bp + 20)) = SQLITE_OK
		var pSrcPager uintptr = (*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pSrc)).FpBt)).FpPager
		var pPgnoOut uintptr = uintptr(0)
		var ovflIn Pgno = Pgno(0)
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		var pPageOut uintptr = uintptr(0)
		var nOut U32

		nOut = U32(btreePayloadToLocal(tls, (*BtCursor)(unsafe.Pointer(pDest)).FpPage, int64((*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload)))
		(*BtShared)(unsafe.Pointer(pBt)).FnPreformatSize = int32(int64(nOut) + (int64(aOut)-int64((*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace))/1)
		if nOut < (*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FnPayload {
			pPgnoOut = aOut + uintptr(nOut)
			*(*int32)(unsafe.Pointer(pBt + 144)) += 4
		}

		if nRem > nIn {
			if aIn+uintptr(nIn)+uintptr(4) > (*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pSrc)).FpPage)).FaDataEnd {
				return Xsqlite3CorruptError(tls, 77802)
			}
			ovflIn = Xsqlite3Get4byte(tls, (*BtCursor)(unsafe.Pointer(pSrc)).Finfo.FpPayload+uintptr(nIn))
		}

		for __ccgo := true; __ccgo; __ccgo = nRem > U32(0) && *(*int32)(unsafe.Pointer(bp + 20)) == SQLITE_OK {
			nRem = nRem - nOut
			for __ccgo1 := true; __ccgo1; __ccgo1 = *(*int32)(unsafe.Pointer(bp + 20)) == SQLITE_OK && nOut > U32(0) {
				if nIn > U32(0) {
					var nCopy int32 = func() int32 {
						if nOut < nIn {
							return int32(nOut)
						}
						return int32(nIn)
					}()
					libc.Xmemcpy(tls, aOut, aIn, uint64(nCopy))
					nOut = nOut - U32(nCopy)
					nIn = nIn - U32(nCopy)
					aOut += uintptr(nCopy)
					aIn += uintptr(nCopy)
				}
				if nOut > U32(0) {
					Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
					*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
					*(*int32)(unsafe.Pointer(bp + 20)) = Xsqlite3PagerGet(tls, pSrcPager, ovflIn, bp, PAGER_GET_READONLY)
					if *(*int32)(unsafe.Pointer(bp + 20)) == SQLITE_OK {
						aIn = Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))
						ovflIn = Xsqlite3Get4byte(tls, aIn)
						aIn += uintptr(4)
						nIn = (*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pSrc)).FpBt)).FusableSize - U32(4)
					}
				}
			}

			if *(*int32)(unsafe.Pointer(bp + 20)) == SQLITE_OK && nRem > U32(0) && pPgnoOut != 0 {
				*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
				*(*int32)(unsafe.Pointer(bp + 20)) = allocateBtreePage(tls, pBt, bp+8, bp+16, uint32(0), uint8(0))
				Xsqlite3Put4byte(tls, pPgnoOut, *(*Pgno)(unsafe.Pointer(bp + 16)))
				if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && pPageOut != 0 {
					ptrmapPut(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 16)), uint8(PTRMAP_OVERFLOW2), (*MemPage)(unsafe.Pointer(pPageOut)).Fpgno, bp+20)
				}
				releasePage(tls, pPageOut)
				pPageOut = *(*uintptr)(unsafe.Pointer(bp + 8))
				if pPageOut != 0 {
					pPgnoOut = (*MemPage)(unsafe.Pointer(pPageOut)).FaData
					Xsqlite3Put4byte(tls, pPgnoOut, uint32(0))
					aOut = pPgnoOut + 4
					nOut = func() uint32 {
						if (*BtShared)(unsafe.Pointer(pBt)).FusableSize-U32(4) < nRem {
							return (*BtShared)(unsafe.Pointer(pBt)).FusableSize - U32(4)
						}
						return nRem
					}()
				}
			}
		}

		releasePage(tls, pPageOut)
		Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return *(*int32)(unsafe.Pointer(bp + 20))
	}
	return int32(0)
}

func Xsqlite3BtreeDelete(tls *libc.TLS, pCur uintptr, flags U8) int32 {
	bp := tls.Alloc(28)
	defer tls.Free(28)

	var p uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpBtree
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	var pPage uintptr
	var pCell uintptr
	var iCellIdx int32
	var iCellDepth int32

	var bPreserve U8

	if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
		if int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) >= CURSOR_REQUIRESEEK {
			*(*int32)(unsafe.Pointer(bp + 24)) = btreeRestoreCursorPosition(tls, pCur)

			if *(*int32)(unsafe.Pointer(bp + 24)) != 0 || int32((*BtCursor)(unsafe.Pointer(pCur)).FeState) != CURSOR_VALID {
				return *(*int32)(unsafe.Pointer(bp + 24))
			}
		} else {
			return Xsqlite3CorruptError(tls, 77898)
		}
	}

	iCellDepth = int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage)
	iCellIdx = int32((*BtCursor)(unsafe.Pointer(pCur)).Fix)
	pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
	if int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) <= iCellIdx {
		return Xsqlite3CorruptError(tls, 77907)
	}
	pCell = (*MemPage)(unsafe.Pointer(pPage)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*iCellIdx))))))
	if (*MemPage)(unsafe.Pointer(pPage)).FnFree < 0 && btreeComputeFreeSpace(tls, pPage) != 0 {
		return Xsqlite3CorruptError(tls, 77911)
	}

	bPreserve = U8(libc.Bool32(int32(flags)&BTREE_SAVEPOSITION != 0))
	if bPreserve != 0 {
		if !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) ||
			(*MemPage)(unsafe.Pointer(pPage)).FnFree+int32((*struct {
				f func(*libc.TLS, uintptr, uintptr) U16
			})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxCellSize})).f(tls, pPage, pCell))+2 > int32((*BtShared)(unsafe.Pointer(pBt)).FusableSize*U32(2)/U32(3)) ||
			int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) == 1 {
			*(*int32)(unsafe.Pointer(bp + 24)) = saveCursorKey(tls, pCur)
			if *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
				return *(*int32)(unsafe.Pointer(bp + 24))
			}
		} else {
			bPreserve = U8(2)
		}
	}

	if !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
		*(*int32)(unsafe.Pointer(bp + 24)) = Xsqlite3BtreePrevious(tls, pCur, 0)

		if *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
			return *(*int32)(unsafe.Pointer(bp + 24))
		}
	}

	if int32((*BtCursor)(unsafe.Pointer(pCur)).FcurFlags)&BTCF_Multiple != 0 {
		*(*int32)(unsafe.Pointer(bp + 24)) = saveAllCursors(tls, pBt, (*BtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, pCur)
		if *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
			return *(*int32)(unsafe.Pointer(bp + 24))
		}
	}

	if (*BtCursor)(unsafe.Pointer(pCur)).FpKeyInfo == uintptr(0) && (*Btree)(unsafe.Pointer(p)).FhasIncrblobCur != 0 {
		invalidateIncrblobCursors(tls, p, (*BtCursor)(unsafe.Pointer(pCur)).FpgnoRoot, (*BtCursor)(unsafe.Pointer(pCur)).Finfo.FnKey, 0)
	}

	*(*int32)(unsafe.Pointer(bp + 24)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pPage)).FpDbPage)
	if *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
		return *(*int32)(unsafe.Pointer(bp + 24))
	}
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pPage)).FxParseCell})).f(tls, pPage, pCell, bp)
	if U32((*CellInfo)(unsafe.Pointer(bp)).FnLocal) != (*CellInfo)(unsafe.Pointer(bp)).FnPayload {
		*(*int32)(unsafe.Pointer(bp + 24)) = clearCellOverflow(tls, pPage, pCell, bp)
	} else {
		*(*int32)(unsafe.Pointer(bp + 24)) = SQLITE_OK
	}

	dropCell(tls, pPage, iCellIdx, int32((*CellInfo)(unsafe.Pointer(bp)).FnSize), bp+24)
	if *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
		return *(*int32)(unsafe.Pointer(bp + 24))
	}

	if !(int32((*MemPage)(unsafe.Pointer(pPage)).Fleaf) != 0) {
		var pLeaf uintptr = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
		var nCell int32
		var n Pgno
		var pTmp uintptr

		if (*MemPage)(unsafe.Pointer(pLeaf)).FnFree < 0 {
			*(*int32)(unsafe.Pointer(bp + 24)) = btreeComputeFreeSpace(tls, pLeaf)
			if *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
				return *(*int32)(unsafe.Pointer(bp + 24))
			}
		}
		if iCellDepth < int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage)-1 {
			n = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr(iCellDepth+1)*8)))).Fpgno
		} else {
			n = (*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).Fpgno
		}
		pCell = (*MemPage)(unsafe.Pointer(pLeaf)).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(pLeaf)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pLeaf)).FaCellIdx + uintptr(2*(int32((*MemPage)(unsafe.Pointer(pLeaf)).FnCell)-1)))))))
		if pCell < (*MemPage)(unsafe.Pointer(pLeaf)).FaData+4 {
			return Xsqlite3CorruptError(tls, 78002)
		}
		nCell = int32((*struct {
			f func(*libc.TLS, uintptr, uintptr) U16
		})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(pLeaf)).FxCellSize})).f(tls, pLeaf, pCell))

		pTmp = (*BtShared)(unsafe.Pointer(pBt)).FpTmpSpace

		*(*int32)(unsafe.Pointer(bp + 24)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(pLeaf)).FpDbPage)
		if *(*int32)(unsafe.Pointer(bp + 24)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 24)) = insertCell(tls, pPage, iCellIdx, pCell-uintptr(4), nCell+4, pTmp, n)
		}
		dropCell(tls, pLeaf, int32((*MemPage)(unsafe.Pointer(pLeaf)).FnCell)-1, nCell, bp+24)
		if *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
			return *(*int32)(unsafe.Pointer(bp + 24))
		}
	}

	if (*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FnFree*3 <= int32((*BtShared)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBt)).FusableSize)*2 {
		*(*int32)(unsafe.Pointer(bp + 24)) = SQLITE_OK
	} else {
		*(*int32)(unsafe.Pointer(bp + 24)) = balance(tls, pCur)
	}
	if *(*int32)(unsafe.Pointer(bp + 24)) == SQLITE_OK && int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) > iCellDepth {
		releasePageNotNull(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpPage)
		(*BtCursor)(unsafe.Pointer(pCur)).FiPage--
		for int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) > iCellDepth {
			releasePage(tls, *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr(libc.PostDecInt8(&(*BtCursor)(unsafe.Pointer(pCur)).FiPage, 1))*8)))
		}
		(*BtCursor)(unsafe.Pointer(pCur)).FpPage = *(*uintptr)(unsafe.Pointer(pCur + 144 + uintptr((*BtCursor)(unsafe.Pointer(pCur)).FiPage)*8))
		*(*int32)(unsafe.Pointer(bp + 24)) = balance(tls, pCur)
	}

	if *(*int32)(unsafe.Pointer(bp + 24)) == SQLITE_OK {
		if int32(bPreserve) > 1 {
			(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_SKIPNEXT)
			if iCellIdx >= int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) {
				(*BtCursor)(unsafe.Pointer(pCur)).FskipNext = -1
				(*BtCursor)(unsafe.Pointer(pCur)).Fix = U16(int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) - 1)
			} else {
				(*BtCursor)(unsafe.Pointer(pCur)).FskipNext = 1
			}
		} else {
			*(*int32)(unsafe.Pointer(bp + 24)) = moveToRoot(tls, pCur)
			if bPreserve != 0 {
				btreeReleaseAllCursorPages(tls, pCur)
				(*BtCursor)(unsafe.Pointer(pCur)).FeState = U8(CURSOR_REQUIRESEEK)
			}
			if *(*int32)(unsafe.Pointer(bp + 24)) == SQLITE_EMPTY {
				*(*int32)(unsafe.Pointer(bp + 24)) = SQLITE_OK
			}
		}
	}
	return *(*int32)(unsafe.Pointer(bp + 24))
}

func btreeCreateTable(tls *libc.TLS, p uintptr, piTable uintptr, createTabFlags int32) int32 {
	bp := tls.Alloc(44)
	defer tls.Free(44)

	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	var ptfFlags int32

	if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
		invalidateAllOverflowCache(tls, pBt)

		Xsqlite3BtreeGetMeta(tls, p, BTREE_LARGEST_ROOT_PAGE, bp)
		if *(*Pgno)(unsafe.Pointer(bp)) > btreePagecount(tls, pBt) {
			return Xsqlite3CorruptError(tls, 78118)
		}
		*(*Pgno)(unsafe.Pointer(bp))++

		for *(*Pgno)(unsafe.Pointer(bp)) == ptrmapPageno(tls, pBt, *(*Pgno)(unsafe.Pointer(bp))) || *(*Pgno)(unsafe.Pointer(bp)) == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) {
			*(*Pgno)(unsafe.Pointer(bp))++
		}

		*(*int32)(unsafe.Pointer(bp + 40)) = allocateBtreePage(tls, pBt, bp+8, bp+16, *(*Pgno)(unsafe.Pointer(bp)), uint8(BTALLOC_EXACT))
		if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
			return *(*int32)(unsafe.Pointer(bp + 40))
		}

		if *(*Pgno)(unsafe.Pointer(bp + 16)) != *(*Pgno)(unsafe.Pointer(bp)) {
			*(*U8)(unsafe.Pointer(bp + 32)) = U8(0)
			*(*Pgno)(unsafe.Pointer(bp + 36)) = Pgno(0)

			*(*int32)(unsafe.Pointer(bp + 40)) = saveAllCursors(tls, pBt, uint32(0), uintptr(0))
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
			if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 40))
			}

			*(*int32)(unsafe.Pointer(bp + 40)) = btreeGetPage(tls, pBt, *(*Pgno)(unsafe.Pointer(bp)), bp+24, 0)
			if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 40))
			}
			*(*int32)(unsafe.Pointer(bp + 40)) = ptrmapGet(tls, pBt, *(*Pgno)(unsafe.Pointer(bp)), bp+32, bp+36)
			if int32(*(*U8)(unsafe.Pointer(bp + 32))) == PTRMAP_ROOTPAGE || int32(*(*U8)(unsafe.Pointer(bp + 32))) == PTRMAP_FREEPAGE {
				*(*int32)(unsafe.Pointer(bp + 40)) = Xsqlite3CorruptError(tls, 78166)
			}
			if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
				releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
				return *(*int32)(unsafe.Pointer(bp + 40))
			}

			*(*int32)(unsafe.Pointer(bp + 40)) = relocatePage(tls, pBt, *(*uintptr)(unsafe.Pointer(bp + 24)), *(*U8)(unsafe.Pointer(bp + 32)), *(*Pgno)(unsafe.Pointer(bp + 36)), *(*Pgno)(unsafe.Pointer(bp + 16)), 0)
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))

			if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 40))
			}
			*(*int32)(unsafe.Pointer(bp + 40)) = btreeGetPage(tls, pBt, *(*Pgno)(unsafe.Pointer(bp)), bp+24, 0)
			if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 40))
			}
			*(*int32)(unsafe.Pointer(bp + 40)) = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).FpDbPage)
			if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
				releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
				return *(*int32)(unsafe.Pointer(bp + 40))
			}
		} else {
			*(*uintptr)(unsafe.Pointer(bp + 24)) = *(*uintptr)(unsafe.Pointer(bp + 8))
		}

		ptrmapPut(tls, pBt, *(*Pgno)(unsafe.Pointer(bp)), uint8(PTRMAP_ROOTPAGE), uint32(0), bp+40)
		if *(*int32)(unsafe.Pointer(bp + 40)) != 0 {
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
			return *(*int32)(unsafe.Pointer(bp + 40))
		}

		*(*int32)(unsafe.Pointer(bp + 40)) = Xsqlite3BtreeUpdateMeta(tls, p, 4, *(*Pgno)(unsafe.Pointer(bp)))
		if *(*int32)(unsafe.Pointer(bp + 40)) != 0 {
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
			return *(*int32)(unsafe.Pointer(bp + 40))
		}

	} else {
		*(*int32)(unsafe.Pointer(bp + 40)) = allocateBtreePage(tls, pBt, bp+24, bp, uint32(1), uint8(0))
		if *(*int32)(unsafe.Pointer(bp + 40)) != 0 {
			return *(*int32)(unsafe.Pointer(bp + 40))
		}
	}

	if createTabFlags&BTREE_INTKEY != 0 {
		ptfFlags = PTF_INTKEY | PTF_LEAFDATA | PTF_LEAF
	} else {
		ptfFlags = PTF_ZERODATA | PTF_LEAF
	}
	zeroPage(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), ptfFlags)
	Xsqlite3PagerUnref(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).FpDbPage)

	*(*Pgno)(unsafe.Pointer(piTable)) = *(*Pgno)(unsafe.Pointer(bp))
	return SQLITE_OK
}

func Xsqlite3BtreeCreateTable(tls *libc.TLS, p uintptr, piTable uintptr, flags int32) int32 {
	var rc int32
	Xsqlite3BtreeEnter(tls, p)
	rc = btreeCreateTable(tls, p, piTable, flags)
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func clearDatabasePage(tls *libc.TLS, pBt uintptr, pgno Pgno, freePageFlag int32, pnChange uintptr) int32 {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var pCell uintptr
	var i int32
	var hdr int32

	if !(pgno > btreePagecount(tls, pBt)) {
		goto __1
	}
	return Xsqlite3CorruptError(tls, 78256)
__1:
	;
	*(*int32)(unsafe.Pointer(bp + 32)) = getAndInitPage(tls, pBt, pgno, bp, uintptr(0), 0)
	if !(*(*int32)(unsafe.Pointer(bp + 32)) != 0) {
		goto __2
	}
	return *(*int32)(unsafe.Pointer(bp + 32))
__2:
	;
	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FopenFlags)&BTREE_SINGLE == 0 &&
		Xsqlite3PagerPageRefcount(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage) != 1+libc.Bool32(pgno == Pgno(1))) {
		goto __3
	}
	*(*int32)(unsafe.Pointer(bp + 32)) = Xsqlite3CorruptError(tls, 78263)
	goto cleardatabasepage_out
__3:
	;
	hdr = int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FhdrOffset)
	i = 0
__4:
	if !(i < int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnCell)) {
		goto __6
	}
	pCell = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData + uintptr(int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaCellIdx + uintptr(2*i))))))
	if !!(int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fleaf) != 0) {
		goto __7
	}
	*(*int32)(unsafe.Pointer(bp + 32)) = clearDatabasePage(tls, pBt, Xsqlite3Get4byte(tls, pCell), 1, pnChange)
	if !(*(*int32)(unsafe.Pointer(bp + 32)) != 0) {
		goto __8
	}
	goto cleardatabasepage_out
__8:
	;
__7:
	;
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FxParseCell})).f(tls, *(*uintptr)(unsafe.Pointer(bp)), pCell, bp+8)
	if !(U32((*CellInfo)(unsafe.Pointer(bp+8)).FnLocal) != (*CellInfo)(unsafe.Pointer(bp+8)).FnPayload) {
		goto __9
	}
	*(*int32)(unsafe.Pointer(bp + 32)) = clearCellOverflow(tls, *(*uintptr)(unsafe.Pointer(bp)), pCell, bp+8)
	goto __10
__9:
	*(*int32)(unsafe.Pointer(bp + 32)) = SQLITE_OK
__10:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 32)) != 0) {
		goto __11
	}
	goto cleardatabasepage_out
__11:
	;
	goto __5
__5:
	i++
	goto __4
	goto __6
__6:
	;
	if !!(int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fleaf) != 0) {
		goto __12
	}
	*(*int32)(unsafe.Pointer(bp + 32)) = clearDatabasePage(tls, pBt, Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData+uintptr(hdr+8)), 1, pnChange)
	if !(*(*int32)(unsafe.Pointer(bp + 32)) != 0) {
		goto __13
	}
	goto cleardatabasepage_out
__13:
	;
	if !((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FintKey != 0) {
		goto __14
	}
	pnChange = uintptr(0)
__14:
	;
__12:
	;
	if !(pnChange != 0) {
		goto __15
	}

	*(*I64)(unsafe.Pointer(pnChange)) += I64((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnCell)
__15:
	;
	if !(freePageFlag != 0) {
		goto __16
	}
	freePage(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+32)
	goto __17
__16:
	if !(libc.AssignPtrInt32(bp+32, Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpDbPage)) == 0) {
		goto __18
	}
	zeroPage(tls, *(*uintptr)(unsafe.Pointer(bp)), int32(*(*U8)(unsafe.Pointer((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaData + uintptr(hdr))))|PTF_LEAF)
__18:
	;
__17:
	;
cleardatabasepage_out:
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return *(*int32)(unsafe.Pointer(bp + 32))
}

func Xsqlite3BtreeClearTable(tls *libc.TLS, p uintptr, iTable int32, pnChange uintptr) int32 {
	var rc int32
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	Xsqlite3BtreeEnter(tls, p)

	rc = saveAllCursors(tls, pBt, Pgno(iTable), uintptr(0))

	if SQLITE_OK == rc {
		if (*Btree)(unsafe.Pointer(p)).FhasIncrblobCur != 0 {
			invalidateIncrblobCursors(tls, p, Pgno(iTable), int64(0), 1)
		}
		rc = clearDatabasePage(tls, pBt, Pgno(iTable), 0, pnChange)
	}
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeClearTableOfCursor(tls *libc.TLS, pCur uintptr) int32 {
	return Xsqlite3BtreeClearTable(tls, (*BtCursor)(unsafe.Pointer(pCur)).FpBtree, int32((*BtCursor)(unsafe.Pointer(pCur)).FpgnoRoot), uintptr(0))
}

func btreeDropTable(tls *libc.TLS, p uintptr, iTable Pgno, piMoved uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	if iTable > btreePagecount(tls, pBt) {
		return Xsqlite3CorruptError(tls, 78367)
	}

	*(*int32)(unsafe.Pointer(bp + 12)) = Xsqlite3BtreeClearTable(tls, p, int32(iTable), uintptr(0))
	if *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
		return *(*int32)(unsafe.Pointer(bp + 12))
	}
	*(*int32)(unsafe.Pointer(bp + 12)) = btreeGetPage(tls, pBt, iTable, bp, 0)
	if *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
		releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
		return *(*int32)(unsafe.Pointer(bp + 12))
	}

	*(*int32)(unsafe.Pointer(piMoved)) = 0

	if (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 {
		Xsqlite3BtreeGetMeta(tls, p, BTREE_LARGEST_ROOT_PAGE, bp+8)

		if iTable == *(*Pgno)(unsafe.Pointer(bp + 8)) {
			freePage(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+12)
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
			if *(*int32)(unsafe.Pointer(bp + 12)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 12))
			}
		} else {
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
			*(*int32)(unsafe.Pointer(bp + 12)) = btreeGetPage(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 8)), bp+16, 0)
			if *(*int32)(unsafe.Pointer(bp + 12)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 12))
			}
			*(*int32)(unsafe.Pointer(bp + 12)) = relocatePage(tls, pBt, *(*uintptr)(unsafe.Pointer(bp + 16)), uint8(PTRMAP_ROOTPAGE), uint32(0), iTable, 0)
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
			if *(*int32)(unsafe.Pointer(bp + 12)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 12))
			}
			*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
			*(*int32)(unsafe.Pointer(bp + 12)) = btreeGetPage(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 8)), bp+16, 0)
			freePage(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), bp+12)
			releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
			if *(*int32)(unsafe.Pointer(bp + 12)) != SQLITE_OK {
				return *(*int32)(unsafe.Pointer(bp + 12))
			}
			*(*int32)(unsafe.Pointer(piMoved)) = int32(*(*Pgno)(unsafe.Pointer(bp + 8)))
		}

		*(*Pgno)(unsafe.Pointer(bp + 8))--
		for *(*Pgno)(unsafe.Pointer(bp + 8)) == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize+U32(1) ||
			ptrmapPageno(tls, pBt, *(*Pgno)(unsafe.Pointer(bp + 8))) == *(*Pgno)(unsafe.Pointer(bp + 8)) {
			*(*Pgno)(unsafe.Pointer(bp + 8))--
		}

		*(*int32)(unsafe.Pointer(bp + 12)) = Xsqlite3BtreeUpdateMeta(tls, p, 4, *(*Pgno)(unsafe.Pointer(bp + 8)))
	} else {
		freePage(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+12)
		releasePage(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return *(*int32)(unsafe.Pointer(bp + 12))
}

func Xsqlite3BtreeDropTable(tls *libc.TLS, p uintptr, iTable int32, piMoved uintptr) int32 {
	var rc int32
	Xsqlite3BtreeEnter(tls, p)
	rc = btreeDropTable(tls, p, uint32(iTable), piMoved)
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeGetMeta(tls *libc.TLS, p uintptr, idx int32, pMeta uintptr) {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt

	Xsqlite3BtreeEnter(tls, p)

	if idx == BTREE_DATA_VERSION {
		*(*U32)(unsafe.Pointer(pMeta)) = Xsqlite3PagerDataVersion(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager) + (*Btree)(unsafe.Pointer(p)).FiBDataVersion
	} else {
		*(*U32)(unsafe.Pointer(pMeta)) = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+uintptr(36+idx*4))
	}

	Xsqlite3BtreeLeave(tls, p)
}

func Xsqlite3BtreeUpdateMeta(tls *libc.TLS, p uintptr, idx int32, iMeta U32) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	var pP1 uintptr
	var rc int32

	Xsqlite3BtreeEnter(tls, p)

	pP1 = (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData
	rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
	if rc == SQLITE_OK {
		Xsqlite3Put4byte(tls, pP1+uintptr(36+idx*4), iMeta)
		if idx == BTREE_INCR_VACUUM {
			(*BtShared)(unsafe.Pointer(pBt)).FincrVacuum = U8(iMeta)
		}
	}
	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeCount(tls *libc.TLS, db uintptr, pCur uintptr, pnEntry uintptr) int32 {
	var nEntry I64 = int64(0)
	var rc int32

	rc = moveToRoot(tls, pCur)
	if rc == SQLITE_EMPTY {
		*(*I64)(unsafe.Pointer(pnEntry)) = int64(0)
		return SQLITE_OK
	}

	for rc == SQLITE_OK && !(libc.AtomicLoadNInt32(db+432, 0) != 0) {
		var iIdx int32
		var pPage uintptr

		pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
		if (*MemPage)(unsafe.Pointer(pPage)).Fleaf != 0 || !(int32((*MemPage)(unsafe.Pointer(pPage)).FintKey) != 0) {
			nEntry = nEntry + I64((*MemPage)(unsafe.Pointer(pPage)).FnCell)
		}

		if (*MemPage)(unsafe.Pointer(pPage)).Fleaf != 0 {
			for __ccgo := true; __ccgo; __ccgo = int32((*BtCursor)(unsafe.Pointer(pCur)).Fix) >= int32((*MemPage)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpPage)).FnCell) {
				if int32((*BtCursor)(unsafe.Pointer(pCur)).FiPage) == 0 {
					*(*I64)(unsafe.Pointer(pnEntry)) = nEntry
					return moveToRoot(tls, pCur)
				}
				moveToParent(tls, pCur)
			}

			(*BtCursor)(unsafe.Pointer(pCur)).Fix++
			pPage = (*BtCursor)(unsafe.Pointer(pCur)).FpPage
		}

		iIdx = int32((*BtCursor)(unsafe.Pointer(pCur)).Fix)
		if iIdx == int32((*MemPage)(unsafe.Pointer(pPage)).FnCell) {
			rc = moveToChild(tls, pCur, Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FhdrOffset)+8)))
		} else {
			rc = moveToChild(tls, pCur, Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer(pPage)).FaData+uintptr(int32((*MemPage)(unsafe.Pointer(pPage)).FmaskPage)&int32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer((*MemPage)(unsafe.Pointer(pPage)).FaCellIdx + uintptr(2*iIdx))))))))
		}
	}

	return rc
}

func Xsqlite3BtreePager(tls *libc.TLS, p uintptr) uintptr {
	return (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FpPager
}

func checkOom(tls *libc.TLS, pCheck uintptr) {
	(*IntegrityCk)(unsafe.Pointer(pCheck)).Frc = SQLITE_NOMEM
	(*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr = 0
	if (*IntegrityCk)(unsafe.Pointer(pCheck)).FnErr == 0 {
		(*IntegrityCk)(unsafe.Pointer(pCheck)).FnErr++
	}
}

func checkProgress(tls *libc.TLS, pCheck uintptr) {
	var db uintptr = (*IntegrityCk)(unsafe.Pointer(pCheck)).Fdb
	if libc.AtomicLoadNInt32(db+432, 0) != 0 {
		(*IntegrityCk)(unsafe.Pointer(pCheck)).Frc = SQLITE_INTERRUPT
		(*IntegrityCk)(unsafe.Pointer(pCheck)).FnErr++
		(*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr = 0
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FxProgress != 0 {
		(*IntegrityCk)(unsafe.Pointer(pCheck)).FnStep++
		if (*IntegrityCk)(unsafe.Pointer(pCheck)).FnStep%(*Sqlite3)(unsafe.Pointer(db)).FnProgressOps == U32(0) &&
			(*struct {
				f func(*libc.TLS, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxProgress})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0 {
			(*IntegrityCk)(unsafe.Pointer(pCheck)).Frc = SQLITE_INTERRUPT
			(*IntegrityCk)(unsafe.Pointer(pCheck)).FnErr++
			(*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr = 0
		}
	}
}

func checkAppendMsg(tls *libc.TLS, pCheck uintptr, zFormat uintptr, va uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var ap Va_list
	_ = ap
	checkProgress(tls, pCheck)
	if !((*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0) {
		return
	}
	(*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr--
	(*IntegrityCk)(unsafe.Pointer(pCheck)).FnErr++
	ap = va
	if (*IntegrityCk)(unsafe.Pointer(pCheck)).FerrMsg.FnChar != 0 {
		Xsqlite3_str_append(tls, pCheck+64, ts+6942, 1)
	}
	if (*IntegrityCk)(unsafe.Pointer(pCheck)).FzPfx != 0 {
		Xsqlite3_str_appendf(tls, pCheck+64, (*IntegrityCk)(unsafe.Pointer(pCheck)).FzPfx, libc.VaList(bp, (*IntegrityCk)(unsafe.Pointer(pCheck)).Fv1, (*IntegrityCk)(unsafe.Pointer(pCheck)).Fv2))
	}
	Xsqlite3_str_vappendf(tls, pCheck+64, zFormat, ap)
	_ = ap
	if int32((*IntegrityCk)(unsafe.Pointer(pCheck)).FerrMsg.FaccError) == SQLITE_NOMEM {
		checkOom(tls, pCheck)
	}
}

func getPageReferenced(tls *libc.TLS, pCheck uintptr, iPg Pgno) int32 {
	return int32(*(*U8)(unsafe.Pointer((*IntegrityCk)(unsafe.Pointer(pCheck)).FaPgRef + uintptr(iPg/Pgno(8))))) & (int32(1) << (iPg & Pgno(0x07)))
}

func setPageReferenced(tls *libc.TLS, pCheck uintptr, iPg Pgno) {
	*(*U8)(unsafe.Pointer((*IntegrityCk)(unsafe.Pointer(pCheck)).FaPgRef + uintptr(iPg/Pgno(8)))) |= U8(int32(1) << (iPg & Pgno(0x07)))
}

func checkRef(tls *libc.TLS, pCheck uintptr, iPage Pgno) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if iPage > (*IntegrityCk)(unsafe.Pointer(pCheck)).FnPage || iPage == Pgno(0) {
		checkAppendMsg(tls, pCheck, ts+6944, libc.VaList(bp, iPage))
		return 1
	}
	if getPageReferenced(tls, pCheck, iPage) != 0 {
		checkAppendMsg(tls, pCheck, ts+6967, libc.VaList(bp+8, iPage))
		return 1
	}
	setPageReferenced(tls, pCheck, iPage)
	return 0
}

func checkPtrmap(tls *libc.TLS, pCheck uintptr, iChild Pgno, eType U8, iParent Pgno) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var rc int32

	rc = ptrmapGet(tls, (*IntegrityCk)(unsafe.Pointer(pCheck)).FpBt, iChild, bp+48, bp+52)
	if rc != SQLITE_OK {
		if rc == SQLITE_NOMEM || rc == SQLITE_IOERR|int32(12)<<8 {
			checkOom(tls, pCheck)
		}
		checkAppendMsg(tls, pCheck, ts+6992, libc.VaList(bp, iChild))
		return
	}

	if int32(*(*U8)(unsafe.Pointer(bp + 48))) != int32(eType) || *(*Pgno)(unsafe.Pointer(bp + 52)) != iParent {
		checkAppendMsg(tls, pCheck,
			ts+7021,
			libc.VaList(bp+8, iChild, int32(eType), iParent, int32(*(*U8)(unsafe.Pointer(bp + 48))), *(*Pgno)(unsafe.Pointer(bp + 52))))
	}
}

func checkList(tls *libc.TLS, pCheck uintptr, isFreeList int32, iPage Pgno, N U32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var i int32
	var expected U32 = N
	var nErrAtStart int32 = (*IntegrityCk)(unsafe.Pointer(pCheck)).FnErr
	for iPage != Pgno(0) && (*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0 {
		var pOvflData uintptr
		if checkRef(tls, pCheck, iPage) != 0 {
			break
		}
		N--
		if Xsqlite3PagerGet(tls, (*IntegrityCk)(unsafe.Pointer(pCheck)).FpPager, iPage, bp+40, 0) != 0 {
			checkAppendMsg(tls, pCheck, ts+7075, libc.VaList(bp, iPage))
			break
		}
		pOvflData = Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
		if isFreeList != 0 {
			var n U32 = Xsqlite3Get4byte(tls, pOvflData+4)
			if (*BtShared)(unsafe.Pointer((*IntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 {
				checkPtrmap(tls, pCheck, iPage, uint8(PTRMAP_FREEPAGE), uint32(0))
			}
			if n > (*BtShared)(unsafe.Pointer((*IntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FusableSize/U32(4)-U32(2) {
				checkAppendMsg(tls, pCheck,
					ts+7097, libc.VaList(bp+8, iPage))
				N--
			} else {
				for i = 0; i < int32(n); i++ {
					var iFreePage Pgno = Xsqlite3Get4byte(tls, pOvflData+uintptr(8+i*4))
					if (*BtShared)(unsafe.Pointer((*IntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 {
						checkPtrmap(tls, pCheck, iFreePage, uint8(PTRMAP_FREEPAGE), uint32(0))
					}
					checkRef(tls, pCheck, iFreePage)
				}
				N = N - n
			}
		} else {
			if (*BtShared)(unsafe.Pointer((*IntegrityCk)(unsafe.Pointer(pCheck)).FpBt)).FautoVacuum != 0 && N > U32(0) {
				i = int32(Xsqlite3Get4byte(tls, pOvflData))
				checkPtrmap(tls, pCheck, uint32(i), uint8(PTRMAP_OVERFLOW2), iPage)
			}
		}
		iPage = Xsqlite3Get4byte(tls, pOvflData)
		Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
	}
	if N != 0 && nErrAtStart == (*IntegrityCk)(unsafe.Pointer(pCheck)).FnErr {
		checkAppendMsg(tls, pCheck,
			ts+7136,
			libc.VaList(bp+16, func() uintptr {
				if isFreeList != 0 {
					return ts + 7162
				}
				return ts + 7167
			}(),
				expected-N, expected))
	}
}

func btreeHeapInsert(tls *libc.TLS, aHeap uintptr, x U32) {
	var j U32
	var i U32

	i = libc.PreIncUint32(&*(*U32)(unsafe.Pointer(aHeap)), 1)
	*(*U32)(unsafe.Pointer(aHeap + uintptr(i)*4)) = x
	for libc.AssignUint32(&j, i/U32(2)) > U32(0) && *(*U32)(unsafe.Pointer(aHeap + uintptr(j)*4)) > *(*U32)(unsafe.Pointer(aHeap + uintptr(i)*4)) {
		x = *(*U32)(unsafe.Pointer(aHeap + uintptr(j)*4))
		*(*U32)(unsafe.Pointer(aHeap + uintptr(j)*4)) = *(*U32)(unsafe.Pointer(aHeap + uintptr(i)*4))
		*(*U32)(unsafe.Pointer(aHeap + uintptr(i)*4)) = x
		i = j
	}
}

func btreeHeapPull(tls *libc.TLS, aHeap uintptr, pOut uintptr) int32 {
	var j U32
	var i U32
	var x U32
	if libc.AssignUint32(&x, *(*U32)(unsafe.Pointer(aHeap))) == U32(0) {
		return 0
	}
	*(*U32)(unsafe.Pointer(pOut)) = *(*U32)(unsafe.Pointer(aHeap + 1*4))
	*(*U32)(unsafe.Pointer(aHeap + 1*4)) = *(*U32)(unsafe.Pointer(aHeap + uintptr(x)*4))
	*(*U32)(unsafe.Pointer(aHeap + uintptr(x)*4)) = 0xffffffff
	*(*U32)(unsafe.Pointer(aHeap))--
	i = U32(1)
	for libc.AssignUint32(&j, i*U32(2)) <= *(*U32)(unsafe.Pointer(aHeap)) {
		if *(*U32)(unsafe.Pointer(aHeap + uintptr(j)*4)) > *(*U32)(unsafe.Pointer(aHeap + uintptr(j+U32(1))*4)) {
			j++
		}
		if *(*U32)(unsafe.Pointer(aHeap + uintptr(i)*4)) < *(*U32)(unsafe.Pointer(aHeap + uintptr(j)*4)) {
			break
		}
		x = *(*U32)(unsafe.Pointer(aHeap + uintptr(i)*4))
		*(*U32)(unsafe.Pointer(aHeap + uintptr(i)*4)) = *(*U32)(unsafe.Pointer(aHeap + uintptr(j)*4))
		*(*U32)(unsafe.Pointer(aHeap + uintptr(j)*4)) = x
		i = j
	}
	return 1
}

func checkTreePage(tls *libc.TLS, pCheck uintptr, iPage Pgno, piMinKey uintptr, maxKey I64) int32 {
	bp := tls.Alloc(140)
	defer tls.Free(140)
	*(*I64)(unsafe.Pointer(bp + 104)) = maxKey

	var i int32
	var rc int32
	var depth int32
	var d2 int32
	var pgno int32
	var nFrag int32
	var hdr int32
	var cellStart int32
	var nCell int32
	var doCoverageCheck int32
	var keyCanBeEqual int32

	var data uintptr
	var pCell uintptr
	var pCellIdx uintptr
	var pBt uintptr
	var pc U32
	var usableSize U32
	var contentOffset U32
	var heap uintptr

	var prev U32
	var saved_zPfx uintptr
	var saved_v1 int32
	var saved_v2 int32
	var savedIsInit U8
	var nPage U32
	var pgnoOvfl Pgno

	var size U32
	var size1 int32
	var j int32
	*(*uintptr)(unsafe.Pointer(bp + 96)) = uintptr(0)
	depth = -1
	doCoverageCheck = 1
	keyCanBeEqual = 1
	heap = uintptr(0)
	prev = U32(0)
	saved_zPfx = (*IntegrityCk)(unsafe.Pointer(pCheck)).FzPfx
	saved_v1 = int32((*IntegrityCk)(unsafe.Pointer(pCheck)).Fv1)
	saved_v2 = (*IntegrityCk)(unsafe.Pointer(pCheck)).Fv2
	savedIsInit = U8(0)

	checkProgress(tls, pCheck)
	if !((*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr == 0) {
		goto __1
	}
	goto end_of_check
__1:
	;
	pBt = (*IntegrityCk)(unsafe.Pointer(pCheck)).FpBt
	usableSize = (*BtShared)(unsafe.Pointer(pBt)).FusableSize
	if !(iPage == Pgno(0)) {
		goto __2
	}
	return 0
__2:
	;
	if !(checkRef(tls, pCheck, iPage) != 0) {
		goto __3
	}
	return 0
__3:
	;
	(*IntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = ts + 7188
	(*IntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = iPage
	if !(libc.AssignInt32(&rc, btreeGetPage(tls, pBt, iPage, bp+96, 0)) != 0) {
		goto __4
	}
	checkAppendMsg(tls, pCheck,
		ts+7198, libc.VaList(bp, rc))
	goto end_of_check
__4:
	;
	savedIsInit = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FisInit
	(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FisInit = U8(0)
	if !(libc.AssignInt32(&rc, btreeInitPage(tls, *(*uintptr)(unsafe.Pointer(bp + 96)))) != 0) {
		goto __5
	}

	checkAppendMsg(tls, pCheck,
		ts+7236, libc.VaList(bp+8, rc))
	goto end_of_check
__5:
	;
	if !(libc.AssignInt32(&rc, btreeComputeFreeSpace(tls, *(*uintptr)(unsafe.Pointer(bp + 96)))) != 0) {
		goto __6
	}

	checkAppendMsg(tls, pCheck, ts+7274, libc.VaList(bp+16, rc))
	goto end_of_check
__6:
	;
	data = (*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FaData
	hdr = int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FhdrOffset)

	(*IntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = ts + 7296
	contentOffset = U32((int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+5))))<<8|int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+5) + 1)))-1)&0xffff + 1)

	nCell = int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+3))))<<8 | int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+3) + 1)))

	cellStart = hdr + 12 - 4*int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).Fleaf)

	pCellIdx = data + uintptr(cellStart+2*(nCell-1))

	if !!(int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).Fleaf) != 0) {
		goto __7
	}

	pgno = int32(Xsqlite3Get4byte(tls, data+uintptr(hdr+8)))
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
		goto __9
	}
	(*IntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = ts + 7322
	checkPtrmap(tls, pCheck, uint32(pgno), uint8(PTRMAP_BTREE), iPage)
__9:
	;
	depth = checkTreePage(tls, pCheck, uint32(pgno), bp+104, *(*I64)(unsafe.Pointer(bp + 104)))
	keyCanBeEqual = 0
	goto __8
__7:
	heap = (*IntegrityCk)(unsafe.Pointer(pCheck)).Fheap
	*(*U32)(unsafe.Pointer(heap)) = U32(0)
__8:
	;
	i = nCell - 1
__10:
	if !(i >= 0 && (*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr != 0) {
		goto __12
	}

	(*IntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = i

	pc = U32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer(pCellIdx))))
	pCellIdx -= uintptr(2)
	if !(pc < contentOffset || pc > usableSize-U32(4)) {
		goto __13
	}
	checkAppendMsg(tls, pCheck, ts+7350,
		libc.VaList(bp+24, pc, contentOffset, usableSize-U32(4)))
	doCoverageCheck = 0
	goto __11
__13:
	;
	pCell = data + uintptr(pc)
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FxParseCell})).f(tls, *(*uintptr)(unsafe.Pointer(bp + 96)), pCell, bp+112)
	if !(pc+U32((*CellInfo)(unsafe.Pointer(bp+112)).FnSize) > usableSize) {
		goto __14
	}
	checkAppendMsg(tls, pCheck, ts+7380, 0)
	doCoverageCheck = 0
	goto __11
__14:
	;
	if !((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FintKey != 0) {
		goto __15
	}
	if !(func() int32 {
		if keyCanBeEqual != 0 {
			return libc.Bool32((*CellInfo)(unsafe.Pointer(bp+112)).FnKey > *(*I64)(unsafe.Pointer(bp + 104)))
		}
		return libc.Bool32((*CellInfo)(unsafe.Pointer(bp+112)).FnKey >= *(*I64)(unsafe.Pointer(bp + 104)))
	}() != 0) {
		goto __16
	}
	checkAppendMsg(tls, pCheck, ts+7404, libc.VaList(bp+48, (*CellInfo)(unsafe.Pointer(bp+112)).FnKey))
__16:
	;
	*(*I64)(unsafe.Pointer(bp + 104)) = (*CellInfo)(unsafe.Pointer(bp + 112)).FnKey
	keyCanBeEqual = 0
__15:
	;
	if !((*CellInfo)(unsafe.Pointer(bp+112)).FnPayload > U32((*CellInfo)(unsafe.Pointer(bp+112)).FnLocal)) {
		goto __17
	}

	nPage = ((*CellInfo)(unsafe.Pointer(bp+112)).FnPayload - U32((*CellInfo)(unsafe.Pointer(bp+112)).FnLocal) + usableSize - U32(5)) / (usableSize - U32(4))
	pgnoOvfl = Xsqlite3Get4byte(tls, pCell+uintptr(int32((*CellInfo)(unsafe.Pointer(bp+112)).FnSize)-4))
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
		goto __18
	}
	checkPtrmap(tls, pCheck, pgnoOvfl, uint8(PTRMAP_OVERFLOW1), iPage)
__18:
	;
	checkList(tls, pCheck, 0, pgnoOvfl, nPage)
__17:
	;
	if !!(int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).Fleaf) != 0) {
		goto __19
	}

	pgno = int32(Xsqlite3Get4byte(tls, pCell))
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
		goto __21
	}
	checkPtrmap(tls, pCheck, uint32(pgno), uint8(PTRMAP_BTREE), iPage)
__21:
	;
	d2 = checkTreePage(tls, pCheck, uint32(pgno), bp+104, *(*I64)(unsafe.Pointer(bp + 104)))
	keyCanBeEqual = 0
	if !(d2 != depth) {
		goto __22
	}
	checkAppendMsg(tls, pCheck, ts+7428, 0)
	depth = d2
__22:
	;
	goto __20
__19:
	btreeHeapInsert(tls, heap, pc<<16|(pc+U32((*CellInfo)(unsafe.Pointer(bp+112)).FnSize)-U32(1)))
__20:
	;
	goto __11
__11:
	i--
	goto __10
	goto __12
__12:
	;
	*(*I64)(unsafe.Pointer(piMinKey)) = *(*I64)(unsafe.Pointer(bp + 104))

	(*IntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = uintptr(0)
	if !(doCoverageCheck != 0 && (*IntegrityCk)(unsafe.Pointer(pCheck)).FmxErr > 0) {
		goto __23
	}

	if !!(int32((*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).Fleaf) != 0) {
		goto __24
	}
	heap = (*IntegrityCk)(unsafe.Pointer(pCheck)).Fheap
	*(*U32)(unsafe.Pointer(heap)) = U32(0)
	i = nCell - 1
__25:
	if !(i >= 0) {
		goto __27
	}
	pc = U32(libc.X__builtin_bswap16(tls, *(*U16)(unsafe.Pointer(data + uintptr(cellStart+i*2)))))
	size = U32((*struct {
		f func(*libc.TLS, uintptr, uintptr) U16
	})(unsafe.Pointer(&struct{ uintptr }{(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FxCellSize})).f(tls, *(*uintptr)(unsafe.Pointer(bp + 96)), data+uintptr(pc)))
	btreeHeapInsert(tls, heap, pc<<16|(pc+size-U32(1)))
	goto __26
__26:
	i--
	goto __25
	goto __27
__27:
	;
__24:
	;
	i = int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+1))))<<8 | int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+1) + 1)))
__28:
	if !(i > 0) {
		goto __29
	}

	size1 = int32(*(*U8)(unsafe.Pointer(data + uintptr(i+2))))<<8 | int32(*(*U8)(unsafe.Pointer(data + uintptr(i+2) + 1)))

	btreeHeapInsert(tls, heap, U32(i)<<16|U32(i+size1-1))

	j = int32(*(*U8)(unsafe.Pointer(data + uintptr(i))))<<8 | int32(*(*U8)(unsafe.Pointer(data + uintptr(i) + 1)))

	i = j
	goto __28
__29:
	;
	nFrag = 0
	prev = contentOffset - U32(1)
__30:
	if !(btreeHeapPull(tls, heap, bp+136) != 0) {
		goto __31
	}
	if !(prev&U32(0xffff) >= *(*U32)(unsafe.Pointer(bp + 136))>>16) {
		goto __32
	}
	checkAppendMsg(tls, pCheck,
		ts+7453, libc.VaList(bp+56, *(*U32)(unsafe.Pointer(bp + 136))>>16, iPage))
	goto __31
	goto __33
__32:
	nFrag = int32(U32(nFrag) + (*(*U32)(unsafe.Pointer(bp + 136))>>16 - prev&U32(0xffff) - U32(1)))
	prev = *(*U32)(unsafe.Pointer(bp + 136))
__33:
	;
	goto __30
__31:
	;
	nFrag = int32(U32(nFrag) + (usableSize - prev&U32(0xffff) - U32(1)))

	if !(*(*U32)(unsafe.Pointer(heap)) == U32(0) && nFrag != int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+7))))) {
		goto __34
	}
	checkAppendMsg(tls, pCheck,
		ts+7490,
		libc.VaList(bp+72, nFrag, int32(*(*U8)(unsafe.Pointer(data + uintptr(hdr+7)))), iPage))
__34:
	;
__23:
	;
end_of_check:
	if !!(doCoverageCheck != 0) {
		goto __35
	}
	(*MemPage)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FisInit = savedIsInit
__35:
	;
	releasePage(tls, *(*uintptr)(unsafe.Pointer(bp + 96)))
	(*IntegrityCk)(unsafe.Pointer(pCheck)).FzPfx = saved_zPfx
	(*IntegrityCk)(unsafe.Pointer(pCheck)).Fv1 = Pgno(saved_v1)
	(*IntegrityCk)(unsafe.Pointer(pCheck)).Fv2 = saved_v2
	return depth + 1
}

func Xsqlite3BtreeIntegrityCheck(tls *libc.TLS, db uintptr, p uintptr, aRoot uintptr, nRoot int32, mxErr int32, pnErr uintptr, pzOut uintptr) int32 {
	bp := tls.Alloc(256)
	defer tls.Free(256)

	var i Pgno

	var pBt uintptr
	var savedDbFlags U64

	var bPartial int32
	var bCkFreelist int32
	var mx Pgno
	var mxInHdr Pgno

	pBt = (*Btree)(unsafe.Pointer(p)).FpBt
	savedDbFlags = (*Sqlite3)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags
	bPartial = 0
	bCkFreelist = 1

	if !(*(*Pgno)(unsafe.Pointer(aRoot)) == Pgno(0)) {
		goto __1
	}

	bPartial = 1
	if !(*(*Pgno)(unsafe.Pointer(aRoot + 1*4)) != Pgno(1)) {
		goto __2
	}
	bCkFreelist = 0
__2:
	;
__1:
	;
	Xsqlite3BtreeEnter(tls, p)

	libc.Xmemset(tls, bp+32, 0, uint64(unsafe.Sizeof(IntegrityCk{})))
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).Fdb = db
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).FpBt = pBt
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).FpPager = (*BtShared)(unsafe.Pointer(pBt)).FpPager
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).FnPage = btreePagecount(tls, (*IntegrityCk)(unsafe.Pointer(bp+32)).FpBt)
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).FmxErr = mxErr
	Xsqlite3StrAccumInit(tls, bp+32+64, uintptr(0), bp+144, int32(unsafe.Sizeof([100]uint8{})), SQLITE_MAX_LENGTH)
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).FerrMsg.FprintfFlags = U8(SQLITE_PRINTF_INTERNAL)
	if !((*IntegrityCk)(unsafe.Pointer(bp+32)).FnPage == Pgno(0)) {
		goto __3
	}
	goto integrity_ck_cleanup
__3:
	;
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).FaPgRef = Xsqlite3MallocZero(tls, uint64((*IntegrityCk)(unsafe.Pointer(bp+32)).FnPage/Pgno(8)+Pgno(1)))
	if !!(int32((*IntegrityCk)(unsafe.Pointer(bp+32)).FaPgRef) != 0) {
		goto __4
	}
	checkOom(tls, bp+32)
	goto integrity_ck_cleanup
__4:
	;
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).Fheap = Xsqlite3PageMalloc(tls, int32((*BtShared)(unsafe.Pointer(pBt)).FpageSize))
	if !((*IntegrityCk)(unsafe.Pointer(bp+32)).Fheap == uintptr(0)) {
		goto __5
	}
	checkOom(tls, bp+32)
	goto integrity_ck_cleanup
__5:
	;
	i = U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer(pBt)).FpageSize + U32(1)
	if !(i <= (*IntegrityCk)(unsafe.Pointer(bp+32)).FnPage) {
		goto __6
	}
	setPageReferenced(tls, bp+32, i)
__6:
	;
	if !(bCkFreelist != 0) {
		goto __7
	}
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).FzPfx = ts + 7542
	checkList(tls, bp+32, 1, Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+32),
		Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+36))
	(*IntegrityCk)(unsafe.Pointer(bp + 32)).FzPfx = uintptr(0)
__7:
	;
	if !!(bPartial != 0) {
		goto __8
	}
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0) {
		goto __9
	}
	mx = Pgno(0)
	i = Pgno(0)
__11:
	if !(int32(i) < nRoot) {
		goto __13
	}
	if !(mx < *(*Pgno)(unsafe.Pointer(aRoot + uintptr(i)*4))) {
		goto __14
	}
	mx = *(*Pgno)(unsafe.Pointer(aRoot + uintptr(i)*4))
__14:
	;
	goto __12
__12:
	i++
	goto __11
	goto __13
__13:
	;
	mxInHdr = Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+52)
	if !(mx != mxInHdr) {
		goto __15
	}
	checkAppendMsg(tls, bp+32,
		ts+7558,
		libc.VaList(bp, mx, mxInHdr))
__15:
	;
	goto __10
__9:
	if !(Xsqlite3Get4byte(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData+64) != U32(0)) {
		goto __16
	}
	checkAppendMsg(tls, bp+32,
		ts+7603, 0)
__16:
	;
__10:
	;
__8:
	;
	*(*U64)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).Fdb + 48)) &= libc.CplUint64(uint64(SQLITE_CellSizeCk))
	i = Pgno(0)
__17:
	if !(int32(i) < nRoot && (*IntegrityCk)(unsafe.Pointer(bp+32)).FmxErr != 0) {
		goto __19
	}
	if !(*(*Pgno)(unsafe.Pointer(aRoot + uintptr(i)*4)) == Pgno(0)) {
		goto __20
	}
	goto __18
__20:
	;
	if !((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0 && *(*Pgno)(unsafe.Pointer(aRoot + uintptr(i)*4)) > Pgno(1) && !(bPartial != 0)) {
		goto __21
	}
	checkPtrmap(tls, bp+32, *(*Pgno)(unsafe.Pointer(aRoot + uintptr(i)*4)), uint8(PTRMAP_ROOTPAGE), uint32(0))
__21:
	;
	checkTreePage(tls, bp+32, *(*Pgno)(unsafe.Pointer(aRoot + uintptr(i)*4)), bp+248, int64(0xffffffff)|int64(0x7fffffff)<<32)
	goto __18
__18:
	i++
	goto __17
	goto __19
__19:
	;
	(*Sqlite3)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).Fdb)).Fflags = savedDbFlags

	if !!(bPartial != 0) {
		goto __22
	}
	i = Pgno(1)
__23:
	if !(i <= (*IntegrityCk)(unsafe.Pointer(bp+32)).FnPage && (*IntegrityCk)(unsafe.Pointer(bp+32)).FmxErr != 0) {
		goto __25
	}

	if !(getPageReferenced(tls, bp+32, i) == 0 && (ptrmapPageno(tls, pBt, i) != i || !(int32((*BtShared)(unsafe.Pointer(pBt)).FautoVacuum) != 0))) {
		goto __26
	}
	checkAppendMsg(tls, bp+32, ts+7658, libc.VaList(bp+16, i))
__26:
	;
	if !(getPageReferenced(tls, bp+32, i) != 0 && (ptrmapPageno(tls, pBt, i) == i && (*BtShared)(unsafe.Pointer(pBt)).FautoVacuum != 0)) {
		goto __27
	}
	checkAppendMsg(tls, bp+32, ts+7680, libc.VaList(bp+24, i))
__27:
	;
	goto __24
__24:
	i++
	goto __23
	goto __25
__25:
	;
__22:
	;
integrity_ck_cleanup:
	Xsqlite3PageFree(tls, (*IntegrityCk)(unsafe.Pointer(bp+32)).Fheap)
	Xsqlite3_free(tls, (*IntegrityCk)(unsafe.Pointer(bp+32)).FaPgRef)
	*(*int32)(unsafe.Pointer(pnErr)) = (*IntegrityCk)(unsafe.Pointer(bp + 32)).FnErr
	if !((*IntegrityCk)(unsafe.Pointer(bp+32)).FnErr == 0) {
		goto __28
	}
	Xsqlite3_str_reset(tls, bp+32+64)
	*(*uintptr)(unsafe.Pointer(pzOut)) = uintptr(0)
	goto __29
__28:
	*(*uintptr)(unsafe.Pointer(pzOut)) = Xsqlite3StrAccumFinish(tls, bp+32+64)
__29:
	;
	Xsqlite3BtreeLeave(tls, p)
	return (*IntegrityCk)(unsafe.Pointer(bp + 32)).Frc
}

func Xsqlite3BtreeGetFilename(tls *libc.TLS, p uintptr) uintptr {
	return Xsqlite3PagerFilename(tls, (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FpPager, 1)
}

func Xsqlite3BtreeGetJournalname(tls *libc.TLS, p uintptr) uintptr {
	return Xsqlite3PagerJournalname(tls, (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FpPager)
}

func Xsqlite3BtreeTxnState(tls *libc.TLS, p uintptr) int32 {
	if p != 0 {
		return int32((*Btree)(unsafe.Pointer(p)).FinTrans)
	}
	return 0
}

func Xsqlite3BtreeCheckpoint(tls *libc.TLS, p uintptr, eMode int32, pnLog uintptr, pnCkpt uintptr) int32 {
	var rc int32 = SQLITE_OK
	if p != 0 {
		var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
		Xsqlite3BtreeEnter(tls, p)
		if int32((*BtShared)(unsafe.Pointer(pBt)).FinTransaction) != TRANS_NONE {
			rc = SQLITE_LOCKED
		} else {
			rc = Xsqlite3PagerCheckpoint(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager, (*Btree)(unsafe.Pointer(p)).Fdb, eMode, pnLog, pnCkpt)
		}
		Xsqlite3BtreeLeave(tls, p)
	}
	return rc
}

func Xsqlite3BtreeIsInBackup(tls *libc.TLS, p uintptr) int32 {
	return libc.Bool32((*Btree)(unsafe.Pointer(p)).FnBackup != 0)
}

func Xsqlite3BtreeSchema(tls *libc.TLS, p uintptr, nBytes int32, xFree uintptr) uintptr {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	Xsqlite3BtreeEnter(tls, p)
	if !(int32((*BtShared)(unsafe.Pointer(pBt)).FpSchema) != 0) && nBytes != 0 {
		(*BtShared)(unsafe.Pointer(pBt)).FpSchema = Xsqlite3DbMallocZero(tls, uintptr(0), uint64(nBytes))
		(*BtShared)(unsafe.Pointer(pBt)).FxFreeSchema = xFree
	}
	Xsqlite3BtreeLeave(tls, p)
	return (*BtShared)(unsafe.Pointer(pBt)).FpSchema
}

func Xsqlite3BtreeSchemaLocked(tls *libc.TLS, p uintptr) int32 {
	var rc int32

	Xsqlite3BtreeEnter(tls, p)
	rc = querySharedCacheTableLock(tls, p, uint32(SCHEMA_ROOT), uint8(READ_LOCK))

	Xsqlite3BtreeLeave(tls, p)
	return rc
}

func Xsqlite3BtreeLockTable(tls *libc.TLS, p uintptr, iTab int32, isWriteLock U8) int32 {
	var rc int32 = SQLITE_OK

	if (*Btree)(unsafe.Pointer(p)).Fsharable != 0 {
		var lockType U8 = U8(READ_LOCK + int32(isWriteLock))

		Xsqlite3BtreeEnter(tls, p)
		rc = querySharedCacheTableLock(tls, p, uint32(iTab), lockType)
		if rc == SQLITE_OK {
			rc = setSharedCacheTableLock(tls, p, uint32(iTab), lockType)
		}
		Xsqlite3BtreeLeave(tls, p)
	}
	return rc
}

func Xsqlite3BtreePutData(tls *libc.TLS, pCsr uintptr, offset U32, amt U32, z uintptr) int32 {
	var rc int32

	rc = func() int32 {
		if int32((*BtCursor)(unsafe.Pointer(pCsr)).FeState) >= CURSOR_REQUIRESEEK {
			return btreeRestoreCursorPosition(tls, pCsr)
		}
		return SQLITE_OK
	}()
	if rc != SQLITE_OK {
		return rc
	}

	if int32((*BtCursor)(unsafe.Pointer(pCsr)).FeState) != CURSOR_VALID {
		return SQLITE_ABORT
	}

	saveAllCursors(tls, (*BtCursor)(unsafe.Pointer(pCsr)).FpBt, (*BtCursor)(unsafe.Pointer(pCsr)).FpgnoRoot, pCsr)

	if int32((*BtCursor)(unsafe.Pointer(pCsr)).FcurFlags)&BTCF_WriteFlag == 0 {
		return SQLITE_READONLY
	}

	return accessPayload(tls, pCsr, offset, amt, z, 1)
}

func Xsqlite3BtreeIncrblobCursor(tls *libc.TLS, pCur uintptr) {
	*(*U8)(unsafe.Pointer(pCur + 1)) |= U8(BTCF_Incrblob)
	(*Btree)(unsafe.Pointer((*BtCursor)(unsafe.Pointer(pCur)).FpBtree)).FhasIncrblobCur = U8(1)
}

func Xsqlite3BtreeSetVersion(tls *libc.TLS, pBtree uintptr, iVersion int32) int32 {
	var pBt uintptr = (*Btree)(unsafe.Pointer(pBtree)).FpBt
	var rc int32

	*(*U16)(unsafe.Pointer(pBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_NO_WAL))
	if iVersion == 1 {
		*(*U16)(unsafe.Pointer(pBt + 40)) |= U16(BTS_NO_WAL)
	}

	rc = Xsqlite3BtreeBeginTrans(tls, pBtree, 0, uintptr(0))
	if rc == SQLITE_OK {
		var aData uintptr = (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FaData
		if int32(*(*U8)(unsafe.Pointer(aData + 18))) != int32(U8(iVersion)) || int32(*(*U8)(unsafe.Pointer(aData + 19))) != int32(U8(iVersion)) {
			rc = Xsqlite3BtreeBeginTrans(tls, pBtree, 2, uintptr(0))
			if rc == SQLITE_OK {
				rc = Xsqlite3PagerWrite(tls, (*MemPage)(unsafe.Pointer((*BtShared)(unsafe.Pointer(pBt)).FpPage1)).FpDbPage)
				if rc == SQLITE_OK {
					*(*U8)(unsafe.Pointer(aData + 18)) = U8(iVersion)
					*(*U8)(unsafe.Pointer(aData + 19)) = U8(iVersion)
				}
			}
		}
	}

	*(*U16)(unsafe.Pointer(pBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_NO_WAL))
	return rc
}

func Xsqlite3BtreeCursorHasHint(tls *libc.TLS, pCsr uintptr, mask uint32) int32 {
	return libc.Bool32(uint32((*BtCursor)(unsafe.Pointer(pCsr)).Fhints)&mask != uint32(0))
}

func Xsqlite3BtreeIsReadonly(tls *libc.TLS, p uintptr) int32 {
	return libc.Bool32(int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FbtsFlags)&BTS_READ_ONLY != 0)
}

func Xsqlite3HeaderSizeBtree(tls *libc.TLS) int32 {
	return int32((uint64(unsafe.Sizeof(MemPage{})) + uint64(7)) & libc.Uint64FromInt32(libc.CplInt32(7)))
}

func Xsqlite3BtreeClearCache(tls *libc.TLS, p uintptr) {
	var pBt uintptr = (*Btree)(unsafe.Pointer(p)).FpBt
	if int32((*BtShared)(unsafe.Pointer(pBt)).FinTransaction) == TRANS_NONE {
		Xsqlite3PagerClearCache(tls, (*BtShared)(unsafe.Pointer(pBt)).FpPager)
	}
}

func Xsqlite3BtreeSharable(tls *libc.TLS, p uintptr) int32 {
	return int32((*Btree)(unsafe.Pointer(p)).Fsharable)
}

func Xsqlite3BtreeConnectionCount(tls *libc.TLS, p uintptr) int32 {
	return (*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer(p)).FpBt)).FnRef
}

func findBtree(tls *libc.TLS, pErrorDb uintptr, pDb uintptr, zDb uintptr) uintptr {
	bp := tls.Alloc(440)
	defer tls.Free(440)

	var i int32 = Xsqlite3FindDbName(tls, pDb, zDb)

	if i == 1 {
		var rc int32 = 0
		Xsqlite3ParseObjectInit(tls, bp+16, pDb)
		if Xsqlite3OpenTempDatabase(tls, bp+16) != 0 {
			Xsqlite3ErrorWithMsg(tls, pErrorDb, (*Parse)(unsafe.Pointer(bp+16)).Frc, ts+1684, libc.VaList(bp, (*Parse)(unsafe.Pointer(bp+16)).FzErrMsg))
			rc = SQLITE_ERROR
		}
		Xsqlite3DbFree(tls, pErrorDb, (*Parse)(unsafe.Pointer(bp+16)).FzErrMsg)
		Xsqlite3ParseObjectReset(tls, bp+16)
		if rc != 0 {
			return uintptr(0)
		}
	}

	if i < 0 {
		Xsqlite3ErrorWithMsg(tls, pErrorDb, SQLITE_ERROR, ts+7714, libc.VaList(bp+8, zDb))
		return uintptr(0)
	}

	return (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(pDb)).FaDb + uintptr(i)*32)).FpBt
}

func setDestPgsz(tls *libc.TLS, p uintptr) int32 {
	var rc int32
	rc = Xsqlite3BtreeSetPageSize(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest, Xsqlite3BtreeGetPageSize(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc), 0, 0)
	return rc
}

func checkReadTransaction(tls *libc.TLS, db uintptr, p uintptr) int32 {
	if Xsqlite3BtreeTxnState(tls, p) != SQLITE_TXN_NONE {
		Xsqlite3ErrorWithMsg(tls, db, SQLITE_ERROR, ts+7734, 0)
		return SQLITE_ERROR
	}
	return SQLITE_OK
}

func Xsqlite3_backup_init(tls *libc.TLS, pDestDb uintptr, zDestDb uintptr, pSrcDb uintptr, zSrcDb uintptr) uintptr {
	var p uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(pDestDb)).Fmutex)

	if pSrcDb == pDestDb {
		Xsqlite3ErrorWithMsg(tls,
			pDestDb, SQLITE_ERROR, ts+7765, 0)
		p = uintptr(0)
	} else {
		p = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(Sqlite3_backup{})))
		if !(p != 0) {
			Xsqlite3Error(tls, pDestDb, SQLITE_NOMEM)
		}
	}

	if p != 0 {
		(*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc = findBtree(tls, pDestDb, pSrcDb, zSrcDb)
		(*Sqlite3_backup)(unsafe.Pointer(p)).FpDest = findBtree(tls, pDestDb, pDestDb, zDestDb)
		(*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb = pDestDb
		(*Sqlite3_backup)(unsafe.Pointer(p)).FpSrcDb = pSrcDb
		(*Sqlite3_backup)(unsafe.Pointer(p)).FiNext = Pgno(1)
		(*Sqlite3_backup)(unsafe.Pointer(p)).FisAttached = 0

		if uintptr(0) == (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc || uintptr(0) == (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest ||
			checkReadTransaction(tls, pDestDb, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest) != SQLITE_OK {
			Xsqlite3_free(tls, p)
			p = uintptr(0)
		}
	}
	if p != 0 {
		(*Btree)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup++
	}

	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(pDestDb)).Fmutex)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	return p
}

func isFatalError(tls *libc.TLS, rc int32) int32 {
	return libc.Bool32(rc != SQLITE_OK && rc != SQLITE_BUSY && rc != SQLITE_LOCKED)
}

func backupOnePage(tls *libc.TLS, p uintptr, iSrcPg Pgno, zSrcData uintptr, bUpdate int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pDestPager uintptr = Xsqlite3BtreePager(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest)
	var nSrcPgsz int32 = Xsqlite3BtreeGetPageSize(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	var nDestPgsz int32 = Xsqlite3BtreeGetPageSize(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest)
	var nCopy int32 = func() int32 {
		if nSrcPgsz < nDestPgsz {
			return nSrcPgsz
		}
		return nDestPgsz
	}()
	var iEnd I64 = I64(iSrcPg) * I64(nSrcPgsz)
	var rc int32 = SQLITE_OK
	var iOff I64

	if nSrcPgsz != nDestPgsz && Xsqlite3PagerIsMemdb(tls, pDestPager) != 0 {
		rc = SQLITE_READONLY
	}

	for iOff = iEnd - I64(nSrcPgsz); rc == SQLITE_OK && iOff < iEnd; iOff = iOff + I64(nDestPgsz) {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		var iDest Pgno = Pgno(iOff/I64(nDestPgsz)) + Pgno(1)
		if iDest == U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpDest)).FpBt)).FpageSize+U32(1) {
			continue
		}
		if SQLITE_OK == libc.AssignInt32(&rc, Xsqlite3PagerGet(tls, pDestPager, iDest, bp, 0)) &&
			SQLITE_OK == libc.AssignInt32(&rc, Xsqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp)))) {
			var zIn uintptr = zSrcData + uintptr(iOff%I64(nSrcPgsz))
			var zDestData uintptr = Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))
			var zOut uintptr = zDestData + uintptr(iOff%I64(nDestPgsz))

			libc.Xmemcpy(tls, zOut, zIn, uint64(nCopy))
			*(*U8)(unsafe.Pointer(Xsqlite3PagerGetExtra(tls, *(*uintptr)(unsafe.Pointer(bp))))) = U8(0)
			if iOff == int64(0) && bUpdate == 0 {
				Xsqlite3Put4byte(tls, zOut+28, Xsqlite3BtreeLastPage(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc))
			}
		}
		Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}

	return rc
}

func backupTruncateFile(tls *libc.TLS, pFile uintptr, iSize I64) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = Xsqlite3OsFileSize(tls, pFile, bp)
	if rc == SQLITE_OK && *(*I64)(unsafe.Pointer(bp)) > iSize {
		rc = Xsqlite3OsTruncate(tls, pFile, iSize)
	}
	return rc
}

func attachBackupObject(tls *libc.TLS, p uintptr) {
	var pp uintptr

	pp = Xsqlite3PagerBackupPtr(tls, Xsqlite3BtreePager(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc))
	(*Sqlite3_backup)(unsafe.Pointer(p)).FpNext = *(*uintptr)(unsafe.Pointer(pp))
	*(*uintptr)(unsafe.Pointer(pp)) = p
	(*Sqlite3_backup)(unsafe.Pointer(p)).FisAttached = 1
}

func Xsqlite3_backup_step(tls *libc.TLS, p uintptr, nPage int32) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var rc int32
	var destMode int32
	var pgszSrc int32 = 0
	var pgszDest int32 = 0

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpSrcDb)).Fmutex)
	Xsqlite3BtreeEnter(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	if (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
	}

	rc = (*Sqlite3_backup)(unsafe.Pointer(p)).Frc
	if !(isFatalError(tls, rc) != 0) {
		var pSrcPager uintptr = Xsqlite3BtreePager(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)
		var pDestPager uintptr = Xsqlite3BtreePager(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest)
		var ii int32
		var nSrcPage int32 = -1
		var bCloseTrans int32 = 0

		if (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 && int32((*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FpBt)).FinTransaction) == TRANS_WRITE {
			rc = SQLITE_BUSY
		} else {
			rc = SQLITE_OK
		}

		if rc == SQLITE_OK && SQLITE_TXN_NONE == Xsqlite3BtreeTxnState(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc) {
			rc = Xsqlite3BtreeBeginTrans(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc, 0, uintptr(0))
			bCloseTrans = 1
		}

		if (*Sqlite3_backup)(unsafe.Pointer(p)).FbDestLocked == 0 && rc == SQLITE_OK && setDestPgsz(tls, p) == SQLITE_NOMEM {
			rc = SQLITE_NOMEM
		}

		if SQLITE_OK == rc && (*Sqlite3_backup)(unsafe.Pointer(p)).FbDestLocked == 0 &&
			SQLITE_OK == libc.AssignInt32(&rc, Xsqlite3BtreeBeginTrans(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest, 2,
				p+16)) {
			(*Sqlite3_backup)(unsafe.Pointer(p)).FbDestLocked = 1
		}

		pgszSrc = Xsqlite3BtreeGetPageSize(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)
		pgszDest = Xsqlite3BtreeGetPageSize(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest)
		destMode = Xsqlite3PagerGetJournalMode(tls, Xsqlite3BtreePager(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest))
		if SQLITE_OK == rc && destMode == PAGER_JOURNALMODE_WAL && pgszSrc != pgszDest {
			rc = SQLITE_READONLY
		}

		nSrcPage = int32(Xsqlite3BtreeLastPage(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc))

		for ii = 0; (nPage < 0 || ii < nPage) && (*Sqlite3_backup)(unsafe.Pointer(p)).FiNext <= Pgno(nSrcPage) && !(rc != 0); ii++ {
			var iSrcPg Pgno = (*Sqlite3_backup)(unsafe.Pointer(p)).FiNext
			if iSrcPg != U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FpBt)).FpageSize+U32(1) {
				rc = Xsqlite3PagerGet(tls, pSrcPager, iSrcPg, bp, PAGER_GET_READONLY)
				if rc == SQLITE_OK {
					rc = backupOnePage(tls, p, iSrcPg, Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp))), 0)
					Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
				}
			}
			(*Sqlite3_backup)(unsafe.Pointer(p)).FiNext++
		}
		if rc == SQLITE_OK {
			(*Sqlite3_backup)(unsafe.Pointer(p)).FnPagecount = Pgno(nSrcPage)
			(*Sqlite3_backup)(unsafe.Pointer(p)).FnRemaining = Pgno(nSrcPage+1) - (*Sqlite3_backup)(unsafe.Pointer(p)).FiNext
			if (*Sqlite3_backup)(unsafe.Pointer(p)).FiNext > Pgno(nSrcPage) {
				rc = SQLITE_DONE
			} else if !((*Sqlite3_backup)(unsafe.Pointer(p)).FisAttached != 0) {
				attachBackupObject(tls, p)
			}
		}

		if rc == SQLITE_DONE {
			if nSrcPage == 0 {
				rc = Xsqlite3BtreeNewDb(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest)
				nSrcPage = 1
			}
			if rc == SQLITE_OK || rc == SQLITE_DONE {
				rc = Xsqlite3BtreeUpdateMeta(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest, 1, (*Sqlite3_backup)(unsafe.Pointer(p)).FiDestSchema+U32(1))
			}
			if rc == SQLITE_OK {
				if (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
					Xsqlite3ResetAllSchemasOfConnection(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb)
				}
				if destMode == PAGER_JOURNALMODE_WAL {
					rc = Xsqlite3BtreeSetVersion(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest, 2)
				}
			}
			if rc == SQLITE_OK {
				var nDestTruncate int32

				if pgszSrc < pgszDest {
					var ratio int32 = pgszDest / pgszSrc
					nDestTruncate = (nSrcPage + ratio - 1) / ratio
					if nDestTruncate == int32(U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpDest)).FpBt)).FpageSize+U32(1)) {
						nDestTruncate--
					}
				} else {
					nDestTruncate = nSrcPage * (pgszSrc / pgszDest)
				}

				if pgszSrc < pgszDest {
					var iSize I64 = I64(pgszSrc) * I64(nSrcPage)
					var pFile uintptr = Xsqlite3PagerFile(tls, pDestPager)
					var iPg Pgno

					var iOff I64
					var iEnd I64

					Xsqlite3PagerPagecount(tls, pDestPager, bp+8)
					for iPg = Pgno(nDestTruncate); rc == SQLITE_OK && iPg <= Pgno(*(*int32)(unsafe.Pointer(bp + 8))); iPg++ {
						if iPg != U32(Xsqlite3PendingByte)/(*BtShared)(unsafe.Pointer((*Btree)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpDest)).FpBt)).FpageSize+U32(1) {
							rc = Xsqlite3PagerGet(tls, pDestPager, iPg, bp+16, 0)
							if rc == SQLITE_OK {
								rc = Xsqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
								Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
							}
						}
					}
					if rc == SQLITE_OK {
						rc = Xsqlite3PagerCommitPhaseOne(tls, pDestPager, uintptr(0), 1)
					}

					iEnd = func() int64 {
						if I64(Xsqlite3PendingByte+pgszDest) < iSize {
							return int64(Xsqlite3PendingByte + pgszDest)
						}
						return iSize
					}()
					for iOff = I64(Xsqlite3PendingByte + pgszSrc); rc == SQLITE_OK && iOff < iEnd; iOff = iOff + I64(pgszSrc) {
						*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
						var iSrcPg Pgno = Pgno(iOff/I64(pgszSrc) + int64(1))
						rc = Xsqlite3PagerGet(tls, pSrcPager, iSrcPg, bp+24, 0)
						if rc == SQLITE_OK {
							var zData uintptr = Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
							rc = Xsqlite3OsWrite(tls, pFile, zData, pgszSrc, iOff)
						}
						Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
					}
					if rc == SQLITE_OK {
						rc = backupTruncateFile(tls, pFile, iSize)
					}

					if rc == SQLITE_OK {
						rc = Xsqlite3PagerSync(tls, pDestPager, uintptr(0))
					}
				} else {
					Xsqlite3PagerTruncateImage(tls, pDestPager, uint32(nDestTruncate))
					rc = Xsqlite3PagerCommitPhaseOne(tls, pDestPager, uintptr(0), 0)
				}

				if SQLITE_OK == rc &&
					SQLITE_OK == libc.AssignInt32(&rc, Xsqlite3BtreeCommitPhaseTwo(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest, 0)) {
					rc = SQLITE_DONE
				}
			}
		}

		if bCloseTrans != 0 {
			Xsqlite3BtreeCommitPhaseOne(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc, uintptr(0))
			Xsqlite3BtreeCommitPhaseTwo(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc, 0)

		}

		if rc == SQLITE_IOERR|int32(12)<<8 {
			rc = SQLITE_NOMEM
		}
		(*Sqlite3_backup)(unsafe.Pointer(p)).Frc = rc
	}
	if (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
	}
	Xsqlite3BtreeLeave(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpSrcDb)).Fmutex)
	return rc
}

func Xsqlite3_backup_finish(tls *libc.TLS, p uintptr) int32 {
	var pp uintptr
	var pSrcDb uintptr
	var rc int32

	if p == uintptr(0) {
		return SQLITE_OK
	}
	pSrcDb = (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrcDb
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	Xsqlite3BtreeEnter(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	if (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
	}

	if (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		(*Btree)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup--
	}
	if (*Sqlite3_backup)(unsafe.Pointer(p)).FisAttached != 0 {
		pp = Xsqlite3PagerBackupPtr(tls, Xsqlite3BtreePager(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc))

		for *(*uintptr)(unsafe.Pointer(pp)) != p {
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 64

		}
		*(*uintptr)(unsafe.Pointer(pp)) = (*Sqlite3_backup)(unsafe.Pointer(p)).FpNext
	}

	Xsqlite3BtreeRollback(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDest, SQLITE_OK, 0)

	if (*Sqlite3_backup)(unsafe.Pointer(p)).Frc == SQLITE_DONE {
		rc = SQLITE_OK
	} else {
		rc = (*Sqlite3_backup)(unsafe.Pointer(p)).Frc
	}
	if (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3Error(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb, rc)

		Xsqlite3LeaveMutexAndCloseZombie(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb)
	}
	Xsqlite3BtreeLeave(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	if (*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3_free(tls, p)
	}
	Xsqlite3LeaveMutexAndCloseZombie(tls, pSrcDb)
	return rc
}

func Xsqlite3_backup_remaining(tls *libc.TLS, p uintptr) int32 {
	return int32((*Sqlite3_backup)(unsafe.Pointer(p)).FnRemaining)
}

func Xsqlite3_backup_pagecount(tls *libc.TLS, p uintptr) int32 {
	return int32((*Sqlite3_backup)(unsafe.Pointer(p)).FnPagecount)
}

func backupUpdate(tls *libc.TLS, p uintptr, iPage Pgno, aData uintptr) {
	for __ccgo := true; __ccgo; __ccgo = libc.AssignUintptr(&p, (*Sqlite3_backup)(unsafe.Pointer(p)).FpNext) != uintptr(0) {
		if !(isFatalError(tls, (*Sqlite3_backup)(unsafe.Pointer(p)).Frc) != 0) && iPage < (*Sqlite3_backup)(unsafe.Pointer(p)).FiNext {
			var rc int32

			Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
			rc = backupOnePage(tls, p, iPage, aData, 1)
			Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Sqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)

			if rc != SQLITE_OK {
				(*Sqlite3_backup)(unsafe.Pointer(p)).Frc = rc
			}
		}
	}
}

func Xsqlite3BackupUpdate(tls *libc.TLS, pBackup uintptr, iPage Pgno, aData uintptr) {
	if pBackup != 0 {
		backupUpdate(tls, pBackup, iPage, aData)
	}
}

func Xsqlite3BackupRestart(tls *libc.TLS, pBackup uintptr) {
	var p uintptr
	for p = pBackup; p != 0; p = (*Sqlite3_backup)(unsafe.Pointer(p)).FpNext {
		(*Sqlite3_backup)(unsafe.Pointer(p)).FiNext = Pgno(1)
	}
}

func Xsqlite3BtreeCopyFile(tls *libc.TLS, pTo uintptr, pFrom uintptr) int32 {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var rc int32
	var pFd uintptr

	Xsqlite3BtreeEnter(tls, pTo)
	Xsqlite3BtreeEnter(tls, pFrom)

	pFd = Xsqlite3PagerFile(tls, Xsqlite3BtreePager(tls, pTo))
	if !((*Sqlite3_file)(unsafe.Pointer(pFd)).FpMethods != 0) {
		goto __1
	}
	*(*I64)(unsafe.Pointer(bp)) = I64(Xsqlite3BtreeGetPageSize(tls, pFrom)) * I64(Xsqlite3BtreeLastPage(tls, pFrom))
	rc = Xsqlite3OsFileControl(tls, pFd, SQLITE_FCNTL_OVERWRITE, bp)
	if !(rc == SQLITE_NOTFOUND) {
		goto __2
	}
	rc = SQLITE_OK
__2:
	;
	if !(rc != 0) {
		goto __3
	}
	goto copy_finished
__3:
	;
__1:
	;
	libc.Xmemset(tls, bp+8, 0, uint64(unsafe.Sizeof(Sqlite3_backup{})))
	(*Sqlite3_backup)(unsafe.Pointer(bp + 8)).FpSrcDb = (*Btree)(unsafe.Pointer(pFrom)).Fdb
	(*Sqlite3_backup)(unsafe.Pointer(bp + 8)).FpSrc = pFrom
	(*Sqlite3_backup)(unsafe.Pointer(bp + 8)).FpDest = pTo
	(*Sqlite3_backup)(unsafe.Pointer(bp + 8)).FiNext = Pgno(1)

	Xsqlite3_backup_step(tls, bp+8, 0x7FFFFFFF)

	rc = Xsqlite3_backup_finish(tls, bp+8)
	if !(rc == SQLITE_OK) {
		goto __4
	}
	*(*U16)(unsafe.Pointer((*Btree)(unsafe.Pointer(pTo)).FpBt + 40)) &= libc.Uint16FromInt32(libc.CplInt32(BTS_PAGESIZE_FIXED))
	goto __5
__4:
	Xsqlite3PagerClearCache(tls, Xsqlite3BtreePager(tls, (*Sqlite3_backup)(unsafe.Pointer(bp+8)).FpDest))
__5:
	;
copy_finished:
	Xsqlite3BtreeLeave(tls, pFrom)
	Xsqlite3BtreeLeave(tls, pTo)
	return rc
}

func vdbeMemRenderNum(tls *libc.TLS, sz int32, zBuf uintptr, p uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Int != 0 {
		libc.Xmemcpy(tls, bp+8, p, uint64(int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Int*2))
		(*Mem)(unsafe.Pointer(p)).Fn = Xsqlite3Int64ToText(tls, *(*I64)(unsafe.Pointer(bp + 8)), zBuf)
	} else {
		Xsqlite3StrAccumInit(tls, bp+16, uintptr(0), zBuf, sz, 0)
		Xsqlite3_str_appendf(tls, bp+16, ts+7805,
			libc.VaList(bp, func() float64 {
				if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_IntReal != 0 {
					return float64(*(*I64)(unsafe.Pointer(p)))
				}
				return *(*float64)(unsafe.Pointer(p))
			}()))

		*(*uint8)(unsafe.Pointer(zBuf + uintptr((*StrAccum)(unsafe.Pointer(bp+16)).FnChar))) = uint8(0)
		(*Mem)(unsafe.Pointer(p)).Fn = int32((*StrAccum)(unsafe.Pointer(bp + 16)).FnChar)
	}
}

func Xsqlite3VdbeChangeEncoding(tls *libc.TLS, pMem uintptr, desiredEnc int32) int32 {
	var rc int32

	if !(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Str != 0) {
		(*Mem)(unsafe.Pointer(pMem)).Fenc = U8(desiredEnc)
		return SQLITE_OK
	}
	if int32((*Mem)(unsafe.Pointer(pMem)).Fenc) == desiredEnc {
		return SQLITE_OK
	}

	rc = Xsqlite3VdbeMemTranslate(tls, pMem, U8(desiredEnc))

	return rc
}

func Xsqlite3VdbeMemGrow(tls *libc.TLS, pMem uintptr, n int32, bPreserve int32) int32 {
	if (*Mem)(unsafe.Pointer(pMem)).FszMalloc > 0 && bPreserve != 0 && (*Mem)(unsafe.Pointer(pMem)).Fz == (*Mem)(unsafe.Pointer(pMem)).FzMalloc {
		if (*Mem)(unsafe.Pointer(pMem)).Fdb != 0 {
			(*Mem)(unsafe.Pointer(pMem)).Fz = libc.AssignPtrUintptr(pMem+40, Xsqlite3DbReallocOrFree(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, (*Mem)(unsafe.Pointer(pMem)).Fz, uint64(n)))
		} else {
			(*Mem)(unsafe.Pointer(pMem)).FzMalloc = Xsqlite3Realloc(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, uint64(n))
			if (*Mem)(unsafe.Pointer(pMem)).FzMalloc == uintptr(0) {
				Xsqlite3_free(tls, (*Mem)(unsafe.Pointer(pMem)).Fz)
			}
			(*Mem)(unsafe.Pointer(pMem)).Fz = (*Mem)(unsafe.Pointer(pMem)).FzMalloc
		}
		bPreserve = 0
	} else {
		if (*Mem)(unsafe.Pointer(pMem)).FszMalloc > 0 {
			Xsqlite3DbFreeNN(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, (*Mem)(unsafe.Pointer(pMem)).FzMalloc)
		}
		(*Mem)(unsafe.Pointer(pMem)).FzMalloc = Xsqlite3DbMallocRaw(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, uint64(n))
	}
	if (*Mem)(unsafe.Pointer(pMem)).FzMalloc == uintptr(0) {
		Xsqlite3VdbeMemSetNull(tls, pMem)
		(*Mem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
		(*Mem)(unsafe.Pointer(pMem)).FszMalloc = 0
		return SQLITE_NOMEM
	} else {
		(*Mem)(unsafe.Pointer(pMem)).FszMalloc = Xsqlite3DbMallocSize(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, (*Mem)(unsafe.Pointer(pMem)).FzMalloc)
	}

	if bPreserve != 0 && (*Mem)(unsafe.Pointer(pMem)).Fz != 0 {
		libc.Xmemcpy(tls, (*Mem)(unsafe.Pointer(pMem)).FzMalloc, (*Mem)(unsafe.Pointer(pMem)).Fz, uint64((*Mem)(unsafe.Pointer(pMem)).Fn))
	}
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Dyn != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Mem)(unsafe.Pointer(pMem)).FxDel})).f(tls, (*Mem)(unsafe.Pointer(pMem)).Fz)
	}

	(*Mem)(unsafe.Pointer(pMem)).Fz = (*Mem)(unsafe.Pointer(pMem)).FzMalloc
	*(*U16)(unsafe.Pointer(pMem + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Dyn | MEM_Ephem | MEM_Static))
	return SQLITE_OK
}

func Xsqlite3VdbeMemClearAndResize(tls *libc.TLS, pMem uintptr, szNew int32) int32 {
	if (*Mem)(unsafe.Pointer(pMem)).FszMalloc < szNew {
		return Xsqlite3VdbeMemGrow(tls, pMem, szNew, 0)
	}

	(*Mem)(unsafe.Pointer(pMem)).Fz = (*Mem)(unsafe.Pointer(pMem)).FzMalloc
	*(*U16)(unsafe.Pointer(pMem + 20)) &= U16(MEM_Null | MEM_Int | MEM_Real | MEM_IntReal)
	return SQLITE_OK
}

func vdbeMemAddTerminator(tls *libc.TLS, pMem uintptr) int32 {
	if Xsqlite3VdbeMemGrow(tls, pMem, (*Mem)(unsafe.Pointer(pMem)).Fn+3, 1) != 0 {
		return SQLITE_NOMEM
	}
	*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fz + uintptr((*Mem)(unsafe.Pointer(pMem)).Fn))) = uint8(0)
	*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fz + uintptr((*Mem)(unsafe.Pointer(pMem)).Fn+1))) = uint8(0)
	*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fz + uintptr((*Mem)(unsafe.Pointer(pMem)).Fn+2))) = uint8(0)
	*(*U16)(unsafe.Pointer(pMem + 20)) |= U16(MEM_Term)
	return SQLITE_OK
}

func Xsqlite3VdbeMemMakeWriteable(tls *libc.TLS, pMem uintptr) int32 {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Str|MEM_Blob) != 0 {
		if func() int32 {
			if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Zero != 0 {
				return Xsqlite3VdbeMemExpandBlob(tls, pMem)
			}
			return 0
		}() != 0 {
			return SQLITE_NOMEM
		}
		if (*Mem)(unsafe.Pointer(pMem)).FszMalloc == 0 || (*Mem)(unsafe.Pointer(pMem)).Fz != (*Mem)(unsafe.Pointer(pMem)).FzMalloc {
			var rc int32 = vdbeMemAddTerminator(tls, pMem)
			if rc != 0 {
				return rc
			}
		}
	}
	*(*U16)(unsafe.Pointer(pMem + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Ephem))

	return SQLITE_OK
}

func Xsqlite3VdbeMemExpandBlob(tls *libc.TLS, pMem uintptr) int32 {
	var nByte int32

	nByte = (*Mem)(unsafe.Pointer(pMem)).Fn + *(*int32)(unsafe.Pointer(pMem))
	if nByte <= 0 {
		if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Blob == 0 {
			return SQLITE_OK
		}
		nByte = 1
	}
	if Xsqlite3VdbeMemGrow(tls, pMem, nByte, 1) != 0 {
		return SQLITE_NOMEM
	}

	libc.Xmemset(tls, (*Mem)(unsafe.Pointer(pMem)).Fz+uintptr((*Mem)(unsafe.Pointer(pMem)).Fn), 0, uint64(*(*int32)(unsafe.Pointer(pMem))))
	*(*int32)(unsafe.Pointer(pMem + 16)) += *(*int32)(unsafe.Pointer(pMem))
	*(*U16)(unsafe.Pointer(pMem + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Zero | MEM_Term))
	return SQLITE_OK
}

func Xsqlite3VdbeMemNulTerminate(tls *libc.TLS, pMem uintptr) int32 {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Term|MEM_Str) != MEM_Str {
		return SQLITE_OK
	} else {
		return vdbeMemAddTerminator(tls, pMem)
	}
	return int32(0)
}

func Xsqlite3VdbeMemStringify(tls *libc.TLS, pMem uintptr, enc U8, bForce U8) int32 {
	var nByte int32 = 32

	if Xsqlite3VdbeMemClearAndResize(tls, pMem, nByte) != 0 {
		(*Mem)(unsafe.Pointer(pMem)).Fenc = U8(0)
		return SQLITE_NOMEM
	}

	vdbeMemRenderNum(tls, nByte, (*Mem)(unsafe.Pointer(pMem)).Fz, pMem)

	(*Mem)(unsafe.Pointer(pMem)).Fenc = U8(SQLITE_UTF8)
	*(*U16)(unsafe.Pointer(pMem + 20)) |= U16(MEM_Str | MEM_Term)
	if bForce != 0 {
		*(*U16)(unsafe.Pointer(pMem + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Int | MEM_Real | MEM_IntReal))
	}
	Xsqlite3VdbeChangeEncoding(tls, pMem, int32(enc))
	return SQLITE_OK
}

func Xsqlite3VdbeMemFinalize(tls *libc.TLS, pMem uintptr, pFunc uintptr) int32 {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Sqlite3_context{})))
	libc.Xmemset(tls, bp+56, 0, uint64(unsafe.Sizeof(Mem{})))
	(*Mem)(unsafe.Pointer(bp + 56)).Fflags = U16(MEM_Null)
	(*Mem)(unsafe.Pointer(bp + 56)).Fdb = (*Mem)(unsafe.Pointer(pMem)).Fdb
	(*Sqlite3_context)(unsafe.Pointer(bp)).FpOut = bp + 56
	(*Sqlite3_context)(unsafe.Pointer(bp)).FpMem = pMem
	(*Sqlite3_context)(unsafe.Pointer(bp)).FpFunc = pFunc
	(*Sqlite3_context)(unsafe.Pointer(bp)).Fenc = (*Sqlite3)(unsafe.Pointer((*Mem)(unsafe.Pointer(bp + 56)).Fdb)).Fenc
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*FuncDef)(unsafe.Pointer(pFunc)).FxFinalize})).f(tls, bp)

	if (*Mem)(unsafe.Pointer(pMem)).FszMalloc > 0 {
		Xsqlite3DbFreeNN(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, (*Mem)(unsafe.Pointer(pMem)).FzMalloc)
	}
	libc.Xmemcpy(tls, pMem, bp+56, uint64(unsafe.Sizeof(Mem{})))
	return (*Sqlite3_context)(unsafe.Pointer(bp)).FisError
}

func Xsqlite3VdbeMemAggValue(tls *libc.TLS, pAccum uintptr, pOut uintptr, pFunc uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Sqlite3_context{})))
	Xsqlite3VdbeMemSetNull(tls, pOut)
	(*Sqlite3_context)(unsafe.Pointer(bp)).FpOut = pOut
	(*Sqlite3_context)(unsafe.Pointer(bp)).FpMem = pAccum
	(*Sqlite3_context)(unsafe.Pointer(bp)).FpFunc = pFunc
	(*Sqlite3_context)(unsafe.Pointer(bp)).Fenc = (*Sqlite3)(unsafe.Pointer((*Mem)(unsafe.Pointer(pAccum)).Fdb)).Fenc
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*FuncDef)(unsafe.Pointer(pFunc)).FxValue})).f(tls, bp)
	return (*Sqlite3_context)(unsafe.Pointer(bp)).FisError
}

func vdbeMemClearExternAndSetNull(tls *libc.TLS, p uintptr) {
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Agg != 0 {
		Xsqlite3VdbeMemFinalize(tls, p, *(*uintptr)(unsafe.Pointer(p)))

	}
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Dyn != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Mem)(unsafe.Pointer(p)).FxDel})).f(tls, (*Mem)(unsafe.Pointer(p)).Fz)
	}
	(*Mem)(unsafe.Pointer(p)).Fflags = U16(MEM_Null)
}

func vdbeMemClear(tls *libc.TLS, p uintptr) {
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_Agg|MEM_Dyn) != 0 {
		vdbeMemClearExternAndSetNull(tls, p)
	}
	if (*Mem)(unsafe.Pointer(p)).FszMalloc != 0 {
		Xsqlite3DbFreeNN(tls, (*Mem)(unsafe.Pointer(p)).Fdb, (*Mem)(unsafe.Pointer(p)).FzMalloc)
		(*Mem)(unsafe.Pointer(p)).FszMalloc = 0
	}
	(*Mem)(unsafe.Pointer(p)).Fz = uintptr(0)
}

func Xsqlite3VdbeMemRelease(tls *libc.TLS, p uintptr) {
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_Agg|MEM_Dyn) != 0 || (*Mem)(unsafe.Pointer(p)).FszMalloc != 0 {
		vdbeMemClear(tls, p)
	}
}

func Xsqlite3VdbeMemReleaseMalloc(tls *libc.TLS, p uintptr) {
	if (*Mem)(unsafe.Pointer(p)).FszMalloc != 0 {
		vdbeMemClear(tls, p)
	}
}

func doubleToInt64(tls *libc.TLS, r float64) I64 {
	if r <= float64(minInt) {
		return minInt
	} else if r >= float64(maxInt) {
		return maxInt
	} else {
		return I64(r)
	}
	return I64(0)
}

var maxInt I64 = int64(0xffffffff) | int64(0x7fffffff)<<32
var minInt I64 = int64(-1) - (int64(0xffffffff) | int64(0x7fffffff)<<32)

func memIntValue(tls *libc.TLS, pMem uintptr) I64 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*I64)(unsafe.Pointer(bp)) = int64(0)
	Xsqlite3Atoi64(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, bp, (*Mem)(unsafe.Pointer(pMem)).Fn, (*Mem)(unsafe.Pointer(pMem)).Fenc)
	return *(*I64)(unsafe.Pointer(bp))
}

func Xsqlite3VdbeIntValue(tls *libc.TLS, pMem uintptr) I64 {
	var flags int32

	flags = int32((*Mem)(unsafe.Pointer(pMem)).Fflags)
	if flags&(MEM_Int|MEM_IntReal) != 0 {
		return *(*I64)(unsafe.Pointer(pMem))
	} else if flags&MEM_Real != 0 {
		return doubleToInt64(tls, *(*float64)(unsafe.Pointer(pMem)))
	} else if flags&(MEM_Str|MEM_Blob) != 0 && (*Mem)(unsafe.Pointer(pMem)).Fz != uintptr(0) {
		return memIntValue(tls, pMem)
	} else {
		return int64(0)
	}
	return I64(0)
}

func memRealValue(tls *libc.TLS, pMem uintptr) float64 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*float64)(unsafe.Pointer(bp)) = float64(0)
	Xsqlite3AtoF(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, bp, (*Mem)(unsafe.Pointer(pMem)).Fn, (*Mem)(unsafe.Pointer(pMem)).Fenc)
	return *(*float64)(unsafe.Pointer(bp))
}

func Xsqlite3VdbeRealValue(tls *libc.TLS, pMem uintptr) float64 {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Real != 0 {
		return *(*float64)(unsafe.Pointer(pMem))
	} else if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Int|MEM_IntReal) != 0 {
		return float64(*(*I64)(unsafe.Pointer(pMem)))
	} else if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Str|MEM_Blob) != 0 {
		return memRealValue(tls, pMem)
	} else {
		return float64(0)
	}
	return float64(0)
}

func Xsqlite3VdbeBooleanValue(tls *libc.TLS, pMem uintptr, ifNull int32) int32 {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Int|MEM_IntReal) != 0 {
		return libc.Bool32(*(*I64)(unsafe.Pointer(pMem)) != int64(0))
	}
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Null != 0 {
		return ifNull
	}
	return libc.Bool32(Xsqlite3VdbeRealValue(tls, pMem) != 0.0)
}

func Xsqlite3VdbeIntegerAffinity(tls *libc.TLS, pMem uintptr) {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_IntReal != 0 {
		(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Int)
	} else {
		var ix I64 = doubleToInt64(tls, *(*float64)(unsafe.Pointer(pMem)))

		if *(*float64)(unsafe.Pointer(pMem)) == float64(ix) && ix > int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32) && ix < int64(0xffffffff)|int64(0x7fffffff)<<32 {
			*(*I64)(unsafe.Pointer(pMem)) = ix
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Int)
		}
	}
}

func Xsqlite3VdbeMemIntegerify(tls *libc.TLS, pMem uintptr) int32 {
	*(*I64)(unsafe.Pointer(pMem)) = Xsqlite3VdbeIntValue(tls, pMem)
	(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Int)
	return SQLITE_OK
}

func Xsqlite3VdbeMemRealify(tls *libc.TLS, pMem uintptr) int32 {
	*(*float64)(unsafe.Pointer(pMem)) = Xsqlite3VdbeRealValue(tls, pMem)
	(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Real)
	return SQLITE_OK
}

func Xsqlite3RealSameAsInt(tls *libc.TLS, r1 float64, i Sqlite3_int64) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp)) = r1

	*(*float64)(unsafe.Pointer(bp + 8)) = float64(i)
	return libc.Bool32(*(*float64)(unsafe.Pointer(bp)) == 0.0 ||
		libc.Xmemcmp(tls, bp, bp+8, uint64(unsafe.Sizeof(float64(0)))) == 0 &&
			i >= -2251799813685248 && i < 2251799813685248)
}

func Xsqlite3RealToI64(tls *libc.TLS, r float64) I64 {
	if r <= float64(int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32)) {
		return int64(-1) - (int64(0xffffffff) | int64(0x7fffffff)<<32)
	}
	if r >= float64(int64(0xffffffff)|int64(0x7fffffff)<<32) {
		return int64(0xffffffff) | int64(0x7fffffff)<<32
	}
	return I64(r)
}

func Xsqlite3VdbeMemNumerify(tls *libc.TLS, pMem uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Int|MEM_Real|MEM_IntReal|MEM_Null) == 0 {
		var rc int32

		rc = Xsqlite3AtoF(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, pMem, (*Mem)(unsafe.Pointer(pMem)).Fn, (*Mem)(unsafe.Pointer(pMem)).Fenc)
		if (rc == 0 || rc == 1) && Xsqlite3Atoi64(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, bp, (*Mem)(unsafe.Pointer(pMem)).Fn, (*Mem)(unsafe.Pointer(pMem)).Fenc) <= 1 ||
			Xsqlite3RealSameAsInt(tls, *(*float64)(unsafe.Pointer(pMem)), libc.AssignPtrInt64(bp, Xsqlite3RealToI64(tls, *(*float64)(unsafe.Pointer(pMem))))) != 0 {
			*(*I64)(unsafe.Pointer(pMem)) = *(*Sqlite3_int64)(unsafe.Pointer(bp))
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Int)
		} else {
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Real)
		}
	}

	*(*U16)(unsafe.Pointer(pMem + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Str | MEM_Blob | MEM_Zero))
	return SQLITE_OK
}

func Xsqlite3VdbeMemCast(tls *libc.TLS, pMem uintptr, aff U8, encoding U8) int32 {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Null != 0 {
		return SQLITE_OK
	}
	switch int32(aff) {
	case SQLITE_AFF_BLOB:
		{
			if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Blob == 0 {
				Xsqlite3ValueApplyAffinity(tls, pMem, uint8(SQLITE_AFF_TEXT), encoding)

				if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Str != 0 {
					(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Blob)
				}
			} else {
				*(*U16)(unsafe.Pointer(pMem + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_TypeMask & libc.CplInt32(MEM_Blob)))
			}
			break

		}
	case SQLITE_AFF_NUMERIC:
		{
			Xsqlite3VdbeMemNumerify(tls, pMem)
			break

		}
	case SQLITE_AFF_INTEGER:
		{
			Xsqlite3VdbeMemIntegerify(tls, pMem)
			break

		}
	case SQLITE_AFF_REAL:
		{
			Xsqlite3VdbeMemRealify(tls, pMem)
			break

		}
	default:
		{
			*(*U16)(unsafe.Pointer(pMem + 20)) |= U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags) & MEM_Blob >> 3)
			Xsqlite3ValueApplyAffinity(tls, pMem, uint8(SQLITE_AFF_TEXT), encoding)

			*(*U16)(unsafe.Pointer(pMem + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Int | MEM_Real | MEM_IntReal | MEM_Blob | MEM_Zero))
			if int32(encoding) != SQLITE_UTF8 {
				*(*int32)(unsafe.Pointer(pMem + 16)) &= libc.CplInt32(1)
			}
			return Xsqlite3VdbeChangeEncoding(tls, pMem, int32(encoding))

		}
	}
	return SQLITE_OK
}

func Xsqlite3VdbeMemInit(tls *libc.TLS, pMem uintptr, db uintptr, flags U16) {
	(*Mem)(unsafe.Pointer(pMem)).Fflags = flags
	(*Mem)(unsafe.Pointer(pMem)).Fdb = db
	(*Mem)(unsafe.Pointer(pMem)).FszMalloc = 0
}

func Xsqlite3VdbeMemSetNull(tls *libc.TLS, pMem uintptr) {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Agg|MEM_Dyn) != 0 {
		vdbeMemClearExternAndSetNull(tls, pMem)
	} else {
		(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Null)
	}
}

func Xsqlite3ValueSetNull(tls *libc.TLS, p uintptr) {
	Xsqlite3VdbeMemSetNull(tls, p)
}

func Xsqlite3VdbeMemSetZeroBlob(tls *libc.TLS, pMem uintptr, n int32) {
	Xsqlite3VdbeMemRelease(tls, pMem)
	(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Blob | MEM_Zero)
	(*Mem)(unsafe.Pointer(pMem)).Fn = 0
	if n < 0 {
		n = 0
	}
	*(*int32)(unsafe.Pointer(pMem)) = n
	(*Mem)(unsafe.Pointer(pMem)).Fenc = U8(SQLITE_UTF8)
	(*Mem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
}

func vdbeReleaseAndSetInt64(tls *libc.TLS, pMem uintptr, val I64) {
	Xsqlite3VdbeMemSetNull(tls, pMem)
	*(*I64)(unsafe.Pointer(pMem)) = val
	(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)
}

func Xsqlite3VdbeMemSetInt64(tls *libc.TLS, pMem uintptr, val I64) {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Agg|MEM_Dyn) != 0 {
		vdbeReleaseAndSetInt64(tls, pMem, val)
	} else {
		*(*I64)(unsafe.Pointer(pMem)) = val
		(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)
	}
}

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

func Xsqlite3VdbeMemSetPointer(tls *libc.TLS, pMem uintptr, pPtr uintptr, zPType uintptr, xDestructor uintptr) {
	vdbeMemClear(tls, pMem)
	*(*uintptr)(unsafe.Pointer(pMem)) = func() uintptr {
		if zPType != 0 {
			return zPType
		}
		return ts + 1636
	}()
	(*Mem)(unsafe.Pointer(pMem)).Fz = pPtr
	(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Null | MEM_Dyn | MEM_Subtype | MEM_Term)
	(*Mem)(unsafe.Pointer(pMem)).FeSubtype = U8('p')
	(*Mem)(unsafe.Pointer(pMem)).FxDel = func() uintptr {
		if xDestructor != 0 {
			return xDestructor
		}
		return *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3NoopDestructor}))
	}()
}

func Xsqlite3VdbeMemSetDouble(tls *libc.TLS, pMem uintptr, val float64) {
	Xsqlite3VdbeMemSetNull(tls, pMem)
	if !(Xsqlite3IsNaN(tls, val) != 0) {
		*(*float64)(unsafe.Pointer(pMem)) = val
		(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Real)
	}
}

func Xsqlite3VdbeMemSetRowSet(tls *libc.TLS, pMem uintptr) int32 {
	var db uintptr = (*Mem)(unsafe.Pointer(pMem)).Fdb
	var p uintptr

	Xsqlite3VdbeMemRelease(tls, pMem)
	p = Xsqlite3RowSetInit(tls, db)
	if p == uintptr(0) {
		return SQLITE_NOMEM
	}
	(*Mem)(unsafe.Pointer(pMem)).Fz = p
	(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Blob | MEM_Dyn)
	(*Mem)(unsafe.Pointer(pMem)).FxDel = *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3RowSetDelete}))
	return SQLITE_OK
}

func Xsqlite3VdbeMemTooBig(tls *libc.TLS, p uintptr) int32 {
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_Str|MEM_Blob) != 0 {
		var n int32 = (*Mem)(unsafe.Pointer(p)).Fn
		if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Zero != 0 {
			n = n + *(*int32)(unsafe.Pointer(p))
		}
		return libc.Bool32(n > *(*int32)(unsafe.Pointer((*Mem)(unsafe.Pointer(p)).Fdb + 136)))
	}
	return 0
}

func vdbeClrCopy(tls *libc.TLS, pTo uintptr, pFrom uintptr, eType int32) {
	vdbeMemClearExternAndSetNull(tls, pTo)

	Xsqlite3VdbeMemShallowCopy(tls, pTo, pFrom, eType)
}

func Xsqlite3VdbeMemShallowCopy(tls *libc.TLS, pTo uintptr, pFrom uintptr, srcType int32) {
	if int32((*Mem)(unsafe.Pointer(pTo)).Fflags)&(MEM_Agg|MEM_Dyn) != 0 {
		vdbeClrCopy(tls, pTo, pFrom, srcType)
		return
	}
	libc.Xmemcpy(tls, pTo, pFrom, uint64(uintptr(0)+24))
	if int32((*Mem)(unsafe.Pointer(pFrom)).Fflags)&MEM_Static == 0 {
		*(*U16)(unsafe.Pointer(pTo + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Dyn | MEM_Static | MEM_Ephem))

		*(*U16)(unsafe.Pointer(pTo + 20)) |= U16(srcType)
	}
}

func Xsqlite3VdbeMemCopy(tls *libc.TLS, pTo uintptr, pFrom uintptr) int32 {
	var rc int32 = SQLITE_OK

	if int32((*Mem)(unsafe.Pointer(pTo)).Fflags)&(MEM_Agg|MEM_Dyn) != 0 {
		vdbeMemClearExternAndSetNull(tls, pTo)
	}
	libc.Xmemcpy(tls, pTo, pFrom, uint64(uintptr(0)+24))
	*(*U16)(unsafe.Pointer(pTo + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Dyn))
	if int32((*Mem)(unsafe.Pointer(pTo)).Fflags)&(MEM_Str|MEM_Blob) != 0 {
		if 0 == int32((*Mem)(unsafe.Pointer(pFrom)).Fflags)&MEM_Static {
			*(*U16)(unsafe.Pointer(pTo + 20)) |= U16(MEM_Ephem)
			rc = Xsqlite3VdbeMemMakeWriteable(tls, pTo)
		}
	}

	return rc
}

func Xsqlite3VdbeMemMove(tls *libc.TLS, pTo uintptr, pFrom uintptr) {
	Xsqlite3VdbeMemRelease(tls, pTo)
	libc.Xmemcpy(tls, pTo, pFrom, uint64(unsafe.Sizeof(Mem{})))
	(*Mem)(unsafe.Pointer(pFrom)).Fflags = U16(MEM_Null)
	(*Mem)(unsafe.Pointer(pFrom)).FszMalloc = 0
}

func Xsqlite3VdbeMemSetStr(tls *libc.TLS, pMem uintptr, z uintptr, n I64, enc U8, xDel uintptr) int32 {
	var nByte I64 = n
	var iLimit int32
	var flags U16

	if !(z != 0) {
		Xsqlite3VdbeMemSetNull(tls, pMem)
		return SQLITE_OK
	}

	if (*Mem)(unsafe.Pointer(pMem)).Fdb != 0 {
		iLimit = *(*int32)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fdb + 136))
	} else {
		iLimit = SQLITE_MAX_LENGTH
	}
	if nByte < int64(0) {
		if int32(enc) == SQLITE_UTF8 {
			nByte = I64(libc.Xstrlen(tls, z))
		} else {
			for nByte = int64(0); nByte <= I64(iLimit) && int32(*(*uint8)(unsafe.Pointer(z + uintptr(nByte))))|int32(*(*uint8)(unsafe.Pointer(z + uintptr(nByte+int64(1))))) != 0; nByte = nByte + int64(2) {
			}
		}
		flags = U16(MEM_Str | MEM_Term)
	} else if int32(enc) == 0 {
		flags = U16(MEM_Blob)
		enc = U8(SQLITE_UTF8)
	} else {
		flags = U16(MEM_Str)
	}
	if nByte > I64(iLimit) {
		if xDel != 0 && xDel != libc.UintptrFromInt32(-1) {
			if xDel == *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})) {
				Xsqlite3DbFree(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, z)
			} else {
				(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDel})).f(tls, z)
			}
		}
		Xsqlite3VdbeMemSetNull(tls, pMem)
		return Xsqlite3ErrorToParser(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, SQLITE_TOOBIG)
	}

	if xDel == libc.UintptrFromInt32(-1) {
		var nAlloc I64 = nByte
		if int32(flags)&MEM_Term != 0 {
			nAlloc = nAlloc + func() int64 {
				if int32(enc) == SQLITE_UTF8 {
					return int64(1)
				}
				return int64(2)
			}()
		}

		if Xsqlite3VdbeMemClearAndResize(tls, pMem, func() int32 {
			if nAlloc > int64(32) {
				return int32(nAlloc)
			}
			return 32
		}()) != 0 {
			return SQLITE_NOMEM
		}
		libc.Xmemcpy(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, z, uint64(nAlloc))
	} else {
		Xsqlite3VdbeMemRelease(tls, pMem)
		(*Mem)(unsafe.Pointer(pMem)).Fz = z
		if xDel == *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})) {
			(*Mem)(unsafe.Pointer(pMem)).FzMalloc = (*Mem)(unsafe.Pointer(pMem)).Fz
			(*Mem)(unsafe.Pointer(pMem)).FszMalloc = Xsqlite3DbMallocSize(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, (*Mem)(unsafe.Pointer(pMem)).FzMalloc)
		} else {
			(*Mem)(unsafe.Pointer(pMem)).FxDel = xDel
			flags = U16(int32(flags) | func() int32 {
				if xDel == uintptr(0) {
					return MEM_Static
				}
				return MEM_Dyn
			}())
		}
	}

	(*Mem)(unsafe.Pointer(pMem)).Fn = int32(nByte & int64(0x7fffffff))
	(*Mem)(unsafe.Pointer(pMem)).Fflags = flags
	(*Mem)(unsafe.Pointer(pMem)).Fenc = enc

	if int32(enc) > SQLITE_UTF8 && Xsqlite3VdbeMemHandleBom(tls, pMem) != 0 {
		return SQLITE_NOMEM
	}

	return SQLITE_OK
}

func Xsqlite3VdbeMemFromBtree(tls *libc.TLS, pCur uintptr, offset U32, amt U32, pMem uintptr) int32 {
	var rc int32
	(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Null)
	if Xsqlite3BtreeMaxRecordSize(tls, pCur) < Sqlite3_int64(offset+amt) {
		return Xsqlite3CorruptError(tls, 81634)
	}
	if SQLITE_OK == libc.AssignInt32(&rc, Xsqlite3VdbeMemClearAndResize(tls, pMem, int32(amt+U32(1)))) {
		rc = Xsqlite3BtreePayload(tls, pCur, offset, amt, (*Mem)(unsafe.Pointer(pMem)).Fz)
		if rc == SQLITE_OK {
			*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pMem)).Fz + uintptr(amt))) = uint8(0)
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Blob)
			(*Mem)(unsafe.Pointer(pMem)).Fn = int32(amt)
		} else {
			Xsqlite3VdbeMemRelease(tls, pMem)
		}
	}
	return rc
}

func Xsqlite3VdbeMemFromBtreeZeroOffset(tls *libc.TLS, pCur uintptr, amt U32, pMem uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*U32)(unsafe.Pointer(bp)) = U32(0)
	var rc int32 = SQLITE_OK

	(*Mem)(unsafe.Pointer(pMem)).Fz = Xsqlite3BtreePayloadFetch(tls, pCur, bp)

	if amt <= *(*U32)(unsafe.Pointer(bp)) {
		(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Blob | MEM_Ephem)
		(*Mem)(unsafe.Pointer(pMem)).Fn = int32(amt)
	} else {
		rc = Xsqlite3VdbeMemFromBtree(tls, pCur, uint32(0), amt, pMem)
	}

	return rc
}

func valueToText(tls *libc.TLS, pVal uintptr, enc U8) uintptr {
	if int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fflags)&(MEM_Blob|MEM_Str) != 0 {
		if func() int32 {
			if int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fflags)&MEM_Zero != 0 {
				return Xsqlite3VdbeMemExpandBlob(tls, pVal)
			}
			return 0
		}() != 0 {
			return uintptr(0)
		}
		*(*U16)(unsafe.Pointer(pVal + 20)) |= U16(MEM_Str)
		if int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fenc) != int32(enc)&libc.CplInt32(SQLITE_UTF16_ALIGNED) {
			Xsqlite3VdbeChangeEncoding(tls, pVal, int32(enc)&libc.CplInt32(SQLITE_UTF16_ALIGNED))
		}
		if int32(enc)&SQLITE_UTF16_ALIGNED != 0 && 1 == 1&int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fz) {
			if Xsqlite3VdbeMemMakeWriteable(tls, pVal) != SQLITE_OK {
				return uintptr(0)
			}
		}
		Xsqlite3VdbeMemNulTerminate(tls, pVal)
	} else {
		Xsqlite3VdbeMemStringify(tls, pVal, enc, uint8(0))

	}

	if int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fenc) == int32(enc)&libc.CplInt32(SQLITE_UTF16_ALIGNED) {
		return (*Sqlite3_value)(unsafe.Pointer(pVal)).Fz
	} else {
		return uintptr(0)
	}
	return uintptr(0)
}

func Xsqlite3ValueText(tls *libc.TLS, pVal uintptr, enc U8) uintptr {
	if !(pVal != 0) {
		return uintptr(0)
	}

	if int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fflags)&(MEM_Str|MEM_Term) == MEM_Str|MEM_Term && int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fenc) == int32(enc) {
		return (*Sqlite3_value)(unsafe.Pointer(pVal)).Fz
	}
	if int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fflags)&MEM_Null != 0 {
		return uintptr(0)
	}
	return valueToText(tls, pVal, enc)
}

func Xsqlite3ValueNew(tls *libc.TLS, db uintptr) uintptr {
	var p uintptr = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Mem{})))
	if p != 0 {
		(*Mem)(unsafe.Pointer(p)).Fflags = U16(MEM_Null)
		(*Mem)(unsafe.Pointer(p)).Fdb = db
	}
	return p
}

type ValueNewStat4Ctx = struct {
	FpParse      uintptr
	FpIdx        uintptr
	FppRec       uintptr
	FiVal        int32
	F__ccgo_pad1 [4]byte
}

func valueNew(tls *libc.TLS, db uintptr, p uintptr) uintptr {
	if p != 0 {
		var pRec uintptr = *(*uintptr)(unsafe.Pointer((*ValueNewStat4Ctx)(unsafe.Pointer(p)).FppRec))

		if pRec == uintptr(0) {
			var pIdx uintptr = (*ValueNewStat4Ctx)(unsafe.Pointer(p)).FpIdx
			var nByte int32
			var i int32
			var nCol int32 = int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)

			nByte = int32(uint64(unsafe.Sizeof(Mem{}))*uint64(nCol) + (uint64(unsafe.Sizeof(UnpackedRecord{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7)))
			pRec = Xsqlite3DbMallocZero(tls, db, uint64(nByte))
			if pRec != 0 {
				(*UnpackedRecord)(unsafe.Pointer(pRec)).FpKeyInfo = Xsqlite3KeyInfoOfIndex(tls, (*ValueNewStat4Ctx)(unsafe.Pointer(p)).FpParse, pIdx)
				if (*UnpackedRecord)(unsafe.Pointer(pRec)).FpKeyInfo != 0 {
					(*UnpackedRecord)(unsafe.Pointer(pRec)).FaMem = pRec + uintptr((uint64(unsafe.Sizeof(UnpackedRecord{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7)))
					for i = 0; i < nCol; i++ {
						(*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(pRec)).FaMem + uintptr(i)*56)).Fflags = U16(MEM_Null)
						(*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(pRec)).FaMem + uintptr(i)*56)).Fdb = db
					}
				} else {
					Xsqlite3DbFreeNN(tls, db, pRec)
					pRec = uintptr(0)
				}
			}
			if pRec == uintptr(0) {
				return uintptr(0)
			}
			*(*uintptr)(unsafe.Pointer((*ValueNewStat4Ctx)(unsafe.Pointer(p)).FppRec)) = pRec
		}

		(*UnpackedRecord)(unsafe.Pointer(pRec)).FnField = U16((*ValueNewStat4Ctx)(unsafe.Pointer(p)).FiVal + 1)
		return (*UnpackedRecord)(unsafe.Pointer(pRec)).FaMem + uintptr((*ValueNewStat4Ctx)(unsafe.Pointer(p)).FiVal)*56
	}
	return Xsqlite3ValueNew(tls, db)
}

func valueFromFunction(tls *libc.TLS, db uintptr, p uintptr, enc U8, aff U8, ppVal uintptr, pCtx uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var apVal uintptr
	var nVal int32
	var pFunc uintptr
	var pVal uintptr
	var rc int32
	var pList uintptr
	var i int32
	apVal = uintptr(0)
	nVal = 0
	pFunc = uintptr(0)
	pVal = uintptr(0)
	rc = SQLITE_OK
	pList = uintptr(0)

	pList = *(*uintptr)(unsafe.Pointer(p + 32))
	if !(pList != 0) {
		goto __1
	}
	nVal = (*ExprList)(unsafe.Pointer(pList)).FnExpr
__1:
	;
	pFunc = Xsqlite3FindFunction(tls, db, *(*uintptr)(unsafe.Pointer(p + 8)), nVal, enc, uint8(0))

	if !((*FuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&U32(SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) == U32(0) ||
		(*FuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&U32(SQLITE_FUNC_NEEDCOLL) != 0) {
		goto __2
	}
	return SQLITE_OK
__2:
	;
	if !(pList != 0) {
		goto __3
	}
	apVal = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(uintptr(0)))*uint64(nVal))
	if !(apVal == uintptr(0)) {
		goto __4
	}
	rc = SQLITE_NOMEM
	goto value_from_function_out
__4:
	;
	i = 0
__5:
	if !(i < nVal) {
		goto __7
	}
	rc = Xsqlite3ValueFromExpr(tls, db, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr, enc, aff, apVal+uintptr(i)*8)
	if !(*(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8)) == uintptr(0) || rc != SQLITE_OK) {
		goto __8
	}
	goto value_from_function_out
__8:
	;
	goto __6
__6:
	i++
	goto __5
	goto __7
__7:
	;
__3:
	;
	pVal = valueNew(tls, db, pCtx)
	if !(pVal == uintptr(0)) {
		goto __9
	}
	rc = SQLITE_NOMEM
	goto value_from_function_out
__9:
	;
	libc.Xmemset(tls, bp+8, 0, uint64(unsafe.Sizeof(Sqlite3_context{})))
	(*Sqlite3_context)(unsafe.Pointer(bp + 8)).FpOut = pVal
	(*Sqlite3_context)(unsafe.Pointer(bp + 8)).FpFunc = pFunc
	(*Sqlite3_context)(unsafe.Pointer(bp + 8)).Fenc = (*Sqlite3)(unsafe.Pointer(db)).Fenc
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*FuncDef)(unsafe.Pointer(pFunc)).FxSFunc})).f(tls, bp+8, nVal, apVal)
	if !((*Sqlite3_context)(unsafe.Pointer(bp+8)).FisError != 0) {
		goto __10
	}
	rc = (*Sqlite3_context)(unsafe.Pointer(bp + 8)).FisError
	Xsqlite3ErrorMsg(tls, (*ValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse, ts+1684, libc.VaList(bp, Xsqlite3_value_text(tls, pVal)))
	goto __11
__10:
	Xsqlite3ValueApplyAffinity(tls, pVal, aff, uint8(SQLITE_UTF8))

__11:
	;
value_from_function_out:
	if !(rc != SQLITE_OK) {
		goto __12
	}
	pVal = uintptr(0)
	(*Parse)(unsafe.Pointer((*ValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).Frc = rc
__12:
	;
	if !(apVal != 0) {
		goto __13
	}
	i = 0
__14:
	if !(i < nVal) {
		goto __16
	}
	Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8)))
	goto __15
__15:
	i++
	goto __14
	goto __16
__16:
	;
	Xsqlite3DbFreeNN(tls, db, apVal)
__13:
	;
	*(*uintptr)(unsafe.Pointer(ppVal)) = pVal
	return rc
}

func valueFromExpr(tls *libc.TLS, db uintptr, pExpr uintptr, enc U8, affinity U8, ppVal uintptr, pCtx uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var op int32
	var zVal uintptr

	var negInt int32
	var zNeg uintptr
	var rc int32
	var aff U8
	var nVal int32
	zVal = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	negInt = 1
	zNeg = ts + 1636
	rc = SQLITE_OK

__1:
	if !(libc.AssignInt32(&op, int32((*Expr)(unsafe.Pointer(pExpr)).Fop)) == TK_UPLUS || op == TK_SPAN) {
		goto __2
	}
	pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	goto __1
__2:
	;
	if !(op == TK_REGISTER) {
		goto __3
	}
	op = int32((*Expr)(unsafe.Pointer(pExpr)).Fop2)
__3:
	;
	if !(op == TK_CAST) {
		goto __4
	}

	aff = Xsqlite3AffinityType(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), uintptr(0))
	rc = valueFromExpr(tls, db, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, enc, aff, ppVal, pCtx)

	if !(*(*uintptr)(unsafe.Pointer(ppVal)) != 0) {
		goto __5
	}
	Xsqlite3VdbeMemCast(tls, *(*uintptr)(unsafe.Pointer(ppVal)), aff, enc)
	Xsqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(ppVal)), affinity, enc)
__5:
	;
	return rc
__4:
	;
	if !(op == TK_UMINUS &&
		(int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == TK_INTEGER || int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == TK_FLOAT)) {
		goto __6
	}
	pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	op = int32((*Expr)(unsafe.Pointer(pExpr)).Fop)
	negInt = -1
	zNeg = ts + 7812
__6:
	;
	if !(op == TK_STRING || op == TK_FLOAT || op == TK_INTEGER) {
		goto __7
	}
	*(*uintptr)(unsafe.Pointer(bp + 16)) = valueNew(tls, db, pCtx)
	if !(*(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0)) {
		goto __9
	}
	goto no_mem
__9:
	;
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_IntValue) != U32(0)) {
		goto __10
	}
	Xsqlite3VdbeMemSetInt64(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), I64(*(*int32)(unsafe.Pointer(pExpr + 8)))*I64(negInt))
	goto __11
__10:
	zVal = Xsqlite3MPrintf(tls, db, ts+7814, libc.VaList(bp, zNeg, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
	if !(zVal == uintptr(0)) {
		goto __12
	}
	goto no_mem
__12:
	;
	Xsqlite3ValueSetStr(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), -1, zVal, uint8(SQLITE_UTF8), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})))
__11:
	;
	if !((op == TK_INTEGER || op == TK_FLOAT) && int32(affinity) == SQLITE_AFF_BLOB) {
		goto __13
	}
	Xsqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), uint8(SQLITE_AFF_NUMERIC), uint8(SQLITE_UTF8))
	goto __14
__13:
	Xsqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), affinity, uint8(SQLITE_UTF8))
__14:
	;
	if !(int32((*Sqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fflags)&(MEM_Int|MEM_IntReal|MEM_Real) != 0) {
		goto __15
	}

	*(*U16)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)) + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Str))
__15:
	;
	if !(int32(enc) != SQLITE_UTF8) {
		goto __16
	}
	rc = Xsqlite3VdbeChangeEncoding(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), int32(enc))
__16:
	;
	goto __8
__7:
	if !(op == TK_UMINUS) {
		goto __17
	}

	if !(SQLITE_OK == valueFromExpr(tls, db, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, enc, affinity, bp+16, pCtx) &&
		*(*uintptr)(unsafe.Pointer(bp + 16)) != uintptr(0)) {
		goto __19
	}
	Xsqlite3VdbeMemNumerify(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if !(int32((*Sqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fflags)&MEM_Real != 0) {
		goto __20
	}
	*(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))) = -*(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16))))
	goto __21
__20:
	if !(*(*I64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))) == int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32)) {
		goto __22
	}
	*(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))) = -float64(int64(-1) - (int64(0xffffffff) | int64(0x7fffffff)<<32))
	(*Sqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fflags = U16(int32((*Sqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Real)
	goto __23
__22:
	*(*I64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))) = -*(*I64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16))))
__23:
	;
__21:
	;
	Xsqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), affinity, enc)
__19:
	;
	goto __18
__17:
	if !(op == TK_NULL) {
		goto __24
	}
	*(*uintptr)(unsafe.Pointer(bp + 16)) = valueNew(tls, db, pCtx)
	if !(*(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0)) {
		goto __26
	}
	goto no_mem
__26:
	;
	Xsqlite3VdbeMemSetNull(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	goto __25
__24:
	if !(op == TK_BLOB) {
		goto __27
	}

	*(*uintptr)(unsafe.Pointer(bp + 16)) = valueNew(tls, db, pCtx)
	if !!(*(*uintptr)(unsafe.Pointer(bp + 16)) != 0) {
		goto __29
	}
	goto no_mem
__29:
	;
	zVal = *(*uintptr)(unsafe.Pointer(pExpr + 8)) + 2
	nVal = Xsqlite3Strlen30(tls, zVal) - 1

	Xsqlite3VdbeMemSetStr(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), Xsqlite3HexToBlob(tls, db, zVal, nVal), int64(nVal/2),
		uint8(0), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})))
	goto __28
__27:
	if !(op == TK_FUNCTION && pCtx != uintptr(0)) {
		goto __30
	}
	rc = valueFromFunction(tls, db, pExpr, enc, affinity, bp+16, pCtx)
	goto __31
__30:
	if !(op == TK_TRUEFALSE) {
		goto __32
	}

	*(*uintptr)(unsafe.Pointer(bp + 16)) = valueNew(tls, db, pCtx)
	if !(*(*uintptr)(unsafe.Pointer(bp + 16)) != 0) {
		goto __33
	}
	(*Sqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fflags = U16(MEM_Int)
	*(*I64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))) = I64(libc.Bool32(int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 8)) + 4))) == 0))
__33:
	;
__32:
	;
__31:
	;
__28:
	;
__25:
	;
__18:
	;
__8:
	;
	*(*uintptr)(unsafe.Pointer(ppVal)) = *(*uintptr)(unsafe.Pointer(bp + 16))
	return rc

no_mem:
	if !(pCtx == uintptr(0) || (*Parse)(unsafe.Pointer((*ValueNewStat4Ctx)(unsafe.Pointer(pCtx)).FpParse)).FnErr == 0) {
		goto __34
	}
	Xsqlite3OomFault(tls, db)
__34:
	;
	Xsqlite3DbFree(tls, db, zVal)

	if !(pCtx == uintptr(0)) {
		goto __35
	}
	Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
__35:
	;
	return SQLITE_NOMEM
}

func Xsqlite3ValueFromExpr(tls *libc.TLS, db uintptr, pExpr uintptr, enc U8, affinity U8, ppVal uintptr) int32 {
	if pExpr != 0 {
		return valueFromExpr(tls, db, pExpr, enc, affinity, ppVal, uintptr(0))
	}
	return 0
}

func stat4ValueFromExpr(tls *libc.TLS, pParse uintptr, pExpr uintptr, affinity U8, pAlloc uintptr, ppVal uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	pExpr = Xsqlite3ExprSkipCollate(tls, pExpr)

	if !(pExpr != 0) {
		*(*uintptr)(unsafe.Pointer(bp)) = valueNew(tls, db, pAlloc)
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
			Xsqlite3VdbeMemSetNull(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	} else if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_VARIABLE && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_EnableQPSG) == uint64(0) {
		var v uintptr
		var iBindVar int32 = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)
		Xsqlite3VdbeSetVarmask(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, iBindVar)
		if libc.AssignUintptr(&v, (*Parse)(unsafe.Pointer(pParse)).FpReprepare) != uintptr(0) {
			*(*uintptr)(unsafe.Pointer(bp)) = valueNew(tls, db, pAlloc)
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				rc = Xsqlite3VdbeMemCopy(tls, *(*uintptr)(unsafe.Pointer(bp)), (*Vdbe)(unsafe.Pointer(v)).FaVar+uintptr(iBindVar-1)*56)
				Xsqlite3ValueApplyAffinity(tls, *(*uintptr)(unsafe.Pointer(bp)), affinity, (*Sqlite3)(unsafe.Pointer(db)).Fenc)
				(*Sqlite3_value)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fdb = (*Parse)(unsafe.Pointer(pParse)).Fdb
			}
		}
	} else {
		rc = valueFromExpr(tls, db, pExpr, (*Sqlite3)(unsafe.Pointer(db)).Fenc, affinity, bp, pAlloc)
	}

	*(*uintptr)(unsafe.Pointer(ppVal)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
}

func Xsqlite3Stat4ProbeSetValue(tls *libc.TLS, pParse uintptr, pIdx uintptr, ppRec uintptr, pExpr uintptr, nElem int32, iVal int32, pnExtract uintptr) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var rc int32 = SQLITE_OK
	var nExtract int32 = 0

	if pExpr == uintptr(0) || int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_SELECT {
		var i int32

		(*ValueNewStat4Ctx)(unsafe.Pointer(bp)).FpParse = pParse
		(*ValueNewStat4Ctx)(unsafe.Pointer(bp)).FpIdx = pIdx
		(*ValueNewStat4Ctx)(unsafe.Pointer(bp)).FppRec = ppRec

		for i = 0; i < nElem; i++ {
			*(*uintptr)(unsafe.Pointer(bp + 32)) = uintptr(0)
			var pElem uintptr = func() uintptr {
				if pExpr != 0 {
					return Xsqlite3VectorFieldSubexpr(tls, pExpr, i)
				}
				return uintptr(0)
			}()
			var aff U8 = Xsqlite3IndexColumnAffinity(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pIdx, iVal+i)
			(*ValueNewStat4Ctx)(unsafe.Pointer(bp)).FiVal = iVal + i
			rc = stat4ValueFromExpr(tls, pParse, pElem, aff, bp, bp+32)
			if !(*(*uintptr)(unsafe.Pointer(bp + 32)) != 0) {
				break
			}
			nExtract++
		}
	}

	*(*int32)(unsafe.Pointer(pnExtract)) = nExtract
	return rc
}

func Xsqlite3Stat4ValueFromExpr(tls *libc.TLS, pParse uintptr, pExpr uintptr, affinity U8, ppVal uintptr) int32 {
	return stat4ValueFromExpr(tls, pParse, pExpr, affinity, uintptr(0), ppVal)
}

func Xsqlite3Stat4Column(tls *libc.TLS, db uintptr, pRec uintptr, nRec int32, iCol int32, ppVal uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*U32)(unsafe.Pointer(bp + 4)) = U32(0)

	var iHdr int32
	var iField int32
	var szField int32 = 0
	var i int32
	var a uintptr = pRec
	var pMem uintptr = *(*uintptr)(unsafe.Pointer(ppVal))

	iHdr = int32(func() uint8 {
		if int32(*(*U8)(unsafe.Pointer(a))) < int32(U8(0x80)) {
			return uint8(func() int32 { *(*int32)(unsafe.Pointer(bp)) = int32(U32(*(*U8)(unsafe.Pointer(a)))); return 1 }())
		}
		return Xsqlite3GetVarint32(tls, a, bp)
	}())
	if *(*int32)(unsafe.Pointer(bp)) > nRec || iHdr >= *(*int32)(unsafe.Pointer(bp)) {
		return Xsqlite3CorruptError(tls, 82274)
	}
	iField = *(*int32)(unsafe.Pointer(bp))
	for i = 0; i <= iCol; i++ {
		iHdr = iHdr + int32(func() uint8 {
			if int32(*(*U8)(unsafe.Pointer(a + uintptr(iHdr)))) < int32(U8(0x80)) {
				return uint8(func() int32 {
					*(*U32)(unsafe.Pointer(bp + 4)) = U32(*(*U8)(unsafe.Pointer(a + uintptr(iHdr))))
					return 1
				}())
			}
			return Xsqlite3GetVarint32(tls, a+uintptr(iHdr), bp+4)
		}())

		if iHdr > *(*int32)(unsafe.Pointer(bp)) {
			return Xsqlite3CorruptError(tls, 82280)
		}
		szField = int32(Xsqlite3VdbeSerialTypeLen(tls, *(*U32)(unsafe.Pointer(bp + 4))))
		iField = iField + szField
	}

	if iField > nRec {
		return Xsqlite3CorruptError(tls, 82286)
	}
	if pMem == uintptr(0) {
		pMem = libc.AssignPtrUintptr(ppVal, Xsqlite3ValueNew(tls, db))
		if pMem == uintptr(0) {
			return SQLITE_NOMEM
		}
	}
	Xsqlite3VdbeSerialGet(tls, a+uintptr(iField-szField), *(*U32)(unsafe.Pointer(bp + 4)), pMem)
	(*Mem)(unsafe.Pointer(pMem)).Fenc = (*Sqlite3)(unsafe.Pointer(db)).Fenc
	return SQLITE_OK
}

func Xsqlite3Stat4ProbeFree(tls *libc.TLS, pRec uintptr) {
	if pRec != 0 {
		var i int32
		var nCol int32 = int32((*KeyInfo)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(pRec)).FpKeyInfo)).FnAllField)
		var aMem uintptr = (*UnpackedRecord)(unsafe.Pointer(pRec)).FaMem
		var db uintptr = (*Mem)(unsafe.Pointer(aMem)).Fdb
		for i = 0; i < nCol; i++ {
			Xsqlite3VdbeMemRelease(tls, aMem+uintptr(i)*56)
		}
		Xsqlite3KeyInfoUnref(tls, (*UnpackedRecord)(unsafe.Pointer(pRec)).FpKeyInfo)
		Xsqlite3DbFreeNN(tls, db, pRec)
	}
}

func Xsqlite3ValueSetStr(tls *libc.TLS, v uintptr, n int32, z uintptr, enc U8, xDel uintptr) {
	if v != 0 {
		Xsqlite3VdbeMemSetStr(tls, v, z, int64(n), enc, xDel)
	}
}

func Xsqlite3ValueFree(tls *libc.TLS, v uintptr) {
	if !(v != 0) {
		return
	}
	Xsqlite3VdbeMemRelease(tls, v)
	Xsqlite3DbFreeNN(tls, (*Mem)(unsafe.Pointer(v)).Fdb, v)
}

func valueBytes(tls *libc.TLS, pVal uintptr, enc U8) int32 {
	if valueToText(tls, pVal, enc) != uintptr(0) {
		return (*Sqlite3_value)(unsafe.Pointer(pVal)).Fn
	}
	return 0
}

func Xsqlite3ValueBytes(tls *libc.TLS, pVal uintptr, enc U8) int32 {
	var p uintptr = pVal

	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Str != 0 && int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fenc) == int32(enc) {
		return (*Mem)(unsafe.Pointer(p)).Fn
	}
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Str != 0 && int32(enc) != SQLITE_UTF8 && int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fenc) != SQLITE_UTF8 {
		return (*Mem)(unsafe.Pointer(p)).Fn
	}
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Blob != 0 {
		if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Zero != 0 {
			return (*Mem)(unsafe.Pointer(p)).Fn + *(*int32)(unsafe.Pointer(p))
		} else {
			return (*Mem)(unsafe.Pointer(p)).Fn
		}
	}
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Null != 0 {
		return 0
	}
	return valueBytes(tls, pVal, enc)
}

func Xsqlite3VdbeCreate(tls *libc.TLS, pParse uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var p uintptr
	p = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(Vdbe{})))
	if p == uintptr(0) {
		return uintptr(0)
	}
	libc.Xmemset(tls, p+136, 0, uint64(unsafe.Sizeof(Vdbe{}))-uint64(uintptr(0)+136))
	(*Vdbe)(unsafe.Pointer(p)).Fdb = db
	if (*Sqlite3)(unsafe.Pointer(db)).FpVdbe != 0 {
		(*Vdbe1)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpVdbe)).FppVPrev = p + 16
	}
	(*Vdbe)(unsafe.Pointer(p)).FpVNext = (*Sqlite3)(unsafe.Pointer(db)).FpVdbe
	(*Vdbe)(unsafe.Pointer(p)).FppVPrev = db + 8
	(*Sqlite3)(unsafe.Pointer(db)).FpVdbe = p

	(*Vdbe)(unsafe.Pointer(p)).FpParse = pParse
	(*Parse)(unsafe.Pointer(pParse)).FpVdbe = p

	Xsqlite3VdbeAddOp2(tls, p, OP_Init, 0, 1)
	return p
}

func Xsqlite3VdbeParser(tls *libc.TLS, p uintptr) uintptr {
	return (*Vdbe)(unsafe.Pointer(p)).FpParse
}

func Xsqlite3VdbeError(tls *libc.TLS, p uintptr, zFormat uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	Xsqlite3DbFree(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg)
	ap = va
	(*Vdbe)(unsafe.Pointer(p)).FzErrMsg = Xsqlite3VMPrintf(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, zFormat, ap)
	_ = ap
}

func Xsqlite3VdbeSetSql(tls *libc.TLS, p uintptr, z uintptr, n int32, prepFlags U8) {
	if p == uintptr(0) {
		return
	}
	(*Vdbe)(unsafe.Pointer(p)).FprepFlags = prepFlags
	if int32(prepFlags)&SQLITE_PREPARE_SAVESQL == 0 {
		(*Vdbe)(unsafe.Pointer(p)).Fexpmask = U32(0)
	}

	(*Vdbe)(unsafe.Pointer(p)).FzSql = Xsqlite3DbStrNDup(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, z, uint64(n))
}

func Xsqlite3VdbeSwap(tls *libc.TLS, pA uintptr, pB uintptr) {
	var tmp Vdbe
	var pTmp uintptr
	var ppTmp uintptr
	var zTmp uintptr

	tmp = *(*Vdbe)(unsafe.Pointer(pA))
	*(*Vdbe)(unsafe.Pointer(pA)) = *(*Vdbe)(unsafe.Pointer(pB))
	*(*Vdbe)(unsafe.Pointer(pB)) = tmp
	pTmp = (*Vdbe)(unsafe.Pointer(pA)).FpVNext
	(*Vdbe)(unsafe.Pointer(pA)).FpVNext = (*Vdbe)(unsafe.Pointer(pB)).FpVNext
	(*Vdbe)(unsafe.Pointer(pB)).FpVNext = pTmp
	ppTmp = (*Vdbe)(unsafe.Pointer(pA)).FppVPrev
	(*Vdbe)(unsafe.Pointer(pA)).FppVPrev = (*Vdbe)(unsafe.Pointer(pB)).FppVPrev
	(*Vdbe)(unsafe.Pointer(pB)).FppVPrev = ppTmp
	zTmp = (*Vdbe)(unsafe.Pointer(pA)).FzSql
	(*Vdbe)(unsafe.Pointer(pA)).FzSql = (*Vdbe)(unsafe.Pointer(pB)).FzSql
	(*Vdbe)(unsafe.Pointer(pB)).FzSql = zTmp
	(*Vdbe)(unsafe.Pointer(pB)).Fexpmask = (*Vdbe)(unsafe.Pointer(pA)).Fexpmask
	(*Vdbe)(unsafe.Pointer(pB)).FprepFlags = (*Vdbe)(unsafe.Pointer(pA)).FprepFlags
	libc.Xmemcpy(tls, pB+212, pA+212, uint64(unsafe.Sizeof([9]U32{})))
	*(*U32)(unsafe.Pointer(pB + 212 + 5*4))++
}

func growOpArray(tls *libc.TLS, v uintptr, nOp int32) int32 {
	var pNew uintptr
	var p uintptr = (*Vdbe)(unsafe.Pointer(v)).FpParse

	var nNew Sqlite3_int64 = func() int64 {
		if (*Vdbe)(unsafe.Pointer(v)).FnOpAlloc != 0 {
			return int64(2) * Sqlite3_int64((*Vdbe)(unsafe.Pointer(v)).FnOpAlloc)
		}
		return int64(uint64(1024) / uint64(unsafe.Sizeof(Op{})))
	}()
	_ = nOp

	if nNew > Sqlite3_int64(*(*int32)(unsafe.Pointer((*Parse)(unsafe.Pointer(p)).Fdb + 136 + 5*4))) {
		Xsqlite3OomFault(tls, (*Parse)(unsafe.Pointer(p)).Fdb)
		return SQLITE_NOMEM
	}

	pNew = Xsqlite3DbRealloc(tls, (*Parse)(unsafe.Pointer(p)).Fdb, (*Vdbe)(unsafe.Pointer(v)).FaOp, uint64(nNew)*uint64(unsafe.Sizeof(Op{})))
	if pNew != 0 {
		(*Parse)(unsafe.Pointer(p)).FszOpAlloc = Xsqlite3DbMallocSize(tls, (*Parse)(unsafe.Pointer(p)).Fdb, pNew)
		(*Vdbe)(unsafe.Pointer(v)).FnOpAlloc = int32(uint64((*Parse)(unsafe.Pointer(p)).FszOpAlloc) / uint64(unsafe.Sizeof(Op{})))
		(*Vdbe)(unsafe.Pointer(v)).FaOp = pNew
	}
	return func() int32 {
		if pNew != 0 {
			return SQLITE_OK
		}
		return SQLITE_NOMEM
	}()
}

func growOp3(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32) int32 {
	if growOpArray(tls, p, 1) != 0 {
		return 1
	}

	return Xsqlite3VdbeAddOp3(tls, p, op, p1, p2, p3)
}

func Xsqlite3VdbeAddOp3(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32) int32 {
	var i int32
	var pOp uintptr

	i = (*Vdbe)(unsafe.Pointer(p)).FnOp

	if (*Vdbe)(unsafe.Pointer(p)).FnOpAlloc <= i {
		return growOp3(tls, p, op, p1, p2, p3)
	}

	(*Vdbe)(unsafe.Pointer(p)).FnOp++
	pOp = (*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr(i)*32

	(*VdbeOp)(unsafe.Pointer(pOp)).Fopcode = U8(op)
	(*VdbeOp)(unsafe.Pointer(pOp)).Fp5 = U16(0)
	(*VdbeOp)(unsafe.Pointer(pOp)).Fp1 = p1
	(*VdbeOp)(unsafe.Pointer(pOp)).Fp2 = p2
	(*VdbeOp)(unsafe.Pointer(pOp)).Fp3 = p3
	*(*uintptr)(unsafe.Pointer(pOp + 16)) = uintptr(0)
	(*VdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(P4_NOTUSED)
	(*VdbeOp)(unsafe.Pointer(pOp)).FzComment = uintptr(0)
	return i
}

func Xsqlite3VdbeAddOp0(tls *libc.TLS, p uintptr, op int32) int32 {
	return Xsqlite3VdbeAddOp3(tls, p, op, 0, 0, 0)
}

func Xsqlite3VdbeAddOp1(tls *libc.TLS, p uintptr, op int32, p1 int32) int32 {
	return Xsqlite3VdbeAddOp3(tls, p, op, p1, 0, 0)
}

func Xsqlite3VdbeAddOp2(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32) int32 {
	return Xsqlite3VdbeAddOp3(tls, p, op, p1, p2, 0)
}

func Xsqlite3VdbeGoto(tls *libc.TLS, p uintptr, iDest int32) int32 {
	return Xsqlite3VdbeAddOp3(tls, p, OP_Goto, 0, iDest, 0)
}

func Xsqlite3VdbeLoadString(tls *libc.TLS, p uintptr, iDest int32, zStr uintptr) int32 {
	return Xsqlite3VdbeAddOp4(tls, p, OP_String8, 0, iDest, 0, zStr, 0)
}

func Xsqlite3VdbeMultiLoad(tls *libc.TLS, p uintptr, iDest int32, zTypes uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	var i int32
	var c uint8
	var z uintptr
	ap = va
	i = 0
__1:
	if !(int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(zTypes + uintptr(i))))) != 0) {
		goto __3
	}
	if !(int32(c) == 's') {
		goto __4
	}
	z = libc.VaUintptr(&ap)
	Xsqlite3VdbeAddOp4(tls, p, func() int32 {
		if z == uintptr(0) {
			return OP_Null
		}
		return OP_String8
	}(), 0, iDest+i, 0, z, 0)
	goto __5
__4:
	if !(int32(c) == 'i') {
		goto __6
	}
	Xsqlite3VdbeAddOp2(tls, p, OP_Integer, libc.VaInt32(&ap), iDest+i)
	goto __7
__6:
	goto skip_op_resultrow
__7:
	;
__5:
	;
	goto __2
__2:
	i++
	goto __1
	goto __3
__3:
	;
	Xsqlite3VdbeAddOp2(tls, p, OP_ResultRow, iDest, i)
skip_op_resultrow:
	_ = ap
}

func Xsqlite3VdbeAddOp4(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32, zP4 uintptr, p4type int32) int32 {
	var addr int32 = Xsqlite3VdbeAddOp3(tls, p, op, p1, p2, p3)
	Xsqlite3VdbeChangeP4(tls, p, addr, zP4, p4type)
	return addr
}

func Xsqlite3VdbeAddFunctionCall(tls *libc.TLS, pParse uintptr, p1 int32, p2 int32, p3 int32, nArg int32, pFunc uintptr, eCallCtx int32) int32 {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var nByte int32
	var addr int32
	var pCtx uintptr

	nByte = int32(uint64(unsafe.Sizeof(Sqlite3_context{})) + uint64(nArg-1)*uint64(unsafe.Sizeof(uintptr(0))))
	pCtx = Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(nByte))
	if pCtx == uintptr(0) {
		freeEphemeralFunction(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pFunc)
		return 0
	}
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut = uintptr(0)
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FpFunc = pFunc
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe = uintptr(0)
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError = 0
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).Fargc = U8(nArg)
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FiOp = Xsqlite3VdbeCurrentAddr(tls, v)
	addr = Xsqlite3VdbeAddOp4(tls, v, func() int32 {
		if eCallCtx != 0 {
			return OP_PureFunc
		}
		return OP_Function
	}(),
		p1, p2, p3, pCtx, -15)
	Xsqlite3VdbeChangeP5(tls, v, uint16(eCallCtx&NC_SelfRef))
	Xsqlite3MayAbort(tls, pParse)
	return addr
}

func Xsqlite3VdbeAddOp4Dup8(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32, zP4 uintptr, p4type int32) int32 {
	var p4copy uintptr = Xsqlite3DbMallocRawNN(tls, Xsqlite3VdbeDb(tls, p), uint64(8))
	if p4copy != 0 {
		libc.Xmemcpy(tls, p4copy, zP4, uint64(8))
	}
	return Xsqlite3VdbeAddOp4(tls, p, op, p1, p2, p3, p4copy, p4type)
}

func Xsqlite3VdbeExplainParent(tls *libc.TLS, pParse uintptr) int32 {
	var pOp uintptr
	if (*Parse)(unsafe.Pointer(pParse)).FaddrExplain == 0 {
		return 0
	}
	pOp = Xsqlite3VdbeGetOp(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, (*Parse)(unsafe.Pointer(pParse)).FaddrExplain)
	return (*VdbeOp)(unsafe.Pointer(pOp)).Fp2
}

func Xsqlite3VdbeExplain(tls *libc.TLS, pParse uintptr, bPush U8, zFmt uintptr, va uintptr) int32 {
	var addr int32 = 0

	if int32((*Parse)(unsafe.Pointer(pParse)).Fexplain) == 2 {
		var zMsg uintptr
		var v uintptr
		var ap Va_list
		_ = ap
		var iThis int32
		ap = va
		zMsg = Xsqlite3VMPrintf(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, zFmt, ap)
		_ = ap
		v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
		iThis = (*Vdbe)(unsafe.Pointer(v)).FnOp
		addr = Xsqlite3VdbeAddOp4(tls, v, OP_Explain, iThis, (*Parse)(unsafe.Pointer(pParse)).FaddrExplain, 0,
			zMsg, -6)

		if bPush != 0 {
			(*Parse)(unsafe.Pointer(pParse)).FaddrExplain = iThis
		}

	}
	return addr
}

func Xsqlite3VdbeExplainPop(tls *libc.TLS, pParse uintptr) {
	(*Parse)(unsafe.Pointer(pParse)).FaddrExplain = Xsqlite3VdbeExplainParent(tls, pParse)
}

func Xsqlite3VdbeAddParseSchemaOp(tls *libc.TLS, p uintptr, iDb int32, zWhere uintptr, p5 U16) {
	var j int32
	Xsqlite3VdbeAddOp4(tls, p, OP_ParseSchema, iDb, 0, 0, zWhere, -6)
	Xsqlite3VdbeChangeP5(tls, p, p5)
	for j = 0; j < (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FnDb; j++ {
		Xsqlite3VdbeUsesBtree(tls, p, j)
	}
	Xsqlite3MayAbort(tls, (*Vdbe)(unsafe.Pointer(p)).FpParse)
}

func Xsqlite3VdbeAddOp4Int(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32, p4 int32) int32 {
	var addr int32 = Xsqlite3VdbeAddOp3(tls, p, op, p1, p2, p3)
	if int32((*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed) == 0 {
		var pOp uintptr = (*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*32
		(*VdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(-3)
		*(*int32)(unsafe.Pointer(pOp + 16)) = p4
	}
	return addr
}

func Xsqlite3VdbeEndCoroutine(tls *libc.TLS, v uintptr, regYield int32) {
	Xsqlite3VdbeAddOp1(tls, v, OP_EndCoroutine, regYield)

	(*Parse)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).FpParse)).FnTempReg = U8(0)
	(*Parse)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).FpParse)).FnRangeReg = 0
}

func Xsqlite3VdbeMakeLabel(tls *libc.TLS, pParse uintptr) int32 {
	return libc.PreDecInt32(&(*Parse)(unsafe.Pointer(pParse)).FnLabel, 1)
}

func resizeResolveLabel(tls *libc.TLS, p uintptr, v uintptr, j int32) {
	var nNewSize int32 = 10 - (*Parse)(unsafe.Pointer(p)).FnLabel
	(*Parse)(unsafe.Pointer(p)).FaLabel = Xsqlite3DbReallocOrFree(tls, (*Parse)(unsafe.Pointer(p)).Fdb, (*Parse)(unsafe.Pointer(p)).FaLabel,
		uint64(nNewSize)*uint64(unsafe.Sizeof(int32(0))))
	if (*Parse)(unsafe.Pointer(p)).FaLabel == uintptr(0) {
		(*Parse)(unsafe.Pointer(p)).FnLabelAlloc = 0
	} else {
		if nNewSize >= 100 && nNewSize/100 > (*Parse)(unsafe.Pointer(p)).FnLabelAlloc/100 {
			Xsqlite3ProgressCheck(tls, p)
		}
		(*Parse)(unsafe.Pointer(p)).FnLabelAlloc = nNewSize
		*(*int32)(unsafe.Pointer((*Parse)(unsafe.Pointer(p)).FaLabel + uintptr(j)*4)) = (*Vdbe)(unsafe.Pointer(v)).FnOp
	}
}

func Xsqlite3VdbeResolveLabel(tls *libc.TLS, v uintptr, x int32) {
	var p uintptr = (*Vdbe)(unsafe.Pointer(v)).FpParse
	var j int32 = ^x

	if (*Parse)(unsafe.Pointer(p)).FnLabelAlloc+(*Parse)(unsafe.Pointer(p)).FnLabel < 0 {
		resizeResolveLabel(tls, p, v, j)
	} else {
		*(*int32)(unsafe.Pointer((*Parse)(unsafe.Pointer(p)).FaLabel + uintptr(j)*4)) = (*Vdbe)(unsafe.Pointer(v)).FnOp
	}
}

func Xsqlite3VdbeRunOnlyOnce(tls *libc.TLS, p uintptr) {
	Xsqlite3VdbeAddOp2(tls, p, OP_Expire, 1, 1)
}

func Xsqlite3VdbeReusable(tls *libc.TLS, p uintptr) {
	var i int32
	for i = 1; i < (*Vdbe)(unsafe.Pointer(p)).FnOp; i++ {
		if int32((*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp+uintptr(i)*32)).Fopcode) == OP_Expire {
			(*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp + 1*32)).Fopcode = U8(OP_Noop)
			break
		}
	}
}

func resolveP2Values(tls *libc.TLS, p uintptr, pMaxFuncArgs uintptr) {
	var nMaxArgs int32
	var pOp uintptr
	var pParse uintptr
	var aLabel uintptr
	var n int32
	nMaxArgs = *(*int32)(unsafe.Pointer(pMaxFuncArgs))
	pParse = (*Vdbe)(unsafe.Pointer(p)).FpParse
	aLabel = (*Parse)(unsafe.Pointer(pParse)).FaLabel
	libc.SetBitFieldPtr8Uint32(p+200, Bft(1), 6, 0x40)
	libc.SetBitFieldPtr8Uint32(p+200, Bft(0), 7, 0x80)
	pOp = (*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr((*Vdbe)(unsafe.Pointer(p)).FnOp-1)*32

__1:
	if !(1 != 0) {
		goto __2
	}

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) <= SQLITE_MX_JUMP_OPCODE) {
		goto __3
	}

	switch int32((*Op)(unsafe.Pointer(pOp)).Fopcode) {
	case OP_Transaction:
		goto __5
	case OP_AutoCommit:
		goto __6
	case OP_Savepoint:
		goto __7
	case OP_Checkpoint:
		goto __8
	case OP_Vacuum:
		goto __9
	case OP_JournalMode:
		goto __10
	case OP_Init:
		goto __11
	case OP_VUpdate:
		goto __12
	case OP_VFilter:
		goto __13
	default:
		goto __14
	}
	goto __4
__5:
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 != 0) {
		goto __15
	}
	libc.SetBitFieldPtr8Uint32(p+200, Bft(0), 6, 0x40)
__15:
	;
__6:
__7:
	libc.SetBitFieldPtr8Uint32(p+200, Bft(1), 7, 0x80)
	goto __4

__8:
__9:
__10:
	libc.SetBitFieldPtr8Uint32(p+200, Bft(0), 6, 0x40)
	libc.SetBitFieldPtr8Uint32(p+200, Bft(1), 7, 0x80)
	goto __4

__11:
	;
	goto resolve_p2_values_loop_exit

__12:
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 > nMaxArgs) {
		goto __16
	}
	nMaxArgs = (*Op)(unsafe.Pointer(pOp)).Fp2
__16:
	;
	goto __4

__13:
	;
	n = (*Op)(unsafe.Pointer(pOp + libc.UintptrFromInt32(-1)*32)).Fp1
	if !(n > nMaxArgs) {
		goto __17
	}
	nMaxArgs = n
__17:
	;
__14:
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 < 0) {
		goto __18
	}

	(*Op)(unsafe.Pointer(pOp)).Fp2 = *(*int32)(unsafe.Pointer(aLabel + uintptr(^(*Op)(unsafe.Pointer(pOp)).Fp2)*4))
__18:
	;
	goto __4

__4:
	;
__3:
	;
	pOp -= 32
	goto __1
__2:
	;
resolve_p2_values_loop_exit:
	if !(aLabel != 0) {
		goto __19
	}
	Xsqlite3DbNNFreeNN(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, (*Parse)(unsafe.Pointer(pParse)).FaLabel)
	(*Parse)(unsafe.Pointer(pParse)).FaLabel = uintptr(0)
__19:
	;
	(*Parse)(unsafe.Pointer(pParse)).FnLabel = 0
	*(*int32)(unsafe.Pointer(pMaxFuncArgs)) = nMaxArgs

}

func Xsqlite3VdbeCurrentAddr(tls *libc.TLS, p uintptr) int32 {
	return (*Vdbe)(unsafe.Pointer(p)).FnOp
}

func Xsqlite3VdbeTakeOpArray(tls *libc.TLS, p uintptr, pnOp uintptr, pnMaxArg uintptr) uintptr {
	var aOp uintptr = (*Vdbe)(unsafe.Pointer(p)).FaOp

	resolveP2Values(tls, p, pnMaxArg)
	*(*int32)(unsafe.Pointer(pnOp)) = (*Vdbe)(unsafe.Pointer(p)).FnOp
	(*Vdbe)(unsafe.Pointer(p)).FaOp = uintptr(0)
	return aOp
}

func Xsqlite3VdbeAddOpList(tls *libc.TLS, p uintptr, nOp int32, aOp uintptr, iLineno int32) uintptr {
	var i int32
	var pOut uintptr
	var pFirst uintptr

	if (*Vdbe)(unsafe.Pointer(p)).FnOp+nOp > (*Vdbe)(unsafe.Pointer(p)).FnOpAlloc && growOpArray(tls, p, nOp) != 0 {
		return uintptr(0)
	}
	pFirst = libc.AssignUintptr(&pOut, (*Vdbe)(unsafe.Pointer(p)).FaOp+uintptr((*Vdbe)(unsafe.Pointer(p)).FnOp)*32)
	i = 0
__1:
	if !(i < nOp) {
		goto __3
	}
	{
		(*VdbeOp)(unsafe.Pointer(pOut)).Fopcode = (*VdbeOpList)(unsafe.Pointer(aOp)).Fopcode
		(*VdbeOp)(unsafe.Pointer(pOut)).Fp1 = int32((*VdbeOpList)(unsafe.Pointer(aOp)).Fp1)
		(*VdbeOp)(unsafe.Pointer(pOut)).Fp2 = int32((*VdbeOpList)(unsafe.Pointer(aOp)).Fp2)

		if int32(Xsqlite3OpcodeProperty[(*VdbeOpList)(unsafe.Pointer(aOp)).Fopcode])&OPFLG_JUMP != 0 && int32((*VdbeOpList)(unsafe.Pointer(aOp)).Fp2) > 0 {
			*(*int32)(unsafe.Pointer(pOut + 8)) += (*Vdbe)(unsafe.Pointer(p)).FnOp
		}
		(*VdbeOp)(unsafe.Pointer(pOut)).Fp3 = int32((*VdbeOpList)(unsafe.Pointer(aOp)).Fp3)
		(*VdbeOp)(unsafe.Pointer(pOut)).Fp4type = int8(P4_NOTUSED)
		*(*uintptr)(unsafe.Pointer(pOut + 16)) = uintptr(0)
		(*VdbeOp)(unsafe.Pointer(pOut)).Fp5 = U16(0)
		(*VdbeOp)(unsafe.Pointer(pOut)).FzComment = uintptr(0)
		_ = iLineno

	}
	goto __2
__2:
	i++
	aOp += 4
	pOut += 32
	goto __1
	goto __3
__3:
	;
	*(*int32)(unsafe.Pointer(p + 144)) += nOp
	return pFirst
}

func Xsqlite3VdbeChangeOpcode(tls *libc.TLS, p uintptr, addr int32, iNewOpcode U8) {
	(*VdbeOp)(unsafe.Pointer(Xsqlite3VdbeGetOp(tls, p, addr))).Fopcode = iNewOpcode
}

func Xsqlite3VdbeChangeP1(tls *libc.TLS, p uintptr, addr int32, val int32) {
	(*VdbeOp)(unsafe.Pointer(Xsqlite3VdbeGetOp(tls, p, addr))).Fp1 = val
}

func Xsqlite3VdbeChangeP2(tls *libc.TLS, p uintptr, addr int32, val int32) {
	(*VdbeOp)(unsafe.Pointer(Xsqlite3VdbeGetOp(tls, p, addr))).Fp2 = val
}

func Xsqlite3VdbeChangeP3(tls *libc.TLS, p uintptr, addr int32, val int32) {
	(*VdbeOp)(unsafe.Pointer(Xsqlite3VdbeGetOp(tls, p, addr))).Fp3 = val
}

func Xsqlite3VdbeChangeP5(tls *libc.TLS, p uintptr, p5 U16) {
	if (*Vdbe)(unsafe.Pointer(p)).FnOp > 0 {
		(*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr((*Vdbe)(unsafe.Pointer(p)).FnOp-1)*32)).Fp5 = p5
	}
}

func Xsqlite3VdbeTypeofColumn(tls *libc.TLS, p uintptr, iDest int32) {
	var pOp uintptr = Xsqlite3VdbeGetLastOp(tls, p)
	if (*VdbeOp)(unsafe.Pointer(pOp)).Fp3 == iDest && int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Column {
		*(*U16)(unsafe.Pointer(pOp + 2)) |= U16(OPFLAG_TYPEOFARG)
	}
}

func Xsqlite3VdbeJumpHere(tls *libc.TLS, p uintptr, addr int32) {
	Xsqlite3VdbeChangeP2(tls, p, addr, (*Vdbe)(unsafe.Pointer(p)).FnOp)
}

func Xsqlite3VdbeJumpHereOrPopInst(tls *libc.TLS, p uintptr, addr int32) {
	if addr == (*Vdbe)(unsafe.Pointer(p)).FnOp-1 {
		(*Vdbe)(unsafe.Pointer(p)).FnOp--
	} else {
		Xsqlite3VdbeChangeP2(tls, p, addr, (*Vdbe)(unsafe.Pointer(p)).FnOp)
	}
}

func freeEphemeralFunction(tls *libc.TLS, db uintptr, pDef uintptr) {
	if (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_EPHEM) != U32(0) {
		Xsqlite3DbNNFreeNN(tls, db, pDef)
	}
}

func freeP4Mem(tls *libc.TLS, db uintptr, p uintptr) {
	if (*Mem)(unsafe.Pointer(p)).FszMalloc != 0 {
		Xsqlite3DbFree(tls, db, (*Mem)(unsafe.Pointer(p)).FzMalloc)
	}
	Xsqlite3DbNNFreeNN(tls, db, p)
}

func freeP4FuncCtx(tls *libc.TLS, db uintptr, p uintptr) {
	freeEphemeralFunction(tls, db, (*Sqlite3_context)(unsafe.Pointer(p)).FpFunc)
	Xsqlite3DbNNFreeNN(tls, db, p)
}

func freeP4(tls *libc.TLS, db uintptr, p4type int32, p4 uintptr) {
	switch p4type {
	case -15:
		{
			freeP4FuncCtx(tls, db, p4)
			break

		}
	case -12:
		fallthrough
	case -13:
		fallthrough
	case -6:
		fallthrough
	case -14:
		{
			if p4 != 0 {
				Xsqlite3DbNNFreeNN(tls, db, p4)
			}
			break

		}
	case -8:
		{
			if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
				Xsqlite3KeyInfoUnref(tls, p4)
			}
			break

		}
	case -7:
		{
			freeEphemeralFunction(tls, db, p4)
			break

		}
	case -10:
		{
			if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
				Xsqlite3ValueFree(tls, p4)
			} else {
				freeP4Mem(tls, db, p4)
			}
			break

		}
	case -11:
		{
			if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
				Xsqlite3VtabUnlock(tls, p4)
			}
			break

		}
	}
}

func vdbeFreeOpArray(tls *libc.TLS, db uintptr, aOp uintptr, nOp int32) {
	if aOp != 0 {
		var pOp uintptr = aOp + uintptr(nOp-1)*32
		for 1 != 0 {
			if int32((*Op)(unsafe.Pointer(pOp)).Fp4type) <= -6 {
				freeP4(tls, db, int32((*Op)(unsafe.Pointer(pOp)).Fp4type), *(*uintptr)(unsafe.Pointer(pOp + 16)))
			}
			Xsqlite3DbFree(tls, db, (*Op)(unsafe.Pointer(pOp)).FzComment)
			if pOp == aOp {
				break
			}
			pOp -= 32
		}
		Xsqlite3DbNNFreeNN(tls, db, aOp)
	}
}

func Xsqlite3VdbeLinkSubProgram(tls *libc.TLS, pVdbe uintptr, p uintptr) {
	(*SubProgram)(unsafe.Pointer(p)).FpNext = (*Vdbe)(unsafe.Pointer(pVdbe)).FpProgram
	(*Vdbe)(unsafe.Pointer(pVdbe)).FpProgram = p
}

func Xsqlite3VdbeHasSubProgram(tls *libc.TLS, pVdbe uintptr) int32 {
	return libc.Bool32((*Vdbe)(unsafe.Pointer(pVdbe)).FpProgram != uintptr(0))
}

func Xsqlite3VdbeChangeToNoop(tls *libc.TLS, p uintptr, addr int32) int32 {
	var pOp uintptr
	if (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		return 0
	}

	pOp = (*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*32
	freeP4(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, int32((*VdbeOp)(unsafe.Pointer(pOp)).Fp4type), *(*uintptr)(unsafe.Pointer(pOp + 16)))
	(*VdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(P4_NOTUSED)
	*(*uintptr)(unsafe.Pointer(pOp + 16)) = uintptr(0)
	(*VdbeOp)(unsafe.Pointer(pOp)).Fopcode = U8(OP_Noop)
	return 1
}

func Xsqlite3VdbeDeletePriorOpcode(tls *libc.TLS, p uintptr, op U8) int32 {
	if (*Vdbe)(unsafe.Pointer(p)).FnOp > 0 && int32((*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp+uintptr((*Vdbe)(unsafe.Pointer(p)).FnOp-1)*32)).Fopcode) == int32(op) {
		return Xsqlite3VdbeChangeToNoop(tls, p, (*Vdbe)(unsafe.Pointer(p)).FnOp-1)
	} else {
		return 0
	}
	return int32(0)
}

func vdbeChangeP4Full(tls *libc.TLS, p uintptr, pOp uintptr, zP4 uintptr, n int32) {
	if (*Op)(unsafe.Pointer(pOp)).Fp4type != 0 {
		freeP4(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, int32((*Op)(unsafe.Pointer(pOp)).Fp4type), *(*uintptr)(unsafe.Pointer(pOp + 16)))
		(*Op)(unsafe.Pointer(pOp)).Fp4type = int8(0)
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = uintptr(0)
	}
	if n < 0 {
		Xsqlite3VdbeChangeP4(tls, p, int32((int64(pOp)-int64((*Vdbe)(unsafe.Pointer(p)).FaOp))/32), zP4, n)
	} else {
		if n == 0 {
			n = Xsqlite3Strlen30(tls, zP4)
		}
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = Xsqlite3DbStrNDup(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, zP4, uint64(n))
		(*Op)(unsafe.Pointer(pOp)).Fp4type = int8(-6)
	}
}

func Xsqlite3VdbeChangeP4(tls *libc.TLS, p uintptr, addr int32, zP4 uintptr, n int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = zP4

	var pOp uintptr
	var db uintptr

	db = (*Vdbe)(unsafe.Pointer(p)).Fdb

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		if n != -11 {
			freeP4(tls, db, n, *(*uintptr)(unsafe.Pointer(bp)))
		}
		return
	}

	if addr < 0 {
		addr = (*Vdbe)(unsafe.Pointer(p)).FnOp - 1
	}
	pOp = (*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*32
	if n >= 0 || (*Op)(unsafe.Pointer(pOp)).Fp4type != 0 {
		vdbeChangeP4Full(tls, p, pOp, *(*uintptr)(unsafe.Pointer(bp)), n)
		return
	}
	if n == -3 {
		*(*int32)(unsafe.Pointer(pOp + 16)) = int32(*(*uintptr)(unsafe.Pointer(bp)))
		(*Op)(unsafe.Pointer(pOp)).Fp4type = int8(-3)
	} else if *(*uintptr)(unsafe.Pointer(bp)) != uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = *(*uintptr)(unsafe.Pointer(bp))
		(*Op)(unsafe.Pointer(pOp)).Fp4type = int8(n)
		if n == -11 {
			Xsqlite3VtabLock(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
}

func Xsqlite3VdbeAppendP4(tls *libc.TLS, p uintptr, pP4 uintptr, n int32) {
	var pOp uintptr

	if (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		freeP4(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, n, pP4)
	} else {
		pOp = (*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr((*Vdbe)(unsafe.Pointer(p)).FnOp-1)*32

		(*VdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(n)
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = pP4
	}
}

func Xsqlite3VdbeSetP4KeyInfo(tls *libc.TLS, pParse uintptr, pIdx uintptr) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var pKeyInfo uintptr

	pKeyInfo = Xsqlite3KeyInfoOfIndex(tls, pParse, pIdx)
	if pKeyInfo != 0 {
		Xsqlite3VdbeAppendP4(tls, v, pKeyInfo, -8)
	}
}

func vdbeVComment(tls *libc.TLS, p uintptr, zFormat uintptr, ap Va_list) {
	if (*Vdbe)(unsafe.Pointer(p)).FnOp != 0 {
		Xsqlite3DbFree(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, (*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp+uintptr((*Vdbe)(unsafe.Pointer(p)).FnOp-1)*32)).FzComment)
		(*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr((*Vdbe)(unsafe.Pointer(p)).FnOp-1)*32)).FzComment = Xsqlite3VMPrintf(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, zFormat, ap)
	}
}

func Xsqlite3VdbeComment(tls *libc.TLS, p uintptr, zFormat uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	if p != 0 {
		ap = va
		vdbeVComment(tls, p, zFormat, ap)
		_ = ap
	}
}

func Xsqlite3VdbeNoopComment(tls *libc.TLS, p uintptr, zFormat uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	if p != 0 {
		Xsqlite3VdbeAddOp0(tls, p, OP_Noop)
		ap = va
		vdbeVComment(tls, p, zFormat, ap)
		_ = ap
	}
}

func Xsqlite3VdbeGetOp(tls *libc.TLS, p uintptr, addr int32) uintptr {
	if (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		return uintptr(unsafe.Pointer(&dummy))
	} else {
		return (*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*32
	}
	return uintptr(0)
}

var dummy VdbeOp

func Xsqlite3VdbeGetLastOp(tls *libc.TLS, p uintptr) uintptr {
	return Xsqlite3VdbeGetOp(tls, p, (*Vdbe)(unsafe.Pointer(p)).FnOp-1)
}

func translateP(tls *libc.TLS, c uint8, pOp uintptr) int32 {
	if int32(c) == '1' {
		return (*Op)(unsafe.Pointer(pOp)).Fp1
	}
	if int32(c) == '2' {
		return (*Op)(unsafe.Pointer(pOp)).Fp2
	}
	if int32(c) == '3' {
		return (*Op)(unsafe.Pointer(pOp)).Fp3
	}
	if int32(c) == '4' {
		return *(*int32)(unsafe.Pointer(pOp + 16))
	}
	return int32((*Op)(unsafe.Pointer(pOp)).Fp5)
}

func Xsqlite3VdbeDisplayComment(tls *libc.TLS, db uintptr, pOp uintptr, zP4 uintptr) uintptr {
	bp := tls.Alloc(154)
	defer tls.Free(154)

	var zOpName uintptr
	var zSynopsis uintptr
	var nOpName int32
	var ii int32

	Xsqlite3StrAccumInit(tls, bp+72, uintptr(0), uintptr(0), 0, SQLITE_MAX_LENGTH)
	zOpName = Xsqlite3OpcodeName(tls, int32((*Op)(unsafe.Pointer(pOp)).Fopcode))
	nOpName = Xsqlite3Strlen30(tls, zOpName)
	if *(*uint8)(unsafe.Pointer(zOpName + uintptr(nOpName+1))) != 0 {
		var seenCom int32 = 0
		var c uint8
		zSynopsis = zOpName + uintptr(nOpName) + uintptr(1)
		if libc.Xstrncmp(tls, zSynopsis, ts+7819, uint64(3)) == 0 {
			Xsqlite3_snprintf(tls, int32(unsafe.Sizeof([50]uint8{})), bp+104, ts+7823, libc.VaList(bp, zSynopsis+uintptr(3)))
			zSynopsis = bp + 104
		}
		for ii = 0; int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(zSynopsis + uintptr(ii))))) != 0; ii++ {
			if int32(c) == 'P' {
				c = *(*uint8)(unsafe.Pointer(zSynopsis + uintptr(libc.PreIncInt32(&ii, 1))))
				if int32(c) == '4' {
					Xsqlite3_str_appendall(tls, bp+72, zP4)
				} else if int32(c) == 'X' {
					if (*Op)(unsafe.Pointer(pOp)).FzComment != 0 && *(*uint8)(unsafe.Pointer((*Op)(unsafe.Pointer(pOp)).FzComment)) != 0 {
						Xsqlite3_str_appendall(tls, bp+72, (*Op)(unsafe.Pointer(pOp)).FzComment)
						seenCom = 1
						break
					}
				} else {
					var v1 int32 = translateP(tls, c, pOp)
					var v2 int32
					if libc.Xstrncmp(tls, zSynopsis+uintptr(ii)+uintptr(1), ts+7837, uint64(2)) == 0 {
						ii = ii + 3
						v2 = translateP(tls, *(*uint8)(unsafe.Pointer(zSynopsis + uintptr(ii))), pOp)
						if libc.Xstrncmp(tls, zSynopsis+uintptr(ii)+uintptr(1), ts+7840, uint64(2)) == 0 {
							ii = ii + 2
							v2++
						}
						if v2 < 2 {
							Xsqlite3_str_appendf(tls, bp+72, ts+7843, libc.VaList(bp+8, v1))
						} else {
							Xsqlite3_str_appendf(tls, bp+72, ts+7846, libc.VaList(bp+16, v1, v1+v2-1))
						}
					} else if libc.Xstrncmp(tls, zSynopsis+uintptr(ii)+uintptr(1), ts+7853, uint64(3)) == 0 {
						var pCtx uintptr = *(*uintptr)(unsafe.Pointer(pOp + 16))
						if int32((*Op)(unsafe.Pointer(pOp)).Fp4type) != -15 || int32((*Sqlite3_context)(unsafe.Pointer(pCtx)).Fargc) == 1 {
							Xsqlite3_str_appendf(tls, bp+72, ts+7843, libc.VaList(bp+32, v1))
						} else if int32((*Sqlite3_context)(unsafe.Pointer(pCtx)).Fargc) > 1 {
							Xsqlite3_str_appendf(tls, bp+72, ts+7846, libc.VaList(bp+40, v1, v1+int32((*Sqlite3_context)(unsafe.Pointer(pCtx)).Fargc)-1))
						} else if int32((*StrAccum)(unsafe.Pointer(bp+72)).FaccError) == 0 {
							*(*U32)(unsafe.Pointer(bp + 72 + 24)) -= U32(2)
							ii++
						}
						ii = ii + 3
					} else {
						Xsqlite3_str_appendf(tls, bp+72, ts+7843, libc.VaList(bp+56, v1))
						if libc.Xstrncmp(tls, zSynopsis+uintptr(ii)+uintptr(1), ts+7857, uint64(4)) == 0 && (*Op)(unsafe.Pointer(pOp)).Fp3 == 0 {
							ii = ii + 4
						}
					}
				}
			} else {
				Xsqlite3_str_appendchar(tls, bp+72, 1, c)
			}
		}
		if !(seenCom != 0) && (*Op)(unsafe.Pointer(pOp)).FzComment != 0 {
			Xsqlite3_str_appendf(tls, bp+72, ts+7862, libc.VaList(bp+64, (*Op)(unsafe.Pointer(pOp)).FzComment))
		}
	} else if (*Op)(unsafe.Pointer(pOp)).FzComment != 0 {
		Xsqlite3_str_appendall(tls, bp+72, (*Op)(unsafe.Pointer(pOp)).FzComment)
	}
	if int32((*StrAccum)(unsafe.Pointer(bp+72)).FaccError)&SQLITE_NOMEM != 0 && db != uintptr(0) {
		Xsqlite3OomFault(tls, db)
	}
	return Xsqlite3StrAccumFinish(tls, bp+72)
}

func Xsqlite3VdbeDisplayP4(tls *libc.TLS, db uintptr, pOp uintptr) uintptr {
	bp := tls.Alloc(176)
	defer tls.Free(176)

	var zP4 uintptr = uintptr(0)

	Xsqlite3StrAccumInit(tls, bp+144, uintptr(0), uintptr(0), 0, SQLITE_MAX_LENGTH)
	switch int32((*Op)(unsafe.Pointer(pOp)).Fp4type) {
	case -8:
		{
			var j int32
			var pKeyInfo uintptr = *(*uintptr)(unsafe.Pointer(pOp + 16))

			Xsqlite3_str_appendf(tls, bp+144, ts+7867, libc.VaList(bp, int32((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)))
			for j = 0; j < int32((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField); j++ {
				var pColl uintptr = *(*uintptr)(unsafe.Pointer(pKeyInfo + 32 + uintptr(j)*8))
				var zColl uintptr
				if pColl != 0 {
					zColl = (*CollSeq)(unsafe.Pointer(pColl)).FzName
				} else {
					zColl = ts + 1636
				}
				if libc.Xstrcmp(tls, zColl, ts+1181) == 0 {
					zColl = ts + 7872
				}
				Xsqlite3_str_appendf(tls, bp+144, ts+7874,
					libc.VaList(bp+8, func() uintptr {
						if int32(*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(j))))&KEYINFO_ORDER_DESC != 0 {
							return ts + 7812
						}
						return ts + 1636
					}(),
						func() uintptr {
							if int32(*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(j))))&KEYINFO_ORDER_BIGNULL != 0 {
								return ts + 7882
							}
							return ts + 1636
						}(),
						zColl))
			}
			Xsqlite3_str_append(tls, bp+144, ts+7885, 1)
			break

		}
	case -2:
		{
			var pColl uintptr = *(*uintptr)(unsafe.Pointer(pOp + 16))

			Xsqlite3_str_appendf(tls, bp+144, ts+7887, libc.VaList(bp+32, (*CollSeq)(unsafe.Pointer(pColl)).FzName,
				encnames[(*CollSeq)(unsafe.Pointer(pColl)).Fenc]))
			break

		}
	case -7:
		{
			var pDef uintptr = *(*uintptr)(unsafe.Pointer(pOp + 16))
			Xsqlite3_str_appendf(tls, bp+144, ts+7896, libc.VaList(bp+48, (*FuncDef)(unsafe.Pointer(pDef)).FzName, int32((*FuncDef)(unsafe.Pointer(pDef)).FnArg)))
			break

		}
	case -15:
		{
			var pDef uintptr = (*Sqlite3_context)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpFunc
			Xsqlite3_str_appendf(tls, bp+144, ts+7896, libc.VaList(bp+64, (*FuncDef)(unsafe.Pointer(pDef)).FzName, int32((*FuncDef)(unsafe.Pointer(pDef)).FnArg)))
			break

		}
	case -13:
		{
			Xsqlite3_str_appendf(tls, bp+144, ts+1416, libc.VaList(bp+80, *(*I64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16))))))
			break

		}
	case -3:
		{
			Xsqlite3_str_appendf(tls, bp+144, ts+7843, libc.VaList(bp+88, *(*int32)(unsafe.Pointer(pOp + 16))))
			break

		}
	case -12:
		{
			Xsqlite3_str_appendf(tls, bp+144, ts+1410, libc.VaList(bp+96, *(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16))))))
			break

		}
	case -10:
		{
			var pMem uintptr = *(*uintptr)(unsafe.Pointer(pOp + 16))
			if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Str != 0 {
				zP4 = (*Mem)(unsafe.Pointer(pMem)).Fz
			} else if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Int|MEM_IntReal) != 0 {
				Xsqlite3_str_appendf(tls, bp+144, ts+1416, libc.VaList(bp+104, *(*I64)(unsafe.Pointer(pMem))))
			} else if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Real != 0 {
				Xsqlite3_str_appendf(tls, bp+144, ts+1410, libc.VaList(bp+112, *(*float64)(unsafe.Pointer(pMem))))
			} else if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Null != 0 {
				zP4 = ts + 1637
			} else {
				zP4 = ts + 7903
			}
			break

		}
	case -11:
		{
			var pVtab uintptr = (*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
			Xsqlite3_str_appendf(tls, bp+144, ts+7910, libc.VaList(bp+120, pVtab))
			break

		}
	case -14:
		{
			var i U32
			var ai uintptr = *(*uintptr)(unsafe.Pointer(pOp + 16))
			var n U32 = *(*U32)(unsafe.Pointer(ai))

			for i = U32(1); i <= n; i++ {
				Xsqlite3_str_appendf(tls, bp+144, ts+7918, libc.VaList(bp+128, func() int32 {
					if i == U32(1) {
						return '['
					}
					return ','
				}(), *(*U32)(unsafe.Pointer(ai + uintptr(i)*4))))
			}
			Xsqlite3_str_append(tls, bp+144, ts+7923, 1)
			break

		}
	case -4:
		{
			zP4 = ts + 7925
			break

		}
	case -5:
		{
			zP4 = (*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FzName
			break

		}
	default:
		{
			zP4 = *(*uintptr)(unsafe.Pointer(pOp + 16))

		}
	}
	if zP4 != 0 {
		Xsqlite3_str_appendall(tls, bp+144, zP4)
	}
	if int32((*StrAccum)(unsafe.Pointer(bp+144)).FaccError)&SQLITE_NOMEM != 0 {
		Xsqlite3OomFault(tls, db)
	}
	return Xsqlite3StrAccumFinish(tls, bp+144)
}

var encnames = [4]uintptr{ts + 7933, ts + 7935, ts + 7937, ts + 7942}

func Xsqlite3VdbeUsesBtree(tls *libc.TLS, p uintptr, i int32) {
	*(*YDbMask)(unsafe.Pointer(p + 204)) |= YDbMask(1) << i
	if i != 1 && Xsqlite3BtreeSharable(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FaDb+uintptr(i)*32)).FpBt) != 0 {
		*(*YDbMask)(unsafe.Pointer(p + 208)) |= YDbMask(1) << i
	}
}

func Xsqlite3VdbeEnter(tls *libc.TLS, p uintptr) {
	var i int32
	var db uintptr
	var aDb uintptr
	var nDb int32
	if (*Vdbe)(unsafe.Pointer(p)).FlockMask == YDbMask(0) {
		return
	}
	db = (*Vdbe)(unsafe.Pointer(p)).Fdb
	aDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb
	nDb = (*Sqlite3)(unsafe.Pointer(db)).FnDb
	for i = 0; i < nDb; i++ {
		if i != 1 && (*Vdbe)(unsafe.Pointer(p)).FlockMask&(YDbMask(1)<<i) != YDbMask(0) && (*Db)(unsafe.Pointer(aDb+uintptr(i)*32)).FpBt != uintptr(0) {
			Xsqlite3BtreeEnter(tls, (*Db)(unsafe.Pointer(aDb+uintptr(i)*32)).FpBt)
		}
	}
}

func vdbeLeave(tls *libc.TLS, p uintptr) {
	var i int32
	var db uintptr
	var aDb uintptr
	var nDb int32
	db = (*Vdbe)(unsafe.Pointer(p)).Fdb
	aDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb
	nDb = (*Sqlite3)(unsafe.Pointer(db)).FnDb
	for i = 0; i < nDb; i++ {
		if i != 1 && (*Vdbe)(unsafe.Pointer(p)).FlockMask&(YDbMask(1)<<i) != YDbMask(0) && (*Db)(unsafe.Pointer(aDb+uintptr(i)*32)).FpBt != uintptr(0) {
			Xsqlite3BtreeLeave(tls, (*Db)(unsafe.Pointer(aDb+uintptr(i)*32)).FpBt)
		}
	}
}

func Xsqlite3VdbeLeave(tls *libc.TLS, p uintptr) {
	if (*Vdbe)(unsafe.Pointer(p)).FlockMask == YDbMask(0) {
		return
	}
	vdbeLeave(tls, p)
}

func initMemArray(tls *libc.TLS, p uintptr, N int32, db uintptr, flags U16) {
	if N > 0 {
		for __ccgo := true; __ccgo; __ccgo = libc.PreDecInt32(&N, 1) > 0 {
			(*Mem)(unsafe.Pointer(p)).Fflags = flags
			(*Mem)(unsafe.Pointer(p)).Fdb = db
			(*Mem)(unsafe.Pointer(p)).FszMalloc = 0
			p += 56
		}
	}
}

func releaseMemArray(tls *libc.TLS, p uintptr, N int32) {
	if p != 0 && N != 0 {
		var pEnd uintptr = p + uintptr(N)*56
		var db uintptr = (*Mem)(unsafe.Pointer(p)).Fdb
		if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed != 0 {
			for __ccgo := true; __ccgo; __ccgo = libc.PreIncUintptr(&p, 56) < pEnd {
				if (*Mem)(unsafe.Pointer(p)).FszMalloc != 0 {
					Xsqlite3DbFree(tls, db, (*Mem)(unsafe.Pointer(p)).FzMalloc)
				}
			}
			return
		}
		for __ccgo1 := true; __ccgo1; __ccgo1 = libc.PreIncUintptr(&p, 56) < pEnd {
			if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_Agg|MEM_Dyn) != 0 {
				Xsqlite3VdbeMemRelease(tls, p)
				(*Mem)(unsafe.Pointer(p)).Fflags = U16(MEM_Undefined)
			} else if (*Mem)(unsafe.Pointer(p)).FszMalloc != 0 {
				Xsqlite3DbNNFreeNN(tls, db, (*Mem)(unsafe.Pointer(p)).FzMalloc)
				(*Mem)(unsafe.Pointer(p)).FszMalloc = 0
				(*Mem)(unsafe.Pointer(p)).Fflags = U16(MEM_Undefined)
			}
		}
	}
}

func Xsqlite3VdbeFrameMemDel(tls *libc.TLS, pArg uintptr) {
	var pFrame uintptr = pArg

	(*VdbeFrame)(unsafe.Pointer(pFrame)).FpParent = (*Vdbe)(unsafe.Pointer((*VdbeFrame)(unsafe.Pointer(pFrame)).Fv)).FpDelFrame
	(*Vdbe)(unsafe.Pointer((*VdbeFrame)(unsafe.Pointer(pFrame)).Fv)).FpDelFrame = pFrame
}

func Xsqlite3VdbeNextOpcode(tls *libc.TLS, p uintptr, pSub uintptr, eMode int32, piPc uintptr, piAddr uintptr, paOp uintptr) int32 {
	var nRow int32
	var nSub int32 = 0
	var apSub uintptr = uintptr(0)
	var i int32
	var rc int32 = SQLITE_OK
	var aOp uintptr = uintptr(0)
	var iPc int32

	nRow = (*Vdbe)(unsafe.Pointer(p)).FnOp
	if pSub != uintptr(0) {
		if int32((*Mem)(unsafe.Pointer(pSub)).Fflags)&MEM_Blob != 0 {
			nSub = int32(uint64((*Mem)(unsafe.Pointer(pSub)).Fn) / uint64(unsafe.Sizeof(uintptr(0))))
			apSub = (*Mem)(unsafe.Pointer(pSub)).Fz
		}
		for i = 0; i < nSub; i++ {
			nRow = nRow + (*SubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apSub + uintptr(i)*8)))).FnOp
		}
	}
	iPc = *(*int32)(unsafe.Pointer(piPc))
	for 1 != 0 {
		i = libc.PostIncInt32(&iPc, 1)
		if i >= nRow {
			(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
			rc = SQLITE_DONE
			break
		}
		if i < (*Vdbe)(unsafe.Pointer(p)).FnOp {
			aOp = (*Vdbe)(unsafe.Pointer(p)).FaOp
		} else {
			var j int32
			i = i - (*Vdbe)(unsafe.Pointer(p)).FnOp

			for j = 0; i >= (*SubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apSub + uintptr(j)*8)))).FnOp; j++ {
				i = i - (*SubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apSub + uintptr(j)*8)))).FnOp

			}
			aOp = (*SubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(apSub + uintptr(j)*8)))).FaOp
		}

		if pSub != uintptr(0) && int32((*Op)(unsafe.Pointer(aOp+uintptr(i)*32)).Fp4type) == -4 {
			var nByte int32 = int32(uint64(nSub+1) * uint64(unsafe.Sizeof(uintptr(0))))
			var j int32
			for j = 0; j < nSub; j++ {
				if *(*uintptr)(unsafe.Pointer(apSub + uintptr(j)*8)) == *(*uintptr)(unsafe.Pointer(aOp + uintptr(i)*32 + 16)) {
					break
				}
			}
			if j == nSub {
				(*Vdbe)(unsafe.Pointer(p)).Frc = Xsqlite3VdbeMemGrow(tls, pSub, nByte, libc.Bool32(nSub != 0))
				if (*Vdbe)(unsafe.Pointer(p)).Frc != SQLITE_OK {
					rc = SQLITE_ERROR
					break
				}
				apSub = (*Mem)(unsafe.Pointer(pSub)).Fz
				*(*uintptr)(unsafe.Pointer(apSub + uintptr(libc.PostIncInt32(&nSub, 1))*8)) = *(*uintptr)(unsafe.Pointer(aOp + uintptr(i)*32 + 16))
				(*Mem)(unsafe.Pointer(pSub)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pSub)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Blob)
				(*Mem)(unsafe.Pointer(pSub)).Fn = int32(uint64(nSub) * uint64(unsafe.Sizeof(uintptr(0))))
				nRow = nRow + (*SubProgram)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aOp + uintptr(i)*32 + 16)))).FnOp
			}
		}
		if eMode == 0 {
			break
		}
		if eMode == 2 {
			var pOp uintptr = aOp + uintptr(i)*32
			if int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_OpenRead {
				break
			}
			if int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_OpenWrite && int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_P2ISREG == 0 {
				break
			}
			if int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_ReopenIdx {
				break
			}
		} else {
			if int32((*Op)(unsafe.Pointer(aOp+uintptr(i)*32)).Fopcode) == OP_Explain {
				break
			}
			if int32((*Op)(unsafe.Pointer(aOp+uintptr(i)*32)).Fopcode) == OP_Init && iPc > 1 {
				break
			}
		}
	}
	*(*int32)(unsafe.Pointer(piPc)) = iPc
	*(*int32)(unsafe.Pointer(piAddr)) = i
	*(*uintptr)(unsafe.Pointer(paOp)) = aOp
	return rc
}

func Xsqlite3VdbeFrameDelete(tls *libc.TLS, p uintptr) {
	var i int32
	var aMem uintptr = p + 112
	var apCsr uintptr = aMem + uintptr((*VdbeFrame)(unsafe.Pointer(p)).FnChildMem)*56

	for i = 0; i < (*VdbeFrame)(unsafe.Pointer(p)).FnChildCsr; i++ {
		if *(*uintptr)(unsafe.Pointer(apCsr + uintptr(i)*8)) != 0 {
			Xsqlite3VdbeFreeCursorNN(tls, (*VdbeFrame)(unsafe.Pointer(p)).Fv, *(*uintptr)(unsafe.Pointer(apCsr + uintptr(i)*8)))
		}
	}
	releaseMemArray(tls, aMem, (*VdbeFrame)(unsafe.Pointer(p)).FnChildMem)
	Xsqlite3VdbeDeleteAuxData(tls, (*Vdbe)(unsafe.Pointer((*VdbeFrame)(unsafe.Pointer(p)).Fv)).Fdb, p+64, -1, 0)
	Xsqlite3DbFree(tls, (*Vdbe)(unsafe.Pointer((*VdbeFrame)(unsafe.Pointer(p)).Fv)).Fdb, p)
}

func Xsqlite3VdbeList(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pSub uintptr = uintptr(0)
	var db uintptr = (*Vdbe)(unsafe.Pointer(p)).Fdb

	var rc int32 = SQLITE_OK
	var pMem uintptr = (*Vdbe)(unsafe.Pointer(p)).FaMem + 1*56
	var bListSubprogs int32 = libc.Bool32(int32(*(*uint8)(unsafe.Pointer(p + 200))&0xc>>2) == 1 || (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_TriggerEQP) != uint64(0))

	var pOp uintptr

	releaseMemArray(tls, pMem, 8)

	if (*Vdbe)(unsafe.Pointer(p)).Frc == SQLITE_NOMEM {
		Xsqlite3OomFault(tls, db)
		return SQLITE_ERROR
	}

	if bListSubprogs != 0 {
		pSub = (*Vdbe)(unsafe.Pointer(p)).FaMem + 9*56
	} else {
		pSub = uintptr(0)
	}

	rc = Xsqlite3VdbeNextOpcode(tls, p, pSub, libc.Bool32(int32(*(*uint8)(unsafe.Pointer(p + 200))&0xc>>2) == 2), p+48, bp, bp+8)

	if rc == SQLITE_OK {
		pOp = *(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(*(*int32)(unsafe.Pointer(bp)))*32
		if libc.AtomicLoadNInt32(db+432, 0) != 0 {
			(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_INTERRUPT
			rc = SQLITE_ERROR
			Xsqlite3VdbeError(tls, p, Xsqlite3ErrStr(tls, (*Vdbe)(unsafe.Pointer(p)).Frc), 0)
		} else {
			var zP4 uintptr = Xsqlite3VdbeDisplayP4(tls, db, pOp)
			if int32(*(*uint8)(unsafe.Pointer(p + 200))&0xc>>2) == 2 {
				Xsqlite3VdbeMemSetInt64(tls, pMem, int64((*Op)(unsafe.Pointer(pOp)).Fp1))
				Xsqlite3VdbeMemSetInt64(tls, pMem+uintptr(1)*56, int64((*Op)(unsafe.Pointer(pOp)).Fp2))
				Xsqlite3VdbeMemSetInt64(tls, pMem+uintptr(2)*56, int64((*Op)(unsafe.Pointer(pOp)).Fp3))
				Xsqlite3VdbeMemSetStr(tls, pMem+uintptr(3)*56, zP4, int64(-1), uint8(SQLITE_UTF8), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
				(*Vdbe)(unsafe.Pointer(p)).FnResColumn = U16(4)
			} else {
				Xsqlite3VdbeMemSetInt64(tls, pMem+uintptr(0)*56, int64(*(*int32)(unsafe.Pointer(bp))))
				Xsqlite3VdbeMemSetStr(tls, pMem+uintptr(1)*56, Xsqlite3OpcodeName(tls, int32((*Op)(unsafe.Pointer(pOp)).Fopcode)),
					int64(-1), uint8(SQLITE_UTF8), uintptr(0))
				Xsqlite3VdbeMemSetInt64(tls, pMem+uintptr(2)*56, int64((*Op)(unsafe.Pointer(pOp)).Fp1))
				Xsqlite3VdbeMemSetInt64(tls, pMem+uintptr(3)*56, int64((*Op)(unsafe.Pointer(pOp)).Fp2))
				Xsqlite3VdbeMemSetInt64(tls, pMem+uintptr(4)*56, int64((*Op)(unsafe.Pointer(pOp)).Fp3))

				Xsqlite3VdbeMemSetInt64(tls, pMem+uintptr(6)*56, int64((*Op)(unsafe.Pointer(pOp)).Fp5))
				{
					var zCom uintptr = Xsqlite3VdbeDisplayComment(tls, db, pOp, zP4)
					Xsqlite3VdbeMemSetStr(tls, pMem+uintptr(7)*56, zCom, int64(-1), uint8(SQLITE_UTF8), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))

				}
				Xsqlite3VdbeMemSetStr(tls, pMem+uintptr(5)*56, zP4, int64(-1), uint8(SQLITE_UTF8), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
				(*Vdbe)(unsafe.Pointer(p)).FnResColumn = U16(8)
			}
			(*Vdbe)(unsafe.Pointer(p)).FpResultRow = pMem
			if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
				rc = SQLITE_ERROR
			} else {
				(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
				rc = SQLITE_ROW
			}
		}
	}
	return rc
}

type ReusableSpace = struct {
	FpSpace  uintptr
	FnFree   Sqlite3_int64
	FnNeeded Sqlite3_int64
}

func allocSpace(tls *libc.TLS, p uintptr, pBuf uintptr, nByte Sqlite3_int64) uintptr {
	if pBuf == uintptr(0) {
		nByte = nByte
		if nByte <= (*ReusableSpace)(unsafe.Pointer(p)).FnFree {
			*(*Sqlite3_int64)(unsafe.Pointer(p + 8)) -= nByte
			pBuf = (*ReusableSpace)(unsafe.Pointer(p)).FpSpace + uintptr((*ReusableSpace)(unsafe.Pointer(p)).FnFree)
		} else {
			*(*Sqlite3_int64)(unsafe.Pointer(p + 16)) += nByte
		}
	}

	return pBuf
}

func Xsqlite3VdbeRewind(tls *libc.TLS, p uintptr) {
	(*Vdbe)(unsafe.Pointer(p)).FeVdbeState = U8(VDBE_READY_STATE)

	(*Vdbe)(unsafe.Pointer(p)).Fpc = -1
	(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
	(*Vdbe)(unsafe.Pointer(p)).FerrorAction = U8(OE_Abort)
	(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
	(*Vdbe)(unsafe.Pointer(p)).FcacheCtr = U32(1)
	(*Vdbe)(unsafe.Pointer(p)).FminWriteFileFormat = U8(255)
	(*Vdbe)(unsafe.Pointer(p)).FiStatement = 0
	(*Vdbe)(unsafe.Pointer(p)).FnFkConstraint = int64(0)
}

func Xsqlite3VdbeMakeReady(tls *libc.TLS, p uintptr, pParse uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var db uintptr
	var nVar int32
	var nMem int32
	var nCursor int32

	var n int32

	(*Vdbe)(unsafe.Pointer(p)).FpVList = (*Parse)(unsafe.Pointer(pParse)).FpVList
	(*Parse)(unsafe.Pointer(pParse)).FpVList = uintptr(0)
	db = (*Vdbe)(unsafe.Pointer(p)).Fdb

	nVar = int32((*Parse)(unsafe.Pointer(pParse)).FnVar)
	nMem = (*Parse)(unsafe.Pointer(pParse)).FnMem
	nCursor = (*Parse)(unsafe.Pointer(pParse)).FnTab
	*(*int32)(unsafe.Pointer(bp)) = (*Parse)(unsafe.Pointer(pParse)).FnMaxArg

	nMem = nMem + nCursor
	if nCursor == 0 && nMem > 0 {
		nMem++
	}

	n = int32(uint64(unsafe.Sizeof(Op{})) * uint64((*Vdbe)(unsafe.Pointer(p)).FnOp))
	(*ReusableSpace)(unsafe.Pointer(bp + 8)).FpSpace = (*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr(n)

	(*ReusableSpace)(unsafe.Pointer(bp + 8)).FnFree = Sqlite3_int64(((*Parse)(unsafe.Pointer(pParse)).FszOpAlloc - n) & libc.CplInt32(7))

	resolveP2Values(tls, p, bp)
	libc.SetBitFieldPtr8Uint32(p+200, Bft(U8(libc.Bool32((*Parse)(unsafe.Pointer(pParse)).FisMultiWrite != 0 && (*Parse)(unsafe.Pointer(pParse)).FmayAbort != 0))), 5, 0x20)
	if (*Parse)(unsafe.Pointer(pParse)).Fexplain != 0 {
		var iFirst int32
		var mx int32
		var i int32
		if nMem < 10 {
			nMem = 10
		}
		libc.SetBitFieldPtr8Uint32(p+200, Bft((*Parse)(unsafe.Pointer(pParse)).Fexplain), 2, 0xc)
		if int32((*Parse)(unsafe.Pointer(pParse)).Fexplain) == 2 {
			Xsqlite3VdbeSetNumCols(tls, p, 4)
			iFirst = 8
			mx = 12
		} else {
			Xsqlite3VdbeSetNumCols(tls, p, 8)
			iFirst = 0
			mx = 8
		}
		for i = iFirst; i < mx; i++ {
			Xsqlite3VdbeSetColName(tls, p, i-iFirst, COLNAME_NAME,
				azColName[i], uintptr(0))
		}
	}
	libc.SetBitFieldPtr8Uint32(p+200, Bft(0), 0, 0x3)

	(*ReusableSpace)(unsafe.Pointer(bp + 8)).FnNeeded = int64(0)
	(*Vdbe)(unsafe.Pointer(p)).FaMem = allocSpace(tls, bp+8, uintptr(0), int64(uint64(nMem)*uint64(unsafe.Sizeof(Mem{}))))
	(*Vdbe)(unsafe.Pointer(p)).FaVar = allocSpace(tls, bp+8, uintptr(0), int64(uint64(nVar)*uint64(unsafe.Sizeof(Mem{}))))
	(*Vdbe)(unsafe.Pointer(p)).FapArg = allocSpace(tls, bp+8, uintptr(0), int64(uint64(*(*int32)(unsafe.Pointer(bp)))*uint64(unsafe.Sizeof(uintptr(0)))))
	(*Vdbe)(unsafe.Pointer(p)).FapCsr = allocSpace(tls, bp+8, uintptr(0), int64(uint64(nCursor)*uint64(unsafe.Sizeof(uintptr(0)))))
	if (*ReusableSpace)(unsafe.Pointer(bp+8)).FnNeeded != 0 {
		(*ReusableSpace)(unsafe.Pointer(bp + 8)).FpSpace = libc.AssignPtrUintptr(p+256, Xsqlite3DbMallocRawNN(tls, db, uint64((*ReusableSpace)(unsafe.Pointer(bp+8)).FnNeeded)))
		(*ReusableSpace)(unsafe.Pointer(bp + 8)).FnFree = (*ReusableSpace)(unsafe.Pointer(bp + 8)).FnNeeded
		if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
			(*Vdbe)(unsafe.Pointer(p)).FaMem = allocSpace(tls, bp+8, (*Vdbe)(unsafe.Pointer(p)).FaMem, int64(uint64(nMem)*uint64(unsafe.Sizeof(Mem{}))))
			(*Vdbe)(unsafe.Pointer(p)).FaVar = allocSpace(tls, bp+8, (*Vdbe)(unsafe.Pointer(p)).FaVar, int64(uint64(nVar)*uint64(unsafe.Sizeof(Mem{}))))
			(*Vdbe)(unsafe.Pointer(p)).FapArg = allocSpace(tls, bp+8, (*Vdbe)(unsafe.Pointer(p)).FapArg, int64(uint64(*(*int32)(unsafe.Pointer(bp)))*uint64(unsafe.Sizeof(uintptr(0)))))
			(*Vdbe)(unsafe.Pointer(p)).FapCsr = allocSpace(tls, bp+8, (*Vdbe)(unsafe.Pointer(p)).FapCsr, int64(uint64(nCursor)*uint64(unsafe.Sizeof(uintptr(0)))))
		}
	}

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*Vdbe)(unsafe.Pointer(p)).FnVar = int16(0)
		(*Vdbe)(unsafe.Pointer(p)).FnCursor = 0
		(*Vdbe)(unsafe.Pointer(p)).FnMem = 0
	} else {
		(*Vdbe)(unsafe.Pointer(p)).FnCursor = nCursor
		(*Vdbe)(unsafe.Pointer(p)).FnVar = YnVar(nVar)
		initMemArray(tls, (*Vdbe)(unsafe.Pointer(p)).FaVar, nVar, db, uint16(MEM_Null))
		(*Vdbe)(unsafe.Pointer(p)).FnMem = nMem
		initMemArray(tls, (*Vdbe)(unsafe.Pointer(p)).FaMem, nMem, db, uint16(MEM_Undefined))
		libc.Xmemset(tls, (*Vdbe)(unsafe.Pointer(p)).FapCsr, 0, uint64(nCursor)*uint64(unsafe.Sizeof(uintptr(0))))
	}
	Xsqlite3VdbeRewind(tls, p)
}

var azColName = [12]uintptr{
	ts + 7947, ts + 7952, ts + 7959, ts + 7962, ts + 7965, ts + 7968, ts + 7971, ts + 7974,
	ts + 7982, ts + 7985, ts + 7992, ts + 8000,
}

func Xsqlite3VdbeFreeCursor(tls *libc.TLS, p uintptr, pCx uintptr) {
	if pCx != 0 {
		Xsqlite3VdbeFreeCursorNN(tls, p, pCx)
	}
}

func Xsqlite3VdbeFreeCursorNN(tls *libc.TLS, p uintptr, pCx uintptr) {
	switch int32((*VdbeCursor)(unsafe.Pointer(pCx)).FeCurType) {
	case CURTYPE_SORTER:
		{
			Xsqlite3VdbeSorterClose(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, pCx)
			break

		}
	case CURTYPE_BTREE:
		{
			Xsqlite3BtreeCloseCursor(tls, *(*uintptr)(unsafe.Pointer(pCx + 48)))
			break

		}
	case CURTYPE_VTAB:
		{
			var pVCur uintptr = *(*uintptr)(unsafe.Pointer(pCx + 48))
			var pModule uintptr = (*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(pVCur)).FpVtab)).FpModule

			(*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(pVCur)).FpVtab)).FnRef--
			(*struct {
				f func(*libc.TLS, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule)).FxClose})).f(tls, pVCur)
			break

		}
	}
}

func closeCursorsInFrame(tls *libc.TLS, p uintptr) {
	var i int32
	for i = 0; i < (*Vdbe)(unsafe.Pointer(p)).FnCursor; i++ {
		var pC uintptr = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr(i)*8))
		if pC != 0 {
			Xsqlite3VdbeFreeCursorNN(tls, p, pC)
			*(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr(i)*8)) = uintptr(0)
		}
	}
}

func Xsqlite3VdbeFrameRestore(tls *libc.TLS, pFrame uintptr) int32 {
	var v uintptr = (*VdbeFrame)(unsafe.Pointer(pFrame)).Fv
	closeCursorsInFrame(tls, v)
	(*Vdbe)(unsafe.Pointer(v)).FaOp = (*VdbeFrame)(unsafe.Pointer(pFrame)).FaOp
	(*Vdbe)(unsafe.Pointer(v)).FnOp = (*VdbeFrame)(unsafe.Pointer(pFrame)).FnOp
	(*Vdbe)(unsafe.Pointer(v)).FaMem = (*VdbeFrame)(unsafe.Pointer(pFrame)).FaMem
	(*Vdbe)(unsafe.Pointer(v)).FnMem = (*VdbeFrame)(unsafe.Pointer(pFrame)).FnMem
	(*Vdbe)(unsafe.Pointer(v)).FapCsr = (*VdbeFrame)(unsafe.Pointer(pFrame)).FapCsr
	(*Vdbe)(unsafe.Pointer(v)).FnCursor = (*VdbeFrame)(unsafe.Pointer(pFrame)).FnCursor
	(*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).Fdb)).FlastRowid = (*VdbeFrame)(unsafe.Pointer(pFrame)).FlastRowid
	(*Vdbe)(unsafe.Pointer(v)).FnChange = (*VdbeFrame)(unsafe.Pointer(pFrame)).FnChange
	(*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).Fdb)).FnChange = (*VdbeFrame)(unsafe.Pointer(pFrame)).FnDbChange
	Xsqlite3VdbeDeleteAuxData(tls, (*Vdbe)(unsafe.Pointer(v)).Fdb, v+296, -1, 0)
	(*Vdbe)(unsafe.Pointer(v)).FpAuxData = (*VdbeFrame)(unsafe.Pointer(pFrame)).FpAuxData
	(*VdbeFrame)(unsafe.Pointer(pFrame)).FpAuxData = uintptr(0)
	return (*VdbeFrame)(unsafe.Pointer(pFrame)).Fpc
}

func closeAllCursors(tls *libc.TLS, p uintptr) {
	if (*Vdbe)(unsafe.Pointer(p)).FpFrame != 0 {
		var pFrame uintptr
		for pFrame = (*Vdbe)(unsafe.Pointer(p)).FpFrame; (*VdbeFrame)(unsafe.Pointer(pFrame)).FpParent != 0; pFrame = (*VdbeFrame)(unsafe.Pointer(pFrame)).FpParent {
		}
		Xsqlite3VdbeFrameRestore(tls, pFrame)
		(*Vdbe)(unsafe.Pointer(p)).FpFrame = uintptr(0)
		(*Vdbe)(unsafe.Pointer(p)).FnFrame = 0
	}

	closeCursorsInFrame(tls, p)
	releaseMemArray(tls, (*Vdbe)(unsafe.Pointer(p)).FaMem, (*Vdbe)(unsafe.Pointer(p)).FnMem)
	for (*Vdbe)(unsafe.Pointer(p)).FpDelFrame != 0 {
		var pDel uintptr = (*Vdbe)(unsafe.Pointer(p)).FpDelFrame
		(*Vdbe)(unsafe.Pointer(p)).FpDelFrame = (*VdbeFrame)(unsafe.Pointer(pDel)).FpParent
		Xsqlite3VdbeFrameDelete(tls, pDel)
	}

	if (*Vdbe)(unsafe.Pointer(p)).FpAuxData != 0 {
		Xsqlite3VdbeDeleteAuxData(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, p+296, -1, 0)
	}

}

func Xsqlite3VdbeSetNumCols(tls *libc.TLS, p uintptr, nResColumn int32) {
	var n int32
	var db uintptr = (*Vdbe)(unsafe.Pointer(p)).Fdb

	if (*Vdbe)(unsafe.Pointer(p)).FnResColumn != 0 {
		releaseMemArray(tls, (*Vdbe)(unsafe.Pointer(p)).FaColName, int32((*Vdbe)(unsafe.Pointer(p)).FnResColumn)*COLNAME_N)
		Xsqlite3DbFree(tls, db, (*Vdbe)(unsafe.Pointer(p)).FaColName)
	}
	n = nResColumn * COLNAME_N
	(*Vdbe)(unsafe.Pointer(p)).FnResColumn = U16(nResColumn)
	(*Vdbe)(unsafe.Pointer(p)).FaColName = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(Mem{}))*uint64(n))
	if (*Vdbe)(unsafe.Pointer(p)).FaColName == uintptr(0) {
		return
	}
	initMemArray(tls, (*Vdbe)(unsafe.Pointer(p)).FaColName, n, db, uint16(MEM_Null))
}

func Xsqlite3VdbeSetColName(tls *libc.TLS, p uintptr, idx int32, var1 int32, zName uintptr, xDel uintptr) int32 {
	var rc int32
	var pColName uintptr

	if (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		return SQLITE_NOMEM
	}

	pColName = (*Vdbe)(unsafe.Pointer(p)).FaColName + uintptr(idx+var1*int32((*Vdbe)(unsafe.Pointer(p)).FnResColumn))*56
	rc = Xsqlite3VdbeMemSetStr(tls, pColName, zName, int64(-1), uint8(SQLITE_UTF8), xDel)

	return rc
}

func vdbeCommit(tls *libc.TLS, db uintptr, p uintptr) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var i int32
	var nTrans int32 = 0

	var rc int32 = SQLITE_OK
	var needXcommit int32 = 0

	rc = Xsqlite3VtabSync(tls, db, p)

	for i = 0; rc == SQLITE_OK && i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if Xsqlite3BtreeTxnState(tls, pBt) == SQLITE_TXN_WRITE {
			var pPager uintptr
			needXcommit = 1
			Xsqlite3BtreeEnter(tls, pBt)
			pPager = Xsqlite3BtreePager(tls, pBt)
			if int32((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).Fsafety_level) != PAGER_SYNCHRONOUS_OFF &&
				aMJNeeded[Xsqlite3PagerGetJournalMode(tls, pPager)] != 0 &&
				Xsqlite3PagerIsMemdb(tls, pPager) == 0 {
				nTrans++
			}
			rc = Xsqlite3PagerExclusiveLock(tls, pPager)
			Xsqlite3BtreeLeave(tls, pBt)
		}
	}
	if rc != SQLITE_OK {
		return rc
	}

	if needXcommit != 0 && (*Sqlite3)(unsafe.Pointer(db)).FxCommitCallback != 0 {
		rc = (*struct {
			f func(*libc.TLS, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxCommitCallback})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpCommitArg)
		if rc != 0 {
			return SQLITE_CONSTRAINT | int32(2)<<8
		}
	}

	if 0 == Xsqlite3Strlen30(tls, Xsqlite3BtreeGetFilename(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpBt)) ||
		nTrans <= 1 {
		for i = 0; rc == SQLITE_OK && i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
			if pBt != 0 {
				rc = Xsqlite3BtreeCommitPhaseOne(tls, pBt, uintptr(0))
			}
		}

		for i = 0; rc == SQLITE_OK && i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
			if pBt != 0 {
				rc = Xsqlite3BtreeCommitPhaseTwo(tls, pBt, 0)
			}
		}
		if rc == SQLITE_OK {
			Xsqlite3VtabCommit(tls, db)
		}
	} else {
		var pVfs uintptr = (*Sqlite3)(unsafe.Pointer(db)).FpVfs
		var zSuper uintptr = uintptr(0)
		var zMainFile uintptr = Xsqlite3BtreeGetFilename(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpBt)
		*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)
		var offset I64 = int64(0)

		var retryCount int32 = 0
		var nMainFile int32

		nMainFile = Xsqlite3Strlen30(tls, zMainFile)
		zSuper = Xsqlite3MPrintf(tls, db, ts+8007, libc.VaList(bp, 0, zMainFile, 0))
		if zSuper == uintptr(0) {
			return SQLITE_NOMEM
		}
		zSuper += uintptr(4)
		for __ccgo := true; __ccgo; __ccgo = rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 60)) != 0 {
			if retryCount != 0 {
				if retryCount > 100 {
					Xsqlite3_log(tls, SQLITE_FULL, ts+8019, libc.VaList(bp+24, zSuper))
					Xsqlite3OsDelete(tls, pVfs, zSuper, 0)
					break
				} else if retryCount == 1 {
					Xsqlite3_log(tls, SQLITE_FULL, ts+8033, libc.VaList(bp+32, zSuper))
				}
			}
			retryCount++
			Xsqlite3_randomness(tls, int32(unsafe.Sizeof(U32(0))), bp+56)
			Xsqlite3_snprintf(tls, 13, zSuper+uintptr(nMainFile), ts+8048,
				libc.VaList(bp+40, *(*U32)(unsafe.Pointer(bp + 56))>>8&U32(0xffffff), *(*U32)(unsafe.Pointer(bp + 56))&U32(0xff)))

			rc = Xsqlite3OsAccess(tls, pVfs, zSuper, SQLITE_ACCESS_EXISTS, bp+60)
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3OsOpenMalloc(tls, pVfs, zSuper, bp+64,
				SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_SUPER_JOURNAL, uintptr(0))
		}
		if rc != SQLITE_OK {
			Xsqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}

		for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
			if Xsqlite3BtreeTxnState(tls, pBt) == SQLITE_TXN_WRITE {
				var zFile uintptr = Xsqlite3BtreeGetJournalname(tls, pBt)
				if zFile == uintptr(0) {
					continue
				}

				rc = Xsqlite3OsWrite(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), zFile, Xsqlite3Strlen30(tls, zFile)+1, offset)
				offset = offset + I64(Xsqlite3Strlen30(tls, zFile)+1)
				if rc != SQLITE_OK {
					Xsqlite3OsCloseFree(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
					Xsqlite3OsDelete(tls, pVfs, zSuper, 0)
					Xsqlite3DbFree(tls, db, zSuper-uintptr(4))
					return rc
				}
			}
		}

		if 0 == Xsqlite3OsDeviceCharacteristics(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))&SQLITE_IOCAP_SEQUENTIAL &&
			SQLITE_OK != libc.AssignInt32(&rc, Xsqlite3OsSync(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), SQLITE_SYNC_NORMAL)) {
			Xsqlite3OsCloseFree(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
			Xsqlite3OsDelete(tls, pVfs, zSuper, 0)
			Xsqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}

		for i = 0; rc == SQLITE_OK && i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
			if pBt != 0 {
				rc = Xsqlite3BtreeCommitPhaseOne(tls, pBt, zSuper)
			}
		}
		Xsqlite3OsCloseFree(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))

		if rc != SQLITE_OK {
			Xsqlite3DbFree(tls, db, zSuper-uintptr(4))
			return rc
		}

		rc = Xsqlite3OsDelete(tls, pVfs, zSuper, 1)
		Xsqlite3DbFree(tls, db, zSuper-uintptr(4))
		zSuper = uintptr(0)
		if rc != 0 {
			return rc
		}

		Xdisable_simulated_io_errors(tls)
		Xsqlite3BeginBenignMalloc(tls)
		for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
			if pBt != 0 {
				Xsqlite3BtreeCommitPhaseTwo(tls, pBt, 1)
			}
		}
		Xsqlite3EndBenignMalloc(tls)
		Xenable_simulated_io_errors(tls)

		Xsqlite3VtabCommit(tls, db)
	}

	return rc
}

var aMJNeeded = [6]U8{
	U8(1),
	U8(1),
	U8(0),
	U8(1),
	U8(0),
	U8(0),
}

func vdbeCloseStatement(tls *libc.TLS, p uintptr, eOp int32) int32 {
	var db uintptr = (*Vdbe)(unsafe.Pointer(p)).Fdb
	var rc int32 = SQLITE_OK
	var i int32
	var iSavepoint int32 = (*Vdbe)(unsafe.Pointer(p)).FiStatement - 1

	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var rc2 int32 = SQLITE_OK
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if pBt != 0 {
			if eOp == SAVEPOINT_ROLLBACK {
				rc2 = Xsqlite3BtreeSavepoint(tls, pBt, SAVEPOINT_ROLLBACK, iSavepoint)
			}
			if rc2 == SQLITE_OK {
				rc2 = Xsqlite3BtreeSavepoint(tls, pBt, SAVEPOINT_RELEASE, iSavepoint)
			}
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnStatement--
	(*Vdbe)(unsafe.Pointer(p)).FiStatement = 0

	if rc == SQLITE_OK {
		if eOp == SAVEPOINT_ROLLBACK {
			rc = Xsqlite3VtabSavepoint(tls, db, SAVEPOINT_ROLLBACK, iSavepoint)
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3VtabSavepoint(tls, db, SAVEPOINT_RELEASE, iSavepoint)
		}
	}

	if eOp == SAVEPOINT_ROLLBACK {
		(*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons = (*Vdbe)(unsafe.Pointer(p)).FnStmtDefCons
		(*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = (*Vdbe)(unsafe.Pointer(p)).FnStmtDefImmCons
	}
	return rc
}

func Xsqlite3VdbeCloseStatement(tls *libc.TLS, p uintptr, eOp int32) int32 {
	if (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FnStatement != 0 && (*Vdbe)(unsafe.Pointer(p)).FiStatement != 0 {
		return vdbeCloseStatement(tls, p, eOp)
	}
	return SQLITE_OK
}

func Xsqlite3VdbeCheckFk(tls *libc.TLS, p uintptr, deferred int32) int32 {
	var db uintptr = (*Vdbe)(unsafe.Pointer(p)).Fdb
	if deferred != 0 && (*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons+(*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons > int64(0) ||
		!(deferred != 0) && (*Vdbe)(unsafe.Pointer(p)).FnFkConstraint > int64(0) {
		(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_CONSTRAINT | int32(3)<<8
		(*Vdbe)(unsafe.Pointer(p)).FerrorAction = U8(OE_Abort)
		Xsqlite3VdbeError(tls, p, ts+8061, 0)
		if int32((*Vdbe)(unsafe.Pointer(p)).FprepFlags)&SQLITE_PREPARE_SAVESQL == 0 {
			return SQLITE_ERROR
		}
		return SQLITE_CONSTRAINT | int32(3)<<8
	}
	return SQLITE_OK
}

func Xsqlite3VdbeHalt(tls *libc.TLS, p uintptr) int32 {
	var rc int32
	var db uintptr = (*Vdbe)(unsafe.Pointer(p)).Fdb

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
	}
	closeAllCursors(tls, p)

	if Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x80>>7)) != 0 {
		var mrc int32
		var eStatementOp int32 = 0
		var isSpecialError int32

		Xsqlite3VdbeEnter(tls, p)

		if (*Vdbe)(unsafe.Pointer(p)).Frc != 0 {
			mrc = (*Vdbe)(unsafe.Pointer(p)).Frc & 0xff
			isSpecialError = libc.Bool32(mrc == SQLITE_NOMEM ||
				mrc == SQLITE_IOERR ||
				mrc == SQLITE_INTERRUPT ||
				mrc == SQLITE_FULL)
		} else {
			mrc = libc.AssignInt32(&isSpecialError, 0)
		}
		if isSpecialError != 0 {
			if !(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x40>>6) != 0) || mrc != SQLITE_INTERRUPT {
				if (mrc == SQLITE_NOMEM || mrc == SQLITE_FULL) && Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x20>>5)) != 0 {
					eStatementOp = SAVEPOINT_ROLLBACK
				} else {
					Xsqlite3RollbackAll(tls, db, SQLITE_ABORT|int32(2)<<8)
					Xsqlite3CloseSavepoints(tls, db)
					(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(1)
					(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
				}
			}
		}

		if (*Vdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || int32((*Vdbe)(unsafe.Pointer(p)).FerrorAction) == OE_Fail && !(isSpecialError != 0) {
			Xsqlite3VdbeCheckFk(tls, p, 0)
		}

		if !((*Sqlite3)(unsafe.Pointer(db)).FnVTrans > 0 && (*Sqlite3)(unsafe.Pointer(db)).FaVTrans == uintptr(0)) &&
			(*Sqlite3)(unsafe.Pointer(db)).FautoCommit != 0 &&
			(*Sqlite3)(unsafe.Pointer(db)).FnVdbeWrite == libc.Bool32(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x40>>6) == 0) {
			if (*Vdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || int32((*Vdbe)(unsafe.Pointer(p)).FerrorAction) == OE_Fail && !(isSpecialError != 0) {
				rc = Xsqlite3VdbeCheckFk(tls, p, 1)
				if rc != SQLITE_OK {
					if Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x40>>6)) != 0 {
						Xsqlite3VdbeLeave(tls, p)
						return SQLITE_ERROR
					}
					rc = SQLITE_CONSTRAINT | int32(3)<<8
				} else if (*Sqlite3)(unsafe.Pointer(db)).Fflags&(uint64(0x00002)<<32) != 0 {
					rc = SQLITE_CORRUPT
					*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(0x00002) << 32)
				} else {
					rc = vdbeCommit(tls, db, p)
				}
				if rc == SQLITE_BUSY && Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x40>>6)) != 0 {
					Xsqlite3VdbeLeave(tls, p)
					return SQLITE_BUSY
				} else if rc != SQLITE_OK {
					(*Vdbe)(unsafe.Pointer(p)).Frc = rc
					Xsqlite3RollbackAll(tls, db, SQLITE_OK)
					(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
				} else {
					(*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons = int64(0)
					(*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = int64(0)
					*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(SQLITE_DeferFKs))
					Xsqlite3CommitInternalChanges(tls, db)
				}
			} else {
				Xsqlite3RollbackAll(tls, db, SQLITE_OK)
				(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
			}
			(*Sqlite3)(unsafe.Pointer(db)).FnStatement = 0
		} else if eStatementOp == 0 {
			if (*Vdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || int32((*Vdbe)(unsafe.Pointer(p)).FerrorAction) == OE_Fail {
				eStatementOp = SAVEPOINT_RELEASE
			} else if int32((*Vdbe)(unsafe.Pointer(p)).FerrorAction) == OE_Abort {
				eStatementOp = SAVEPOINT_ROLLBACK
			} else {
				Xsqlite3RollbackAll(tls, db, SQLITE_ABORT|int32(2)<<8)
				Xsqlite3CloseSavepoints(tls, db)
				(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(1)
				(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
			}
		}

		if eStatementOp != 0 {
			rc = Xsqlite3VdbeCloseStatement(tls, p, eStatementOp)
			if rc != 0 {
				if (*Vdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK || (*Vdbe)(unsafe.Pointer(p)).Frc&0xff == SQLITE_CONSTRAINT {
					(*Vdbe)(unsafe.Pointer(p)).Frc = rc
					Xsqlite3DbFree(tls, db, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg)
					(*Vdbe)(unsafe.Pointer(p)).FzErrMsg = uintptr(0)
				}
				Xsqlite3RollbackAll(tls, db, SQLITE_ABORT|int32(2)<<8)
				Xsqlite3CloseSavepoints(tls, db)
				(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(1)
				(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
			}
		}

		if Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x10>>4)) != 0 {
			if eStatementOp != SAVEPOINT_ROLLBACK {
				Xsqlite3VdbeSetChanges(tls, db, (*Vdbe)(unsafe.Pointer(p)).FnChange)
			} else {
				Xsqlite3VdbeSetChanges(tls, db, int64(0))
			}
			(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
		}

		Xsqlite3VdbeLeave(tls, p)
	}

	(*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive--
	if !(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x40>>6) != 0) {
		(*Sqlite3)(unsafe.Pointer(db)).FnVdbeWrite--
	}
	if Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x80>>7)) != 0 {
		(*Sqlite3)(unsafe.Pointer(db)).FnVdbeRead--
	}

	(*Vdbe)(unsafe.Pointer(p)).FeVdbeState = U8(VDBE_HALT_STATE)

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
	}

	if (*Sqlite3)(unsafe.Pointer(db)).FautoCommit != 0 {
		Xsqlite3ConnectionUnlocked(tls, db)
	}

	return func() int32 {
		if (*Vdbe)(unsafe.Pointer(p)).Frc == SQLITE_BUSY {
			return SQLITE_BUSY
		}
		return SQLITE_OK
	}()
}

func Xsqlite3VdbeResetStepResult(tls *libc.TLS, p uintptr) {
	(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK
}

func Xsqlite3VdbeTransferError(tls *libc.TLS, p uintptr) int32 {
	var db uintptr = (*Vdbe)(unsafe.Pointer(p)).Fdb
	var rc int32 = (*Vdbe)(unsafe.Pointer(p)).Frc
	if (*Vdbe)(unsafe.Pointer(p)).FzErrMsg != 0 {
		(*Sqlite3)(unsafe.Pointer(db)).FbBenignMalloc++
		Xsqlite3BeginBenignMalloc(tls)
		if (*Sqlite3)(unsafe.Pointer(db)).FpErr == uintptr(0) {
			(*Sqlite3)(unsafe.Pointer(db)).FpErr = Xsqlite3ValueNew(tls, db)
		}
		Xsqlite3ValueSetStr(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr, -1, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg, uint8(SQLITE_UTF8), libc.UintptrFromInt32(-1))
		Xsqlite3EndBenignMalloc(tls)
		(*Sqlite3)(unsafe.Pointer(db)).FbBenignMalloc--
	} else if (*Sqlite3)(unsafe.Pointer(db)).FpErr != 0 {
		Xsqlite3ValueSetNull(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr)
	}
	(*Sqlite3)(unsafe.Pointer(db)).FerrCode = rc
	(*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset = -1
	return rc
}

func Xsqlite3VdbeReset(tls *libc.TLS, p uintptr) int32 {
	var db uintptr
	db = (*Vdbe)(unsafe.Pointer(p)).Fdb

	if int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) == VDBE_RUN_STATE {
		Xsqlite3VdbeHalt(tls, p)
	}

	if (*Vdbe)(unsafe.Pointer(p)).Fpc >= 0 {
		if (*Sqlite3)(unsafe.Pointer(db)).FpErr != 0 || (*Vdbe)(unsafe.Pointer(p)).FzErrMsg != 0 {
			Xsqlite3VdbeTransferError(tls, p)
		} else {
			(*Sqlite3)(unsafe.Pointer(db)).FerrCode = (*Vdbe)(unsafe.Pointer(p)).Frc
		}
	}

	if (*Vdbe)(unsafe.Pointer(p)).FzErrMsg != 0 {
		Xsqlite3DbFree(tls, db, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg)
		(*Vdbe)(unsafe.Pointer(p)).FzErrMsg = uintptr(0)
	}
	(*Vdbe)(unsafe.Pointer(p)).FpResultRow = uintptr(0)

	return (*Vdbe)(unsafe.Pointer(p)).Frc & (*Sqlite3)(unsafe.Pointer(db)).FerrMask
}

func Xsqlite3VdbeFinalize(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = SQLITE_OK

	if int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) >= VDBE_READY_STATE {
		rc = Xsqlite3VdbeReset(tls, p)

	}
	Xsqlite3VdbeDelete(tls, p)
	return rc
}

func Xsqlite3VdbeDeleteAuxData(tls *libc.TLS, db uintptr, pp uintptr, iOp int32, mask int32) {
	for *(*uintptr)(unsafe.Pointer(pp)) != 0 {
		var pAux uintptr = *(*uintptr)(unsafe.Pointer(pp))
		if iOp < 0 ||
			(*AuxData)(unsafe.Pointer(pAux)).FiAuxOp == iOp &&
				(*AuxData)(unsafe.Pointer(pAux)).FiAuxArg >= 0 &&
				((*AuxData)(unsafe.Pointer(pAux)).FiAuxArg > 31 || !(uint32(mask)&(uint32(1)<<(*AuxData)(unsafe.Pointer(pAux)).FiAuxArg) != 0)) {
			if (*AuxData)(unsafe.Pointer(pAux)).FxDeleteAux != 0 {
				(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*AuxData)(unsafe.Pointer(pAux)).FxDeleteAux})).f(tls, (*AuxData)(unsafe.Pointer(pAux)).FpAux)
			}
			*(*uintptr)(unsafe.Pointer(pp)) = (*AuxData)(unsafe.Pointer(pAux)).FpNextAux
			Xsqlite3DbFree(tls, db, pAux)
		} else {
			pp = pAux + 24
		}
	}
}

func sqlite3VdbeClearObject(tls *libc.TLS, db uintptr, p uintptr) {
	var pSub uintptr
	var pNext uintptr

	if (*Vdbe)(unsafe.Pointer(p)).FaColName != 0 {
		releaseMemArray(tls, (*Vdbe)(unsafe.Pointer(p)).FaColName, int32((*Vdbe)(unsafe.Pointer(p)).FnResColumn)*COLNAME_N)
		Xsqlite3DbNNFreeNN(tls, db, (*Vdbe)(unsafe.Pointer(p)).FaColName)
	}
	for pSub = (*Vdbe)(unsafe.Pointer(p)).FpProgram; pSub != 0; pSub = pNext {
		pNext = (*SubProgram)(unsafe.Pointer(pSub)).FpNext
		vdbeFreeOpArray(tls, db, (*SubProgram)(unsafe.Pointer(pSub)).FaOp, (*SubProgram)(unsafe.Pointer(pSub)).FnOp)
		Xsqlite3DbFree(tls, db, pSub)
	}
	if int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) != VDBE_INIT_STATE {
		releaseMemArray(tls, (*Vdbe)(unsafe.Pointer(p)).FaVar, int32((*Vdbe)(unsafe.Pointer(p)).FnVar))
		if (*Vdbe)(unsafe.Pointer(p)).FpVList != 0 {
			Xsqlite3DbNNFreeNN(tls, db, (*Vdbe)(unsafe.Pointer(p)).FpVList)
		}
		if (*Vdbe)(unsafe.Pointer(p)).FpFree != 0 {
			Xsqlite3DbNNFreeNN(tls, db, (*Vdbe)(unsafe.Pointer(p)).FpFree)
		}
	}
	vdbeFreeOpArray(tls, db, (*Vdbe)(unsafe.Pointer(p)).FaOp, (*Vdbe)(unsafe.Pointer(p)).FnOp)
	if (*Vdbe)(unsafe.Pointer(p)).FzSql != 0 {
		Xsqlite3DbNNFreeNN(tls, db, (*Vdbe)(unsafe.Pointer(p)).FzSql)
	}
}

func Xsqlite3VdbeDelete(tls *libc.TLS, p uintptr) {
	var db uintptr

	db = (*Vdbe)(unsafe.Pointer(p)).Fdb

	sqlite3VdbeClearObject(tls, db, p)
	if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
		*(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FppVPrev)) = (*Vdbe)(unsafe.Pointer(p)).FpVNext
		if (*Vdbe)(unsafe.Pointer(p)).FpVNext != 0 {
			(*Vdbe)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FpVNext)).FppVPrev = (*Vdbe)(unsafe.Pointer(p)).FppVPrev
		}
	}
	Xsqlite3DbNNFreeNN(tls, db, p)
}

func Xsqlite3VdbeFinishMoveto(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32

	rc = Xsqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(p + 48)), (*VdbeCursor)(unsafe.Pointer(p)).FmovetoTarget, 0, bp)
	if rc != 0 {
		return rc
	}
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		return Xsqlite3CorruptError(tls, 86062)
	}
	atomic.AddInt32(&Xsqlite3_search_count, 1)
	(*VdbeCursor)(unsafe.Pointer(p)).FdeferredMoveto = U8(0)
	(*VdbeCursor)(unsafe.Pointer(p)).FcacheStatus = U32(CACHE_STALE)
	return SQLITE_OK
}

func Xsqlite3VdbeHandleMovedCursor(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32

	rc = Xsqlite3BtreeCursorRestore(tls, *(*uintptr)(unsafe.Pointer(p + 48)), bp)
	(*VdbeCursor)(unsafe.Pointer(p)).FcacheStatus = U32(CACHE_STALE)
	if *(*int32)(unsafe.Pointer(bp)) != 0 {
		(*VdbeCursor)(unsafe.Pointer(p)).FnullRow = U8(1)
	}
	return rc
}

func Xsqlite3VdbeCursorRestore(tls *libc.TLS, p uintptr) int32 {
	if Xsqlite3BtreeCursorHasMoved(tls, *(*uintptr)(unsafe.Pointer(p + 48))) != 0 {
		return Xsqlite3VdbeHandleMovedCursor(tls, p)
	}
	return SQLITE_OK
}

var Xsqlite3SmallTypeSizes = [128]U8{
	U8(0), U8(1), U8(2), U8(3), U8(4), U8(6), U8(8), U8(8), U8(0), U8(0),
	U8(0), U8(0), U8(0), U8(0), U8(1), U8(1), U8(2), U8(2), U8(3), U8(3),
	U8(4), U8(4), U8(5), U8(5), U8(6), U8(6), U8(7), U8(7), U8(8), U8(8),
	U8(9), U8(9), U8(10), U8(10), U8(11), U8(11), U8(12), U8(12), U8(13), U8(13),
	U8(14), U8(14), U8(15), U8(15), U8(16), U8(16), U8(17), U8(17), U8(18), U8(18),
	U8(19), U8(19), U8(20), U8(20), U8(21), U8(21), U8(22), U8(22), U8(23), U8(23),
	U8(24), U8(24), U8(25), U8(25), U8(26), U8(26), U8(27), U8(27), U8(28), U8(28),
	U8(29), U8(29), U8(30), U8(30), U8(31), U8(31), U8(32), U8(32), U8(33), U8(33),
	U8(34), U8(34), U8(35), U8(35), U8(36), U8(36), U8(37), U8(37), U8(38), U8(38),
	U8(39), U8(39), U8(40), U8(40), U8(41), U8(41), U8(42), U8(42), U8(43), U8(43),
	U8(44), U8(44), U8(45), U8(45), U8(46), U8(46), U8(47), U8(47), U8(48), U8(48),
	U8(49), U8(49), U8(50), U8(50), U8(51), U8(51), U8(52), U8(52), U8(53), U8(53),
	U8(54), U8(54), U8(55), U8(55), U8(56), U8(56), U8(57), U8(57),
}

func Xsqlite3VdbeSerialTypeLen(tls *libc.TLS, serial_type U32) U32 {
	if serial_type >= U32(128) {
		return (serial_type - U32(12)) / U32(2)
	} else {
		return U32(Xsqlite3SmallTypeSizes[serial_type])
	}
	return U32(0)
}

func Xsqlite3VdbeOneByteSerialTypeLen(tls *libc.TLS, serial_type U8) U8 {
	return Xsqlite3SmallTypeSizes[serial_type]
}

func serialGet(tls *libc.TLS, buf uintptr, serial_type U32, pMem uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*U64)(unsafe.Pointer(bp)) = U64(U32(*(*uint8)(unsafe.Pointer(buf)))<<24 | U32(int32(*(*uint8)(unsafe.Pointer(buf + 1)))<<16) | U32(int32(*(*uint8)(unsafe.Pointer(buf + 2)))<<8) | U32(*(*uint8)(unsafe.Pointer(buf + 3))))
	var y U32 = U32(*(*uint8)(unsafe.Pointer(buf + uintptr(4))))<<24 | U32(int32(*(*uint8)(unsafe.Pointer(buf + uintptr(4) + 1)))<<16) | U32(int32(*(*uint8)(unsafe.Pointer(buf + uintptr(4) + 2)))<<8) | U32(*(*uint8)(unsafe.Pointer(buf + uintptr(4) + 3)))
	*(*U64)(unsafe.Pointer(bp)) = *(*U64)(unsafe.Pointer(bp))<<32 + U64(y)
	if serial_type == U32(6) {
		*(*I64)(unsafe.Pointer(pMem)) = *(*I64)(unsafe.Pointer(bp))
		(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)

	} else {
		libc.Xmemcpy(tls, pMem, bp, uint64(unsafe.Sizeof(U64(0))))
		(*Mem)(unsafe.Pointer(pMem)).Fflags = func() uint16 {
			if *(*U64)(unsafe.Pointer(bp))&(uint64(0x7ff)<<52) == uint64(0x7ff)<<52 && *(*U64)(unsafe.Pointer(bp))&(uint64(1)<<52-uint64(1)) != uint64(0) {
				return uint16(MEM_Null)
			}
			return uint16(MEM_Real)
		}()
	}
}

func Xsqlite3VdbeSerialGet(tls *libc.TLS, buf uintptr, serial_type U32, pMem uintptr) {
	switch serial_type {
	case U32(10):
		{
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Null | MEM_Zero)
			(*Mem)(unsafe.Pointer(pMem)).Fn = 0
			*(*int32)(unsafe.Pointer(pMem)) = 0
			return

		}
	case U32(11):
		fallthrough
	case U32(0):
		{
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Null)
			return

		}
	case U32(1):
		{
			*(*I64)(unsafe.Pointer(pMem)) = I64(I8(*(*uint8)(unsafe.Pointer(buf))))
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)

			return

		}
	case U32(2):
		{
			*(*I64)(unsafe.Pointer(pMem)) = I64(256*int32(I8(*(*uint8)(unsafe.Pointer(buf)))) | int32(*(*uint8)(unsafe.Pointer(buf + 1))))
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)

			return

		}
	case U32(3):
		{
			*(*I64)(unsafe.Pointer(pMem)) = I64(65536*int32(I8(*(*uint8)(unsafe.Pointer(buf)))) | int32(*(*uint8)(unsafe.Pointer(buf + 1)))<<8 | int32(*(*uint8)(unsafe.Pointer(buf + 2))))
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)

			return

		}
	case U32(4):
		{
			*(*I64)(unsafe.Pointer(pMem)) = I64(16777216*int32(I8(*(*uint8)(unsafe.Pointer(buf)))) | int32(*(*uint8)(unsafe.Pointer(buf + 1)))<<16 | int32(*(*uint8)(unsafe.Pointer(buf + 2)))<<8 | int32(*(*uint8)(unsafe.Pointer(buf + 3))))
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)

			return

		}
	case U32(5):
		{
			*(*I64)(unsafe.Pointer(pMem)) = I64(U32(*(*uint8)(unsafe.Pointer(buf + uintptr(2))))<<24|U32(int32(*(*uint8)(unsafe.Pointer(buf + uintptr(2) + 1)))<<16)|U32(int32(*(*uint8)(unsafe.Pointer(buf + uintptr(2) + 2)))<<8)|U32(*(*uint8)(unsafe.Pointer(buf + uintptr(2) + 3)))) + int64(1)<<32*I64(256*int32(I8(*(*uint8)(unsafe.Pointer(buf))))|int32(*(*uint8)(unsafe.Pointer(buf + 1))))
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)

			return

		}
	case U32(6):
		fallthrough
	case U32(7):
		{
			serialGet(tls, buf, serial_type, pMem)
			return

		}
	case U32(8):
		fallthrough
	case U32(9):
		{
			*(*I64)(unsafe.Pointer(pMem)) = I64(serial_type - U32(8))
			(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Int)
			return

		}
	default:
		{
			(*Mem)(unsafe.Pointer(pMem)).Fz = buf
			(*Mem)(unsafe.Pointer(pMem)).Fn = int32((serial_type - U32(12)) / U32(2))
			(*Mem)(unsafe.Pointer(pMem)).Fflags = aFlag[serial_type&U32(1)]
			return

		}
	}
	return
}

var aFlag = [2]U16{U16(MEM_Blob | MEM_Ephem), U16(MEM_Str | MEM_Ephem)}

func Xsqlite3VdbeAllocUnpackedRecord(tls *libc.TLS, pKeyInfo uintptr) uintptr {
	var p uintptr
	var nByte int32
	nByte = int32(uint64(unsafe.Sizeof(UnpackedRecord{})) + uint64(unsafe.Sizeof(Mem{}))*uint64(int32((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)+1))
	p = Xsqlite3DbMallocRaw(tls, (*KeyInfo)(unsafe.Pointer(pKeyInfo)).Fdb, uint64(nByte))
	if !(p != 0) {
		return uintptr(0)
	}
	(*UnpackedRecord)(unsafe.Pointer(p)).FaMem = p + 40

	(*UnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo = pKeyInfo
	(*UnpackedRecord)(unsafe.Pointer(p)).FnField = U16(int32((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField) + 1)
	return p
}

func Xsqlite3VdbeRecordUnpack(tls *libc.TLS, pKeyInfo uintptr, nKey int32, pKey uintptr, p uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var aKey uintptr = pKey
	var d U32
	var idx U32
	var u U16

	var pMem uintptr = (*UnpackedRecord)(unsafe.Pointer(p)).FaMem

	(*UnpackedRecord)(unsafe.Pointer(p)).Fdefault_rc = int8(0)

	idx = U32(func() uint8 {
		if int32(*(*uint8)(unsafe.Pointer(aKey))) < int32(U8(0x80)) {
			return uint8(func() int32 { *(*U32)(unsafe.Pointer(bp)) = U32(*(*uint8)(unsafe.Pointer(aKey))); return 1 }())
		}
		return Xsqlite3GetVarint32(tls, aKey, bp)
	}())
	d = *(*U32)(unsafe.Pointer(bp))
	u = U16(0)
	for idx < *(*U32)(unsafe.Pointer(bp)) && d <= U32(nKey) {
		idx = idx + U32(func() uint8 {
			if int32(*(*uint8)(unsafe.Pointer(aKey + uintptr(idx)))) < int32(U8(0x80)) {
				return uint8(func() int32 {
					*(*U32)(unsafe.Pointer(bp + 4)) = U32(*(*uint8)(unsafe.Pointer(aKey + uintptr(idx))))
					return 1
				}())
			}
			return Xsqlite3GetVarint32(tls, aKey+uintptr(idx), bp+4)
		}())
		(*Mem)(unsafe.Pointer(pMem)).Fenc = (*KeyInfo)(unsafe.Pointer(pKeyInfo)).Fenc
		(*Mem)(unsafe.Pointer(pMem)).Fdb = (*KeyInfo)(unsafe.Pointer(pKeyInfo)).Fdb

		(*Mem)(unsafe.Pointer(pMem)).FszMalloc = 0
		(*Mem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
		Xsqlite3VdbeSerialGet(tls, aKey+uintptr(d), *(*U32)(unsafe.Pointer(bp + 4)), pMem)
		d = d + Xsqlite3VdbeSerialTypeLen(tls, *(*U32)(unsafe.Pointer(bp + 4)))
		pMem += 56
		if int32(libc.PreIncUint16(&u, 1)) >= int32((*UnpackedRecord)(unsafe.Pointer(p)).FnField) {
			break
		}
	}
	if d > U32(nKey) && u != 0 {
		Xsqlite3VdbeMemSetNull(tls, pMem-uintptr(1)*56)
	}

	(*UnpackedRecord)(unsafe.Pointer(p)).FnField = u
}

func vdbeCompareMemString(tls *libc.TLS, pMem1 uintptr, pMem2 uintptr, pColl uintptr, prcErr uintptr) int32 {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	if int32((*Mem)(unsafe.Pointer(pMem1)).Fenc) == int32((*CollSeq)(unsafe.Pointer(pColl)).Fenc) {
		return (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*CollSeq)(unsafe.Pointer(pColl)).FxCmp})).f(tls, (*CollSeq)(unsafe.Pointer(pColl)).FpUser, (*Mem)(unsafe.Pointer(pMem1)).Fn, (*Mem)(unsafe.Pointer(pMem1)).Fz, (*Mem)(unsafe.Pointer(pMem2)).Fn, (*Mem)(unsafe.Pointer(pMem2)).Fz)
	} else {
		var rc int32
		var v1 uintptr
		var v2 uintptr

		Xsqlite3VdbeMemInit(tls, bp, (*Mem)(unsafe.Pointer(pMem1)).Fdb, uint16(MEM_Null))
		Xsqlite3VdbeMemInit(tls, bp+56, (*Mem)(unsafe.Pointer(pMem1)).Fdb, uint16(MEM_Null))
		Xsqlite3VdbeMemShallowCopy(tls, bp, pMem1, MEM_Ephem)
		Xsqlite3VdbeMemShallowCopy(tls, bp+56, pMem2, MEM_Ephem)
		v1 = Xsqlite3ValueText(tls, bp, (*CollSeq)(unsafe.Pointer(pColl)).Fenc)
		v2 = Xsqlite3ValueText(tls, bp+56, (*CollSeq)(unsafe.Pointer(pColl)).Fenc)
		if v1 == uintptr(0) || v2 == uintptr(0) {
			if prcErr != 0 {
				*(*U8)(unsafe.Pointer(prcErr)) = U8(SQLITE_NOMEM)
			}
			rc = 0
		} else {
			rc = (*struct {
				f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*CollSeq)(unsafe.Pointer(pColl)).FxCmp})).f(tls, (*CollSeq)(unsafe.Pointer(pColl)).FpUser, (*Mem)(unsafe.Pointer(bp)).Fn, v1, (*Mem)(unsafe.Pointer(bp+56)).Fn, v2)
		}
		Xsqlite3VdbeMemReleaseMalloc(tls, bp)
		Xsqlite3VdbeMemReleaseMalloc(tls, bp+56)
		return rc
	}
	return int32(0)
}

func isAllZero(tls *libc.TLS, z uintptr, n int32) int32 {
	var i int32
	for i = 0; i < n; i++ {
		if *(*uint8)(unsafe.Pointer(z + uintptr(i))) != 0 {
			return 0
		}
	}
	return 1
}

func Xsqlite3BlobCompare(tls *libc.TLS, pB1 uintptr, pB2 uintptr) int32 {
	var c int32
	var n1 int32 = (*Mem)(unsafe.Pointer(pB1)).Fn
	var n2 int32 = (*Mem)(unsafe.Pointer(pB2)).Fn

	if (int32((*Mem)(unsafe.Pointer(pB1)).Fflags)|int32((*Mem)(unsafe.Pointer(pB2)).Fflags))&MEM_Zero != 0 {
		if int32((*Mem)(unsafe.Pointer(pB1)).Fflags)&int32((*Mem)(unsafe.Pointer(pB2)).Fflags)&MEM_Zero != 0 {
			return *(*int32)(unsafe.Pointer(pB1)) - *(*int32)(unsafe.Pointer(pB2))
		} else if int32((*Mem)(unsafe.Pointer(pB1)).Fflags)&MEM_Zero != 0 {
			if !(isAllZero(tls, (*Mem)(unsafe.Pointer(pB2)).Fz, (*Mem)(unsafe.Pointer(pB2)).Fn) != 0) {
				return -1
			}
			return *(*int32)(unsafe.Pointer(pB1)) - n2
		} else {
			if !(isAllZero(tls, (*Mem)(unsafe.Pointer(pB1)).Fz, (*Mem)(unsafe.Pointer(pB1)).Fn) != 0) {
				return +1
			}
			return n1 - *(*int32)(unsafe.Pointer(pB2))
		}
	}
	c = libc.Xmemcmp(tls, (*Mem)(unsafe.Pointer(pB1)).Fz, (*Mem)(unsafe.Pointer(pB2)).Fz, func() uint64 {
		if n1 > n2 {
			return uint64(n2)
		}
		return uint64(n1)
	}())
	if c != 0 {
		return c
	}
	return n1 - n2
}

func Xsqlite3IntFloatCompare(tls *libc.TLS, i I64, r float64) int32 {
	if uint64(unsafe.Sizeof(float64(0))) > uint64(8) {
		var x float64 = float64(i)

		if x < r {
			return -1
		}
		if x > r {
			return +1
		}
		return 0
	} else {
		var y I64
		var s float64
		if r < -9223372036854775808.0 {
			return +1
		}
		if r >= 9223372036854775808.0 {
			return -1
		}
		y = I64(r)
		if i < y {
			return -1
		}
		if i > y {
			return +1
		}
		s = float64(i)
		if s < r {
			return -1
		}
		if s > r {
			return +1
		}
		return 0
	}
	return int32(0)
}

func Xsqlite3MemCompare(tls *libc.TLS, pMem1 uintptr, pMem2 uintptr, pColl uintptr) int32 {
	var f1 int32
	var f2 int32
	var combined_flags int32

	f1 = int32((*Mem)(unsafe.Pointer(pMem1)).Fflags)
	f2 = int32((*Mem)(unsafe.Pointer(pMem2)).Fflags)
	combined_flags = f1 | f2

	if combined_flags&MEM_Null != 0 {
		return f2&MEM_Null - f1&MEM_Null
	}

	if combined_flags&(MEM_Int|MEM_Real|MEM_IntReal) != 0 {
		if f1&f2&(MEM_Int|MEM_IntReal) != 0 {
			if *(*I64)(unsafe.Pointer(pMem1)) < *(*I64)(unsafe.Pointer(pMem2)) {
				return -1
			}
			if *(*I64)(unsafe.Pointer(pMem1)) > *(*I64)(unsafe.Pointer(pMem2)) {
				return +1
			}
			return 0
		}
		if f1&f2&MEM_Real != 0 {
			if *(*float64)(unsafe.Pointer(pMem1)) < *(*float64)(unsafe.Pointer(pMem2)) {
				return -1
			}
			if *(*float64)(unsafe.Pointer(pMem1)) > *(*float64)(unsafe.Pointer(pMem2)) {
				return +1
			}
			return 0
		}
		if f1&(MEM_Int|MEM_IntReal) != 0 {
			if f2&MEM_Real != 0 {
				return Xsqlite3IntFloatCompare(tls, *(*I64)(unsafe.Pointer(pMem1)), *(*float64)(unsafe.Pointer(pMem2)))
			} else if f2&(MEM_Int|MEM_IntReal) != 0 {
				if *(*I64)(unsafe.Pointer(pMem1)) < *(*I64)(unsafe.Pointer(pMem2)) {
					return -1
				}
				if *(*I64)(unsafe.Pointer(pMem1)) > *(*I64)(unsafe.Pointer(pMem2)) {
					return +1
				}
				return 0
			} else {
				return -1
			}
		}
		if f1&MEM_Real != 0 {
			if f2&(MEM_Int|MEM_IntReal) != 0 {
				return -Xsqlite3IntFloatCompare(tls, *(*I64)(unsafe.Pointer(pMem2)), *(*float64)(unsafe.Pointer(pMem1)))
			} else {
				return -1
			}
		}
		return +1
	}

	if combined_flags&MEM_Str != 0 {
		if f1&MEM_Str == 0 {
			return 1
		}
		if f2&MEM_Str == 0 {
			return -1
		}

		if pColl != 0 {
			return vdbeCompareMemString(tls, pMem1, pMem2, pColl, uintptr(0))
		}

	}

	return Xsqlite3BlobCompare(tls, pMem1, pMem2)
}

func vdbeRecordDecodeInt(tls *libc.TLS, serial_type U32, aKey uintptr) I64 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	switch serial_type {
	case U32(0):
		fallthrough
	case U32(1):
		return I64(I8(*(*U8)(unsafe.Pointer(aKey))))
	case U32(2):
		return I64(256*int32(I8(*(*U8)(unsafe.Pointer(aKey)))) | int32(*(*U8)(unsafe.Pointer(aKey + 1))))
	case U32(3):
		return I64(65536*int32(I8(*(*U8)(unsafe.Pointer(aKey)))) | int32(*(*U8)(unsafe.Pointer(aKey + 1)))<<8 | int32(*(*U8)(unsafe.Pointer(aKey + 2))))
	case U32(4):
		{
			*(*U32)(unsafe.Pointer(bp)) = U32(*(*U8)(unsafe.Pointer(aKey)))<<24 | U32(int32(*(*U8)(unsafe.Pointer(aKey + 1)))<<16) | U32(int32(*(*U8)(unsafe.Pointer(aKey + 2)))<<8) | U32(*(*U8)(unsafe.Pointer(aKey + 3)))
			return I64(*(*int32)(unsafe.Pointer(bp)))

		}
	case U32(5):
		{
			return I64(U32(*(*U8)(unsafe.Pointer(aKey + uintptr(2))))<<24|U32(int32(*(*U8)(unsafe.Pointer(aKey + uintptr(2) + 1)))<<16)|U32(int32(*(*U8)(unsafe.Pointer(aKey + uintptr(2) + 2)))<<8)|U32(*(*U8)(unsafe.Pointer(aKey + uintptr(2) + 3)))) + int64(1)<<32*I64(256*int32(I8(*(*U8)(unsafe.Pointer(aKey))))|int32(*(*U8)(unsafe.Pointer(aKey + 1))))

		}
	case U32(6):
		{
			*(*U64)(unsafe.Pointer(bp + 8)) = U64(U32(*(*U8)(unsafe.Pointer(aKey)))<<24 | U32(int32(*(*U8)(unsafe.Pointer(aKey + 1)))<<16) | U32(int32(*(*U8)(unsafe.Pointer(aKey + 2)))<<8) | U32(*(*U8)(unsafe.Pointer(aKey + 3))))

			*(*U64)(unsafe.Pointer(bp + 8)) = *(*U64)(unsafe.Pointer(bp + 8))<<32 | U64(U32(*(*U8)(unsafe.Pointer(aKey + uintptr(4))))<<24|U32(int32(*(*U8)(unsafe.Pointer(aKey + uintptr(4) + 1)))<<16)|U32(int32(*(*U8)(unsafe.Pointer(aKey + uintptr(4) + 2)))<<8)|U32(*(*U8)(unsafe.Pointer(aKey + uintptr(4) + 3))))
			return *(*I64)(unsafe.Pointer(bp + 8))

		}
	}

	return I64(serial_type - U32(8))
}

func Xsqlite3VdbeRecordCompareWithSkip(tls *libc.TLS, nKey1 int32, pKey1 uintptr, pPKey2 uintptr, bSkip int32) int32 {
	bp := tls.Alloc(68)
	defer tls.Free(68)

	var d1 U32
	var i int32

	var idx1 U32
	var rc int32 = 0
	var pRhs uintptr = (*UnpackedRecord)(unsafe.Pointer(pPKey2)).FaMem
	var pKeyInfo uintptr
	var aKey1 uintptr = pKey1

	if bSkip != 0 {
		*(*U32)(unsafe.Pointer(bp)) = U32(*(*uint8)(unsafe.Pointer(aKey1 + 1)))
		if *(*U32)(unsafe.Pointer(bp)) < U32(0x80) {
			idx1 = U32(2)
		} else {
			idx1 = U32(1 + int32(Xsqlite3GetVarint32(tls, aKey1+1, bp)))
		}
		*(*U32)(unsafe.Pointer(bp + 4)) = U32(*(*uint8)(unsafe.Pointer(aKey1)))
		d1 = *(*U32)(unsafe.Pointer(bp + 4)) + Xsqlite3VdbeSerialTypeLen(tls, *(*U32)(unsafe.Pointer(bp)))
		i = 1
		pRhs += 56
	} else {
		if libc.AssignPtrUint32(bp+4, U32(*(*uint8)(unsafe.Pointer(aKey1)))) < U32(0x80) {
			idx1 = U32(1)
		} else {
			idx1 = U32(Xsqlite3GetVarint32(tls, aKey1, bp+4))
		}
		d1 = *(*U32)(unsafe.Pointer(bp + 4))
		i = 0
	}
	if d1 > uint32(nKey1) {
		(*UnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = U8(Xsqlite3CorruptError(tls, 86989))
		return 0
	}

	for 1 != 0 {
		if int32((*Mem)(unsafe.Pointer(pRhs)).Fflags)&(MEM_Int|MEM_IntReal) != 0 {
			*(*U32)(unsafe.Pointer(bp + 64)) = U32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))

			if *(*U32)(unsafe.Pointer(bp + 64)) >= U32(10) {
				if *(*U32)(unsafe.Pointer(bp + 64)) == U32(10) {
					rc = -1
				} else {
					rc = +1
				}
			} else if *(*U32)(unsafe.Pointer(bp + 64)) == U32(0) {
				rc = -1
			} else if *(*U32)(unsafe.Pointer(bp + 64)) == U32(7) {
				Xsqlite3VdbeSerialGet(tls, aKey1+uintptr(d1), *(*U32)(unsafe.Pointer(bp + 64)), bp+8)
				rc = -Xsqlite3IntFloatCompare(tls, *(*I64)(unsafe.Pointer(pRhs)), *(*float64)(unsafe.Pointer(bp + 8)))
			} else {
				var lhs I64 = vdbeRecordDecodeInt(tls, *(*U32)(unsafe.Pointer(bp + 64)), aKey1+uintptr(d1))
				var rhs I64 = *(*I64)(unsafe.Pointer(pRhs))
				if lhs < rhs {
					rc = -1
				} else if lhs > rhs {
					rc = +1
				}
			}
		} else if int32((*Mem)(unsafe.Pointer(pRhs)).Fflags)&MEM_Real != 0 {
			*(*U32)(unsafe.Pointer(bp + 64)) = U32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
			if *(*U32)(unsafe.Pointer(bp + 64)) >= U32(10) {
				if *(*U32)(unsafe.Pointer(bp + 64)) == U32(10) {
					rc = -1
				} else {
					rc = +1
				}
			} else if *(*U32)(unsafe.Pointer(bp + 64)) == U32(0) {
				rc = -1
			} else {
				Xsqlite3VdbeSerialGet(tls, aKey1+uintptr(d1), *(*U32)(unsafe.Pointer(bp + 64)), bp+8)
				if *(*U32)(unsafe.Pointer(bp + 64)) == U32(7) {
					if *(*float64)(unsafe.Pointer(bp + 8)) < *(*float64)(unsafe.Pointer(pRhs)) {
						rc = -1
					} else if *(*float64)(unsafe.Pointer(bp + 8)) > *(*float64)(unsafe.Pointer(pRhs)) {
						rc = +1
					}
				} else {
					rc = Xsqlite3IntFloatCompare(tls, *(*I64)(unsafe.Pointer(bp + 8)), *(*float64)(unsafe.Pointer(pRhs)))
				}
			}
		} else if int32((*Mem)(unsafe.Pointer(pRhs)).Fflags)&MEM_Str != 0 {
			*(*U32)(unsafe.Pointer(bp + 64)) = U32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
			if *(*U32)(unsafe.Pointer(bp + 64)) >= U32(0x80) {
				Xsqlite3GetVarint32(tls, aKey1+uintptr(idx1), bp+64)
			}

			if *(*U32)(unsafe.Pointer(bp + 64)) < U32(12) {
				rc = -1
			} else if !(*(*U32)(unsafe.Pointer(bp + 64))&U32(0x01) != 0) {
				rc = +1
			} else {
				(*Mem)(unsafe.Pointer(bp + 8)).Fn = int32((*(*U32)(unsafe.Pointer(bp + 64)) - U32(12)) / U32(2))

				if d1+U32((*Mem)(unsafe.Pointer(bp+8)).Fn) > uint32(nKey1) ||
					int32((*KeyInfo)(unsafe.Pointer(libc.AssignUintptr(&pKeyInfo, (*UnpackedRecord)(unsafe.Pointer(pPKey2)).FpKeyInfo))).FnAllField) <= i {
					(*UnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = U8(Xsqlite3CorruptError(tls, 87066))
					return 0
				} else if *(*uintptr)(unsafe.Pointer(pKeyInfo + 32 + uintptr(i)*8)) != 0 {
					(*Mem)(unsafe.Pointer(bp + 8)).Fenc = (*KeyInfo)(unsafe.Pointer(pKeyInfo)).Fenc
					(*Mem)(unsafe.Pointer(bp + 8)).Fdb = (*KeyInfo)(unsafe.Pointer(pKeyInfo)).Fdb
					(*Mem)(unsafe.Pointer(bp + 8)).Fflags = U16(MEM_Str)
					(*Mem)(unsafe.Pointer(bp + 8)).Fz = aKey1 + uintptr(d1)
					rc = vdbeCompareMemString(tls,
						bp+8, pRhs, *(*uintptr)(unsafe.Pointer(pKeyInfo + 32 + uintptr(i)*8)), pPKey2+31)
				} else {
					var nCmp int32 = func() int32 {
						if (*Mem)(unsafe.Pointer(bp+8)).Fn < (*Mem)(unsafe.Pointer(pRhs)).Fn {
							return (*Mem)(unsafe.Pointer(bp + 8)).Fn
						}
						return (*Mem)(unsafe.Pointer(pRhs)).Fn
					}()
					rc = libc.Xmemcmp(tls, aKey1+uintptr(d1), (*Mem)(unsafe.Pointer(pRhs)).Fz, uint64(nCmp))
					if rc == 0 {
						rc = (*Mem)(unsafe.Pointer(bp+8)).Fn - (*Mem)(unsafe.Pointer(pRhs)).Fn
					}
				}
			}
		} else if int32((*Mem)(unsafe.Pointer(pRhs)).Fflags)&MEM_Blob != 0 {
			*(*U32)(unsafe.Pointer(bp + 64)) = U32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
			if *(*U32)(unsafe.Pointer(bp + 64)) >= U32(0x80) {
				Xsqlite3GetVarint32(tls, aKey1+uintptr(idx1), bp+64)
			}

			if *(*U32)(unsafe.Pointer(bp + 64)) < U32(12) || *(*U32)(unsafe.Pointer(bp + 64))&U32(0x01) != 0 {
				rc = -1
			} else {
				var nStr int32 = int32((*(*U32)(unsafe.Pointer(bp + 64)) - U32(12)) / U32(2))

				if d1+U32(nStr) > uint32(nKey1) {
					(*UnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = U8(Xsqlite3CorruptError(tls, 87096))
					return 0
				} else if int32((*Mem)(unsafe.Pointer(pRhs)).Fflags)&MEM_Zero != 0 {
					if !(isAllZero(tls, aKey1+uintptr(d1), nStr) != 0) {
						rc = 1
					} else {
						rc = nStr - *(*int32)(unsafe.Pointer(pRhs))
					}
				} else {
					var nCmp int32 = func() int32 {
						if nStr < (*Mem)(unsafe.Pointer(pRhs)).Fn {
							return nStr
						}
						return (*Mem)(unsafe.Pointer(pRhs)).Fn
					}()
					rc = libc.Xmemcmp(tls, aKey1+uintptr(d1), (*Mem)(unsafe.Pointer(pRhs)).Fz, uint64(nCmp))
					if rc == 0 {
						rc = nStr - (*Mem)(unsafe.Pointer(pRhs)).Fn
					}
				}
			}
		} else {
			*(*U32)(unsafe.Pointer(bp + 64)) = U32(*(*uint8)(unsafe.Pointer(aKey1 + uintptr(idx1))))
			rc = libc.Bool32(*(*U32)(unsafe.Pointer(bp + 64)) != U32(0) && *(*U32)(unsafe.Pointer(bp + 64)) != U32(10))
		}

		if rc != 0 {
			var sortFlags int32 = int32(*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(pPKey2)).FpKeyInfo)).FaSortFlags + uintptr(i))))
			if sortFlags != 0 {
				if sortFlags&KEYINFO_ORDER_BIGNULL == 0 ||
					sortFlags&KEYINFO_ORDER_DESC !=
						libc.Bool32(*(*U32)(unsafe.Pointer(bp + 64)) == U32(0) || int32((*Mem)(unsafe.Pointer(pRhs)).Fflags)&MEM_Null != 0) {
					rc = -rc
				}
			}

			return rc
		}

		i++
		if i == int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).FnField) {
			break
		}
		pRhs += 56
		d1 = d1 + Xsqlite3VdbeSerialTypeLen(tls, *(*U32)(unsafe.Pointer(bp + 64)))
		if d1 > uint32(nKey1) {
			break
		}
		idx1 = idx1 + U32(Xsqlite3VarintLen(tls, uint64(*(*U32)(unsafe.Pointer(bp + 64)))))
		if idx1 >= *(*U32)(unsafe.Pointer(bp + 4)) {
			(*UnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = U8(Xsqlite3CorruptError(tls, 87140))
			return 0
		}
	}

	(*UnpackedRecord)(unsafe.Pointer(pPKey2)).FeqSeen = U8(1)
	return int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fdefault_rc)
}

func Xsqlite3VdbeRecordCompare(tls *libc.TLS, nKey1 int32, pKey1 uintptr, pPKey2 uintptr) int32 {
	return Xsqlite3VdbeRecordCompareWithSkip(tls, nKey1, pKey1, pPKey2, 0)
}

func vdbeRecordCompareInt(tls *libc.TLS, nKey1 int32, pKey1 uintptr, pPKey2 uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var aKey uintptr = pKey1 + uintptr(int32(*(*U8)(unsafe.Pointer(pKey1)))&0x3F)
	var serial_type int32 = int32(*(*U8)(unsafe.Pointer(pKey1 + 1)))
	var res int32

	var v I64
	var lhs I64

	switch serial_type {
	case 1:
		{
			lhs = I64(I8(*(*U8)(unsafe.Pointer(aKey))))

			break

		}
	case 2:
		{
			lhs = I64(256*int32(I8(*(*U8)(unsafe.Pointer(aKey)))) | int32(*(*U8)(unsafe.Pointer(aKey + 1))))

			break

		}
	case 3:
		{
			lhs = I64(65536*int32(I8(*(*U8)(unsafe.Pointer(aKey)))) | int32(*(*U8)(unsafe.Pointer(aKey + 1)))<<8 | int32(*(*U8)(unsafe.Pointer(aKey + 2))))

			break

		}
	case 4:
		{
			*(*U32)(unsafe.Pointer(bp)) = U32(*(*U8)(unsafe.Pointer(aKey)))<<24 | U32(int32(*(*U8)(unsafe.Pointer(aKey + 1)))<<16) | U32(int32(*(*U8)(unsafe.Pointer(aKey + 2)))<<8) | U32(*(*U8)(unsafe.Pointer(aKey + 3)))
			lhs = I64(*(*int32)(unsafe.Pointer(bp)))

			break

		}
	case 5:
		{
			lhs = I64(U32(*(*U8)(unsafe.Pointer(aKey + uintptr(2))))<<24|U32(int32(*(*U8)(unsafe.Pointer(aKey + uintptr(2) + 1)))<<16)|U32(int32(*(*U8)(unsafe.Pointer(aKey + uintptr(2) + 2)))<<8)|U32(*(*U8)(unsafe.Pointer(aKey + uintptr(2) + 3)))) + int64(1)<<32*I64(256*int32(I8(*(*U8)(unsafe.Pointer(aKey))))|int32(*(*U8)(unsafe.Pointer(aKey + 1))))

			break

		}
	case 6:
		{
			*(*U64)(unsafe.Pointer(bp + 8)) = U64(U32(*(*U8)(unsafe.Pointer(aKey)))<<24 | U32(int32(*(*U8)(unsafe.Pointer(aKey + 1)))<<16) | U32(int32(*(*U8)(unsafe.Pointer(aKey + 2)))<<8) | U32(*(*U8)(unsafe.Pointer(aKey + 3))))
			*(*U64)(unsafe.Pointer(bp + 8)) = *(*U64)(unsafe.Pointer(bp + 8))<<32 | U64(U32(*(*U8)(unsafe.Pointer(aKey + uintptr(4))))<<24|U32(int32(*(*U8)(unsafe.Pointer(aKey + uintptr(4) + 1)))<<16)|U32(int32(*(*U8)(unsafe.Pointer(aKey + uintptr(4) + 2)))<<8)|U32(*(*U8)(unsafe.Pointer(aKey + uintptr(4) + 3))))
			lhs = *(*I64)(unsafe.Pointer(bp + 8))

			break

		}
	case 8:
		lhs = int64(0)
		break
	case 9:
		lhs = int64(1)
		break

	case 0:
		fallthrough
	case 7:
		return Xsqlite3VdbeRecordCompare(tls, nKey1, pKey1, pPKey2)

	default:
		return Xsqlite3VdbeRecordCompare(tls, nKey1, pKey1, pPKey2)
	}

	v = *(*I64)(unsafe.Pointer(pPKey2 + 16))
	if v > lhs {
		res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fr1)
	} else if v < lhs {
		res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fr2)
	} else if int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).FnField) > 1 {
		res = Xsqlite3VdbeRecordCompareWithSkip(tls, nKey1, pKey1, pPKey2, 1)
	} else {
		res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fdefault_rc)
		(*UnpackedRecord)(unsafe.Pointer(pPKey2)).FeqSeen = U8(1)
	}

	return res
}

func vdbeRecordCompareString(tls *libc.TLS, nKey1 int32, pKey1 uintptr, pPKey2 uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var aKey1 uintptr

	var res int32
	var nCmp int32
	var nStr int32
	var szHdr int32
	aKey1 = pKey1

	*(*int32)(unsafe.Pointer(bp)) = int32(int8(*(*U8)(unsafe.Pointer(aKey1 + 1))))

vrcs_restart:
	if !(*(*int32)(unsafe.Pointer(bp)) < 12) {
		goto __1
	}
	if !(*(*int32)(unsafe.Pointer(bp)) < 0) {
		goto __3
	}
	Xsqlite3GetVarint32(tls, aKey1+1, bp)
	if !(*(*int32)(unsafe.Pointer(bp)) >= 12) {
		goto __4
	}
	goto vrcs_restart
__4:
	;
__3:
	;
	res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fr1)
	goto __2
__1:
	if !!(*(*int32)(unsafe.Pointer(bp))&0x01 != 0) {
		goto __5
	}
	res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fr2)
	goto __6
__5:
	szHdr = int32(*(*U8)(unsafe.Pointer(aKey1)))

	nStr = (*(*int32)(unsafe.Pointer(bp)) - 12) / 2
	if !(szHdr+nStr > nKey1) {
		goto __7
	}
	(*UnpackedRecord)(unsafe.Pointer(pPKey2)).FerrCode = U8(Xsqlite3CorruptError(tls, 87303))
	return 0
__7:
	;
	nCmp = func() int32 {
		if (*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fn < nStr {
			return (*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fn
		}
		return nStr
	}()
	res = libc.Xmemcmp(tls, aKey1+uintptr(szHdr), *(*uintptr)(unsafe.Pointer(pPKey2 + 16)), uint64(nCmp))

	if !(res > 0) {
		goto __8
	}
	res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fr2)
	goto __9
__8:
	if !(res < 0) {
		goto __10
	}
	res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fr1)
	goto __11
__10:
	res = nStr - (*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fn
	if !(res == 0) {
		goto __12
	}
	if !(int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).FnField) > 1) {
		goto __14
	}
	res = Xsqlite3VdbeRecordCompareWithSkip(tls, nKey1, pKey1, pPKey2, 1)
	goto __15
__14:
	res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fdefault_rc)
	(*UnpackedRecord)(unsafe.Pointer(pPKey2)).FeqSeen = U8(1)
__15:
	;
	goto __13
__12:
	if !(res > 0) {
		goto __16
	}
	res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fr2)
	goto __17
__16:
	res = int32((*UnpackedRecord)(unsafe.Pointer(pPKey2)).Fr1)
__17:
	;
__13:
	;
__11:
	;
__9:
	;
__6:
	;
__2:
	;
	return res
}

func Xsqlite3VdbeFindCompare(tls *libc.TLS, p uintptr) RecordCompare {
	if int32((*KeyInfo)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo)).FnAllField) <= 13 {
		var flags int32 = int32((*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(p)).FaMem)).Fflags)
		if *(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo)).FaSortFlags)) != 0 {
			if int32(*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo)).FaSortFlags)))&KEYINFO_ORDER_BIGNULL != 0 {
				return *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, int32, uintptr, uintptr) int32
				}{Xsqlite3VdbeRecordCompare}))
			}
			(*UnpackedRecord)(unsafe.Pointer(p)).Fr1 = int8(1)
			(*UnpackedRecord)(unsafe.Pointer(p)).Fr2 = int8(-1)
		} else {
			(*UnpackedRecord)(unsafe.Pointer(p)).Fr1 = int8(-1)
			(*UnpackedRecord)(unsafe.Pointer(p)).Fr2 = int8(1)
		}
		if flags&MEM_Int != 0 {
			*(*I64)(unsafe.Pointer(p + 16)) = *(*I64)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(p)).FaMem))
			return *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, int32, uintptr, uintptr) int32
			}{vdbeRecordCompareInt}))
		}

		if flags&(MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob) == 0 &&
			*(*uintptr)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(p)).FpKeyInfo + 32)) == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(p + 16)) = (*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(p)).FaMem)).Fz
			(*UnpackedRecord)(unsafe.Pointer(p)).Fn = (*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(p)).FaMem)).Fn
			return *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, int32, uintptr, uintptr) int32
			}{vdbeRecordCompareString}))
		}
	}

	return *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, int32, uintptr, uintptr) int32
	}{Xsqlite3VdbeRecordCompare}))
}

func Xsqlite3VdbeIdxRowid(tls *libc.TLS, db uintptr, pCur uintptr, rowid uintptr) int32 {
	bp := tls.Alloc(120)
	defer tls.Free(120)

	var nCellKey I64
	var rc int32

	var lenRowid U32

	nCellKey = int64(0)

	nCellKey = I64(Xsqlite3BtreePayloadSize(tls, pCur))

	Xsqlite3VdbeMemInit(tls, bp, db, uint16(0))
	rc = Xsqlite3VdbeMemFromBtreeZeroOffset(tls, pCur, U32(nCellKey), bp)
	if !(rc != 0) {
		goto __1
	}
	return rc
__1:
	;
	*(*U32)(unsafe.Pointer(bp + 56)) = U32(*(*U8)(unsafe.Pointer((*Mem)(unsafe.Pointer(bp)).Fz)))
	if !(*(*U32)(unsafe.Pointer(bp + 56)) >= U32(0x80)) {
		goto __2
	}
	Xsqlite3GetVarint32(tls, (*Mem)(unsafe.Pointer(bp)).Fz, bp+56)
__2:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 56)) < U32(3) || *(*U32)(unsafe.Pointer(bp + 56)) > uint32((*Mem)(unsafe.Pointer(bp)).Fn)) {
		goto __3
	}
	goto idx_rowid_corruption
__3:
	;
	*(*U32)(unsafe.Pointer(bp + 60)) = U32(*(*U8)(unsafe.Pointer((*Mem)(unsafe.Pointer(bp)).Fz + uintptr(*(*U32)(unsafe.Pointer(bp + 56))-U32(1)))))
	if !(*(*U32)(unsafe.Pointer(bp + 60)) >= U32(0x80)) {
		goto __4
	}
	Xsqlite3GetVarint32(tls, (*Mem)(unsafe.Pointer(bp)).Fz+uintptr(*(*U32)(unsafe.Pointer(bp + 56))-U32(1)), bp+60)
__4:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 60)) < U32(1) || *(*U32)(unsafe.Pointer(bp + 60)) > U32(9) || *(*U32)(unsafe.Pointer(bp + 60)) == U32(7)) {
		goto __5
	}
	goto idx_rowid_corruption
__5:
	;
	lenRowid = U32(Xsqlite3SmallTypeSizes[*(*U32)(unsafe.Pointer(bp + 60))])

	if !(U32((*Mem)(unsafe.Pointer(bp)).Fn) < *(*U32)(unsafe.Pointer(bp + 56))+lenRowid) {
		goto __6
	}
	goto idx_rowid_corruption
__6:
	;
	Xsqlite3VdbeSerialGet(tls, (*Mem)(unsafe.Pointer(bp)).Fz+uintptr(U32((*Mem)(unsafe.Pointer(bp)).Fn)-lenRowid), *(*U32)(unsafe.Pointer(bp + 60)), bp+64)
	*(*I64)(unsafe.Pointer(rowid)) = *(*I64)(unsafe.Pointer(bp + 64))
	Xsqlite3VdbeMemReleaseMalloc(tls, bp)
	return SQLITE_OK

idx_rowid_corruption:
	;
	Xsqlite3VdbeMemReleaseMalloc(tls, bp)
	return Xsqlite3CorruptError(tls, 87461)
}

func Xsqlite3VdbeIdxKeyCompare(tls *libc.TLS, db uintptr, pC uintptr, pUnpacked uintptr, res uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var nCellKey I64 = int64(0)
	var rc int32
	var pCur uintptr

	pCur = *(*uintptr)(unsafe.Pointer(pC + 48))

	nCellKey = I64(Xsqlite3BtreePayloadSize(tls, pCur))

	if nCellKey <= int64(0) || nCellKey > int64(0x7fffffff) {
		*(*int32)(unsafe.Pointer(res)) = 0
		return Xsqlite3CorruptError(tls, 87494)
	}
	Xsqlite3VdbeMemInit(tls, bp, db, uint16(0))
	rc = Xsqlite3VdbeMemFromBtreeZeroOffset(tls, pCur, U32(nCellKey), bp)
	if rc != 0 {
		return rc
	}
	*(*int32)(unsafe.Pointer(res)) = Xsqlite3VdbeRecordCompareWithSkip(tls, (*Mem)(unsafe.Pointer(bp)).Fn, (*Mem)(unsafe.Pointer(bp)).Fz, pUnpacked, 0)
	Xsqlite3VdbeMemReleaseMalloc(tls, bp)
	return SQLITE_OK
}

func Xsqlite3VdbeSetChanges(tls *libc.TLS, db uintptr, nChange I64) {
	(*Sqlite3)(unsafe.Pointer(db)).FnChange = nChange
	*(*I64)(unsafe.Pointer(db + 128)) += nChange
}

func Xsqlite3VdbeCountChanges(tls *libc.TLS, v uintptr) {
	libc.SetBitFieldPtr8Uint32(v+200, Bft(1), 4, 0x10)
}

func Xsqlite3ExpirePreparedStatements(tls *libc.TLS, db uintptr, iCode int32) {
	var p uintptr
	for p = (*Sqlite3)(unsafe.Pointer(db)).FpVdbe; p != 0; p = (*Vdbe)(unsafe.Pointer(p)).FpVNext {
		libc.SetBitFieldPtr8Uint32(p+200, Bft(iCode+1), 0, 0x3)
	}
}

func Xsqlite3VdbeDb(tls *libc.TLS, v uintptr) uintptr {
	return (*Vdbe)(unsafe.Pointer(v)).Fdb
}

func Xsqlite3VdbePrepareFlags(tls *libc.TLS, v uintptr) U8 {
	return (*Vdbe)(unsafe.Pointer(v)).FprepFlags
}

func Xsqlite3VdbeGetBoundValue(tls *libc.TLS, v uintptr, iVar int32, aff U8) uintptr {
	if v != 0 {
		var pMem uintptr = (*Vdbe)(unsafe.Pointer(v)).FaVar + uintptr(iVar-1)*56

		if 0 == int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Null {
			var pRet uintptr = Xsqlite3ValueNew(tls, (*Vdbe)(unsafe.Pointer(v)).Fdb)
			if pRet != 0 {
				Xsqlite3VdbeMemCopy(tls, pRet, pMem)
				Xsqlite3ValueApplyAffinity(tls, pRet, aff, uint8(SQLITE_UTF8))
			}
			return pRet
		}
	}
	return uintptr(0)
}

func Xsqlite3VdbeSetVarmask(tls *libc.TLS, v uintptr, iVar int32) {
	if iVar >= 32 {
		*(*U32)(unsafe.Pointer(v + 284)) |= 0x80000000
	} else {
		*(*U32)(unsafe.Pointer(v + 284)) |= U32(1) << (iVar - 1)
	}
}

func Xsqlite3NotPureFunc(tls *libc.TLS, pCtx uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pOp uintptr
	if (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe == uintptr(0) {
		return 1
	}
	pOp = (*Vdbe)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe)).FaOp + uintptr((*Sqlite3_context)(unsafe.Pointer(pCtx)).FiOp)*32
	if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_PureFunc {
		var zContext uintptr
		var zMsg uintptr
		if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fp5)&NC_IsCheck != 0 {
			zContext = ts + 8091
		} else if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fp5)&NC_GenCol != 0 {
			zContext = ts + 8110
		} else {
			zContext = ts + 8129
		}
		zMsg = Xsqlite3_mprintf(tls, ts+8138,
			libc.VaList(bp, (*FuncDef)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx)).FpFunc)).FzName, zContext))
		Xsqlite3_result_error(tls, pCtx, zMsg, -1)
		Xsqlite3_free(tls, zMsg)
		return 0
	}
	return 1
}

func Xsqlite3VtabImportErrmsg(tls *libc.TLS, p uintptr, pVtab uintptr) {
	if (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg != 0 {
		var db uintptr = (*Vdbe)(unsafe.Pointer(p)).Fdb
		Xsqlite3DbFree(tls, db, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg)
		(*Vdbe)(unsafe.Pointer(p)).FzErrMsg = Xsqlite3DbStrDup(tls, db, (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
		Xsqlite3_free(tls, (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
		(*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = uintptr(0)
	}
}

func vdbeFreeUnpacked(tls *libc.TLS, db uintptr, nField int32, p uintptr) {
	if p != 0 {
		var i int32
		for i = 0; i < nField; i++ {
			var pMem uintptr = (*UnpackedRecord)(unsafe.Pointer(p)).FaMem + uintptr(i)*56
			if (*Mem)(unsafe.Pointer(pMem)).FzMalloc != 0 {
				Xsqlite3VdbeMemReleaseMalloc(tls, pMem)
			}
		}
		Xsqlite3DbNNFreeNN(tls, db, p)
	}
}

func Xsqlite3VdbePreUpdateHook(tls *libc.TLS, v uintptr, pCsr uintptr, op int32, zDb uintptr, pTab uintptr, iKey1 I64, iReg int32, iBlobWrite int32) {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var db uintptr = (*Vdbe)(unsafe.Pointer(v)).Fdb
	var iKey2 I64

	var zTbl uintptr = (*Table)(unsafe.Pointer(pTab)).FzName

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(PreUpdate{})))
	if libc.Bool32((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) == 0 {
		iKey1 = libc.AssignInt64(&iKey2, int64(0))
		(*PreUpdate)(unsafe.Pointer(bp)).FpPk = Xsqlite3PrimaryKeyIndex(tls, pTab)
	} else {
		if op == SQLITE_UPDATE {
			iKey2 = *(*I64)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).FaMem + uintptr(iReg)*56))
		} else {
			iKey2 = iKey1
		}
	}

	(*PreUpdate)(unsafe.Pointer(bp)).Fv = v
	(*PreUpdate)(unsafe.Pointer(bp)).FpCsr = pCsr
	(*PreUpdate)(unsafe.Pointer(bp)).Fop = op
	(*PreUpdate)(unsafe.Pointer(bp)).FiNewReg = iReg
	(*PreUpdate)(unsafe.Pointer(bp)).Fkeyinfo.Fdb = db
	(*PreUpdate)(unsafe.Pointer(bp)).Fkeyinfo.Fenc = (*Sqlite3)(unsafe.Pointer(db)).Fenc
	(*PreUpdate)(unsafe.Pointer(bp)).Fkeyinfo.FnKeyField = U16((*Table)(unsafe.Pointer(pTab)).FnCol)
	(*PreUpdate)(unsafe.Pointer(bp)).Fkeyinfo.FaSortFlags = uintptr(unsafe.Pointer(&fakeSortOrder))
	(*PreUpdate)(unsafe.Pointer(bp)).FiKey1 = iKey1
	(*PreUpdate)(unsafe.Pointer(bp)).FiKey2 = iKey2
	(*PreUpdate)(unsafe.Pointer(bp)).FpTab = pTab
	(*PreUpdate)(unsafe.Pointer(bp)).FiBlobWrite = iBlobWrite

	(*Sqlite3)(unsafe.Pointer(db)).FpPreUpdate = bp
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, Sqlite3_int64, Sqlite3_int64)
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2)
	(*Sqlite3)(unsafe.Pointer(db)).FpPreUpdate = uintptr(0)
	Xsqlite3DbFree(tls, db, (*PreUpdate)(unsafe.Pointer(bp)).FaRecord)
	vdbeFreeUnpacked(tls, db, int32((*PreUpdate)(unsafe.Pointer(bp)).Fkeyinfo.FnKeyField)+1, (*PreUpdate)(unsafe.Pointer(bp)).FpUnpacked)
	vdbeFreeUnpacked(tls, db, int32((*PreUpdate)(unsafe.Pointer(bp)).Fkeyinfo.FnKeyField)+1, (*PreUpdate)(unsafe.Pointer(bp)).FpNewUnpacked)
	if (*PreUpdate)(unsafe.Pointer(bp)).FaNew != 0 {
		var i int32
		for i = 0; i < int32((*VdbeCursor)(unsafe.Pointer(pCsr)).FnField); i++ {
			Xsqlite3VdbeMemRelease(tls, (*PreUpdate)(unsafe.Pointer(bp)).FaNew+uintptr(i)*56)
		}
		Xsqlite3DbNNFreeNN(tls, db, (*PreUpdate)(unsafe.Pointer(bp)).FaNew)
	}
}

var fakeSortOrder U8 = U8(0)

func Xsqlite3_expired(tls *libc.TLS, pStmt uintptr) int32 {
	var p uintptr = pStmt
	return libc.Bool32(p == uintptr(0) || Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x3>>0)) != 0)
}

func vdbeSafety(tls *libc.TLS, p uintptr) int32 {
	if (*Vdbe)(unsafe.Pointer(p)).Fdb == uintptr(0) {
		Xsqlite3_log(tls, SQLITE_MISUSE, ts+8174, 0)
		return 1
	} else {
		return 0
	}
	return int32(0)
}

func vdbeSafetyNotNull(tls *libc.TLS, p uintptr) int32 {
	if p == uintptr(0) {
		Xsqlite3_log(tls, SQLITE_MISUSE, ts+8219, 0)
		return 1
	} else {
		return vdbeSafety(tls, p)
	}
	return int32(0)
}

func invokeProfileCallback(tls *libc.TLS, db uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	Xsqlite3OsCurrentTimeInt64(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, bp)
	*(*Sqlite3_int64)(unsafe.Pointer(bp + 8)) = (*(*Sqlite3_int64)(unsafe.Pointer(bp)) - (*Vdbe)(unsafe.Pointer(p)).FstartTime) * int64(1000000)
	if (*Sqlite3)(unsafe.Pointer(db)).FxProfile != 0 {
		(*struct {
			f func(*libc.TLS, uintptr, uintptr, U64)
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxProfile})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpProfileArg, (*Vdbe)(unsafe.Pointer(p)).FzSql, uint64(*(*Sqlite3_int64)(unsafe.Pointer(bp + 8))))
	}
	if int32((*Sqlite3)(unsafe.Pointer(db)).FmTrace)&SQLITE_TRACE_PROFILE != 0 {
		(*struct {
			f func(*libc.TLS, U32, uintptr, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(db + 248))})).f(tls, uint32(SQLITE_TRACE_PROFILE), (*Sqlite3)(unsafe.Pointer(db)).FpTraceArg, p, bp+8)
	}
	(*Vdbe)(unsafe.Pointer(p)).FstartTime = int64(0)
}

func Xsqlite3_finalize(tls *libc.TLS, pStmt uintptr) int32 {
	var rc int32
	if pStmt == uintptr(0) {
		rc = SQLITE_OK
	} else {
		var v uintptr = pStmt
		var db uintptr = (*Vdbe)(unsafe.Pointer(v)).Fdb
		if vdbeSafety(tls, v) != 0 {
			return Xsqlite3MisuseError(tls, 87858)
		}
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		if (*Vdbe)(unsafe.Pointer(v)).FstartTime > int64(0) {
			invokeProfileCallback(tls, db, v)
		}

		rc = Xsqlite3VdbeReset(tls, v)
		Xsqlite3VdbeDelete(tls, v)
		rc = Xsqlite3ApiExit(tls, db, rc)
		Xsqlite3LeaveMutexAndCloseZombie(tls, db)
	}
	return rc
}

func Xsqlite3_reset(tls *libc.TLS, pStmt uintptr) int32 {
	var rc int32
	if pStmt == uintptr(0) {
		rc = SQLITE_OK
	} else {
		var v uintptr = pStmt
		var db uintptr = (*Vdbe)(unsafe.Pointer(v)).Fdb
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		if (*Vdbe)(unsafe.Pointer(v)).FstartTime > int64(0) {
			invokeProfileCallback(tls, db, v)
		}

		rc = Xsqlite3VdbeReset(tls, v)
		Xsqlite3VdbeRewind(tls, v)

		rc = Xsqlite3ApiExit(tls, db, rc)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	}
	return rc
}

func Xsqlite3_clear_bindings(tls *libc.TLS, pStmt uintptr) int32 {
	var i int32
	var rc int32 = SQLITE_OK
	var p uintptr = pStmt
	var mutex uintptr = (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(pStmt)).Fdb)).Fmutex
	Xsqlite3_mutex_enter(tls, mutex)
	for i = 0; i < int32((*Vdbe)(unsafe.Pointer(p)).FnVar); i++ {
		Xsqlite3VdbeMemRelease(tls, (*Vdbe)(unsafe.Pointer(p)).FaVar+uintptr(i)*56)
		(*Mem)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaVar + uintptr(i)*56)).Fflags = U16(MEM_Null)
	}

	if (*Vdbe)(unsafe.Pointer(p)).Fexpmask != 0 {
		libc.SetBitFieldPtr8Uint32(p+200, Bft(1), 0, 0x3)
	}
	Xsqlite3_mutex_leave(tls, mutex)
	return rc
}

func Xsqlite3_value_blob(tls *libc.TLS, pVal uintptr) uintptr {
	var p uintptr = pVal
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_Blob|MEM_Str) != 0 {
		if func() int32 {
			if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Zero != 0 {
				return Xsqlite3VdbeMemExpandBlob(tls, p)
			}
			return 0
		}() != SQLITE_OK {
			return uintptr(0)
		}
		*(*U16)(unsafe.Pointer(p + 20)) |= U16(MEM_Blob)
		if (*Mem)(unsafe.Pointer(p)).Fn != 0 {
			return (*Mem)(unsafe.Pointer(p)).Fz
		}
		return uintptr(0)
	} else {
		return Xsqlite3_value_text(tls, pVal)
	}
	return uintptr(0)
}

func Xsqlite3_value_bytes(tls *libc.TLS, pVal uintptr) int32 {
	return Xsqlite3ValueBytes(tls, pVal, uint8(SQLITE_UTF8))
}

func Xsqlite3_value_bytes16(tls *libc.TLS, pVal uintptr) int32 {
	return Xsqlite3ValueBytes(tls, pVal, uint8(SQLITE_UTF16LE))
}

func Xsqlite3_value_double(tls *libc.TLS, pVal uintptr) float64 {
	return Xsqlite3VdbeRealValue(tls, pVal)
}

func Xsqlite3_value_int(tls *libc.TLS, pVal uintptr) int32 {
	return int32(Xsqlite3VdbeIntValue(tls, pVal))
}

func Xsqlite3_value_int64(tls *libc.TLS, pVal uintptr) Sqlite_int64 {
	return Xsqlite3VdbeIntValue(tls, pVal)
}

func Xsqlite3_value_subtype(tls *libc.TLS, pVal uintptr) uint32 {
	var pMem uintptr = pVal
	return func() uint32 {
		if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Subtype != 0 {
			return uint32((*Mem)(unsafe.Pointer(pMem)).FeSubtype)
		}
		return uint32(0)
	}()
}

func Xsqlite3_value_pointer(tls *libc.TLS, pVal uintptr, zPType uintptr) uintptr {
	var p uintptr = pVal
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_TypeMask|MEM_Term|MEM_Subtype) == MEM_Null|MEM_Term|MEM_Subtype &&
		zPType != uintptr(0) &&
		int32((*Mem)(unsafe.Pointer(p)).FeSubtype) == 'p' &&
		libc.Xstrcmp(tls, *(*uintptr)(unsafe.Pointer(p)), zPType) == 0 {
		return (*Mem)(unsafe.Pointer(p)).Fz
	} else {
		return uintptr(0)
	}
	return uintptr(0)
}

func Xsqlite3_value_text(tls *libc.TLS, pVal uintptr) uintptr {
	return Xsqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
}

func Xsqlite3_value_text16(tls *libc.TLS, pVal uintptr) uintptr {
	return Xsqlite3ValueText(tls, pVal, uint8(SQLITE_UTF16LE))
}

func Xsqlite3_value_text16be(tls *libc.TLS, pVal uintptr) uintptr {
	return Xsqlite3ValueText(tls, pVal, uint8(SQLITE_UTF16BE))
}

func Xsqlite3_value_text16le(tls *libc.TLS, pVal uintptr) uintptr {
	return Xsqlite3ValueText(tls, pVal, uint8(SQLITE_UTF16LE))
}

func Xsqlite3_value_type(tls *libc.TLS, pVal uintptr) int32 {
	return int32(aType[int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fflags)&MEM_AffMask])
}

var aType = [64]U8{
	U8(SQLITE_BLOB),
	U8(SQLITE_NULL),
	U8(SQLITE_TEXT),
	U8(SQLITE_NULL),
	U8(SQLITE_INTEGER),
	U8(SQLITE_NULL),
	U8(SQLITE_INTEGER),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_INTEGER),
	U8(SQLITE_NULL),
	U8(SQLITE_INTEGER),
	U8(SQLITE_NULL),
	U8(SQLITE_BLOB),
	U8(SQLITE_NULL),
	U8(SQLITE_TEXT),
	U8(SQLITE_NULL),
	U8(SQLITE_INTEGER),
	U8(SQLITE_NULL),
	U8(SQLITE_INTEGER),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_INTEGER),
	U8(SQLITE_NULL),
	U8(SQLITE_INTEGER),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_TEXT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_BLOB),
	U8(SQLITE_NULL),
	U8(SQLITE_TEXT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
	U8(SQLITE_FLOAT),
	U8(SQLITE_NULL),
}

func Xsqlite3_value_encoding(tls *libc.TLS, pVal uintptr) int32 {
	return int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fenc)
}

func Xsqlite3_value_nochange(tls *libc.TLS, pVal uintptr) int32 {
	return libc.Bool32(int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fflags)&(MEM_Null|MEM_Zero) == MEM_Null|MEM_Zero)
}

func Xsqlite3_value_frombind(tls *libc.TLS, pVal uintptr) int32 {
	return libc.Bool32(int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fflags)&MEM_FromBind != 0)
}

func Xsqlite3_value_dup(tls *libc.TLS, pOrig uintptr) uintptr {
	var pNew uintptr
	if pOrig == uintptr(0) {
		return uintptr(0)
	}
	pNew = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Sqlite3_value{})))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Sqlite3_value{})))
	libc.Xmemcpy(tls, pNew, pOrig, uint64(uintptr(0)+24))
	*(*U16)(unsafe.Pointer(pNew + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Dyn))
	(*Sqlite3_value)(unsafe.Pointer(pNew)).Fdb = uintptr(0)
	if int32((*Sqlite3_value)(unsafe.Pointer(pNew)).Fflags)&(MEM_Str|MEM_Blob) != 0 {
		*(*U16)(unsafe.Pointer(pNew + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Static | MEM_Dyn))
		*(*U16)(unsafe.Pointer(pNew + 20)) |= U16(MEM_Ephem)
		if Xsqlite3VdbeMemMakeWriteable(tls, pNew) != SQLITE_OK {
			Xsqlite3ValueFree(tls, pNew)
			pNew = uintptr(0)
		}
	} else if int32((*Sqlite3_value)(unsafe.Pointer(pNew)).Fflags)&MEM_Null != 0 {
		*(*U16)(unsafe.Pointer(pNew + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Term | MEM_Subtype))
	}
	return pNew
}

func Xsqlite3_value_free(tls *libc.TLS, pOld uintptr) {
	Xsqlite3ValueFree(tls, pOld)
}

func setResultStrOrError(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, enc U8, xDel uintptr) {
	var pOut uintptr = (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut
	var rc int32 = Xsqlite3VdbeMemSetStr(tls, pOut, z, int64(n), enc, xDel)
	if rc != 0 {
		if rc == SQLITE_TOOBIG {
			Xsqlite3_result_error_toobig(tls, pCtx)
		} else {
			Xsqlite3_result_error_nomem(tls, pCtx)
		}
		return
	}
	Xsqlite3VdbeChangeEncoding(tls, pOut, int32((*Sqlite3_context)(unsafe.Pointer(pCtx)).Fenc))
	if Xsqlite3VdbeMemTooBig(tls, pOut) != 0 {
		Xsqlite3_result_error_toobig(tls, pCtx)
	}
}

func invokeValueDestructor(tls *libc.TLS, p uintptr, xDel uintptr, pCtx uintptr) int32 {
	if xDel == uintptr(0) {
	} else if xDel == libc.UintptrFromInt32(-1) {
	} else {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDel})).f(tls, p)
	}
	Xsqlite3_result_error_toobig(tls, pCtx)
	return 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 Sqlite3_uint64, xDel uintptr) {
	if n > uint64(0x7fffffff) {
		invokeValueDestructor(tls, z, xDel, pCtx)
	} else {
		setResultStrOrError(tls, pCtx, z, int32(n), uint8(0), xDel)
	}
}

func Xsqlite3_result_double(tls *libc.TLS, pCtx uintptr, rVal float64) {
	Xsqlite3VdbeMemSetDouble(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut, rVal)
}

func Xsqlite3_result_error(tls *libc.TLS, pCtx uintptr, z uintptr, n int32) {
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError = SQLITE_ERROR
	Xsqlite3VdbeMemSetStr(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut, z, int64(n), uint8(SQLITE_UTF8), libc.UintptrFromInt32(-1))
}

func Xsqlite3_result_error16(tls *libc.TLS, pCtx uintptr, z uintptr, n int32) {
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError = SQLITE_ERROR
	Xsqlite3VdbeMemSetStr(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut, z, int64(n), uint8(SQLITE_UTF16LE), libc.UintptrFromInt32(-1))
}

func Xsqlite3_result_int(tls *libc.TLS, pCtx uintptr, iVal int32) {
	Xsqlite3VdbeMemSetInt64(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut, I64(iVal))
}

func Xsqlite3_result_int64(tls *libc.TLS, pCtx uintptr, iVal I64) {
	Xsqlite3VdbeMemSetInt64(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut, iVal)
}

func Xsqlite3_result_null(tls *libc.TLS, pCtx uintptr) {
	Xsqlite3VdbeMemSetNull(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut)
}

func Xsqlite3_result_pointer(tls *libc.TLS, pCtx uintptr, pPtr uintptr, zPType uintptr, xDestructor uintptr) {
	var pOut uintptr = (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut

	Xsqlite3VdbeMemRelease(tls, pOut)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Null)
	Xsqlite3VdbeMemSetPointer(tls, pOut, pPtr, zPType, xDestructor)
}

func Xsqlite3_result_subtype(tls *libc.TLS, pCtx uintptr, eSubtype uint32) {
	var pOut uintptr = (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut

	(*Mem)(unsafe.Pointer(pOut)).FeSubtype = U8(eSubtype & uint32(0xff))
	*(*U16)(unsafe.Pointer(pOut + 20)) |= U16(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 Sqlite3_uint64, xDel uintptr, enc uint8) {
	if int32(enc) != SQLITE_UTF8 {
		if int32(enc) == SQLITE_UTF16 {
			enc = uint8(SQLITE_UTF16LE)
		}
		n = n & libc.CplUint64(uint64(1))
	}
	if n > uint64(0x7fffffff) {
		invokeValueDestructor(tls, z, xDel, pCtx)
	} else {
		setResultStrOrError(tls, pCtx, z, int32(n), enc, xDel)
	}
}

func Xsqlite3_result_text16(tls *libc.TLS, pCtx uintptr, z uintptr, n int32, xDel uintptr) {
	setResultStrOrError(tls, pCtx, z, int32(U64(n)&libc.CplUint64(uint64(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(U64(n)&libc.CplUint64(uint64(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(U64(n)&libc.CplUint64(uint64(1))), uint8(SQLITE_UTF16LE), xDel)
}

func Xsqlite3_result_value(tls *libc.TLS, pCtx uintptr, pValue uintptr) {
	var pOut uintptr = (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut

	Xsqlite3VdbeMemCopy(tls, pOut, pValue)
	Xsqlite3VdbeChangeEncoding(tls, pOut, int32((*Sqlite3_context)(unsafe.Pointer(pCtx)).Fenc))
	if Xsqlite3VdbeMemTooBig(tls, pOut) != 0 {
		Xsqlite3_result_error_toobig(tls, pCtx)
	}
}

func Xsqlite3_result_zeroblob(tls *libc.TLS, pCtx uintptr, n int32) {
	Xsqlite3_result_zeroblob64(tls, pCtx, func() uint64 {
		if n > 0 {
			return uint64(n)
		}
		return uint64(0)
	}())
}

func Xsqlite3_result_zeroblob64(tls *libc.TLS, pCtx uintptr, n U64) int32 {
	var pOut uintptr = (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut

	if n > U64(*(*int32)(unsafe.Pointer((*Mem)(unsafe.Pointer(pOut)).Fdb + 136))) {
		Xsqlite3_result_error_toobig(tls, pCtx)
		return SQLITE_TOOBIG
	}
	Xsqlite3VdbeMemSetZeroBlob(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut, int32(n))
	return SQLITE_OK
}

func Xsqlite3_result_error_code(tls *libc.TLS, pCtx uintptr, errCode int32) {
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError = func() int32 {
		if errCode != 0 {
			return errCode
		}
		return -1
	}()
	if int32((*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut)).Fflags)&MEM_Null != 0 {
		setResultStrOrError(tls, pCtx, Xsqlite3ErrStr(tls, errCode), -1, uint8(SQLITE_UTF8),
			uintptr(0))
	}
}

func Xsqlite3_result_error_toobig(tls *libc.TLS, pCtx uintptr) {
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError = SQLITE_TOOBIG
	Xsqlite3VdbeMemSetStr(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut, ts+8259, int64(-1),
		uint8(SQLITE_UTF8), uintptr(0))
}

func Xsqlite3_result_error_nomem(tls *libc.TLS, pCtx uintptr) {
	Xsqlite3VdbeMemSetNull(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut)
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError = SQLITE_NOMEM
	Xsqlite3OomFault(tls, (*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut)).Fdb)
}

func Xsqlite3ResultIntReal(tls *libc.TLS, pCtx uintptr) {
	if int32((*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut)).Fflags)&MEM_Int != 0 {
		*(*U16)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Int))
		*(*U16)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut + 20)) |= U16(MEM_IntReal)
	}
}

func doWalCallbacks(tls *libc.TLS, db uintptr) int32 {
	var rc int32 = SQLITE_OK
	var i int32
	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if pBt != 0 {
			var nEntry int32
			Xsqlite3BtreeEnter(tls, pBt)
			nEntry = Xsqlite3PagerWalCallback(tls, Xsqlite3BtreePager(tls, pBt))
			Xsqlite3BtreeLeave(tls, pBt)
			if nEntry > 0 && (*Sqlite3)(unsafe.Pointer(db)).FxWalCallback != 0 && rc == SQLITE_OK {
				rc = (*struct {
					f func(*libc.TLS, uintptr, uintptr, uintptr, int32) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxWalCallback})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpWalArg, db, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FzDbSName, nEntry)
			}
		}
	}
	return rc
}

func sqlite3Step(tls *libc.TLS, p uintptr) int32 {
	var db uintptr
	var rc int32

	db = (*Vdbe)(unsafe.Pointer(p)).Fdb
	if !(int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) != VDBE_RUN_STATE) {
		goto __1
	}
restart_step:
	if !(int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) == VDBE_READY_STATE) {
		goto __2
	}
	if !(Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x3>>0)) != 0) {
		goto __4
	}
	(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_SCHEMA
	rc = SQLITE_ERROR
	if !(int32((*Vdbe)(unsafe.Pointer(p)).FprepFlags)&SQLITE_PREPARE_SAVESQL != 0) {
		goto __5
	}

	rc = Xsqlite3VdbeTransferError(tls, p)
__5:
	;
	goto end_of_step
__4:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0) {
		goto __6
	}
	libc.AtomicStoreNInt32(db+432, int32(0), 0)
__6:
	;
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmTrace)&(SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE) != 0 &&
		!(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) && (*Vdbe)(unsafe.Pointer(p)).FzSql != 0) {
		goto __7
	}
	Xsqlite3OsCurrentTimeInt64(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, p+184)
	goto __8
__7:
	;
__8:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive++
	if !(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x40>>6) == 0) {
		goto __9
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnVdbeWrite++
__9:
	;
	if !(Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x80>>7)) != 0) {
		goto __10
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnVdbeRead++
__10:
	;
	(*Vdbe)(unsafe.Pointer(p)).Fpc = 0
	(*Vdbe)(unsafe.Pointer(p)).FeVdbeState = U8(VDBE_RUN_STATE)
	goto __3
__2:
	if !(int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) == VDBE_HALT_STATE) {
		goto __11
	}

	Xsqlite3_reset(tls, p)

	goto restart_step
__11:
	;
__3:
	;
__1:
	;
	if !(Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0xc>>2)) != 0) {
		goto __12
	}
	rc = Xsqlite3VdbeList(tls, p)
	goto __13
__12:
	(*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec++
	rc = Xsqlite3VdbeExec(tls, p)
	(*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec--
__13:
	;
	if !(rc == SQLITE_ROW) {
		goto __14
	}

	(*Sqlite3)(unsafe.Pointer(db)).FerrCode = SQLITE_ROW
	return SQLITE_ROW
	goto __15
__14:
	if !((*Vdbe)(unsafe.Pointer(p)).FstartTime > int64(0)) {
		goto __16
	}
	invokeProfileCallback(tls, db, p)
__16:
	;
	(*Vdbe)(unsafe.Pointer(p)).FpResultRow = uintptr(0)
	if !(rc == SQLITE_DONE && (*Sqlite3)(unsafe.Pointer(db)).FautoCommit != 0) {
		goto __17
	}

	(*Vdbe)(unsafe.Pointer(p)).Frc = doWalCallbacks(tls, db)
	if !((*Vdbe)(unsafe.Pointer(p)).Frc != SQLITE_OK) {
		goto __19
	}
	rc = SQLITE_ERROR
__19:
	;
	goto __18
__17:
	if !(rc != SQLITE_DONE && int32((*Vdbe)(unsafe.Pointer(p)).FprepFlags)&SQLITE_PREPARE_SAVESQL != 0) {
		goto __20
	}

	rc = Xsqlite3VdbeTransferError(tls, p)
__20:
	;
__18:
	;
__15:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FerrCode = rc
	if !(SQLITE_NOMEM == Xsqlite3ApiExit(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, (*Vdbe)(unsafe.Pointer(p)).Frc)) {
		goto __21
	}
	(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
	if !(int32((*Vdbe)(unsafe.Pointer(p)).FprepFlags)&SQLITE_PREPARE_SAVESQL != 0) {
		goto __22
	}
	rc = (*Vdbe)(unsafe.Pointer(p)).Frc
__22:
	;
__21:
	;
end_of_step:
	;
	return rc & (*Sqlite3)(unsafe.Pointer(db)).FerrMask
}

func Xsqlite3_step(tls *libc.TLS, pStmt uintptr) int32 {
	var rc int32 = SQLITE_OK
	var v uintptr = pStmt
	var cnt int32 = 0
	var db uintptr

	if vdbeSafetyNotNull(tls, v) != 0 {
		return Xsqlite3MisuseError(tls, 88548)
	}
	db = (*Vdbe)(unsafe.Pointer(v)).Fdb
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	for libc.AssignInt32(&rc, sqlite3Step(tls, v)) == SQLITE_SCHEMA &&
		libc.PostIncInt32(&cnt, 1) < SQLITE_MAX_SCHEMA_RETRY {
		var savedPc int32 = (*Vdbe)(unsafe.Pointer(v)).Fpc
		rc = Xsqlite3Reprepare(tls, v)
		if rc != SQLITE_OK {
			var zErr uintptr = Xsqlite3_value_text(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr)
			Xsqlite3DbFree(tls, db, (*Vdbe)(unsafe.Pointer(v)).FzErrMsg)
			if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
				(*Vdbe)(unsafe.Pointer(v)).FzErrMsg = Xsqlite3DbStrDup(tls, db, zErr)
				(*Vdbe)(unsafe.Pointer(v)).Frc = libc.AssignInt32(&rc, Xsqlite3ApiExit(tls, db, rc))
			} else {
				(*Vdbe)(unsafe.Pointer(v)).FzErrMsg = uintptr(0)
				(*Vdbe)(unsafe.Pointer(v)).Frc = libc.AssignInt32(&rc, SQLITE_NOMEM)
			}
			break
		}
		Xsqlite3_reset(tls, pStmt)
		if savedPc >= 0 {
			(*Vdbe)(unsafe.Pointer(v)).FminWriteFileFormat = U8(254)
		}

	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_user_data(tls *libc.TLS, p uintptr) uintptr {
	return (*FuncDef)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(p)).FpFunc)).FpUserData
}

func Xsqlite3_context_db_handle(tls *libc.TLS, p uintptr) uintptr {
	return (*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(p)).FpOut)).Fdb
}

func Xsqlite3_vtab_nochange(tls *libc.TLS, p uintptr) int32 {
	return Xsqlite3_value_nochange(tls, (*Sqlite3_context)(unsafe.Pointer(p)).FpOut)
}

func Xsqlite3VdbeValueListFree(tls *libc.TLS, pToDelete uintptr) {
	Xsqlite3_free(tls, pToDelete)
}

func valueFromValueList(tls *libc.TLS, pVal uintptr, ppOut uintptr, bNext int32) int32 {
	bp := tls.Alloc(68)
	defer tls.Free(68)

	var rc int32
	var pRhs uintptr

	*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
	if pVal == uintptr(0) {
		return SQLITE_MISUSE
	}
	if int32((*Sqlite3_value)(unsafe.Pointer(pVal)).Fflags)&MEM_Dyn == 0 || (*Sqlite3_value)(unsafe.Pointer(pVal)).FxDel != *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3VdbeValueListFree})) {
		return SQLITE_ERROR
	} else {
		pRhs = (*Sqlite3_value)(unsafe.Pointer(pVal)).Fz
	}
	if bNext != 0 {
		rc = Xsqlite3BtreeNext(tls, (*ValueList)(unsafe.Pointer(pRhs)).FpCsr, 0)
	} else {
		*(*int32)(unsafe.Pointer(bp)) = 0
		rc = Xsqlite3BtreeFirst(tls, (*ValueList)(unsafe.Pointer(pRhs)).FpCsr, bp)

		if Xsqlite3BtreeEof(tls, (*ValueList)(unsafe.Pointer(pRhs)).FpCsr) != 0 {
			rc = SQLITE_DONE
		}
	}
	if rc == SQLITE_OK {
		var sz U32

		libc.Xmemset(tls, bp+8, 0, uint64(unsafe.Sizeof(Mem{})))
		sz = Xsqlite3BtreePayloadSize(tls, (*ValueList)(unsafe.Pointer(pRhs)).FpCsr)
		rc = Xsqlite3VdbeMemFromBtreeZeroOffset(tls, (*ValueList)(unsafe.Pointer(pRhs)).FpCsr, uint32(int32(sz)), bp+8)
		if rc == SQLITE_OK {
			var zBuf uintptr = (*Mem)(unsafe.Pointer(bp + 8)).Fz

			var pOut uintptr = (*ValueList)(unsafe.Pointer(pRhs)).FpOut
			var iOff int32 = 1 + int32(func() uint8 {
				if int32(*(*U8)(unsafe.Pointer(zBuf + 1))) < int32(U8(0x80)) {
					return uint8(func() int32 { *(*U32)(unsafe.Pointer(bp + 64)) = U32(*(*U8)(unsafe.Pointer(zBuf + 1))); return 1 }())
				}
				return Xsqlite3GetVarint32(tls, zBuf+1, bp+64)
			}())
			Xsqlite3VdbeSerialGet(tls, zBuf+uintptr(iOff), *(*U32)(unsafe.Pointer(bp + 64)), pOut)
			(*Sqlite3_value)(unsafe.Pointer(pOut)).Fenc = (*Sqlite3)(unsafe.Pointer((*Sqlite3_value)(unsafe.Pointer(pOut)).Fdb)).Fenc
			if int32((*Sqlite3_value)(unsafe.Pointer(pOut)).Fflags)&MEM_Ephem != 0 && Xsqlite3VdbeMemMakeWriteable(tls, pOut) != 0 {
				rc = SQLITE_NOMEM
			} else {
				*(*uintptr)(unsafe.Pointer(ppOut)) = pOut
			}
		}
		Xsqlite3VdbeMemRelease(tls, bp+8)
	}
	return rc
}

func Xsqlite3_vtab_in_first(tls *libc.TLS, pVal uintptr, ppOut uintptr) int32 {
	return valueFromValueList(tls, pVal, ppOut, 0)
}

func Xsqlite3_vtab_in_next(tls *libc.TLS, pVal uintptr, ppOut uintptr) int32 {
	return valueFromValueList(tls, pVal, ppOut, 1)
}

func Xsqlite3StmtCurrentTime(tls *libc.TLS, p uintptr) Sqlite3_int64 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	*(*Sqlite3_int64)(unsafe.Pointer(bp)) = int64(0)
	var piTime uintptr
	if (*Sqlite3_context)(unsafe.Pointer(p)).FpVdbe != uintptr(0) {
		piTime = (*Sqlite3_context)(unsafe.Pointer(p)).FpVdbe + 72
	} else {
		piTime = bp
	}
	if *(*Sqlite3_int64)(unsafe.Pointer(piTime)) == int64(0) {
		rc = Xsqlite3OsCurrentTimeInt64(tls, (*Sqlite3)(unsafe.Pointer((*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(p)).FpOut)).Fdb)).FpVfs, piTime)
		if rc != 0 {
			*(*Sqlite3_int64)(unsafe.Pointer(piTime)) = int64(0)
		}
	}
	return *(*Sqlite3_int64)(unsafe.Pointer(piTime))
}

func createAggContext(tls *libc.TLS, p uintptr, nByte int32) uintptr {
	var pMem uintptr = (*Sqlite3_context)(unsafe.Pointer(p)).FpMem

	if nByte <= 0 {
		Xsqlite3VdbeMemSetNull(tls, pMem)
		(*Mem)(unsafe.Pointer(pMem)).Fz = uintptr(0)
	} else {
		Xsqlite3VdbeMemClearAndResize(tls, pMem, nByte)
		(*Mem)(unsafe.Pointer(pMem)).Fflags = U16(MEM_Agg)
		*(*uintptr)(unsafe.Pointer(pMem)) = (*Sqlite3_context)(unsafe.Pointer(p)).FpFunc
		if (*Mem)(unsafe.Pointer(pMem)).Fz != 0 {
			libc.Xmemset(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, 0, uint64(nByte))
		}
	}
	return (*Mem)(unsafe.Pointer(pMem)).Fz
}

func Xsqlite3_aggregate_context(tls *libc.TLS, p uintptr, nByte int32) uintptr {
	if int32((*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(p)).FpMem)).Fflags)&MEM_Agg == 0 {
		return createAggContext(tls, p, nByte)
	} else {
		return (*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(p)).FpMem)).Fz
	}
	return uintptr(0)
}

func Xsqlite3_get_auxdata(tls *libc.TLS, pCtx uintptr, iArg int32) uintptr {
	var pAuxData uintptr

	if (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe == uintptr(0) {
		return uintptr(0)
	}
	for pAuxData = (*Vdbe)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe)).FpAuxData; pAuxData != 0; pAuxData = (*AuxData)(unsafe.Pointer(pAuxData)).FpNextAux {
		if (*AuxData)(unsafe.Pointer(pAuxData)).FiAuxArg == iArg && ((*AuxData)(unsafe.Pointer(pAuxData)).FiAuxOp == (*Sqlite3_context)(unsafe.Pointer(pCtx)).FiOp || iArg < 0) {
			return (*AuxData)(unsafe.Pointer(pAuxData)).FpAux
		}
	}
	return uintptr(0)
}

func Xsqlite3_set_auxdata(tls *libc.TLS, pCtx uintptr, iArg int32, pAux uintptr, xDelete uintptr) {
	var pAuxData uintptr
	var pVdbe uintptr
	pVdbe = (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe

	if !(pVdbe == uintptr(0)) {
		goto __1
	}
	goto failed
__1:
	;
	pAuxData = (*Vdbe)(unsafe.Pointer(pVdbe)).FpAuxData
__2:
	if !(pAuxData != 0) {
		goto __4
	}
	if !((*AuxData)(unsafe.Pointer(pAuxData)).FiAuxArg == iArg && ((*AuxData)(unsafe.Pointer(pAuxData)).FiAuxOp == (*Sqlite3_context)(unsafe.Pointer(pCtx)).FiOp || iArg < 0)) {
		goto __5
	}
	goto __4
__5:
	;
	goto __3
__3:
	pAuxData = (*AuxData)(unsafe.Pointer(pAuxData)).FpNextAux
	goto __2
	goto __4
__4:
	;
	if !(pAuxData == uintptr(0)) {
		goto __6
	}
	pAuxData = Xsqlite3DbMallocZero(tls, (*Vdbe)(unsafe.Pointer(pVdbe)).Fdb, uint64(unsafe.Sizeof(AuxData{})))
	if !!(pAuxData != 0) {
		goto __8
	}
	goto failed
__8:
	;
	(*AuxData)(unsafe.Pointer(pAuxData)).FiAuxOp = (*Sqlite3_context)(unsafe.Pointer(pCtx)).FiOp
	(*AuxData)(unsafe.Pointer(pAuxData)).FiAuxArg = iArg
	(*AuxData)(unsafe.Pointer(pAuxData)).FpNextAux = (*Vdbe)(unsafe.Pointer(pVdbe)).FpAuxData
	(*Vdbe)(unsafe.Pointer(pVdbe)).FpAuxData = pAuxData
	if !((*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError == 0) {
		goto __9
	}
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError = -1
__9:
	;
	goto __7
__6:
	if !((*AuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux != 0) {
		goto __10
	}
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*AuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux})).f(tls, (*AuxData)(unsafe.Pointer(pAuxData)).FpAux)
__10:
	;
__7:
	;
	(*AuxData)(unsafe.Pointer(pAuxData)).FpAux = pAux
	(*AuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux = xDelete
	return

failed:
	if !(xDelete != 0) {
		goto __11
	}
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDelete})).f(tls, pAux)
__11:
}

func Xsqlite3_aggregate_count(tls *libc.TLS, p uintptr) int32 {
	return (*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(p)).FpMem)).Fn
}

func Xsqlite3_column_count(tls *libc.TLS, pStmt uintptr) int32 {
	var pVm uintptr = pStmt
	if pVm != 0 {
		return int32((*Vdbe)(unsafe.Pointer(pVm)).FnResColumn)
	}
	return 0
}

func Xsqlite3_data_count(tls *libc.TLS, pStmt uintptr) int32 {
	var pVm uintptr = pStmt
	if pVm == uintptr(0) || (*Vdbe)(unsafe.Pointer(pVm)).FpResultRow == uintptr(0) {
		return 0
	}
	return int32((*Vdbe)(unsafe.Pointer(pVm)).FnResColumn)
}

func columnNullValue(tls *libc.TLS) uintptr {
	return uintptr(unsafe.Pointer(&nullMem))
}

var nullMem = Mem{
	Fflags: U16(MEM_Null),
}

func columnMem(tls *libc.TLS, pStmt uintptr, i int32) uintptr {
	var pVm uintptr
	var pOut uintptr

	pVm = pStmt
	if pVm == uintptr(0) {
		return columnNullValue(tls)
	}

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(pVm)).Fdb)).Fmutex)
	if (*Vdbe)(unsafe.Pointer(pVm)).FpResultRow != uintptr(0) && i < int32((*Vdbe)(unsafe.Pointer(pVm)).FnResColumn) && i >= 0 {
		pOut = (*Vdbe)(unsafe.Pointer(pVm)).FpResultRow + uintptr(i)*56
	} else {
		Xsqlite3Error(tls, (*Vdbe)(unsafe.Pointer(pVm)).Fdb, SQLITE_RANGE)
		pOut = columnNullValue(tls)
	}
	return pOut
}

func columnMallocFailure(tls *libc.TLS, pStmt uintptr) {
	var p uintptr = pStmt
	if p != 0 {
		(*Vdbe)(unsafe.Pointer(p)).Frc = Xsqlite3ApiExit(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, (*Vdbe)(unsafe.Pointer(p)).Frc)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
}

func Xsqlite3_column_blob(tls *libc.TLS, pStmt uintptr, i int32) uintptr {
	var val uintptr
	val = Xsqlite3_value_blob(tls, columnMem(tls, pStmt, i))

	columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_bytes(tls *libc.TLS, pStmt uintptr, i int32) int32 {
	var val int32 = Xsqlite3_value_bytes(tls, columnMem(tls, pStmt, i))
	columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_bytes16(tls *libc.TLS, pStmt uintptr, i int32) int32 {
	var val int32 = Xsqlite3_value_bytes16(tls, columnMem(tls, pStmt, i))
	columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_double(tls *libc.TLS, pStmt uintptr, i int32) float64 {
	var val float64 = Xsqlite3_value_double(tls, columnMem(tls, pStmt, i))
	columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_int(tls *libc.TLS, pStmt uintptr, i int32) int32 {
	var val int32 = Xsqlite3_value_int(tls, columnMem(tls, pStmt, i))
	columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_int64(tls *libc.TLS, pStmt uintptr, i int32) Sqlite_int64 {
	var val Sqlite_int64 = Xsqlite3_value_int64(tls, columnMem(tls, pStmt, i))
	columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_text(tls *libc.TLS, pStmt uintptr, i int32) uintptr {
	var val uintptr = Xsqlite3_value_text(tls, columnMem(tls, pStmt, i))
	columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_value(tls *libc.TLS, pStmt uintptr, i int32) uintptr {
	var pOut uintptr = columnMem(tls, pStmt, i)
	if int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&MEM_Static != 0 {
		*(*U16)(unsafe.Pointer(pOut + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Static))
		*(*U16)(unsafe.Pointer(pOut + 20)) |= U16(MEM_Ephem)
	}
	columnMallocFailure(tls, pStmt)
	return pOut
}

func Xsqlite3_column_text16(tls *libc.TLS, pStmt uintptr, i int32) uintptr {
	var val uintptr = Xsqlite3_value_text16(tls, columnMem(tls, pStmt, i))
	columnMallocFailure(tls, pStmt)
	return val
}

func Xsqlite3_column_type(tls *libc.TLS, pStmt uintptr, i int32) int32 {
	var iType int32 = Xsqlite3_value_type(tls, columnMem(tls, pStmt, i))
	columnMallocFailure(tls, pStmt)
	return iType
}

func columnName(tls *libc.TLS, pStmt uintptr, N int32, useUtf16 int32, useType int32) uintptr {
	var ret uintptr
	var p uintptr
	var n int32
	var db uintptr
	ret = uintptr(0)
	p = pStmt
	db = (*Vdbe)(unsafe.Pointer(p)).Fdb

	n = Xsqlite3_column_count(tls, pStmt)
	if N < n && N >= 0 {
		N = N + useType*n
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)

		if useUtf16 != 0 {
			ret = Xsqlite3_value_text16(tls, (*Vdbe)(unsafe.Pointer(p)).FaColName+uintptr(N)*56)
		} else {
			ret = Xsqlite3_value_text(tls, (*Vdbe)(unsafe.Pointer(p)).FaColName+uintptr(N)*56)
		}

		if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			Xsqlite3OomClear(tls, db)
			ret = uintptr(0)
		}
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	}
	return ret
}

func Xsqlite3_column_name(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 0, COLNAME_NAME)
}

func Xsqlite3_column_name16(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 1, COLNAME_NAME)
}

func Xsqlite3_column_decltype(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 0, COLNAME_DECLTYPE)
}

func Xsqlite3_column_decltype16(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 1, COLNAME_DECLTYPE)
}

func Xsqlite3_column_database_name(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 0, COLNAME_DATABASE)
}

func Xsqlite3_column_database_name16(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 1, COLNAME_DATABASE)
}

func Xsqlite3_column_table_name(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 0, COLNAME_TABLE)
}

func Xsqlite3_column_table_name16(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 1, COLNAME_TABLE)
}

func Xsqlite3_column_origin_name(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 0, COLNAME_COLUMN)
}

func Xsqlite3_column_origin_name16(tls *libc.TLS, pStmt uintptr, N int32) uintptr {
	return columnName(tls, pStmt, N, 1, COLNAME_COLUMN)
}

func vdbeUnbind(tls *libc.TLS, p uintptr, i uint32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pVar uintptr
	if vdbeSafetyNotNull(tls, p) != 0 {
		return Xsqlite3MisuseError(tls, 89212)
	}
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	if int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) != VDBE_READY_STATE {
		Xsqlite3Error(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, SQLITE_MISUSE)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		Xsqlite3_log(tls, SQLITE_MISUSE,
			ts+8282, libc.VaList(bp, (*Vdbe)(unsafe.Pointer(p)).FzSql))
		return Xsqlite3MisuseError(tls, 89220)
	}
	if i >= uint32((*Vdbe)(unsafe.Pointer(p)).FnVar) {
		Xsqlite3Error(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, SQLITE_RANGE)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		return SQLITE_RANGE
	}
	pVar = (*Vdbe)(unsafe.Pointer(p)).FaVar + uintptr(i)*56
	Xsqlite3VdbeMemRelease(tls, pVar)
	(*Mem)(unsafe.Pointer(pVar)).Fflags = U16(MEM_Null)
	(*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FerrCode = SQLITE_OK

	if (*Vdbe)(unsafe.Pointer(p)).Fexpmask != U32(0) && (*Vdbe)(unsafe.Pointer(p)).Fexpmask&func() uint32 {
		if i >= uint32(31) {
			return 0x80000000
		}
		return U32(1) << i
	}() != U32(0) {
		libc.SetBitFieldPtr8Uint32(p+200, Bft(1), 0, 0x3)
	}
	return SQLITE_OK
}

func bindText(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData I64, xDel uintptr, encoding U8) int32 {
	var p uintptr = pStmt
	var pVar uintptr
	var rc int32

	rc = vdbeUnbind(tls, p, U32(i-1))
	if rc == SQLITE_OK {
		if zData != uintptr(0) {
			pVar = (*Vdbe)(unsafe.Pointer(p)).FaVar + uintptr(i-1)*56
			rc = Xsqlite3VdbeMemSetStr(tls, pVar, zData, nData, encoding, xDel)
			if rc == SQLITE_OK && int32(encoding) != 0 {
				rc = Xsqlite3VdbeChangeEncoding(tls, pVar, int32((*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fenc))
			}
			if rc != 0 {
				Xsqlite3Error(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, rc)
				rc = Xsqlite3ApiExit(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, rc)
			}
		}
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	} else if xDel != uintptr(0) && xDel != libc.UintptrFromInt32(-1) {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDel})).f(tls, zData)
	}
	return rc
}

func Xsqlite3_bind_blob(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData int32, xDel uintptr) int32 {
	return bindText(tls, pStmt, i, zData, int64(nData), xDel, uint8(0))
}

func Xsqlite3_bind_blob64(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData Sqlite3_uint64, xDel uintptr) int32 {
	return bindText(tls, pStmt, i, zData, int64(nData), xDel, uint8(0))
}

func Xsqlite3_bind_double(tls *libc.TLS, pStmt uintptr, i int32, rValue float64) int32 {
	var rc int32
	var p uintptr = pStmt
	rc = vdbeUnbind(tls, p, U32(i-1))
	if rc == SQLITE_OK {
		Xsqlite3VdbeMemSetDouble(tls, (*Vdbe)(unsafe.Pointer(p)).FaVar+uintptr(i-1)*56, rValue)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return rc
}

func Xsqlite3_bind_int(tls *libc.TLS, p uintptr, i int32, iValue int32) int32 {
	return Xsqlite3_bind_int64(tls, p, i, I64(iValue))
}

func Xsqlite3_bind_int64(tls *libc.TLS, pStmt uintptr, i int32, iValue Sqlite_int64) int32 {
	var rc int32
	var p uintptr = pStmt
	rc = vdbeUnbind(tls, p, U32(i-1))
	if rc == SQLITE_OK {
		Xsqlite3VdbeMemSetInt64(tls, (*Vdbe)(unsafe.Pointer(p)).FaVar+uintptr(i-1)*56, iValue)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return rc
}

func Xsqlite3_bind_null(tls *libc.TLS, pStmt uintptr, i int32) int32 {
	var rc int32
	var p uintptr = pStmt
	rc = vdbeUnbind(tls, p, U32(i-1))
	if rc == SQLITE_OK {
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return rc
}

func Xsqlite3_bind_pointer(tls *libc.TLS, pStmt uintptr, i int32, pPtr uintptr, zPTtype uintptr, xDestructor uintptr) int32 {
	var rc int32
	var p uintptr = pStmt
	rc = vdbeUnbind(tls, p, U32(i-1))
	if rc == SQLITE_OK {
		Xsqlite3VdbeMemSetPointer(tls, (*Vdbe)(unsafe.Pointer(p)).FaVar+uintptr(i-1)*56, pPtr, zPTtype, xDestructor)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	} else if xDestructor != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDestructor})).f(tls, pPtr)
	}
	return rc
}

func Xsqlite3_bind_text(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData int32, xDel uintptr) int32 {
	return bindText(tls, pStmt, i, zData, int64(nData), xDel, uint8(SQLITE_UTF8))
}

func Xsqlite3_bind_text64(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, nData Sqlite3_uint64, xDel uintptr, enc uint8) int32 {
	if int32(enc) != SQLITE_UTF8 {
		if int32(enc) == SQLITE_UTF16 {
			enc = uint8(SQLITE_UTF16LE)
		}
		nData = nData & libc.Uint64FromInt32(libc.CplInt32(int32(U16(1))))
	}
	return bindText(tls, pStmt, i, zData, int64(nData), xDel, enc)
}

func Xsqlite3_bind_text16(tls *libc.TLS, pStmt uintptr, i int32, zData uintptr, n int32, xDel uintptr) int32 {
	return bindText(tls, pStmt, i, zData, int64(U64(n)&libc.CplUint64(uint64(1))), xDel, uint8(SQLITE_UTF16LE))
}

func Xsqlite3_bind_value(tls *libc.TLS, pStmt uintptr, i int32, pValue uintptr) int32 {
	var rc int32
	switch Xsqlite3_value_type(tls, pValue) {
	case SQLITE_INTEGER:
		{
			rc = Xsqlite3_bind_int64(tls, pStmt, i, *(*I64)(unsafe.Pointer(pValue)))
			break

		}
	case SQLITE_FLOAT:
		{
			rc = Xsqlite3_bind_double(tls, pStmt, i,
				func() float64 {
					if int32((*Sqlite3_value)(unsafe.Pointer(pValue)).Fflags)&MEM_Real != 0 {
						return *(*float64)(unsafe.Pointer(pValue))
					}
					return float64(*(*I64)(unsafe.Pointer(pValue)))
				}())
			break

		}
	case SQLITE_BLOB:
		{
			if int32((*Sqlite3_value)(unsafe.Pointer(pValue)).Fflags)&MEM_Zero != 0 {
				rc = Xsqlite3_bind_zeroblob(tls, pStmt, i, *(*int32)(unsafe.Pointer(pValue)))
			} else {
				rc = Xsqlite3_bind_blob(tls, pStmt, i, (*Sqlite3_value)(unsafe.Pointer(pValue)).Fz, (*Sqlite3_value)(unsafe.Pointer(pValue)).Fn, libc.UintptrFromInt32(-1))
			}
			break

		}
	case SQLITE_TEXT:
		{
			rc = bindText(tls, pStmt, i, (*Sqlite3_value)(unsafe.Pointer(pValue)).Fz, int64((*Sqlite3_value)(unsafe.Pointer(pValue)).Fn), libc.UintptrFromInt32(-1),
				(*Sqlite3_value)(unsafe.Pointer(pValue)).Fenc)
			break

		}
	default:
		{
			rc = Xsqlite3_bind_null(tls, pStmt, i)
			break

		}
	}
	return rc
}

func Xsqlite3_bind_zeroblob(tls *libc.TLS, pStmt uintptr, i int32, n int32) int32 {
	var rc int32
	var p uintptr = pStmt
	rc = vdbeUnbind(tls, p, U32(i-1))
	if rc == SQLITE_OK {
		Xsqlite3VdbeMemSetZeroBlob(tls, (*Vdbe)(unsafe.Pointer(p)).FaVar+uintptr(i-1)*56, n)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return rc
}

func Xsqlite3_bind_zeroblob64(tls *libc.TLS, pStmt uintptr, i int32, n Sqlite3_uint64) int32 {
	var rc int32
	var p uintptr = pStmt
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	if n > U64(*(*int32)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb + 136))) {
		rc = SQLITE_TOOBIG
	} else {
		rc = Xsqlite3_bind_zeroblob(tls, pStmt, i, int32(n))
	}
	rc = Xsqlite3ApiExit(tls, (*Vdbe)(unsafe.Pointer(p)).Fdb, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	return rc
}

func Xsqlite3_bind_parameter_count(tls *libc.TLS, pStmt uintptr) int32 {
	var p uintptr = pStmt
	if p != 0 {
		return int32((*Vdbe)(unsafe.Pointer(p)).FnVar)
	}
	return 0
}

func Xsqlite3_bind_parameter_name(tls *libc.TLS, pStmt uintptr, i int32) uintptr {
	var p uintptr = pStmt
	if p == uintptr(0) {
		return uintptr(0)
	}
	return Xsqlite3VListNumToName(tls, (*Vdbe)(unsafe.Pointer(p)).FpVList, i)
}

func Xsqlite3VdbeParameterIndex(tls *libc.TLS, p uintptr, zName uintptr, nName int32) int32 {
	if p == uintptr(0) || zName == uintptr(0) {
		return 0
	}
	return Xsqlite3VListNameToNum(tls, (*Vdbe)(unsafe.Pointer(p)).FpVList, zName, nName)
}

func Xsqlite3_bind_parameter_index(tls *libc.TLS, pStmt uintptr, zName uintptr) int32 {
	return Xsqlite3VdbeParameterIndex(tls, pStmt, zName, Xsqlite3Strlen30(tls, zName))
}

func Xsqlite3TransferBindings(tls *libc.TLS, pFromStmt uintptr, pToStmt uintptr) int32 {
	var pFrom uintptr = pFromStmt
	var pTo uintptr = pToStmt
	var i int32

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(pTo)).Fdb)).Fmutex)
	for i = 0; i < int32((*Vdbe)(unsafe.Pointer(pFrom)).FnVar); i++ {
		Xsqlite3VdbeMemMove(tls, (*Vdbe)(unsafe.Pointer(pTo)).FaVar+uintptr(i)*56, (*Vdbe)(unsafe.Pointer(pFrom)).FaVar+uintptr(i)*56)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(pTo)).Fdb)).Fmutex)
	return SQLITE_OK
}

func Xsqlite3_transfer_bindings(tls *libc.TLS, pFromStmt uintptr, pToStmt uintptr) int32 {
	var pFrom uintptr = pFromStmt
	var pTo uintptr = pToStmt
	if int32((*Vdbe)(unsafe.Pointer(pFrom)).FnVar) != int32((*Vdbe)(unsafe.Pointer(pTo)).FnVar) {
		return SQLITE_ERROR
	}

	if (*Vdbe)(unsafe.Pointer(pTo)).Fexpmask != 0 {
		libc.SetBitFieldPtr8Uint32(pTo+200, Bft(1), 0, 0x3)
	}

	if (*Vdbe)(unsafe.Pointer(pFrom)).Fexpmask != 0 {
		libc.SetBitFieldPtr8Uint32(pFrom+200, Bft(1), 0, 0x3)
	}
	return Xsqlite3TransferBindings(tls, pFromStmt, pToStmt)
}

func Xsqlite3_db_handle(tls *libc.TLS, pStmt uintptr) uintptr {
	if pStmt != 0 {
		return (*Vdbe)(unsafe.Pointer(pStmt)).Fdb
	}
	return uintptr(0)
}

func Xsqlite3_stmt_readonly(tls *libc.TLS, pStmt uintptr) int32 {
	if pStmt != 0 {
		return int32(*(*uint8)(unsafe.Pointer(pStmt + 200)) & 0x40 >> 6)
	}
	return 1
}

func Xsqlite3_stmt_isexplain(tls *libc.TLS, pStmt uintptr) int32 {
	if pStmt != 0 {
		return int32(*(*uint8)(unsafe.Pointer(pStmt + 200)) & 0xc >> 2)
	}
	return 0
}

func Xsqlite3_stmt_busy(tls *libc.TLS, pStmt uintptr) int32 {
	var v uintptr = pStmt
	return libc.Bool32(v != uintptr(0) && int32((*Vdbe)(unsafe.Pointer(v)).FeVdbeState) == VDBE_RUN_STATE)
}

func Xsqlite3_next_stmt(tls *libc.TLS, pDb uintptr, pStmt uintptr) uintptr {
	var pNext uintptr
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(pDb)).Fmutex)
	if pStmt == uintptr(0) {
		pNext = (*Sqlite3)(unsafe.Pointer(pDb)).FpVdbe
	} else {
		pNext = (*Vdbe)(unsafe.Pointer(pStmt)).FpVNext
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(pDb)).Fmutex)
	return pNext
}

func Xsqlite3_stmt_status(tls *libc.TLS, pStmt uintptr, op int32, resetFlag int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pVdbe uintptr = pStmt

	if op == SQLITE_STMTSTATUS_MEMUSED {
		var db uintptr = (*Vdbe)(unsafe.Pointer(pVdbe)).Fdb
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		*(*U32)(unsafe.Pointer(bp)) = U32(0)
		(*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed = bp

		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart
		Xsqlite3VdbeDelete(tls, pVdbe)
		(*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	} else {
		*(*U32)(unsafe.Pointer(bp)) = *(*U32)(unsafe.Pointer(pVdbe + 212 + uintptr(op)*4))
		if resetFlag != 0 {
			*(*U32)(unsafe.Pointer(pVdbe + 212 + uintptr(op)*4)) = U32(0)
		}
	}
	return int32(*(*U32)(unsafe.Pointer(bp)))
}

func Xsqlite3_sql(tls *libc.TLS, pStmt uintptr) uintptr {
	var p uintptr = pStmt
	if p != 0 {
		return (*Vdbe)(unsafe.Pointer(p)).FzSql
	}
	return uintptr(0)
}

func Xsqlite3_expanded_sql(tls *libc.TLS, pStmt uintptr) uintptr {
	var z uintptr = uintptr(0)
	var zSql uintptr = Xsqlite3_sql(tls, pStmt)
	if zSql != 0 {
		var p uintptr = pStmt
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
		z = Xsqlite3VdbeExpandSql(tls, p, zSql)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).Fmutex)
	}
	return z
}

func vdbeUnpackRecord(tls *libc.TLS, pKeyInfo uintptr, nKey int32, pKey uintptr) uintptr {
	var pRet uintptr

	pRet = Xsqlite3VdbeAllocUnpackedRecord(tls, pKeyInfo)
	if pRet != 0 {
		libc.Xmemset(tls, (*UnpackedRecord)(unsafe.Pointer(pRet)).FaMem, 0, uint64(unsafe.Sizeof(Mem{}))*uint64(int32((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField)+1))
		Xsqlite3VdbeRecordUnpack(tls, pKeyInfo, nKey, pKey, pRet)
	}
	return pRet
}

func Xsqlite3_preupdate_old(tls *libc.TLS, db uintptr, iIdx int32, ppValue uintptr) int32 {
	var p uintptr
	var pMem uintptr
	var rc int32
	var nRec U32
	var aRec uintptr
	p = (*Sqlite3)(unsafe.Pointer(db)).FpPreUpdate
	rc = SQLITE_OK

	if !(!(p != 0) || (*PreUpdate)(unsafe.Pointer(p)).Fop == SQLITE_INSERT) {
		goto __1
	}
	rc = Xsqlite3MisuseError(tls, 89711)
	goto preupdate_old_out
__1:
	;
	if !((*PreUpdate)(unsafe.Pointer(p)).FpPk != 0) {
		goto __2
	}
	iIdx = int32(Xsqlite3TableColumnToIndex(tls, (*PreUpdate)(unsafe.Pointer(p)).FpPk, int16(iIdx)))
__2:
	;
	if !(iIdx >= int32((*VdbeCursor)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpCsr)).FnField) || iIdx < 0) {
		goto __3
	}
	rc = SQLITE_RANGE
	goto preupdate_old_out
__3:
	;
	if !((*PreUpdate)(unsafe.Pointer(p)).FpUnpacked == uintptr(0)) {
		goto __4
	}

	nRec = Xsqlite3BtreePayloadSize(tls, *(*uintptr)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpCsr + 48)))
	aRec = Xsqlite3DbMallocRaw(tls, db, uint64(nRec))
	if !!(aRec != 0) {
		goto __5
	}
	goto preupdate_old_out
__5:
	;
	rc = Xsqlite3BtreePayload(tls, *(*uintptr)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpCsr + 48)), uint32(0), nRec, aRec)
	if !(rc == SQLITE_OK) {
		goto __6
	}
	(*PreUpdate)(unsafe.Pointer(p)).FpUnpacked = vdbeUnpackRecord(tls, p+32, int32(nRec), aRec)
	if !!(int32((*PreUpdate)(unsafe.Pointer(p)).FpUnpacked) != 0) {
		goto __7
	}
	rc = SQLITE_NOMEM
__7:
	;
__6:
	;
	if !(rc != SQLITE_OK) {
		goto __8
	}
	Xsqlite3DbFree(tls, db, aRec)
	goto preupdate_old_out
__8:
	;
	(*PreUpdate)(unsafe.Pointer(p)).FaRecord = aRec
__4:
	;
	pMem = libc.AssignPtrUintptr(ppValue, (*UnpackedRecord)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpUnpacked)).FaMem+uintptr(iIdx)*56)
	if !(iIdx == int32((*Table)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpTab)).FiPKey)) {
		goto __9
	}
	Xsqlite3VdbeMemSetInt64(tls, pMem, (*PreUpdate)(unsafe.Pointer(p)).FiKey1)
	goto __10
__9:
	if !(iIdx >= int32((*UnpackedRecord)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpUnpacked)).FnField)) {
		goto __11
	}
	*(*uintptr)(unsafe.Pointer(ppValue)) = columnNullValue(tls)
	goto __12
__11:
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpTab)).FaCol+uintptr(iIdx)*24)).Faffinity) == SQLITE_AFF_REAL) {
		goto __13
	}
	if !(int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Int|MEM_IntReal) != 0) {
		goto __14
	}

	Xsqlite3VdbeMemRealify(tls, pMem)
__14:
	;
__13:
	;
__12:
	;
__10:
	;
preupdate_old_out:
	Xsqlite3Error(tls, db, rc)
	return Xsqlite3ApiExit(tls, db, rc)
}

func Xsqlite3_preupdate_count(tls *libc.TLS, db uintptr) int32 {
	var p uintptr = (*Sqlite3)(unsafe.Pointer(db)).FpPreUpdate
	return func() int32 {
		if p != 0 {
			return int32((*PreUpdate)(unsafe.Pointer(p)).Fkeyinfo.FnKeyField)
		}
		return 0
	}()
}

func Xsqlite3_preupdate_depth(tls *libc.TLS, db uintptr) int32 {
	var p uintptr = (*Sqlite3)(unsafe.Pointer(db)).FpPreUpdate
	return func() int32 {
		if p != 0 {
			return (*Vdbe)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).Fv)).FnFrame
		}
		return 0
	}()
}

func Xsqlite3_preupdate_blobwrite(tls *libc.TLS, db uintptr) int32 {
	var p uintptr = (*Sqlite3)(unsafe.Pointer(db)).FpPreUpdate
	return func() int32 {
		if p != 0 {
			return (*PreUpdate)(unsafe.Pointer(p)).FiBlobWrite
		}
		return -1
	}()
}

func Xsqlite3_preupdate_new(tls *libc.TLS, db uintptr, iIdx int32, ppValue uintptr) int32 {
	var p uintptr
	var rc int32
	var pMem uintptr
	var pData uintptr

	var pUnpack uintptr
	p = (*Sqlite3)(unsafe.Pointer(db)).FpPreUpdate
	rc = SQLITE_OK

	if !(!(p != 0) || (*PreUpdate)(unsafe.Pointer(p)).Fop == SQLITE_DELETE) {
		goto __1
	}
	rc = Xsqlite3MisuseError(tls, 89813)
	goto preupdate_new_out
__1:
	;
	if !((*PreUpdate)(unsafe.Pointer(p)).FpPk != 0 && (*PreUpdate)(unsafe.Pointer(p)).Fop != SQLITE_UPDATE) {
		goto __2
	}
	iIdx = int32(Xsqlite3TableColumnToIndex(tls, (*PreUpdate)(unsafe.Pointer(p)).FpPk, int16(iIdx)))
__2:
	;
	if !(iIdx >= int32((*VdbeCursor)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpCsr)).FnField) || iIdx < 0) {
		goto __3
	}
	rc = SQLITE_RANGE
	goto preupdate_new_out
__3:
	;
	if !((*PreUpdate)(unsafe.Pointer(p)).Fop == SQLITE_INSERT) {
		goto __4
	}

	pUnpack = (*PreUpdate)(unsafe.Pointer(p)).FpNewUnpacked
	if !!(pUnpack != 0) {
		goto __6
	}
	pData = (*Vdbe)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).Fv)).FaMem + uintptr((*PreUpdate)(unsafe.Pointer(p)).FiNewReg)*56
	rc = func() int32 {
		if int32((*Mem)(unsafe.Pointer(pData)).Fflags)&MEM_Zero != 0 {
			return Xsqlite3VdbeMemExpandBlob(tls, pData)
		}
		return 0
	}()
	if !(rc != SQLITE_OK) {
		goto __7
	}
	goto preupdate_new_out
__7:
	;
	pUnpack = vdbeUnpackRecord(tls, p+32, (*Mem)(unsafe.Pointer(pData)).Fn, (*Mem)(unsafe.Pointer(pData)).Fz)
	if !!(pUnpack != 0) {
		goto __8
	}
	rc = SQLITE_NOMEM
	goto preupdate_new_out
__8:
	;
	(*PreUpdate)(unsafe.Pointer(p)).FpNewUnpacked = pUnpack
__6:
	;
	pMem = (*UnpackedRecord)(unsafe.Pointer(pUnpack)).FaMem + uintptr(iIdx)*56
	if !(iIdx == int32((*Table)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpTab)).FiPKey)) {
		goto __9
	}
	Xsqlite3VdbeMemSetInt64(tls, pMem, (*PreUpdate)(unsafe.Pointer(p)).FiKey2)
	goto __10
__9:
	if !(iIdx >= int32((*UnpackedRecord)(unsafe.Pointer(pUnpack)).FnField)) {
		goto __11
	}
	pMem = columnNullValue(tls)
__11:
	;
__10:
	;
	goto __5
__4:
	;
	if !!(int32((*PreUpdate)(unsafe.Pointer(p)).FaNew) != 0) {
		goto __12
	}
	(*PreUpdate)(unsafe.Pointer(p)).FaNew = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Mem{}))*uint64((*VdbeCursor)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpCsr)).FnField))
	if !!(int32((*PreUpdate)(unsafe.Pointer(p)).FaNew) != 0) {
		goto __13
	}
	rc = SQLITE_NOMEM
	goto preupdate_new_out
__13:
	;
__12:
	;
	pMem = (*PreUpdate)(unsafe.Pointer(p)).FaNew + uintptr(iIdx)*56
	if !(int32((*Mem)(unsafe.Pointer(pMem)).Fflags) == 0) {
		goto __14
	}
	if !(iIdx == int32((*Table)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).FpTab)).FiPKey)) {
		goto __15
	}
	Xsqlite3VdbeMemSetInt64(tls, pMem, (*PreUpdate)(unsafe.Pointer(p)).FiKey2)
	goto __16
__15:
	rc = Xsqlite3VdbeMemCopy(tls, pMem, (*Vdbe)(unsafe.Pointer((*PreUpdate)(unsafe.Pointer(p)).Fv)).FaMem+uintptr((*PreUpdate)(unsafe.Pointer(p)).FiNewReg+1+iIdx)*56)
	if !(rc != SQLITE_OK) {
		goto __17
	}
	goto preupdate_new_out
__17:
	;
__16:
	;
__14:
	;
__5:
	;
	*(*uintptr)(unsafe.Pointer(ppValue)) = pMem

preupdate_new_out:
	Xsqlite3Error(tls, db, rc)
	return Xsqlite3ApiExit(tls, db, rc)
}

func findNextHostParameter(tls *libc.TLS, zSql uintptr, pnToken uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var nTotal int32 = 0
	var n int32

	*(*int32)(unsafe.Pointer(pnToken)) = 0
	for *(*uint8)(unsafe.Pointer(zSql)) != 0 {
		n = Xsqlite3GetToken(tls, zSql, bp)

		if *(*int32)(unsafe.Pointer(bp)) == TK_VARIABLE {
			*(*int32)(unsafe.Pointer(pnToken)) = n
			break
		}
		nTotal = nTotal + n
		zSql += uintptr(n)
	}
	return nTotal
}

func Xsqlite3VdbeExpandSql(tls *libc.TLS, p uintptr, zRawSql uintptr) uintptr {
	bp := tls.Alloc(144)
	defer tls.Free(144)

	var db uintptr
	*(*int32)(unsafe.Pointer(bp + 84)) = 0
	var nextIndex int32 = 1
	var n int32

	var i int32
	var pVar uintptr

	db = (*Vdbe)(unsafe.Pointer(p)).Fdb
	Xsqlite3StrAccumInit(tls, bp+48, uintptr(0), uintptr(0), 0, *(*int32)(unsafe.Pointer(db + 136)))
	if (*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec > 1 {
		for *(*uint8)(unsafe.Pointer(zRawSql)) != 0 {
			var zStart uintptr = zRawSql
			for int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zRawSql, 1)))) != '\n' && *(*uint8)(unsafe.Pointer(zRawSql)) != 0 {
			}
			Xsqlite3_str_append(tls, bp+48, ts+8322, 3)

			Xsqlite3_str_append(tls, bp+48, zStart, int32((int64(zRawSql)-int64(zStart))/1))
		}
	} else if int32((*Vdbe)(unsafe.Pointer(p)).FnVar) == 0 {
		Xsqlite3_str_append(tls, bp+48, zRawSql, Xsqlite3Strlen30(tls, zRawSql))
	} else {
		for *(*uint8)(unsafe.Pointer(zRawSql)) != 0 {
			n = findNextHostParameter(tls, zRawSql, bp+80)

			Xsqlite3_str_append(tls, bp+48, zRawSql, n)
			zRawSql += uintptr(n)

			if *(*int32)(unsafe.Pointer(bp + 80)) == 0 {
				break
			}
			if int32(*(*uint8)(unsafe.Pointer(zRawSql))) == '?' {
				if *(*int32)(unsafe.Pointer(bp + 80)) > 1 {
					Xsqlite3GetInt32(tls, zRawSql+1, bp+84)
				} else {
					*(*int32)(unsafe.Pointer(bp + 84)) = nextIndex
				}
			} else {
				*(*int32)(unsafe.Pointer(bp + 84)) = Xsqlite3VdbeParameterIndex(tls, p, zRawSql, *(*int32)(unsafe.Pointer(bp + 80)))

			}
			zRawSql += uintptr(*(*int32)(unsafe.Pointer(bp + 80)))
			nextIndex = func() int32 {
				if *(*int32)(unsafe.Pointer(bp + 84))+1 > nextIndex {
					return *(*int32)(unsafe.Pointer(bp + 84)) + 1
				}
				return nextIndex
			}()

			pVar = (*Vdbe)(unsafe.Pointer(p)).FaVar + uintptr(*(*int32)(unsafe.Pointer(bp + 84))-1)*56
			if int32((*Mem)(unsafe.Pointer(pVar)).Fflags)&MEM_Null != 0 {
				Xsqlite3_str_append(tls, bp+48, ts+1637, 4)
			} else if int32((*Mem)(unsafe.Pointer(pVar)).Fflags)&(MEM_Int|MEM_IntReal) != 0 {
				Xsqlite3_str_appendf(tls, bp+48, ts+1416, libc.VaList(bp, *(*I64)(unsafe.Pointer(pVar))))
			} else if int32((*Mem)(unsafe.Pointer(pVar)).Fflags)&MEM_Real != 0 {
				Xsqlite3_str_appendf(tls, bp+48, ts+7805, libc.VaList(bp+8, *(*float64)(unsafe.Pointer(pVar))))
			} else if int32((*Mem)(unsafe.Pointer(pVar)).Fflags)&MEM_Str != 0 {
				var nOut int32
				var enc U8 = (*Sqlite3)(unsafe.Pointer(db)).Fenc
				if int32(enc) != SQLITE_UTF8 {
					libc.Xmemset(tls, bp+88, 0, uint64(unsafe.Sizeof(Mem{})))
					(*Mem)(unsafe.Pointer(bp + 88)).Fdb = db
					Xsqlite3VdbeMemSetStr(tls, bp+88, (*Mem)(unsafe.Pointer(pVar)).Fz, int64((*Mem)(unsafe.Pointer(pVar)).Fn), enc, uintptr(0))
					if SQLITE_NOMEM == Xsqlite3VdbeChangeEncoding(tls, bp+88, SQLITE_UTF8) {
						(*StrAccum)(unsafe.Pointer(bp + 48)).FaccError = U8(SQLITE_NOMEM)
						(*StrAccum)(unsafe.Pointer(bp + 48)).FnAlloc = U32(0)
					}
					pVar = bp + 88
				}
				nOut = (*Mem)(unsafe.Pointer(pVar)).Fn
				Xsqlite3_str_appendf(tls, bp+48, ts+8326, libc.VaList(bp+16, nOut, (*Mem)(unsafe.Pointer(pVar)).Fz))
				if int32(enc) != SQLITE_UTF8 {
					Xsqlite3VdbeMemRelease(tls, bp+88)
				}
			} else if int32((*Mem)(unsafe.Pointer(pVar)).Fflags)&MEM_Zero != 0 {
				Xsqlite3_str_appendf(tls, bp+48, ts+8333, libc.VaList(bp+32, *(*int32)(unsafe.Pointer(pVar))))
			} else {
				var nOut int32

				Xsqlite3_str_append(tls, bp+48, ts+8346, 2)
				nOut = (*Mem)(unsafe.Pointer(pVar)).Fn
				for i = 0; i < nOut; i++ {
					Xsqlite3_str_appendf(tls, bp+48, ts+8349, libc.VaList(bp+40, int32(*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pVar)).Fz + uintptr(i))))&0xff))
				}
				Xsqlite3_str_append(tls, bp+48, ts+8354, 1)
			}
		}
	}
	if (*StrAccum)(unsafe.Pointer(bp+48)).FaccError != 0 {
		Xsqlite3_str_reset(tls, bp+48)
	}
	return Xsqlite3StrAccumFinish(tls, bp+48)
}

var Xsqlite3_search_count int32 = 0

var Xsqlite3_interrupt_count int32 = 0

var Xsqlite3_sort_count int32 = 0

var Xsqlite3_max_blobsize int32 = 0

func updateMaxBlobsize(tls *libc.TLS, p uintptr) {
	if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_Str|MEM_Blob) != 0 && (*Mem)(unsafe.Pointer(p)).Fn > Xsqlite3_max_blobsize {
		Xsqlite3_max_blobsize = (*Mem)(unsafe.Pointer(p)).Fn
	}
}

var Xsqlite3_found_count int32 = 0

func allocateCursor(tls *libc.TLS, p uintptr, iCur int32, nField int32, eCurType U8) uintptr {
	var pMem uintptr
	if iCur > 0 {
		pMem = (*Vdbe)(unsafe.Pointer(p)).FaMem + uintptr((*Vdbe)(unsafe.Pointer(p)).FnMem-iCur)*56
	} else {
		pMem = (*Vdbe)(unsafe.Pointer(p)).FaMem
	}
	var nByte int32
	var pCx uintptr = uintptr(0)
	nByte = int32(uint64(unsafe.Sizeof(VdbeCursor{})) + uint64(2)*uint64(unsafe.Sizeof(U32(0)))*uint64(nField) + func() uint64 {
		if int32(eCurType) == CURTYPE_BTREE {
			return uint64(Xsqlite3BtreeCursorSize(tls))
		}
		return uint64(0)
	}())

	if *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*8)) != 0 {
		Xsqlite3VdbeFreeCursorNN(tls, p, *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*8)))
		*(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*8)) = uintptr(0)
	}

	if (*Mem)(unsafe.Pointer(pMem)).FszMalloc < nByte {
		if (*Mem)(unsafe.Pointer(pMem)).FszMalloc > 0 {
			Xsqlite3DbFreeNN(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, (*Mem)(unsafe.Pointer(pMem)).FzMalloc)
		}
		(*Mem)(unsafe.Pointer(pMem)).Fz = libc.AssignPtrUintptr(pMem+40, Xsqlite3DbMallocRaw(tls, (*Mem)(unsafe.Pointer(pMem)).Fdb, uint64(nByte)))
		if (*Mem)(unsafe.Pointer(pMem)).FzMalloc == uintptr(0) {
			(*Mem)(unsafe.Pointer(pMem)).FszMalloc = 0
			return uintptr(0)
		}
		(*Mem)(unsafe.Pointer(pMem)).FszMalloc = nByte
	}

	*(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr(iCur)*8)) = libc.AssignUintptr(&pCx, (*Mem)(unsafe.Pointer(pMem)).FzMalloc)
	libc.Xmemset(tls, pCx, 0, uint64(uintptr(0)+40))
	(*VdbeCursor)(unsafe.Pointer(pCx)).FeCurType = eCurType
	(*VdbeCursor)(unsafe.Pointer(pCx)).FnField = I16(nField)
	(*VdbeCursor)(unsafe.Pointer(pCx)).FaOffset = pCx + 112 + uintptr(nField)*4
	if int32(eCurType) == CURTYPE_BTREE {
		*(*uintptr)(unsafe.Pointer(pCx + 48)) = (*Mem)(unsafe.Pointer(pMem)).Fz + uintptr(uint64(unsafe.Sizeof(VdbeCursor{}))+uint64(2)*uint64(unsafe.Sizeof(U32(0)))*uint64(nField))
		Xsqlite3BtreeCursorZero(tls, *(*uintptr)(unsafe.Pointer(pCx + 48)))
	}
	return pCx
}

func alsoAnInt(tls *libc.TLS, pRec uintptr, rValue float64, piValue uintptr) int32 {
	var iValue I64
	iValue = Xsqlite3RealToI64(tls, rValue)
	if Xsqlite3RealSameAsInt(tls, rValue, iValue) != 0 {
		*(*I64)(unsafe.Pointer(piValue)) = iValue
		return 1
	}
	return libc.Bool32(0 == Xsqlite3Atoi64(tls, (*Mem)(unsafe.Pointer(pRec)).Fz, piValue, (*Mem)(unsafe.Pointer(pRec)).Fn, (*Mem)(unsafe.Pointer(pRec)).Fenc))
}

func applyNumericAffinity(tls *libc.TLS, pRec uintptr, bTryForInt int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var enc U8 = (*Mem)(unsafe.Pointer(pRec)).Fenc
	var rc int32

	rc = Xsqlite3AtoF(tls, (*Mem)(unsafe.Pointer(pRec)).Fz, bp, (*Mem)(unsafe.Pointer(pRec)).Fn, enc)
	if rc <= 0 {
		return
	}
	if rc == 1 && alsoAnInt(tls, pRec, *(*float64)(unsafe.Pointer(bp)), pRec) != 0 {
		*(*U16)(unsafe.Pointer(pRec + 20)) |= U16(MEM_Int)
	} else {
		*(*float64)(unsafe.Pointer(pRec)) = *(*float64)(unsafe.Pointer(bp))
		*(*U16)(unsafe.Pointer(pRec + 20)) |= U16(MEM_Real)
		if bTryForInt != 0 {
			Xsqlite3VdbeIntegerAffinity(tls, pRec)
		}
	}

	*(*U16)(unsafe.Pointer(pRec + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Str))
}

func applyAffinity(tls *libc.TLS, pRec uintptr, affinity uint8, enc U8) {
	if int32(affinity) >= SQLITE_AFF_NUMERIC {
		if int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Int == 0 {
			if int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&(MEM_Real|MEM_IntReal) == 0 {
				if int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Str != 0 {
					applyNumericAffinity(tls, pRec, 1)
				}
			} else if int32(affinity) <= SQLITE_AFF_REAL {
				Xsqlite3VdbeIntegerAffinity(tls, pRec)
			}
		}
	} else if int32(affinity) == SQLITE_AFF_TEXT {
		if 0 == int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Str {
			if int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&(MEM_Real|MEM_Int|MEM_IntReal) != 0 {
				Xsqlite3VdbeMemStringify(tls, pRec, enc, uint8(1))
			}
		}
		*(*U16)(unsafe.Pointer(pRec + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Real | MEM_Int | MEM_IntReal))
	}
}

func Xsqlite3_value_numeric_type(tls *libc.TLS, pVal uintptr) int32 {
	var eType int32 = Xsqlite3_value_type(tls, pVal)
	if eType == SQLITE_TEXT {
		var pMem uintptr = pVal
		applyNumericAffinity(tls, pMem, 0)
		eType = Xsqlite3_value_type(tls, pVal)
	}
	return eType
}

func Xsqlite3ValueApplyAffinity(tls *libc.TLS, pVal uintptr, affinity U8, enc U8) {
	applyAffinity(tls, pVal, affinity, enc)
}

func computeNumericType(tls *libc.TLS, pMem uintptr) U16 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	if func() int32 {
		if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&MEM_Zero != 0 {
			return Xsqlite3VdbeMemExpandBlob(tls, pMem)
		}
		return 0
	}() != 0 {
		*(*I64)(unsafe.Pointer(pMem)) = int64(0)
		return U16(MEM_Int)
	}
	rc = Xsqlite3AtoF(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, pMem, (*Mem)(unsafe.Pointer(pMem)).Fn, (*Mem)(unsafe.Pointer(pMem)).Fenc)
	if rc <= 0 {
		if rc == 0 && Xsqlite3Atoi64(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, bp, (*Mem)(unsafe.Pointer(pMem)).Fn, (*Mem)(unsafe.Pointer(pMem)).Fenc) <= 1 {
			*(*I64)(unsafe.Pointer(pMem)) = *(*Sqlite3_int64)(unsafe.Pointer(bp))
			return U16(MEM_Int)
		} else {
			return U16(MEM_Real)
		}
	} else if rc == 1 && Xsqlite3Atoi64(tls, (*Mem)(unsafe.Pointer(pMem)).Fz, bp, (*Mem)(unsafe.Pointer(pMem)).Fn, (*Mem)(unsafe.Pointer(pMem)).Fenc) == 0 {
		*(*I64)(unsafe.Pointer(pMem)) = *(*Sqlite3_int64)(unsafe.Pointer(bp))
		return U16(MEM_Int)
	}
	return U16(MEM_Real)
}

func numericType(tls *libc.TLS, pMem uintptr) U16 {
	if int32((*Mem)(unsafe.Pointer(pMem)).Fflags)&(MEM_Int|MEM_Real|MEM_IntReal|MEM_Null) != 0 {
		return U16(int32((*Mem)(unsafe.Pointer(pMem)).Fflags) & (MEM_Int | MEM_Real | MEM_IntReal | MEM_Null))
	}

	return computeNumericType(tls, pMem)
	return U16(0)
}

func out2PrereleaseWithClear(tls *libc.TLS, pOut uintptr) uintptr {
	Xsqlite3VdbeMemSetNull(tls, pOut)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Int)
	return pOut
}

func out2Prerelease(tls *libc.TLS, p uintptr, pOp uintptr) uintptr {
	var pOut uintptr

	pOut = (*Vdbe)(unsafe.Pointer(p)).FaMem + uintptr((*VdbeOp)(unsafe.Pointer(pOp)).Fp2)*56

	if int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&(MEM_Agg|MEM_Dyn) != 0 {
		return out2PrereleaseWithClear(tls, pOut)
	} else {
		(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Int)
		return pOut
	}
	return uintptr(0)
}

func filterHash(tls *libc.TLS, aMem uintptr, pOp uintptr) U64 {
	var i int32
	var mx int32
	var h U64 = uint64(0)

	i = (*Op)(unsafe.Pointer(pOp)).Fp3
	mx = i + *(*int32)(unsafe.Pointer(pOp + 16))
	for ; i < mx; i++ {
		var p uintptr = aMem + uintptr(i)*56
		if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_Int|MEM_IntReal) != 0 {
			h = h + U64(*(*I64)(unsafe.Pointer(p)))
		} else if int32((*Mem)(unsafe.Pointer(p)).Fflags)&MEM_Real != 0 {
			h = h + U64(Xsqlite3VdbeIntValue(tls, p))
		} else if int32((*Mem)(unsafe.Pointer(p)).Fflags)&(MEM_Str|MEM_Blob) != 0 {
		}
	}
	return h
}

func vdbeMemTypeName(tls *libc.TLS, pMem uintptr) uintptr {
	return azTypes[Xsqlite3_value_type(tls, pMem)-1]
}

var azTypes = [5]uintptr{
	ts + 1197,
	ts + 1209,
	ts + 1214,
	ts + 1192,
	ts + 1637,
}

func Xsqlite3VdbeExec(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(1048)
	defer tls.Free(1048)

	var aOp uintptr
	var pOp uintptr
	var rc int32
	var db uintptr
	var resetSchemaOnFault U8
	var encoding U8
	var iCompare int32
	var nVmStep U64
	var nProgressLimit U64
	var aMem uintptr
	var pIn1 uintptr
	var pIn2 uintptr
	var pIn3 uintptr
	var pOut uintptr
	var iPrior U32
	var pCaller uintptr
	var pcDest int32
	var pFrame uintptr
	var pcx int32
	var cnt int32
	var nullFlag U16
	var pVar uintptr
	var n int32
	var p1 int32
	var p2 int32
	var n1 int32
	var nByte I64
	var flags1 U16
	var flags2 U16
	var type1 U16
	var type2 U16
	var iA I64

	var rA float64
	var rB float64

	var iB1 I64
	var op U8
	var res int32
	var res2 int32
	var affinity uint8
	var flags11 U16
	var flags3 U16
	var n2 int32
	var i int32
	var p11 int32
	var p21 int32
	var pKeyInfo uintptr
	var idx U32
	var pColl uintptr
	var bRev int32
	var aPermute uintptr
	var v1 int32
	var v2 int32
	var iAddr U32
	var c int32
	var c1 int32
	var pC uintptr
	var typeMask U16
	var serialType U32
	var pC1 uintptr
	var pC2 uintptr
	var iMap U32
	var p22 U32
	var pC3 uintptr
	var pCrsr uintptr
	var aOffset uintptr
	var len int32
	var i1 int32
	var pDest uintptr

	var zData uintptr
	var zHdr uintptr
	var zEndHdr uintptr
	var offset64 U64

	var pReg uintptr
	var pTab uintptr
	var aCol uintptr
	var i2 int32
	var zAffinity uintptr

	var i3 I64
	var uu U64

	var i4 U32
	var pRec uintptr
	var nData U64
	var nHdr int32
	var nByte1 I64
	var nZero I64
	var nVarint int32
	var serial_type U32
	var pData0 uintptr
	var pLast uintptr
	var nField int32
	var zAffinity1 uintptr
	var len1 U32
	var zHdr1 uintptr
	var zPayload uintptr

	var pCrsr1 uintptr
	var isSchemaChange int32

	var isTransaction int32
	var p12 int32
	var zName uintptr
	var nName int32
	var pNew uintptr
	var pSavepoint uintptr
	var pTmp uintptr
	var iSavepoint int32
	var ii int32
	var desiredAutoCommit int32
	var iRollback int32
	var pBt uintptr
	var pDb uintptr

	var iDb int32
	var iCookie int32
	var pDb1 uintptr
	var nField1 int32
	var pKeyInfo1 uintptr
	var p23 U32
	var iDb1 int32
	var wrFlag int32
	var pX uintptr
	var pCur uintptr
	var pDb2 uintptr
	var pOrig uintptr
	var pCx uintptr
	var pCx1 uintptr
	var pKeyInfo2 uintptr
	var pCx2 uintptr
	var pC4 uintptr
	var pCx3 uintptr
	var c2 int32
	var flags31 U16
	var newType U16

	var oc int32
	var pC5 uintptr

	var nField2 int32
	var iKey I64
	var eqOnly int32
	var pC6 uintptr

	var nStep int32

	var pC7 uintptr
	var pCur1 uintptr
	var pC8 uintptr
	var alreadyExists int32
	var ii1 int32
	var pC9 uintptr
	var pIdxKey uintptr

	var pC10 uintptr
	var pCrsr2 uintptr

	var iKey1 U64

	var pC11 uintptr

	var cnt1 int32
	var pMem uintptr
	var pFrame1 uintptr
	var pData uintptr
	var pKey uintptr
	var pC12 uintptr
	var seekResult int32
	var zDb uintptr
	var pTab1 uintptr

	var pDest1 uintptr
	var pSrc uintptr
	var iKey2 I64
	var pC13 uintptr
	var zDb1 uintptr
	var pTab2 uintptr
	var opflags int32
	var pC14 uintptr

	var nKeyCol int32
	var pC15 uintptr
	var pC16 uintptr
	var pCrsr3 uintptr
	var n3 U32
	var pC17 uintptr

	var pVtab uintptr
	var pModule uintptr
	var pC18 uintptr
	var pC19 uintptr
	var pCrsr4 uintptr

	var pC20 uintptr
	var pCrsr5 uintptr

	var sz I64
	var pC21 uintptr
	var pCrsr6 uintptr

	var pC22 uintptr
	var pC23 uintptr

	var pC24 uintptr
	var pC25 uintptr
	var pCrsr7 uintptr

	var pC26 uintptr
	var pTabCur uintptr

	var pC27 uintptr
	var nCellKey I64
	var pCur2 uintptr

	var pC28 uintptr
	var res11 int32

	var iDb2 int32

	var pC29 uintptr

	var pDb3 uintptr
	var iDb3 int32
	var zSchema uintptr
	var zSql uintptr

	var nRoot int32
	var aRoot uintptr

	var pnErr uintptr

	var iSet int32
	var exists int32
	var nMem int32
	var nByte2 int32
	var pRt uintptr
	var pMem1 uintptr
	var pEnd uintptr
	var pFrame2 uintptr
	var pProgram uintptr
	var t1 uintptr
	var pFrame3 uintptr
	var pIn uintptr
	var pFrame4 uintptr

	var n4 int32
	var pCtx uintptr
	var i5 int32
	var pCtx1 uintptr
	var pMem2 uintptr
	var pMem3 uintptr
	var i6 int32

	var pMem4 uintptr
	var pBt1 uintptr
	var pPager uintptr
	var eNew int32
	var eOld int32
	var zFilename uintptr
	var pBt2 uintptr
	var pC30 uintptr
	var pC31 uintptr
	var z1 uintptr
	var p13 int32
	var isWriteLock U8
	var pVTab uintptr

	var zTab uintptr
	var pCur3 uintptr

	var pVtab1 uintptr
	var pModule1 uintptr
	var pC32 uintptr
	var pRhs uintptr
	var nArg int32
	var iQuery int32
	var pModule2 uintptr
	var pQuery uintptr
	var pArgc uintptr
	var pVCur1 uintptr
	var pVtab2 uintptr
	var pCur4 uintptr
	var res12 int32
	var i7 int32
	var apArg uintptr
	var pVtab3 uintptr
	var pModule3 uintptr
	var pDest2 uintptr

	var pCur5 uintptr
	var pVtab4 uintptr
	var pModule4 uintptr
	var res13 int32
	var pCur6 uintptr
	var pVtab5 uintptr
	var pName uintptr
	var isLegacy int32
	var vtabOnConflict U8
	var pVtab6 uintptr
	var pModule5 uintptr
	var nArg1 int32
	var i8 int32

	var apArg1 uintptr
	var pX1 uintptr
	var newMax uint32
	var pBt3 uintptr
	var i9 int32
	var pCtx2 uintptr
	var h U64
	var h1 U64
	var z2 uintptr
	var z3 uintptr
	var i10 int32
	var zTrace uintptr
	aOp = (*Vdbe)(unsafe.Pointer(p)).FaOp
	pOp = aOp
	rc = SQLITE_OK
	db = (*Vdbe)(unsafe.Pointer(p)).Fdb
	resetSchemaOnFault = U8(0)
	encoding = (*Sqlite3)(unsafe.Pointer(db)).Fenc
	iCompare = 0
	nVmStep = uint64(0)
	aMem = (*Vdbe)(unsafe.Pointer(p)).FaMem
	pIn1 = uintptr(0)
	pIn2 = uintptr(0)
	pIn3 = uintptr(0)
	pOut = uintptr(0)

	if !((*Vdbe)(unsafe.Pointer(p)).FlockMask != YDbMask(0)) {
		goto __1
	}
	Xsqlite3VdbeEnter(tls, p)
__1:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FxProgress != 0) {
		goto __2
	}
	iPrior = *(*U32)(unsafe.Pointer(p + 212 + 4*4))

	nProgressLimit = U64((*Sqlite3)(unsafe.Pointer(db)).FnProgressOps - iPrior%(*Sqlite3)(unsafe.Pointer(db)).FnProgressOps)
	goto __3
__2:
	nProgressLimit = uint64(0xffffffff) | uint64(0xffffffff)<<32
__3:
	;
	if !((*Vdbe)(unsafe.Pointer(p)).Frc == SQLITE_NOMEM) {
		goto __4
	}

	goto no_mem
__4:
	;
	(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_OK

	(*Vdbe)(unsafe.Pointer(p)).FiCurrentTime = int64(0)

	(*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	if !(libc.AtomicLoadNInt32(db+432, 0) != 0) {
		goto __5
	}
	goto abort_due_to_interrupt
__5:
	;
	pOp = aOp + uintptr((*Vdbe)(unsafe.Pointer(p)).Fpc)*32
__6:
	if !(1 != 0) {
		goto __8
	}

	nVmStep++

	if !(Xsqlite3_interrupt_count > 0) {
		goto __9
	}
	Xsqlite3_interrupt_count--
	if !(Xsqlite3_interrupt_count == 0) {
		goto __10
	}
	Xsqlite3_interrupt(tls, db)
__10:
	;
__9:
	;
	switch int32((*Op)(unsafe.Pointer(pOp)).Fopcode) {
	case OP_Goto:
		goto __12

	case OP_Gosub:
		goto __13

	case OP_Return:
		goto __14

	case OP_InitCoroutine:
		goto __15

	case OP_EndCoroutine:
		goto __16

	case OP_Yield:
		goto __17

	case OP_HaltIfNull:
		goto __18

	case OP_Halt:
		goto __19

	case OP_Integer:
		goto __20

	case OP_Int64:
		goto __21

	case OP_Real:
		goto __22

	case OP_String8:
		goto __23

	case OP_String:
		goto __24

	case OP_BeginSubrtn:
		goto __25
	case OP_Null:
		goto __26

	case OP_SoftNull:
		goto __27

	case OP_Blob:
		goto __28

	case OP_Variable:
		goto __29

	case OP_Move:
		goto __30

	case OP_Copy:
		goto __31

	case OP_SCopy:
		goto __32

	case OP_IntCopy:
		goto __33

	case OP_FkCheck:
		goto __34

	case OP_ResultRow:
		goto __35

	case OP_Concat:
		goto __36

	case OP_Add:
		goto __37
	case OP_Subtract:
		goto __38
	case OP_Multiply:
		goto __39
	case OP_Divide:
		goto __40
	case OP_Remainder:
		goto __41

	case OP_CollSeq:
		goto __42

	case OP_BitAnd:
		goto __43
	case OP_BitOr:
		goto __44
	case OP_ShiftLeft:
		goto __45
	case OP_ShiftRight:
		goto __46

	case OP_AddImm:
		goto __47

	case OP_MustBeInt:
		goto __48

	case OP_RealAffinity:
		goto __49

	case OP_Cast:
		goto __50

	case OP_Eq:
		goto __51
	case OP_Ne:
		goto __52
	case OP_Lt:
		goto __53
	case OP_Le:
		goto __54
	case OP_Gt:
		goto __55
	case OP_Ge:
		goto __56

	case OP_ElseEq:
		goto __57

	case OP_Permutation:
		goto __58

	case OP_Compare:
		goto __59

	case OP_Jump:
		goto __60

	case OP_And:
		goto __61
	case OP_Or:
		goto __62

	case OP_IsTrue:
		goto __63

	case OP_Not:
		goto __64

	case OP_BitNot:
		goto __65

	case OP_Once:
		goto __66

	case OP_If:
		goto __67

	case OP_IfNot:
		goto __68

	case OP_IsNull:
		goto __69

	case OP_IsType:
		goto __70

	case OP_ZeroOrNull:
		goto __71

	case OP_NotNull:
		goto __72

	case OP_IfNullRow:
		goto __73

	case OP_Offset:
		goto __74

	case OP_Column:
		goto __75

	case OP_TypeCheck:
		goto __76

	case OP_Affinity:
		goto __77

	case OP_MakeRecord:
		goto __78

	case OP_Count:
		goto __79

	case OP_Savepoint:
		goto __80

	case OP_AutoCommit:
		goto __81

	case OP_Transaction:
		goto __82

	case OP_ReadCookie:
		goto __83

	case OP_SetCookie:
		goto __84

	case OP_ReopenIdx:
		goto __85

	case OP_OpenRead:
		goto __86
	case OP_OpenWrite:
		goto __87

	case OP_OpenDup:
		goto __88

	case OP_OpenAutoindex:
		goto __89
	case OP_OpenEphemeral:
		goto __90

	case OP_SorterOpen:
		goto __91

	case OP_SequenceTest:
		goto __92

	case OP_OpenPseudo:
		goto __93

	case OP_Close:
		goto __94

	case OP_SeekLT:
		goto __95
	case OP_SeekLE:
		goto __96
	case OP_SeekGE:
		goto __97
	case OP_SeekGT:
		goto __98

	case OP_SeekScan:
		goto __99

	case OP_SeekHit:
		goto __100

	case OP_IfNotOpen:
		goto __101

	case OP_IfNoHope:
		goto __102
	case OP_NoConflict:
		goto __103
	case OP_NotFound:
		goto __104
	case OP_Found:
		goto __105

	case OP_SeekRowid:
		goto __106
	case OP_NotExists:
		goto __107

	case OP_Sequence:
		goto __108

	case OP_NewRowid:
		goto __109

	case OP_Insert:
		goto __110

	case OP_RowCell:
		goto __111

	case OP_Delete:
		goto __112

	case OP_ResetCount:
		goto __113

	case OP_SorterCompare:
		goto __114

	case OP_SorterData:
		goto __115

	case OP_RowData:
		goto __116

	case OP_Rowid:
		goto __117

	case OP_NullRow:
		goto __118

	case OP_SeekEnd:
		goto __119
	case OP_Last:
		goto __120

	case OP_IfSmaller:
		goto __121

	case OP_SorterSort:
		goto __122
	case OP_Sort:
		goto __123

	case OP_Rewind:
		goto __124

	case OP_SorterNext:
		goto __125

	case OP_Prev:
		goto __126

	case OP_Next:
		goto __127

	case OP_IdxInsert:
		goto __128

	case OP_SorterInsert:
		goto __129

	case OP_IdxDelete:
		goto __130

	case OP_DeferredSeek:
		goto __131
	case OP_IdxRowid:
		goto __132

	case OP_FinishSeek:
		goto __133

	case OP_IdxLE:
		goto __134
	case OP_IdxGT:
		goto __135
	case OP_IdxLT:
		goto __136
	case OP_IdxGE:
		goto __137

	case OP_Destroy:
		goto __138

	case OP_Clear:
		goto __139

	case OP_ResetSorter:
		goto __140

	case OP_CreateBtree:
		goto __141

	case OP_SqlExec:
		goto __142

	case OP_ParseSchema:
		goto __143

	case OP_LoadAnalysis:
		goto __144

	case OP_DropTable:
		goto __145

	case OP_DropIndex:
		goto __146

	case OP_DropTrigger:
		goto __147

	case OP_IntegrityCk:
		goto __148

	case OP_RowSetAdd:
		goto __149

	case OP_RowSetRead:
		goto __150

	case OP_RowSetTest:
		goto __151

	case OP_Program:
		goto __152

	case OP_Param:
		goto __153

	case OP_FkCounter:
		goto __154

	case OP_FkIfZero:
		goto __155

	case OP_MemMax:
		goto __156

	case OP_IfPos:
		goto __157

	case OP_OffsetLimit:
		goto __158

	case OP_IfNotZero:
		goto __159

	case OP_DecrJumpZero:
		goto __160

	case OP_AggInverse:
		goto __161
	case OP_AggStep:
		goto __162
	case OP_AggStep1:
		goto __163

	case OP_AggValue:
		goto __164
	case OP_AggFinal:
		goto __165

	case OP_Checkpoint:
		goto __166

	case OP_JournalMode:
		goto __167

	case OP_Vacuum:
		goto __168

	case OP_IncrVacuum:
		goto __169

	case OP_Expire:
		goto __170

	case OP_CursorLock:
		goto __171

	case OP_CursorUnlock:
		goto __172

	case OP_TableLock:
		goto __173

	case OP_VBegin:
		goto __174

	case OP_VCreate:
		goto __175

	case OP_VDestroy:
		goto __176

	case OP_VOpen:
		goto __177

	case OP_VInitIn:
		goto __178

	case OP_VFilter:
		goto __179

	case OP_VColumn:
		goto __180

	case OP_VNext:
		goto __181

	case OP_VRename:
		goto __182

	case OP_VUpdate:
		goto __183

	case OP_Pagecount:
		goto __184

	case OP_MaxPgcnt:
		goto __185

	case OP_PureFunc:
		goto __186
	case OP_Function:
		goto __187

	case OP_ClrSubtype:
		goto __188

	case OP_FilterAdd:
		goto __189

	case OP_Filter:
		goto __190

	case OP_Trace:
		goto __191
	case OP_Init:
		goto __192

	default:
		goto __193
	}
	goto __11

__12:
jump_to_p2_and_check_for_interrupt:
	pOp = aOp + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2-1)*32

check_for_interrupt:
	if !(libc.AtomicLoadNInt32(db+432, 0) != 0) {
		goto __194
	}
	goto abort_due_to_interrupt
__194:
	;
__195:
	if !(nVmStep >= nProgressLimit && (*Sqlite3)(unsafe.Pointer(db)).FxProgress != uintptr(0)) {
		goto __196
	}

	nProgressLimit = nProgressLimit + U64((*Sqlite3)(unsafe.Pointer(db)).FnProgressOps)
	if !((*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxProgress})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0) {
		goto __197
	}
	nProgressLimit = uint64(0xffffffff) | uint64(0xffffffff)<<32
	rc = SQLITE_INTERRUPT
	goto abort_due_to_error
__197:
	;
	goto __195
__196:
	;
	goto __11

__13:
	;
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	(*Mem)(unsafe.Pointer(pIn1)).Fflags = U16(MEM_Int)
	*(*I64)(unsafe.Pointer(pIn1)) = I64(int32((int64(pOp) - int64(aOp)) / 32))

	goto jump_to_p2_and_check_for_interrupt

__14:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Int != 0) {
		goto __198
	}
	if !((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __200
	}
__200:
	;
	pOp = aOp + uintptr(*(*I64)(unsafe.Pointer(pIn1)))*32
	goto __199
__198:
	if !((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __201
	}

__201:
	;
__199:
	;
	goto __11

__15:
	;
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	*(*I64)(unsafe.Pointer(pOut)) = I64((*Op)(unsafe.Pointer(pOp)).Fp3 - 1)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Int)
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 == 0) {
		goto __202
	}
	goto __11
__202:
	;
jump_to_p2:
	;
	pOp = aOp + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2-1)*32
	goto __11

__16:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	pCaller = aOp + uintptr(*(*I64)(unsafe.Pointer(pIn1)))*32

	pOp = aOp + uintptr((*VdbeOp)(unsafe.Pointer(pCaller)).Fp2-1)*32
	(*Mem)(unsafe.Pointer(pIn1)).Fflags = U16(MEM_Undefined)
	goto __11

__17:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	(*Mem)(unsafe.Pointer(pIn1)).Fflags = U16(MEM_Int)
	pcDest = int32(*(*I64)(unsafe.Pointer(pIn1)))
	*(*I64)(unsafe.Pointer(pIn1)) = I64(int32((int64(pOp) - int64(aOp)) / 32))

	pOp = aOp + uintptr(pcDest)*32
	goto __11

__18:
	pIn3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	if !(int32((*Mem)(unsafe.Pointer(pIn3)).Fflags)&MEM_Null == 0) {
		goto __203
	}
	goto __11
__203:
	;
__19:
	;
	if !((*Vdbe)(unsafe.Pointer(p)).FpFrame != 0 && (*Op)(unsafe.Pointer(pOp)).Fp1 == SQLITE_OK) {
		goto __204
	}

	pFrame = (*Vdbe)(unsafe.Pointer(p)).FpFrame
	(*Vdbe)(unsafe.Pointer(p)).FpFrame = (*VdbeFrame)(unsafe.Pointer(pFrame)).FpParent
	(*Vdbe)(unsafe.Pointer(p)).FnFrame--
	Xsqlite3VdbeSetChanges(tls, db, (*Vdbe)(unsafe.Pointer(p)).FnChange)
	pcx = Xsqlite3VdbeFrameRestore(tls, pFrame)
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 == OE_Ignore) {
		goto __205
	}

	pcx = (*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp+uintptr(pcx)*32)).Fp2 - 1
__205:
	;
	aOp = (*Vdbe)(unsafe.Pointer(p)).FaOp
	aMem = (*Vdbe)(unsafe.Pointer(p)).FaMem
	pOp = aOp + uintptr(pcx)*32
	goto __11
__204:
	;
	(*Vdbe)(unsafe.Pointer(p)).Frc = (*Op)(unsafe.Pointer(pOp)).Fp1
	(*Vdbe)(unsafe.Pointer(p)).FerrorAction = U8((*Op)(unsafe.Pointer(pOp)).Fp2)

	if !((*Vdbe)(unsafe.Pointer(p)).Frc != 0) {
		goto __206
	}
	if !((*Op)(unsafe.Pointer(pOp)).Fp5 != 0) {
		goto __207
	}

	Xsqlite3VdbeError(tls, p, ts+8356, libc.VaList(bp, azType[int32((*Op)(unsafe.Pointer(pOp)).Fp5)-1]))
	if !(*(*uintptr)(unsafe.Pointer(pOp + 16)) != 0) {
		goto __209
	}
	(*Vdbe)(unsafe.Pointer(p)).FzErrMsg = Xsqlite3MPrintf(tls, db, ts+8377, libc.VaList(bp+8, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg, *(*uintptr)(unsafe.Pointer(pOp + 16))))
__209:
	;
	goto __208
__207:
	Xsqlite3VdbeError(tls, p, ts+1684, libc.VaList(bp+24, *(*uintptr)(unsafe.Pointer(pOp + 16))))
__208:
	;
	pcx = int32((int64(pOp) - int64(aOp)) / 32)
	Xsqlite3_log(tls, (*Op)(unsafe.Pointer(pOp)).Fp1, ts+8384, libc.VaList(bp+32, pcx, (*Vdbe)(unsafe.Pointer(p)).FzSql, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg))
__206:
	;
	rc = Xsqlite3VdbeHalt(tls, p)

	if !(rc == SQLITE_BUSY) {
		goto __210
	}
	(*Vdbe)(unsafe.Pointer(p)).Frc = SQLITE_BUSY
	goto __211
__210:
	;
	if (*Vdbe)(unsafe.Pointer(p)).Frc != 0 {
		rc = SQLITE_ERROR
	} else {
		rc = SQLITE_DONE
	}
__211:
	;
	goto vdbe_return

__20:
	pOut = out2Prerelease(tls, p, pOp)
	*(*I64)(unsafe.Pointer(pOut)) = I64((*Op)(unsafe.Pointer(pOp)).Fp1)
	goto __11

__21:
	pOut = out2Prerelease(tls, p, pOp)

	*(*I64)(unsafe.Pointer(pOut)) = *(*I64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16))))
	goto __11

__22:
	pOut = out2Prerelease(tls, p, pOp)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Real)

	*(*float64)(unsafe.Pointer(pOut)) = *(*float64)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16))))
	goto __11

__23:
	;
	pOut = out2Prerelease(tls, p, pOp)
	(*Op)(unsafe.Pointer(pOp)).Fp1 = Xsqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pOp + 16)))

	if !(int32(encoding) != SQLITE_UTF8) {
		goto __212
	}
	rc = Xsqlite3VdbeMemSetStr(tls, pOut, *(*uintptr)(unsafe.Pointer(pOp + 16)), int64(-1), uint8(SQLITE_UTF8), uintptr(0))

	if !(rc != 0) {
		goto __213
	}
	goto too_big
__213:
	;
	if !(SQLITE_OK != Xsqlite3VdbeChangeEncoding(tls, pOut, int32(encoding))) {
		goto __214
	}
	goto no_mem
__214:
	;
	(*Mem)(unsafe.Pointer(pOut)).FszMalloc = 0
	*(*U16)(unsafe.Pointer(pOut + 20)) |= U16(MEM_Static)
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp4type) == -6) {
		goto __215
	}
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)))
__215:
	;
	(*Op)(unsafe.Pointer(pOp)).Fp4type = int8(-6)
	*(*uintptr)(unsafe.Pointer(pOp + 16)) = (*Mem)(unsafe.Pointer(pOut)).Fz
	(*Op)(unsafe.Pointer(pOp)).Fp1 = (*Mem)(unsafe.Pointer(pOut)).Fn
__212:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp1 > *(*int32)(unsafe.Pointer(db + 136))) {
		goto __216
	}
	goto too_big
__216:
	;
	(*Op)(unsafe.Pointer(pOp)).Fopcode = U8(OP_String)

__24:
	;
	pOut = out2Prerelease(tls, p, pOp)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Str | MEM_Static | MEM_Term)
	(*Mem)(unsafe.Pointer(pOut)).Fz = *(*uintptr)(unsafe.Pointer(pOp + 16))
	(*Mem)(unsafe.Pointer(pOut)).Fn = (*Op)(unsafe.Pointer(pOp)).Fp1
	(*Mem)(unsafe.Pointer(pOut)).Fenc = encoding
	updateMaxBlobsize(tls, pOut)
	goto __11

__25:
__26:
	pOut = out2Prerelease(tls, p, pOp)
	cnt = (*Op)(unsafe.Pointer(pOp)).Fp3 - (*Op)(unsafe.Pointer(pOp)).Fp2

	(*Mem)(unsafe.Pointer(pOut)).Fflags = libc.AssignUint16(&nullFlag, func() uint16 {
		if (*Op)(unsafe.Pointer(pOp)).Fp1 != 0 {
			return uint16(MEM_Null | MEM_Cleared)
		}
		return uint16(MEM_Null)
	}())
	(*Mem)(unsafe.Pointer(pOut)).Fn = 0
__217:
	if !(cnt > 0) {
		goto __218
	}
	pOut += 56

	Xsqlite3VdbeMemSetNull(tls, pOut)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = nullFlag
	(*Mem)(unsafe.Pointer(pOut)).Fn = 0
	cnt--
	goto __217
__218:
	;
	goto __11

__27:
	;
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_Undefined|MEM_AffMask) | MEM_Null)
	goto __11

__28:
	;
	pOut = out2Prerelease(tls, p, pOp)
	if !(*(*uintptr)(unsafe.Pointer(pOp + 16)) == uintptr(0)) {
		goto __219
	}
	Xsqlite3VdbeMemSetZeroBlob(tls, pOut, (*Op)(unsafe.Pointer(pOp)).Fp1)
	if !(Xsqlite3VdbeMemExpandBlob(tls, pOut) != 0) {
		goto __221
	}
	goto no_mem
__221:
	;
	goto __220
__219:
	Xsqlite3VdbeMemSetStr(tls, pOut, *(*uintptr)(unsafe.Pointer(pOp + 16)), int64((*Op)(unsafe.Pointer(pOp)).Fp1), uint8(0), uintptr(0))
__220:
	;
	(*Mem)(unsafe.Pointer(pOut)).Fenc = encoding
	updateMaxBlobsize(tls, pOut)
	goto __11

__29:
	;
	pVar = (*Vdbe)(unsafe.Pointer(p)).FaVar + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1-1)*56
	if !(Xsqlite3VdbeMemTooBig(tls, pVar) != 0) {
		goto __222
	}
	goto too_big
__222:
	;
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	if !(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&(MEM_Agg|MEM_Dyn) != 0) {
		goto __223
	}
	Xsqlite3VdbeMemSetNull(tls, pOut)
__223:
	;
	libc.Xmemcpy(tls, pOut, pVar, uint64(uintptr(0)+24))
	*(*U16)(unsafe.Pointer(pOut + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Dyn | MEM_Ephem))
	*(*U16)(unsafe.Pointer(pOut + 20)) |= U16(MEM_Static | MEM_FromBind)
	updateMaxBlobsize(tls, pOut)
	goto __11

__30:
	n = (*Op)(unsafe.Pointer(pOp)).Fp3
	p1 = (*Op)(unsafe.Pointer(pOp)).Fp1
	p2 = (*Op)(unsafe.Pointer(pOp)).Fp2

	pIn1 = aMem + uintptr(p1)*56
	pOut = aMem + uintptr(p2)*56
__224:
	;
	Xsqlite3VdbeMemMove(tls, pOut, pIn1)
	if !(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&MEM_Ephem != 0 && Xsqlite3VdbeMemMakeWriteable(tls, pOut) != 0) {
		goto __227
	}
	goto no_mem
__227:
	;
	pIn1 += 56
	pOut += 56
	goto __225
__225:
	if libc.PreDecInt32(&n, 1) != 0 {
		goto __224
	}
	goto __226
__226:
	;
	goto __11

__31:
	n1 = (*Op)(unsafe.Pointer(pOp)).Fp3
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56

__228:
	if !(1 != 0) {
		goto __229
	}

	Xsqlite3VdbeMemShallowCopy(tls, pOut, pIn1, MEM_Ephem)
	if !(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&MEM_Ephem != 0 && Xsqlite3VdbeMemMakeWriteable(tls, pOut) != 0) {
		goto __230
	}
	goto no_mem
__230:
	;
	if !(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&MEM_Subtype != 0 && int32((*Op)(unsafe.Pointer(pOp)).Fp5)&0x0002 != 0) {
		goto __231
	}
	*(*U16)(unsafe.Pointer(pOut + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Subtype))
__231:
	;
	if !(libc.PostDecInt32(&n1, 1) == 0) {
		goto __232
	}
	goto __229
__232:
	;
	pOut += 56
	pIn1 += 56
	goto __228
__229:
	;
	goto __11

__32:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56

	Xsqlite3VdbeMemShallowCopy(tls, pOut, pIn1, MEM_Ephem)
	goto __11

__33:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	Xsqlite3VdbeMemSetInt64(tls, pOut, *(*I64)(unsafe.Pointer(pIn1)))
	goto __11

__34:
	if !(libc.AssignInt32(&rc, Xsqlite3VdbeCheckFk(tls, p, 0)) != SQLITE_OK) {
		goto __233
	}
	goto abort_due_to_error
__233:
	;
	goto __11

__35:
	;
	(*Vdbe)(unsafe.Pointer(p)).FcacheCtr = (*Vdbe)(unsafe.Pointer(p)).FcacheCtr + U32(2) | U32(1)
	(*Vdbe)(unsafe.Pointer(p)).FpResultRow = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __234
	}
	goto no_mem
__234:
	;
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmTrace)&SQLITE_TRACE_ROW != 0) {
		goto __235
	}
	(*struct {
		f func(*libc.TLS, U32, uintptr, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(db + 248))})).f(tls, uint32(SQLITE_TRACE_ROW), (*Sqlite3)(unsafe.Pointer(db)).FpTraceArg, p, uintptr(0))
__235:
	;
	(*Vdbe)(unsafe.Pointer(p)).Fpc = int32((int64(pOp)-int64(aOp))/32) + 1
	rc = SQLITE_ROW
	goto vdbe_return

__36:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pIn2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	flags1 = (*Mem)(unsafe.Pointer(pIn1)).Fflags

	if !((int32(flags1)|int32((*Mem)(unsafe.Pointer(pIn2)).Fflags))&MEM_Null != 0) {
		goto __236
	}
	Xsqlite3VdbeMemSetNull(tls, pOut)
	goto __11
__236:
	;
	if !(int32(flags1)&(MEM_Str|MEM_Blob) == 0) {
		goto __237
	}
	if !(Xsqlite3VdbeMemStringify(tls, pIn1, encoding, uint8(0)) != 0) {
		goto __239
	}
	goto no_mem
__239:
	;
	flags1 = U16(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags) & libc.CplInt32(MEM_Str))
	goto __238
__237:
	if !(int32(flags1)&MEM_Zero != 0) {
		goto __240
	}
	if !(Xsqlite3VdbeMemExpandBlob(tls, pIn1) != 0) {
		goto __241
	}
	goto no_mem
__241:
	;
	flags1 = U16(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags) & libc.CplInt32(MEM_Str))
__240:
	;
__238:
	;
	flags2 = (*Mem)(unsafe.Pointer(pIn2)).Fflags
	if !(int32(flags2)&(MEM_Str|MEM_Blob) == 0) {
		goto __242
	}
	if !(Xsqlite3VdbeMemStringify(tls, pIn2, encoding, uint8(0)) != 0) {
		goto __244
	}
	goto no_mem
__244:
	;
	flags2 = U16(int32((*Mem)(unsafe.Pointer(pIn2)).Fflags) & libc.CplInt32(MEM_Str))
	goto __243
__242:
	if !(int32(flags2)&MEM_Zero != 0) {
		goto __245
	}
	if !(Xsqlite3VdbeMemExpandBlob(tls, pIn2) != 0) {
		goto __246
	}
	goto no_mem
__246:
	;
	flags2 = U16(int32((*Mem)(unsafe.Pointer(pIn2)).Fflags) & libc.CplInt32(MEM_Str))
__245:
	;
__243:
	;
	nByte = I64((*Mem)(unsafe.Pointer(pIn1)).Fn + (*Mem)(unsafe.Pointer(pIn2)).Fn)
	if !(nByte > I64(*(*int32)(unsafe.Pointer(db + 136)))) {
		goto __247
	}
	goto too_big
__247:
	;
	if !(Xsqlite3VdbeMemGrow(tls, pOut, int32(nByte)+2, libc.Bool32(pOut == pIn2)) != 0) {
		goto __248
	}
	goto no_mem
__248:
	;
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Str)
	if !(pOut != pIn2) {
		goto __249
	}
	libc.Xmemcpy(tls, (*Mem)(unsafe.Pointer(pOut)).Fz, (*Mem)(unsafe.Pointer(pIn2)).Fz, uint64((*Mem)(unsafe.Pointer(pIn2)).Fn))

	(*Mem)(unsafe.Pointer(pIn2)).Fflags = flags2
__249:
	;
	libc.Xmemcpy(tls, (*Mem)(unsafe.Pointer(pOut)).Fz+uintptr((*Mem)(unsafe.Pointer(pIn2)).Fn), (*Mem)(unsafe.Pointer(pIn1)).Fz, uint64((*Mem)(unsafe.Pointer(pIn1)).Fn))

	(*Mem)(unsafe.Pointer(pIn1)).Fflags = flags1
	if !(int32(encoding) > SQLITE_UTF8) {
		goto __250
	}
	nByte = nByte & int64(libc.CplInt32(1))
__250:
	;
	*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pOut)).Fz + uintptr(nByte))) = uint8(0)
	*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pOut)).Fz + uintptr(nByte+int64(1)))) = uint8(0)
	*(*U16)(unsafe.Pointer(pOut + 20)) |= U16(MEM_Term)
	(*Mem)(unsafe.Pointer(pOut)).Fn = int32(nByte)
	(*Mem)(unsafe.Pointer(pOut)).Fenc = encoding
	updateMaxBlobsize(tls, pOut)
	goto __11

__37:
__38:
__39:
__40:
__41:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	type1 = (*Mem)(unsafe.Pointer(pIn1)).Fflags
	pIn2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	type2 = (*Mem)(unsafe.Pointer(pIn2)).Fflags
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	if !(int32(type1)&int32(type2)&MEM_Int != 0) {
		goto __251
	}
int_math:
	iA = *(*I64)(unsafe.Pointer(pIn1))
	*(*I64)(unsafe.Pointer(bp + 208)) = *(*I64)(unsafe.Pointer(pIn2))
	switch int32((*Op)(unsafe.Pointer(pOp)).Fopcode) {
	case OP_Add:
		goto __254
	case OP_Subtract:
		goto __255
	case OP_Multiply:
		goto __256
	case OP_Divide:
		goto __257
	default:
		goto __258
	}
	goto __253
__254:
	if !(Xsqlite3AddInt64(tls, bp+208, iA) != 0) {
		goto __259
	}
	goto fp_math
__259:
	;
	goto __253
__255:
	if !(Xsqlite3SubInt64(tls, bp+208, iA) != 0) {
		goto __260
	}
	goto fp_math
__260:
	;
	goto __253
__256:
	if !(Xsqlite3MulInt64(tls, bp+208, iA) != 0) {
		goto __261
	}
	goto fp_math
__261:
	;
	goto __253
__257:
	if !(iA == int64(0)) {
		goto __262
	}
	goto arithmetic_result_is_null
__262:
	;
	if !(iA == int64(-1) && *(*I64)(unsafe.Pointer(bp + 208)) == int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32)) {
		goto __263
	}
	goto fp_math
__263:
	;
	*(*I64)(unsafe.Pointer(bp + 208)) /= iA
	goto __253

__258:
	if !(iA == int64(0)) {
		goto __264
	}
	goto arithmetic_result_is_null
__264:
	;
	if !(iA == int64(-1)) {
		goto __265
	}
	iA = int64(1)
__265:
	;
	*(*I64)(unsafe.Pointer(bp + 208)) %= iA
	goto __253

__253:
	;
	*(*I64)(unsafe.Pointer(pOut)) = *(*I64)(unsafe.Pointer(bp + 208))
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Int)
	goto __252
__251:
	if !((int32(type1)|int32(type2))&MEM_Null != 0) {
		goto __266
	}
	goto arithmetic_result_is_null
	goto __267
__266:
	type1 = numericType(tls, pIn1)
	type2 = numericType(tls, pIn2)
	if !(int32(type1)&int32(type2)&MEM_Int != 0) {
		goto __268
	}
	goto int_math
__268:
	;
fp_math:
	rA = Xsqlite3VdbeRealValue(tls, pIn1)
	rB = Xsqlite3VdbeRealValue(tls, pIn2)
	switch int32((*Op)(unsafe.Pointer(pOp)).Fopcode) {
	case OP_Add:
		goto __270
	case OP_Subtract:
		goto __271
	case OP_Multiply:
		goto __272
	case OP_Divide:
		goto __273
	default:
		goto __274
	}
	goto __269
__270:
	rB = rB + rA
	goto __269
__271:
	rB = rB - rA
	goto __269
__272:
	rB = rB * rA
	goto __269
__273:
	if !(rA == float64(0)) {
		goto __275
	}
	goto arithmetic_result_is_null
__275:
	;
	rB = rB / rA
	goto __269

__274:
	iA = Xsqlite3VdbeIntValue(tls, pIn1)
	*(*I64)(unsafe.Pointer(bp + 208)) = Xsqlite3VdbeIntValue(tls, pIn2)
	if !(iA == int64(0)) {
		goto __276
	}
	goto arithmetic_result_is_null
__276:
	;
	if !(iA == int64(-1)) {
		goto __277
	}
	iA = int64(1)
__277:
	;
	rB = float64(*(*I64)(unsafe.Pointer(bp + 208)) % iA)
	goto __269

__269:
	;
	if !(Xsqlite3IsNaN(tls, rB) != 0) {
		goto __278
	}
	goto arithmetic_result_is_null
__278:
	;
	*(*float64)(unsafe.Pointer(pOut)) = rB
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Real)
__267:
	;
__252:
	;
	goto __11

arithmetic_result_is_null:
	Xsqlite3VdbeMemSetNull(tls, pOut)
	goto __11

__42:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp1 != 0) {
		goto __279
	}
	Xsqlite3VdbeMemSetInt64(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56, int64(0))
__279:
	;
	goto __11

__43:
__44:
__45:
__46:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pIn2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	if !((int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)|int32((*Mem)(unsafe.Pointer(pIn2)).Fflags))&MEM_Null != 0) {
		goto __280
	}
	Xsqlite3VdbeMemSetNull(tls, pOut)
	goto __11
__280:
	;
	*(*I64)(unsafe.Pointer(bp + 224)) = Xsqlite3VdbeIntValue(tls, pIn2)
	iB1 = Xsqlite3VdbeIntValue(tls, pIn1)
	op = (*Op)(unsafe.Pointer(pOp)).Fopcode
	if !(int32(op) == OP_BitAnd) {
		goto __281
	}
	*(*I64)(unsafe.Pointer(bp + 224)) &= iB1
	goto __282
__281:
	if !(int32(op) == OP_BitOr) {
		goto __283
	}
	*(*I64)(unsafe.Pointer(bp + 224)) |= iB1
	goto __284
__283:
	if !(iB1 != int64(0)) {
		goto __285
	}

	if !(iB1 < int64(0)) {
		goto __286
	}

	op = U8(2*OP_ShiftLeft + 1 - int32(op))
	if iB1 > int64(-64) {
		iB1 = -iB1
	} else {
		iB1 = int64(64)
	}
__286:
	;
	if !(iB1 >= int64(64)) {
		goto __287
	}
	if *(*I64)(unsafe.Pointer(bp + 224)) >= int64(0) || int32(op) == OP_ShiftLeft {
		*(*I64)(unsafe.Pointer(bp + 224)) = int64(0)
	} else {
		*(*I64)(unsafe.Pointer(bp + 224)) = int64(-1)
	}
	goto __288
__287:
	libc.Xmemcpy(tls, bp+216, bp+224, uint64(unsafe.Sizeof(U64(0))))
	if !(int32(op) == OP_ShiftLeft) {
		goto __289
	}
	*(*U64)(unsafe.Pointer(bp + 216)) <<= iB1
	goto __290
__289:
	*(*U64)(unsafe.Pointer(bp + 216)) >>= iB1

	if !(*(*I64)(unsafe.Pointer(bp + 224)) < int64(0)) {
		goto __291
	}
	*(*U64)(unsafe.Pointer(bp + 216)) |= (uint64(0xffffffff)<<32 | uint64(0xffffffff)) << (int64(64) - iB1)
__291:
	;
__290:
	;
	libc.Xmemcpy(tls, bp+224, bp+216, uint64(unsafe.Sizeof(I64(0))))
__288:
	;
__285:
	;
__284:
	;
__282:
	;
	*(*I64)(unsafe.Pointer(pOut)) = *(*I64)(unsafe.Pointer(bp + 224))
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Int)
	goto __11

__47:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	Xsqlite3VdbeMemIntegerify(tls, pIn1)
	*(*I64)(unsafe.Pointer(pIn1)) += I64((*Op)(unsafe.Pointer(pOp)).Fp2)
	goto __11

__48:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Int == 0) {
		goto __292
	}
	applyAffinity(tls, pIn1, uint8(SQLITE_AFF_NUMERIC), encoding)
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Int == 0) {
		goto __293
	}

	if !((*Op)(unsafe.Pointer(pOp)).Fp2 == 0) {
		goto __294
	}
	rc = SQLITE_MISMATCH
	goto abort_due_to_error
	goto __295
__294:
	goto jump_to_p2
__295:
	;
__293:
	;
__292:
	;
	(*Mem)(unsafe.Pointer(pIn1)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Int)
	goto __11

__49:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&(MEM_Int|MEM_IntReal) != 0) {
		goto __296
	}

	Xsqlite3VdbeMemRealify(tls, pIn1)

__296:
	;
	goto __11

__50:
	;
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	rc = func() int32 {
		if int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Zero != 0 {
			return Xsqlite3VdbeMemExpandBlob(tls, pIn1)
		}
		return 0
	}()
	if !(rc != 0) {
		goto __297
	}
	goto abort_due_to_error
__297:
	;
	rc = Xsqlite3VdbeMemCast(tls, pIn1, uint8((*Op)(unsafe.Pointer(pOp)).Fp2), encoding)
	if !(rc != 0) {
		goto __298
	}
	goto abort_due_to_error
__298:
	;
	updateMaxBlobsize(tls, pIn1)

	goto __11

__51:
__52:
__53:
__54:
__55:
__56:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pIn3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	flags11 = (*Mem)(unsafe.Pointer(pIn1)).Fflags
	flags3 = (*Mem)(unsafe.Pointer(pIn3)).Fflags
	if !(int32(flags11)&int32(flags3)&MEM_Int != 0) {
		goto __299
	}

	if !(*(*I64)(unsafe.Pointer(pIn3)) > *(*I64)(unsafe.Pointer(pIn1))) {
		goto __300
	}
	if !(*(*uint8)(unsafe.Pointer(Xsqlite3aGTb + uintptr((*Op)(unsafe.Pointer(pOp)).Fopcode))) != 0) {
		goto __302
	}

	goto jump_to_p2
__302:
	;
	iCompare = +1

	goto __301
__300:
	if !(*(*I64)(unsafe.Pointer(pIn3)) < *(*I64)(unsafe.Pointer(pIn1))) {
		goto __303
	}
	if !(*(*uint8)(unsafe.Pointer(Xsqlite3aLTb + uintptr((*Op)(unsafe.Pointer(pOp)).Fopcode))) != 0) {
		goto __305
	}

	goto jump_to_p2
__305:
	;
	iCompare = -1

	goto __304
__303:
	if !(*(*uint8)(unsafe.Pointer(Xsqlite3aEQb + uintptr((*Op)(unsafe.Pointer(pOp)).Fopcode))) != 0) {
		goto __306
	}

	goto jump_to_p2
__306:
	;
	iCompare = 0

__304:
	;
__301:
	;
	goto __11
__299:
	;
	if !((int32(flags11)|int32(flags3))&MEM_Null != 0) {
		goto __307
	}

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&SQLITE_NULLEQ != 0) {
		goto __309
	}

	if !(int32(flags11)&int32(flags3)&MEM_Null != 0 &&
		int32(flags3)&MEM_Cleared == 0) {
		goto __311
	}
	res = 0
	goto __312
__311:
	res = func() int32 {
		if int32(flags3)&MEM_Null != 0 {
			return -1
		}
		return +1
	}()
__312:
	;
	goto __310
__309:
	;
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&SQLITE_JUMPIFNULL != 0) {
		goto __313
	}
	goto jump_to_p2
__313:
	;
	iCompare = 1

	goto __11
__310:
	;
	goto __308
__307:
	affinity = uint8(int32((*Op)(unsafe.Pointer(pOp)).Fp5) & SQLITE_AFF_MASK)
	if !(int32(affinity) >= SQLITE_AFF_NUMERIC) {
		goto __314
	}
	if !((int32(flags11)|int32(flags3))&MEM_Str != 0) {
		goto __316
	}
	if !(int32(flags11)&(MEM_Int|MEM_IntReal|MEM_Real|MEM_Str) == MEM_Str) {
		goto __317
	}
	applyNumericAffinity(tls, pIn1, 0)

	flags3 = (*Mem)(unsafe.Pointer(pIn3)).Fflags
__317:
	;
	if !(int32(flags3)&(MEM_Int|MEM_IntReal|MEM_Real|MEM_Str) == MEM_Str) {
		goto __318
	}
	applyNumericAffinity(tls, pIn3, 0)
__318:
	;
__316:
	;
	goto __315
__314:
	if !(int32(affinity) == SQLITE_AFF_TEXT && (int32(flags11)|int32(flags3))&MEM_Str != 0) {
		goto __319
	}
	if !(int32(flags11)&MEM_Str == 0 && int32(flags11)&(MEM_Int|MEM_Real|MEM_IntReal) != 0) {
		goto __320
	}

	Xsqlite3VdbeMemStringify(tls, pIn1, encoding, uint8(1))

	flags11 = U16(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&libc.CplInt32(MEM_TypeMask) | int32(flags11)&MEM_TypeMask)
	if !(pIn1 == pIn3) {
		goto __321
	}
	flags3 = U16(int32(flags11) | MEM_Str)
__321:
	;
__320:
	;
	if !(int32(flags3)&MEM_Str == 0 && int32(flags3)&(MEM_Int|MEM_Real|MEM_IntReal) != 0) {
		goto __322
	}

	Xsqlite3VdbeMemStringify(tls, pIn3, encoding, uint8(1))

	flags3 = U16(int32((*Mem)(unsafe.Pointer(pIn3)).Fflags)&libc.CplInt32(MEM_TypeMask) | int32(flags3)&MEM_TypeMask)
__322:
	;
__319:
	;
__315:
	;
	res = Xsqlite3MemCompare(tls, pIn3, pIn1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
__308:
	;
	if !(res < 0) {
		goto __323
	}
	res2 = int32(*(*uint8)(unsafe.Pointer(Xsqlite3aLTb + uintptr((*Op)(unsafe.Pointer(pOp)).Fopcode))))
	goto __324
__323:
	if !(res == 0) {
		goto __325
	}
	res2 = int32(*(*uint8)(unsafe.Pointer(Xsqlite3aEQb + uintptr((*Op)(unsafe.Pointer(pOp)).Fopcode))))
	goto __326
__325:
	res2 = int32(*(*uint8)(unsafe.Pointer(Xsqlite3aGTb + uintptr((*Op)(unsafe.Pointer(pOp)).Fopcode))))
__326:
	;
__324:
	;
	iCompare = res

	(*Mem)(unsafe.Pointer(pIn3)).Fflags = flags3

	(*Mem)(unsafe.Pointer(pIn1)).Fflags = flags11

	if !(res2 != 0) {
		goto __327
	}
	goto jump_to_p2
__327:
	;
	goto __11

__57:
	;
	if !(iCompare == 0) {
		goto __328
	}
	goto jump_to_p2
__328:
	;
	goto __11

__58:
	;
	goto __11

__59:
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_PERMUTE == 0) {
		goto __329
	}
	aPermute = uintptr(0)
	goto __330
__329:
	;
	aPermute = *(*uintptr)(unsafe.Pointer(pOp + libc.UintptrFromInt32(-1)*32 + 16)) + uintptr(1)*4

__330:
	;
	n2 = (*Op)(unsafe.Pointer(pOp)).Fp3
	pKeyInfo = *(*uintptr)(unsafe.Pointer(pOp + 16))

	p11 = (*Op)(unsafe.Pointer(pOp)).Fp1
	p21 = (*Op)(unsafe.Pointer(pOp)).Fp2
	i = 0
__331:
	if !(i < n2) {
		goto __333
	}
	if aPermute != 0 {
		idx = *(*U32)(unsafe.Pointer(aPermute + uintptr(i)*4))
	} else {
		idx = U32(i)
	}

	pColl = *(*uintptr)(unsafe.Pointer(pKeyInfo + 32 + uintptr(i)*8))
	bRev = int32(*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(i)))) & KEYINFO_ORDER_DESC
	iCompare = Xsqlite3MemCompare(tls, aMem+uintptr(U32(p11)+idx)*56, aMem+uintptr(U32(p21)+idx)*56, pColl)

	if !(iCompare != 0) {
		goto __334
	}
	if !(int32(*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags + uintptr(i))))&KEYINFO_ORDER_BIGNULL != 0 &&
		(int32((*Mem)(unsafe.Pointer(aMem+uintptr(U32(p11)+idx)*56)).Fflags)&MEM_Null != 0 || int32((*Mem)(unsafe.Pointer(aMem+uintptr(U32(p21)+idx)*56)).Fflags)&MEM_Null != 0)) {
		goto __335
	}
	iCompare = -iCompare
__335:
	;
	if !(bRev != 0) {
		goto __336
	}
	iCompare = -iCompare
__336:
	;
	goto __333
__334:
	;
	goto __332
__332:
	i++
	goto __331
	goto __333
__333:
	;
	goto __11

__60:
	;
	if !(iCompare < 0) {
		goto __337
	}
	pOp = aOp + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1-1)*32
	goto __338
__337:
	if !(iCompare == 0) {
		goto __339
	}
	pOp = aOp + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2-1)*32
	goto __340
__339:
	;
	pOp = aOp + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3-1)*32
__340:
	;
__338:
	;
	goto __11

__61:
__62:
	v1 = Xsqlite3VdbeBooleanValue(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56, 2)
	v2 = Xsqlite3VdbeBooleanValue(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56, 2)
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_And) {
		goto __341
	}
	v1 = int32(and_logic[v1*3+v2])
	goto __342
__341:
	v1 = int32(or_logic[v1*3+v2])
__342:
	;
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	if !(v1 == 2) {
		goto __343
	}
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Null)
	goto __344
__343:
	*(*I64)(unsafe.Pointer(pOut)) = I64(v1)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Int)
__344:
	;
	goto __11

__63:
	;
	Xsqlite3VdbeMemSetInt64(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56,
		int64(Xsqlite3VdbeBooleanValue(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56, (*Op)(unsafe.Pointer(pOp)).Fp3)^*(*int32)(unsafe.Pointer(pOp + 16))))
	goto __11

__64:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Null == 0) {
		goto __345
	}
	Xsqlite3VdbeMemSetInt64(tls, pOut, libc.BoolInt64(!(Xsqlite3VdbeBooleanValue(tls, pIn1, 0) != 0)))
	goto __346
__345:
	Xsqlite3VdbeMemSetNull(tls, pOut)
__346:
	;
	goto __11

__65:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	Xsqlite3VdbeMemSetNull(tls, pOut)
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Null == 0) {
		goto __347
	}
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Int)
	*(*I64)(unsafe.Pointer(pOut)) = ^Xsqlite3VdbeIntValue(tls, pIn1)
__347:
	;
	goto __11

__66:
	;
	if !((*Vdbe)(unsafe.Pointer(p)).FpFrame != 0) {
		goto __348
	}
	iAddr = U32(int32((int64(pOp) - int64((*Vdbe)(unsafe.Pointer(p)).FaOp)) / 32))
	if !(int32(*(*U8)(unsafe.Pointer((*VdbeFrame)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FpFrame)).FaOnce + uintptr(iAddr/U32(8)))))&(int32(1)<<(iAddr&U32(7))) != 0) {
		goto __350
	}

	goto jump_to_p2
__350:
	;
	*(*U8)(unsafe.Pointer((*VdbeFrame)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FpFrame)).FaOnce + uintptr(iAddr/U32(8)))) |= U8(int32(1) << (iAddr & U32(7)))
	goto __349
__348:
	if !((*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp)).Fp1 == (*Op)(unsafe.Pointer(pOp)).Fp1) {
		goto __351
	}

	goto jump_to_p2
__351:
	;
__349:
	;
	(*Op)(unsafe.Pointer(pOp)).Fp1 = (*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp)).Fp1
	goto __11

__67:
	c = Xsqlite3VdbeBooleanValue(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56, (*Op)(unsafe.Pointer(pOp)).Fp3)

	if !(c != 0) {
		goto __352
	}
	goto jump_to_p2
__352:
	;
	goto __11

__68:
	c1 = libc.BoolInt32(!(Xsqlite3VdbeBooleanValue(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56, libc.BoolInt32(!((*Op)(unsafe.Pointer(pOp)).Fp3 != 0))) != 0))

	if !(c1 != 0) {
		goto __353
	}
	goto jump_to_p2
__353:
	;
	goto __11

__69:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Null != 0) {
		goto __354
	}
	goto jump_to_p2
__354:
	;
	goto __11

__70:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp1 >= 0) {
		goto __355
	}
	pC = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !((*Op)(unsafe.Pointer(pOp)).Fp3 < int32((*VdbeCursor)(unsafe.Pointer(pC)).FnHdrParsed)) {
		goto __357
	}
	serialType = *(*U32)(unsafe.Pointer(pC + 112 + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*4))
	if !(serialType >= U32(12)) {
		goto __359
	}
	if !(serialType&U32(1) != 0) {
		goto __361
	}
	typeMask = U16(0x04)
	goto __362
__361:
	typeMask = U16(0x08)
__362:
	;
	goto __360
__359:
	;
	typeMask = U16(aMask[serialType])
__360:
	;
	goto __358
__357:
	typeMask = U16(int32(1) << (*(*int32)(unsafe.Pointer(pOp + 16)) - 1))

__358:
	;
	goto __356
__355:
	;
	typeMask = U16(int32(1) << (Xsqlite3_value_type(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56) - 1))

__356:
	;
	if !(int32(typeMask)&int32((*Op)(unsafe.Pointer(pOp)).Fp5) != 0) {
		goto __363
	}
	goto jump_to_p2
__363:
	;
	goto __11

__71:
	if !(int32((*Mem)(unsafe.Pointer(aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56)).Fflags)&MEM_Null != 0 ||
		int32((*Mem)(unsafe.Pointer(aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56)).Fflags)&MEM_Null != 0) {
		goto __364
	}
	Xsqlite3VdbeMemSetNull(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56)
	goto __365
__364:
	Xsqlite3VdbeMemSetInt64(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56, int64(0))
__365:
	;
	goto __11

__72:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Null == 0) {
		goto __366
	}
	goto jump_to_p2
__366:
	;
	goto __11

__73:
	;
	pC1 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	if !(pC1 != 0 && (*VdbeCursor)(unsafe.Pointer(pC1)).FnullRow != 0) {
		goto __367
	}
	Xsqlite3VdbeMemSetNull(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56)
	goto jump_to_p2
__367:
	;
	goto __11

__74:
	;
	pC2 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	pOut = (*Vdbe)(unsafe.Pointer(p)).FaMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	if !(pC2 == uintptr(0) || int32((*VdbeCursor)(unsafe.Pointer(pC2)).FeCurType) != CURTYPE_BTREE) {
		goto __368
	}
	Xsqlite3VdbeMemSetNull(tls, pOut)
	goto __369
__368:
	if !((*VdbeCursor)(unsafe.Pointer(pC2)).FdeferredMoveto != 0) {
		goto __370
	}
	rc = Xsqlite3VdbeFinishMoveto(tls, pC2)
	if !(rc != 0) {
		goto __371
	}
	goto abort_due_to_error
__371:
	;
__370:
	;
	if !(Xsqlite3BtreeEof(tls, *(*uintptr)(unsafe.Pointer(pC2 + 48))) != 0) {
		goto __372
	}
	Xsqlite3VdbeMemSetNull(tls, pOut)
	goto __373
__372:
	Xsqlite3VdbeMemSetInt64(tls, pOut, Xsqlite3BtreeOffset(tls, *(*uintptr)(unsafe.Pointer(pC2 + 48))))
__373:
	;
__369:
	;
	goto __11

__75:
	;
	pC3 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	p22 = U32((*Op)(unsafe.Pointer(pOp)).Fp2)

op_column_restart:
	;
	aOffset = (*VdbeCursor)(unsafe.Pointer(pC3)).FaOffset

	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FcacheStatus != (*Vdbe)(unsafe.Pointer(p)).FcacheCtr) {
		goto __374
	}
	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FnullRow != 0) {
		goto __376
	}
	if !(int32((*VdbeCursor)(unsafe.Pointer(pC3)).FeCurType) == CURTYPE_PSEUDO && (*VdbeCursor)(unsafe.Pointer(pC3)).FseekResult > 0) {
		goto __378
	}

	pReg = aMem + uintptr((*VdbeCursor)(unsafe.Pointer(pC3)).FseekResult)*56

	(*VdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize = libc.AssignPtrUint32(pC3+108, U32((*Mem)(unsafe.Pointer(pReg)).Fn))
	(*VdbeCursor)(unsafe.Pointer(pC3)).FaRow = (*Mem)(unsafe.Pointer(pReg)).Fz
	goto __379
__378:
	pDest = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	Xsqlite3VdbeMemSetNull(tls, pDest)
	goto op_column_out
__379:
	;
	goto __377
__376:
	pCrsr = *(*uintptr)(unsafe.Pointer(pC3 + 48))
	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FdeferredMoveto != 0) {
		goto __380
	}

	if !(*(*uintptr)(unsafe.Pointer(pC3 + 16)) != 0 && libc.AssignUint32(&iMap, *(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pC3 + 16)) + uintptr(U32(1)+p22)*4))) > U32(0)) {
		goto __382
	}
	pC3 = (*VdbeCursor)(unsafe.Pointer(pC3)).FpAltCursor
	p22 = iMap - U32(1)
	goto op_column_restart
__382:
	;
	rc = Xsqlite3VdbeFinishMoveto(tls, pC3)
	if !(rc != 0) {
		goto __383
	}
	goto abort_due_to_error
__383:
	;
	goto __381
__380:
	if !(Xsqlite3BtreeCursorHasMoved(tls, pCrsr) != 0) {
		goto __384
	}
	rc = Xsqlite3VdbeHandleMovedCursor(tls, pC3)
	if !(rc != 0) {
		goto __385
	}
	goto abort_due_to_error
__385:
	;
	goto op_column_restart
__384:
	;
__381:
	;
	(*VdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize = Xsqlite3BtreePayloadSize(tls, pCrsr)
	(*VdbeCursor)(unsafe.Pointer(pC3)).FaRow = Xsqlite3BtreePayloadFetch(tls, pCrsr, pC3+108)

__377:
	;
	(*VdbeCursor)(unsafe.Pointer(pC3)).FcacheStatus = (*Vdbe)(unsafe.Pointer(p)).FcacheCtr
	if !(libc.AssignPtrUint32(aOffset, U32(*(*U8)(unsafe.Pointer((*VdbeCursor)(unsafe.Pointer(pC3)).FaRow)))) < U32(0x80)) {
		goto __386
	}
	(*VdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = U32(1)
	goto __387
__386:
	(*VdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = U32(Xsqlite3GetVarint32(tls, (*VdbeCursor)(unsafe.Pointer(pC3)).FaRow, aOffset))
__387:
	;
	(*VdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed = U16(0)

	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FszRow < *(*U32)(unsafe.Pointer(aOffset))) {
		goto __388
	}

	(*VdbeCursor)(unsafe.Pointer(pC3)).FaRow = uintptr(0)
	(*VdbeCursor)(unsafe.Pointer(pC3)).FszRow = U32(0)

	if !(*(*U32)(unsafe.Pointer(aOffset)) > U32(98307) || *(*U32)(unsafe.Pointer(aOffset)) > (*VdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize) {
		goto __390
	}
	goto op_column_corrupt
__390:
	;
	goto __389
__388:
	zData = (*VdbeCursor)(unsafe.Pointer(pC3)).FaRow

	goto op_column_read_header
__389:
	;
	goto __375
__374:
	if !(Xsqlite3BtreeCursorHasMoved(tls, *(*uintptr)(unsafe.Pointer(pC3 + 48))) != 0) {
		goto __391
	}
	rc = Xsqlite3VdbeHandleMovedCursor(tls, pC3)
	if !(rc != 0) {
		goto __392
	}
	goto abort_due_to_error
__392:
	;
	goto op_column_restart
__391:
	;
__375:
	;
	if !(U32((*VdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed) <= p22) {
		goto __393
	}

	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset < *(*U32)(unsafe.Pointer(aOffset))) {
		goto __395
	}

	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0)) {
		goto __397
	}
	libc.Xmemset(tls, bp+232, 0, uint64(unsafe.Sizeof(Mem{})))
	rc = Xsqlite3VdbeMemFromBtreeZeroOffset(tls, *(*uintptr)(unsafe.Pointer(pC3 + 48)), *(*U32)(unsafe.Pointer(aOffset)), bp+232)
	if !(rc != SQLITE_OK) {
		goto __399
	}
	goto abort_due_to_error
__399:
	;
	zData = (*Mem)(unsafe.Pointer(bp + 232)).Fz
	goto __398
__397:
	zData = (*VdbeCursor)(unsafe.Pointer(pC3)).FaRow
__398:
	;
op_column_read_header:
	i1 = int32((*VdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed)
	offset64 = U64(*(*U32)(unsafe.Pointer(aOffset + uintptr(i1)*4)))
	zHdr = zData + uintptr((*VdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset)
	zEndHdr = zData + uintptr(*(*U32)(unsafe.Pointer(aOffset)))

__400:
	if !(libc.AssignPtrUint32(pC3+112+uintptr(i1)*4, libc.AssignPtrUint32(bp+288, U32(*(*U8)(unsafe.Pointer(zHdr))))) < U32(0x80)) {
		goto __403
	}
	zHdr++
	offset64 = offset64 + U64(Xsqlite3VdbeOneByteSerialTypeLen(tls, uint8(*(*U32)(unsafe.Pointer(bp + 288)))))
	goto __404
__403:
	zHdr += uintptr(Xsqlite3GetVarint32(tls, zHdr, bp+288))
	*(*U32)(unsafe.Pointer(pC3 + 112 + uintptr(i1)*4)) = *(*U32)(unsafe.Pointer(bp + 288))
	offset64 = offset64 + U64(Xsqlite3VdbeSerialTypeLen(tls, *(*U32)(unsafe.Pointer(bp + 288))))
__404:
	;
	*(*U32)(unsafe.Pointer(aOffset + uintptr(libc.PreIncInt32(&i1, 1))*4)) = U32(offset64 & uint64(0xffffffff))
	goto __401
__401:
	if U32(i1) <= p22 && zHdr < zEndHdr {
		goto __400
	}
	goto __402
__402:
	;
	if !(zHdr >= zEndHdr && (zHdr > zEndHdr || offset64 != U64((*VdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize)) ||
		offset64 > U64((*VdbeCursor)(unsafe.Pointer(pC3)).FpayloadSize)) {
		goto __405
	}
	if !(*(*U32)(unsafe.Pointer(aOffset)) == U32(0)) {
		goto __406
	}
	i1 = 0
	zHdr = zEndHdr
	goto __407
__406:
	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0)) {
		goto __408
	}
	Xsqlite3VdbeMemRelease(tls, bp+232)
__408:
	;
	goto op_column_corrupt
__407:
	;
__405:
	;
	(*VdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed = U16(i1)
	(*VdbeCursor)(unsafe.Pointer(pC3)).FiHdrOffset = U32((int64(zHdr) - int64(zData)) / 1)
	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FaRow == uintptr(0)) {
		goto __409
	}
	Xsqlite3VdbeMemRelease(tls, bp+232)
__409:
	;
	goto __396
__395:
	*(*U32)(unsafe.Pointer(bp + 288)) = U32(0)
__396:
	;
	if !(U32((*VdbeCursor)(unsafe.Pointer(pC3)).FnHdrParsed) <= p22) {
		goto __410
	}
	pDest = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp4type) == -10) {
		goto __411
	}
	Xsqlite3VdbeMemShallowCopy(tls, pDest, *(*uintptr)(unsafe.Pointer(pOp + 16)), MEM_Static)
	goto __412
__411:
	Xsqlite3VdbeMemSetNull(tls, pDest)
__412:
	;
	goto op_column_out
__410:
	;
	goto __394
__393:
	*(*U32)(unsafe.Pointer(bp + 288)) = *(*U32)(unsafe.Pointer(pC3 + 112 + uintptr(p22)*4))
__394:
	;
	pDest = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	if !(int32((*Mem)(unsafe.Pointer(pDest)).Fflags)&(MEM_Agg|MEM_Dyn) != 0) {
		goto __413
	}
	Xsqlite3VdbeMemSetNull(tls, pDest)
__413:
	;
	if !((*VdbeCursor)(unsafe.Pointer(pC3)).FszRow >= *(*U32)(unsafe.Pointer(aOffset + uintptr(p22+U32(1))*4))) {
		goto __414
	}

	zData = (*VdbeCursor)(unsafe.Pointer(pC3)).FaRow + uintptr(*(*U32)(unsafe.Pointer(aOffset + uintptr(p22)*4)))
	if !(*(*U32)(unsafe.Pointer(bp + 288)) < U32(12)) {
		goto __416
	}
	Xsqlite3VdbeSerialGet(tls, zData, *(*U32)(unsafe.Pointer(bp + 288)), pDest)
	goto __417
__416:
	(*Mem)(unsafe.Pointer(pDest)).Fn = libc.AssignInt32(&len, int32((*(*U32)(unsafe.Pointer(bp + 288))-U32(12))/U32(2)))
	(*Mem)(unsafe.Pointer(pDest)).Fenc = encoding
	if !((*Mem)(unsafe.Pointer(pDest)).FszMalloc < len+2) {
		goto __418
	}
	if !(len > *(*int32)(unsafe.Pointer(db + 136))) {
		goto __420
	}
	goto too_big
__420:
	;
	(*Mem)(unsafe.Pointer(pDest)).Fflags = U16(MEM_Null)
	if !(Xsqlite3VdbeMemGrow(tls, pDest, len+2, 0) != 0) {
		goto __421
	}
	goto no_mem
__421:
	;
	goto __419
__418:
	(*Mem)(unsafe.Pointer(pDest)).Fz = (*Mem)(unsafe.Pointer(pDest)).FzMalloc
__419:
	;
	libc.Xmemcpy(tls, (*Mem)(unsafe.Pointer(pDest)).Fz, zData, uint64(len))
	*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pDest)).Fz + uintptr(len))) = uint8(0)
	*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pDest)).Fz + uintptr(len+1))) = uint8(0)
	(*Mem)(unsafe.Pointer(pDest)).Fflags = aFlag1[*(*U32)(unsafe.Pointer(bp + 288))&U32(1)]
__417:
	;
	goto __415
__414:
	(*Mem)(unsafe.Pointer(pDest)).Fenc = encoding

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&(OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG) != 0 &&
		(*(*U32)(unsafe.Pointer(bp + 288)) >= U32(12) && *(*U32)(unsafe.Pointer(bp + 288))&U32(1) == U32(0) || int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_TYPEOFARG != 0) ||
		libc.AssignInt32(&len, int32(Xsqlite3VdbeSerialTypeLen(tls, *(*U32)(unsafe.Pointer(bp + 288))))) == 0) {
		goto __422
	}

	Xsqlite3VdbeSerialGet(tls, uintptr(unsafe.Pointer(&Xsqlite3CtypeMap)), *(*U32)(unsafe.Pointer(bp + 288)), pDest)
	goto __423
__422:
	if !(len > *(*int32)(unsafe.Pointer(db + 136))) {
		goto __424
	}
	goto too_big
__424:
	;
	rc = Xsqlite3VdbeMemFromBtree(tls, *(*uintptr)(unsafe.Pointer(pC3 + 48)), *(*U32)(unsafe.Pointer(aOffset + uintptr(p22)*4)), uint32(len), pDest)
	if !(rc != SQLITE_OK) {
		goto __425
	}
	goto abort_due_to_error
__425:
	;
	Xsqlite3VdbeSerialGet(tls, (*Mem)(unsafe.Pointer(pDest)).Fz, *(*U32)(unsafe.Pointer(bp + 288)), pDest)
	*(*U16)(unsafe.Pointer(pDest + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Ephem))
__423:
	;
__415:
	;
op_column_out:
	updateMaxBlobsize(tls, pDest)

	goto __11

op_column_corrupt:
	if !((*Op)(unsafe.Pointer(aOp)).Fp3 > 0) {
		goto __426
	}
	pOp = aOp + uintptr((*Op)(unsafe.Pointer(aOp)).Fp3-1)*32
	goto __11
	goto __427
__426:
	rc = Xsqlite3CorruptError(tls, 93320)
	goto abort_due_to_error
__427:
	;
__76:
	;
	pTab = *(*uintptr)(unsafe.Pointer(pOp + 16))

	aCol = (*Table)(unsafe.Pointer(pTab)).FaCol
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	i2 = 0
__428:
	if !(i2 < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __430
	}
	if !(int32((*Column)(unsafe.Pointer(aCol+uintptr(i2)*24)).FcolFlags)&COLFLAG_GENERATED != 0) {
		goto __431
	}
	if !(int32((*Column)(unsafe.Pointer(aCol+uintptr(i2)*24)).FcolFlags)&COLFLAG_VIRTUAL != 0) {
		goto __432
	}
	goto __429
__432:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __433
	}
	pIn1 += 56
	goto __429
__433:
	;
__431:
	;
	applyAffinity(tls, pIn1, (*Column)(unsafe.Pointer(aCol+uintptr(i2)*24)).Faffinity, encoding)
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Null == 0) {
		goto __434
	}
	switch int32(*(*uint8)(unsafe.Pointer(aCol + uintptr(i2)*24 + 8)) & 0xf0 >> 4) {
	case COLTYPE_BLOB:
		goto __436
	case COLTYPE_INTEGER:
		goto __437
	case COLTYPE_INT:
		goto __438
	case COLTYPE_TEXT:
		goto __439
	case COLTYPE_REAL:
		goto __440
	default:
		goto __441
	}
	goto __435
__436:
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Blob == 0) {
		goto __442
	}
	goto vdbe_type_error
__442:
	;
	goto __435

__437:
__438:
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Int == 0) {
		goto __443
	}
	goto vdbe_type_error
__443:
	;
	goto __435

__439:
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Str == 0) {
		goto __444
	}
	goto vdbe_type_error
__444:
	;
	goto __435

__440:
	;
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Int != 0) {
		goto __445
	}

	if !(*(*I64)(unsafe.Pointer(pIn1)) <= 140737488355327 && *(*I64)(unsafe.Pointer(pIn1)) >= -140737488355328) {
		goto __447
	}
	*(*U16)(unsafe.Pointer(pIn1 + 20)) |= U16(MEM_IntReal)
	*(*U16)(unsafe.Pointer(pIn1 + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Int))
	goto __448
__447:
	*(*float64)(unsafe.Pointer(pIn1)) = float64(*(*I64)(unsafe.Pointer(pIn1)))
	*(*U16)(unsafe.Pointer(pIn1 + 20)) |= U16(MEM_Real)
	*(*U16)(unsafe.Pointer(pIn1 + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Int))
__448:
	;
	goto __446
__445:
	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&(MEM_Real|MEM_IntReal) == 0) {
		goto __449
	}
	goto vdbe_type_error
__449:
	;
__446:
	;
	goto __435

__441:
	goto __435

__435:
	;
__434:
	;
	pIn1 += 56
	goto __429
__429:
	i2++
	goto __428
	goto __430
__430:
	;
	goto __11

vdbe_type_error:
	Xsqlite3VdbeError(tls, p, ts+8408,
		libc.VaList(bp+56, vdbeMemTypeName(tls, pIn1), Xsqlite3StdType[(int32(*(*uint8)(unsafe.Pointer(aCol + uintptr(i2)*24 + 8))&0xf0>>4)-1)&0xf<<28>>28],
			(*Table)(unsafe.Pointer(pTab)).FzName, (*Column)(unsafe.Pointer(aCol+uintptr(i2)*24)).FzCnName))
	rc = SQLITE_CONSTRAINT | int32(12)<<8
	goto abort_due_to_error

__77:
	zAffinity = *(*uintptr)(unsafe.Pointer(pOp + 16))

	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
__450:
	if !(1 != 0) {
		goto __451
	}

	applyAffinity(tls, pIn1, *(*uint8)(unsafe.Pointer(zAffinity)), encoding)
	if !(int32(*(*uint8)(unsafe.Pointer(zAffinity))) == SQLITE_AFF_REAL && int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Int != 0) {
		goto __452
	}

	if !(*(*I64)(unsafe.Pointer(pIn1)) <= 140737488355327 && *(*I64)(unsafe.Pointer(pIn1)) >= -140737488355328) {
		goto __453
	}
	*(*U16)(unsafe.Pointer(pIn1 + 20)) |= U16(MEM_IntReal)
	*(*U16)(unsafe.Pointer(pIn1 + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Int))
	goto __454
__453:
	*(*float64)(unsafe.Pointer(pIn1)) = float64(*(*I64)(unsafe.Pointer(pIn1)))
	*(*U16)(unsafe.Pointer(pIn1 + 20)) |= U16(MEM_Real)
	*(*U16)(unsafe.Pointer(pIn1 + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Int))
__454:
	;
__452:
	;
	zAffinity++
	if !(int32(*(*uint8)(unsafe.Pointer(zAffinity))) == 0) {
		goto __455
	}
	goto __451
__455:
	;
	pIn1 += 56
	goto __450
__451:
	;
	goto __11

__78:
	nData = uint64(0)
	nHdr = 0
	nZero = int64(0)
	nField = (*Op)(unsafe.Pointer(pOp)).Fp1
	zAffinity1 = *(*uintptr)(unsafe.Pointer(pOp + 16))

	pData0 = aMem + uintptr(nField)*56
	nField = (*Op)(unsafe.Pointer(pOp)).Fp2
	pLast = pData0 + uintptr(nField-1)*56

	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	if !(zAffinity1 != 0) {
		goto __456
	}
	pRec = pData0
__457:
	applyAffinity(tls, pRec, *(*uint8)(unsafe.Pointer(zAffinity1)), encoding)
	if !(int32(*(*uint8)(unsafe.Pointer(zAffinity1))) == SQLITE_AFF_REAL && int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Int != 0) {
		goto __460
	}
	*(*U16)(unsafe.Pointer(pRec + 20)) |= U16(MEM_IntReal)
	*(*U16)(unsafe.Pointer(pRec + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Int))
__460:
	;
	zAffinity1++
	pRec += 56

	goto __458
__458:
	if *(*uint8)(unsafe.Pointer(zAffinity1)) != 0 {
		goto __457
	}
	goto __459
__459:
	;
__456:
	;
	pRec = pLast
__461:
	;
	if !(int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Null != 0) {
		goto __464
	}
	if !(int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Zero != 0) {
		goto __466
	}

	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(10)
	goto __467
__466:
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(0)
__467:
	;
	nHdr++
	goto __465
__464:
	if !(int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&(MEM_Int|MEM_IntReal) != 0) {
		goto __468
	}

	i3 = *(*I64)(unsafe.Pointer(pRec))

	if !(i3 < int64(0)) {
		goto __470
	}
	uu = U64(^i3)
	goto __471
__470:
	uu = U64(i3)
__471:
	;
	nHdr++

	if !(uu <= uint64(127)) {
		goto __472
	}
	if !(i3&int64(1) == i3 && int32((*Vdbe)(unsafe.Pointer(p)).FminWriteFileFormat) >= 4) {
		goto __474
	}
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(8) + U32(uu)
	goto __475
__474:
	nData++
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(1)
__475:
	;
	goto __473
__472:
	if !(uu <= uint64(32767)) {
		goto __476
	}
	nData = nData + uint64(2)
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(2)
	goto __477
__476:
	if !(uu <= uint64(8388607)) {
		goto __478
	}
	nData = nData + uint64(3)
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(3)
	goto __479
__478:
	if !(uu <= uint64(2147483647)) {
		goto __480
	}
	nData = nData + uint64(4)
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(4)
	goto __481
__480:
	if !(uu <= uint64(140737488355327)) {
		goto __482
	}
	nData = nData + uint64(6)
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(5)
	goto __483
__482:
	nData = nData + uint64(8)
	if !(int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_IntReal != 0) {
		goto __484
	}

	*(*float64)(unsafe.Pointer(pRec)) = float64(*(*I64)(unsafe.Pointer(pRec)))
	*(*U16)(unsafe.Pointer(pRec + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_IntReal))
	*(*U16)(unsafe.Pointer(pRec + 20)) |= U16(MEM_Real)
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(7)
	goto __485
__484:
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(6)
__485:
	;
__483:
	;
__481:
	;
__479:
	;
__477:
	;
__473:
	;
	goto __469
__468:
	if !(int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Real != 0) {
		goto __486
	}
	nHdr++
	nData = nData + uint64(8)
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = U32(7)
	goto __487
__486:
	;
	len1 = U32((*Mem)(unsafe.Pointer(pRec)).Fn)
	serial_type = len1*U32(2) + U32(12) + U32(libc.Bool32(int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Str != 0))
	if !(int32((*Mem)(unsafe.Pointer(pRec)).Fflags)&MEM_Zero != 0) {
		goto __488
	}
	serial_type = serial_type + U32(*(*int32)(unsafe.Pointer(pRec))*2)
	if !(nData != 0) {
		goto __489
	}
	if !(Xsqlite3VdbeMemExpandBlob(tls, pRec) != 0) {
		goto __491
	}
	goto no_mem
__491:
	;
	len1 = len1 + U32(*(*int32)(unsafe.Pointer(pRec)))
	goto __490
__489:
	nZero = nZero + I64(*(*int32)(unsafe.Pointer(pRec)))
__490:
	;
__488:
	;
	nData = nData + U64(len1)
	nHdr = nHdr + Xsqlite3VarintLen(tls, uint64(serial_type))
	(*Mem)(unsafe.Pointer(pRec)).FuTemp = serial_type
__487:
	;
__469:
	;
__465:
	;
	if !(pRec == pData0) {
		goto __492
	}
	goto __463
__492:
	;
	pRec -= 56
	goto __462
__462:
	if 1 != 0 {
		goto __461
	}
	goto __463
__463:
	;
	if !(nHdr <= 126) {
		goto __493
	}

	nHdr = nHdr + 1
	goto __494
__493:
	nVarint = Xsqlite3VarintLen(tls, uint64(nHdr))
	nHdr = nHdr + nVarint
	if !(nVarint < Xsqlite3VarintLen(tls, uint64(nHdr))) {
		goto __495
	}
	nHdr++
__495:
	;
__494:
	;
	nByte1 = I64(U64(nHdr) + nData)

	if !(nByte1+nZero <= I64((*Mem)(unsafe.Pointer(pOut)).FszMalloc)) {
		goto __496
	}

	(*Mem)(unsafe.Pointer(pOut)).Fz = (*Mem)(unsafe.Pointer(pOut)).FzMalloc
	goto __497
__496:
	if !(nByte1+nZero > I64(*(*int32)(unsafe.Pointer(db + 136)))) {
		goto __498
	}
	goto too_big
__498:
	;
	if !(Xsqlite3VdbeMemClearAndResize(tls, pOut, int32(nByte1)) != 0) {
		goto __499
	}
	goto no_mem
__499:
	;
__497:
	;
	(*Mem)(unsafe.Pointer(pOut)).Fn = int32(nByte1)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Blob)
	if !(nZero != 0) {
		goto __500
	}
	*(*int32)(unsafe.Pointer(pOut)) = int32(nZero)
	*(*U16)(unsafe.Pointer(pOut + 20)) |= U16(MEM_Zero)
__500:
	;
	updateMaxBlobsize(tls, pOut)
	zHdr1 = (*Mem)(unsafe.Pointer(pOut)).Fz
	zPayload = zHdr1 + uintptr(nHdr)

	if !(nHdr < 0x80) {
		goto __501
	}
	*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&zHdr1, 1))) = U8(nHdr)
	goto __502
__501:
	zHdr1 += uintptr(Xsqlite3PutVarint(tls, zHdr1, uint64(nHdr)))
__502:
	;
	pRec = pData0
__503:
	if !(1 != 0) {
		goto __504
	}
	serial_type = (*Mem)(unsafe.Pointer(pRec)).FuTemp

	if !(serial_type <= U32(7)) {
		goto __505
	}
	*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&zHdr1, 1))) = U8(serial_type)
	if !(serial_type == U32(0)) {
		goto __507
	}

	goto __508
__507:
	if !(serial_type == U32(7)) {
		goto __509
	}

	libc.Xmemcpy(tls, bp+296, pRec, uint64(unsafe.Sizeof(U64(0))))

	goto __510
__509:
	*(*U64)(unsafe.Pointer(bp + 296)) = U64(*(*I64)(unsafe.Pointer(pRec)))
__510:
	;
	len1 = libc.AssignUint32(&i4, U32(Xsqlite3SmallTypeSizes[serial_type]))

__511:
	if !(1 != 0) {
		goto __512
	}
	*(*U8)(unsafe.Pointer(zPayload + uintptr(libc.PreDecUint32(&i4, 1)))) = U8(*(*U64)(unsafe.Pointer(bp + 296)) & uint64(0xFF))
	if !(i4 == U32(0)) {
		goto __513
	}
	goto __512
__513:
	;
	*(*U64)(unsafe.Pointer(bp + 296)) >>= 8
	goto __511
__512:
	;
	zPayload += uintptr(len1)
__508:
	;
	goto __506
__505:
	if !(serial_type < U32(0x80)) {
		goto __514
	}
	*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&zHdr1, 1))) = U8(serial_type)
	if !(serial_type >= U32(14) && (*Mem)(unsafe.Pointer(pRec)).Fn > 0) {
		goto __516
	}

	libc.Xmemcpy(tls, zPayload, (*Mem)(unsafe.Pointer(pRec)).Fz, uint64((*Mem)(unsafe.Pointer(pRec)).Fn))
	zPayload += uintptr((*Mem)(unsafe.Pointer(pRec)).Fn)
__516:
	;
	goto __515
__514:
	zHdr1 += uintptr(Xsqlite3PutVarint(tls, zHdr1, uint64(serial_type)))
	if !((*Mem)(unsafe.Pointer(pRec)).Fn != 0) {
		goto __517
	}

	libc.Xmemcpy(tls, zPayload, (*Mem)(unsafe.Pointer(pRec)).Fz, uint64((*Mem)(unsafe.Pointer(pRec)).Fn))
	zPayload += uintptr((*Mem)(unsafe.Pointer(pRec)).Fn)
__517:
	;
__515:
	;
__506:
	;
	if !(pRec == pLast) {
		goto __518
	}
	goto __504
__518:
	;
	pRec += 56
	goto __503
__504:
	;
	goto __11

__79:
	;
	pCrsr1 = *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8)) + 48))

	if !((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __519
	}
	*(*I64)(unsafe.Pointer(bp + 304)) = Xsqlite3BtreeRowCountEst(tls, pCrsr1)
	goto __520
__519:
	*(*I64)(unsafe.Pointer(bp + 304)) = int64(0)
	rc = Xsqlite3BtreeCount(tls, db, pCrsr1, bp+304)
	if !(rc != 0) {
		goto __521
	}
	goto abort_due_to_error
__521:
	;
__520:
	;
	pOut = out2Prerelease(tls, p, pOp)
	*(*I64)(unsafe.Pointer(pOut)) = *(*I64)(unsafe.Pointer(bp + 304))
	goto check_for_interrupt

__80:
	p12 = (*Op)(unsafe.Pointer(pOp)).Fp1
	zName = *(*uintptr)(unsafe.Pointer(pOp + 16))

	if !(p12 == SAVEPOINT_BEGIN) {
		goto __522
	}
	if !((*Sqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0) {
		goto __524
	}

	Xsqlite3VdbeError(tls, p, ts+8449, 0)
	rc = SQLITE_BUSY
	goto __525
__524:
	nName = Xsqlite3Strlen30(tls, zName)

	rc = Xsqlite3VtabSavepoint(tls, db, SAVEPOINT_BEGIN,
		(*Sqlite3)(unsafe.Pointer(db)).FnStatement+(*Sqlite3)(unsafe.Pointer(db)).FnSavepoint)
	if !(rc != SQLITE_OK) {
		goto __526
	}
	goto abort_due_to_error
__526:
	;
	pNew = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(Savepoint{}))+uint64(nName)+uint64(1))
	if !(pNew != 0) {
		goto __527
	}
	(*Savepoint)(unsafe.Pointer(pNew)).FzName = pNew + 1*32
	libc.Xmemcpy(tls, (*Savepoint)(unsafe.Pointer(pNew)).FzName, zName, uint64(nName+1))

	if !((*Sqlite3)(unsafe.Pointer(db)).FautoCommit != 0) {
		goto __528
	}
	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(0)
	(*Sqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint = U8(1)
	goto __529
__528:
	(*Sqlite3)(unsafe.Pointer(db)).FnSavepoint++
__529:
	;
	(*Savepoint)(unsafe.Pointer(pNew)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).FpSavepoint
	(*Sqlite3)(unsafe.Pointer(db)).FpSavepoint = pNew
	(*Savepoint)(unsafe.Pointer(pNew)).FnDeferredCons = (*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons
	(*Savepoint)(unsafe.Pointer(pNew)).FnDeferredImmCons = (*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons
__527:
	;
__525:
	;
	goto __523
__522:
	;
	iSavepoint = 0

	pSavepoint = (*Sqlite3)(unsafe.Pointer(db)).FpSavepoint
__530:
	if !(pSavepoint != 0 && Xsqlite3StrICmp(tls, (*Savepoint)(unsafe.Pointer(pSavepoint)).FzName, zName) != 0) {
		goto __532
	}
	iSavepoint++
	goto __531
__531:
	pSavepoint = (*Savepoint)(unsafe.Pointer(pSavepoint)).FpNext
	goto __530
	goto __532
__532:
	;
	if !!(pSavepoint != 0) {
		goto __533
	}
	Xsqlite3VdbeError(tls, p, ts+8500, libc.VaList(bp+88, zName))
	rc = SQLITE_ERROR
	goto __534
__533:
	if !((*Sqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0 && p12 == SAVEPOINT_RELEASE) {
		goto __535
	}

	Xsqlite3VdbeError(tls, p,
		ts+8522, 0)
	rc = SQLITE_BUSY
	goto __536
__535:
	isTransaction = libc.Bool32((*Savepoint)(unsafe.Pointer(pSavepoint)).FpNext == uintptr(0) && (*Sqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint != 0)
	if !(isTransaction != 0 && p12 == SAVEPOINT_RELEASE) {
		goto __537
	}
	if !(libc.AssignInt32(&rc, Xsqlite3VdbeCheckFk(tls, p, 1)) != SQLITE_OK) {
		goto __539
	}
	goto vdbe_return
__539:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(1)
	if !(Xsqlite3VdbeHalt(tls, p) == SQLITE_BUSY) {
		goto __540
	}
	(*Vdbe)(unsafe.Pointer(p)).Fpc = int32((int64(pOp) - int64(aOp)) / 32)
	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(0)
	(*Vdbe)(unsafe.Pointer(p)).Frc = libc.AssignInt32(&rc, SQLITE_BUSY)
	goto vdbe_return
__540:
	;
	rc = (*Vdbe)(unsafe.Pointer(p)).Frc
	if !(rc != 0) {
		goto __541
	}
	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(0)
	goto __542
__541:
	(*Sqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint = U8(0)
__542:
	;
	goto __538
__537:
	iSavepoint = (*Sqlite3)(unsafe.Pointer(db)).FnSavepoint - iSavepoint - 1
	if !(p12 == SAVEPOINT_ROLLBACK) {
		goto __543
	}
	isSchemaChange = libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_SchemaChange) != U32(0))
	ii = 0
__545:
	if !(ii < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __547
	}
	rc = Xsqlite3BtreeTripAllCursors(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii)*32)).FpBt,
		SQLITE_ABORT|int32(2)<<8,
		libc.Bool32(isSchemaChange == 0))
	if !(rc != SQLITE_OK) {
		goto __548
	}
	goto abort_due_to_error
__548:
	;
	goto __546
__546:
	ii++
	goto __545
	goto __547
__547:
	;
	goto __544
__543:
	;
	isSchemaChange = 0
__544:
	;
	ii = 0
__549:
	if !(ii < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __551
	}
	rc = Xsqlite3BtreeSavepoint(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii)*32)).FpBt, p12, iSavepoint)
	if !(rc != SQLITE_OK) {
		goto __552
	}
	goto abort_due_to_error
__552:
	;
	goto __550
__550:
	ii++
	goto __549
	goto __551
__551:
	;
	if !(isSchemaChange != 0) {
		goto __553
	}
	Xsqlite3ExpirePreparedStatements(tls, db, 0)
	Xsqlite3ResetAllSchemasOfConnection(tls, db)
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaChange)
__553:
	;
__538:
	;
	if !(rc != 0) {
		goto __554
	}
	goto abort_due_to_error
__554:
	;
__555:
	if !((*Sqlite3)(unsafe.Pointer(db)).FpSavepoint != pSavepoint) {
		goto __556
	}
	pTmp = (*Sqlite3)(unsafe.Pointer(db)).FpSavepoint
	(*Sqlite3)(unsafe.Pointer(db)).FpSavepoint = (*Savepoint)(unsafe.Pointer(pTmp)).FpNext
	Xsqlite3DbFree(tls, db, pTmp)
	(*Sqlite3)(unsafe.Pointer(db)).FnSavepoint--
	goto __555
__556:
	;
	if !(p12 == SAVEPOINT_RELEASE) {
		goto __557
	}

	(*Sqlite3)(unsafe.Pointer(db)).FpSavepoint = (*Savepoint)(unsafe.Pointer(pSavepoint)).FpNext
	Xsqlite3DbFree(tls, db, pSavepoint)
	if !!(isTransaction != 0) {
		goto __559
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnSavepoint--
__559:
	;
	goto __558
__557:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons = (*Savepoint)(unsafe.Pointer(pSavepoint)).FnDeferredCons
	(*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = (*Savepoint)(unsafe.Pointer(pSavepoint)).FnDeferredImmCons
__558:
	;
	if !(!(isTransaction != 0) || p12 == SAVEPOINT_ROLLBACK) {
		goto __560
	}
	rc = Xsqlite3VtabSavepoint(tls, db, p12, iSavepoint)
	if !(rc != SQLITE_OK) {
		goto __561
	}
	goto abort_due_to_error
__561:
	;
__560:
	;
__536:
	;
__534:
	;
__523:
	;
	if !(rc != 0) {
		goto __562
	}
	goto abort_due_to_error
__562:
	;
	if !(int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) == VDBE_HALT_STATE) {
		goto __563
	}
	rc = SQLITE_DONE
	goto vdbe_return
__563:
	;
	goto __11

__81:
	desiredAutoCommit = (*Op)(unsafe.Pointer(pOp)).Fp1
	iRollback = (*Op)(unsafe.Pointer(pOp)).Fp2

	if !(desiredAutoCommit != int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit)) {
		goto __564
	}
	if !(iRollback != 0) {
		goto __566
	}

	Xsqlite3RollbackAll(tls, db, SQLITE_ABORT|int32(2)<<8)
	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(1)
	goto __567
__566:
	if !(desiredAutoCommit != 0 && (*Sqlite3)(unsafe.Pointer(db)).FnVdbeWrite > 0) {
		goto __568
	}

	Xsqlite3VdbeError(tls, p,
		ts+8576, 0)
	rc = SQLITE_BUSY
	goto abort_due_to_error
	goto __569
__568:
	if !(libc.AssignInt32(&rc, Xsqlite3VdbeCheckFk(tls, p, 1)) != SQLITE_OK) {
		goto __570
	}
	goto vdbe_return
	goto __571
__570:
	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(desiredAutoCommit)
__571:
	;
__569:
	;
__567:
	;
	if !(Xsqlite3VdbeHalt(tls, p) == SQLITE_BUSY) {
		goto __572
	}
	(*Vdbe)(unsafe.Pointer(p)).Fpc = int32((int64(pOp) - int64(aOp)) / 32)
	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(1 - desiredAutoCommit)
	(*Vdbe)(unsafe.Pointer(p)).Frc = libc.AssignInt32(&rc, SQLITE_BUSY)
	goto vdbe_return
__572:
	;
	Xsqlite3CloseSavepoints(tls, db)
	if !((*Vdbe)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
		goto __573
	}
	rc = SQLITE_DONE
	goto __574
__573:
	rc = SQLITE_ERROR
__574:
	;
	goto vdbe_return
	goto __565
__564:
	Xsqlite3VdbeError(tls, p,
		func() uintptr {
			if !(desiredAutoCommit != 0) {
				return ts + 8631
			}
			return func() uintptr {
				if iRollback != 0 {
					return ts + 8679
				}
				return ts + 8722
			}()
		}(), 0)

	rc = SQLITE_ERROR
	goto abort_due_to_error
__565:
	;
__82:
	*(*int32)(unsafe.Pointer(bp + 312)) = 0

	if !((*Op)(unsafe.Pointer(pOp)).Fp2 != 0 && (*Sqlite3)(unsafe.Pointer(db)).Fflags&(uint64(SQLITE_QueryOnly)|uint64(0x00002)<<32) != uint64(0)) {
		goto __575
	}
	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_QueryOnly) != 0) {
		goto __576
	}

	rc = SQLITE_READONLY
	goto __577
__576:
	rc = SQLITE_CORRUPT
__577:
	;
	goto abort_due_to_error
__575:
	;
	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*32
	pBt = (*Db)(unsafe.Pointer(pDb)).FpBt

	if !(pBt != 0) {
		goto __578
	}
	rc = Xsqlite3BtreeBeginTrans(tls, pBt, (*Op)(unsafe.Pointer(pOp)).Fp2, bp+312)

	if !(rc != SQLITE_OK) {
		goto __579
	}
	if !(rc&0xff == SQLITE_BUSY) {
		goto __580
	}
	(*Vdbe)(unsafe.Pointer(p)).Fpc = int32((int64(pOp) - int64(aOp)) / 32)
	(*Vdbe)(unsafe.Pointer(p)).Frc = rc
	goto vdbe_return
__580:
	;
	goto abort_due_to_error
__579:
	;
	if !(Bft(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x20>>5)) != 0 &&
		(*Op)(unsafe.Pointer(pOp)).Fp2 != 0 &&
		(int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit) == 0 || (*Sqlite3)(unsafe.Pointer(db)).FnVdbeRead > 1)) {
		goto __581
	}

	if !((*Vdbe)(unsafe.Pointer(p)).FiStatement == 0) {
		goto __582
	}

	(*Sqlite3)(unsafe.Pointer(db)).FnStatement++
	(*Vdbe)(unsafe.Pointer(p)).FiStatement = (*Sqlite3)(unsafe.Pointer(db)).FnSavepoint + (*Sqlite3)(unsafe.Pointer(db)).FnStatement
__582:
	;
	rc = Xsqlite3VtabSavepoint(tls, db, SAVEPOINT_BEGIN, (*Vdbe)(unsafe.Pointer(p)).FiStatement-1)
	if !(rc == SQLITE_OK) {
		goto __583
	}
	rc = Xsqlite3BtreeBeginStmt(tls, pBt, (*Vdbe)(unsafe.Pointer(p)).FiStatement)
__583:
	;
	(*Vdbe)(unsafe.Pointer(p)).FnStmtDefCons = (*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons
	(*Vdbe)(unsafe.Pointer(p)).FnStmtDefImmCons = (*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons
__581:
	;
__578:
	;
	if !(rc == SQLITE_OK &&
		(*Op)(unsafe.Pointer(pOp)).Fp5 != 0 &&
		(*(*int32)(unsafe.Pointer(bp + 312)) != (*Op)(unsafe.Pointer(pOp)).Fp3 || (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).FiGeneration != *(*int32)(unsafe.Pointer(pOp + 16)))) {
		goto __584
	}

	Xsqlite3DbFree(tls, db, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg)
	(*Vdbe)(unsafe.Pointer(p)).FzErrMsg = Xsqlite3DbStrDup(tls, db, ts+8763)

	if !((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*32)).FpSchema)).Fschema_cookie != *(*int32)(unsafe.Pointer(bp + 312))) {
		goto __585
	}
	Xsqlite3ResetOneSchema(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1)
__585:
	;
	libc.SetBitFieldPtr8Uint32(p+200, Bft(1), 0, 0x3)
	rc = SQLITE_SCHEMA

	libc.SetBitFieldPtr8Uint32(p+200, Bft(0), 4, 0x10)
__584:
	;
	if !(rc != 0) {
		goto __586
	}
	goto abort_due_to_error
__586:
	;
	goto __11

__83:
	;
	iDb = (*Op)(unsafe.Pointer(pOp)).Fp1
	iCookie = (*Op)(unsafe.Pointer(pOp)).Fp3

	Xsqlite3BtreeGetMeta(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpBt, iCookie, bp+316)
	pOut = out2Prerelease(tls, p, pOp)
	*(*I64)(unsafe.Pointer(pOut)) = I64(*(*int32)(unsafe.Pointer(bp + 316)))
	goto __11

__84:
	;
	pDb1 = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*32

	rc = Xsqlite3BtreeUpdateMeta(tls, (*Db)(unsafe.Pointer(pDb1)).FpBt, (*Op)(unsafe.Pointer(pOp)).Fp2, uint32((*Op)(unsafe.Pointer(pOp)).Fp3))
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 == BTREE_SCHEMA_VERSION) {
		goto __587
	}

	*(*U32)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb1)).FpSchema)) = *(*U32)(unsafe.Pointer(pOp + 12)) - U32((*Op)(unsafe.Pointer(pOp)).Fp5)
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaChange)
	Xsqlite3FkClearTriggerCache(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1)
	goto __588
__587:
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 == BTREE_FILE_FORMAT) {
		goto __589
	}

	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb1)).FpSchema)).Ffile_format = U8((*Op)(unsafe.Pointer(pOp)).Fp3)
__589:
	;
__588:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp1 == 1) {
		goto __590
	}

	Xsqlite3ExpirePreparedStatements(tls, db, 0)
	libc.SetBitFieldPtr8Uint32(p+200, Bft(0), 0, 0x3)
__590:
	;
	if !(rc != 0) {
		goto __591
	}
	goto abort_due_to_error
__591:
	;
	goto __11

__85:
	;
	pCur = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	if !(pCur != 0 && (*VdbeCursor)(unsafe.Pointer(pCur)).FpgnoRoot == U32((*Op)(unsafe.Pointer(pOp)).Fp2)) {
		goto __592
	}

	Xsqlite3BtreeClearCursor(tls, *(*uintptr)(unsafe.Pointer(pCur + 48)))
	goto open_cursor_set_hints
__592:
	;
__86:
__87:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(p + 200))&0x3>>0) == 1) {
		goto __593
	}
	rc = SQLITE_ABORT | int32(2)<<8
	goto abort_due_to_error
__593:
	;
	nField1 = 0
	pKeyInfo1 = uintptr(0)
	p23 = U32((*Op)(unsafe.Pointer(pOp)).Fp2)
	iDb1 = (*Op)(unsafe.Pointer(pOp)).Fp3

	pDb2 = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb1)*32
	pX = (*Db)(unsafe.Pointer(pDb2)).FpBt

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_OpenWrite) {
		goto __594
	}

	wrFlag = BTREE_WRCSR | int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_FORDELETE

	if !(int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb2)).FpSchema)).Ffile_format) < int32((*Vdbe)(unsafe.Pointer(p)).FminWriteFileFormat)) {
		goto __596
	}
	(*Vdbe)(unsafe.Pointer(p)).FminWriteFileFormat = (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb2)).FpSchema)).Ffile_format
__596:
	;
	goto __595
__594:
	wrFlag = 0
__595:
	;
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_P2ISREG != 0) {
		goto __597
	}

	pIn2 = aMem + uintptr(p23)*56

	Xsqlite3VdbeMemIntegerify(tls, pIn2)
	p23 = U32(int32(*(*I64)(unsafe.Pointer(pIn2))))

__597:
	;
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp4type) == -8) {
		goto __598
	}
	pKeyInfo1 = *(*uintptr)(unsafe.Pointer(pOp + 16))

	nField1 = int32((*KeyInfo)(unsafe.Pointer(pKeyInfo1)).FnAllField)
	goto __599
__598:
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp4type) == -3) {
		goto __600
	}
	nField1 = *(*int32)(unsafe.Pointer(pOp + 16))
__600:
	;
__599:
	;
	pCur = allocateCursor(tls, p, (*Op)(unsafe.Pointer(pOp)).Fp1, nField1, uint8(CURTYPE_BTREE))
	if !(pCur == uintptr(0)) {
		goto __601
	}
	goto no_mem
__601:
	;
	(*VdbeCursor)(unsafe.Pointer(pCur)).FiDb = I8(iDb1)
	(*VdbeCursor)(unsafe.Pointer(pCur)).FnullRow = U8(1)
	libc.SetBitFieldPtr8Uint32(pCur+8, Bool(1), 2, 0x4)
	(*VdbeCursor)(unsafe.Pointer(pCur)).FpgnoRoot = p23
	rc = Xsqlite3BtreeCursor(tls, pX, p23, wrFlag, pKeyInfo1, *(*uintptr)(unsafe.Pointer(pCur + 48)))
	(*VdbeCursor)(unsafe.Pointer(pCur)).FpKeyInfo = pKeyInfo1

	(*VdbeCursor)(unsafe.Pointer(pCur)).FisTable = U8(libc.Bool32(int32((*Op)(unsafe.Pointer(pOp)).Fp4type) != -8))

open_cursor_set_hints:
	;
	Xsqlite3BtreeCursorHintFlags(tls, *(*uintptr)(unsafe.Pointer(pCur + 48)),
		uint32(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&(OPFLAG_BULKCSR|OPFLAG_SEEKEQ)))
	if !(rc != 0) {
		goto __602
	}
	goto abort_due_to_error
__602:
	;
	goto __11

__88:
	pOrig = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*8))

	pCx = allocateCursor(tls, p, (*Op)(unsafe.Pointer(pOp)).Fp1, int32((*VdbeCursor)(unsafe.Pointer(pOrig)).FnField), uint8(CURTYPE_BTREE))
	if !(pCx == uintptr(0)) {
		goto __603
	}
	goto no_mem
__603:
	;
	(*VdbeCursor)(unsafe.Pointer(pCx)).FnullRow = U8(1)
	libc.SetBitFieldPtr8Uint32(pCx+8, Bool(1), 0, 0x1)
	(*VdbeCursor)(unsafe.Pointer(pCx)).FpKeyInfo = (*VdbeCursor)(unsafe.Pointer(pOrig)).FpKeyInfo
	(*VdbeCursor)(unsafe.Pointer(pCx)).FisTable = (*VdbeCursor)(unsafe.Pointer(pOrig)).FisTable
	(*VdbeCursor)(unsafe.Pointer(pCx)).FpgnoRoot = (*VdbeCursor)(unsafe.Pointer(pOrig)).FpgnoRoot
	libc.SetBitFieldPtr8Uint32(pCx+8, Bool(int32(*(*uint8)(unsafe.Pointer(pOrig + 8))&0x4>>2)), 2, 0x4)
	*(*uintptr)(unsafe.Pointer(pCx + 16)) = *(*uintptr)(unsafe.Pointer(pOrig + 16))
	libc.SetBitFieldPtr8Uint32(pCx+8, Bool(1), 3, 0x8)
	libc.SetBitFieldPtr8Uint32(pOrig+8, Bool(1), 3, 0x8)
	rc = Xsqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx + 16)), (*VdbeCursor)(unsafe.Pointer(pCx)).FpgnoRoot, BTREE_WRCSR,
		(*VdbeCursor)(unsafe.Pointer(pCx)).FpKeyInfo, *(*uintptr)(unsafe.Pointer(pCx + 48)))

	goto __11

__89:
__90:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp3 > 0) {
		goto __604
	}

	(*Mem)(unsafe.Pointer(aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56)).Fn = 0
	(*Mem)(unsafe.Pointer(aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56)).Fz = ts + 1636
__604:
	;
	pCx1 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	if !(pCx1 != 0 && !(int32(*(*uint8)(unsafe.Pointer(pCx1 + 8))&0x8>>3) != 0) && (*Op)(unsafe.Pointer(pOp)).Fp2 <= int32((*VdbeCursor)(unsafe.Pointer(pCx1)).FnField)) {
		goto __605
	}

	(*VdbeCursor)(unsafe.Pointer(pCx1)).FseqCount = int64(0)
	(*VdbeCursor)(unsafe.Pointer(pCx1)).FcacheStatus = U32(CACHE_STALE)
	rc = Xsqlite3BtreeClearTable(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), int32((*VdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot), uintptr(0))
	goto __606
__605:
	pCx1 = allocateCursor(tls, p, (*Op)(unsafe.Pointer(pOp)).Fp1, (*Op)(unsafe.Pointer(pOp)).Fp2, uint8(CURTYPE_BTREE))
	if !(pCx1 == uintptr(0)) {
		goto __607
	}
	goto no_mem
__607:
	;
	libc.SetBitFieldPtr8Uint32(pCx1+8, Bool(1), 0, 0x1)
	rc = Xsqlite3BtreeOpen(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), db, pCx1+16,
		BTREE_OMIT_JOURNAL|BTREE_SINGLE|int32((*Op)(unsafe.Pointer(pOp)).Fp5),
		vfsFlags)
	if !(rc == SQLITE_OK) {
		goto __608
	}
	rc = Xsqlite3BtreeBeginTrans(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), 1, uintptr(0))
	if !(rc == SQLITE_OK) {
		goto __609
	}

	if !(libc.AssignPtrUintptr(pCx1+56, libc.AssignUintptr(&pKeyInfo2, *(*uintptr)(unsafe.Pointer(pOp + 16)))) != uintptr(0)) {
		goto __610
	}

	rc = Xsqlite3BtreeCreateTable(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), pCx1+68,
		BTREE_BLOBKEY|int32((*Op)(unsafe.Pointer(pOp)).Fp5))
	if !(rc == SQLITE_OK) {
		goto __612
	}

	rc = Xsqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), (*VdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot, BTREE_WRCSR,
		pKeyInfo2, *(*uintptr)(unsafe.Pointer(pCx1 + 48)))
__612:
	;
	(*VdbeCursor)(unsafe.Pointer(pCx1)).FisTable = U8(0)
	goto __611
__610:
	(*VdbeCursor)(unsafe.Pointer(pCx1)).FpgnoRoot = Pgno(SCHEMA_ROOT)
	rc = Xsqlite3BtreeCursor(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)), uint32(SCHEMA_ROOT), BTREE_WRCSR,
		uintptr(0), *(*uintptr)(unsafe.Pointer(pCx1 + 48)))
	(*VdbeCursor)(unsafe.Pointer(pCx1)).FisTable = U8(1)
__611:
	;
__609:
	;
	libc.SetBitFieldPtr8Uint32(pCx1+8, Bool(libc.Bool32(int32((*Op)(unsafe.Pointer(pOp)).Fp5) != BTREE_UNORDERED)), 2, 0x4)
	if !(rc != 0) {
		goto __613
	}
	Xsqlite3BtreeClose(tls, *(*uintptr)(unsafe.Pointer(pCx1 + 16)))
__613:
	;
__608:
	;
__606:
	;
	if !(rc != 0) {
		goto __614
	}
	goto abort_due_to_error
__614:
	;
	(*VdbeCursor)(unsafe.Pointer(pCx1)).FnullRow = U8(1)
	goto __11

__91:
	;
	pCx2 = allocateCursor(tls, p, (*Op)(unsafe.Pointer(pOp)).Fp1, (*Op)(unsafe.Pointer(pOp)).Fp2, uint8(CURTYPE_SORTER))
	if !(pCx2 == uintptr(0)) {
		goto __615
	}
	goto no_mem
__615:
	;
	(*VdbeCursor)(unsafe.Pointer(pCx2)).FpKeyInfo = *(*uintptr)(unsafe.Pointer(pOp + 16))

	rc = Xsqlite3VdbeSorterInit(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp3, pCx2)
	if !(rc != 0) {
		goto __616
	}
	goto abort_due_to_error
__616:
	;
	goto __11

__92:
	;
	pC4 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !(libc.PostIncInt64(&(*VdbeCursor)(unsafe.Pointer(pC4)).FseqCount, 1) == int64(0)) {
		goto __617
	}
	goto jump_to_p2
__617:
	;
	goto __11

__93:
	;
	pCx3 = allocateCursor(tls, p, (*Op)(unsafe.Pointer(pOp)).Fp1, (*Op)(unsafe.Pointer(pOp)).Fp3, uint8(CURTYPE_PSEUDO))
	if !(pCx3 == uintptr(0)) {
		goto __618
	}
	goto no_mem
__618:
	;
	(*VdbeCursor)(unsafe.Pointer(pCx3)).FnullRow = U8(1)
	(*VdbeCursor)(unsafe.Pointer(pCx3)).FseekResult = (*Op)(unsafe.Pointer(pOp)).Fp2
	(*VdbeCursor)(unsafe.Pointer(pCx3)).FisTable = U8(1)

	*(*uintptr)(unsafe.Pointer(pCx3 + 48)) = Xsqlite3BtreeFakeValidCursor(tls)

	goto __11

__94:
	;
	Xsqlite3VdbeFreeCursor(tls, p, *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8)))
	*(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8)) = uintptr(0)
	goto __11

__95:
__96:
__97:
__98:
	;
	pC5 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	oc = int32((*Op)(unsafe.Pointer(pOp)).Fopcode)
	eqOnly = 0
	(*VdbeCursor)(unsafe.Pointer(pC5)).FnullRow = U8(0)

	(*VdbeCursor)(unsafe.Pointer(pC5)).FdeferredMoveto = U8(0)
	(*VdbeCursor)(unsafe.Pointer(pC5)).FcacheStatus = U32(CACHE_STALE)
	if !((*VdbeCursor)(unsafe.Pointer(pC5)).FisTable != 0) {
		goto __619
	}

	pIn3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	flags31 = (*Mem)(unsafe.Pointer(pIn3)).Fflags
	if !(int32(flags31)&(MEM_Int|MEM_Real|MEM_IntReal|MEM_Str) == MEM_Str) {
		goto __621
	}
	applyNumericAffinity(tls, pIn3, 0)
__621:
	;
	iKey = Xsqlite3VdbeIntValue(tls, pIn3)
	newType = (*Mem)(unsafe.Pointer(pIn3)).Fflags
	(*Mem)(unsafe.Pointer(pIn3)).Fflags = flags31

	if !(int32(newType)&(MEM_Int|MEM_IntReal) == 0) {
		goto __622
	}
	if !(int32(newType)&MEM_Real == 0) {
		goto __623
	}
	if !(int32(newType)&MEM_Null != 0 || oc >= OP_SeekGE) {
		goto __624
	}

	goto jump_to_p2
	goto __625
__624:
	rc = Xsqlite3BtreeLast(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), bp+320)
	if !(rc != SQLITE_OK) {
		goto __626
	}
	goto abort_due_to_error
__626:
	;
	goto seek_not_found
__625:
	;
__623:
	;
	c2 = Xsqlite3IntFloatCompare(tls, iKey, *(*float64)(unsafe.Pointer(pIn3)))

	if !(c2 > 0) {
		goto __627
	}

	if !(oc&0x0001 == OP_SeekGT&0x0001) {
		goto __629
	}
	oc--
__629:
	;
	goto __628
__627:
	if !(c2 < 0) {
		goto __630
	}

	if !(oc&0x0001 == OP_SeekLT&0x0001) {
		goto __631
	}
	oc++
__631:
	;
__630:
	;
__628:
	;
__622:
	;
	rc = Xsqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), int64(U64(iKey)), 0, bp+320)
	(*VdbeCursor)(unsafe.Pointer(pC5)).FmovetoTarget = iKey
	if !(rc != SQLITE_OK) {
		goto __632
	}
	goto abort_due_to_error
__632:
	;
	goto __620
__619:
	if !(Xsqlite3BtreeCursorHasHint(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), uint32(BTREE_SEEK_EQ)) != 0) {
		goto __633
	}
	eqOnly = 1

__633:
	;
	nField2 = *(*int32)(unsafe.Pointer(pOp + 16))

	(*UnpackedRecord)(unsafe.Pointer(bp + 328)).FpKeyInfo = (*VdbeCursor)(unsafe.Pointer(pC5)).FpKeyInfo
	(*UnpackedRecord)(unsafe.Pointer(bp + 328)).FnField = U16(nField2)

	(*UnpackedRecord)(unsafe.Pointer(bp + 328)).Fdefault_rc = func() int8 {
		if 1&(oc-OP_SeekLT) != 0 {
			return int8(-1)
		}
		return +int8(1)
	}()

	(*UnpackedRecord)(unsafe.Pointer(bp + 328)).FaMem = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	(*UnpackedRecord)(unsafe.Pointer(bp + 328)).FeqSeen = U8(0)
	rc = Xsqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), bp+328, bp+320)
	if !(rc != SQLITE_OK) {
		goto __634
	}
	goto abort_due_to_error
__634:
	;
	if !(eqOnly != 0 && int32((*UnpackedRecord)(unsafe.Pointer(bp+328)).FeqSeen) == 0) {
		goto __635
	}

	goto seek_not_found
__635:
	;
__620:
	;
	atomic.AddInt32(&Xsqlite3_search_count, 1)
	if !(oc >= OP_SeekGE) {
		goto __636
	}
	if !(*(*int32)(unsafe.Pointer(bp + 320)) < 0 || *(*int32)(unsafe.Pointer(bp + 320)) == 0 && oc == OP_SeekGT) {
		goto __638
	}
	*(*int32)(unsafe.Pointer(bp + 320)) = 0
	rc = Xsqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), 0)
	if !(rc != SQLITE_OK) {
		goto __640
	}
	if !(rc == SQLITE_DONE) {
		goto __641
	}
	rc = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 320)) = 1
	goto __642
__641:
	goto abort_due_to_error
__642:
	;
__640:
	;
	goto __639
__638:
	*(*int32)(unsafe.Pointer(bp + 320)) = 0
__639:
	;
	goto __637
__636:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 320)) > 0 || *(*int32)(unsafe.Pointer(bp + 320)) == 0 && oc == OP_SeekLT) {
		goto __643
	}
	*(*int32)(unsafe.Pointer(bp + 320)) = 0
	rc = Xsqlite3BtreePrevious(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)), 0)
	if !(rc != SQLITE_OK) {
		goto __645
	}
	if !(rc == SQLITE_DONE) {
		goto __646
	}
	rc = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 320)) = 1
	goto __647
__646:
	goto abort_due_to_error
__647:
	;
__645:
	;
	goto __644
__643:
	*(*int32)(unsafe.Pointer(bp + 320)) = Xsqlite3BtreeEof(tls, *(*uintptr)(unsafe.Pointer(pC5 + 48)))
__644:
	;
__637:
	;
seek_not_found:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 320)) != 0) {
		goto __648
	}
	goto jump_to_p2
	goto __649
__648:
	if !(eqOnly != 0) {
		goto __650
	}

	pOp += 32
__650:
	;
__649:
	;
	goto __11

__99:
	;
	pC6 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp+1*32)).Fp1)*8))

	if !!(Xsqlite3BtreeCursorIsValidNN(tls, *(*uintptr)(unsafe.Pointer(pC6 + 48))) != 0) {
		goto __651
	}
	goto __11
__651:
	;
	nStep = (*Op)(unsafe.Pointer(pOp)).Fp1

	(*UnpackedRecord)(unsafe.Pointer(bp + 368)).FpKeyInfo = (*VdbeCursor)(unsafe.Pointer(pC6)).FpKeyInfo
	(*UnpackedRecord)(unsafe.Pointer(bp + 368)).FnField = U16(*(*int32)(unsafe.Pointer(pOp + 1*32 + 16)))
	(*UnpackedRecord)(unsafe.Pointer(bp + 368)).Fdefault_rc = int8(0)
	(*UnpackedRecord)(unsafe.Pointer(bp + 368)).FaMem = aMem + uintptr((*Op)(unsafe.Pointer(pOp+1*32)).Fp3)*56
	*(*int32)(unsafe.Pointer(bp + 408)) = 0
__652:
	if !(1 != 0) {
		goto __653
	}
	rc = Xsqlite3VdbeIdxKeyCompare(tls, db, pC6, bp+368, bp+408)
	if !(rc != 0) {
		goto __654
	}
	goto abort_due_to_error
__654:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 408)) > 0 && int32((*Op)(unsafe.Pointer(pOp)).Fp5) == 0) {
		goto __655
	}
seekscan_search_fail:
	;
	pOp += 32
	goto jump_to_p2
__655:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 408)) >= 0) {
		goto __656
	}

	goto jump_to_p2
	goto __653
__656:
	;
	if !(nStep <= 0) {
		goto __657
	}

	goto __653
__657:
	;
	nStep--
	rc = Xsqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC6 + 48)), 0)
	if !(rc != 0) {
		goto __658
	}
	if !(rc == SQLITE_DONE) {
		goto __659
	}
	rc = SQLITE_OK
	goto seekscan_search_fail
	goto __660
__659:
	goto abort_due_to_error
__660:
	;
__658:
	;
	goto __652
__653:
	;
	goto __11

__100:
	;
	pC7 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !(int32((*VdbeCursor)(unsafe.Pointer(pC7)).FseekHit) < (*Op)(unsafe.Pointer(pOp)).Fp2) {
		goto __661
	}
	(*VdbeCursor)(unsafe.Pointer(pC7)).FseekHit = U16((*Op)(unsafe.Pointer(pOp)).Fp2)
	goto __662
__661:
	if !(int32((*VdbeCursor)(unsafe.Pointer(pC7)).FseekHit) > (*Op)(unsafe.Pointer(pOp)).Fp3) {
		goto __663
	}
	(*VdbeCursor)(unsafe.Pointer(pC7)).FseekHit = U16((*Op)(unsafe.Pointer(pOp)).Fp3)
__663:
	;
__662:
	;
	goto __11

__101:
	;
	pCur1 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !(pCur1 == uintptr(0) || (*VdbeCursor)(unsafe.Pointer(pCur1)).FnullRow != 0) {
		goto __664
	}
	goto jump_to_p2_and_check_for_interrupt
__664:
	;
	goto __11

__102:
	;
	pC8 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !(int32((*VdbeCursor)(unsafe.Pointer(pC8)).FseekHit) >= *(*int32)(unsafe.Pointer(pOp + 16))) {
		goto __665
	}
	goto __11
__665:
	;
__103:
__104:
__105:
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) != OP_NoConflict) {
		goto __666
	}
	Xsqlite3_found_count++
__666:
	;
	pC9 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	(*UnpackedRecord)(unsafe.Pointer(bp + 416)).FaMem = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	(*UnpackedRecord)(unsafe.Pointer(bp + 416)).FnField = U16(*(*int32)(unsafe.Pointer(pOp + 16)))
	if !(int32((*UnpackedRecord)(unsafe.Pointer(bp+416)).FnField) > 0) {
		goto __667
	}

	(*UnpackedRecord)(unsafe.Pointer(bp + 416)).FpKeyInfo = (*VdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo
	(*UnpackedRecord)(unsafe.Pointer(bp + 416)).Fdefault_rc = int8(0)
	rc = Xsqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC9 + 48)), bp+416, pC9+36)
	goto __668
__667:
	;
	rc = func() int32 {
		if int32((*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(bp+416)).FaMem)).Fflags)&MEM_Zero != 0 {
			return Xsqlite3VdbeMemExpandBlob(tls, (*UnpackedRecord)(unsafe.Pointer(bp+416)).FaMem)
		}
		return 0
	}()

	if !(rc != 0) {
		goto __669
	}
	goto no_mem
__669:
	;
	pIdxKey = Xsqlite3VdbeAllocUnpackedRecord(tls, (*VdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo)
	if !(pIdxKey == uintptr(0)) {
		goto __670
	}
	goto no_mem
__670:
	;
	Xsqlite3VdbeRecordUnpack(tls, (*VdbeCursor)(unsafe.Pointer(pC9)).FpKeyInfo, (*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(bp+416)).FaMem)).Fn, (*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(bp+416)).FaMem)).Fz, pIdxKey)
	(*UnpackedRecord)(unsafe.Pointer(pIdxKey)).Fdefault_rc = int8(0)
	rc = Xsqlite3BtreeIndexMoveto(tls, *(*uintptr)(unsafe.Pointer(pC9 + 48)), pIdxKey, pC9+36)
	Xsqlite3DbFreeNN(tls, db, pIdxKey)
__668:
	;
	if !(rc != SQLITE_OK) {
		goto __671
	}
	goto abort_due_to_error
__671:
	;
	alreadyExists = libc.Bool32((*VdbeCursor)(unsafe.Pointer(pC9)).FseekResult == 0)
	(*VdbeCursor)(unsafe.Pointer(pC9)).FnullRow = U8(1 - alreadyExists)
	(*VdbeCursor)(unsafe.Pointer(pC9)).FdeferredMoveto = U8(0)
	(*VdbeCursor)(unsafe.Pointer(pC9)).FcacheStatus = U32(CACHE_STALE)
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_Found) {
		goto __672
	}

	if !(alreadyExists != 0) {
		goto __674
	}
	goto jump_to_p2
__674:
	;
	goto __673
__672:
	if !!(alreadyExists != 0) {
		goto __675
	}

	goto jump_to_p2
__675:
	;
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_NoConflict) {
		goto __676
	}

	ii1 = 0
__677:
	if !(ii1 < int32((*UnpackedRecord)(unsafe.Pointer(bp+416)).FnField)) {
		goto __679
	}
	if !(int32((*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(bp+416)).FaMem+uintptr(ii1)*56)).Fflags)&MEM_Null != 0) {
		goto __680
	}

	goto jump_to_p2
__680:
	;
	goto __678
__678:
	ii1++
	goto __677
	goto __679
__679:
	;
__676:
	;
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_IfNoHope) {
		goto __681
	}
	(*VdbeCursor)(unsafe.Pointer(pC9)).FseekHit = U16(*(*int32)(unsafe.Pointer(pOp + 16)))
__681:
	;
__673:
	;
	goto __11

__106:
	pIn3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	if !(int32((*Mem)(unsafe.Pointer(pIn3)).Fflags)&(MEM_Int|MEM_IntReal) == 0) {
		goto __682
	}

	*(*Mem)(unsafe.Pointer(bp + 456)) = *(*Mem)(unsafe.Pointer(pIn3))
	applyAffinity(tls, bp+456, uint8(SQLITE_AFF_NUMERIC), encoding)
	if !(int32((*Mem)(unsafe.Pointer(bp+456)).Fflags)&MEM_Int == 0) {
		goto __683
	}
	goto jump_to_p2
__683:
	;
	iKey1 = U64(*(*I64)(unsafe.Pointer(bp + 456)))
	goto notExistsWithKey
__682:
	;
__107:
	pIn3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	iKey1 = U64(*(*I64)(unsafe.Pointer(pIn3)))
notExistsWithKey:
	pC10 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pCrsr2 = *(*uintptr)(unsafe.Pointer(pC10 + 48))

	*(*int32)(unsafe.Pointer(bp + 512)) = 0
	rc = Xsqlite3BtreeTableMoveto(tls, pCrsr2, int64(iKey1), 0, bp+512)

	(*VdbeCursor)(unsafe.Pointer(pC10)).FmovetoTarget = I64(iKey1)
	(*VdbeCursor)(unsafe.Pointer(pC10)).FnullRow = U8(0)
	(*VdbeCursor)(unsafe.Pointer(pC10)).FcacheStatus = U32(CACHE_STALE)
	(*VdbeCursor)(unsafe.Pointer(pC10)).FdeferredMoveto = U8(0)

	(*VdbeCursor)(unsafe.Pointer(pC10)).FseekResult = *(*int32)(unsafe.Pointer(bp + 512))
	if !(*(*int32)(unsafe.Pointer(bp + 512)) != 0) {
		goto __684
	}

	if !((*Op)(unsafe.Pointer(pOp)).Fp2 == 0) {
		goto __685
	}
	rc = Xsqlite3CorruptError(tls, 95563)
	goto __686
__685:
	goto jump_to_p2
__686:
	;
__684:
	;
	if !(rc != 0) {
		goto __687
	}
	goto abort_due_to_error
__687:
	;
	goto __11

__108:
	;
	pOut = out2Prerelease(tls, p, pOp)
	*(*I64)(unsafe.Pointer(pOut)) = libc.PostIncInt64(&(*VdbeCursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8)))).FseqCount, 1)
	goto __11

__109:
	*(*I64)(unsafe.Pointer(bp + 520)) = int64(0)
	*(*int32)(unsafe.Pointer(bp + 516)) = 0
	pOut = out2Prerelease(tls, p, pOp)

	pC11 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !!(int32(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x2>>1) != 0) {
		goto __688
	}
	rc = Xsqlite3BtreeLast(tls, *(*uintptr)(unsafe.Pointer(pC11 + 48)), bp+516)
	if !(rc != SQLITE_OK) {
		goto __689
	}
	goto abort_due_to_error
__689:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 516)) != 0) {
		goto __690
	}
	*(*I64)(unsafe.Pointer(bp + 520)) = int64(1)
	goto __691
__690:
	;
	*(*I64)(unsafe.Pointer(bp + 520)) = Xsqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC11 + 48)))
	if !(*(*I64)(unsafe.Pointer(bp + 520)) >= int64(uint64(0x7fffffff)<<32|uint64(0xffffffff))) {
		goto __692
	}
	libc.SetBitFieldPtr8Uint32(pC11+8, Bool(1), 1, 0x2)
	goto __693
__692:
	*(*I64)(unsafe.Pointer(bp + 520))++
__693:
	;
__691:
	;
__688:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __694
	}

	if !((*Vdbe)(unsafe.Pointer(p)).FpFrame != 0) {
		goto __695
	}
	pFrame1 = (*Vdbe)(unsafe.Pointer(p)).FpFrame
__697:
	if !((*VdbeFrame)(unsafe.Pointer(pFrame1)).FpParent != 0) {
		goto __699
	}
	goto __698
__698:
	pFrame1 = (*VdbeFrame)(unsafe.Pointer(pFrame1)).FpParent
	goto __697
	goto __699
__699:
	;
	pMem = (*VdbeFrame)(unsafe.Pointer(pFrame1)).FaMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	goto __696
__695:
	;
	pMem = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

__696:
	;
	Xsqlite3VdbeMemIntegerify(tls, pMem)

	if !(*(*I64)(unsafe.Pointer(pMem)) == int64(uint64(0x7fffffff)<<32|uint64(0xffffffff)) || Bool(int32(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x2>>1)) != 0) {
		goto __700
	}
	rc = SQLITE_FULL
	goto abort_due_to_error
__700:
	;
	if !(*(*I64)(unsafe.Pointer(bp + 520)) < *(*I64)(unsafe.Pointer(pMem))+int64(1)) {
		goto __701
	}
	*(*I64)(unsafe.Pointer(bp + 520)) = *(*I64)(unsafe.Pointer(pMem)) + int64(1)
__701:
	;
	*(*I64)(unsafe.Pointer(pMem)) = *(*I64)(unsafe.Pointer(bp + 520))
__694:
	;
	if !(Bool(int32(*(*uint8)(unsafe.Pointer(pC11 + 8))&0x2>>1)) != 0) {
		goto __702
	}

	cnt1 = 0
__703:
	Xsqlite3_randomness(tls, int32(unsafe.Sizeof(I64(0))), bp+520)
	*(*I64)(unsafe.Pointer(bp + 520)) &= int64(uint64(0x7fffffff)<<32|uint64(0xffffffff)) >> 1
	*(*I64)(unsafe.Pointer(bp + 520))++
	goto __704
__704:
	if libc.AssignInt32(&rc, Xsqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(pC11 + 48)), int64(U64(*(*I64)(unsafe.Pointer(bp + 520)))),
		0, bp+516)) == SQLITE_OK &&
		*(*int32)(unsafe.Pointer(bp + 516)) == 0 &&
		libc.PreIncInt32(&cnt1, 1) < 100 {
		goto __703
	}
	goto __705
__705:
	;
	if !(rc != 0) {
		goto __706
	}
	goto abort_due_to_error
__706:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 516)) == 0) {
		goto __707
	}
	rc = SQLITE_FULL
	goto abort_due_to_error
__707:
	;
__702:
	;
	(*VdbeCursor)(unsafe.Pointer(pC11)).FdeferredMoveto = U8(0)
	(*VdbeCursor)(unsafe.Pointer(pC11)).FcacheStatus = U32(CACHE_STALE)

	*(*I64)(unsafe.Pointer(pOut)) = *(*I64)(unsafe.Pointer(bp + 520))
	goto __11

__110:
	pData = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56

	pC12 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pKey = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	(*BtreePayload)(unsafe.Pointer(bp + 528)).FnKey = *(*I64)(unsafe.Pointer(pKey))

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp4type) == -5 && ((*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 || (*Sqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0)) {
		goto __708
	}

	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*VdbeCursor)(unsafe.Pointer(pC12)).FiDb)*32)).FzDbSName
	pTab1 = *(*uintptr)(unsafe.Pointer(pOp + 16))

	goto __709
__708:
	pTab1 = uintptr(0)
	zDb = uintptr(0)
__709:
	;
	if !(pTab1 != 0) {
		goto __710
	}
	if !((*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 && !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_ISUPDATE != 0)) {
		goto __711
	}
	Xsqlite3VdbePreUpdateHook(tls, p, pC12, SQLITE_INSERT, zDb, pTab1, (*BtreePayload)(unsafe.Pointer(bp+528)).FnKey, (*Op)(unsafe.Pointer(pOp)).Fp2, -1)
__711:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FxUpdateCallback == uintptr(0) || (*Table)(unsafe.Pointer(pTab1)).FaCol == uintptr(0)) {
		goto __712
	}

	pTab1 = uintptr(0)
__712:
	;
__710:
	;
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_ISNOOP != 0) {
		goto __713
	}
	goto __11
__713:
	;
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_NCHANGE != 0) {
		goto __714
	}
	(*Vdbe)(unsafe.Pointer(p)).FnChange++
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_LASTROWID != 0) {
		goto __715
	}
	(*Sqlite3)(unsafe.Pointer(db)).FlastRowid = (*BtreePayload)(unsafe.Pointer(bp + 528)).FnKey
__715:
	;
__714:
	;
	(*BtreePayload)(unsafe.Pointer(bp + 528)).FpData = (*Mem)(unsafe.Pointer(pData)).Fz
	(*BtreePayload)(unsafe.Pointer(bp + 528)).FnData = (*Mem)(unsafe.Pointer(pData)).Fn
	seekResult = func() int32 {
		if int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_USESEEKRESULT != 0 {
			return (*VdbeCursor)(unsafe.Pointer(pC12)).FseekResult
		}
		return 0
	}()
	if !(int32((*Mem)(unsafe.Pointer(pData)).Fflags)&MEM_Zero != 0) {
		goto __716
	}
	(*BtreePayload)(unsafe.Pointer(bp + 528)).FnZero = *(*int32)(unsafe.Pointer(pData))
	goto __717
__716:
	(*BtreePayload)(unsafe.Pointer(bp + 528)).FnZero = 0
__717:
	;
	(*BtreePayload)(unsafe.Pointer(bp + 528)).FpKey = uintptr(0)

	rc = Xsqlite3BtreeInsert(tls, *(*uintptr)(unsafe.Pointer(pC12 + 48)), bp+528,
		int32((*Op)(unsafe.Pointer(pOp)).Fp5)&(OPFLAG_APPEND|OPFLAG_SAVEPOSITION|OPFLAG_PREFORMAT),
		seekResult)
	(*VdbeCursor)(unsafe.Pointer(pC12)).FdeferredMoveto = U8(0)
	(*VdbeCursor)(unsafe.Pointer(pC12)).FcacheStatus = U32(CACHE_STALE)

	if !(rc != 0) {
		goto __718
	}
	goto abort_due_to_error
__718:
	;
	if !(pTab1 != 0) {
		goto __719
	}

	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr, Sqlite_int64)
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxUpdateCallback})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpUpdateArg,
		func() int32 {
			if int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_ISUPDATE != 0 {
				return SQLITE_UPDATE
			}
			return SQLITE_INSERT
		}(),
		zDb, (*Table)(unsafe.Pointer(pTab1)).FzName, (*BtreePayload)(unsafe.Pointer(bp+528)).FnKey)
__719:
	;
	goto __11

__111:
	;
	pDest1 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	pSrc = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*8))
	if (*Op)(unsafe.Pointer(pOp)).Fp3 != 0 {
		iKey2 = *(*I64)(unsafe.Pointer(aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56))
	} else {
		iKey2 = int64(0)
	}
	rc = Xsqlite3BtreeTransferRow(tls, *(*uintptr)(unsafe.Pointer(pDest1 + 48)), *(*uintptr)(unsafe.Pointer(pSrc + 48)), iKey2)
	if !(rc != SQLITE_OK) {
		goto __720
	}
	goto abort_due_to_error
__720:
	;
	goto __11

__112:
	opflags = (*Op)(unsafe.Pointer(pOp)).Fp2

	pC13 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp4type) == -5 && ((*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 || (*Sqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0)) {
		goto __721
	}

	zDb1 = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*VdbeCursor)(unsafe.Pointer(pC13)).FiDb)*32)).FzDbSName
	pTab2 = *(*uintptr)(unsafe.Pointer(pOp + 16))
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_SAVEPOSITION != 0 && (*VdbeCursor)(unsafe.Pointer(pC13)).FisTable != 0) {
		goto __723
	}
	(*VdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget = Xsqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC13 + 48)))
__723:
	;
	goto __722
__721:
	zDb1 = uintptr(0)
	pTab2 = uintptr(0)
__722:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 && pTab2 != 0) {
		goto __724
	}

	Xsqlite3VdbePreUpdateHook(tls, p, pC13,
		func() int32 {
			if opflags&OPFLAG_ISUPDATE != 0 {
				return SQLITE_UPDATE
			}
			return SQLITE_DELETE
		}(),
		zDb1, pTab2, (*VdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget,
		(*Op)(unsafe.Pointer(pOp)).Fp3, -1)
__724:
	;
	if !(opflags&OPFLAG_ISNOOP != 0) {
		goto __725
	}
	goto __11
__725:
	;
	rc = Xsqlite3BtreeDelete(tls, *(*uintptr)(unsafe.Pointer(pC13 + 48)), uint8((*Op)(unsafe.Pointer(pOp)).Fp5))
	(*VdbeCursor)(unsafe.Pointer(pC13)).FcacheStatus = U32(CACHE_STALE)
	(*VdbeCursor)(unsafe.Pointer(pC13)).FseekResult = 0
	if !(rc != 0) {
		goto __726
	}
	goto abort_due_to_error
__726:
	;
	if !(opflags&OPFLAG_NCHANGE != 0) {
		goto __727
	}
	(*Vdbe)(unsafe.Pointer(p)).FnChange++
	if !((*Sqlite3)(unsafe.Pointer(db)).FxUpdateCallback != 0 && pTab2 != uintptr(0) && (*Table)(unsafe.Pointer(pTab2)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __728
	}
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr, Sqlite_int64)
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxUpdateCallback})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpUpdateArg, SQLITE_DELETE, zDb1, (*Table)(unsafe.Pointer(pTab2)).FzName,
		(*VdbeCursor)(unsafe.Pointer(pC13)).FmovetoTarget)

__728:
	;
__727:
	;
	goto __11

__113:
	Xsqlite3VdbeSetChanges(tls, db, (*Vdbe)(unsafe.Pointer(p)).FnChange)
	(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
	goto __11

__114:
	pC14 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pIn3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	nKeyCol = *(*int32)(unsafe.Pointer(pOp + 16))
	*(*int32)(unsafe.Pointer(bp + 576)) = 0
	rc = Xsqlite3VdbeSorterCompare(tls, pC14, pIn3, nKeyCol, bp+576)

	if !(rc != 0) {
		goto __729
	}
	goto abort_due_to_error
__729:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 576)) != 0) {
		goto __730
	}
	goto jump_to_p2
__730:
	;
	goto __11

__115:
	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	pC15 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	rc = Xsqlite3VdbeSorterRowkey(tls, pC15, pOut)

	if !(rc != 0) {
		goto __731
	}
	goto abort_due_to_error
__731:
	;
	(*VdbeCursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*8)))).FcacheStatus = U32(CACHE_STALE)
	goto __11

__116:
	pOut = out2Prerelease(tls, p, pOp)

	pC16 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pCrsr3 = *(*uintptr)(unsafe.Pointer(pC16 + 48))

	n3 = Xsqlite3BtreePayloadSize(tls, pCrsr3)
	if !(n3 > U32(*(*int32)(unsafe.Pointer(db + 136)))) {
		goto __732
	}
	goto too_big
__732:
	;
	rc = Xsqlite3VdbeMemFromBtreeZeroOffset(tls, pCrsr3, n3, pOut)
	if !(rc != 0) {
		goto __733
	}
	goto abort_due_to_error
__733:
	;
	if !!((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __734
	}
	if !(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&MEM_Ephem != 0 && Xsqlite3VdbeMemMakeWriteable(tls, pOut) != 0) {
		goto __735
	}
	goto no_mem
__735:
	;
__734:
	;
	updateMaxBlobsize(tls, pOut)

	goto __11

__117:
	pOut = out2Prerelease(tls, p, pOp)

	pC17 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !((*VdbeCursor)(unsafe.Pointer(pC17)).FnullRow != 0) {
		goto __736
	}
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Null)
	goto __11
	goto __737
__736:
	if !((*VdbeCursor)(unsafe.Pointer(pC17)).FdeferredMoveto != 0) {
		goto __738
	}
	*(*I64)(unsafe.Pointer(bp + 584)) = (*VdbeCursor)(unsafe.Pointer(pC17)).FmovetoTarget
	goto __739
__738:
	if !(int32((*VdbeCursor)(unsafe.Pointer(pC17)).FeCurType) == CURTYPE_VTAB) {
		goto __740
	}

	pVtab = (*Sqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pC17 + 48)))).FpVtab
	pModule = (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule

	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule)).FxRowid})).f(tls, *(*uintptr)(unsafe.Pointer(pC17 + 48)), bp+584)
	Xsqlite3VtabImportErrmsg(tls, p, pVtab)
	if !(rc != 0) {
		goto __742
	}
	goto abort_due_to_error
__742:
	;
	goto __741
__740:
	;
	rc = Xsqlite3VdbeCursorRestore(tls, pC17)
	if !(rc != 0) {
		goto __743
	}
	goto abort_due_to_error
__743:
	;
	if !((*VdbeCursor)(unsafe.Pointer(pC17)).FnullRow != 0) {
		goto __744
	}
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Null)
	goto __11
__744:
	;
	*(*I64)(unsafe.Pointer(bp + 584)) = Xsqlite3BtreeIntegerKey(tls, *(*uintptr)(unsafe.Pointer(pC17 + 48)))
__741:
	;
__739:
	;
__737:
	;
	*(*I64)(unsafe.Pointer(pOut)) = *(*I64)(unsafe.Pointer(bp + 584))
	goto __11

__118:
	;
	pC18 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	if !(pC18 == uintptr(0)) {
		goto __745
	}

	pC18 = allocateCursor(tls, p, (*Op)(unsafe.Pointer(pOp)).Fp1, 1, uint8(CURTYPE_PSEUDO))
	if !(pC18 == uintptr(0)) {
		goto __746
	}
	goto no_mem
__746:
	;
	(*VdbeCursor)(unsafe.Pointer(pC18)).FseekResult = 0
	(*VdbeCursor)(unsafe.Pointer(pC18)).FisTable = U8(1)
	libc.SetBitFieldPtr8Uint32(pC18+8, Bool(1), 3, 0x8)
	*(*uintptr)(unsafe.Pointer(pC18 + 48)) = Xsqlite3BtreeFakeValidCursor(tls)
__745:
	;
	(*VdbeCursor)(unsafe.Pointer(pC18)).FnullRow = U8(1)
	(*VdbeCursor)(unsafe.Pointer(pC18)).FcacheStatus = U32(CACHE_STALE)
	if !(int32((*VdbeCursor)(unsafe.Pointer(pC18)).FeCurType) == CURTYPE_BTREE) {
		goto __747
	}

	Xsqlite3BtreeClearCursor(tls, *(*uintptr)(unsafe.Pointer(pC18 + 48)))
__747:
	;
	goto __11

__119:
__120:
	;
	pC19 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pCrsr4 = *(*uintptr)(unsafe.Pointer(pC19 + 48))
	*(*int32)(unsafe.Pointer(bp + 592)) = 0

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_SeekEnd) {
		goto __748
	}

	(*VdbeCursor)(unsafe.Pointer(pC19)).FseekResult = -1
	if !(Xsqlite3BtreeCursorIsValidNN(tls, pCrsr4) != 0) {
		goto __749
	}
	goto __11
__749:
	;
__748:
	;
	rc = Xsqlite3BtreeLast(tls, pCrsr4, bp+592)
	(*VdbeCursor)(unsafe.Pointer(pC19)).FnullRow = U8(*(*int32)(unsafe.Pointer(bp + 592)))
	(*VdbeCursor)(unsafe.Pointer(pC19)).FdeferredMoveto = U8(0)
	(*VdbeCursor)(unsafe.Pointer(pC19)).FcacheStatus = U32(CACHE_STALE)
	if !(rc != 0) {
		goto __750
	}
	goto abort_due_to_error
__750:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 > 0) {
		goto __751
	}

	if !(*(*int32)(unsafe.Pointer(bp + 592)) != 0) {
		goto __752
	}
	goto jump_to_p2
__752:
	;
__751:
	;
	goto __11

__121:
	;
	pC20 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pCrsr5 = *(*uintptr)(unsafe.Pointer(pC20 + 48))

	rc = Xsqlite3BtreeFirst(tls, pCrsr5, bp+596)
	if !(rc != 0) {
		goto __753
	}
	goto abort_due_to_error
__753:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 596)) == 0) {
		goto __754
	}
	sz = Xsqlite3BtreeRowCountEst(tls, pCrsr5)
	if !(sz >= int64(0) && int32(Xsqlite3LogEst(tls, U64(sz))) < (*Op)(unsafe.Pointer(pOp)).Fp3) {
		goto __755
	}
	*(*int32)(unsafe.Pointer(bp + 596)) = 1
__755:
	;
__754:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 596)) != 0) {
		goto __756
	}
	goto jump_to_p2
__756:
	;
	goto __11

__122:
__123:
	atomic.AddInt32(&Xsqlite3_sort_count, 1)
	atomic.AddInt32(&Xsqlite3_search_count, -1)
	*(*U32)(unsafe.Pointer(p + 212 + 2*4))++

__124:
	;
	pC21 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	*(*int32)(unsafe.Pointer(bp + 600)) = 1
	if !(int32((*VdbeCursor)(unsafe.Pointer(pC21)).FeCurType) == CURTYPE_SORTER) {
		goto __757
	}
	rc = Xsqlite3VdbeSorterRewind(tls, pC21, bp+600)
	goto __758
__757:
	;
	pCrsr6 = *(*uintptr)(unsafe.Pointer(pC21 + 48))

	rc = Xsqlite3BtreeFirst(tls, pCrsr6, bp+600)
	(*VdbeCursor)(unsafe.Pointer(pC21)).FdeferredMoveto = U8(0)
	(*VdbeCursor)(unsafe.Pointer(pC21)).FcacheStatus = U32(CACHE_STALE)
__758:
	;
	if !(rc != 0) {
		goto __759
	}
	goto abort_due_to_error
__759:
	;
	(*VdbeCursor)(unsafe.Pointer(pC21)).FnullRow = U8(*(*int32)(unsafe.Pointer(bp + 600)))
	if !((*Op)(unsafe.Pointer(pOp)).Fp2 > 0) {
		goto __760
	}

	if !(*(*int32)(unsafe.Pointer(bp + 600)) != 0) {
		goto __761
	}
	goto jump_to_p2
__761:
	;
__760:
	;
	goto __11

__125:
	pC22 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	rc = Xsqlite3VdbeSorterNext(tls, db, pC22)
	goto next_tail

__126:
	;
	pC22 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	rc = Xsqlite3BtreePrevious(tls, *(*uintptr)(unsafe.Pointer(pC22 + 48)), (*Op)(unsafe.Pointer(pOp)).Fp3)
	goto next_tail

__127:
	;
	pC22 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	rc = Xsqlite3BtreeNext(tls, *(*uintptr)(unsafe.Pointer(pC22 + 48)), (*Op)(unsafe.Pointer(pOp)).Fp3)

next_tail:
	(*VdbeCursor)(unsafe.Pointer(pC22)).FcacheStatus = U32(CACHE_STALE)

	if !(rc == SQLITE_OK) {
		goto __762
	}
	(*VdbeCursor)(unsafe.Pointer(pC22)).FnullRow = U8(0)
	*(*U32)(unsafe.Pointer(p + 212 + uintptr((*Op)(unsafe.Pointer(pOp)).Fp5)*4))++
	atomic.AddInt32(&Xsqlite3_search_count, 1)
	goto jump_to_p2_and_check_for_interrupt
__762:
	;
	if !(rc != SQLITE_DONE) {
		goto __763
	}
	goto abort_due_to_error
__763:
	;
	rc = SQLITE_OK
	(*VdbeCursor)(unsafe.Pointer(pC22)).FnullRow = U8(1)
	goto check_for_interrupt

__128:
	;
	pC23 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pIn2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_NCHANGE != 0) {
		goto __764
	}
	(*Vdbe)(unsafe.Pointer(p)).FnChange++
__764:
	;
	rc = func() int32 {
		if int32((*Mem)(unsafe.Pointer(pIn2)).Fflags)&MEM_Zero != 0 {
			return Xsqlite3VdbeMemExpandBlob(tls, pIn2)
		}
		return 0
	}()
	if !(rc != 0) {
		goto __765
	}
	goto abort_due_to_error
__765:
	;
	(*BtreePayload)(unsafe.Pointer(bp + 608)).FnKey = Sqlite3_int64((*Mem)(unsafe.Pointer(pIn2)).Fn)
	(*BtreePayload)(unsafe.Pointer(bp + 608)).FpKey = (*Mem)(unsafe.Pointer(pIn2)).Fz
	(*BtreePayload)(unsafe.Pointer(bp + 608)).FaMem = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	(*BtreePayload)(unsafe.Pointer(bp + 608)).FnMem = U16(*(*int32)(unsafe.Pointer(pOp + 16)))
	rc = Xsqlite3BtreeInsert(tls, *(*uintptr)(unsafe.Pointer(pC23 + 48)), bp+608,
		int32((*Op)(unsafe.Pointer(pOp)).Fp5)&(OPFLAG_APPEND|OPFLAG_SAVEPOSITION|OPFLAG_PREFORMAT),
		func() int32 {
			if int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_USESEEKRESULT != 0 {
				return (*VdbeCursor)(unsafe.Pointer(pC23)).FseekResult
			}
			return 0
		}())

	(*VdbeCursor)(unsafe.Pointer(pC23)).FcacheStatus = U32(CACHE_STALE)
	if !(rc != 0) {
		goto __766
	}
	goto abort_due_to_error
__766:
	;
	goto __11

__129:
	;
	pC24 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pIn2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56

	rc = func() int32 {
		if int32((*Mem)(unsafe.Pointer(pIn2)).Fflags)&MEM_Zero != 0 {
			return Xsqlite3VdbeMemExpandBlob(tls, pIn2)
		}
		return 0
	}()
	if !(rc != 0) {
		goto __767
	}
	goto abort_due_to_error
__767:
	;
	rc = Xsqlite3VdbeSorterWrite(tls, pC24, pIn2)
	if !(rc != 0) {
		goto __768
	}
	goto abort_due_to_error
__768:
	;
	goto __11

__130:
	;
	pC25 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pCrsr7 = *(*uintptr)(unsafe.Pointer(pC25 + 48))

	(*UnpackedRecord)(unsafe.Pointer(bp + 656)).FpKeyInfo = (*VdbeCursor)(unsafe.Pointer(pC25)).FpKeyInfo
	(*UnpackedRecord)(unsafe.Pointer(bp + 656)).FnField = U16((*Op)(unsafe.Pointer(pOp)).Fp3)
	(*UnpackedRecord)(unsafe.Pointer(bp + 656)).Fdefault_rc = int8(0)
	(*UnpackedRecord)(unsafe.Pointer(bp + 656)).FaMem = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	rc = Xsqlite3BtreeIndexMoveto(tls, pCrsr7, bp+656, bp+696)
	if !(rc != 0) {
		goto __769
	}
	goto abort_due_to_error
__769:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 696)) == 0) {
		goto __770
	}
	rc = Xsqlite3BtreeDelete(tls, pCrsr7, uint8(BTREE_AUXDELETE))
	if !(rc != 0) {
		goto __772
	}
	goto abort_due_to_error
__772:
	;
	goto __771
__770:
	if !((*Op)(unsafe.Pointer(pOp)).Fp5 != 0 && !(Xsqlite3WritableSchema(tls, db) != 0)) {
		goto __773
	}
	rc = Xsqlite3ReportError(tls, SQLITE_CORRUPT|int32(3)<<8, 96638, ts+8791)
	goto abort_due_to_error
__773:
	;
__771:
	;
	(*VdbeCursor)(unsafe.Pointer(pC25)).FcacheStatus = U32(CACHE_STALE)
	(*VdbeCursor)(unsafe.Pointer(pC25)).FseekResult = 0
	goto __11

__131:
__132:
	;
	pC26 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	rc = Xsqlite3VdbeCursorRestore(tls, pC26)

	if !(rc != SQLITE_OK) {
		goto __774
	}
	goto abort_due_to_error
__774:
	;
	if !!(int32((*VdbeCursor)(unsafe.Pointer(pC26)).FnullRow) != 0) {
		goto __775
	}
	*(*I64)(unsafe.Pointer(bp + 704)) = int64(0)
	rc = Xsqlite3VdbeIdxRowid(tls, db, *(*uintptr)(unsafe.Pointer(pC26 + 48)), bp+704)
	if !(rc != SQLITE_OK) {
		goto __777
	}
	goto abort_due_to_error
__777:
	;
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_DeferredSeek) {
		goto __778
	}

	pTabCur = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*8))

	(*VdbeCursor)(unsafe.Pointer(pTabCur)).FnullRow = U8(0)
	(*VdbeCursor)(unsafe.Pointer(pTabCur)).FmovetoTarget = *(*I64)(unsafe.Pointer(bp + 704))
	(*VdbeCursor)(unsafe.Pointer(pTabCur)).FdeferredMoveto = U8(1)
	(*VdbeCursor)(unsafe.Pointer(pTabCur)).FcacheStatus = U32(CACHE_STALE)

	*(*uintptr)(unsafe.Pointer(pTabCur + 16)) = *(*uintptr)(unsafe.Pointer(pOp + 16))

	(*VdbeCursor)(unsafe.Pointer(pTabCur)).FpAltCursor = pC26
	goto __779
__778:
	pOut = out2Prerelease(tls, p, pOp)
	*(*I64)(unsafe.Pointer(pOut)) = *(*I64)(unsafe.Pointer(bp + 704))
__779:
	;
	goto __776
__775:
	;
	Xsqlite3VdbeMemSetNull(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56)
__776:
	;
	goto __11

__133:
	;
	pC27 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	if !((*VdbeCursor)(unsafe.Pointer(pC27)).FdeferredMoveto != 0) {
		goto __780
	}
	rc = Xsqlite3VdbeFinishMoveto(tls, pC27)
	if !(rc != 0) {
		goto __781
	}
	goto abort_due_to_error
__781:
	;
__780:
	;
	goto __11

__134:
__135:
__136:
__137:
	;
	pC28 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	(*UnpackedRecord)(unsafe.Pointer(bp + 768)).FpKeyInfo = (*VdbeCursor)(unsafe.Pointer(pC28)).FpKeyInfo
	(*UnpackedRecord)(unsafe.Pointer(bp + 768)).FnField = U16(*(*int32)(unsafe.Pointer(pOp + 16)))
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) < OP_IdxLT) {
		goto __782
	}

	(*UnpackedRecord)(unsafe.Pointer(bp + 768)).Fdefault_rc = int8(-1)
	goto __783
__782:
	;
	(*UnpackedRecord)(unsafe.Pointer(bp + 768)).Fdefault_rc = int8(0)
__783:
	;
	(*UnpackedRecord)(unsafe.Pointer(bp + 768)).FaMem = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	nCellKey = int64(0)

	pCur2 = *(*uintptr)(unsafe.Pointer(pC28 + 48))

	nCellKey = I64(Xsqlite3BtreePayloadSize(tls, pCur2))

	if !(nCellKey <= int64(0) || nCellKey > int64(0x7fffffff)) {
		goto __784
	}
	rc = Xsqlite3CorruptError(tls, 96843)
	goto abort_due_to_error
__784:
	;
	Xsqlite3VdbeMemInit(tls, bp+712, db, uint16(0))
	rc = Xsqlite3VdbeMemFromBtreeZeroOffset(tls, pCur2, U32(nCellKey), bp+712)
	if !(rc != 0) {
		goto __785
	}
	goto abort_due_to_error
__785:
	;
	res11 = Xsqlite3VdbeRecordCompareWithSkip(tls, (*Mem)(unsafe.Pointer(bp+712)).Fn, (*Mem)(unsafe.Pointer(bp+712)).Fz, bp+768, 0)
	Xsqlite3VdbeMemReleaseMalloc(tls, bp+712)

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode)&1 == OP_IdxLT&1) {
		goto __786
	}

	res11 = -res11
	goto __787
__786:
	;
	res11++
__787:
	;
	if !(res11 > 0) {
		goto __788
	}
	goto jump_to_p2
__788:
	;
	goto __11

__138:
	;
	pOut = out2Prerelease(tls, p, pOp)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Null)
	if !((*Sqlite3)(unsafe.Pointer(db)).FnVdbeRead > (*Sqlite3)(unsafe.Pointer(db)).FnVDestroy+1) {
		goto __789
	}
	rc = SQLITE_LOCKED
	(*Vdbe)(unsafe.Pointer(p)).FerrorAction = U8(OE_Abort)
	goto abort_due_to_error
	goto __790
__789:
	iDb2 = (*Op)(unsafe.Pointer(pOp)).Fp3

	*(*int32)(unsafe.Pointer(bp + 808)) = 0
	rc = Xsqlite3BtreeDropTable(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb2)*32)).FpBt, (*Op)(unsafe.Pointer(pOp)).Fp1, bp+808)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Int)
	*(*I64)(unsafe.Pointer(pOut)) = I64(*(*int32)(unsafe.Pointer(bp + 808)))
	if !(rc != 0) {
		goto __791
	}
	goto abort_due_to_error
__791:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 808)) != 0) {
		goto __792
	}
	Xsqlite3RootPageMoved(tls, db, iDb2, uint32(*(*int32)(unsafe.Pointer(bp + 808))), uint32((*Op)(unsafe.Pointer(pOp)).Fp1))

	resetSchemaOnFault = U8(iDb2 + 1)
__792:
	;
__790:
	;
	goto __11

__139:
	;
	*(*I64)(unsafe.Pointer(bp + 816)) = int64(0)

	rc = Xsqlite3BtreeClearTable(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*32)).FpBt, int32(U32((*Op)(unsafe.Pointer(pOp)).Fp1)), bp+816)
	if !((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __793
	}
	*(*I64)(unsafe.Pointer(p + 56)) += *(*I64)(unsafe.Pointer(bp + 816))
	if !((*Op)(unsafe.Pointer(pOp)).Fp3 > 0) {
		goto __794
	}

	*(*I64)(unsafe.Pointer(aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56)) += *(*I64)(unsafe.Pointer(bp + 816))
__794:
	;
__793:
	;
	if !(rc != 0) {
		goto __795
	}
	goto abort_due_to_error
__795:
	;
	goto __11

__140:
	;
	pC29 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !(int32((*VdbeCursor)(unsafe.Pointer(pC29)).FeCurType) == CURTYPE_SORTER) {
		goto __796
	}
	Xsqlite3VdbeSorterReset(tls, db, *(*uintptr)(unsafe.Pointer(pC29 + 48)))
	goto __797
__796:
	;
	rc = Xsqlite3BtreeClearTableOfCursor(tls, *(*uintptr)(unsafe.Pointer(pC29 + 48)))
	if !(rc != 0) {
		goto __798
	}
	goto abort_due_to_error
__798:
	;
__797:
	;
	goto __11

__141:
	;
	pOut = out2Prerelease(tls, p, pOp)
	*(*Pgno)(unsafe.Pointer(bp + 824)) = Pgno(0)

	pDb3 = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*32

	rc = Xsqlite3BtreeCreateTable(tls, (*Db)(unsafe.Pointer(pDb3)).FpBt, bp+824, (*Op)(unsafe.Pointer(pOp)).Fp3)
	if !(rc != 0) {
		goto __799
	}
	goto abort_due_to_error
__799:
	;
	*(*I64)(unsafe.Pointer(pOut)) = I64(*(*Pgno)(unsafe.Pointer(bp + 824)))
	goto __11

__142:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FnSqlExec++
	rc = Xsqlite3_exec(tls, db, *(*uintptr)(unsafe.Pointer(pOp + 16)), uintptr(0), uintptr(0), uintptr(0))
	(*Sqlite3)(unsafe.Pointer(db)).FnSqlExec--
	if !(rc != 0) {
		goto __800
	}
	goto abort_due_to_error
__800:
	;
	goto __11

__143:
	iDb3 = (*Op)(unsafe.Pointer(pOp)).Fp1

	if !(*(*uintptr)(unsafe.Pointer(pOp + 16)) == uintptr(0)) {
		goto __801
	}
	Xsqlite3SchemaClear(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb3)*32)).FpSchema)
	*(*U32)(unsafe.Pointer(db + 44)) &= libc.Uint32FromInt32(libc.CplInt32(DBFLAG_SchemaKnownOk))
	rc = Xsqlite3InitOne(tls, db, iDb3, p+168, uint32((*Op)(unsafe.Pointer(pOp)).Fp5))
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaChange)
	libc.SetBitFieldPtr8Uint32(p+200, Bft(0), 0, 0x3)
	goto __802
__801:
	zSchema = ts + 8808
	(*InitData)(unsafe.Pointer(bp + 832)).Fdb = db
	(*InitData)(unsafe.Pointer(bp + 832)).FiDb = iDb3
	(*InitData)(unsafe.Pointer(bp + 832)).FpzErrMsg = p + 168
	(*InitData)(unsafe.Pointer(bp + 832)).FmInitFlags = U32(0)
	(*InitData)(unsafe.Pointer(bp + 832)).FmxPage = Xsqlite3BtreeLastPage(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb3)*32)).FpBt)
	zSql = Xsqlite3MPrintf(tls, db,
		ts+8822,
		libc.VaList(bp+96, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb3)*32)).FzDbSName, zSchema, *(*uintptr)(unsafe.Pointer(pOp + 16))))
	if !(zSql == uintptr(0)) {
		goto __803
	}
	rc = SQLITE_NOMEM
	goto __804
__803:
	;
	(*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy = U8(1)
	(*InitData)(unsafe.Pointer(bp + 832)).Frc = SQLITE_OK
	(*InitData)(unsafe.Pointer(bp + 832)).FnInitRow = U32(0)

	rc = Xsqlite3_exec(tls, db, zSql, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
	}{Xsqlite3InitCallback})), bp+832, uintptr(0))
	if !(rc == SQLITE_OK) {
		goto __805
	}
	rc = (*InitData)(unsafe.Pointer(bp + 832)).Frc
__805:
	;
	if !(rc == SQLITE_OK && (*InitData)(unsafe.Pointer(bp+832)).FnInitRow == U32(0)) {
		goto __806
	}

	rc = Xsqlite3CorruptError(tls, 97095)
__806:
	;
	Xsqlite3DbFreeNN(tls, db, zSql)
	(*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy = U8(0)
__804:
	;
__802:
	;
	if !(rc != 0) {
		goto __807
	}
	Xsqlite3ResetAllSchemasOfConnection(tls, db)
	if !(rc == SQLITE_NOMEM) {
		goto __808
	}
	goto no_mem
__808:
	;
	goto abort_due_to_error
__807:
	;
	goto __11

__144:
	;
	rc = Xsqlite3AnalysisLoad(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1)
	if !(rc != 0) {
		goto __809
	}
	goto abort_due_to_error
__809:
	;
	goto __11

__145:
	;
	Xsqlite3UnlinkAndDeleteTable(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
	goto __11

__146:
	;
	Xsqlite3UnlinkAndDeleteIndex(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
	goto __11

__147:
	;
	Xsqlite3UnlinkAndDeleteTrigger(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
	goto __11

__148:
	;
	nRoot = (*Op)(unsafe.Pointer(pOp)).Fp2
	aRoot = *(*uintptr)(unsafe.Pointer(pOp + 16))

	pnErr = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	rc = Xsqlite3BtreeIntegrityCheck(tls, db, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr((*Op)(unsafe.Pointer(pOp)).Fp5)*32)).FpBt, aRoot+1*4, nRoot,
		int32(*(*I64)(unsafe.Pointer(pnErr)))+1, bp+872, bp+880)
	Xsqlite3VdbeMemSetNull(tls, pIn1)
	if !(*(*int32)(unsafe.Pointer(bp + 872)) == 0) {
		goto __810
	}

	goto __811
__810:
	if !(rc != 0) {
		goto __812
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 880)))
	goto abort_due_to_error
	goto __813
__812:
	*(*I64)(unsafe.Pointer(pnErr)) -= I64(*(*int32)(unsafe.Pointer(bp + 872)) - 1)
	Xsqlite3VdbeMemSetStr(tls, pIn1, *(*uintptr)(unsafe.Pointer(bp + 880)), int64(-1), uint8(SQLITE_UTF8), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
__813:
	;
__811:
	;
	updateMaxBlobsize(tls, pIn1)
	Xsqlite3VdbeChangeEncoding(tls, pIn1, int32(encoding))
	goto check_for_interrupt

__149:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pIn2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56

	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Blob == 0) {
		goto __814
	}
	if !(Xsqlite3VdbeMemSetRowSet(tls, pIn1) != 0) {
		goto __815
	}
	goto no_mem
__815:
	;
__814:
	;
	Xsqlite3RowSetInsert(tls, (*Mem)(unsafe.Pointer(pIn1)).Fz, *(*I64)(unsafe.Pointer(pIn2)))
	goto __11

__150:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Blob == 0 ||
		Xsqlite3RowSetNext(tls, (*Mem)(unsafe.Pointer(pIn1)).Fz, bp+888) == 0) {
		goto __816
	}

	Xsqlite3VdbeMemSetNull(tls, pIn1)

	goto jump_to_p2_and_check_for_interrupt
	goto __817
__816:
	;
	Xsqlite3VdbeMemSetInt64(tls, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56, *(*I64)(unsafe.Pointer(bp + 888)))
__817:
	;
	goto check_for_interrupt

__151:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pIn3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	iSet = *(*int32)(unsafe.Pointer(pOp + 16))

	if !(int32((*Mem)(unsafe.Pointer(pIn1)).Fflags)&MEM_Blob == 0) {
		goto __818
	}
	if !(Xsqlite3VdbeMemSetRowSet(tls, pIn1) != 0) {
		goto __819
	}
	goto no_mem
__819:
	;
__818:
	;
	if !(iSet != 0) {
		goto __820
	}
	exists = Xsqlite3RowSetTest(tls, (*Mem)(unsafe.Pointer(pIn1)).Fz, iSet, *(*I64)(unsafe.Pointer(pIn3)))

	if !(exists != 0) {
		goto __821
	}
	goto jump_to_p2
__821:
	;
__820:
	;
	if !(iSet >= 0) {
		goto __822
	}
	Xsqlite3RowSetInsert(tls, (*Mem)(unsafe.Pointer(pIn1)).Fz, *(*I64)(unsafe.Pointer(pIn3)))
__822:
	;
	goto __11

__152:
	pProgram = *(*uintptr)(unsafe.Pointer(pOp + 16))
	pRt = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	if !((*Op)(unsafe.Pointer(pOp)).Fp5 != 0) {
		goto __823
	}
	t1 = (*SubProgram)(unsafe.Pointer(pProgram)).Ftoken
	pFrame2 = (*Vdbe)(unsafe.Pointer(p)).FpFrame
__824:
	if !(pFrame2 != 0 && (*VdbeFrame)(unsafe.Pointer(pFrame2)).Ftoken != t1) {
		goto __826
	}
	goto __825
__825:
	pFrame2 = (*VdbeFrame)(unsafe.Pointer(pFrame2)).FpParent
	goto __824
	goto __826
__826:
	;
	if !(pFrame2 != 0) {
		goto __827
	}
	goto __11
__827:
	;
__823:
	;
	if !((*Vdbe)(unsafe.Pointer(p)).FnFrame >= *(*int32)(unsafe.Pointer(db + 136 + 10*4))) {
		goto __828
	}
	rc = SQLITE_ERROR
	Xsqlite3VdbeError(tls, p, ts+8865, 0)
	goto abort_due_to_error
__828:
	;
	if !(int32((*Mem)(unsafe.Pointer(pRt)).Fflags)&MEM_Blob == 0) {
		goto __829
	}

	nMem = (*SubProgram)(unsafe.Pointer(pProgram)).FnMem + (*SubProgram)(unsafe.Pointer(pProgram)).FnCsr

	if !((*SubProgram)(unsafe.Pointer(pProgram)).FnCsr == 0) {
		goto __831
	}
	nMem++
__831:
	;
	nByte2 = int32((uint64(unsafe.Sizeof(VdbeFrame{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7)) +
		uint64(nMem)*uint64(unsafe.Sizeof(Mem{})) +
		uint64((*SubProgram)(unsafe.Pointer(pProgram)).FnCsr)*uint64(unsafe.Sizeof(uintptr(0))) +
		uint64(((*SubProgram)(unsafe.Pointer(pProgram)).FnOp+7)/8))
	pFrame2 = Xsqlite3DbMallocZero(tls, db, uint64(nByte2))
	if !!(pFrame2 != 0) {
		goto __832
	}
	goto no_mem
__832:
	;
	Xsqlite3VdbeMemRelease(tls, pRt)
	(*Mem)(unsafe.Pointer(pRt)).Fflags = U16(MEM_Blob | MEM_Dyn)
	(*Mem)(unsafe.Pointer(pRt)).Fz = pFrame2
	(*Mem)(unsafe.Pointer(pRt)).Fn = nByte2
	(*Mem)(unsafe.Pointer(pRt)).FxDel = *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3VdbeFrameMemDel}))

	(*VdbeFrame)(unsafe.Pointer(pFrame2)).Fv = p
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem = nMem
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FnChildCsr = (*SubProgram)(unsafe.Pointer(pProgram)).FnCsr
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).Fpc = int32((int64(pOp) - int64(aOp)) / 32)
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FaMem = (*Vdbe)(unsafe.Pointer(p)).FaMem
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FnMem = (*Vdbe)(unsafe.Pointer(p)).FnMem
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FapCsr = (*Vdbe)(unsafe.Pointer(p)).FapCsr
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FnCursor = (*Vdbe)(unsafe.Pointer(p)).FnCursor
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FaOp = (*Vdbe)(unsafe.Pointer(p)).FaOp
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FnOp = (*Vdbe)(unsafe.Pointer(p)).FnOp
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).Ftoken = (*SubProgram)(unsafe.Pointer(pProgram)).Ftoken

	pEnd = pFrame2 + 112 + uintptr((*VdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem)*56
	pMem1 = pFrame2 + 112
__833:
	if !(pMem1 != pEnd) {
		goto __835
	}
	(*Mem)(unsafe.Pointer(pMem1)).Fflags = U16(MEM_Undefined)
	(*Mem)(unsafe.Pointer(pMem1)).Fdb = db
	goto __834
__834:
	pMem1 += 56
	goto __833
	goto __835
__835:
	;
	goto __830
__829:
	pFrame2 = (*Mem)(unsafe.Pointer(pRt)).Fz

__830:
	;
	(*Vdbe)(unsafe.Pointer(p)).FnFrame++
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FpParent = (*Vdbe)(unsafe.Pointer(p)).FpFrame
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FlastRowid = (*Sqlite3)(unsafe.Pointer(db)).FlastRowid
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FnChange = (*Vdbe)(unsafe.Pointer(p)).FnChange
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FnDbChange = (*Sqlite3)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).Fdb)).FnChange

	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FpAuxData = (*Vdbe)(unsafe.Pointer(p)).FpAuxData
	(*Vdbe)(unsafe.Pointer(p)).FpAuxData = uintptr(0)
	(*Vdbe)(unsafe.Pointer(p)).FnChange = int64(0)
	(*Vdbe)(unsafe.Pointer(p)).FpFrame = pFrame2
	(*Vdbe)(unsafe.Pointer(p)).FaMem = libc.AssignUintptr(&aMem, pFrame2+112)
	(*Vdbe)(unsafe.Pointer(p)).FnMem = (*VdbeFrame)(unsafe.Pointer(pFrame2)).FnChildMem
	(*Vdbe)(unsafe.Pointer(p)).FnCursor = int32(U16((*VdbeFrame)(unsafe.Pointer(pFrame2)).FnChildCsr))
	(*Vdbe)(unsafe.Pointer(p)).FapCsr = aMem + uintptr((*Vdbe)(unsafe.Pointer(p)).FnMem)*56
	(*VdbeFrame)(unsafe.Pointer(pFrame2)).FaOnce = (*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*SubProgram)(unsafe.Pointer(pProgram)).FnCsr)*8
	libc.Xmemset(tls, (*VdbeFrame)(unsafe.Pointer(pFrame2)).FaOnce, 0, uint64(((*SubProgram)(unsafe.Pointer(pProgram)).FnOp+7)/8))
	(*Vdbe)(unsafe.Pointer(p)).FaOp = libc.AssignUintptr(&aOp, (*SubProgram)(unsafe.Pointer(pProgram)).FaOp)
	(*Vdbe)(unsafe.Pointer(p)).FnOp = (*SubProgram)(unsafe.Pointer(pProgram)).FnOp
	pOp = aOp + libc.UintptrFromInt32(-1)*32
	goto check_for_interrupt

__153:
	pOut = out2Prerelease(tls, p, pOp)
	pFrame3 = (*Vdbe)(unsafe.Pointer(p)).FpFrame
	pIn = (*VdbeFrame)(unsafe.Pointer(pFrame3)).FaMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1+(*Op)(unsafe.Pointer((*VdbeFrame)(unsafe.Pointer(pFrame3)).FaOp+uintptr((*VdbeFrame)(unsafe.Pointer(pFrame3)).Fpc)*32)).Fp1)*56
	Xsqlite3VdbeMemShallowCopy(tls, pOut, pIn, MEM_Ephem)
	goto __11

__154:
	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0) {
		goto __836
	}
	*(*I64)(unsafe.Pointer(db + 792)) += I64((*Op)(unsafe.Pointer(pOp)).Fp2)
	goto __837
__836:
	if !((*Op)(unsafe.Pointer(pOp)).Fp1 != 0) {
		goto __838
	}
	*(*I64)(unsafe.Pointer(db + 784)) += I64((*Op)(unsafe.Pointer(pOp)).Fp2)
	goto __839
__838:
	*(*I64)(unsafe.Pointer(p + 80)) += I64((*Op)(unsafe.Pointer(pOp)).Fp2)
__839:
	;
__837:
	;
	goto __11

__155:
	if !((*Op)(unsafe.Pointer(pOp)).Fp1 != 0) {
		goto __840
	}

	if !((*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons == int64(0) && (*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons == int64(0)) {
		goto __842
	}
	goto jump_to_p2
__842:
	;
	goto __841
__840:
	;
	if !((*Vdbe)(unsafe.Pointer(p)).FnFkConstraint == int64(0) && (*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons == int64(0)) {
		goto __843
	}
	goto jump_to_p2
__843:
	;
__841:
	;
	goto __11

__156:
	if !((*Vdbe)(unsafe.Pointer(p)).FpFrame != 0) {
		goto __844
	}
	pFrame4 = (*Vdbe)(unsafe.Pointer(p)).FpFrame
__846:
	if !((*VdbeFrame)(unsafe.Pointer(pFrame4)).FpParent != 0) {
		goto __848
	}
	goto __847
__847:
	pFrame4 = (*VdbeFrame)(unsafe.Pointer(pFrame4)).FpParent
	goto __846
	goto __848
__848:
	;
	pIn1 = (*VdbeFrame)(unsafe.Pointer(pFrame4)).FaMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	goto __845
__844:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
__845:
	;
	Xsqlite3VdbeMemIntegerify(tls, pIn1)
	pIn2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
	Xsqlite3VdbeMemIntegerify(tls, pIn2)
	if !(*(*I64)(unsafe.Pointer(pIn1)) < *(*I64)(unsafe.Pointer(pIn2))) {
		goto __849
	}
	*(*I64)(unsafe.Pointer(pIn1)) = *(*I64)(unsafe.Pointer(pIn2))
__849:
	;
	goto __11

__157:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	if !(*(*I64)(unsafe.Pointer(pIn1)) > int64(0)) {
		goto __850
	}
	*(*I64)(unsafe.Pointer(pIn1)) -= I64((*Op)(unsafe.Pointer(pOp)).Fp3)
	goto jump_to_p2
__850:
	;
	goto __11

__158:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	pIn3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	pOut = out2Prerelease(tls, p, pOp)

	*(*I64)(unsafe.Pointer(bp + 896)) = *(*I64)(unsafe.Pointer(pIn1))
	if !(*(*I64)(unsafe.Pointer(bp + 896)) <= int64(0) || Xsqlite3AddInt64(tls, bp+896, func() int64 {
		if *(*I64)(unsafe.Pointer(pIn3)) > int64(0) {
			return *(*I64)(unsafe.Pointer(pIn3))
		}
		return int64(0)
	}()) != 0) {
		goto __851
	}

	*(*I64)(unsafe.Pointer(pOut)) = int64(-1)
	goto __852
__851:
	*(*I64)(unsafe.Pointer(pOut)) = *(*I64)(unsafe.Pointer(bp + 896))
__852:
	;
	goto __11

__159:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	if !(*(*I64)(unsafe.Pointer(pIn1)) != 0) {
		goto __853
	}
	if !(*(*I64)(unsafe.Pointer(pIn1)) > int64(0)) {
		goto __854
	}
	*(*I64)(unsafe.Pointer(pIn1))--
__854:
	;
	goto jump_to_p2
__853:
	;
	goto __11

__160:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	if !(*(*I64)(unsafe.Pointer(pIn1)) > int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32)) {
		goto __855
	}
	*(*I64)(unsafe.Pointer(pIn1))--
__855:
	;
	if !(*(*I64)(unsafe.Pointer(pIn1)) == int64(0)) {
		goto __856
	}
	goto jump_to_p2
__856:
	;
	goto __11

__161:
__162:
	;
	n4 = int32((*Op)(unsafe.Pointer(pOp)).Fp5)

	pCtx = Xsqlite3DbMallocRawNN(tls, db, uint64(n4)*uint64(unsafe.Sizeof(uintptr(0)))+(uint64(unsafe.Sizeof(Sqlite3_context{}))+uint64(unsafe.Sizeof(Mem{}))-uint64(unsafe.Sizeof(uintptr(0)))))
	if !(pCtx == uintptr(0)) {
		goto __857
	}
	goto no_mem
__857:
	;
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FpMem = uintptr(0)
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut = pCtx + 48 + uintptr(n4)*8
	Xsqlite3VdbeMemInit(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx)).FpOut, db, uint16(MEM_Null))
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FpFunc = *(*uintptr)(unsafe.Pointer(pOp + 16))
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FiOp = int32((int64(pOp) - int64(aOp)) / 32)
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe = p
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FskipFlag = U8(0)
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).FisError = 0
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).Fenc = encoding
	(*Sqlite3_context)(unsafe.Pointer(pCtx)).Fargc = U8(n4)
	(*Op)(unsafe.Pointer(pOp)).Fp4type = int8(-15)
	*(*uintptr)(unsafe.Pointer(pOp + 16)) = pCtx

	(*Op)(unsafe.Pointer(pOp)).Fopcode = U8(OP_AggStep1)

__163:
	;
	pCtx1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
	pMem2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	if !((*Sqlite3_context)(unsafe.Pointer(pCtx1)).FpMem != pMem2) {
		goto __858
	}
	(*Sqlite3_context)(unsafe.Pointer(pCtx1)).FpMem = pMem2
	i5 = int32((*Sqlite3_context)(unsafe.Pointer(pCtx1)).Fargc) - 1
__859:
	if !(i5 >= 0) {
		goto __861
	}
	*(*uintptr)(unsafe.Pointer(pCtx1 + 48 + uintptr(i5)*8)) = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2+i5)*56
	goto __860
__860:
	i5--
	goto __859
	goto __861
__861:
	;
__858:
	;
	(*Mem)(unsafe.Pointer(pMem2)).Fn++

	if !((*Op)(unsafe.Pointer(pOp)).Fp1 != 0) {
		goto __862
	}
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*FuncDef)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx1)).FpFunc)).FxInverse})).f(tls, pCtx1, int32((*Sqlite3_context)(unsafe.Pointer(pCtx1)).Fargc), pCtx1+48)
	goto __863
__862:
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*FuncDef)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx1)).FpFunc)).FxSFunc})).f(tls, pCtx1, int32((*Sqlite3_context)(unsafe.Pointer(pCtx1)).Fargc), pCtx1+48)
__863:
	;
	if !((*Sqlite3_context)(unsafe.Pointer(pCtx1)).FisError != 0) {
		goto __864
	}
	if !((*Sqlite3_context)(unsafe.Pointer(pCtx1)).FisError > 0) {
		goto __865
	}
	Xsqlite3VdbeError(tls, p, ts+1684, libc.VaList(bp+120, Xsqlite3_value_text(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)))
	rc = (*Sqlite3_context)(unsafe.Pointer(pCtx1)).FisError
__865:
	;
	if !((*Sqlite3_context)(unsafe.Pointer(pCtx1)).FskipFlag != 0) {
		goto __866
	}

	i5 = (*Op)(unsafe.Pointer(pOp + libc.UintptrFromInt32(-1)*32)).Fp1
	if !(i5 != 0) {
		goto __867
	}
	Xsqlite3VdbeMemSetInt64(tls, aMem+uintptr(i5)*56, int64(1))
__867:
	;
	(*Sqlite3_context)(unsafe.Pointer(pCtx1)).FskipFlag = U8(0)
__866:
	;
	Xsqlite3VdbeMemRelease(tls, (*Sqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)
	(*Mem)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx1)).FpOut)).Fflags = U16(MEM_Null)
	(*Sqlite3_context)(unsafe.Pointer(pCtx1)).FisError = 0
	if !(rc != 0) {
		goto __868
	}
	goto abort_due_to_error
__868:
	;
__864:
	;
	goto __11

__164:
__165:
	;
	pMem3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	if !((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __869
	}

	rc = Xsqlite3VdbeMemAggValue(tls, pMem3, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56, *(*uintptr)(unsafe.Pointer(pOp + 16)))
	pMem3 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	goto __870
__869:
	rc = Xsqlite3VdbeMemFinalize(tls, pMem3, *(*uintptr)(unsafe.Pointer(pOp + 16)))
__870:
	;
	if !(rc != 0) {
		goto __871
	}
	Xsqlite3VdbeError(tls, p, ts+1684, libc.VaList(bp+128, Xsqlite3_value_text(tls, pMem3)))
	goto abort_due_to_error
__871:
	;
	Xsqlite3VdbeChangeEncoding(tls, pMem3, int32(encoding))
	updateMaxBlobsize(tls, pMem3)
	goto __11

__166:
	;
	*(*int32)(unsafe.Pointer(bp + 904)) = 0
	*(*int32)(unsafe.Pointer(bp + 904 + 1*4)) = libc.AssignPtrInt32(bp+904+2*4, -1)

	rc = Xsqlite3Checkpoint(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1, (*Op)(unsafe.Pointer(pOp)).Fp2, bp+904+1*4, bp+904+2*4)
	if !(rc != 0) {
		goto __872
	}
	if !(rc != SQLITE_BUSY) {
		goto __873
	}
	goto abort_due_to_error
__873:
	;
	rc = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 904)) = 1
__872:
	;
	i6 = 0
	pMem4 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
__874:
	if !(i6 < 3) {
		goto __876
	}
	Xsqlite3VdbeMemSetInt64(tls, pMem4, I64(*(*int32)(unsafe.Pointer(bp + 904 + uintptr(i6)*4))))
	goto __875
__875:
	i6++
	pMem4 += 56
	goto __874
	goto __876
__876:
	;
	goto __11

__167:
	pOut = out2Prerelease(tls, p, pOp)
	eNew = (*Op)(unsafe.Pointer(pOp)).Fp3

	pBt1 = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*32)).FpBt
	pPager = Xsqlite3BtreePager(tls, pBt1)
	eOld = Xsqlite3PagerGetJournalMode(tls, pPager)
	if !(eNew == -1) {
		goto __877
	}
	eNew = eOld
__877:
	;
	if !!(Xsqlite3PagerOkToChangeJournalMode(tls, pPager) != 0) {
		goto __878
	}
	eNew = eOld
__878:
	;
	zFilename = Xsqlite3PagerFilename(tls, pPager, 1)

	if !(eNew == PAGER_JOURNALMODE_WAL &&
		(Xsqlite3Strlen30(tls, zFilename) == 0 ||
			!(Xsqlite3PagerWalSupported(tls, pPager) != 0))) {
		goto __879
	}
	eNew = eOld
__879:
	;
	if !(eNew != eOld &&
		(eOld == PAGER_JOURNALMODE_WAL || eNew == PAGER_JOURNALMODE_WAL)) {
		goto __880
	}
	if !(!(int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit) != 0) || (*Sqlite3)(unsafe.Pointer(db)).FnVdbeRead > 1) {
		goto __881
	}
	rc = SQLITE_ERROR
	Xsqlite3VdbeError(tls, p,
		ts+8902,
		libc.VaList(bp+136, func() uintptr {
			if eNew == PAGER_JOURNALMODE_WAL {
				return ts + 8954
			}
			return ts + 8959
		}()))
	goto abort_due_to_error
	goto __882
__881:
	if !(eOld == PAGER_JOURNALMODE_WAL) {
		goto __883
	}

	rc = Xsqlite3PagerCloseWal(tls, pPager, db)
	if !(rc == SQLITE_OK) {
		goto __885
	}
	Xsqlite3PagerSetJournalMode(tls, pPager, eNew)
__885:
	;
	goto __884
__883:
	if !(eOld == PAGER_JOURNALMODE_MEMORY) {
		goto __886
	}

	Xsqlite3PagerSetJournalMode(tls, pPager, PAGER_JOURNALMODE_OFF)
__886:
	;
__884:
	;
	if !(rc == SQLITE_OK) {
		goto __887
	}
	rc = Xsqlite3BtreeSetVersion(tls, pBt1, func() int32 {
		if eNew == PAGER_JOURNALMODE_WAL {
			return 2
		}
		return 1
	}())
__887:
	;
__882:
	;
__880:
	;
	if !(rc != 0) {
		goto __888
	}
	eNew = eOld
__888:
	;
	eNew = Xsqlite3PagerSetJournalMode(tls, pPager, eNew)

	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Str | MEM_Static | MEM_Term)
	(*Mem)(unsafe.Pointer(pOut)).Fz = Xsqlite3JournalModename(tls, eNew)
	(*Mem)(unsafe.Pointer(pOut)).Fn = Xsqlite3Strlen30(tls, (*Mem)(unsafe.Pointer(pOut)).Fz)
	(*Mem)(unsafe.Pointer(pOut)).Fenc = U8(SQLITE_UTF8)
	Xsqlite3VdbeChangeEncoding(tls, pOut, int32(encoding))
	if !(rc != 0) {
		goto __889
	}
	goto abort_due_to_error
__889:
	;
	goto __11

__168:
	;
	rc = Xsqlite3RunVacuum(tls, p+168, db, (*Op)(unsafe.Pointer(pOp)).Fp1,
		func() uintptr {
			if (*Op)(unsafe.Pointer(pOp)).Fp2 != 0 {
				return aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56
			}
			return uintptr(0)
		}())
	if !(rc != 0) {
		goto __890
	}
	goto abort_due_to_error
__890:
	;
	goto __11

__169:
	;
	pBt2 = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*32)).FpBt
	rc = Xsqlite3BtreeIncrVacuum(tls, pBt2)

	if !(rc != 0) {
		goto __891
	}
	if !(rc != SQLITE_DONE) {
		goto __892
	}
	goto abort_due_to_error
__892:
	;
	rc = SQLITE_OK
	goto jump_to_p2
__891:
	;
	goto __11

__170:
	;
	if !!((*Op)(unsafe.Pointer(pOp)).Fp1 != 0) {
		goto __893
	}
	Xsqlite3ExpirePreparedStatements(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp2)
	goto __894
__893:
	libc.SetBitFieldPtr8Uint32(p+200, Bft((*Op)(unsafe.Pointer(pOp)).Fp2+1), 0, 0x3)
__894:
	;
	goto __11

__171:
	;
	pC30 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	Xsqlite3BtreeCursorPin(tls, *(*uintptr)(unsafe.Pointer(pC30 + 48)))
	goto __11

__172:
	;
	pC31 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	Xsqlite3BtreeCursorUnpin(tls, *(*uintptr)(unsafe.Pointer(pC31 + 48)))
	goto __11

__173:
	isWriteLock = U8((*Op)(unsafe.Pointer(pOp)).Fp3)
	if !(isWriteLock != 0 || uint64(0) == (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ReadUncommit)) {
		goto __895
	}
	p13 = (*Op)(unsafe.Pointer(pOp)).Fp1

	rc = Xsqlite3BtreeLockTable(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(p13)*32)).FpBt, (*Op)(unsafe.Pointer(pOp)).Fp2, isWriteLock)
	if !(rc != 0) {
		goto __896
	}
	if !(rc&0xFF == SQLITE_LOCKED) {
		goto __897
	}
	z1 = *(*uintptr)(unsafe.Pointer(pOp + 16))
	Xsqlite3VdbeError(tls, p, ts+8966, libc.VaList(bp+144, z1))
__897:
	;
	goto abort_due_to_error
__896:
	;
__895:
	;
	goto __11

__174:
	pVTab = *(*uintptr)(unsafe.Pointer(pOp + 16))
	rc = Xsqlite3VtabBegin(tls, db, pVTab)
	if !(pVTab != 0) {
		goto __898
	}
	Xsqlite3VtabImportErrmsg(tls, p, (*VTable)(unsafe.Pointer(pVTab)).FpVtab)
__898:
	;
	if !(rc != 0) {
		goto __899
	}
	goto abort_due_to_error
__899:
	;
	goto __11

__175:
	libc.Xmemset(tls, bp+920, 0, uint64(unsafe.Sizeof(Mem{})))
	(*Mem)(unsafe.Pointer(bp + 920)).Fdb = db

	rc = Xsqlite3VdbeMemCopy(tls, bp+920, aMem+uintptr((*Op)(unsafe.Pointer(pOp)).Fp2)*56)

	zTab = Xsqlite3_value_text(tls, bp+920)

	if !(zTab != 0) {
		goto __900
	}
	rc = Xsqlite3VtabCallCreate(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1, zTab, p+168)
__900:
	;
	Xsqlite3VdbeMemRelease(tls, bp+920)
	if !(rc != 0) {
		goto __901
	}
	goto abort_due_to_error
__901:
	;
	goto __11

__176:
	(*Sqlite3)(unsafe.Pointer(db)).FnVDestroy++
	rc = Xsqlite3VtabCallDestroy(tls, db, (*Op)(unsafe.Pointer(pOp)).Fp1, *(*uintptr)(unsafe.Pointer(pOp + 16)))
	(*Sqlite3)(unsafe.Pointer(db)).FnVDestroy--

	if !(rc != 0) {
		goto __902
	}
	goto abort_due_to_error
__902:
	;
	goto __11

__177:
	;
	pCur3 = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 976)) = uintptr(0)
	pVtab1 = (*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
	if !(pVtab1 == uintptr(0) || (*Sqlite3_vtab)(unsafe.Pointer(pVtab1)).FpModule == uintptr(0)) {
		goto __903
	}
	rc = SQLITE_LOCKED
	goto abort_due_to_error
__903:
	;
	pModule1 = (*Sqlite3_vtab)(unsafe.Pointer(pVtab1)).FpModule
	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule1)).FxOpen})).f(tls, pVtab1, bp+976)
	Xsqlite3VtabImportErrmsg(tls, p, pVtab1)
	if !(rc != 0) {
		goto __904
	}
	goto abort_due_to_error
__904:
	;
	(*Sqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 976)))).FpVtab = pVtab1

	pCur3 = allocateCursor(tls, p, (*Op)(unsafe.Pointer(pOp)).Fp1, 0, uint8(CURTYPE_VTAB))
	if !(pCur3 != 0) {
		goto __905
	}
	*(*uintptr)(unsafe.Pointer(pCur3 + 48)) = *(*uintptr)(unsafe.Pointer(bp + 976))
	(*Sqlite3_vtab)(unsafe.Pointer(pVtab1)).FnRef++
	goto __906
__905:
	;
	(*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule1)).FxClose})).f(tls, *(*uintptr)(unsafe.Pointer(bp + 976)))
	goto no_mem
__906:
	;
	goto __11

__178:
	pC32 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))
	pRhs = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(ValueList{})))
	if !(pRhs == uintptr(0)) {
		goto __907
	}
	goto no_mem
__907:
	;
	(*ValueList)(unsafe.Pointer(pRhs)).FpCsr = *(*uintptr)(unsafe.Pointer(pC32 + 48))
	(*ValueList)(unsafe.Pointer(pRhs)).FpOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	pOut = out2Prerelease(tls, p, pOp)
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(MEM_Null)
	Xsqlite3VdbeMemSetPointer(tls, pOut, pRhs, ts+8995, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3VdbeValueListFree})))
	goto __11

__179:
	pQuery = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	pArgc = pQuery + 1*56
	pCur4 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pVCur1 = *(*uintptr)(unsafe.Pointer(pCur4 + 48))
	pVtab2 = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pVCur1)).FpVtab
	pModule2 = (*Sqlite3_vtab)(unsafe.Pointer(pVtab2)).FpModule

	nArg = int32(*(*I64)(unsafe.Pointer(pArgc)))
	iQuery = int32(*(*I64)(unsafe.Pointer(pQuery)))

	apArg = (*Vdbe)(unsafe.Pointer(p)).FapArg
	i7 = 0
__908:
	if !(i7 < nArg) {
		goto __910
	}
	*(*uintptr)(unsafe.Pointer(apArg + uintptr(i7)*8)) = pArgc + uintptr(i7+1)*56
	goto __909
__909:
	i7++
	goto __908
	goto __910
__910:
	;
	rc = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule2)).FxFilter})).f(tls, pVCur1, iQuery, *(*uintptr)(unsafe.Pointer(pOp + 16)), nArg, apArg)
	Xsqlite3VtabImportErrmsg(tls, p, pVtab2)
	if !(rc != 0) {
		goto __911
	}
	goto abort_due_to_error
__911:
	;
	res12 = (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule2)).FxEof})).f(tls, pVCur1)
	(*VdbeCursor)(unsafe.Pointer(pCur4)).FnullRow = U8(0)

	if !(res12 != 0) {
		goto __912
	}
	goto jump_to_p2
__912:
	;
	goto __11

__180:
	pCur5 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	pDest2 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56

	if !((*VdbeCursor)(unsafe.Pointer(pCur5)).FnullRow != 0) {
		goto __913
	}
	Xsqlite3VdbeMemSetNull(tls, pDest2)
	goto __11
__913:
	;
	pVtab3 = (*Sqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur5 + 48)))).FpVtab
	pModule3 = (*Sqlite3_vtab)(unsafe.Pointer(pVtab3)).FpModule

	libc.Xmemset(tls, bp+984, 0, uint64(unsafe.Sizeof(Sqlite3_context{})))
	(*Sqlite3_context)(unsafe.Pointer(bp + 984)).FpOut = pDest2
	(*Sqlite3_context)(unsafe.Pointer(bp + 984)).Fenc = encoding

	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5)&OPFLAG_NOCHNG != 0) {
		goto __914
	}
	Xsqlite3VdbeMemSetNull(tls, pDest2)
	(*Mem)(unsafe.Pointer(pDest2)).Fflags = U16(MEM_Null | MEM_Zero)
	*(*int32)(unsafe.Pointer(pDest2)) = 0
	goto __915
__914:
	(*Mem)(unsafe.Pointer(pDest2)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pDest2)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Null)
__915:
	;
	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule3)).FxColumn})).f(tls, *(*uintptr)(unsafe.Pointer(pCur5 + 48)), bp+984, (*Op)(unsafe.Pointer(pOp)).Fp2)
	Xsqlite3VtabImportErrmsg(tls, p, pVtab3)
	if !((*Sqlite3_context)(unsafe.Pointer(bp+984)).FisError > 0) {
		goto __916
	}
	Xsqlite3VdbeError(tls, p, ts+1684, libc.VaList(bp+152, Xsqlite3_value_text(tls, pDest2)))
	rc = (*Sqlite3_context)(unsafe.Pointer(bp + 984)).FisError
__916:
	;
	Xsqlite3VdbeChangeEncoding(tls, pDest2, int32(encoding))

	updateMaxBlobsize(tls, pDest2)

	if !(rc != 0) {
		goto __917
	}
	goto abort_due_to_error
__917:
	;
	goto __11

__181:
	pCur6 = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FapCsr + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*8))

	if !((*VdbeCursor)(unsafe.Pointer(pCur6)).FnullRow != 0) {
		goto __918
	}
	goto __11
__918:
	;
	pVtab4 = (*Sqlite3_vtab_cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCur6 + 48)))).FpVtab
	pModule4 = (*Sqlite3_vtab)(unsafe.Pointer(pVtab4)).FpModule

	rc = (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule4)).FxNext})).f(tls, *(*uintptr)(unsafe.Pointer(pCur6 + 48)))
	Xsqlite3VtabImportErrmsg(tls, p, pVtab4)
	if !(rc != 0) {
		goto __919
	}
	goto abort_due_to_error
__919:
	;
	res13 = (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule4)).FxEof})).f(tls, *(*uintptr)(unsafe.Pointer(pCur6 + 48)))

	if !!(res13 != 0) {
		goto __920
	}

	goto jump_to_p2_and_check_for_interrupt
__920:
	;
	goto check_for_interrupt

__182:
	isLegacy = int32((*Sqlite3)(unsafe.Pointer(db)).Fflags & uint64(SQLITE_LegacyAlter))
	*(*U64)(unsafe.Pointer(db + 48)) |= uint64(SQLITE_LegacyAlter)
	pVtab5 = (*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
	pName = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	rc = Xsqlite3VdbeChangeEncoding(tls, pName, SQLITE_UTF8)
	if !(rc != 0) {
		goto __921
	}
	goto abort_due_to_error
__921:
	;
	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer((*Sqlite3_vtab)(unsafe.Pointer(pVtab5)).FpModule)).FxRename})).f(tls, pVtab5, (*Mem)(unsafe.Pointer(pName)).Fz)
	if !(isLegacy == 0) {
		goto __922
	}
	*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(SQLITE_LegacyAlter))
__922:
	;
	Xsqlite3VtabImportErrmsg(tls, p, pVtab5)
	libc.SetBitFieldPtr8Uint32(p+200, Bft(0), 0, 0x3)
	if !(rc != 0) {
		goto __923
	}
	goto abort_due_to_error
__923:
	;
	goto __11

__183:
	*(*Sqlite_int64)(unsafe.Pointer(bp + 1040)) = int64(0)

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __924
	}
	goto no_mem
__924:
	;
	pVtab6 = (*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FpVtab
	if !(pVtab6 == uintptr(0) || (*Sqlite3_vtab)(unsafe.Pointer(pVtab6)).FpModule == uintptr(0)) {
		goto __925
	}
	rc = SQLITE_LOCKED
	goto abort_due_to_error
__925:
	;
	pModule5 = (*Sqlite3_vtab)(unsafe.Pointer(pVtab6)).FpModule
	nArg1 = (*Op)(unsafe.Pointer(pOp)).Fp2

	if !((*Sqlite3_module)(unsafe.Pointer(pModule5)).FxUpdate != 0) {
		goto __926
	}
	vtabOnConflict = (*Sqlite3)(unsafe.Pointer(db)).FvtabOnConflict
	apArg1 = (*Vdbe)(unsafe.Pointer(p)).FapArg
	pX1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	i8 = 0
__927:
	if !(i8 < nArg1) {
		goto __929
	}

	*(*uintptr)(unsafe.Pointer(apArg1 + uintptr(i8)*8)) = pX1
	pX1 += 56
	goto __928
__928:
	i8++
	goto __927
	goto __929
__929:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FvtabOnConflict = U8((*Op)(unsafe.Pointer(pOp)).Fp5)
	rc = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule5)).FxUpdate})).f(tls, pVtab6, nArg1, apArg1, bp+1040)
	(*Sqlite3)(unsafe.Pointer(db)).FvtabOnConflict = vtabOnConflict
	Xsqlite3VtabImportErrmsg(tls, p, pVtab6)
	if !(rc == SQLITE_OK && (*Op)(unsafe.Pointer(pOp)).Fp1 != 0) {
		goto __930
	}

	(*Sqlite3)(unsafe.Pointer(db)).FlastRowid = *(*Sqlite_int64)(unsafe.Pointer(bp + 1040))
__930:
	;
	if !(rc&0xff == SQLITE_CONSTRAINT && (*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pOp + 16)))).FbConstraint != 0) {
		goto __931
	}
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fp5) == OE_Ignore) {
		goto __933
	}
	rc = SQLITE_OK
	goto __934
__933:
	(*Vdbe)(unsafe.Pointer(p)).FerrorAction = func() uint8 {
		if int32((*Op)(unsafe.Pointer(pOp)).Fp5) == OE_Replace {
			return uint8(OE_Abort)
		}
		return uint8((*Op)(unsafe.Pointer(pOp)).Fp5)
	}()
__934:
	;
	goto __932
__931:
	(*Vdbe)(unsafe.Pointer(p)).FnChange++
__932:
	;
	if !(rc != 0) {
		goto __935
	}
	goto abort_due_to_error
__935:
	;
__926:
	;
	goto __11

__184:
	pOut = out2Prerelease(tls, p, pOp)
	*(*I64)(unsafe.Pointer(pOut)) = I64(Xsqlite3BtreeLastPage(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*32)).FpBt))
	goto __11

__185:
	pOut = out2Prerelease(tls, p, pOp)
	pBt3 = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*32)).FpBt
	newMax = uint32(0)
	if !((*Op)(unsafe.Pointer(pOp)).Fp3 != 0) {
		goto __936
	}
	newMax = Xsqlite3BtreeLastPage(tls, pBt3)
	if !(newMax < uint32((*Op)(unsafe.Pointer(pOp)).Fp3)) {
		goto __937
	}
	newMax = uint32((*Op)(unsafe.Pointer(pOp)).Fp3)
__937:
	;
__936:
	;
	*(*I64)(unsafe.Pointer(pOut)) = I64(Xsqlite3BtreeMaxPageCount(tls, pBt3, newMax))
	goto __11

__186:
__187:
	;
	pCtx2 = *(*uintptr)(unsafe.Pointer(pOp + 16))

	pOut = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp3)*56
	if !((*Sqlite3_context)(unsafe.Pointer(pCtx2)).FpOut != pOut) {
		goto __938
	}
	(*Sqlite3_context)(unsafe.Pointer(pCtx2)).FpVdbe = p
	(*Sqlite3_context)(unsafe.Pointer(pCtx2)).FpOut = pOut
	(*Sqlite3_context)(unsafe.Pointer(pCtx2)).Fenc = encoding
	i9 = int32((*Sqlite3_context)(unsafe.Pointer(pCtx2)).Fargc) - 1
__939:
	if !(i9 >= 0) {
		goto __941
	}
	*(*uintptr)(unsafe.Pointer(pCtx2 + 48 + uintptr(i9)*8)) = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp2+i9)*56
	goto __940
__940:
	i9--
	goto __939
	goto __941
__941:
	;
__938:
	;
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Null)

	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*FuncDef)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(pCtx2)).FpFunc)).FxSFunc})).f(tls, pCtx2, int32((*Sqlite3_context)(unsafe.Pointer(pCtx2)).Fargc), pCtx2+48)

	if !((*Sqlite3_context)(unsafe.Pointer(pCtx2)).FisError != 0) {
		goto __942
	}
	if !((*Sqlite3_context)(unsafe.Pointer(pCtx2)).FisError > 0) {
		goto __943
	}
	Xsqlite3VdbeError(tls, p, ts+1684, libc.VaList(bp+160, Xsqlite3_value_text(tls, pOut)))
	rc = (*Sqlite3_context)(unsafe.Pointer(pCtx2)).FisError
__943:
	;
	Xsqlite3VdbeDeleteAuxData(tls, db, p+296, (*Sqlite3_context)(unsafe.Pointer(pCtx2)).FiOp, (*Op)(unsafe.Pointer(pOp)).Fp1)
	(*Sqlite3_context)(unsafe.Pointer(pCtx2)).FisError = 0
	if !(rc != 0) {
		goto __944
	}
	goto abort_due_to_error
__944:
	;
__942:
	;
	updateMaxBlobsize(tls, pOut)
	goto __11

__188:
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56
	*(*U16)(unsafe.Pointer(pIn1 + 20)) &= libc.Uint16FromInt32(libc.CplInt32(MEM_Subtype))
	goto __11

__189:
	;
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	h = filterHash(tls, aMem, pOp)
	h = h % U64((*Mem)(unsafe.Pointer(pIn1)).Fn)
	*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pIn1)).Fz + uintptr(h/uint64(8)))) |= uint8(int32(1) << (h & uint64(7)))
	goto __11

__190:
	;
	pIn1 = aMem + uintptr((*Op)(unsafe.Pointer(pOp)).Fp1)*56

	h1 = filterHash(tls, aMem, pOp)
	h1 = h1 % U64((*Mem)(unsafe.Pointer(pIn1)).Fn)
	if !(int32(*(*uint8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pIn1)).Fz + uintptr(h1/uint64(8)))))&(int32(1)<<(h1&uint64(7))) == 0) {
		goto __945
	}

	*(*U32)(unsafe.Pointer(p + 212 + 8*4))++
	goto jump_to_p2
	goto __946
__945:
	*(*U32)(unsafe.Pointer(p + 212 + 7*4))++

__946:
	;
	goto __11

__191:
__192:
	;
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmTrace)&(SQLITE_TRACE_STMT|SQLITE_TRACE_LEGACY) != 0 &&
		int32((*Vdbe)(unsafe.Pointer(p)).FminWriteFileFormat) != 254 &&
		libc.AssignUintptr(&zTrace, func() uintptr {
			if *(*uintptr)(unsafe.Pointer(pOp + 16)) != 0 {
				return *(*uintptr)(unsafe.Pointer(pOp + 16))
			}
			return (*Vdbe)(unsafe.Pointer(p)).FzSql
		}()) != uintptr(0)) {
		goto __947
	}
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmTrace)&SQLITE_TRACE_LEGACY != 0) {
		goto __948
	}
	z2 = Xsqlite3VdbeExpandSql(tls, p, zTrace)
	(*struct {
		f func(*libc.TLS, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(db + 248))})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpTraceArg, z2)
	Xsqlite3_free(tls, z2)
	goto __949
__948:
	if !((*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec > 1) {
		goto __950
	}
	z3 = Xsqlite3MPrintf(tls, db, ts+9005, libc.VaList(bp+168, zTrace))
	(*struct {
		f func(*libc.TLS, U32, uintptr, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(db + 248))})).f(tls, uint32(SQLITE_TRACE_STMT), (*Sqlite3)(unsafe.Pointer(db)).FpTraceArg, p, z3)
	Xsqlite3DbFree(tls, db, z3)
	goto __951
__950:
	(*struct {
		f func(*libc.TLS, U32, uintptr, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(db + 248))})).f(tls, uint32(SQLITE_TRACE_STMT), (*Sqlite3)(unsafe.Pointer(db)).FpTraceArg, p, zTrace)
__951:
	;
__949:
	;
__947:
	;
	if !((*Op)(unsafe.Pointer(pOp)).Fp1 >= Xsqlite3Config.FiOnceResetThreshold) {
		goto __952
	}
	if !(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_Trace) {
		goto __953
	}
	goto __11
__953:
	;
	i10 = 1
__954:
	if !(i10 < (*Vdbe)(unsafe.Pointer(p)).FnOp) {
		goto __956
	}
	if !(int32((*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp+uintptr(i10)*32)).Fopcode) == OP_Once) {
		goto __957
	}
	(*Op)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(p)).FaOp + uintptr(i10)*32)).Fp1 = 0
__957:
	;
	goto __955
__955:
	i10++
	goto __954
	goto __956
__956:
	;
	(*Op)(unsafe.Pointer(pOp)).Fp1 = 0
__952:
	;
	(*Op)(unsafe.Pointer(pOp)).Fp1++
	*(*U32)(unsafe.Pointer(p + 212 + 6*4))++
	goto jump_to_p2

__193:
	;
	goto __11

__11:
	;
	goto __7
__7:
	pOp += 32
	goto __6
	goto __8
__8:
	;
abort_due_to_error:
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __958
	}
	rc = SQLITE_NOMEM
	goto __959
__958:
	if !(rc == SQLITE_IOERR|int32(33)<<8) {
		goto __960
	}
	rc = Xsqlite3CorruptError(tls, 99034)
__960:
	;
__959:
	;
	if !((*Vdbe)(unsafe.Pointer(p)).FzErrMsg == uintptr(0) && rc != SQLITE_IOERR|int32(12)<<8) {
		goto __961
	}
	Xsqlite3VdbeError(tls, p, ts+1684, libc.VaList(bp+176, Xsqlite3ErrStr(tls, rc)))
__961:
	;
	(*Vdbe)(unsafe.Pointer(p)).Frc = rc
	Xsqlite3SystemError(tls, db, rc)

	Xsqlite3_log(tls, rc, ts+9011,
		libc.VaList(bp+184, int32((int64(pOp)-int64(aOp))/32), (*Vdbe)(unsafe.Pointer(p)).FzSql, (*Vdbe)(unsafe.Pointer(p)).FzErrMsg))
	if !(int32((*Vdbe)(unsafe.Pointer(p)).FeVdbeState) == VDBE_RUN_STATE) {
		goto __962
	}
	Xsqlite3VdbeHalt(tls, p)
__962:
	;
	if !(rc == SQLITE_IOERR|int32(12)<<8) {
		goto __963
	}
	Xsqlite3OomFault(tls, db)
__963:
	;
	if !(rc == SQLITE_CORRUPT && int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit) == 0) {
		goto __964
	}
	*(*U64)(unsafe.Pointer(db + 48)) |= uint64(0x00002) << 32
__964:
	;
	rc = SQLITE_ERROR
	if !(int32(resetSchemaOnFault) > 0) {
		goto __965
	}
	Xsqlite3ResetOneSchema(tls, db, int32(resetSchemaOnFault)-1)
__965:
	;
vdbe_return:
__966:
	if !(nVmStep >= nProgressLimit && (*Sqlite3)(unsafe.Pointer(db)).FxProgress != uintptr(0)) {
		goto __967
	}
	nProgressLimit = nProgressLimit + U64((*Sqlite3)(unsafe.Pointer(db)).FnProgressOps)
	if !((*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxProgress})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpProgressArg) != 0) {
		goto __968
	}
	nProgressLimit = uint64(0xffffffff) | uint64(0xffffffff)<<32
	rc = SQLITE_INTERRUPT
	goto abort_due_to_error
__968:
	;
	goto __966
__967:
	;
	*(*U32)(unsafe.Pointer(p + 212 + 4*4)) += U32(int32(nVmStep))
	if !((*Vdbe)(unsafe.Pointer(p)).FlockMask != YDbMask(0)) {
		goto __969
	}
	Xsqlite3VdbeLeave(tls, p)
__969:
	;
	return rc

too_big:
	Xsqlite3VdbeError(tls, p, ts+8259, 0)
	rc = SQLITE_TOOBIG
	goto abort_due_to_error

no_mem:
	Xsqlite3OomFault(tls, db)
	Xsqlite3VdbeError(tls, p, ts+1572, 0)
	rc = SQLITE_NOMEM
	goto abort_due_to_error

abort_due_to_interrupt:
	;
	rc = SQLITE_INTERRUPT
	goto abort_due_to_error
	return int32(0)
}

var azType = [4]uintptr{ts + 9043, ts + 9052, ts + 9059,
	ts + 9065}
var and_logic = [9]uint8{uint8(0), uint8(0), uint8(0), uint8(0), uint8(1), uint8(2), uint8(0), uint8(2), uint8(2)}
var or_logic = [9]uint8{uint8(0), uint8(1), uint8(2), uint8(1), uint8(1), uint8(1), uint8(2), uint8(1), uint8(2)}
var aMask = [12]uint8{
	uint8(0x10), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x01), uint8(0x2),
	uint8(0x01), uint8(0x01), uint8(0x10), uint8(0x10),
}
var aFlag1 = [2]U16{U16(MEM_Blob), U16(MEM_Str | MEM_Term)}
var vfsFlags int32 = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_TRANSIENT_DB

type Incrblob1 = struct {
	FnByte       int32
	FiOffset     int32
	FiCol        U16
	F__ccgo_pad1 [6]byte
	FpCsr        uintptr
	FpStmt       uintptr
	Fdb          uintptr
	FzDb         uintptr
	FpTab        uintptr
}

type Incrblob = Incrblob1

func blobSeekToRow(tls *libc.TLS, p uintptr, iRow Sqlite3_int64, pzErr uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32
	var zErr uintptr = uintptr(0)
	var v uintptr = (*Incrblob)(unsafe.Pointer(p)).FpStmt

	(*Mem)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).FaMem + 1*56)).Fflags = U16(MEM_Int)
	*(*I64)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).FaMem + 1*56)) = iRow

	if (*Vdbe)(unsafe.Pointer(v)).Fpc > 4 {
		(*Vdbe)(unsafe.Pointer(v)).Fpc = 4

		rc = Xsqlite3VdbeExec(tls, v)
	} else {
		rc = Xsqlite3_step(tls, (*Incrblob)(unsafe.Pointer(p)).FpStmt)
	}
	if rc == SQLITE_ROW {
		var pC uintptr = *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).FapCsr))
		var type1 U32

		if int32((*VdbeCursor)(unsafe.Pointer(pC)).FnHdrParsed) > int32((*Incrblob)(unsafe.Pointer(p)).FiCol) {
			type1 = *(*U32)(unsafe.Pointer(pC + 112 + uintptr((*Incrblob)(unsafe.Pointer(p)).FiCol)*4))
		} else {
			type1 = uint32(0)
		}

		if type1 < U32(12) {
			zErr = Xsqlite3MPrintf(tls, (*Incrblob)(unsafe.Pointer(p)).Fdb, ts+9077,
				libc.VaList(bp, func() uintptr {
					if type1 == U32(0) {
						return ts + 9106
					}
					return func() uintptr {
						if type1 == U32(7) {
							return ts + 9111
						}
						return ts + 9116
					}()
				}()))
			rc = SQLITE_ERROR
			Xsqlite3_finalize(tls, (*Incrblob)(unsafe.Pointer(p)).FpStmt)
			(*Incrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
		} else {
			(*Incrblob)(unsafe.Pointer(p)).FiOffset = int32(*(*U32)(unsafe.Pointer(pC + 112 + uintptr(int32((*Incrblob)(unsafe.Pointer(p)).FiCol)+int32((*VdbeCursor)(unsafe.Pointer(pC)).FnField))*4)))
			(*Incrblob)(unsafe.Pointer(p)).FnByte = int32(Xsqlite3VdbeSerialTypeLen(tls, type1))
			(*Incrblob)(unsafe.Pointer(p)).FpCsr = *(*uintptr)(unsafe.Pointer(pC + 48))
			Xsqlite3BtreeIncrblobCursor(tls, (*Incrblob)(unsafe.Pointer(p)).FpCsr)
		}
	}

	if rc == SQLITE_ROW {
		rc = SQLITE_OK
	} else if (*Incrblob)(unsafe.Pointer(p)).FpStmt != 0 {
		rc = Xsqlite3_finalize(tls, (*Incrblob)(unsafe.Pointer(p)).FpStmt)
		(*Incrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
		if rc == SQLITE_OK {
			zErr = Xsqlite3MPrintf(tls, (*Incrblob)(unsafe.Pointer(p)).Fdb, ts+9124, libc.VaList(bp+8, iRow))
			rc = SQLITE_ERROR
		} else {
			zErr = Xsqlite3MPrintf(tls, (*Incrblob)(unsafe.Pointer(p)).Fdb, ts+1684, libc.VaList(bp+16, Xsqlite3_errmsg(tls, (*Incrblob)(unsafe.Pointer(p)).Fdb)))
		}
	}

	*(*uintptr)(unsafe.Pointer(pzErr)) = zErr
	return rc
}

func Xsqlite3_blob_open(tls *libc.TLS, db uintptr, zDb uintptr, zTable uintptr, zColumn uintptr, iRow Sqlite_int64, wrFlag int32, ppBlob uintptr) int32 {
	bp := tls.Alloc(480)
	defer tls.Free(480)

	var nAttempt int32
	var iCol int32
	var rc int32

	var pTab uintptr
	var pBlob uintptr

	var j int32

	var pFKey uintptr
	var j1 int32
	var zFault uintptr
	var pIdx uintptr
	var v uintptr
	var iDb int32
	var aOp uintptr
	nAttempt = 0
	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp + 472)) = uintptr(0)
	pBlob = uintptr(0)

	*(*uintptr)(unsafe.Pointer(ppBlob)) = uintptr(0)
	wrFlag = libc.BoolInt32(!!(wrFlag != 0))

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)

	pBlob = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Incrblob{})))
__1:
	if !(1 != 0) {
		goto __2
	}
	Xsqlite3ParseObjectInit(tls, bp+48, db)
	if !!(pBlob != 0) {
		goto __3
	}
	goto blob_open_out
__3:
	;
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 472)))
	*(*uintptr)(unsafe.Pointer(bp + 472)) = uintptr(0)

	Xsqlite3BtreeEnterAll(tls, db)
	pTab = Xsqlite3LocateTable(tls, bp+48, uint32(0), zTable, zDb)
	if !(pTab != 0 && int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __4
	}
	pTab = uintptr(0)
	Xsqlite3ErrorMsg(tls, bp+48, ts+9144, libc.VaList(bp, zTable))
__4:
	;
	if !(pTab != 0 && !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0))) {
		goto __5
	}
	pTab = uintptr(0)
	Xsqlite3ErrorMsg(tls, bp+48, ts+9174, libc.VaList(bp+8, zTable))
__5:
	;
	if !(pTab != 0 && int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		goto __6
	}
	pTab = uintptr(0)
	Xsqlite3ErrorMsg(tls, bp+48, ts+9210, libc.VaList(bp+16, zTable))
__6:
	;
	if !!(pTab != 0) {
		goto __7
	}
	if !((*Parse)(unsafe.Pointer(bp+48)).FzErrMsg != 0) {
		goto __8
	}
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 472)))
	*(*uintptr)(unsafe.Pointer(bp + 472)) = (*Parse)(unsafe.Pointer(bp + 48)).FzErrMsg
	(*Parse)(unsafe.Pointer(bp + 48)).FzErrMsg = uintptr(0)
__8:
	;
	rc = SQLITE_ERROR
	Xsqlite3BtreeLeaveAll(tls, db)
	goto blob_open_out
__7:
	;
	(*Incrblob)(unsafe.Pointer(pBlob)).FpTab = pTab
	(*Incrblob)(unsafe.Pointer(pBlob)).FzDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema))*32)).FzDbSName

	iCol = 0
__9:
	if !(iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __11
	}
	if !(Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FzCnName, zColumn) == 0) {
		goto __12
	}
	goto __11
__12:
	;
	goto __10
__10:
	iCol++
	goto __9
	goto __11
__11:
	;
	if !(iCol == int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __13
	}
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 472)))
	*(*uintptr)(unsafe.Pointer(bp + 472)) = Xsqlite3MPrintf(tls, db, ts+9231, libc.VaList(bp+24, zColumn))
	rc = SQLITE_ERROR
	Xsqlite3BtreeLeaveAll(tls, db)
	goto blob_open_out
__13:
	;
	if !(wrFlag != 0) {
		goto __14
	}
	zFault = uintptr(0)
	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0) {
		goto __15
	}

	pFKey = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8))
__16:
	if !(pFKey != 0) {
		goto __18
	}
	j = 0
__19:
	if !(j < (*FKey)(unsafe.Pointer(pFKey)).FnCol) {
		goto __21
	}
	if !((*sColMap)(unsafe.Pointer(pFKey+64+uintptr(j)*16)).FiFrom == iCol) {
		goto __22
	}
	zFault = ts + 9252
__22:
	;
	goto __20
__20:
	j++
	goto __19
	goto __21
__21:
	;
	goto __17
__17:
	pFKey = (*FKey)(unsafe.Pointer(pFKey)).FpNextFrom
	goto __16
	goto __18
__18:
	;
__15:
	;
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__23:
	if !(pIdx != 0) {
		goto __25
	}
	j1 = 0
__26:
	if !(j1 < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)) {
		goto __28
	}

	if !(int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j1)*2))) == iCol || int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j1)*2))) == -2) {
		goto __29
	}
	zFault = ts + 9264
__29:
	;
	goto __27
__27:
	j1++
	goto __26
	goto __28
__28:
	;
	goto __24
__24:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	goto __23
	goto __25
__25:
	;
	if !(zFault != 0) {
		goto __30
	}
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 472)))
	*(*uintptr)(unsafe.Pointer(bp + 472)) = Xsqlite3MPrintf(tls, db, ts+9272, libc.VaList(bp+32, zFault))
	rc = SQLITE_ERROR
	Xsqlite3BtreeLeaveAll(tls, db)
	goto blob_open_out
__30:
	;
__14:
	;
	(*Incrblob)(unsafe.Pointer(pBlob)).FpStmt = Xsqlite3VdbeCreate(tls, bp+48)

	if !((*Incrblob)(unsafe.Pointer(pBlob)).FpStmt != 0) {
		goto __31
	}
	v = (*Incrblob)(unsafe.Pointer(pBlob)).FpStmt
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	Xsqlite3VdbeAddOp4Int(tls, v, OP_Transaction, iDb, wrFlag,
		(*Schema)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FpSchema)).Fschema_cookie,
		(*Schema)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FpSchema)).FiGeneration)
	Xsqlite3VdbeChangeP5(tls, v, uint16(1))

	aOp = Xsqlite3VdbeAddOpList(tls, v, int32(uint64(unsafe.Sizeof(openBlob))/uint64(unsafe.Sizeof(VdbeOpList{}))), uintptr(unsafe.Pointer(&openBlob)), iLn)

	Xsqlite3VdbeUsesBtree(tls, v, iDb)

	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0) {
		goto __32
	}

	(*VdbeOp)(unsafe.Pointer(aOp)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp)).Fp2 = int32((*Table)(unsafe.Pointer(pTab)).Ftnum)
	(*VdbeOp)(unsafe.Pointer(aOp)).Fp3 = wrFlag
	Xsqlite3VdbeChangeP4(tls, v, 2, (*Table)(unsafe.Pointer(pTab)).FzName, P4_TRANSIENT)
__32:
	;
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0) {
		goto __33
	}

	if !(wrFlag != 0) {
		goto __34
	}
	(*VdbeOp)(unsafe.Pointer(aOp + 1*32)).Fopcode = U8(OP_OpenWrite)
__34:
	;
	(*VdbeOp)(unsafe.Pointer(aOp + 1*32)).Fp2 = int32((*Table)(unsafe.Pointer(pTab)).Ftnum)
	(*VdbeOp)(unsafe.Pointer(aOp + 1*32)).Fp3 = iDb

	(*VdbeOp)(unsafe.Pointer(aOp + 1*32)).Fp4type = int8(-3)
	*(*int32)(unsafe.Pointer(aOp + 1*32 + 16)) = int32((*Table)(unsafe.Pointer(pTab)).FnCol) + 1
	(*VdbeOp)(unsafe.Pointer(aOp + 3*32)).Fp2 = int32((*Table)(unsafe.Pointer(pTab)).FnCol)

	(*Parse)(unsafe.Pointer(bp + 48)).FnVar = int16(0)
	(*Parse)(unsafe.Pointer(bp + 48)).FnMem = 1
	(*Parse)(unsafe.Pointer(bp + 48)).FnTab = 1
	Xsqlite3VdbeMakeReady(tls, v, bp+48)
__33:
	;
__31:
	;
	(*Incrblob)(unsafe.Pointer(pBlob)).FiCol = U16(iCol)
	(*Incrblob)(unsafe.Pointer(pBlob)).Fdb = db
	Xsqlite3BtreeLeaveAll(tls, db)
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __35
	}
	goto blob_open_out
__35:
	;
	rc = blobSeekToRow(tls, pBlob, iRow, bp+472)
	if !(libc.PreIncInt32(&nAttempt, 1) >= SQLITE_MAX_SCHEMA_RETRY || rc != SQLITE_SCHEMA) {
		goto __36
	}
	goto __2
__36:
	;
	Xsqlite3ParseObjectReset(tls, bp+48)
	goto __1
__2:
	;
blob_open_out:
	if !(rc == SQLITE_OK && int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0) {
		goto __37
	}
	*(*uintptr)(unsafe.Pointer(ppBlob)) = pBlob
	goto __38
__37:
	if !(pBlob != 0 && (*Incrblob)(unsafe.Pointer(pBlob)).FpStmt != 0) {
		goto __39
	}
	Xsqlite3VdbeFinalize(tls, (*Incrblob)(unsafe.Pointer(pBlob)).FpStmt)
__39:
	;
	Xsqlite3DbFree(tls, db, pBlob)
__38:
	;
	Xsqlite3ErrorWithMsg(tls, db, rc, func() uintptr {
		if *(*uintptr)(unsafe.Pointer(bp + 472)) != 0 {
			return ts + 1684
		}
		return uintptr(0)
	}(), libc.VaList(bp+40, *(*uintptr)(unsafe.Pointer(bp + 472))))
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 472)))
	Xsqlite3ParseObjectReset(tls, bp+48)
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

var iLn int32 = 0
var openBlob = [6]VdbeOpList{
	{Fopcode: U8(OP_TableLock)},
	{Fopcode: U8(OP_OpenRead)},
	{Fopcode: U8(OP_NotExists), Fp2: int8(5), Fp3: int8(1)},
	{Fopcode: U8(OP_Column), Fp3: int8(1)},
	{Fopcode: U8(OP_ResultRow), Fp1: int8(1)},
	{Fopcode: U8(OP_Halt)},
}

func Xsqlite3_blob_close(tls *libc.TLS, pBlob uintptr) int32 {
	var p uintptr = pBlob
	var rc int32
	var db uintptr

	if p != 0 {
		var pStmt uintptr = (*Incrblob)(unsafe.Pointer(p)).FpStmt
		db = (*Incrblob)(unsafe.Pointer(p)).Fdb
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		Xsqlite3DbFree(tls, db, p)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		rc = Xsqlite3_finalize(tls, pStmt)
	} else {
		rc = SQLITE_OK
	}
	return rc
}

func blobReadWrite(tls *libc.TLS, pBlob uintptr, z uintptr, n int32, iOffset int32, xCall uintptr) int32 {
	var rc int32
	var p uintptr = pBlob
	var v uintptr
	var db uintptr

	if p == uintptr(0) {
		return Xsqlite3MisuseError(tls, 99519)
	}
	db = (*Incrblob)(unsafe.Pointer(p)).Fdb
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	v = (*Incrblob)(unsafe.Pointer(p)).FpStmt

	if n < 0 || iOffset < 0 || Sqlite3_int64(iOffset)+Sqlite3_int64(n) > Sqlite3_int64((*Incrblob)(unsafe.Pointer(p)).FnByte) {
		rc = SQLITE_ERROR
	} else if v == uintptr(0) {
		rc = SQLITE_ABORT
	} else {
		Xsqlite3BtreeEnterCursor(tls, (*Incrblob)(unsafe.Pointer(p)).FpCsr)

		if xCall == *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, U32, U32, uintptr) int32
		}{Xsqlite3BtreePutData})) && (*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
			var iKey Sqlite3_int64
			iKey = Xsqlite3BtreeIntegerKey(tls, (*Incrblob)(unsafe.Pointer(p)).FpCsr)

			Xsqlite3VdbePreUpdateHook(tls,
				v, *(*uintptr)(unsafe.Pointer((*Vdbe)(unsafe.Pointer(v)).FapCsr)), SQLITE_DELETE, (*Incrblob)(unsafe.Pointer(p)).FzDb, (*Incrblob)(unsafe.Pointer(p)).FpTab, iKey, -1, int32((*Incrblob)(unsafe.Pointer(p)).FiCol))
		}

		rc = (*struct {
			f func(*libc.TLS, uintptr, U32, U32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{xCall})).f(tls, (*Incrblob)(unsafe.Pointer(p)).FpCsr, uint32(iOffset+(*Incrblob)(unsafe.Pointer(p)).FiOffset), uint32(n), z)
		Xsqlite3BtreeLeaveCursor(tls, (*Incrblob)(unsafe.Pointer(p)).FpCsr)
		if rc == SQLITE_ABORT {
			Xsqlite3VdbeFinalize(tls, v)
			(*Incrblob)(unsafe.Pointer(p)).FpStmt = uintptr(0)
		} else {
			(*Vdbe)(unsafe.Pointer(v)).Frc = rc
		}
	}
	Xsqlite3Error(tls, db, rc)
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_blob_read(tls *libc.TLS, pBlob uintptr, z uintptr, n int32, iOffset int32) int32 {
	return blobReadWrite(tls, pBlob, z, n, iOffset, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, U32, U32, uintptr) int32
	}{Xsqlite3BtreePayloadChecked})))
}

func Xsqlite3_blob_write(tls *libc.TLS, pBlob uintptr, z uintptr, n int32, iOffset int32) int32 {
	return blobReadWrite(tls, pBlob, z, n, iOffset, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, U32, U32, uintptr) int32
	}{Xsqlite3BtreePutData})))
}

func Xsqlite3_blob_bytes(tls *libc.TLS, pBlob uintptr) int32 {
	var p uintptr = pBlob
	if p != 0 && (*Incrblob)(unsafe.Pointer(p)).FpStmt != 0 {
		return (*Incrblob)(unsafe.Pointer(p)).FnByte
	}
	return 0
}

func Xsqlite3_blob_reopen(tls *libc.TLS, pBlob uintptr, iRow Sqlite3_int64) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32
	var p uintptr = pBlob
	var db uintptr

	if p == uintptr(0) {
		return Xsqlite3MisuseError(tls, 99619)
	}
	db = (*Incrblob)(unsafe.Pointer(p)).Fdb
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)

	if (*Incrblob)(unsafe.Pointer(p)).FpStmt == uintptr(0) {
		rc = SQLITE_ABORT
	} else {
		(*Vdbe)(unsafe.Pointer((*Incrblob)(unsafe.Pointer(p)).FpStmt)).Frc = SQLITE_OK
		rc = blobSeekToRow(tls, p, iRow, bp+8)
		if rc != SQLITE_OK {
			Xsqlite3ErrorWithMsg(tls, db, rc, func() uintptr {
				if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
					return ts + 1684
				}
				return uintptr(0)
			}(), libc.VaList(bp, *(*uintptr)(unsafe.Pointer(bp + 8))))
			Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8)))
		}

	}

	rc = Xsqlite3ApiExit(tls, db, rc)

	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

type MergeEngine1 = struct {
	FnTree       int32
	F__ccgo_pad1 [4]byte
	FpTask       uintptr
	FaTree       uintptr
	FaReadr      uintptr
}

type MergeEngine = MergeEngine1
type PmaReader1 = struct {
	FiReadOff    I64
	FiEof        I64
	FnAlloc      int32
	FnKey        int32
	FpFd         uintptr
	FaAlloc      uintptr
	FaKey        uintptr
	FaBuffer     uintptr
	FnBuffer     int32
	F__ccgo_pad1 [4]byte
	FaMap        uintptr
	FpIncr       uintptr
}

type PmaReader = PmaReader1
type PmaWriter1 = struct {
	FeFWErr      int32
	F__ccgo_pad1 [4]byte
	FaBuffer     uintptr
	FnBuffer     int32
	FiBufStart   int32
	FiBufEnd     int32
	F__ccgo_pad2 [4]byte
	FiWriteOff   I64
	FpFd         uintptr
}

type PmaWriter = PmaWriter1
type SorterRecord1 = struct {
	FnVal        int32
	F__ccgo_pad1 [4]byte
	Fu           struct{ FpNext uintptr }
}

type SorterRecord = SorterRecord1
type SortSubtask1 = struct {
	FpThread     uintptr
	FbDone       int32
	F__ccgo_pad1 [4]byte
	FpSorter     uintptr
	FpUnpacked   uintptr
	Flist        SorterList
	FnPMA        int32
	F__ccgo_pad2 [4]byte
	FxCompare    SorterCompare
	Ffile        SorterFile
	Ffile2       SorterFile
}

type SortSubtask = SortSubtask1
type SorterFile1 = struct {
	FpFd  uintptr
	FiEof I64
}

type SorterFile = SorterFile1
type SorterList1 = struct {
	FpList       uintptr
	FaMemory     uintptr
	FszPMA       int32
	F__ccgo_pad1 [4]byte
}

type SorterList = SorterList1
type IncrMerger1 = struct {
	FpTask       uintptr
	FpMerger     uintptr
	FiStartOff   I64
	FmxSz        int32
	FbEof        int32
	FbUseThread  int32
	F__ccgo_pad1 [4]byte
	FaFile       [2]SorterFile
}

type IncrMerger = IncrMerger1

type SorterCompare = uintptr

func vdbePmaReaderClear(tls *libc.TLS, pReadr uintptr) {
	Xsqlite3_free(tls, (*PmaReader)(unsafe.Pointer(pReadr)).FaAlloc)
	Xsqlite3_free(tls, (*PmaReader)(unsafe.Pointer(pReadr)).FaBuffer)
	if (*PmaReader)(unsafe.Pointer(pReadr)).FaMap != 0 {
		Xsqlite3OsUnfetch(tls, (*PmaReader)(unsafe.Pointer(pReadr)).FpFd, int64(0), (*PmaReader)(unsafe.Pointer(pReadr)).FaMap)
	}
	vdbeIncrFree(tls, (*PmaReader)(unsafe.Pointer(pReadr)).FpIncr)
	libc.Xmemset(tls, pReadr, 0, uint64(unsafe.Sizeof(PmaReader{})))
}

func vdbePmaReadBlob(tls *libc.TLS, p uintptr, nByte int32, ppOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var iBuf int32
	var nAvail int32

	if (*PmaReader)(unsafe.Pointer(p)).FaMap != 0 {
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*PmaReader)(unsafe.Pointer(p)).FaMap + uintptr((*PmaReader)(unsafe.Pointer(p)).FiReadOff)
		*(*I64)(unsafe.Pointer(p)) += I64(nByte)
		return SQLITE_OK
	}

	iBuf = int32((*PmaReader)(unsafe.Pointer(p)).FiReadOff % I64((*PmaReader)(unsafe.Pointer(p)).FnBuffer))
	if iBuf == 0 {
		var nRead int32
		var rc int32

		if (*PmaReader)(unsafe.Pointer(p)).FiEof-(*PmaReader)(unsafe.Pointer(p)).FiReadOff > I64((*PmaReader)(unsafe.Pointer(p)).FnBuffer) {
			nRead = (*PmaReader)(unsafe.Pointer(p)).FnBuffer
		} else {
			nRead = int32((*PmaReader)(unsafe.Pointer(p)).FiEof - (*PmaReader)(unsafe.Pointer(p)).FiReadOff)
		}

		rc = Xsqlite3OsRead(tls, (*PmaReader)(unsafe.Pointer(p)).FpFd, (*PmaReader)(unsafe.Pointer(p)).FaBuffer, nRead, (*PmaReader)(unsafe.Pointer(p)).FiReadOff)

		if rc != SQLITE_OK {
			return rc
		}
	}
	nAvail = (*PmaReader)(unsafe.Pointer(p)).FnBuffer - iBuf

	if nByte <= nAvail {
		*(*uintptr)(unsafe.Pointer(ppOut)) = (*PmaReader)(unsafe.Pointer(p)).FaBuffer + uintptr(iBuf)
		*(*I64)(unsafe.Pointer(p)) += I64(nByte)
	} else {
		var nRem int32

		if (*PmaReader)(unsafe.Pointer(p)).FnAlloc < nByte {
			var aNew uintptr
			var nNew Sqlite3_int64 = func() int64 {
				if int64(128) > int64(2)*Sqlite3_int64((*PmaReader)(unsafe.Pointer(p)).FnAlloc) {
					return int64(128)
				}
				return int64(2) * Sqlite3_int64((*PmaReader)(unsafe.Pointer(p)).FnAlloc)
			}()
			for Sqlite3_int64(nByte) > nNew {
				nNew = nNew * int64(2)
			}
			aNew = Xsqlite3Realloc(tls, (*PmaReader)(unsafe.Pointer(p)).FaAlloc, uint64(nNew))
			if !(aNew != 0) {
				return SQLITE_NOMEM
			}
			(*PmaReader)(unsafe.Pointer(p)).FnAlloc = int32(nNew)
			(*PmaReader)(unsafe.Pointer(p)).FaAlloc = aNew
		}

		libc.Xmemcpy(tls, (*PmaReader)(unsafe.Pointer(p)).FaAlloc, (*PmaReader)(unsafe.Pointer(p)).FaBuffer+uintptr(iBuf), uint64(nAvail))
		*(*I64)(unsafe.Pointer(p)) += I64(nAvail)
		nRem = nByte - nAvail

		for nRem > 0 {
			var rc int32
			var nCopy int32

			nCopy = nRem
			if nRem > (*PmaReader)(unsafe.Pointer(p)).FnBuffer {
				nCopy = (*PmaReader)(unsafe.Pointer(p)).FnBuffer
			}
			rc = vdbePmaReadBlob(tls, p, nCopy, bp)
			if rc != SQLITE_OK {
				return rc
			}

			libc.Xmemcpy(tls, (*PmaReader)(unsafe.Pointer(p)).FaAlloc+uintptr(nByte-nRem), *(*uintptr)(unsafe.Pointer(bp)), uint64(nCopy))
			nRem = nRem - nCopy
		}

		*(*uintptr)(unsafe.Pointer(ppOut)) = (*PmaReader)(unsafe.Pointer(p)).FaAlloc
	}

	return SQLITE_OK
}

func vdbePmaReadVarint(tls *libc.TLS, p uintptr, pnOut uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var iBuf int32

	if (*PmaReader)(unsafe.Pointer(p)).FaMap != 0 {
		*(*I64)(unsafe.Pointer(p)) += I64(Xsqlite3GetVarint(tls, (*PmaReader)(unsafe.Pointer(p)).FaMap+uintptr((*PmaReader)(unsafe.Pointer(p)).FiReadOff), pnOut))
	} else {
		iBuf = int32((*PmaReader)(unsafe.Pointer(p)).FiReadOff % I64((*PmaReader)(unsafe.Pointer(p)).FnBuffer))
		if iBuf != 0 && (*PmaReader)(unsafe.Pointer(p)).FnBuffer-iBuf >= 9 {
			*(*I64)(unsafe.Pointer(p)) += I64(Xsqlite3GetVarint(tls, (*PmaReader)(unsafe.Pointer(p)).FaBuffer+uintptr(iBuf), pnOut))
		} else {
			var i int32 = 0
			var rc int32
			for __ccgo := true; __ccgo; __ccgo = int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))))&0x80 != 0 {
				rc = vdbePmaReadBlob(tls, p, 1, bp)
				if rc != 0 {
					return rc
				}
				*(*U8)(unsafe.Pointer(bp + 8 + uintptr(libc.PostIncInt32(&i, 1)&0xf))) = *(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))
			}
			Xsqlite3GetVarint(tls, bp+8, pnOut)
		}
	}

	return SQLITE_OK
}

func vdbeSorterMapFile(tls *libc.TLS, pTask uintptr, pFile uintptr, pp uintptr) int32 {
	var rc int32 = SQLITE_OK
	if (*SorterFile)(unsafe.Pointer(pFile)).FiEof <= I64((*Sqlite3)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fdb)).FnMaxSorterMmap) {
		var pFd uintptr = (*SorterFile)(unsafe.Pointer(pFile)).FpFd
		if (*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pFd)).FpMethods)).FiVersion >= 3 {
			rc = Xsqlite3OsFetch(tls, pFd, int64(0), int32((*SorterFile)(unsafe.Pointer(pFile)).FiEof), pp)

		}
	}
	return rc
}

func vdbePmaReaderSeek(tls *libc.TLS, pTask uintptr, pReadr uintptr, pFile uintptr, iOff I64) int32 {
	var rc int32 = SQLITE_OK

	if Xsqlite3FaultSim(tls, 201) != 0 {
		return SQLITE_IOERR | int32(1)<<8
	}
	if (*PmaReader)(unsafe.Pointer(pReadr)).FaMap != 0 {
		Xsqlite3OsUnfetch(tls, (*PmaReader)(unsafe.Pointer(pReadr)).FpFd, int64(0), (*PmaReader)(unsafe.Pointer(pReadr)).FaMap)
		(*PmaReader)(unsafe.Pointer(pReadr)).FaMap = uintptr(0)
	}
	(*PmaReader)(unsafe.Pointer(pReadr)).FiReadOff = iOff
	(*PmaReader)(unsafe.Pointer(pReadr)).FiEof = (*SorterFile)(unsafe.Pointer(pFile)).FiEof
	(*PmaReader)(unsafe.Pointer(pReadr)).FpFd = (*SorterFile)(unsafe.Pointer(pFile)).FpFd

	rc = vdbeSorterMapFile(tls, pTask, pFile, pReadr+64)
	if rc == SQLITE_OK && (*PmaReader)(unsafe.Pointer(pReadr)).FaMap == uintptr(0) {
		var pgsz int32 = (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fpgsz
		var iBuf int32 = int32((*PmaReader)(unsafe.Pointer(pReadr)).FiReadOff % I64(pgsz))
		if (*PmaReader)(unsafe.Pointer(pReadr)).FaBuffer == uintptr(0) {
			(*PmaReader)(unsafe.Pointer(pReadr)).FaBuffer = Xsqlite3Malloc(tls, uint64(pgsz))
			if (*PmaReader)(unsafe.Pointer(pReadr)).FaBuffer == uintptr(0) {
				rc = SQLITE_NOMEM
			}
			(*PmaReader)(unsafe.Pointer(pReadr)).FnBuffer = pgsz
		}
		if rc == SQLITE_OK && iBuf != 0 {
			var nRead int32 = pgsz - iBuf
			if (*PmaReader)(unsafe.Pointer(pReadr)).FiReadOff+I64(nRead) > (*PmaReader)(unsafe.Pointer(pReadr)).FiEof {
				nRead = int32((*PmaReader)(unsafe.Pointer(pReadr)).FiEof - (*PmaReader)(unsafe.Pointer(pReadr)).FiReadOff)
			}
			rc = Xsqlite3OsRead(tls,
				(*PmaReader)(unsafe.Pointer(pReadr)).FpFd, (*PmaReader)(unsafe.Pointer(pReadr)).FaBuffer+uintptr(iBuf), nRead, (*PmaReader)(unsafe.Pointer(pReadr)).FiReadOff)

		}
	}

	return rc
}

func vdbePmaReaderNext(tls *libc.TLS, pReadr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	*(*U64)(unsafe.Pointer(bp)) = uint64(0)

	if (*PmaReader)(unsafe.Pointer(pReadr)).FiReadOff >= (*PmaReader)(unsafe.Pointer(pReadr)).FiEof {
		var pIncr uintptr = (*PmaReader)(unsafe.Pointer(pReadr)).FpIncr
		var bEof int32 = 1
		if pIncr != 0 {
			rc = vdbeIncrSwap(tls, pIncr)
			if rc == SQLITE_OK && (*IncrMerger)(unsafe.Pointer(pIncr)).FbEof == 0 {
				rc = vdbePmaReaderSeek(tls,
					(*IncrMerger)(unsafe.Pointer(pIncr)).FpTask, pReadr, pIncr+40, (*IncrMerger)(unsafe.Pointer(pIncr)).FiStartOff)
				bEof = 0
			}
		}

		if bEof != 0 {
			vdbePmaReaderClear(tls, pReadr)

			return rc
		}
	}

	if rc == SQLITE_OK {
		rc = vdbePmaReadVarint(tls, pReadr, bp)
	}
	if rc == SQLITE_OK {
		(*PmaReader)(unsafe.Pointer(pReadr)).FnKey = int32(*(*U64)(unsafe.Pointer(bp)))
		rc = vdbePmaReadBlob(tls, pReadr, int32(*(*U64)(unsafe.Pointer(bp))), pReadr+40)

	}

	return rc
}

func vdbePmaReaderInit(tls *libc.TLS, pTask uintptr, pFile uintptr, iStart I64, pReadr uintptr, pnByte uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	rc = vdbePmaReaderSeek(tls, pTask, pReadr, pFile, iStart)
	if rc == SQLITE_OK {
		*(*U64)(unsafe.Pointer(bp)) = uint64(0)
		rc = vdbePmaReadVarint(tls, pReadr, bp)
		(*PmaReader)(unsafe.Pointer(pReadr)).FiEof = I64(U64((*PmaReader)(unsafe.Pointer(pReadr)).FiReadOff) + *(*U64)(unsafe.Pointer(bp)))
		*(*I64)(unsafe.Pointer(pnByte)) += I64(*(*U64)(unsafe.Pointer(bp)))
	}

	if rc == SQLITE_OK {
		rc = vdbePmaReaderNext(tls, pReadr)
	}
	return rc
}

func vdbeSorterCompareTail(tls *libc.TLS, pTask uintptr, pbKey2Cached uintptr, pKey1 uintptr, nKey1 int32, pKey2 uintptr, nKey2 int32) int32 {
	var r2 uintptr = (*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked
	if *(*int32)(unsafe.Pointer(pbKey2Cached)) == 0 {
		Xsqlite3VdbeRecordUnpack(tls, (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo, nKey2, pKey2, r2)
		*(*int32)(unsafe.Pointer(pbKey2Cached)) = 1
	}
	return Xsqlite3VdbeRecordCompareWithSkip(tls, nKey1, pKey1, r2, 1)
}

func vdbeSorterCompare(tls *libc.TLS, pTask uintptr, pbKey2Cached uintptr, pKey1 uintptr, nKey1 int32, pKey2 uintptr, nKey2 int32) int32 {
	var r2 uintptr = (*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked
	if !(*(*int32)(unsafe.Pointer(pbKey2Cached)) != 0) {
		Xsqlite3VdbeRecordUnpack(tls, (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo, nKey2, pKey2, r2)
		*(*int32)(unsafe.Pointer(pbKey2Cached)) = 1
	}
	return Xsqlite3VdbeRecordCompare(tls, nKey1, pKey1, r2)
}

func vdbeSorterCompareText(tls *libc.TLS, pTask uintptr, pbKey2Cached uintptr, pKey1 uintptr, nKey1 int32, pKey2 uintptr, nKey2 int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p1 uintptr = pKey1
	var p2 uintptr = pKey2
	var v1 uintptr = p1 + uintptr(*(*U8)(unsafe.Pointer(p1)))
	var v2 uintptr = p2 + uintptr(*(*U8)(unsafe.Pointer(p2)))

	var res int32

	*(*int32)(unsafe.Pointer(bp)) = int32(U32(*(*U8)(unsafe.Pointer(p1 + 1))))
	if *(*int32)(unsafe.Pointer(bp)) >= 0x80 {
		Xsqlite3GetVarint32(tls, p1+1, bp)
	}
	*(*int32)(unsafe.Pointer(bp + 4)) = int32(U32(*(*U8)(unsafe.Pointer(p2 + 1))))
	if *(*int32)(unsafe.Pointer(bp + 4)) >= 0x80 {
		Xsqlite3GetVarint32(tls, p2+1, bp+4)
	}
	res = libc.Xmemcmp(tls, v1, v2, uint64((func() int32 {
		if *(*int32)(unsafe.Pointer(bp)) < *(*int32)(unsafe.Pointer(bp + 4)) {
			return *(*int32)(unsafe.Pointer(bp))
		}
		return *(*int32)(unsafe.Pointer(bp + 4))
	}()-13)/2))
	if res == 0 {
		res = *(*int32)(unsafe.Pointer(bp)) - *(*int32)(unsafe.Pointer(bp + 4))
	}

	if res == 0 {
		if int32((*KeyInfo)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FnKeyField) > 1 {
			res = vdbeSorterCompareTail(tls,
				pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2)
		}
	} else {
		if *(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FaSortFlags)) != 0 {
			res = res * -1
		}
	}

	return res
}

func vdbeSorterCompareInt(tls *libc.TLS, pTask uintptr, pbKey2Cached uintptr, pKey1 uintptr, nKey1 int32, pKey2 uintptr, nKey2 int32) int32 {
	var p1 uintptr = pKey1
	var p2 uintptr = pKey2
	var s1 int32 = int32(*(*U8)(unsafe.Pointer(p1 + 1)))
	var s2 int32 = int32(*(*U8)(unsafe.Pointer(p2 + 1)))
	var v1 uintptr = p1 + uintptr(*(*U8)(unsafe.Pointer(p1)))
	var v2 uintptr = p2 + uintptr(*(*U8)(unsafe.Pointer(p2)))
	var res int32

	if s1 == s2 {
		var n U8 = aLen[s1]
		var i int32
		res = 0
		for i = 0; i < int32(n); i++ {
			if libc.AssignInt32(&res, int32(*(*U8)(unsafe.Pointer(v1 + uintptr(i))))-int32(*(*U8)(unsafe.Pointer(v2 + uintptr(i))))) != 0 {
				if (int32(*(*U8)(unsafe.Pointer(v1)))^int32(*(*U8)(unsafe.Pointer(v2))))&0x80 != 0 {
					if int32(*(*U8)(unsafe.Pointer(v1)))&0x80 != 0 {
						res = -1
					} else {
						res = +1
					}
				}
				break
			}
		}
	} else if s1 > 7 && s2 > 7 {
		res = s1 - s2
	} else {
		if s2 > 7 {
			res = +1
		} else if s1 > 7 {
			res = -1
		} else {
			res = s1 - s2
		}

		if res > 0 {
			if int32(*(*U8)(unsafe.Pointer(v1)))&0x80 != 0 {
				res = -1
			}
		} else {
			if int32(*(*U8)(unsafe.Pointer(v2)))&0x80 != 0 {
				res = +1
			}
		}
	}

	if res == 0 {
		if int32((*KeyInfo)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FnKeyField) > 1 {
			res = vdbeSorterCompareTail(tls,
				pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2)
		}
	} else if *(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FaSortFlags)) != 0 {
		res = res * -1
	}

	return res
}

var aLen = [10]U8{U8(0), U8(1), U8(2), U8(3), U8(4), U8(6), U8(8), U8(0), U8(0), U8(0)}

func Xsqlite3VdbeSorterInit(tls *libc.TLS, db uintptr, nField int32, pCsr uintptr) int32 {
	var pgsz int32
	var i int32
	var pSorter uintptr
	var pKeyInfo uintptr
	var szKeyInfo int32
	var sz int32
	var rc int32 = SQLITE_OK
	var nWorker int32

	if Xsqlite3TempInMemory(tls, db) != 0 || int32(Xsqlite3Config.FbCoreMutex) == 0 {
		nWorker = 0
	} else {
		nWorker = *(*int32)(unsafe.Pointer(db + 136 + 11*4))
	}

	szKeyInfo = int32(uint64(unsafe.Sizeof(KeyInfo{})) + uint64(int32((*KeyInfo)(unsafe.Pointer((*VdbeCursor)(unsafe.Pointer(pCsr)).FpKeyInfo)).FnKeyField)-1)*uint64(unsafe.Sizeof(uintptr(0))))
	sz = int32(uint64(unsafe.Sizeof(VdbeSorter{})) + uint64(nWorker)*uint64(unsafe.Sizeof(SortSubtask{})))

	pSorter = Xsqlite3DbMallocZero(tls, db, uint64(sz+szKeyInfo))
	*(*uintptr)(unsafe.Pointer(pCsr + 48)) = pSorter
	if pSorter == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpBt
		(*VdbeSorter)(unsafe.Pointer(pSorter)).FpKeyInfo = libc.AssignUintptr(&pKeyInfo, pSorter+uintptr(sz))
		libc.Xmemcpy(tls, pKeyInfo, (*VdbeCursor)(unsafe.Pointer(pCsr)).FpKeyInfo, uint64(szKeyInfo))
		(*KeyInfo)(unsafe.Pointer(pKeyInfo)).Fdb = uintptr(0)
		if nField != 0 && nWorker == 0 {
			(*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnKeyField = U16(nField)
		}
		Xsqlite3BtreeEnter(tls, pBt)
		(*VdbeSorter)(unsafe.Pointer(pSorter)).Fpgsz = libc.AssignInt32(&pgsz, Xsqlite3BtreeGetPageSize(tls, pBt))
		Xsqlite3BtreeLeave(tls, pBt)
		(*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask = U8(nWorker + 1)
		(*VdbeSorter)(unsafe.Pointer(pSorter)).FiPrev = U8(nWorker - 1)
		(*VdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads = U8(libc.Bool32(int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask) > 1))
		(*VdbeSorter)(unsafe.Pointer(pSorter)).Fdb = db
		for i = 0; i < int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask); i++ {
			var pTask uintptr = pSorter + 96 + uintptr(i)*104
			(*SortSubtask)(unsafe.Pointer(pTask)).FpSorter = pSorter
		}

		if !(Xsqlite3TempInMemory(tls, db) != 0) {
			var mxCache I64
			var szPma U32 = Xsqlite3Config.FszPma
			(*VdbeSorter)(unsafe.Pointer(pSorter)).FmnPmaSize = int32(szPma * U32(pgsz))

			mxCache = I64((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema)).Fcache_size)
			if mxCache < int64(0) {
				mxCache = mxCache * int64(-1024)
			} else {
				mxCache = mxCache * I64(pgsz)
			}
			mxCache = func() int64 {
				if mxCache < int64(int32(1)<<29) {
					return mxCache
				}
				return int64(int32(1) << 29)
			}()
			(*VdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize = func() int32 {
				if (*VdbeSorter)(unsafe.Pointer(pSorter)).FmnPmaSize > int32(mxCache) {
					return (*VdbeSorter)(unsafe.Pointer(pSorter)).FmnPmaSize
				}
				return int32(mxCache)
			}()

			if int32(Xsqlite3Config.FbSmallMalloc) == 0 {
				(*VdbeSorter)(unsafe.Pointer(pSorter)).FnMemory = pgsz
				(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory = Xsqlite3Malloc(tls, uint64(pgsz))
				if !(int32((*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory) != 0) {
					rc = SQLITE_NOMEM
				}
			}
		}

		if int32((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnAllField) < 13 &&
			(*(*uintptr)(unsafe.Pointer(pKeyInfo + 32)) == uintptr(0) || *(*uintptr)(unsafe.Pointer(pKeyInfo + 32)) == (*Sqlite3)(unsafe.Pointer(db)).FpDfltColl) &&
			int32(*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags)))&KEYINFO_ORDER_BIGNULL == 0 {
			(*VdbeSorter)(unsafe.Pointer(pSorter)).FtypeMask = U8(SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT)
		}
	}

	return rc
}

func vdbeSorterRecordFree(tls *libc.TLS, db uintptr, pRecord uintptr) {
	var p uintptr
	var pNext uintptr
	for p = pRecord; p != 0; p = pNext {
		pNext = *(*uintptr)(unsafe.Pointer(p + 8))
		Xsqlite3DbFree(tls, db, p)
	}
}

func vdbeSortSubtaskCleanup(tls *libc.TLS, db uintptr, pTask uintptr) {
	Xsqlite3DbFree(tls, db, (*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)

	if (*SortSubtask)(unsafe.Pointer(pTask)).Flist.FaMemory != 0 {
		Xsqlite3_free(tls, (*SortSubtask)(unsafe.Pointer(pTask)).Flist.FaMemory)
	} else {
		vdbeSorterRecordFree(tls, uintptr(0), (*SortSubtask)(unsafe.Pointer(pTask)).Flist.FpList)
	}
	if (*SortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd != 0 {
		Xsqlite3OsCloseFree(tls, (*SortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd)
	}
	if (*SortSubtask)(unsafe.Pointer(pTask)).Ffile2.FpFd != 0 {
		Xsqlite3OsCloseFree(tls, (*SortSubtask)(unsafe.Pointer(pTask)).Ffile2.FpFd)
	}
	libc.Xmemset(tls, pTask, 0, uint64(unsafe.Sizeof(SortSubtask{})))
}

func vdbeSorterJoinThread(tls *libc.TLS, pTask uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	if (*SortSubtask)(unsafe.Pointer(pTask)).FpThread != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(int64(SQLITE_ERROR))

		Xsqlite3ThreadJoin(tls, (*SortSubtask)(unsafe.Pointer(pTask)).FpThread, bp)

		rc = int32(*(*uintptr)(unsafe.Pointer(bp)))

		(*SortSubtask)(unsafe.Pointer(pTask)).FbDone = 0
		(*SortSubtask)(unsafe.Pointer(pTask)).FpThread = uintptr(0)
	}
	return rc
}

func vdbeSorterCreateThread(tls *libc.TLS, pTask uintptr, xTask uintptr, pIn uintptr) int32 {
	return Xsqlite3ThreadCreate(tls, pTask, xTask, pIn)
}

func vdbeSorterJoinAll(tls *libc.TLS, pSorter uintptr, rcin int32) int32 {
	var rc int32 = rcin
	var i int32

	for i = int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask) - 1; i >= 0; i-- {
		var pTask uintptr = pSorter + 96 + uintptr(i)*104
		var rc2 int32 = vdbeSorterJoinThread(tls, pTask)
		if rc == SQLITE_OK {
			rc = rc2
		}
	}
	return rc
}

func vdbeMergeEngineNew(tls *libc.TLS, nReader int32) uintptr {
	var N int32 = 2
	var nByte int32
	var pNew uintptr

	for N < nReader {
		N = N + N
	}
	nByte = int32(uint64(unsafe.Sizeof(MergeEngine{})) + uint64(N)*(uint64(unsafe.Sizeof(int32(0)))+uint64(unsafe.Sizeof(PmaReader{}))))

	if Xsqlite3FaultSim(tls, 100) != 0 {
		pNew = uintptr(0)
	} else {
		pNew = Xsqlite3MallocZero(tls, uint64(nByte))
	}
	if pNew != 0 {
		(*MergeEngine)(unsafe.Pointer(pNew)).FnTree = N
		(*MergeEngine)(unsafe.Pointer(pNew)).FpTask = uintptr(0)
		(*MergeEngine)(unsafe.Pointer(pNew)).FaReadr = pNew + 1*32
		(*MergeEngine)(unsafe.Pointer(pNew)).FaTree = (*MergeEngine)(unsafe.Pointer(pNew)).FaReadr + uintptr(N)*80
	}
	return pNew
}

func vdbeMergeEngineFree(tls *libc.TLS, pMerger uintptr) {
	var i int32
	if pMerger != 0 {
		for i = 0; i < (*MergeEngine)(unsafe.Pointer(pMerger)).FnTree; i++ {
			vdbePmaReaderClear(tls, (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(i)*80)
		}
	}
	Xsqlite3_free(tls, pMerger)
}

func vdbeIncrFree(tls *libc.TLS, pIncr uintptr) {
	if pIncr != 0 {
		if (*IncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
			vdbeSorterJoinThread(tls, (*IncrMerger)(unsafe.Pointer(pIncr)).FpTask)
			if (*SorterFile)(unsafe.Pointer(pIncr+40)).FpFd != 0 {
				Xsqlite3OsCloseFree(tls, (*SorterFile)(unsafe.Pointer(pIncr+40)).FpFd)
			}
			if (*SorterFile)(unsafe.Pointer(pIncr+40+1*16)).FpFd != 0 {
				Xsqlite3OsCloseFree(tls, (*SorterFile)(unsafe.Pointer(pIncr+40+1*16)).FpFd)
			}
		}
		vdbeMergeEngineFree(tls, (*IncrMerger)(unsafe.Pointer(pIncr)).FpMerger)
		Xsqlite3_free(tls, pIncr)
	}
}

func Xsqlite3VdbeSorterReset(tls *libc.TLS, db uintptr, pSorter uintptr) {
	var i int32
	vdbeSorterJoinAll(tls, pSorter, SQLITE_OK)

	if (*VdbeSorter)(unsafe.Pointer(pSorter)).FpReader != 0 {
		vdbePmaReaderClear(tls, (*VdbeSorter)(unsafe.Pointer(pSorter)).FpReader)
		Xsqlite3DbFree(tls, db, (*VdbeSorter)(unsafe.Pointer(pSorter)).FpReader)
		(*VdbeSorter)(unsafe.Pointer(pSorter)).FpReader = uintptr(0)
	}
	vdbeMergeEngineFree(tls, (*VdbeSorter)(unsafe.Pointer(pSorter)).FpMerger)
	(*VdbeSorter)(unsafe.Pointer(pSorter)).FpMerger = uintptr(0)
	for i = 0; i < int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask); i++ {
		var pTask uintptr = pSorter + 96 + uintptr(i)*104
		vdbeSortSubtaskCleanup(tls, db, pTask)
		(*SortSubtask)(unsafe.Pointer(pTask)).FpSorter = pSorter
	}
	if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory == uintptr(0) {
		vdbeSorterRecordFree(tls, uintptr(0), (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList)
	}
	(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = uintptr(0)
	(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA = 0
	(*VdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA = U8(0)
	(*VdbeSorter)(unsafe.Pointer(pSorter)).FiMemory = 0
	(*VdbeSorter)(unsafe.Pointer(pSorter)).FmxKeysize = 0
	Xsqlite3DbFree(tls, db, (*VdbeSorter)(unsafe.Pointer(pSorter)).FpUnpacked)
	(*VdbeSorter)(unsafe.Pointer(pSorter)).FpUnpacked = uintptr(0)
}

func Xsqlite3VdbeSorterClose(tls *libc.TLS, db uintptr, pCsr uintptr) {
	var pSorter uintptr

	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 48))
	if pSorter != 0 {
		Xsqlite3VdbeSorterReset(tls, db, pSorter)
		Xsqlite3_free(tls, (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory)
		Xsqlite3DbFree(tls, db, pSorter)
		*(*uintptr)(unsafe.Pointer(pCsr + 48)) = uintptr(0)
	}
}

func vdbeSorterExtendFile(tls *libc.TLS, db uintptr, pFd uintptr, nByte I64) {
	bp := tls.Alloc(24)
	defer tls.Free(24)
	*(*I64)(unsafe.Pointer(bp + 8)) = nByte

	if *(*I64)(unsafe.Pointer(bp + 8)) <= I64((*Sqlite3)(unsafe.Pointer(db)).FnMaxSorterMmap) && (*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pFd)).FpMethods)).FiVersion >= 3 {
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
		*(*int32)(unsafe.Pointer(bp)) = 4 * 1024
		Xsqlite3OsFileControlHint(tls, pFd, SQLITE_FCNTL_CHUNK_SIZE, bp)
		Xsqlite3OsFileControlHint(tls, pFd, SQLITE_FCNTL_SIZE_HINT, bp+8)
		Xsqlite3OsFetch(tls, pFd, int64(0), int32(*(*I64)(unsafe.Pointer(bp + 8))), bp+16)
		if *(*uintptr)(unsafe.Pointer(bp + 16)) != 0 {
			Xsqlite3OsUnfetch(tls, pFd, int64(0), *(*uintptr)(unsafe.Pointer(bp + 16)))
		}
	}
}

func vdbeSorterOpenTempFile(tls *libc.TLS, db uintptr, nExtend I64, ppFd uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if Xsqlite3FaultSim(tls, 202) != 0 {
		return SQLITE_IOERR | int32(13)<<8
	}
	*(*int32)(unsafe.Pointer(bp)) = Xsqlite3OsOpenMalloc(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), ppFd,
		SQLITE_OPEN_TEMP_JOURNAL|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_DELETEONCLOSE, bp)
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*I64)(unsafe.Pointer(bp + 8)) = int64(SQLITE_MAX_MMAP_SIZE)
		Xsqlite3OsFileControlHint(tls, *(*uintptr)(unsafe.Pointer(ppFd)), SQLITE_FCNTL_MMAP_SIZE, bp+8)
		if nExtend > int64(0) {
			vdbeSorterExtendFile(tls, db, *(*uintptr)(unsafe.Pointer(ppFd)), nExtend)
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func vdbeSortAllocUnpacked(tls *libc.TLS, pTask uintptr) int32 {
	if (*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked == uintptr(0) {
		(*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked = Xsqlite3VdbeAllocUnpackedRecord(tls, (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)
		if (*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked == uintptr(0) {
			return SQLITE_NOMEM
		}
		(*UnpackedRecord)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FnField = (*KeyInfo)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FpKeyInfo)).FnKeyField
		(*UnpackedRecord)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FerrCode = U8(0)
	}
	return SQLITE_OK
}

func vdbeSorterMerge(tls *libc.TLS, pTask uintptr, p1 uintptr, p2 uintptr) uintptr {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var pp uintptr = bp
	*(*int32)(unsafe.Pointer(bp + 8)) = 0

	for {
		var res int32
		res = (*struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*SortSubtask)(unsafe.Pointer(pTask)).FxCompare})).f(tls,
			pTask, bp+8, p1+uintptr(1)*16, (*SorterRecord)(unsafe.Pointer(p1)).FnVal, p2+uintptr(1)*16, (*SorterRecord)(unsafe.Pointer(p2)).FnVal)

		if res <= 0 {
			*(*uintptr)(unsafe.Pointer(pp)) = p1
			pp = p1 + 8
			p1 = *(*uintptr)(unsafe.Pointer(p1 + 8))
			if p1 == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(pp)) = p2
				break
			}
		} else {
			*(*uintptr)(unsafe.Pointer(pp)) = p2
			pp = p2 + 8
			p2 = *(*uintptr)(unsafe.Pointer(p2 + 8))
			*(*int32)(unsafe.Pointer(bp + 8)) = 0
			if p2 == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(pp)) = p1
				break
			}
		}
	}
	return *(*uintptr)(unsafe.Pointer(bp))
}

func vdbeSorterGetCompare(tls *libc.TLS, p uintptr) SorterCompare {
	if int32((*VdbeSorter)(unsafe.Pointer(p)).FtypeMask) == SORTER_TYPE_INTEGER {
		return *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32
		}{vdbeSorterCompareInt}))
	} else if int32((*VdbeSorter)(unsafe.Pointer(p)).FtypeMask) == SORTER_TYPE_TEXT {
		return *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32
		}{vdbeSorterCompareText}))
	}
	return *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32
	}{vdbeSorterCompare}))
}

func vdbeSorterSort(tls *libc.TLS, pTask uintptr, pList uintptr) int32 {
	bp := tls.Alloc(512)
	defer tls.Free(512)

	var i int32
	var p uintptr
	var rc int32

	rc = vdbeSortAllocUnpacked(tls, pTask)
	if rc != SQLITE_OK {
		return rc
	}

	p = (*SorterList)(unsafe.Pointer(pList)).FpList
	(*SortSubtask)(unsafe.Pointer(pTask)).FxCompare = vdbeSorterGetCompare(tls, (*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([64]uintptr{})))

	for p != 0 {
		var pNext uintptr
		if (*SorterList)(unsafe.Pointer(pList)).FaMemory != 0 {
			if p == (*SorterList)(unsafe.Pointer(pList)).FaMemory {
				pNext = uintptr(0)
			} else {
				pNext = (*SorterList)(unsafe.Pointer(pList)).FaMemory + uintptr(*(*int32)(unsafe.Pointer(p + 8)))
			}
		} else {
			pNext = *(*uintptr)(unsafe.Pointer(p + 8))
		}

		*(*uintptr)(unsafe.Pointer(p + 8)) = uintptr(0)
		for i = 0; *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) != 0; i++ {
			p = vdbeSorterMerge(tls, pTask, p, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)))
			*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = uintptr(0)
		}
		*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = p
		p = pNext
	}

	p = uintptr(0)
	for i = 0; i < int32(uint64(unsafe.Sizeof([64]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0)))); i++ {
		if *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) == uintptr(0) {
			continue
		}
		if p != 0 {
			p = vdbeSorterMerge(tls, pTask, p, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)))
		} else {
			p = *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8))
		}
	}
	(*SorterList)(unsafe.Pointer(pList)).FpList = p

	return int32((*UnpackedRecord)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FerrCode)
}

func vdbePmaWriterInit(tls *libc.TLS, pFd uintptr, p uintptr, nBuf int32, iStart I64) {
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(PmaWriter{})))
	(*PmaWriter)(unsafe.Pointer(p)).FaBuffer = Xsqlite3Malloc(tls, uint64(nBuf))
	if !(int32((*PmaWriter)(unsafe.Pointer(p)).FaBuffer) != 0) {
		(*PmaWriter)(unsafe.Pointer(p)).FeFWErr = SQLITE_NOMEM
	} else {
		(*PmaWriter)(unsafe.Pointer(p)).FiBufEnd = libc.AssignPtrInt32(p+20, int32(iStart%I64(nBuf)))
		(*PmaWriter)(unsafe.Pointer(p)).FiWriteOff = iStart - I64((*PmaWriter)(unsafe.Pointer(p)).FiBufStart)
		(*PmaWriter)(unsafe.Pointer(p)).FnBuffer = nBuf
		(*PmaWriter)(unsafe.Pointer(p)).FpFd = pFd
	}
}

func vdbePmaWriteBlob(tls *libc.TLS, p uintptr, pData uintptr, nData int32) {
	var nRem int32 = nData
	for nRem > 0 && (*PmaWriter)(unsafe.Pointer(p)).FeFWErr == 0 {
		var nCopy int32 = nRem
		if nCopy > (*PmaWriter)(unsafe.Pointer(p)).FnBuffer-(*PmaWriter)(unsafe.Pointer(p)).FiBufEnd {
			nCopy = (*PmaWriter)(unsafe.Pointer(p)).FnBuffer - (*PmaWriter)(unsafe.Pointer(p)).FiBufEnd
		}

		libc.Xmemcpy(tls, (*PmaWriter)(unsafe.Pointer(p)).FaBuffer+uintptr((*PmaWriter)(unsafe.Pointer(p)).FiBufEnd), pData+uintptr(nData-nRem), uint64(nCopy))
		*(*int32)(unsafe.Pointer(p + 24)) += nCopy
		if (*PmaWriter)(unsafe.Pointer(p)).FiBufEnd == (*PmaWriter)(unsafe.Pointer(p)).FnBuffer {
			(*PmaWriter)(unsafe.Pointer(p)).FeFWErr = Xsqlite3OsWrite(tls, (*PmaWriter)(unsafe.Pointer(p)).FpFd,
				(*PmaWriter)(unsafe.Pointer(p)).FaBuffer+uintptr((*PmaWriter)(unsafe.Pointer(p)).FiBufStart), (*PmaWriter)(unsafe.Pointer(p)).FiBufEnd-(*PmaWriter)(unsafe.Pointer(p)).FiBufStart,
				(*PmaWriter)(unsafe.Pointer(p)).FiWriteOff+I64((*PmaWriter)(unsafe.Pointer(p)).FiBufStart))
			(*PmaWriter)(unsafe.Pointer(p)).FiBufStart = libc.AssignPtrInt32(p+24, 0)
			*(*I64)(unsafe.Pointer(p + 32)) += I64((*PmaWriter)(unsafe.Pointer(p)).FnBuffer)
		}

		nRem = nRem - nCopy
	}
}

func vdbePmaWriterFinish(tls *libc.TLS, p uintptr, piEof uintptr) int32 {
	var rc int32
	if (*PmaWriter)(unsafe.Pointer(p)).FeFWErr == 0 && (*PmaWriter)(unsafe.Pointer(p)).FaBuffer != 0 && (*PmaWriter)(unsafe.Pointer(p)).FiBufEnd > (*PmaWriter)(unsafe.Pointer(p)).FiBufStart {
		(*PmaWriter)(unsafe.Pointer(p)).FeFWErr = Xsqlite3OsWrite(tls, (*PmaWriter)(unsafe.Pointer(p)).FpFd,
			(*PmaWriter)(unsafe.Pointer(p)).FaBuffer+uintptr((*PmaWriter)(unsafe.Pointer(p)).FiBufStart), (*PmaWriter)(unsafe.Pointer(p)).FiBufEnd-(*PmaWriter)(unsafe.Pointer(p)).FiBufStart,
			(*PmaWriter)(unsafe.Pointer(p)).FiWriteOff+I64((*PmaWriter)(unsafe.Pointer(p)).FiBufStart))
	}
	*(*I64)(unsafe.Pointer(piEof)) = (*PmaWriter)(unsafe.Pointer(p)).FiWriteOff + I64((*PmaWriter)(unsafe.Pointer(p)).FiBufEnd)
	Xsqlite3_free(tls, (*PmaWriter)(unsafe.Pointer(p)).FaBuffer)
	rc = (*PmaWriter)(unsafe.Pointer(p)).FeFWErr
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(PmaWriter{})))
	return rc
}

func vdbePmaWriteVarint(tls *libc.TLS, p uintptr, iVal U64) {
	bp := tls.Alloc(10)
	defer tls.Free(10)

	var nByte int32

	nByte = Xsqlite3PutVarint(tls, bp, iVal)
	vdbePmaWriteBlob(tls, p, bp, nByte)
}

func vdbeSorterListToPMA(tls *libc.TLS, pTask uintptr, pList uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var db uintptr = (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fdb
	var rc int32 = SQLITE_OK

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(PmaWriter{})))

	if (*SortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd == uintptr(0) {
		rc = vdbeSorterOpenTempFile(tls, db, int64(0), pTask+72)

	}

	if rc == SQLITE_OK {
		vdbeSorterExtendFile(tls, db, (*SortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd, (*SortSubtask)(unsafe.Pointer(pTask)).Ffile.FiEof+I64((*SorterList)(unsafe.Pointer(pList)).FszPMA)+int64(9))
	}

	if rc == SQLITE_OK {
		rc = vdbeSorterSort(tls, pTask, pList)
	}

	if rc == SQLITE_OK {
		var p uintptr
		var pNext uintptr = uintptr(0)

		vdbePmaWriterInit(tls, (*SortSubtask)(unsafe.Pointer(pTask)).Ffile.FpFd, bp, (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fpgsz,
			(*SortSubtask)(unsafe.Pointer(pTask)).Ffile.FiEof)
		(*SortSubtask)(unsafe.Pointer(pTask)).FnPMA++
		vdbePmaWriteVarint(tls, bp, uint64((*SorterList)(unsafe.Pointer(pList)).FszPMA))
		for p = (*SorterList)(unsafe.Pointer(pList)).FpList; p != 0; p = pNext {
			pNext = *(*uintptr)(unsafe.Pointer(p + 8))
			vdbePmaWriteVarint(tls, bp, uint64((*SorterRecord)(unsafe.Pointer(p)).FnVal))
			vdbePmaWriteBlob(tls, bp, p+uintptr(1)*16, (*SorterRecord)(unsafe.Pointer(p)).FnVal)
			if (*SorterList)(unsafe.Pointer(pList)).FaMemory == uintptr(0) {
				Xsqlite3_free(tls, p)
			}
		}
		(*SorterList)(unsafe.Pointer(pList)).FpList = p
		rc = vdbePmaWriterFinish(tls, bp, pTask+72+8)
	}

	return rc
}

func vdbeMergeEngineStep(tls *libc.TLS, pMerger uintptr, pbEof uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32
	var iPrev int32 = *(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + 1*4))
	var pTask uintptr = (*MergeEngine)(unsafe.Pointer(pMerger)).FpTask

	rc = vdbePmaReaderNext(tls, (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(iPrev)*80)

	if rc == SQLITE_OK {
		var i int32
		var pReadr1 uintptr
		var pReadr2 uintptr
		*(*int32)(unsafe.Pointer(bp)) = 0

		pReadr1 = (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(iPrev&0xFFFE)*80
		pReadr2 = (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(iPrev|0x0001)*80

		for i = ((*MergeEngine)(unsafe.Pointer(pMerger)).FnTree + iPrev) / 2; i > 0; i = i / 2 {
			var iRes int32
			if (*PmaReader)(unsafe.Pointer(pReadr1)).FpFd == uintptr(0) {
				iRes = +1
			} else if (*PmaReader)(unsafe.Pointer(pReadr2)).FpFd == uintptr(0) {
				iRes = -1
			} else {
				iRes = (*struct {
					f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*SortSubtask)(unsafe.Pointer(pTask)).FxCompare})).f(tls, pTask, bp,
					(*PmaReader)(unsafe.Pointer(pReadr1)).FaKey, (*PmaReader)(unsafe.Pointer(pReadr1)).FnKey, (*PmaReader)(unsafe.Pointer(pReadr2)).FaKey, (*PmaReader)(unsafe.Pointer(pReadr2)).FnKey)
			}

			if iRes < 0 || iRes == 0 && pReadr1 < pReadr2 {
				*(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(i)*4)) = int32((int64(pReadr1) - int64((*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr)) / 80)
				pReadr2 = (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(i^0x0001)*4)))*80
				*(*int32)(unsafe.Pointer(bp)) = 0
			} else {
				if (*PmaReader)(unsafe.Pointer(pReadr1)).FpFd != 0 {
					*(*int32)(unsafe.Pointer(bp)) = 0
				}
				*(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(i)*4)) = int32((int64(pReadr2) - int64((*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr)) / 80)
				pReadr1 = (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(i^0x0001)*4)))*80
			}
		}
		*(*int32)(unsafe.Pointer(pbEof)) = libc.Bool32((*PmaReader)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(*(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + 1*4)))*80)).FpFd == uintptr(0))
	}

	return func() int32 {
		if rc == SQLITE_OK {
			return int32((*UnpackedRecord)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FerrCode)
		}
		return rc
	}()
}

func vdbeSorterFlushThread(tls *libc.TLS, pCtx uintptr) uintptr {
	var pTask uintptr = pCtx
	var rc int32

	rc = vdbeSorterListToPMA(tls, pTask, pTask+32)
	(*SortSubtask)(unsafe.Pointer(pTask)).FbDone = 1
	return uintptr(int64(rc))
}

func vdbeSorterFlushPMA(tls *libc.TLS, pSorter uintptr) int32 {
	var rc int32 = SQLITE_OK
	var i int32
	var pTask uintptr = uintptr(0)
	var nWorker int32 = int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask) - 1

	(*VdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA = U8(1)

	for i = 0; i < nWorker; i++ {
		var iTest int32 = (int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FiPrev) + i + 1) % nWorker
		pTask = pSorter + 96 + uintptr(iTest)*104
		if (*SortSubtask)(unsafe.Pointer(pTask)).FbDone != 0 {
			rc = vdbeSorterJoinThread(tls, pTask)
		}
		if rc != SQLITE_OK || (*SortSubtask)(unsafe.Pointer(pTask)).FpThread == uintptr(0) {
			break
		}
	}

	if rc == SQLITE_OK {
		if i == nWorker {
			rc = vdbeSorterListToPMA(tls, pSorter+96+uintptr(nWorker)*104, pSorter+56)
		} else {
			var aMem uintptr
			var pCtx uintptr

			aMem = (*SortSubtask)(unsafe.Pointer(pTask)).Flist.FaMemory
			pCtx = pTask
			(*VdbeSorter)(unsafe.Pointer(pSorter)).FiPrev = U8(int64((pTask - (pSorter + 96)) / 104))
			(*SortSubtask)(unsafe.Pointer(pTask)).Flist = (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist
			(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = uintptr(0)
			(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA = 0
			if aMem != 0 {
				(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory = aMem
				(*VdbeSorter)(unsafe.Pointer(pSorter)).FnMemory = Xsqlite3MallocSize(tls, aMem)
			} else if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory != 0 {
				(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory = Xsqlite3Malloc(tls, uint64((*VdbeSorter)(unsafe.Pointer(pSorter)).FnMemory))
				if !(int32((*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory) != 0) {
					return SQLITE_NOMEM
				}
			}

			rc = vdbeSorterCreateThread(tls, pTask, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr) uintptr
			}{vdbeSorterFlushThread})), pCtx)
		}
	}

	return rc
}

func Xsqlite3VdbeSorterWrite(tls *libc.TLS, pCsr uintptr, pVal uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pSorter uintptr
	var rc int32 = SQLITE_OK
	var pNew uintptr
	var bFlush int32
	var nReq int32
	var nPMA int32

	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 48))
	*(*int32)(unsafe.Pointer(bp)) = int32(U32(*(*U8)(unsafe.Pointer((*Mem)(unsafe.Pointer(pVal)).Fz + 1))))
	if *(*int32)(unsafe.Pointer(bp)) >= 0x80 {
		Xsqlite3GetVarint32(tls, (*Mem)(unsafe.Pointer(pVal)).Fz+1, bp)
	}
	if *(*int32)(unsafe.Pointer(bp)) > 0 && *(*int32)(unsafe.Pointer(bp)) < 10 && *(*int32)(unsafe.Pointer(bp)) != 7 {
		*(*U8)(unsafe.Pointer(pSorter + 92)) &= U8(SORTER_TYPE_INTEGER)
	} else if *(*int32)(unsafe.Pointer(bp)) > 10 && *(*int32)(unsafe.Pointer(bp))&0x01 != 0 {
		*(*U8)(unsafe.Pointer(pSorter + 92)) &= U8(SORTER_TYPE_TEXT)
	} else {
		(*VdbeSorter)(unsafe.Pointer(pSorter)).FtypeMask = U8(0)
	}

	nReq = int32(uint64((*Mem)(unsafe.Pointer(pVal)).Fn) + uint64(unsafe.Sizeof(SorterRecord{})))
	nPMA = (*Mem)(unsafe.Pointer(pVal)).Fn + Xsqlite3VarintLen(tls, uint64((*Mem)(unsafe.Pointer(pVal)).Fn))
	if (*VdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize != 0 {
		if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory != 0 {
			bFlush = libc.Bool32((*VdbeSorter)(unsafe.Pointer(pSorter)).FiMemory != 0 && (*VdbeSorter)(unsafe.Pointer(pSorter)).FiMemory+nReq > (*VdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize)
		} else {
			bFlush = libc.Bool32((*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA > (*VdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize ||
				(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA > (*VdbeSorter)(unsafe.Pointer(pSorter)).FmnPmaSize && Xsqlite3HeapNearlyFull(tls) != 0)
		}
		if bFlush != 0 {
			rc = vdbeSorterFlushPMA(tls, pSorter)
			(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FszPMA = 0
			(*VdbeSorter)(unsafe.Pointer(pSorter)).FiMemory = 0

		}
	}

	*(*int32)(unsafe.Pointer(pSorter + 56 + 16)) += nPMA
	if nPMA > (*VdbeSorter)(unsafe.Pointer(pSorter)).FmxKeysize {
		(*VdbeSorter)(unsafe.Pointer(pSorter)).FmxKeysize = nPMA
	}

	if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory != 0 {
		var nMin int32 = (*VdbeSorter)(unsafe.Pointer(pSorter)).FiMemory + nReq

		if nMin > (*VdbeSorter)(unsafe.Pointer(pSorter)).FnMemory {
			var aNew uintptr
			var nNew Sqlite3_int64 = int64(2) * Sqlite3_int64((*VdbeSorter)(unsafe.Pointer(pSorter)).FnMemory)
			var iListOff int32 = -1
			if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
				iListOff = int32((int64((*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList) - int64((*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory)) / 1)
			}
			for nNew < Sqlite3_int64(nMin) {
				nNew = nNew * int64(2)
			}
			if nNew > Sqlite3_int64((*VdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize) {
				nNew = Sqlite3_int64((*VdbeSorter)(unsafe.Pointer(pSorter)).FmxPmaSize)
			}
			if nNew < Sqlite3_int64(nMin) {
				nNew = Sqlite3_int64(nMin)
			}
			aNew = Xsqlite3Realloc(tls, (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory, uint64(nNew))
			if !(aNew != 0) {
				return SQLITE_NOMEM
			}
			if iListOff >= 0 {
				(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = aNew + uintptr(iListOff)
			}
			(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory = aNew
			(*VdbeSorter)(unsafe.Pointer(pSorter)).FnMemory = int32(nNew)
		}

		pNew = (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory + uintptr((*VdbeSorter)(unsafe.Pointer(pSorter)).FiMemory)
		*(*int32)(unsafe.Pointer(pSorter + 80)) += (nReq + 7) & libc.CplInt32(7)
		if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
			*(*int32)(unsafe.Pointer(pNew + 8)) = int32((int64((*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList) - int64((*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory)) / 1)
		}
	} else {
		pNew = Xsqlite3Malloc(tls, uint64(nReq))
		if pNew == uintptr(0) {
			return SQLITE_NOMEM
		}
		*(*uintptr)(unsafe.Pointer(pNew + 8)) = (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList
	}

	libc.Xmemcpy(tls, pNew+uintptr(1)*16, (*Mem)(unsafe.Pointer(pVal)).Fz, uint64((*Mem)(unsafe.Pointer(pVal)).Fn))
	(*SorterRecord)(unsafe.Pointer(pNew)).FnVal = (*Mem)(unsafe.Pointer(pVal)).Fn
	(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = pNew

	return rc
}

func vdbeIncrPopulate(tls *libc.TLS, pIncr uintptr) int32 {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var rc int32 = SQLITE_OK
	var rc2 int32
	var iStart I64 = (*IncrMerger)(unsafe.Pointer(pIncr)).FiStartOff
	var pOut uintptr = pIncr + 40 + 1*16
	var pTask uintptr = (*IncrMerger)(unsafe.Pointer(pIncr)).FpTask
	var pMerger uintptr = (*IncrMerger)(unsafe.Pointer(pIncr)).FpMerger

	vdbePmaWriterInit(tls, (*SorterFile)(unsafe.Pointer(pOut)).FpFd, bp, (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fpgsz, iStart)
	for rc == SQLITE_OK {
		var pReader uintptr = (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + 1*4)))*80
		var nKey int32 = (*PmaReader)(unsafe.Pointer(pReader)).FnKey
		var iEof I64 = (*PmaWriter)(unsafe.Pointer(bp)).FiWriteOff + I64((*PmaWriter)(unsafe.Pointer(bp)).FiBufEnd)

		if (*PmaReader)(unsafe.Pointer(pReader)).FpFd == uintptr(0) {
			break
		}
		if iEof+I64(nKey)+I64(Xsqlite3VarintLen(tls, uint64(nKey))) > iStart+I64((*IncrMerger)(unsafe.Pointer(pIncr)).FmxSz) {
			break
		}

		vdbePmaWriteVarint(tls, bp, uint64(nKey))
		vdbePmaWriteBlob(tls, bp, (*PmaReader)(unsafe.Pointer(pReader)).FaKey, nKey)

		rc = vdbeMergeEngineStep(tls, (*IncrMerger)(unsafe.Pointer(pIncr)).FpMerger, bp+48)
	}

	rc2 = vdbePmaWriterFinish(tls, bp, pOut+8)
	if rc == SQLITE_OK {
		rc = rc2
	}

	return rc
}

func vdbeIncrPopulateThread(tls *libc.TLS, pCtx uintptr) uintptr {
	var pIncr uintptr = pCtx
	var pRet uintptr = uintptr(int64(vdbeIncrPopulate(tls, pIncr)))
	(*SortSubtask)(unsafe.Pointer((*IncrMerger)(unsafe.Pointer(pIncr)).FpTask)).FbDone = 1
	return pRet
}

func vdbeIncrBgPopulate(tls *libc.TLS, pIncr uintptr) int32 {
	var p uintptr = pIncr

	return vdbeSorterCreateThread(tls, (*IncrMerger)(unsafe.Pointer(pIncr)).FpTask, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) uintptr
	}{vdbeIncrPopulateThread})), p)
}

func vdbeIncrSwap(tls *libc.TLS, pIncr uintptr) int32 {
	var rc int32 = SQLITE_OK

	if (*IncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
		rc = vdbeSorterJoinThread(tls, (*IncrMerger)(unsafe.Pointer(pIncr)).FpTask)

		if rc == SQLITE_OK {
			var f0 = *(*SorterFile)(unsafe.Pointer(pIncr + 40))
			*(*SorterFile)(unsafe.Pointer(pIncr + 40)) = *(*SorterFile)(unsafe.Pointer(pIncr + 40 + 1*16))
			*(*SorterFile)(unsafe.Pointer(pIncr + 40 + 1*16)) = f0
		}

		if rc == SQLITE_OK {
			if (*SorterFile)(unsafe.Pointer(pIncr+40)).FiEof == (*IncrMerger)(unsafe.Pointer(pIncr)).FiStartOff {
				(*IncrMerger)(unsafe.Pointer(pIncr)).FbEof = 1
			} else {
				rc = vdbeIncrBgPopulate(tls, pIncr)
			}
		}
	} else {
		rc = vdbeIncrPopulate(tls, pIncr)
		*(*SorterFile)(unsafe.Pointer(pIncr + 40)) = *(*SorterFile)(unsafe.Pointer(pIncr + 40 + 1*16))
		if (*SorterFile)(unsafe.Pointer(pIncr+40)).FiEof == (*IncrMerger)(unsafe.Pointer(pIncr)).FiStartOff {
			(*IncrMerger)(unsafe.Pointer(pIncr)).FbEof = 1
		}
	}

	return rc
}

func vdbeIncrMergerNew(tls *libc.TLS, pTask uintptr, pMerger uintptr, ppOut uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pIncr uintptr = libc.AssignPtrUintptr(ppOut, func() uintptr {
		if Xsqlite3FaultSim(tls, 100) != 0 {
			return uintptr(0)
		}
		return Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(IncrMerger{})))
	}())
	if pIncr != 0 {
		(*IncrMerger)(unsafe.Pointer(pIncr)).FpMerger = pMerger
		(*IncrMerger)(unsafe.Pointer(pIncr)).FpTask = pTask
		(*IncrMerger)(unsafe.Pointer(pIncr)).FmxSz = func() int32 {
			if (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FmxKeysize+9 > (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FmxPmaSize/2 {
				return (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FmxKeysize + 9
			}
			return (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).FmxPmaSize / 2
		}()
		*(*I64)(unsafe.Pointer(pTask + 88 + 8)) += I64((*IncrMerger)(unsafe.Pointer(pIncr)).FmxSz)
	} else {
		vdbeMergeEngineFree(tls, pMerger)
		rc = SQLITE_NOMEM
	}

	return rc
}

func vdbeIncrMergerSetThreads(tls *libc.TLS, pIncr uintptr) {
	(*IncrMerger)(unsafe.Pointer(pIncr)).FbUseThread = 1
	*(*I64)(unsafe.Pointer((*IncrMerger)(unsafe.Pointer(pIncr)).FpTask + 88 + 8)) -= I64((*IncrMerger)(unsafe.Pointer(pIncr)).FmxSz)
}

func vdbeMergeEngineCompare(tls *libc.TLS, pMerger uintptr, iOut int32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var i1 int32
	var i2 int32
	var iRes int32
	var p1 uintptr
	var p2 uintptr

	if iOut >= (*MergeEngine)(unsafe.Pointer(pMerger)).FnTree/2 {
		i1 = (iOut - (*MergeEngine)(unsafe.Pointer(pMerger)).FnTree/2) * 2
		i2 = i1 + 1
	} else {
		i1 = *(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(iOut*2)*4))
		i2 = *(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(iOut*2+1)*4))
	}

	p1 = (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(i1)*80
	p2 = (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr + uintptr(i2)*80

	if (*PmaReader)(unsafe.Pointer(p1)).FpFd == uintptr(0) {
		iRes = i2
	} else if (*PmaReader)(unsafe.Pointer(p2)).FpFd == uintptr(0) {
		iRes = i1
	} else {
		var pTask uintptr = (*MergeEngine)(unsafe.Pointer(pMerger)).FpTask
		*(*int32)(unsafe.Pointer(bp)) = 0
		var res int32

		res = (*struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*SortSubtask)(unsafe.Pointer(pTask)).FxCompare})).f(tls,
			pTask, bp, (*PmaReader)(unsafe.Pointer(p1)).FaKey, (*PmaReader)(unsafe.Pointer(p1)).FnKey, (*PmaReader)(unsafe.Pointer(p2)).FaKey, (*PmaReader)(unsafe.Pointer(p2)).FnKey)
		if res <= 0 {
			iRes = i1
		} else {
			iRes = i2
		}
	}

	*(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(pMerger)).FaTree + uintptr(iOut)*4)) = iRes
}

func vdbeMergeEngineInit(tls *libc.TLS, pTask uintptr, pMerger uintptr, eMode int32) int32 {
	var rc int32 = SQLITE_OK
	var i int32
	var nTree int32

	(*MergeEngine)(unsafe.Pointer(pMerger)).FpTask = pTask

	nTree = (*MergeEngine)(unsafe.Pointer(pMerger)).FnTree
	for i = 0; i < nTree; i++ {
		if SQLITE_MAX_WORKER_THREADS > 0 && eMode == INCRINIT_ROOT {
			rc = vdbePmaReaderNext(tls, (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(nTree-i-1)*80)
		} else {
			rc = vdbePmaReaderIncrInit(tls, (*MergeEngine)(unsafe.Pointer(pMerger)).FaReadr+uintptr(i)*80, INCRINIT_NORMAL)
		}
		if rc != SQLITE_OK {
			return rc
		}
	}

	for i = (*MergeEngine)(unsafe.Pointer(pMerger)).FnTree - 1; i > 0; i-- {
		vdbeMergeEngineCompare(tls, pMerger, i)
	}
	return int32((*UnpackedRecord)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpUnpacked)).FerrCode)
}

func vdbePmaReaderIncrMergeInit(tls *libc.TLS, pReadr uintptr, eMode int32) int32 {
	var rc int32 = SQLITE_OK
	var pIncr uintptr = (*PmaReader)(unsafe.Pointer(pReadr)).FpIncr
	var pTask uintptr = (*IncrMerger)(unsafe.Pointer(pIncr)).FpTask
	var db uintptr = (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask)).FpSorter)).Fdb

	rc = vdbeMergeEngineInit(tls, pTask, (*IncrMerger)(unsafe.Pointer(pIncr)).FpMerger, eMode)

	if rc == SQLITE_OK {
		var mxSz int32 = (*IncrMerger)(unsafe.Pointer(pIncr)).FmxSz
		if (*IncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
			rc = vdbeSorterOpenTempFile(tls, db, int64(mxSz), pIncr+40)
			if rc == SQLITE_OK {
				rc = vdbeSorterOpenTempFile(tls, db, int64(mxSz), pIncr+40+1*16)
			}
		} else {
			if (*SortSubtask)(unsafe.Pointer(pTask)).Ffile2.FpFd == uintptr(0) {
				rc = vdbeSorterOpenTempFile(tls, db, (*SortSubtask)(unsafe.Pointer(pTask)).Ffile2.FiEof, pTask+88)
				(*SortSubtask)(unsafe.Pointer(pTask)).Ffile2.FiEof = int64(0)
			}
			if rc == SQLITE_OK {
				(*SorterFile)(unsafe.Pointer(pIncr + 40 + 1*16)).FpFd = (*SortSubtask)(unsafe.Pointer(pTask)).Ffile2.FpFd
				(*IncrMerger)(unsafe.Pointer(pIncr)).FiStartOff = (*SortSubtask)(unsafe.Pointer(pTask)).Ffile2.FiEof
				*(*I64)(unsafe.Pointer(pTask + 88 + 8)) += I64(mxSz)
			}
		}
	}

	if rc == SQLITE_OK && (*IncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
		rc = vdbeIncrPopulate(tls, pIncr)
	}

	if rc == SQLITE_OK && (SQLITE_MAX_WORKER_THREADS == 0 || eMode != INCRINIT_TASK) {
		rc = vdbePmaReaderNext(tls, pReadr)
	}

	return rc
}

func vdbePmaReaderBgIncrInit(tls *libc.TLS, pCtx uintptr) uintptr {
	var pReader uintptr = pCtx
	var pRet uintptr = uintptr(int64(vdbePmaReaderIncrMergeInit(tls, pReader, INCRINIT_TASK)))
	(*SortSubtask)(unsafe.Pointer((*IncrMerger)(unsafe.Pointer((*PmaReader)(unsafe.Pointer(pReader)).FpIncr)).FpTask)).FbDone = 1
	return pRet
}

func vdbePmaReaderIncrInit(tls *libc.TLS, pReadr uintptr, eMode int32) int32 {
	var pIncr uintptr = (*PmaReader)(unsafe.Pointer(pReadr)).FpIncr
	var rc int32 = SQLITE_OK
	if pIncr != 0 {
		if (*IncrMerger)(unsafe.Pointer(pIncr)).FbUseThread != 0 {
			var pCtx uintptr = pReadr
			rc = vdbeSorterCreateThread(tls, (*IncrMerger)(unsafe.Pointer(pIncr)).FpTask, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr) uintptr
			}{vdbePmaReaderBgIncrInit})), pCtx)
		} else {
			rc = vdbePmaReaderIncrMergeInit(tls, pReadr, eMode)
		}
	}
	return rc
}

func vdbeMergeEngineLevel0(tls *libc.TLS, pTask uintptr, nPMA int32, piOffset uintptr, ppOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pNew uintptr
	var iOff I64 = *(*I64)(unsafe.Pointer(piOffset))
	var i int32
	var rc int32 = SQLITE_OK

	*(*uintptr)(unsafe.Pointer(ppOut)) = libc.AssignUintptr(&pNew, vdbeMergeEngineNew(tls, nPMA))
	if pNew == uintptr(0) {
		rc = SQLITE_NOMEM
	}

	for i = 0; i < nPMA && rc == SQLITE_OK; i++ {
		*(*I64)(unsafe.Pointer(bp)) = int64(0)
		var pReadr uintptr = (*MergeEngine)(unsafe.Pointer(pNew)).FaReadr + uintptr(i)*80
		rc = vdbePmaReaderInit(tls, pTask, pTask+72, iOff, pReadr, bp)
		iOff = (*PmaReader)(unsafe.Pointer(pReadr)).FiEof
	}

	if rc != SQLITE_OK {
		vdbeMergeEngineFree(tls, pNew)
		*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
	}
	*(*I64)(unsafe.Pointer(piOffset)) = iOff
	return rc
}

func vdbeSorterTreeDepth(tls *libc.TLS, nPMA int32) int32 {
	var nDepth int32 = 0
	var nDiv I64 = int64(SORTER_MAX_MERGE_COUNT)
	for nDiv < I64(nPMA) {
		nDiv = nDiv * int64(SORTER_MAX_MERGE_COUNT)
		nDepth++
	}
	return nDepth
}

func vdbeSorterAddToTree(tls *libc.TLS, pTask uintptr, nDepth int32, iSeq int32, pRoot uintptr, pLeaf uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var nDiv int32 = 1
	var i int32
	var p uintptr = pRoot

	rc = vdbeIncrMergerNew(tls, pTask, pLeaf, bp)

	for i = 1; i < nDepth; i++ {
		nDiv = nDiv * SORTER_MAX_MERGE_COUNT
	}

	for i = 1; i < nDepth && rc == SQLITE_OK; i++ {
		var iIter int32 = iSeq / nDiv % SORTER_MAX_MERGE_COUNT
		var pReadr uintptr = (*MergeEngine)(unsafe.Pointer(p)).FaReadr + uintptr(iIter)*80

		if (*PmaReader)(unsafe.Pointer(pReadr)).FpIncr == uintptr(0) {
			var pNew uintptr = vdbeMergeEngineNew(tls, SORTER_MAX_MERGE_COUNT)
			if pNew == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				rc = vdbeIncrMergerNew(tls, pTask, pNew, pReadr+72)
			}
		}
		if rc == SQLITE_OK {
			p = (*IncrMerger)(unsafe.Pointer((*PmaReader)(unsafe.Pointer(pReadr)).FpIncr)).FpMerger
			nDiv = nDiv / SORTER_MAX_MERGE_COUNT
		}
	}

	if rc == SQLITE_OK {
		(*PmaReader)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(p)).FaReadr + uintptr(iSeq%SORTER_MAX_MERGE_COUNT)*80)).FpIncr = *(*uintptr)(unsafe.Pointer(bp))
	} else {
		vdbeIncrFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
	return rc
}

func vdbeSorterMergeTreeBuild(tls *libc.TLS, pSorter uintptr, ppOut uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pMain uintptr = uintptr(0)
	var rc int32 = SQLITE_OK
	var iTask int32

	if int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask) > 1 {
		pMain = vdbeMergeEngineNew(tls, int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask))
		if pMain == uintptr(0) {
			rc = SQLITE_NOMEM
		}
	}

	for iTask = 0; rc == SQLITE_OK && iTask < int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask); iTask++ {
		var pTask uintptr = pSorter + 96 + uintptr(iTask)*104

		if SQLITE_MAX_WORKER_THREADS == 0 || (*SortSubtask)(unsafe.Pointer(pTask)).FnPMA != 0 {
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
			var nDepth int32 = vdbeSorterTreeDepth(tls, (*SortSubtask)(unsafe.Pointer(pTask)).FnPMA)
			*(*I64)(unsafe.Pointer(bp)) = int64(0)

			if (*SortSubtask)(unsafe.Pointer(pTask)).FnPMA <= SORTER_MAX_MERGE_COUNT {
				rc = vdbeMergeEngineLevel0(tls, pTask, (*SortSubtask)(unsafe.Pointer(pTask)).FnPMA, bp, bp+8)
			} else {
				var i int32
				var iSeq int32 = 0
				*(*uintptr)(unsafe.Pointer(bp + 8)) = vdbeMergeEngineNew(tls, SORTER_MAX_MERGE_COUNT)
				if *(*uintptr)(unsafe.Pointer(bp + 8)) == uintptr(0) {
					rc = SQLITE_NOMEM
				}
				for i = 0; i < (*SortSubtask)(unsafe.Pointer(pTask)).FnPMA && rc == SQLITE_OK; i = i + SORTER_MAX_MERGE_COUNT {
					*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
					var nReader int32

					nReader = func() int32 {
						if (*SortSubtask)(unsafe.Pointer(pTask)).FnPMA-i < SORTER_MAX_MERGE_COUNT {
							return (*SortSubtask)(unsafe.Pointer(pTask)).FnPMA - i
						}
						return SORTER_MAX_MERGE_COUNT
					}()
					rc = vdbeMergeEngineLevel0(tls, pTask, nReader, bp, bp+16)
					if rc == SQLITE_OK {
						rc = vdbeSorterAddToTree(tls, pTask, nDepth, libc.PostIncInt32(&iSeq, 1), *(*uintptr)(unsafe.Pointer(bp + 8)), *(*uintptr)(unsafe.Pointer(bp + 16)))
					}
				}
			}

			if rc == SQLITE_OK {
				if pMain != uintptr(0) {
					rc = vdbeIncrMergerNew(tls, pTask, *(*uintptr)(unsafe.Pointer(bp + 8)), (*MergeEngine)(unsafe.Pointer(pMain)).FaReadr+uintptr(iTask)*80+72)
				} else {
					pMain = *(*uintptr)(unsafe.Pointer(bp + 8))
				}
			} else {
				vdbeMergeEngineFree(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
			}
		}
	}

	if rc != SQLITE_OK {
		vdbeMergeEngineFree(tls, pMain)
		pMain = uintptr(0)
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = pMain
	return rc
}

func vdbeSorterSetupMerge(tls *libc.TLS, pSorter uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	var pTask0 uintptr = pSorter + 96
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var db uintptr = (*VdbeSorter)(unsafe.Pointer((*SortSubtask)(unsafe.Pointer(pTask0)).FpSorter)).Fdb
	var i int32
	var xCompare SorterCompare = vdbeSorterGetCompare(tls, pSorter)
	for i = 0; i < int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask); i++ {
		(*SortSubtask)(unsafe.Pointer(pSorter + 96 + uintptr(i)*104)).FxCompare = xCompare
	}

	rc = vdbeSorterMergeTreeBuild(tls, pSorter, bp)
	if rc == SQLITE_OK {
		if (*VdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads != 0 {
			var iTask int32
			var pReadr uintptr = uintptr(0)
			var pLast uintptr = pSorter + 96 + uintptr(int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask)-1)*104
			rc = vdbeSortAllocUnpacked(tls, pLast)
			if rc == SQLITE_OK {
				pReadr = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(PmaReader{})))
				(*VdbeSorter)(unsafe.Pointer(pSorter)).FpReader = pReadr
				if pReadr == uintptr(0) {
					rc = SQLITE_NOMEM
				}
			}
			if rc == SQLITE_OK {
				rc = vdbeIncrMergerNew(tls, pLast, *(*uintptr)(unsafe.Pointer(bp)), pReadr+72)
				if rc == SQLITE_OK {
					vdbeIncrMergerSetThreads(tls, (*PmaReader)(unsafe.Pointer(pReadr)).FpIncr)
					for iTask = 0; iTask < int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask)-1; iTask++ {
						var pIncr uintptr
						if libc.AssignUintptr(&pIncr, (*PmaReader)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaReadr+uintptr(iTask)*80)).FpIncr) != 0 {
							vdbeIncrMergerSetThreads(tls, pIncr)

						}
					}
					for iTask = 0; rc == SQLITE_OK && iTask < int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FnTask); iTask++ {
						var p uintptr = (*MergeEngine)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaReadr + uintptr(iTask)*80

						rc = vdbePmaReaderIncrInit(tls, p, INCRINIT_TASK)
					}
				}
				*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			}
			if rc == SQLITE_OK {
				rc = vdbePmaReaderIncrMergeInit(tls, pReadr, INCRINIT_ROOT)
			}
		} else {
			rc = vdbeMergeEngineInit(tls, pTask0, *(*uintptr)(unsafe.Pointer(bp)), INCRINIT_NORMAL)
			(*VdbeSorter)(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
}

func Xsqlite3VdbeSorterRewind(tls *libc.TLS, pCsr uintptr, pbEof uintptr) int32 {
	var pSorter uintptr
	var rc int32 = SQLITE_OK

	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 48))

	if int32((*VdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA) == 0 {
		if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
			*(*int32)(unsafe.Pointer(pbEof)) = 0
			rc = vdbeSorterSort(tls, pSorter+96, pSorter+56)
		} else {
			*(*int32)(unsafe.Pointer(pbEof)) = 1
		}
		return rc
	}

	rc = vdbeSorterFlushPMA(tls, pSorter)

	rc = vdbeSorterJoinAll(tls, pSorter, rc)

	if rc == SQLITE_OK {
		rc = vdbeSorterSetupMerge(tls, pSorter)
		*(*int32)(unsafe.Pointer(pbEof)) = 0
	}

	return rc
}

func Xsqlite3VdbeSorterNext(tls *libc.TLS, db uintptr, pCsr uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pSorter uintptr
	var rc int32

	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 48))

	if (*VdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA != 0 {
		if (*VdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads != 0 {
			rc = vdbePmaReaderNext(tls, (*VdbeSorter)(unsafe.Pointer(pSorter)).FpReader)
			if rc == SQLITE_OK && (*PmaReader)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer(pSorter)).FpReader)).FpFd == uintptr(0) {
				rc = SQLITE_DONE
			}
		} else {
			*(*int32)(unsafe.Pointer(bp)) = 0

			rc = vdbeMergeEngineStep(tls, (*VdbeSorter)(unsafe.Pointer(pSorter)).FpMerger, bp)
			if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) != 0 {
				rc = SQLITE_DONE
			}
		}
	} else {
		var pFree uintptr = (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList
		(*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = *(*uintptr)(unsafe.Pointer(pFree + 8))
		*(*uintptr)(unsafe.Pointer(pFree + 8)) = uintptr(0)
		if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory == uintptr(0) {
			vdbeSorterRecordFree(tls, db, pFree)
		}
		if (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
			rc = SQLITE_OK
		} else {
			rc = SQLITE_DONE
		}
	}
	return rc
}

func vdbeSorterRowkey(tls *libc.TLS, pSorter uintptr, pnKey uintptr) uintptr {
	var pKey uintptr
	if (*VdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA != 0 {
		var pReader uintptr
		if (*VdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads != 0 {
			pReader = (*VdbeSorter)(unsafe.Pointer(pSorter)).FpReader
		} else {
			pReader = (*MergeEngine)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer(pSorter)).FpMerger)).FaReadr + uintptr(*(*int32)(unsafe.Pointer((*MergeEngine)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer(pSorter)).FpMerger)).FaTree + 1*4)))*80
		}
		*(*int32)(unsafe.Pointer(pnKey)) = (*PmaReader)(unsafe.Pointer(pReader)).FnKey
		pKey = (*PmaReader)(unsafe.Pointer(pReader)).FaKey
	} else {
		*(*int32)(unsafe.Pointer(pnKey)) = (*SorterRecord)(unsafe.Pointer((*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList)).FnVal
		pKey = (*VdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList + uintptr(1)*16
	}
	return pKey
}

func Xsqlite3VdbeSorterRowkey(tls *libc.TLS, pCsr uintptr, pOut uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pSorter uintptr
	var pKey uintptr

	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 48))
	pKey = vdbeSorterRowkey(tls, pSorter, bp)
	if Xsqlite3VdbeMemClearAndResize(tls, pOut, *(*int32)(unsafe.Pointer(bp))) != 0 {
		return SQLITE_NOMEM
	}
	(*Mem)(unsafe.Pointer(pOut)).Fn = *(*int32)(unsafe.Pointer(bp))
	(*Mem)(unsafe.Pointer(pOut)).Fflags = U16(int32((*Mem)(unsafe.Pointer(pOut)).Fflags)&libc.CplInt32(MEM_TypeMask|MEM_Zero) | MEM_Blob)
	libc.Xmemcpy(tls, (*Mem)(unsafe.Pointer(pOut)).Fz, pKey, uint64(*(*int32)(unsafe.Pointer(bp))))

	return SQLITE_OK
}

func Xsqlite3VdbeSorterCompare(tls *libc.TLS, pCsr uintptr, pVal uintptr, nKeyCol int32, pRes uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pSorter uintptr
	var r2 uintptr
	var pKeyInfo uintptr
	var i int32
	var pKey uintptr

	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 48))
	r2 = (*VdbeSorter)(unsafe.Pointer(pSorter)).FpUnpacked
	pKeyInfo = (*VdbeCursor)(unsafe.Pointer(pCsr)).FpKeyInfo
	if r2 == uintptr(0) {
		r2 = libc.AssignPtrUintptr(pSorter+48, Xsqlite3VdbeAllocUnpackedRecord(tls, pKeyInfo))
		if r2 == uintptr(0) {
			return SQLITE_NOMEM
		}
		(*UnpackedRecord)(unsafe.Pointer(r2)).FnField = U16(nKeyCol)
	}

	pKey = vdbeSorterRowkey(tls, pSorter, bp)
	Xsqlite3VdbeRecordUnpack(tls, pKeyInfo, *(*int32)(unsafe.Pointer(bp)), pKey, r2)
	for i = 0; i < nKeyCol; i++ {
		if int32((*Mem)(unsafe.Pointer((*UnpackedRecord)(unsafe.Pointer(r2)).FaMem+uintptr(i)*56)).Fflags)&MEM_Null != 0 {
			*(*int32)(unsafe.Pointer(pRes)) = -1
			return SQLITE_OK
		}
	}

	*(*int32)(unsafe.Pointer(pRes)) = Xsqlite3VdbeRecordCompare(tls, (*Mem)(unsafe.Pointer(pVal)).Fn, (*Mem)(unsafe.Pointer(pVal)).Fz, r2)
	return SQLITE_OK
}

type bytecodevtab = struct {
	Fbase        Sqlite3_vtab
	Fdb          uintptr
	FbTablesUsed int32
	F__ccgo_pad1 [4]byte
}

type Bytecodevtab = bytecodevtab

type bytecodevtab_cursor = struct {
	Fbase            Sqlite3_vtab_cursor
	FpStmt           uintptr
	FiRowid          int32
	FiAddr           int32
	FneedFinalize    int32
	FshowSubprograms int32
	FaOp             uintptr
	FzP4             uintptr
	FzType           uintptr
	FzSchema         uintptr
	FzName           uintptr
	Fsub             Mem
}

type Bytecodevtab_cursor = bytecodevtab_cursor

func bytecodevtabConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pNew uintptr
	var rc int32
	var isTabUsed int32 = libc.Bool32(pAux != uintptr(0))
	*(*[2]uintptr)(unsafe.Pointer(bp)) = [2]uintptr{
		ts + 9306,
		ts + 9418,
	}

	_ = argc
	_ = argv
	_ = pzErr
	rc = Xsqlite3_declare_vtab(tls, db, *(*uintptr)(unsafe.Pointer(bp + uintptr(isTabUsed)*8)))
	if rc == SQLITE_OK {
		pNew = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Bytecodevtab{})))
		*(*uintptr)(unsafe.Pointer(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Bytecodevtab{})))
		(*Bytecodevtab)(unsafe.Pointer(pNew)).Fdb = db
		(*Bytecodevtab)(unsafe.Pointer(pNew)).FbTablesUsed = isTabUsed * 2
	}
	return rc
}

func bytecodevtabDisconnect(tls *libc.TLS, pVtab uintptr) int32 {
	var p uintptr = pVtab
	Xsqlite3_free(tls, p)
	return SQLITE_OK
}

func bytecodevtabOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) int32 {
	var pVTab uintptr = p
	var pCur uintptr
	pCur = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Bytecodevtab_cursor{})))
	if pCur == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pCur, 0, uint64(unsafe.Sizeof(Bytecodevtab_cursor{})))
	Xsqlite3VdbeMemInit(tls, pCur+72, (*Bytecodevtab)(unsafe.Pointer(pVTab)).Fdb, uint16(1))
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return SQLITE_OK
}

func bytecodevtabCursorClear(tls *libc.TLS, pCur uintptr) {
	Xsqlite3_free(tls, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4)
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4 = uintptr(0)
	Xsqlite3VdbeMemRelease(tls, pCur+72)
	Xsqlite3VdbeMemSetNull(tls, pCur+72)
	if (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FneedFinalize != 0 {
		Xsqlite3_finalize(tls, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FpStmt)
	}
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FpStmt = uintptr(0)
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FneedFinalize = 0
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzType = uintptr(0)
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzSchema = uintptr(0)
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzName = uintptr(0)
}

func bytecodevtabClose(tls *libc.TLS, cur uintptr) int32 {
	var pCur uintptr = cur
	bytecodevtabCursorClear(tls, pCur)
	Xsqlite3_free(tls, pCur)
	return SQLITE_OK
}

func bytecodevtabNext(tls *libc.TLS, cur uintptr) int32 {
	var pCur uintptr = cur
	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	var rc int32
	if (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4 != 0 {
		Xsqlite3_free(tls, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4)
		(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4 = uintptr(0)
	}
	if (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzName != 0 {
		(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzName = uintptr(0)
		(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzType = uintptr(0)
		(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzSchema = uintptr(0)
	}
	rc = Xsqlite3VdbeNextOpcode(tls,
		(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FpStmt,
		func() uintptr {
			if (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FshowSubprograms != 0 {
				return pCur + 72
			}
			return uintptr(0)
		}(),
		(*Bytecodevtab)(unsafe.Pointer(pTab)).FbTablesUsed,
		pCur+16,
		pCur+20,
		pCur+32)
	if rc != SQLITE_OK {
		Xsqlite3VdbeMemSetNull(tls, pCur+72)
		(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FaOp = uintptr(0)
	}
	return SQLITE_OK
}

func bytecodevtabEof(tls *libc.TLS, cur uintptr) int32 {
	var pCur uintptr = cur
	return libc.Bool32((*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FaOp == uintptr(0))
}

func bytecodevtabColumn(tls *libc.TLS, cur uintptr, ctx uintptr, i int32) int32 {
	var pCur uintptr = cur
	var pVTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	var pOp uintptr = (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FaOp + uintptr((*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FiAddr)*32
	if (*Bytecodevtab)(unsafe.Pointer(pVTab)).FbTablesUsed != 0 {
		if i == 4 {
			i = 8
		} else {
			if i <= 2 && (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzType == uintptr(0) {
				var pSchema uintptr
				var k uintptr
				var iDb int32 = (*Op)(unsafe.Pointer(pOp)).Fp3
				var iRoot Pgno = Pgno((*Op)(unsafe.Pointer(pOp)).Fp2)
				var db uintptr = (*Bytecodevtab)(unsafe.Pointer(pVTab)).Fdb
				pSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
				(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
				for k = (*Hash)(unsafe.Pointer(pSchema + 8)).Ffirst; k != 0; k = (*HashElem)(unsafe.Pointer(k)).Fnext {
					var pTab uintptr = (*HashElem)(unsafe.Pointer(k)).Fdata
					if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) && (*Table)(unsafe.Pointer(pTab)).Ftnum == iRoot {
						(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzName = (*Table)(unsafe.Pointer(pTab)).FzName
						(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzType = ts + 9499
						break
					}
				}
				if (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzName == uintptr(0) {
					for k = (*Hash)(unsafe.Pointer(pSchema + 32)).Ffirst; k != 0; k = (*HashElem)(unsafe.Pointer(k)).Fnext {
						var pIdx uintptr = (*HashElem)(unsafe.Pointer(k)).Fdata
						if (*Index)(unsafe.Pointer(pIdx)).Ftnum == iRoot {
							(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzName = (*Index)(unsafe.Pointer(pIdx)).FzName
							(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzType = ts + 9505
						}
					}
				}
			}
			i = i + 10
		}
	}
	switch i {
	case 0:
		Xsqlite3_result_int(tls, ctx, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FiAddr)
		break
	case 1:
		Xsqlite3_result_text(tls, ctx, Xsqlite3OpcodeName(tls, int32((*Op)(unsafe.Pointer(pOp)).Fopcode)),
			-1, uintptr(0))
		break
	case 2:
		Xsqlite3_result_int(tls, ctx, (*Op)(unsafe.Pointer(pOp)).Fp1)
		break
	case 3:
		Xsqlite3_result_int(tls, ctx, (*Op)(unsafe.Pointer(pOp)).Fp2)
		break
	case 4:
		Xsqlite3_result_int(tls, ctx, (*Op)(unsafe.Pointer(pOp)).Fp3)
		break
	case 5:
		fallthrough
	case 7:
		if (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4 == uintptr(0) {
			(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4 = Xsqlite3VdbeDisplayP4(tls, (*Bytecodevtab)(unsafe.Pointer(pVTab)).Fdb, pOp)
		}
		if i == 5 {
			Xsqlite3_result_text(tls, ctx, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4, -1, uintptr(0))
		} else {
			var zCom uintptr = Xsqlite3VdbeDisplayComment(tls, (*Bytecodevtab)(unsafe.Pointer(pVTab)).Fdb, pOp, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzP4)
			Xsqlite3_result_text(tls, ctx, zCom, -1, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
		}
		break
	case 6:
		Xsqlite3_result_int(tls, ctx, int32((*Op)(unsafe.Pointer(pOp)).Fp5))
		break
	case 8:
		{
			var aOp uintptr = (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FaOp

			if (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FiRowid == (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FiAddr+1 {
				break
			} else if *(*uintptr)(unsafe.Pointer(aOp + 16)) != uintptr(0) {
				Xsqlite3_result_text(tls, ctx, *(*uintptr)(unsafe.Pointer(aOp + 16))+uintptr(3), -1, uintptr(0))
			} else {
				Xsqlite3_result_text(tls, ctx, ts+9511, 4, uintptr(0))
			}
			break

		}
	case 10:
		Xsqlite3_result_text(tls, ctx, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzType, -1, uintptr(0))
		break
	case 11:
		Xsqlite3_result_text(tls, ctx, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzSchema, -1, uintptr(0))
		break
	case 12:
		Xsqlite3_result_text(tls, ctx, (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FzName, -1, uintptr(0))
		break
	case 13:
		Xsqlite3_result_int(tls, ctx, libc.Bool32(int32((*Op)(unsafe.Pointer(pOp)).Fopcode) == OP_OpenWrite))
		break
	}
	return SQLITE_OK
}

func bytecodevtabRowid(tls *libc.TLS, cur uintptr, pRowid uintptr) int32 {
	var pCur uintptr = cur
	*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = Sqlite_int64((*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FiRowid)
	return SQLITE_OK
}

func bytecodevtabFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pCur uintptr = pVtabCursor
	var pVTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	var rc int32 = SQLITE_OK
	_ = idxStr

	bytecodevtabCursorClear(tls, pCur)
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FiRowid = 0
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FiAddr = 0
	(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FshowSubprograms = libc.Bool32(idxNum == 0)

	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == SQLITE_TEXT {
		var zSql uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if zSql == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			rc = Xsqlite3_prepare_v2(tls, (*Bytecodevtab)(unsafe.Pointer(pVTab)).Fdb, zSql, -1, pCur+8, uintptr(0))
			(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FneedFinalize = 1
		}
	} else {
		(*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FpStmt = Xsqlite3_value_pointer(tls, *(*uintptr)(unsafe.Pointer(argv)), ts+9516)
	}
	if (*Bytecodevtab_cursor)(unsafe.Pointer(pCur)).FpStmt == uintptr(0) {
		(*Bytecodevtab)(unsafe.Pointer(pVTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls,
			ts+9529,
			libc.VaList(bp, func() uintptr {
				if (*Bytecodevtab)(unsafe.Pointer(pVTab)).FbTablesUsed != 0 {
					return ts + 9575
				}
				return ts + 9587
			}()))
		rc = SQLITE_ERROR
	} else {
		bytecodevtabNext(tls, pVtabCursor)
	}
	return rc
}

func bytecodevtabBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) int32 {
	var i int32
	var rc int32 = SQLITE_CONSTRAINT
	var p uintptr
	var pVTab uintptr = tab
	var iBaseCol int32
	if (*Bytecodevtab)(unsafe.Pointer(pVTab)).FbTablesUsed != 0 {
		iBaseCol = 4
	} else {
		iBaseCol = 8
	}
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(100)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(100)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 0
	i = 0
	p = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint
__1:
	if !(i < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
		goto __3
	}
	{
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable) == 0 {
			goto __2
		}
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_EQ && (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn == iBaseCol+1 {
			rc = SQLITE_OK
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).Fomit = uint8(1)
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = 1
		}
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_ISNULL && (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn == iBaseCol {
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).Fomit = uint8(1)
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 1
		}

	}
	goto __2
__2:
	i++
	p += 12
	goto __1
	goto __3
__3:
	;
	return rc
}

var bytecodevtabModule = Sqlite3_module{
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
}

func Xsqlite3VdbeBytecodeVtabInit(tls *libc.TLS, db uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = db

	var rc int32
	rc = Xsqlite3_create_module(tls, *(*uintptr)(unsafe.Pointer(bp)), ts+9587, uintptr(unsafe.Pointer(&bytecodevtabModule)), uintptr(0))
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_module(tls, *(*uintptr)(unsafe.Pointer(bp)), ts+9575, uintptr(unsafe.Pointer(&bytecodevtabModule)), bp)
	}
	return rc
}

type MemJournal1 = struct {
	FpMethod     uintptr
	FnChunkSize  int32
	FnSpill      int32
	FpFirst      uintptr
	Fendpoint    FilePoint
	Freadpoint   FilePoint
	Fflags       int32
	F__ccgo_pad1 [4]byte
	FpVfs        uintptr
	FzJournal    uintptr
}

type MemJournal = MemJournal1
type FilePoint1 = struct {
	FiOffset Sqlite3_int64
	FpChunk  uintptr
}

type FilePoint = FilePoint1
type FileChunk1 = struct {
	FpNext  uintptr
	FzChunk [8]U8
}

type FileChunk = FileChunk1

func memjrnlRead(tls *libc.TLS, pJfd uintptr, zBuf uintptr, iAmt int32, iOfst Sqlite_int64) int32 {
	var p uintptr = pJfd
	var zOut uintptr = zBuf
	var nRead int32 = iAmt
	var iChunkOffset int32
	var pChunk uintptr

	if Sqlite_int64(iAmt)+iOfst > (*MemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset {
		return SQLITE_IOERR | int32(2)<<8
	}

	if (*MemJournal)(unsafe.Pointer(p)).Freadpoint.FiOffset != iOfst || iOfst == int64(0) {
		var iOff Sqlite3_int64 = int64(0)
		for pChunk = (*MemJournal)(unsafe.Pointer(p)).FpFirst; pChunk != 0 && iOff+Sqlite3_int64((*MemJournal)(unsafe.Pointer(p)).FnChunkSize) <= iOfst; pChunk = (*FileChunk)(unsafe.Pointer(pChunk)).FpNext {
			iOff = iOff + Sqlite3_int64((*MemJournal)(unsafe.Pointer(p)).FnChunkSize)
		}
	} else {
		pChunk = (*MemJournal)(unsafe.Pointer(p)).Freadpoint.FpChunk

	}

	iChunkOffset = int32(iOfst % Sqlite_int64((*MemJournal)(unsafe.Pointer(p)).FnChunkSize))
	for __ccgo := true; __ccgo; __ccgo = nRead >= 0 && libc.AssignUintptr(&pChunk, (*FileChunk)(unsafe.Pointer(pChunk)).FpNext) != uintptr(0) && nRead > 0 {
		var iSpace int32 = (*MemJournal)(unsafe.Pointer(p)).FnChunkSize - iChunkOffset
		var nCopy int32 = func() int32 {
			if nRead < (*MemJournal)(unsafe.Pointer(p)).FnChunkSize-iChunkOffset {
				return nRead
			}
			return (*MemJournal)(unsafe.Pointer(p)).FnChunkSize - iChunkOffset
		}()
		libc.Xmemcpy(tls, zOut, pChunk+8+uintptr(iChunkOffset), uint64(nCopy))
		zOut += uintptr(nCopy)
		nRead = nRead - iSpace
		iChunkOffset = 0
	}
	(*MemJournal)(unsafe.Pointer(p)).Freadpoint.FiOffset = func() int64 {
		if pChunk != 0 {
			return iOfst + Sqlite_int64(iAmt)
		}
		return int64(0)
	}()
	(*MemJournal)(unsafe.Pointer(p)).Freadpoint.FpChunk = pChunk

	return SQLITE_OK
}

func memjrnlFreeChunks(tls *libc.TLS, pFirst uintptr) {
	var pIter uintptr
	var pNext uintptr
	for pIter = pFirst; pIter != 0; pIter = pNext {
		pNext = (*FileChunk)(unsafe.Pointer(pIter)).FpNext
		Xsqlite3_free(tls, pIter)
	}
}

func memjrnlCreateFile(tls *libc.TLS, p uintptr) int32 {
	var rc int32
	var pReal uintptr = p
	var copy = *(*MemJournal)(unsafe.Pointer(p))

	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(MemJournal{})))
	rc = Xsqlite3OsOpen(tls, copy.FpVfs, copy.FzJournal, pReal, copy.Fflags, uintptr(0))
	if rc == SQLITE_OK {
		var nChunk int32 = copy.FnChunkSize
		var iOff I64 = int64(0)
		var pIter uintptr
		for pIter = copy.FpFirst; pIter != 0; pIter = (*FileChunk)(unsafe.Pointer(pIter)).FpNext {
			if iOff+I64(nChunk) > copy.Fendpoint.FiOffset {
				nChunk = int32(copy.Fendpoint.FiOffset - iOff)
			}
			rc = Xsqlite3OsWrite(tls, pReal, pIter+8, nChunk, iOff)
			if rc != 0 {
				break
			}
			iOff = iOff + I64(nChunk)
		}
		if rc == SQLITE_OK {
			memjrnlFreeChunks(tls, copy.FpFirst)
		}
	}
	if rc != SQLITE_OK {
		Xsqlite3OsClose(tls, pReal)
		*(*MemJournal)(unsafe.Pointer(p)) = copy
	}
	return rc
}

func memjrnlWrite(tls *libc.TLS, pJfd uintptr, zBuf uintptr, iAmt int32, iOfst Sqlite_int64) int32 {
	var p uintptr = pJfd
	var nWrite int32 = iAmt
	var zWrite uintptr = zBuf

	if (*MemJournal)(unsafe.Pointer(p)).FnSpill > 0 && Sqlite_int64(iAmt)+iOfst > Sqlite_int64((*MemJournal)(unsafe.Pointer(p)).FnSpill) {
		var rc int32 = memjrnlCreateFile(tls, p)
		if rc == SQLITE_OK {
			rc = Xsqlite3OsWrite(tls, pJfd, zBuf, iAmt, iOfst)
		}
		return rc
	} else {
		if iOfst > int64(0) && iOfst != (*MemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset {
			memjrnlTruncate(tls, pJfd, iOfst)
		}
		if iOfst == int64(0) && (*MemJournal)(unsafe.Pointer(p)).FpFirst != 0 {
			libc.Xmemcpy(tls, (*MemJournal)(unsafe.Pointer(p)).FpFirst+8, zBuf, uint64(iAmt))
		} else {
			for nWrite > 0 {
				var pChunk uintptr = (*MemJournal)(unsafe.Pointer(p)).Fendpoint.FpChunk
				var iChunkOffset int32 = int32((*MemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset % Sqlite3_int64((*MemJournal)(unsafe.Pointer(p)).FnChunkSize))
				var iSpace int32 = func() int32 {
					if nWrite < (*MemJournal)(unsafe.Pointer(p)).FnChunkSize-iChunkOffset {
						return nWrite
					}
					return (*MemJournal)(unsafe.Pointer(p)).FnChunkSize - iChunkOffset
				}()

				if iChunkOffset == 0 {
					var pNew uintptr = Xsqlite3_malloc(tls, int32(uint64(unsafe.Sizeof(FileChunk{}))+uint64((*MemJournal)(unsafe.Pointer(p)).FnChunkSize-8)))
					if !(pNew != 0) {
						return SQLITE_IOERR | int32(12)<<8
					}
					(*FileChunk)(unsafe.Pointer(pNew)).FpNext = uintptr(0)
					if pChunk != 0 {
						(*FileChunk)(unsafe.Pointer(pChunk)).FpNext = pNew
					} else {
						(*MemJournal)(unsafe.Pointer(p)).FpFirst = pNew
					}
					pChunk = libc.AssignPtrUintptr(p+24+8, pNew)
				}

				libc.Xmemcpy(tls, pChunk+8+uintptr(iChunkOffset), zWrite, uint64(iSpace))
				zWrite += uintptr(iSpace)
				nWrite = nWrite - iSpace
				*(*Sqlite3_int64)(unsafe.Pointer(p + 24)) += Sqlite3_int64(iSpace)
			}
		}
	}

	return SQLITE_OK
}

func memjrnlTruncate(tls *libc.TLS, pJfd uintptr, size Sqlite_int64) int32 {
	var p uintptr = pJfd

	if size < (*MemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset {
		var pIter uintptr = uintptr(0)
		if size == int64(0) {
			memjrnlFreeChunks(tls, (*MemJournal)(unsafe.Pointer(p)).FpFirst)
			(*MemJournal)(unsafe.Pointer(p)).FpFirst = uintptr(0)
		} else {
			var iOff I64 = I64((*MemJournal)(unsafe.Pointer(p)).FnChunkSize)
			for pIter = (*MemJournal)(unsafe.Pointer(p)).FpFirst; pIter != 0 && iOff < size; pIter = (*FileChunk)(unsafe.Pointer(pIter)).FpNext {
				iOff = iOff + I64((*MemJournal)(unsafe.Pointer(p)).FnChunkSize)
			}
			if pIter != 0 {
				memjrnlFreeChunks(tls, (*FileChunk)(unsafe.Pointer(pIter)).FpNext)
				(*FileChunk)(unsafe.Pointer(pIter)).FpNext = uintptr(0)
			}
		}

		(*MemJournal)(unsafe.Pointer(p)).Fendpoint.FpChunk = pIter
		(*MemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset = size
		(*MemJournal)(unsafe.Pointer(p)).Freadpoint.FpChunk = uintptr(0)
		(*MemJournal)(unsafe.Pointer(p)).Freadpoint.FiOffset = int64(0)
	}
	return SQLITE_OK
}

func memjrnlClose(tls *libc.TLS, pJfd uintptr) int32 {
	var p uintptr = pJfd
	memjrnlFreeChunks(tls, (*MemJournal)(unsafe.Pointer(p)).FpFirst)
	return SQLITE_OK
}

func memjrnlSync(tls *libc.TLS, pJfd uintptr, flags int32) int32 {
	_ = pJfd
	_ = flags
	return SQLITE_OK
}

func memjrnlFileSize(tls *libc.TLS, pJfd uintptr, pSize uintptr) int32 {
	var p uintptr = pJfd
	*(*Sqlite_int64)(unsafe.Pointer(pSize)) = (*MemJournal)(unsafe.Pointer(p)).Fendpoint.FiOffset
	return SQLITE_OK
}

var sMemJournalMethods = sqlite3_io_methods{
	FiVersion:  1,
	FxClose:    0,
	FxRead:     0,
	FxWrite:    0,
	FxTruncate: 0,
	FxSync:     0,
	FxFileSize: 0,
}

func Xsqlite3JournalOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pJfd uintptr, flags int32, nSpill int32) int32 {
	var p uintptr = pJfd

	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(MemJournal{})))
	if nSpill == 0 {
		return Xsqlite3OsOpen(tls, pVfs, zName, pJfd, flags, uintptr(0))
	}

	if nSpill > 0 {
		(*MemJournal)(unsafe.Pointer(p)).FnChunkSize = nSpill
	} else {
		(*MemJournal)(unsafe.Pointer(p)).FnChunkSize = int32(uint64(8+MEMJOURNAL_DFLT_FILECHUNKSIZE) - uint64(unsafe.Sizeof(FileChunk{})))

	}

	(*Sqlite3_file)(unsafe.Pointer(pJfd)).FpMethods = uintptr(unsafe.Pointer(&sMemJournalMethods))
	(*MemJournal)(unsafe.Pointer(p)).FnSpill = nSpill
	(*MemJournal)(unsafe.Pointer(p)).Fflags = flags
	(*MemJournal)(unsafe.Pointer(p)).FzJournal = zName
	(*MemJournal)(unsafe.Pointer(p)).FpVfs = pVfs
	return SQLITE_OK
}

func Xsqlite3MemJournalOpen(tls *libc.TLS, pJfd uintptr) {
	Xsqlite3JournalOpen(tls, uintptr(0), uintptr(0), pJfd, 0, -1)
}

func Xsqlite3JournalIsInMemory(tls *libc.TLS, p uintptr) int32 {
	return libc.Bool32((*Sqlite3_file)(unsafe.Pointer(p)).FpMethods == uintptr(unsafe.Pointer(&sMemJournalMethods)))
}

func Xsqlite3JournalSize(tls *libc.TLS, pVfs uintptr) int32 {
	return func() int32 {
		if (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile > int32(unsafe.Sizeof(MemJournal{})) {
			return (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FszOsFile
		}
		return int32(unsafe.Sizeof(MemJournal{}))
	}()
}

func walkWindowList(tls *libc.TLS, pWalker uintptr, pList uintptr, bOneOnly int32) int32 {
	var pWin uintptr
	for pWin = pList; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
		var rc int32
		rc = Xsqlite3WalkExprList(tls, pWalker, (*Window)(unsafe.Pointer(pWin)).FpOrderBy)
		if rc != 0 {
			return WRC_Abort
		}
		rc = Xsqlite3WalkExprList(tls, pWalker, (*Window)(unsafe.Pointer(pWin)).FpPartition)
		if rc != 0 {
			return WRC_Abort
		}
		rc = Xsqlite3WalkExpr(tls, pWalker, (*Window)(unsafe.Pointer(pWin)).FpFilter)
		if rc != 0 {
			return WRC_Abort
		}
		rc = Xsqlite3WalkExpr(tls, pWalker, (*Window)(unsafe.Pointer(pWin)).FpStart)
		if rc != 0 {
			return WRC_Abort
		}
		rc = Xsqlite3WalkExpr(tls, pWalker, (*Window)(unsafe.Pointer(pWin)).FpEnd)
		if rc != 0 {
			return WRC_Abort
		}
		if bOneOnly != 0 {
			break
		}
	}
	return WRC_Continue
}

func walkExpr(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var rc int32

	for 1 != 0 {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Walker)(unsafe.Pointer(pWalker)).FxExprCallback})).f(tls, pWalker, pExpr)
		if rc != 0 {
			return rc & WRC_Abort
		}
		if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_TokenOnly|EP_Leaf) != U32(0)) {
			if (*Expr)(unsafe.Pointer(pExpr)).FpLeft != 0 && walkExpr(tls, pWalker, (*Expr)(unsafe.Pointer(pExpr)).FpLeft) != 0 {
				return WRC_Abort
			}
			if (*Expr)(unsafe.Pointer(pExpr)).FpRight != 0 {
				pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpRight
				continue
			} else if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
				if Xsqlite3WalkSelect(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 32))) != 0 {
					return WRC_Abort
				}
			} else {
				if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != 0 {
					if Xsqlite3WalkExprList(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 32))) != 0 {
						return WRC_Abort
					}
				}
				if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
					if walkWindowList(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 64)), 1) != 0 {
						return WRC_Abort
					}
				}
			}
		}
		break
	}
	return WRC_Continue
}

func Xsqlite3WalkExpr(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if pExpr != 0 {
		return walkExpr(tls, pWalker, pExpr)
	}
	return WRC_Continue
}

func Xsqlite3WalkExprList(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	var i int32
	var pItem uintptr
	if p != 0 {
		i = (*ExprList)(unsafe.Pointer(p)).FnExpr
		pItem = p + 8
	__1:
		if !(i > 0) {
			goto __3
		}
		{
			if Xsqlite3WalkExpr(tls, pWalker, (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr) != 0 {
				return WRC_Abort
			}

		}
		goto __2
	__2:
		i--
		pItem += 32
		goto __1
		goto __3
	__3:
	}
	return WRC_Continue
}

func Xsqlite3WalkWinDefnDummyCallback(tls *libc.TLS, pWalker uintptr, p uintptr) {
	_ = pWalker
	_ = p

}

func Xsqlite3WalkSelectExpr(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	if Xsqlite3WalkExprList(tls, pWalker, (*Select)(unsafe.Pointer(p)).FpEList) != 0 {
		return WRC_Abort
	}
	if Xsqlite3WalkExpr(tls, pWalker, (*Select)(unsafe.Pointer(p)).FpWhere) != 0 {
		return WRC_Abort
	}
	if Xsqlite3WalkExprList(tls, pWalker, (*Select)(unsafe.Pointer(p)).FpGroupBy) != 0 {
		return WRC_Abort
	}
	if Xsqlite3WalkExpr(tls, pWalker, (*Select)(unsafe.Pointer(p)).FpHaving) != 0 {
		return WRC_Abort
	}
	if Xsqlite3WalkExprList(tls, pWalker, (*Select)(unsafe.Pointer(p)).FpOrderBy) != 0 {
		return WRC_Abort
	}
	if Xsqlite3WalkExpr(tls, pWalker, (*Select)(unsafe.Pointer(p)).FpLimit) != 0 {
		return WRC_Abort
	}
	if (*Select)(unsafe.Pointer(p)).FpWinDefn != 0 {
		var pParse uintptr
		if (*Walker)(unsafe.Pointer(pWalker)).FxSelectCallback2 == *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{Xsqlite3WalkWinDefnDummyCallback})) ||
			libc.AssignUintptr(&pParse, (*Walker)(unsafe.Pointer(pWalker)).FpParse) != uintptr(0) && int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME ||
			(*Walker)(unsafe.Pointer(pWalker)).FxSelectCallback2 == *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr)
			}{Xsqlite3SelectPopWith})) {
			var rc int32 = walkWindowList(tls, pWalker, (*Select)(unsafe.Pointer(p)).FpWinDefn, 0)
			return rc
		}
	}
	return WRC_Continue
}

func Xsqlite3WalkSelectFrom(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	var pSrc uintptr
	var i int32
	var pItem uintptr

	pSrc = (*Select)(unsafe.Pointer(p)).FpSrc
	if pSrc != 0 {
		i = (*SrcList)(unsafe.Pointer(pSrc)).FnSrc
		pItem = pSrc + 8
	__1:
		if !(i > 0) {
			goto __3
		}
		{
			if (*SrcItem)(unsafe.Pointer(pItem)).FpSelect != 0 && Xsqlite3WalkSelect(tls, pWalker, (*SrcItem)(unsafe.Pointer(pItem)).FpSelect) != 0 {
				return WRC_Abort
			}
			if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x4>>2)) != 0 &&
				Xsqlite3WalkExprList(tls, pWalker, *(*uintptr)(unsafe.Pointer(pItem + 88))) != 0 {
				return WRC_Abort
			}

		}
		goto __2
	__2:
		i--
		pItem += 104
		goto __1
		goto __3
	__3:
	}
	return WRC_Continue
}

func Xsqlite3WalkSelect(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	var rc int32
	if p == uintptr(0) {
		return WRC_Continue
	}
	if (*Walker)(unsafe.Pointer(pWalker)).FxSelectCallback == uintptr(0) {
		return WRC_Continue
	}
	for __ccgo := true; __ccgo; __ccgo = p != uintptr(0) {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Walker)(unsafe.Pointer(pWalker)).FxSelectCallback})).f(tls, pWalker, p)
		if rc != 0 {
			return rc & WRC_Abort
		}
		if Xsqlite3WalkSelectExpr(tls, pWalker, p) != 0 ||
			Xsqlite3WalkSelectFrom(tls, pWalker, p) != 0 {
			return WRC_Abort
		}
		if (*Walker)(unsafe.Pointer(pWalker)).FxSelectCallback2 != 0 {
			(*struct {
				f func(*libc.TLS, uintptr, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{(*Walker)(unsafe.Pointer(pWalker)).FxSelectCallback2})).f(tls, pWalker, p)
		}
		p = (*Select)(unsafe.Pointer(p)).FpPrior
	}
	return WRC_Continue
}

func Xsqlite3WalkerDepthIncrease(tls *libc.TLS, pWalker uintptr, pSelect uintptr) int32 {
	_ = pSelect
	(*Walker)(unsafe.Pointer(pWalker)).FwalkerDepth++
	return WRC_Continue
}

func Xsqlite3WalkerDepthDecrease(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
	_ = pSelect
	(*Walker)(unsafe.Pointer(pWalker)).FwalkerDepth--
}

func Xsqlite3ExprWalkNoop(tls *libc.TLS, NotUsed uintptr, NotUsed2 uintptr) int32 {
	_ = NotUsed
	_ = NotUsed2
	return WRC_Continue
}

func Xsqlite3SelectWalkNoop(tls *libc.TLS, NotUsed uintptr, NotUsed2 uintptr) int32 {
	_ = NotUsed
	_ = NotUsed2
	return WRC_Continue
}

func incrAggDepth(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AGG_FUNCTION {
		*(*U8)(unsafe.Pointer(pExpr + 2)) += U8(*(*int32)(unsafe.Pointer(pWalker + 40)))
	}
	return WRC_Continue
}

func incrAggFunctionDepth(tls *libc.TLS, pExpr uintptr, N int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if N > 0 {
		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
		(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		}{incrAggDepth}))
		*(*int32)(unsafe.Pointer(bp + 40)) = N
		Xsqlite3WalkExpr(tls, bp, pExpr)
	}
}

func resolveAlias(tls *libc.TLS, pParse uintptr, pEList uintptr, iCol int32, pExpr uintptr, nSubquery int32) {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var pOrig uintptr
	var pDup uintptr
	var db uintptr

	pOrig = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(iCol)*32)).FpExpr

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	pDup = Xsqlite3ExprDup(tls, db, pOrig, 0)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		Xsqlite3ExprDelete(tls, db, pDup)
		pDup = uintptr(0)
	} else {
		incrAggFunctionDepth(tls, pDup, nSubquery)
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLLATE {
			pDup = Xsqlite3ExprAddCollateString(tls, pParse, pDup, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
		}
		libc.Xmemcpy(tls, bp, pDup, uint64(unsafe.Sizeof(Expr{})))
		libc.Xmemcpy(tls, pDup, pExpr, uint64(unsafe.Sizeof(Expr{})))
		libc.Xmemcpy(tls, pExpr, bp, uint64(unsafe.Sizeof(Expr{})))
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
			if *(*uintptr)(unsafe.Pointer(pExpr + 64)) != uintptr(0) {
				(*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FpOwner = pExpr
			}
		}
		Xsqlite3ExprDeferredDelete(tls, pParse, pDup)
	}
}

func Xsqlite3MatchEName(tls *libc.TLS, pItem uintptr, zCol uintptr, zTab uintptr, zDb uintptr) int32 {
	var n int32
	var zSpan uintptr
	if int32(*(*uint16)(unsafe.Pointer(pItem + 16 + 4))&0x3>>0) != ENAME_TAB {
		return 0
	}
	zSpan = (*ExprList_item)(unsafe.Pointer(pItem)).FzEName
	for n = 0; *(*uint8)(unsafe.Pointer(zSpan + uintptr(n))) != 0 && int32(*(*uint8)(unsafe.Pointer(zSpan + uintptr(n)))) != '.'; n++ {
	}
	if zDb != 0 && (Xsqlite3_strnicmp(tls, zSpan, zDb, n) != 0 || int32(*(*uint8)(unsafe.Pointer(zDb + uintptr(n)))) != 0) {
		return 0
	}
	zSpan += uintptr(n + 1)
	for n = 0; *(*uint8)(unsafe.Pointer(zSpan + uintptr(n))) != 0 && int32(*(*uint8)(unsafe.Pointer(zSpan + uintptr(n)))) != '.'; n++ {
	}
	if zTab != 0 && (Xsqlite3_strnicmp(tls, zSpan, zTab, n) != 0 || int32(*(*uint8)(unsafe.Pointer(zTab + uintptr(n)))) != 0) {
		return 0
	}
	zSpan += uintptr(n + 1)
	if zCol != 0 && Xsqlite3StrICmp(tls, zSpan, zCol) != 0 {
		return 0
	}
	return 1
}

func areDoubleQuotedStringsEnabled(tls *libc.TLS, db uintptr, pTopNC uintptr) int32 {
	if (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 {
		return 1
	}
	if (*NameContext)(unsafe.Pointer(pTopNC)).FncFlags&NC_IsDDL != 0 {
		if Xsqlite3WritableSchema(tls, db) != 0 && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DqsDML) != uint64(0) {
			return 1
		}
		return libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DqsDDL) != uint64(0))
	} else {
		return libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DqsDML) != uint64(0))
	}
	return int32(0)
}

func Xsqlite3ExprColUsed(tls *libc.TLS, pExpr uintptr) Bitmask {
	var n int32
	var pExTab uintptr

	n = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)

	pExTab = *(*uintptr)(unsafe.Pointer(pExpr + 64))

	if (*Table)(unsafe.Pointer(pExTab)).FtabFlags&U32(TF_HasGenerated) != U32(0) &&
		int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pExTab)).FaCol+uintptr(n)*24)).FcolFlags)&COLFLAG_GENERATED != 0 {
		if int32((*Table)(unsafe.Pointer(pExTab)).FnCol) >= int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) {
			return libc.Uint64(libc.Uint64FromInt32(-1))
		}
		return uint64(1)<<int32((*Table)(unsafe.Pointer(pExTab)).FnCol) - uint64(1)
	} else {
		if n >= int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) {
			n = int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) - 1
		}
		return uint64(1) << n
	}
	return Bitmask(0)
}

func extendFJMatch(tls *libc.TLS, pParse uintptr, ppList uintptr, pMatch uintptr, iColumn I16) {
	var pNew uintptr = Xsqlite3ExprAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_COLUMN, uintptr(0), 0)
	if pNew != 0 {
		(*Expr)(unsafe.Pointer(pNew)).FiTable = (*SrcItem)(unsafe.Pointer(pMatch)).FiCursor
		(*Expr)(unsafe.Pointer(pNew)).FiColumn = iColumn
		*(*uintptr)(unsafe.Pointer(pNew + 64)) = (*SrcItem)(unsafe.Pointer(pMatch)).FpTab

		*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(EP_CanBeNull)
		*(*uintptr)(unsafe.Pointer(ppList)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(ppList)), pNew)
	}
}

func isValidSchemaTableName(tls *libc.TLS, zTab uintptr, pTab uintptr, pSchema uintptr) int32 {
	var zLegacy uintptr

	if Xsqlite3_strnicmp(tls, zTab, ts+9596, 7) != 0 {
		return 0
	}
	zLegacy = (*Table)(unsafe.Pointer(pTab)).FzName
	if libc.Xstrcmp(tls, zLegacy+uintptr(7), ts+9604+7) == 0 {
		if Xsqlite3StrICmp(tls, zTab+uintptr(7), ts+9623+7) == 0 {
			return 1
		}
		if pSchema == uintptr(0) {
			return 0
		}
		if Xsqlite3StrICmp(tls, zTab+uintptr(7), ts+8808+7) == 0 {
			return 1
		}
		if Xsqlite3StrICmp(tls, zTab+uintptr(7), ts+9642+7) == 0 {
			return 1
		}
	} else {
		if Xsqlite3StrICmp(tls, zTab+uintptr(7), ts+9642+7) == 0 {
			return 1
		}
	}
	return 0
}

func lookupName(tls *libc.TLS, pParse uintptr, zDb uintptr, zTab uintptr, zCol uintptr, pNC uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(104)
	defer tls.Free(104)

	var i int32
	var j int32
	var cnt int32
	var cntTab int32
	var nSubquery int32
	var db uintptr
	var pItem uintptr
	var pMatch uintptr
	var pTopNC uintptr
	var pSchema uintptr
	var eNewExprOp int32
	var pTab uintptr
	var pCol uintptr

	var hit int32
	var hCol U8
	var op int32
	var pUpsert uintptr
	var iCol int32
	var hCol1 U8
	var pOrig uintptr
	var zAs uintptr
	var pEList uintptr
	var pSrcList uintptr
	var zErr uintptr
	cnt = 0
	cntTab = 0
	nSubquery = 0
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	pMatch = uintptr(0)
	pTopNC = pNC
	pSchema = uintptr(0)
	eNewExprOp = TK_COLUMN
	pTab = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 96)) = uintptr(0)

	(*Expr)(unsafe.Pointer(pExpr)).FiTable = -1

	if !(zDb != 0) {
		goto __1
	}

	if !((*NameContext)(unsafe.Pointer(pNC)).FncFlags&(NC_PartIdx|NC_IsCheck) != 0) {
		goto __2
	}

	zDb = uintptr(0)
	goto __3
__2:
	i = 0
__4:
	if !(i < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __6
	}

	if !(Xsqlite3StrICmp(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FzDbSName, zDb) == 0) {
		goto __7
	}
	pSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpSchema
	goto __6
__7:
	;
	goto __5
__5:
	i++
	goto __4
	goto __6
__6:
	;
	if !(i == (*Sqlite3)(unsafe.Pointer(db)).FnDb && Xsqlite3StrICmp(tls, ts+9656, zDb) == 0) {
		goto __8
	}

	pSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FzDbSName
__8:
	;
__3:
	;
__1:
	;
__9:
	pSrcList = (*NameContext)(unsafe.Pointer(pNC)).FpSrcList

	if !(pSrcList != 0) {
		goto __12
	}
	i = 0
	pItem = pSrcList + 8
__13:
	if !(i < (*SrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
		goto __15
	}
	pTab = (*SrcItem)(unsafe.Pointer(pItem)).FpTab

	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x2000>>13)) != 0) {
		goto __16
	}

	hit = 0

	pEList = (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpSelect)).FpEList

	j = 0
__17:
	if !(j < (*ExprList)(unsafe.Pointer(pEList)).FnExpr) {
		goto __19
	}
	if !!(Xsqlite3MatchEName(tls, pEList+8+uintptr(j)*32, zCol, zTab, zDb) != 0) {
		goto __20
	}
	goto __18
__20:
	;
	if !(cnt > 0) {
		goto __21
	}
	if !(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x400>>10) == 0 ||
		Xsqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 72)), zCol) < 0) {
		goto __22
	}

	Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp + 96)))
	*(*uintptr)(unsafe.Pointer(bp + 96)) = uintptr(0)
	goto __23
__22:
	if !(int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&JT_RIGHT == 0) {
		goto __24
	}

	goto __18
	goto __25
__24:
	if !(int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&JT_LEFT == 0) {
		goto __26
	}

	cnt = 0
	Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp + 96)))
	*(*uintptr)(unsafe.Pointer(bp + 96)) = uintptr(0)
	goto __27
__26:
	extendFJMatch(tls, pParse, bp+96, pMatch, (*Expr)(unsafe.Pointer(pExpr)).FiColumn)
__27:
	;
__25:
	;
__23:
	;
__21:
	;
	cnt++
	cntTab = 2
	pMatch = pItem
	(*Expr)(unsafe.Pointer(pExpr)).FiColumn = YnVar(j)
	libc.SetBitFieldPtr16Uint32(pEList+8+uintptr(j)*32+16+4, uint32(1), 6, 0x40)
	hit = 1
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*32 + 16 + 4))&0x80>>7)) != 0) {
		goto __28
	}
	goto __19
__28:
	;
	goto __18
__18:
	j++
	goto __17
	goto __19
__19:
	;
	if !(hit != 0 || zTab == uintptr(0)) {
		goto __29
	}
	goto __14
__29:
	;
__16:
	;
	if !(zTab != 0) {
		goto __30
	}
	if !(zDb != 0) {
		goto __31
	}
	if !((*Table)(unsafe.Pointer(pTab)).FpSchema != pSchema) {
		goto __32
	}
	goto __14
__32:
	;
	if !(pSchema == uintptr(0) && libc.Xstrcmp(tls, zDb, ts+9661) != 0) {
		goto __33
	}
	goto __14
__33:
	;
__31:
	;
	if !((*SrcItem)(unsafe.Pointer(pItem)).FzAlias != uintptr(0)) {
		goto __34
	}
	if !(Xsqlite3StrICmp(tls, zTab, (*SrcItem)(unsafe.Pointer(pItem)).FzAlias) != 0) {
		goto __36
	}
	goto __14
__36:
	;
	goto __35
__34:
	if !(Xsqlite3StrICmp(tls, zTab, (*Table)(unsafe.Pointer(pTab)).FzName) != 0) {
		goto __37
	}
	if !((*Table)(unsafe.Pointer(pTab)).Ftnum != Pgno(1)) {
		goto __38
	}
	goto __14
__38:
	;
	if !!(isValidSchemaTableName(tls, zTab, pTab, pSchema) != 0) {
		goto __39
	}
	goto __14
__39:
	;
__37:
	;
__35:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && (*SrcItem)(unsafe.Pointer(pItem)).FzAlias != 0) {
		goto __40
	}
	Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr+64)
__40:
	;
__30:
	;
	hCol = Xsqlite3StrIHash(tls, zCol)
	j = 0
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol
__41:
	if !(j < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __43
	}
	if !(int32((*Column)(unsafe.Pointer(pCol)).FhName) == int32(hCol) &&
		Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName, zCol) == 0) {
		goto __44
	}
	if !(cnt > 0) {
		goto __45
	}
	if !(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x400>>10) == 0 ||
		Xsqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pItem + 72)), zCol) < 0) {
		goto __46
	}

	Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp + 96)))
	*(*uintptr)(unsafe.Pointer(bp + 96)) = uintptr(0)
	goto __47
__46:
	if !(int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&JT_RIGHT == 0) {
		goto __48
	}

	goto __42
	goto __49
__48:
	if !(int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&JT_LEFT == 0) {
		goto __50
	}

	cnt = 0
	Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp + 96)))
	*(*uintptr)(unsafe.Pointer(bp + 96)) = uintptr(0)
	goto __51
__50:
	extendFJMatch(tls, pParse, bp+96, pMatch, (*Expr)(unsafe.Pointer(pExpr)).FiColumn)
__51:
	;
__49:
	;
__47:
	;
__45:
	;
	cnt++
	pMatch = pItem

	(*Expr)(unsafe.Pointer(pExpr)).FiColumn = func() int16 {
		if j == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) {
			return int16(-1)
		}
		return I16(j)
	}()
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x2000>>13)) != 0) {
		goto __52
	}
	Xsqlite3SrcItemColumnUsed(tls, pItem, j)
__52:
	;
	goto __43
__44:
	;
	goto __42
__42:
	j++
	pCol += 24
	goto __41
	goto __43
__43:
	;
	if !(0 == cnt && (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_NoVisibleRowid) == U32(0)) {
		goto __53
	}
	cntTab++
	pMatch = pItem
__53:
	;
	goto __14
__14:
	i++
	pItem += 104
	goto __13
	goto __15
__15:
	;
	if !(pMatch != 0) {
		goto __54
	}
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = (*SrcItem)(unsafe.Pointer(pMatch)).FiCursor

	*(*uintptr)(unsafe.Pointer(pExpr + 64)) = (*SrcItem)(unsafe.Pointer(pMatch)).FpTab
	if !(int32((*SrcItem)(unsafe.Pointer(pMatch)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ) != 0) {
		goto __55
	}
	*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_CanBeNull)
__55:
	;
	pSchema = (*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FpSchema
__54:
	;
__12:
	;
	if !(cnt == 0 && zDb == uintptr(0)) {
		goto __56
	}
	pTab = uintptr(0)
	if !((*Parse)(unsafe.Pointer(pParse)).FpTriggerTab != uintptr(0)) {
		goto __57
	}
	op = int32((*Parse)(unsafe.Pointer(pParse)).FeTriggerOp)

	if !((*Parse)(unsafe.Pointer(pParse)).FbReturning != 0) {
		goto __58
	}
	if !((*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_UBaseReg != 0 &&
		(zTab == uintptr(0) || Xsqlite3StrICmp(tls, zTab, (*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).FpTriggerTab)).FzName) == 0)) {
		goto __60
	}
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = libc.Bool32(op != TK_DELETE)
	pTab = (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab
__60:
	;
	goto __59
__58:
	if !(op != TK_DELETE && zTab != 0 && Xsqlite3StrICmp(tls, ts+9663, zTab) == 0) {
		goto __61
	}
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = 1
	pTab = (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab
	goto __62
__61:
	if !(op != TK_INSERT && zTab != 0 && Xsqlite3StrICmp(tls, ts+9667, zTab) == 0) {
		goto __63
	}
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = 0
	pTab = (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab
__63:
	;
__62:
	;
__59:
	;
__57:
	;
	if !((*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_UUpsert != 0 && zTab != uintptr(0)) {
		goto __64
	}
	pUpsert = *(*uintptr)(unsafe.Pointer(pNC + 16))
	if !(pUpsert != 0 && Xsqlite3StrICmp(tls, ts+9671, zTab) == 0) {
		goto __65
	}
	pTab = (*SrcItem)(unsafe.Pointer((*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertSrc + 8)).FpTab
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = EXCLUDED_TABLE_NUMBER
__65:
	;
__64:
	;
	if !(pTab != 0) {
		goto __66
	}
	hCol1 = Xsqlite3StrIHash(tls, zCol)
	pSchema = (*Table)(unsafe.Pointer(pTab)).FpSchema
	cntTab++
	iCol = 0
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol
__67:
	if !(iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __69
	}
	if !(int32((*Column)(unsafe.Pointer(pCol)).FhName) == int32(hCol1) &&
		Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName, zCol) == 0) {
		goto __70
	}
	if !(iCol == int32((*Table)(unsafe.Pointer(pTab)).FiPKey)) {
		goto __71
	}
	iCol = -1
__71:
	;
	goto __69
__70:
	;
	goto __68
__68:
	iCol++
	pCol += 24
	goto __67
	goto __69
__69:
	;
	if !(iCol >= int32((*Table)(unsafe.Pointer(pTab)).FnCol) && Xsqlite3IsRowid(tls, zCol) != 0 && (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_NoVisibleRowid) == U32(0)) {
		goto __72
	}

	iCol = -1
__72:
	;
	if !(iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __73
	}
	cnt++
	pMatch = uintptr(0)
	if !((*Expr)(unsafe.Pointer(pExpr)).FiTable == EXCLUDED_TABLE_NUMBER) {
		goto __74
	}

	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __76
	}
	(*Expr)(unsafe.Pointer(pExpr)).FiColumn = YnVar(iCol)
	*(*uintptr)(unsafe.Pointer(pExpr + 64)) = pTab
	eNewExprOp = TK_COLUMN
	goto __77
__76:
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = (*Upsert)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNC + 16)))).FregData + int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(iCol)))
	eNewExprOp = TK_REGISTER
__77:
	;
	goto __75
__74:
	;
	*(*uintptr)(unsafe.Pointer(pExpr + 64)) = pTab
	if !((*Parse)(unsafe.Pointer(pParse)).FbReturning != 0) {
		goto __78
	}
	eNewExprOp = TK_REGISTER
	(*Expr)(unsafe.Pointer(pExpr)).Fop2 = U8(TK_COLUMN)
	(*Expr)(unsafe.Pointer(pExpr)).FiColumn = YnVar(iCol)
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = *(*int32)(unsafe.Pointer(pNC + 16)) + (int32((*Table)(unsafe.Pointer(pTab)).FnCol)+1)*(*Expr)(unsafe.Pointer(pExpr)).FiTable + int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(iCol))) + 1
	goto __79
__78:
	(*Expr)(unsafe.Pointer(pExpr)).FiColumn = I16(iCol)
	eNewExprOp = TK_TRIGGER
	if !(iCol < 0) {
		goto __80
	}
	(*Expr)(unsafe.Pointer(pExpr)).FaffExpr = uint8(SQLITE_AFF_INTEGER)
	goto __81
__80:
	if !((*Expr)(unsafe.Pointer(pExpr)).FiTable == 0) {
		goto __82
	}

	*(*U32)(unsafe.Pointer(pParse + 212)) |= func() uint32 {
		if iCol >= 32 {
			return 0xffffffff
		}
		return U32(1) << iCol
	}()
	goto __83
__82:
	;
	*(*U32)(unsafe.Pointer(pParse + 216)) |= func() uint32 {
		if iCol >= 32 {
			return 0xffffffff
		}
		return U32(1) << iCol
	}()
__83:
	;
__81:
	;
__79:
	;
__75:
	;
__73:
	;
__66:
	;
__56:
	;
	if !(cnt == 0 &&
		cntTab == 1 &&
		pMatch != 0 &&
		(*NameContext)(unsafe.Pointer(pNC)).FncFlags&(NC_IdxExpr|NC_GenCol) == 0 &&
		Xsqlite3IsRowid(tls, zCol) != 0 &&
		(*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pMatch)).FpTab)).FtabFlags&U32(TF_NoVisibleRowid) == U32(0)) {
		goto __84
	}
	cnt = 1
	(*Expr)(unsafe.Pointer(pExpr)).FiColumn = int16(-1)
	(*Expr)(unsafe.Pointer(pExpr)).FaffExpr = uint8(SQLITE_AFF_INTEGER)
__84:
	;
	if !(cnt == 0 &&
		(*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_UEList != 0 &&
		zTab == uintptr(0)) {
		goto __85
	}
	pEList = *(*uintptr)(unsafe.Pointer(pNC + 16))

	j = 0
__86:
	if !(j < (*ExprList)(unsafe.Pointer(pEList)).FnExpr) {
		goto __88
	}
	zAs = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*32)).FzEName
	if !(int32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(j)*32 + 16 + 4))&0x3>>0) == ENAME_NAME &&
		Xsqlite3_stricmp(tls, zAs, zCol) == 0) {
		goto __89
	}

	pOrig = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(j)*32)).FpExpr
	if !((*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_AllowAgg == 0 && (*Expr)(unsafe.Pointer(pOrig)).Fflags&U32(EP_Agg) != U32(0)) {
		goto __90
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+9680, libc.VaList(bp, zAs))
	return WRC_Abort
__90:
	;
	if !((*Expr)(unsafe.Pointer(pOrig)).Fflags&U32(EP_Win) != U32(0) &&
		((*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_AllowWin == 0 || pNC != pTopNC)) {
		goto __91
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+9711, libc.VaList(bp+8, zAs))
	return WRC_Abort
__91:
	;
	if !(Xsqlite3ExprVectorSize(tls, pOrig) != 1) {
		goto __92
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+9748, 0)
	return WRC_Abort
__92:
	;
	resolveAlias(tls, pParse, pEList, j, pExpr, nSubquery)
	cnt = 1
	pMatch = uintptr(0)

	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __93
	}
	Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr)
__93:
	;
	goto lookupname_end
__89:
	;
	goto __87
__87:
	j++
	goto __86
	goto __88
__88:
	;
__85:
	;
	if !(cnt != 0) {
		goto __94
	}
	goto __11
__94:
	;
	pNC = (*NameContext)(unsafe.Pointer(pNC)).FpNext
	nSubquery++
	goto __10
__10:
	if pNC != 0 {
		goto __9
	}
	goto __11
__11:
	;
	if !(cnt == 0 && zTab == uintptr(0)) {
		goto __95
	}

	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_DblQuoted) != U32(0) &&
		areDoubleQuotedStringsEnabled(tls, db, pTopNC) != 0) {
		goto __96
	}

	Xsqlite3_log(tls, SQLITE_WARNING,
		ts+9766, libc.VaList(bp+16, zCol))
	(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_STRING)
	libc.Xmemset(tls, pExpr+64, 0, uint64(unsafe.Sizeof(struct{ FpTab uintptr }{})))
	return WRC_Prune
__96:
	;
	if !(Xsqlite3ExprIdToTrueFalse(tls, pExpr) != 0) {
		goto __97
	}
	return WRC_Prune
__97:
	;
__95:
	;
	if !(cnt != 1) {
		goto __98
	}
	if !(*(*uintptr)(unsafe.Pointer(bp + 96)) != 0) {
		goto __99
	}
	if !((*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 96)))).FnExpr == cnt-1) {
		goto __100
	}
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Leaf) != U32(0)) {
		goto __102
	}
	*(*U32)(unsafe.Pointer(pExpr + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_Leaf))
	goto __103
__102:
	Xsqlite3ExprDelete(tls, db, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
	(*Expr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
	Xsqlite3ExprDelete(tls, db, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
	(*Expr)(unsafe.Pointer(pExpr)).FpRight = uintptr(0)
__103:
	;
	extendFJMatch(tls, pParse, bp+96, pMatch, (*Expr)(unsafe.Pointer(pExpr)).FiColumn)
	(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_FUNCTION)
	*(*uintptr)(unsafe.Pointer(pExpr + 8)) = ts + 9801
	*(*uintptr)(unsafe.Pointer(pExpr + 32)) = *(*uintptr)(unsafe.Pointer(bp + 96))
	cnt = 1
	goto lookupname_end
	goto __101
__100:
	Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp + 96)))
	*(*uintptr)(unsafe.Pointer(bp + 96)) = uintptr(0)
__101:
	;
__99:
	;
	if cnt == 0 {
		zErr = ts + 9810
	} else {
		zErr = ts + 9825
	}
	if !(zDb != 0) {
		goto __104
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+9847, libc.VaList(bp+24, zErr, zDb, zTab, zCol))
	goto __105
__104:
	if !(zTab != 0) {
		goto __106
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+9860, libc.VaList(bp+56, zErr, zTab, zCol))
	goto __107
__106:
	Xsqlite3ErrorMsg(tls, pParse, ts+9870, libc.VaList(bp+80, zErr, zCol))
__107:
	;
__105:
	;
	Xsqlite3RecordErrorOffsetOfExpr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
	(*Parse)(unsafe.Pointer(pParse)).FcheckSchema = U8(1)
	(*NameContext)(unsafe.Pointer(pTopNC)).FnNcErr++
__98:
	;
	if !!((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_TokenOnly|EP_Leaf) != U32(0)) {
		goto __108
	}
	Xsqlite3ExprDelete(tls, db, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
	(*Expr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
	Xsqlite3ExprDelete(tls, db, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
	(*Expr)(unsafe.Pointer(pExpr)).FpRight = uintptr(0)
	*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_Leaf)
__108:
	;
	if !(int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) >= 0 && pMatch != uintptr(0)) {
		goto __109
	}
	*(*Bitmask)(unsafe.Pointer(pMatch + 80)) |= Xsqlite3ExprColUsed(tls, pExpr)
__109:
	;
	(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(eNewExprOp)
lookupname_end:
	if !(cnt == 1) {
		goto __110
	}

	if !((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FxAuth != 0 &&
		(int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN || int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_TRIGGER)) {
		goto __112
	}
	Xsqlite3AuthRead(tls, pParse, pExpr, pSchema, (*NameContext)(unsafe.Pointer(pNC)).FpSrcList)
__112:
	;
__113:
	;
	(*NameContext)(unsafe.Pointer(pTopNC)).FnRef++
	if !(pTopNC == pNC) {
		goto __116
	}
	goto __115
__116:
	;
	pTopNC = (*NameContext)(unsafe.Pointer(pTopNC)).FpNext
	goto __114
__114:
	goto __113
	goto __115
__115:
	;
	return WRC_Prune
	goto __111
__110:
	return WRC_Abort
__111:
	;
	return int32(0)
}

func Xsqlite3CreateColumnExpr(tls *libc.TLS, db uintptr, pSrc uintptr, iSrc int32, iCol int32) uintptr {
	var p uintptr = Xsqlite3ExprAlloc(tls, db, TK_COLUMN, uintptr(0), 0)
	if p != 0 {
		var pItem uintptr = pSrc + 8 + uintptr(iSrc)*104
		var pTab uintptr

		pTab = libc.AssignPtrUintptr(p+64, (*SrcItem)(unsafe.Pointer(pItem)).FpTab)
		(*Expr)(unsafe.Pointer(p)).FiTable = (*SrcItem)(unsafe.Pointer(pItem)).FiCursor
		if int32((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FiPKey) == iCol {
			(*Expr)(unsafe.Pointer(p)).FiColumn = int16(-1)
		} else {
			(*Expr)(unsafe.Pointer(p)).FiColumn = YnVar(iCol)
			if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated) != U32(0) &&
				int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FcolFlags)&COLFLAG_GENERATED != 0 {
				(*SrcItem)(unsafe.Pointer(pItem)).FcolUsed = func() uint64 {
					if int32((*Table)(unsafe.Pointer(pTab)).FnCol) >= 64 {
						return libc.Uint64(libc.Uint64FromInt32(-1))
					}
					return uint64(1)<<int32((*Table)(unsafe.Pointer(pTab)).FnCol) - uint64(1)
				}()
			} else {
				*(*Bitmask)(unsafe.Pointer(pItem + 80)) |= uint64(1) << func() int32 {
					if iCol >= int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) {
						return int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) - 1
					}
					return iCol
				}()
			}
		}
	}
	return p
}

func notValidImpl(tls *libc.TLS, pParse uintptr, pNC uintptr, zMsg uintptr, pExpr uintptr, pError uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var zIn uintptr = ts + 9877
	if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_IdxExpr != 0 {
		zIn = ts + 9905
	} else if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_IsCheck != 0 {
		zIn = ts + 9923
	} else if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_GenCol != 0 {
		zIn = ts + 9941
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+9959, libc.VaList(bp, zMsg, zIn))
	if pExpr != 0 {
		(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_NULL)
	}
	Xsqlite3RecordErrorOffsetOfExpr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pError)
}

func exprProbability(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*float64)(unsafe.Pointer(bp)) = -1.0
	if int32((*Expr)(unsafe.Pointer(p)).Fop) != TK_FLOAT {
		return -1
	}

	Xsqlite3AtoF(tls, *(*uintptr)(unsafe.Pointer(p + 8)), bp, Xsqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(p + 8))), uint8(SQLITE_UTF8))

	if *(*float64)(unsafe.Pointer(bp)) > 1.0 {
		return -1
	}
	return libc.Int32FromFloat64(*(*float64)(unsafe.Pointer(bp)) * 134217728.0)
}

func resolveExprStep(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(96)
	defer tls.Free(96)

	var pNC uintptr
	var pParse uintptr

	pNC = *(*uintptr)(unsafe.Pointer(pWalker + 40))

	pParse = (*NameContext)(unsafe.Pointer(pNC)).FpParse

	switch int32((*Expr)(unsafe.Pointer(pExpr)).Fop) {
	case TK_ROW:
		{
			var pSrcList uintptr = (*NameContext)(unsafe.Pointer(pNC)).FpSrcList
			var pItem uintptr

			pItem = pSrcList + 8
			(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_COLUMN)

			*(*uintptr)(unsafe.Pointer(pExpr + 64)) = (*SrcItem)(unsafe.Pointer(pItem)).FpTab
			(*Expr)(unsafe.Pointer(pExpr)).FiTable = (*SrcItem)(unsafe.Pointer(pItem)).FiCursor
			(*Expr)(unsafe.Pointer(pExpr)).FiColumn--
			(*Expr)(unsafe.Pointer(pExpr)).FaffExpr = uint8(SQLITE_AFF_INTEGER)
			break

		}

	case TK_NOTNULL:
		fallthrough
	case TK_ISNULL:
		{
			var p uintptr
			var i int32
			i = 0
			p = pNC
		__1:
			if !(p != 0 && i < int32(uint64(unsafe.Sizeof([8]int32{}))/uint64(unsafe.Sizeof(int32(0))))) {
				goto __3
			}
			{
				*(*int32)(unsafe.Pointer(bp + 64 + uintptr(i)*4)) = (*NameContext)(unsafe.Pointer(p)).FnRef

			}
			goto __2
		__2:
			p = (*NameContext)(unsafe.Pointer(p)).FpNext
			i++
			goto __1
			goto __3
		__3:
			;
			Xsqlite3WalkExpr(tls, pWalker, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
			if 0 == Xsqlite3ExprCanBeNull(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft) && !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
				*(*int32)(unsafe.Pointer(pExpr + 8)) = libc.Bool32(int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_NOTNULL)
				*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_IntValue)
				(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_INTEGER)

				i = 0
				p = pNC
			__4:
				if !(p != 0 && i < int32(uint64(unsafe.Sizeof([8]int32{}))/uint64(unsafe.Sizeof(int32(0))))) {
					goto __6
				}
				{
					(*NameContext)(unsafe.Pointer(p)).FnRef = *(*int32)(unsafe.Pointer(bp + 64 + uintptr(i)*4))

				}
				goto __5
			__5:
				p = (*NameContext)(unsafe.Pointer(p)).FpNext
				i++
				goto __4
				goto __6
			__6:
				;
				Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
				(*Expr)(unsafe.Pointer(pExpr)).FpLeft = uintptr(0)
			}
			return WRC_Prune

		}

	case TK_ID:
		fallthrough
	case TK_DOT:
		{
			var zColumn uintptr
			var zTable uintptr
			var zDb uintptr
			var pRight uintptr

			if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_ID {
				zDb = uintptr(0)
				zTable = uintptr(0)

				zColumn = *(*uintptr)(unsafe.Pointer(pExpr + 8))
			} else {
				var pLeft uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft

				if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&(NC_IdxExpr|NC_GenCol) != 0 {
					notValidImpl(tls, pParse, pNC, ts+9979, uintptr(0), pExpr)
				}

				pRight = (*Expr)(unsafe.Pointer(pExpr)).FpRight
				if int32((*Expr)(unsafe.Pointer(pRight)).Fop) == TK_ID {
					zDb = uintptr(0)
				} else {
					zDb = *(*uintptr)(unsafe.Pointer(pLeft + 8))
					pLeft = (*Expr)(unsafe.Pointer(pRight)).FpLeft
					pRight = (*Expr)(unsafe.Pointer(pRight)).FpRight
				}

				zTable = *(*uintptr)(unsafe.Pointer(pLeft + 8))
				zColumn = *(*uintptr)(unsafe.Pointer(pRight + 8))

				if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
					Xsqlite3RenameTokenRemap(tls, pParse, pExpr, pRight)
					Xsqlite3RenameTokenRemap(tls, pParse, pExpr+64, pLeft)
				}
			}
			return lookupName(tls, pParse, zDb, zTable, zColumn, pNC, pExpr)

		}

	case TK_FUNCTION:
		{
			var pList uintptr = *(*uintptr)(unsafe.Pointer(pExpr + 32))
			var n int32
			if pList != 0 {
				n = (*ExprList)(unsafe.Pointer(pList)).FnExpr
			} else {
				n = 0
			}
			var no_such_func int32 = 0
			var wrong_num_args int32 = 0
			var is_agg int32 = 0
			var zId uintptr
			var pDef uintptr
			var enc U8 = (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fenc
			var savedAllowFlags int32 = (*NameContext)(unsafe.Pointer(pNC)).FncFlags & (NC_AllowAgg | NC_AllowWin)
			var pWin uintptr = func() uintptr {
				if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) && int32((*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FeFrmType) != TK_FILTER {
					return *(*uintptr)(unsafe.Pointer(pExpr + 64))
				}
				return uintptr(0)
			}()

			zId = *(*uintptr)(unsafe.Pointer(pExpr + 8))
			pDef = Xsqlite3FindFunction(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, zId, n, enc, uint8(0))
			if pDef == uintptr(0) {
				pDef = Xsqlite3FindFunction(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, zId, -2, enc, uint8(0))
				if pDef == uintptr(0) {
					no_such_func = 1
				} else {
					wrong_num_args = 1
				}
			} else {
				is_agg = libc.Bool32((*FuncDef)(unsafe.Pointer(pDef)).FxFinalize != uintptr(0))
				if (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_UNLIKELY) != 0 {
					*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_Unlikely)
					if n == 2 {
						(*Expr)(unsafe.Pointer(pExpr)).FiTable = exprProbability(tls, (*ExprList_item)(unsafe.Pointer(pList+8+1*32)).FpExpr)
						if (*Expr)(unsafe.Pointer(pExpr)).FiTable < 0 {
							Xsqlite3ErrorMsg(tls, pParse,
								ts+9996, libc.VaList(bp, pExpr))
							(*NameContext)(unsafe.Pointer(pNC)).FnNcErr++
						}
					} else {
						(*Expr)(unsafe.Pointer(pExpr)).FiTable = func() int32 {
							if int32(*(*uint8)(unsafe.Pointer((*FuncDef)(unsafe.Pointer(pDef)).FzName))) == 'u' {
								return 8388608
							}
							return 125829120
						}()
					}
				}
				{
					var auth int32 = Xsqlite3AuthCheck(tls, pParse, SQLITE_FUNCTION, uintptr(0), (*FuncDef)(unsafe.Pointer(pDef)).FzName, uintptr(0))
					if auth != SQLITE_OK {
						if auth == SQLITE_DENY {
							Xsqlite3ErrorMsg(tls, pParse, ts+10060,
								libc.VaList(bp+8, pExpr))
							(*NameContext)(unsafe.Pointer(pNC)).FnNcErr++
						}
						(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_NULL)
						return WRC_Prune
					}

				}
				if (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_CONSTANT|SQLITE_FUNC_SLOCHNG) != 0 {
					*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_ConstFunc)
				}
				if (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_CONSTANT) == U32(0) {
					if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&(NC_IdxExpr|NC_PartIdx|NC_GenCol) != 0 {
						notValidImpl(tls, pParse, pNC, ts+10096, uintptr(0), pExpr)
					}

				} else {
					(*Expr)(unsafe.Pointer(pExpr)).Fop2 = U8((*NameContext)(unsafe.Pointer(pNC)).FncFlags & NC_SelfRef)
					if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_FromDDL != 0 {
						*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_FromDDL)
					}
				}
				if (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_INTERNAL) != U32(0) &&
					int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0 &&
					(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmDbFlags&U32(DBFLAG_InternalFunc) == U32(0) {
					no_such_func = 1
					pDef = uintptr(0)
				} else if (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE) != U32(0) &&
					!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
					Xsqlite3ExprFunctionUsable(tls, pParse, pExpr, pDef)
				}
			}

			if 0 == libc.Bool32(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
				if pDef != 0 && (*FuncDef)(unsafe.Pointer(pDef)).FxValue == uintptr(0) && pWin != 0 {
					Xsqlite3ErrorMsg(tls, pParse,
						ts+10124, libc.VaList(bp+16, pExpr))
					(*NameContext)(unsafe.Pointer(pNC)).FnNcErr++
				} else if is_agg != 0 && (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_AllowAgg == 0 ||
					is_agg != 0 && (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_WINDOW) != 0 && !(pWin != 0) ||
					is_agg != 0 && pWin != 0 && (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_AllowWin == 0 {
					var zType uintptr
					if (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_WINDOW) != 0 || pWin != 0 {
						zType = ts + 10167
					} else {
						zType = ts + 10174
					}
					Xsqlite3ErrorMsg(tls, pParse, ts+10184, libc.VaList(bp+24, zType, pExpr))
					(*NameContext)(unsafe.Pointer(pNC)).FnNcErr++
					is_agg = 0
				} else if no_such_func != 0 && int32((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Finit.Fbusy) == 0 {
					Xsqlite3ErrorMsg(tls, pParse, ts+10212, libc.VaList(bp+40, pExpr))
					(*NameContext)(unsafe.Pointer(pNC)).FnNcErr++
				} else if wrong_num_args != 0 {
					Xsqlite3ErrorMsg(tls, pParse, ts+10234,
						libc.VaList(bp+48, pExpr))
					(*NameContext)(unsafe.Pointer(pNC)).FnNcErr++
				} else if is_agg == 0 && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
					Xsqlite3ErrorMsg(tls, pParse,
						ts+10278,
						libc.VaList(bp+56, pExpr))
					(*NameContext)(unsafe.Pointer(pNC)).FnNcErr++
				}
				if is_agg != 0 {
					*(*int32)(unsafe.Pointer(pNC + 40)) &= ^(NC_AllowWin | func() int32 {
						if !(pWin != 0) {
							return NC_AllowAgg
						}
						return 0
					}())
				}
			} else if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
				is_agg = 1
			}
			Xsqlite3WalkExprList(tls, pWalker, pList)
			if is_agg != 0 {
				if pWin != 0 {
					var pSel uintptr = (*NameContext)(unsafe.Pointer(pNC)).FpWinSelect

					if libc.Bool32(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) == 0 {
						Xsqlite3WindowUpdate(tls, pParse, func() uintptr {
							if pSel != 0 {
								return (*Select)(unsafe.Pointer(pSel)).FpWinDefn
							}
							return uintptr(0)
						}(), pWin, pDef)
						if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
							break
						}
					}
					Xsqlite3WalkExprList(tls, pWalker, (*Window)(unsafe.Pointer(pWin)).FpPartition)
					Xsqlite3WalkExprList(tls, pWalker, (*Window)(unsafe.Pointer(pWin)).FpOrderBy)
					Xsqlite3WalkExpr(tls, pWalker, (*Window)(unsafe.Pointer(pWin)).FpFilter)
					Xsqlite3WindowLink(tls, pSel, pWin)
					*(*int32)(unsafe.Pointer(pNC + 40)) |= NC_HasWin
				} else {
					var pNC2 uintptr
					(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_AGG_FUNCTION)
					(*Expr)(unsafe.Pointer(pExpr)).Fop2 = U8(0)
					if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
						Xsqlite3WalkExpr(tls, pWalker, (*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FpFilter)
					}
					pNC2 = pNC
					for pNC2 != 0 &&
						Xsqlite3ReferencesSrcList(tls, pParse, pExpr, (*NameContext)(unsafe.Pointer(pNC2)).FpSrcList) == 0 {
						(*Expr)(unsafe.Pointer(pExpr)).Fop2++
						pNC2 = (*NameContext)(unsafe.Pointer(pNC2)).FpNext
					}

					if pNC2 != 0 && pDef != 0 {
						*(*int32)(unsafe.Pointer(pNC2 + 40)) |= int32(U32(NC_HasAgg) |
							((*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags^U32(SQLITE_FUNC_ANYORDER))&
								U32(SQLITE_FUNC_MINMAX|SQLITE_FUNC_ANYORDER))
					}
				}
				*(*int32)(unsafe.Pointer(pNC + 40)) |= savedAllowFlags
			}

			return WRC_Prune

		}
	case TK_SELECT:
		fallthrough
	case TK_EXISTS:
		fallthrough
	case TK_IN:
		{
			if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
				var nRef int32 = (*NameContext)(unsafe.Pointer(pNC)).FnRef

				if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_SelfRef != 0 {
					notValidImpl(tls, pParse, pNC, ts+10326, pExpr, pExpr)
				} else {
					Xsqlite3WalkSelect(tls, pWalker, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
				}

				if nRef != (*NameContext)(unsafe.Pointer(pNC)).FnRef {
					*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_VarSelect)
				}
				*(*int32)(unsafe.Pointer(pNC + 40)) |= NC_Subquery
			}
			break

		}
	case TK_VARIABLE:
		{
			if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&(NC_IsCheck|NC_PartIdx|NC_IdxExpr|NC_GenCol) != 0 {
				notValidImpl(tls, pParse, pNC, ts+10337, pExpr, pExpr)
			}

			break

		}
	case TK_IS:
		fallthrough
	case TK_ISNOT:
		{
			var pRight uintptr = Xsqlite3ExprSkipCollateAndLikely(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight)

			if pRight != 0 && (int32((*Expr)(unsafe.Pointer(pRight)).Fop) == TK_ID || int32((*Expr)(unsafe.Pointer(pRight)).Fop) == TK_TRUEFALSE) {
				var rc int32 = resolveExprStep(tls, pWalker, pRight)
				if rc == WRC_Abort {
					return WRC_Abort
				}
				if int32((*Expr)(unsafe.Pointer(pRight)).Fop) == TK_TRUEFALSE {
					(*Expr)(unsafe.Pointer(pExpr)).Fop2 = (*Expr)(unsafe.Pointer(pExpr)).Fop
					(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_TRUTH)
					return WRC_Continue
				}
			}

		}
		fallthrough
	case TK_BETWEEN:
		fallthrough
	case TK_EQ:
		fallthrough
	case TK_NE:
		fallthrough
	case TK_LT:
		fallthrough
	case TK_LE:
		fallthrough
	case TK_GT:
		fallthrough
	case TK_GE:
		{
			var nLeft int32
			var nRight int32
			if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
				break
			}

			nLeft = Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
			if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_BETWEEN {
				nRight = Xsqlite3ExprVectorSize(tls, (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32))+8)).FpExpr)
				if nRight == nLeft {
					nRight = Xsqlite3ExprVectorSize(tls, (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32))+8+1*32)).FpExpr)
				}
			} else {
				nRight = Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
			}
			if nLeft != nRight {
				Xsqlite3ErrorMsg(tls, pParse, ts+9748, 0)
				Xsqlite3RecordErrorOffsetOfExpr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
			}
			break

		}
	}

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return WRC_Abort
	}
	return WRC_Continue
}

func resolveAsName(tls *libc.TLS, pParse uintptr, pEList uintptr, pE uintptr) int32 {
	var i int32

	_ = pParse

	if int32((*Expr)(unsafe.Pointer(pE)).Fop) == TK_ID {
		var zCol uintptr

		zCol = *(*uintptr)(unsafe.Pointer(pE + 8))
		for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
			if int32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0x3>>0) == ENAME_NAME &&
				Xsqlite3_stricmp(tls, (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(i)*32)).FzEName, zCol) == 0 {
				return i + 1
			}
		}
	}
	return 0
}

func resolveOrderByTermToExprList(tls *libc.TLS, pParse uintptr, pSelect uintptr, pE uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var i int32
	var pEList uintptr

	var db uintptr
	var rc int32
	var savedSuppErr U8

	pEList = (*Select)(unsafe.Pointer(pSelect)).FpEList

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp)).FpParse = pParse
	(*NameContext)(unsafe.Pointer(bp)).FpSrcList = (*Select)(unsafe.Pointer(pSelect)).FpSrc
	*(*uintptr)(unsafe.Pointer(bp + 16)) = pEList
	(*NameContext)(unsafe.Pointer(bp)).FncFlags = NC_AllowAgg | NC_UEList | NC_NoSelect
	(*NameContext)(unsafe.Pointer(bp)).FnNcErr = 0
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	savedSuppErr = (*Sqlite3)(unsafe.Pointer(db)).FsuppressErr
	(*Sqlite3)(unsafe.Pointer(db)).FsuppressErr = U8(1)
	rc = Xsqlite3ResolveExprNames(tls, bp, pE)
	(*Sqlite3)(unsafe.Pointer(db)).FsuppressErr = savedSuppErr
	if rc != 0 {
		return 0
	}

	for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
		if Xsqlite3ExprCompare(tls, uintptr(0), (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(i)*32)).FpExpr, pE, -1) < 2 {
			return i + 1
		}
	}

	return 0
}

func resolveOutOfRangeError(tls *libc.TLS, pParse uintptr, zType uintptr, i int32, mx int32, pError uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	Xsqlite3ErrorMsg(tls, pParse,
		ts+10348, libc.VaList(bp, i, zType, mx))
	Xsqlite3RecordErrorOffsetOfExpr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pError)
}

func resolveCompoundOrderBy(tls *libc.TLS, pParse uintptr, pSelect uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var i int32
	var pOrderBy uintptr
	var pEList uintptr
	var db uintptr
	var moreToDo int32 = 1

	pOrderBy = (*Select)(unsafe.Pointer(pSelect)).FpOrderBy
	if pOrderBy == uintptr(0) {
		return 0
	}
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr > *(*int32)(unsafe.Pointer(db + 136 + 2*4)) {
		Xsqlite3ErrorMsg(tls, pParse, ts+10404, 0)
		return 1
	}
	for i = 0; i < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr; i++ {
		libc.SetBitFieldPtr16Uint32(pOrderBy+8+uintptr(i)*32+16+4, uint32(0), 2, 0x4)
	}
	(*Select)(unsafe.Pointer(pSelect)).FpNext = uintptr(0)
	for (*Select)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		(*Select)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpPrior)).FpNext = pSelect
		pSelect = (*Select)(unsafe.Pointer(pSelect)).FpPrior
	}
	for pSelect != 0 && moreToDo != 0 {
		var pItem uintptr
		moreToDo = 0
		pEList = (*Select)(unsafe.Pointer(pSelect)).FpEList

		i = 0
		pItem = pOrderBy + 8
	__1:
		if !(i < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
			goto __3
		}
		{
			*(*int32)(unsafe.Pointer(bp + 8)) = -1
			var pE uintptr
			var pDup uintptr
			if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 16 + 4))&0x4>>2)) != 0 {
				goto __2
			}
			pE = Xsqlite3ExprSkipCollateAndLikely(tls, (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			if pE == uintptr(0) {
				goto __2
			}
			if Xsqlite3ExprIsInteger(tls, pE, bp+8) != 0 {
				if *(*int32)(unsafe.Pointer(bp + 8)) <= 0 || *(*int32)(unsafe.Pointer(bp + 8)) > (*ExprList)(unsafe.Pointer(pEList)).FnExpr {
					resolveOutOfRangeError(tls, pParse, ts+10438, i+1, (*ExprList)(unsafe.Pointer(pEList)).FnExpr, pE)
					return 1
				}
			} else {
				*(*int32)(unsafe.Pointer(bp + 8)) = resolveAsName(tls, pParse, pEList, pE)
				if *(*int32)(unsafe.Pointer(bp + 8)) == 0 {
					pDup = Xsqlite3ExprDup(tls, db, pE, 0)
					if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
						*(*int32)(unsafe.Pointer(bp + 8)) = resolveOrderByTermToExprList(tls, pParse, pSelect, pDup)
						if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && *(*int32)(unsafe.Pointer(bp + 8)) > 0 {
							resolveOrderByTermToExprList(tls, pParse, pSelect, pE)
						}
					}
					Xsqlite3ExprDelete(tls, db, pDup)
				}
			}
			if *(*int32)(unsafe.Pointer(bp + 8)) > 0 {
				if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
					var pNew uintptr = Xsqlite3Expr(tls, db, TK_INTEGER, uintptr(0))
					if pNew == uintptr(0) {
						return 1
					}
					*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(EP_IntValue)
					*(*int32)(unsafe.Pointer(pNew + 8)) = *(*int32)(unsafe.Pointer(bp + 8))
					if (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr == pE {
						(*ExprList_item)(unsafe.Pointer(pItem)).FpExpr = pNew
					} else {
						var pParent uintptr = (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr

						for int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pParent)).FpLeft)).Fop) == TK_COLLATE {
							pParent = (*Expr)(unsafe.Pointer(pParent)).FpLeft
						}

						(*Expr)(unsafe.Pointer(pParent)).FpLeft = pNew
					}
					Xsqlite3ExprDelete(tls, db, pE)
					*(*U16)(unsafe.Pointer(pItem + 24)) = U16(*(*int32)(unsafe.Pointer(bp + 8)))
				}
				libc.SetBitFieldPtr16Uint32(pItem+16+4, uint32(1), 2, 0x4)
			} else {
				moreToDo = 1
			}

		}
		goto __2
	__2:
		i++
		pItem += 32
		goto __1
		goto __3
	__3:
		;
		pSelect = (*Select)(unsafe.Pointer(pSelect)).FpNext
	}
	for i = 0; i < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr; i++ {
		if int32(*(*uint16)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32 + 16 + 4))&0x4>>2) == 0 {
			Xsqlite3ErrorMsg(tls, pParse,
				ts+10444, libc.VaList(bp, i+1))
			return 1
		}
	}
	return 0
}

func Xsqlite3ResolveOrderGroupBy(tls *libc.TLS, pParse uintptr, pSelect uintptr, pOrderBy uintptr, zType uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var i int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pEList uintptr
	var pItem uintptr

	if pOrderBy == uintptr(0) || (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 || int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
		return 0
	}
	if (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr > *(*int32)(unsafe.Pointer(db + 136 + 2*4)) {
		Xsqlite3ErrorMsg(tls, pParse, ts+10505, libc.VaList(bp, zType))
		return 1
	}
	pEList = (*Select)(unsafe.Pointer(pSelect)).FpEList

	i = 0
	pItem = pOrderBy + 8
__1:
	if !(i < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
		goto __3
	}
	{
		if *(*U16)(unsafe.Pointer(pItem + 24)) != 0 {
			if int32(*(*U16)(unsafe.Pointer(pItem + 24))) > (*ExprList)(unsafe.Pointer(pEList)).FnExpr {
				resolveOutOfRangeError(tls, pParse, zType, i+1, (*ExprList)(unsafe.Pointer(pEList)).FnExpr, uintptr(0))
				return 1
			}
			resolveAlias(tls, pParse, pEList, int32(*(*U16)(unsafe.Pointer(pItem + 24)))-1, (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr, 0)
		}

	}
	goto __2
__2:
	i++
	pItem += 32
	goto __1
	goto __3
__3:
	;
	return 0
}

func resolveRemoveWindowsCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	_ = pWalker
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
		var pWin uintptr = *(*uintptr)(unsafe.Pointer(pExpr + 64))
		Xsqlite3WindowUnlinkFromSelect(tls, pWin)
	}
	return WRC_Continue
}

func windowRemoveExprFromSelect(tls *libc.TLS, pSelect uintptr, pExpr uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if (*Select)(unsafe.Pointer(pSelect)).FpWin != 0 {
		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
		(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		}{resolveRemoveWindowsCb}))
		*(*uintptr)(unsafe.Pointer(bp + 40)) = pSelect
		Xsqlite3WalkExpr(tls, bp, pExpr)
	}
}

func resolveOrderGroupBy(tls *libc.TLS, pNC uintptr, pSelect uintptr, pOrderBy uintptr, zType uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var i int32
	var j int32

	var pItem uintptr
	var pParse uintptr
	var nResult int32

	nResult = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpEList)).FnExpr
	pParse = (*NameContext)(unsafe.Pointer(pNC)).FpParse
	i = 0
	pItem = pOrderBy + 8
__1:
	if !(i < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr) {
		goto __3
	}
	{
		var pE uintptr = (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr
		var pE2 uintptr = Xsqlite3ExprSkipCollateAndLikely(tls, pE)
		if pE2 == uintptr(0) {
			goto __2
		}
		if int32(*(*uint8)(unsafe.Pointer(zType))) != 'G' {
			*(*int32)(unsafe.Pointer(bp)) = resolveAsName(tls, pParse, (*Select)(unsafe.Pointer(pSelect)).FpEList, pE2)
			if *(*int32)(unsafe.Pointer(bp)) > 0 {
				*(*U16)(unsafe.Pointer(pItem + 24)) = U16(*(*int32)(unsafe.Pointer(bp)))
				goto __2
			}
		}
		if Xsqlite3ExprIsInteger(tls, pE2, bp) != 0 {
			if *(*int32)(unsafe.Pointer(bp)) < 1 || *(*int32)(unsafe.Pointer(bp)) > 0xffff {
				resolveOutOfRangeError(tls, pParse, zType, i+1, nResult, pE2)
				return 1
			}
			*(*U16)(unsafe.Pointer(pItem + 24)) = U16(*(*int32)(unsafe.Pointer(bp)))
			goto __2
		}

		*(*U16)(unsafe.Pointer(pItem + 24)) = U16(0)
		if Xsqlite3ResolveExprNames(tls, pNC, pE) != 0 {
			return 1
		}
		for j = 0; j < (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpEList)).FnExpr; j++ {
			if Xsqlite3ExprCompare(tls, uintptr(0), pE, (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpEList+8+uintptr(j)*32)).FpExpr, -1) == 0 {
				windowRemoveExprFromSelect(tls, pSelect, pE)
				*(*U16)(unsafe.Pointer(pItem + 24)) = U16(j + 1)
			}
		}

	}
	goto __2
__2:
	i++
	pItem += 32
	goto __1
	goto __3
__3:
	;
	return Xsqlite3ResolveOrderGroupBy(tls, pParse, pSelect, pOrderBy, zType)
}

func resolveSelectStep(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var pOuterNC uintptr

	var isCompound int32
	var nCompound int32
	var pParse uintptr
	var i int32
	var pGroupBy uintptr
	var pLeftmost uintptr
	var db uintptr

	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Resolved) != 0 {
		return WRC_Prune
	}
	pOuterNC = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	pParse = (*Walker)(unsafe.Pointer(pWalker)).FpParse
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Expanded) == U32(0) {
		Xsqlite3SelectPrep(tls, pParse, p, pOuterNC)
		if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
			return WRC_Abort
		}
		return WRC_Prune
	}

	isCompound = libc.Bool32((*Select)(unsafe.Pointer(p)).FpPrior != uintptr(0))
	nCompound = 0
	pLeftmost = p
	for p != 0 {
		*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_Resolved)

		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(NameContext{})))
		(*NameContext)(unsafe.Pointer(bp)).FpParse = pParse
		(*NameContext)(unsafe.Pointer(bp)).FpWinSelect = p
		if Xsqlite3ResolveExprNames(tls, bp, (*Select)(unsafe.Pointer(p)).FpLimit) != 0 {
			return WRC_Abort
		}

		if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Converted) != 0 {
			var pSub uintptr = (*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FpSelect

			(*Select)(unsafe.Pointer(pSub)).FpOrderBy = (*Select)(unsafe.Pointer(p)).FpOrderBy
			(*Select)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
		}

		for i = 0; i < (*SrcList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc)).FnSrc; i++ {
			var pItem uintptr = (*Select)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*104
			if (*SrcItem)(unsafe.Pointer(pItem)).FpSelect != 0 && (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpSelect)).FselFlags&U32(SF_Resolved) == U32(0) {
				var nRef int32
				if pOuterNC != 0 {
					nRef = (*NameContext)(unsafe.Pointer(pOuterNC)).FnRef
				} else {
					nRef = 0
				}
				var zSavedContext uintptr = (*Parse)(unsafe.Pointer(pParse)).FzAuthContext

				if (*SrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
					(*Parse)(unsafe.Pointer(pParse)).FzAuthContext = (*SrcItem)(unsafe.Pointer(pItem)).FzName
				}
				Xsqlite3ResolveSelectNames(tls, pParse, (*SrcItem)(unsafe.Pointer(pItem)).FpSelect, pOuterNC)
				(*Parse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedContext
				if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
					return WRC_Abort
				}

				if pOuterNC != 0 {
					libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(libc.Bool32((*NameContext)(unsafe.Pointer(pOuterNC)).FnRef > nRef)), 3, 0x8)
				}
			}
		}

		(*NameContext)(unsafe.Pointer(bp)).FncFlags = NC_AllowAgg | NC_AllowWin
		(*NameContext)(unsafe.Pointer(bp)).FpSrcList = (*Select)(unsafe.Pointer(p)).FpSrc
		(*NameContext)(unsafe.Pointer(bp)).FpNext = pOuterNC

		if Xsqlite3ResolveExprListNames(tls, bp, (*Select)(unsafe.Pointer(p)).FpEList) != 0 {
			return WRC_Abort
		}
		*(*int32)(unsafe.Pointer(bp + 40)) &= libc.CplInt32(NC_AllowWin)

		pGroupBy = (*Select)(unsafe.Pointer(p)).FpGroupBy
		if pGroupBy != 0 || (*NameContext)(unsafe.Pointer(bp)).FncFlags&NC_HasAgg != 0 {
			*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_Aggregate | (*NameContext)(unsafe.Pointer(bp)).FncFlags&(NC_MinMaxAgg|NC_OrderAgg))
		} else {
			*(*int32)(unsafe.Pointer(bp + 40)) &= libc.CplInt32(NC_AllowAgg)
		}

		*(*uintptr)(unsafe.Pointer(bp + 16)) = (*Select)(unsafe.Pointer(p)).FpEList
		*(*int32)(unsafe.Pointer(bp + 40)) |= NC_UEList
		if (*Select)(unsafe.Pointer(p)).FpHaving != 0 {
			if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Aggregate) == U32(0) {
				Xsqlite3ErrorMsg(tls, pParse, ts+10536, 0)
				return WRC_Abort
			}
			if Xsqlite3ResolveExprNames(tls, bp, (*Select)(unsafe.Pointer(p)).FpHaving) != 0 {
				return WRC_Abort
			}
		}
		if Xsqlite3ResolveExprNames(tls, bp, (*Select)(unsafe.Pointer(p)).FpWhere) != 0 {
			return WRC_Abort
		}

		for i = 0; i < (*SrcList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc)).FnSrc; i++ {
			var pItem uintptr = (*Select)(unsafe.Pointer(p)).FpSrc + 8 + uintptr(i)*104
			if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x4>>2)) != 0 &&
				Xsqlite3ResolveExprListNames(tls, bp, *(*uintptr)(unsafe.Pointer(pItem + 88))) != 0 {
				return WRC_Abort
			}
		}

		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			var pWin uintptr
			for pWin = (*Select)(unsafe.Pointer(p)).FpWinDefn; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
				if Xsqlite3ResolveExprListNames(tls, bp, (*Window)(unsafe.Pointer(pWin)).FpOrderBy) != 0 ||
					Xsqlite3ResolveExprListNames(tls, bp, (*Window)(unsafe.Pointer(pWin)).FpPartition) != 0 {
					return WRC_Abort
				}
			}
		}

		(*NameContext)(unsafe.Pointer(bp)).FpNext = uintptr(0)
		*(*int32)(unsafe.Pointer(bp + 40)) |= NC_AllowAgg | NC_AllowWin

		if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Converted) != 0 {
			var pSub uintptr = (*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FpSelect
			(*Select)(unsafe.Pointer(p)).FpOrderBy = (*Select)(unsafe.Pointer(pSub)).FpOrderBy
			(*Select)(unsafe.Pointer(pSub)).FpOrderBy = uintptr(0)
		}

		if (*Select)(unsafe.Pointer(p)).FpOrderBy != uintptr(0) &&
			isCompound <= nCompound &&
			resolveOrderGroupBy(tls, bp, p, (*Select)(unsafe.Pointer(p)).FpOrderBy, ts+10438) != 0 {
			return WRC_Abort
		}
		if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return WRC_Abort
		}
		*(*int32)(unsafe.Pointer(bp + 40)) &= libc.CplInt32(NC_AllowWin)

		if pGroupBy != 0 {
			var pItem uintptr

			if resolveOrderGroupBy(tls, bp, p, pGroupBy, ts+10575) != 0 || (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				return WRC_Abort
			}
			i = 0
			pItem = pGroupBy + 8
		__1:
			if !(i < (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
				goto __3
			}
			{
				if (*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pItem)).FpExpr)).Fflags&U32(EP_Agg) != U32(0) {
					Xsqlite3ErrorMsg(tls, pParse,
						ts+10581, 0)
					return WRC_Abort
				}

			}
			goto __2
		__2:
			i++
			pItem += 32
			goto __1
			goto __3
		__3:
		}

		if (*Select)(unsafe.Pointer(p)).FpNext != 0 && (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr != (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpNext)).FpEList)).FnExpr {
			Xsqlite3SelectWrongNumTermsError(tls, pParse, (*Select)(unsafe.Pointer(p)).FpNext)
			return WRC_Abort
		}

		p = (*Select)(unsafe.Pointer(p)).FpPrior
		nCompound++
	}

	if isCompound != 0 && resolveCompoundOrderBy(tls, pParse, pLeftmost) != 0 {
		return WRC_Abort
	}

	return WRC_Prune
}

func Xsqlite3ResolveExprNames(tls *libc.TLS, pNC uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var savedHasAgg int32

	if pExpr == uintptr(0) {
		return SQLITE_OK
	}
	savedHasAgg = (*NameContext)(unsafe.Pointer(pNC)).FncFlags & (NC_HasAgg | NC_MinMaxAgg | NC_HasWin | NC_OrderAgg)
	*(*int32)(unsafe.Pointer(pNC + 40)) &= libc.CplInt32(NC_HasAgg | NC_MinMaxAgg | NC_HasWin | NC_OrderAgg)
	(*Walker)(unsafe.Pointer(bp)).FpParse = (*NameContext)(unsafe.Pointer(pNC)).FpParse
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{resolveExprStep}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = func() uintptr {
		if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_NoSelect != 0 {
			return uintptr(0)
		}
		return *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		}{resolveSelectStep}))
	}()
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 40)) = pNC
	*(*int32)(unsafe.Pointer((*Walker)(unsafe.Pointer(bp)).FpParse + 316)) += (*Expr)(unsafe.Pointer(pExpr)).FnHeight
	if Xsqlite3ExprCheckHeight(tls, (*Walker)(unsafe.Pointer(bp)).FpParse, (*Parse)(unsafe.Pointer((*Walker)(unsafe.Pointer(bp)).FpParse)).FnHeight) != 0 {
		return SQLITE_ERROR
	}
	Xsqlite3WalkExpr(tls, bp, pExpr)
	*(*int32)(unsafe.Pointer((*Walker)(unsafe.Pointer(bp)).FpParse + 316)) -= (*Expr)(unsafe.Pointer(pExpr)).FnHeight

	*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32((*NameContext)(unsafe.Pointer(pNC)).FncFlags & (NC_HasAgg | NC_HasWin))
	*(*int32)(unsafe.Pointer(pNC + 40)) |= savedHasAgg
	return libc.Bool32((*NameContext)(unsafe.Pointer(pNC)).FnNcErr > 0 || (*Parse)(unsafe.Pointer((*Walker)(unsafe.Pointer(bp)).FpParse)).FnErr > 0)
}

func Xsqlite3ResolveExprListNames(tls *libc.TLS, pNC uintptr, pList uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var i int32
	var savedHasAgg int32 = 0

	if pList == uintptr(0) {
		return WRC_Continue
	}
	(*Walker)(unsafe.Pointer(bp)).FpParse = (*NameContext)(unsafe.Pointer(pNC)).FpParse
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{resolveExprStep}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{resolveSelectStep}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 40)) = pNC
	savedHasAgg = (*NameContext)(unsafe.Pointer(pNC)).FncFlags & (NC_HasAgg | NC_MinMaxAgg | NC_HasWin | NC_OrderAgg)
	*(*int32)(unsafe.Pointer(pNC + 40)) &= libc.CplInt32(NC_HasAgg | NC_MinMaxAgg | NC_HasWin | NC_OrderAgg)
	for i = 0; i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
		var pExpr uintptr = (*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32)).FpExpr
		if pExpr == uintptr(0) {
			continue
		}
		*(*int32)(unsafe.Pointer((*Walker)(unsafe.Pointer(bp)).FpParse + 316)) += (*Expr)(unsafe.Pointer(pExpr)).FnHeight
		if Xsqlite3ExprCheckHeight(tls, (*Walker)(unsafe.Pointer(bp)).FpParse, (*Parse)(unsafe.Pointer((*Walker)(unsafe.Pointer(bp)).FpParse)).FnHeight) != 0 {
			return WRC_Abort
		}
		Xsqlite3WalkExpr(tls, bp, pExpr)
		*(*int32)(unsafe.Pointer((*Walker)(unsafe.Pointer(bp)).FpParse + 316)) -= (*Expr)(unsafe.Pointer(pExpr)).FnHeight

		if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&(NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg) != 0 {
			*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32((*NameContext)(unsafe.Pointer(pNC)).FncFlags & (NC_HasAgg | NC_HasWin))
			savedHasAgg = savedHasAgg | (*NameContext)(unsafe.Pointer(pNC)).FncFlags&(NC_HasAgg|NC_MinMaxAgg|NC_HasWin|NC_OrderAgg)
			*(*int32)(unsafe.Pointer(pNC + 40)) &= libc.CplInt32(NC_HasAgg | NC_MinMaxAgg | NC_HasWin | NC_OrderAgg)
		}
		if (*Parse)(unsafe.Pointer((*Walker)(unsafe.Pointer(bp)).FpParse)).FnErr > 0 {
			return WRC_Abort
		}
	}
	*(*int32)(unsafe.Pointer(pNC + 40)) |= savedHasAgg
	return WRC_Continue
}

func Xsqlite3ResolveSelectNames(tls *libc.TLS, pParse uintptr, p uintptr, pOuterNC uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{resolveExprStep}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{resolveSelectStep}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = uintptr(0)
	(*Walker)(unsafe.Pointer(bp)).FpParse = pParse
	*(*uintptr)(unsafe.Pointer(bp + 40)) = pOuterNC
	Xsqlite3WalkSelect(tls, bp, p)
}

func Xsqlite3ResolveSelfReference(tls *libc.TLS, pParse uintptr, pTab uintptr, type1 int32, pExpr uintptr, pList uintptr) int32 {
	bp := tls.Alloc(168)
	defer tls.Free(168)

	var rc int32

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(NameContext{})))
	libc.Xmemset(tls, bp+56, 0, uint64(unsafe.Sizeof(SrcList{})))
	if pTab != 0 {
		(*SrcList)(unsafe.Pointer(bp + 56)).FnSrc = 1
		(*SrcItem)(unsafe.Pointer(bp + 56 + 8)).FzName = (*Table)(unsafe.Pointer(pTab)).FzName
		(*SrcItem)(unsafe.Pointer(bp + 56 + 8)).FpTab = pTab
		(*SrcItem)(unsafe.Pointer(bp + 56 + 8)).FiCursor = -1
		if (*Table)(unsafe.Pointer(pTab)).FpSchema != (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FaDb+1*32)).FpSchema {
			type1 = type1 | NC_FromDDL
		}
	}
	(*NameContext)(unsafe.Pointer(bp)).FpParse = pParse
	(*NameContext)(unsafe.Pointer(bp)).FpSrcList = bp + 56
	(*NameContext)(unsafe.Pointer(bp)).FncFlags = type1 | NC_IsDDL
	if libc.AssignInt32(&rc, Xsqlite3ResolveExprNames(tls, bp, pExpr)) != SQLITE_OK {
		return rc
	}
	if pList != 0 {
		rc = Xsqlite3ResolveExprListNames(tls, bp, pList)
	}
	return rc
}

func Xsqlite3TableColumnAffinity(tls *libc.TLS, pTab uintptr, iCol int32) uint8 {
	if iCol < 0 || iCol >= int32((*Table)(unsafe.Pointer(pTab)).FnCol) {
		return uint8(SQLITE_AFF_INTEGER)
	}
	return (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24)).Faffinity
}

func Xsqlite3ExprAffinity(tls *libc.TLS, pExpr uintptr) uint8 {
	var op int32
	op = int32((*Expr)(unsafe.Pointer(pExpr)).Fop)
	for 1 != 0 {
		if op == TK_COLUMN || op == TK_AGG_COLUMN && *(*uintptr)(unsafe.Pointer(pExpr + 64)) != uintptr(0) {
			return Xsqlite3TableColumnAffinity(tls, *(*uintptr)(unsafe.Pointer(pExpr + 64)), int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn))
		}
		if op == TK_SELECT {
			return Xsqlite3ExprAffinity(tls, (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList+8)).FpExpr)
		}
		if op == TK_CAST {
			return Xsqlite3AffinityType(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), uintptr(0))
		}
		if op == TK_SELECT_COLUMN {
			return Xsqlite3ExprAffinity(tls,
				(*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpLeft + 32)))).FpEList+8+uintptr((*Expr)(unsafe.Pointer(pExpr)).FiColumn)*32)).FpExpr)
		}
		if op == TK_VECTOR {
			return Xsqlite3ExprAffinity(tls, (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32))+8)).FpExpr)
		}
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Skip|EP_IfNullRow) != U32(0) {
			pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
			op = int32((*Expr)(unsafe.Pointer(pExpr)).Fop)
			continue
		}
		if op != TK_REGISTER || libc.AssignInt32(&op, int32((*Expr)(unsafe.Pointer(pExpr)).Fop2)) == TK_REGISTER {
			break
		}
	}
	return (*Expr)(unsafe.Pointer(pExpr)).FaffExpr
}

func Xsqlite3ExprDataType(tls *libc.TLS, pExpr uintptr) int32 {
	for pExpr != 0 {
		switch int32((*Expr)(unsafe.Pointer(pExpr)).Fop) {
		case TK_COLLATE:
			fallthrough
		case TK_IF_NULL_ROW:
			fallthrough
		case TK_UPLUS:
			{
				pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
				break

			}
		case TK_NULL:
			{
				pExpr = uintptr(0)
				break

			}
		case TK_STRING:
			{
				return 0x02

			}
		case TK_BLOB:
			{
				return 0x04

			}
		case TK_CONCAT:
			{
				return 0x06

			}
		case TK_VARIABLE:
			fallthrough
		case TK_AGG_FUNCTION:
			fallthrough
		case TK_FUNCTION:
			{
				return 0x07

			}
		case TK_COLUMN:
			fallthrough
		case TK_AGG_COLUMN:
			fallthrough
		case TK_SELECT:
			fallthrough
		case TK_CAST:
			fallthrough
		case TK_SELECT_COLUMN:
			fallthrough
		case TK_VECTOR:
			{
				var aff int32 = int32(Xsqlite3ExprAffinity(tls, pExpr))
				if aff >= SQLITE_AFF_NUMERIC {
					return 0x05
				}
				if aff == SQLITE_AFF_TEXT {
					return 0x06
				}
				return 0x07

			}
		case TK_CASE:
			{
				var res int32 = 0
				var ii int32
				var pList uintptr = *(*uintptr)(unsafe.Pointer(pExpr + 32))

				for ii = 1; ii < (*ExprList)(unsafe.Pointer(pList)).FnExpr; ii = ii + 2 {
					res = res | Xsqlite3ExprDataType(tls, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(ii)*32)).FpExpr)
				}
				if (*ExprList)(unsafe.Pointer(pList)).FnExpr%2 != 0 {
					res = res | Xsqlite3ExprDataType(tls, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr((*ExprList)(unsafe.Pointer(pList)).FnExpr-1)*32)).FpExpr)
				}
				return res

			}
		default:
			{
				return 0x01

			}
		}
	}
	return 0x00
}

func Xsqlite3ExprAddCollateToken(tls *libc.TLS, pParse uintptr, pExpr uintptr, pCollName uintptr, dequote int32) uintptr {
	if (*Token)(unsafe.Pointer(pCollName)).Fn > uint32(0) {
		var pNew uintptr = Xsqlite3ExprAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_COLLATE, pCollName, dequote)
		if pNew != 0 {
			(*Expr)(unsafe.Pointer(pNew)).FpLeft = pExpr
			*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(EP_Collate | EP_Skip)
			pExpr = pNew
		}
	}
	return pExpr
}

func Xsqlite3ExprAddCollateString(tls *libc.TLS, pParse uintptr, pExpr uintptr, zC uintptr) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	Xsqlite3TokenInit(tls, bp, zC)
	return Xsqlite3ExprAddCollateToken(tls, pParse, pExpr, bp, 0)
}

func Xsqlite3ExprSkipCollate(tls *libc.TLS, pExpr uintptr) uintptr {
	for pExpr != 0 && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Skip) != U32(0) {
		pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	}
	return pExpr
}

func Xsqlite3ExprSkipCollateAndLikely(tls *libc.TLS, pExpr uintptr) uintptr {
	for pExpr != 0 && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Skip|EP_Unlikely) != U32(0) {
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Unlikely) != U32(0) {
			pExpr = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8)).FpExpr
		} else {
			pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
		}
	}
	return pExpr
}

func Xsqlite3ExprCollSeq(tls *libc.TLS, pParse uintptr, pExpr uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pColl uintptr = uintptr(0)
	var p uintptr = pExpr
	for p != 0 {
		var op int32 = int32((*Expr)(unsafe.Pointer(p)).Fop)
		if op == TK_REGISTER {
			op = int32((*Expr)(unsafe.Pointer(p)).Fop2)
		}
		if op == TK_AGG_COLUMN && *(*uintptr)(unsafe.Pointer(p + 64)) != uintptr(0) ||
			op == TK_COLUMN || op == TK_TRIGGER {
			var j int32

			if libc.AssignInt32(&j, int32((*Expr)(unsafe.Pointer(p)).FiColumn)) >= 0 {
				var zColl uintptr = Xsqlite3ColumnColl(tls, (*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FaCol+uintptr(j)*24)
				pColl = Xsqlite3FindCollSeq(tls, db, (*Sqlite3)(unsafe.Pointer(db)).Fenc, zColl, 0)
			}
			break
		}
		if op == TK_CAST || op == TK_UPLUS {
			p = (*Expr)(unsafe.Pointer(p)).FpLeft
			continue
		}
		if op == TK_VECTOR {
			p = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32)) + 8)).FpExpr
			continue
		}
		if op == TK_COLLATE {
			pColl = Xsqlite3GetCollSeq(tls, pParse, (*Sqlite3)(unsafe.Pointer(db)).Fenc, uintptr(0), *(*uintptr)(unsafe.Pointer(p + 8)))
			break
		}
		if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_Collate) != 0 {
			if (*Expr)(unsafe.Pointer(p)).FpLeft != 0 && (*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(p)).FpLeft)).Fflags&U32(EP_Collate) != U32(0) {
				p = (*Expr)(unsafe.Pointer(p)).FpLeft
			} else {
				var pNext uintptr = (*Expr)(unsafe.Pointer(p)).FpRight

				if *(*uintptr)(unsafe.Pointer(p + 32)) != uintptr(0) && !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
					var i int32
					for i = 0; i < (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32)))).FnExpr; i++ {
						if (*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32))+8+uintptr(i)*32)).FpExpr)).Fflags&U32(EP_Collate) != U32(0) {
							pNext = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32)) + 8 + uintptr(i)*32)).FpExpr
							break
						}
					}
				}
				p = pNext
			}
		} else {
			break
		}
	}
	if Xsqlite3CheckCollSeq(tls, pParse, pColl) != 0 {
		pColl = uintptr(0)
	}
	return pColl
}

func Xsqlite3ExprNNCollSeq(tls *libc.TLS, pParse uintptr, pExpr uintptr) uintptr {
	var p uintptr = Xsqlite3ExprCollSeq(tls, pParse, pExpr)
	if p == uintptr(0) {
		p = (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FpDfltColl
	}

	return p
}

func Xsqlite3ExprCollSeqMatch(tls *libc.TLS, pParse uintptr, pE1 uintptr, pE2 uintptr) int32 {
	var pColl1 uintptr = Xsqlite3ExprNNCollSeq(tls, pParse, pE1)
	var pColl2 uintptr = Xsqlite3ExprNNCollSeq(tls, pParse, pE2)
	return libc.Bool32(Xsqlite3StrICmp(tls, (*CollSeq)(unsafe.Pointer(pColl1)).FzName, (*CollSeq)(unsafe.Pointer(pColl2)).FzName) == 0)
}

func Xsqlite3CompareAffinity(tls *libc.TLS, pExpr uintptr, aff2 uint8) uint8 {
	var aff1 uint8 = Xsqlite3ExprAffinity(tls, pExpr)
	if int32(aff1) > SQLITE_AFF_NONE && int32(aff2) > SQLITE_AFF_NONE {
		if int32(aff1) >= SQLITE_AFF_NUMERIC || int32(aff2) >= SQLITE_AFF_NUMERIC {
			return uint8(SQLITE_AFF_NUMERIC)
		} else {
			return uint8(SQLITE_AFF_BLOB)
		}
	} else {
		return uint8(func() int32 {
			if int32(aff1) <= SQLITE_AFF_NONE {
				return int32(aff2)
			}
			return int32(aff1)
		}() | SQLITE_AFF_NONE)
	}
	return uint8(0)
}

func comparisonAffinity(tls *libc.TLS, pExpr uintptr) uint8 {
	var aff uint8

	aff = Xsqlite3ExprAffinity(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
	if (*Expr)(unsafe.Pointer(pExpr)).FpRight != 0 {
		aff = Xsqlite3CompareAffinity(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight, aff)
	} else if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
		aff = Xsqlite3CompareAffinity(tls, (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList+8)).FpExpr, aff)
	} else if int32(aff) == 0 {
		aff = uint8(SQLITE_AFF_BLOB)
	}
	return aff
}

func Xsqlite3IndexAffinityOk(tls *libc.TLS, pExpr uintptr, idx_affinity uint8) int32 {
	var aff uint8 = comparisonAffinity(tls, pExpr)
	if int32(aff) < SQLITE_AFF_TEXT {
		return 1
	}
	if int32(aff) == SQLITE_AFF_TEXT {
		return libc.Bool32(int32(idx_affinity) == SQLITE_AFF_TEXT)
	}
	return libc.Bool32(int32(idx_affinity) >= SQLITE_AFF_NUMERIC)
}

func binaryCompareP5(tls *libc.TLS, pExpr1 uintptr, pExpr2 uintptr, jumpIfNull int32) U8 {
	var aff U8 = Xsqlite3ExprAffinity(tls, pExpr2)
	aff = U8(int32(Xsqlite3CompareAffinity(tls, pExpr1, aff)) | int32(U8(jumpIfNull)))
	return aff
}

func Xsqlite3BinaryCompareCollSeq(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRight uintptr) uintptr {
	var pColl uintptr

	if (*Expr)(unsafe.Pointer(pLeft)).Fflags&U32(EP_Collate) != 0 {
		pColl = Xsqlite3ExprCollSeq(tls, pParse, pLeft)
	} else if pRight != 0 && (*Expr)(unsafe.Pointer(pRight)).Fflags&U32(EP_Collate) != U32(0) {
		pColl = Xsqlite3ExprCollSeq(tls, pParse, pRight)
	} else {
		pColl = Xsqlite3ExprCollSeq(tls, pParse, pLeft)
		if !(pColl != 0) {
			pColl = Xsqlite3ExprCollSeq(tls, pParse, pRight)
		}
	}
	return pColl
}

func Xsqlite3ExprCompareCollSeq(tls *libc.TLS, pParse uintptr, p uintptr) uintptr {
	if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_Commuted) != U32(0) {
		return Xsqlite3BinaryCompareCollSeq(tls, pParse, (*Expr)(unsafe.Pointer(p)).FpRight, (*Expr)(unsafe.Pointer(p)).FpLeft)
	} else {
		return Xsqlite3BinaryCompareCollSeq(tls, pParse, (*Expr)(unsafe.Pointer(p)).FpLeft, (*Expr)(unsafe.Pointer(p)).FpRight)
	}
	return uintptr(0)
}

func codeCompare(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRight uintptr, opcode int32, in1 int32, in2 int32, dest int32, jumpIfNull int32, isCommuted int32) int32 {
	var p5 int32
	var addr int32
	var p4 uintptr

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return 0
	}
	if isCommuted != 0 {
		p4 = Xsqlite3BinaryCompareCollSeq(tls, pParse, pRight, pLeft)
	} else {
		p4 = Xsqlite3BinaryCompareCollSeq(tls, pParse, pLeft, pRight)
	}
	p5 = int32(binaryCompareP5(tls, pLeft, pRight, jumpIfNull))
	addr = Xsqlite3VdbeAddOp4(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, opcode, in2, dest, in1,
		p4, -2)
	Xsqlite3VdbeChangeP5(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, uint16(U8(p5)))
	return addr
}

func Xsqlite3ExprIsVector(tls *libc.TLS, pExpr uintptr) int32 {
	return libc.Bool32(Xsqlite3ExprVectorSize(tls, pExpr) > 1)
}

func Xsqlite3ExprVectorSize(tls *libc.TLS, pExpr uintptr) int32 {
	var op U8 = (*Expr)(unsafe.Pointer(pExpr)).Fop
	if int32(op) == TK_REGISTER {
		op = (*Expr)(unsafe.Pointer(pExpr)).Fop2
	}
	if int32(op) == TK_VECTOR {
		return (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr
	} else if int32(op) == TK_SELECT {
		return (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList)).FnExpr
	} else {
		return 1
	}
	return int32(0)
}

func Xsqlite3VectorFieldSubexpr(tls *libc.TLS, pVector uintptr, i int32) uintptr {
	if Xsqlite3ExprIsVector(tls, pVector) != 0 {
		if int32((*Expr)(unsafe.Pointer(pVector)).Fop) == TK_SELECT || int32((*Expr)(unsafe.Pointer(pVector)).Fop2) == TK_SELECT {
			return (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pVector + 32)))).FpEList + 8 + uintptr(i)*32)).FpExpr
		} else {
			return (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pVector + 32)) + 8 + uintptr(i)*32)).FpExpr
		}
	}
	return pVector
}

func Xsqlite3ExprForVectorField(tls *libc.TLS, pParse uintptr, pVector uintptr, iField int32, nField int32) uintptr {
	var pRet uintptr
	if int32((*Expr)(unsafe.Pointer(pVector)).Fop) == TK_SELECT {
		pRet = Xsqlite3PExpr(tls, pParse, TK_SELECT_COLUMN, uintptr(0), uintptr(0))
		if pRet != 0 {
			(*Expr)(unsafe.Pointer(pRet)).FiTable = nField
			(*Expr)(unsafe.Pointer(pRet)).FiColumn = YnVar(iField)
			(*Expr)(unsafe.Pointer(pRet)).FpLeft = pVector
		}
	} else {
		if int32((*Expr)(unsafe.Pointer(pVector)).Fop) == TK_VECTOR {
			var ppVector uintptr

			ppVector = *(*uintptr)(unsafe.Pointer(pVector + 32)) + 8 + uintptr(iField)*32
			pVector = *(*uintptr)(unsafe.Pointer(ppVector))
			if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
				*(*uintptr)(unsafe.Pointer(ppVector)) = uintptr(0)
				return pVector
			}
		}
		pRet = Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pVector, 0)
	}
	return pRet
}

func exprCodeSubselect(tls *libc.TLS, pParse uintptr, pExpr uintptr) int32 {
	var reg int32 = 0
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_SELECT {
		reg = Xsqlite3CodeSubselect(tls, pParse, pExpr)
	}
	return reg
}

func exprVectorRegister(tls *libc.TLS, pParse uintptr, pVector uintptr, iField int32, regSelect int32, ppExpr uintptr, pRegFree uintptr) int32 {
	var op U8 = (*Expr)(unsafe.Pointer(pVector)).Fop

	if int32(op) == TK_REGISTER {
		*(*uintptr)(unsafe.Pointer(ppExpr)) = Xsqlite3VectorFieldSubexpr(tls, pVector, iField)
		return (*Expr)(unsafe.Pointer(pVector)).FiTable + iField
	}
	if int32(op) == TK_SELECT {
		*(*uintptr)(unsafe.Pointer(ppExpr)) = (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pVector + 32)))).FpEList + 8 + uintptr(iField)*32)).FpExpr
		return regSelect + iField
	}
	if int32(op) == TK_VECTOR {
		*(*uintptr)(unsafe.Pointer(ppExpr)) = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pVector + 32)) + 8 + uintptr(iField)*32)).FpExpr
		return Xsqlite3ExprCodeTemp(tls, pParse, *(*uintptr)(unsafe.Pointer(ppExpr)), pRegFree)
	}
	return 0
}

func codeVectorCompare(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, op U8, p5 U8) {
	bp := tls.Alloc(28)
	defer tls.Free(28)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var pLeft uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	var pRight uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpRight
	var nLeft int32 = Xsqlite3ExprVectorSize(tls, pLeft)
	var i int32
	var regLeft int32 = 0
	var regRight int32 = 0
	var opx U8 = op
	var addrCmp int32 = 0
	var addrDone int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
	var isCommuted int32 = libc.Bool32((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Commuted) != U32(0))

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	if nLeft != Xsqlite3ExprVectorSize(tls, pRight) {
		Xsqlite3ErrorMsg(tls, pParse, ts+9748, 0)
		return
	}

	if int32(op) == TK_LE {
		opx = U8(TK_LT)
	}
	if int32(op) == TK_GE {
		opx = U8(TK_GT)
	}
	if int32(op) == TK_NE {
		opx = U8(TK_EQ)
	}

	regLeft = exprCodeSubselect(tls, pParse, pLeft)
	regRight = exprCodeSubselect(tls, pParse, pRight)

	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, dest)
	for i = 0; 1 != 0; i++ {
		*(*int32)(unsafe.Pointer(bp + 8)) = 0
		*(*int32)(unsafe.Pointer(bp + 24)) = 0
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
		var r1 int32
		var r2 int32

		if addrCmp != 0 {
			Xsqlite3VdbeJumpHere(tls, v, addrCmp)
		}
		r1 = exprVectorRegister(tls, pParse, pLeft, i, regLeft, bp, bp+8)
		r2 = exprVectorRegister(tls, pParse, pRight, i, regRight, bp+16, bp+24)
		addrCmp = Xsqlite3VdbeCurrentAddr(tls, v)
		codeCompare(tls, pParse, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 16)), int32(opx), r1, r2, addrDone, int32(p5), isCommuted)

		Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 8)))
		Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 24)))
		if (int32(opx) == TK_LT || int32(opx) == TK_GT) && i < nLeft-1 {
			addrCmp = Xsqlite3VdbeAddOp0(tls, v, OP_ElseEq)

		}
		if int32(p5) == SQLITE_NULLEQ {
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, dest)
		} else {
			Xsqlite3VdbeAddOp3(tls, v, OP_ZeroOrNull, r1, dest, r2)
		}
		if i == nLeft-1 {
			break
		}
		if int32(opx) == TK_EQ {
			Xsqlite3VdbeAddOp2(tls, v, OP_NotNull, dest, addrDone)
		} else {
			Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addrDone)
			if i == nLeft-2 {
				opx = op
			}
		}
	}
	Xsqlite3VdbeJumpHere(tls, v, addrCmp)
	Xsqlite3VdbeResolveLabel(tls, v, addrDone)
	if int32(op) == TK_NE {
		Xsqlite3VdbeAddOp2(tls, v, OP_Not, dest, dest)
	}
}

func Xsqlite3ExprCheckHeight(tls *libc.TLS, pParse uintptr, nHeight int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var mxHeight int32 = *(*int32)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb + 136 + 3*4))
	if nHeight > mxHeight {
		Xsqlite3ErrorMsg(tls, pParse,
			ts+10640, libc.VaList(bp, mxHeight))
		rc = SQLITE_ERROR
	}
	return rc
}

func heightOfExpr(tls *libc.TLS, p uintptr, pnHeight uintptr) {
	if p != 0 {
		if (*Expr)(unsafe.Pointer(p)).FnHeight > *(*int32)(unsafe.Pointer(pnHeight)) {
			*(*int32)(unsafe.Pointer(pnHeight)) = (*Expr)(unsafe.Pointer(p)).FnHeight
		}
	}
}

func heightOfExprList(tls *libc.TLS, p uintptr, pnHeight uintptr) {
	if p != 0 {
		var i int32
		for i = 0; i < (*ExprList)(unsafe.Pointer(p)).FnExpr; i++ {
			heightOfExpr(tls, (*ExprList_item)(unsafe.Pointer(p+8+uintptr(i)*32)).FpExpr, pnHeight)
		}
	}
}

func heightOfSelect(tls *libc.TLS, pSelect uintptr, pnHeight uintptr) {
	var p uintptr
	for p = pSelect; p != 0; p = (*Select)(unsafe.Pointer(p)).FpPrior {
		heightOfExpr(tls, (*Select)(unsafe.Pointer(p)).FpWhere, pnHeight)
		heightOfExpr(tls, (*Select)(unsafe.Pointer(p)).FpHaving, pnHeight)
		heightOfExpr(tls, (*Select)(unsafe.Pointer(p)).FpLimit, pnHeight)
		heightOfExprList(tls, (*Select)(unsafe.Pointer(p)).FpEList, pnHeight)
		heightOfExprList(tls, (*Select)(unsafe.Pointer(p)).FpGroupBy, pnHeight)
		heightOfExprList(tls, (*Select)(unsafe.Pointer(p)).FpOrderBy, pnHeight)
	}
}

func exprSetHeight(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	if (*Expr)(unsafe.Pointer(p)).FpLeft != 0 {
		*(*int32)(unsafe.Pointer(bp)) = (*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(p)).FpLeft)).FnHeight
	} else {
		*(*int32)(unsafe.Pointer(bp)) = 0
	}
	if (*Expr)(unsafe.Pointer(p)).FpRight != 0 && (*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(p)).FpRight)).FnHeight > *(*int32)(unsafe.Pointer(bp)) {
		*(*int32)(unsafe.Pointer(bp)) = (*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(p)).FpRight)).FnHeight
	}
	if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_xIsSelect) != U32(0) {
		heightOfSelect(tls, *(*uintptr)(unsafe.Pointer(p + 32)), bp)
	} else if *(*uintptr)(unsafe.Pointer(p + 32)) != 0 {
		heightOfExprList(tls, *(*uintptr)(unsafe.Pointer(p + 32)), bp)
		*(*U32)(unsafe.Pointer(p + 4)) |= U32(EP_Collate|EP_Subquery|EP_HasFunc) & Xsqlite3ExprListFlags(tls, *(*uintptr)(unsafe.Pointer(p + 32)))
	}
	(*Expr)(unsafe.Pointer(p)).FnHeight = *(*int32)(unsafe.Pointer(bp)) + 1
}

func Xsqlite3ExprSetHeightAndFlags(tls *libc.TLS, pParse uintptr, p uintptr) {
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	exprSetHeight(tls, p)
	Xsqlite3ExprCheckHeight(tls, pParse, (*Expr)(unsafe.Pointer(p)).FnHeight)
}

func Xsqlite3SelectExprHeight(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = 0
	heightOfSelect(tls, p, bp)
	return *(*int32)(unsafe.Pointer(bp))
}

func Xsqlite3ExprAlloc(tls *libc.TLS, db uintptr, op int32, pToken uintptr, dequote int32) uintptr {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pNew uintptr
	var nExtra int32 = 0
	*(*int32)(unsafe.Pointer(bp)) = 0

	if pToken != 0 {
		if op != TK_INTEGER || (*Token)(unsafe.Pointer(pToken)).Fz == uintptr(0) ||
			Xsqlite3GetInt32(tls, (*Token)(unsafe.Pointer(pToken)).Fz, bp) == 0 {
			nExtra = int32((*Token)(unsafe.Pointer(pToken)).Fn + uint32(1))

		}
	}
	pNew = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(Expr{}))+uint64(nExtra))
	if pNew != 0 {
		libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Expr{})))
		(*Expr)(unsafe.Pointer(pNew)).Fop = U8(op)
		(*Expr)(unsafe.Pointer(pNew)).FiAgg = int16(-1)
		if pToken != 0 {
			if nExtra == 0 {
				*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(EP_IntValue | EP_Leaf | func() int32 {
					if *(*int32)(unsafe.Pointer(bp)) != 0 {
						return EP_IsTrue
					}
					return EP_IsFalse
				}())
				*(*int32)(unsafe.Pointer(pNew + 8)) = *(*int32)(unsafe.Pointer(bp))
			} else {
				*(*uintptr)(unsafe.Pointer(pNew + 8)) = pNew + 1*72

				if (*Token)(unsafe.Pointer(pToken)).Fn != 0 {
					libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(pNew + 8)), (*Token)(unsafe.Pointer(pToken)).Fz, uint64((*Token)(unsafe.Pointer(pToken)).Fn))
				}
				*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNew + 8)) + uintptr((*Token)(unsafe.Pointer(pToken)).Fn))) = uint8(0)
				if dequote != 0 && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNew + 8))))])&0x80 != 0 {
					Xsqlite3DequoteExpr(tls, pNew)
				}
			}
		}
		(*Expr)(unsafe.Pointer(pNew)).FnHeight = 1
	}
	return pNew
}

func Xsqlite3Expr(tls *libc.TLS, db uintptr, op int32, zToken uintptr) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	(*Token)(unsafe.Pointer(bp)).Fz = zToken
	(*Token)(unsafe.Pointer(bp)).Fn = uint32(Xsqlite3Strlen30(tls, zToken))
	return Xsqlite3ExprAlloc(tls, db, op, bp, 0)
}

func Xsqlite3ExprAttachSubtrees(tls *libc.TLS, db uintptr, pRoot uintptr, pLeft uintptr, pRight uintptr) {
	if pRoot == uintptr(0) {
		Xsqlite3ExprDelete(tls, db, pLeft)
		Xsqlite3ExprDelete(tls, db, pRight)
	} else {
		if pRight != 0 {
			(*Expr)(unsafe.Pointer(pRoot)).FpRight = pRight
			*(*U32)(unsafe.Pointer(pRoot + 4)) |= U32(EP_Collate|EP_Subquery|EP_HasFunc) & (*Expr)(unsafe.Pointer(pRight)).Fflags
			(*Expr)(unsafe.Pointer(pRoot)).FnHeight = (*Expr)(unsafe.Pointer(pRight)).FnHeight + 1
		} else {
			(*Expr)(unsafe.Pointer(pRoot)).FnHeight = 1
		}
		if pLeft != 0 {
			(*Expr)(unsafe.Pointer(pRoot)).FpLeft = pLeft
			*(*U32)(unsafe.Pointer(pRoot + 4)) |= U32(EP_Collate|EP_Subquery|EP_HasFunc) & (*Expr)(unsafe.Pointer(pLeft)).Fflags
			if (*Expr)(unsafe.Pointer(pLeft)).FnHeight >= (*Expr)(unsafe.Pointer(pRoot)).FnHeight {
				(*Expr)(unsafe.Pointer(pRoot)).FnHeight = (*Expr)(unsafe.Pointer(pLeft)).FnHeight + 1
			}
		}
	}
}

func Xsqlite3PExpr(tls *libc.TLS, pParse uintptr, op int32, pLeft uintptr, pRight uintptr) uintptr {
	var p uintptr
	p = Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(Expr{})))
	if p != 0 {
		libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(Expr{})))
		(*Expr)(unsafe.Pointer(p)).Fop = U8(op & 0xff)
		(*Expr)(unsafe.Pointer(p)).FiAgg = int16(-1)
		Xsqlite3ExprAttachSubtrees(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, p, pLeft, pRight)
		Xsqlite3ExprCheckHeight(tls, pParse, (*Expr)(unsafe.Pointer(p)).FnHeight)
	} else {
		Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pLeft)
		Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pRight)
	}
	return p
}

func Xsqlite3PExprAddSelect(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSelect uintptr) {
	if pExpr != 0 {
		*(*uintptr)(unsafe.Pointer(pExpr + 32)) = pSelect
		*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_xIsSelect | EP_Subquery)
		Xsqlite3ExprSetHeightAndFlags(tls, pParse, pExpr)
	} else {
		Xsqlite3SelectDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pSelect)
	}
}

func Xsqlite3ExprListToValues(tls *libc.TLS, pParse uintptr, nElem int32, pEList uintptr) uintptr {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var ii int32
	var pRet uintptr = uintptr(0)

	for ii = 0; ii < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; ii++ {
		var pSel uintptr
		var pExpr uintptr = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32)).FpExpr
		var nExprElem int32
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_VECTOR {
			nExprElem = (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr
		} else {
			nExprElem = 1
		}
		if nExprElem != nElem {
			Xsqlite3ErrorMsg(tls, pParse, ts+10688,
				libc.VaList(bp, nExprElem, func() uintptr {
					if nExprElem > 1 {
						return ts + 10732
					}
					return ts + 1636
				}(), nElem))
			break
		}

		pSel = Xsqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(pExpr + 32)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values), uintptr(0))
		*(*uintptr)(unsafe.Pointer(pExpr + 32)) = uintptr(0)
		if pSel != 0 {
			if pRet != 0 {
				(*Select)(unsafe.Pointer(pSel)).Fop = U8(TK_ALL)
				(*Select)(unsafe.Pointer(pSel)).FpPrior = pRet
			}
			pRet = pSel
		}
	}

	if pRet != 0 && (*Select)(unsafe.Pointer(pRet)).FpPrior != 0 {
		*(*U32)(unsafe.Pointer(pRet + 4)) |= U32(SF_MultiValue)
	}
	Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pEList)
	return pRet
}

func Xsqlite3ExprAnd(tls *libc.TLS, pParse uintptr, pLeft uintptr, pRight uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if pLeft == uintptr(0) {
		return pRight
	} else if pRight == uintptr(0) {
		return pLeft
	} else if ((*Expr)(unsafe.Pointer(pLeft)).Fflags&U32(EP_OuterON|EP_IsFalse) == U32(EP_IsFalse) || (*Expr)(unsafe.Pointer(pRight)).Fflags&U32(EP_OuterON|EP_IsFalse) == U32(EP_IsFalse)) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		Xsqlite3ExprDeferredDelete(tls, pParse, pLeft)
		Xsqlite3ExprDeferredDelete(tls, pParse, pRight)
		return Xsqlite3Expr(tls, db, TK_INTEGER, ts+10734)
	} else {
		return Xsqlite3PExpr(tls, pParse, TK_AND, pLeft, pRight)
	}
	return uintptr(0)
}

func Xsqlite3ExprFunction(tls *libc.TLS, pParse uintptr, pList uintptr, pToken uintptr, eDistinct int32) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pNew uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	pNew = Xsqlite3ExprAlloc(tls, db, TK_FUNCTION, pToken, 1)
	if pNew == uintptr(0) {
		Xsqlite3ExprListDelete(tls, db, pList)
		return uintptr(0)
	}

	*(*int32)(unsafe.Pointer(pNew + 52)) = int32((int64((*Token)(unsafe.Pointer(pToken)).Fz) - int64((*Parse)(unsafe.Pointer(pParse)).FzTail)) / 1)
	if pList != 0 &&
		(*ExprList)(unsafe.Pointer(pList)).FnExpr > *(*int32)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb + 136 + 6*4)) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) != 0) {
		Xsqlite3ErrorMsg(tls, pParse, ts+10736, libc.VaList(bp, pToken))
	}
	*(*uintptr)(unsafe.Pointer(pNew + 32)) = pList
	*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(EP_HasFunc)

	Xsqlite3ExprSetHeightAndFlags(tls, pParse, pNew)
	if eDistinct == SF_Distinct {
		*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(EP_Distinct)
	}
	return pNew
}

func Xsqlite3ExprFunctionUsable(tls *libc.TLS, pParse uintptr, pExpr uintptr, pDef uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_FromDDL) != U32(0) {
		if (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_DIRECT) != U32(0) ||
			(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_TrustedSchema) == uint64(0) {
			Xsqlite3ErrorMsg(tls, pParse, ts+10770, libc.VaList(bp, pExpr))
		}
	}
}

func Xsqlite3ExprAssignVarNumber(tls *libc.TLS, pParse uintptr, pExpr uintptr, n U32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var z uintptr
	var x YnVar

	if pExpr == uintptr(0) {
		return
	}

	z = *(*uintptr)(unsafe.Pointer(pExpr + 8))

	if int32(*(*uint8)(unsafe.Pointer(z + 1))) == 0 {
		x = libc.PreIncInt16(&(*Parse)(unsafe.Pointer(pParse)).FnVar, 1)
	} else {
		var doAdd int32 = 0
		if int32(*(*uint8)(unsafe.Pointer(z))) == '?' {
			var bOk int32
			if n == U32(2) {
				*(*I64)(unsafe.Pointer(bp + 8)) = I64(int32(*(*uint8)(unsafe.Pointer(z + 1))) - '0')
				bOk = 1
			} else {
				bOk = libc.Bool32(0 == Xsqlite3Atoi64(tls, z+1, bp+8, int32(n-U32(1)), uint8(SQLITE_UTF8)))
			}

			if bOk == 0 || *(*I64)(unsafe.Pointer(bp + 8)) < int64(1) || *(*I64)(unsafe.Pointer(bp + 8)) > I64(*(*int32)(unsafe.Pointer(db + 136 + 9*4))) {
				Xsqlite3ErrorMsg(tls, pParse, ts+10790,
					libc.VaList(bp, *(*int32)(unsafe.Pointer(db + 136 + 9*4))))
				Xsqlite3RecordErrorOffsetOfExpr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
				return
			}
			x = YnVar(*(*I64)(unsafe.Pointer(bp + 8)))
			if int32(x) > int32((*Parse)(unsafe.Pointer(pParse)).FnVar) {
				(*Parse)(unsafe.Pointer(pParse)).FnVar = YnVar(int32(x))
				doAdd = 1
			} else if Xsqlite3VListNumToName(tls, (*Parse)(unsafe.Pointer(pParse)).FpVList, int32(x)) == uintptr(0) {
				doAdd = 1
			}
		} else {
			x = YnVar(Xsqlite3VListNameToNum(tls, (*Parse)(unsafe.Pointer(pParse)).FpVList, z, int32(n)))
			if int32(x) == 0 {
				x = libc.PreIncInt16(&(*Parse)(unsafe.Pointer(pParse)).FnVar, 1)
				doAdd = 1
			}
		}
		if doAdd != 0 {
			(*Parse)(unsafe.Pointer(pParse)).FpVList = Xsqlite3VListAdd(tls, db, (*Parse)(unsafe.Pointer(pParse)).FpVList, z, int32(n), int32(x))
		}
	}
	(*Expr)(unsafe.Pointer(pExpr)).FiColumn = x
	if int32(x) > *(*int32)(unsafe.Pointer(db + 136 + 9*4)) {
		Xsqlite3ErrorMsg(tls, pParse, ts+10833, 0)
		Xsqlite3RecordErrorOffsetOfExpr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
	}
}

func sqlite3ExprDeleteNN(tls *libc.TLS, db uintptr, p uintptr) {
	if !((*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_TokenOnly|EP_Leaf) != U32(0)) {
		if (*Expr)(unsafe.Pointer(p)).FpLeft != 0 && int32((*Expr)(unsafe.Pointer(p)).Fop) != TK_SELECT_COLUMN {
			sqlite3ExprDeleteNN(tls, db, (*Expr)(unsafe.Pointer(p)).FpLeft)
		}
		if (*Expr)(unsafe.Pointer(p)).FpRight != 0 {
			sqlite3ExprDeleteNN(tls, db, (*Expr)(unsafe.Pointer(p)).FpRight)
		} else if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_xIsSelect) != U32(0) {
			Xsqlite3SelectDelete(tls, db, *(*uintptr)(unsafe.Pointer(p + 32)))
		} else {
			Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(p + 32)))
			if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_WinFunc) != U32(0) {
				Xsqlite3WindowDelete(tls, db, *(*uintptr)(unsafe.Pointer(p + 64)))
			}
		}
	}
	if !((*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_Static) != U32(0)) {
		Xsqlite3DbNNFreeNN(tls, db, p)
	}
}

func Xsqlite3ExprDelete(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		sqlite3ExprDeleteNN(tls, db, p)
	}
}

func Xsqlite3ClearOnOrUsing(tls *libc.TLS, db uintptr, p uintptr) {
	if p == uintptr(0) {
	} else if (*OnOrUsing)(unsafe.Pointer(p)).FpOn != 0 {
		sqlite3ExprDeleteNN(tls, db, (*OnOrUsing)(unsafe.Pointer(p)).FpOn)
	} else if (*OnOrUsing)(unsafe.Pointer(p)).FpUsing != 0 {
		Xsqlite3IdListDelete(tls, db, (*OnOrUsing)(unsafe.Pointer(p)).FpUsing)
	}
}

func Xsqlite3ExprDeferredDelete(tls *libc.TLS, pParse uintptr, pExpr uintptr) {
	Xsqlite3ParserAddCleanup(tls, pParse,
		*(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{Xsqlite3ExprDelete})),
		pExpr)
}

func Xsqlite3ExprUnmapAndDelete(tls *libc.TLS, pParse uintptr, p uintptr) {
	if p != 0 {
		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			Xsqlite3RenameExprUnmap(tls, pParse, p)
		}
		sqlite3ExprDeleteNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, p)
	}
}

func exprStructSize(tls *libc.TLS, p uintptr) int32 {
	if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_TokenOnly) != U32(0) {
		return int32(uintptr(0) + 16)
	}
	if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_Reduced) != U32(0) {
		return int32(uintptr(0) + 44)
	}
	return int32(unsafe.Sizeof(Expr{}))
}

func dupedExprStructSize(tls *libc.TLS, p uintptr, flags int32) int32 {
	var nSize int32

	if 0 == flags || int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_SELECT_COLUMN ||
		(*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_WinFunc) != U32(0) {
		nSize = int32(unsafe.Sizeof(Expr{}))
	} else {
		if (*Expr)(unsafe.Pointer(p)).FpLeft != 0 || *(*uintptr)(unsafe.Pointer(p + 32)) != 0 {
			nSize = int32(uint64(uintptr(0)+44) | uint64(EP_Reduced))
		} else {
			nSize = int32(uint64(uintptr(0)+16) | uint64(EP_TokenOnly))
		}
	}
	return nSize
}

func dupedExprNodeSize(tls *libc.TLS, p uintptr, flags int32) int32 {
	var nByte int32 = dupedExprStructSize(tls, p, flags) & 0xfff
	if !((*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_IntValue) != U32(0)) && *(*uintptr)(unsafe.Pointer(p + 8)) != 0 {
		nByte = int32(Size_t(nByte) + (libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(p + 8)))&uint64(0x3fffffff) + uint64(1)))
	}
	return (nByte + 7) & libc.CplInt32(7)
}

func dupedExprSize(tls *libc.TLS, p uintptr, flags int32) int32 {
	var nByte int32 = 0
	if p != 0 {
		nByte = dupedExprNodeSize(tls, p, flags)
		if flags&EXPRDUP_REDUCE != 0 {
			nByte = nByte + (dupedExprSize(tls, (*Expr)(unsafe.Pointer(p)).FpLeft, flags) + dupedExprSize(tls, (*Expr)(unsafe.Pointer(p)).FpRight, flags))
		}
	}
	return nByte
}

func exprDup(tls *libc.TLS, db uintptr, p uintptr, dupFlags int32, pzBuffer uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pNew uintptr

	var staticFlag U32

	if pzBuffer != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(pzBuffer))
		staticFlag = U32(EP_Static)

	} else {
		*(*uintptr)(unsafe.Pointer(bp)) = Xsqlite3DbMallocRawNN(tls, db, uint64(dupedExprSize(tls, p, dupFlags)))
		staticFlag = U32(0)
	}
	pNew = *(*uintptr)(unsafe.Pointer(bp))

	if pNew != 0 {
		var nStructSize uint32 = uint32(dupedExprStructSize(tls, p, dupFlags))
		var nNewSize int32 = int32(nStructSize & uint32(0xfff))
		var nToken int32
		if !((*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_IntValue) != U32(0)) && *(*uintptr)(unsafe.Pointer(p + 8)) != 0 {
			nToken = Xsqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(p + 8))) + 1
		} else {
			nToken = 0
		}
		if dupFlags != 0 {
			libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp)), p, uint64(nNewSize))
		} else {
			var nSize U32 = U32(exprStructSize(tls, p))
			libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp)), p, uint64(nSize))
			if uint64(nSize) < uint64(unsafe.Sizeof(Expr{})) {
				libc.Xmemset(tls, *(*uintptr)(unsafe.Pointer(bp))+uintptr(nSize), 0, uint64(unsafe.Sizeof(Expr{}))-uint64(nSize))
			}
		}

		*(*U32)(unsafe.Pointer(pNew + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_Reduced | EP_TokenOnly | EP_Static))
		*(*U32)(unsafe.Pointer(pNew + 4)) |= nStructSize & uint32(EP_Reduced|EP_TokenOnly)
		*(*U32)(unsafe.Pointer(pNew + 4)) |= staticFlag

		if dupFlags != 0 {
		}

		if nToken != 0 {
			var zToken uintptr = libc.AssignPtrUintptr(pNew+8, *(*uintptr)(unsafe.Pointer(bp))+uintptr(nNewSize))
			libc.Xmemcpy(tls, zToken, *(*uintptr)(unsafe.Pointer(p + 8)), uint64(nToken))
		}

		if U32(0) == ((*Expr)(unsafe.Pointer(p)).Fflags|(*Expr)(unsafe.Pointer(pNew)).Fflags)&U32(EP_TokenOnly|EP_Leaf) {
			if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_xIsSelect) != U32(0) {
				*(*uintptr)(unsafe.Pointer(pNew + 32)) = Xsqlite3SelectDup(tls, db, *(*uintptr)(unsafe.Pointer(p + 32)), dupFlags)
			} else {
				*(*uintptr)(unsafe.Pointer(pNew + 32)) = Xsqlite3ExprListDup(tls, db, *(*uintptr)(unsafe.Pointer(p + 32)), dupFlags)
			}
		}

		if (*Expr)(unsafe.Pointer(pNew)).Fflags&U32(EP_Reduced|EP_TokenOnly|EP_WinFunc) != U32(0) {
			*(*uintptr)(unsafe.Pointer(bp)) += uintptr(dupedExprNodeSize(tls, p, dupFlags))
			if !((*Expr)(unsafe.Pointer(pNew)).Fflags&U32(EP_TokenOnly|EP_Leaf) != U32(0)) {
				(*Expr)(unsafe.Pointer(pNew)).FpLeft = func() uintptr {
					if (*Expr)(unsafe.Pointer(p)).FpLeft != 0 {
						return exprDup(tls, db, (*Expr)(unsafe.Pointer(p)).FpLeft, EXPRDUP_REDUCE, bp)
					}
					return uintptr(0)
				}()
				(*Expr)(unsafe.Pointer(pNew)).FpRight = func() uintptr {
					if (*Expr)(unsafe.Pointer(p)).FpRight != 0 {
						return exprDup(tls, db, (*Expr)(unsafe.Pointer(p)).FpRight, EXPRDUP_REDUCE, bp)
					}
					return uintptr(0)
				}()
			}
			if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_WinFunc) != U32(0) {
				*(*uintptr)(unsafe.Pointer(pNew + 64)) = Xsqlite3WindowDup(tls, db, pNew, *(*uintptr)(unsafe.Pointer(p + 64)))

			}
			if pzBuffer != 0 {
				*(*uintptr)(unsafe.Pointer(pzBuffer)) = *(*uintptr)(unsafe.Pointer(bp))
			}
		} else {
			if !((*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_TokenOnly|EP_Leaf) != U32(0)) {
				if int32((*Expr)(unsafe.Pointer(pNew)).Fop) == TK_SELECT_COLUMN {
					(*Expr)(unsafe.Pointer(pNew)).FpLeft = (*Expr)(unsafe.Pointer(p)).FpLeft

				} else {
					(*Expr)(unsafe.Pointer(pNew)).FpLeft = Xsqlite3ExprDup(tls, db, (*Expr)(unsafe.Pointer(p)).FpLeft, 0)
				}
				(*Expr)(unsafe.Pointer(pNew)).FpRight = Xsqlite3ExprDup(tls, db, (*Expr)(unsafe.Pointer(p)).FpRight, 0)
			}
		}
	}
	return pNew
}

func Xsqlite3WithDup(tls *libc.TLS, db uintptr, p uintptr) uintptr {
	var pRet uintptr = uintptr(0)
	if p != 0 {
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(With{})) + uint64(unsafe.Sizeof(Cte{}))*uint64((*With)(unsafe.Pointer(p)).FnCte-1))
		pRet = Xsqlite3DbMallocZero(tls, db, uint64(nByte))
		if pRet != 0 {
			var i int32
			(*With)(unsafe.Pointer(pRet)).FnCte = (*With)(unsafe.Pointer(p)).FnCte
			for i = 0; i < (*With)(unsafe.Pointer(p)).FnCte; i++ {
				(*Cte)(unsafe.Pointer(pRet + 16 + uintptr(i)*48)).FpSelect = Xsqlite3SelectDup(tls, db, (*Cte)(unsafe.Pointer(p+16+uintptr(i)*48)).FpSelect, 0)
				(*Cte)(unsafe.Pointer(pRet + 16 + uintptr(i)*48)).FpCols = Xsqlite3ExprListDup(tls, db, (*Cte)(unsafe.Pointer(p+16+uintptr(i)*48)).FpCols, 0)
				(*Cte)(unsafe.Pointer(pRet + 16 + uintptr(i)*48)).FzName = Xsqlite3DbStrDup(tls, db, (*Cte)(unsafe.Pointer(p+16+uintptr(i)*48)).FzName)
				(*Cte)(unsafe.Pointer(pRet + 16 + uintptr(i)*48)).FeM10d = (*Cte)(unsafe.Pointer(p + 16 + uintptr(i)*48)).FeM10d
			}
		}
	}
	return pRet
}

func gatherSelectWindowsCallback(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_FUNCTION && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
		var pSelect uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
		var pWin uintptr = *(*uintptr)(unsafe.Pointer(pExpr + 64))

		Xsqlite3WindowLink(tls, pSelect, pWin)
	}
	return WRC_Continue
}

func gatherSelectWindowsSelectCallback(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	if p == *(*uintptr)(unsafe.Pointer(pWalker + 40)) {
		return WRC_Continue
	}
	return WRC_Prune
}

func gatherSelectWindows(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{gatherSelectWindowsCallback}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{gatherSelectWindowsSelectCallback}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = uintptr(0)
	(*Walker)(unsafe.Pointer(bp)).FpParse = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 40)) = p
	Xsqlite3WalkSelect(tls, bp, p)
}

func Xsqlite3ExprDup(tls *libc.TLS, db uintptr, p uintptr, flags int32) uintptr {
	if p != 0 {
		return exprDup(tls, db, p, flags, uintptr(0))
	}
	return uintptr(0)
}

func Xsqlite3ExprListDup(tls *libc.TLS, db uintptr, p uintptr, flags int32) uintptr {
	var pNew uintptr
	var pItem uintptr
	var pOldItem uintptr
	var i int32
	var pPriorSelectColOld uintptr = uintptr(0)
	var pPriorSelectColNew uintptr = uintptr(0)

	if p == uintptr(0) {
		return uintptr(0)
	}
	pNew = Xsqlite3DbMallocRawNN(tls, db, uint64(Xsqlite3DbMallocSize(tls, db, p)))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	(*ExprList)(unsafe.Pointer(pNew)).FnExpr = (*ExprList)(unsafe.Pointer(p)).FnExpr
	(*ExprList)(unsafe.Pointer(pNew)).FnAlloc = (*ExprList)(unsafe.Pointer(p)).FnAlloc
	pItem = pNew + 8
	pOldItem = p + 8
	i = 0
__1:
	if !(i < (*ExprList)(unsafe.Pointer(p)).FnExpr) {
		goto __3
	}
	{
		var pOldExpr uintptr = (*ExprList_item)(unsafe.Pointer(pOldItem)).FpExpr
		var pNewExpr uintptr
		(*ExprList_item)(unsafe.Pointer(pItem)).FpExpr = Xsqlite3ExprDup(tls, db, pOldExpr, flags)
		if pOldExpr != 0 &&
			int32((*Expr)(unsafe.Pointer(pOldExpr)).Fop) == TK_SELECT_COLUMN &&
			libc.AssignUintptr(&pNewExpr, (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr) != uintptr(0) {
			if (*Expr)(unsafe.Pointer(pNewExpr)).FpRight != 0 {
				pPriorSelectColOld = (*Expr)(unsafe.Pointer(pOldExpr)).FpRight
				pPriorSelectColNew = (*Expr)(unsafe.Pointer(pNewExpr)).FpRight
				(*Expr)(unsafe.Pointer(pNewExpr)).FpLeft = (*Expr)(unsafe.Pointer(pNewExpr)).FpRight
			} else {
				if (*Expr)(unsafe.Pointer(pOldExpr)).FpLeft != pPriorSelectColOld {
					pPriorSelectColOld = (*Expr)(unsafe.Pointer(pOldExpr)).FpLeft
					pPriorSelectColNew = Xsqlite3ExprDup(tls, db, pPriorSelectColOld, flags)
					(*Expr)(unsafe.Pointer(pNewExpr)).FpRight = pPriorSelectColNew
				}
				(*Expr)(unsafe.Pointer(pNewExpr)).FpLeft = pPriorSelectColNew
			}
		}
		(*ExprList_item)(unsafe.Pointer(pItem)).FzEName = Xsqlite3DbStrDup(tls, db, (*ExprList_item)(unsafe.Pointer(pOldItem)).FzEName)
		(*ExprList_item)(unsafe.Pointer(pItem)).Ffg = (*ExprList_item)(unsafe.Pointer(pOldItem)).Ffg
		libc.SetBitFieldPtr16Uint32(pItem+16+4, uint32(0), 2, 0x4)
		(*ExprList_item)(unsafe.Pointer(pItem)).Fu = (*ExprList_item)(unsafe.Pointer(pOldItem)).Fu

	}
	goto __2
__2:
	i++
	pItem += 32
	pOldItem += 32
	goto __1
	goto __3
__3:
	;
	return pNew
}

func Xsqlite3SrcListDup(tls *libc.TLS, db uintptr, p uintptr, flags int32) uintptr {
	var pNew uintptr
	var i int32
	var nByte int32

	if p == uintptr(0) {
		return uintptr(0)
	}
	nByte = int32(uint64(unsafe.Sizeof(SrcList{})) + func() uint64 {
		if (*SrcList)(unsafe.Pointer(p)).FnSrc > 0 {
			return uint64(unsafe.Sizeof(SrcItem{})) * uint64((*SrcList)(unsafe.Pointer(p)).FnSrc-1)
		}
		return uint64(0)
	}())
	pNew = Xsqlite3DbMallocRawNN(tls, db, uint64(nByte))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	(*SrcList)(unsafe.Pointer(pNew)).FnSrc = int32(libc.AssignPtrUint32(pNew+4, U32((*SrcList)(unsafe.Pointer(p)).FnSrc)))
	for i = 0; i < (*SrcList)(unsafe.Pointer(p)).FnSrc; i++ {
		var pNewItem uintptr = pNew + 8 + uintptr(i)*104
		var pOldItem uintptr = p + 8 + uintptr(i)*104
		var pTab uintptr
		(*SrcItem)(unsafe.Pointer(pNewItem)).FpSchema = (*SrcItem)(unsafe.Pointer(pOldItem)).FpSchema
		(*SrcItem)(unsafe.Pointer(pNewItem)).FzDatabase = Xsqlite3DbStrDup(tls, db, (*SrcItem)(unsafe.Pointer(pOldItem)).FzDatabase)
		(*SrcItem)(unsafe.Pointer(pNewItem)).FzName = Xsqlite3DbStrDup(tls, db, (*SrcItem)(unsafe.Pointer(pOldItem)).FzName)
		(*SrcItem)(unsafe.Pointer(pNewItem)).FzAlias = Xsqlite3DbStrDup(tls, db, (*SrcItem)(unsafe.Pointer(pOldItem)).FzAlias)
		(*SrcItem)(unsafe.Pointer(pNewItem)).Ffg = (*SrcItem)(unsafe.Pointer(pOldItem)).Ffg
		(*SrcItem)(unsafe.Pointer(pNewItem)).FiCursor = (*SrcItem)(unsafe.Pointer(pOldItem)).FiCursor
		(*SrcItem)(unsafe.Pointer(pNewItem)).FaddrFillSub = (*SrcItem)(unsafe.Pointer(pOldItem)).FaddrFillSub
		(*SrcItem)(unsafe.Pointer(pNewItem)).FregReturn = (*SrcItem)(unsafe.Pointer(pOldItem)).FregReturn
		if uint32(int32(*(*uint16)(unsafe.Pointer(pNewItem + 60 + 4))&0x2>>1)) != 0 {
			*(*uintptr)(unsafe.Pointer(pNewItem + 88)) = Xsqlite3DbStrDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 88)))
		}
		(*SrcItem)(unsafe.Pointer(pNewItem)).Fu2 = (*SrcItem)(unsafe.Pointer(pOldItem)).Fu2
		if uint32(int32(*(*uint16)(unsafe.Pointer(pNewItem + 60 + 4))&0x100>>8)) != 0 {
			(*CteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNewItem + 96)))).FnUse++
		}
		if uint32(int32(*(*uint16)(unsafe.Pointer(pNewItem + 60 + 4))&0x4>>2)) != 0 {
			*(*uintptr)(unsafe.Pointer(pNewItem + 88)) = Xsqlite3ExprListDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 88)), flags)
		}
		pTab = libc.AssignPtrUintptr(pNewItem+32, (*SrcItem)(unsafe.Pointer(pOldItem)).FpTab)
		if pTab != 0 {
			(*Table)(unsafe.Pointer(pTab)).FnTabRef++
		}
		(*SrcItem)(unsafe.Pointer(pNewItem)).FpSelect = Xsqlite3SelectDup(tls, db, (*SrcItem)(unsafe.Pointer(pOldItem)).FpSelect, flags)
		if uint32(int32(*(*uint16)(unsafe.Pointer(pOldItem + 60 + 4))&0x400>>10)) != 0 {
			*(*uintptr)(unsafe.Pointer(pNewItem + 72)) = Xsqlite3IdListDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 72)))
		} else {
			*(*uintptr)(unsafe.Pointer(pNewItem + 72)) = Xsqlite3ExprDup(tls, db, *(*uintptr)(unsafe.Pointer(pOldItem + 72)), flags)
		}
		(*SrcItem)(unsafe.Pointer(pNewItem)).FcolUsed = (*SrcItem)(unsafe.Pointer(pOldItem)).FcolUsed
	}
	return pNew
}

func Xsqlite3IdListDup(tls *libc.TLS, db uintptr, p uintptr) uintptr {
	var pNew uintptr
	var i int32

	if p == uintptr(0) {
		return uintptr(0)
	}

	pNew = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(IdList{}))+uint64((*IdList)(unsafe.Pointer(p)).FnId-1)*uint64(unsafe.Sizeof(IdList_item{})))
	if pNew == uintptr(0) {
		return uintptr(0)
	}
	(*IdList)(unsafe.Pointer(pNew)).FnId = (*IdList)(unsafe.Pointer(p)).FnId
	(*IdList)(unsafe.Pointer(pNew)).FeU4 = (*IdList)(unsafe.Pointer(p)).FeU4
	for i = 0; i < (*IdList)(unsafe.Pointer(p)).FnId; i++ {
		var pNewItem uintptr = pNew + 8 + uintptr(i)*16
		var pOldItem uintptr = p + 8 + uintptr(i)*16
		(*IdList_item)(unsafe.Pointer(pNewItem)).FzName = Xsqlite3DbStrDup(tls, db, (*IdList_item)(unsafe.Pointer(pOldItem)).FzName)
		(*IdList_item)(unsafe.Pointer(pNewItem)).Fu4 = (*IdList_item)(unsafe.Pointer(pOldItem)).Fu4
	}
	return pNew
}

func Xsqlite3SelectDup(tls *libc.TLS, db uintptr, pDup uintptr, flags int32) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var pNext uintptr = uintptr(0)
	var pp uintptr = bp
	var p uintptr

	for p = pDup; p != 0; p = (*Select)(unsafe.Pointer(p)).FpPrior {
		var pNew uintptr = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(Select{})))
		if pNew == uintptr(0) {
			break
		}
		(*Select)(unsafe.Pointer(pNew)).FpEList = Xsqlite3ExprListDup(tls, db, (*Select)(unsafe.Pointer(p)).FpEList, flags)
		(*Select)(unsafe.Pointer(pNew)).FpSrc = Xsqlite3SrcListDup(tls, db, (*Select)(unsafe.Pointer(p)).FpSrc, flags)
		(*Select)(unsafe.Pointer(pNew)).FpWhere = Xsqlite3ExprDup(tls, db, (*Select)(unsafe.Pointer(p)).FpWhere, flags)
		(*Select)(unsafe.Pointer(pNew)).FpGroupBy = Xsqlite3ExprListDup(tls, db, (*Select)(unsafe.Pointer(p)).FpGroupBy, flags)
		(*Select)(unsafe.Pointer(pNew)).FpHaving = Xsqlite3ExprDup(tls, db, (*Select)(unsafe.Pointer(p)).FpHaving, flags)
		(*Select)(unsafe.Pointer(pNew)).FpOrderBy = Xsqlite3ExprListDup(tls, db, (*Select)(unsafe.Pointer(p)).FpOrderBy, flags)
		(*Select)(unsafe.Pointer(pNew)).Fop = (*Select)(unsafe.Pointer(p)).Fop
		(*Select)(unsafe.Pointer(pNew)).FpNext = pNext
		(*Select)(unsafe.Pointer(pNew)).FpPrior = uintptr(0)
		(*Select)(unsafe.Pointer(pNew)).FpLimit = Xsqlite3ExprDup(tls, db, (*Select)(unsafe.Pointer(p)).FpLimit, flags)
		(*Select)(unsafe.Pointer(pNew)).FiLimit = 0
		(*Select)(unsafe.Pointer(pNew)).FiOffset = 0
		(*Select)(unsafe.Pointer(pNew)).FselFlags = (*Select)(unsafe.Pointer(p)).FselFlags & libc.Uint32FromInt32(libc.CplInt32(SF_UsesEphemeral))
		*(*int32)(unsafe.Pointer(pNew + 20)) = -1
		*(*int32)(unsafe.Pointer(pNew + 20 + 1*4)) = -1
		(*Select)(unsafe.Pointer(pNew)).FnSelectRow = (*Select)(unsafe.Pointer(p)).FnSelectRow
		(*Select)(unsafe.Pointer(pNew)).FpWith = Xsqlite3WithDup(tls, db, (*Select)(unsafe.Pointer(p)).FpWith)
		(*Select)(unsafe.Pointer(pNew)).FpWin = uintptr(0)
		(*Select)(unsafe.Pointer(pNew)).FpWinDefn = Xsqlite3WindowListDup(tls, db, (*Select)(unsafe.Pointer(p)).FpWinDefn)
		if (*Select)(unsafe.Pointer(p)).FpWin != 0 && int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
			gatherSelectWindows(tls, pNew)
		}
		(*Select)(unsafe.Pointer(pNew)).FselId = (*Select)(unsafe.Pointer(p)).FselId
		if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			(*Select)(unsafe.Pointer(pNew)).FpNext = uintptr(0)
			Xsqlite3SelectDelete(tls, db, pNew)
			break
		}
		*(*uintptr)(unsafe.Pointer(pp)) = pNew
		pp = pNew + 80
		pNext = pNew
	}

	return *(*uintptr)(unsafe.Pointer(bp))
}

var zeroItem = ExprList_item{}

func Xsqlite3ExprListAppendNew(tls *libc.TLS, db uintptr, pExpr uintptr) uintptr {
	var pItem uintptr
	var pList uintptr

	pList = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(ExprList{}))+uint64(unsafe.Sizeof(ExprList_item{}))*uint64(4))
	if pList == uintptr(0) {
		Xsqlite3ExprDelete(tls, db, pExpr)
		return uintptr(0)
	}
	(*ExprList)(unsafe.Pointer(pList)).FnAlloc = 4
	(*ExprList)(unsafe.Pointer(pList)).FnExpr = 1
	pItem = pList + 8
	*(*ExprList_item)(unsafe.Pointer(pItem)) = zeroItem
	(*ExprList_item)(unsafe.Pointer(pItem)).FpExpr = pExpr
	return pList
}

func Xsqlite3ExprListAppendGrow(tls *libc.TLS, db uintptr, pList uintptr, pExpr uintptr) uintptr {
	var pItem uintptr
	var pNew uintptr
	*(*int32)(unsafe.Pointer(pList + 4)) *= 2
	pNew = Xsqlite3DbRealloc(tls, db, pList,
		uint64(unsafe.Sizeof(ExprList{}))+uint64((*ExprList)(unsafe.Pointer(pList)).FnAlloc-1)*uint64(unsafe.Sizeof(ExprList_item{})))
	if pNew == uintptr(0) {
		Xsqlite3ExprListDelete(tls, db, pList)
		Xsqlite3ExprDelete(tls, db, pExpr)
		return uintptr(0)
	} else {
		pList = pNew
	}
	pItem = pList + 8 + uintptr(libc.PostIncInt32(&(*ExprList)(unsafe.Pointer(pList)).FnExpr, 1))*32
	*(*ExprList_item)(unsafe.Pointer(pItem)) = zeroItem
	(*ExprList_item)(unsafe.Pointer(pItem)).FpExpr = pExpr
	return pList
}

func Xsqlite3ExprListAppend(tls *libc.TLS, pParse uintptr, pList uintptr, pExpr uintptr) uintptr {
	var pItem uintptr
	if pList == uintptr(0) {
		return Xsqlite3ExprListAppendNew(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
	}
	if (*ExprList)(unsafe.Pointer(pList)).FnAlloc < (*ExprList)(unsafe.Pointer(pList)).FnExpr+1 {
		return Xsqlite3ExprListAppendGrow(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pList, pExpr)
	}
	pItem = pList + 8 + uintptr(libc.PostIncInt32(&(*ExprList)(unsafe.Pointer(pList)).FnExpr, 1))*32
	*(*ExprList_item)(unsafe.Pointer(pItem)) = zeroItem
	(*ExprList_item)(unsafe.Pointer(pItem)).FpExpr = pExpr
	return pList
}

func Xsqlite3ExprListAppendVector(tls *libc.TLS, pParse uintptr, pList uintptr, pColumns uintptr, pExpr uintptr) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var db uintptr
	var n int32
	var i int32
	var iFirst int32
	var pSubExpr uintptr
	var pFirst uintptr
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if pList != 0 {
		iFirst = (*ExprList)(unsafe.Pointer(pList)).FnExpr
	} else {
		iFirst = 0
	}

	if !(pColumns == uintptr(0)) {
		goto __1
	}
	goto vector_append_error
__1:
	;
	if !(pExpr == uintptr(0)) {
		goto __2
	}
	goto vector_append_error
__2:
	;
	if !(int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_SELECT && (*IdList)(unsafe.Pointer(pColumns)).FnId != libc.AssignInt32(&n, Xsqlite3ExprVectorSize(tls, pExpr))) {
		goto __3
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+10856,
		libc.VaList(bp, (*IdList)(unsafe.Pointer(pColumns)).FnId, n))
	goto vector_append_error
__3:
	;
	i = 0
__4:
	if !(i < (*IdList)(unsafe.Pointer(pColumns)).FnId) {
		goto __6
	}
	pSubExpr = Xsqlite3ExprForVectorField(tls, pParse, pExpr, i, (*IdList)(unsafe.Pointer(pColumns)).FnId)

	if !(pSubExpr == uintptr(0)) {
		goto __7
	}
	goto __5
__7:
	;
	pList = Xsqlite3ExprListAppend(tls, pParse, pList, pSubExpr)
	if !(pList != 0) {
		goto __8
	}

	(*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr((*ExprList)(unsafe.Pointer(pList)).FnExpr-1)*32)).FzEName = (*IdList_item)(unsafe.Pointer(pColumns + 8 + uintptr(i)*16)).FzName
	(*IdList_item)(unsafe.Pointer(pColumns + 8 + uintptr(i)*16)).FzName = uintptr(0)
__8:
	;
	goto __5
__5:
	i++
	goto __4
	goto __6
__6:
	;
	if !(!(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) && int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_SELECT && pList != uintptr(0)) {
		goto __9
	}
	pFirst = (*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(iFirst)*32)).FpExpr

	(*Expr)(unsafe.Pointer(pFirst)).FpRight = pExpr
	pExpr = uintptr(0)

	(*Expr)(unsafe.Pointer(pFirst)).FiTable = (*IdList)(unsafe.Pointer(pColumns)).FnId
__9:
	;
vector_append_error:
	Xsqlite3ExprUnmapAndDelete(tls, pParse, pExpr)
	Xsqlite3IdListDelete(tls, db, pColumns)
	return pList
}

func Xsqlite3ExprListSetSortOrder(tls *libc.TLS, p uintptr, iSortOrder int32, eNulls int32) {
	var pItem uintptr
	if p == uintptr(0) {
		return
	}

	pItem = p + 8 + uintptr((*ExprList)(unsafe.Pointer(p)).FnExpr-1)*32

	if iSortOrder == -1 {
		iSortOrder = SQLITE_SO_ASC
	}
	(*ExprList_item)(unsafe.Pointer(pItem)).Ffg.FsortFlags = U8(iSortOrder)

	if eNulls != -1 {
		libc.SetBitFieldPtr16Uint32(pItem+16+4, uint32(1), 5, 0x20)
		if iSortOrder != eNulls {
			*(*U8)(unsafe.Pointer(pItem + 16)) |= U8(KEYINFO_ORDER_BIGNULL)
		}
	}
}

func Xsqlite3ExprListSetName(tls *libc.TLS, pParse uintptr, pList uintptr, pName uintptr, dequote int32) {
	if pList != 0 {
		var pItem uintptr

		pItem = pList + 8 + uintptr((*ExprList)(unsafe.Pointer(pList)).FnExpr-1)*32

		(*ExprList_item)(unsafe.Pointer(pItem)).FzEName = Xsqlite3DbStrNDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Token)(unsafe.Pointer(pName)).Fz, uint64((*Token)(unsafe.Pointer(pName)).Fn))
		if dequote != 0 {
			Xsqlite3Dequote(tls, (*ExprList_item)(unsafe.Pointer(pItem)).FzEName)
			if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
				Xsqlite3RenameTokenMap(tls, pParse, (*ExprList_item)(unsafe.Pointer(pItem)).FzEName, pName)
			}
		}
	}
}

func Xsqlite3ExprListSetSpan(tls *libc.TLS, pParse uintptr, pList uintptr, zStart uintptr, zEnd uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if pList != 0 {
		var pItem uintptr = pList + 8 + uintptr((*ExprList)(unsafe.Pointer(pList)).FnExpr-1)*32

		if (*ExprList_item)(unsafe.Pointer(pItem)).FzEName == uintptr(0) {
			(*ExprList_item)(unsafe.Pointer(pItem)).FzEName = Xsqlite3DbSpanDup(tls, db, zStart, zEnd)
			libc.SetBitFieldPtr16Uint32(pItem+16+4, uint32(ENAME_SPAN), 0, 0x3)
		}
	}
}

func Xsqlite3ExprListCheckLength(tls *libc.TLS, pParse uintptr, pEList uintptr, zObject uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var mx int32 = *(*int32)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb + 136 + 2*4))

	if pEList != 0 && (*ExprList)(unsafe.Pointer(pEList)).FnExpr > mx {
		Xsqlite3ErrorMsg(tls, pParse, ts+10886, libc.VaList(bp, zObject))
	}
}

func exprListDeleteNN(tls *libc.TLS, db uintptr, pList uintptr) {
	var i int32 = (*ExprList)(unsafe.Pointer(pList)).FnExpr
	var pItem uintptr = pList + 8

	for __ccgo := true; __ccgo; __ccgo = libc.PreDecInt32(&i, 1) > 0 {
		Xsqlite3ExprDelete(tls, db, (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr)
		if (*ExprList_item)(unsafe.Pointer(pItem)).FzEName != 0 {
			Xsqlite3DbNNFreeNN(tls, db, (*ExprList_item)(unsafe.Pointer(pItem)).FzEName)
		}
		pItem += 32
	}
	Xsqlite3DbNNFreeNN(tls, db, pList)
}

func Xsqlite3ExprListDelete(tls *libc.TLS, db uintptr, pList uintptr) {
	if pList != 0 {
		exprListDeleteNN(tls, db, pList)
	}
}

func Xsqlite3ExprListFlags(tls *libc.TLS, pList uintptr) U32 {
	var i int32
	var m U32 = U32(0)

	for i = 0; i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
		var pExpr uintptr = (*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32)).FpExpr

		m = m | (*Expr)(unsafe.Pointer(pExpr)).Fflags
	}
	return m
}

func Xsqlite3SelectWalkFail(tls *libc.TLS, pWalker uintptr, NotUsed uintptr) int32 {
	_ = NotUsed
	(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(0)
	return WRC_Abort
}

func Xsqlite3IsTrueOrFalse(tls *libc.TLS, zIn uintptr) U32 {
	if Xsqlite3StrICmp(tls, zIn, ts+10909) == 0 {
		return U32(EP_IsTrue)
	}
	if Xsqlite3StrICmp(tls, zIn, ts+10914) == 0 {
		return U32(EP_IsFalse)
	}
	return U32(0)
}

func Xsqlite3ExprIdToTrueFalse(tls *libc.TLS, pExpr uintptr) int32 {
	var v U32

	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Quoted|EP_IntValue) != U32(0)) &&
		libc.AssignUint32(&v, Xsqlite3IsTrueOrFalse(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)))) != U32(0) {
		(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_TRUEFALSE)
		*(*U32)(unsafe.Pointer(pExpr + 4)) |= v
		return 1
	}
	return 0
}

func Xsqlite3ExprTruthValue(tls *libc.TLS, pExpr uintptr) int32 {
	pExpr = Xsqlite3ExprSkipCollate(tls, pExpr)

	return libc.Bool32(int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 8)) + 4))) == 0)
}

func Xsqlite3ExprSimplifiedAndOr(tls *libc.TLS, pExpr uintptr) uintptr {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AND || int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_OR {
		var pRight uintptr = Xsqlite3ExprSimplifiedAndOr(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
		var pLeft uintptr = Xsqlite3ExprSimplifiedAndOr(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
		if (*Expr)(unsafe.Pointer(pLeft)).Fflags&U32(EP_OuterON|EP_IsTrue) == U32(EP_IsTrue) || (*Expr)(unsafe.Pointer(pRight)).Fflags&U32(EP_OuterON|EP_IsFalse) == U32(EP_IsFalse) {
			if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AND {
				pExpr = pRight
			} else {
				pExpr = pLeft
			}
		} else if (*Expr)(unsafe.Pointer(pRight)).Fflags&U32(EP_OuterON|EP_IsTrue) == U32(EP_IsTrue) || (*Expr)(unsafe.Pointer(pLeft)).Fflags&U32(EP_OuterON|EP_IsFalse) == U32(EP_IsFalse) {
			if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AND {
				pExpr = pLeft
			} else {
				pExpr = pRight
			}
		}
	}
	return pExpr
}

func exprNodeIsConstant(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Walker)(unsafe.Pointer(pWalker)).FeCode) == 2 && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0) {
		(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(0)
		return WRC_Abort
	}

	{
		switch int32((*Expr)(unsafe.Pointer(pExpr)).Fop) {
		case TK_FUNCTION:
			if (int32((*Walker)(unsafe.Pointer(pWalker)).FeCode) >= 4 || (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_ConstFunc) != U32(0)) &&
				!((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0)) {
				if int32((*Walker)(unsafe.Pointer(pWalker)).FeCode) == 5 {
					*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_FromDDL)
				}
				return WRC_Continue
			} else {
				(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(0)
				return WRC_Abort
			}
			fallthrough
		case TK_ID:
			if Xsqlite3ExprIdToTrueFalse(tls, pExpr) != 0 {
				return WRC_Prune
			}
			fallthrough
		case TK_COLUMN:
			fallthrough
		case TK_AGG_FUNCTION:
			fallthrough
		case TK_AGG_COLUMN:
			if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_FixedCol) != U32(0) && int32((*Walker)(unsafe.Pointer(pWalker)).FeCode) != 2 {
				return WRC_Continue
			}
			if int32((*Walker)(unsafe.Pointer(pWalker)).FeCode) == 3 && (*Expr)(unsafe.Pointer(pExpr)).FiTable == *(*int32)(unsafe.Pointer(pWalker + 40)) {
				return WRC_Continue
			}
			fallthrough
		case TK_IF_NULL_ROW:
			fallthrough
		case TK_REGISTER:
			fallthrough
		case TK_DOT:
			(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(0)
			return WRC_Abort
		case TK_VARIABLE:
			if int32((*Walker)(unsafe.Pointer(pWalker)).FeCode) == 5 {
				(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_NULL)
			} else if int32((*Walker)(unsafe.Pointer(pWalker)).FeCode) == 4 {
				(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(0)
				return WRC_Abort
			}
			fallthrough
		default:
			return WRC_Continue
		}
	}
	return int32(0)
}

func exprIsConst(tls *libc.TLS, p uintptr, initFlag int32, iCur int32) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	(*Walker)(unsafe.Pointer(bp)).FeCode = U16(initFlag)
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{exprNodeIsConstant}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3SelectWalkFail}))
	*(*int32)(unsafe.Pointer(bp + 40)) = iCur
	Xsqlite3WalkExpr(tls, bp, p)
	return int32((*Walker)(unsafe.Pointer(bp)).FeCode)
}

func Xsqlite3ExprIsConstant(tls *libc.TLS, p uintptr) int32 {
	return exprIsConst(tls, p, 1, 0)
}

func Xsqlite3ExprIsConstantNotJoin(tls *libc.TLS, p uintptr) int32 {
	return exprIsConst(tls, p, 2, 0)
}

func Xsqlite3ExprIsTableConstant(tls *libc.TLS, p uintptr, iCur int32) int32 {
	return exprIsConst(tls, p, 3, iCur)
}

func Xsqlite3ExprIsTableConstraint(tls *libc.TLS, pExpr uintptr, pSrc uintptr) int32 {
	if int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&JT_LTORJ != 0 {
		return 0
	}
	if int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&JT_LEFT != 0 {
		if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0)) {
			return 0
		}
		if *(*int32)(unsafe.Pointer(pExpr + 52)) != (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor {
			return 0
		}
	} else {
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0) {
			return 0
		}
	}
	return Xsqlite3ExprIsTableConstant(tls, pExpr, (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor)
}

func exprNodeIsConstantOrGroupBy(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var pGroupBy uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	var i int32

	for i = 0; i < (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr; i++ {
		var p uintptr = (*ExprList_item)(unsafe.Pointer(pGroupBy + 8 + uintptr(i)*32)).FpExpr
		if Xsqlite3ExprCompare(tls, uintptr(0), pExpr, p, -1) < 2 {
			var pColl uintptr = Xsqlite3ExprNNCollSeq(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse, p)
			if Xsqlite3IsBinary(tls, pColl) != 0 {
				return WRC_Prune
			}
		}
	}

	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
		(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(0)
		return WRC_Abort
	}

	return exprNodeIsConstant(tls, pWalker, pExpr)
}

func Xsqlite3ExprIsConstantOrGroupBy(tls *libc.TLS, pParse uintptr, p uintptr, pGroupBy uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	(*Walker)(unsafe.Pointer(bp)).FeCode = U16(1)
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{exprNodeIsConstantOrGroupBy}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 40)) = pGroupBy
	(*Walker)(unsafe.Pointer(bp)).FpParse = pParse
	Xsqlite3WalkExpr(tls, bp, p)
	return int32((*Walker)(unsafe.Pointer(bp)).FeCode)
}

func Xsqlite3ExprIsConstantOrFunction(tls *libc.TLS, p uintptr, isInit U8) int32 {
	return exprIsConst(tls, p, 4+int32(isInit), 0)
}

func Xsqlite3ExprIsInteger(tls *libc.TLS, p uintptr, pValue uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32 = 0
	if p == uintptr(0) {
		return 0
	}

	if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_IntValue) != 0 {
		*(*int32)(unsafe.Pointer(pValue)) = *(*int32)(unsafe.Pointer(p + 8))
		return 1
	}
	switch int32((*Expr)(unsafe.Pointer(p)).Fop) {
	case TK_UPLUS:
		{
			rc = Xsqlite3ExprIsInteger(tls, (*Expr)(unsafe.Pointer(p)).FpLeft, pValue)
			break

		}
	case TK_UMINUS:
		{
			*(*int32)(unsafe.Pointer(bp)) = 0
			if Xsqlite3ExprIsInteger(tls, (*Expr)(unsafe.Pointer(p)).FpLeft, bp) != 0 {
				*(*int32)(unsafe.Pointer(pValue)) = -*(*int32)(unsafe.Pointer(bp))
				rc = 1
			}
			break

		}
	default:
		break
	}
	return rc
}

func Xsqlite3ExprCanBeNull(tls *libc.TLS, p uintptr) int32 {
	var op U8

	for int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_UPLUS || int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_UMINUS {
		p = (*Expr)(unsafe.Pointer(p)).FpLeft

	}
	op = (*Expr)(unsafe.Pointer(p)).Fop
	if int32(op) == TK_REGISTER {
		op = (*Expr)(unsafe.Pointer(p)).Fop2
	}
	switch int32(op) {
	case TK_INTEGER:
		fallthrough
	case TK_STRING:
		fallthrough
	case TK_FLOAT:
		fallthrough
	case TK_BLOB:
		return 0
	case TK_COLUMN:
		return libc.Bool32((*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_CanBeNull) != U32(0) || *(*uintptr)(unsafe.Pointer(p + 64)) == uintptr(0) || int32((*Expr)(unsafe.Pointer(p)).FiColumn) >= 0 &&
			(*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FaCol != uintptr(0) &&
			int32(*(*uint8)(unsafe.Pointer((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FaCol + uintptr((*Expr)(unsafe.Pointer(p)).FiColumn)*24 + 8))&0xf>>0) == 0)
	default:
		return 1
	}
	return int32(0)
}

func Xsqlite3ExprNeedsNoAffinityChange(tls *libc.TLS, p uintptr, aff uint8) int32 {
	var op U8
	var unaryMinus int32 = 0
	if int32(aff) == SQLITE_AFF_BLOB {
		return 1
	}
	for int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_UPLUS || int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_UMINUS {
		if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_UMINUS {
			unaryMinus = 1
		}
		p = (*Expr)(unsafe.Pointer(p)).FpLeft
	}
	op = (*Expr)(unsafe.Pointer(p)).Fop
	if int32(op) == TK_REGISTER {
		op = (*Expr)(unsafe.Pointer(p)).Fop2
	}
	switch int32(op) {
	case TK_INTEGER:
		{
			return libc.Bool32(int32(aff) >= SQLITE_AFF_NUMERIC)

		}
	case TK_FLOAT:
		{
			return libc.Bool32(int32(aff) >= SQLITE_AFF_NUMERIC)

		}
	case TK_STRING:
		{
			return libc.Bool32(!(unaryMinus != 0) && int32(aff) == SQLITE_AFF_TEXT)

		}
	case TK_BLOB:
		{
			return libc.BoolInt32(!(unaryMinus != 0))

		}
	case TK_COLUMN:
		{
			return libc.Bool32(int32(aff) >= SQLITE_AFF_NUMERIC && int32((*Expr)(unsafe.Pointer(p)).FiColumn) < 0)

		}
	default:
		{
			return 0

		}
	}
	return int32(0)
}

func Xsqlite3IsRowid(tls *libc.TLS, z uintptr) int32 {
	if Xsqlite3StrICmp(tls, z, ts+10920) == 0 {
		return 1
	}
	if Xsqlite3StrICmp(tls, z, ts+10928) == 0 {
		return 1
	}
	if Xsqlite3StrICmp(tls, z, ts+10934) == 0 {
		return 1
	}
	return 0
}

func isCandidateForInOpt(tls *libc.TLS, pX uintptr) uintptr {
	var p uintptr
	var pSrc uintptr
	var pEList uintptr
	var pTab uintptr
	var i int32
	if !((*Expr)(unsafe.Pointer(pX)).Fflags&U32(EP_xIsSelect) != U32(0)) {
		return uintptr(0)
	}
	if (*Expr)(unsafe.Pointer(pX)).Fflags&U32(EP_VarSelect) != U32(0) {
		return uintptr(0)
	}
	p = *(*uintptr)(unsafe.Pointer(pX + 32))
	if (*Select)(unsafe.Pointer(p)).FpPrior != 0 {
		return uintptr(0)
	}
	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct|SF_Aggregate) != 0 {
		return uintptr(0)
	}

	if (*Select)(unsafe.Pointer(p)).FpLimit != 0 {
		return uintptr(0)
	}
	if (*Select)(unsafe.Pointer(p)).FpWhere != 0 {
		return uintptr(0)
	}
	pSrc = (*Select)(unsafe.Pointer(p)).FpSrc

	if (*SrcList)(unsafe.Pointer(pSrc)).FnSrc != 1 {
		return uintptr(0)
	}
	if (*SrcItem)(unsafe.Pointer(pSrc+8)).FpSelect != 0 {
		return uintptr(0)
	}
	pTab = (*SrcItem)(unsafe.Pointer(pSrc + 8)).FpTab

	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
		return uintptr(0)
	}
	pEList = (*Select)(unsafe.Pointer(p)).FpEList

	for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
		var pRes uintptr = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32)).FpExpr
		if int32((*Expr)(unsafe.Pointer(pRes)).Fop) != TK_COLUMN {
			return uintptr(0)
		}

	}
	return p
}

func sqlite3SetHasNullFlag(tls *libc.TLS, v uintptr, iCur int32, regHasNull int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var addr1 int32
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regHasNull)
	addr1 = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, iCur)
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, iCur, 0, regHasNull)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_TYPEOFARG))
	Xsqlite3VdbeComment(tls, v, ts+10938, libc.VaList(bp, iCur))
	Xsqlite3VdbeJumpHere(tls, v, addr1)
}

func sqlite3InRhsIsConstant(tls *libc.TLS, pIn uintptr) int32 {
	var pLHS uintptr
	var res int32

	pLHS = (*Expr)(unsafe.Pointer(pIn)).FpLeft
	(*Expr)(unsafe.Pointer(pIn)).FpLeft = uintptr(0)
	res = Xsqlite3ExprIsConstant(tls, pIn)
	(*Expr)(unsafe.Pointer(pIn)).FpLeft = pLHS
	return res
}

func Xsqlite3FindInIndex(tls *libc.TLS, pParse uintptr, pX uintptr, inFlags U32, prRhsHasNull uintptr, aiMap uintptr, piTab uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var p uintptr
	var eType int32 = 0
	var iTab int32
	var mustBeUnique int32
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)

	mustBeUnique = libc.Bool32(inFlags&U32(IN_INDEX_LOOP) != U32(0))
	iTab = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)

	if prRhsHasNull != 0 && (*Expr)(unsafe.Pointer(pX)).Fflags&U32(EP_xIsSelect) != U32(0) {
		var i int32
		var pEList uintptr = (*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 32)))).FpEList
		for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
			if Xsqlite3ExprCanBeNull(tls, (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(i)*32)).FpExpr) != 0 {
				break
			}
		}
		if i == (*ExprList)(unsafe.Pointer(pEList)).FnExpr {
			prRhsHasNull = uintptr(0)
		}
	}

	if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 && libc.AssignUintptr(&p, isCandidateForInOpt(tls, pX)) != uintptr(0) {
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		var pTab uintptr
		var iDb int32
		var pEList uintptr = (*Select)(unsafe.Pointer(p)).FpEList
		var nExpr int32 = (*ExprList)(unsafe.Pointer(pEList)).FnExpr

		pTab = (*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FpTab

		iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

		Xsqlite3CodeVerifySchema(tls, pParse, iDb)
		Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*Table)(unsafe.Pointer(pTab)).FzName)

		if nExpr == 1 && int32((*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pEList+8)).FpExpr)).FiColumn) < 0 {
			var iAddr int32 = Xsqlite3VdbeAddOp0(tls, v, OP_Once)

			Xsqlite3OpenTable(tls, pParse, iTab, iDb, pTab, OP_OpenRead)
			eType = IN_INDEX_ROWID
			Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+10957, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
			Xsqlite3VdbeJumpHere(tls, v, iAddr)
		} else {
			var pIdx uintptr
			var affinity_ok int32 = 1
			var i int32

			for i = 0; i < nExpr && affinity_ok != 0; i++ {
				var pLhs uintptr = Xsqlite3VectorFieldSubexpr(tls, (*Expr)(unsafe.Pointer(pX)).FpLeft, i)
				var iCol int32 = int32((*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32)).FpExpr)).FiColumn)
				var idxaff uint8 = Xsqlite3TableColumnAffinity(tls, pTab, iCol)
				var cmpaff uint8 = Xsqlite3CompareAffinity(tls, pLhs, idxaff)

				switch int32(cmpaff) {
				case SQLITE_AFF_BLOB:
					break
					fallthrough
				case SQLITE_AFF_TEXT:
					break
					fallthrough
				default:
					affinity_ok = libc.Bool32(int32(idxaff) >= SQLITE_AFF_NUMERIC)
				}
			}

			if affinity_ok != 0 {
				for pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIdx != 0 && eType == 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
					var colUsed Bitmask
					var mCol Bitmask
					if int32((*Index)(unsafe.Pointer(pIdx)).FnColumn) < nExpr {
						continue
					}
					if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) {
						continue
					}

					if int32((*Index)(unsafe.Pointer(pIdx)).FnColumn) >= int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1 {
						continue
					}
					if mustBeUnique != 0 {
						if int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) > nExpr ||
							int32((*Index)(unsafe.Pointer(pIdx)).FnColumn) > nExpr && !(int32((*Index)(unsafe.Pointer(pIdx)).FonError) != OE_None) {
							continue
						}
					}

					colUsed = uint64(0)
					for i = 0; i < nExpr; i++ {
						var pLhs uintptr = Xsqlite3VectorFieldSubexpr(tls, (*Expr)(unsafe.Pointer(pX)).FpLeft, i)
						var pRhs uintptr = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32)).FpExpr
						var pReq uintptr = Xsqlite3BinaryCompareCollSeq(tls, pParse, pLhs, pRhs)
						var j int32

						for j = 0; j < nExpr; j++ {
							if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) != int32((*Expr)(unsafe.Pointer(pRhs)).FiColumn) {
								continue
							}

							if pReq != uintptr(0) && Xsqlite3StrICmp(tls, (*CollSeq)(unsafe.Pointer(pReq)).FzName, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*8))) != 0 {
								continue
							}
							break
						}
						if j == nExpr {
							break
						}
						mCol = uint64(1) << j
						if mCol&colUsed != 0 {
							break
						}
						colUsed = colUsed | mCol
						if aiMap != 0 {
							*(*int32)(unsafe.Pointer(aiMap + uintptr(i)*4)) = j
						}
					}

					if colUsed == uint64(1)<<nExpr-uint64(1) {
						var iAddr int32 = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
						Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+11004, libc.VaList(bp+8, (*Index)(unsafe.Pointer(pIdx)).FzName))
						Xsqlite3VdbeAddOp3(tls, v, OP_OpenRead, iTab, int32((*Index)(unsafe.Pointer(pIdx)).Ftnum), iDb)
						Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
						Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+16, (*Index)(unsafe.Pointer(pIdx)).FzName))

						eType = IN_INDEX_INDEX_ASC + int32(*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSortOrder)))

						if prRhsHasNull != 0 {
							*(*int32)(unsafe.Pointer(prRhsHasNull)) = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
							if nExpr == 1 {
								sqlite3SetHasNullFlag(tls, v, iTab, *(*int32)(unsafe.Pointer(prRhsHasNull)))
							}
						}
						Xsqlite3VdbeJumpHere(tls, v, iAddr)
					}
				}
			}
		}
	}

	if eType == 0 &&
		inFlags&U32(IN_INDEX_NOOP_OK) != 0 &&
		(*Expr)(unsafe.Pointer(pX)).Fflags&U32(EP_xIsSelect) == U32(0) &&
		(!(sqlite3InRhsIsConstant(tls, pX) != 0) || (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 32)))).FnExpr <= 2) {
		(*Parse)(unsafe.Pointer(pParse)).FnTab--
		iTab = -1
		eType = IN_INDEX_NOOP
	}

	if eType == 0 {
		var savedNQueryLoop U32 = (*Parse)(unsafe.Pointer(pParse)).FnQueryLoop
		var rMayHaveNull int32 = 0
		eType = IN_INDEX_EPH
		if inFlags&U32(IN_INDEX_LOOP) != 0 {
			(*Parse)(unsafe.Pointer(pParse)).FnQueryLoop = U32(0)
		} else if prRhsHasNull != 0 {
			*(*int32)(unsafe.Pointer(prRhsHasNull)) = libc.AssignInt32(&rMayHaveNull, libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1))
		}

		Xsqlite3CodeRhsOfIN(tls, pParse, pX, iTab)
		if rMayHaveNull != 0 {
			sqlite3SetHasNullFlag(tls, v, iTab, rMayHaveNull)
		}
		(*Parse)(unsafe.Pointer(pParse)).FnQueryLoop = savedNQueryLoop
	}

	if aiMap != 0 && eType != IN_INDEX_INDEX_ASC && eType != IN_INDEX_INDEX_DESC {
		var i int32
		var n int32
		n = Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pX)).FpLeft)
		for i = 0; i < n; i++ {
			*(*int32)(unsafe.Pointer(aiMap + uintptr(i)*4)) = i
		}
	}
	*(*int32)(unsafe.Pointer(piTab)) = iTab
	return eType
}

func exprINAffinity(tls *libc.TLS, pParse uintptr, pExpr uintptr) uintptr {
	var pLeft uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	var nVal int32 = Xsqlite3ExprVectorSize(tls, pLeft)
	var pSelect uintptr
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
		pSelect = *(*uintptr)(unsafe.Pointer(pExpr + 32))
	} else {
		pSelect = uintptr(0)
	}
	var zRet uintptr

	zRet = Xsqlite3DbMallocRaw(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(nVal+1))
	if zRet != 0 {
		var i int32
		for i = 0; i < nVal; i++ {
			var pA uintptr = Xsqlite3VectorFieldSubexpr(tls, pLeft, i)
			var a uint8 = Xsqlite3ExprAffinity(tls, pA)
			if pSelect != 0 {
				*(*uint8)(unsafe.Pointer(zRet + uintptr(i))) = Xsqlite3CompareAffinity(tls, (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpEList+8+uintptr(i)*32)).FpExpr, a)
			} else {
				*(*uint8)(unsafe.Pointer(zRet + uintptr(i))) = a
			}
		}
		*(*uint8)(unsafe.Pointer(zRet + uintptr(nVal))) = uint8(0)
	}
	return zRet
}

func Xsqlite3SubselectError(tls *libc.TLS, pParse uintptr, nActual int32, nExpect int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 {
		var zFmt uintptr = ts + 11035
		Xsqlite3ErrorMsg(tls, pParse, zFmt, libc.VaList(bp, nActual, nExpect))
	}
}

func Xsqlite3VectorErrorMsg(tls *libc.TLS, pParse uintptr, pExpr uintptr) {
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
		Xsqlite3SubselectError(tls, pParse, (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList)).FnExpr, 1)
	} else {
		Xsqlite3ErrorMsg(tls, pParse, ts+9748, 0)
	}
}

func Xsqlite3CodeRhsOfIN(tls *libc.TLS, pParse uintptr, pExpr uintptr, iTab int32) {
	bp := tls.Alloc(73)
	defer tls.Free(73)

	var addrOnce int32 = 0
	var addr int32
	var pLeft uintptr
	var pKeyInfo uintptr = uintptr(0)
	var nVal int32
	var v uintptr

	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_VarSelect) != U32(0)) && (*Parse)(unsafe.Pointer(pParse)).FiSelfTab == 0 {
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Subrtn) != U32(0) {
			addrOnce = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
			if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
				Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+11079, libc.VaList(bp, (*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FselId))
			}

			Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, *(*int32)(unsafe.Pointer(pExpr + 64 + 4)),
				*(*int32)(unsafe.Pointer(pExpr + 64)))

			Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, iTab, (*Expr)(unsafe.Pointer(pExpr)).FiTable)
			Xsqlite3VdbeJumpHere(tls, v, addrOnce)
			return
		}

		*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_Subrtn)

		*(*int32)(unsafe.Pointer(pExpr + 64 + 4)) = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		*(*int32)(unsafe.Pointer(pExpr + 64)) = Xsqlite3VdbeAddOp2(tls, v, OP_BeginSubrtn, 0, *(*int32)(unsafe.Pointer(pExpr + 64 + 4))) + 1

		addrOnce = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
	}

	pLeft = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	nVal = Xsqlite3ExprVectorSize(tls, pLeft)

	(*Expr)(unsafe.Pointer(pExpr)).FiTable = iTab
	addr = Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, (*Expr)(unsafe.Pointer(pExpr)).FiTable, nVal)
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
		Xsqlite3VdbeComment(tls, v, ts+11102, libc.VaList(bp+8, (*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FselId))
	} else {
		Xsqlite3VdbeComment(tls, v, ts+11122, 0)
	}
	pKeyInfo = Xsqlite3KeyInfoAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, nVal, 1)

	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
		var pSelect uintptr = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		var pEList uintptr = (*Select)(unsafe.Pointer(pSelect)).FpEList

		Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+11141, libc.VaList(bp+16, func() uintptr {
			if addrOnce != 0 {
				return ts + 1636
			}
			return ts + 11160
		}(), (*Select)(unsafe.Pointer(pSelect)).FselId))

		if (*ExprList)(unsafe.Pointer(pEList)).FnExpr == nVal {
			var pCopy uintptr

			var i int32
			var rc int32
			Xsqlite3SelectDestInit(tls, bp+32, SRT_Set, iTab)
			(*SelectDest)(unsafe.Pointer(bp + 32)).FzAffSdst = exprINAffinity(tls, pParse, pExpr)
			(*Select)(unsafe.Pointer(pSelect)).FiLimit = 0

			pCopy = Xsqlite3SelectDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pSelect, 0)
			if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
				rc = 1
			} else {
				rc = Xsqlite3Select(tls, pParse, pCopy, bp+32)
			}
			Xsqlite3SelectDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pCopy)
			Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*SelectDest)(unsafe.Pointer(bp+32)).FzAffSdst)
			if rc != 0 {
				Xsqlite3KeyInfoUnref(tls, pKeyInfo)
				return
			}

			for i = 0; i < nVal; i++ {
				var p uintptr = Xsqlite3VectorFieldSubexpr(tls, pLeft, i)
				*(*uintptr)(unsafe.Pointer(pKeyInfo + 32 + uintptr(i)*8)) = Xsqlite3BinaryCompareCollSeq(tls,
					pParse, p, (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(i)*32)).FpExpr)
			}
		}
	} else if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != uintptr(0) {
		var i int32
		var pList uintptr = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		var pItem uintptr
		var r1 int32
		var r2 int32
		*(*uint8)(unsafe.Pointer(bp + 72)) = Xsqlite3ExprAffinity(tls, pLeft)
		if int32(*(*uint8)(unsafe.Pointer(bp + 72))) <= SQLITE_AFF_NONE {
			*(*uint8)(unsafe.Pointer(bp + 72)) = uint8(SQLITE_AFF_BLOB)
		} else if int32(*(*uint8)(unsafe.Pointer(bp + 72))) == SQLITE_AFF_REAL {
			*(*uint8)(unsafe.Pointer(bp + 72)) = uint8(SQLITE_AFF_NUMERIC)
		}
		if pKeyInfo != 0 {
			*(*uintptr)(unsafe.Pointer(pKeyInfo + 32)) = Xsqlite3ExprCollSeq(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
		}

		r1 = Xsqlite3GetTempReg(tls, pParse)
		r2 = Xsqlite3GetTempReg(tls, pParse)
		i = (*ExprList)(unsafe.Pointer(pList)).FnExpr
		pItem = pList + 8
	__1:
		if !(i > 0) {
			goto __3
		}
		{
			var pE2 uintptr = (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr

			if addrOnce != 0 && !(Xsqlite3ExprIsConstant(tls, pE2) != 0) {
				Xsqlite3VdbeChangeToNoop(tls, v, addrOnce-1)
				Xsqlite3VdbeChangeToNoop(tls, v, addrOnce)
				*(*U32)(unsafe.Pointer(pExpr + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_Subrtn))
				addrOnce = 0
			}

			Xsqlite3ExprCode(tls, pParse, pE2, r1)
			Xsqlite3VdbeAddOp4(tls, v, OP_MakeRecord, r1, 1, r2, bp+72, 1)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iTab, r2, r1, 1)

		}
		goto __2
	__2:
		i--
		pItem += 32
		goto __1
		goto __3
	__3:
		;
		Xsqlite3ReleaseTempReg(tls, pParse, r1)
		Xsqlite3ReleaseTempReg(tls, pParse, r2)
	}
	if pKeyInfo != 0 {
		Xsqlite3VdbeChangeP4(tls, v, addr, pKeyInfo, -8)
	}
	if addrOnce != 0 {
		Xsqlite3VdbeAddOp1(tls, v, OP_NullRow, iTab)
		Xsqlite3VdbeJumpHere(tls, v, addrOnce)

		Xsqlite3VdbeAddOp3(tls, v, OP_Return, *(*int32)(unsafe.Pointer(pExpr + 64 + 4)),
			*(*int32)(unsafe.Pointer(pExpr + 64)), 1)

		Xsqlite3ClearTempRegCache(tls, pParse)
	}
}

func Xsqlite3CodeSubselect(tls *libc.TLS, pParse uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var addrOnce int32 = 0
	var rReg int32 = 0
	var pSel uintptr

	var nReg int32
	var pLimit uintptr

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return 0
	}

	pSel = *(*uintptr)(unsafe.Pointer(pExpr + 32))

	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Subrtn) != U32(0) {
		Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+11172, libc.VaList(bp, (*Select)(unsafe.Pointer(pSel)).FselId))

		Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, *(*int32)(unsafe.Pointer(pExpr + 64 + 4)),
			*(*int32)(unsafe.Pointer(pExpr + 64)))
		return (*Expr)(unsafe.Pointer(pExpr)).FiTable
	}

	*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_Subrtn)
	*(*int32)(unsafe.Pointer(pExpr + 64 + 4)) = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	*(*int32)(unsafe.Pointer(pExpr + 64)) = Xsqlite3VdbeAddOp2(tls, v, OP_BeginSubrtn, 0, *(*int32)(unsafe.Pointer(pExpr + 64 + 4))) + 1

	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_VarSelect) != U32(0)) {
		addrOnce = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
	}

	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+11190, libc.VaList(bp+8, func() uintptr {
		if addrOnce != 0 {
			return ts + 1636
		}
		return ts + 11160
	}(), (*Select)(unsafe.Pointer(pSel)).FselId))

	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_SELECT {
		nReg = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSel)).FpEList)).FnExpr
	} else {
		nReg = 1
	}
	Xsqlite3SelectDestInit(tls, bp+24, 0, (*Parse)(unsafe.Pointer(pParse)).FnMem+1)
	*(*int32)(unsafe.Pointer(pParse + 56)) += nReg
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_SELECT {
		(*SelectDest)(unsafe.Pointer(bp + 24)).FeDest = U8(SRT_Mem)
		(*SelectDest)(unsafe.Pointer(bp + 24)).FiSdst = (*SelectDest)(unsafe.Pointer(bp + 24)).FiSDParm
		(*SelectDest)(unsafe.Pointer(bp + 24)).FnSdst = nReg
		Xsqlite3VdbeAddOp3(tls, v, OP_Null, 0, (*SelectDest)(unsafe.Pointer(bp+24)).FiSDParm, (*SelectDest)(unsafe.Pointer(bp+24)).FiSDParm+nReg-1)
		Xsqlite3VdbeComment(tls, v, ts+11211, 0)
	} else {
		(*SelectDest)(unsafe.Pointer(bp + 24)).FeDest = U8(SRT_Exists)
		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*SelectDest)(unsafe.Pointer(bp+24)).FiSDParm)
		Xsqlite3VdbeComment(tls, v, ts+11232, 0)
	}
	if (*Select)(unsafe.Pointer(pSel)).FpLimit != 0 {
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		pLimit = Xsqlite3Expr(tls, db, TK_INTEGER, ts+10734)
		if pLimit != 0 {
			(*Expr)(unsafe.Pointer(pLimit)).FaffExpr = uint8(SQLITE_AFF_NUMERIC)
			pLimit = Xsqlite3PExpr(tls, pParse, TK_NE,
				Xsqlite3ExprDup(tls, db, (*Expr)(unsafe.Pointer((*Select)(unsafe.Pointer(pSel)).FpLimit)).FpLeft, 0), pLimit)
		}
		Xsqlite3ExprDeferredDelete(tls, pParse, (*Expr)(unsafe.Pointer((*Select)(unsafe.Pointer(pSel)).FpLimit)).FpLeft)
		(*Expr)(unsafe.Pointer((*Select)(unsafe.Pointer(pSel)).FpLimit)).FpLeft = pLimit
	} else {
		pLimit = Xsqlite3Expr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_INTEGER, ts+11251)
		(*Select)(unsafe.Pointer(pSel)).FpLimit = Xsqlite3PExpr(tls, pParse, TK_LIMIT, pLimit, uintptr(0))
	}
	(*Select)(unsafe.Pointer(pSel)).FiLimit = 0
	if Xsqlite3Select(tls, pParse, pSel, bp+24) != 0 {
		(*Expr)(unsafe.Pointer(pExpr)).Fop2 = (*Expr)(unsafe.Pointer(pExpr)).Fop
		(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_ERROR)
		return 0
	}
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = libc.AssignInt32(&rReg, (*SelectDest)(unsafe.Pointer(bp+24)).FiSDParm)

	if addrOnce != 0 {
		Xsqlite3VdbeJumpHere(tls, v, addrOnce)
	}

	Xsqlite3VdbeAddOp3(tls, v, OP_Return, *(*int32)(unsafe.Pointer(pExpr + 64 + 4)),
		*(*int32)(unsafe.Pointer(pExpr + 64)), 1)

	Xsqlite3ClearTempRegCache(tls, pParse)
	return rReg
}

func Xsqlite3ExprCheckIN(tls *libc.TLS, pParse uintptr, pIn uintptr) int32 {
	var nVector int32 = Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pIn)).FpLeft)
	if (*Expr)(unsafe.Pointer(pIn)).Fflags&U32(EP_xIsSelect) != U32(0) && !(int32((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed) != 0) {
		if nVector != (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIn + 32)))).FpEList)).FnExpr {
			Xsqlite3SubselectError(tls, pParse, (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIn + 32)))).FpEList)).FnExpr, nVector)
			return 1
		}
	} else if nVector != 1 {
		Xsqlite3VectorErrorMsg(tls, pParse, (*Expr)(unsafe.Pointer(pIn)).FpLeft)
		return 1
	}
	return 0
}

func sqlite3ExprCodeIN(tls *libc.TLS, pParse uintptr, pExpr uintptr, destIfFalse int32, destIfNull int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var eType int32
	var rLhs int32
	var rLhsOrig int32
	var v uintptr
	var aiMap uintptr
	var zAff uintptr
	var nVector int32

	var pLeft uintptr
	var i int32
	var destStep2 int32
	var destStep6 int32
	var addrTruthOp int32
	var destNotNull int32
	var addrTop int32

	var okConstFactor U8
	var op int32
	var op1 int32
	var pList uintptr
	var pColl uintptr
	var labelOk int32
	var r2 int32

	var regCkNull int32
	var ii int32
	var p uintptr
	var p1 uintptr
	var pColl1 uintptr
	var r3 int32
	*(*int32)(unsafe.Pointer(bp)) = 0
	aiMap = uintptr(0)
	zAff = uintptr(0)
	destStep6 = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	okConstFactor = (*Parse)(unsafe.Pointer(pParse)).FokConstFactor

	pLeft = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	if !(Xsqlite3ExprCheckIN(tls, pParse, pExpr) != 0) {
		goto __1
	}
	return
__1:
	;
	zAff = exprINAffinity(tls, pParse, pExpr)
	nVector = Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
	aiMap = Xsqlite3DbMallocZero(tls,
		(*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(nVector)*(uint64(unsafe.Sizeof(int32(0)))+uint64(unsafe.Sizeof(uint8(0))))+uint64(1))
	if !((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
		goto __2
	}
	goto sqlite3ExprCodeIN_oom_error
__2:
	;
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	Xsqlite3VdbeNoopComment(tls, v, ts+11253, 0)
	eType = Xsqlite3FindInIndex(tls, pParse, pExpr,
		uint32(IN_INDEX_MEMBERSHIP|IN_INDEX_NOOP_OK),
		func() uintptr {
			if destIfFalse == destIfNull {
				return uintptr(0)
			}
			return bp
		}(),
		aiMap, bp+4)

	(*Parse)(unsafe.Pointer(pParse)).FokConstFactor = U8(0)
	rLhsOrig = exprCodeVector(tls, pParse, pLeft, bp+8)
	(*Parse)(unsafe.Pointer(pParse)).FokConstFactor = okConstFactor
	i = 0
__3:
	if !(i < nVector && *(*int32)(unsafe.Pointer(aiMap + uintptr(i)*4)) == i) {
		goto __5
	}
	goto __4
__4:
	i++
	goto __3
	goto __5
__5:
	;
	if !(i == nVector) {
		goto __6
	}

	rLhs = rLhsOrig
	goto __7
__6:
	rLhs = Xsqlite3GetTempRange(tls, pParse, nVector)
	i = 0
__8:
	if !(i < nVector) {
		goto __10
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Copy, rLhsOrig+i, rLhs+*(*int32)(unsafe.Pointer(aiMap + uintptr(i)*4)), 0)
	goto __9
__9:
	i++
	goto __8
	goto __10
__10:
	;
__7:
	;
	if !(eType == IN_INDEX_NOOP) {
		goto __11
	}
	labelOk = Xsqlite3VdbeMakeLabel(tls, pParse)
	regCkNull = 0

	pList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
	pColl = Xsqlite3ExprCollSeq(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
	if !(destIfNull != destIfFalse) {
		goto __12
	}
	regCkNull = Xsqlite3GetTempReg(tls, pParse)
	Xsqlite3VdbeAddOp3(tls, v, OP_BitAnd, rLhs, rLhs, regCkNull)
__12:
	;
	ii = 0
__13:
	if !(ii < (*ExprList)(unsafe.Pointer(pList)).FnExpr) {
		goto __15
	}
	r2 = Xsqlite3ExprCodeTemp(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(ii)*32)).FpExpr, bp+12)
	if !(regCkNull != 0 && Xsqlite3ExprCanBeNull(tls, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(ii)*32)).FpExpr) != 0) {
		goto __16
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_BitAnd, regCkNull, r2, regCkNull)
__16:
	;
	Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 12)))
	if !(ii < (*ExprList)(unsafe.Pointer(pList)).FnExpr-1 || destIfNull != destIfFalse) {
		goto __17
	}
	if rLhs != r2 {
		op = OP_Eq
	} else {
		op = OP_NotNull
	}
	Xsqlite3VdbeAddOp4(tls, v, op, rLhs, labelOk, r2,
		pColl, -2)

	Xsqlite3VdbeChangeP5(tls, v, uint16(*(*uint8)(unsafe.Pointer(zAff))))
	goto __18
__17:
	if rLhs != r2 {
		op1 = OP_Ne
	} else {
		op1 = OP_IsNull
	}

	Xsqlite3VdbeAddOp4(tls, v, op1, rLhs, destIfFalse, r2,
		pColl, -2)

	Xsqlite3VdbeChangeP5(tls, v, uint16(int32(*(*uint8)(unsafe.Pointer(zAff)))|SQLITE_JUMPIFNULL))
__18:
	;
	goto __14
__14:
	ii++
	goto __13
	goto __15
__15:
	;
	if !(regCkNull != 0) {
		goto __19
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, regCkNull, destIfNull)
	Xsqlite3VdbeGoto(tls, v, destIfFalse)
__19:
	;
	Xsqlite3VdbeResolveLabel(tls, v, labelOk)
	Xsqlite3ReleaseTempReg(tls, pParse, regCkNull)
	goto sqlite3ExprCodeIN_finished
__11:
	;
	if !(destIfNull == destIfFalse) {
		goto __20
	}
	destStep2 = destIfFalse
	goto __21
__20:
	destStep2 = libc.AssignInt32(&destStep6, Xsqlite3VdbeMakeLabel(tls, pParse))
__21:
	;
	i = 0
__22:
	if !(i < nVector) {
		goto __24
	}
	p = Xsqlite3VectorFieldSubexpr(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, i)
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __25
	}
	goto sqlite3ExprCodeIN_oom_error
__25:
	;
	if !(Xsqlite3ExprCanBeNull(tls, p) != 0) {
		goto __26
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, rLhs+i, destStep2)

__26:
	;
	goto __23
__23:
	i++
	goto __22
	goto __24
__24:
	;
	if !(eType == IN_INDEX_ROWID) {
		goto __27
	}

	Xsqlite3VdbeAddOp3(tls, v, OP_SeekRowid, *(*int32)(unsafe.Pointer(bp + 4)), destIfFalse, rLhs)

	addrTruthOp = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
	goto __28
__27:
	Xsqlite3VdbeAddOp4(tls, v, OP_Affinity, rLhs, nVector, 0, zAff, nVector)
	if !(destIfFalse == destIfNull) {
		goto __29
	}

	Xsqlite3VdbeAddOp4Int(tls, v, OP_NotFound, *(*int32)(unsafe.Pointer(bp + 4)), destIfFalse,
		rLhs, nVector)
	goto sqlite3ExprCodeIN_finished
__29:
	;
	addrTruthOp = Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, *(*int32)(unsafe.Pointer(bp + 4)), 0,
		rLhs, nVector)
__28:
	;
	if !(*(*int32)(unsafe.Pointer(bp)) != 0 && nVector == 1) {
		goto __30
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_NotNull, *(*int32)(unsafe.Pointer(bp)), destIfFalse)

__30:
	;
	if !(destIfFalse == destIfNull) {
		goto __31
	}
	Xsqlite3VdbeGoto(tls, v, destIfFalse)
__31:
	;
	if !(destStep6 != 0) {
		goto __32
	}
	Xsqlite3VdbeResolveLabel(tls, v, destStep6)
__32:
	;
	addrTop = Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, *(*int32)(unsafe.Pointer(bp + 4)), destIfFalse)

	if !(nVector > 1) {
		goto __33
	}
	destNotNull = Xsqlite3VdbeMakeLabel(tls, pParse)
	goto __34
__33:
	destNotNull = destIfFalse
__34:
	;
	i = 0
__35:
	if !(i < nVector) {
		goto __37
	}
	r3 = Xsqlite3GetTempReg(tls, pParse)
	p1 = Xsqlite3VectorFieldSubexpr(tls, pLeft, i)
	pColl1 = Xsqlite3ExprCollSeq(tls, pParse, p1)
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, *(*int32)(unsafe.Pointer(bp + 4)), i, r3)
	Xsqlite3VdbeAddOp4(tls, v, OP_Ne, rLhs+i, destNotNull, r3,
		pColl1, -2)

	Xsqlite3ReleaseTempReg(tls, pParse, r3)
	goto __36
__36:
	i++
	goto __35
	goto __37
__37:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, destIfNull)
	if !(nVector > 1) {
		goto __38
	}
	Xsqlite3VdbeResolveLabel(tls, v, destNotNull)
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, *(*int32)(unsafe.Pointer(bp + 4)), addrTop+1)

	Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, destIfFalse)
__38:
	;
	Xsqlite3VdbeJumpHere(tls, v, addrTruthOp)

sqlite3ExprCodeIN_finished:
	if !(rLhs != rLhsOrig) {
		goto __39
	}
	Xsqlite3ReleaseTempReg(tls, pParse, rLhs)
__39:
	;
	Xsqlite3VdbeComment(tls, v, ts+11267, 0)
sqlite3ExprCodeIN_oom_error:
	Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, aiMap)
	Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, zAff)
}

func codeReal(tls *libc.TLS, v uintptr, z uintptr, negateFlag int32, iMem int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if z != uintptr(0) {
		Xsqlite3AtoF(tls, z, bp, Xsqlite3Strlen30(tls, z), uint8(SQLITE_UTF8))

		if negateFlag != 0 {
			*(*float64)(unsafe.Pointer(bp)) = -*(*float64)(unsafe.Pointer(bp))
		}
		Xsqlite3VdbeAddOp4Dup8(tls, v, OP_Real, 0, iMem, 0, bp, -12)
	}
}

func codeInteger(tls *libc.TLS, pParse uintptr, pExpr uintptr, negFlag int32, iMem int32) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_IntValue) != 0 {
		var i int32 = *(*int32)(unsafe.Pointer(pExpr + 8))

		if negFlag != 0 {
			i = -i
		}
		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, i, iMem)
	} else {
		var c int32

		var z uintptr = *(*uintptr)(unsafe.Pointer(pExpr + 8))

		c = Xsqlite3DecOrHexToI64(tls, z, bp+16)
		if c == 3 && !(negFlag != 0) || c == 2 || negFlag != 0 && *(*I64)(unsafe.Pointer(bp + 16)) == int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32) {
			if Xsqlite3_strnicmp(tls, z, ts+11279, 2) == 0 {
				Xsqlite3ErrorMsg(tls, pParse, ts+11282,
					libc.VaList(bp, func() uintptr {
						if negFlag != 0 {
							return ts + 7812
						}
						return ts + 1636
					}(), pExpr))
			} else {
				codeReal(tls, v, z, negFlag, iMem)
			}
		} else {
			if negFlag != 0 {
				if c == 3 {
					*(*I64)(unsafe.Pointer(bp + 16)) = int64(-1) - (int64(0xffffffff) | int64(0x7fffffff)<<32)
				} else {
					*(*I64)(unsafe.Pointer(bp + 16)) = -*(*I64)(unsafe.Pointer(bp + 16))
				}
			}
			Xsqlite3VdbeAddOp4Dup8(tls, v, OP_Int64, 0, iMem, 0, bp+16, -13)
		}
	}
}

func Xsqlite3ExprCodeLoadIndexColumn(tls *libc.TLS, pParse uintptr, pIdx uintptr, iTabCur int32, iIdxCol int32, regOut int32) {
	var iTabCol I16 = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iIdxCol)*2))
	if int32(iTabCol) == -2 {
		(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = iTabCur + 1
		Xsqlite3ExprCodeCopy(tls, pParse, (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr+8+uintptr(iIdxCol)*32)).FpExpr, regOut)
		(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = 0
	} else {
		Xsqlite3ExprCodeGetColumnOfTable(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, (*Index)(unsafe.Pointer(pIdx)).FpTable, iTabCur,
			int32(iTabCol), regOut)
	}
}

func Xsqlite3ExprCodeGeneratedColumn(tls *libc.TLS, pParse uintptr, pTab uintptr, pCol uintptr, regOut int32) {
	var iAddr int32
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var nErr int32 = (*Parse)(unsafe.Pointer(pParse)).FnErr

	if (*Parse)(unsafe.Pointer(pParse)).FiSelfTab > 0 {
		iAddr = Xsqlite3VdbeAddOp3(tls, v, OP_IfNullRow, (*Parse)(unsafe.Pointer(pParse)).FiSelfTab-1, 0, regOut)
	} else {
		iAddr = 0
	}
	Xsqlite3ExprCodeCopy(tls, pParse, Xsqlite3ColumnExpr(tls, pTab, pCol), regOut)
	if int32((*Column)(unsafe.Pointer(pCol)).Faffinity) >= SQLITE_AFF_TEXT {
		Xsqlite3VdbeAddOp4(tls, v, OP_Affinity, regOut, 1, 0, pCol+10, 1)
	}
	if iAddr != 0 {
		Xsqlite3VdbeJumpHere(tls, v, iAddr)
	}
	if (*Parse)(unsafe.Pointer(pParse)).FnErr > nErr {
		(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FerrByteOffset = -1
	}
}

func Xsqlite3ExprCodeGetColumnOfTable(tls *libc.TLS, v uintptr, pTab uintptr, iTabCur int32, iCol int32, regOut int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pCol uintptr

	if iCol < 0 || iCol == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) {
		Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iTabCur, regOut)
		Xsqlite3VdbeComment(tls, v, ts+11309, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
	} else {
		var op int32
		var x int32
		if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
			op = OP_VColumn
			x = iCol
		} else if int32((*Column)(unsafe.Pointer(libc.AssignUintptr(&pCol, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24))).FcolFlags)&COLFLAG_VIRTUAL != 0 {
			var pParse uintptr = Xsqlite3VdbeParser(tls, v)
			if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_BUSY != 0 {
				Xsqlite3ErrorMsg(tls, pParse, ts+11318,
					libc.VaList(bp+8, (*Column)(unsafe.Pointer(pCol)).FzCnName))
			} else {
				var savedSelfTab int32 = (*Parse)(unsafe.Pointer(pParse)).FiSelfTab
				*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_BUSY)
				(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = iTabCur + 1
				Xsqlite3ExprCodeGeneratedColumn(tls, pParse, pTab, pCol, regOut)
				(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = savedSelfTab
				*(*U16)(unsafe.Pointer(pCol + 16)) &= libc.Uint16FromInt32(libc.CplInt32(COLFLAG_BUSY))
			}
			return
		} else if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
			x = int32(Xsqlite3TableColumnToIndex(tls, Xsqlite3PrimaryKeyIndex(tls, pTab), int16(iCol)))
			op = OP_Column
		} else {
			x = int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(iCol)))

			op = OP_Column
		}
		Xsqlite3VdbeAddOp3(tls, v, op, iTabCur, x, regOut)
		Xsqlite3ColumnDefault(tls, v, pTab, iCol, regOut)
	}
}

func Xsqlite3ExprCodeGetColumn(tls *libc.TLS, pParse uintptr, pTab uintptr, iColumn int32, iTable int32, iReg int32, p5 U8) int32 {
	Xsqlite3ExprCodeGetColumnOfTable(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, pTab, iTable, iColumn, iReg)
	if p5 != 0 {
		var pOp uintptr = Xsqlite3VdbeGetLastOp(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe)
		if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Column {
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp5 = U16(p5)
		}
	}
	return iReg
}

func Xsqlite3ExprCodeMove(tls *libc.TLS, pParse uintptr, iFrom int32, iTo int32, nReg int32) {
	Xsqlite3VdbeAddOp3(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, OP_Move, iFrom, iTo, nReg)
}

func exprToRegister(tls *libc.TLS, pExpr uintptr, iReg int32) {
	var p uintptr = Xsqlite3ExprSkipCollateAndLikely(tls, pExpr)
	if p == uintptr(0) {
		return
	}
	(*Expr)(unsafe.Pointer(p)).Fop2 = (*Expr)(unsafe.Pointer(p)).Fop
	(*Expr)(unsafe.Pointer(p)).Fop = U8(TK_REGISTER)
	(*Expr)(unsafe.Pointer(p)).FiTable = iReg
	*(*U32)(unsafe.Pointer(p + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_Skip))
}

func exprCodeVector(tls *libc.TLS, pParse uintptr, p uintptr, piFreeable uintptr) int32 {
	var iResult int32
	var nResult int32 = Xsqlite3ExprVectorSize(tls, p)
	if nResult == 1 {
		iResult = Xsqlite3ExprCodeTemp(tls, pParse, p, piFreeable)
	} else {
		*(*int32)(unsafe.Pointer(piFreeable)) = 0
		if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_SELECT {
			iResult = Xsqlite3CodeSubselect(tls, pParse, p)
		} else {
			var i int32
			iResult = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
			*(*int32)(unsafe.Pointer(pParse + 56)) += nResult

			for i = 0; i < nResult; i++ {
				Xsqlite3ExprCodeFactorable(tls, pParse, (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32))+8+uintptr(i)*32)).FpExpr, i+iResult)
			}
		}
	}
	return iResult
}

func setDoNotMergeFlagOnCopy(tls *libc.TLS, v uintptr) {
	if int32((*VdbeOp)(unsafe.Pointer(Xsqlite3VdbeGetLastOp(tls, v))).Fopcode) == OP_Copy {
		Xsqlite3VdbeChangeP5(tls, v, uint16(1))
	}
}

func exprCodeInlineFunction(tls *libc.TLS, pParse uintptr, pFarg uintptr, iFuncId int32, target int32) int32 {
	bp := tls.Alloc(120)
	defer tls.Free(120)

	var nFarg int32
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	nFarg = (*ExprList)(unsafe.Pointer(pFarg)).FnExpr

	switch iFuncId {
	case INLINEFUNC_coalesce:
		{
			var endCoalesce int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
			var i int32

			Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pFarg+8)).FpExpr, target)
			for i = 1; i < nFarg; i++ {
				Xsqlite3VdbeAddOp2(tls, v, OP_NotNull, target, endCoalesce)

				Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pFarg+8+uintptr(i)*32)).FpExpr, target)
			}
			setDoNotMergeFlagOnCopy(tls, v)
			Xsqlite3VdbeResolveLabel(tls, v, endCoalesce)
			break

		}
	case INLINEFUNC_iif:
		{
			libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Expr{})))
			(*Expr)(unsafe.Pointer(bp)).Fop = U8(TK_CASE)
			*(*uintptr)(unsafe.Pointer(bp + 32)) = pFarg
			return Xsqlite3ExprCodeTarget(tls, pParse, bp, target)

		}
	case INLINEFUNC_sqlite_offset:
		{
			var pArg uintptr = (*ExprList_item)(unsafe.Pointer(pFarg + 8)).FpExpr
			if int32((*Expr)(unsafe.Pointer(pArg)).Fop) == TK_COLUMN && (*Expr)(unsafe.Pointer(pArg)).FiTable >= 0 {
				Xsqlite3VdbeAddOp3(tls, v, OP_Offset, (*Expr)(unsafe.Pointer(pArg)).FiTable, int32((*Expr)(unsafe.Pointer(pArg)).FiColumn), target)
			} else {
				Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, target)
			}
			break

		}
	default:
		{
			target = Xsqlite3ExprCodeTarget(tls, pParse, (*ExprList_item)(unsafe.Pointer(pFarg+8)).FpExpr, target)
			break

		}

	case INLINEFUNC_expr_compare:
		{
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer,
				Xsqlite3ExprCompare(tls, uintptr(0), (*ExprList_item)(unsafe.Pointer(pFarg+8)).FpExpr, (*ExprList_item)(unsafe.Pointer(pFarg+8+1*32)).FpExpr, -1),
				target)
			break

		}

	case INLINEFUNC_expr_implies_expr:
		{
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer,
				Xsqlite3ExprImpliesExpr(tls, pParse, (*ExprList_item)(unsafe.Pointer(pFarg+8)).FpExpr, (*ExprList_item)(unsafe.Pointer(pFarg+8+1*32)).FpExpr, -1),
				target)
			break

		}

	case INLINEFUNC_implies_nonnull_row:
		{
			var pA1 uintptr

			pA1 = (*ExprList_item)(unsafe.Pointer(pFarg + 8 + 1*32)).FpExpr
			if int32((*Expr)(unsafe.Pointer(pA1)).Fop) == TK_COLUMN {
				Xsqlite3VdbeAddOp2(tls, v, OP_Integer,
					Xsqlite3ExprImpliesNonNullRow(tls, (*ExprList_item)(unsafe.Pointer(pFarg+8)).FpExpr, (*Expr)(unsafe.Pointer(pA1)).FiTable),
					target)
			} else {
				Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, target)
			}
			break

		}

	case INLINEFUNC_affinity:
		{
			*(*[6]uintptr)(unsafe.Pointer(bp + 72)) = [6]uintptr{ts + 11348, ts + 11353, ts + 11358, ts + 9116,
				ts + 9111, ts + 11366}
			var aff uint8

			aff = Xsqlite3ExprAffinity(tls, (*ExprList_item)(unsafe.Pointer(pFarg+8)).FpExpr)

			Xsqlite3VdbeLoadString(tls, v, target,
				func() uintptr {
					if int32(aff) <= SQLITE_AFF_NONE {
						return ts + 11374
					}
					return *(*uintptr)(unsafe.Pointer(bp + 72 + uintptr(int32(aff)-SQLITE_AFF_BLOB)*8))
				}())
			break

		}
	}
	return target
}

func sqlite3IndexedExprLookup(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var p uintptr
	var v uintptr
	for p = (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr; p != 0; p = (*IndexedExpr)(unsafe.Pointer(p)).FpIENext {
		var exprAff U8
		var iDataCur int32 = (*IndexedExpr)(unsafe.Pointer(p)).FiDataCur
		if iDataCur < 0 {
			continue
		}
		if (*Parse)(unsafe.Pointer(pParse)).FiSelfTab != 0 {
			if (*IndexedExpr)(unsafe.Pointer(p)).FiDataCur != (*Parse)(unsafe.Pointer(pParse)).FiSelfTab-1 {
				continue
			}
			iDataCur = -1
		}
		if Xsqlite3ExprCompare(tls, uintptr(0), pExpr, (*IndexedExpr)(unsafe.Pointer(p)).FpExpr, iDataCur) != 0 {
			continue
		}

		exprAff = Xsqlite3ExprAffinity(tls, pExpr)
		if int32(exprAff) <= SQLITE_AFF_BLOB && int32((*IndexedExpr)(unsafe.Pointer(p)).Faff) != SQLITE_AFF_BLOB ||
			int32(exprAff) == SQLITE_AFF_TEXT && int32((*IndexedExpr)(unsafe.Pointer(p)).Faff) != SQLITE_AFF_TEXT ||
			int32(exprAff) >= SQLITE_AFF_NUMERIC && int32((*IndexedExpr)(unsafe.Pointer(p)).Faff) != SQLITE_AFF_NUMERIC {
			continue
		}

		v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

		if (*IndexedExpr)(unsafe.Pointer(p)).FbMaybeNullRow != 0 {
			var addr int32 = Xsqlite3VdbeCurrentAddr(tls, v)
			Xsqlite3VdbeAddOp3(tls, v, OP_IfNullRow, (*IndexedExpr)(unsafe.Pointer(p)).FiIdxCur, addr+3, target)

			Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*IndexedExpr)(unsafe.Pointer(p)).FiIdxCur, (*IndexedExpr)(unsafe.Pointer(p)).FiIdxCol, target)
			Xsqlite3VdbeComment(tls, v, ts+11379, libc.VaList(bp, (*IndexedExpr)(unsafe.Pointer(p)).FzIdxName, (*IndexedExpr)(unsafe.Pointer(p)).FiIdxCol))
			Xsqlite3VdbeGoto(tls, v, 0)
			p = (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr
			(*Parse)(unsafe.Pointer(pParse)).FpIdxEpr = uintptr(0)
			Xsqlite3ExprCode(tls, pParse, pExpr, target)
			(*Parse)(unsafe.Pointer(pParse)).FpIdxEpr = p
			Xsqlite3VdbeJumpHere(tls, v, addr+2)
		} else {
			Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*IndexedExpr)(unsafe.Pointer(p)).FiIdxCur, (*IndexedExpr)(unsafe.Pointer(p)).FiIdxCol, target)
			Xsqlite3VdbeComment(tls, v, ts+11379, libc.VaList(bp+16, (*IndexedExpr)(unsafe.Pointer(p)).FzIdxName, (*IndexedExpr)(unsafe.Pointer(p)).FiIdxCol))
		}
		return target
	}
	return -1
}

func Xsqlite3ExprCodeTarget(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) int32 {
	bp := tls.Alloc(240)
	defer tls.Free(240)

	var v uintptr
	var op int32
	var inReg int32

	var r1 int32
	var r2 int32

	var p5 int32
	var pTab uintptr
	var pAggInfo uintptr
	var pCol uintptr

	var aff int32

	var pCol1 uintptr
	var pTab1 uintptr
	var iSrc int32
	var iCol int32
	var iTab int32
	var iReg int32
	var n int32
	var z uintptr
	var zBlob uintptr
	var z1 uintptr
	var pLeft uintptr
	var pLeft1 uintptr
	var isTrue int32
	var bNormal int32
	var addr int32
	var pInfo uintptr
	var exprOp U8
	var pFarg uintptr
	var nFarg int32
	var pDef uintptr
	var zId uintptr
	var constMask U32
	var i int32
	var db uintptr
	var enc U8
	var pColl uintptr
	var nCol int32
	var n1 int32
	var pLeft2 uintptr
	var destIfFalse int32
	var destIfNull int32

	var pTab2 uintptr
	var iCol1 int32
	var p1 int32
	var addrINR int32
	var okConstFactor U8
	var pAggInfo1 uintptr
	var endLabel int32
	var nextCase int32
	var nExpr int32
	var i1 int32
	var pEList uintptr
	var aListelem uintptr

	var pX uintptr
	var pTest uintptr
	var pDel uintptr
	var db1 uintptr
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	inReg = target
	*(*int32)(unsafe.Pointer(bp + 88)) = 0
	*(*int32)(unsafe.Pointer(bp + 92)) = 0
	p5 = 0

expr_code_doover:
	if !(pExpr == uintptr(0)) {
		goto __1
	}
	op = TK_NULL
	goto __2
__1:
	if !((*Parse)(unsafe.Pointer(pParse)).FpIdxEpr != uintptr(0) &&
		!((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Leaf) != U32(0)) &&
		libc.AssignInt32(&r1, sqlite3IndexedExprLookup(tls, pParse, pExpr, target)) >= 0) {
		goto __3
	}
	return r1
	goto __4
__3:
	;
	op = int32((*Expr)(unsafe.Pointer(pExpr)).Fop)
__4:
	;
__2:
	;
	switch op {
	case TK_AGG_COLUMN:
		goto __6
	case TK_COLUMN:
		goto __7
	case TK_INTEGER:
		goto __8
	case TK_TRUEFALSE:
		goto __9
	case TK_FLOAT:
		goto __10
	case TK_STRING:
		goto __11
	default:
		goto __12
	case TK_BLOB:
		goto __13
	case TK_VARIABLE:
		goto __14
	case TK_REGISTER:
		goto __15
	case TK_CAST:
		goto __16
	case TK_IS:
		goto __17
	case TK_ISNOT:
		goto __18

	case TK_LT:
		goto __19
	case TK_LE:
		goto __20
	case TK_GT:
		goto __21
	case TK_GE:
		goto __22
	case TK_NE:
		goto __23
	case TK_EQ:
		goto __24
	case TK_AND:
		goto __25
	case TK_OR:
		goto __26
	case TK_PLUS:
		goto __27
	case TK_STAR:
		goto __28
	case TK_MINUS:
		goto __29
	case TK_REM:
		goto __30
	case TK_BITAND:
		goto __31
	case TK_BITOR:
		goto __32
	case TK_SLASH:
		goto __33
	case TK_LSHIFT:
		goto __34
	case TK_RSHIFT:
		goto __35
	case TK_CONCAT:
		goto __36
	case TK_UMINUS:
		goto __37
	case TK_BITNOT:
		goto __38
	case TK_NOT:
		goto __39
	case TK_TRUTH:
		goto __40
	case TK_ISNULL:
		goto __41
	case TK_NOTNULL:
		goto __42
	case TK_AGG_FUNCTION:
		goto __43
	case TK_FUNCTION:
		goto __44
	case TK_EXISTS:
		goto __45
	case TK_SELECT:
		goto __46
	case TK_SELECT_COLUMN:
		goto __47
	case TK_IN:
		goto __48

	case TK_BETWEEN:
		goto __49
	case TK_COLLATE:
		goto __50
	case TK_SPAN:
		goto __51
	case TK_UPLUS:
		goto __52

	case TK_TRIGGER:
		goto __53

	case TK_VECTOR:
		goto __54

	case TK_IF_NULL_ROW:
		goto __55

	case TK_CASE:
		goto __56
	case TK_RAISE:
		goto __57
	}
	goto __5
__6:
	pAggInfo = (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo

	pCol = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((*Expr)(unsafe.Pointer(pExpr)).FiAgg)*24
	if !!(int32((*AggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode) != 0) {
		goto __58
	}
	return func() int32 {
		return (*AggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg + int32((*Expr)(unsafe.Pointer(pExpr)).FiAgg)
	}()
	goto __59
__58:
	if !((*AggInfo)(unsafe.Pointer(pAggInfo)).FuseSortingIdx != 0) {
		goto __60
	}
	pTab = (*AggInfo_col)(unsafe.Pointer(pCol)).FpTab
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*AggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdxPTab,
		int32((*AggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn), target)
	if !(pTab == uintptr(0)) {
		goto __62
	}

	goto __63
__62:
	if !(int32((*AggInfo_col)(unsafe.Pointer(pCol)).FiColumn) < 0) {
		goto __64
	}
	Xsqlite3VdbeComment(tls, v, ts+11309, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto __65
__64:
	Xsqlite3VdbeComment(tls, v, ts+11397, libc.VaList(bp+8, (*Table)(unsafe.Pointer(pTab)).FzName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr((*AggInfo_col)(unsafe.Pointer(pCol)).FiColumn)*24)).FzCnName))
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr((*AggInfo_col)(unsafe.Pointer(pCol)).FiColumn)*24)).Faffinity) == SQLITE_AFF_REAL) {
		goto __66
	}
	Xsqlite3VdbeAddOp1(tls, v, OP_RealAffinity, target)
__66:
	;
__65:
	;
__63:
	;
	return target
	goto __61
__60:
	if !(*(*uintptr)(unsafe.Pointer(pExpr + 64)) == uintptr(0)) {
		goto __67
	}

	Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*Expr)(unsafe.Pointer(pExpr)).FiTable, int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn), target)
	return target
__67:
	;
__61:
	;
__59:
	;
__7:
	iTab = (*Expr)(unsafe.Pointer(pExpr)).FiTable
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_FixedCol) != U32(0)) {
		goto __68
	}
	iReg = Xsqlite3ExprCodeTarget(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, target)

	aff = int32(Xsqlite3TableColumnAffinity(tls, *(*uintptr)(unsafe.Pointer(pExpr + 64)), int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)))
	if !(aff > SQLITE_AFF_BLOB) {
		goto __69
	}

	Xsqlite3VdbeAddOp4(tls, v, OP_Affinity, iReg, 1, 0,
		uintptr(unsafe.Pointer(&zAff))+uintptr((aff-'B')*2), -1)
__69:
	;
	return iReg
__68:
	;
	if !(iTab < 0) {
		goto __70
	}
	if !((*Parse)(unsafe.Pointer(pParse)).FiSelfTab < 0) {
		goto __71
	}
	iCol = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)

	pTab1 = *(*uintptr)(unsafe.Pointer(pExpr + 64))

	if !(iCol < 0) {
		goto __73
	}
	return -1 - (*Parse)(unsafe.Pointer(pParse)).FiSelfTab
__73:
	;
	pCol1 = (*Table)(unsafe.Pointer(pTab1)).FaCol + uintptr(iCol)*24

	iSrc = int32(Xsqlite3TableColumnToStorage(tls, pTab1, int16(iCol))) - (*Parse)(unsafe.Pointer(pParse)).FiSelfTab
	if !(int32((*Column)(unsafe.Pointer(pCol1)).FcolFlags)&COLFLAG_GENERATED != 0) {
		goto __74
	}
	if !(int32((*Column)(unsafe.Pointer(pCol1)).FcolFlags)&COLFLAG_BUSY != 0) {
		goto __76
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+11318,
		libc.VaList(bp+24, (*Column)(unsafe.Pointer(pCol1)).FzCnName))
	return 0
__76:
	;
	*(*U16)(unsafe.Pointer(pCol1 + 16)) |= U16(COLFLAG_BUSY)
	if !(int32((*Column)(unsafe.Pointer(pCol1)).FcolFlags)&COLFLAG_NOTAVAIL != 0) {
		goto __77
	}
	Xsqlite3ExprCodeGeneratedColumn(tls, pParse, pTab1, pCol1, iSrc)
__77:
	;
	*(*U16)(unsafe.Pointer(pCol1 + 16)) &= libc.Uint16FromInt32(libc.CplInt32(COLFLAG_BUSY | COLFLAG_NOTAVAIL))
	return iSrc
	goto __75
__74:
	if !(int32((*Column)(unsafe.Pointer(pCol1)).Faffinity) == SQLITE_AFF_REAL) {
		goto __78
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_SCopy, iSrc, target)
	Xsqlite3VdbeAddOp1(tls, v, OP_RealAffinity, target)
	return target
	goto __79
__78:
	return iSrc
__79:
	;
__75:
	;
	goto __72
__71:
	iTab = (*Parse)(unsafe.Pointer(pParse)).FiSelfTab - 1
__72:
	;
__70:
	;
	iReg = Xsqlite3ExprCodeGetColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(pExpr + 64)),
		int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn), iTab, target,
		(*Expr)(unsafe.Pointer(pExpr)).Fop2)
	return iReg

__8:
	codeInteger(tls, pParse, pExpr, 0, target)
	return target

__9:
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, Xsqlite3ExprTruthValue(tls, pExpr), target)
	return target

__10:
	;
	codeReal(tls, v, *(*uintptr)(unsafe.Pointer(pExpr + 8)), 0, target)
	return target

__11:
	;
	Xsqlite3VdbeLoadString(tls, v, target, *(*uintptr)(unsafe.Pointer(pExpr + 8)))
	return target

__12:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, target)
	return target

__13:
	;
	z = *(*uintptr)(unsafe.Pointer(pExpr + 8)) + 2
	n = Xsqlite3Strlen30(tls, z) - 1

	zBlob = Xsqlite3HexToBlob(tls, Xsqlite3VdbeDb(tls, v), z, n)
	Xsqlite3VdbeAddOp4(tls, v, OP_Blob, n/2, target, 0, zBlob, -6)
	return target

__14:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Variable, int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn), target)
	if !(int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 8)) + 1))) != 0) {
		goto __80
	}
	z1 = Xsqlite3VListNumToName(tls, (*Parse)(unsafe.Pointer(pParse)).FpVList, int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn))

	*(*VList)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).FpVList)) = 0
	Xsqlite3VdbeAppendP4(tls, v, z1, -1)
__80:
	;
	return target

__15:
	return (*Expr)(unsafe.Pointer(pExpr)).FiTable

__16:
	inReg = Xsqlite3ExprCodeTarget(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, target)
	if !(inReg != target) {
		goto __81
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_SCopy, inReg, target)
	inReg = target
__81:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Cast, target,
		int32(Xsqlite3AffinityType(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), uintptr(0))))
	return inReg

__17:
__18:
	if op == TK_IS {
		op = TK_EQ
	} else {
		op = TK_NE
	}
	p5 = SQLITE_NULLEQ

__19:
__20:
__21:
__22:
__23:
__24:
	pLeft = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	if !(Xsqlite3ExprIsVector(tls, pLeft) != 0) {
		goto __82
	}
	codeVectorCompare(tls, pParse, pExpr, target, uint8(op), uint8(p5))
	goto __83
__82:
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, pLeft, bp+88)
	r2 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, bp+92)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, inReg)
	codeCompare(tls, pParse, pLeft, (*Expr)(unsafe.Pointer(pExpr)).FpRight, op, r1, r2,
		Xsqlite3VdbeCurrentAddr(tls, v)+2, p5,
		libc.Bool32((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Commuted) != U32(0)))

	if !(p5 == SQLITE_NULLEQ) {
		goto __84
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, inReg)
	goto __85
__84:
	Xsqlite3VdbeAddOp3(tls, v, OP_ZeroOrNull, r1, inReg, r2)
__85:
	;
__83:
	;
	goto __5

__25:
__26:
__27:
__28:
__29:
__30:
__31:
__32:
__33:
__34:
__35:
__36:
	;
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp+88)
	r2 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, bp+92)
	Xsqlite3VdbeAddOp3(tls, v, op, r2, r1, target)

	goto __5

__37:
	pLeft1 = (*Expr)(unsafe.Pointer(pExpr)).FpLeft

	if !(int32((*Expr)(unsafe.Pointer(pLeft1)).Fop) == TK_INTEGER) {
		goto __86
	}
	codeInteger(tls, pParse, pLeft1, 1, target)
	return target
	goto __87
__86:
	if !(int32((*Expr)(unsafe.Pointer(pLeft1)).Fop) == TK_FLOAT) {
		goto __88
	}

	codeReal(tls, v, *(*uintptr)(unsafe.Pointer(pLeft1 + 8)), 1, target)
	return target
	goto __89
__88:
	(*Expr)(unsafe.Pointer(bp + 96)).Fop = U8(TK_INTEGER)
	(*Expr)(unsafe.Pointer(bp + 96)).Fflags = U32(EP_IntValue | EP_TokenOnly)
	*(*int32)(unsafe.Pointer(bp + 96 + 8)) = 0

	r1 = Xsqlite3ExprCodeTemp(tls, pParse, bp+96, bp+88)
	r2 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp+92)
	Xsqlite3VdbeAddOp3(tls, v, OP_Subtract, r2, r1, target)

__89:
	;
__87:
	;
	goto __5

__38:
__39:
	;
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp+88)

	Xsqlite3VdbeAddOp2(tls, v, op, r1, inReg)
	goto __5

__40:
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp+88)

	isTrue = Xsqlite3ExprTruthValue(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
	bNormal = libc.Bool32(int32((*Expr)(unsafe.Pointer(pExpr)).Fop2) == TK_IS)

	Xsqlite3VdbeAddOp4Int(tls, v, OP_IsTrue, r1, inReg, libc.BoolInt32(!(isTrue != 0)), isTrue^bNormal)
	goto __5

__41:
__42:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, target)
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp+88)

	addr = Xsqlite3VdbeAddOp1(tls, v, op, r1)

	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, target)
	Xsqlite3VdbeJumpHere(tls, v, addr)
	goto __5

__43:
	pInfo = (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo
	if !(pInfo == uintptr(0) ||
		int32((*Expr)(unsafe.Pointer(pExpr)).FiAgg) < 0 ||
		int32((*Expr)(unsafe.Pointer(pExpr)).FiAgg) >= (*AggInfo)(unsafe.Pointer(pInfo)).FnFunc) {
		goto __90
	}

	Xsqlite3ErrorMsg(tls, pParse, ts+11403, libc.VaList(bp+32, pExpr))
	goto __91
__90:
	return func() int32 {
		return (*AggInfo)(unsafe.Pointer(pInfo)).FiFirstReg + (*AggInfo)(unsafe.Pointer(pInfo)).FnColumn + int32((*Expr)(unsafe.Pointer(pExpr)).FiAgg)
	}()
__91:
	;
	goto __5

__44:
	constMask = U32(0)
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	enc = (*Sqlite3)(unsafe.Pointer(db)).Fenc
	pColl = uintptr(0)

	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0)) {
		goto __92
	}
	return (*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FregResult
__92:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FokConstFactor != 0 && Xsqlite3ExprIsConstantNotJoin(tls, pExpr) != 0) {
		goto __93
	}

	return Xsqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, -1)
__93:
	;
	pFarg = *(*uintptr)(unsafe.Pointer(pExpr + 32))
	if pFarg != 0 {
		nFarg = (*ExprList)(unsafe.Pointer(pFarg)).FnExpr
	} else {
		nFarg = 0
	}

	zId = *(*uintptr)(unsafe.Pointer(pExpr + 8))
	pDef = Xsqlite3FindFunction(tls, db, zId, nFarg, enc, uint8(0))
	if !(pDef == uintptr(0) || (*FuncDef)(unsafe.Pointer(pDef)).FxFinalize != uintptr(0)) {
		goto __94
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+11430, libc.VaList(bp+40, pExpr))
	goto __5
__94:
	;
	if !((*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_INLINE) != 0) {
		goto __95
	}

	return exprCodeInlineFunction(tls, pParse, pFarg,
		int32((*FuncDef)(unsafe.Pointer(pDef)).FpUserData), target)
	goto __96
__95:
	if !((*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE) != 0) {
		goto __97
	}
	Xsqlite3ExprFunctionUsable(tls, pParse, pExpr, pDef)
__97:
	;
__96:
	;
	i = 0
__98:
	if !(i < nFarg) {
		goto __100
	}
	if !(i < 32 && Xsqlite3ExprIsConstant(tls, (*ExprList_item)(unsafe.Pointer(pFarg+8+uintptr(i)*32)).FpExpr) != 0) {
		goto __101
	}

	constMask = constMask | uint32(1)<<i
__101:
	;
	if !((*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_NEEDCOLL) != U32(0) && !(pColl != 0)) {
		goto __102
	}
	pColl = Xsqlite3ExprCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(pFarg+8+uintptr(i)*32)).FpExpr)
__102:
	;
	goto __99
__99:
	i++
	goto __98
	goto __100
__100:
	;
	if !(pFarg != 0) {
		goto __103
	}
	if !(constMask != 0) {
		goto __105
	}
	r1 = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += nFarg
	goto __106
__105:
	r1 = Xsqlite3GetTempRange(tls, pParse, nFarg)
__106:
	;
	if !((*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF) != U32(0)) {
		goto __107
	}

	exprOp = (*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pFarg + 8)).FpExpr)).Fop
	if !(int32(exprOp) == TK_COLUMN || int32(exprOp) == TK_AGG_COLUMN) {
		goto __108
	}

	(*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pFarg + 8)).FpExpr)).Fop2 = U8((*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags & U32(OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))
__108:
	;
__107:
	;
	Xsqlite3ExprCodeExprList(tls, pParse, pFarg, r1, 0,
		uint8(SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR))
	goto __104
__103:
	r1 = 0
__104:
	;
	if !(nFarg >= 2 && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_InfixFunc) != U32(0)) {
		goto __109
	}
	pDef = Xsqlite3VtabOverloadFunction(tls, db, pDef, nFarg, (*ExprList_item)(unsafe.Pointer(pFarg+8+1*32)).FpExpr)
	goto __110
__109:
	if !(nFarg > 0) {
		goto __111
	}
	pDef = Xsqlite3VtabOverloadFunction(tls, db, pDef, nFarg, (*ExprList_item)(unsafe.Pointer(pFarg+8)).FpExpr)
__111:
	;
__110:
	;
	if !((*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_NEEDCOLL) != 0) {
		goto __112
	}
	if !!(pColl != 0) {
		goto __113
	}
	pColl = (*Sqlite3)(unsafe.Pointer(db)).FpDfltColl
__113:
	;
	Xsqlite3VdbeAddOp4(tls, v, OP_CollSeq, 0, 0, 0, pColl, -2)
__112:
	;
	Xsqlite3VdbeAddFunctionCall(tls, pParse, int32(constMask), r1, target, nFarg,
		pDef, int32((*Expr)(unsafe.Pointer(pExpr)).Fop2))
	if !(nFarg != 0) {
		goto __114
	}
	if !(constMask == U32(0)) {
		goto __115
	}
	Xsqlite3ReleaseTempRange(tls, pParse, r1, nFarg)
	goto __116
__115:
	;
__116:
	;
__114:
	;
	return target

__45:
__46:
	;
	if !((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
		goto __117
	}
	return 0
	goto __118
__117:
	if !(op == TK_SELECT &&
		(*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) &&
		libc.AssignInt32(&nCol, (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpEList)).FnExpr) != 1) {
		goto __119
	}
	Xsqlite3SubselectError(tls, pParse, nCol, 1)
	goto __120
__119:
	return Xsqlite3CodeSubselect(tls, pParse, pExpr)
__120:
	;
__118:
	;
	goto __5

__47:
	pLeft2 = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	if !((*Expr)(unsafe.Pointer(pLeft2)).FiTable == 0 || int32((*Parse)(unsafe.Pointer(pParse)).FwithinRJSubrtn) > int32((*Expr)(unsafe.Pointer(pLeft2)).Fop2)) {
		goto __121
	}
	(*Expr)(unsafe.Pointer(pLeft2)).FiTable = Xsqlite3CodeSubselect(tls, pParse, pLeft2)
	(*Expr)(unsafe.Pointer(pLeft2)).Fop2 = (*Parse)(unsafe.Pointer(pParse)).FwithinRJSubrtn
__121:
	;
	n1 = Xsqlite3ExprVectorSize(tls, pLeft2)
	if !((*Expr)(unsafe.Pointer(pExpr)).FiTable != n1) {
		goto __122
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+10856,
		libc.VaList(bp+48, (*Expr)(unsafe.Pointer(pExpr)).FiTable, n1))
__122:
	;
	return (*Expr)(unsafe.Pointer(pLeft2)).FiTable + int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)

__48:
	destIfFalse = Xsqlite3VdbeMakeLabel(tls, pParse)
	destIfNull = Xsqlite3VdbeMakeLabel(tls, pParse)
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, target)
	sqlite3ExprCodeIN(tls, pParse, pExpr, destIfFalse, destIfNull)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, target)
	Xsqlite3VdbeResolveLabel(tls, v, destIfFalse)
	Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, target, 0)
	Xsqlite3VdbeResolveLabel(tls, v, destIfNull)
	return target

__49:
	exprCodeBetween(tls, pParse, pExpr, target, uintptr(0), 0)
	return target

__50:
	if !!((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Collate) != U32(0)) {
		goto __123
	}

	inReg = Xsqlite3ExprCodeTarget(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, target)
	if !(inReg != target) {
		goto __125
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_SCopy, inReg, target)
	inReg = target
__125:
	;
	Xsqlite3VdbeAddOp1(tls, v, OP_ClrSubtype, inReg)
	return inReg
	goto __124
__123:
	pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	goto expr_code_doover
__124:
	;
__51:
__52:
	pExpr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
	goto expr_code_doover

__53:
	;
	pTab2 = *(*uintptr)(unsafe.Pointer(pExpr + 64))
	iCol1 = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)
	p1 = (*Expr)(unsafe.Pointer(pExpr)).FiTable*(int32((*Table)(unsafe.Pointer(pTab2)).FnCol)+1) + 1 +
		int32(Xsqlite3TableColumnToStorage(tls, pTab2, int16(iCol1)))

	Xsqlite3VdbeAddOp2(tls, v, OP_Param, p1, target)
	Xsqlite3VdbeComment(tls, v, ts+11454, libc.VaList(bp+64, target, func() uintptr {
		if (*Expr)(unsafe.Pointer(pExpr)).FiTable != 0 {
			return ts + 9663
		}
		return ts + 9667
	}(), func() uintptr {
		if int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) < 0 {
			return ts + 11466
		}
		return (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FaCol + uintptr(iCol1)*24)).FzCnName
	}()))

	if !(iCol1 >= 0 && int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab2)).FaCol+uintptr(iCol1)*24)).Faffinity) == SQLITE_AFF_REAL) {
		goto __126
	}
	Xsqlite3VdbeAddOp1(tls, v, OP_RealAffinity, target)
__126:
	;
	goto __5

__54:
	Xsqlite3ErrorMsg(tls, pParse, ts+9748, 0)
	goto __5

__55:
	okConstFactor = (*Parse)(unsafe.Pointer(pParse)).FokConstFactor
	pAggInfo1 = (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo
	if !(pAggInfo1 != 0) {
		goto __127
	}

	if !!(int32((*AggInfo)(unsafe.Pointer(pAggInfo1)).FdirectMode) != 0) {
		goto __128
	}
	inReg = func() int32 {
		return (*AggInfo)(unsafe.Pointer(pAggInfo1)).FiFirstReg + int32((*Expr)(unsafe.Pointer(pExpr)).FiAgg)
	}()
	goto __5
__128:
	;
	if !((*AggInfo)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpAggInfo)).FuseSortingIdx != 0) {
		goto __129
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*AggInfo)(unsafe.Pointer(pAggInfo1)).FsortingIdxPTab,
		int32((*AggInfo_col)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo1)).FaCol+uintptr((*Expr)(unsafe.Pointer(pExpr)).FiAgg)*24)).FiSorterColumn),
		target)
	inReg = target
	goto __5
__129:
	;
__127:
	;
	addrINR = Xsqlite3VdbeAddOp3(tls, v, OP_IfNullRow, (*Expr)(unsafe.Pointer(pExpr)).FiTable, 0, target)

	(*Parse)(unsafe.Pointer(pParse)).FokConstFactor = U8(0)
	inReg = Xsqlite3ExprCodeTarget(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, target)
	(*Parse)(unsafe.Pointer(pParse)).FokConstFactor = okConstFactor
	if !(inReg != target) {
		goto __130
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_SCopy, inReg, target)
	inReg = target
__130:
	;
	Xsqlite3VdbeJumpHere(tls, v, addrINR)
	goto __5

__56:
	pTest = uintptr(0)
	pDel = uintptr(0)
	db1 = (*Parse)(unsafe.Pointer(pParse)).Fdb

	pEList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
	aListelem = pEList + 8
	nExpr = (*ExprList)(unsafe.Pointer(pEList)).FnExpr
	endLabel = Xsqlite3VdbeMakeLabel(tls, pParse)
	if !(libc.AssignUintptr(&pX, (*Expr)(unsafe.Pointer(pExpr)).FpLeft) != uintptr(0)) {
		goto __131
	}
	pDel = Xsqlite3ExprDup(tls, db1, pX, 0)
	if !((*Sqlite3)(unsafe.Pointer(db1)).FmallocFailed != 0) {
		goto __132
	}
	Xsqlite3ExprDelete(tls, db1, pDel)
	goto __5
__132:
	;
	exprToRegister(tls, pDel, exprCodeVector(tls, pParse, pDel, bp+88))

	libc.Xmemset(tls, bp+168, 0, uint64(unsafe.Sizeof(Expr{})))
	(*Expr)(unsafe.Pointer(bp + 168)).Fop = U8(TK_EQ)
	(*Expr)(unsafe.Pointer(bp + 168)).FpLeft = pDel
	pTest = bp + 168

	*(*int32)(unsafe.Pointer(bp + 88)) = 0
__131:
	;
	i1 = 0
__133:
	if !(i1 < nExpr-1) {
		goto __135
	}
	if !(pX != 0) {
		goto __136
	}

	(*Expr)(unsafe.Pointer(bp + 168)).FpRight = (*ExprList_item)(unsafe.Pointer(aListelem + uintptr(i1)*32)).FpExpr
	goto __137
__136:
	pTest = (*ExprList_item)(unsafe.Pointer(aListelem + uintptr(i1)*32)).FpExpr
__137:
	;
	nextCase = Xsqlite3VdbeMakeLabel(tls, pParse)

	Xsqlite3ExprIfFalse(tls, pParse, pTest, nextCase, SQLITE_JUMPIFNULL)

	Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(aListelem+uintptr(i1+1)*32)).FpExpr, target)
	Xsqlite3VdbeGoto(tls, v, endLabel)
	Xsqlite3VdbeResolveLabel(tls, v, nextCase)
	goto __134
__134:
	i1 = i1 + 2
	goto __133
	goto __135
__135:
	;
	if !(nExpr&1 != 0) {
		goto __138
	}
	Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(nExpr-1)*32)).FpExpr, target)
	goto __139
__138:
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, target)
__139:
	;
	Xsqlite3ExprDelete(tls, db1, pDel)
	setDoNotMergeFlagOnCopy(tls, v)
	Xsqlite3VdbeResolveLabel(tls, v, endLabel)
	goto __5

__57:
	;
	if !(!(int32((*Parse)(unsafe.Pointer(pParse)).FpTriggerTab) != 0) && !(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) != 0)) {
		goto __140
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+11472, 0)
	return 0
__140:
	;
	if !(int32((*Expr)(unsafe.Pointer(pExpr)).FaffExpr) == OE_Abort) {
		goto __141
	}
	Xsqlite3MayAbort(tls, pParse)
__141:
	;
	if !(int32((*Expr)(unsafe.Pointer(pExpr)).FaffExpr) == OE_Ignore) {
		goto __142
	}
	Xsqlite3VdbeAddOp4(tls,
		v, OP_Halt, SQLITE_OK, OE_Ignore, 0, *(*uintptr)(unsafe.Pointer(pExpr + 8)), 0)

	goto __143
__142:
	Xsqlite3HaltConstraint(tls, pParse,
		func() int32 {
			if (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab != 0 {
				return SQLITE_CONSTRAINT | int32(7)<<8
			}
			return SQLITE_ERROR
		}(),
		int32((*Expr)(unsafe.Pointer(pExpr)).FaffExpr), *(*uintptr)(unsafe.Pointer(pExpr + 8)), int8(0), uint8(0))
__143:
	;
	goto __5

__5:
	;
	Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 88)))
	Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 92)))
	return inReg
}

var zAff = *(*[10]uint8)(unsafe.Pointer(ts + 11522))

func Xsqlite3ExprCodeRunJustOnce(tls *libc.TLS, pParse uintptr, pExpr uintptr, regDest int32) int32 {
	var p uintptr

	p = (*Parse)(unsafe.Pointer(pParse)).FpConstExpr
	if regDest < 0 && p != 0 {
		var pItem uintptr
		var i int32
		pItem = p + 8
		i = (*ExprList)(unsafe.Pointer(p)).FnExpr
	__1:
		if !(i > 0) {
			goto __3
		}
		{
			if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 16 + 4))&0x8>>3)) != 0 &&
				Xsqlite3ExprCompare(tls, uintptr(0), (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr, pExpr, -1) == 0 {
				return *(*int32)(unsafe.Pointer(pItem + 24))
			}

		}
		goto __2
	__2:
		pItem += 32
		i--
		goto __1
		goto __3
	__3:
	}
	pExpr = Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0)
	if pExpr != uintptr(0) && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_HasFunc) != U32(0) {
		var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
		var addr int32

		addr = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
		(*Parse)(unsafe.Pointer(pParse)).FokConstFactor = U8(0)
		if !(int32((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed) != 0) {
			if regDest < 0 {
				regDest = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
			}
			Xsqlite3ExprCode(tls, pParse, pExpr, regDest)
		}
		(*Parse)(unsafe.Pointer(pParse)).FokConstFactor = U8(1)
		Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		Xsqlite3VdbeJumpHere(tls, v, addr)
	} else {
		p = Xsqlite3ExprListAppend(tls, pParse, p, pExpr)
		if p != 0 {
			var pItem uintptr = p + 8 + uintptr((*ExprList)(unsafe.Pointer(p)).FnExpr-1)*32
			libc.SetBitFieldPtr16Uint32(pItem+16+4, uint32(libc.Bool32(regDest < 0)), 3, 0x8)
			if regDest < 0 {
				regDest = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
			}
			*(*int32)(unsafe.Pointer(pItem + 24)) = regDest
		}
		(*Parse)(unsafe.Pointer(pParse)).FpConstExpr = p
	}
	return regDest
}

func Xsqlite3ExprCodeTemp(tls *libc.TLS, pParse uintptr, pExpr uintptr, pReg uintptr) int32 {
	var r2 int32
	pExpr = Xsqlite3ExprSkipCollateAndLikely(tls, pExpr)
	if (*Parse)(unsafe.Pointer(pParse)).FokConstFactor != 0 &&
		pExpr != uintptr(0) &&
		int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_REGISTER &&
		Xsqlite3ExprIsConstantNotJoin(tls, pExpr) != 0 {
		*(*int32)(unsafe.Pointer(pReg)) = 0
		r2 = Xsqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, -1)
	} else {
		var r1 int32 = Xsqlite3GetTempReg(tls, pParse)
		r2 = Xsqlite3ExprCodeTarget(tls, pParse, pExpr, r1)
		if r2 == r1 {
			*(*int32)(unsafe.Pointer(pReg)) = r1
		} else {
			Xsqlite3ReleaseTempReg(tls, pParse, r1)
			*(*int32)(unsafe.Pointer(pReg)) = 0
		}
	}
	return r2
}

func Xsqlite3ExprCode(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) {
	var inReg int32

	if (*Parse)(unsafe.Pointer(pParse)).FpVdbe == uintptr(0) {
		return
	}
	inReg = Xsqlite3ExprCodeTarget(tls, pParse, pExpr, target)
	if inReg != target {
		var op U8
		if pExpr != 0 && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Subquery) != U32(0) {
			op = U8(OP_Copy)
		} else {
			op = U8(OP_SCopy)
		}
		Xsqlite3VdbeAddOp2(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, int32(op), inReg, target)
	}
}

func Xsqlite3ExprCodeCopy(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	pExpr = Xsqlite3ExprDup(tls, db, pExpr, 0)
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
		Xsqlite3ExprCode(tls, pParse, pExpr, target)
	}
	Xsqlite3ExprDelete(tls, db, pExpr)
}

func Xsqlite3ExprCodeFactorable(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) {
	if (*Parse)(unsafe.Pointer(pParse)).FokConstFactor != 0 && Xsqlite3ExprIsConstantNotJoin(tls, pExpr) != 0 {
		Xsqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, target)
	} else {
		Xsqlite3ExprCodeCopy(tls, pParse, pExpr, target)
	}
}

func Xsqlite3ExprCodeExprList(tls *libc.TLS, pParse uintptr, pList uintptr, target int32, srcReg int32, flags U8) int32 {
	var pItem uintptr
	var i int32
	var j int32
	var n int32
	var copyOp U8
	if int32(flags)&SQLITE_ECEL_DUP != 0 {
		copyOp = uint8(OP_Copy)
	} else {
		copyOp = uint8(OP_SCopy)
	}
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	n = (*ExprList)(unsafe.Pointer(pList)).FnExpr
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FokConstFactor) != 0) {
		flags = libc.Uint8FromInt32(int32(flags) & libc.CplInt32(SQLITE_ECEL_FACTOR))
	}
	pItem = pList + 8
	i = 0
__1:
	if !(i < n) {
		goto __3
	}
	{
		var pExpr uintptr = (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr
		if int32(flags)&SQLITE_ECEL_REF != 0 && libc.AssignInt32(&j, int32(*(*U16)(unsafe.Pointer(pItem + 24)))) > 0 {
			if int32(flags)&SQLITE_ECEL_OMITREF != 0 {
				i--
				n--
			} else {
				Xsqlite3VdbeAddOp2(tls, v, int32(copyOp), j+srcReg-1, target+i)
			}
		} else if int32(flags)&SQLITE_ECEL_FACTOR != 0 &&
			Xsqlite3ExprIsConstantNotJoin(tls, pExpr) != 0 {
			Xsqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, target+i)
		} else {
			var inReg int32 = Xsqlite3ExprCodeTarget(tls, pParse, pExpr, target+i)
			if inReg != target+i {
				var pOp uintptr
				if int32(copyOp) == OP_Copy &&
					int32((*VdbeOp)(unsafe.Pointer(libc.AssignUintptr(&pOp, Xsqlite3VdbeGetLastOp(tls, v)))).Fopcode) == OP_Copy &&
					(*VdbeOp)(unsafe.Pointer(pOp)).Fp1+(*VdbeOp)(unsafe.Pointer(pOp)).Fp3+1 == inReg &&
					(*VdbeOp)(unsafe.Pointer(pOp)).Fp2+(*VdbeOp)(unsafe.Pointer(pOp)).Fp3+1 == target+i &&
					int32((*VdbeOp)(unsafe.Pointer(pOp)).Fp5) == 0 {
					(*VdbeOp)(unsafe.Pointer(pOp)).Fp3++
				} else {
					Xsqlite3VdbeAddOp2(tls, v, int32(copyOp), inReg, target+i)
				}
			}
		}

	}
	goto __2
__2:
	i++
	pItem += 32
	goto __1
	goto __3
__3:
	;
	return n
}

func exprCodeBetween(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, xJump uintptr, jumpIfNull int32) {
	bp := tls.Alloc(220)
	defer tls.Free(220)

	*(*int32)(unsafe.Pointer(bp + 216)) = 0
	var pDel uintptr = uintptr(0)
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Expr{})))
	libc.Xmemset(tls, bp+72, 0, uint64(unsafe.Sizeof(Expr{})))
	libc.Xmemset(tls, bp+144, 0, uint64(unsafe.Sizeof(Expr{})))

	pDel = Xsqlite3ExprDup(tls, db, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, 0)
	if int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		(*Expr)(unsafe.Pointer(bp + 144)).Fop = U8(TK_AND)
		(*Expr)(unsafe.Pointer(bp + 144)).FpLeft = bp
		(*Expr)(unsafe.Pointer(bp + 144)).FpRight = bp + 72
		(*Expr)(unsafe.Pointer(bp)).Fop = U8(TK_GE)
		(*Expr)(unsafe.Pointer(bp)).FpLeft = pDel
		(*Expr)(unsafe.Pointer(bp)).FpRight = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8)).FpExpr
		(*Expr)(unsafe.Pointer(bp + 72)).Fop = U8(TK_LE)
		(*Expr)(unsafe.Pointer(bp + 72)).FpLeft = pDel
		(*Expr)(unsafe.Pointer(bp + 72)).FpRight = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8 + 1*32)).FpExpr
		exprToRegister(tls, pDel, exprCodeVector(tls, pParse, pDel, bp+216))
		if xJump != 0 {
			(*struct {
				f func(*libc.TLS, uintptr, uintptr, int32, int32)
			})(unsafe.Pointer(&struct{ uintptr }{xJump})).f(tls, pParse, bp+144, dest, jumpIfNull)
		} else {
			*(*U32)(unsafe.Pointer(pDel + 4)) |= U32(EP_OuterON)
			Xsqlite3ExprCodeTarget(tls, pParse, bp+144, dest)
		}
		Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 216)))
	}
	Xsqlite3ExprDelete(tls, db, pDel)

}

func Xsqlite3ExprIfTrue(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, jumpIfNull int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var v uintptr
	var op int32

	var r1 int32
	var r2 int32
	var d2 int32
	var pAlt uintptr
	var isNot int32
	var isTrue int32
	var destIfFalse int32
	var destIfNull int32
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	op = 0
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0

	if !(v == uintptr(0)) {
		goto __1
	}
	return
__1:
	;
	if !(pExpr == uintptr(0)) {
		goto __2
	}
	return
__2:
	;
	op = int32((*Expr)(unsafe.Pointer(pExpr)).Fop)
	switch op {
	case TK_AND:
		goto __4
	case TK_OR:
		goto __5
	case TK_NOT:
		goto __6
	case TK_TRUTH:
		goto __7
	case TK_IS:
		goto __8
	case TK_ISNOT:
		goto __9
	case TK_LT:
		goto __10
	case TK_LE:
		goto __11
	case TK_GT:
		goto __12
	case TK_GE:
		goto __13
	case TK_NE:
		goto __14
	case TK_EQ:
		goto __15
	case TK_ISNULL:
		goto __16
	case TK_NOTNULL:
		goto __17
	case TK_BETWEEN:
		goto __18
	case TK_IN:
		goto __19
	default:
		goto __20
	}
	goto __3
__4:
__5:
	pAlt = Xsqlite3ExprSimplifiedAndOr(tls, pExpr)
	if !(pAlt != pExpr) {
		goto __21
	}
	Xsqlite3ExprIfTrue(tls, pParse, pAlt, dest, jumpIfNull)
	goto __22
__21:
	if !(op == TK_AND) {
		goto __23
	}
	d2 = Xsqlite3VdbeMakeLabel(tls, pParse)

	Xsqlite3ExprIfFalse(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, d2,
		jumpIfNull^SQLITE_JUMPIFNULL)
	Xsqlite3ExprIfTrue(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, dest, jumpIfNull)
	Xsqlite3VdbeResolveLabel(tls, v, d2)
	goto __24
__23:
	;
	Xsqlite3ExprIfTrue(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, dest, jumpIfNull)
	Xsqlite3ExprIfTrue(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, dest, jumpIfNull)
__24:
	;
__22:
	;
	goto __3

__6:
	;
	Xsqlite3ExprIfFalse(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, dest, jumpIfNull)
	goto __3

__7:
	;
	isNot = libc.Bool32(int32((*Expr)(unsafe.Pointer(pExpr)).Fop2) == TK_ISNOT)
	isTrue = Xsqlite3ExprTruthValue(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight)

	if !(isTrue^isNot != 0) {
		goto __25
	}
	Xsqlite3ExprIfTrue(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, dest,
		func() int32 {
			if isNot != 0 {
				return SQLITE_JUMPIFNULL
			}
			return 0
		}())
	goto __26
__25:
	Xsqlite3ExprIfFalse(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, dest,
		func() int32 {
			if isNot != 0 {
				return SQLITE_JUMPIFNULL
			}
			return 0
		}())
__26:
	;
	goto __3

__8:
__9:
	;
	if op == TK_IS {
		op = TK_EQ
	} else {
		op = TK_NE
	}
	jumpIfNull = SQLITE_NULLEQ
__10:
__11:
__12:
__13:
__14:
__15:
	if !(Xsqlite3ExprIsVector(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft) != 0) {
		goto __27
	}
	goto default_expr
__27:
	;
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp)
	r2 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
	codeCompare(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, (*Expr)(unsafe.Pointer(pExpr)).FpRight, op,
		r1, r2, dest, jumpIfNull, libc.Bool32((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Commuted) != U32(0)))

	goto __3

__16:
__17:
	;
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp)
	Xsqlite3VdbeTypeofColumn(tls, v, r1)
	Xsqlite3VdbeAddOp2(tls, v, op, r1, dest)

	goto __3

__18:
	;
	exprCodeBetween(tls, pParse, pExpr, dest, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr, int32, int32)
	}{Xsqlite3ExprIfTrue})), jumpIfNull)
	goto __3

__19:
	destIfFalse = Xsqlite3VdbeMakeLabel(tls, pParse)
	if jumpIfNull != 0 {
		destIfNull = dest
	} else {
		destIfNull = destIfFalse
	}
	sqlite3ExprCodeIN(tls, pParse, pExpr, destIfFalse, destIfNull)
	Xsqlite3VdbeGoto(tls, v, dest)
	Xsqlite3VdbeResolveLabel(tls, v, destIfFalse)
	goto __3

__20:
default_expr:
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_IsTrue) == U32(EP_IsTrue)) {
		goto __28
	}
	Xsqlite3VdbeGoto(tls, v, dest)
	goto __29
__28:
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_IsFalse) == U32(EP_IsFalse)) {
		goto __30
	}

	goto __31
__30:
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, pExpr, bp)
	Xsqlite3VdbeAddOp3(tls, v, OP_If, r1, dest, libc.Bool32(jumpIfNull != 0))

__31:
	;
__29:
	;
	goto __3

__3:
	;
	Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
	Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 4)))
}

func Xsqlite3ExprIfFalse(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, jumpIfNull int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var v uintptr
	var op int32

	var r1 int32
	var r2 int32
	var d2 int32
	var pAlt uintptr
	var isNot int32
	var isTrue int32
	var destIfNull int32
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	op = 0
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0

	if !(v == uintptr(0)) {
		goto __1
	}
	return
__1:
	;
	if !(pExpr == uintptr(0)) {
		goto __2
	}
	return
__2:
	;
	op = int32((*Expr)(unsafe.Pointer(pExpr)).Fop) + TK_ISNULL&1 ^ 1 - TK_ISNULL&1

	switch int32((*Expr)(unsafe.Pointer(pExpr)).Fop) {
	case TK_AND:
		goto __4
	case TK_OR:
		goto __5
	case TK_NOT:
		goto __6
	case TK_TRUTH:
		goto __7
	case TK_IS:
		goto __8
	case TK_ISNOT:
		goto __9
	case TK_LT:
		goto __10
	case TK_LE:
		goto __11
	case TK_GT:
		goto __12
	case TK_GE:
		goto __13
	case TK_NE:
		goto __14
	case TK_EQ:
		goto __15
	case TK_ISNULL:
		goto __16
	case TK_NOTNULL:
		goto __17
	case TK_BETWEEN:
		goto __18
	case TK_IN:
		goto __19
	default:
		goto __20
	}
	goto __3
__4:
__5:
	pAlt = Xsqlite3ExprSimplifiedAndOr(tls, pExpr)
	if !(pAlt != pExpr) {
		goto __21
	}
	Xsqlite3ExprIfFalse(tls, pParse, pAlt, dest, jumpIfNull)
	goto __22
__21:
	if !(int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AND) {
		goto __23
	}

	Xsqlite3ExprIfFalse(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, dest, jumpIfNull)
	Xsqlite3ExprIfFalse(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, dest, jumpIfNull)
	goto __24
__23:
	d2 = Xsqlite3VdbeMakeLabel(tls, pParse)

	Xsqlite3ExprIfTrue(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, d2,
		jumpIfNull^SQLITE_JUMPIFNULL)
	Xsqlite3ExprIfFalse(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, dest, jumpIfNull)
	Xsqlite3VdbeResolveLabel(tls, v, d2)
__24:
	;
__22:
	;
	goto __3

__6:
	;
	Xsqlite3ExprIfTrue(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, dest, jumpIfNull)
	goto __3

__7:
	;
	isNot = libc.Bool32(int32((*Expr)(unsafe.Pointer(pExpr)).Fop2) == TK_ISNOT)
	isTrue = Xsqlite3ExprTruthValue(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight)

	if !(isTrue^isNot != 0) {
		goto __25
	}

	Xsqlite3ExprIfFalse(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, dest,
		func() int32 {
			if isNot != 0 {
				return 0
			}
			return SQLITE_JUMPIFNULL
		}())

	goto __26
__25:
	Xsqlite3ExprIfTrue(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, dest,
		func() int32 {
			if isNot != 0 {
				return 0
			}
			return SQLITE_JUMPIFNULL
		}())
__26:
	;
	goto __3

__8:
__9:
	;
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_IS {
		op = TK_NE
	} else {
		op = TK_EQ
	}
	jumpIfNull = SQLITE_NULLEQ
__10:
__11:
__12:
__13:
__14:
__15:
	if !(Xsqlite3ExprIsVector(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft) != 0) {
		goto __27
	}
	goto default_expr
__27:
	;
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp)
	r2 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, bp+4)
	codeCompare(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, (*Expr)(unsafe.Pointer(pExpr)).FpRight, op,
		r1, r2, dest, jumpIfNull, libc.Bool32((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Commuted) != U32(0)))

	goto __3

__16:
__17:
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, bp)
	Xsqlite3VdbeTypeofColumn(tls, v, r1)
	Xsqlite3VdbeAddOp2(tls, v, op, r1, dest)

	goto __3

__18:
	;
	exprCodeBetween(tls, pParse, pExpr, dest, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr, int32, int32)
	}{Xsqlite3ExprIfFalse})), jumpIfNull)
	goto __3

__19:
	if !(jumpIfNull != 0) {
		goto __28
	}
	sqlite3ExprCodeIN(tls, pParse, pExpr, dest, dest)
	goto __29
__28:
	destIfNull = Xsqlite3VdbeMakeLabel(tls, pParse)
	sqlite3ExprCodeIN(tls, pParse, pExpr, dest, destIfNull)
	Xsqlite3VdbeResolveLabel(tls, v, destIfNull)
__29:
	;
	goto __3

__20:
default_expr:
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_IsFalse) == U32(EP_IsFalse)) {
		goto __30
	}
	Xsqlite3VdbeGoto(tls, v, dest)
	goto __31
__30:
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_IsTrue) == U32(EP_IsTrue)) {
		goto __32
	}

	goto __33
__32:
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, pExpr, bp)
	Xsqlite3VdbeAddOp3(tls, v, OP_IfNot, r1, dest, libc.Bool32(jumpIfNull != 0))

__33:
	;
__31:
	;
	goto __3

__3:
	;
	Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
	Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 4)))
}

func Xsqlite3ExprIfFalseDup(tls *libc.TLS, pParse uintptr, pExpr uintptr, dest int32, jumpIfNull int32) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pCopy uintptr = Xsqlite3ExprDup(tls, db, pExpr, 0)
	if int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		Xsqlite3ExprIfFalse(tls, pParse, pCopy, dest, jumpIfNull)
	}
	Xsqlite3ExprDelete(tls, db, pCopy)
}

func exprCompareVariable(tls *libc.TLS, pParse uintptr, pVar uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var res int32 = 0
	var iVar int32
	var pL uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)

	Xsqlite3ValueFromExpr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr, uint8(SQLITE_UTF8), uint8(SQLITE_AFF_BLOB), bp)
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		iVar = int32((*Expr)(unsafe.Pointer(pVar)).FiColumn)
		Xsqlite3VdbeSetVarmask(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, iVar)
		pL = Xsqlite3VdbeGetBoundValue(tls, (*Parse)(unsafe.Pointer(pParse)).FpReprepare, iVar, uint8(SQLITE_AFF_BLOB))
		if pL != 0 {
			if Xsqlite3_value_type(tls, pL) == SQLITE_TEXT {
				Xsqlite3_value_text(tls, pL)
			}
			res = libc.Bool32(0 == Xsqlite3MemCompare(tls, pL, *(*uintptr)(unsafe.Pointer(bp)), uintptr(0)))
		}
		Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
		Xsqlite3ValueFree(tls, pL)
	}

	return res
}

func Xsqlite3ExprCompare(tls *libc.TLS, pParse uintptr, pA uintptr, pB uintptr, iTab int32) int32 {
	var combinedFlags U32
	if pA == uintptr(0) || pB == uintptr(0) {
		if pB == pA {
			return 0
		}
		return 2
	}
	if pParse != 0 && int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_VARIABLE && exprCompareVariable(tls, pParse, pA, pB) != 0 {
		return 0
	}
	combinedFlags = (*Expr)(unsafe.Pointer(pA)).Fflags | (*Expr)(unsafe.Pointer(pB)).Fflags
	if combinedFlags&U32(EP_IntValue) != 0 {
		if (*Expr)(unsafe.Pointer(pA)).Fflags&(*Expr)(unsafe.Pointer(pB)).Fflags&U32(EP_IntValue) != U32(0) && *(*int32)(unsafe.Pointer(pA + 8)) == *(*int32)(unsafe.Pointer(pB + 8)) {
			return 0
		}
		return 2
	}
	if int32((*Expr)(unsafe.Pointer(pA)).Fop) != int32((*Expr)(unsafe.Pointer(pB)).Fop) || int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_RAISE {
		if int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_COLLATE && Xsqlite3ExprCompare(tls, pParse, (*Expr)(unsafe.Pointer(pA)).FpLeft, pB, iTab) < 2 {
			return 1
		}
		if int32((*Expr)(unsafe.Pointer(pB)).Fop) == TK_COLLATE && Xsqlite3ExprCompare(tls, pParse, pA, (*Expr)(unsafe.Pointer(pB)).FpLeft, iTab) < 2 {
			return 1
		}
		if int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_AGG_COLUMN && int32((*Expr)(unsafe.Pointer(pB)).Fop) == TK_COLUMN &&
			(*Expr)(unsafe.Pointer(pB)).FiTable < 0 && (*Expr)(unsafe.Pointer(pA)).FiTable == iTab {
		} else {
			return 2
		}
	}

	if *(*uintptr)(unsafe.Pointer(pA + 8)) != 0 {
		if int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_FUNCTION || int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_AGG_FUNCTION {
			if Xsqlite3StrICmp(tls, *(*uintptr)(unsafe.Pointer(pA + 8)), *(*uintptr)(unsafe.Pointer(pB + 8))) != 0 {
				return 2
			}

			if libc.Bool32((*Expr)(unsafe.Pointer(pA)).Fflags&U32(EP_WinFunc) != U32(0)) != libc.Bool32((*Expr)(unsafe.Pointer(pB)).Fflags&U32(EP_WinFunc) != U32(0)) {
				return 2
			}
			if (*Expr)(unsafe.Pointer(pA)).Fflags&U32(EP_WinFunc) != U32(0) {
				if Xsqlite3WindowCompare(tls, pParse, *(*uintptr)(unsafe.Pointer(pA + 64)), *(*uintptr)(unsafe.Pointer(pB + 64)), 1) != 0 {
					return 2
				}
			}
		} else if int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_NULL {
			return 0
		} else if int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_COLLATE {
			if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(pA + 8)), *(*uintptr)(unsafe.Pointer(pB + 8))) != 0 {
				return 2
			}
		} else if *(*uintptr)(unsafe.Pointer(pB + 8)) != uintptr(0) &&
			int32((*Expr)(unsafe.Pointer(pA)).Fop) != TK_COLUMN &&
			int32((*Expr)(unsafe.Pointer(pA)).Fop) != TK_AGG_COLUMN &&
			libc.Xstrcmp(tls, *(*uintptr)(unsafe.Pointer(pA + 8)), *(*uintptr)(unsafe.Pointer(pB + 8))) != 0 {
			return 2
		}
	}
	if (*Expr)(unsafe.Pointer(pA)).Fflags&U32(EP_Distinct|EP_Commuted) !=
		(*Expr)(unsafe.Pointer(pB)).Fflags&U32(EP_Distinct|EP_Commuted) {
		return 2
	}
	if combinedFlags&U32(EP_TokenOnly) == U32(0) {
		if combinedFlags&U32(EP_xIsSelect) != 0 {
			return 2
		}
		if combinedFlags&U32(EP_FixedCol) == U32(0) &&
			Xsqlite3ExprCompare(tls, pParse, (*Expr)(unsafe.Pointer(pA)).FpLeft, (*Expr)(unsafe.Pointer(pB)).FpLeft, iTab) != 0 {
			return 2
		}
		if Xsqlite3ExprCompare(tls, pParse, (*Expr)(unsafe.Pointer(pA)).FpRight, (*Expr)(unsafe.Pointer(pB)).FpRight, iTab) != 0 {
			return 2
		}
		if Xsqlite3ExprListCompare(tls, *(*uintptr)(unsafe.Pointer(pA + 32)), *(*uintptr)(unsafe.Pointer(pB + 32)), iTab) != 0 {
			return 2
		}
		if int32((*Expr)(unsafe.Pointer(pA)).Fop) != TK_STRING &&
			int32((*Expr)(unsafe.Pointer(pA)).Fop) != TK_TRUEFALSE &&
			combinedFlags&U32(EP_Reduced) == U32(0) {
			if int32((*Expr)(unsafe.Pointer(pA)).FiColumn) != int32((*Expr)(unsafe.Pointer(pB)).FiColumn) {
				return 2
			}
			if int32((*Expr)(unsafe.Pointer(pA)).Fop2) != int32((*Expr)(unsafe.Pointer(pB)).Fop2) && int32((*Expr)(unsafe.Pointer(pA)).Fop) == TK_TRUTH {
				return 2
			}
			if int32((*Expr)(unsafe.Pointer(pA)).Fop) != TK_IN && (*Expr)(unsafe.Pointer(pA)).FiTable != (*Expr)(unsafe.Pointer(pB)).FiTable && (*Expr)(unsafe.Pointer(pA)).FiTable != iTab {
				return 2
			}
		}
	}
	return 0
}

func Xsqlite3ExprListCompare(tls *libc.TLS, pA uintptr, pB uintptr, iTab int32) int32 {
	var i int32
	if pA == uintptr(0) && pB == uintptr(0) {
		return 0
	}
	if pA == uintptr(0) || pB == uintptr(0) {
		return 1
	}
	if (*ExprList)(unsafe.Pointer(pA)).FnExpr != (*ExprList)(unsafe.Pointer(pB)).FnExpr {
		return 1
	}
	for i = 0; i < (*ExprList)(unsafe.Pointer(pA)).FnExpr; i++ {
		var res int32
		var pExprA uintptr = (*ExprList_item)(unsafe.Pointer(pA + 8 + uintptr(i)*32)).FpExpr
		var pExprB uintptr = (*ExprList_item)(unsafe.Pointer(pB + 8 + uintptr(i)*32)).FpExpr
		if int32((*ExprList_item)(unsafe.Pointer(pA+8+uintptr(i)*32)).Ffg.FsortFlags) != int32((*ExprList_item)(unsafe.Pointer(pB+8+uintptr(i)*32)).Ffg.FsortFlags) {
			return 1
		}
		if libc.AssignInt32(&res, Xsqlite3ExprCompare(tls, uintptr(0), pExprA, pExprB, iTab)) != 0 {
			return res
		}
	}
	return 0
}

func Xsqlite3ExprCompareSkip(tls *libc.TLS, pA uintptr, pB uintptr, iTab int32) int32 {
	return Xsqlite3ExprCompare(tls, uintptr(0),
		Xsqlite3ExprSkipCollateAndLikely(tls, pA),
		Xsqlite3ExprSkipCollateAndLikely(tls, pB),
		iTab)
}

func exprImpliesNotNull(tls *libc.TLS, pParse uintptr, p uintptr, pNN uintptr, iTab int32, seenNot int32) int32 {
	if Xsqlite3ExprCompare(tls, pParse, p, pNN, iTab) == 0 {
		return libc.Bool32(int32((*Expr)(unsafe.Pointer(pNN)).Fop) != TK_NULL)
	}
	{
		switch int32((*Expr)(unsafe.Pointer(p)).Fop) {
		case TK_IN:
			{
				if seenNot != 0 && (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_xIsSelect) != U32(0) {
					return 0
				}

				return exprImpliesNotNull(tls, pParse, (*Expr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, 1)

			}
		case TK_BETWEEN:
			{
				var pList uintptr

				pList = *(*uintptr)(unsafe.Pointer(p + 32))

				if seenNot != 0 {
					return 0
				}
				if exprImpliesNotNull(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8)).FpExpr, pNN, iTab, 1) != 0 ||
					exprImpliesNotNull(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8+1*32)).FpExpr, pNN, iTab, 1) != 0 {
					return 1
				}
				return exprImpliesNotNull(tls, pParse, (*Expr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, 1)

			}
		case TK_EQ:
			fallthrough
		case TK_NE:
			fallthrough
		case TK_LT:
			fallthrough
		case TK_LE:
			fallthrough
		case TK_GT:
			fallthrough
		case TK_GE:
			fallthrough
		case TK_PLUS:
			fallthrough
		case TK_MINUS:
			fallthrough
		case TK_BITOR:
			fallthrough
		case TK_LSHIFT:
			fallthrough
		case TK_RSHIFT:
			fallthrough
		case TK_CONCAT:
			seenNot = 1
			fallthrough
		case TK_STAR:
			fallthrough
		case TK_REM:
			fallthrough
		case TK_BITAND:
			fallthrough
		case TK_SLASH:
			{
				if exprImpliesNotNull(tls, pParse, (*Expr)(unsafe.Pointer(p)).FpRight, pNN, iTab, seenNot) != 0 {
					return 1
				}

			}
			fallthrough
		case TK_SPAN:
			fallthrough
		case TK_COLLATE:
			fallthrough
		case TK_UPLUS:
			fallthrough
		case TK_UMINUS:
			{
				return exprImpliesNotNull(tls, pParse, (*Expr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, seenNot)

			}
		case TK_TRUTH:
			{
				if seenNot != 0 {
					return 0
				}
				if int32((*Expr)(unsafe.Pointer(p)).Fop2) != TK_IS {
					return 0
				}
				return exprImpliesNotNull(tls, pParse, (*Expr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, 1)

			}
		case TK_BITNOT:
			fallthrough
		case TK_NOT:
			{
				return exprImpliesNotNull(tls, pParse, (*Expr)(unsafe.Pointer(p)).FpLeft, pNN, iTab, 1)

			}
		}
	}
	return 0
}

func Xsqlite3ExprImpliesExpr(tls *libc.TLS, pParse uintptr, pE1 uintptr, pE2 uintptr, iTab int32) int32 {
	if Xsqlite3ExprCompare(tls, pParse, pE1, pE2, iTab) == 0 {
		return 1
	}
	if int32((*Expr)(unsafe.Pointer(pE2)).Fop) == TK_OR &&
		(Xsqlite3ExprImpliesExpr(tls, pParse, pE1, (*Expr)(unsafe.Pointer(pE2)).FpLeft, iTab) != 0 ||
			Xsqlite3ExprImpliesExpr(tls, pParse, pE1, (*Expr)(unsafe.Pointer(pE2)).FpRight, iTab) != 0) {
		return 1
	}
	if int32((*Expr)(unsafe.Pointer(pE2)).Fop) == TK_NOTNULL &&
		exprImpliesNotNull(tls, pParse, pE1, (*Expr)(unsafe.Pointer(pE2)).FpLeft, iTab, 0) != 0 {
		return 1
	}
	return 0
}

func impliesNotNullRow(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0) {
		return WRC_Prune
	}
	switch int32((*Expr)(unsafe.Pointer(pExpr)).Fop) {
	case TK_ISNOT:
		fallthrough
	case TK_ISNULL:
		fallthrough
	case TK_NOTNULL:
		fallthrough
	case TK_IS:
		fallthrough
	case TK_OR:
		fallthrough
	case TK_VECTOR:
		fallthrough
	case TK_CASE:
		fallthrough
	case TK_IN:
		fallthrough
	case TK_FUNCTION:
		fallthrough
	case TK_TRUTH:
		return WRC_Prune
	case TK_COLUMN:
		if *(*int32)(unsafe.Pointer(pWalker + 40)) == (*Expr)(unsafe.Pointer(pExpr)).FiTable {
			(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(1)
			return WRC_Abort
		}
		return WRC_Prune

	case TK_AND:
		if int32((*Walker)(unsafe.Pointer(pWalker)).FeCode) == 0 {
			Xsqlite3WalkExpr(tls, pWalker, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
			if (*Walker)(unsafe.Pointer(pWalker)).FeCode != 0 {
				(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(0)
				Xsqlite3WalkExpr(tls, pWalker, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
			}
		}
		return WRC_Prune

	case TK_BETWEEN:
		if Xsqlite3WalkExpr(tls, pWalker, (*Expr)(unsafe.Pointer(pExpr)).FpLeft) == WRC_Abort {
			return WRC_Abort
		}
		return WRC_Prune

	case TK_EQ:
		fallthrough
	case TK_NE:
		fallthrough
	case TK_LT:
		fallthrough
	case TK_LE:
		fallthrough
	case TK_GT:
		fallthrough
	case TK_GE:
		{
			var pLeft uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
			var pRight uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpRight

			if int32((*Expr)(unsafe.Pointer(pLeft)).Fop) == TK_COLUMN &&
				*(*uintptr)(unsafe.Pointer(pLeft + 64)) != uintptr(0) &&
				int32((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 64)))).FeTabType) == TABTYP_VTAB ||
				int32((*Expr)(unsafe.Pointer(pRight)).Fop) == TK_COLUMN &&
					*(*uintptr)(unsafe.Pointer(pRight + 64)) != uintptr(0) &&
					int32((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pRight + 64)))).FeTabType) == TABTYP_VTAB {
				return WRC_Prune
			}

		}
		fallthrough
	default:
		return WRC_Continue
	}
	return int32(0)
}

func Xsqlite3ExprImpliesNonNullRow(tls *libc.TLS, p uintptr, iTab int32) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	p = Xsqlite3ExprSkipCollateAndLikely(tls, p)
	if p == uintptr(0) {
		return 0
	}
	if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_NOTNULL {
		p = (*Expr)(unsafe.Pointer(p)).FpLeft
	} else {
		for int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_AND {
			if Xsqlite3ExprImpliesNonNullRow(tls, (*Expr)(unsafe.Pointer(p)).FpLeft, iTab) != 0 {
				return 1
			}
			p = (*Expr)(unsafe.Pointer(p)).FpRight
		}
	}
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{impliesNotNullRow}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = uintptr(0)
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = uintptr(0)
	(*Walker)(unsafe.Pointer(bp)).FeCode = U16(0)
	*(*int32)(unsafe.Pointer(bp + 40)) = iTab
	Xsqlite3WalkExpr(tls, bp, p)
	return int32((*Walker)(unsafe.Pointer(bp)).FeCode)
}

func exprIdxCover(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN &&
		(*Expr)(unsafe.Pointer(pExpr)).FiTable == (*IdxCover)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalker + 40)))).FiCur &&
		int32(Xsqlite3TableColumnToIndex(tls, (*IdxCover)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalker + 40)))).FpIdx, (*Expr)(unsafe.Pointer(pExpr)).FiColumn)) < 0 {
		(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(1)
		return WRC_Abort
	}
	return WRC_Continue
}

func Xsqlite3ExprCoveredByIndex(tls *libc.TLS, pExpr uintptr, iCur int32, pIdx uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	(*IdxCover)(unsafe.Pointer(bp + 48)).FiCur = iCur
	(*IdxCover)(unsafe.Pointer(bp + 48)).FpIdx = pIdx
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{exprIdxCover}))
	*(*uintptr)(unsafe.Pointer(bp + 40)) = bp + 48
	Xsqlite3WalkExpr(tls, bp, pExpr)
	return libc.BoolInt32(!((*Walker)(unsafe.Pointer(bp)).FeCode != 0))
}

func selectRefEnter(tls *libc.TLS, pWalker uintptr, pSelect uintptr) int32 {
	var p uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	var pSrc uintptr = (*Select)(unsafe.Pointer(pSelect)).FpSrc
	var i I64
	var j I64
	var piNew uintptr
	if (*SrcList)(unsafe.Pointer(pSrc)).FnSrc == 0 {
		return WRC_Continue
	}
	j = (*RefSrcList)(unsafe.Pointer(p)).FnExclude
	*(*I64)(unsafe.Pointer(p + 16)) += I64((*SrcList)(unsafe.Pointer(pSrc)).FnSrc)
	piNew = Xsqlite3DbRealloc(tls, (*RefSrcList)(unsafe.Pointer(p)).Fdb, (*RefSrcList)(unsafe.Pointer(p)).FaiExclude, uint64((*RefSrcList)(unsafe.Pointer(p)).FnExclude)*uint64(unsafe.Sizeof(int32(0))))
	if piNew == uintptr(0) {
		(*RefSrcList)(unsafe.Pointer(p)).FnExclude = int64(0)
		return WRC_Abort
	} else {
		(*RefSrcList)(unsafe.Pointer(p)).FaiExclude = piNew
	}
	i = int64(0)
__1:
	if !(i < I64((*SrcList)(unsafe.Pointer(pSrc)).FnSrc)) {
		goto __3
	}
	{
		*(*int32)(unsafe.Pointer((*RefSrcList)(unsafe.Pointer(p)).FaiExclude + uintptr(j)*4)) = (*SrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104)).FiCursor

	}
	goto __2
__2:
	i++
	j++
	goto __1
	goto __3
__3:
	;
	return WRC_Continue
}

func selectRefLeave(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
	var p uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	var pSrc uintptr = (*Select)(unsafe.Pointer(pSelect)).FpSrc
	if (*RefSrcList)(unsafe.Pointer(p)).FnExclude != 0 {
		*(*I64)(unsafe.Pointer(p + 16)) -= I64((*SrcList)(unsafe.Pointer(pSrc)).FnSrc)
	}
}

func exprRefToSrcList(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN ||
		int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AGG_COLUMN {
		var i int32
		var p uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
		var pSrc uintptr = (*RefSrcList)(unsafe.Pointer(p)).FpRef
		var nSrc int32
		if pSrc != 0 {
			nSrc = (*SrcList)(unsafe.Pointer(pSrc)).FnSrc
		} else {
			nSrc = 0
		}
		for i = 0; i < nSrc; i++ {
			if (*Expr)(unsafe.Pointer(pExpr)).FiTable == (*SrcItem)(unsafe.Pointer(pSrc+8+uintptr(i)*104)).FiCursor {
				*(*U16)(unsafe.Pointer(pWalker + 36)) |= U16(1)
				return WRC_Continue
			}
		}
		for i = 0; I64(i) < (*RefSrcList)(unsafe.Pointer(p)).FnExclude && *(*int32)(unsafe.Pointer((*RefSrcList)(unsafe.Pointer(p)).FaiExclude + uintptr(i)*4)) != (*Expr)(unsafe.Pointer(pExpr)).FiTable; i++ {
		}
		if I64(i) >= (*RefSrcList)(unsafe.Pointer(p)).FnExclude {
			*(*U16)(unsafe.Pointer(pWalker + 36)) |= U16(2)
		}
	}
	return WRC_Continue
}

func Xsqlite3ReferencesSrcList(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSrcList uintptr) int32 {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	libc.Xmemset(tls, bp+48, 0, uint64(unsafe.Sizeof(RefSrcList{})))
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{exprRefToSrcList}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{selectRefEnter}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr)
	}{selectRefLeave}))
	*(*uintptr)(unsafe.Pointer(bp + 40)) = bp + 48
	(*RefSrcList)(unsafe.Pointer(bp + 48)).Fdb = (*Parse)(unsafe.Pointer(pParse)).Fdb
	(*RefSrcList)(unsafe.Pointer(bp + 48)).FpRef = pSrcList

	Xsqlite3WalkExprList(tls, bp, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
		Xsqlite3WalkExpr(tls, bp, (*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FpFilter)
	}
	if (*RefSrcList)(unsafe.Pointer(bp+48)).FaiExclude != 0 {
		Xsqlite3DbNNFreeNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*RefSrcList)(unsafe.Pointer(bp+48)).FaiExclude)
	}
	if int32((*Walker)(unsafe.Pointer(bp)).FeCode)&0x01 != 0 {
		return 1
	} else if (*Walker)(unsafe.Pointer(bp)).FeCode != 0 {
		return 0
	} else {
		return -1
	}
	return int32(0)
}

func agginfoPersistExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_TokenOnly|EP_Reduced) != U32(0)) &&
		(*Expr)(unsafe.Pointer(pExpr)).FpAggInfo != uintptr(0) {
		var pAggInfo uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo
		var iAgg int32 = int32((*Expr)(unsafe.Pointer(pExpr)).FiAgg)
		var pParse uintptr = (*Walker)(unsafe.Pointer(pWalker)).FpParse
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_AGG_FUNCTION {
			if (*AggInfo_col)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol+uintptr(iAgg)*24)).FpCExpr == pExpr {
				pExpr = Xsqlite3ExprDup(tls, db, pExpr, 0)
				if pExpr != 0 {
					(*AggInfo_col)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(iAgg)*24)).FpCExpr = pExpr
					Xsqlite3ExprDeferredDelete(tls, pParse, pExpr)
				}
			}
		} else {
			if (*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc+uintptr(iAgg)*24)).FpFExpr == pExpr {
				pExpr = Xsqlite3ExprDup(tls, db, pExpr, 0)
				if pExpr != 0 {
					(*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(iAgg)*24)).FpFExpr = pExpr
					Xsqlite3ExprDeferredDelete(tls, pParse, pExpr)
				}
			}
		}
	}
	return WRC_Continue
}

func Xsqlite3AggInfoPersistWalkerInit(tls *libc.TLS, pWalker uintptr, pParse uintptr) {
	libc.Xmemset(tls, pWalker, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(pWalker)).FpParse = pParse
	(*Walker)(unsafe.Pointer(pWalker)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{agginfoPersistExprCb}))
	(*Walker)(unsafe.Pointer(pWalker)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3SelectWalkNoop}))
}

func addAggInfoColumn(tls *libc.TLS, db uintptr, pInfo uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	(*AggInfo)(unsafe.Pointer(pInfo)).FaCol = Xsqlite3ArrayAllocate(tls,
		db,
		(*AggInfo)(unsafe.Pointer(pInfo)).FaCol,
		int32(unsafe.Sizeof(AggInfo_col{})),
		pInfo+32,
		bp)
	return *(*int32)(unsafe.Pointer(bp))
}

func addAggInfoFunc(tls *libc.TLS, db uintptr, pInfo uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	(*AggInfo)(unsafe.Pointer(pInfo)).FaFunc = Xsqlite3ArrayAllocate(tls,
		db,
		(*AggInfo)(unsafe.Pointer(pInfo)).FaFunc,
		int32(unsafe.Sizeof(AggInfo_func{})),
		pInfo+48,
		bp)
	return *(*int32)(unsafe.Pointer(bp))
}

func findOrCreateAggInfoColumn(tls *libc.TLS, pParse uintptr, pAggInfo uintptr, pExpr uintptr) {
	var pCol uintptr
	var k int32
	var pE uintptr
	var j int32
	var n int32
	var pGB uintptr
	var pTerm uintptr

	pCol = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol
	k = 0
__1:
	if !(k < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
		goto __3
	}
	if !((*AggInfo_col)(unsafe.Pointer(pCol)).FiTable == (*Expr)(unsafe.Pointer(pExpr)).FiTable &&
		int32((*AggInfo_col)(unsafe.Pointer(pCol)).FiColumn) == int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) &&
		int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_IF_NULL_ROW) {
		goto __4
	}
	goto fix_up_expr
__4:
	;
	goto __2
__2:
	k++
	pCol += 24
	goto __1
	goto __3
__3:
	;
	k = addAggInfoColumn(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
	if !(k < 0) {
		goto __5
	}

	return
__5:
	;
	pCol = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(k)*24

	(*AggInfo_col)(unsafe.Pointer(pCol)).FpTab = *(*uintptr)(unsafe.Pointer(pExpr + 64))
	(*AggInfo_col)(unsafe.Pointer(pCol)).FiTable = (*Expr)(unsafe.Pointer(pExpr)).FiTable
	(*AggInfo_col)(unsafe.Pointer(pCol)).FiColumn = (*Expr)(unsafe.Pointer(pExpr)).FiColumn
	(*AggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = int16(-1)
	(*AggInfo_col)(unsafe.Pointer(pCol)).FpCExpr = pExpr
	if !((*AggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy != 0 && int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_IF_NULL_ROW) {
		goto __6
	}
	pGB = (*AggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy
	pTerm = pGB + 8
	n = (*ExprList)(unsafe.Pointer(pGB)).FnExpr
	j = 0
__7:
	if !(j < n) {
		goto __9
	}
	pE = (*ExprList_item)(unsafe.Pointer(pTerm)).FpExpr
	if !(int32((*Expr)(unsafe.Pointer(pE)).Fop) == TK_COLUMN &&
		(*Expr)(unsafe.Pointer(pE)).FiTable == (*Expr)(unsafe.Pointer(pExpr)).FiTable &&
		int32((*Expr)(unsafe.Pointer(pE)).FiColumn) == int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)) {
		goto __10
	}
	(*AggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = I16(j)
	goto __9
__10:
	;
	goto __8
__8:
	j++
	pTerm += 32
	goto __7
	goto __9
__9:
	;
__6:
	;
	if !(int32((*AggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn) < 0) {
		goto __11
	}
	(*AggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn = I16(libc.PostIncUint16(&(*AggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn, 1))
__11:
	;
fix_up_expr:
	;
	(*Expr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
	if !(int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN) {
		goto __12
	}
	(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_AGG_COLUMN)
__12:
	;
	(*Expr)(unsafe.Pointer(pExpr)).FiAgg = I16(k)
}

func analyzeAggregate(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var i int32
	var pNC uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	var pParse uintptr = (*NameContext)(unsafe.Pointer(pNC)).FpParse
	var pSrcList uintptr = (*NameContext)(unsafe.Pointer(pNC)).FpSrcList
	var pAggInfo uintptr = *(*uintptr)(unsafe.Pointer(pNC + 16))

	switch int32((*Expr)(unsafe.Pointer(pExpr)).Fop) {
	default:
		{
			var pIEpr uintptr

			if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_InAggFunc == 0 {
				break
			}
			if (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr == uintptr(0) {
				break
			}
			for pIEpr = (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr; pIEpr != 0; pIEpr = (*IndexedExpr)(unsafe.Pointer(pIEpr)).FpIENext {
				var iDataCur int32 = (*IndexedExpr)(unsafe.Pointer(pIEpr)).FiDataCur
				if iDataCur < 0 {
					continue
				}
				if Xsqlite3ExprCompare(tls, uintptr(0), pExpr, (*IndexedExpr)(unsafe.Pointer(pIEpr)).FpExpr, iDataCur) == 0 {
					break
				}
			}
			if pIEpr == uintptr(0) {
				break
			}
			if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc|EP_Subrtn) == U32(0)) {
				break
			}
			if (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo != uintptr(0) {
				break
			}

			libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Expr{})))
			(*Expr)(unsafe.Pointer(bp)).Fop = U8(TK_AGG_COLUMN)
			(*Expr)(unsafe.Pointer(bp)).FiTable = (*IndexedExpr)(unsafe.Pointer(pIEpr)).FiIdxCur
			(*Expr)(unsafe.Pointer(bp)).FiColumn = YnVar((*IndexedExpr)(unsafe.Pointer(pIEpr)).FiIdxCol)
			findOrCreateAggInfoColumn(tls, pParse, pAggInfo, bp)
			(*AggInfo_col)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((*Expr)(unsafe.Pointer(bp)).FiAgg)*24)).FpCExpr = pExpr
			(*Expr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
			(*Expr)(unsafe.Pointer(pExpr)).FiAgg = (*Expr)(unsafe.Pointer(bp)).FiAgg
			return WRC_Prune

		}
	case TK_IF_NULL_ROW:
		fallthrough
	case TK_AGG_COLUMN:
		fallthrough
	case TK_COLUMN:
		{
			if pSrcList != uintptr(0) {
				var pItem uintptr = pSrcList + 8
				i = 0
			__1:
				if !(i < (*SrcList)(unsafe.Pointer(pSrcList)).FnSrc) {
					goto __3
				}
				{
					if (*Expr)(unsafe.Pointer(pExpr)).FiTable == (*SrcItem)(unsafe.Pointer(pItem)).FiCursor {
						findOrCreateAggInfoColumn(tls, pParse, pAggInfo, pExpr)
						goto __3
					}

				}
				goto __2
			__2:
				i++
				pItem += 104
				goto __1
				goto __3
			__3:
			}
			return WRC_Prune

		}
	case TK_AGG_FUNCTION:
		{
			if (*NameContext)(unsafe.Pointer(pNC)).FncFlags&NC_InAggFunc == 0 &&
				(*Walker)(unsafe.Pointer(pWalker)).FwalkerDepth == int32((*Expr)(unsafe.Pointer(pExpr)).Fop2) {
				var pItem uintptr = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
				i = 0
			__4:
				if !(i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
					goto __6
				}
				{
					if (*AggInfo_func)(unsafe.Pointer(pItem)).FpFExpr == pExpr {
						goto __6
					}
					if Xsqlite3ExprCompare(tls, uintptr(0), (*AggInfo_func)(unsafe.Pointer(pItem)).FpFExpr, pExpr, -1) == 0 {
						goto __6
					}

				}
				goto __5
			__5:
				i++
				pItem += 24
				goto __4
				goto __6
			__6:
				;
				if i >= (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc {
					var enc U8 = (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fenc
					i = addAggInfoFunc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pAggInfo)
					if i >= 0 {
						pItem = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*24
						(*AggInfo_func)(unsafe.Pointer(pItem)).FpFExpr = pExpr

						(*AggInfo_func)(unsafe.Pointer(pItem)).FpFunc = Xsqlite3FindFunction(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb,
							*(*uintptr)(unsafe.Pointer(pExpr + 8)),
							func() int32 {
								if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != 0 {
									return (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr
								}
								return 0
							}(), enc, uint8(0))
						if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Distinct) != 0 {
							(*AggInfo_func)(unsafe.Pointer(pItem)).FiDistinct = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
						} else {
							(*AggInfo_func)(unsafe.Pointer(pItem)).FiDistinct = -1
						}
					}
				}

				(*Expr)(unsafe.Pointer(pExpr)).FiAgg = I16(i)
				(*Expr)(unsafe.Pointer(pExpr)).FpAggInfo = pAggInfo
				return WRC_Prune
			} else {
				return WRC_Continue
			}

		}
	}
	return WRC_Continue
}

func Xsqlite3ExprAnalyzeAggregates(tls *libc.TLS, pNC uintptr, pExpr uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{analyzeAggregate}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3WalkerDepthIncrease}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr)
	}{Xsqlite3WalkerDepthDecrease}))
	(*Walker)(unsafe.Pointer(bp)).FwalkerDepth = 0
	*(*uintptr)(unsafe.Pointer(bp + 40)) = pNC
	(*Walker)(unsafe.Pointer(bp)).FpParse = uintptr(0)

	Xsqlite3WalkExpr(tls, bp, pExpr)
}

func Xsqlite3ExprAnalyzeAggList(tls *libc.TLS, pNC uintptr, pList uintptr) {
	var pItem uintptr
	var i int32
	if pList != 0 {
		pItem = pList + 8
		i = 0
	__1:
		if !(i < (*ExprList)(unsafe.Pointer(pList)).FnExpr) {
			goto __3
		}
		{
			Xsqlite3ExprAnalyzeAggregates(tls, pNC, (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr)

		}
		goto __2
	__2:
		i++
		pItem += 32
		goto __1
		goto __3
	__3:
	}
}

func Xsqlite3GetTempReg(tls *libc.TLS, pParse uintptr) int32 {
	if int32((*Parse)(unsafe.Pointer(pParse)).FnTempReg) == 0 {
		return libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	}
	return *(*int32)(unsafe.Pointer(pParse + 228 + uintptr(libc.PreDecUint8(&(*Parse)(unsafe.Pointer(pParse)).FnTempReg, 1))*4))
}

func Xsqlite3ReleaseTempReg(tls *libc.TLS, pParse uintptr, iReg int32) {
	if iReg != 0 {
		if int32((*Parse)(unsafe.Pointer(pParse)).FnTempReg) < int32(uint64(unsafe.Sizeof([8]int32{}))/uint64(unsafe.Sizeof(int32(0)))) {
			*(*int32)(unsafe.Pointer(pParse + 228 + uintptr(libc.PostIncUint8(&(*Parse)(unsafe.Pointer(pParse)).FnTempReg, 1))*4)) = iReg
		}
	}
}

func Xsqlite3GetTempRange(tls *libc.TLS, pParse uintptr, nReg int32) int32 {
	var i int32
	var n int32
	if nReg == 1 {
		return Xsqlite3GetTempReg(tls, pParse)
	}
	i = (*Parse)(unsafe.Pointer(pParse)).FiRangeReg
	n = (*Parse)(unsafe.Pointer(pParse)).FnRangeReg
	if nReg <= n {
		*(*int32)(unsafe.Pointer(pParse + 44)) += nReg
		*(*int32)(unsafe.Pointer(pParse + 40)) -= nReg
	} else {
		i = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nReg
	}
	return i
}

func Xsqlite3ReleaseTempRange(tls *libc.TLS, pParse uintptr, iReg int32, nReg int32) {
	if nReg == 1 {
		Xsqlite3ReleaseTempReg(tls, pParse, iReg)
		return
	}

	if nReg > (*Parse)(unsafe.Pointer(pParse)).FnRangeReg {
		(*Parse)(unsafe.Pointer(pParse)).FnRangeReg = nReg
		(*Parse)(unsafe.Pointer(pParse)).FiRangeReg = iReg
	}
}

func Xsqlite3ClearTempRegCache(tls *libc.TLS, pParse uintptr) {
	(*Parse)(unsafe.Pointer(pParse)).FnTempReg = U8(0)
	(*Parse)(unsafe.Pointer(pParse)).FnRangeReg = 0
}

func isAlterableTable(tls *libc.TLS, pParse uintptr, pTab uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if 0 == Xsqlite3_strnicmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName, ts+9596, 7) ||
		(*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Eponymous) != U32(0) ||
		(*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Shadow) != U32(0) &&
			Xsqlite3ReadOnlyShadowTables(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb) != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+11532, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
		return 1
	}
	return 0
}

func renameTestSchema(tls *libc.TLS, pParse uintptr, zDb uintptr, bTemp int32, zWhen uintptr, bNoDQS int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	(*Parse)(unsafe.Pointer(pParse)).FcolNamesSet = U8(1)
	Xsqlite3NestedParse(tls, pParse,
		ts+11560,
		libc.VaList(bp, zDb,
			zDb, bTemp, zWhen, bNoDQS))

	if bTemp == 0 {
		Xsqlite3NestedParse(tls, pParse,
			ts+11735,
			libc.VaList(bp+40, zDb, zWhen, bNoDQS))
	}
}

func renameFixQuotes(tls *libc.TLS, pParse uintptr, zDb uintptr, bTemp int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	Xsqlite3NestedParse(tls, pParse,
		ts+11909, libc.VaList(bp, zDb, zDb))
	if bTemp == 0 {
		Xsqlite3NestedParse(tls, pParse,
			ts+12056, 0)
	}
}

func renameReloadSchema(tls *libc.TLS, pParse uintptr, iDb int32, p5 U16) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	if v != 0 {
		Xsqlite3ChangeCookie(tls, pParse, iDb)
		Xsqlite3VdbeAddParseSchemaOp(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, iDb, uintptr(0), p5)
		if iDb != 1 {
			Xsqlite3VdbeAddParseSchemaOp(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, 1, uintptr(0), p5)
		}
	}
}

func Xsqlite3AlterRenameTable(tls *libc.TLS, pParse uintptr, pSrc uintptr, pName uintptr) {
	bp := tls.Alloc(184)
	defer tls.Free(184)

	var iDb int32
	var zDb uintptr
	var pTab uintptr
	var zName uintptr
	var db uintptr
	var nTabName int32
	var zTabName uintptr
	var v uintptr
	var pVTab uintptr
	var i int32
	zName = uintptr(0)
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	pVTab = uintptr(0)

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __1
	}
	goto exit_rename_table
__1:
	;
	pTab = Xsqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !!(pTab != 0) {
		goto __2
	}
	goto exit_rename_table
__2:
	;
	iDb = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Table)(unsafe.Pointer(pTab)).FpSchema)
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName

	zName = Xsqlite3NameFromToken(tls, db, pName)
	if !!(zName != 0) {
		goto __3
	}
	goto exit_rename_table
__3:
	;
	if !(Xsqlite3FindTable(tls, db, zName, zDb) != 0 ||
		Xsqlite3FindIndex(tls, db, zName, zDb) != 0 ||
		Xsqlite3IsShadowTableOf(tls, db, pTab, zName) != 0) {
		goto __4
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+12207, libc.VaList(bp, zName))
	goto exit_rename_table
__4:
	;
	if !(SQLITE_OK != isAlterableTable(tls, pParse, pTab)) {
		goto __5
	}
	goto exit_rename_table
__5:
	;
	if !(SQLITE_OK != Xsqlite3CheckObjectName(tls, pParse, zName, ts+9499, zName)) {
		goto __6
	}
	goto exit_rename_table
__6:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		goto __7
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+12266, libc.VaList(bp+8, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto exit_rename_table
__7:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_ALTER_TABLE, zDb, (*Table)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0) {
		goto __8
	}
	goto exit_rename_table
__8:
	;
	if !(Xsqlite3ViewGetColumnNames(tls, pParse, pTab) != 0) {
		goto __9
	}
	goto exit_rename_table
__9:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __10
	}
	pVTab = Xsqlite3GetVTable(tls, db, pTab)
	if !((*Sqlite3_module)(unsafe.Pointer((*Sqlite3_vtab)(unsafe.Pointer((*VTable)(unsafe.Pointer(pVTab)).FpVtab)).FpModule)).FxRename == uintptr(0)) {
		goto __11
	}
	pVTab = uintptr(0)
__11:
	;
__10:
	;
	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v == uintptr(0)) {
		goto __12
	}
	goto exit_rename_table
__12:
	;
	Xsqlite3MayAbort(tls, pParse)

	zTabName = (*Table)(unsafe.Pointer(pTab)).FzName
	nTabName = Xsqlite3Utf8CharLen(tls, zTabName, -1)

	Xsqlite3NestedParse(tls, pParse,
		ts+12293, libc.VaList(bp+16, zDb, zDb, zTabName, zName, libc.Bool32(iDb == 1), zTabName))

	Xsqlite3NestedParse(tls, pParse,
		ts+12477,
		libc.VaList(bp+64, zDb,
			zName, zName, zName,
			nTabName, zTabName))

	if !(Xsqlite3FindTable(tls, db, ts+12782, zDb) != 0) {
		goto __13
	}
	Xsqlite3NestedParse(tls, pParse,
		ts+12798,
		libc.VaList(bp+112, zDb, zName, (*Table)(unsafe.Pointer(pTab)).FzName))
__13:
	;
	if !(iDb != 1) {
		goto __14
	}
	Xsqlite3NestedParse(tls, pParse,
		ts+12856, libc.VaList(bp+136, zDb, zTabName, zName, zTabName, zDb, zName))
__14:
	;
	if !(pVTab != 0) {
		goto __15
	}
	i = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeLoadString(tls, v, i, zName)
	Xsqlite3VdbeAddOp4(tls, v, OP_VRename, i, 0, 0, pVTab, -11)
__15:
	;
	renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterRename))
	renameTestSchema(tls, pParse, zDb, libc.Bool32(iDb == 1), ts+13121, 0)

exit_rename_table:
	Xsqlite3SrcListDelete(tls, db, pSrc)
	Xsqlite3DbFree(tls, db, zName)
}

func sqlite3ErrorIfNotEmpty(tls *libc.TLS, pParse uintptr, zDb uintptr, zTab uintptr, zErr uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	Xsqlite3NestedParse(tls, pParse,
		ts+13134,
		libc.VaList(bp, zErr, zDb, zTab))
}

func Xsqlite3AlterFinishAddColumn(tls *libc.TLS, pParse uintptr, pColDef uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var pNew uintptr
	var pTab uintptr
	var iDb int32
	var zDb uintptr
	var zTab uintptr
	var zCol uintptr
	var pCol uintptr
	var pDflt uintptr
	var db uintptr
	var v uintptr
	var r1 int32

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}

	pNew = (*Parse)(unsafe.Pointer(pParse)).FpNewTable

	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pNew)).FpSchema)
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	zTab = (*Table)(unsafe.Pointer(pNew)).FzName + 16
	pCol = (*Table)(unsafe.Pointer(pNew)).FaCol + uintptr(int32((*Table)(unsafe.Pointer(pNew)).FnCol)-1)*24
	pDflt = Xsqlite3ColumnExpr(tls, pNew, pCol)
	pTab = Xsqlite3FindTable(tls, db, zTab, zDb)

	if Xsqlite3AuthCheck(tls, pParse, SQLITE_ALTER_TABLE, zDb, (*Table)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
		return
	}

	if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_PRIMKEY != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+13172, 0)
		return
	}
	if (*Table)(unsafe.Pointer(pNew)).FpIndex != 0 {
		Xsqlite3ErrorMsg(tls, pParse,
			ts+13204, 0)
		return
	}
	if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_GENERATED == 0 {
		if pDflt != 0 && int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pDflt)).FpLeft)).Fop) == TK_NULL {
			pDflt = uintptr(0)
		}

		if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && *(*uintptr)(unsafe.Pointer(pNew + 64 + 8)) != 0 && pDflt != 0 {
			sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab,
				ts+13231)
		}
		if uint32(int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) != 0 && !(pDflt != 0) {
			sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab,
				ts+13290)
		}

		if pDflt != 0 {
			*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
			var rc int32
			rc = Xsqlite3ValueFromExpr(tls, db, pDflt, uint8(SQLITE_UTF8), uint8(SQLITE_AFF_BLOB), bp+56)

			if rc != SQLITE_OK {
				return
			}
			if !(*(*uintptr)(unsafe.Pointer(bp + 56)) != 0) {
				sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab,
					ts+13343)
			}
			Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp + 56)))
		}
	} else if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_STORED != 0 {
		sqlite3ErrorIfNotEmpty(tls, pParse, zDb, zTab, ts+13389)
	}

	zCol = Xsqlite3DbStrNDup(tls, db, (*Token)(unsafe.Pointer(pColDef)).Fz, uint64((*Token)(unsafe.Pointer(pColDef)).Fn))
	if zCol != 0 {
		var zEnd uintptr = zCol + uintptr((*Token)(unsafe.Pointer(pColDef)).Fn-uint32(1))
		for zEnd > zCol && (int32(*(*uint8)(unsafe.Pointer(zEnd))) == ';' || int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zEnd))])&0x01 != 0) {
			*(*uint8)(unsafe.Pointer(libc.PostDecUintptr(&zEnd, 1))) = uint8(0)
		}

		Xsqlite3NestedParse(tls, pParse,
			ts+13416,
			libc.VaList(bp, zDb, *(*int32)(unsafe.Pointer(pNew + 64)), zCol, *(*int32)(unsafe.Pointer(pNew + 64)),
				zTab))
		Xsqlite3DbFree(tls, db, zCol)
	}

	v = Xsqlite3GetVdbe(tls, pParse)
	if v != 0 {
		r1 = Xsqlite3GetTempReg(tls, pParse)
		Xsqlite3VdbeAddOp3(tls, v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT)
		Xsqlite3VdbeUsesBtree(tls, v, iDb)
		Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, r1, -2)
		Xsqlite3VdbeAddOp2(tls, v, OP_IfPos, r1, Xsqlite3VdbeCurrentAddr(tls, v)+2)

		Xsqlite3VdbeAddOp3(tls, v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, 3)
		Xsqlite3ReleaseTempReg(tls, pParse, r1)

		renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterAdd))

		if (*Table)(unsafe.Pointer(pNew)).FpCheck != uintptr(0) ||
			uint32(int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) != 0 && int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_GENERATED != 0 {
			Xsqlite3NestedParse(tls, pParse,
				ts+13562,
				libc.VaList(bp+40, zTab, zDb))
		}
	}
}

func Xsqlite3AlterBeginAddColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pNew uintptr
	var pTab uintptr
	var iDb int32
	var i int32
	var nAlloc int32
	var db uintptr
	var pCol uintptr
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __1
	}
	goto exit_begin_add_column
__1:
	;
	pTab = Xsqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !!(pTab != 0) {
		goto __2
	}
	goto exit_begin_add_column
__2:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __3
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+13792, 0)
	goto exit_begin_add_column
__3:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		goto __4
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+13826, 0)
	goto exit_begin_add_column
__4:
	;
	if !(SQLITE_OK != isAlterableTable(tls, pParse, pTab)) {
		goto __5
	}
	goto exit_begin_add_column
__5:
	;
	Xsqlite3MayAbort(tls, pParse)

	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	pNew = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Table{})))
	if !!(pNew != 0) {
		goto __6
	}
	goto exit_begin_add_column
__6:
	;
	(*Parse)(unsafe.Pointer(pParse)).FpNewTable = pNew
	(*Table)(unsafe.Pointer(pNew)).FnTabRef = U32(1)
	(*Table)(unsafe.Pointer(pNew)).FnCol = (*Table)(unsafe.Pointer(pTab)).FnCol

	nAlloc = (int32((*Table)(unsafe.Pointer(pNew)).FnCol)-1)/8*8 + 8

	(*Table)(unsafe.Pointer(pNew)).FaCol = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Column{}))*uint64(nAlloc))
	(*Table)(unsafe.Pointer(pNew)).FzName = Xsqlite3MPrintf(tls, db, ts+13856, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
	if !(!(int32((*Table)(unsafe.Pointer(pNew)).FaCol) != 0) || !(int32((*Table)(unsafe.Pointer(pNew)).FzName) != 0)) {
		goto __7
	}

	goto exit_begin_add_column
__7:
	;
	libc.Xmemcpy(tls, (*Table)(unsafe.Pointer(pNew)).FaCol, (*Table)(unsafe.Pointer(pTab)).FaCol, uint64(unsafe.Sizeof(Column{}))*uint64((*Table)(unsafe.Pointer(pNew)).FnCol))
	i = 0
__8:
	if !(i < int32((*Table)(unsafe.Pointer(pNew)).FnCol)) {
		goto __10
	}
	pCol = (*Table)(unsafe.Pointer(pNew)).FaCol + uintptr(i)*24
	(*Column)(unsafe.Pointer(pCol)).FzCnName = Xsqlite3DbStrDup(tls, db, (*Column)(unsafe.Pointer(pCol)).FzCnName)
	(*Column)(unsafe.Pointer(pCol)).FhName = Xsqlite3StrIHash(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName)
	goto __9
__9:
	i++
	goto __8
	goto __10
__10:
	;
	*(*uintptr)(unsafe.Pointer(pNew + 64 + 16)) = Xsqlite3ExprListDup(tls, db, *(*uintptr)(unsafe.Pointer(pTab + 64 + 16)), 0)
	(*Table)(unsafe.Pointer(pNew)).FpSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
	*(*int32)(unsafe.Pointer(pNew + 64)) = *(*int32)(unsafe.Pointer(pTab + 64))
	(*Table)(unsafe.Pointer(pNew)).FnTabRef = U32(1)

exit_begin_add_column:
	Xsqlite3SrcListDelete(tls, db, pSrc)
	return
}

func isRealTable(tls *libc.TLS, pParse uintptr, pTab uintptr, bDrop int32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var zType uintptr = uintptr(0)
	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW {
		zType = ts + 13875
	}
	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
		zType = ts + 13880
	}
	if zType != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+13894,
			libc.VaList(bp, func() uintptr {
				if bDrop != 0 {
					return ts + 13912
				}
				return ts + 13929
			}(),
				zType, (*Table)(unsafe.Pointer(pTab)).FzName))
		return 1
	}
	return 0
}

func Xsqlite3AlterRenameColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr, pOld uintptr, pNew uintptr) {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	var db uintptr
	var pTab uintptr
	var iCol int32
	var zOld uintptr
	var zNew uintptr
	var zDb uintptr
	var iSchema int32
	var bQuote int32
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	zOld = uintptr(0)
	zNew = uintptr(0)

	pTab = Xsqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !!(pTab != 0) {
		goto __1
	}
	goto exit_rename_column
__1:
	;
	if !(SQLITE_OK != isAlterableTable(tls, pParse, pTab)) {
		goto __2
	}
	goto exit_rename_column
__2:
	;
	if !(SQLITE_OK != isRealTable(tls, pParse, pTab, 0)) {
		goto __3
	}
	goto exit_rename_column
__3:
	;
	iSchema = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iSchema)*32)).FzDbSName

	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_ALTER_TABLE, zDb, (*Table)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0) {
		goto __4
	}
	goto exit_rename_column
__4:
	;
	zOld = Xsqlite3NameFromToken(tls, db, pOld)
	if !!(zOld != 0) {
		goto __5
	}
	goto exit_rename_column
__5:
	;
	iCol = 0
__6:
	if !(iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __8
	}
	if !(0 == Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FzCnName, zOld)) {
		goto __9
	}
	goto __8
__9:
	;
	goto __7
__7:
	iCol++
	goto __6
	goto __8
__8:
	;
	if !(iCol == int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __10
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+13947, libc.VaList(bp, pOld))
	goto exit_rename_column
__10:
	;
	renameTestSchema(tls, pParse, zDb, libc.Bool32(iSchema == 1), ts+1636, 0)
	renameFixQuotes(tls, pParse, zDb, libc.Bool32(iSchema == 1))

	Xsqlite3MayAbort(tls, pParse)
	zNew = Xsqlite3NameFromToken(tls, db, pNew)
	if !!(zNew != 0) {
		goto __11
	}
	goto exit_rename_column
__11:
	;
	bQuote = int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(pNew)).Fz))]) & 0x80
	Xsqlite3NestedParse(tls, pParse,
		ts+13968,
		libc.VaList(bp+8, zDb,
			zDb, (*Table)(unsafe.Pointer(pTab)).FzName, iCol, zNew, bQuote, libc.Bool32(iSchema == 1),
			(*Table)(unsafe.Pointer(pTab)).FzName))

	Xsqlite3NestedParse(tls, pParse,
		ts+14150,
		libc.VaList(bp+72, zDb, (*Table)(unsafe.Pointer(pTab)).FzName, iCol, zNew, bQuote))

	renameReloadSchema(tls, pParse, iSchema, uint16(INITFLAG_AlterRename))
	renameTestSchema(tls, pParse, zDb, libc.Bool32(iSchema == 1), ts+13121, 1)

exit_rename_column:
	Xsqlite3SrcListDelete(tls, db, pSrc)
	Xsqlite3DbFree(tls, db, zOld)
	Xsqlite3DbFree(tls, db, zNew)
	return
}

type RenameCtx = RenameCtx1

func Xsqlite3RenameTokenMap(tls *libc.TLS, pParse uintptr, pPtr uintptr, pToken uintptr) uintptr {
	var pNew uintptr

	if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_UNMAP {
		pNew = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(RenameToken{})))
		if pNew != 0 {
			(*RenameToken)(unsafe.Pointer(pNew)).Fp = pPtr
			(*RenameToken)(unsafe.Pointer(pNew)).Ft = *(*Token)(unsafe.Pointer(pToken))
			(*RenameToken)(unsafe.Pointer(pNew)).FpNext = (*Parse)(unsafe.Pointer(pParse)).FpRename
			(*Parse)(unsafe.Pointer(pParse)).FpRename = pNew
		}
	}

	return pPtr
}

func Xsqlite3RenameTokenRemap(tls *libc.TLS, pParse uintptr, pTo uintptr, pFrom uintptr) {
	var p uintptr

	for p = (*Parse)(unsafe.Pointer(pParse)).FpRename; p != 0; p = (*RenameToken)(unsafe.Pointer(p)).FpNext {
		if (*RenameToken)(unsafe.Pointer(p)).Fp == pFrom {
			(*RenameToken)(unsafe.Pointer(p)).Fp = pTo
			break
		}
	}
}

func renameUnmapExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var pParse uintptr = (*Walker)(unsafe.Pointer(pWalker)).FpParse
	Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr)
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc|EP_Subrtn) == U32(0) {
		Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), pExpr+64)
	}
	return WRC_Continue
}

func renameWalkWith(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var pWith uintptr = (*Select)(unsafe.Pointer(pSelect)).FpWith
	if pWith != 0 {
		var pParse uintptr = (*Walker)(unsafe.Pointer(pWalker)).FpParse
		var i int32
		var pCopy uintptr = uintptr(0)

		if (*Select)(unsafe.Pointer((*Cte)(unsafe.Pointer(pWith+16)).FpSelect)).FselFlags&U32(SF_Expanded) == U32(0) {
			pCopy = Xsqlite3WithDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pWith)
			pCopy = Xsqlite3WithPush(tls, pParse, pCopy, uint8(1))
		}
		for i = 0; i < (*With)(unsafe.Pointer(pWith)).FnCte; i++ {
			var p uintptr = (*Cte)(unsafe.Pointer(pWith + 16 + uintptr(i)*48)).FpSelect

			libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(NameContext{})))
			(*NameContext)(unsafe.Pointer(bp)).FpParse = pParse
			if pCopy != 0 {
				Xsqlite3SelectPrep(tls, (*NameContext)(unsafe.Pointer(bp)).FpParse, p, bp)
			}
			if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer((*NameContext)(unsafe.Pointer(bp)).FpParse)).Fdb)).FmallocFailed != 0 {
				return
			}
			Xsqlite3WalkSelect(tls, pWalker, p)
			Xsqlite3RenameExprlistUnmap(tls, pParse, (*Cte)(unsafe.Pointer(pWith+16+uintptr(i)*48)).FpCols)
		}
		if pCopy != 0 && (*Parse)(unsafe.Pointer(pParse)).FpWith == pCopy {
			(*Parse)(unsafe.Pointer(pParse)).FpWith = (*With)(unsafe.Pointer(pCopy)).FpOuter
		}
	}
}

func unmapColumnIdlistNames(tls *libc.TLS, pParse uintptr, pIdList uintptr) {
	var ii int32

	for ii = 0; ii < (*IdList)(unsafe.Pointer(pIdList)).FnId; ii++ {
		Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*IdList_item)(unsafe.Pointer(pIdList+8+uintptr(ii)*16)).FzName)
	}
}

func renameUnmapSelectCb(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	var pParse uintptr = (*Walker)(unsafe.Pointer(pWalker)).FpParse
	var i int32
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return WRC_Abort
	}

	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_View|SF_CopyCte) != 0 {
		return WRC_Prune
	}
	if (*Select)(unsafe.Pointer(p)).FpEList != 0 {
		var pList uintptr = (*Select)(unsafe.Pointer(p)).FpEList
		for i = 0; i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
			if (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FzEName != 0 && int32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*32 + 16 + 4))&0x3>>0) == ENAME_NAME {
				Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FzEName)
			}
		}
	}
	if (*Select)(unsafe.Pointer(p)).FpSrc != 0 {
		var pSrc uintptr = (*Select)(unsafe.Pointer(p)).FpSrc
		for i = 0; i < (*SrcList)(unsafe.Pointer(pSrc)).FnSrc; i++ {
			Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*SrcItem)(unsafe.Pointer(pSrc+8+uintptr(i)*104)).FzName)
			if int32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104 + 60 + 4))&0x400>>10) == 0 {
				Xsqlite3WalkExpr(tls, pWalker, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104 + 72)))
			} else {
				unmapColumnIdlistNames(tls, pParse, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104 + 72)))
			}
		}
	}

	renameWalkWith(tls, pWalker, p)
	return WRC_Continue
}

func Xsqlite3RenameExprUnmap(tls *libc.TLS, pParse uintptr, pExpr uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var eMode U8 = (*Parse)(unsafe.Pointer(pParse)).FeParseMode

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(bp)).FpParse = pParse
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{renameUnmapExprCb}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{renameUnmapSelectCb}))
	(*Parse)(unsafe.Pointer(pParse)).FeParseMode = U8(PARSE_MODE_UNMAP)
	Xsqlite3WalkExpr(tls, bp, pExpr)
	(*Parse)(unsafe.Pointer(pParse)).FeParseMode = eMode
}

func Xsqlite3RenameExprlistUnmap(tls *libc.TLS, pParse uintptr, pEList uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if pEList != 0 {
		var i int32

		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
		(*Walker)(unsafe.Pointer(bp)).FpParse = pParse
		(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		}{renameUnmapExprCb}))
		Xsqlite3WalkExprList(tls, bp, pEList)
		for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
			if int32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0x3>>0) == ENAME_NAME {
				Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(i)*32)).FzEName)
			}
		}
	}
}

func renameTokenFree(tls *libc.TLS, db uintptr, pToken uintptr) {
	var pNext uintptr
	var p uintptr
	for p = pToken; p != 0; p = pNext {
		pNext = (*RenameToken)(unsafe.Pointer(p)).FpNext
		Xsqlite3DbFree(tls, db, p)
	}
}

func renameTokenFind(tls *libc.TLS, pParse uintptr, pCtx uintptr, pPtr uintptr) uintptr {
	var pp uintptr
	if pPtr == uintptr(0) {
		return uintptr(0)
	}
	for pp = pParse + 416; *(*uintptr)(unsafe.Pointer(pp)) != 0; pp = *(*uintptr)(unsafe.Pointer(pp)) + 24 {
		if (*RenameToken)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).Fp == pPtr {
			var pToken uintptr = *(*uintptr)(unsafe.Pointer(pp))
			if pCtx != 0 {
				*(*uintptr)(unsafe.Pointer(pp)) = (*RenameToken)(unsafe.Pointer(pToken)).FpNext
				(*RenameToken)(unsafe.Pointer(pToken)).FpNext = (*RenameCtx1)(unsafe.Pointer(pCtx)).FpList
				(*RenameCtx1)(unsafe.Pointer(pCtx)).FpList = pToken
				(*RenameCtx1)(unsafe.Pointer(pCtx)).FnList++
			}
			return pToken
		}
	}
	return uintptr(0)
}

func renameColumnSelectCb(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_View|SF_CopyCte) != 0 {
		return WRC_Prune
	}
	renameWalkWith(tls, pWalker, p)
	return WRC_Continue
}

func renameColumnExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var p uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_TRIGGER &&
		int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) == (*RenameCtx)(unsafe.Pointer(p)).FiCol &&
		(*Parse)(unsafe.Pointer((*Walker)(unsafe.Pointer(pWalker)).FpParse)).FpTriggerTab == (*RenameCtx)(unsafe.Pointer(p)).FpTab {
		renameTokenFind(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse, p, pExpr)
	} else if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN &&
		int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) == (*RenameCtx)(unsafe.Pointer(p)).FiCol &&
		(*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc|EP_Subrtn) == U32(0) &&
		(*RenameCtx)(unsafe.Pointer(p)).FpTab == *(*uintptr)(unsafe.Pointer(pExpr + 64)) {
		renameTokenFind(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse, p, pExpr)
	}
	return WRC_Continue
}

func renameColumnTokenNext(tls *libc.TLS, pCtx uintptr) uintptr {
	var pBest uintptr = (*RenameCtx)(unsafe.Pointer(pCtx)).FpList
	var pToken uintptr
	var pp uintptr

	for pToken = (*RenameToken)(unsafe.Pointer(pBest)).FpNext; pToken != 0; pToken = (*RenameToken)(unsafe.Pointer(pToken)).FpNext {
		if (*RenameToken)(unsafe.Pointer(pToken)).Ft.Fz > (*RenameToken)(unsafe.Pointer(pBest)).Ft.Fz {
			pBest = pToken
		}
	}
	for pp = pCtx; *(*uintptr)(unsafe.Pointer(pp)) != pBest; pp = *(*uintptr)(unsafe.Pointer(pp)) + 24 {
	}
	*(*uintptr)(unsafe.Pointer(pp)) = (*RenameToken)(unsafe.Pointer(pBest)).FpNext

	return pBest
}

func renameColumnParseError(tls *libc.TLS, pCtx uintptr, zWhen uintptr, pType uintptr, pObject uintptr, pParse uintptr) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var zT uintptr = Xsqlite3_value_text(tls, pType)
	var zN uintptr = Xsqlite3_value_text(tls, pObject)
	var zErr uintptr

	zErr = Xsqlite3MPrintf(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, ts+14281,
		libc.VaList(bp, zT, zN, func() uintptr {
			if *(*uint8)(unsafe.Pointer(zWhen)) != 0 {
				return ts + 14304
			}
			return ts + 1636
		}(), zWhen,
			(*Parse)(unsafe.Pointer(pParse)).FzErrMsg))
	Xsqlite3_result_error(tls, pCtx, zErr, -1)
	Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, zErr)
}

func renameColumnElistNames(tls *libc.TLS, pParse uintptr, pCtx uintptr, pEList uintptr, zOld uintptr) {
	if pEList != 0 {
		var i int32
		for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
			var zName uintptr = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32)).FzEName
			if int32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0x3>>0) == ENAME_NAME &&
				zName != uintptr(0) &&
				0 == Xsqlite3_stricmp(tls, zName, zOld) {
				renameTokenFind(tls, pParse, pCtx, zName)
			}
		}
	}
}

func renameColumnIdlistNames(tls *libc.TLS, pParse uintptr, pCtx uintptr, pIdList uintptr, zOld uintptr) {
	if pIdList != 0 {
		var i int32
		for i = 0; i < (*IdList)(unsafe.Pointer(pIdList)).FnId; i++ {
			var zName uintptr = (*IdList_item)(unsafe.Pointer(pIdList + 8 + uintptr(i)*16)).FzName
			if 0 == Xsqlite3_stricmp(tls, zName, zOld) {
				renameTokenFind(tls, pParse, pCtx, zName)
			}
		}
	}
}

func renameParseSql(tls *libc.TLS, p uintptr, zDb uintptr, db uintptr, zSql uintptr, bTemp int32) int32 {
	var rc int32

	Xsqlite3ParseObjectInit(tls, p, db)
	if zSql == uintptr(0) {
		return SQLITE_NOMEM
	}
	if Xsqlite3_strnicmp(tls, zSql, ts+14306, 7) != 0 {
		return Xsqlite3CorruptError(tls, 113516)
	}
	(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = func() uint8 {
		if bTemp != 0 {
			return uint8(1)
		}
		return uint8(Xsqlite3FindDbName(tls, db, zDb))
	}()
	(*Parse)(unsafe.Pointer(p)).FeParseMode = U8(PARSE_MODE_RENAME)
	(*Parse)(unsafe.Pointer(p)).Fdb = db
	(*Parse)(unsafe.Pointer(p)).FnQueryLoop = U32(1)
	rc = Xsqlite3RunParser(tls, p, zSql)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		rc = SQLITE_NOMEM
	}
	if rc == SQLITE_OK &&
		((*Parse)(unsafe.Pointer(p)).FpNewTable == uintptr(0) && (*Parse)(unsafe.Pointer(p)).FpNewIndex == uintptr(0) && (*Parse)(unsafe.Pointer(p)).FpNewTrigger == uintptr(0)) {
		rc = Xsqlite3CorruptError(tls, 113527)
	}

	(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = U8(0)
	return rc
}

func renameEditSql(tls *libc.TLS, pCtx uintptr, pRename uintptr, zSql uintptr, zNew uintptr, bQuote int32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var nNew I64 = I64(Xsqlite3Strlen30(tls, zNew))
	var nSql I64 = I64(Xsqlite3Strlen30(tls, zSql))
	var db uintptr = Xsqlite3_context_db_handle(tls, pCtx)
	var rc int32 = SQLITE_OK
	var zQuot uintptr = uintptr(0)
	var zOut uintptr
	var nQuot I64 = int64(0)
	var zBuf1 uintptr = uintptr(0)
	var zBuf2 uintptr = uintptr(0)

	if zNew != 0 {
		zQuot = Xsqlite3MPrintf(tls, db, ts+14314, libc.VaList(bp, zNew))
		if zQuot == uintptr(0) {
			return SQLITE_NOMEM
		} else {
			nQuot = I64(Xsqlite3Strlen30(tls, zQuot) - 1)
		}

		zOut = Xsqlite3DbMallocZero(tls, db, uint64(nSql+I64((*RenameCtx)(unsafe.Pointer(pRename)).FnList)*nQuot+int64(1)))
	} else {
		zOut = Xsqlite3DbMallocZero(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))
		}
	}

	if zOut != 0 {
		var nOut int32 = int32(nSql)
		libc.Xmemcpy(tls, zOut, zSql, uint64(nSql))
		for (*RenameCtx)(unsafe.Pointer(pRename)).FpList != 0 {
			var iOff int32
			var nReplace U32
			var zReplace uintptr
			var pBest uintptr = renameColumnTokenNext(tls, pRename)

			if zNew != 0 {
				if bQuote == 0 && Xsqlite3IsIdChar(tls, *(*uint8)(unsafe.Pointer((*RenameToken)(unsafe.Pointer(pBest)).Ft.Fz))) != 0 {
					nReplace = U32(nNew)
					zReplace = zNew
				} else {
					nReplace = U32(nQuot)
					zReplace = zQuot
					if int32(*(*uint8)(unsafe.Pointer((*RenameToken)(unsafe.Pointer(pBest)).Ft.Fz + uintptr((*RenameToken)(unsafe.Pointer(pBest)).Ft.Fn)))) == '"' {
						nReplace++
					}
				}
			} else {
				libc.Xmemcpy(tls, zBuf1, (*RenameToken)(unsafe.Pointer(pBest)).Ft.Fz, uint64((*RenameToken)(unsafe.Pointer(pBest)).Ft.Fn))
				*(*uint8)(unsafe.Pointer(zBuf1 + uintptr((*RenameToken)(unsafe.Pointer(pBest)).Ft.Fn))) = uint8(0)
				Xsqlite3Dequote(tls, zBuf1)
				Xsqlite3_snprintf(tls, int32(nSql*int64(2)), zBuf2, ts+14320, libc.VaList(bp+8, zBuf1,
					func() uintptr {
						if int32(*(*uint8)(unsafe.Pointer((*RenameToken)(unsafe.Pointer(pBest)).Ft.Fz + uintptr((*RenameToken)(unsafe.Pointer(pBest)).Ft.Fn)))) == '\'' {
							return ts + 14304
						}
						return ts + 1636
					}()))
				zReplace = zBuf2
				nReplace = U32(Xsqlite3Strlen30(tls, zReplace))
			}

			iOff = int32((int64((*RenameToken)(unsafe.Pointer(pBest)).Ft.Fz) - int64(zSql)) / 1)
			if (*RenameToken)(unsafe.Pointer(pBest)).Ft.Fn != nReplace {
				libc.Xmemmove(tls, zOut+uintptr(U32(iOff)+nReplace), zOut+uintptr(uint32(iOff)+(*RenameToken)(unsafe.Pointer(pBest)).Ft.Fn),
					uint64(uint32(nOut)-(uint32(iOff)+(*RenameToken)(unsafe.Pointer(pBest)).Ft.Fn)))
				nOut = int32(U32(nOut) + (nReplace - (*RenameToken)(unsafe.Pointer(pBest)).Ft.Fn))
				*(*uint8)(unsafe.Pointer(zOut + uintptr(nOut))) = uint8(0)
			}
			libc.Xmemcpy(tls, zOut+uintptr(iOff), zReplace, uint64(nReplace))
			Xsqlite3DbFree(tls, db, pBest)
		}

		Xsqlite3_result_text(tls, pCtx, zOut, -1, libc.UintptrFromInt32(-1))
		Xsqlite3DbFree(tls, db, zOut)
	} else {
		rc = SQLITE_NOMEM
	}

	Xsqlite3_free(tls, zQuot)
	return rc
}

func renameResolveTrigger(tls *libc.TLS, pParse uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pNew uintptr = (*Parse)(unsafe.Pointer(pParse)).FpNewTrigger
	var pStep uintptr

	var rc int32 = SQLITE_OK

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp)).FpParse = pParse

	(*Parse)(unsafe.Pointer(pParse)).FpTriggerTab = Xsqlite3FindTable(tls, db, (*Trigger)(unsafe.Pointer(pNew)).Ftable,
		(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(Xsqlite3SchemaToIndex(tls, db, (*Trigger)(unsafe.Pointer(pNew)).FpTabSchema))*32)).FzDbSName)
	(*Parse)(unsafe.Pointer(pParse)).FeTriggerOp = (*Trigger)(unsafe.Pointer(pNew)).Fop

	if (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab != 0 {
		rc = Xsqlite3ViewGetColumnNames(tls, pParse, (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab)
	}

	if rc == SQLITE_OK && (*Trigger)(unsafe.Pointer(pNew)).FpWhen != 0 {
		rc = Xsqlite3ResolveExprNames(tls, bp, (*Trigger)(unsafe.Pointer(pNew)).FpWhen)
	}

	for pStep = (*Trigger)(unsafe.Pointer(pNew)).Fstep_list; rc == SQLITE_OK && pStep != 0; pStep = (*TriggerStep)(unsafe.Pointer(pStep)).FpNext {
		if (*TriggerStep)(unsafe.Pointer(pStep)).FpSelect != 0 {
			Xsqlite3SelectPrep(tls, pParse, (*TriggerStep)(unsafe.Pointer(pStep)).FpSelect, bp)
			if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
				rc = (*Parse)(unsafe.Pointer(pParse)).Frc
			}
		}
		if rc == SQLITE_OK && (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget != 0 {
			var pSrc uintptr = Xsqlite3TriggerStepSrc(tls, pParse, pStep)
			if pSrc != 0 {
				var pSel uintptr = Xsqlite3SelectNew(tls,
					pParse, (*TriggerStep)(unsafe.Pointer(pStep)).FpExprList, pSrc, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
				if pSel == uintptr(0) {
					(*TriggerStep)(unsafe.Pointer(pStep)).FpExprList = uintptr(0)
					pSrc = uintptr(0)
					rc = SQLITE_NOMEM
				} else {
					Xsqlite3SelectPrep(tls, pParse, pSel, uintptr(0))
					if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
						rc = SQLITE_ERROR
					} else {
						rc = SQLITE_OK
					}

					if (*TriggerStep)(unsafe.Pointer(pStep)).FpExprList != 0 {
						(*Select)(unsafe.Pointer(pSel)).FpEList = uintptr(0)
					}
					(*Select)(unsafe.Pointer(pSel)).FpSrc = uintptr(0)
					Xsqlite3SelectDelete(tls, db, pSel)
				}
				if (*TriggerStep)(unsafe.Pointer(pStep)).FpFrom != 0 {
					var i int32
					for i = 0; i < (*SrcList)(unsafe.Pointer((*TriggerStep)(unsafe.Pointer(pStep)).FpFrom)).FnSrc && rc == SQLITE_OK; i++ {
						var p uintptr = (*TriggerStep)(unsafe.Pointer(pStep)).FpFrom + 8 + uintptr(i)*104
						if (*SrcItem)(unsafe.Pointer(p)).FpSelect != 0 {
							Xsqlite3SelectPrep(tls, pParse, (*SrcItem)(unsafe.Pointer(p)).FpSelect, uintptr(0))
						}
					}
				}

				if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
					rc = SQLITE_NOMEM
				}
				(*NameContext)(unsafe.Pointer(bp)).FpSrcList = pSrc
				if rc == SQLITE_OK && (*TriggerStep)(unsafe.Pointer(pStep)).FpWhere != 0 {
					rc = Xsqlite3ResolveExprNames(tls, bp, (*TriggerStep)(unsafe.Pointer(pStep)).FpWhere)
				}
				if rc == SQLITE_OK {
					rc = Xsqlite3ResolveExprListNames(tls, bp, (*TriggerStep)(unsafe.Pointer(pStep)).FpExprList)
				}

				if (*TriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 && rc == SQLITE_OK {
					var pUpsert uintptr = (*TriggerStep)(unsafe.Pointer(pStep)).FpUpsert
					(*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertSrc = pSrc
					*(*uintptr)(unsafe.Pointer(bp + 16)) = pUpsert
					(*NameContext)(unsafe.Pointer(bp)).FncFlags = NC_UUpsert
					rc = Xsqlite3ResolveExprListNames(tls, bp, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
					if rc == SQLITE_OK {
						var pUpsertSet uintptr = (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertSet
						rc = Xsqlite3ResolveExprListNames(tls, bp, pUpsertSet)
					}
					if rc == SQLITE_OK {
						rc = Xsqlite3ResolveExprNames(tls, bp, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere)
					}
					if rc == SQLITE_OK {
						rc = Xsqlite3ResolveExprNames(tls, bp, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
					}
					(*NameContext)(unsafe.Pointer(bp)).FncFlags = 0
				}
				(*NameContext)(unsafe.Pointer(bp)).FpSrcList = uintptr(0)
				Xsqlite3SrcListDelete(tls, db, pSrc)
			} else {
				rc = SQLITE_NOMEM
			}
		}
	}
	return rc
}

func renameWalkTrigger(tls *libc.TLS, pWalker uintptr, pTrigger uintptr) {
	var pStep uintptr

	Xsqlite3WalkExpr(tls, pWalker, (*Trigger)(unsafe.Pointer(pTrigger)).FpWhen)

	for pStep = (*Trigger)(unsafe.Pointer(pTrigger)).Fstep_list; pStep != 0; pStep = (*TriggerStep)(unsafe.Pointer(pStep)).FpNext {
		Xsqlite3WalkSelect(tls, pWalker, (*TriggerStep)(unsafe.Pointer(pStep)).FpSelect)
		Xsqlite3WalkExpr(tls, pWalker, (*TriggerStep)(unsafe.Pointer(pStep)).FpWhere)
		Xsqlite3WalkExprList(tls, pWalker, (*TriggerStep)(unsafe.Pointer(pStep)).FpExprList)
		if (*TriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 {
			var pUpsert uintptr = (*TriggerStep)(unsafe.Pointer(pStep)).FpUpsert
			Xsqlite3WalkExprList(tls, pWalker, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
			Xsqlite3WalkExprList(tls, pWalker, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertSet)
			Xsqlite3WalkExpr(tls, pWalker, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere)
			Xsqlite3WalkExpr(tls, pWalker, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
		}
		if (*TriggerStep)(unsafe.Pointer(pStep)).FpFrom != 0 {
			var i int32
			for i = 0; i < (*SrcList)(unsafe.Pointer((*TriggerStep)(unsafe.Pointer(pStep)).FpFrom)).FnSrc; i++ {
				Xsqlite3WalkSelect(tls, pWalker, (*SrcItem)(unsafe.Pointer((*TriggerStep)(unsafe.Pointer(pStep)).FpFrom+8+uintptr(i)*104)).FpSelect)
			}
		}
	}
}

func renameParseCleanup(tls *libc.TLS, pParse uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pIdx uintptr
	if (*Parse)(unsafe.Pointer(pParse)).FpVdbe != 0 {
		Xsqlite3VdbeFinalize(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe)
	}
	Xsqlite3DeleteTable(tls, db, (*Parse)(unsafe.Pointer(pParse)).FpNewTable)
	for libc.AssignUintptr(&pIdx, (*Parse)(unsafe.Pointer(pParse)).FpNewIndex) != uintptr(0) {
		(*Parse)(unsafe.Pointer(pParse)).FpNewIndex = (*Index)(unsafe.Pointer(pIdx)).FpNext
		Xsqlite3FreeIndex(tls, db, pIdx)
	}
	Xsqlite3DeleteTrigger(tls, db, (*Parse)(unsafe.Pointer(pParse)).FpNewTrigger)
	Xsqlite3DbFree(tls, db, (*Parse)(unsafe.Pointer(pParse)).FzErrMsg)
	renameTokenFree(tls, db, (*Parse)(unsafe.Pointer(pParse)).FpRename)
	Xsqlite3ParseObjectReset(tls, pParse)
}

func renameColumnFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(504)
	defer tls.Free(504)

	var db uintptr

	var zSql uintptr
	var zDb uintptr
	var zTable uintptr
	var iCol int32
	var zNew uintptr
	var bQuote int32
	var bTemp int32
	var zOld uintptr
	var rc int32

	var pIdx uintptr
	var i int32
	var pTab uintptr
	var xAuth Sqlite3_xauth
	var pSelect uintptr
	var pExpr uintptr

	var bFKOnly int32
	var pFKey uintptr
	var pUpsertSet uintptr
	var pTarget uintptr

	var pStep uintptr
	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*8)))
	zTable = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 4*8)))
	iCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 5*8)))
	zNew = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 6*8)))
	bQuote = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 7*8)))
	bTemp = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 8*8)))
	xAuth = (*Sqlite3)(unsafe.Pointer(db)).FxAuth

	_ = NotUsed
	if !(zSql == uintptr(0)) {
		goto __1
	}
	return
__1:
	;
	if !(zTable == uintptr(0)) {
		goto __2
	}
	return
__2:
	;
	if !(zNew == uintptr(0)) {
		goto __3
	}
	return
__3:
	;
	if !(iCol < 0) {
		goto __4
	}
	return
__4:
	;
	Xsqlite3BtreeEnterAll(tls, db)
	pTab = Xsqlite3FindTable(tls, db, zTable, zDb)
	if !(pTab == uintptr(0) || iCol >= int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __5
	}
	Xsqlite3BtreeLeaveAll(tls, db)
	return
__5:
	;
	zOld = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24)).FzCnName
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(RenameCtx{})))
	(*RenameCtx)(unsafe.Pointer(bp)).FiCol = func() int32 {
		if iCol == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) {
			return -1
		}
		return iCol
	}()

	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	rc = renameParseSql(tls, bp+32, zDb, db, zSql, bTemp)

	libc.Xmemset(tls, bp+456, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(bp + 456)).FpParse = bp + 32
	(*Walker)(unsafe.Pointer(bp + 456)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{renameColumnExprCb}))
	(*Walker)(unsafe.Pointer(bp + 456)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{renameColumnSelectCb}))
	*(*uintptr)(unsafe.Pointer(bp + 456 + 40)) = bp

	(*RenameCtx)(unsafe.Pointer(bp)).FpTab = pTab
	if !(rc != SQLITE_OK) {
		goto __6
	}
	goto renameColumnFunc_done
__6:
	;
	if !((*Parse)(unsafe.Pointer(bp+32)).FpNewTable != 0) {
		goto __7
	}
	if !(int32((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable)).FeTabType) == TABTYP_VIEW) {
		goto __9
	}
	pSelect = *(*uintptr)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable + 64))
	*(*U32)(unsafe.Pointer(pSelect + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_View))
	(*Parse)(unsafe.Pointer(bp + 32)).Frc = SQLITE_OK
	Xsqlite3SelectPrep(tls, bp+32, pSelect, uintptr(0))
	rc = func() int32 {
		if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return SQLITE_NOMEM
		}
		return (*Parse)(unsafe.Pointer(bp + 32)).Frc
	}()
	if !(rc == SQLITE_OK) {
		goto __11
	}
	Xsqlite3WalkSelect(tls, bp+456, pSelect)
__11:
	;
	if !(rc != SQLITE_OK) {
		goto __12
	}
	goto renameColumnFunc_done
__12:
	;
	goto __10
__9:
	if !(int32((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable)).FeTabType) == TABTYP_NORM) {
		goto __13
	}

	bFKOnly = Xsqlite3_stricmp(tls, zTable, (*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable)).FzName)
	(*RenameCtx)(unsafe.Pointer(bp)).FpTab = (*Parse)(unsafe.Pointer(bp + 32)).FpNewTable
	if !(bFKOnly == 0) {
		goto __14
	}
	if !(iCol < int32((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable)).FnCol)) {
		goto __15
	}
	renameTokenFind(tls,
		bp+32, bp, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable)).FaCol+uintptr(iCol)*24)).FzCnName)
__15:
	;
	if !((*RenameCtx)(unsafe.Pointer(bp)).FiCol < 0) {
		goto __16
	}
	renameTokenFind(tls, bp+32, bp, (*Parse)(unsafe.Pointer(bp+32)).FpNewTable+52)
__16:
	;
	Xsqlite3WalkExprList(tls, bp+456, (*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable)).FpCheck)
	pIdx = (*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp + 32)).FpNewTable)).FpIndex
__17:
	if !(pIdx != 0) {
		goto __19
	}
	Xsqlite3WalkExprList(tls, bp+456, (*Index)(unsafe.Pointer(pIdx)).FaColExpr)
	goto __18
__18:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	goto __17
	goto __19
__19:
	;
	pIdx = (*Parse)(unsafe.Pointer(bp + 32)).FpNewIndex
__20:
	if !(pIdx != 0) {
		goto __22
	}
	Xsqlite3WalkExprList(tls, bp+456, (*Index)(unsafe.Pointer(pIdx)).FaColExpr)
	goto __21
__21:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	goto __20
	goto __22
__22:
	;
	i = 0
__23:
	if !(i < int32((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable)).FnCol)) {
		goto __25
	}
	pExpr = Xsqlite3ColumnExpr(tls, (*Parse)(unsafe.Pointer(bp+32)).FpNewTable,
		(*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable)).FaCol+uintptr(i)*24)
	Xsqlite3WalkExpr(tls, bp+456, pExpr)
	goto __24
__24:
	i++
	goto __23
	goto __25
__25:
	;
__14:
	;
	pFKey = *(*uintptr)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTable + 64 + 8))
__26:
	if !(pFKey != 0) {
		goto __28
	}
	i = 0
__29:
	if !(i < (*FKey)(unsafe.Pointer(pFKey)).FnCol) {
		goto __31
	}
	if !(bFKOnly == 0 && (*sColMap)(unsafe.Pointer(pFKey+64+uintptr(i)*16)).FiFrom == iCol) {
		goto __32
	}
	renameTokenFind(tls, bp+32, bp, pFKey+64+uintptr(i)*16)
__32:
	;
	if !(0 == Xsqlite3_stricmp(tls, (*FKey)(unsafe.Pointer(pFKey)).FzTo, zTable) &&
		0 == Xsqlite3_stricmp(tls, (*sColMap)(unsafe.Pointer(pFKey+64+uintptr(i)*16)).FzCol, zOld)) {
		goto __33
	}
	renameTokenFind(tls, bp+32, bp, (*sColMap)(unsafe.Pointer(pFKey+64+uintptr(i)*16)).FzCol)
__33:
	;
	goto __30
__30:
	i++
	goto __29
	goto __31
__31:
	;
	goto __27
__27:
	pFKey = (*FKey)(unsafe.Pointer(pFKey)).FpNextFrom
	goto __26
	goto __28
__28:
	;
__13:
	;
__10:
	;
	goto __8
__7:
	if !((*Parse)(unsafe.Pointer(bp+32)).FpNewIndex != 0) {
		goto __34
	}
	Xsqlite3WalkExprList(tls, bp+456, (*Index)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewIndex)).FaColExpr)
	Xsqlite3WalkExpr(tls, bp+456, (*Index)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewIndex)).FpPartIdxWhere)
	goto __35
__34:
	rc = renameResolveTrigger(tls, bp+32)
	if !(rc != SQLITE_OK) {
		goto __36
	}
	goto renameColumnFunc_done
__36:
	;
	pStep = (*Trigger)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp + 32)).FpNewTrigger)).Fstep_list
__37:
	if !(pStep != 0) {
		goto __39
	}
	if !((*TriggerStep)(unsafe.Pointer(pStep)).FzTarget != 0) {
		goto __40
	}
	pTarget = Xsqlite3LocateTable(tls, bp+32, uint32(0), (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget, zDb)
	if !(pTarget == pTab) {
		goto __41
	}
	if !((*TriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0) {
		goto __42
	}
	pUpsertSet = (*Upsert)(unsafe.Pointer((*TriggerStep)(unsafe.Pointer(pStep)).FpUpsert)).FpUpsertSet
	renameColumnElistNames(tls, bp+32, bp, pUpsertSet, zOld)
__42:
	;
	renameColumnIdlistNames(tls, bp+32, bp, (*TriggerStep)(unsafe.Pointer(pStep)).FpIdList, zOld)
	renameColumnElistNames(tls, bp+32, bp, (*TriggerStep)(unsafe.Pointer(pStep)).FpExprList, zOld)
__41:
	;
__40:
	;
	goto __38
__38:
	pStep = (*TriggerStep)(unsafe.Pointer(pStep)).FpNext
	goto __37
	goto __39
__39:
	;
	if !((*Parse)(unsafe.Pointer(bp+32)).FpTriggerTab == pTab) {
		goto __43
	}
	renameColumnIdlistNames(tls, bp+32, bp, (*Trigger)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+32)).FpNewTrigger)).FpColumns, zOld)
__43:
	;
	renameWalkTrigger(tls, bp+456, (*Parse)(unsafe.Pointer(bp+32)).FpNewTrigger)
__35:
	;
__8:
	;
	rc = renameEditSql(tls, context, bp, zSql, zNew, bQuote)

renameColumnFunc_done:
	if !(rc != SQLITE_OK) {
		goto __44
	}
	if !(rc == SQLITE_ERROR && Xsqlite3WritableSchema(tls, db) != 0) {
		goto __45
	}
	Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv)))
	goto __46
__45:
	if !((*Parse)(unsafe.Pointer(bp+32)).FzErrMsg != 0) {
		goto __47
	}
	renameColumnParseError(tls, context, ts+1636, *(*uintptr)(unsafe.Pointer(argv + 1*8)), *(*uintptr)(unsafe.Pointer(argv + 2*8)), bp+32)
	goto __48
__47:
	Xsqlite3_result_error_code(tls, context, rc)
__48:
	;
__46:
	;
__44:
	;
	renameParseCleanup(tls, bp+32)
	renameTokenFree(tls, db, (*RenameCtx)(unsafe.Pointer(bp)).FpList)
	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	Xsqlite3BtreeLeaveAll(tls, db)
}

func renameTableExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var p uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN &&
		(*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc|EP_Subrtn) == U32(0) &&
		(*RenameCtx)(unsafe.Pointer(p)).FpTab == *(*uintptr)(unsafe.Pointer(pExpr + 64)) {
		renameTokenFind(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse, p, pExpr+64)
	}
	return WRC_Continue
}

func renameTableSelectCb(tls *libc.TLS, pWalker uintptr, pSelect uintptr) int32 {
	var i int32
	var p uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	var pSrc uintptr = (*Select)(unsafe.Pointer(pSelect)).FpSrc
	if (*Select)(unsafe.Pointer(pSelect)).FselFlags&U32(SF_View|SF_CopyCte) != 0 {
		return WRC_Prune
	}
	if pSrc == uintptr(0) {
		return WRC_Abort
	}
	for i = 0; i < (*SrcList)(unsafe.Pointer(pSrc)).FnSrc; i++ {
		var pItem uintptr = pSrc + 8 + uintptr(i)*104
		if (*SrcItem)(unsafe.Pointer(pItem)).FpTab == (*RenameCtx)(unsafe.Pointer(p)).FpTab {
			renameTokenFind(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse, p, (*SrcItem)(unsafe.Pointer(pItem)).FzName)
		}
	}
	renameWalkWith(tls, pWalker, pSelect)

	return WRC_Continue
}

func renameTableFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(560)
	defer tls.Free(560)

	var db uintptr = Xsqlite3_context_db_handle(tls, context)
	var zDb uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	var zInput uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8)))
	var zOld uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 4*8)))
	var zNew uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 5*8)))
	var bTemp int32 = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 6*8)))
	_ = NotUsed

	if zInput != 0 && zOld != 0 && zNew != 0 {
		var rc int32
		var bQuote int32 = 1

		var xAuth Sqlite3_xauth = (*Sqlite3)(unsafe.Pointer(db)).FxAuth
		(*Sqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)

		Xsqlite3BtreeEnterAll(tls, db)

		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(RenameCtx{})))
		(*RenameCtx)(unsafe.Pointer(bp)).FpTab = Xsqlite3FindTable(tls, db, zOld, zDb)
		libc.Xmemset(tls, bp+32, 0, uint64(unsafe.Sizeof(Walker{})))
		(*Walker)(unsafe.Pointer(bp + 32)).FpParse = bp + 80
		(*Walker)(unsafe.Pointer(bp + 32)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		}{renameTableExprCb}))
		(*Walker)(unsafe.Pointer(bp + 32)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		}{renameTableSelectCb}))
		*(*uintptr)(unsafe.Pointer(bp + 32 + 40)) = bp

		rc = renameParseSql(tls, bp+80, zDb, db, zInput, bTemp)

		if rc == SQLITE_OK {
			var isLegacy int32 = int32((*Sqlite3)(unsafe.Pointer(db)).Fflags & uint64(SQLITE_LegacyAlter))
			if (*Parse)(unsafe.Pointer(bp+80)).FpNewTable != 0 {
				var pTab uintptr = (*Parse)(unsafe.Pointer(bp + 80)).FpNewTable

				if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW {
					if isLegacy == 0 {
						var pSelect uintptr = *(*uintptr)(unsafe.Pointer(pTab + 64))

						libc.Xmemset(tls, bp+504, 0, uint64(unsafe.Sizeof(NameContext{})))
						(*NameContext)(unsafe.Pointer(bp + 504)).FpParse = bp + 80

						*(*U32)(unsafe.Pointer(pSelect + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_View))
						Xsqlite3SelectPrep(tls, bp+80, *(*uintptr)(unsafe.Pointer(pTab + 64)), bp+504)
						if (*Parse)(unsafe.Pointer(bp+80)).FnErr != 0 {
							rc = (*Parse)(unsafe.Pointer(bp + 80)).Frc
						} else {
							Xsqlite3WalkSelect(tls, bp+32, *(*uintptr)(unsafe.Pointer(pTab + 64)))
						}
					}
				} else {
					if (isLegacy == 0 || (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0) &&
						!(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
						var pFKey uintptr

						for pFKey = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8)); pFKey != 0; pFKey = (*FKey)(unsafe.Pointer(pFKey)).FpNextFrom {
							if Xsqlite3_stricmp(tls, (*FKey)(unsafe.Pointer(pFKey)).FzTo, zOld) == 0 {
								renameTokenFind(tls, bp+80, bp, (*FKey)(unsafe.Pointer(pFKey)).FzTo)
							}
						}
					}

					if Xsqlite3_stricmp(tls, zOld, (*Table)(unsafe.Pointer(pTab)).FzName) == 0 {
						(*RenameCtx)(unsafe.Pointer(bp)).FpTab = pTab
						if isLegacy == 0 {
							Xsqlite3WalkExprList(tls, bp+32, (*Table)(unsafe.Pointer(pTab)).FpCheck)
						}
						renameTokenFind(tls, bp+80, bp, (*Table)(unsafe.Pointer(pTab)).FzName)
					}
				}
			} else if (*Parse)(unsafe.Pointer(bp+80)).FpNewIndex != 0 {
				renameTokenFind(tls, bp+80, bp, (*Index)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+80)).FpNewIndex)).FzName)
				if isLegacy == 0 {
					Xsqlite3WalkExpr(tls, bp+32, (*Index)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+80)).FpNewIndex)).FpPartIdxWhere)
				}
			} else {
				var pTrigger uintptr = (*Parse)(unsafe.Pointer(bp + 80)).FpNewTrigger
				var pStep uintptr
				if 0 == Xsqlite3_stricmp(tls, (*Trigger)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+80)).FpNewTrigger)).Ftable, zOld) &&
					(*Table)(unsafe.Pointer((*RenameCtx)(unsafe.Pointer(bp)).FpTab)).FpSchema == (*Trigger)(unsafe.Pointer(pTrigger)).FpTabSchema {
					renameTokenFind(tls, bp+80, bp, (*Trigger)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+80)).FpNewTrigger)).Ftable)
				}

				if isLegacy == 0 {
					rc = renameResolveTrigger(tls, bp+80)
					if rc == SQLITE_OK {
						renameWalkTrigger(tls, bp+32, pTrigger)
						for pStep = (*Trigger)(unsafe.Pointer(pTrigger)).Fstep_list; pStep != 0; pStep = (*TriggerStep)(unsafe.Pointer(pStep)).FpNext {
							if (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget != 0 && 0 == Xsqlite3_stricmp(tls, (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget, zOld) {
								renameTokenFind(tls, bp+80, bp, (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget)
							}
							if (*TriggerStep)(unsafe.Pointer(pStep)).FpFrom != 0 {
								var i int32
								for i = 0; i < (*SrcList)(unsafe.Pointer((*TriggerStep)(unsafe.Pointer(pStep)).FpFrom)).FnSrc; i++ {
									var pItem uintptr = (*TriggerStep)(unsafe.Pointer(pStep)).FpFrom + 8 + uintptr(i)*104
									if 0 == Xsqlite3_stricmp(tls, (*SrcItem)(unsafe.Pointer(pItem)).FzName, zOld) {
										renameTokenFind(tls, bp+80, bp, (*SrcItem)(unsafe.Pointer(pItem)).FzName)
									}
								}
							}
						}
					}
				}
			}
		}

		if rc == SQLITE_OK {
			rc = renameEditSql(tls, context, bp, zInput, zNew, bQuote)
		}
		if rc != SQLITE_OK {
			if rc == SQLITE_ERROR && Xsqlite3WritableSchema(tls, db) != 0 {
				Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv + 3*8)))
			} else if (*Parse)(unsafe.Pointer(bp+80)).FzErrMsg != 0 {
				renameColumnParseError(tls, context, ts+1636, *(*uintptr)(unsafe.Pointer(argv + 1*8)), *(*uintptr)(unsafe.Pointer(argv + 2*8)), bp+80)
			} else {
				Xsqlite3_result_error_code(tls, context, rc)
			}
		}

		renameParseCleanup(tls, bp+80)
		renameTokenFree(tls, db, (*RenameCtx)(unsafe.Pointer(bp)).FpList)
		Xsqlite3BtreeLeaveAll(tls, db)
		(*Sqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	}

	return
}

func renameQuotefixExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_STRING && (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_DblQuoted) != 0 {
		renameTokenFind(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse, *(*uintptr)(unsafe.Pointer(pWalker + 40)), pExpr)
	}
	return WRC_Continue
}

func renameQuotefixFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(504)
	defer tls.Free(504)

	var db uintptr = Xsqlite3_context_db_handle(tls, context)
	var zDb uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	var zInput uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))

	var xAuth Sqlite3_xauth = (*Sqlite3)(unsafe.Pointer(db)).FxAuth
	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)

	Xsqlite3BtreeEnterAll(tls, db)

	_ = NotUsed
	if zDb != 0 && zInput != 0 {
		var rc int32

		rc = renameParseSql(tls, bp, zDb, db, zInput, 0)

		if rc == SQLITE_OK {
			libc.Xmemset(tls, bp+424, 0, uint64(unsafe.Sizeof(RenameCtx{})))
			libc.Xmemset(tls, bp+456, 0, uint64(unsafe.Sizeof(Walker{})))
			(*Walker)(unsafe.Pointer(bp + 456)).FpParse = bp
			(*Walker)(unsafe.Pointer(bp + 456)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			}{renameQuotefixExprCb}))
			(*Walker)(unsafe.Pointer(bp + 456)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			}{renameColumnSelectCb}))
			*(*uintptr)(unsafe.Pointer(bp + 456 + 40)) = bp + 424

			if (*Parse)(unsafe.Pointer(bp)).FpNewTable != 0 {
				if int32((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewTable)).FeTabType) == TABTYP_VIEW {
					var pSelect uintptr = *(*uintptr)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewTable + 64))
					*(*U32)(unsafe.Pointer(pSelect + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_View))
					(*Parse)(unsafe.Pointer(bp)).Frc = SQLITE_OK
					Xsqlite3SelectPrep(tls, bp, pSelect, uintptr(0))
					rc = func() int32 {
						if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
							return SQLITE_NOMEM
						}
						return (*Parse)(unsafe.Pointer(bp)).Frc
					}()
					if rc == SQLITE_OK {
						Xsqlite3WalkSelect(tls, bp+456, pSelect)
					}
				} else {
					var i int32
					Xsqlite3WalkExprList(tls, bp+456, (*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewTable)).FpCheck)
					for i = 0; i < int32((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewTable)).FnCol); i++ {
						Xsqlite3WalkExpr(tls, bp+456,
							Xsqlite3ColumnExpr(tls, (*Parse)(unsafe.Pointer(bp)).FpNewTable,
								(*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewTable)).FaCol+uintptr(i)*24))
					}
				}
			} else if (*Parse)(unsafe.Pointer(bp)).FpNewIndex != 0 {
				Xsqlite3WalkExprList(tls, bp+456, (*Index)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewIndex)).FaColExpr)
				Xsqlite3WalkExpr(tls, bp+456, (*Index)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewIndex)).FpPartIdxWhere)
			} else {
				rc = renameResolveTrigger(tls, bp)
				if rc == SQLITE_OK {
					renameWalkTrigger(tls, bp+456, (*Parse)(unsafe.Pointer(bp)).FpNewTrigger)
				}
			}

			if rc == SQLITE_OK {
				rc = renameEditSql(tls, context, bp+424, zInput, uintptr(0), 0)
			}
			renameTokenFree(tls, db, (*RenameCtx)(unsafe.Pointer(bp+424)).FpList)
		}
		if rc != SQLITE_OK {
			if Xsqlite3WritableSchema(tls, db) != 0 && rc == SQLITE_ERROR {
				Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
			} else {
				Xsqlite3_result_error_code(tls, context, rc)
			}
		}
		renameParseCleanup(tls, bp)
	}

	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = xAuth

	Xsqlite3BtreeLeaveAll(tls, db)
}

func renameTableTest(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(480)
	defer tls.Free(480)

	var db uintptr = Xsqlite3_context_db_handle(tls, context)
	var zDb uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	var zInput uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	var bTemp int32 = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 4*8)))
	var isLegacy int32 = int32((*Sqlite3)(unsafe.Pointer(db)).Fflags & uint64(SQLITE_LegacyAlter))
	var zWhen uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 5*8)))
	var bNoDQS int32 = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 6*8)))

	var xAuth Sqlite3_xauth = (*Sqlite3)(unsafe.Pointer(db)).FxAuth
	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)

	_ = NotUsed

	if zDb != 0 && zInput != 0 {
		var rc int32

		var flags int32 = int32((*Sqlite3)(unsafe.Pointer(db)).Fflags)
		if bNoDQS != 0 {
			*(*U64)(unsafe.Pointer(db + 48)) &= libc.Uint64FromInt32(libc.CplInt32(SQLITE_DqsDML | SQLITE_DqsDDL))
		}
		rc = renameParseSql(tls, bp, zDb, db, zInput, bTemp)
		*(*U64)(unsafe.Pointer(db + 48)) |= U64(flags & (SQLITE_DqsDML | SQLITE_DqsDDL))
		if rc == SQLITE_OK {
			if isLegacy == 0 && (*Parse)(unsafe.Pointer(bp)).FpNewTable != 0 && int32((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewTable)).FeTabType) == TABTYP_VIEW {
				libc.Xmemset(tls, bp+424, 0, uint64(unsafe.Sizeof(NameContext{})))
				(*NameContext)(unsafe.Pointer(bp + 424)).FpParse = bp
				Xsqlite3SelectPrep(tls, bp, *(*uintptr)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewTable + 64)), bp+424)
				if (*Parse)(unsafe.Pointer(bp)).FnErr != 0 {
					rc = (*Parse)(unsafe.Pointer(bp)).Frc
				}
			} else if (*Parse)(unsafe.Pointer(bp)).FpNewTrigger != 0 {
				if isLegacy == 0 {
					rc = renameResolveTrigger(tls, bp)
				}
				if rc == SQLITE_OK {
					var i1 int32 = Xsqlite3SchemaToIndex(tls, db, (*Trigger)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp)).FpNewTrigger)).FpTabSchema)
					var i2 int32 = Xsqlite3FindDbName(tls, db, zDb)
					if i1 == i2 {
						Xsqlite3_result_int(tls, context, 1)
					}
				}
			}
		}

		if rc != SQLITE_OK && zWhen != 0 && !(Xsqlite3WritableSchema(tls, db) != 0) {
			renameColumnParseError(tls, context, zWhen, *(*uintptr)(unsafe.Pointer(argv + 2*8)), *(*uintptr)(unsafe.Pointer(argv + 3*8)), bp)
		}
		renameParseCleanup(tls, bp)
	}

	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
}

func dropColumnFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(448)
	defer tls.Free(448)

	var db uintptr
	var iSchema int32
	var zSql uintptr
	var iCol int32
	var zDb uintptr
	var rc int32

	var pCol uintptr
	var pTab uintptr
	var zEnd uintptr
	var zNew uintptr
	var xAuth Sqlite3_xauth
	var pEnd uintptr
	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*8)))
	iCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8)))
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iSchema)*32)).FzDbSName
	zNew = uintptr(0)
	xAuth = (*Sqlite3)(unsafe.Pointer(db)).FxAuth
	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)

	_ = NotUsed
	rc = renameParseSql(tls, bp+24, zDb, db, zSql, libc.Bool32(iSchema == 1))
	if !(rc != SQLITE_OK) {
		goto __1
	}
	goto drop_column_done
__1:
	;
	pTab = (*Parse)(unsafe.Pointer(bp + 24)).FpNewTable
	if !(pTab == uintptr(0) || int32((*Table)(unsafe.Pointer(pTab)).FnCol) == 1 || iCol >= int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __2
	}

	rc = Xsqlite3CorruptError(tls, 114463)
	goto drop_column_done
__2:
	;
	pCol = renameTokenFind(tls, bp+24, uintptr(0), (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FzCnName)
	if !(iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol)-1) {
		goto __3
	}
	pEnd = renameTokenFind(tls, bp+24, uintptr(0), (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol+1)*24)).FzCnName)
	zEnd = (*RenameToken)(unsafe.Pointer(pEnd)).Ft.Fz
	goto __4
__3:
	;
	zEnd = zSql + uintptr(*(*int32)(unsafe.Pointer(pTab + 64)))
__5:
	if !(int32(*(*uint8)(unsafe.Pointer((*RenameToken)(unsafe.Pointer(pCol)).Ft.Fz))) != 0 && int32(*(*uint8)(unsafe.Pointer((*RenameToken)(unsafe.Pointer(pCol)).Ft.Fz))) != ',') {
		goto __6
	}
	(*RenameToken)(unsafe.Pointer(pCol)).Ft.Fz--
	goto __5
__6:
	;
__4:
	;
	zNew = Xsqlite3MPrintf(tls, db, ts+14325, libc.VaList(bp, (int64((*RenameToken)(unsafe.Pointer(pCol)).Ft.Fz)-int64(zSql))/1, zSql, zEnd))
	Xsqlite3_result_text(tls, context, zNew, -1, libc.UintptrFromInt32(-1))
	Xsqlite3_free(tls, zNew)

drop_column_done:
	renameParseCleanup(tls, bp+24)
	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	if !(rc != SQLITE_OK) {
		goto __7
	}
	Xsqlite3_result_error_code(tls, context, rc)
__7:
}

func Xsqlite3AlterDropColumn(tls *libc.TLS, pParse uintptr, pSrc uintptr, pName uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var db uintptr
	var pTab uintptr
	var iDb int32
	var zDb uintptr
	var zCol uintptr
	var iCol int32
	var iPos int32
	var iColPos int32
	var regOut int32
	var i int32
	var addr int32
	var reg int32
	var regRec int32
	var pPk uintptr
	var nField int32
	var iCur int32
	var v uintptr
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	zCol = uintptr(0)

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __1
	}
	goto exit_drop_column
__1:
	;
	pTab = Xsqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if !!(pTab != 0) {
		goto __2
	}
	goto exit_drop_column
__2:
	;
	if !(SQLITE_OK != isAlterableTable(tls, pParse, pTab)) {
		goto __3
	}
	goto exit_drop_column
__3:
	;
	if !(SQLITE_OK != isRealTable(tls, pParse, pTab, 1)) {
		goto __4
	}
	goto exit_drop_column
__4:
	;
	zCol = Xsqlite3NameFromToken(tls, db, pName)
	if !(zCol == uintptr(0)) {
		goto __5
	}

	goto exit_drop_column
__5:
	;
	iCol = Xsqlite3ColumnIndex(tls, pTab, zCol)
	if !(iCol < 0) {
		goto __6
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+13947, libc.VaList(bp, pName))
	goto exit_drop_column
__6:
	;
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FcolFlags)&(COLFLAG_PRIMKEY|COLFLAG_UNIQUE) != 0) {
		goto __7
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+14332,
		libc.VaList(bp+8, func() uintptr {
			if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FcolFlags)&COLFLAG_PRIMKEY != 0 {
				return ts + 14360
			}
			return ts + 9052
		}(),
			zCol))
	goto exit_drop_column
__7:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FnCol) <= 1) {
		goto __8
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+14372, libc.VaList(bp+24, zCol))
	goto exit_drop_column
__8:
	;
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName

	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_ALTER_TABLE, zDb, (*Table)(unsafe.Pointer(pTab)).FzName, zCol) != 0) {
		goto __9
	}
	goto exit_drop_column
__9:
	;
	renameTestSchema(tls, pParse, zDb, libc.Bool32(iDb == 1), ts+1636, 0)
	renameFixQuotes(tls, pParse, zDb, libc.Bool32(iDb == 1))
	Xsqlite3NestedParse(tls, pParse,
		ts+14420, libc.VaList(bp+32, zDb, iDb, iCol, (*Table)(unsafe.Pointer(pTab)).FzName))

	renameReloadSchema(tls, pParse, iDb, uint16(INITFLAG_AlterDrop))
	renameTestSchema(tls, pParse, zDb, libc.Bool32(iDb == 1), ts+14541, 1)

	if !((*Parse)(unsafe.Pointer(pParse)).FnErr == 0 && int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FcolFlags)&COLFLAG_VIRTUAL == 0) {
		goto __10
	}
	pPk = uintptr(0)
	nField = 0
	v = Xsqlite3GetVdbe(tls, pParse)
	iCur = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	Xsqlite3OpenTable(tls, pParse, iCur, iDb, pTab, OP_OpenWrite)
	addr = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, iCur)
	reg = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __11
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iCur, reg)
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32((*Table)(unsafe.Pointer(pTab)).FnCol)
	goto __12
__11:
	pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32((*Index)(unsafe.Pointer(pPk)).FnColumn)
	i = 0
__13:
	if !(i < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)) {
		goto __15
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, iCur, i, reg+i+1)
	goto __14
__14:
	i++
	goto __13
	goto __15
__15:
	;
	nField = int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
__12:
	;
	regRec = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	i = 0
__16:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __18
	}
	if !(i != iCol && int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL == 0) {
		goto __19
	}
	if !(pPk != 0) {
		goto __20
	}
	iPos = int32(Xsqlite3TableColumnToIndex(tls, pPk, int16(i)))
	iColPos = int32(Xsqlite3TableColumnToIndex(tls, pPk, int16(iCol)))
	if !(iPos < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)) {
		goto __22
	}
	goto __17
__22:
	;
	regOut = reg + 1 + iPos - libc.Bool32(iPos > iColPos)
	goto __21
__20:
	regOut = reg + 1 + nField
__21:
	;
	if !(i == int32((*Table)(unsafe.Pointer(pTab)).FiPKey)) {
		goto __23
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regOut)
	goto __24
__23:
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, i, regOut)
__24:
	;
	nField++
__19:
	;
	goto __17
__17:
	i++
	goto __16
	goto __18
__18:
	;
	if !(nField == 0) {
		goto __25
	}

	(*Parse)(unsafe.Pointer(pParse)).FnMem++
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, reg+1)
	nField = 1
__25:
	;
	Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, reg+1, nField, regRec)
	if !(pPk != 0) {
		goto __26
	}
	Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iCur, regRec, reg+1, int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol))
	goto __27
__26:
	Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iCur, regRec, reg)
__27:
	;
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SAVEPOSITION))

	Xsqlite3VdbeAddOp2(tls, v, OP_Next, iCur, addr+1)
	Xsqlite3VdbeJumpHere(tls, v, addr)
__10:
	;
exit_drop_column:
	Xsqlite3DbFree(tls, db, zCol)
	Xsqlite3SrcListDelete(tls, db, pSrc)
}

func Xsqlite3AlterFunctions(tls *libc.TLS) {
	Xsqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&aAlterTableFuncs)), int32(uint64(unsafe.Sizeof(aAlterTableFuncs))/uint64(unsafe.Sizeof(FuncDef{}))))
}

var aAlterTableFuncs = [5]FuncDef{
	{FnArg: int8(9), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_INTERNAL | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FxSFunc: 0, FzName: ts + 14559},
	{FnArg: int8(7), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_INTERNAL | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FxSFunc: 0, FzName: ts + 14580},
	{FnArg: int8(7), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_INTERNAL | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FxSFunc: 0, FzName: ts + 14600},
	{FnArg: int8(3), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_INTERNAL | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FxSFunc: 0, FzName: ts + 14619},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_INTERNAL | SQLITE_UTF8 | SQLITE_FUNC_CONSTANT), FxSFunc: 0, FzName: ts + 14638}}

func openStatTable(tls *libc.TLS, pParse uintptr, iDb int32, iStatCur int32, zWhere uintptr, zWhereType uintptr) {
	bp := tls.Alloc(88)
	defer tls.Free(88)

	var i int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pDb uintptr
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)

	var nToOpen int32
	if (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_Stat4) == U32(0) {
		nToOpen = 2
	} else {
		nToOpen = 1
	}

	if v == uintptr(0) {
		return
	}

	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32

	for i = 0; i < int32(uint64(unsafe.Sizeof(aTable))/uint64(unsafe.Sizeof(struct {
		FzName uintptr
		FzCols uintptr
	}{}))); i++ {
		var zTab uintptr = aTable[i].FzName
		var pStat uintptr
		*(*U8)(unsafe.Pointer(bp + 72 + uintptr(i))) = U8(0)
		if libc.AssignUintptr(&pStat, Xsqlite3FindTable(tls, db, zTab, (*Db)(unsafe.Pointer(pDb)).FzDbSName)) == uintptr(0) {
			if i < nToOpen {
				Xsqlite3NestedParse(tls, pParse,
					ts+14661, libc.VaList(bp, (*Db)(unsafe.Pointer(pDb)).FzDbSName, zTab, aTable[i].FzCols))
				*(*U32)(unsafe.Pointer(bp + 76 + uintptr(i)*4)) = U32((*Parse)(unsafe.Pointer(pParse)).FregRoot)
				*(*U8)(unsafe.Pointer(bp + 72 + uintptr(i))) = U8(OPFLAG_P2ISREG)
			}
		} else {
			*(*U32)(unsafe.Pointer(bp + 76 + uintptr(i)*4)) = (*Table)(unsafe.Pointer(pStat)).Ftnum
			Xsqlite3TableLock(tls, pParse, iDb, *(*U32)(unsafe.Pointer(bp + 76 + uintptr(i)*4)), uint8(1), zTab)
			if zWhere != 0 {
				Xsqlite3NestedParse(tls, pParse,
					ts+14684,
					libc.VaList(bp+24, (*Db)(unsafe.Pointer(pDb)).FzDbSName, zTab, zWhereType, zWhere))
			} else if (*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
				Xsqlite3NestedParse(tls, pParse, ts+14714, libc.VaList(bp+56, (*Db)(unsafe.Pointer(pDb)).FzDbSName, zTab))
			} else {
				Xsqlite3VdbeAddOp2(tls, v, OP_Clear, int32(*(*U32)(unsafe.Pointer(bp + 76 + uintptr(i)*4))), iDb)
			}
		}
	}

	for i = 0; i < nToOpen; i++ {
		Xsqlite3VdbeAddOp4Int(tls, v, OP_OpenWrite, iStatCur+i, int32(*(*U32)(unsafe.Pointer(bp + 76 + uintptr(i)*4))), iDb, 3)
		Xsqlite3VdbeChangeP5(tls, v, uint16(*(*U8)(unsafe.Pointer(bp + 72 + uintptr(i)))))
		Xsqlite3VdbeComment(tls, v, aTable[i].FzName, 0)
	}
}

var aTable = [3]struct {
	FzName uintptr
	FzCols uintptr
}{
	{FzName: ts + 14732, FzCols: ts + 14745},
	{FzName: ts + 14758, FzCols: ts + 14771},
	{FzName: ts + 14799},
}

type StatAccum1 = struct {
	Fdb          uintptr
	FnEst        TRowcnt
	FnRow        TRowcnt
	FnLimit      int32
	FnCol        int32
	FnKeyCol     int32
	FnSkipAhead  U8
	F__ccgo_pad1 [3]byte
	Fcurrent     StatSample
	FnPSample    TRowcnt
	FmxSample    int32
	FiPrn        U32
	FaBest       uintptr
	FiMin        int32
	FnSample     int32
	FnMaxEqZero  int32
	FiGet        int32
	Fa           uintptr
}

type StatAccum = StatAccum1
type StatSample1 = struct {
	FanEq        uintptr
	FanDLt       uintptr
	FanLt        uintptr
	Fu           struct{ FiRowid I64 }
	FnRowid      U32
	FisPSample   U8
	F__ccgo_pad1 [3]byte
	FiCol        int32
	FiHash       U32
}

type StatSample = StatSample1

func sampleClear(tls *libc.TLS, db uintptr, p uintptr) {
	if (*StatSample)(unsafe.Pointer(p)).FnRowid != 0 {
		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(p + 24)))
		(*StatSample)(unsafe.Pointer(p)).FnRowid = U32(0)
	}
}

func sampleSetRowid(tls *libc.TLS, db uintptr, p uintptr, n int32, pData uintptr) {
	if (*StatSample)(unsafe.Pointer(p)).FnRowid != 0 {
		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(p + 24)))
	}
	*(*uintptr)(unsafe.Pointer(p + 24)) = Xsqlite3DbMallocRawNN(tls, db, uint64(n))
	if *(*uintptr)(unsafe.Pointer(p + 24)) != 0 {
		(*StatSample)(unsafe.Pointer(p)).FnRowid = U32(n)
		libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(p + 24)), pData, uint64(n))
	} else {
		(*StatSample)(unsafe.Pointer(p)).FnRowid = U32(0)
	}
}

func sampleSetRowidInt64(tls *libc.TLS, db uintptr, p uintptr, iRowid I64) {
	if (*StatSample)(unsafe.Pointer(p)).FnRowid != 0 {
		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(p + 24)))
	}
	(*StatSample)(unsafe.Pointer(p)).FnRowid = U32(0)
	*(*I64)(unsafe.Pointer(p + 24)) = iRowid
}

func sampleCopy(tls *libc.TLS, p uintptr, pTo uintptr, pFrom uintptr) {
	(*StatSample)(unsafe.Pointer(pTo)).FisPSample = (*StatSample)(unsafe.Pointer(pFrom)).FisPSample
	(*StatSample)(unsafe.Pointer(pTo)).FiCol = (*StatSample)(unsafe.Pointer(pFrom)).FiCol
	(*StatSample)(unsafe.Pointer(pTo)).FiHash = (*StatSample)(unsafe.Pointer(pFrom)).FiHash
	libc.Xmemcpy(tls, (*StatSample)(unsafe.Pointer(pTo)).FanEq, (*StatSample)(unsafe.Pointer(pFrom)).FanEq, uint64(unsafe.Sizeof(TRowcnt(0)))*uint64((*StatAccum)(unsafe.Pointer(p)).FnCol))
	libc.Xmemcpy(tls, (*StatSample)(unsafe.Pointer(pTo)).FanLt, (*StatSample)(unsafe.Pointer(pFrom)).FanLt, uint64(unsafe.Sizeof(TRowcnt(0)))*uint64((*StatAccum)(unsafe.Pointer(p)).FnCol))
	libc.Xmemcpy(tls, (*StatSample)(unsafe.Pointer(pTo)).FanDLt, (*StatSample)(unsafe.Pointer(pFrom)).FanDLt, uint64(unsafe.Sizeof(TRowcnt(0)))*uint64((*StatAccum)(unsafe.Pointer(p)).FnCol))
	if (*StatSample)(unsafe.Pointer(pFrom)).FnRowid != 0 {
		sampleSetRowid(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, pTo, int32((*StatSample)(unsafe.Pointer(pFrom)).FnRowid), *(*uintptr)(unsafe.Pointer(pFrom + 24)))
	} else {
		sampleSetRowidInt64(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, pTo, *(*I64)(unsafe.Pointer(pFrom + 24)))
	}
}

func statAccumDestructor(tls *libc.TLS, pOld uintptr) {
	var p uintptr = pOld
	if (*StatAccum)(unsafe.Pointer(p)).FmxSample != 0 {
		var i int32
		for i = 0; i < (*StatAccum)(unsafe.Pointer(p)).FnCol; i++ {
			sampleClear(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, (*StatAccum)(unsafe.Pointer(p)).FaBest+uintptr(i)*48)
		}
		for i = 0; i < (*StatAccum)(unsafe.Pointer(p)).FmxSample; i++ {
			sampleClear(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, (*StatAccum)(unsafe.Pointer(p)).Fa+uintptr(i)*48)
		}
		sampleClear(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, p+40)
	}
	Xsqlite3DbFree(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, p)
}

func statInit(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	var nCol int32
	var nKeyCol int32
	var nColUp int32
	var n int32
	var db uintptr = Xsqlite3_context_db_handle(tls, context)

	var mxSample int32
	if (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_Stat4) == U32(0) {
		mxSample = SQLITE_STAT4_SAMPLES
	} else {
		mxSample = 0
	}

	_ = argc
	nCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv)))

	if uint64(unsafe.Sizeof(TRowcnt(0))) < uint64(8) {
		nColUp = (nCol + 1) & libc.CplInt32(1)
	} else {
		nColUp = nCol
	}
	nKeyCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))

	n = int32(uint64(unsafe.Sizeof(StatAccum{})) +
		uint64(unsafe.Sizeof(TRowcnt(0)))*uint64(nColUp) +
		uint64(unsafe.Sizeof(TRowcnt(0)))*uint64(nColUp))
	if mxSample != 0 {
		n = int32(uint64(n) + (uint64(unsafe.Sizeof(TRowcnt(0)))*uint64(nColUp) +
			uint64(unsafe.Sizeof(StatSample{}))*uint64(nCol+mxSample) +
			uint64(unsafe.Sizeof(TRowcnt(0)))*uint64(3)*uint64(nColUp)*uint64(nCol+mxSample)))
	}
	p = Xsqlite3DbMallocZero(tls, db, uint64(n))
	if p == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
		return
	}

	(*StatAccum)(unsafe.Pointer(p)).Fdb = db
	(*StatAccum)(unsafe.Pointer(p)).FnEst = TRowcnt(Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))))
	(*StatAccum)(unsafe.Pointer(p)).FnRow = uint64(0)
	(*StatAccum)(unsafe.Pointer(p)).FnLimit = int32(Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8))))
	(*StatAccum)(unsafe.Pointer(p)).FnCol = nCol
	(*StatAccum)(unsafe.Pointer(p)).FnKeyCol = nKeyCol
	(*StatAccum)(unsafe.Pointer(p)).FnSkipAhead = U8(0)
	(*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt = p + 1*136
	(*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq = (*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt + uintptr(nColUp)*8

	(*StatAccum)(unsafe.Pointer(p)).FmxSample = func() int32 {
		if (*StatAccum)(unsafe.Pointer(p)).FnLimit == 0 {
			return mxSample
		}
		return 0
	}()
	if mxSample != 0 {
		var pSpace uintptr
		var i int32

		(*StatAccum)(unsafe.Pointer(p)).FiGet = -1
		(*StatAccum)(unsafe.Pointer(p)).FnPSample = (*StatAccum)(unsafe.Pointer(p)).FnEst/TRowcnt(mxSample/3+1) + uint64(1)
		(*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanLt = (*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(nColUp)*8
		(*StatAccum)(unsafe.Pointer(p)).FiPrn = U32(0x689e962d)*U32(nCol) ^ 0xd0944565*U32(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))))

		(*StatAccum)(unsafe.Pointer(p)).Fa = (*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanLt + uintptr(nColUp)*8
		(*StatAccum)(unsafe.Pointer(p)).FaBest = (*StatAccum)(unsafe.Pointer(p)).Fa + uintptr(mxSample)*48
		pSpace = (*StatAccum)(unsafe.Pointer(p)).Fa + uintptr(mxSample+nCol)*48
		for i = 0; i < mxSample+nCol; i++ {
			(*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*48)).FanEq = pSpace
			pSpace += uintptr(uint64(unsafe.Sizeof(TRowcnt(0))) * uint64(nColUp))
			(*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*48)).FanLt = pSpace
			pSpace += uintptr(uint64(unsafe.Sizeof(TRowcnt(0))) * uint64(nColUp))
			(*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*48)).FanDLt = pSpace
			pSpace += uintptr(uint64(unsafe.Sizeof(TRowcnt(0))) * uint64(nColUp))
		}

		for i = 0; i < nCol; i++ {
			(*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).FaBest + uintptr(i)*48)).FiCol = i
		}
	}

	Xsqlite3_result_blob(tls, context, p, int32(unsafe.Sizeof(StatAccum{})), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{statAccumDestructor})))
}

var statInitFuncdef = FuncDef{
	FnArg:      int8(4),
	FfuncFlags: U32(SQLITE_UTF8),
	FxSFunc:    0,
	FzName:     ts + 14812}

func sampleIsBetterPost(tls *libc.TLS, pAccum uintptr, pNew uintptr, pOld uintptr) int32 {
	var nCol int32 = (*StatAccum)(unsafe.Pointer(pAccum)).FnCol
	var i int32

	for i = (*StatSample)(unsafe.Pointer(pNew)).FiCol + 1; i < nCol; i++ {
		if *(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pNew)).FanEq + uintptr(i)*8)) > *(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pOld)).FanEq + uintptr(i)*8)) {
			return 1
		}
		if *(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pNew)).FanEq + uintptr(i)*8)) < *(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pOld)).FanEq + uintptr(i)*8)) {
			return 0
		}
	}
	if (*StatSample)(unsafe.Pointer(pNew)).FiHash > (*StatSample)(unsafe.Pointer(pOld)).FiHash {
		return 1
	}
	return 0
}

func sampleIsBetter(tls *libc.TLS, pAccum uintptr, pNew uintptr, pOld uintptr) int32 {
	var nEqNew TRowcnt = *(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pNew)).FanEq + uintptr((*StatSample)(unsafe.Pointer(pNew)).FiCol)*8))
	var nEqOld TRowcnt = *(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pOld)).FanEq + uintptr((*StatSample)(unsafe.Pointer(pOld)).FiCol)*8))

	if nEqNew > nEqOld {
		return 1
	}
	if nEqNew == nEqOld {
		if (*StatSample)(unsafe.Pointer(pNew)).FiCol < (*StatSample)(unsafe.Pointer(pOld)).FiCol {
			return 1
		}
		return libc.Bool32((*StatSample)(unsafe.Pointer(pNew)).FiCol == (*StatSample)(unsafe.Pointer(pOld)).FiCol && sampleIsBetterPost(tls, pAccum, pNew, pOld) != 0)
	}
	return 0
}

func sampleInsert(tls *libc.TLS, p uintptr, pNew uintptr, nEqZero int32) {
	var pSample uintptr
	var i int32
	var pOld uintptr
	var pUpgrade uintptr
	var pMin uintptr
	var anEq uintptr
	var anLt uintptr
	var anDLt uintptr
	var iMin int32
	pSample = uintptr(0)

	if !(nEqZero > (*StatAccum)(unsafe.Pointer(p)).FnMaxEqZero) {
		goto __1
	}
	(*StatAccum)(unsafe.Pointer(p)).FnMaxEqZero = nEqZero
__1:
	;
	if !(int32((*StatSample)(unsafe.Pointer(pNew)).FisPSample) == 0) {
		goto __2
	}
	pUpgrade = uintptr(0)

	i = (*StatAccum)(unsafe.Pointer(p)).FnSample - 1
__3:
	if !(i >= 0) {
		goto __5
	}
	pOld = (*StatAccum)(unsafe.Pointer(p)).Fa + uintptr(i)*48
	if !(*(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pOld)).FanEq + uintptr((*StatSample)(unsafe.Pointer(pNew)).FiCol)*8)) == uint64(0)) {
		goto __6
	}
	if !((*StatSample)(unsafe.Pointer(pOld)).FisPSample != 0) {
		goto __7
	}
	return
__7:
	;
	if !(pUpgrade == uintptr(0) || sampleIsBetter(tls, p, pOld, pUpgrade) != 0) {
		goto __8
	}
	pUpgrade = pOld
__8:
	;
__6:
	;
	goto __4
__4:
	i--
	goto __3
	goto __5
__5:
	;
	if !(pUpgrade != 0) {
		goto __9
	}
	(*StatSample)(unsafe.Pointer(pUpgrade)).FiCol = (*StatSample)(unsafe.Pointer(pNew)).FiCol
	*(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pUpgrade)).FanEq + uintptr((*StatSample)(unsafe.Pointer(pUpgrade)).FiCol)*8)) = *(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pNew)).FanEq + uintptr((*StatSample)(unsafe.Pointer(pUpgrade)).FiCol)*8))
	goto find_new_min
__9:
	;
__2:
	;
	if !((*StatAccum)(unsafe.Pointer(p)).FnSample >= (*StatAccum)(unsafe.Pointer(p)).FmxSample) {
		goto __10
	}
	pMin = (*StatAccum)(unsafe.Pointer(p)).Fa + uintptr((*StatAccum)(unsafe.Pointer(p)).FiMin)*48
	anEq = (*StatSample)(unsafe.Pointer(pMin)).FanEq
	anLt = (*StatSample)(unsafe.Pointer(pMin)).FanLt
	anDLt = (*StatSample)(unsafe.Pointer(pMin)).FanDLt
	sampleClear(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, pMin)
	libc.Xmemmove(tls, pMin, pMin+1*48, uint64(unsafe.Sizeof(StatSample{}))*uint64((*StatAccum)(unsafe.Pointer(p)).FnSample-(*StatAccum)(unsafe.Pointer(p)).FiMin-1))
	pSample = (*StatAccum)(unsafe.Pointer(p)).Fa + uintptr((*StatAccum)(unsafe.Pointer(p)).FnSample-1)*48
	(*StatSample)(unsafe.Pointer(pSample)).FnRowid = U32(0)
	(*StatSample)(unsafe.Pointer(pSample)).FanEq = anEq
	(*StatSample)(unsafe.Pointer(pSample)).FanDLt = anDLt
	(*StatSample)(unsafe.Pointer(pSample)).FanLt = anLt
	(*StatAccum)(unsafe.Pointer(p)).FnSample = (*StatAccum)(unsafe.Pointer(p)).FmxSample - 1
__10:
	;
	pSample = (*StatAccum)(unsafe.Pointer(p)).Fa + uintptr((*StatAccum)(unsafe.Pointer(p)).FnSample)*48
	sampleCopy(tls, p, pSample, pNew)
	(*StatAccum)(unsafe.Pointer(p)).FnSample++

	libc.Xmemset(tls, (*StatSample)(unsafe.Pointer(pSample)).FanEq, 0, uint64(unsafe.Sizeof(TRowcnt(0)))*uint64(nEqZero))

find_new_min:
	if !((*StatAccum)(unsafe.Pointer(p)).FnSample >= (*StatAccum)(unsafe.Pointer(p)).FmxSample) {
		goto __11
	}
	iMin = -1
	i = 0
__12:
	if !(i < (*StatAccum)(unsafe.Pointer(p)).FmxSample) {
		goto __14
	}
	if !((*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa+uintptr(i)*48)).FisPSample != 0) {
		goto __15
	}
	goto __13
__15:
	;
	if !(iMin < 0 || sampleIsBetter(tls, p, (*StatAccum)(unsafe.Pointer(p)).Fa+uintptr(iMin)*48, (*StatAccum)(unsafe.Pointer(p)).Fa+uintptr(i)*48) != 0) {
		goto __16
	}
	iMin = i
__16:
	;
	goto __13
__13:
	i++
	goto __12
	goto __14
__14:
	;
	(*StatAccum)(unsafe.Pointer(p)).FiMin = iMin
__11:
}

func samplePushPrevious(tls *libc.TLS, p uintptr, iChng int32) {
	var i int32

	for i = (*StatAccum)(unsafe.Pointer(p)).FnCol - 2; i >= iChng; i-- {
		var pBest uintptr = (*StatAccum)(unsafe.Pointer(p)).FaBest + uintptr(i)*48
		*(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer(pBest)).FanEq + uintptr(i)*8)) = *(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8))
		if (*StatAccum)(unsafe.Pointer(p)).FnSample < (*StatAccum)(unsafe.Pointer(p)).FmxSample || sampleIsBetter(tls, p, pBest, (*StatAccum)(unsafe.Pointer(p)).Fa+uintptr((*StatAccum)(unsafe.Pointer(p)).FiMin)*48) != 0 {
			sampleInsert(tls, p, pBest, i)
		}
	}

	for i = (*StatAccum)(unsafe.Pointer(p)).FnSample - 1; i >= 0; i-- {
		var j int32
		for j = (*StatAccum)(unsafe.Pointer(p)).FnMaxEqZero; j < (*StatAccum)(unsafe.Pointer(p)).FnCol; j++ {
		}
	}

	if iChng < (*StatAccum)(unsafe.Pointer(p)).FnMaxEqZero {
		for i = (*StatAccum)(unsafe.Pointer(p)).FnSample - 1; i >= 0; i-- {
			var j int32
			for j = iChng; j < (*StatAccum)(unsafe.Pointer(p)).FnCol; j++ {
				if *(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa+uintptr(i)*48)).FanEq + uintptr(j)*8)) == uint64(0) {
					*(*TRowcnt)(unsafe.Pointer((*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa+uintptr(i)*48)).FanEq + uintptr(j)*8)) = *(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(j)*8))
				}
			}
		}
		(*StatAccum)(unsafe.Pointer(p)).FnMaxEqZero = iChng
	}
}

func statPush(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var i int32

	var p uintptr = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
	var iChng int32 = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))

	_ = argc
	_ = context

	if (*StatAccum)(unsafe.Pointer(p)).FnRow == uint64(0) {
		for i = 0; i < (*StatAccum)(unsafe.Pointer(p)).FnCol; i++ {
			*(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8)) = uint64(1)
		}
	} else {
		if (*StatAccum)(unsafe.Pointer(p)).FmxSample != 0 {
			samplePushPrevious(tls, p, iChng)
		}

		for i = 0; i < iChng; i++ {
			*(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8))++
		}
		for i = iChng; i < (*StatAccum)(unsafe.Pointer(p)).FnCol; i++ {
			*(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt + uintptr(i)*8))++
			if (*StatAccum)(unsafe.Pointer(p)).FmxSample != 0 {
				*(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanLt + uintptr(i)*8)) += *(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8))
			}
			*(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanEq + uintptr(i)*8)) = uint64(1)
		}
	}

	(*StatAccum)(unsafe.Pointer(p)).FnRow++
	if (*StatAccum)(unsafe.Pointer(p)).FmxSample != 0 {
		var nLt TRowcnt
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))) == SQLITE_INTEGER {
			sampleSetRowidInt64(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, p+40, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))))
		} else {
			sampleSetRowid(tls, (*StatAccum)(unsafe.Pointer(p)).Fdb, p+40, Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))),
				Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))))
		}
		(*StatAccum)(unsafe.Pointer(p)).Fcurrent.FiHash = libc.AssignPtrUint32(p+100, (*StatAccum)(unsafe.Pointer(p)).FiPrn*U32(1103515245)+U32(12345))

		nLt = *(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanLt + uintptr((*StatAccum)(unsafe.Pointer(p)).FnCol-1)*8))

		if nLt/(*StatAccum)(unsafe.Pointer(p)).FnPSample != (nLt+uint64(1))/(*StatAccum)(unsafe.Pointer(p)).FnPSample {
			(*StatAccum)(unsafe.Pointer(p)).Fcurrent.FisPSample = U8(1)
			(*StatAccum)(unsafe.Pointer(p)).Fcurrent.FiCol = 0
			sampleInsert(tls, p, p+40, (*StatAccum)(unsafe.Pointer(p)).FnCol-1)
			(*StatAccum)(unsafe.Pointer(p)).Fcurrent.FisPSample = U8(0)
		}

		for i = 0; i < (*StatAccum)(unsafe.Pointer(p)).FnCol-1; i++ {
			(*StatAccum)(unsafe.Pointer(p)).Fcurrent.FiCol = i
			if i >= iChng || sampleIsBetterPost(tls, p, p+40, (*StatAccum)(unsafe.Pointer(p)).FaBest+uintptr(i)*48) != 0 {
				sampleCopy(tls, p, (*StatAccum)(unsafe.Pointer(p)).FaBest+uintptr(i)*48, p+40)
			}
		}
	} else if (*StatAccum)(unsafe.Pointer(p)).FnLimit != 0 && (*StatAccum)(unsafe.Pointer(p)).FnRow > TRowcnt((*StatAccum)(unsafe.Pointer(p)).FnLimit)*TRowcnt(int32((*StatAccum)(unsafe.Pointer(p)).FnSkipAhead)+1) {
		(*StatAccum)(unsafe.Pointer(p)).FnSkipAhead++
		Xsqlite3_result_int(tls, context, libc.Bool32(*(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt)) > uint64(0)))
	}
}

var statPushFuncdef = FuncDef{
	FnArg:      int8(2 + IsStat4),
	FfuncFlags: U32(SQLITE_UTF8),
	FxSFunc:    0,
	FzName:     ts + 14822}

func statGet(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(88)
	defer tls.Free(88)

	var p uintptr = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))

	var eCall int32 = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))

	if eCall == STAT_GET_STAT1 {
		var i int32

		Xsqlite3StrAccumInit(tls, bp+24, uintptr(0), uintptr(0), 0, ((*StatAccum)(unsafe.Pointer(p)).FnKeyCol+1)*100)
		Xsqlite3_str_appendf(tls, bp+24, ts+14832,
			libc.VaList(bp, func() uint64 {
				if (*StatAccum)(unsafe.Pointer(p)).FnSkipAhead != 0 {
					return (*StatAccum)(unsafe.Pointer(p)).FnEst
				}
				return (*StatAccum)(unsafe.Pointer(p)).FnRow
			}()))
		for i = 0; i < (*StatAccum)(unsafe.Pointer(p)).FnKeyCol; i++ {
			var nDistinct U64 = *(*TRowcnt)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fcurrent.FanDLt + uintptr(i)*8)) + uint64(1)
			var iVal U64 = ((*StatAccum)(unsafe.Pointer(p)).FnRow + nDistinct - uint64(1)) / nDistinct
			if iVal == uint64(2) && (*StatAccum)(unsafe.Pointer(p)).FnRow*uint64(10) <= nDistinct*uint64(11) {
				iVal = uint64(1)
			}
			Xsqlite3_str_appendf(tls, bp+24, ts+14837, libc.VaList(bp+8, iVal))

		}
		Xsqlite3ResultStrAccum(tls, context, bp+24)
	} else if eCall == STAT_GET_ROWID {
		if (*StatAccum)(unsafe.Pointer(p)).FiGet < 0 {
			samplePushPrevious(tls, p, 0)
			(*StatAccum)(unsafe.Pointer(p)).FiGet = 0
		}
		if (*StatAccum)(unsafe.Pointer(p)).FiGet < (*StatAccum)(unsafe.Pointer(p)).FnSample {
			var pS uintptr = (*StatAccum)(unsafe.Pointer(p)).Fa + uintptr((*StatAccum)(unsafe.Pointer(p)).FiGet)*48
			if (*StatSample)(unsafe.Pointer(pS)).FnRowid == U32(0) {
				Xsqlite3_result_int64(tls, context, *(*I64)(unsafe.Pointer(pS + 24)))
			} else {
				Xsqlite3_result_blob(tls, context, *(*uintptr)(unsafe.Pointer(pS + 24)), int32((*StatSample)(unsafe.Pointer(pS)).FnRowid),
					libc.UintptrFromInt32(-1))
			}
		}
	} else {
		var aCnt uintptr = uintptr(0)

		var i int32

		switch eCall {
		case STAT_GET_NEQ:
			aCnt = (*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa + uintptr((*StatAccum)(unsafe.Pointer(p)).FiGet)*48)).FanEq
			break
			fallthrough
		case STAT_GET_NLT:
			aCnt = (*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa + uintptr((*StatAccum)(unsafe.Pointer(p)).FiGet)*48)).FanLt
			break
			fallthrough
		default:
			{
				aCnt = (*StatSample)(unsafe.Pointer((*StatAccum)(unsafe.Pointer(p)).Fa + uintptr((*StatAccum)(unsafe.Pointer(p)).FiGet)*48)).FanDLt
				(*StatAccum)(unsafe.Pointer(p)).FiGet++
				break

			}
		}
		Xsqlite3StrAccumInit(tls, bp+56, uintptr(0), uintptr(0), 0, (*StatAccum)(unsafe.Pointer(p)).FnCol*100)
		for i = 0; i < (*StatAccum)(unsafe.Pointer(p)).FnCol; i++ {
			Xsqlite3_str_appendf(tls, bp+56, ts+14843, libc.VaList(bp+16, *(*TRowcnt)(unsafe.Pointer(aCnt + uintptr(i)*8))))
		}
		if (*Sqlite3_str)(unsafe.Pointer(bp+56)).FnChar != 0 {
			(*Sqlite3_str)(unsafe.Pointer(bp+56)).FnChar--
		}
		Xsqlite3ResultStrAccum(tls, context, bp+56)
	}
	_ = argc
}

var statGetFuncdef = FuncDef{
	FnArg:      int8(1 + IsStat4),
	FfuncFlags: U32(SQLITE_UTF8),
	FxSFunc:    0,
	FzName:     ts + 14849}

func callStatGet(tls *libc.TLS, pParse uintptr, regStat int32, iParam int32, regOut int32) {
	Xsqlite3VdbeAddOp2(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, OP_Integer, iParam, regStat+1)

	Xsqlite3VdbeAddFunctionCall(tls, pParse, 0, regStat, regOut, 1+IsStat4,
		uintptr(unsafe.Pointer(&statGetFuncdef)), 0)
}

func analyzeVdbeCommentIndexWithColumnName(tls *libc.TLS, v uintptr, pIdx uintptr, k int32) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var i int32

	i = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(k)*2)))
	if i == -1 {
		Xsqlite3VdbeComment(tls, v, ts+11309, libc.VaList(bp, (*Index)(unsafe.Pointer(pIdx)).FzName))
	} else if i == -2 {
		Xsqlite3VdbeComment(tls, v, ts+14858, libc.VaList(bp+8, (*Index)(unsafe.Pointer(pIdx)).FzName, k))
	} else {
		Xsqlite3VdbeComment(tls, v, ts+11397, libc.VaList(bp+24, (*Index)(unsafe.Pointer(pIdx)).FzName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FaCol+uintptr(i)*24)).FzCnName))
	}
}

func analyzeOneTable(tls *libc.TLS, pParse uintptr, pTab uintptr, pOnlyIdx uintptr, iStatCur int32, iMem int32, iTab int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pIdx uintptr
	var iIdxCur int32
	var iTabCur int32
	var v uintptr
	var i int32
	var jZeroRows int32 = -1
	var iDb int32
	var needTableCnt U8 = U8(1)
	var regNewRowid int32 = libc.PostIncInt32(&iMem, 1)
	var regStat int32 = libc.PostIncInt32(&iMem, 1)
	var regChng int32 = libc.PostIncInt32(&iMem, 1)
	var regRowid int32 = libc.PostIncInt32(&iMem, 1)
	var regTemp int32 = libc.PostIncInt32(&iMem, 1)
	var regTemp2 int32 = libc.PostIncInt32(&iMem, 1)
	var regTabname int32 = libc.PostIncInt32(&iMem, 1)
	var regIdxname int32 = libc.PostIncInt32(&iMem, 1)
	var regStat1 int32 = libc.PostIncInt32(&iMem, 1)
	var regPrev int32 = iMem
	var pStat1 uintptr = uintptr(0)

	(*Parse)(unsafe.Pointer(pParse)).FnMem = func() int32 {
		if (*Parse)(unsafe.Pointer(pParse)).FnMem > iMem {
			return (*Parse)(unsafe.Pointer(pParse)).FnMem
		}
		return iMem
	}()
	v = Xsqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) || pTab == uintptr(0) {
		return
	}
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM) {
		return
	}
	if Xsqlite3_strlike(tls, ts+14870, (*Table)(unsafe.Pointer(pTab)).FzName, uint32('\\')) == 0 {
		return
	}

	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	if Xsqlite3AuthCheck(tls, pParse, SQLITE_ANALYZE, (*Table)(unsafe.Pointer(pTab)).FzName, uintptr(0),
		(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName) != 0 {
		return
	}

	if (*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback != 0 {
		pStat1 = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Table{}))+uint64(13))
		if pStat1 == uintptr(0) {
			return
		}
		(*Table)(unsafe.Pointer(pStat1)).FzName = pStat1 + 1*104
		libc.Xmemcpy(tls, (*Table)(unsafe.Pointer(pStat1)).FzName, ts+14732, uint64(13))
		(*Table)(unsafe.Pointer(pStat1)).FnCol = int16(3)
		(*Table)(unsafe.Pointer(pStat1)).FiPKey = int16(-1)
		Xsqlite3VdbeAddOp4(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, OP_Noop, 0, 0, 0, pStat1, -6)
	}

	Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*Table)(unsafe.Pointer(pTab)).FzName)
	iTabCur = libc.PostIncInt32(&iTab, 1)
	iIdxCur = libc.PostIncInt32(&iTab, 1)
	(*Parse)(unsafe.Pointer(pParse)).FnTab = func() int32 {
		if (*Parse)(unsafe.Pointer(pParse)).FnTab > iTab {
			return (*Parse)(unsafe.Pointer(pParse)).FnTab
		}
		return iTab
	}()
	Xsqlite3OpenTable(tls, pParse, iTabCur, iDb, pTab, OP_OpenRead)
	Xsqlite3VdbeLoadString(tls, v, regTabname, (*Table)(unsafe.Pointer(pTab)).FzName)

	for pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
		var nCol int32
		var addrRewind int32
		var addrNextRow int32
		var zIdxName uintptr
		var nColTest int32

		if pOnlyIdx != 0 && pOnlyIdx != pIdx {
			continue
		}
		if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
			needTableCnt = U8(0)
		}
		if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) && int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
			nCol = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
			zIdxName = (*Table)(unsafe.Pointer(pTab)).FzName
			nColTest = nCol - 1
		} else {
			nCol = int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
			zIdxName = (*Index)(unsafe.Pointer(pIdx)).FzName
			if uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x8>>3)) != 0 {
				nColTest = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) - 1
			} else {
				nColTest = nCol - 1
			}
		}

		Xsqlite3VdbeLoadString(tls, v, regIdxname, zIdxName)
		Xsqlite3VdbeComment(tls, v, ts+14880, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName, zIdxName))

		(*Parse)(unsafe.Pointer(pParse)).FnMem = func() int32 {
			if (*Parse)(unsafe.Pointer(pParse)).FnMem > regPrev+nColTest {
				return (*Parse)(unsafe.Pointer(pParse)).FnMem
			}
			return regPrev + nColTest
		}()

		Xsqlite3VdbeAddOp3(tls, v, OP_OpenRead, iIdxCur, int32((*Index)(unsafe.Pointer(pIdx)).Ftnum), iDb)
		Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
		Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+16, (*Index)(unsafe.Pointer(pIdx)).FzName))

		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, nCol, regStat+1)

		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol), regRowid)
		if (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_Stat4) == U32(0) {
			Xsqlite3VdbeAddOp2(tls, v, OP_Count, iIdxCur, regTemp)
			addrRewind = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, iIdxCur)

		} else {
			addrRewind = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, iIdxCur)

			Xsqlite3VdbeAddOp3(tls, v, OP_Count, iIdxCur, regTemp, 1)
		}

		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, (*Sqlite3)(unsafe.Pointer(db)).FnAnalysisLimit, regTemp2)
		Xsqlite3VdbeAddFunctionCall(tls, pParse, 0, regStat+1, regStat, 4,
			uintptr(unsafe.Pointer(&statInitFuncdef)), 0)

		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regChng)
		addrNextRow = Xsqlite3VdbeCurrentAddr(tls, v)

		if nColTest > 0 {
			var endDistinctTest int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
			var aGotoChng uintptr
			aGotoChng = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(int32(0)))*uint64(nColTest))
			if aGotoChng == uintptr(0) {
				continue
			}

			Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
			addrNextRow = Xsqlite3VdbeCurrentAddr(tls, v)
			if nColTest == 1 && int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) == 1 && int32((*Index)(unsafe.Pointer(pIdx)).FonError) != OE_None {
				Xsqlite3VdbeAddOp2(tls, v, OP_NotNull, regPrev, endDistinctTest)

			}
			for i = 0; i < nColTest; i++ {
				var pColl uintptr = Xsqlite3LocateCollSeq(tls, pParse, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*8)))
				Xsqlite3VdbeAddOp2(tls, v, OP_Integer, i, regChng)
				Xsqlite3VdbeAddOp3(tls, v, OP_Column, iIdxCur, i, regTemp)
				analyzeVdbeCommentIndexWithColumnName(tls, v, pIdx, i)
				*(*int32)(unsafe.Pointer(aGotoChng + uintptr(i)*4)) = Xsqlite3VdbeAddOp4(tls, v, OP_Ne, regTemp, 0, regPrev+i, pColl, -2)
				Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))

			}
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer, nColTest, regChng)
			Xsqlite3VdbeGoto(tls, v, endDistinctTest)

			Xsqlite3VdbeJumpHere(tls, v, addrNextRow-1)
			for i = 0; i < nColTest; i++ {
				Xsqlite3VdbeJumpHere(tls, v, *(*int32)(unsafe.Pointer(aGotoChng + uintptr(i)*4)))
				Xsqlite3VdbeAddOp3(tls, v, OP_Column, iIdxCur, i, regPrev+i)
				analyzeVdbeCommentIndexWithColumnName(tls, v, pIdx, i)
			}
			Xsqlite3VdbeResolveLabel(tls, v, endDistinctTest)
			Xsqlite3DbFree(tls, db, aGotoChng)
		}

		if (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_Stat4) == U32(0) {
			if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
				Xsqlite3VdbeAddOp2(tls, v, OP_IdxRowid, iIdxCur, regRowid)
			} else {
				var pPk uintptr = Xsqlite3PrimaryKeyIndex(tls, (*Index)(unsafe.Pointer(pIdx)).FpTable)
				var j int32
				var k int32
				var regKey int32
				regKey = Xsqlite3GetTempRange(tls, pParse, int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol))
				for j = 0; j < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol); j++ {
					k = int32(Xsqlite3TableColumnToIndex(tls, pIdx, *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))

					Xsqlite3VdbeAddOp3(tls, v, OP_Column, iIdxCur, k, regKey+j)
					analyzeVdbeCommentIndexWithColumnName(tls, v, pIdx, k)
				}
				Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regKey, int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol), regRowid)
				Xsqlite3ReleaseTempRange(tls, pParse, regKey, int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol))
			}
		}

		{
			Xsqlite3VdbeAddFunctionCall(tls, pParse, 1, regStat, regTemp, 2+IsStat4,
				uintptr(unsafe.Pointer(&statPushFuncdef)), 0)
			if (*Sqlite3)(unsafe.Pointer(db)).FnAnalysisLimit != 0 {
				var j1 int32
				var j2 int32
				var j3 int32
				j1 = Xsqlite3VdbeAddOp1(tls, v, OP_IsNull, regTemp)
				j2 = Xsqlite3VdbeAddOp1(tls, v, OP_If, regTemp)
				j3 = Xsqlite3VdbeAddOp4Int(tls, v, OP_SeekGT, iIdxCur, 0, regPrev, 1)

				Xsqlite3VdbeJumpHere(tls, v, j1)
				Xsqlite3VdbeAddOp2(tls, v, OP_Next, iIdxCur, addrNextRow)
				Xsqlite3VdbeJumpHere(tls, v, j2)
				Xsqlite3VdbeJumpHere(tls, v, j3)
			} else {
				Xsqlite3VdbeAddOp2(tls, v, OP_Next, iIdxCur, addrNextRow)
			}

		}

		callStatGet(tls, pParse, regStat, STAT_GET_STAT1, regStat1)

		Xsqlite3VdbeAddOp4(tls, v, OP_MakeRecord, regTabname, 3, regTemp, ts+14899, 0)
		Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, iStatCur, regNewRowid)
		Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iStatCur, regTemp, regNewRowid)
		Xsqlite3VdbeChangeP4(tls, v, -1, pStat1, -5)
		Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))

		if (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_Stat4) == U32(0) && (*Sqlite3)(unsafe.Pointer(db)).FnAnalysisLimit == 0 {
			var regEq int32 = regStat1
			var regLt int32 = regStat1 + 1
			var regDLt int32 = regStat1 + 2
			var regSample int32 = regStat1 + 3
			var regCol int32 = regStat1 + 4
			var regSampleRowid int32 = regCol + nCol
			var addrNext int32
			var addrIsNull int32
			var seekOp U8
			if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
				seekOp = uint8(OP_NotExists)
			} else {
				seekOp = uint8(OP_NotFound)
			}

			(*Parse)(unsafe.Pointer(pParse)).FnMem = func() int32 {
				if (*Parse)(unsafe.Pointer(pParse)).FnMem > regCol+nCol {
					return (*Parse)(unsafe.Pointer(pParse)).FnMem
				}
				return regCol + nCol
			}()

			addrNext = Xsqlite3VdbeCurrentAddr(tls, v)
			callStatGet(tls, pParse, regStat, STAT_GET_ROWID, regSampleRowid)
			addrIsNull = Xsqlite3VdbeAddOp1(tls, v, OP_IsNull, regSampleRowid)

			callStatGet(tls, pParse, regStat, STAT_GET_NEQ, regEq)
			callStatGet(tls, pParse, regStat, STAT_GET_NLT, regLt)
			callStatGet(tls, pParse, regStat, STAT_GET_NDLT, regDLt)
			Xsqlite3VdbeAddOp4Int(tls, v, int32(seekOp), iTabCur, addrNext, regSampleRowid, 0)

			for i = 0; i < nCol; i++ {
				Xsqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iTabCur, i, regCol+i)
			}
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regCol, nCol, regSample)
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regTabname, 6, regTemp)
			Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, iStatCur+1, regNewRowid)
			Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iStatCur+1, regTemp, regNewRowid)
			Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 1, addrNext)
			Xsqlite3VdbeJumpHere(tls, v, addrIsNull)
		}

		Xsqlite3VdbeJumpHere(tls, v, addrRewind)
	}

	if pOnlyIdx == uintptr(0) && needTableCnt != 0 {
		Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+24, (*Table)(unsafe.Pointer(pTab)).FzName))
		Xsqlite3VdbeAddOp2(tls, v, OP_Count, iTabCur, regStat1)
		jZeroRows = Xsqlite3VdbeAddOp1(tls, v, OP_IfNot, regStat1)
		Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regIdxname)

		Xsqlite3VdbeAddOp4(tls, v, OP_MakeRecord, regTabname, 3, regTemp, ts+14899, 0)
		Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, iStatCur, regNewRowid)
		Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iStatCur, regTemp, regNewRowid)
		Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
		Xsqlite3VdbeChangeP4(tls, v, -1, pStat1, -5)
		Xsqlite3VdbeJumpHere(tls, v, jZeroRows)
	}
}

func loadAnalysis(tls *libc.TLS, pParse uintptr, iDb int32) {
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	if v != 0 {
		Xsqlite3VdbeAddOp1(tls, v, OP_LoadAnalysis, iDb)
	}
}

func analyzeDatabase(tls *libc.TLS, pParse uintptr, iDb int32) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pSchema uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
	var k uintptr
	var iStatCur int32
	var iMem int32
	var iTab int32

	Xsqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	iStatCur = (*Parse)(unsafe.Pointer(pParse)).FnTab
	*(*int32)(unsafe.Pointer(pParse + 52)) += 3
	openStatTable(tls, pParse, iDb, iStatCur, uintptr(0), uintptr(0))
	iMem = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	iTab = (*Parse)(unsafe.Pointer(pParse)).FnTab

	for k = (*Hash)(unsafe.Pointer(pSchema + 8)).Ffirst; k != 0; k = (*HashElem)(unsafe.Pointer(k)).Fnext {
		var pTab uintptr = (*HashElem)(unsafe.Pointer(k)).Fdata
		analyzeOneTable(tls, pParse, pTab, uintptr(0), iStatCur, iMem, iTab)
	}
	loadAnalysis(tls, pParse, iDb)
}

func analyzeTable(tls *libc.TLS, pParse uintptr, pTab uintptr, pOnlyIdx uintptr) {
	var iDb int32
	var iStatCur int32

	iDb = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Table)(unsafe.Pointer(pTab)).FpSchema)
	Xsqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	iStatCur = (*Parse)(unsafe.Pointer(pParse)).FnTab
	*(*int32)(unsafe.Pointer(pParse + 52)) += 3
	if pOnlyIdx != 0 {
		openStatTable(tls, pParse, iDb, iStatCur, (*Index)(unsafe.Pointer(pOnlyIdx)).FzName, ts+14903)
	} else {
		openStatTable(tls, pParse, iDb, iStatCur, (*Table)(unsafe.Pointer(pTab)).FzName, ts+14907)
	}
	analyzeOneTable(tls, pParse, pTab, pOnlyIdx, iStatCur, (*Parse)(unsafe.Pointer(pParse)).FnMem+1, (*Parse)(unsafe.Pointer(pParse)).FnTab)
	loadAnalysis(tls, pParse, iDb)
}

func Xsqlite3Analyze(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var iDb int32
	var i int32
	var z uintptr
	var zDb uintptr
	var pTab uintptr
	var pIdx uintptr

	var v uintptr

	if SQLITE_OK != Xsqlite3ReadSchema(tls, pParse) {
		return
	}

	if pName1 == uintptr(0) {
		for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			if i == 1 {
				continue
			}
			analyzeDatabase(tls, pParse, i)
		}
	} else if (*Token)(unsafe.Pointer(pName2)).Fn == uint32(0) && libc.AssignInt32(&iDb, Xsqlite3FindDb(tls, db, pName1)) >= 0 {
		analyzeDatabase(tls, pParse, iDb)
	} else {
		iDb = Xsqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
		if iDb >= 0 {
			if (*Token)(unsafe.Pointer(pName2)).Fn != 0 {
				zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
			} else {
				zDb = uintptr(0)
			}
			z = Xsqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
			if z != 0 {
				if libc.AssignUintptr(&pIdx, Xsqlite3FindIndex(tls, db, z, zDb)) != uintptr(0) {
					analyzeTable(tls, pParse, (*Index)(unsafe.Pointer(pIdx)).FpTable, pIdx)
				} else if libc.AssignUintptr(&pTab, Xsqlite3LocateTable(tls, pParse, uint32(0), z, zDb)) != uintptr(0) {
					analyzeTable(tls, pParse, pTab, uintptr(0))
				}
				Xsqlite3DbFree(tls, db, z)
			}
		}
	}
	if int32((*Sqlite3)(unsafe.Pointer(db)).FnSqlExec) == 0 && libc.AssignUintptr(&v, Xsqlite3GetVdbe(tls, pParse)) != uintptr(0) {
		Xsqlite3VdbeAddOp0(tls, v, OP_Expire)
	}
}

type analysisInfo = struct {
	Fdb        uintptr
	FzDatabase uintptr
}

type AnalysisInfo = analysisInfo

func decodeIntArray(tls *libc.TLS, zIntArray uintptr, nOut int32, aOut uintptr, aLog uintptr, pIndex uintptr) {
	var z uintptr = zIntArray
	var c int32
	var i int32
	var v TRowcnt

	if z == uintptr(0) {
		z = ts + 1636
	}
	for i = 0; *(*uint8)(unsafe.Pointer(z)) != 0 && i < nOut; i++ {
		v = uint64(0)
		for libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z)))) >= '0' && c <= '9' {
			v = v*uint64(10) + TRowcnt(c) - uint64('0')
			z++
		}
		if aOut != 0 {
			*(*TRowcnt)(unsafe.Pointer(aOut + uintptr(i)*8)) = v
		}
		if aLog != 0 {
			*(*LogEst)(unsafe.Pointer(aLog + uintptr(i)*2)) = Xsqlite3LogEst(tls, v)
		}
		if int32(*(*uint8)(unsafe.Pointer(z))) == ' ' {
			z++
		}
	}
	if pIndex != 0 {
		libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(0), 2, 0x4)
		libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(0), 6, 0x40)
		for *(*uint8)(unsafe.Pointer(z)) != 0 {
			if Xsqlite3_strglob(tls, ts+14911, z) == 0 {
				libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(1), 2, 0x4)
			} else if Xsqlite3_strglob(tls, ts+14922, z) == 0 {
				var sz int32 = Xsqlite3Atoi(tls, z+uintptr(3))
				if sz < 2 {
					sz = 2
				}
				(*Index)(unsafe.Pointer(pIndex)).FszIdxRow = Xsqlite3LogEst(tls, uint64(sz))
			} else if Xsqlite3_strglob(tls, ts+14932, z) == 0 {
				libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(1), 6, 0x40)
			}
			for int32(*(*uint8)(unsafe.Pointer(z))) != 0 && int32(*(*uint8)(unsafe.Pointer(z))) != ' ' {
				z++
			}
			for int32(*(*uint8)(unsafe.Pointer(z))) == ' ' {
				z++
			}
		}
	}
}

func analysisLoader(tls *libc.TLS, pData uintptr, argc int32, argv uintptr, NotUsed uintptr) int32 {
	bp := tls.Alloc(152)
	defer tls.Free(152)

	var pInfo uintptr = pData
	var pIndex uintptr
	var pTable uintptr
	var z uintptr

	_ = NotUsed
	_ = argc

	if argv == uintptr(0) || *(*uintptr)(unsafe.Pointer(argv)) == uintptr(0) || *(*uintptr)(unsafe.Pointer(argv + 2*8)) == uintptr(0) {
		return 0
	}
	pTable = Xsqlite3FindTable(tls, (*AnalysisInfo)(unsafe.Pointer(pInfo)).Fdb, *(*uintptr)(unsafe.Pointer(argv)), (*AnalysisInfo)(unsafe.Pointer(pInfo)).FzDatabase)
	if pTable == uintptr(0) {
		return 0
	}
	if *(*uintptr)(unsafe.Pointer(argv + 1*8)) == uintptr(0) {
		pIndex = uintptr(0)
	} else if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*8))) == 0 {
		pIndex = Xsqlite3PrimaryKeyIndex(tls, pTable)
	} else {
		pIndex = Xsqlite3FindIndex(tls, (*AnalysisInfo)(unsafe.Pointer(pInfo)).Fdb, *(*uintptr)(unsafe.Pointer(argv + 1*8)), (*AnalysisInfo)(unsafe.Pointer(pInfo)).FzDatabase)
	}
	z = *(*uintptr)(unsafe.Pointer(argv + 2*8))

	if pIndex != 0 {
		var aiRowEst uintptr = uintptr(0)
		var nCol int32 = int32((*Index)(unsafe.Pointer(pIndex)).FnKeyCol) + 1

		if (*Index)(unsafe.Pointer(pIndex)).FaiRowEst == uintptr(0) {
			(*Index)(unsafe.Pointer(pIndex)).FaiRowEst = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(TRowcnt(0)))*uint64(nCol))
			if (*Index)(unsafe.Pointer(pIndex)).FaiRowEst == uintptr(0) {
				Xsqlite3OomFault(tls, (*AnalysisInfo)(unsafe.Pointer(pInfo)).Fdb)
			}
		}
		aiRowEst = (*Index)(unsafe.Pointer(pIndex)).FaiRowEst
		libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(0), 2, 0x4)
		decodeIntArray(tls, z, nCol, aiRowEst, (*Index)(unsafe.Pointer(pIndex)).FaiRowLogEst, pIndex)
		libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(1), 7, 0x80)
		if (*Index)(unsafe.Pointer(pIndex)).FpPartIdxWhere == uintptr(0) {
			(*Table)(unsafe.Pointer(pTable)).FnRowLogEst = *(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiRowLogEst))
			*(*U32)(unsafe.Pointer(pTable + 48)) |= U32(TF_HasStat1)
		}
	} else {
		(*Index)(unsafe.Pointer(bp)).FszIdxRow = (*Table)(unsafe.Pointer(pTable)).FszTabRow
		decodeIntArray(tls, z, 1, uintptr(0), pTable+58, bp)
		(*Table)(unsafe.Pointer(pTable)).FszTabRow = (*Index)(unsafe.Pointer(bp)).FszIdxRow
		*(*U32)(unsafe.Pointer(pTable + 48)) |= U32(TF_HasStat1)
	}

	return 0
}

func Xsqlite3DeleteIndexSamples(tls *libc.TLS, db uintptr, pIdx uintptr) {
	if (*Index)(unsafe.Pointer(pIdx)).FaSample != 0 {
		var j int32
		for j = 0; j < (*Index)(unsafe.Pointer(pIdx)).FnSample; j++ {
			var p uintptr = (*Index)(unsafe.Pointer(pIdx)).FaSample + uintptr(j)*40
			Xsqlite3DbFree(tls, db, (*IndexSample)(unsafe.Pointer(p)).Fp)
		}
		Xsqlite3DbFree(tls, db, (*Index)(unsafe.Pointer(pIdx)).FaSample)
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
		(*Index)(unsafe.Pointer(pIdx)).FnSample = 0
		(*Index)(unsafe.Pointer(pIdx)).FaSample = uintptr(0)
	}
}

func initAvgEq(tls *libc.TLS, pIdx uintptr) {
	if pIdx != 0 {
		var aSample uintptr = (*Index)(unsafe.Pointer(pIdx)).FaSample
		var pFinal uintptr = aSample + uintptr((*Index)(unsafe.Pointer(pIdx)).FnSample-1)*40
		var iCol int32
		var nCol int32 = 1
		if (*Index)(unsafe.Pointer(pIdx)).FnSampleCol > 1 {
			nCol = (*Index)(unsafe.Pointer(pIdx)).FnSampleCol - 1
			*(*TRowcnt)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaAvgEq + uintptr(nCol)*8)) = uint64(1)
		}
		for iCol = 0; iCol < nCol; iCol++ {
			var nSample int32 = (*Index)(unsafe.Pointer(pIdx)).FnSample
			var i int32
			var sumEq TRowcnt = uint64(0)
			var avgEq TRowcnt = uint64(0)
			var nRow TRowcnt
			var nSum100 I64 = int64(0)
			var nDist100 I64

			if !(int32((*Index)(unsafe.Pointer(pIdx)).FaiRowEst) != 0) || iCol >= int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) || *(*TRowcnt)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiRowEst + uintptr(iCol+1)*8)) == uint64(0) {
				nRow = *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(pFinal)).FanLt + uintptr(iCol)*8))
				nDist100 = I64(TRowcnt(int64(100)) * *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(pFinal)).FanDLt + uintptr(iCol)*8)))
				nSample--
			} else {
				nRow = *(*TRowcnt)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiRowEst))
				nDist100 = I64(TRowcnt(int64(100)) * *(*TRowcnt)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiRowEst)) / *(*TRowcnt)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiRowEst + uintptr(iCol+1)*8)))
			}
			(*Index)(unsafe.Pointer(pIdx)).FnRowEst0 = nRow

			for i = 0; i < nSample; i++ {
				if i == (*Index)(unsafe.Pointer(pIdx)).FnSample-1 ||
					*(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(i)*40)).FanDLt + uintptr(iCol)*8)) != *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(i+1)*40)).FanDLt + uintptr(iCol)*8)) {
					sumEq = sumEq + *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(i)*40)).FanEq + uintptr(iCol)*8))
					nSum100 = nSum100 + int64(100)
				}
			}

			if nDist100 > nSum100 && sumEq < nRow {
				avgEq = TRowcnt(int64(100)) * (nRow - sumEq) / TRowcnt(nDist100-nSum100)
			}
			if avgEq == uint64(0) {
				avgEq = uint64(1)
			}
			*(*TRowcnt)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaAvgEq + uintptr(iCol)*8)) = avgEq
		}
	}
}

func findIndexOrPrimaryKey(tls *libc.TLS, db uintptr, zName uintptr, zDb uintptr) uintptr {
	var pIdx uintptr = Xsqlite3FindIndex(tls, db, zName, zDb)
	if pIdx == uintptr(0) {
		var pTab uintptr = Xsqlite3FindTable(tls, db, zName, zDb)
		if pTab != 0 && !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
			pIdx = Xsqlite3PrimaryKeyIndex(tls, pTab)
		}
	}
	return pIdx
}

func loadStatTbl(tls *libc.TLS, db uintptr, zSql1 uintptr, zSql2 uintptr, zDb uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	var zSql uintptr
	var pPrevIdx uintptr = uintptr(0)
	var pSample uintptr

	zSql = Xsqlite3MPrintf(tls, db, zSql1, libc.VaList(bp, zDb))
	if !(zSql != 0) {
		return SQLITE_NOMEM
	}
	rc = Xsqlite3_prepare(tls, db, zSql, -1, bp+16, uintptr(0))
	Xsqlite3DbFree(tls, db, zSql)
	if rc != 0 {
		return rc
	}

	for Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) == SQLITE_ROW {
		var nIdxCol int32 = 1

		var zIndex uintptr
		var pIdx uintptr
		var nSample int32
		var nByte int32
		var i int32
		var pSpace uintptr

		zIndex = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 0)
		if zIndex == uintptr(0) {
			continue
		}
		nSample = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 1)
		pIdx = findIndexOrPrimaryKey(tls, db, zIndex, zDb)

		if pIdx == uintptr(0) {
			continue
		}

		if !((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) && int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
			nIdxCol = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
		} else {
			nIdxCol = int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
		}
		(*Index)(unsafe.Pointer(pIdx)).FnSampleCol = nIdxCol
		nByte = int32(uint64(unsafe.Sizeof(IndexSample{})) * uint64(nSample))
		nByte = int32(uint64(nByte) + uint64(unsafe.Sizeof(TRowcnt(0)))*uint64(nIdxCol)*uint64(3)*uint64(nSample))
		nByte = int32(uint64(nByte) + uint64(nIdxCol)*uint64(unsafe.Sizeof(TRowcnt(0))))

		(*Index)(unsafe.Pointer(pIdx)).FaSample = Xsqlite3DbMallocZero(tls, db, uint64(nByte))
		if (*Index)(unsafe.Pointer(pIdx)).FaSample == uintptr(0) {
			Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
			return SQLITE_NOMEM
		}
		pSpace = (*Index)(unsafe.Pointer(pIdx)).FaSample + uintptr(nSample)*40
		(*Index)(unsafe.Pointer(pIdx)).FaAvgEq = pSpace
		pSpace += 8 * uintptr(nIdxCol)
		*(*U32)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable + 48)) |= U32(TF_HasStat4)
		for i = 0; i < nSample; i++ {
			(*IndexSample)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40)).FanEq = pSpace
			pSpace += 8 * uintptr(nIdxCol)
			(*IndexSample)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40)).FanLt = pSpace
			pSpace += 8 * uintptr(nIdxCol)
			(*IndexSample)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSample + uintptr(i)*40)).FanDLt = pSpace
			pSpace += 8 * uintptr(nIdxCol)
		}

	}
	rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if rc != 0 {
		return rc
	}

	zSql = Xsqlite3MPrintf(tls, db, zSql2, libc.VaList(bp+8, zDb))
	if !(zSql != 0) {
		return SQLITE_NOMEM
	}
	rc = Xsqlite3_prepare(tls, db, zSql, -1, bp+16, uintptr(0))
	Xsqlite3DbFree(tls, db, zSql)
	if rc != 0 {
		return rc
	}

	for Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) == SQLITE_ROW {
		var zIndex uintptr
		var pIdx uintptr
		var nCol int32 = 1

		zIndex = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 0)
		if zIndex == uintptr(0) {
			continue
		}
		pIdx = findIndexOrPrimaryKey(tls, db, zIndex, zDb)
		if pIdx == uintptr(0) {
			continue
		}

		nCol = (*Index)(unsafe.Pointer(pIdx)).FnSampleCol
		if pIdx != pPrevIdx {
			initAvgEq(tls, pPrevIdx)
			pPrevIdx = pIdx
		}
		pSample = (*Index)(unsafe.Pointer(pIdx)).FaSample + uintptr((*Index)(unsafe.Pointer(pIdx)).FnSample)*40
		decodeIntArray(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 1), nCol, (*IndexSample)(unsafe.Pointer(pSample)).FanEq, uintptr(0), uintptr(0))
		decodeIntArray(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 2), nCol, (*IndexSample)(unsafe.Pointer(pSample)).FanLt, uintptr(0), uintptr(0))
		decodeIntArray(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 3), nCol, (*IndexSample)(unsafe.Pointer(pSample)).FanDLt, uintptr(0), uintptr(0))

		(*IndexSample)(unsafe.Pointer(pSample)).Fn = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 4)
		(*IndexSample)(unsafe.Pointer(pSample)).Fp = Xsqlite3DbMallocZero(tls, db, uint64((*IndexSample)(unsafe.Pointer(pSample)).Fn+2))
		if (*IndexSample)(unsafe.Pointer(pSample)).Fp == uintptr(0) {
			Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
			return SQLITE_NOMEM
		}
		if (*IndexSample)(unsafe.Pointer(pSample)).Fn != 0 {
			libc.Xmemcpy(tls, (*IndexSample)(unsafe.Pointer(pSample)).Fp, Xsqlite3_column_blob(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 4), uint64((*IndexSample)(unsafe.Pointer(pSample)).Fn))
		}
		(*Index)(unsafe.Pointer(pIdx)).FnSample++
	}
	rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if rc == SQLITE_OK {
		initAvgEq(tls, pPrevIdx)
	}
	return rc
}

func loadStat4(tls *libc.TLS, db uintptr, zDb uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pStat4 uintptr

	if libc.AssignUintptr(&pStat4, Xsqlite3FindTable(tls, db, ts+14758, zDb)) != uintptr(0) &&
		int32((*Table)(unsafe.Pointer(pStat4)).FeTabType) == TABTYP_NORM {
		rc = loadStatTbl(tls, db,
			ts+14944,
			ts+14998,
			zDb)
	}
	return rc
}

func Xsqlite3AnalysisLoad(tls *libc.TLS, db uintptr, iDb int32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var i uintptr
	var zSql uintptr
	var rc int32 = SQLITE_OK
	var pSchema uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
	var pStat1 uintptr

	for i = (*Hash)(unsafe.Pointer(pSchema + 8)).Ffirst; i != 0; i = (*HashElem)(unsafe.Pointer(i)).Fnext {
		var pTab uintptr = (*HashElem)(unsafe.Pointer(i)).Fdata
		*(*U32)(unsafe.Pointer(pTab + 48)) &= libc.Uint32FromInt32(libc.CplInt32(TF_HasStat1))
	}
	for i = (*Hash)(unsafe.Pointer(pSchema + 32)).Ffirst; i != 0; i = (*HashElem)(unsafe.Pointer(i)).Fnext {
		var pIdx uintptr = (*HashElem)(unsafe.Pointer(i)).Fdata
		libc.SetBitFieldPtr16Uint32(pIdx+100, uint32(0), 7, 0x80)
		Xsqlite3DeleteIndexSamples(tls, db, pIdx)
		(*Index)(unsafe.Pointer(pIdx)).FaSample = uintptr(0)
	}

	(*AnalysisInfo)(unsafe.Pointer(bp + 8)).Fdb = db
	(*AnalysisInfo)(unsafe.Pointer(bp + 8)).FzDatabase = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	if libc.AssignUintptr(&pStat1, Xsqlite3FindTable(tls, db, ts+14732, (*AnalysisInfo)(unsafe.Pointer(bp+8)).FzDatabase)) != 0 &&
		int32((*Table)(unsafe.Pointer(pStat1)).FeTabType) == TABTYP_NORM {
		zSql = Xsqlite3MPrintf(tls, db,
			ts+15050, libc.VaList(bp, (*AnalysisInfo)(unsafe.Pointer(bp+8)).FzDatabase))
		if zSql == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			rc = Xsqlite3_exec(tls, db, zSql, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
			}{analysisLoader})), bp+8, uintptr(0))
			Xsqlite3DbFree(tls, db, zSql)
		}
	}

	for i = (*Hash)(unsafe.Pointer(pSchema + 32)).Ffirst; i != 0; i = (*HashElem)(unsafe.Pointer(i)).Fnext {
		var pIdx uintptr = (*HashElem)(unsafe.Pointer(i)).Fdata
		if !(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x80>>7) != 0) {
			Xsqlite3DefaultRowEst(tls, pIdx)
		}
	}

	if rc == SQLITE_OK {
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)
		rc = loadStat4(tls, db, (*AnalysisInfo)(unsafe.Pointer(bp+8)).FzDatabase)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable--
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = func() uint16 {
			if (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
				return uint16(0)
			}
			return (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue
		}()
	}
	for i = (*Hash)(unsafe.Pointer(pSchema + 32)).Ffirst; i != 0; i = (*HashElem)(unsafe.Pointer(i)).Fnext {
		var pIdx uintptr = (*HashElem)(unsafe.Pointer(i)).Fdata
		Xsqlite3_free(tls, (*Index)(unsafe.Pointer(pIdx)).FaiRowEst)
		(*Index)(unsafe.Pointer(pIdx)).FaiRowEst = uintptr(0)
	}

	if rc == SQLITE_NOMEM {
		Xsqlite3OomFault(tls, db)
	}
	return rc
}

func resolveAttachExpr(tls *libc.TLS, pName uintptr, pExpr uintptr) int32 {
	var rc int32 = SQLITE_OK
	if pExpr != 0 {
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_ID {
			rc = Xsqlite3ResolveExprNames(tls, pName, pExpr)
		} else {
			(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_STRING)
		}
	}
	return rc
}

func Xsqlite3DbIsNamed(tls *libc.TLS, db uintptr, iDb int32, zName uintptr) int32 {
	return libc.Bool32(Xsqlite3StrICmp(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName, zName) == 0 ||
		iDb == 0 && Xsqlite3StrICmp(tls, ts+9656, zName) == 0)
}

func attachFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var i int32
	var rc int32
	var db uintptr
	var zName uintptr
	var zFile uintptr

	var aNew uintptr
	var pNew uintptr

	var pNewSchema uintptr

	var pPager uintptr
	var iDb int32
	rc = 0
	db = Xsqlite3_context_db_handle(tls, context)
	*(*uintptr)(unsafe.Pointer(bp + 48)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
	pNew = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)

	_ = NotUsed
	zFile = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zName = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	if !(zFile == uintptr(0)) {
		goto __1
	}
	zFile = ts + 1636
__1:
	;
	if !(zName == uintptr(0)) {
		goto __2
	}
	zName = ts + 1636
__2:
	;
	if !(uint32(int32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x4>>2)) != 0) {
		goto __3
	}

	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3_vfs_find(tls, ts+6715)
	if !(*(*uintptr)(unsafe.Pointer(bp + 40)) == uintptr(0)) {
		goto __5
	}
	return
__5:
	;
	rc = Xsqlite3BtreeOpen(tls, *(*uintptr)(unsafe.Pointer(bp + 40)), ts+15091, db, bp+24, 0, SQLITE_OPEN_MAIN_DB)
	if !(rc == SQLITE_OK) {
		goto __6
	}
	pNewSchema = Xsqlite3SchemaGet(tls, db, *(*uintptr)(unsafe.Pointer(bp + 24)))
	if !(pNewSchema != 0) {
		goto __7
	}

	pNew = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb)*32
	if !((*Db)(unsafe.Pointer(pNew)).FpBt != 0) {
		goto __9
	}
	Xsqlite3BtreeClose(tls, (*Db)(unsafe.Pointer(pNew)).FpBt)
__9:
	;
	(*Db)(unsafe.Pointer(pNew)).FpBt = *(*uintptr)(unsafe.Pointer(bp + 24))
	(*Db)(unsafe.Pointer(pNew)).FpSchema = pNewSchema
	goto __8
__7:
	Xsqlite3BtreeClose(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
	rc = SQLITE_NOMEM
__8:
	;
__6:
	;
	if !(rc != 0) {
		goto __10
	}
	goto attach_error
__10:
	;
	goto __4
__3:
	if !((*Sqlite3)(unsafe.Pointer(db)).FnDb >= *(*int32)(unsafe.Pointer(db + 136 + 7*4))+2) {
		goto __11
	}
	*(*uintptr)(unsafe.Pointer(bp + 64)) = Xsqlite3MPrintf(tls, db, ts+15094,
		libc.VaList(bp, *(*int32)(unsafe.Pointer(db + 136 + 7*4))))
	goto attach_error
__11:
	;
	i = 0
__12:
	if !(i < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __14
	}

	if !(Xsqlite3DbIsNamed(tls, db, i, zName) != 0) {
		goto __15
	}
	*(*uintptr)(unsafe.Pointer(bp + 64)) = Xsqlite3MPrintf(tls, db, ts+15131, libc.VaList(bp+8, zName))
	goto attach_error
__15:
	;
	goto __13
__13:
	i++
	goto __12
	goto __14
__14:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FaDb == db+696) {
		goto __16
	}
	aNew = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(Db{}))*uint64(3))
	if !(aNew == uintptr(0)) {
		goto __18
	}
	return
__18:
	;
	libc.Xmemcpy(tls, aNew, (*Sqlite3)(unsafe.Pointer(db)).FaDb, uint64(unsafe.Sizeof(Db{}))*uint64(2))
	goto __17
__16:
	aNew = Xsqlite3DbRealloc(tls, db, (*Sqlite3)(unsafe.Pointer(db)).FaDb, uint64(unsafe.Sizeof(Db{}))*uint64((*Sqlite3)(unsafe.Pointer(db)).FnDb+1))
	if !(aNew == uintptr(0)) {
		goto __19
	}
	return
__19:
	;
__17:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FaDb = aNew
	pNew = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*Sqlite3)(unsafe.Pointer(db)).FnDb)*32
	libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Db{})))

	*(*uint32)(unsafe.Pointer(bp + 32)) = (*Sqlite3)(unsafe.Pointer(db)).FopenFlags
	rc = Xsqlite3ParseUri(tls, (*Sqlite3_vfs)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpVfs)).FzName, zFile, bp+32, bp+40, bp+48, bp+56)
	if !(rc != SQLITE_OK) {
		goto __20
	}
	if !(rc == SQLITE_NOMEM) {
		goto __21
	}
	Xsqlite3OomFault(tls, db)
__21:
	;
	Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 56)), -1)
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 56)))
	return
__20:
	;
	*(*uint32)(unsafe.Pointer(bp + 32)) |= uint32(SQLITE_OPEN_MAIN_DB)
	rc = Xsqlite3BtreeOpen(tls, *(*uintptr)(unsafe.Pointer(bp + 40)), *(*uintptr)(unsafe.Pointer(bp + 48)), db, pNew+8, 0, int32(*(*uint32)(unsafe.Pointer(bp + 32))))
	(*Sqlite3)(unsafe.Pointer(db)).FnDb++
	(*Db)(unsafe.Pointer(pNew)).FzDbSName = Xsqlite3DbStrDup(tls, db, zName)
__4:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FnoSharedCache = U8(0)
	if !(rc == SQLITE_CONSTRAINT) {
		goto __22
	}
	rc = SQLITE_ERROR
	*(*uintptr)(unsafe.Pointer(bp + 64)) = Xsqlite3MPrintf(tls, db, ts+15161, 0)
	goto __23
__22:
	if !(rc == SQLITE_OK) {
		goto __24
	}
	(*Db)(unsafe.Pointer(pNew)).FpSchema = Xsqlite3SchemaGet(tls, db, (*Db)(unsafe.Pointer(pNew)).FpBt)
	if !!(int32((*Db)(unsafe.Pointer(pNew)).FpSchema) != 0) {
		goto __25
	}
	rc = SQLITE_NOMEM
	goto __26
__25:
	if !((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pNew)).FpSchema)).Ffile_format != 0 && int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pNew)).FpSchema)).Fenc) != int32((*Sqlite3)(unsafe.Pointer(db)).Fenc)) {
		goto __27
	}
	*(*uintptr)(unsafe.Pointer(bp + 64)) = Xsqlite3MPrintf(tls, db,
		ts+15190, 0)
	rc = SQLITE_ERROR
__27:
	;
__26:
	;
	Xsqlite3BtreeEnter(tls, (*Db)(unsafe.Pointer(pNew)).FpBt)
	pPager = Xsqlite3BtreePager(tls, (*Db)(unsafe.Pointer(pNew)).FpBt)
	Xsqlite3PagerLockingMode(tls, pPager, int32((*Sqlite3)(unsafe.Pointer(db)).FdfltLockMode))
	Xsqlite3BtreeSecureDelete(tls, (*Db)(unsafe.Pointer(pNew)).FpBt,
		Xsqlite3BtreeSecureDelete(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpBt, -1))
	Xsqlite3BtreeSetPagerFlags(tls, (*Db)(unsafe.Pointer(pNew)).FpBt,
		uint32(uint64(PAGER_SYNCHRONOUS_FULL)|(*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK)))
	Xsqlite3BtreeLeave(tls, (*Db)(unsafe.Pointer(pNew)).FpBt)
__24:
	;
__23:
	;
	(*Db)(unsafe.Pointer(pNew)).Fsafety_level = U8(SQLITE_DEFAULT_SYNCHRONOUS + 1)
	if !(rc == SQLITE_OK && (*Db)(unsafe.Pointer(pNew)).FzDbSName == uintptr(0)) {
		goto __28
	}
	rc = SQLITE_NOMEM
__28:
	;
	Xsqlite3_free_filename(tls, *(*uintptr)(unsafe.Pointer(bp + 48)))

	if !(rc == SQLITE_OK) {
		goto __29
	}
	Xsqlite3BtreeEnterAll(tls, db)
	(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = U8(0)
	*(*U32)(unsafe.Pointer(db + 44)) &= libc.Uint32FromInt32(libc.CplInt32(DBFLAG_SchemaKnownOk))
	if !!(int32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x4>>2) != 0) {
		goto __30
	}
	rc = Xsqlite3Init(tls, db, bp+64)
__30:
	;
	Xsqlite3BtreeLeaveAll(tls, db)

__29:
	;
	if !(rc != 0) {
		goto __31
	}
	if !!(int32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x4>>2) != 0) {
		goto __32
	}
	iDb = (*Sqlite3)(unsafe.Pointer(db)).FnDb - 1

	if !((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpBt != 0) {
		goto __33
	}
	Xsqlite3BtreeClose(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpBt)
	(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpBt = uintptr(0)
	(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema = uintptr(0)
__33:
	;
	Xsqlite3ResetAllSchemasOfConnection(tls, db)
	(*Sqlite3)(unsafe.Pointer(db)).FnDb = iDb
	if !(rc == SQLITE_NOMEM || rc == SQLITE_IOERR|int32(12)<<8) {
		goto __34
	}
	Xsqlite3OomFault(tls, db)
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 64)))
	*(*uintptr)(unsafe.Pointer(bp + 64)) = Xsqlite3MPrintf(tls, db, ts+1572, 0)
	goto __35
__34:
	if !(*(*uintptr)(unsafe.Pointer(bp + 64)) == uintptr(0)) {
		goto __36
	}
	*(*uintptr)(unsafe.Pointer(bp + 64)) = Xsqlite3MPrintf(tls, db, ts+15258, libc.VaList(bp+16, zFile))
__36:
	;
__35:
	;
__32:
	;
	goto attach_error
__31:
	;
	return

attach_error:
	if !(*(*uintptr)(unsafe.Pointer(bp + 64)) != 0) {
		goto __37
	}
	Xsqlite3_result_error(tls, context, *(*uintptr)(unsafe.Pointer(bp + 64)), -1)
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 64)))
__37:
	;
	if !(rc != 0) {
		goto __38
	}
	Xsqlite3_result_error_code(tls, context, rc)
__38:
}

func detachFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(152)
	defer tls.Free(152)

	var zName uintptr
	var db uintptr
	var i int32
	var pDb uintptr
	var pEntry uintptr

	var pTrig uintptr
	zName = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	db = Xsqlite3_context_db_handle(tls, context)
	pDb = uintptr(0)

	_ = NotUsed

	if !(zName == uintptr(0)) {
		goto __1
	}
	zName = ts + 1636
__1:
	;
	i = 0
__2:
	if !(i < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __4
	}
	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32
	if !((*Db)(unsafe.Pointer(pDb)).FpBt == uintptr(0)) {
		goto __5
	}
	goto __3
__5:
	;
	if !(Xsqlite3DbIsNamed(tls, db, i, zName) != 0) {
		goto __6
	}
	goto __4
__6:
	;
	goto __3
__3:
	i++
	goto __2
	goto __4
__4:
	;
	if !(i >= (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __7
	}
	Xsqlite3_snprintf(tls, int32(unsafe.Sizeof([128]uint8{})), bp+24, ts+15286, libc.VaList(bp, zName))
	goto detach_error
__7:
	;
	if !(i < 2) {
		goto __8
	}
	Xsqlite3_snprintf(tls, int32(unsafe.Sizeof([128]uint8{})), bp+24, ts+15307, libc.VaList(bp+8, zName))
	goto detach_error
__8:
	;
	if !(Xsqlite3BtreeTxnState(tls, (*Db)(unsafe.Pointer(pDb)).FpBt) != SQLITE_TXN_NONE ||
		Xsqlite3BtreeIsInBackup(tls, (*Db)(unsafe.Pointer(pDb)).FpBt) != 0) {
		goto __9
	}
	Xsqlite3_snprintf(tls, int32(unsafe.Sizeof([128]uint8{})), bp+24, ts+15333, libc.VaList(bp+16, zName))
	goto detach_error
__9:
	;
	pEntry = (*Hash)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema + 56)).Ffirst
__10:
	if !(pEntry != 0) {
		goto __11
	}
	pTrig = (*HashElem)(unsafe.Pointer(pEntry)).Fdata
	if !((*Trigger)(unsafe.Pointer(pTrig)).FpTabSchema == (*Db)(unsafe.Pointer(pDb)).FpSchema) {
		goto __12
	}
	(*Trigger)(unsafe.Pointer(pTrig)).FpTabSchema = (*Trigger)(unsafe.Pointer(pTrig)).FpSchema
__12:
	;
	pEntry = (*HashElem)(unsafe.Pointer(pEntry)).Fnext
	goto __10
__11:
	;
	Xsqlite3BtreeClose(tls, (*Db)(unsafe.Pointer(pDb)).FpBt)
	(*Db)(unsafe.Pointer(pDb)).FpBt = uintptr(0)
	(*Db)(unsafe.Pointer(pDb)).FpSchema = uintptr(0)
	Xsqlite3CollapseDatabaseArray(tls, db)
	return

detach_error:
	Xsqlite3_result_error(tls, context, bp+24, -1)
}

func codeAttach(tls *libc.TLS, pParse uintptr, type1 int32, pFunc uintptr, pAuthArg uintptr, pFilename uintptr, pDbname uintptr, pKey uintptr) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var rc int32

	var v uintptr
	var db uintptr
	var regArgs int32
	var zAuthArg uintptr
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !(SQLITE_OK != Xsqlite3ReadSchema(tls, pParse)) {
		goto __1
	}
	goto attach_end
__1:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __2
	}
	goto attach_end
__2:
	;
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(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 __3
	}
	goto attach_end
__3:
	;
	if !(pAuthArg != 0) {
		goto __4
	}
	if !(int32((*Expr)(unsafe.Pointer(pAuthArg)).Fop) == TK_STRING) {
		goto __5
	}

	zAuthArg = *(*uintptr)(unsafe.Pointer(pAuthArg + 8))
	goto __6
__5:
	zAuthArg = uintptr(0)
__6:
	;
	rc = Xsqlite3AuthCheck(tls, pParse, type1, zAuthArg, uintptr(0), uintptr(0))
	if !(rc != SQLITE_OK) {
		goto __7
	}
	goto attach_end
__7:
	;
__4:
	;
	v = Xsqlite3GetVdbe(tls, pParse)
	regArgs = Xsqlite3GetTempRange(tls, pParse, 4)
	Xsqlite3ExprCode(tls, pParse, pFilename, regArgs)
	Xsqlite3ExprCode(tls, pParse, pDbname, regArgs+1)
	Xsqlite3ExprCode(tls, pParse, pKey, regArgs+2)

	if !(v != 0) {
		goto __8
	}
	Xsqlite3VdbeAddFunctionCall(tls, pParse, 0, regArgs+3-int32((*FuncDef)(unsafe.Pointer(pFunc)).FnArg), regArgs+3,
		int32((*FuncDef)(unsafe.Pointer(pFunc)).FnArg), pFunc, 0)

	Xsqlite3VdbeAddOp1(tls, v, OP_Expire, libc.Bool32(type1 == SQLITE_ATTACH))
__8:
	;
attach_end:
	Xsqlite3ExprDelete(tls, db, pFilename)
	Xsqlite3ExprDelete(tls, db, pDbname)
	Xsqlite3ExprDelete(tls, db, pKey)
}

func Xsqlite3Detach(tls *libc.TLS, pParse uintptr, pDbname uintptr) {
	codeAttach(tls, pParse, SQLITE_DETACH, uintptr(unsafe.Pointer(&detach_func)), pDbname, uintptr(0), uintptr(0), pDbname)
}

var detach_func = FuncDef{
	FnArg:      int8(1),
	FfuncFlags: U32(SQLITE_UTF8),
	FxSFunc:    0,
	FzName:     ts + 15355}

func Xsqlite3Attach(tls *libc.TLS, pParse uintptr, p uintptr, pDbname uintptr, pKey uintptr) {
	codeAttach(tls, pParse, SQLITE_ATTACH, uintptr(unsafe.Pointer(&attach_func)), p, p, pDbname, pKey)
}

var attach_func = FuncDef{
	FnArg:      int8(3),
	FfuncFlags: U32(SQLITE_UTF8),
	FxSFunc:    0,
	FzName:     ts + 15369}

func fixExprCb(tls *libc.TLS, p uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pFix uintptr = *(*uintptr)(unsafe.Pointer(p + 40))
	if !(int32((*DbFixer)(unsafe.Pointer(pFix)).FbTemp) != 0) {
		*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_FromDDL)
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_VARIABLE {
		if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer((*DbFixer)(unsafe.Pointer(pFix)).FpParse)).Fdb)).Finit.Fbusy != 0 {
			(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_NULL)
		} else {
			Xsqlite3ErrorMsg(tls, (*DbFixer)(unsafe.Pointer(pFix)).FpParse, ts+15383, libc.VaList(bp, (*DbFixer)(unsafe.Pointer(pFix)).FzType))
			return WRC_Abort
		}
	}
	return WRC_Continue
}

func fixSelectCb(tls *libc.TLS, p uintptr, pSelect uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pFix uintptr = *(*uintptr)(unsafe.Pointer(p + 40))
	var i int32
	var pItem uintptr
	var db uintptr = (*Parse)(unsafe.Pointer((*DbFixer)(unsafe.Pointer(pFix)).FpParse)).Fdb
	var iDb int32 = Xsqlite3FindDbName(tls, db, (*DbFixer)(unsafe.Pointer(pFix)).FzDb)
	var pList uintptr = (*Select)(unsafe.Pointer(pSelect)).FpSrc

	if pList == uintptr(0) {
		return WRC_Continue
	}
	i = 0
	pItem = pList + 8
__1:
	if !(i < (*SrcList)(unsafe.Pointer(pList)).FnSrc) {
		goto __3
	}
	{
		if int32((*DbFixer)(unsafe.Pointer(pFix)).FbTemp) == 0 {
			if (*SrcItem)(unsafe.Pointer(pItem)).FzDatabase != 0 {
				if iDb != Xsqlite3FindDbName(tls, db, (*SrcItem)(unsafe.Pointer(pItem)).FzDatabase) {
					Xsqlite3ErrorMsg(tls, (*DbFixer)(unsafe.Pointer(pFix)).FpParse,
						ts+15407,
						libc.VaList(bp, (*DbFixer)(unsafe.Pointer(pFix)).FzType, (*DbFixer)(unsafe.Pointer(pFix)).FpName, (*SrcItem)(unsafe.Pointer(pItem)).FzDatabase))
					return WRC_Abort
				}
				Xsqlite3DbFree(tls, db, (*SrcItem)(unsafe.Pointer(pItem)).FzDatabase)
				(*SrcItem)(unsafe.Pointer(pItem)).FzDatabase = uintptr(0)
				libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(1), 9, 0x200)
			}
			(*SrcItem)(unsafe.Pointer(pItem)).FpSchema = (*DbFixer)(unsafe.Pointer(pFix)).FpSchema
			libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(1), 7, 0x80)
		}
		if int32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*104 + 60 + 4))&0x400>>10) == 0 &&
			Xsqlite3WalkExpr(tls, pFix+8, *(*uintptr)(unsafe.Pointer(pList + 8 + uintptr(i)*104 + 72))) != 0 {
			return WRC_Abort
		}

	}
	goto __2
__2:
	i++
	pItem += 104
	goto __1
	goto __3
__3:
	;
	if (*Select)(unsafe.Pointer(pSelect)).FpWith != 0 {
		for i = 0; i < (*With)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpWith)).FnCte; i++ {
			if Xsqlite3WalkSelect(tls, p, (*Cte)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpWith+16+uintptr(i)*48)).FpSelect) != 0 {
				return WRC_Abort
			}
		}
	}
	return WRC_Continue
}

func Xsqlite3FixInit(tls *libc.TLS, pFix uintptr, pParse uintptr, iDb int32, zType uintptr, pName uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	(*DbFixer)(unsafe.Pointer(pFix)).FpParse = pParse
	(*DbFixer)(unsafe.Pointer(pFix)).FzDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	(*DbFixer)(unsafe.Pointer(pFix)).FpSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
	(*DbFixer)(unsafe.Pointer(pFix)).FzType = zType
	(*DbFixer)(unsafe.Pointer(pFix)).FpName = pName
	(*DbFixer)(unsafe.Pointer(pFix)).FbTemp = U8(libc.Bool32(iDb == 1))
	(*DbFixer)(unsafe.Pointer(pFix)).Fw.FpParse = pParse
	(*DbFixer)(unsafe.Pointer(pFix)).Fw.FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{fixExprCb}))
	(*DbFixer)(unsafe.Pointer(pFix)).Fw.FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{fixSelectCb}))
	(*DbFixer)(unsafe.Pointer(pFix)).Fw.FxSelectCallback2 = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr)
	}{Xsqlite3WalkWinDefnDummyCallback}))
	(*DbFixer)(unsafe.Pointer(pFix)).Fw.FwalkerDepth = 0
	(*DbFixer)(unsafe.Pointer(pFix)).Fw.FeCode = U16(0)
	*(*uintptr)(unsafe.Pointer(pFix + 8 + 40)) = pFix
}

func Xsqlite3FixSrcList(tls *libc.TLS, pFix uintptr, pList uintptr) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	var res int32 = 0
	if pList != 0 {
		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Select{})))
		(*Select)(unsafe.Pointer(bp)).FpSrc = pList
		res = Xsqlite3WalkSelect(tls, pFix+8, bp)
	}
	return res
}

func Xsqlite3FixSelect(tls *libc.TLS, pFix uintptr, pSelect uintptr) int32 {
	return Xsqlite3WalkSelect(tls, pFix+8, pSelect)
}

func Xsqlite3FixExpr(tls *libc.TLS, pFix uintptr, pExpr uintptr) int32 {
	return Xsqlite3WalkExpr(tls, pFix+8, pExpr)
}

func Xsqlite3FixTriggerStep(tls *libc.TLS, pFix uintptr, pStep uintptr) int32 {
	for pStep != 0 {
		if Xsqlite3WalkSelect(tls, pFix+8, (*TriggerStep)(unsafe.Pointer(pStep)).FpSelect) != 0 ||
			Xsqlite3WalkExpr(tls, pFix+8, (*TriggerStep)(unsafe.Pointer(pStep)).FpWhere) != 0 ||
			Xsqlite3WalkExprList(tls, pFix+8, (*TriggerStep)(unsafe.Pointer(pStep)).FpExprList) != 0 ||
			Xsqlite3FixSrcList(tls, pFix, (*TriggerStep)(unsafe.Pointer(pStep)).FpFrom) != 0 {
			return 1
		}
		{
			var pUp uintptr
			for pUp = (*TriggerStep)(unsafe.Pointer(pStep)).FpUpsert; pUp != 0; pUp = (*Upsert)(unsafe.Pointer(pUp)).FpNextUpsert {
				if Xsqlite3WalkExprList(tls, pFix+8, (*Upsert)(unsafe.Pointer(pUp)).FpUpsertTarget) != 0 ||
					Xsqlite3WalkExpr(tls, pFix+8, (*Upsert)(unsafe.Pointer(pUp)).FpUpsertTargetWhere) != 0 ||
					Xsqlite3WalkExprList(tls, pFix+8, (*Upsert)(unsafe.Pointer(pUp)).FpUpsertSet) != 0 ||
					Xsqlite3WalkExpr(tls, pFix+8, (*Upsert)(unsafe.Pointer(pUp)).FpUpsertWhere) != 0 {
					return 1
				}
			}

		}
		pStep = (*TriggerStep)(unsafe.Pointer(pStep)).FpNext
	}

	return 0
}

func Xsqlite3_set_authorizer(tls *libc.TLS, db uintptr, xAuth uintptr, pArg uintptr) int32 {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
	(*Sqlite3)(unsafe.Pointer(db)).FpAuthArg = pArg
	if (*Sqlite3)(unsafe.Pointer(db)).FxAuth != 0 {
		Xsqlite3ExpirePreparedStatements(tls, db, 1)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

func sqliteAuthBadReturnCode(tls *libc.TLS, pParse uintptr) {
	Xsqlite3ErrorMsg(tls, pParse, ts+15453, 0)
	(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_ERROR
}

func Xsqlite3AuthReadCol(tls *libc.TLS, pParse uintptr, zTab uintptr, zCol uintptr, iDb int32) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var zDb uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	var rc int32

	if (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 {
		return SQLITE_OK
	}
	rc = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxAuth})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpAuthArg, SQLITE_READ, zTab, zCol, zDb, (*Parse)(unsafe.Pointer(pParse)).FzAuthContext)
	if rc == SQLITE_DENY {
		var z uintptr = Xsqlite3_mprintf(tls, ts+11397, libc.VaList(bp, zTab, zCol))
		if (*Sqlite3)(unsafe.Pointer(db)).FnDb > 2 || iDb != 0 {
			z = Xsqlite3_mprintf(tls, ts+15476, libc.VaList(bp+16, zDb, z))
		}
		Xsqlite3ErrorMsg(tls, pParse, ts+15482, libc.VaList(bp+32, z))
		(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_AUTH
	} else if rc != SQLITE_IGNORE && rc != SQLITE_OK {
		sqliteAuthBadReturnCode(tls, pParse)
	}
	return rc
}

func Xsqlite3AuthRead(tls *libc.TLS, pParse uintptr, pExpr uintptr, pSchema uintptr, pTabList uintptr) {
	var pTab uintptr = uintptr(0)
	var zCol uintptr
	var iSrc int32
	var iDb int32
	var iCol int32

	iDb = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pSchema)
	if iDb < 0 {
		return
	}

	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_TRIGGER {
		pTab = (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab
	} else {
		for iSrc = 0; iSrc < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc; iSrc++ {
			if (*Expr)(unsafe.Pointer(pExpr)).FiTable == (*SrcItem)(unsafe.Pointer(pTabList+8+uintptr(iSrc)*104)).FiCursor {
				pTab = (*SrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(iSrc)*104)).FpTab
				break
			}
		}
	}
	iCol = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)
	if pTab == uintptr(0) {
		return
	}

	if iCol >= 0 {
		zCol = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24)).FzCnName
	} else if int32((*Table)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
		zCol = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr((*Table)(unsafe.Pointer(pTab)).FiPKey)*24)).FzCnName
	} else {
		zCol = ts + 10928
	}

	if SQLITE_IGNORE == Xsqlite3AuthReadCol(tls, pParse, (*Table)(unsafe.Pointer(pTab)).FzName, zCol, iDb) {
		(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_NULL)
	}
}

func Xsqlite3AuthCheck(tls *libc.TLS, pParse uintptr, code int32, zArg1 uintptr, zArg2 uintptr, zArg3 uintptr) int32 {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var rc int32

	if (*Sqlite3)(unsafe.Pointer(db)).FxAuth == uintptr(0) || (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 || int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
		return SQLITE_OK
	}

	rc = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxAuth})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpAuthArg, code, zArg1, zArg2, zArg3, (*Parse)(unsafe.Pointer(pParse)).FzAuthContext)
	if rc == SQLITE_DENY {
		Xsqlite3ErrorMsg(tls, pParse, ts+15509, 0)
		(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_AUTH
	} else if rc != SQLITE_OK && rc != SQLITE_IGNORE {
		rc = SQLITE_DENY
		sqliteAuthBadReturnCode(tls, pParse)
	}
	return rc
}

func Xsqlite3AuthContextPush(tls *libc.TLS, pParse uintptr, pContext uintptr, zContext uintptr) {
	(*AuthContext)(unsafe.Pointer(pContext)).FpParse = pParse
	(*AuthContext)(unsafe.Pointer(pContext)).FzAuthContext = (*Parse)(unsafe.Pointer(pParse)).FzAuthContext
	(*Parse)(unsafe.Pointer(pParse)).FzAuthContext = zContext
}

func Xsqlite3AuthContextPop(tls *libc.TLS, pContext uintptr) {
	if (*AuthContext)(unsafe.Pointer(pContext)).FpParse != 0 {
		(*Parse)(unsafe.Pointer((*AuthContext)(unsafe.Pointer(pContext)).FpParse)).FzAuthContext = (*AuthContext)(unsafe.Pointer(pContext)).FzAuthContext
		(*AuthContext)(unsafe.Pointer(pContext)).FpParse = uintptr(0)
	}
}

func lockTable(tls *libc.TLS, pParse uintptr, iDb int32, iTab Pgno, isWriteLock U8, zName uintptr) {
	var pToplevel uintptr
	var i int32
	var nBytes int32
	var p uintptr

	pToplevel = func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}()
	for i = 0; i < (*Parse)(unsafe.Pointer(pToplevel)).FnTableLock; i++ {
		p = (*Parse)(unsafe.Pointer(pToplevel)).FaTableLock + uintptr(i)*24
		if (*TableLock)(unsafe.Pointer(p)).FiDb == iDb && (*TableLock)(unsafe.Pointer(p)).FiTab == iTab {
			(*TableLock)(unsafe.Pointer(p)).FisWriteLock = U8(libc.Bool32((*TableLock)(unsafe.Pointer(p)).FisWriteLock != 0 || isWriteLock != 0))
			return
		}
	}

	nBytes = int32(uint64(unsafe.Sizeof(TableLock{})) * uint64((*Parse)(unsafe.Pointer(pToplevel)).FnTableLock+1))
	(*Parse)(unsafe.Pointer(pToplevel)).FaTableLock = Xsqlite3DbReallocOrFree(tls, (*Parse)(unsafe.Pointer(pToplevel)).Fdb, (*Parse)(unsafe.Pointer(pToplevel)).FaTableLock, uint64(nBytes))
	if (*Parse)(unsafe.Pointer(pToplevel)).FaTableLock != 0 {
		p = (*Parse)(unsafe.Pointer(pToplevel)).FaTableLock + uintptr(libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pToplevel)).FnTableLock, 1))*24
		(*TableLock)(unsafe.Pointer(p)).FiDb = iDb
		(*TableLock)(unsafe.Pointer(p)).FiTab = iTab
		(*TableLock)(unsafe.Pointer(p)).FisWriteLock = isWriteLock
		(*TableLock)(unsafe.Pointer(p)).FzLockName = zName
	} else {
		(*Parse)(unsafe.Pointer(pToplevel)).FnTableLock = 0
		Xsqlite3OomFault(tls, (*Parse)(unsafe.Pointer(pToplevel)).Fdb)
	}
}

func Xsqlite3TableLock(tls *libc.TLS, pParse uintptr, iDb int32, iTab Pgno, isWriteLock U8, zName uintptr) {
	if iDb == 1 {
		return
	}
	if !(Xsqlite3BtreeSharable(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FaDb+uintptr(iDb)*32)).FpBt) != 0) {
		return
	}
	lockTable(tls, pParse, iDb, iTab, isWriteLock, zName)
}

func codeTableLocks(tls *libc.TLS, pParse uintptr) {
	var i int32
	var pVdbe uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	for i = 0; i < (*Parse)(unsafe.Pointer(pParse)).FnTableLock; i++ {
		var p uintptr = (*Parse)(unsafe.Pointer(pParse)).FaTableLock + uintptr(i)*24
		var p1 int32 = (*TableLock)(unsafe.Pointer(p)).FiDb
		Xsqlite3VdbeAddOp4(tls, pVdbe, OP_TableLock, p1, int32((*TableLock)(unsafe.Pointer(p)).FiTab), int32((*TableLock)(unsafe.Pointer(p)).FisWriteLock),
			(*TableLock)(unsafe.Pointer(p)).FzLockName, -1)
	}
}

func Xsqlite3FinishCoding(tls *libc.TLS, pParse uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var db uintptr
	var v uintptr
	var iDb int32
	var i int32

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if (*Parse)(unsafe.Pointer(pParse)).Fnested != 0 {
		return
	}
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
		}
		return
	}

	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	if v == uintptr(0) {
		if (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 {
			(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_DONE
			return
		}
		v = Xsqlite3GetVdbe(tls, pParse)
		if v == uintptr(0) {
			(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_ERROR
		}
	}

	if v != 0 {
		if (*Parse)(unsafe.Pointer(pParse)).FbReturning != 0 {
			var pReturning uintptr = *(*uintptr)(unsafe.Pointer(pParse + 200))
			var addrRewind int32
			var reg int32

			if (*Returning)(unsafe.Pointer(pReturning)).FnRetCol != 0 {
				Xsqlite3VdbeAddOp0(tls, v, OP_FkCheck)
				addrRewind = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, (*Returning)(unsafe.Pointer(pReturning)).FiRetCur)

				reg = (*Returning)(unsafe.Pointer(pReturning)).FiRetReg
				for i = 0; i < (*Returning)(unsafe.Pointer(pReturning)).FnRetCol; i++ {
					Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*Returning)(unsafe.Pointer(pReturning)).FiRetCur, i, reg+i)
				}
				Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, reg, i)
				Xsqlite3VdbeAddOp2(tls, v, OP_Next, (*Returning)(unsafe.Pointer(pReturning)).FiRetCur, addrRewind+1)

				Xsqlite3VdbeJumpHere(tls, v, addrRewind)
			}
		}
		Xsqlite3VdbeAddOp0(tls, v, OP_Halt)

		Xsqlite3VdbeJumpHere(tls, v, 0)

		iDb = 0
		for __ccgo := true; __ccgo; __ccgo = libc.PreIncInt32(&iDb, 1) < (*Sqlite3)(unsafe.Pointer(db)).FnDb {
			var pSchema uintptr
			if libc.Bool32((*Parse)(unsafe.Pointer(pParse)).FcookieMask&(YDbMask(1)<<iDb) != YDbMask(0)) == 0 {
				continue
			}
			Xsqlite3VdbeUsesBtree(tls, v, iDb)
			pSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
			Xsqlite3VdbeAddOp4Int(tls, v,
				OP_Transaction,
				iDb,
				libc.Bool32((*Parse)(unsafe.Pointer(pParse)).FwriteMask&(YDbMask(1)<<iDb) != YDbMask(0)),
				(*Schema)(unsafe.Pointer(pSchema)).Fschema_cookie,
				(*Schema)(unsafe.Pointer(pSchema)).FiGeneration)
			if int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) == 0 {
				Xsqlite3VdbeChangeP5(tls, v, uint16(1))
			}
			Xsqlite3VdbeComment(tls, v, ts+15524, libc.VaList(bp, libc.Bool32((*Parse)(unsafe.Pointer(pParse)).FmayAbort != 0 && (*Parse)(unsafe.Pointer(pParse)).FisMultiWrite != 0)))
		}
		for i = 0; i < (*Parse)(unsafe.Pointer(pParse)).FnVtabLock; i++ {
			var vtab uintptr = Xsqlite3GetVTable(tls, db, *(*uintptr)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).FapVtabLock + uintptr(i)*8)))
			Xsqlite3VdbeAddOp4(tls, v, OP_VBegin, 0, 0, 0, vtab, -11)
		}
		(*Parse)(unsafe.Pointer(pParse)).FnVtabLock = 0

		codeTableLocks(tls, pParse)

		Xsqlite3AutoincrementBegin(tls, pParse)

		if (*Parse)(unsafe.Pointer(pParse)).FpConstExpr != 0 {
			var pEL uintptr = (*Parse)(unsafe.Pointer(pParse)).FpConstExpr
			(*Parse)(unsafe.Pointer(pParse)).FokConstFactor = U8(0)
			for i = 0; i < (*ExprList)(unsafe.Pointer(pEL)).FnExpr; i++ {
				var iReg int32 = *(*int32)(unsafe.Pointer(pEL + 8 + uintptr(i)*32 + 24))
				Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pEL+8+uintptr(i)*32)).FpExpr, iReg)
			}
		}

		if (*Parse)(unsafe.Pointer(pParse)).FbReturning != 0 {
			var pRet uintptr = *(*uintptr)(unsafe.Pointer(pParse + 200))
			if (*Returning)(unsafe.Pointer(pRet)).FnRetCol != 0 {
				Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, (*Returning)(unsafe.Pointer(pRet)).FiRetCur, (*Returning)(unsafe.Pointer(pRet)).FnRetCol)
			}
		}

		Xsqlite3VdbeGoto(tls, v, 1)
	}

	if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 {
		Xsqlite3VdbeMakeReady(tls, v, pParse)
		(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_DONE
	} else {
		(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_ERROR
	}
}

func Xsqlite3NestedParse(tls *libc.TLS, pParse uintptr, zFormat uintptr, va uintptr) {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var ap Va_list
	_ = ap
	var zSql uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var savedDbFlags U32 = (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	if (*Parse)(unsafe.Pointer(pParse)).FeParseMode != 0 {
		return
	}

	ap = va
	zSql = Xsqlite3VMPrintf(tls, db, zFormat, ap)
	_ = ap
	if zSql == uintptr(0) {
		if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
			(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_TOOBIG
		}
		(*Parse)(unsafe.Pointer(pParse)).FnErr++
		return
	}
	(*Parse)(unsafe.Pointer(pParse)).Fnested++
	libc.Xmemcpy(tls, bp, pParse+uintptr(uint64(uintptr(0)+288)), uint64(unsafe.Sizeof(Parse{}))-uint64(uintptr(0)+288))
	libc.Xmemset(tls, pParse+uintptr(uint64(uintptr(0)+288)), 0, uint64(unsafe.Sizeof(Parse{}))-uint64(uintptr(0)+288))
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_PreferBuiltin)
	Xsqlite3RunParser(tls, pParse, zSql)
	(*Sqlite3)(unsafe.Pointer(db)).FmDbFlags = savedDbFlags
	Xsqlite3DbFree(tls, db, zSql)
	libc.Xmemcpy(tls, pParse+uintptr(uint64(uintptr(0)+288)), bp, uint64(unsafe.Sizeof(Parse{}))-uint64(uintptr(0)+288))
	(*Parse)(unsafe.Pointer(pParse)).Fnested--
}

func Xsqlite3FindTable(tls *libc.TLS, db uintptr, zName uintptr, zDatabase uintptr) uintptr {
	var p uintptr = uintptr(0)
	var i int32

	if zDatabase != 0 {
		for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			if Xsqlite3StrICmp(tls, zDatabase, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FzDbSName) == 0 {
				break
			}
		}
		if i >= (*Sqlite3)(unsafe.Pointer(db)).FnDb {
			if Xsqlite3StrICmp(tls, zDatabase, ts+9656) == 0 {
				i = 0
			} else {
				return uintptr(0)
			}
		}
		p = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpSchema+8, zName)
		if p == uintptr(0) && Xsqlite3_strnicmp(tls, zName, ts+9596, 7) == 0 {
			if i == 1 {
				if Xsqlite3StrICmp(tls, zName+uintptr(7), ts+9623+7) == 0 ||
					Xsqlite3StrICmp(tls, zName+uintptr(7), ts+9642+7) == 0 ||
					Xsqlite3StrICmp(tls, zName+uintptr(7), ts+8808+7) == 0 {
					p = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema+8,
						ts+9604)
				}
			} else {
				if Xsqlite3StrICmp(tls, zName+uintptr(7), ts+9642+7) == 0 {
					p = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpSchema+8,
						ts+8808)
				}
			}
		}
	} else {
		p = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema+8, zName)
		if p != 0 {
			return p
		}

		p = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema+8, zName)
		if p != 0 {
			return p
		}

		for i = 2; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			p = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpSchema+8, zName)
			if p != 0 {
				break
			}
		}
		if p == uintptr(0) && Xsqlite3_strnicmp(tls, zName, ts+9596, 7) == 0 {
			if Xsqlite3StrICmp(tls, zName+uintptr(7), ts+9642+7) == 0 {
				p = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema+8, ts+8808)
			} else if Xsqlite3StrICmp(tls, zName+uintptr(7), ts+9623+7) == 0 {
				p = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema+8,
					ts+9604)
			}
		}
	}
	return p
}

func Xsqlite3LocateTable(tls *libc.TLS, pParse uintptr, flags U32, zName uintptr, zDbase uintptr) uintptr {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var p uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_SchemaKnownOk) == U32(0) &&
		SQLITE_OK != Xsqlite3ReadSchema(tls, pParse) {
		return uintptr(0)
	}

	p = Xsqlite3FindTable(tls, db, zName, zDbase)
	if p == uintptr(0) {
		if int32((*Parse)(unsafe.Pointer(pParse)).FprepFlags)&SQLITE_PREPARE_NO_VTAB == 0 && int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) == 0 {
			var pMod uintptr = Xsqlite3HashFind(tls, db+576, zName)
			if pMod == uintptr(0) && Xsqlite3_strnicmp(tls, zName, ts+15543, 7) == 0 {
				pMod = Xsqlite3PragmaVtabRegister(tls, db, zName)
			}
			if pMod != 0 && Xsqlite3VtabEponymousTableInit(tls, pParse, pMod) != 0 {
				return (*Module)(unsafe.Pointer(pMod)).FpEpoTab
			}
		}
		if flags&U32(LOCATE_NOERR) != 0 {
			return uintptr(0)
		}
		(*Parse)(unsafe.Pointer(pParse)).FcheckSchema = U8(1)
	} else if int32((*Table)(unsafe.Pointer(p)).FeTabType) == TABTYP_VTAB && int32((*Parse)(unsafe.Pointer(pParse)).FprepFlags)&SQLITE_PREPARE_NO_VTAB != 0 {
		p = uintptr(0)
	}

	if p == uintptr(0) {
		var zMsg uintptr
		if flags&U32(LOCATE_VIEW) != 0 {
			zMsg = ts + 15551
		} else {
			zMsg = ts + 15564
		}
		if zDbase != 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+9860, libc.VaList(bp, zMsg, zDbase, zName))
		} else {
			Xsqlite3ErrorMsg(tls, pParse, ts+9870, libc.VaList(bp+24, zMsg, zName))
		}
	} else {
	}

	return p
}

func Xsqlite3LocateTableItem(tls *libc.TLS, pParse uintptr, flags U32, p uintptr) uintptr {
	var zDb uintptr

	if (*SrcItem)(unsafe.Pointer(p)).FpSchema != 0 {
		var iDb int32 = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*SrcItem)(unsafe.Pointer(p)).FpSchema)
		zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*32)).FzDbSName
	} else {
		zDb = (*SrcItem)(unsafe.Pointer(p)).FzDatabase
	}
	return Xsqlite3LocateTable(tls, pParse, flags, (*SrcItem)(unsafe.Pointer(p)).FzName, zDb)
}

func Xsqlite3PreferredTableName(tls *libc.TLS, zName uintptr) uintptr {
	if Xsqlite3_strnicmp(tls, zName, ts+9596, 7) == 0 {
		if Xsqlite3StrICmp(tls, zName+uintptr(7), ts+8808+7) == 0 {
			return ts + 9642
		}
		if Xsqlite3StrICmp(tls, zName+uintptr(7), ts+9604+7) == 0 {
			return ts + 9623
		}
	}
	return zName
}

func Xsqlite3FindIndex(tls *libc.TLS, db uintptr, zName uintptr, zDb uintptr) uintptr {
	var p uintptr = uintptr(0)
	var i int32

	for i = OMIT_TEMPDB; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var j int32
		if i < 2 {
			j = i ^ 1
		} else {
			j = i
		}
		var pSchema uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*32)).FpSchema

		if zDb != 0 && Xsqlite3DbIsNamed(tls, db, j, zDb) == 0 {
			continue
		}

		p = Xsqlite3HashFind(tls, pSchema+32, zName)
		if p != 0 {
			break
		}
	}
	return p
}

func Xsqlite3FreeIndex(tls *libc.TLS, db uintptr, p uintptr) {
	Xsqlite3DeleteIndexSamples(tls, db, p)
	Xsqlite3ExprDelete(tls, db, (*Index)(unsafe.Pointer(p)).FpPartIdxWhere)
	Xsqlite3ExprListDelete(tls, db, (*Index)(unsafe.Pointer(p)).FaColExpr)
	Xsqlite3DbFree(tls, db, (*Index)(unsafe.Pointer(p)).FzColAff)
	if uint32(int32(*(*uint16)(unsafe.Pointer(p + 100))&0x10>>4)) != 0 {
		Xsqlite3DbFree(tls, db, (*Index)(unsafe.Pointer(p)).FazColl)
	}
	Xsqlite3_free(tls, (*Index)(unsafe.Pointer(p)).FaiRowEst)
	Xsqlite3DbFree(tls, db, p)
}

func Xsqlite3UnlinkAndDeleteIndex(tls *libc.TLS, db uintptr, iDb int32, zIdxName uintptr) {
	var pIndex uintptr
	var pHash uintptr

	pHash = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema + 32
	pIndex = Xsqlite3HashInsert(tls, pHash, zIdxName, uintptr(0))
	if pIndex != 0 {
		if (*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FpTable)).FpIndex == pIndex {
			(*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FpTable)).FpIndex = (*Index)(unsafe.Pointer(pIndex)).FpNext
		} else {
			var p uintptr

			p = (*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FpTable)).FpIndex
			for p != 0 && (*Index)(unsafe.Pointer(p)).FpNext != pIndex {
				p = (*Index)(unsafe.Pointer(p)).FpNext
			}
			if p != 0 && (*Index)(unsafe.Pointer(p)).FpNext == pIndex {
				(*Index)(unsafe.Pointer(p)).FpNext = (*Index)(unsafe.Pointer(pIndex)).FpNext
			}
		}
		Xsqlite3FreeIndex(tls, db, pIndex)
	}
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaChange)
}

func Xsqlite3CollapseDatabaseArray(tls *libc.TLS, db uintptr) {
	var i int32
	var j int32
	for i = libc.AssignInt32(&j, 2); i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pDb uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32
		if (*Db1)(unsafe.Pointer(pDb)).FpBt == uintptr(0) {
			Xsqlite3DbFree(tls, db, (*Db1)(unsafe.Pointer(pDb)).FzDbSName)
			(*Db1)(unsafe.Pointer(pDb)).FzDbSName = uintptr(0)
			continue
		}
		if j < i {
			*(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*32)) = *(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32))
		}
		j++
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnDb = j
	if (*Sqlite3)(unsafe.Pointer(db)).FnDb <= 2 && (*Sqlite3)(unsafe.Pointer(db)).FaDb != db+696 {
		libc.Xmemcpy(tls, db+696, (*Sqlite3)(unsafe.Pointer(db)).FaDb, uint64(2)*uint64(unsafe.Sizeof(Db{})))
		Xsqlite3DbFree(tls, db, (*Sqlite3)(unsafe.Pointer(db)).FaDb)
		(*Sqlite3)(unsafe.Pointer(db)).FaDb = db + 696
	}
}

func Xsqlite3ResetOneSchema(tls *libc.TLS, db uintptr, iDb int32) {
	var i int32

	if iDb >= 0 {
		*(*U16)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema + 114)) |= U16(DB_ResetWanted)
		*(*U16)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema + 114)) |= U16(DB_ResetWanted)
		*(*U32)(unsafe.Pointer(db + 44)) &= libc.Uint32FromInt32(libc.CplInt32(DBFLAG_SchemaKnownOk))
	}

	if (*Sqlite3)(unsafe.Pointer(db)).FnSchemaLock == U32(0) {
		for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			if int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpSchema)).FschemaFlags)&DB_ResetWanted == DB_ResetWanted {
				Xsqlite3SchemaClear(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpSchema)
			}
		}
	}
}

func Xsqlite3ResetAllSchemasOfConnection(tls *libc.TLS, db uintptr) {
	var i int32
	Xsqlite3BtreeEnterAll(tls, db)
	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pDb uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32
		if (*Db)(unsafe.Pointer(pDb)).FpSchema != 0 {
			if (*Sqlite3)(unsafe.Pointer(db)).FnSchemaLock == U32(0) {
				Xsqlite3SchemaClear(tls, (*Db)(unsafe.Pointer(pDb)).FpSchema)
			} else {
				*(*U16)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpSchema + 114)) |= U16(DB_ResetWanted)
			}
		}
	}
	*(*U32)(unsafe.Pointer(db + 44)) &= libc.Uint32FromInt32(libc.CplInt32(DBFLAG_SchemaChange | DBFLAG_SchemaKnownOk))
	Xsqlite3VtabUnlockList(tls, db)
	Xsqlite3BtreeLeaveAll(tls, db)
	if (*Sqlite3)(unsafe.Pointer(db)).FnSchemaLock == U32(0) {
		Xsqlite3CollapseDatabaseArray(tls, db)
	}
}

func Xsqlite3CommitInternalChanges(tls *libc.TLS, db uintptr) {
	*(*U32)(unsafe.Pointer(db + 44)) &= libc.Uint32FromInt32(libc.CplInt32(DBFLAG_SchemaChange))
}

func Xsqlite3ColumnSetExpr(tls *libc.TLS, pParse uintptr, pTab uintptr, pCol uintptr, pExpr uintptr) {
	var pList uintptr

	pList = *(*uintptr)(unsafe.Pointer(pTab + 64 + 16))
	if int32((*Column)(unsafe.Pointer(pCol)).FiDflt) == 0 ||
		pList == uintptr(0) ||
		(*ExprList)(unsafe.Pointer(pList)).FnExpr < int32((*Column)(unsafe.Pointer(pCol)).FiDflt) {
		(*Column)(unsafe.Pointer(pCol)).FiDflt = func() uint16 {
			if pList == uintptr(0) {
				return uint16(1)
			}
			return uint16((*ExprList)(unsafe.Pointer(pList)).FnExpr + 1)
		}()
		*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)) = Xsqlite3ExprListAppend(tls, pParse, pList, pExpr)
	} else {
		Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(int32((*Column)(unsafe.Pointer(pCol)).FiDflt)-1)*32)).FpExpr)
		(*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(int32((*Column)(unsafe.Pointer(pCol)).FiDflt)-1)*32)).FpExpr = pExpr
	}
}

func Xsqlite3ColumnExpr(tls *libc.TLS, pTab uintptr, pCol uintptr) uintptr {
	if int32((*Column)(unsafe.Pointer(pCol)).FiDflt) == 0 {
		return uintptr(0)
	}
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM) {
		return uintptr(0)
	}
	if *(*uintptr)(unsafe.Pointer(pTab + 64 + 16)) == uintptr(0) {
		return uintptr(0)
	}
	if (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)))).FnExpr < int32((*Column)(unsafe.Pointer(pCol)).FiDflt) {
		return uintptr(0)
	}
	return (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)) + 8 + uintptr(int32((*Column)(unsafe.Pointer(pCol)).FiDflt)-1)*32)).FpExpr
}

func Xsqlite3ColumnSetColl(tls *libc.TLS, db uintptr, pCol uintptr, zColl uintptr) {
	var nColl I64
	var n I64
	var zNew uintptr

	n = I64(Xsqlite3Strlen30(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName) + 1)
	if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_HASTYPE != 0 {
		n = n + I64(Xsqlite3Strlen30(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName+uintptr(n))+1)
	}
	nColl = I64(Xsqlite3Strlen30(tls, zColl) + 1)
	zNew = Xsqlite3DbRealloc(tls, db, (*Column)(unsafe.Pointer(pCol)).FzCnName, uint64(nColl+n))
	if zNew != 0 {
		(*Column)(unsafe.Pointer(pCol)).FzCnName = zNew
		libc.Xmemcpy(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName+uintptr(n), zColl, uint64(nColl))
		*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_HASCOLL)
	}
}

func Xsqlite3ColumnColl(tls *libc.TLS, pCol uintptr) uintptr {
	var z uintptr
	if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_HASCOLL == 0 {
		return uintptr(0)
	}
	z = (*Column)(unsafe.Pointer(pCol)).FzCnName
	for *(*uint8)(unsafe.Pointer(z)) != 0 {
		z++
	}
	if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_HASTYPE != 0 {
		for __ccgo := true; __ccgo; __ccgo = *(*uint8)(unsafe.Pointer(z)) != 0 {
			z++
		}
	}
	return z + uintptr(1)
}

func Xsqlite3DeleteColumnNames(tls *libc.TLS, db uintptr, pTable uintptr) {
	var i int32
	var pCol uintptr

	if libc.AssignUintptr(&pCol, (*Table)(unsafe.Pointer(pTable)).FaCol) != uintptr(0) {
		i = 0
	__1:
		if !(i < int32((*Table)(unsafe.Pointer(pTable)).FnCol)) {
			goto __3
		}
		{
			Xsqlite3DbFree(tls, db, (*Column)(unsafe.Pointer(pCol)).FzCnName)

		}
		goto __2
	__2:
		i++
		pCol += 24
		goto __1
		goto __3
	__3:
		;
		Xsqlite3DbNNFreeNN(tls, db, (*Table)(unsafe.Pointer(pTable)).FaCol)
		if int32((*Table)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_NORM {
			Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pTable + 64 + 16)))
		}
		if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			(*Table)(unsafe.Pointer(pTable)).FaCol = uintptr(0)
			(*Table)(unsafe.Pointer(pTable)).FnCol = int16(0)
			if int32((*Table)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_NORM {
				*(*uintptr)(unsafe.Pointer(pTable + 64 + 16)) = uintptr(0)
			}
		}
	}
}

func deleteTable(tls *libc.TLS, db uintptr, pTable uintptr) {
	var pIndex uintptr
	var pNext uintptr

	for pIndex = (*Table)(unsafe.Pointer(pTable)).FpIndex; pIndex != 0; pIndex = pNext {
		pNext = (*Index)(unsafe.Pointer(pIndex)).FpNext

		if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) && !(int32((*Table)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_VTAB) {
			var zName uintptr = (*Index)(unsafe.Pointer(pIndex)).FzName
			Xsqlite3HashInsert(tls,
				(*Index)(unsafe.Pointer(pIndex)).FpSchema+32, zName, uintptr(0))

		}
		Xsqlite3FreeIndex(tls, db, pIndex)
	}

	if int32((*Table)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_NORM {
		Xsqlite3FkDelete(tls, db, pTable)
	} else if int32((*Table)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_VTAB {
		Xsqlite3VtabClear(tls, db, pTable)
	} else {
		Xsqlite3SelectDelete(tls, db, *(*uintptr)(unsafe.Pointer(pTable + 64)))
	}

	Xsqlite3DeleteColumnNames(tls, db, pTable)
	Xsqlite3DbFree(tls, db, (*Table)(unsafe.Pointer(pTable)).FzName)
	Xsqlite3DbFree(tls, db, (*Table)(unsafe.Pointer(pTable)).FzColAff)
	Xsqlite3ExprListDelete(tls, db, (*Table)(unsafe.Pointer(pTable)).FpCheck)
	Xsqlite3DbFree(tls, db, pTable)

}

func Xsqlite3DeleteTable(tls *libc.TLS, db uintptr, pTable uintptr) {
	if !(pTable != 0) {
		return
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) && libc.PreDecUint32(&(*Table)(unsafe.Pointer(pTable)).FnTabRef, 1) > U32(0) {
		return
	}
	deleteTable(tls, db, pTable)
}

func Xsqlite3UnlinkAndDeleteTable(tls *libc.TLS, db uintptr, iDb int32, zTabName uintptr) {
	var p uintptr
	var pDb uintptr

	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	p = Xsqlite3HashInsert(tls, (*Db)(unsafe.Pointer(pDb)).FpSchema+8, zTabName, uintptr(0))
	Xsqlite3DeleteTable(tls, db, p)
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaChange)
}

func Xsqlite3NameFromToken(tls *libc.TLS, db uintptr, pName uintptr) uintptr {
	var zName uintptr
	if pName != 0 {
		zName = Xsqlite3DbStrNDup(tls, db, (*Token)(unsafe.Pointer(pName)).Fz, uint64((*Token)(unsafe.Pointer(pName)).Fn))
		Xsqlite3Dequote(tls, zName)
	} else {
		zName = uintptr(0)
	}
	return zName
}

func Xsqlite3OpenSchemaTable(tls *libc.TLS, p uintptr, iDb int32) {
	var v uintptr = Xsqlite3GetVdbe(tls, p)
	Xsqlite3TableLock(tls, p, iDb, uint32(SCHEMA_ROOT), uint8(1), ts+8808)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5)
	if (*Parse)(unsafe.Pointer(p)).FnTab == 0 {
		(*Parse)(unsafe.Pointer(p)).FnTab = 1
	}
}

func Xsqlite3FindDbName(tls *libc.TLS, db uintptr, zName uintptr) int32 {
	var i int32 = -1
	if zName != 0 {
		var pDb uintptr
		i = (*Sqlite3)(unsafe.Pointer(db)).FnDb - 1
		pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32
	__1:
		if !(i >= 0) {
			goto __3
		}
		{
			if 0 == Xsqlite3_stricmp(tls, (*Db)(unsafe.Pointer(pDb)).FzDbSName, zName) {
				goto __3
			}

			if i == 0 && 0 == Xsqlite3_stricmp(tls, ts+9656, zName) {
				goto __3
			}

		}
		goto __2
	__2:
		i--
		pDb -= 32
		goto __1
		goto __3
	__3:
	}
	return i
}

func Xsqlite3FindDb(tls *libc.TLS, db uintptr, pName uintptr) int32 {
	var i int32
	var zName uintptr
	zName = Xsqlite3NameFromToken(tls, db, pName)
	i = Xsqlite3FindDbName(tls, db, zName)
	Xsqlite3DbFree(tls, db, zName)
	return i
}

func Xsqlite3TwoPartName(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, pUnqual uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var iDb int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if (*Token)(unsafe.Pointer(pName2)).Fn > uint32(0) {
		if (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+15578, 0)
			return -1
		}
		*(*uintptr)(unsafe.Pointer(pUnqual)) = pName2
		iDb = Xsqlite3FindDb(tls, db, pName1)
		if iDb < 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+15595, libc.VaList(bp, pName1))
			return -1
		}
	} else {
		iDb = int32((*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb)
		*(*uintptr)(unsafe.Pointer(pUnqual)) = pName1
	}
	return iDb
}

func Xsqlite3WritableSchema(tls *libc.TLS, db uintptr) int32 {
	return libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_WriteSchema|SQLITE_Defensive) == uint64(SQLITE_WriteSchema))
}

func Xsqlite3CheckObjectName(tls *libc.TLS, pParse uintptr, zName uintptr, zType uintptr, zTblName uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if Xsqlite3WritableSchema(tls, db) != 0 ||
		uint32(int32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x2>>1)) != 0 ||
		!(int32(Xsqlite3Config.FbExtraSchemaChecks) != 0) {
		return SQLITE_OK
	}
	if (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 {
		if Xsqlite3_stricmp(tls, zType, *(*uintptr)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).Finit.FazInit))) != 0 ||
			Xsqlite3_stricmp(tls, zName, *(*uintptr)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).Finit.FazInit + 1*8))) != 0 ||
			Xsqlite3_stricmp(tls, zTblName, *(*uintptr)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).Finit.FazInit + 2*8))) != 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+1636, 0)
			return SQLITE_ERROR
		}
	} else {
		if int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0 && 0 == Xsqlite3_strnicmp(tls, zName, ts+9596, 7) ||
			Xsqlite3ReadOnlyShadowTables(tls, db) != 0 && Xsqlite3ShadowTableName(tls, db, zName) != 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+15615,
				libc.VaList(bp, zName))
			return SQLITE_ERROR
		}

	}
	return SQLITE_OK
}

func Xsqlite3PrimaryKeyIndex(tls *libc.TLS, pTab uintptr) uintptr {
	var p uintptr
	for p = (*Table)(unsafe.Pointer(pTab)).FpIndex; p != 0 && !(int32(*(*uint16)(unsafe.Pointer(p + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY); p = (*Index)(unsafe.Pointer(p)).FpNext {
	}
	return p
}

func Xsqlite3TableColumnToIndex(tls *libc.TLS, pIdx uintptr, iCol I16) I16 {
	var i int32
	for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn); i++ {
		if int32(iCol) == int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) {
			return I16(i)
		}
	}
	return int16(-1)
}

func Xsqlite3StorageColumnToTable(tls *libc.TLS, pTab uintptr, iCol I16) I16 {
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasVirtual) != 0 {
		var i int32
		for i = 0; i <= int32(iCol); i++ {
			if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL != 0 {
				iCol++
			}
		}
	}
	return iCol
}

func Xsqlite3TableColumnToStorage(tls *libc.TLS, pTab uintptr, iCol I16) I16 {
	var i int32
	var n I16

	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasVirtual) == U32(0) || int32(iCol) < 0 {
		return iCol
	}
	i = 0
	n = int16(0)
	for ; i < int32(iCol); i++ {
		if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL == 0 {
			n++
		}
	}
	if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL != 0 {
		return I16(int32((*Table)(unsafe.Pointer(pTab)).FnNVCol) + i - int32(n))
	} else {
		return n
	}
	return I16(0)
}

func sqlite3ForceNotReadOnly(tls *libc.TLS, pParse uintptr) {
	var iReg int32 = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	if v != 0 {
		Xsqlite3VdbeAddOp3(tls, v, OP_JournalMode, 0, iReg, -1)
		Xsqlite3VdbeUsesBtree(tls, v, 0)
	}
}

func Xsqlite3StartTable(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 pTable uintptr
	var zName uintptr
	var db uintptr
	var v uintptr
	var iDb int32

	var zDb uintptr
	var zDb1 uintptr
	var addr1 int32
	var fileFormat int32
	var reg1 int32
	var reg2 int32
	var reg3 int32
	zName = uintptr(0)
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 && (*Sqlite3)(unsafe.Pointer(db)).Finit.FnewTnum == Pgno(1)) {
		goto __1
	}

	iDb = int32((*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb)
	zName = Xsqlite3DbStrDup(tls, db, func() uintptr {
		if !(0 != 0) && iDb == 1 {
			return ts + 9604
		}
		return ts + 8808
	}())
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pName1
	goto __2
__1:
	iDb = Xsqlite3TwoPartName(tls, pParse, pName1, pName2, bp+24)
	if !(iDb < 0) {
		goto __3
	}
	return
__3:
	;
	if !(!(0 != 0) && isTemp != 0 && (*Token)(unsafe.Pointer(pName2)).Fn > uint32(0) && iDb != 1) {
		goto __4
	}

	Xsqlite3ErrorMsg(tls, pParse, ts+15657, 0)
	return
__4:
	;
	if !(!(0 != 0) && isTemp != 0) {
		goto __5
	}
	iDb = 1
__5:
	;
	zName = Xsqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp + 24)))
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __6
	}
	Xsqlite3RenameTokenMap(tls, pParse, zName, *(*uintptr)(unsafe.Pointer(bp + 24)))
__6:
	;
__2:
	;
	(*Parse)(unsafe.Pointer(pParse)).FsNameToken = *(*Token)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24))))
	if !(zName == uintptr(0)) {
		goto __7
	}
	return
__7:
	;
	if !(Xsqlite3CheckObjectName(tls, pParse, zName, func() uintptr {
		if isView != 0 {
			return ts + 13875
		}
		return ts + 9499
	}(), zName) != 0) {
		goto __8
	}
	goto begin_table_error
__8:
	;
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb) == 1) {
		goto __9
	}
	isTemp = 1
__9:
	;
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_INSERT, func() uintptr {
		if !(0 != 0) && isTemp == 1 {
			return ts + 9604
		}
		return ts + 8808
	}(), uintptr(0), zDb) != 0) {
		goto __10
	}
	goto begin_table_error
__10:
	;
	if !(!(isVirtual != 0) && Xsqlite3AuthCheck(tls, pParse, int32(aCode[isTemp+2*isView]),
		zName, uintptr(0), zDb) != 0) {
		goto __11
	}
	goto begin_table_error
__11:
	;
	if !!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL) {
		goto __12
	}
	zDb1 = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	if !(SQLITE_OK != Xsqlite3ReadSchema(tls, pParse)) {
		goto __13
	}
	goto begin_table_error
__13:
	;
	pTable = Xsqlite3FindTable(tls, db, zName, zDb1)
	if !(pTable != 0) {
		goto __14
	}
	if !!(noErr != 0) {
		goto __15
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+15698,
		libc.VaList(bp, func() uintptr {
			if int32((*Table)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_VIEW {
				return ts + 13875
			}
			return ts + 9499
		}(), *(*uintptr)(unsafe.Pointer(bp + 24))))
	goto __16
__15:
	;
	Xsqlite3CodeVerifySchema(tls, pParse, iDb)
	sqlite3ForceNotReadOnly(tls, pParse)
__16:
	;
	goto begin_table_error
__14:
	;
	if !(Xsqlite3FindIndex(tls, db, zName, zDb1) != uintptr(0)) {
		goto __17
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+15719, libc.VaList(bp+16, zName))
	goto begin_table_error
__17:
	;
__12:
	;
	pTable = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Table{})))
	if !(pTable == uintptr(0)) {
		goto __18
	}

	(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
	(*Parse)(unsafe.Pointer(pParse)).FnErr++
	goto begin_table_error
__18:
	;
	(*Table)(unsafe.Pointer(pTable)).FzName = zName
	(*Table)(unsafe.Pointer(pTable)).FiPKey = int16(-1)
	(*Table)(unsafe.Pointer(pTable)).FpSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
	(*Table)(unsafe.Pointer(pTable)).FnTabRef = U32(1)
	(*Table)(unsafe.Pointer(pTable)).FnRowLogEst = int16(200)

	(*Parse)(unsafe.Pointer(pParse)).FpNewTable = pTable

	if !(!(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) && libc.AssignUintptr(&v, Xsqlite3GetVdbe(tls, pParse)) != uintptr(0)) {
		goto __19
	}
	Xsqlite3BeginWriteOperation(tls, pParse, 1, iDb)

	if !(isVirtual != 0) {
		goto __20
	}
	Xsqlite3VdbeAddOp0(tls, v, OP_VBegin)
__20:
	;
	reg1 = libc.AssignPtrInt32(pParse+128, libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1))
	reg2 = libc.AssignPtrInt32(pParse+132, libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1))
	reg3 = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp3(tls, v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT)
	Xsqlite3VdbeUsesBtree(tls, v, iDb)
	addr1 = Xsqlite3VdbeAddOp1(tls, v, OP_If, reg3)
	if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LegacyFileFmt) != uint64(0) {
		fileFormat = 1
	} else {
		fileFormat = SQLITE_MAX_FILE_FORMAT
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat)
	Xsqlite3VdbeAddOp3(tls, v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, int32((*Sqlite3)(unsafe.Pointer(db)).Fenc))
	Xsqlite3VdbeJumpHere(tls, v, addr1)

	if !(isView != 0 || isVirtual != 0) {
		goto __21
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, reg2)
	goto __22
__21:
	;
	*(*int32)(unsafe.Pointer(pParse + 200)) = Xsqlite3VdbeAddOp3(tls, v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY)
__22:
	;
	Xsqlite3OpenSchemaTable(tls, pParse, iDb)
	Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, 0, reg1)
	Xsqlite3VdbeAddOp4(tls, v, OP_Blob, 6, reg3, 0, uintptr(unsafe.Pointer(&nullRow)), -1)
	Xsqlite3VdbeAddOp3(tls, v, OP_Insert, 0, reg3, reg1)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
	Xsqlite3VdbeAddOp0(tls, v, OP_Close)
__19:
	;
	return

begin_table_error:
	(*Parse)(unsafe.Pointer(pParse)).FcheckSchema = U8(1)
	Xsqlite3DbFree(tls, db, zName)
	return
}

var aCode = [4]U8{
	U8(SQLITE_CREATE_TABLE),
	U8(SQLITE_CREATE_TEMP_TABLE),
	U8(SQLITE_CREATE_VIEW),
	U8(SQLITE_CREATE_TEMP_VIEW),
}
var nullRow = [6]uint8{uint8(6), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0)}

func sqlite3DeleteReturning(tls *libc.TLS, db uintptr, pRet uintptr) {
	var pHash uintptr
	pHash = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema + 56
	Xsqlite3HashInsert(tls, pHash, ts+15754, uintptr(0))
	Xsqlite3ExprListDelete(tls, db, (*Returning)(unsafe.Pointer(pRet)).FpReturnEL)
	Xsqlite3DbFree(tls, db, pRet)
}

func Xsqlite3AddReturning(tls *libc.TLS, pParse uintptr, pList uintptr) {
	var pRet uintptr
	var pHash uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if (*Parse)(unsafe.Pointer(pParse)).FpNewTrigger != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+15771, 0)
	} else {
	}
	(*Parse)(unsafe.Pointer(pParse)).FbReturning = U8(1)
	pRet = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Returning{})))
	if pRet == uintptr(0) {
		Xsqlite3ExprListDelete(tls, db, pList)
		return
	}
	*(*uintptr)(unsafe.Pointer(pParse + 200)) = pRet
	(*Returning)(unsafe.Pointer(pRet)).FpParse = pParse
	(*Returning)(unsafe.Pointer(pRet)).FpReturnEL = pList
	Xsqlite3ParserAddCleanup(tls, pParse,
		*(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{sqlite3DeleteReturning})), pRet)

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return
	}
	(*Returning)(unsafe.Pointer(pRet)).FretTrig.FzName = ts + 15754
	(*Returning)(unsafe.Pointer(pRet)).FretTrig.Fop = U8(TK_RETURNING)
	(*Returning)(unsafe.Pointer(pRet)).FretTrig.Ftr_tm = U8(TRIGGER_AFTER)
	(*Returning)(unsafe.Pointer(pRet)).FretTrig.FbReturning = U8(1)
	(*Returning)(unsafe.Pointer(pRet)).FretTrig.FpSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + 1*32)).FpSchema
	(*Returning)(unsafe.Pointer(pRet)).FretTrig.FpTabSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + 1*32)).FpSchema
	(*Returning)(unsafe.Pointer(pRet)).FretTrig.Fstep_list = pRet + 88
	(*Returning)(unsafe.Pointer(pRet)).FretTStep.Fop = U8(TK_RETURNING)
	(*Returning)(unsafe.Pointer(pRet)).FretTStep.FpTrig = pRet + 16
	(*Returning)(unsafe.Pointer(pRet)).FretTStep.FpExprList = pList
	pHash = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema + 56

	if Xsqlite3HashInsert(tls, pHash, ts+15754, pRet+16) ==
		pRet+16 {
		Xsqlite3OomFault(tls, db)
	}
}

func Xsqlite3AddColumn(tls *libc.TLS, pParse uintptr, sName Token, sType Token) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	*(*Token)(unsafe.Pointer(bp + 16)) = sName
	*(*Token)(unsafe.Pointer(bp + 32)) = sType

	var p uintptr
	var i int32
	var z uintptr
	var zType uintptr
	var pCol uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var hName U8
	var aNew uintptr
	var eType U8 = U8(COLTYPE_CUSTOM)
	var szEst U8 = U8(1)
	var affinity uint8 = uint8(SQLITE_AFF_BLOB)

	if libc.AssignUintptr(&p, (*Parse)(unsafe.Pointer(pParse)).FpNewTable) == uintptr(0) {
		return
	}
	if int32((*Table)(unsafe.Pointer(p)).FnCol)+1 > *(*int32)(unsafe.Pointer(db + 136 + 2*4)) {
		Xsqlite3ErrorMsg(tls, pParse, ts+15805, libc.VaList(bp, (*Table)(unsafe.Pointer(p)).FzName))
		return
	}
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		Xsqlite3DequoteToken(tls, bp+16)
	}

	if (*Token)(unsafe.Pointer(bp+32)).Fn >= uint32(16) &&
		Xsqlite3_strnicmp(tls, (*Token)(unsafe.Pointer(bp+32)).Fz+uintptr((*Token)(unsafe.Pointer(bp+32)).Fn-uint32(6)), ts+15828, 6) == 0 {
		*(*uint32)(unsafe.Pointer(bp + 32 + 8)) -= uint32(6)
		for (*Token)(unsafe.Pointer(bp+32)).Fn > uint32(0) && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(bp+32)).Fz + uintptr((*Token)(unsafe.Pointer(bp+32)).Fn-uint32(1))))])&0x01 != 0 {
			(*Token)(unsafe.Pointer(bp+32)).Fn--
		}
		if (*Token)(unsafe.Pointer(bp+32)).Fn >= uint32(9) &&
			Xsqlite3_strnicmp(tls, (*Token)(unsafe.Pointer(bp+32)).Fz+uintptr((*Token)(unsafe.Pointer(bp+32)).Fn-uint32(9)), ts+15835, 9) == 0 {
			*(*uint32)(unsafe.Pointer(bp + 32 + 8)) -= uint32(9)
			for (*Token)(unsafe.Pointer(bp+32)).Fn > uint32(0) && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(bp+32)).Fz + uintptr((*Token)(unsafe.Pointer(bp+32)).Fn-uint32(1))))])&0x01 != 0 {
				(*Token)(unsafe.Pointer(bp+32)).Fn--
			}
		}
	}

	if (*Token)(unsafe.Pointer(bp+32)).Fn >= uint32(3) {
		Xsqlite3DequoteToken(tls, bp+32)
		for i = 0; i < SQLITE_N_STDTYPE; i++ {
			if (*Token)(unsafe.Pointer(bp+32)).Fn == uint32(Xsqlite3StdTypeLen[i]) &&
				Xsqlite3_strnicmp(tls, (*Token)(unsafe.Pointer(bp+32)).Fz, Xsqlite3StdType[i], int32((*Token)(unsafe.Pointer(bp+32)).Fn)) == 0 {
				(*Token)(unsafe.Pointer(bp + 32)).Fn = uint32(0)
				eType = U8(i + 1)
				affinity = Xsqlite3StdTypeAffinity[i]
				if int32(affinity) <= SQLITE_AFF_TEXT {
					szEst = U8(5)
				}
				break
			}
		}
	}

	z = Xsqlite3DbMallocRaw(tls, db, uint64(I64((*Token)(unsafe.Pointer(bp+16)).Fn)+int64(1)+I64((*Token)(unsafe.Pointer(bp+32)).Fn)+I64(libc.Bool32((*Token)(unsafe.Pointer(bp+32)).Fn > uint32(0)))))
	if z == uintptr(0) {
		return
	}
	if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
		Xsqlite3RenameTokenMap(tls, pParse, z, bp+16)
	}
	libc.Xmemcpy(tls, z, (*Token)(unsafe.Pointer(bp+16)).Fz, uint64((*Token)(unsafe.Pointer(bp+16)).Fn))
	*(*uint8)(unsafe.Pointer(z + uintptr((*Token)(unsafe.Pointer(bp+16)).Fn))) = uint8(0)
	Xsqlite3Dequote(tls, z)
	hName = Xsqlite3StrIHash(tls, z)
	for i = 0; i < int32((*Table)(unsafe.Pointer(p)).FnCol); i++ {
		if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(p)).FaCol+uintptr(i)*24)).FhName) == int32(hName) && Xsqlite3StrICmp(tls, z, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(p)).FaCol+uintptr(i)*24)).FzCnName) == 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+15845, libc.VaList(bp+8, z))
			Xsqlite3DbFree(tls, db, z)
			return
		}
	}
	aNew = Xsqlite3DbRealloc(tls, db, (*Table)(unsafe.Pointer(p)).FaCol, uint64(I64((*Table)(unsafe.Pointer(p)).FnCol)+int64(1))*uint64(unsafe.Sizeof(Column{})))
	if aNew == uintptr(0) {
		Xsqlite3DbFree(tls, db, z)
		return
	}
	(*Table)(unsafe.Pointer(p)).FaCol = aNew
	pCol = (*Table)(unsafe.Pointer(p)).FaCol + uintptr((*Table)(unsafe.Pointer(p)).FnCol)*24
	libc.Xmemset(tls, pCol, 0, uint64(unsafe.Sizeof(Column{})))
	(*Column)(unsafe.Pointer(pCol)).FzCnName = z
	(*Column)(unsafe.Pointer(pCol)).FhName = hName

	if (*Token)(unsafe.Pointer(bp+32)).Fn == uint32(0) {
		(*Column)(unsafe.Pointer(pCol)).Faffinity = affinity
		libc.SetBitFieldPtr8Uint32(pCol+8, uint32(eType), 4, 0xf0)
		(*Column)(unsafe.Pointer(pCol)).FszEst = szEst
	} else {
		zType = z + uintptr(Xsqlite3Strlen30(tls, z)) + uintptr(1)
		libc.Xmemcpy(tls, zType, (*Token)(unsafe.Pointer(bp+32)).Fz, uint64((*Token)(unsafe.Pointer(bp+32)).Fn))
		*(*uint8)(unsafe.Pointer(zType + uintptr((*Token)(unsafe.Pointer(bp+32)).Fn))) = uint8(0)
		Xsqlite3Dequote(tls, zType)
		(*Column)(unsafe.Pointer(pCol)).Faffinity = Xsqlite3AffinityType(tls, zType, pCol)
		*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_HASTYPE)
	}
	(*Table)(unsafe.Pointer(p)).FnCol++
	(*Table)(unsafe.Pointer(p)).FnNVCol++
	(*Parse)(unsafe.Pointer(pParse)).FconstraintName.Fn = uint32(0)
}

func Xsqlite3AddNotNull(tls *libc.TLS, pParse uintptr, onError int32) {
	var p uintptr
	var pCol uintptr
	p = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	if p == uintptr(0) || int32((*Table)(unsafe.Pointer(p)).FnCol) < 1 {
		return
	}
	pCol = (*Table)(unsafe.Pointer(p)).FaCol + uintptr(int32((*Table)(unsafe.Pointer(p)).FnCol)-1)*24
	libc.SetBitFieldPtr8Uint32(pCol+8, uint32(U8(onError)), 0, 0xf)
	*(*U32)(unsafe.Pointer(p + 48)) |= U32(TF_HasNotNull)

	if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_UNIQUE != 0 {
		var pIdx uintptr
		for pIdx = (*Table)(unsafe.Pointer(p)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
			if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn))) == int32((*Table)(unsafe.Pointer(p)).FnCol)-1 {
				libc.SetBitFieldPtr16Uint32(pIdx+100, uint32(1), 3, 0x8)
			}
		}
	}
}

func Xsqlite3AffinityType(tls *libc.TLS, zIn uintptr, pCol uintptr) uint8 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var h U32 = U32(0)
	var aff uint8 = uint8(SQLITE_AFF_NUMERIC)
	var zChar uintptr = uintptr(0)

	for *(*uint8)(unsafe.Pointer(zIn)) != 0 {
		h = h<<8 + U32(Xsqlite3UpperToLower[int32(*(*uint8)(unsafe.Pointer(zIn)))&0xff])
		zIn++
		if h == U32(int32('c')<<24+int32('h')<<16+int32('a')<<8+'r') {
			aff = uint8(SQLITE_AFF_TEXT)
			zChar = zIn
		} else if h == U32(int32('c')<<24+int32('l')<<16+int32('o')<<8+'b') {
			aff = uint8(SQLITE_AFF_TEXT)
		} else if h == U32(int32('t')<<24+int32('e')<<16+int32('x')<<8+'t') {
			aff = uint8(SQLITE_AFF_TEXT)
		} else if h == U32(int32('b')<<24+int32('l')<<16+int32('o')<<8+'b') &&
			(int32(aff) == SQLITE_AFF_NUMERIC || int32(aff) == SQLITE_AFF_REAL) {
			aff = uint8(SQLITE_AFF_BLOB)
			if int32(*(*uint8)(unsafe.Pointer(zIn))) == '(' {
				zChar = zIn
			}
		} else if h == U32(int32('r')<<24+int32('e')<<16+int32('a')<<8+'l') &&
			int32(aff) == SQLITE_AFF_NUMERIC {
			aff = uint8(SQLITE_AFF_REAL)
		} else if h == U32(int32('f')<<24+int32('l')<<16+int32('o')<<8+'a') &&
			int32(aff) == SQLITE_AFF_NUMERIC {
			aff = uint8(SQLITE_AFF_REAL)
		} else if h == U32(int32('d')<<24+int32('o')<<16+int32('u')<<8+'b') &&
			int32(aff) == SQLITE_AFF_NUMERIC {
			aff = uint8(SQLITE_AFF_REAL)
		} else if h&U32(0x00FFFFFF) == U32(int32('i')<<16+int32('n')<<8+'t') {
			aff = uint8(SQLITE_AFF_INTEGER)
			break
		}
	}

	if pCol != 0 {
		*(*int32)(unsafe.Pointer(bp)) = 0
		if int32(aff) < SQLITE_AFF_NUMERIC {
			if zChar != 0 {
				for *(*uint8)(unsafe.Pointer(zChar)) != 0 {
					if int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zChar))])&0x04 != 0 {
						Xsqlite3GetInt32(tls, zChar, bp)
						break
					}
					zChar++
				}
			} else {
				*(*int32)(unsafe.Pointer(bp)) = 16
			}
		}
		*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(bp))/4 + 1
		if *(*int32)(unsafe.Pointer(bp)) > 255 {
			*(*int32)(unsafe.Pointer(bp)) = 255
		}
		(*Column)(unsafe.Pointer(pCol)).FszEst = U8(*(*int32)(unsafe.Pointer(bp)))
	}
	return aff
}

func Xsqlite3AddDefaultValue(tls *libc.TLS, pParse uintptr, pExpr uintptr, zStart uintptr, zEnd uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var p uintptr
	var pCol uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	p = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	if p != uintptr(0) {
		var isInit int32 = libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 && int32((*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb) != 1)
		pCol = (*Table)(unsafe.Pointer(p)).FaCol + uintptr(int32((*Table)(unsafe.Pointer(p)).FnCol)-1)*24
		if !(Xsqlite3ExprIsConstantOrFunction(tls, pExpr, uint8(isInit)) != 0) {
			Xsqlite3ErrorMsg(tls, pParse, ts+15871,
				libc.VaList(bp, (*Column)(unsafe.Pointer(pCol)).FzCnName))
		} else if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_GENERATED != 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+15916, 0)
		} else {
			var pDfltExpr uintptr
			libc.Xmemset(tls, bp+8, 0, uint64(unsafe.Sizeof(Expr{})))
			(*Expr)(unsafe.Pointer(bp + 8)).Fop = U8(TK_SPAN)
			*(*uintptr)(unsafe.Pointer(bp + 8 + 8)) = Xsqlite3DbSpanDup(tls, db, zStart, zEnd)
			(*Expr)(unsafe.Pointer(bp + 8)).FpLeft = pExpr
			(*Expr)(unsafe.Pointer(bp + 8)).Fflags = U32(EP_Skip)
			pDfltExpr = Xsqlite3ExprDup(tls, db, bp+8, EXPRDUP_REDUCE)
			Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8 + 8)))
			Xsqlite3ColumnSetExpr(tls, pParse, p, pCol, pDfltExpr)
		}
	}
	if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
		Xsqlite3RenameExprUnmap(tls, pParse, pExpr)
	}
	Xsqlite3ExprDelete(tls, db, pExpr)
}

func sqlite3StringToId(tls *libc.TLS, p uintptr) {
	if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_STRING {
		(*Expr)(unsafe.Pointer(p)).Fop = U8(TK_ID)
	} else if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_COLLATE && int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(p)).FpLeft)).Fop) == TK_STRING {
		(*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(p)).FpLeft)).Fop = U8(TK_ID)
	}
}

func makeColumnPartOfPrimaryKey(tls *libc.TLS, pParse uintptr, pCol uintptr) {
	*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_PRIMKEY)
	if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_GENERATED != 0 {
		Xsqlite3ErrorMsg(tls, pParse,
			ts+15957, 0)
	}
}

func Xsqlite3AddPrimaryKey(tls *libc.TLS, pParse uintptr, pList uintptr, onError int32, autoInc int32, sortOrder int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pTab uintptr
	var pCol uintptr
	var iCol int32
	var i int32
	var nTerm int32
	var zCName uintptr
	var pCExpr uintptr
	var pCExpr1 uintptr
	pTab = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	pCol = uintptr(0)
	iCol = -1
	if !(pTab == uintptr(0)) {
		goto __1
	}
	goto primary_key_exit
__1:
	;
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasPrimaryKey) != 0) {
		goto __2
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+16009, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto primary_key_exit
__2:
	;
	*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_HasPrimaryKey)
	if !(pList == uintptr(0)) {
		goto __3
	}
	iCol = int32((*Table)(unsafe.Pointer(pTab)).FnCol) - 1
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24
	makeColumnPartOfPrimaryKey(tls, pParse, pCol)
	nTerm = 1
	goto __4
__3:
	nTerm = (*ExprList)(unsafe.Pointer(pList)).FnExpr
	i = 0
__5:
	if !(i < nTerm) {
		goto __7
	}
	pCExpr = Xsqlite3ExprSkipCollate(tls, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr)

	sqlite3StringToId(tls, pCExpr)
	if !(int32((*Expr)(unsafe.Pointer(pCExpr)).Fop) == TK_ID) {
		goto __8
	}

	zCName = *(*uintptr)(unsafe.Pointer(pCExpr + 8))
	iCol = 0
__9:
	if !(iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __11
	}
	if !(Xsqlite3StrICmp(tls, zCName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FzCnName) == 0) {
		goto __12
	}
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24
	makeColumnPartOfPrimaryKey(tls, pParse, pCol)
	goto __11
__12:
	;
	goto __10
__10:
	iCol++
	goto __9
	goto __11
__11:
	;
__8:
	;
	goto __6
__6:
	i++
	goto __5
	goto __7
__7:
	;
__4:
	;
	if !(nTerm == 1 &&
		pCol != 0 &&
		int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4) == COLTYPE_INTEGER &&
		sortOrder != SQLITE_SO_DESC) {
		goto __13
	}
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && pList != 0) {
		goto __15
	}
	pCExpr1 = Xsqlite3ExprSkipCollate(tls, (*ExprList_item)(unsafe.Pointer(pList+8)).FpExpr)
	Xsqlite3RenameTokenRemap(tls, pParse, pTab+52, pCExpr1)
__15:
	;
	(*Table)(unsafe.Pointer(pTab)).FiPKey = I16(iCol)
	(*Table)(unsafe.Pointer(pTab)).FkeyConf = U8(onError)

	*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(autoInc * TF_Autoincrement)
	if !(pList != 0) {
		goto __16
	}
	(*Parse)(unsafe.Pointer(pParse)).FiPkSortOrder = (*ExprList_item)(unsafe.Pointer(pList + 8)).Ffg.FsortFlags
__16:
	;
	Xsqlite3HasExplicitNulls(tls, pParse, pList)
	goto __14
__13:
	if !(autoInc != 0) {
		goto __17
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+16050, 0)
	goto __18
__17:
	Xsqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), pList, onError, uintptr(0),
		uintptr(0), sortOrder, 0, uint8(SQLITE_IDXTYPE_PRIMARYKEY))
	pList = uintptr(0)
__18:
	;
__14:
	;
primary_key_exit:
	Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pList)
	return
}

func Xsqlite3AddCheckConstraint(tls *libc.TLS, pParse uintptr, pCheckExpr uintptr, zStart uintptr, zEnd uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTab uintptr = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if pTab != 0 && !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) == PARSE_MODE_DECLARE_VTAB) &&
		!(Xsqlite3BtreeIsReadonly(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr((*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb)*32)).FpBt) != 0) {
		(*Table)(unsafe.Pointer(pTab)).FpCheck = Xsqlite3ExprListAppend(tls, pParse, (*Table)(unsafe.Pointer(pTab)).FpCheck, pCheckExpr)
		if (*Parse)(unsafe.Pointer(pParse)).FconstraintName.Fn != 0 {
			Xsqlite3ExprListSetName(tls, pParse, (*Table)(unsafe.Pointer(pTab)).FpCheck, pParse+104, 1)
		} else {
			for zStart++; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zStart))])&0x01 != 0; zStart++ {
			}
			for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zEnd + libc.UintptrFromInt32(-1)))])&0x01 != 0 {
				zEnd--
			}
			(*Token)(unsafe.Pointer(bp)).Fz = zStart
			(*Token)(unsafe.Pointer(bp)).Fn = uint32(int32((int64(zEnd) - int64((*Token)(unsafe.Pointer(bp)).Fz)) / 1))
			Xsqlite3ExprListSetName(tls, pParse, (*Table)(unsafe.Pointer(pTab)).FpCheck, bp, 1)
		}
	} else {
		Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pCheckExpr)
	}
}

func Xsqlite3AddCollateType(tls *libc.TLS, pParse uintptr, pToken uintptr) {
	var p uintptr
	var i int32
	var zColl uintptr
	var db uintptr

	if libc.AssignUintptr(&p, (*Parse)(unsafe.Pointer(pParse)).FpNewTable) == uintptr(0) || int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
		return
	}
	i = int32((*Table)(unsafe.Pointer(p)).FnCol) - 1
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	zColl = Xsqlite3NameFromToken(tls, db, pToken)
	if !(zColl != 0) {
		return
	}

	if Xsqlite3LocateCollSeq(tls, pParse, zColl) != 0 {
		var pIdx uintptr
		Xsqlite3ColumnSetColl(tls, db, (*Table)(unsafe.Pointer(p)).FaCol+uintptr(i)*24, zColl)

		for pIdx = (*Table)(unsafe.Pointer(p)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
			if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn))) == i {
				*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl)) = Xsqlite3ColumnColl(tls, (*Table)(unsafe.Pointer(p)).FaCol+uintptr(i)*24)
			}
		}
	}
	Xsqlite3DbFree(tls, db, zColl)
}

func Xsqlite3AddGenerated(tls *libc.TLS, pParse uintptr, pExpr uintptr, pType uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var eType U8
	var pTab uintptr
	var pCol uintptr
	eType = U8(COLFLAG_VIRTUAL)
	pTab = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	if !(pTab == uintptr(0)) {
		goto __1
	}

	goto generated_done
__1:
	;
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(int32((*Table)(unsafe.Pointer(pTab)).FnCol)-1)*24
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) == PARSE_MODE_DECLARE_VTAB) {
		goto __2
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+16106, 0)
	goto generated_done
__2:
	;
	if !(int32((*Column)(unsafe.Pointer(pCol)).FiDflt) > 0) {
		goto __3
	}
	goto generated_error
__3:
	;
	if !(pType != 0) {
		goto __4
	}
	if !((*Token)(unsafe.Pointer(pType)).Fn == uint32(7) && Xsqlite3_strnicmp(tls, ts+16149, (*Token)(unsafe.Pointer(pType)).Fz, 7) == 0) {
		goto __5
	}

	goto __6
__5:
	if !((*Token)(unsafe.Pointer(pType)).Fn == uint32(6) && Xsqlite3_strnicmp(tls, ts+16157, (*Token)(unsafe.Pointer(pType)).Fz, 6) == 0) {
		goto __7
	}
	eType = U8(COLFLAG_STORED)
	goto __8
__7:
	goto generated_error
__8:
	;
__6:
	;
__4:
	;
	if !(int32(eType) == COLFLAG_VIRTUAL) {
		goto __9
	}
	(*Table)(unsafe.Pointer(pTab)).FnNVCol--
__9:
	;
	*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(int32(eType))

	*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(eType)
	if !(int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_PRIMKEY != 0) {
		goto __10
	}
	makeColumnPartOfPrimaryKey(tls, pParse, pCol)
__10:
	;
	if !(pExpr != 0 && int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_ID) {
		goto __11
	}

	pExpr = Xsqlite3PExpr(tls, pParse, TK_UPLUS, pExpr, uintptr(0))
__11:
	;
	if !(pExpr != 0 && int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_RAISE) {
		goto __12
	}
	(*Expr)(unsafe.Pointer(pExpr)).FaffExpr = (*Column)(unsafe.Pointer(pCol)).Faffinity
__12:
	;
	Xsqlite3ColumnSetExpr(tls, pParse, pTab, pCol, pExpr)
	pExpr = uintptr(0)
	goto generated_done

generated_error:
	Xsqlite3ErrorMsg(tls, pParse, ts+16164,
		libc.VaList(bp, (*Column)(unsafe.Pointer(pCol)).FzCnName))
generated_done:
	Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
}

func Xsqlite3ChangeCookie(tls *libc.TLS, pParse uintptr, iDb int32) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	Xsqlite3VdbeAddOp3(tls, v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION,
		int32(uint32(1)+uint32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema)).Fschema_cookie)))
}

func identLength(tls *libc.TLS, z uintptr) int32 {
	var n int32
	n = 0
__1:
	if !(*(*uint8)(unsafe.Pointer(z)) != 0) {
		goto __3
	}
	{
		if int32(*(*uint8)(unsafe.Pointer(z))) == '"' {
			n++
		}

	}
	goto __2
__2:
	n++
	z++
	goto __1
	goto __3
__3:
	;
	return n + 2
}

func identPut(tls *libc.TLS, z uintptr, pIdx uintptr, zSignedIdent uintptr) {
	var zIdent uintptr = zSignedIdent
	var i int32
	var j int32
	var needQuote int32
	i = *(*int32)(unsafe.Pointer(pIdx))

	for j = 0; *(*uint8)(unsafe.Pointer(zIdent + uintptr(j))) != 0; j++ {
		if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))])&0x06 != 0) && int32(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))) != '_' {
			break
		}
	}
	needQuote = libc.Bool32(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zIdent))])&0x04 != 0 ||
		Xsqlite3KeywordCode(tls, zIdent, j) != TK_ID ||
		int32(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))) != 0 ||
		j == 0)

	if needQuote != 0 {
		*(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('"')
	}
	for j = 0; *(*uint8)(unsafe.Pointer(zIdent + uintptr(j))) != 0; j++ {
		*(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&i, 1)))) = *(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))
		if int32(*(*uint8)(unsafe.Pointer(zIdent + uintptr(j)))) == '"' {
			*(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('"')
		}
	}
	if needQuote != 0 {
		*(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('"')
	}
	*(*uint8)(unsafe.Pointer(z + uintptr(i))) = uint8(0)
	*(*int32)(unsafe.Pointer(pIdx)) = i
}

func createTableStmt(tls *libc.TLS, db uintptr, p uintptr) uintptr {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var i int32

	var n int32
	var zStmt uintptr
	var zSep uintptr
	var zSep2 uintptr
	var zEnd uintptr
	var pCol uintptr
	n = 0
	pCol = (*Table)(unsafe.Pointer(p)).FaCol
	i = 0
__1:
	if !(i < int32((*Table)(unsafe.Pointer(p)).FnCol)) {
		goto __3
	}
	{
		n = n + (identLength(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName) + 5)

	}
	goto __2
__2:
	i++
	pCol += 24
	goto __1
	goto __3
__3:
	;
	n = n + identLength(tls, (*Table)(unsafe.Pointer(p)).FzName)
	if n < 50 {
		zSep = ts + 1636
		zSep2 = ts + 16195
		zEnd = ts + 7885
	} else {
		zSep = ts + 16197
		zSep2 = ts + 16201
		zEnd = ts + 16206
	}
	n = n + (35 + 6*int32((*Table)(unsafe.Pointer(p)).FnCol))
	zStmt = Xsqlite3DbMallocRaw(tls, uintptr(0), uint64(n))
	if zStmt == uintptr(0) {
		Xsqlite3OomFault(tls, db)
		return uintptr(0)
	}
	Xsqlite3_snprintf(tls, n, zStmt, ts+16209, 0)
	*(*int32)(unsafe.Pointer(bp + 8)) = Xsqlite3Strlen30(tls, zStmt)
	identPut(tls, zStmt, bp+8, (*Table)(unsafe.Pointer(p)).FzName)
	*(*uint8)(unsafe.Pointer(zStmt + uintptr(libc.PostIncInt32(&*(*int32)(unsafe.Pointer(bp + 8)), 1)))) = uint8('(')
	pCol = (*Table)(unsafe.Pointer(p)).FaCol
	i = 0
__4:
	if !(i < int32((*Table)(unsafe.Pointer(p)).FnCol)) {
		goto __6
	}
	{
		var len int32
		var zType uintptr

		Xsqlite3_snprintf(tls, n-*(*int32)(unsafe.Pointer(bp + 8)), zStmt+uintptr(*(*int32)(unsafe.Pointer(bp + 8))), zSep, 0)
		*(*int32)(unsafe.Pointer(bp + 8)) += Xsqlite3Strlen30(tls, zStmt+uintptr(*(*int32)(unsafe.Pointer(bp + 8))))
		zSep = zSep2
		identPut(tls, zStmt, bp+8, (*Column)(unsafe.Pointer(pCol)).FzCnName)

		zType = azType1[int32((*Column)(unsafe.Pointer(pCol)).Faffinity)-SQLITE_AFF_BLOB]
		len = Xsqlite3Strlen30(tls, zType)

		libc.Xmemcpy(tls, zStmt+uintptr(*(*int32)(unsafe.Pointer(bp + 8))), zType, uint64(len))
		*(*int32)(unsafe.Pointer(bp + 8)) += len

	}
	goto __5
__5:
	i++
	pCol += 24
	goto __4
	goto __6
__6:
	;
	Xsqlite3_snprintf(tls, n-*(*int32)(unsafe.Pointer(bp + 8)), zStmt+uintptr(*(*int32)(unsafe.Pointer(bp + 8))), ts+1684, libc.VaList(bp, zEnd))
	return zStmt
}

var azType1 = [6]uintptr{
	ts + 1636,
	ts + 16223,
	ts + 16229,
	ts + 16234,
	ts + 16239,
	ts + 16229,
}

func resizeIndexObject(tls *libc.TLS, db uintptr, pIdx uintptr, N int32) int32 {
	var zExtra uintptr
	var nByte int32
	if int32((*Index)(unsafe.Pointer(pIdx)).FnColumn) >= N {
		return SQLITE_OK
	}

	nByte = int32((uint64(unsafe.Sizeof(uintptr(0))) + uint64(unsafe.Sizeof(LogEst(0))) + uint64(unsafe.Sizeof(I16(0))) + uint64(1)) * uint64(N))
	zExtra = Xsqlite3DbMallocZero(tls, db, uint64(nByte))
	if zExtra == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemcpy(tls, zExtra, (*Index)(unsafe.Pointer(pIdx)).FazColl, uint64(unsafe.Sizeof(uintptr(0)))*uint64((*Index)(unsafe.Pointer(pIdx)).FnColumn))
	(*Index)(unsafe.Pointer(pIdx)).FazColl = zExtra
	zExtra += uintptr(uint64(unsafe.Sizeof(uintptr(0))) * uint64(N))
	libc.Xmemcpy(tls, zExtra, (*Index)(unsafe.Pointer(pIdx)).FaiRowLogEst, uint64(unsafe.Sizeof(LogEst(0)))*uint64(int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)+1))
	(*Index)(unsafe.Pointer(pIdx)).FaiRowLogEst = zExtra
	zExtra += uintptr(uint64(unsafe.Sizeof(LogEst(0))) * uint64(N))
	libc.Xmemcpy(tls, zExtra, (*Index)(unsafe.Pointer(pIdx)).FaiColumn, uint64(unsafe.Sizeof(I16(0)))*uint64((*Index)(unsafe.Pointer(pIdx)).FnColumn))
	(*Index)(unsafe.Pointer(pIdx)).FaiColumn = zExtra
	zExtra += uintptr(uint64(unsafe.Sizeof(I16(0))) * uint64(N))
	libc.Xmemcpy(tls, zExtra, (*Index)(unsafe.Pointer(pIdx)).FaSortOrder, uint64((*Index)(unsafe.Pointer(pIdx)).FnColumn))
	(*Index)(unsafe.Pointer(pIdx)).FaSortOrder = zExtra
	(*Index)(unsafe.Pointer(pIdx)).FnColumn = U16(N)
	libc.SetBitFieldPtr16Uint32(pIdx+100, uint32(1), 4, 0x10)
	return SQLITE_OK
}

func estimateTableWidth(tls *libc.TLS, pTab uintptr) {
	var wTable uint32 = uint32(0)
	var pTabCol uintptr
	var i int32
	i = int32((*Table)(unsafe.Pointer(pTab)).FnCol)
	pTabCol = (*Table)(unsafe.Pointer(pTab)).FaCol
__1:
	if !(i > 0) {
		goto __3
	}
	{
		wTable = wTable + uint32((*Column)(unsafe.Pointer(pTabCol)).FszEst)

	}
	goto __2
__2:
	i--
	pTabCol += 24
	goto __1
	goto __3
__3:
	;
	if int32((*Table)(unsafe.Pointer(pTab)).FiPKey) < 0 {
		wTable++
	}
	(*Table)(unsafe.Pointer(pTab)).FszTabRow = Xsqlite3LogEst(tls, uint64(wTable*uint32(4)))
}

func estimateIndexWidth(tls *libc.TLS, pIdx uintptr) {
	var wIndex uint32 = uint32(0)
	var i int32
	var aCol uintptr = (*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FaCol
	for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn); i++ {
		var x I16 = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))

		wIndex = wIndex + func() uint32 {
			if int32(x) < 0 {
				return uint32(1)
			}
			return uint32((*Column)(unsafe.Pointer(aCol + uintptr(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))*24)).FszEst)
		}()
	}
	(*Index)(unsafe.Pointer(pIdx)).FszIdxRow = Xsqlite3LogEst(tls, uint64(wIndex*uint32(4)))
}

func hasColumn(tls *libc.TLS, aiCol uintptr, nCol int32, x int32) int32 {
	for libc.PostDecInt32(&nCol, 1) > 0 {
		if x == int32(*(*I16)(unsafe.Pointer(libc.PostIncUintptr(&aiCol, 2)))) {
			return 1
		}
	}
	return 0
}

func isDupColumn(tls *libc.TLS, pIdx uintptr, nKey int32, pPk uintptr, iCol int32) int32 {
	var i int32
	var j int32

	j = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(iCol)*2)))

	for i = 0; i < nKey; i++ {
		if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) == j &&
			Xsqlite3StrICmp(tls, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*8)), *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FazColl + uintptr(iCol)*8))) == 0 {
			return 1
		}
	}
	return 0
}

func recomputeColumnsNotIndexed(tls *libc.TLS, pIdx uintptr) {
	var m Bitmask = uint64(0)
	var j int32
	var pTab uintptr = (*Index)(unsafe.Pointer(pIdx)).FpTable
	for j = int32((*Index)(unsafe.Pointer(pIdx)).FnColumn) - 1; j >= 0; j-- {
		var x int32 = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)))
		if x >= 0 && int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(x)*24)).FcolFlags)&COLFLAG_VIRTUAL == 0 {
			if x < int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1 {
				m = m | uint64(1)<<x
			}
		}
	}
	(*Index)(unsafe.Pointer(pIdx)).FcolNotIdxed = ^m

}

func convertToWithoutRowidTable(tls *libc.TLS, pParse uintptr, pTab uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pIdx uintptr
	var pPk uintptr
	var nPk int32
	var nExtra int32
	var i int32
	var j int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	if !(int32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x2>>1) != 0) {
		for i = 0; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
			if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_PRIMKEY != 0 &&
				int32(*(*uint8)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*24 + 8))&0xf>>0) == OE_None {
				libc.SetBitFieldPtr8Uint32((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24+8, uint32(OE_Abort), 0, 0xf)
			}
		}
		*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_HasNotNull)
	}

	if *(*int32)(unsafe.Pointer(pParse + 200)) != 0 {
		Xsqlite3VdbeChangeP3(tls, v, *(*int32)(unsafe.Pointer(pParse + 200)), BTREE_BLOBKEY)
	}

	if int32((*Table)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
		var pList uintptr

		Xsqlite3TokenInit(tls, bp, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr((*Table)(unsafe.Pointer(pTab)).FiPKey)*24)).FzCnName)
		pList = Xsqlite3ExprListAppend(tls, pParse, uintptr(0),
			Xsqlite3ExprAlloc(tls, db, TK_ID, bp, 0))
		if pList == uintptr(0) {
			*(*U32)(unsafe.Pointer(pTab + 48)) &= libc.Uint32FromInt32(libc.CplInt32(TF_WithoutRowid))
			return
		}
		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			Xsqlite3RenameTokenRemap(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8)).FpExpr, pTab+52)
		}
		(*ExprList_item)(unsafe.Pointer(pList + 8)).Ffg.FsortFlags = (*Parse)(unsafe.Pointer(pParse)).FiPkSortOrder

		(*Table)(unsafe.Pointer(pTab)).FiPKey = int16(-1)
		Xsqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), pList, int32((*Table)(unsafe.Pointer(pTab)).FkeyConf), uintptr(0), uintptr(0), 0, 0,
			uint8(SQLITE_IDXTYPE_PRIMARYKEY))
		if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
			*(*U32)(unsafe.Pointer(pTab + 48)) &= libc.Uint32FromInt32(libc.CplInt32(TF_WithoutRowid))
			return
		}

		pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)

	} else {
		pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)

		for i = libc.AssignInt32(&j, 1); i < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol); i++ {
			if isDupColumn(tls, pPk, j, pPk, i) != 0 {
				(*Index)(unsafe.Pointer(pPk)).FnColumn--
			} else {
				*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*8)) = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*8))
				*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(j))) = *(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(i)))
				*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(libc.PostIncInt32(&j, 1))*2)) = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))
			}
		}
		(*Index)(unsafe.Pointer(pPk)).FnKeyCol = U16(j)
	}

	libc.SetBitFieldPtr16Uint32(pPk+100, uint32(1), 5, 0x20)
	if !(int32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x2>>1) != 0) {
		libc.SetBitFieldPtr16Uint32(pPk+100, uint32(1), 3, 0x8)
	}
	nPk = int32(libc.AssignPtrUint16(pPk+96, (*Index)(unsafe.Pointer(pPk)).FnKeyCol))

	if v != 0 && (*Index)(unsafe.Pointer(pPk)).Ftnum > Pgno(0) {
		Xsqlite3VdbeChangeOpcode(tls, v, int32((*Index)(unsafe.Pointer(pPk)).Ftnum), uint8(OP_Goto))
	}

	(*Index)(unsafe.Pointer(pPk)).Ftnum = (*Table)(unsafe.Pointer(pTab)).Ftnum

	for pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
		var n int32
		if int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
			continue
		}
		for i = libc.AssignInt32(&n, 0); i < nPk; i++ {
			if !(isDupColumn(tls, pIdx, int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol), pPk, i) != 0) {
				n++
			}
		}
		if n == 0 {
			(*Index)(unsafe.Pointer(pIdx)).FnColumn = (*Index)(unsafe.Pointer(pIdx)).FnKeyCol
			continue
		}
		if resizeIndexObject(tls, db, pIdx, int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)+n) != 0 {
			return
		}
		i = 0
		j = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
		for ; i < nPk; i++ {
			if !(isDupColumn(tls, pIdx, int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol), pPk, i) != 0) {
				*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)) = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))
				*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*8)) = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*8))
				if *(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(i))) != 0 {
					libc.SetBitFieldPtr16Uint32(pIdx+100, uint32(1), 9, 0x200)
				}
				j++
			}
		}

	}

	nExtra = 0
	for i = 0; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
		if !(hasColumn(tls, (*Index)(unsafe.Pointer(pPk)).FaiColumn, nPk, i) != 0) &&
			int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL == 0 {
			nExtra++
		}
	}
	if resizeIndexObject(tls, db, pPk, nPk+nExtra) != 0 {
		return
	}
	i = 0
	j = nPk
	for ; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
		if !(hasColumn(tls, (*Index)(unsafe.Pointer(pPk)).FaiColumn, j, i) != 0) &&
			int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL == 0 {
			*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2)) = I16(i)
			*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*8)) = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
			j++
		}
	}

	recomputeColumnsNotIndexed(tls, pPk)
}

func Xsqlite3IsShadowTableOf(tls *libc.TLS, db uintptr, pTab uintptr, zName uintptr) int32 {
	var nName int32
	var pMod uintptr

	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		return 0
	}
	nName = Xsqlite3Strlen30(tls, (*Table)(unsafe.Pointer(pTab)).FzName)
	if Xsqlite3_strnicmp(tls, zName, (*Table)(unsafe.Pointer(pTab)).FzName, nName) != 0 {
		return 0
	}
	if int32(*(*uint8)(unsafe.Pointer(zName + uintptr(nName)))) != '_' {
		return 0
	}
	pMod = Xsqlite3HashFind(tls, db+576, *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 8)))))
	if pMod == uintptr(0) {
		return 0
	}
	if (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FiVersion < 3 {
		return 0
	}
	if (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FxShadowName == uintptr(0) {
		return 0
	}
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FxShadowName})).f(tls, zName+uintptr(nName)+uintptr(1))
}

func Xsqlite3MarkAllShadowTablesOf(tls *libc.TLS, db uintptr, pTab uintptr) {
	var nName int32
	var pMod uintptr
	var k uintptr

	pMod = Xsqlite3HashFind(tls, db+576, *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 8)))))
	if pMod == uintptr(0) {
		return
	}
	if (*Module)(unsafe.Pointer(pMod)).FpModule == uintptr(0) {
		return
	}
	if (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FiVersion < 3 {
		return
	}
	if (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FxShadowName == uintptr(0) {
		return
	}

	nName = Xsqlite3Strlen30(tls, (*Table)(unsafe.Pointer(pTab)).FzName)
	for k = (*Hash)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FpSchema + 8)).Ffirst; k != 0; k = (*HashElem)(unsafe.Pointer(k)).Fnext {
		var pOther uintptr = (*HashElem)(unsafe.Pointer(k)).Fdata

		if !(int32((*Table)(unsafe.Pointer(pOther)).FeTabType) == TABTYP_NORM) {
			continue
		}
		if (*Table)(unsafe.Pointer(pOther)).FtabFlags&U32(TF_Shadow) != 0 {
			continue
		}
		if Xsqlite3_strnicmp(tls, (*Table)(unsafe.Pointer(pOther)).FzName, (*Table)(unsafe.Pointer(pTab)).FzName, nName) == 0 &&
			int32(*(*uint8)(unsafe.Pointer((*Table)(unsafe.Pointer(pOther)).FzName + uintptr(nName)))) == '_' &&
			(*struct {
				f func(*libc.TLS, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FxShadowName})).f(tls, (*Table)(unsafe.Pointer(pOther)).FzName+uintptr(nName)+uintptr(1)) != 0 {
			*(*U32)(unsafe.Pointer(pOther + 48)) |= U32(TF_Shadow)
		}
	}
}

func Xsqlite3ShadowTableName(tls *libc.TLS, db uintptr, zName uintptr) int32 {
	var zTail uintptr
	var pTab uintptr
	zTail = libc.Xstrrchr(tls, zName, '_')
	if zTail == uintptr(0) {
		return 0
	}
	*(*uint8)(unsafe.Pointer(zTail)) = uint8(0)
	pTab = Xsqlite3FindTable(tls, db, zName, uintptr(0))
	*(*uint8)(unsafe.Pointer(zTail)) = uint8('_')
	if pTab == uintptr(0) {
		return 0
	}
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		return 0
	}
	return Xsqlite3IsShadowTableOf(tls, db, pTab, zName)
}

func Xsqlite3EndTable(tls *libc.TLS, pParse uintptr, pCons uintptr, pEnd uintptr, tabOpts U32, pSelect uintptr) {
	bp := tls.Alloc(184)
	defer tls.Free(184)

	var p uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var iDb int32
	var pIdx uintptr

	if pEnd == uintptr(0) && pSelect == uintptr(0) {
		return
	}
	p = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	if p == uintptr(0) {
		return
	}

	if pSelect == uintptr(0) && Xsqlite3ShadowTableName(tls, db, (*Table)(unsafe.Pointer(p)).FzName) != 0 {
		*(*U32)(unsafe.Pointer(p + 48)) |= U32(TF_Shadow)
	}

	if (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 {
		if pSelect != 0 || !(int32((*Table)(unsafe.Pointer(p)).FeTabType) == TABTYP_NORM) && (*Sqlite3)(unsafe.Pointer(db)).Finit.FnewTnum != 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+1636, 0)
			return
		}
		(*Table)(unsafe.Pointer(p)).Ftnum = (*Sqlite3)(unsafe.Pointer(db)).Finit.FnewTnum
		if (*Table)(unsafe.Pointer(p)).Ftnum == Pgno(1) {
			*(*U32)(unsafe.Pointer(p + 48)) |= U32(TF_Readonly)
		}
	}

	if tabOpts&U32(TF_Strict) != 0 {
		var ii int32
		*(*U32)(unsafe.Pointer(p + 48)) |= U32(TF_Strict)
		for ii = 0; ii < int32((*Table)(unsafe.Pointer(p)).FnCol); ii++ {
			var pCol uintptr = (*Table)(unsafe.Pointer(p)).FaCol + uintptr(ii)*24
			if int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4) == COLTYPE_CUSTOM {
				if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_HASTYPE != 0 {
					Xsqlite3ErrorMsg(tls, pParse,
						ts+16245,
						libc.VaList(bp, (*Table)(unsafe.Pointer(p)).FzName, (*Column)(unsafe.Pointer(pCol)).FzCnName, Xsqlite3ColumnType(tls, pCol, ts+1636)))
				} else {
					Xsqlite3ErrorMsg(tls, pParse, ts+16278,
						libc.VaList(bp+24, (*Table)(unsafe.Pointer(p)).FzName, (*Column)(unsafe.Pointer(pCol)).FzCnName))
				}
				return
			} else if int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf0>>4) == COLTYPE_ANY {
				(*Column)(unsafe.Pointer(pCol)).Faffinity = uint8(SQLITE_AFF_BLOB)
			}
			if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_PRIMKEY != 0 &&
				int32((*Table)(unsafe.Pointer(p)).FiPKey) != ii &&
				int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0) == OE_None {
				libc.SetBitFieldPtr8Uint32(pCol+8, uint32(OE_Abort), 0, 0xf)
				*(*U32)(unsafe.Pointer(p + 48)) |= U32(TF_HasNotNull)
			}
		}
	}

	if tabOpts&U32(TF_WithoutRowid) != 0 {
		if (*Table)(unsafe.Pointer(p)).FtabFlags&U32(TF_Autoincrement) != 0 {
			Xsqlite3ErrorMsg(tls, pParse,
				ts+16305, 0)
			return
		}
		if (*Table)(unsafe.Pointer(p)).FtabFlags&U32(TF_HasPrimaryKey) == U32(0) {
			Xsqlite3ErrorMsg(tls, pParse, ts+16355, libc.VaList(bp+40, (*Table)(unsafe.Pointer(p)).FzName))
			return
		}
		*(*U32)(unsafe.Pointer(p + 48)) |= U32(TF_WithoutRowid | TF_NoVisibleRowid)
		convertToWithoutRowidTable(tls, pParse, p)
	}
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(p)).FpSchema)

	if (*Table)(unsafe.Pointer(p)).FpCheck != 0 {
		Xsqlite3ResolveSelfReference(tls, pParse, p, NC_IsCheck, uintptr(0), (*Table)(unsafe.Pointer(p)).FpCheck)
		if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
			Xsqlite3ExprListDelete(tls, db, (*Table)(unsafe.Pointer(p)).FpCheck)
			(*Table)(unsafe.Pointer(p)).FpCheck = uintptr(0)
		} else {
		}
	}
	if (*Table)(unsafe.Pointer(p)).FtabFlags&U32(TF_HasGenerated) != 0 {
		var ii int32
		var nNG int32 = 0

		for ii = 0; ii < int32((*Table)(unsafe.Pointer(p)).FnCol); ii++ {
			var colFlags U32 = U32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(p)).FaCol + uintptr(ii)*24)).FcolFlags)
			if colFlags&U32(COLFLAG_GENERATED) != U32(0) {
				var pX uintptr = Xsqlite3ColumnExpr(tls, p, (*Table)(unsafe.Pointer(p)).FaCol+uintptr(ii)*24)

				if Xsqlite3ResolveSelfReference(tls, pParse, p, NC_GenCol, pX, uintptr(0)) != 0 {
					Xsqlite3ColumnSetExpr(tls, pParse, p, (*Table)(unsafe.Pointer(p)).FaCol+uintptr(ii)*24,
						Xsqlite3ExprAlloc(tls, db, TK_NULL, uintptr(0), 0))
				}
			} else {
				nNG++
			}
		}
		if nNG == 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+16387, 0)
			return
		}
	}

	estimateTableWidth(tls, p)
	for pIdx = (*Table)(unsafe.Pointer(p)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
		estimateIndexWidth(tls, pIdx)
	}

	if !(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) {
		var n int32
		var v uintptr
		var zType uintptr
		var zType2 uintptr
		var zStmt uintptr

		v = Xsqlite3GetVdbe(tls, pParse)
		if v == uintptr(0) {
			return
		}

		Xsqlite3VdbeAddOp1(tls, v, OP_Close, 0)

		if int32((*Table)(unsafe.Pointer(p)).FeTabType) == TABTYP_NORM {
			zType = ts + 9499
			zType2 = ts + 16431
		} else {
			zType = ts + 13875
			zType2 = ts + 16437
		}

		if pSelect != 0 {
			var regYield int32
			var addrTop int32
			var regRec int32
			var regRowid int32
			var addrInsLoop int32
			var pSelTab uintptr

			if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL {
				(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_ERROR
				(*Parse)(unsafe.Pointer(pParse)).FnErr++
				return
			}
			regYield = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
			regRec = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
			regRowid = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)

			Xsqlite3MayAbort(tls, pParse)
			Xsqlite3VdbeAddOp3(tls, v, OP_OpenWrite, 1, (*Parse)(unsafe.Pointer(pParse)).FregRoot, iDb)
			Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_P2ISREG))
			(*Parse)(unsafe.Pointer(pParse)).FnTab = 2
			addrTop = Xsqlite3VdbeCurrentAddr(tls, v) + 1
			Xsqlite3VdbeAddOp3(tls, v, OP_InitCoroutine, regYield, 0, addrTop)
			if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
				return
			}
			pSelTab = Xsqlite3ResultSetOfSelect(tls, pParse, pSelect, uint8(SQLITE_AFF_BLOB))
			if pSelTab == uintptr(0) {
				return
			}

			(*Table)(unsafe.Pointer(p)).FnCol = libc.AssignPtrInt16(p+56, (*Table)(unsafe.Pointer(pSelTab)).FnCol)
			(*Table)(unsafe.Pointer(p)).FaCol = (*Table)(unsafe.Pointer(pSelTab)).FaCol
			(*Table)(unsafe.Pointer(pSelTab)).FnCol = int16(0)
			(*Table)(unsafe.Pointer(pSelTab)).FaCol = uintptr(0)
			Xsqlite3DeleteTable(tls, db, pSelTab)
			Xsqlite3SelectDestInit(tls, bp+144, SRT_Coroutine, regYield)
			Xsqlite3Select(tls, pParse, pSelect, bp+144)
			if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
				return
			}
			Xsqlite3VdbeEndCoroutine(tls, v, regYield)
			Xsqlite3VdbeJumpHere(tls, v, addrTop-1)
			addrInsLoop = Xsqlite3VdbeAddOp1(tls, v, OP_Yield, (*SelectDest)(unsafe.Pointer(bp+144)).FiSDParm)

			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, (*SelectDest)(unsafe.Pointer(bp+144)).FiSdst, (*SelectDest)(unsafe.Pointer(bp+144)).FnSdst, regRec)
			Xsqlite3TableAffinity(tls, v, p, 0)
			Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, 1, regRowid)
			Xsqlite3VdbeAddOp3(tls, v, OP_Insert, 1, regRec, regRowid)
			Xsqlite3VdbeGoto(tls, v, addrInsLoop)
			Xsqlite3VdbeJumpHere(tls, v, addrInsLoop)
			Xsqlite3VdbeAddOp1(tls, v, OP_Close, 1)
		}

		if pSelect != 0 {
			zStmt = createTableStmt(tls, db, p)
		} else {
			var pEnd2 uintptr
			if tabOpts != 0 {
				pEnd2 = pParse + 288
			} else {
				pEnd2 = pEnd
			}
			n = int32((int64((*Token)(unsafe.Pointer(pEnd2)).Fz) - int64((*Parse)(unsafe.Pointer(pParse)).FsNameToken.Fz)) / 1)
			if int32(*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(pEnd2)).Fz))) != ';' {
				n = int32(uint32(n) + (*Token)(unsafe.Pointer(pEnd2)).Fn)
			}
			zStmt = Xsqlite3MPrintf(tls, db,
				ts+16442, libc.VaList(bp+48, zType2, n, (*Parse)(unsafe.Pointer(pParse)).FsNameToken.Fz))
		}

		Xsqlite3NestedParse(tls, pParse,
			ts+16457,
			libc.VaList(bp+72, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName,
				zType,
				(*Table)(unsafe.Pointer(p)).FzName,
				(*Table)(unsafe.Pointer(p)).FzName,
				(*Parse)(unsafe.Pointer(pParse)).FregRoot,
				zStmt,
				(*Parse)(unsafe.Pointer(pParse)).FregRowid))
		Xsqlite3DbFree(tls, db, zStmt)
		Xsqlite3ChangeCookie(tls, pParse, iDb)

		if (*Table)(unsafe.Pointer(p)).FtabFlags&U32(TF_Autoincrement) != U32(0) && !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL) {
			var pDb uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32

			if (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab == uintptr(0) {
				Xsqlite3NestedParse(tls, pParse,
					ts+16555,
					libc.VaList(bp+128, (*Db)(unsafe.Pointer(pDb)).FzDbSName))
			}
		}

		Xsqlite3VdbeAddParseSchemaOp(tls, v, iDb,
			Xsqlite3MPrintf(tls, db, ts+16597, libc.VaList(bp+136, (*Table)(unsafe.Pointer(p)).FzName)), uint16(0))
	}

	if (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 {
		var pOld uintptr
		var pSchema uintptr = (*Table)(unsafe.Pointer(p)).FpSchema

		pOld = Xsqlite3HashInsert(tls, pSchema+8, (*Table)(unsafe.Pointer(p)).FzName, p)
		if pOld != 0 {
			Xsqlite3OomFault(tls, db)
			return
		}
		(*Parse)(unsafe.Pointer(pParse)).FpNewTable = uintptr(0)
		*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaChange)

		if libc.Xstrcmp(tls, (*Table)(unsafe.Pointer(p)).FzName, ts+12782) == 0 {
			(*Schema)(unsafe.Pointer((*Table)(unsafe.Pointer(p)).FpSchema)).FpSeqTab = p
		}
	}

	if !(pSelect != 0) && int32((*Table)(unsafe.Pointer(p)).FeTabType) == TABTYP_NORM {
		if (*Token)(unsafe.Pointer(pCons)).Fz == uintptr(0) {
			pCons = pEnd
		}
		*(*int32)(unsafe.Pointer(p + 64)) = 13 + int32((int64((*Token)(unsafe.Pointer(pCons)).Fz)-int64((*Parse)(unsafe.Pointer(pParse)).FsNameToken.Fz))/1)
	}
}

func Xsqlite3CreateView(tls *libc.TLS, pParse uintptr, pBegin uintptr, pName1 uintptr, pName2 uintptr, pCNames uintptr, pSelect uintptr, isTemp int32, noErr int32) {
	bp := tls.Alloc(120)
	defer tls.Free(120)

	var p uintptr
	var n int32
	var z uintptr

	var iDb int32
	var db uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !(int32((*Parse)(unsafe.Pointer(pParse)).FnVar) > 0) {
		goto __1
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+16631, 0)
	goto create_view_fail
__1:
	;
	Xsqlite3StartTable(tls, pParse, pName1, pName2, isTemp, 1, 0, noErr)
	p = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	if !(p == uintptr(0) || (*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __2
	}
	goto create_view_fail
__2:
	;
	*(*U32)(unsafe.Pointer(p + 48)) |= U32(TF_NoVisibleRowid)

	Xsqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(p)).FpSchema)
	Xsqlite3FixInit(tls, bp+8, pParse, iDb, ts+13875, *(*uintptr)(unsafe.Pointer(bp)))
	if !(Xsqlite3FixSelect(tls, bp+8, pSelect) != 0) {
		goto __3
	}
	goto create_view_fail
__3:
	;
	*(*U32)(unsafe.Pointer(pSelect + 4)) |= U32(SF_View)
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __4
	}
	*(*uintptr)(unsafe.Pointer(p + 64)) = pSelect
	pSelect = uintptr(0)
	goto __5
__4:
	*(*uintptr)(unsafe.Pointer(p + 64)) = Xsqlite3SelectDup(tls, db, pSelect, EXPRDUP_REDUCE)
__5:
	;
	(*Table)(unsafe.Pointer(p)).FpCheck = Xsqlite3ExprListDup(tls, db, pCNames, EXPRDUP_REDUCE)
	(*Table)(unsafe.Pointer(p)).FeTabType = U8(TABTYP_VIEW)
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __6
	}
	goto create_view_fail
__6:
	;
	*(*Token)(unsafe.Pointer(bp + 104)) = (*Parse)(unsafe.Pointer(pParse)).FsLastToken

	if !(int32(*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(bp + 104)).Fz))) != ';') {
		goto __7
	}
	*(*uintptr)(unsafe.Pointer(bp + 104)) += uintptr((*Token)(unsafe.Pointer(bp + 104)).Fn)
__7:
	;
	(*Token)(unsafe.Pointer(bp + 104)).Fn = uint32(0)
	n = int32((int64((*Token)(unsafe.Pointer(bp+104)).Fz) - int64((*Token)(unsafe.Pointer(pBegin)).Fz)) / 1)

	z = (*Token)(unsafe.Pointer(pBegin)).Fz
__8:
	if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(n-1)))])&0x01 != 0) {
		goto __9
	}
	n--
	goto __8
__9:
	;
	(*Token)(unsafe.Pointer(bp + 104)).Fz = z + uintptr(n-1)
	(*Token)(unsafe.Pointer(bp + 104)).Fn = uint32(1)

	Xsqlite3EndTable(tls, pParse, uintptr(0), bp+104, uint32(0), uintptr(0))

create_view_fail:
	Xsqlite3SelectDelete(tls, db, pSelect)
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __10
	}
	Xsqlite3RenameExprlistUnmap(tls, pParse, pCNames)
__10:
	;
	Xsqlite3ExprListDelete(tls, db, pCNames)
	return
}

func viewGetColumnNames(tls *libc.TLS, pParse uintptr, pTable uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pSelTab uintptr
	var pSel uintptr
	var nErr int32 = 0
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var rc int32
	var xAuth Sqlite3_xauth

	if int32((*Table)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_VTAB {
		(*Sqlite3)(unsafe.Pointer(db)).FnSchemaLock++
		rc = Xsqlite3VtabCallConnect(tls, pParse, pTable)
		(*Sqlite3)(unsafe.Pointer(db)).FnSchemaLock--
		return rc
	}

	if int32((*Table)(unsafe.Pointer(pTable)).FnCol) < 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+16667, libc.VaList(bp, (*Table)(unsafe.Pointer(pTable)).FzName))
		return 1
	}

	pSel = Xsqlite3SelectDup(tls, db, *(*uintptr)(unsafe.Pointer(pTable + 64)), 0)
	if pSel != 0 {
		var eParseMode U8 = (*Parse)(unsafe.Pointer(pParse)).FeParseMode
		var nTab int32 = (*Parse)(unsafe.Pointer(pParse)).FnTab
		var nSelect int32 = (*Parse)(unsafe.Pointer(pParse)).FnSelect
		(*Parse)(unsafe.Pointer(pParse)).FeParseMode = U8(PARSE_MODE_NORMAL)
		Xsqlite3SrcListAssignCursors(tls, pParse, (*Select)(unsafe.Pointer(pSel)).FpSrc)
		(*Table)(unsafe.Pointer(pTable)).FnCol = int16(-1)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)
		xAuth = (*Sqlite3)(unsafe.Pointer(db)).FxAuth
		(*Sqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
		pSelTab = Xsqlite3ResultSetOfSelect(tls, pParse, pSel, uint8(SQLITE_AFF_NONE))
		(*Sqlite3)(unsafe.Pointer(db)).FxAuth = xAuth
		(*Parse)(unsafe.Pointer(pParse)).FnTab = nTab
		(*Parse)(unsafe.Pointer(pParse)).FnSelect = nSelect
		if pSelTab == uintptr(0) {
			(*Table)(unsafe.Pointer(pTable)).FnCol = int16(0)
			nErr++
		} else if (*Table)(unsafe.Pointer(pTable)).FpCheck != 0 {
			Xsqlite3ColumnsFromExprList(tls, pParse, (*Table)(unsafe.Pointer(pTable)).FpCheck,
				pTable+54, pTable+8)
			if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 &&
				int32((*Table)(unsafe.Pointer(pTable)).FnCol) == (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSel)).FpEList)).FnExpr {
				Xsqlite3SubqueryColumnTypes(tls, pParse, pTable, pSel, uint8(SQLITE_AFF_NONE))
			}
		} else {
			(*Table)(unsafe.Pointer(pTable)).FnCol = (*Table)(unsafe.Pointer(pSelTab)).FnCol
			(*Table)(unsafe.Pointer(pTable)).FaCol = (*Table)(unsafe.Pointer(pSelTab)).FaCol
			*(*U32)(unsafe.Pointer(pTable + 48)) |= (*Table)(unsafe.Pointer(pSelTab)).FtabFlags & U32(COLFLAG_NOINSERT)
			(*Table)(unsafe.Pointer(pSelTab)).FnCol = int16(0)
			(*Table)(unsafe.Pointer(pSelTab)).FaCol = uintptr(0)

		}
		(*Table)(unsafe.Pointer(pTable)).FnNVCol = (*Table)(unsafe.Pointer(pTable)).FnCol
		Xsqlite3DeleteTable(tls, db, pSelTab)
		Xsqlite3SelectDelete(tls, db, pSel)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable--
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = func() uint16 {
			if (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
				return uint16(0)
			}
			return (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue
		}()
		(*Parse)(unsafe.Pointer(pParse)).FeParseMode = eParseMode
	} else {
		nErr++
	}
	*(*U16)(unsafe.Pointer((*Table)(unsafe.Pointer(pTable)).FpSchema + 114)) |= U16(DB_UnresetViews)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		Xsqlite3DeleteColumnNames(tls, db, pTable)
	}
	return nErr
}

func Xsqlite3ViewGetColumnNames(tls *libc.TLS, pParse uintptr, pTable uintptr) int32 {
	if !(int32((*Table)(unsafe.Pointer(pTable)).FeTabType) == TABTYP_VTAB) && int32((*Table)(unsafe.Pointer(pTable)).FnCol) > 0 {
		return 0
	}
	return viewGetColumnNames(tls, pParse, pTable)
}

func sqliteViewResetAll(tls *libc.TLS, db uintptr, idx int32) {
	var i uintptr

	if !(int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(idx)*32)).FpSchema)).FschemaFlags)&DB_UnresetViews == DB_UnresetViews) {
		return
	}
	for i = (*Hash)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(idx)*32)).FpSchema + 8)).Ffirst; i != 0; i = (*HashElem)(unsafe.Pointer(i)).Fnext {
		var pTab uintptr = (*HashElem)(unsafe.Pointer(i)).Fdata
		if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW {
			Xsqlite3DeleteColumnNames(tls, db, pTab)
		}
	}
	*(*U16)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(idx)*32)).FpSchema + 114)) &= libc.Uint16FromInt32(libc.CplInt32(DB_UnresetViews))
}

func Xsqlite3RootPageMoved(tls *libc.TLS, db uintptr, iDb int32, iFrom Pgno, iTo Pgno) {
	var pElem uintptr
	var pHash uintptr
	var pDb uintptr

	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	pHash = (*Db)(unsafe.Pointer(pDb)).FpSchema + 8
	for pElem = (*Hash)(unsafe.Pointer(pHash)).Ffirst; pElem != 0; pElem = (*HashElem)(unsafe.Pointer(pElem)).Fnext {
		var pTab uintptr = (*HashElem)(unsafe.Pointer(pElem)).Fdata
		if (*Table)(unsafe.Pointer(pTab)).Ftnum == iFrom {
			(*Table)(unsafe.Pointer(pTab)).Ftnum = iTo
		}
	}
	pHash = (*Db)(unsafe.Pointer(pDb)).FpSchema + 32
	for pElem = (*Hash)(unsafe.Pointer(pHash)).Ffirst; pElem != 0; pElem = (*HashElem)(unsafe.Pointer(pElem)).Fnext {
		var pIdx uintptr = (*HashElem)(unsafe.Pointer(pElem)).Fdata
		if (*Index)(unsafe.Pointer(pIdx)).Ftnum == iFrom {
			(*Index)(unsafe.Pointer(pIdx)).Ftnum = iTo
		}
	}
}

func destroyRootPage(tls *libc.TLS, pParse uintptr, iTable int32, iDb int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var r1 int32 = Xsqlite3GetTempReg(tls, pParse)
	if iTable < 2 {
		Xsqlite3ErrorMsg(tls, pParse, ts+16697, 0)
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Destroy, iTable, r1, iDb)
	Xsqlite3MayAbort(tls, pParse)

	Xsqlite3NestedParse(tls, pParse,
		ts+16712,
		libc.VaList(bp, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FaDb+uintptr(iDb)*32)).FzDbSName, iTable, r1, r1))
	Xsqlite3ReleaseTempReg(tls, pParse, r1)
}

func destroyTable(tls *libc.TLS, pParse uintptr, pTab uintptr) {
	var iTab Pgno = (*Table)(unsafe.Pointer(pTab)).Ftnum
	var iDestroyed Pgno = Pgno(0)

	for 1 != 0 {
		var pIdx uintptr
		var iLargest Pgno = Pgno(0)

		if iDestroyed == Pgno(0) || iTab < iDestroyed {
			iLargest = iTab
		}
		for pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
			var iIdx Pgno = (*Index)(unsafe.Pointer(pIdx)).Ftnum

			if (iDestroyed == Pgno(0) || iIdx < iDestroyed) && iIdx > iLargest {
				iLargest = iIdx
			}
		}
		if iLargest == Pgno(0) {
			return
		} else {
			var iDb int32 = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Table)(unsafe.Pointer(pTab)).FpSchema)

			destroyRootPage(tls, pParse, int32(iLargest), iDb)
			iDestroyed = iLargest
		}
	}
}

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 = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*32)).FzDbSName
	for i = 1; i <= 4; i++ {
		Xsqlite3_snprintf(tls, int32(unsafe.Sizeof([24]uint8{})), bp+40, ts+16779, libc.VaList(bp, i))
		if Xsqlite3FindTable(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, bp+40, zDbName) != 0 {
			Xsqlite3NestedParse(tls, pParse,
				ts+14684,
				libc.VaList(bp+8, zDbName, bp+40, zType, zName))
		}
	}
}

func Xsqlite3CodeDropTable(tls *libc.TLS, pParse uintptr, pTab uintptr, iDb int32, isView int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var v uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pTrigger uintptr
	var pDb uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32

	v = Xsqlite3GetVdbe(tls, pParse)

	Xsqlite3BeginWriteOperation(tls, pParse, 1, iDb)

	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
		Xsqlite3VdbeAddOp0(tls, v, OP_VBegin)
	}

	pTrigger = Xsqlite3TriggerList(tls, pParse, pTab)
	for pTrigger != 0 {
		Xsqlite3DropTriggerPtr(tls, pParse, pTrigger)
		pTrigger = (*Trigger)(unsafe.Pointer(pTrigger)).FpNext
	}

	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Autoincrement) != 0 {
		Xsqlite3NestedParse(tls, pParse,
			ts+16793,
			libc.VaList(bp, (*Db)(unsafe.Pointer(pDb)).FzDbSName, (*Table)(unsafe.Pointer(pTab)).FzName))
	}

	Xsqlite3NestedParse(tls, pParse,
		ts+16838,
		libc.VaList(bp+16, (*Db)(unsafe.Pointer(pDb)).FzDbSName, (*Table)(unsafe.Pointer(pTab)).FzName))
	if !(isView != 0) && !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		destroyTable(tls, pParse, pTab)
	}

	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
		Xsqlite3VdbeAddOp4(tls, v, OP_VDestroy, iDb, 0, 0, (*Table)(unsafe.Pointer(pTab)).FzName, 0)
		Xsqlite3MayAbort(tls, pParse)
	}
	Xsqlite3VdbeAddOp4(tls, v, OP_DropTable, iDb, 0, 0, (*Table)(unsafe.Pointer(pTab)).FzName, 0)
	Xsqlite3ChangeCookie(tls, pParse, iDb)
	sqliteViewResetAll(tls, db, iDb)
}

func Xsqlite3ReadOnlyShadowTables(tls *libc.TLS, db uintptr) int32 {
	if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) != uint64(0) &&
		(*Sqlite3)(unsafe.Pointer(db)).FpVtabCtx == uintptr(0) &&
		(*Sqlite3)(unsafe.Pointer(db)).FnVdbeExec == 0 &&
		!((*Sqlite3)(unsafe.Pointer(db)).FnVTrans > 0 && (*Sqlite3)(unsafe.Pointer(db)).FaVTrans == uintptr(0)) {
		return 1
	}
	return 0
}

func tableMayNotBeDropped(tls *libc.TLS, db uintptr, pTab uintptr) int32 {
	if Xsqlite3_strnicmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName, ts+9596, 7) == 0 {
		if Xsqlite3_strnicmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName+uintptr(7), ts+5648, 4) == 0 {
			return 0
		}
		if Xsqlite3_strnicmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName+uintptr(7), ts+10337, 10) == 0 {
			return 0
		}
		return 1
	}
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Shadow) != U32(0) && Xsqlite3ReadOnlyShadowTables(tls, db) != 0 {
		return 1
	}
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Eponymous) != 0 {
		return 1
	}
	return 0
}

func Xsqlite3DropTable(tls *libc.TLS, pParse uintptr, pName uintptr, isView int32, noErr int32) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pTab uintptr
	var v uintptr
	var db uintptr
	var iDb int32
	var code int32
	var zTab uintptr
	var zDb uintptr
	var zArg2 uintptr
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __1
	}
	goto exit_drop_table
__1:
	;
	if !(Xsqlite3ReadSchema(tls, pParse) != 0) {
		goto __2
	}
	goto exit_drop_table
__2:
	;
	if !(noErr != 0) {
		goto __3
	}
	(*Sqlite3)(unsafe.Pointer(db)).FsuppressErr++
__3:
	;
	pTab = Xsqlite3LocateTableItem(tls, pParse, uint32(isView), pName+8)
	if !(noErr != 0) {
		goto __4
	}
	(*Sqlite3)(unsafe.Pointer(db)).FsuppressErr--
__4:
	;
	if !(pTab == uintptr(0)) {
		goto __5
	}
	if !(noErr != 0) {
		goto __6
	}
	Xsqlite3CodeVerifyNamedSchema(tls, pParse, (*SrcItem)(unsafe.Pointer(pName+8)).FzDatabase)
	sqlite3ForceNotReadOnly(tls, pParse)
__6:
	;
	goto exit_drop_table
__5:
	;
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB && Xsqlite3ViewGetColumnNames(tls, pParse, pTab) != 0) {
		goto __7
	}
	goto exit_drop_table
__7:
	;
	zTab = func() uintptr {
		if !(0 != 0) && iDb == 1 {
			return ts + 9604
		}
		return ts + 8808
	}()
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	zArg2 = uintptr(0)
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_DELETE, zTab, uintptr(0), zDb) != 0) {
		goto __8
	}
	goto exit_drop_table
__8:
	;
	if !(isView != 0) {
		goto __9
	}
	if !(!(0 != 0) && iDb == 1) {
		goto __11
	}
	code = SQLITE_DROP_TEMP_VIEW
	goto __12
__11:
	code = SQLITE_DROP_VIEW
__12:
	;
	goto __10
__9:
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __13
	}
	code = SQLITE_DROP_VTABLE
	zArg2 = (*Module)(unsafe.Pointer((*VTable)(unsafe.Pointer(Xsqlite3GetVTable(tls, db, pTab))).FpMod)).FzName
	goto __14
__13:
	if !(!(0 != 0) && iDb == 1) {
		goto __15
	}
	code = SQLITE_DROP_TEMP_TABLE
	goto __16
__15:
	code = SQLITE_DROP_TABLE
__16:
	;
__14:
	;
__10:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, code, (*Table)(unsafe.Pointer(pTab)).FzName, zArg2, zDb) != 0) {
		goto __17
	}
	goto exit_drop_table
__17:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_DELETE, (*Table)(unsafe.Pointer(pTab)).FzName, uintptr(0), zDb) != 0) {
		goto __18
	}
	goto exit_drop_table
__18:
	;
	if !(tableMayNotBeDropped(tls, db, pTab) != 0) {
		goto __19
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+16905, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto exit_drop_table
__19:
	;
	if !(isView != 0 && !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW)) {
		goto __20
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+16933, libc.VaList(bp+8, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto exit_drop_table
__20:
	;
	if !(!(isView != 0) && int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		goto __21
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+16967, libc.VaList(bp+16, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto exit_drop_table
__21:
	;
	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v != 0) {
		goto __22
	}
	Xsqlite3BeginWriteOperation(tls, pParse, 1, iDb)
	if !!(isView != 0) {
		goto __23
	}
	sqlite3ClearStatTables(tls, pParse, iDb, ts+14907, (*Table)(unsafe.Pointer(pTab)).FzName)
	Xsqlite3FkDropTable(tls, pParse, pName, pTab)
__23:
	;
	Xsqlite3CodeDropTable(tls, pParse, pTab, iDb, isView)
__22:
	;
exit_drop_table:
	Xsqlite3SrcListDelete(tls, db, pName)
}

func Xsqlite3CreateForeignKey(tls *libc.TLS, pParse uintptr, pFromCol uintptr, pTo uintptr, pToCol uintptr, flags int32) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var db uintptr
	var pFKey uintptr
	var pNextTo uintptr
	var p uintptr
	var nByte I64
	var i int32
	var nCol int32
	var z uintptr
	var iCol int32
	var j int32
	var n int32
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	pFKey = uintptr(0)
	p = (*Parse)(unsafe.Pointer(pParse)).FpNewTable

	if !(p == uintptr(0) || int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) == PARSE_MODE_DECLARE_VTAB) {
		goto __1
	}
	goto fk_end
__1:
	;
	if !(pFromCol == uintptr(0)) {
		goto __2
	}
	iCol = int32((*Table)(unsafe.Pointer(p)).FnCol) - 1
	if !(iCol < 0) {
		goto __4
	}
	goto fk_end
__4:
	;
	if !(pToCol != 0 && (*ExprList)(unsafe.Pointer(pToCol)).FnExpr != 1) {
		goto __5
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+16999,
		libc.VaList(bp, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(p)).FaCol+uintptr(iCol)*24)).FzCnName, pTo))
	goto fk_end
__5:
	;
	nCol = 1
	goto __3
__2:
	if !(pToCol != 0 && (*ExprList)(unsafe.Pointer(pToCol)).FnExpr != (*ExprList)(unsafe.Pointer(pFromCol)).FnExpr) {
		goto __6
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+17062, 0)
	goto fk_end
	goto __7
__6:
	nCol = (*ExprList)(unsafe.Pointer(pFromCol)).FnExpr
__7:
	;
__3:
	;
	nByte = I64(uint64(unsafe.Sizeof(FKey{})) + uint64(nCol-1)*uint64(unsafe.Sizeof(sColMap{})) + uint64((*Token)(unsafe.Pointer(pTo)).Fn) + uint64(1))
	if !(pToCol != 0) {
		goto __8
	}
	i = 0
__9:
	if !(i < (*ExprList)(unsafe.Pointer(pToCol)).FnExpr) {
		goto __11
	}
	nByte = nByte + I64(Xsqlite3Strlen30(tls, (*ExprList_item)(unsafe.Pointer(pToCol+8+uintptr(i)*32)).FzEName)+1)
	goto __10
__10:
	i++
	goto __9
	goto __11
__11:
	;
__8:
	;
	pFKey = Xsqlite3DbMallocZero(tls, db, uint64(nByte))
	if !(pFKey == uintptr(0)) {
		goto __12
	}
	goto fk_end
__12:
	;
	(*FKey)(unsafe.Pointer(pFKey)).FpFrom = p

	(*FKey)(unsafe.Pointer(pFKey)).FpNextFrom = *(*uintptr)(unsafe.Pointer(p + 64 + 8))
	z = pFKey + 64 + uintptr(nCol)*16
	(*FKey)(unsafe.Pointer(pFKey)).FzTo = z
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __13
	}
	Xsqlite3RenameTokenMap(tls, pParse, z, pTo)
__13:
	;
	libc.Xmemcpy(tls, z, (*Token)(unsafe.Pointer(pTo)).Fz, uint64((*Token)(unsafe.Pointer(pTo)).Fn))
	*(*uint8)(unsafe.Pointer(z + uintptr((*Token)(unsafe.Pointer(pTo)).Fn))) = uint8(0)
	Xsqlite3Dequote(tls, z)
	z += uintptr((*Token)(unsafe.Pointer(pTo)).Fn + uint32(1))
	(*FKey)(unsafe.Pointer(pFKey)).FnCol = nCol
	if !(pFromCol == uintptr(0)) {
		goto __14
	}
	(*sColMap)(unsafe.Pointer(pFKey + 64)).FiFrom = int32((*Table)(unsafe.Pointer(p)).FnCol) - 1
	goto __15
__14:
	i = 0
__16:
	if !(i < nCol) {
		goto __18
	}
	j = 0
__19:
	if !(j < int32((*Table)(unsafe.Pointer(p)).FnCol)) {
		goto __21
	}
	if !(Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(p)).FaCol+uintptr(j)*24)).FzCnName, (*ExprList_item)(unsafe.Pointer(pFromCol+8+uintptr(i)*32)).FzEName) == 0) {
		goto __22
	}
	(*sColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16)).FiFrom = j
	goto __21
__22:
	;
	goto __20
__20:
	j++
	goto __19
	goto __21
__21:
	;
	if !(j >= int32((*Table)(unsafe.Pointer(p)).FnCol)) {
		goto __23
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+17156,
		libc.VaList(bp+16, (*ExprList_item)(unsafe.Pointer(pFromCol+8+uintptr(i)*32)).FzEName))
	goto fk_end
__23:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __24
	}
	Xsqlite3RenameTokenRemap(tls, pParse, pFKey+64+uintptr(i)*16, (*ExprList_item)(unsafe.Pointer(pFromCol+8+uintptr(i)*32)).FzEName)
__24:
	;
	goto __17
__17:
	i++
	goto __16
	goto __18
__18:
	;
__15:
	;
	if !(pToCol != 0) {
		goto __25
	}
	i = 0
__26:
	if !(i < nCol) {
		goto __28
	}
	n = Xsqlite3Strlen30(tls, (*ExprList_item)(unsafe.Pointer(pToCol+8+uintptr(i)*32)).FzEName)
	(*sColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16)).FzCol = z
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __29
	}
	Xsqlite3RenameTokenRemap(tls, pParse, z, (*ExprList_item)(unsafe.Pointer(pToCol+8+uintptr(i)*32)).FzEName)
__29:
	;
	libc.Xmemcpy(tls, z, (*ExprList_item)(unsafe.Pointer(pToCol+8+uintptr(i)*32)).FzEName, uint64(n))
	*(*uint8)(unsafe.Pointer(z + uintptr(n))) = uint8(0)
	z += uintptr(n + 1)
	goto __27
__27:
	i++
	goto __26
	goto __28
__28:
	;
__25:
	;
	(*FKey)(unsafe.Pointer(pFKey)).FisDeferred = U8(0)
	*(*U8)(unsafe.Pointer(pFKey + 45)) = U8(flags & 0xff)
	*(*U8)(unsafe.Pointer(pFKey + 45 + 1)) = U8(flags >> 8 & 0xff)

	pNextTo = Xsqlite3HashInsert(tls, (*Table)(unsafe.Pointer(p)).FpSchema+80,
		(*FKey)(unsafe.Pointer(pFKey)).FzTo, pFKey)
	if !(pNextTo == pFKey) {
		goto __30
	}
	Xsqlite3OomFault(tls, db)
	goto fk_end
__30:
	;
	if !(pNextTo != 0) {
		goto __31
	}

	(*FKey)(unsafe.Pointer(pFKey)).FpNextTo = pNextTo
	(*FKey)(unsafe.Pointer(pNextTo)).FpPrevTo = pFKey
__31:
	;
	*(*uintptr)(unsafe.Pointer(p + 64 + 8)) = pFKey
	pFKey = uintptr(0)

fk_end:
	Xsqlite3DbFree(tls, db, pFKey)
	Xsqlite3ExprListDelete(tls, db, pFromCol)
	Xsqlite3ExprListDelete(tls, db, pToCol)
}

func Xsqlite3DeferForeignKey(tls *libc.TLS, pParse uintptr, isDeferred int32) {
	var pTab uintptr
	var pFKey uintptr
	if libc.AssignUintptr(&pTab, (*Parse)(unsafe.Pointer(pParse)).FpNewTable) == uintptr(0) {
		return
	}
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM) {
		return
	}
	if libc.AssignUintptr(&pFKey, *(*uintptr)(unsafe.Pointer(pTab + 64 + 8))) == uintptr(0) {
		return
	}

	(*FKey)(unsafe.Pointer(pFKey)).FisDeferred = U8(isDeferred)
}

func sqlite3RefillIndex(tls *libc.TLS, pParse uintptr, pIndex uintptr, memRootPage int32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pTab uintptr = (*Index)(unsafe.Pointer(pIndex)).FpTable
	var iTab int32 = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	var iIdx int32 = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	var iSorter int32
	var addr1 int32
	var addr2 int32
	var tnum Pgno

	var v uintptr
	var pKey uintptr
	var regRecord int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var iDb int32 = Xsqlite3SchemaToIndex(tls, db, (*Index)(unsafe.Pointer(pIndex)).FpSchema)

	if Xsqlite3AuthCheck(tls, pParse, SQLITE_REINDEX, (*Index)(unsafe.Pointer(pIndex)).FzName, uintptr(0),
		(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName) != 0 {
		return
	}

	Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab)).Ftnum, uint8(1), (*Table)(unsafe.Pointer(pTab)).FzName)

	v = Xsqlite3GetVdbe(tls, pParse)
	if v == uintptr(0) {
		return
	}
	if memRootPage >= 0 {
		tnum = Pgno(memRootPage)
	} else {
		tnum = (*Index)(unsafe.Pointer(pIndex)).Ftnum
	}
	pKey = Xsqlite3KeyInfoOfIndex(tls, pParse, pIndex)

	iSorter = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	Xsqlite3VdbeAddOp4(tls, v, OP_SorterOpen, iSorter, 0, int32((*Index)(unsafe.Pointer(pIndex)).FnKeyCol), Xsqlite3KeyInfoRef(tls, pKey), -8)

	Xsqlite3OpenTable(tls, pParse, iTab, iDb, pTab, OP_OpenRead)
	addr1 = Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, iTab, 0)
	regRecord = Xsqlite3GetTempReg(tls, pParse)
	Xsqlite3MultiWrite(tls, pParse)

	Xsqlite3GenerateIndexKey(tls, pParse, pIndex, iTab, regRecord, 0, bp, uintptr(0), 0)
	Xsqlite3VdbeAddOp2(tls, v, OP_SorterInsert, iSorter, regRecord)
	Xsqlite3ResolvePartIdxLabel(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, iTab, addr1+1)
	Xsqlite3VdbeJumpHere(tls, v, addr1)
	if memRootPage < 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_Clear, int32(tnum), iDb)
	}
	Xsqlite3VdbeAddOp4(tls, v, OP_OpenWrite, iIdx, int32(tnum), iDb,
		pKey, -8)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_BULKCSR|func() int32 {
		if memRootPage >= 0 {
			return OPFLAG_P2ISREG
		}
		return 0
	}()))

	addr1 = Xsqlite3VdbeAddOp2(tls, v, OP_SorterSort, iSorter, 0)
	if int32((*Index)(unsafe.Pointer(pIndex)).FonError) != OE_None {
		var j2 int32 = Xsqlite3VdbeGoto(tls, v, 1)
		addr2 = Xsqlite3VdbeCurrentAddr(tls, v)

		Xsqlite3VdbeAddOp4Int(tls, v, OP_SorterCompare, iSorter, j2, regRecord,
			int32((*Index)(unsafe.Pointer(pIndex)).FnKeyCol))
		Xsqlite3UniqueConstraint(tls, pParse, OE_Abort, pIndex)
		Xsqlite3VdbeJumpHere(tls, v, j2)
	} else {
		Xsqlite3MayAbort(tls, pParse)
		addr2 = Xsqlite3VdbeCurrentAddr(tls, v)
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_SorterData, iSorter, regRecord, iIdx)
	if !(int32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x200>>9) != 0) {
		Xsqlite3VdbeAddOp1(tls, v, OP_SeekEnd, iIdx)
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_IdxInsert, iIdx, regRecord)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
	Xsqlite3ReleaseTempReg(tls, pParse, regRecord)
	Xsqlite3VdbeAddOp2(tls, v, OP_SorterNext, iSorter, addr2)
	Xsqlite3VdbeJumpHere(tls, v, addr1)

	Xsqlite3VdbeAddOp1(tls, v, OP_Close, iTab)
	Xsqlite3VdbeAddOp1(tls, v, OP_Close, iIdx)
	Xsqlite3VdbeAddOp1(tls, v, OP_Close, iSorter)
}

func Xsqlite3AllocateIndexObject(tls *libc.TLS, db uintptr, nCol I16, nExtra int32, ppExtra uintptr) uintptr {
	var p uintptr
	var nByte int32

	nByte = int32((uint64(unsafe.Sizeof(Index{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7)) + (uint64(unsafe.Sizeof(uintptr(0)))*uint64(nCol)+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7)) + (uint64(unsafe.Sizeof(LogEst(0)))*uint64(int32(nCol)+1)+uint64(unsafe.Sizeof(I16(0)))*uint64(nCol)+uint64(unsafe.Sizeof(U8(0)))*uint64(nCol)+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7)))
	p = Xsqlite3DbMallocZero(tls, db, uint64(nByte+nExtra))
	if p != 0 {
		var pExtra uintptr = p + uintptr((uint64(unsafe.Sizeof(Index{}))+uint64(7))&libc.Uint64FromInt32(libc.CplInt32(7)))
		(*Index)(unsafe.Pointer(p)).FazColl = pExtra
		pExtra += uintptr((uint64(unsafe.Sizeof(uintptr(0)))*uint64(nCol) + uint64(7)) & libc.Uint64FromInt32(libc.CplInt32(7)))
		(*Index)(unsafe.Pointer(p)).FaiRowLogEst = pExtra
		pExtra += uintptr(uint64(unsafe.Sizeof(LogEst(0))) * uint64(int32(nCol)+1))
		(*Index)(unsafe.Pointer(p)).FaiColumn = pExtra
		pExtra += uintptr(uint64(unsafe.Sizeof(I16(0))) * uint64(nCol))
		(*Index)(unsafe.Pointer(p)).FaSortOrder = pExtra
		(*Index)(unsafe.Pointer(p)).FnColumn = U16(nCol)
		(*Index)(unsafe.Pointer(p)).FnKeyCol = U16(int32(nCol) - 1)
		*(*uintptr)(unsafe.Pointer(ppExtra)) = p + uintptr(nByte)
	}
	return p
}

func Xsqlite3HasExplicitNulls(tls *libc.TLS, pParse uintptr, pList uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if pList != 0 {
		var i int32
		for i = 0; i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
			if uint32(int32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*32 + 16 + 4))&0x20>>5)) != 0 {
				var sf U8 = (*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32)).Ffg.FsortFlags
				Xsqlite3ErrorMsg(tls, pParse, ts+17202,
					libc.VaList(bp, func() uintptr {
						if int32(sf) == 0 || int32(sf) == 3 {
							return ts + 17230
						}
						return ts + 17236
					}()))
				return 1
			}
		}
	}
	return 0
}

func Xsqlite3CreateIndex(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, pTblName uintptr, pList uintptr, onError int32, pStart uintptr, pPIWhere uintptr, sortOrder int32, ifNotExist int32, idxType U8) {
	bp := tls.Alloc(256)
	defer tls.Free(256)

	var pTab uintptr
	var pIndex uintptr
	var zName uintptr
	var nName int32
	var i int32
	var j int32

	var sortOrderMask int32
	var db uintptr
	var pDb uintptr
	var iDb int32

	var pListItem uintptr
	var nExtra int32
	var nExtraCol int32

	var pPk uintptr
	var n int32
	var pLoop uintptr
	var zDb uintptr

	var pCol uintptr
	var pExpr uintptr
	var nColl int32
	var pCExpr uintptr
	var requestedSortOrder int32
	var zColl uintptr
	var x int32
	var z1 uintptr
	var z2 uintptr
	var k int32

	var pIdx uintptr
	var p uintptr
	var n1 int32
	var v uintptr
	var zStmt uintptr
	var iMem int32
	var pNext uintptr

	var ppFrom uintptr
	var pThis uintptr
	pTab = uintptr(0)
	pIndex = uintptr(0)
	zName = uintptr(0)
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	*(*uintptr)(unsafe.Pointer(bp + 128)) = uintptr(0)
	nExtra = 0
	*(*uintptr)(unsafe.Pointer(bp + 248)) = uintptr(0)
	pPk = uintptr(0)

	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __1
	}
	goto exit_create_index
__1:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) == PARSE_MODE_DECLARE_VTAB && int32(idxType) != SQLITE_IDXTYPE_PRIMARYKEY) {
		goto __2
	}
	goto exit_create_index
__2:
	;
	if !(SQLITE_OK != Xsqlite3ReadSchema(tls, pParse)) {
		goto __3
	}
	goto exit_create_index
__3:
	;
	if !(Xsqlite3HasExplicitNulls(tls, pParse, pList) != 0) {
		goto __4
	}
	goto exit_create_index
__4:
	;
	if !(pTblName != uintptr(0)) {
		goto __5
	}

	iDb = Xsqlite3TwoPartName(tls, pParse, pName1, pName2, bp+128)
	if !(iDb < 0) {
		goto __7
	}
	goto exit_create_index
__7:
	;
	if !!(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) {
		goto __8
	}
	pTab = Xsqlite3SrcListLookup(tls, pParse, pTblName)
	if !((*Token)(unsafe.Pointer(pName2)).Fn == uint32(0) && pTab != 0 && (*Table)(unsafe.Pointer(pTab)).FpSchema == (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema) {
		goto __9
	}
	iDb = 1
__9:
	;
__8:
	;
	Xsqlite3FixInit(tls, bp+136, pParse, iDb, ts+9505, *(*uintptr)(unsafe.Pointer(bp + 128)))
	if !(Xsqlite3FixSrcList(tls, bp+136, pTblName) != 0) {
		goto __10
	}

__10:
	;
	pTab = Xsqlite3LocateTableItem(tls, pParse, uint32(0), pTblName+8)

	if !(pTab == uintptr(0)) {
		goto __11
	}
	goto exit_create_index
__11:
	;
	if !(iDb == 1 && (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema != (*Table)(unsafe.Pointer(pTab)).FpSchema) {
		goto __12
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+17241,
		libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto exit_create_index
__12:
	;
	if !!((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __13
	}
	pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)
__13:
	;
	goto __6
__5:
	;
	pTab = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	if !!(pTab != 0) {
		goto __14
	}
	goto exit_create_index
__14:
	;
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)
__6:
	;
	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32

	if !(Xsqlite3_strnicmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName, ts+9596, 7) == 0 &&
		int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) == 0 &&
		pTblName != uintptr(0)) {
		goto __15
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+17291, libc.VaList(bp+8, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto exit_create_index
__15:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		goto __16
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+17319, 0)
	goto exit_create_index
__16:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __17
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+17344, 0)
	goto exit_create_index
__17:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp + 128)) != 0) {
		goto __18
	}
	zName = Xsqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp + 128)))
	if !(zName == uintptr(0)) {
		goto __20
	}
	goto exit_create_index
__20:
	;
	if !(SQLITE_OK != Xsqlite3CheckObjectName(tls, pParse, zName, ts+9505, (*Table)(unsafe.Pointer(pTab)).FzName)) {
		goto __21
	}
	goto exit_create_index
__21:
	;
	if !!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __22
	}
	if !!(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) {
		goto __23
	}
	if !(Xsqlite3FindTable(tls, db, zName, (*Db)(unsafe.Pointer(pDb)).FzDbSName) != uintptr(0)) {
		goto __24
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+17378, libc.VaList(bp+16, zName))
	goto exit_create_index
__24:
	;
__23:
	;
	if !(Xsqlite3FindIndex(tls, db, zName, (*Db)(unsafe.Pointer(pDb)).FzDbSName) != uintptr(0)) {
		goto __25
	}
	if !!(ifNotExist != 0) {
		goto __26
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+17412, libc.VaList(bp+24, zName))
	goto __27
__26:
	;
	Xsqlite3CodeVerifySchema(tls, pParse, iDb)
	sqlite3ForceNotReadOnly(tls, pParse)
__27:
	;
	goto exit_create_index
__25:
	;
__22:
	;
	goto __19
__18:
	pLoop = (*Table)(unsafe.Pointer(pTab)).FpIndex
	n = 1
__28:
	if !(pLoop != 0) {
		goto __30
	}
	goto __29
__29:
	pLoop = (*Index)(unsafe.Pointer(pLoop)).FpNext
	n++
	goto __28
	goto __30
__30:
	;
	zName = Xsqlite3MPrintf(tls, db, ts+17436, libc.VaList(bp+32, (*Table)(unsafe.Pointer(pTab)).FzName, n))
	if !(zName == uintptr(0)) {
		goto __31
	}
	goto exit_create_index
__31:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL) {
		goto __32
	}
	*(*uint8)(unsafe.Pointer(zName + 7))++
__32:
	;
__19:
	;
	if !!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __33
	}
	zDb = (*Db)(unsafe.Pointer(pDb)).FzDbSName
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_INSERT, func() uintptr {
		if !(0 != 0) && iDb == 1 {
			return ts + 9604
		}
		return ts + 8808
	}(), uintptr(0), zDb) != 0) {
		goto __34
	}
	goto exit_create_index
__34:
	;
	i = SQLITE_CREATE_INDEX
	if !(!(0 != 0) && iDb == 1) {
		goto __35
	}
	i = SQLITE_CREATE_TEMP_INDEX
__35:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, i, zName, (*Table)(unsafe.Pointer(pTab)).FzName, zDb) != 0) {
		goto __36
	}
	goto exit_create_index
__36:
	;
__33:
	;
	if !(pList == uintptr(0)) {
		goto __37
	}
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(int32((*Table)(unsafe.Pointer(pTab)).FnCol)-1)*24
	*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_UNIQUE)
	Xsqlite3TokenInit(tls, bp+232, (*Column)(unsafe.Pointer(pCol)).FzCnName)
	pList = Xsqlite3ExprListAppend(tls, pParse, uintptr(0),
		Xsqlite3ExprAlloc(tls, db, TK_ID, bp+232, 0))
	if !(pList == uintptr(0)) {
		goto __39
	}
	goto exit_create_index
__39:
	;
	Xsqlite3ExprListSetSortOrder(tls, pList, sortOrder, -1)
	goto __38
__37:
	Xsqlite3ExprListCheckLength(tls, pParse, pList, ts+9505)
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __40
	}
	goto exit_create_index
__40:
	;
__38:
	;
	i = 0
__41:
	if !(i < (*ExprList)(unsafe.Pointer(pList)).FnExpr) {
		goto __43
	}
	pExpr = (*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32)).FpExpr

	if !(int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLLATE) {
		goto __44
	}

	nExtra = nExtra + (1 + Xsqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
__44:
	;
	goto __42
__42:
	i++
	goto __41
	goto __43
__43:
	;
	nName = Xsqlite3Strlen30(tls, zName)
	if pPk != 0 {
		nExtraCol = int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
	} else {
		nExtraCol = 1
	}

	pIndex = Xsqlite3AllocateIndexObject(tls, db, int16((*ExprList)(unsafe.Pointer(pList)).FnExpr+nExtraCol),
		nName+nExtra+1, bp+248)
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __45
	}
	goto exit_create_index
__45:
	;
	(*Index)(unsafe.Pointer(pIndex)).FzName = *(*uintptr)(unsafe.Pointer(bp + 248))
	*(*uintptr)(unsafe.Pointer(bp + 248)) += uintptr(nName + 1)
	libc.Xmemcpy(tls, (*Index)(unsafe.Pointer(pIndex)).FzName, zName, uint64(nName+1))
	(*Index)(unsafe.Pointer(pIndex)).FpTable = pTab
	(*Index)(unsafe.Pointer(pIndex)).FonError = U8(onError)
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(libc.Bool32(onError != OE_None)), 3, 0x8)
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(idxType), 0, 0x3)
	(*Index)(unsafe.Pointer(pIndex)).FpSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
	(*Index)(unsafe.Pointer(pIndex)).FnKeyCol = U16((*ExprList)(unsafe.Pointer(pList)).FnExpr)
	if !(pPIWhere != 0) {
		goto __46
	}
	Xsqlite3ResolveSelfReference(tls, pParse, pTab, NC_PartIdx, pPIWhere, uintptr(0))
	(*Index)(unsafe.Pointer(pIndex)).FpPartIdxWhere = pPIWhere
	pPIWhere = uintptr(0)
__46:
	;
	if !(int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) >= 4) {
		goto __47
	}
	sortOrderMask = -1
	goto __48
__47:
	sortOrderMask = 0
__48:
	;
	pListItem = pList + 8
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __49
	}
	(*Index)(unsafe.Pointer(pIndex)).FaColExpr = pList
	pList = uintptr(0)
__49:
	;
	i = 0
__50:
	if !(i < int32((*Index)(unsafe.Pointer(pIndex)).FnKeyCol)) {
		goto __52
	}

	sqlite3StringToId(tls, (*ExprList_item)(unsafe.Pointer(pListItem)).FpExpr)
	Xsqlite3ResolveSelfReference(tls, pParse, pTab, NC_IdxExpr, (*ExprList_item)(unsafe.Pointer(pListItem)).FpExpr, uintptr(0))
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __53
	}
	goto exit_create_index
__53:
	;
	pCExpr = Xsqlite3ExprSkipCollate(tls, (*ExprList_item)(unsafe.Pointer(pListItem)).FpExpr)
	if !(int32((*Expr)(unsafe.Pointer(pCExpr)).Fop) != TK_COLUMN) {
		goto __54
	}
	if !(pTab == (*Parse)(unsafe.Pointer(pParse)).FpNewTable) {
		goto __56
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+17459, 0)
	goto exit_create_index
__56:
	;
	if !((*Index)(unsafe.Pointer(pIndex)).FaColExpr == uintptr(0)) {
		goto __57
	}
	(*Index)(unsafe.Pointer(pIndex)).FaColExpr = pList
	pList = uintptr(0)
__57:
	;
	j = -2
	*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(-2)
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(0), 3, 0x8)
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(1), 11, 0x800)
	goto __55
__54:
	j = int32((*Expr)(unsafe.Pointer(pCExpr)).FiColumn)

	if !(j < 0) {
		goto __58
	}
	j = int32((*Table)(unsafe.Pointer(pTab)).FiPKey)
	goto __59
__58:
	if !(int32(*(*uint8)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*24 + 8))&0xf>>0) == 0) {
		goto __60
	}
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(0), 3, 0x8)
__60:
	;
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FcolFlags)&COLFLAG_VIRTUAL != 0) {
		goto __61
	}
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(1), 10, 0x400)
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(1), 11, 0x800)
__61:
	;
__59:
	;
	*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = I16(j)
__55:
	;
	zColl = uintptr(0)
	if !(int32((*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pListItem)).FpExpr)).Fop) == TK_COLLATE) {
		goto __62
	}

	zColl = *(*uintptr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pListItem)).FpExpr + 8))
	nColl = Xsqlite3Strlen30(tls, zColl) + 1

	libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp + 248)), zColl, uint64(nColl))
	zColl = *(*uintptr)(unsafe.Pointer(bp + 248))
	*(*uintptr)(unsafe.Pointer(bp + 248)) += uintptr(nColl)
	nExtra = nExtra - nColl
	goto __63
__62:
	if !(j >= 0) {
		goto __64
	}
	zColl = Xsqlite3ColumnColl(tls, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)
__64:
	;
__63:
	;
	if !!(zColl != 0) {
		goto __65
	}
	zColl = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
__65:
	;
	if !(!(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) && !(Xsqlite3LocateCollSeq(tls, pParse, zColl) != 0)) {
		goto __66
	}
	goto exit_create_index
__66:
	;
	*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*8)) = zColl
	requestedSortOrder = int32((*ExprList_item)(unsafe.Pointer(pListItem)).Ffg.FsortFlags) & sortOrderMask
	*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(i))) = U8(requestedSortOrder)
	goto __51
__51:
	i++
	pListItem += 32
	goto __50
	goto __52
__52:
	;
	if !(pPk != 0) {
		goto __67
	}
	j = 0
__69:
	if !(j < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)) {
		goto __71
	}
	x = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2)))

	if !(isDupColumn(tls, pIndex, int32((*Index)(unsafe.Pointer(pIndex)).FnKeyCol), pPk, j) != 0) {
		goto __72
	}
	(*Index)(unsafe.Pointer(pIndex)).FnColumn--
	goto __73
__72:
	;
	*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = I16(x)
	*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FazColl + uintptr(j)*8))
	*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(i))) = *(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaSortOrder + uintptr(j)))
	i++
__73:
	;
	goto __70
__70:
	j++
	goto __69
	goto __71
__71:
	;
	goto __68
__67:
	*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2)) = int16(-1)
	*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*8)) = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
__68:
	;
	Xsqlite3DefaultRowEst(tls, pIndex)
	if !((*Parse)(unsafe.Pointer(pParse)).FpNewTable == uintptr(0)) {
		goto __74
	}
	estimateIndexWidth(tls, pIndex)
__74:
	;
	recomputeColumnsNotIndexed(tls, pIndex)
	if !(pTblName != uintptr(0) && int32((*Index)(unsafe.Pointer(pIndex)).FnColumn) >= int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __75
	}
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(1), 5, 0x20)
	j = 0
__76:
	if !(j < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __78
	}
	if !(j == int32((*Table)(unsafe.Pointer(pTab)).FiPKey)) {
		goto __79
	}
	goto __77
__79:
	;
	if !(int32(Xsqlite3TableColumnToIndex(tls, pIndex, int16(j))) >= 0) {
		goto __80
	}
	goto __77
__80:
	;
	libc.SetBitFieldPtr16Uint32(pIndex+100, uint32(0), 5, 0x20)
	goto __78
	goto __77
__77:
	j++
	goto __76
	goto __78
__78:
	;
__75:
	;
	if !(pTab == (*Parse)(unsafe.Pointer(pParse)).FpNewTable) {
		goto __81
	}
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__82:
	if !(pIdx != 0) {
		goto __84
	}

	if !(int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) != int32((*Index)(unsafe.Pointer(pIndex)).FnKeyCol)) {
		goto __85
	}
	goto __83
__85:
	;
	k = 0
__86:
	if !(k < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)) {
		goto __88
	}

	if !(int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(k)*2))) != int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(k)*2)))) {
		goto __89
	}
	goto __88
__89:
	;
	z1 = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(k)*8))
	z2 = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FazColl + uintptr(k)*8))
	if !(Xsqlite3StrICmp(tls, z1, z2) != 0) {
		goto __90
	}
	goto __88
__90:
	;
	goto __87
__87:
	k++
	goto __86
	goto __88
__88:
	;
	if !(k == int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)) {
		goto __91
	}
	if !(int32((*Index)(unsafe.Pointer(pIdx)).FonError) != int32((*Index)(unsafe.Pointer(pIndex)).FonError)) {
		goto __92
	}

	if !!(int32((*Index)(unsafe.Pointer(pIdx)).FonError) == OE_Default || int32((*Index)(unsafe.Pointer(pIndex)).FonError) == OE_Default) {
		goto __93
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+17520, libc.VaList(bp+48, 0))
__93:
	;
	if !(int32((*Index)(unsafe.Pointer(pIdx)).FonError) == OE_Default) {
		goto __94
	}
	(*Index)(unsafe.Pointer(pIdx)).FonError = (*Index)(unsafe.Pointer(pIndex)).FonError
__94:
	;
__92:
	;
	if !(int32(idxType) == SQLITE_IDXTYPE_PRIMARYKEY) {
		goto __95
	}
	libc.SetBitFieldPtr16Uint32(pIdx+100, uint32(idxType), 0, 0x3)
__95:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __96
	}
	(*Index)(unsafe.Pointer(pIndex)).FpNext = (*Parse)(unsafe.Pointer(pParse)).FpNewIndex
	(*Parse)(unsafe.Pointer(pParse)).FpNewIndex = pIndex
	pIndex = uintptr(0)
__96:
	;
	goto exit_create_index
__91:
	;
	goto __83
__83:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	goto __82
	goto __84
__84:
	;
__81:
	;
	if !!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __97
	}

	if !((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0) {
		goto __98
	}

	if !(pTblName != uintptr(0)) {
		goto __100
	}
	(*Index)(unsafe.Pointer(pIndex)).Ftnum = (*Sqlite3)(unsafe.Pointer(db)).Finit.FnewTnum
	if !(Xsqlite3IndexHasDuplicateRootPage(tls, pIndex) != 0) {
		goto __101
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+17562, 0)
	(*Parse)(unsafe.Pointer(pParse)).Frc = Xsqlite3CorruptError(tls, 121859)
	goto exit_create_index
__101:
	;
__100:
	;
	p = Xsqlite3HashInsert(tls, (*Index)(unsafe.Pointer(pIndex)).FpSchema+32,
		(*Index)(unsafe.Pointer(pIndex)).FzName, pIndex)
	if !(p != 0) {
		goto __102
	}

	Xsqlite3OomFault(tls, db)
	goto exit_create_index
__102:
	;
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaChange)
	goto __99
__98:
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) || pTblName != uintptr(0)) {
		goto __103
	}
	iMem = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)

	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v == uintptr(0)) {
		goto __104
	}
	goto exit_create_index
__104:
	;
	Xsqlite3BeginWriteOperation(tls, pParse, 1, iDb)

	(*Index)(unsafe.Pointer(pIndex)).Ftnum = Pgno(Xsqlite3VdbeAddOp0(tls, v, OP_Noop))
	Xsqlite3VdbeAddOp3(tls, v, OP_CreateBtree, iDb, iMem, BTREE_BLOBKEY)

	if !(pStart != 0) {
		goto __105
	}
	n1 = int32(uint32(int32((int64((*Parse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64((*Token)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 128)))).Fz))/1)) + (*Parse)(unsafe.Pointer(pParse)).FsLastToken.Fn)
	if !(int32(*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 128)))).Fz + uintptr(n1-1)))) == ';') {
		goto __107
	}
	n1--
__107:
	;
	zStmt = Xsqlite3MPrintf(tls, db, ts+17579,
		libc.VaList(bp+56, func() uintptr {
			if onError == OE_None {
				return ts + 1636
			}
			return ts + 17599
		}(), n1, (*Token)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 128)))).Fz))
	goto __106
__105:
	zStmt = uintptr(0)
__106:
	;
	Xsqlite3NestedParse(tls, pParse,
		ts+17607,
		libc.VaList(bp+80, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName,
			(*Index)(unsafe.Pointer(pIndex)).FzName,
			(*Table)(unsafe.Pointer(pTab)).FzName,
			iMem,
			zStmt))
	Xsqlite3DbFree(tls, db, zStmt)

	if !(pTblName != 0) {
		goto __108
	}
	sqlite3RefillIndex(tls, pParse, pIndex, iMem)
	Xsqlite3ChangeCookie(tls, pParse, iDb)
	Xsqlite3VdbeAddParseSchemaOp(tls, v, iDb,
		Xsqlite3MPrintf(tls, db, ts+17666, libc.VaList(bp+120, (*Index)(unsafe.Pointer(pIndex)).FzName)), uint16(0))
	Xsqlite3VdbeAddOp2(tls, v, OP_Expire, 0, 1)
__108:
	;
	Xsqlite3VdbeJumpHere(tls, v, int32((*Index)(unsafe.Pointer(pIndex)).Ftnum))
__103:
	;
__99:
	;
__97:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 || pTblName == uintptr(0)) {
		goto __109
	}
	(*Index)(unsafe.Pointer(pIndex)).FpNext = (*Table)(unsafe.Pointer(pTab)).FpIndex
	(*Table)(unsafe.Pointer(pTab)).FpIndex = pIndex
	pIndex = uintptr(0)
	goto __110
__109:
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __111
	}

	(*Parse)(unsafe.Pointer(pParse)).FpNewIndex = pIndex
	pIndex = uintptr(0)
__111:
	;
__110:
	;
exit_create_index:
	if !(pIndex != 0) {
		goto __112
	}
	Xsqlite3FreeIndex(tls, db, pIndex)
__112:
	;
	if !(pTab != 0) {
		goto __113
	}
	ppFrom = pTab + 16
__114:
	if !(libc.AssignUintptr(&pThis, *(*uintptr)(unsafe.Pointer(ppFrom))) != uintptr(0)) {
		goto __116
	}
	if !(int32((*Index)(unsafe.Pointer(pThis)).FonError) != OE_Replace) {
		goto __117
	}
	goto __115
__117:
	;
__118:
	if !(libc.AssignUintptr(&pNext, (*Index)(unsafe.Pointer(pThis)).FpNext) != uintptr(0) && int32((*Index)(unsafe.Pointer(pNext)).FonError) != OE_Replace) {
		goto __119
	}
	*(*uintptr)(unsafe.Pointer(ppFrom)) = pNext
	(*Index)(unsafe.Pointer(pThis)).FpNext = (*Index)(unsafe.Pointer(pNext)).FpNext
	(*Index)(unsafe.Pointer(pNext)).FpNext = pThis
	ppFrom = pNext + 40
	goto __118
__119:
	;
	goto __116
	goto __115
__115:
	ppFrom = pThis + 40
	goto __114
	goto __116
__116:
	;
__113:
	;
	Xsqlite3ExprDelete(tls, db, pPIWhere)
	Xsqlite3ExprListDelete(tls, db, pList)
	Xsqlite3SrcListDelete(tls, db, pTblName)
	Xsqlite3DbFree(tls, db, zName)
}

func Xsqlite3DefaultRowEst(tls *libc.TLS, pIdx uintptr) {
	var a uintptr = (*Index)(unsafe.Pointer(pIdx)).FaiRowLogEst
	var x LogEst
	var nCopy int32 = func() int32 {
		if int32(uint64(unsafe.Sizeof(aVal))/uint64(unsafe.Sizeof(LogEst(0)))) < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) {
			return int32(uint64(unsafe.Sizeof(aVal)) / uint64(unsafe.Sizeof(LogEst(0))))
		}
		return int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
	}()
	var i int32

	x = (*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FnRowLogEst

	if int32(x) < 99 {
		(*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FnRowLogEst = libc.AssignInt16(&x, int16(99))
	}
	if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) {
		x = int16(int32(x) - 10)
	}
	*(*LogEst)(unsafe.Pointer(a)) = x

	libc.Xmemcpy(tls, a+1*2, uintptr(unsafe.Pointer(&aVal)), uint64(nCopy)*uint64(unsafe.Sizeof(LogEst(0))))
	for i = nCopy + 1; i <= int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol); i++ {
		*(*LogEst)(unsafe.Pointer(a + uintptr(i)*2)) = int16(23)
	}

	if int32((*Index)(unsafe.Pointer(pIdx)).FonError) != OE_None {
		*(*LogEst)(unsafe.Pointer(a + uintptr((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)*2)) = int16(0)
	}
}

var aVal = [5]LogEst{int16(33), int16(32), int16(30), int16(28), int16(26)}

func Xsqlite3DropIndex(tls *libc.TLS, pParse uintptr, pName uintptr, ifExists int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pIndex uintptr
	var v uintptr
	var db uintptr
	var iDb int32
	var code int32
	var pTab uintptr
	var zDb uintptr
	var zTab uintptr
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __1
	}
	goto exit_drop_index
__1:
	;
	if !(SQLITE_OK != Xsqlite3ReadSchema(tls, pParse)) {
		goto __2
	}
	goto exit_drop_index
__2:
	;
	pIndex = Xsqlite3FindIndex(tls, db, (*SrcItem)(unsafe.Pointer(pName+8)).FzName, (*SrcItem)(unsafe.Pointer(pName+8)).FzDatabase)
	if !(pIndex == uintptr(0)) {
		goto __3
	}
	if !!(ifExists != 0) {
		goto __4
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+17693, libc.VaList(bp, pName+8))
	goto __5
__4:
	Xsqlite3CodeVerifyNamedSchema(tls, pParse, (*SrcItem)(unsafe.Pointer(pName+8)).FzDatabase)
	sqlite3ForceNotReadOnly(tls, pParse)
__5:
	;
	(*Parse)(unsafe.Pointer(pParse)).FcheckSchema = U8(1)
	goto exit_drop_index
__3:
	;
	if !(int32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x3>>0) != SQLITE_IDXTYPE_APPDEF) {
		goto __6
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+17711, libc.VaList(bp+8, 0))
	goto exit_drop_index
__6:
	;
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Index)(unsafe.Pointer(pIndex)).FpSchema)

	code = SQLITE_DROP_INDEX
	pTab = (*Index)(unsafe.Pointer(pIndex)).FpTable
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	zTab = func() uintptr {
		if !(0 != 0) && iDb == 1 {
			return ts + 9604
		}
		return ts + 8808
	}()
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_DELETE, zTab, uintptr(0), zDb) != 0) {
		goto __7
	}
	goto exit_drop_index
__7:
	;
	if !(!(0 != 0) && iDb == 1) {
		goto __8
	}
	code = SQLITE_DROP_TEMP_INDEX
__8:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, code, (*Index)(unsafe.Pointer(pIndex)).FzName, (*Table)(unsafe.Pointer(pTab)).FzName, zDb) != 0) {
		goto __9
	}
	goto exit_drop_index
__9:
	;
	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v != 0) {
		goto __10
	}
	Xsqlite3BeginWriteOperation(tls, pParse, 1, iDb)
	Xsqlite3NestedParse(tls, pParse,
		ts+17784,
		libc.VaList(bp+16, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName, (*Index)(unsafe.Pointer(pIndex)).FzName))
	sqlite3ClearStatTables(tls, pParse, iDb, ts+14903, (*Index)(unsafe.Pointer(pIndex)).FzName)
	Xsqlite3ChangeCookie(tls, pParse, iDb)
	destroyRootPage(tls, pParse, int32((*Index)(unsafe.Pointer(pIndex)).Ftnum), iDb)
	Xsqlite3VdbeAddOp4(tls, v, OP_DropIndex, iDb, 0, 0, (*Index)(unsafe.Pointer(pIndex)).FzName, 0)
__10:
	;
exit_drop_index:
	Xsqlite3SrcListDelete(tls, db, pName)
}

func Xsqlite3ArrayAllocate(tls *libc.TLS, db uintptr, pArray uintptr, szEntry int32, pnEntry uintptr, pIdx uintptr) uintptr {
	var z uintptr
	var n Sqlite3_int64 = Sqlite3_int64(libc.AssignPtrInt32(pIdx, *(*int32)(unsafe.Pointer(pnEntry))))
	if n&(n-int64(1)) == int64(0) {
		var sz Sqlite3_int64
		if n == int64(0) {
			sz = int64(1)
		} else {
			sz = int64(2) * n
		}
		var pNew uintptr = Xsqlite3DbRealloc(tls, db, pArray, uint64(sz*Sqlite3_int64(szEntry)))
		if pNew == uintptr(0) {
			*(*int32)(unsafe.Pointer(pIdx)) = -1
			return pArray
		}
		pArray = pNew
	}
	z = pArray
	libc.Xmemset(tls, z+uintptr(n*Sqlite3_int64(szEntry)), 0, uint64(szEntry))
	*(*int32)(unsafe.Pointer(pnEntry))++
	return pArray
}

func Xsqlite3IdListAppend(tls *libc.TLS, pParse uintptr, pList uintptr, pToken uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var i int32
	if pList == uintptr(0) {
		pList = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(IdList{})))
		if pList == uintptr(0) {
			return uintptr(0)
		}
	} else {
		var pNew uintptr
		pNew = Xsqlite3DbRealloc(tls, db, pList,
			uint64(unsafe.Sizeof(IdList{}))+uint64((*IdList)(unsafe.Pointer(pList)).FnId)*uint64(unsafe.Sizeof([1]IdList_item{})))
		if pNew == uintptr(0) {
			Xsqlite3IdListDelete(tls, db, pList)
			return uintptr(0)
		}
		pList = pNew
	}
	i = libc.PostIncInt32(&(*IdList)(unsafe.Pointer(pList)).FnId, 1)
	(*IdList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*16)).FzName = Xsqlite3NameFromToken(tls, db, pToken)
	if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && (*IdList_item)(unsafe.Pointer(pList+8+uintptr(i)*16)).FzName != 0 {
		Xsqlite3RenameTokenMap(tls, pParse, (*IdList_item)(unsafe.Pointer(pList+8+uintptr(i)*16)).FzName, pToken)
	}
	return pList
}

func Xsqlite3IdListDelete(tls *libc.TLS, db uintptr, pList uintptr) {
	var i int32

	if pList == uintptr(0) {
		return
	}

	for i = 0; i < (*IdList)(unsafe.Pointer(pList)).FnId; i++ {
		Xsqlite3DbFree(tls, db, (*IdList_item)(unsafe.Pointer(pList+8+uintptr(i)*16)).FzName)
	}
	Xsqlite3DbNNFreeNN(tls, db, pList)
}

func Xsqlite3IdListIndex(tls *libc.TLS, pList uintptr, zName uintptr) int32 {
	var i int32

	for i = 0; i < (*IdList)(unsafe.Pointer(pList)).FnId; i++ {
		if Xsqlite3StrICmp(tls, (*IdList_item)(unsafe.Pointer(pList+8+uintptr(i)*16)).FzName, zName) == 0 {
			return i
		}
	}
	return -1
}

func Xsqlite3SrcListEnlarge(tls *libc.TLS, pParse uintptr, pSrc uintptr, nExtra int32, iStart int32) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var i int32

	if U32((*SrcList)(unsafe.Pointer(pSrc)).FnSrc)+U32(nExtra) > (*SrcList)(unsafe.Pointer(pSrc)).FnAlloc {
		var pNew uintptr
		var nAlloc Sqlite3_int64 = int64(2)*Sqlite3_int64((*SrcList)(unsafe.Pointer(pSrc)).FnSrc) + Sqlite3_int64(nExtra)
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

		if (*SrcList)(unsafe.Pointer(pSrc)).FnSrc+nExtra >= SQLITE_MAX_SRCLIST {
			Xsqlite3ErrorMsg(tls, pParse, ts+17844,
				libc.VaList(bp, SQLITE_MAX_SRCLIST))
			return uintptr(0)
		}
		if nAlloc > int64(SQLITE_MAX_SRCLIST) {
			nAlloc = int64(SQLITE_MAX_SRCLIST)
		}
		pNew = Xsqlite3DbRealloc(tls, db, pSrc,
			uint64(unsafe.Sizeof(SrcList{}))+uint64(nAlloc-int64(1))*uint64(unsafe.Sizeof(SrcItem{})))
		if pNew == uintptr(0) {
			return uintptr(0)
		}
		pSrc = pNew
		(*SrcList)(unsafe.Pointer(pSrc)).FnAlloc = U32(nAlloc)
	}

	for i = (*SrcList)(unsafe.Pointer(pSrc)).FnSrc - 1; i >= iStart; i-- {
		*(*SrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i+nExtra)*104)) = *(*SrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104))
	}
	*(*int32)(unsafe.Pointer(pSrc)) += nExtra

	libc.Xmemset(tls, pSrc+8+uintptr(iStart)*104, 0, uint64(unsafe.Sizeof(SrcItem{}))*uint64(nExtra))
	for i = iStart; i < iStart+nExtra; i++ {
		(*SrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104)).FiCursor = -1
	}

	return pSrc
}

func Xsqlite3SrcListAppend(tls *libc.TLS, pParse uintptr, pList uintptr, pTable uintptr, pDatabase uintptr) uintptr {
	var pItem uintptr
	var db uintptr

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if pList == uintptr(0) {
		pList = Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(SrcList{})))
		if pList == uintptr(0) {
			return uintptr(0)
		}
		(*SrcList)(unsafe.Pointer(pList)).FnAlloc = U32(1)
		(*SrcList)(unsafe.Pointer(pList)).FnSrc = 1
		libc.Xmemset(tls, pList+8, 0, uint64(unsafe.Sizeof(SrcItem{})))
		(*SrcItem)(unsafe.Pointer(pList + 8)).FiCursor = -1
	} else {
		var pNew uintptr = Xsqlite3SrcListEnlarge(tls, pParse, pList, 1, (*SrcList)(unsafe.Pointer(pList)).FnSrc)
		if pNew == uintptr(0) {
			Xsqlite3SrcListDelete(tls, db, pList)
			return uintptr(0)
		} else {
			pList = pNew
		}
	}
	pItem = pList + 8 + uintptr((*SrcList)(unsafe.Pointer(pList)).FnSrc-1)*104
	if pDatabase != 0 && (*Token)(unsafe.Pointer(pDatabase)).Fz == uintptr(0) {
		pDatabase = uintptr(0)
	}
	if pDatabase != 0 {
		(*SrcItem)(unsafe.Pointer(pItem)).FzName = Xsqlite3NameFromToken(tls, db, pDatabase)
		(*SrcItem)(unsafe.Pointer(pItem)).FzDatabase = Xsqlite3NameFromToken(tls, db, pTable)
	} else {
		(*SrcItem)(unsafe.Pointer(pItem)).FzName = Xsqlite3NameFromToken(tls, db, pTable)
		(*SrcItem)(unsafe.Pointer(pItem)).FzDatabase = uintptr(0)
	}
	return pList
}

func Xsqlite3SrcListAssignCursors(tls *libc.TLS, pParse uintptr, pList uintptr) {
	var i int32
	var pItem uintptr

	if pList != 0 {
		i = 0
		pItem = pList + 8
	__1:
		if !(i < (*SrcList)(unsafe.Pointer(pList)).FnSrc) {
			goto __3
		}
		{
			if (*SrcItem)(unsafe.Pointer(pItem)).FiCursor >= 0 {
				goto __2
			}
			(*SrcItem)(unsafe.Pointer(pItem)).FiCursor = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
			if (*SrcItem)(unsafe.Pointer(pItem)).FpSelect != 0 {
				Xsqlite3SrcListAssignCursors(tls, pParse, (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpSelect)).FpSrc)
			}

		}
		goto __2
	__2:
		i++
		pItem += 104
		goto __1
		goto __3
	__3:
	}
}

func Xsqlite3SrcListDelete(tls *libc.TLS, db uintptr, pList uintptr) {
	var i int32
	var pItem uintptr

	if pList == uintptr(0) {
		return
	}
	pItem = pList + 8
	i = 0
__1:
	if !(i < (*SrcList)(unsafe.Pointer(pList)).FnSrc) {
		goto __3
	}
	{
		if (*SrcItem)(unsafe.Pointer(pItem)).FzDatabase != 0 {
			Xsqlite3DbNNFreeNN(tls, db, (*SrcItem)(unsafe.Pointer(pItem)).FzDatabase)
		}
		if (*SrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
			Xsqlite3DbNNFreeNN(tls, db, (*SrcItem)(unsafe.Pointer(pItem)).FzName)
		}
		if (*SrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 {
			Xsqlite3DbNNFreeNN(tls, db, (*SrcItem)(unsafe.Pointer(pItem)).FzAlias)
		}
		if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x2>>1)) != 0 {
			Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 88)))
		}
		if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x4>>2)) != 0 {
			Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 88)))
		}
		Xsqlite3DeleteTable(tls, db, (*SrcItem)(unsafe.Pointer(pItem)).FpTab)
		if (*SrcItem)(unsafe.Pointer(pItem)).FpSelect != 0 {
			Xsqlite3SelectDelete(tls, db, (*SrcItem)(unsafe.Pointer(pItem)).FpSelect)
		}
		if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x400>>10)) != 0 {
			Xsqlite3IdListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
		} else if *(*uintptr)(unsafe.Pointer(pItem + 72)) != 0 {
			Xsqlite3ExprDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
		}

	}
	goto __2
__2:
	i++
	pItem += 104
	goto __1
	goto __3
__3:
	;
	Xsqlite3DbNNFreeNN(tls, db, pList)
}

func Xsqlite3SrcListAppendFromTerm(tls *libc.TLS, pParse uintptr, p uintptr, pTable uintptr, pDatabase uintptr, pAlias uintptr, pSubquery uintptr, pOnUsing uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pItem uintptr
	var db uintptr
	var pToken uintptr
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if !(!(p != 0) && pOnUsing != uintptr(0) && ((*OnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn != 0 || (*OnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing != 0)) {
		goto __1
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+17880,
		libc.VaList(bp, func() uintptr {
			if (*OnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn != 0 {
				return ts + 17916
			}
			return ts + 17919
		}()))
	goto append_from_error
__1:
	;
	p = Xsqlite3SrcListAppend(tls, pParse, p, pTable, pDatabase)
	if !(p == uintptr(0)) {
		goto __2
	}
	goto append_from_error
__2:
	;
	pItem = p + 8 + uintptr((*SrcList)(unsafe.Pointer(p)).FnSrc-1)*104

	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && (*SrcItem)(unsafe.Pointer(pItem)).FzName != 0) {
		goto __3
	}
	if pDatabase != 0 && (*Token)(unsafe.Pointer(pDatabase)).Fz != 0 {
		pToken = pDatabase
	} else {
		pToken = pTable
	}
	Xsqlite3RenameTokenMap(tls, pParse, (*SrcItem)(unsafe.Pointer(pItem)).FzName, pToken)
__3:
	;
	if !((*Token)(unsafe.Pointer(pAlias)).Fn != 0) {
		goto __4
	}
	(*SrcItem)(unsafe.Pointer(pItem)).FzAlias = Xsqlite3NameFromToken(tls, db, pAlias)
__4:
	;
	if !(pSubquery != 0) {
		goto __5
	}
	(*SrcItem)(unsafe.Pointer(pItem)).FpSelect = pSubquery
	if !((*Select)(unsafe.Pointer(pSubquery)).FselFlags&U32(SF_NestedFrom) != 0) {
		goto __6
	}
	libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(1), 13, 0x2000)
__6:
	;
__5:
	;
	if !(pOnUsing == uintptr(0)) {
		goto __7
	}
	*(*uintptr)(unsafe.Pointer(pItem + 72)) = uintptr(0)
	goto __8
__7:
	if !((*OnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing != 0) {
		goto __9
	}
	libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(1), 10, 0x400)
	*(*uintptr)(unsafe.Pointer(pItem + 72)) = (*OnOrUsing)(unsafe.Pointer(pOnUsing)).FpUsing
	goto __10
__9:
	*(*uintptr)(unsafe.Pointer(pItem + 72)) = (*OnOrUsing)(unsafe.Pointer(pOnUsing)).FpOn
__10:
	;
__8:
	;
	return p

append_from_error:
	;
	Xsqlite3ClearOnOrUsing(tls, db, pOnUsing)
	Xsqlite3SelectDelete(tls, db, pSubquery)
	return uintptr(0)
}

func Xsqlite3SrcListIndexedBy(tls *libc.TLS, pParse uintptr, p uintptr, pIndexedBy uintptr) {
	if p != 0 && (*Token)(unsafe.Pointer(pIndexedBy)).Fn > uint32(0) {
		var pItem uintptr

		pItem = p + 8 + uintptr((*SrcList)(unsafe.Pointer(p)).FnSrc-1)*104

		if (*Token)(unsafe.Pointer(pIndexedBy)).Fn == uint32(1) && !(int32((*Token)(unsafe.Pointer(pIndexedBy)).Fz) != 0) {
			libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(1), 0, 0x1)
		} else {
			*(*uintptr)(unsafe.Pointer(pItem + 88)) = Xsqlite3NameFromToken(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pIndexedBy)
			libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(1), 1, 0x2)

		}
	}
}

func Xsqlite3SrcListAppendList(tls *libc.TLS, pParse uintptr, p1 uintptr, p2 uintptr) uintptr {
	if p2 != 0 {
		var pNew uintptr = Xsqlite3SrcListEnlarge(tls, pParse, p1, (*SrcList)(unsafe.Pointer(p2)).FnSrc, 1)
		if pNew == uintptr(0) {
			Xsqlite3SrcListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, p2)
		} else {
			p1 = pNew
			libc.Xmemcpy(tls, p1+8+1*104, p2+8, uint64((*SrcList)(unsafe.Pointer(p2)).FnSrc)*uint64(unsafe.Sizeof(SrcItem{})))
			Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, p2)
			*(*U8)(unsafe.Pointer(p1 + 8 + 60)) |= U8(JT_LTORJ & int32((*SrcItem)(unsafe.Pointer(p1+8+1*104)).Ffg.Fjointype))
		}
	}
	return p1
}

func Xsqlite3SrcListFuncArgs(tls *libc.TLS, pParse uintptr, p uintptr, pList uintptr) {
	if p != 0 {
		var pItem uintptr = p + 8 + uintptr((*SrcList)(unsafe.Pointer(p)).FnSrc-1)*104

		*(*uintptr)(unsafe.Pointer(pItem + 88)) = pList
		libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(1), 2, 0x4)
	} else {
		Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pList)
	}
}

func Xsqlite3SrcListShiftJoinType(tls *libc.TLS, pParse uintptr, p uintptr) {
	_ = pParse
	if p != 0 && (*SrcList)(unsafe.Pointer(p)).FnSrc > 1 {
		var i int32 = (*SrcList)(unsafe.Pointer(p)).FnSrc - 1
		var allFlags U8 = U8(0)
		for __ccgo := true; __ccgo; __ccgo = libc.PreDecInt32(&i, 1) > 0 {
			allFlags = U8(int32(allFlags) | int32(libc.AssignPtrUint8(p+8+uintptr(i)*104+60, (*SrcItem)(unsafe.Pointer(p+8+uintptr(i-1)*104)).Ffg.Fjointype)))
		}
		(*SrcItem)(unsafe.Pointer(p + 8)).Ffg.Fjointype = U8(0)

		if int32(allFlags)&JT_RIGHT != 0 {
			for i = (*SrcList)(unsafe.Pointer(p)).FnSrc - 1; i > 0 && int32((*SrcItem)(unsafe.Pointer(p+8+uintptr(i)*104)).Ffg.Fjointype)&JT_RIGHT == 0; i-- {
			}
			i--

			for __ccgo1 := true; __ccgo1; __ccgo1 = libc.PreDecInt32(&i, 1) >= 0 {
				*(*U8)(unsafe.Pointer(p + 8 + uintptr(i)*104 + 60)) |= U8(JT_LTORJ)
			}
		}
	}
}

func Xsqlite3BeginTransaction(tls *libc.TLS, pParse uintptr, type1 int32) {
	var db uintptr
	var v uintptr
	var i int32

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if Xsqlite3AuthCheck(tls, pParse, SQLITE_TRANSACTION, ts+17925, uintptr(0), uintptr(0)) != 0 {
		return
	}
	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v != 0) {
		return
	}
	if type1 != TK_DEFERRED {
		for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
			var eTxnType int32
			var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
			if pBt != 0 && Xsqlite3BtreeIsReadonly(tls, pBt) != 0 {
				eTxnType = 0
			} else if type1 == TK_EXCLUSIVE {
				eTxnType = 2
			} else {
				eTxnType = 1
			}
			Xsqlite3VdbeAddOp2(tls, v, OP_Transaction, i, eTxnType)
			Xsqlite3VdbeUsesBtree(tls, v, i)
		}
	}
	Xsqlite3VdbeAddOp0(tls, v, OP_AutoCommit)
}

func Xsqlite3EndTransaction(tls *libc.TLS, pParse uintptr, eType int32) {
	var v uintptr
	var isRollback int32

	isRollback = libc.Bool32(eType == TK_ROLLBACK)
	if Xsqlite3AuthCheck(tls, pParse, SQLITE_TRANSACTION,
		func() uintptr {
			if isRollback != 0 {
				return ts + 17931
			}
			return ts + 17940
		}(), uintptr(0), uintptr(0)) != 0 {
		return
	}
	v = Xsqlite3GetVdbe(tls, pParse)
	if v != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_AutoCommit, 1, isRollback)
	}
}

func Xsqlite3Savepoint(tls *libc.TLS, pParse uintptr, op int32, pName uintptr) {
	var zName uintptr = Xsqlite3NameFromToken(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pName)
	if zName != 0 {
		var v uintptr = Xsqlite3GetVdbe(tls, pParse)

		if !(v != 0) || Xsqlite3AuthCheck(tls, pParse, SQLITE_SAVEPOINT, az[op], zName, uintptr(0)) != 0 {
			Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, zName)
			return
		}
		Xsqlite3VdbeAddOp4(tls, v, OP_Savepoint, op, 0, 0, zName, -6)
	}
}

var az = [3]uintptr{ts + 17925, ts + 17947, ts + 17931}

func Xsqlite3OpenTempDatabase(tls *libc.TLS, pParse uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpBt == uintptr(0) && !(int32((*Parse)(unsafe.Pointer(pParse)).Fexplain) != 0) {
		var rc int32

		rc = Xsqlite3BtreeOpen(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, uintptr(0), db, bp, 0, flags)
		if rc != SQLITE_OK {
			Xsqlite3ErrorMsg(tls, pParse,
				ts+17955, 0)
			(*Parse)(unsafe.Pointer(pParse)).Frc = rc
			return 1
		}
		(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + 1*32)).FpBt = *(*uintptr)(unsafe.Pointer(bp))

		if SQLITE_NOMEM == Xsqlite3BtreeSetPageSize(tls, *(*uintptr)(unsafe.Pointer(bp)), (*Sqlite3)(unsafe.Pointer(db)).FnextPagesize, 0, 0) {
			Xsqlite3OomFault(tls, db)
			return 1
		}
	}
	return 0
}

var flags int32 = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_TEMP_DB

func sqlite3CodeVerifySchemaAtToplevel(tls *libc.TLS, pToplevel uintptr, iDb int32) {
	if libc.Bool32((*Parse)(unsafe.Pointer(pToplevel)).FcookieMask&(YDbMask(1)<<iDb) != YDbMask(0)) == 0 {
		*(*YDbMask)(unsafe.Pointer(pToplevel + 124)) |= YDbMask(1) << iDb
		if !(0 != 0) && iDb == 1 {
			Xsqlite3OpenTempDatabase(tls, pToplevel)
		}
	}
}

func Xsqlite3CodeVerifySchema(tls *libc.TLS, pParse uintptr, iDb int32) {
	sqlite3CodeVerifySchemaAtToplevel(tls, func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}(), iDb)
}

func Xsqlite3CodeVerifyNamedSchema(tls *libc.TLS, pParse uintptr, zDb uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var i int32
	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pDb uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32
		if (*Db)(unsafe.Pointer(pDb)).FpBt != 0 && (!(zDb != 0) || 0 == Xsqlite3StrICmp(tls, zDb, (*Db)(unsafe.Pointer(pDb)).FzDbSName)) {
			Xsqlite3CodeVerifySchema(tls, pParse, i)
		}
	}
}

func Xsqlite3BeginWriteOperation(tls *libc.TLS, pParse uintptr, setStatement int32, iDb int32) {
	var pToplevel uintptr = func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}()
	sqlite3CodeVerifySchemaAtToplevel(tls, pToplevel, iDb)
	*(*YDbMask)(unsafe.Pointer(pToplevel + 120)) |= YDbMask(1) << iDb
	*(*U8)(unsafe.Pointer(pToplevel + 32)) |= U8(setStatement)
}

func Xsqlite3MultiWrite(tls *libc.TLS, pParse uintptr) {
	var pToplevel uintptr = func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}()
	(*Parse)(unsafe.Pointer(pToplevel)).FisMultiWrite = U8(1)
}

func Xsqlite3MayAbort(tls *libc.TLS, pParse uintptr) {
	var pToplevel uintptr = func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}()
	(*Parse)(unsafe.Pointer(pToplevel)).FmayAbort = U8(1)
}

func Xsqlite3HaltConstraint(tls *libc.TLS, pParse uintptr, errCode int32, onError int32, p4 uintptr, p4type I8, p5Errmsg U8) {
	var v uintptr

	v = Xsqlite3GetVdbe(tls, pParse)

	if onError == OE_Abort {
		Xsqlite3MayAbort(tls, pParse)
	}
	Xsqlite3VdbeAddOp4(tls, v, OP_Halt, errCode, onError, 0, p4, int32(p4type))
	Xsqlite3VdbeChangeP5(tls, v, uint16(p5Errmsg))
}

func Xsqlite3UniqueConstraint(tls *libc.TLS, pParse uintptr, onError int32, pIdx uintptr) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var zErr uintptr
	var j int32

	var pTab uintptr = (*Index)(unsafe.Pointer(pIdx)).FpTable

	Xsqlite3StrAccumInit(tls, bp+8, (*Parse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), 0,
		*(*int32)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb + 136)))
	if (*Index)(unsafe.Pointer(pIdx)).FaColExpr != 0 {
		Xsqlite3_str_appendf(tls, bp+8, ts+18025, libc.VaList(bp, (*Index)(unsafe.Pointer(pIdx)).FzName))
	} else {
		for j = 0; j < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol); j++ {
			var zCol uintptr

			zCol = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)))*24)).FzCnName
			if j != 0 {
				Xsqlite3_str_append(tls, bp+8, ts+18036, 2)
			}
			Xsqlite3_str_appendall(tls, bp+8, (*Table)(unsafe.Pointer(pTab)).FzName)
			Xsqlite3_str_append(tls, bp+8, ts+1649, 1)
			Xsqlite3_str_appendall(tls, bp+8, zCol)
		}
	}
	zErr = Xsqlite3StrAccumFinish(tls, bp+8)
	Xsqlite3HaltConstraint(tls, pParse,
		func() int32 {
			if int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
				return SQLITE_CONSTRAINT | int32(6)<<8
			}
			return SQLITE_CONSTRAINT | int32(8)<<8
		}(),
		onError, zErr, int8(-6), uint8(P5_ConstraintUnique))
}

func Xsqlite3RowidConstraint(tls *libc.TLS, pParse uintptr, onError int32, pTab uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var zMsg uintptr
	var rc int32
	if int32((*Table)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
		zMsg = Xsqlite3MPrintf(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, ts+11397, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName,
			(*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr((*Table)(unsafe.Pointer(pTab)).FiPKey)*24)).FzCnName))
		rc = SQLITE_CONSTRAINT | int32(6)<<8
	} else {
		zMsg = Xsqlite3MPrintf(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, ts+11309, libc.VaList(bp+16, (*Table)(unsafe.Pointer(pTab)).FzName))
		rc = SQLITE_CONSTRAINT | int32(10)<<8
	}
	Xsqlite3HaltConstraint(tls, pParse, rc, onError, zMsg, int8(-6),
		uint8(P5_ConstraintUnique))
}

func collationMatch(tls *libc.TLS, zColl uintptr, pIndex uintptr) int32 {
	var i int32

	for i = 0; i < int32((*Index)(unsafe.Pointer(pIndex)).FnColumn); i++ {
		var z uintptr = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FazColl + uintptr(i)*8))

		if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(i)*2))) >= 0 && 0 == Xsqlite3StrICmp(tls, z, zColl) {
			return 1
		}
	}
	return 0
}

func reindexTable(tls *libc.TLS, pParse uintptr, pTab uintptr, zColl uintptr) {
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		var pIndex uintptr

		for pIndex = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIndex != 0; pIndex = (*Index)(unsafe.Pointer(pIndex)).FpNext {
			if zColl == uintptr(0) || collationMatch(tls, zColl, pIndex) != 0 {
				var iDb int32 = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Table)(unsafe.Pointer(pTab)).FpSchema)
				Xsqlite3BeginWriteOperation(tls, pParse, 0, iDb)
				sqlite3RefillIndex(tls, pParse, pIndex, -1)
			}
		}
	}
}

func reindexDatabases(tls *libc.TLS, pParse uintptr, zColl uintptr) {
	var pDb uintptr
	var iDb int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var k uintptr
	var pTab uintptr

	iDb = 0
	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb
__1:
	if !(iDb < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __3
	}
	{
		for k = (*Hash)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema + 8)).Ffirst; k != 0; k = (*HashElem)(unsafe.Pointer(k)).Fnext {
			pTab = (*HashElem)(unsafe.Pointer(k)).Fdata
			reindexTable(tls, pParse, pTab, zColl)
		}

	}
	goto __2
__2:
	iDb++
	pDb += 32
	goto __1
	goto __3
__3:
}

func Xsqlite3Reindex(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pColl uintptr
	var z uintptr
	var zDb uintptr
	var pTab uintptr
	var pIndex uintptr
	var iDb int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if SQLITE_OK != Xsqlite3ReadSchema(tls, pParse) {
		return
	}

	if pName1 == uintptr(0) {
		reindexDatabases(tls, pParse, uintptr(0))
		return
	} else if pName2 == uintptr(0) || (*Token)(unsafe.Pointer(pName2)).Fz == uintptr(0) {
		var zColl uintptr

		zColl = Xsqlite3NameFromToken(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pName1)
		if !(zColl != 0) {
			return
		}
		pColl = Xsqlite3FindCollSeq(tls, db, (*Sqlite3)(unsafe.Pointer(db)).Fenc, zColl, 0)
		if pColl != 0 {
			reindexDatabases(tls, pParse, zColl)
			Xsqlite3DbFree(tls, db, zColl)
			return
		}
		Xsqlite3DbFree(tls, db, zColl)
	}
	iDb = Xsqlite3TwoPartName(tls, pParse, pName1, pName2, bp)
	if iDb < 0 {
		return
	}
	z = Xsqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp)))
	if z == uintptr(0) {
		return
	}
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	pTab = Xsqlite3FindTable(tls, db, z, zDb)
	if pTab != 0 {
		reindexTable(tls, pParse, pTab, uintptr(0))
		Xsqlite3DbFree(tls, db, z)
		return
	}
	pIndex = Xsqlite3FindIndex(tls, db, z, zDb)
	Xsqlite3DbFree(tls, db, z)
	if pIndex != 0 {
		Xsqlite3BeginWriteOperation(tls, pParse, 0, iDb)
		sqlite3RefillIndex(tls, pParse, pIndex, -1)
		return
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+18039, 0)
}

func Xsqlite3KeyInfoOfIndex(tls *libc.TLS, pParse uintptr, pIdx uintptr) uintptr {
	var i int32
	var nCol int32 = int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
	var nKey int32 = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
	var pKey uintptr
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return uintptr(0)
	}
	if uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x8>>3)) != 0 {
		pKey = Xsqlite3KeyInfoAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, nKey, nCol-nKey)
	} else {
		pKey = Xsqlite3KeyInfoAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, nCol, 0)
	}
	if pKey != 0 {
		for i = 0; i < nCol; i++ {
			var zColl uintptr = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*8))
			*(*uintptr)(unsafe.Pointer(pKey + 32 + uintptr(i)*8)) = func() uintptr {
				if zColl == uintptr(unsafe.Pointer(&Xsqlite3StrBINARY)) {
					return uintptr(0)
				}
				return Xsqlite3LocateCollSeq(tls, pParse, zColl)
			}()
			*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pKey)).FaSortFlags + uintptr(i))) = *(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i)))

		}
		if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
			if int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x100>>8) == 0 {
				libc.SetBitFieldPtr16Uint32(pIdx+100, uint32(1), 8, 0x100)
				(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_ERROR | int32(2)<<8
			}
			Xsqlite3KeyInfoUnref(tls, pKey)
			pKey = uintptr(0)
		}
	}
	return pKey
}

func Xsqlite3CteNew(tls *libc.TLS, pParse uintptr, pName uintptr, pArglist uintptr, pQuery uintptr, eM10d U8) uintptr {
	var pNew uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	pNew = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Cte{})))

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		Xsqlite3ExprListDelete(tls, db, pArglist)
		Xsqlite3SelectDelete(tls, db, pQuery)
	} else {
		(*Cte)(unsafe.Pointer(pNew)).FpSelect = pQuery
		(*Cte)(unsafe.Pointer(pNew)).FpCols = pArglist
		(*Cte)(unsafe.Pointer(pNew)).FzName = Xsqlite3NameFromToken(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pName)
		(*Cte)(unsafe.Pointer(pNew)).FeM10d = eM10d
	}
	return pNew
}

func cteClear(tls *libc.TLS, db uintptr, pCte uintptr) {
	Xsqlite3ExprListDelete(tls, db, (*Cte)(unsafe.Pointer(pCte)).FpCols)
	Xsqlite3SelectDelete(tls, db, (*Cte)(unsafe.Pointer(pCte)).FpSelect)
	Xsqlite3DbFree(tls, db, (*Cte)(unsafe.Pointer(pCte)).FzName)
}

func Xsqlite3CteDelete(tls *libc.TLS, db uintptr, pCte uintptr) {
	cteClear(tls, db, pCte)
	Xsqlite3DbFree(tls, db, pCte)
}

func Xsqlite3WithAdd(tls *libc.TLS, pParse uintptr, pWith uintptr, pCte uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pNew uintptr
	var zName uintptr

	if pCte == uintptr(0) {
		return pWith
	}

	zName = (*Cte)(unsafe.Pointer(pCte)).FzName
	if zName != 0 && pWith != 0 {
		var i int32
		for i = 0; i < (*With)(unsafe.Pointer(pWith)).FnCte; i++ {
			if Xsqlite3StrICmp(tls, zName, (*Cte)(unsafe.Pointer(pWith+16+uintptr(i)*48)).FzName) == 0 {
				Xsqlite3ErrorMsg(tls, pParse, ts+18085, libc.VaList(bp, zName))
			}
		}
	}

	if pWith != 0 {
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(With{})) + uint64(unsafe.Sizeof(Cte{}))*uint64((*With)(unsafe.Pointer(pWith)).FnCte))
		pNew = Xsqlite3DbRealloc(tls, db, pWith, uint64(nByte))
	} else {
		pNew = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(With{})))
	}

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		Xsqlite3CteDelete(tls, db, pCte)
		pNew = pWith
	} else {
		*(*Cte)(unsafe.Pointer(pNew + 16 + uintptr(libc.PostIncInt32(&(*With)(unsafe.Pointer(pNew)).FnCte, 1))*48)) = *(*Cte)(unsafe.Pointer(pCte))
		Xsqlite3DbFree(tls, db, pCte)
	}

	return pNew
}

func Xsqlite3WithDelete(tls *libc.TLS, db uintptr, pWith uintptr) {
	if pWith != 0 {
		var i int32
		for i = 0; i < (*With)(unsafe.Pointer(pWith)).FnCte; i++ {
			cteClear(tls, db, pWith+16+uintptr(i)*48)
		}
		Xsqlite3DbFree(tls, db, pWith)
	}
}

func callCollNeeded(tls *libc.TLS, db uintptr, enc int32, zName uintptr) {
	if (*Sqlite3)(unsafe.Pointer(db)).FxCollNeeded != 0 {
		var zExternal uintptr = Xsqlite3DbStrDup(tls, db, zName)
		if !(zExternal != 0) {
			return
		}
		(*struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr)
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxCollNeeded})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpCollNeededArg, db, enc, zExternal)
		Xsqlite3DbFree(tls, db, zExternal)
	}
	if (*Sqlite3)(unsafe.Pointer(db)).FxCollNeeded16 != 0 {
		var zExternal uintptr
		var pTmp uintptr = Xsqlite3ValueNew(tls, db)
		Xsqlite3ValueSetStr(tls, pTmp, -1, zName, uint8(SQLITE_UTF8), uintptr(0))
		zExternal = Xsqlite3ValueText(tls, pTmp, uint8(SQLITE_UTF16LE))
		if zExternal != 0 {
			(*struct {
				f func(*libc.TLS, uintptr, uintptr, int32, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxCollNeeded16})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpCollNeededArg, db, int32((*Sqlite3)(unsafe.Pointer(db)).Fenc), zExternal)
		}
		Xsqlite3ValueFree(tls, pTmp)
	}
}

func synthCollSeq(tls *libc.TLS, db uintptr, pColl uintptr) int32 {
	var pColl2 uintptr
	var z uintptr = (*CollSeq)(unsafe.Pointer(pColl)).FzName
	var i int32
	for i = 0; i < 3; i++ {
		pColl2 = Xsqlite3FindCollSeq(tls, db, aEnc[i], z, 0)
		if (*CollSeq)(unsafe.Pointer(pColl2)).FxCmp != uintptr(0) {
			libc.Xmemcpy(tls, pColl, pColl2, uint64(unsafe.Sizeof(CollSeq{})))
			(*CollSeq)(unsafe.Pointer(pColl)).FxDel = uintptr(0)
			return SQLITE_OK
		}
	}
	return SQLITE_ERROR
}

var aEnc = [3]U8{U8(SQLITE_UTF16BE), U8(SQLITE_UTF16LE), U8(SQLITE_UTF8)}

func Xsqlite3CheckCollSeq(tls *libc.TLS, pParse uintptr, pColl uintptr) int32 {
	if pColl != 0 && (*CollSeq)(unsafe.Pointer(pColl)).FxCmp == uintptr(0) {
		var zName uintptr = (*CollSeq)(unsafe.Pointer(pColl)).FzName
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		var p uintptr = Xsqlite3GetCollSeq(tls, pParse, (*Sqlite3)(unsafe.Pointer(db)).Fenc, pColl, zName)
		if !(p != 0) {
			return SQLITE_ERROR
		}

	}
	return SQLITE_OK
}

func findCollSeqEntry(tls *libc.TLS, db uintptr, zName uintptr, create int32) uintptr {
	var pColl uintptr
	pColl = Xsqlite3HashFind(tls, db+648, zName)

	if uintptr(0) == pColl && create != 0 {
		var nName int32 = Xsqlite3Strlen30(tls, zName) + 1
		pColl = Xsqlite3DbMallocZero(tls, db, uint64(3)*uint64(unsafe.Sizeof(CollSeq{}))+uint64(nName))
		if pColl != 0 {
			var pDel uintptr = uintptr(0)
			(*CollSeq)(unsafe.Pointer(pColl)).FzName = pColl + 3*40
			(*CollSeq)(unsafe.Pointer(pColl)).Fenc = U8(SQLITE_UTF8)
			(*CollSeq)(unsafe.Pointer(pColl + 1*40)).FzName = pColl + 3*40
			(*CollSeq)(unsafe.Pointer(pColl + 1*40)).Fenc = U8(SQLITE_UTF16LE)
			(*CollSeq)(unsafe.Pointer(pColl + 2*40)).FzName = pColl + 3*40
			(*CollSeq)(unsafe.Pointer(pColl + 2*40)).Fenc = U8(SQLITE_UTF16BE)
			libc.Xmemcpy(tls, (*CollSeq)(unsafe.Pointer(pColl)).FzName, zName, uint64(nName))
			pDel = Xsqlite3HashInsert(tls, db+648, (*CollSeq)(unsafe.Pointer(pColl)).FzName, pColl)

			if pDel != uintptr(0) {
				Xsqlite3OomFault(tls, db)
				Xsqlite3DbFree(tls, db, pDel)
				pColl = uintptr(0)
			}
		}
	}
	return pColl
}

func Xsqlite3FindCollSeq(tls *libc.TLS, db uintptr, enc U8, zName uintptr, create int32) uintptr {
	var pColl uintptr

	if zName != 0 {
		pColl = findCollSeqEntry(tls, db, zName, create)
		if pColl != 0 {
			pColl += 40 * uintptr(int32(enc)-1)
		}
	} else {
		pColl = (*Sqlite3)(unsafe.Pointer(db)).FpDfltColl
	}
	return pColl
}

func Xsqlite3SetTextEncoding(tls *libc.TLS, db uintptr, enc U8) {
	(*Sqlite3)(unsafe.Pointer(db)).Fenc = enc

	(*Sqlite3)(unsafe.Pointer(db)).FpDfltColl = Xsqlite3FindCollSeq(tls, db, enc, uintptr(unsafe.Pointer(&Xsqlite3StrBINARY)), 0)
}

func Xsqlite3GetCollSeq(tls *libc.TLS, pParse uintptr, enc U8, pColl uintptr, zName uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	p = pColl
	if !(p != 0) {
		p = Xsqlite3FindCollSeq(tls, db, enc, zName, 0)
	}
	if !(p != 0) || !(int32((*CollSeq)(unsafe.Pointer(p)).FxCmp) != 0) {
		callCollNeeded(tls, db, int32(enc), zName)
		p = Xsqlite3FindCollSeq(tls, db, enc, zName, 0)
	}
	if p != 0 && !(int32((*CollSeq)(unsafe.Pointer(p)).FxCmp) != 0) && synthCollSeq(tls, db, p) != 0 {
		p = uintptr(0)
	}

	if p == uintptr(0) {
		Xsqlite3ErrorMsg(tls, pParse, ts+18115, libc.VaList(bp, zName))
		(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_ERROR | int32(1)<<8
	}
	return p
}

func Xsqlite3LocateCollSeq(tls *libc.TLS, pParse uintptr, zName uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var enc U8 = (*Sqlite3)(unsafe.Pointer(db)).Fenc
	var initbusy U8 = (*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy
	var pColl uintptr

	pColl = Xsqlite3FindCollSeq(tls, db, enc, zName, int32(initbusy))
	if !(initbusy != 0) && (!(pColl != 0) || !(int32((*CollSeq)(unsafe.Pointer(pColl)).FxCmp) != 0)) {
		pColl = Xsqlite3GetCollSeq(tls, pParse, enc, pColl, zName)
	}

	return pColl
}

func matchQuality(tls *libc.TLS, p uintptr, nArg int32, enc U8) int32 {
	var match int32

	if int32((*FuncDef)(unsafe.Pointer(p)).FnArg) != nArg {
		if nArg == -2 {
			if (*FuncDef)(unsafe.Pointer(p)).FxSFunc == uintptr(0) {
				return 0
			}
			return FUNC_PERFECT_MATCH
		}
		if int32((*FuncDef)(unsafe.Pointer(p)).FnArg) >= 0 {
			return 0
		}
	}

	if int32((*FuncDef)(unsafe.Pointer(p)).FnArg) == nArg {
		match = 4
	} else {
		match = 1
	}

	if U32(enc) == (*FuncDef)(unsafe.Pointer(p)).FfuncFlags&U32(SQLITE_FUNC_ENCMASK) {
		match = match + 2
	} else if U32(enc)&(*FuncDef)(unsafe.Pointer(p)).FfuncFlags&U32(2) != U32(0) {
		match = match + 1
	}

	return match
}

func Xsqlite3FunctionSearch(tls *libc.TLS, h int32, zFunc uintptr) uintptr {
	var p uintptr
	for p = *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&Xsqlite3BuiltinFunctions)) + uintptr(h)*8)); p != 0; p = *(*uintptr)(unsafe.Pointer(p + 64)) {
		if Xsqlite3StrICmp(tls, (*FuncDef)(unsafe.Pointer(p)).FzName, zFunc) == 0 {
			return p
		}
	}
	return uintptr(0)
}

func Xsqlite3InsertBuiltinFuncs(tls *libc.TLS, aDef uintptr, nDef int32) {
	var i int32
	for i = 0; i < nDef; i++ {
		var pOther uintptr
		var zName uintptr = (*FuncDef)(unsafe.Pointer(aDef + uintptr(i)*72)).FzName
		var nName int32 = Xsqlite3Strlen30(tls, zName)
		var h int32 = (int32(*(*uint8)(unsafe.Pointer(zName))) + nName) % SQLITE_FUNC_HASH_SZ

		pOther = Xsqlite3FunctionSearch(tls, h, zName)
		if pOther != 0 {
			(*FuncDef)(unsafe.Pointer(aDef + uintptr(i)*72)).FpNext = (*FuncDef)(unsafe.Pointer(pOther)).FpNext
			(*FuncDef)(unsafe.Pointer(pOther)).FpNext = aDef + uintptr(i)*72
		} else {
			(*FuncDef)(unsafe.Pointer(aDef + uintptr(i)*72)).FpNext = uintptr(0)
			*(*uintptr)(unsafe.Pointer(aDef + uintptr(i)*72 + 64)) = *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&Xsqlite3BuiltinFunctions)) + uintptr(h)*8))
			*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&Xsqlite3BuiltinFunctions)) + uintptr(h)*8)) = aDef + uintptr(i)*72
		}
	}
}

func Xsqlite3FindFunction(tls *libc.TLS, db uintptr, zName uintptr, nArg int32, enc U8, createFlag U8) uintptr {
	var p uintptr
	var pBest uintptr = uintptr(0)
	var bestScore int32 = 0
	var h int32
	var nName int32

	nName = Xsqlite3Strlen30(tls, zName)

	p = Xsqlite3HashFind(tls, db+624, zName)
	for p != 0 {
		var score int32 = matchQuality(tls, p, nArg, enc)
		if score > bestScore {
			pBest = p
			bestScore = score
		}
		p = (*FuncDef)(unsafe.Pointer(p)).FpNext
	}

	if !(createFlag != 0) && (pBest == uintptr(0) || (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_PreferBuiltin) != U32(0)) {
		bestScore = 0
		h = (int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(zName))]) + nName) % SQLITE_FUNC_HASH_SZ
		p = Xsqlite3FunctionSearch(tls, h, zName)
		for p != 0 {
			var score int32 = matchQuality(tls, p, nArg, enc)
			if score > bestScore {
				pBest = p
				bestScore = score
			}
			p = (*FuncDef)(unsafe.Pointer(p)).FpNext
		}
	}

	if createFlag != 0 && bestScore < FUNC_PERFECT_MATCH && libc.AssignUintptr(&pBest, Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(FuncDef{}))+uint64(nName)+uint64(1))) != uintptr(0) {
		var pOther uintptr
		var z uintptr
		(*FuncDef)(unsafe.Pointer(pBest)).FzName = pBest + 1*72
		(*FuncDef)(unsafe.Pointer(pBest)).FnArg = I8(U16(nArg))
		(*FuncDef)(unsafe.Pointer(pBest)).FfuncFlags = U32(enc)
		libc.Xmemcpy(tls, pBest+1*72, zName, uint64(nName+1))
		for z = (*FuncDef)(unsafe.Pointer(pBest)).FzName; *(*U8)(unsafe.Pointer(z)) != 0; z++ {
			*(*U8)(unsafe.Pointer(z)) = Xsqlite3UpperToLower[*(*U8)(unsafe.Pointer(z))]
		}
		pOther = Xsqlite3HashInsert(tls, db+624, (*FuncDef)(unsafe.Pointer(pBest)).FzName, pBest)
		if pOther == pBest {
			Xsqlite3DbFree(tls, db, pBest)
			Xsqlite3OomFault(tls, db)
			return uintptr(0)
		} else {
			(*FuncDef)(unsafe.Pointer(pBest)).FpNext = pOther
		}
	}

	if pBest != 0 && ((*FuncDef)(unsafe.Pointer(pBest)).FxSFunc != 0 || createFlag != 0) {
		return pBest
	}
	return uintptr(0)
}

func Xsqlite3SchemaClear(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(896)
	defer tls.Free(896)

	var pElem uintptr
	var pSchema uintptr = p

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Sqlite3{})))
	*(*Hash)(unsafe.Pointer(bp + 872)) = (*Schema)(unsafe.Pointer(pSchema)).FtblHash
	*(*Hash)(unsafe.Pointer(bp + 848)) = (*Schema)(unsafe.Pointer(pSchema)).FtrigHash
	Xsqlite3HashInit(tls, pSchema+56)
	Xsqlite3HashClear(tls, pSchema+32)
	for pElem = (*Hash)(unsafe.Pointer(bp + 848)).Ffirst; pElem != 0; pElem = (*HashElem)(unsafe.Pointer(pElem)).Fnext {
		Xsqlite3DeleteTrigger(tls, bp, (*HashElem)(unsafe.Pointer(pElem)).Fdata)
	}
	Xsqlite3HashClear(tls, bp+848)
	Xsqlite3HashInit(tls, pSchema+8)
	for pElem = (*Hash)(unsafe.Pointer(bp + 872)).Ffirst; pElem != 0; pElem = (*HashElem)(unsafe.Pointer(pElem)).Fnext {
		var pTab uintptr = (*HashElem)(unsafe.Pointer(pElem)).Fdata
		Xsqlite3DeleteTable(tls, bp, pTab)
	}
	Xsqlite3HashClear(tls, bp+872)
	Xsqlite3HashClear(tls, pSchema+80)
	(*Schema)(unsafe.Pointer(pSchema)).FpSeqTab = uintptr(0)
	if int32((*Schema)(unsafe.Pointer(pSchema)).FschemaFlags)&DB_SchemaLoaded != 0 {
		(*Schema)(unsafe.Pointer(pSchema)).FiGeneration++
	}
	*(*U16)(unsafe.Pointer(pSchema + 114)) &= libc.Uint16FromInt32(libc.CplInt32(DB_SchemaLoaded | DB_ResetWanted))
}

func Xsqlite3SchemaGet(tls *libc.TLS, db uintptr, pBt uintptr) uintptr {
	var p uintptr
	if pBt != 0 {
		p = Xsqlite3BtreeSchema(tls, pBt, int32(unsafe.Sizeof(Schema{})), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3SchemaClear})))
	} else {
		p = Xsqlite3DbMallocZero(tls, uintptr(0), uint64(unsafe.Sizeof(Schema{})))
	}
	if !(p != 0) {
		Xsqlite3OomFault(tls, db)
	} else if 0 == int32((*Schema)(unsafe.Pointer(p)).Ffile_format) {
		Xsqlite3HashInit(tls, p+8)
		Xsqlite3HashInit(tls, p+32)
		Xsqlite3HashInit(tls, p+56)
		Xsqlite3HashInit(tls, p+80)
		(*Schema)(unsafe.Pointer(p)).Fenc = U8(SQLITE_UTF8)
	}
	return p
}

func Xsqlite3SrcListLookup(tls *libc.TLS, pParse uintptr, pSrc uintptr) uintptr {
	var pItem uintptr = pSrc + 8
	var pTab uintptr

	pTab = Xsqlite3LocateTableItem(tls, pParse, uint32(0), pItem)
	Xsqlite3DeleteTable(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*SrcItem)(unsafe.Pointer(pItem)).FpTab)
	(*SrcItem)(unsafe.Pointer(pItem)).FpTab = pTab
	if pTab != 0 {
		(*Table)(unsafe.Pointer(pTab)).FnTabRef++
		if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x2>>1)) != 0 && Xsqlite3IndexedByLookup(tls, pParse, pItem) != 0 {
			pTab = uintptr(0)
		}
	}
	return pTab
}

func Xsqlite3CodeChangeCount(tls *libc.TLS, v uintptr, regCounter int32, zColName uintptr) {
	Xsqlite3VdbeAddOp0(tls, v, OP_FkCheck)
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, regCounter, 1)
	Xsqlite3VdbeSetNumCols(tls, v, 1)
	Xsqlite3VdbeSetColName(tls, v, 0, COLNAME_NAME, zColName, uintptr(0))
}

func vtabIsReadOnly(tls *libc.TLS, pParse uintptr, pTab uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer((*VTable)(unsafe.Pointer(Xsqlite3GetVTable(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pTab))).FpMod)).FpModule)).FxUpdate == uintptr(0) {
		return 1
	}

	if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != uintptr(0) &&
		int32((*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)))).FeVtabRisk) > libc.Bool32((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
		Xsqlite3ErrorMsg(tls, pParse, ts+18146,
			libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
	}
	return 0
}

func tabIsReadOnly(tls *libc.TLS, pParse uintptr, pTab uintptr) int32 {
	var db uintptr
	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
		return vtabIsReadOnly(tls, pParse, pTab)
	}
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Readonly|TF_Shadow) == U32(0) {
		return 0
	}
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Readonly) != U32(0) {
		return libc.Bool32(Xsqlite3WritableSchema(tls, db) == 0 && int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0)
	}

	return Xsqlite3ReadOnlyShadowTables(tls, db)
}

func Xsqlite3IsReadOnly(tls *libc.TLS, pParse uintptr, pTab uintptr, viewOk int32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if tabIsReadOnly(tls, pParse, pTab) != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+18179, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
		return 1
	}
	if !(viewOk != 0) && int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW {
		Xsqlite3ErrorMsg(tls, pParse, ts+18208, libc.VaList(bp+8, (*Table)(unsafe.Pointer(pTab)).FzName))
		return 1
	}
	return 0
}

func Xsqlite3MaterializeView(tls *libc.TLS, pParse uintptr, pView uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr, iCur int32) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var pSel uintptr
	var pFrom uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var iDb int32 = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pView)).FpSchema)
	pWhere = Xsqlite3ExprDup(tls, db, pWhere, 0)
	pFrom = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
	if pFrom != 0 {
		(*SrcItem)(unsafe.Pointer(pFrom + 8)).FzName = Xsqlite3DbStrDup(tls, db, (*Table)(unsafe.Pointer(pView)).FzName)
		(*SrcItem)(unsafe.Pointer(pFrom + 8)).FzDatabase = Xsqlite3DbStrDup(tls, db, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName)

	}
	pSel = Xsqlite3SelectNew(tls, pParse, uintptr(0), pFrom, pWhere, uintptr(0), uintptr(0), pOrderBy,
		uint32(SF_IncludeHidden), pLimit)
	Xsqlite3SelectDestInit(tls, bp, SRT_EphemTab, iCur)
	Xsqlite3Select(tls, pParse, pSel, bp)
	Xsqlite3SelectDelete(tls, db, pSel)
}

func Xsqlite3DeleteFrom(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr) {
	bp := tls.Alloc(88)
	defer tls.Free(88)

	var v uintptr
	var pTab uintptr
	var i int32
	var pWInfo uintptr
	var pIdx uintptr
	var iTabCur int32

	var nIdx int32
	var db uintptr

	var iDb int32
	var memCnt int32
	var rcauth int32
	var eOnePass int32

	var aToOpen uintptr
	var pPk uintptr
	var iPk int32
	var nPk I16
	var iKey int32
	var nKey I16
	var iEphCur int32
	var iRowSet int32
	var addrBypass int32
	var addrLoop int32
	var addrEphOpen int32
	var bComplex int32

	var isView int32
	var pTrigger uintptr
	var iAddrOnce int32
	var pVTab uintptr
	var count int32
	var wcf U16
	*(*int32)(unsafe.Pointer(bp + 80)) = 0
	*(*int32)(unsafe.Pointer(bp + 84)) = 0
	memCnt = 0
	aToOpen = uintptr(0)
	iPk = 0
	nPk = int16(1)
	iEphCur = 0
	iRowSet = 0
	addrBypass = 0
	addrLoop = 0
	addrEphOpen = 0

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(AuthContext{})))
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __1
	}
	goto delete_from_cleanup
__1:
	;
	pTab = Xsqlite3SrcListLookup(tls, pParse, pTabList)
	if !(pTab == uintptr(0)) {
		goto __2
	}
	goto delete_from_cleanup
__2:
	;
	pTrigger = Xsqlite3TriggersExist(tls, pParse, pTab, TK_DELETE, uintptr(0), uintptr(0))
	isView = libc.Bool32(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW)
	bComplex = libc.Bool32(pTrigger != 0 || Xsqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0)

	if !(Xsqlite3ViewGetColumnNames(tls, pParse, pTab) != 0) {
		goto __3
	}
	goto delete_from_cleanup
__3:
	;
	if !(Xsqlite3IsReadOnly(tls, pParse, pTab, func() int32 {
		if pTrigger != 0 {
			return 1
		}
		return 0
	}()) != 0) {
		goto __4
	}
	goto delete_from_cleanup
__4:
	;
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	rcauth = Xsqlite3AuthCheck(tls, pParse, SQLITE_DELETE, (*Table)(unsafe.Pointer(pTab)).FzName, uintptr(0),
		(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName)

	if !(rcauth == SQLITE_DENY) {
		goto __5
	}
	goto delete_from_cleanup
__5:
	;
	iTabCur = libc.AssignPtrInt32(pTabList+8+68, libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1))
	nIdx = 0
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__6:
	if !(pIdx != 0) {
		goto __8
	}
	(*Parse)(unsafe.Pointer(pParse)).FnTab++
	goto __7
__7:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	nIdx++
	goto __6
	goto __8
__8:
	;
	if !(isView != 0) {
		goto __9
	}
	Xsqlite3AuthContextPush(tls, pParse, bp, (*Table)(unsafe.Pointer(pTab)).FzName)
__9:
	;
	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v == uintptr(0)) {
		goto __10
	}
	goto delete_from_cleanup
__10:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0) {
		goto __11
	}
	Xsqlite3VdbeCountChanges(tls, v)
__11:
	;
	Xsqlite3BeginWriteOperation(tls, pParse, bComplex, iDb)

	if !(isView != 0) {
		goto __12
	}
	Xsqlite3MaterializeView(tls, pParse, pTab,
		pWhere, pOrderBy, pLimit, iTabCur)
	*(*int32)(unsafe.Pointer(bp + 80)) = libc.AssignPtrInt32(bp+84, iTabCur)
	pOrderBy = uintptr(0)
	pLimit = uintptr(0)
__12:
	;
	libc.Xmemset(tls, bp+16, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp + 16)).FpParse = pParse
	(*NameContext)(unsafe.Pointer(bp + 16)).FpSrcList = pTabList
	if !(Xsqlite3ResolveExprNames(tls, bp+16, pWhere) != 0) {
		goto __13
	}
	goto delete_from_cleanup
__13:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&(uint64(0x00001)<<32) != uint64(0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) != 0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FpTriggerTab) != 0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FbReturning) != 0)) {
		goto __14
	}
	memCnt = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, memCnt)
__14:
	;
	if !(rcauth == SQLITE_OK &&
		pWhere == uintptr(0) &&
		!(bComplex != 0) &&
		!(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) &&
		(*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback == uintptr(0)) {
		goto __15
	}

	Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab)).Ftnum, uint8(1), (*Table)(unsafe.Pointer(pTab)).FzName)
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __17
	}
	Xsqlite3VdbeAddOp4(tls, v, OP_Clear, int32((*Table)(unsafe.Pointer(pTab)).Ftnum), iDb, func() int32 {
		if memCnt != 0 {
			return memCnt
		}
		return -1
	}(),
		(*Table)(unsafe.Pointer(pTab)).FzName, -1)
__17:
	;
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__18:
	if !(pIdx != 0) {
		goto __20
	}

	if !(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY && !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0))) {
		goto __21
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Clear, int32((*Index)(unsafe.Pointer(pIdx)).Ftnum), iDb, func() int32 {
		if memCnt != 0 {
			return memCnt
		}
		return -1
	}())
	goto __22
__21:
	Xsqlite3VdbeAddOp2(tls, v, OP_Clear, int32((*Index)(unsafe.Pointer(pIdx)).Ftnum), iDb)
__22:
	;
	goto __19
__19:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	goto __18
	goto __20
__20:
	;
	goto __16
__15:
	wcf = U16(WHERE_ONEPASS_DESIRED | WHERE_DUPLICATES_OK)
	if !((*NameContext)(unsafe.Pointer(bp+16)).FncFlags&NC_Subquery != 0) {
		goto __23
	}
	bComplex = 1
__23:
	;
	wcf = U16(int32(wcf) | func() int32 {
		if bComplex != 0 {
			return 0
		}
		return WHERE_ONEPASS_MULTIROW
	}())
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __24
	}

	pPk = uintptr(0)
	nPk = int16(1)
	iRowSet = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, iRowSet)
	goto __25
__24:
	pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)

	nPk = I16((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
	iPk = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32(nPk)
	iEphCur = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	addrEphOpen = Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, iEphCur, int32(nPk))
	Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
__25:
	;
	pWInfo = Xsqlite3WhereBegin(tls, pParse, pTabList, pWhere, uintptr(0), uintptr(0), uintptr(0), wcf, iTabCur+1)
	if !(pWInfo == uintptr(0)) {
		goto __26
	}
	goto delete_from_cleanup
__26:
	;
	eOnePass = Xsqlite3WhereOkOnePass(tls, pWInfo, bp+72)

	if !(eOnePass != ONEPASS_SINGLE) {
		goto __27
	}
	Xsqlite3MultiWrite(tls, pParse)
__27:
	;
	if !(Xsqlite3WhereUsesDeferredSeek(tls, pWInfo) != 0) {
		goto __28
	}
	Xsqlite3VdbeAddOp1(tls, v, OP_FinishSeek, iTabCur)
__28:
	;
	if !(memCnt != 0) {
		goto __29
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, memCnt, 1)
__29:
	;
	if !(pPk != 0) {
		goto __30
	}
	i = 0
__32:
	if !(i < int32(nPk)) {
		goto __34
	}

	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur,
		int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
	goto __33
__33:
	i++
	goto __32
	goto __34
__34:
	;
	iKey = iPk
	goto __31
__30:
	iKey = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iTabCur, -1, iKey)
__31:
	;
	if !(eOnePass != ONEPASS_OFF) {
		goto __35
	}

	nKey = nPk
	aToOpen = Xsqlite3DbMallocRawNN(tls, db, uint64(nIdx+2))
	if !(aToOpen == uintptr(0)) {
		goto __37
	}
	Xsqlite3WhereEnd(tls, pWInfo)
	goto delete_from_cleanup
__37:
	;
	libc.Xmemset(tls, aToOpen, 1, uint64(nIdx+1))
	*(*U8)(unsafe.Pointer(aToOpen + uintptr(nIdx+1))) = U8(0)
	if !(*(*int32)(unsafe.Pointer(bp + 72)) >= 0) {
		goto __38
	}
	*(*U8)(unsafe.Pointer(aToOpen + uintptr(*(*int32)(unsafe.Pointer(bp + 72))-iTabCur))) = U8(0)
__38:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 72 + 1*4)) >= 0) {
		goto __39
	}
	*(*U8)(unsafe.Pointer(aToOpen + uintptr(*(*int32)(unsafe.Pointer(bp + 72 + 1*4))-iTabCur))) = U8(0)
__39:
	;
	if !(addrEphOpen != 0) {
		goto __40
	}
	Xsqlite3VdbeChangeToNoop(tls, v, addrEphOpen)
__40:
	;
	addrBypass = Xsqlite3VdbeMakeLabel(tls, pParse)
	goto __36
__35:
	if !(pPk != 0) {
		goto __41
	}

	iKey = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	nKey = int16(0)
	Xsqlite3VdbeAddOp4(tls, v, OP_MakeRecord, iPk, int32(nPk), iKey,
		Xsqlite3IndexAffinityStr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pPk), int32(nPk))
	Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iEphCur, iKey, iPk, int32(nPk))
	goto __42
__41:
	nKey = int16(1)
	Xsqlite3VdbeAddOp2(tls, v, OP_RowSetAdd, iRowSet, iKey)
__42:
	;
	Xsqlite3WhereEnd(tls, pWInfo)
__36:
	;
	if !!(isView != 0) {
		goto __43
	}
	iAddrOnce = 0
	if !(eOnePass == ONEPASS_MULTI) {
		goto __44
	}
	iAddrOnce = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
__44:
	;
	Xsqlite3OpenTableAndIndices(tls, pParse, pTab, OP_OpenWrite, uint8(OPFLAG_FORDELETE),
		iTabCur, aToOpen, bp+80, bp+84)

	if !(eOnePass == ONEPASS_MULTI) {
		goto __45
	}
	Xsqlite3VdbeJumpHereOrPopInst(tls, v, iAddrOnce)
__45:
	;
__43:
	;
	if !(eOnePass != ONEPASS_OFF) {
		goto __46
	}

	if !(!(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) && *(*U8)(unsafe.Pointer(aToOpen + uintptr(*(*int32)(unsafe.Pointer(bp + 80))-iTabCur))) != 0) {
		goto __48
	}

	Xsqlite3VdbeAddOp4Int(tls, v, OP_NotFound, *(*int32)(unsafe.Pointer(bp + 80)), addrBypass, iKey, int32(nKey))

__48:
	;
	goto __47
__46:
	if !(pPk != 0) {
		goto __49
	}
	addrLoop = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, iEphCur)
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __51
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, iEphCur, 0, iKey)
	goto __52
__51:
	Xsqlite3VdbeAddOp2(tls, v, OP_RowData, iEphCur, iKey)
__52:
	;
	goto __50
__49:
	addrLoop = Xsqlite3VdbeAddOp3(tls, v, OP_RowSetRead, iRowSet, 0, iKey)

__50:
	;
__47:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __53
	}
	pVTab = Xsqlite3GetVTable(tls, db, pTab)
	Xsqlite3VtabMakeWritable(tls, pParse, pTab)

	Xsqlite3MayAbort(tls, pParse)
	if !(eOnePass == ONEPASS_SINGLE) {
		goto __55
	}
	Xsqlite3VdbeAddOp1(tls, v, OP_Close, iTabCur)
	if !((*Parse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0)) {
		goto __56
	}
	(*Parse)(unsafe.Pointer(pParse)).FisMultiWrite = U8(0)
__56:
	;
__55:
	;
	Xsqlite3VdbeAddOp4(tls, v, OP_VUpdate, 0, 1, iKey, pVTab, -11)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OE_Abort))
	goto __54
__53:
	count = libc.Bool32(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0)
	Xsqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, *(*int32)(unsafe.Pointer(bp + 80)), *(*int32)(unsafe.Pointer(bp + 84)),
		iKey, nKey, uint8(count), uint8(OE_Default), uint8(eOnePass), *(*int32)(unsafe.Pointer(bp + 72 + 1*4)))
__54:
	;
	if !(eOnePass != ONEPASS_OFF) {
		goto __57
	}
	Xsqlite3VdbeResolveLabel(tls, v, addrBypass)
	Xsqlite3WhereEnd(tls, pWInfo)
	goto __58
__57:
	if !(pPk != 0) {
		goto __59
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, iEphCur, addrLoop+1)
	Xsqlite3VdbeJumpHere(tls, v, addrLoop)
	goto __60
__59:
	Xsqlite3VdbeGoto(tls, v, addrLoop)
	Xsqlite3VdbeJumpHere(tls, v, addrLoop)
__60:
	;
__58:
	;
__16:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0)) {
		goto __61
	}
	Xsqlite3AutoincrementEnd(tls, pParse)
__61:
	;
	if !(memCnt != 0) {
		goto __62
	}
	Xsqlite3CodeChangeCount(tls, v, memCnt, ts+18246)
__62:
	;
delete_from_cleanup:
	Xsqlite3AuthContextPop(tls, bp)
	Xsqlite3SrcListDelete(tls, db, pTabList)
	Xsqlite3ExprDelete(tls, db, pWhere)
	if !(aToOpen != 0) {
		goto __63
	}
	Xsqlite3DbNNFreeNN(tls, db, aToOpen)
__63:
	;
	return
}

func Xsqlite3GenerateRowDelete(tls *libc.TLS, pParse uintptr, pTab uintptr, pTrigger uintptr, iDataCur int32, iIdxCur int32, iPk int32, nPk I16, count U8, onconf U8, eMode U8, iIdxNoSeek int32) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var iOld int32 = 0
	var iLabel int32
	var opSeek U8

	iLabel = Xsqlite3VdbeMakeLabel(tls, pParse)
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
		opSeek = uint8(OP_NotExists)
	} else {
		opSeek = uint8(OP_NotFound)
	}
	if int32(eMode) == ONEPASS_OFF {
		Xsqlite3VdbeAddOp4Int(tls, v, int32(opSeek), iDataCur, iLabel, iPk, int32(nPk))

	}

	if Xsqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0 || pTrigger != 0 {
		var mask U32
		var iCol int32
		var addrStart int32

		mask = Xsqlite3TriggerColmask(tls,
			pParse, pTrigger, uintptr(0), 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, int32(onconf))
		mask = mask | Xsqlite3FkOldmask(tls, pParse, pTab)
		iOld = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += 1 + int32((*Table)(unsafe.Pointer(pTab)).FnCol)

		Xsqlite3VdbeAddOp2(tls, v, OP_Copy, iPk, iOld)
		for iCol = 0; iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol); iCol++ {
			if mask == 0xffffffff || iCol <= 31 && mask&(uint32(1)<<iCol) != U32(0) {
				var kk int32 = int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(iCol)))
				Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, iCol, iOld+kk+1)
			}
		}

		addrStart = Xsqlite3VdbeCurrentAddr(tls, v)
		Xsqlite3CodeRowTrigger(tls, pParse, pTrigger,
			TK_DELETE, uintptr(0), TRIGGER_BEFORE, pTab, iOld, int32(onconf), iLabel)

		if addrStart < Xsqlite3VdbeCurrentAddr(tls, v) {
			Xsqlite3VdbeAddOp4Int(tls, v, int32(opSeek), iDataCur, iLabel, iPk, int32(nPk))

			iIdxNoSeek = -1
		}

		Xsqlite3FkCheck(tls, pParse, pTab, iOld, 0, uintptr(0), 0)
	}

	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		var p5 U8 = U8(0)
		Xsqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, uintptr(0), iIdxNoSeek)
		Xsqlite3VdbeAddOp2(tls, v, OP_Delete, iDataCur, func() int32 {
			if count != 0 {
				return OPFLAG_NCHANGE
			}
			return 0
		}())
		if int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0 || 0 == Xsqlite3_stricmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName, ts+14732) {
			Xsqlite3VdbeAppendP4(tls, v, pTab, -5)
		}
		if int32(eMode) != ONEPASS_OFF {
			Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_AUXDELETE))
		}
		if iIdxNoSeek >= 0 && iIdxNoSeek != iDataCur {
			Xsqlite3VdbeAddOp1(tls, v, OP_Delete, iIdxNoSeek)
		}
		if int32(eMode) == ONEPASS_MULTI {
			p5 = U8(int32(p5) | OPFLAG_SAVEPOSITION)
		}
		Xsqlite3VdbeChangeP5(tls, v, uint16(p5))
	}

	Xsqlite3FkActions(tls, pParse, pTab, uintptr(0), iOld, uintptr(0), 0)

	Xsqlite3CodeRowTrigger(tls, pParse, pTrigger,
		TK_DELETE, uintptr(0), TRIGGER_AFTER, pTab, iOld, int32(onconf), iLabel)

	Xsqlite3VdbeResolveLabel(tls, v, iLabel)

}

func Xsqlite3GenerateRowIndexDelete(tls *libc.TLS, pParse uintptr, pTab uintptr, iDataCur int32, iIdxCur int32, aRegIdx uintptr, iIdxNoSeek int32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var i int32
	var r1 int32 = -1

	var pIdx uintptr
	var pPrior uintptr = uintptr(0)
	var v uintptr
	var pPk uintptr

	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
		pPk = uintptr(0)
	} else {
		pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)
	}
	i = 0
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__1:
	if !(pIdx != 0) {
		goto __3
	}
	{
		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 = Xsqlite3GenerateIndexKey(tls, pParse, pIdx, iDataCur, 0, 1,
			bp, pPrior, r1)
		Xsqlite3VdbeAddOp3(tls, v, OP_IdxDelete, iIdxCur+i, r1,
			func() int32 {
				if uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x8>>3)) != 0 {
					return int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
				}
				return int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
			}())
		Xsqlite3VdbeChangeP5(tls, v, uint16(1))
		Xsqlite3ResolvePartIdxLabel(tls, pParse, *(*int32)(unsafe.Pointer(bp)))
		pPrior = pIdx

	}
	goto __2
__2:
	i++
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	goto __1
	goto __3
__3:
}

func Xsqlite3GenerateIndexKey(tls *libc.TLS, pParse uintptr, pIdx uintptr, iDataCur int32, regOut int32, prefixOnly int32, piPartIdxLabel uintptr, pPrior uintptr, regPrior int32) int32 {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var j int32
	var regBase int32
	var nCol int32

	if piPartIdxLabel != 0 {
		if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			*(*int32)(unsafe.Pointer(piPartIdxLabel)) = Xsqlite3VdbeMakeLabel(tls, pParse)
			(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = iDataCur + 1
			Xsqlite3ExprIfFalseDup(tls, pParse, (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere, *(*int32)(unsafe.Pointer(piPartIdxLabel)),
				SQLITE_JUMPIFNULL)
			(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = 0
			pPrior = uintptr(0)

		} else {
			*(*int32)(unsafe.Pointer(piPartIdxLabel)) = 0
		}
	}
	if prefixOnly != 0 && uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x8>>3)) != 0 {
		nCol = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
	} else {
		nCol = int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
	}
	regBase = Xsqlite3GetTempRange(tls, pParse, nCol)
	if pPrior != 0 && (regBase != regPrior || (*Index)(unsafe.Pointer(pPrior)).FpPartIdxWhere != 0) {
		pPrior = uintptr(0)
	}
	for j = 0; j < nCol; j++ {
		if pPrior != 0 &&
			int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPrior)).FaiColumn + uintptr(j)*2))) == int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) &&
			int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPrior)).FaiColumn + uintptr(j)*2))) != -2 {
			continue
		}
		Xsqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iDataCur, j, regBase+j)
		if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2))) >= 0 {
			Xsqlite3VdbeDeletePriorOpcode(tls, v, uint8(OP_RealAffinity))
		}
	}
	if regOut != 0 {
		Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regBase, nCol, regOut)
	}
	Xsqlite3ReleaseTempRange(tls, pParse, regBase, nCol)
	return regBase
}

func Xsqlite3ResolvePartIdxLabel(tls *libc.TLS, pParse uintptr, iLabel int32) {
	if iLabel != 0 {
		Xsqlite3VdbeResolveLabel(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, iLabel)
	}
}

func sqlite3GetFuncCollSeq(tls *libc.TLS, context uintptr) uintptr {
	var pOp uintptr

	pOp = (*Vdbe)(unsafe.Pointer((*Sqlite3_context)(unsafe.Pointer(context)).FpVdbe)).FaOp + uintptr((*Sqlite3_context)(unsafe.Pointer(context)).FiOp-1)*32

	return *(*uintptr)(unsafe.Pointer(pOp + 16))
}

func sqlite3SkipAccumulatorLoad(tls *libc.TLS, context uintptr) {
	(*Sqlite3_context)(unsafe.Pointer(context)).FisError = -1
	(*Sqlite3_context)(unsafe.Pointer(context)).FskipFlag = U8(1)
}

func minmaxFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var i int32
	var mask int32
	var iBest int32
	var pColl uintptr

	if Xsqlite3_user_data(tls, context) == uintptr(0) {
		mask = 0
	} else {
		mask = -1
	}
	pColl = sqlite3GetFuncCollSeq(tls, context)

	iBest = 0
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == SQLITE_NULL {
		return
	}
	for i = 1; i < argc; i++ {
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8))) == SQLITE_NULL {
			return
		}
		if Xsqlite3MemCompare(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(iBest)*8)), *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)), pColl)^mask >= 0 {
			iBest = i
		}
	}
	Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv + uintptr(iBest)*8)))
}

func typeofFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	var i int32 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) - 1
	_ = NotUsed

	Xsqlite3_result_text(tls, context, azType2[i], -1, uintptr(0))
}

var azType2 = [5]uintptr{ts + 9116, ts + 9111, ts + 11353, ts + 11348, ts + 9106}

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)))))
}

func lengthFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = argc
	switch Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case SQLITE_BLOB:
		fallthrough
	case SQLITE_INTEGER:
		fallthrough
	case SQLITE_FLOAT:
		{
			Xsqlite3_result_int(tls, context, Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
			break

		}
	case SQLITE_TEXT:
		{
			var z uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
			var z0 uintptr
			var c uint8
			if z == uintptr(0) {
				return
			}
			z0 = z
			for int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(z)))) != 0 {
				z++
				if int32(c) >= 0xc0 {
					for int32(*(*uint8)(unsafe.Pointer(z)))&0xc0 == 0x80 {
						z++
						z0++
					}
				}
			}
			Xsqlite3_result_int(tls, context, int32((int64(z)-int64(z0))/1))
			break

		}
	default:
		{
			Xsqlite3_result_null(tls, context)
			break

		}
	}
}

func absFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = argc
	switch Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case SQLITE_INTEGER:
		{
			var iVal I64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
			if iVal < int64(0) {
				if iVal == int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32) {
					Xsqlite3_result_error(tls, context, ts+18259, -1)
					return
				}
				iVal = -iVal
			}
			Xsqlite3_result_int64(tls, context, iVal)
			break

		}
	case SQLITE_NULL:
		{
			Xsqlite3_result_null(tls, context)
			break

		}
	default:
		{
			var rVal float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
			if rVal < float64(0) {
				rVal = -rVal
			}
			Xsqlite3_result_double(tls, context, rVal)
			break

		}
	}
}

func instrFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var zHaystack uintptr
	var zNeedle uintptr
	var nHaystack int32
	var nNeedle int32
	var typeHaystack int32
	var typeNeedle int32
	var N int32
	var isText int32
	var firstChar uint8
	var pC1 uintptr
	var pC2 uintptr
	N = 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*8)))
	if !(typeHaystack == SQLITE_NULL || typeNeedle == SQLITE_NULL) {
		goto __1
	}
	return
__1:
	;
	nHaystack = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	nNeedle = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	if !(nNeedle > 0) {
		goto __2
	}
	if !(typeHaystack == SQLITE_BLOB && typeNeedle == SQLITE_BLOB) {
		goto __3
	}
	zHaystack = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zNeedle = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	isText = 0
	goto __4
__3:
	if !(typeHaystack != SQLITE_BLOB && typeNeedle != SQLITE_BLOB) {
		goto __5
	}
	zHaystack = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zNeedle = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	isText = 1
	goto __6
__5:
	pC1 = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zHaystack = Xsqlite3_value_text(tls, pC1)
	if !(zHaystack == uintptr(0)) {
		goto __7
	}
	goto endInstrOOM
__7:
	;
	nHaystack = Xsqlite3_value_bytes(tls, pC1)
	pC2 = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	zNeedle = Xsqlite3_value_text(tls, pC2)
	if !(zNeedle == uintptr(0)) {
		goto __8
	}
	goto endInstrOOM
__8:
	;
	nNeedle = Xsqlite3_value_bytes(tls, pC2)
	isText = 1
__6:
	;
__4:
	;
	if !(zNeedle == uintptr(0) || nHaystack != 0 && zHaystack == uintptr(0)) {
		goto __9
	}
	goto endInstrOOM
__9:
	;
	firstChar = *(*uint8)(unsafe.Pointer(zNeedle))
__10:
	if !(nNeedle <= nHaystack &&
		(int32(*(*uint8)(unsafe.Pointer(zHaystack))) != int32(firstChar) || libc.Xmemcmp(tls, zHaystack, zNeedle, uint64(nNeedle)) != 0)) {
		goto __11
	}
	N++
__12:
	nHaystack--
	zHaystack++
	goto __13
__13:
	if isText != 0 && int32(*(*uint8)(unsafe.Pointer(zHaystack)))&0xc0 == 0x80 {
		goto __12
	}
	goto __14
__14:
	;
	goto __10
__11:
	;
	if !(nNeedle > nHaystack) {
		goto __15
	}
	N = 0
__15:
	;
__2:
	;
	Xsqlite3_result_int(tls, context, N)
endInstr:
	Xsqlite3_value_free(tls, pC1)
	Xsqlite3_value_free(tls, pC2)
	return
endInstrOOM:
	Xsqlite3_result_error_nomem(tls, context)
	goto endInstr
}

func printfFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var zFormat uintptr
	var n int32
	var db uintptr = Xsqlite3_context_db_handle(tls, context)

	if argc >= 1 && libc.AssignUintptr(&zFormat, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))) != uintptr(0) {
		(*PrintfArguments)(unsafe.Pointer(bp + 40)).FnArg = argc - 1
		(*PrintfArguments)(unsafe.Pointer(bp + 40)).FnUsed = 0
		(*PrintfArguments)(unsafe.Pointer(bp + 40)).FapArg = argv + uintptr(1)*8
		Xsqlite3StrAccumInit(tls, bp+8, db, uintptr(0), 0, *(*int32)(unsafe.Pointer(db + 136)))
		(*StrAccum)(unsafe.Pointer(bp + 8)).FprintfFlags = U8(SQLITE_PRINTF_SQLFUNC)
		Xsqlite3_str_appendf(tls, bp+8, zFormat, libc.VaList(bp, bp+40))
		n = int32((*StrAccum)(unsafe.Pointer(bp + 8)).FnChar)
		Xsqlite3_result_text(tls, context, Xsqlite3StrAccumFinish(tls, bp+8), n,
			*(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})))
	}
}

func substrFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var z uintptr
	var z2 uintptr
	var len int32
	var p0type int32
	var p1 I64
	var p2 I64
	var negP2 int32 = 0

	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))) == SQLITE_NULL ||
		argc == 3 && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))) == SQLITE_NULL {
		return
	}
	p0type = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	p1 = I64(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))))
	if p0type == SQLITE_BLOB {
		len = 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
		}
		len = 0
		if p1 < int64(0) {
			for z2 = z; *(*uint8)(unsafe.Pointer(z2)) != 0; len++ {
				{
					if int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z2, 1)))) >= 0xc0 {
						for int32(*(*uint8)(unsafe.Pointer(z2)))&0xc0 == 0x80 {
							z2++
						}
					}
				}

			}
		}
	}
	if argc == 3 {
		p2 = I64(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))))
		if p2 < int64(0) {
			p2 = -p2
			negP2 = 1
		}
	} else {
		p2 = I64(*(*int32)(unsafe.Pointer(Xsqlite3_context_db_handle(tls, context) + 136)))
	}
	if p1 < int64(0) {
		p1 = p1 + I64(len)
		if p1 < int64(0) {
			p2 = p2 + p1
			if p2 < int64(0) {
				p2 = int64(0)
			}
			p1 = int64(0)
		}
	} else if p1 > int64(0) {
		p1--
	} else if p2 > int64(0) {
		p2--
	}
	if negP2 != 0 {
		p1 = p1 - p2
		if p1 < int64(0) {
			p2 = p2 + p1
			p1 = int64(0)
		}
	}

	if p0type != SQLITE_BLOB {
		for *(*uint8)(unsafe.Pointer(z)) != 0 && p1 != 0 {
			{
				if int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1)))) >= 0xc0 {
					for int32(*(*uint8)(unsafe.Pointer(z)))&0xc0 == 0x80 {
						z++
					}
				}
			}

			p1--
		}
		for z2 = z; *(*uint8)(unsafe.Pointer(z2)) != 0 && p2 != 0; p2-- {
			{
				if int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z2, 1)))) >= 0xc0 {
					for int32(*(*uint8)(unsafe.Pointer(z2)))&0xc0 == 0x80 {
						z2++
					}
				}
			}

		}
		Xsqlite3_result_text64(tls, context, z, uint64((int64(z2)-int64(z))/1), libc.UintptrFromInt32(-1),
			uint8(SQLITE_UTF8))
	} else {
		if p1+p2 > I64(len) {
			p2 = I64(len) - p1
			if p2 < int64(0) {
				p2 = int64(0)
			}
		}
		Xsqlite3_result_blob64(tls, context, z+uintptr(p1), U64(p2), libc.UintptrFromInt32(-1))
	}
}

func roundFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var n int32 = 0

	var zBuf uintptr

	if argc == 2 {
		if SQLITE_NULL == Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))) {
			return
		}
		n = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
		if n > 30 {
			n = 30
		}
		if n < 0 {
			n = 0
		}
	}
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == SQLITE_NULL {
		return
	}
	*(*float64)(unsafe.Pointer(bp + 16)) = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))

	if *(*float64)(unsafe.Pointer(bp + 16)) < -4503599627370496.0 || *(*float64)(unsafe.Pointer(bp + 16)) > +4503599627370496.0 {
	} else if n == 0 {
		*(*float64)(unsafe.Pointer(bp + 16)) = float64(libc.Int64FromFloat64(*(*float64)(unsafe.Pointer(bp + 16)) + func() float64 {
			if *(*float64)(unsafe.Pointer(bp + 16)) < float64(0) {
				return -0.5
			}
			return +0.5
		}()))
	} else {
		zBuf = Xsqlite3_mprintf(tls, ts+18276, libc.VaList(bp, n, *(*float64)(unsafe.Pointer(bp + 16))))
		if zBuf == uintptr(0) {
			Xsqlite3_result_error_nomem(tls, context)
			return
		}
		Xsqlite3AtoF(tls, zBuf, bp+16, Xsqlite3Strlen30(tls, zBuf), uint8(SQLITE_UTF8))
		Xsqlite3_free(tls, zBuf)
	}
	Xsqlite3_result_double(tls, context, *(*float64)(unsafe.Pointer(bp + 16)))
}

func contextMalloc(tls *libc.TLS, context uintptr, nByte I64) uintptr {
	var z uintptr
	var db uintptr = Xsqlite3_context_db_handle(tls, context)

	if nByte > I64(*(*int32)(unsafe.Pointer(db + 136))) {
		Xsqlite3_result_error_toobig(tls, context)
		z = uintptr(0)
	} else {
		z = Xsqlite3Malloc(tls, uint64(nByte))
		if !(z != 0) {
			Xsqlite3_result_error_nomem(tls, context)
		}
	}
	return z
}

func upperFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var z1 uintptr
	var z2 uintptr
	var i int32
	var n int32
	_ = argc
	z2 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))

	if z2 != 0 {
		z1 = contextMalloc(tls, context, I64(n)+int64(1))
		if z1 != 0 {
			for i = 0; i < n; i++ {
				*(*uint8)(unsafe.Pointer(z1 + uintptr(i))) = uint8(int32(*(*uint8)(unsafe.Pointer(z2 + uintptr(i)))) & ^(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z2 + uintptr(i)))]) & 0x20))
			}
			Xsqlite3_result_text(tls, context, z1, n, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
		}
	}
}

func lowerFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var z1 uintptr
	var z2 uintptr
	var i int32
	var n int32
	_ = argc
	z2 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))

	if z2 != 0 {
		z1 = contextMalloc(tls, context, I64(n)+int64(1))
		if z1 != 0 {
			for i = 0; i < n; i++ {
				*(*uint8)(unsafe.Pointer(z1 + uintptr(i))) = Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(z2 + uintptr(i)))]
			}
			Xsqlite3_result_text(tls, context, z1, n, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
		}
	}
}

func randomFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	_ = NotUsed
	_ = NotUsed2
	Xsqlite3_randomness(tls, int32(unsafe.Sizeof(Sqlite_int64(0))), bp)
	if *(*Sqlite_int64)(unsafe.Pointer(bp)) < int64(0) {
		*(*Sqlite_int64)(unsafe.Pointer(bp)) = -(*(*Sqlite_int64)(unsafe.Pointer(bp)) & (int64(0xffffffff) | int64(0x7fffffff)<<32))
	}
	Xsqlite3_result_int64(tls, context, *(*Sqlite_int64)(unsafe.Pointer(bp)))
}

func randomBlob(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var n Sqlite3_int64
	var p uintptr

	_ = 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(n), p)
		Xsqlite3_result_blob(tls, context, p, int32(n), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
	}
}

func last_insert_rowid(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	var db uintptr = Xsqlite3_context_db_handle(tls, context)
	_ = NotUsed
	_ = NotUsed2

	Xsqlite3_result_int64(tls, context, Xsqlite3_last_insert_rowid(tls, db))
}

func changes(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	var db uintptr = Xsqlite3_context_db_handle(tls, context)
	_ = NotUsed
	_ = NotUsed2
	Xsqlite3_result_int64(tls, context, Xsqlite3_changes64(tls, db))
}

func total_changes(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	var db uintptr = Xsqlite3_context_db_handle(tls, context)
	_ = NotUsed
	_ = NotUsed2

	Xsqlite3_result_int64(tls, context, Xsqlite3_total_changes64(tls, db))
}

type compareInfo = struct {
	FmatchAll U8
	FmatchOne U8
	FmatchSet U8
	FnoCase   U8
}

var globInfo = compareInfo{FmatchAll: U8('*'), FmatchOne: U8('?'), FmatchSet: U8('[')}

var likeInfoNorm = compareInfo{FmatchAll: U8('%'), FmatchOne: U8('_'), FnoCase: U8(1)}

var likeInfoAlt = compareInfo{FmatchAll: U8('%'), FmatchOne: U8('_')}

func patternCompare(tls *libc.TLS, zPattern uintptr, zString uintptr, pInfo uintptr, matchOther U32) int32 {
	bp := tls.Alloc(19)
	defer tls.Free(19)
	*(*uintptr)(unsafe.Pointer(bp)) = zPattern
	*(*uintptr)(unsafe.Pointer(bp + 8)) = zString

	var c U32
	var c2 U32
	var matchOne U32 = U32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchOne)
	var matchAll U32 = U32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchAll)
	var noCase U8 = (*compareInfo)(unsafe.Pointer(pInfo)).FnoCase
	var zEscaped uintptr = uintptr(0)

	for libc.AssignUint32(&c, func() uint32 {
		if int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) < 0x80 {
			return uint32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp)), 1))))
		}
		return Xsqlite3Utf8Read(tls, bp)
	}()) != U32(0) {
		if c == matchAll {
			for libc.AssignUint32(&c, func() uint32 {
				if int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) < 0x80 {
					return uint32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp)), 1))))
				}
				return Xsqlite3Utf8Read(tls, bp)
			}()) == matchAll ||
				c == matchOne && matchOne != U32(0) {
				if c == matchOne && Xsqlite3Utf8Read(tls, bp+8) == U32(0) {
					return SQLITE_NOWILDCARDMATCH
				}
			}
			if c == U32(0) {
				return SQLITE_MATCH
			} else if c == matchOther {
				if int32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchSet) == 0 {
					c = Xsqlite3Utf8Read(tls, bp)
					if c == U32(0) {
						return SQLITE_NOWILDCARDMATCH
					}
				} else {
					for *(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))) != 0 {
						var bMatch int32 = patternCompare(tls, *(*uintptr)(unsafe.Pointer(bp))+libc.UintptrFromInt32(-1), *(*uintptr)(unsafe.Pointer(bp + 8)), pInfo, matchOther)
						if bMatch != SQLITE_NOMATCH {
							return bMatch
						}
						{
							if int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 8)), 1)))) >= 0xc0 {
								for int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))))&0xc0 == 0x80 {
									*(*uintptr)(unsafe.Pointer(bp + 8))++
								}
							}
						}

					}
					return SQLITE_NOWILDCARDMATCH
				}
			}

			if c < U32(0x80) {
				var bMatch int32
				if noCase != 0 {
					*(*uint8)(unsafe.Pointer(bp + 16)) = uint8(c & U32(^(int32(Xsqlite3CtypeMap[uint8(c)]) & 0x20)))
					*(*uint8)(unsafe.Pointer(bp + 16 + 1)) = Xsqlite3UpperToLower[uint8(c)]
					*(*uint8)(unsafe.Pointer(bp + 16 + 2)) = uint8(0)
				} else {
					*(*uint8)(unsafe.Pointer(bp + 16)) = uint8(c)
					*(*uint8)(unsafe.Pointer(bp + 16 + 1)) = uint8(0)
				}
				for 1 != 0 {
					*(*uintptr)(unsafe.Pointer(bp + 8)) += uintptr(libc.Xstrcspn(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), bp+16))
					if int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8))))) == 0 {
						break
					}
					*(*uintptr)(unsafe.Pointer(bp + 8))++
					bMatch = patternCompare(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), pInfo, matchOther)
					if bMatch != SQLITE_NOMATCH {
						return bMatch
					}
				}
			} else {
				var bMatch int32
				for libc.AssignUint32(&c2, func() uint32 {
					if int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8))))) < 0x80 {
						return uint32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 8)), 1))))
					}
					return Xsqlite3Utf8Read(tls, bp+8)
				}()) != U32(0) {
					if c2 != c {
						continue
					}
					bMatch = patternCompare(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), pInfo, matchOther)
					if bMatch != SQLITE_NOMATCH {
						return bMatch
					}
				}
			}
			return SQLITE_NOWILDCARDMATCH
		}
		if c == matchOther {
			if int32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchSet) == 0 {
				c = Xsqlite3Utf8Read(tls, bp)
				if c == U32(0) {
					return SQLITE_NOMATCH
				}
				zEscaped = *(*uintptr)(unsafe.Pointer(bp))
			} else {
				var prior_c U32 = U32(0)
				var seen int32 = 0
				var invert int32 = 0
				c = Xsqlite3Utf8Read(tls, bp+8)
				if c == U32(0) {
					return SQLITE_NOMATCH
				}
				c2 = Xsqlite3Utf8Read(tls, bp)
				if c2 == U32('^') {
					invert = 1
					c2 = Xsqlite3Utf8Read(tls, bp)
				}
				if c2 == U32(']') {
					if c == U32(']') {
						seen = 1
					}
					c2 = Xsqlite3Utf8Read(tls, bp)
				}
				for c2 != 0 && c2 != U32(']') {
					if c2 == U32('-') && int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != ']' && int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != 0 && prior_c > U32(0) {
						c2 = Xsqlite3Utf8Read(tls, bp)
						if c >= prior_c && c <= c2 {
							seen = 1
						}
						prior_c = U32(0)
					} else {
						if c == c2 {
							seen = 1
						}
						prior_c = c2
					}
					c2 = Xsqlite3Utf8Read(tls, bp)
				}
				if c2 == U32(0) || seen^invert == 0 {
					return SQLITE_NOMATCH
				}
				continue
			}
		}
		c2 = func() uint32 {
			if int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8))))) < 0x80 {
				return uint32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp + 8)), 1))))
			}
			return Xsqlite3Utf8Read(tls, bp+8)
		}()
		if c == c2 {
			continue
		}
		if noCase != 0 && int32(Xsqlite3UpperToLower[uint8(c)]) == int32(Xsqlite3UpperToLower[uint8(c2)]) && c < U32(0x80) && c2 < U32(0x80) {
			continue
		}
		if c == matchOne && *(*uintptr)(unsafe.Pointer(bp)) != zEscaped && c2 != U32(0) {
			continue
		}
		return SQLITE_NOMATCH
	}
	if int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8))))) == 0 {
		return SQLITE_MATCH
	}
	return SQLITE_NOMATCH
}

func Xsqlite3_strglob(tls *libc.TLS, zGlobPattern uintptr, zString uintptr) int32 {
	if zString == uintptr(0) {
		return libc.Bool32(zGlobPattern != uintptr(0))
	} else if zGlobPattern == uintptr(0) {
		return 1
	} else {
		return patternCompare(tls, zGlobPattern, zString, uintptr(unsafe.Pointer(&globInfo)), uint32('['))
	}
	return int32(0)
}

func Xsqlite3_strlike(tls *libc.TLS, zPattern uintptr, zStr uintptr, esc uint32) int32 {
	if zStr == uintptr(0) {
		return libc.Bool32(zPattern != uintptr(0))
	} else if zPattern == uintptr(0) {
		return 1
	} else {
		return patternCompare(tls, zPattern, zStr, uintptr(unsafe.Pointer(&likeInfoNorm)), esc)
	}
	return int32(0)
}

var Xsqlite3_like_count int32 = 0

func likeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var zA uintptr
	var zB uintptr
	var escape U32
	var nPat int32
	var db uintptr = Xsqlite3_context_db_handle(tls, context)
	var pInfo uintptr = Xsqlite3_user_data(tls, context)

	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == SQLITE_BLOB ||
		Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))) == SQLITE_BLOB {
		Xsqlite3_like_count++
		Xsqlite3_result_int(tls, context, 0)
		return
	}

	nPat = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))

	if nPat > *(*int32)(unsafe.Pointer(db + 136 + 8*4)) {
		Xsqlite3_result_error(tls, context, ts+18281, -1)
		return
	}
	if argc == 3 {
		*(*uintptr)(unsafe.Pointer(bp)) = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8)))
		if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
			return
		}
		if Xsqlite3Utf8CharLen(tls, *(*uintptr)(unsafe.Pointer(bp)), -1) != 1 {
			Xsqlite3_result_error(tls, context,
				ts+18314, -1)
			return
		}
		escape = Xsqlite3Utf8Read(tls, bp)
		if escape == U32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchAll) || escape == U32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
			libc.Xmemcpy(tls, bp+8, pInfo, uint64(unsafe.Sizeof(compareInfo{})))
			pInfo = bp + 8
			if escape == U32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchAll) {
				(*compareInfo)(unsafe.Pointer(pInfo)).FmatchAll = U8(0)
			}
			if escape == U32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchOne) {
				(*compareInfo)(unsafe.Pointer(pInfo)).FmatchOne = U8(0)
			}
		}
	} else {
		escape = U32((*compareInfo)(unsafe.Pointer(pInfo)).FmatchSet)
	}
	zB = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	zA = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	if zA != 0 && zB != 0 {
		Xsqlite3_like_count++
		Xsqlite3_result_int(tls, context,
			libc.Bool32(patternCompare(tls, zB, zA, pInfo, escape) == SQLITE_MATCH))
	}
}

func nullifFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	var pColl uintptr = sqlite3GetFuncCollSeq(tls, context)
	_ = NotUsed
	if Xsqlite3MemCompare(tls, *(*uintptr)(unsafe.Pointer(argv)), *(*uintptr)(unsafe.Pointer(argv + 1*8)), pColl) != 0 {
		Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv)))
	}
}

func versionFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2

	Xsqlite3_result_text(tls, context, Xsqlite3_libversion(tls), -1, uintptr(0))
}

func sourceidFunc(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	_ = NotUsed
	_ = NotUsed2

	Xsqlite3_result_text(tls, context, Xsqlite3_sourceid(tls), -1, uintptr(0))
}

func errlogFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	_ = argc
	_ = context
	Xsqlite3_log(tls, Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv))), ts+1684, libc.VaList(bp, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))))
}

func compileoptionusedFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var zOptName uintptr

	_ = argc

	if libc.AssignUintptr(&zOptName, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))) != uintptr(0) {
		Xsqlite3_result_int(tls, context, Xsqlite3_compileoption_used(tls, zOptName))
	}
}

func compileoptiongetFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var n int32

	_ = argc

	n = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv)))
	Xsqlite3_result_text(tls, context, Xsqlite3_compileoption_get(tls, n), -1, uintptr(0))
}

var hexdigits = [16]uint8{
	uint8('0'), uint8('1'), uint8('2'), uint8('3'), uint8('4'), uint8('5'), uint8('6'), uint8('7'),
	uint8('8'), uint8('9'), uint8('A'), uint8('B'), uint8('C'), uint8('D'), uint8('E'), uint8('F'),
}

func Xsqlite3QuoteValue(tls *libc.TLS, pStr uintptr, pValue uintptr) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	switch Xsqlite3_value_type(tls, pValue) {
	case SQLITE_FLOAT:
		{
			var r1 float64

			var zVal uintptr
			r1 = Xsqlite3_value_double(tls, pValue)
			Xsqlite3_str_appendf(tls, pStr, ts+7805, libc.VaList(bp, r1))
			zVal = Xsqlite3_str_value(tls, pStr)
			if zVal != 0 {
				Xsqlite3AtoF(tls, zVal, bp+32, int32((*StrAccum)(unsafe.Pointer(pStr)).FnChar), uint8(SQLITE_UTF8))
				if r1 != *(*float64)(unsafe.Pointer(bp + 32)) {
					Xsqlite3_str_reset(tls, pStr)
					Xsqlite3_str_appendf(tls, pStr, ts+18359, libc.VaList(bp+8, r1))
				}
			}
			break

		}
	case SQLITE_INTEGER:
		{
			Xsqlite3_str_appendf(tls, pStr, ts+1416, libc.VaList(bp+16, Xsqlite3_value_int64(tls, pValue)))
			break

		}
	case SQLITE_BLOB:
		{
			var zBlob uintptr = Xsqlite3_value_blob(tls, pValue)
			var nBlob I64 = I64(Xsqlite3_value_bytes(tls, pValue))

			Xsqlite3StrAccumEnlarge(tls, pStr, nBlob*int64(2)+int64(4))
			if int32((*StrAccum)(unsafe.Pointer(pStr)).FaccError) == 0 {
				var zText uintptr = (*StrAccum)(unsafe.Pointer(pStr)).FzText
				var i int32
				for i = 0; I64(i) < nBlob; i++ {
					*(*uint8)(unsafe.Pointer(zText + uintptr(i*2+2))) = hexdigits[int32(*(*uint8)(unsafe.Pointer(zBlob + uintptr(i))))>>4&0x0F]
					*(*uint8)(unsafe.Pointer(zText + uintptr(i*2+3))) = hexdigits[int32(*(*uint8)(unsafe.Pointer(zBlob + uintptr(i))))&0x0F]
				}
				*(*uint8)(unsafe.Pointer(zText + uintptr(nBlob*int64(2)+int64(2)))) = uint8('\'')
				*(*uint8)(unsafe.Pointer(zText + uintptr(nBlob*int64(2)+int64(3)))) = uint8(0)
				*(*uint8)(unsafe.Pointer(zText)) = uint8('X')
				*(*uint8)(unsafe.Pointer(zText + 1)) = uint8('\'')
				(*StrAccum)(unsafe.Pointer(pStr)).FnChar = U32(nBlob*int64(2) + int64(3))
			}
			break

		}
	case SQLITE_TEXT:
		{
			var zArg uintptr = Xsqlite3_value_text(tls, pValue)
			Xsqlite3_str_appendf(tls, pStr, ts+18366, libc.VaList(bp+24, zArg))
			break

		}
	default:
		{
			Xsqlite3_str_append(tls, pStr, ts+1637, 4)
			break

		}
	}
}

func quoteFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var db uintptr = Xsqlite3_context_db_handle(tls, context)

	_ = argc
	Xsqlite3StrAccumInit(tls, bp, db, uintptr(0), 0, *(*int32)(unsafe.Pointer(db + 136)))
	Xsqlite3QuoteValue(tls, bp, *(*uintptr)(unsafe.Pointer(argv)))
	Xsqlite3_result_text(tls, context, Xsqlite3StrAccumFinish(tls, bp), int32((*Sqlite3_str)(unsafe.Pointer(bp)).FnChar),
		*(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})))
	if int32((*Sqlite3_str)(unsafe.Pointer(bp)).FaccError) != SQLITE_OK {
		Xsqlite3_result_null(tls, context)
		Xsqlite3_result_error_code(tls, context, int32((*Sqlite3_str)(unsafe.Pointer(bp)).FaccError))
	}
}

func unicodeFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*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(Xsqlite3Utf8Read(tls, bp)))
	}
}

func charFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var z uintptr
	var zOut uintptr
	var i int32
	zOut = libc.AssignUintptr(&z, Xsqlite3_malloc64(tls, uint64(argc*4+1)))
	if z == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
		return
	}
	for i = 0; i < argc; i++ {
		var x Sqlite3_int64
		var c uint32
		x = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
		if x < int64(0) || x > int64(0x10ffff) {
			x = int64(0xfffd)
		}
		c = uint32(x & int64(0x1fffff))
		if c < uint32(0x00080) {
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = U8(c & uint32(0xFF))
		} else if c < uint32(0x00800) {
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xC0 + int32(U8(c>>6&uint32(0x1F))))
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
		} else if c < uint32(0x10000) {
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xE0 + int32(U8(c>>12&uint32(0x0F))))
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(c>>6&uint32(0x3F))))
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
		} else {
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xF0 + int32(U8(c>>18&uint32(0x07))))
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(c>>12&uint32(0x3F))))
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(c>>6&uint32(0x3F))))
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(c&uint32(0x3F))))
		}
	}
	Xsqlite3_result_text64(tls, context, z, uint64((int64(zOut)-int64(z))/1), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})), uint8(SQLITE_UTF8))
}

func hexFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var i int32
	var n int32
	var pBlob uintptr
	var zHex uintptr
	var z uintptr

	_ = argc
	pBlob = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv)))
	n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))

	z = libc.AssignUintptr(&zHex, contextMalloc(tls, context, I64(n)*int64(2)+int64(1)))
	if zHex != 0 {
		i = 0
	__1:
		if !(i < n) {
			goto __3
		}
		{
			var c uint8 = *(*uint8)(unsafe.Pointer(pBlob))
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = hexdigits[int32(c)>>4&0xf]
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))) = hexdigits[int32(c)&0xf]

		}
		goto __2
	__2:
		i++
		pBlob++
		goto __1
		goto __3
	__3:
		;
		*(*uint8)(unsafe.Pointer(z)) = uint8(0)
		Xsqlite3_result_text(tls, context, zHex, n*2, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
	}
}

func strContainsChar(tls *libc.TLS, zStr uintptr, nStr int32, ch U32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zEnd uintptr = zStr + uintptr(nStr)
	*(*uintptr)(unsafe.Pointer(bp)) = zStr
	for *(*uintptr)(unsafe.Pointer(bp)) < zEnd {
		var tst U32 = func() uint32 {
			if int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) < 0x80 {
				return uint32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp)), 1))))
			}
			return Xsqlite3Utf8Read(tls, bp)
		}()
		if tst == ch {
			return 1
		}
	}
	return 0
}

func unhexFunc(tls *libc.TLS, pCtx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zPass uintptr
	var nPass int32

	var nHex int32
	var pBlob uintptr
	var p uintptr
	var ch U32
	var c U8
	var d U8
	zPass = ts + 1636
	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 == 2) {
		goto __1
	}
	zPass = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	nPass = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
__1:
	;
	if !(!(*(*uintptr)(unsafe.Pointer(bp)) != 0) || !(zPass != 0)) {
		goto __2
	}
	return
__2:
	;
	p = libc.AssignUintptr(&pBlob, contextMalloc(tls, pCtx, int64(nHex/2+1)))
	if !(pBlob != 0) {
		goto __3
	}

__4:
	if !(int32(libc.AssignUint8(&c, *(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))))) != 0x00) {
		goto __5
	}
__6:
	if !!(int32(Xsqlite3CtypeMap[c])&0x08 != 0) {
		goto __7
	}
	ch = func() uint32 {
		if int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) < 0x80 {
			return uint32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp)), 1))))
		}
		return Xsqlite3Utf8Read(tls, bp)
	}()

	if !!(strContainsChar(tls, zPass, nPass, ch) != 0) {
		goto __8
	}
	goto unhex_null
__8:
	;
	c = *(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))
	if !(int32(c) == 0x00) {
		goto __9
	}
	goto unhex_done
__9:
	;
	goto __6
__7:
	;
	*(*uintptr)(unsafe.Pointer(bp))++

	d = *(*U8)(unsafe.Pointer(libc.PostIncUintptr(&*(*uintptr)(unsafe.Pointer(bp)), 1)))
	if !!(int32(Xsqlite3CtypeMap[d])&0x08 != 0) {
		goto __10
	}
	goto unhex_null
__10:
	;
	*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&p, 1))) = U8(int32(Xsqlite3HexToInt(tls, int32(c)))<<4 | int32(Xsqlite3HexToInt(tls, int32(d))))
	goto __4
__5:
	;
__3:
	;
unhex_done:
	Xsqlite3_result_blob(tls, pCtx, pBlob, int32((int64(p)-int64(pBlob))/1), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
	return

unhex_null:
	Xsqlite3_free(tls, pBlob)
	return
}

func zeroblobFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var n I64
	var rc int32

	_ = argc
	n = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if n < int64(0) {
		n = int64(0)
	}
	rc = Xsqlite3_result_zeroblob64(tls, context, uint64(n))
	if rc != 0 {
		Xsqlite3_result_error_code(tls, context, rc)
	}
}

func replaceFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var zStr uintptr
	var zPattern uintptr
	var zRep uintptr
	var zOut uintptr
	var nStr int32
	var nPattern int32
	var nRep int32
	var nOut I64
	var loopLimit int32
	var i int32
	var j int32
	var cntExpand uint32
	var db uintptr = 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)))

	zPattern = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	if zPattern == uintptr(0) {
		return
	}
	if int32(*(*uint8)(unsafe.Pointer(zPattern))) == 0 {
		Xsqlite3_result_value(tls, context, *(*uintptr)(unsafe.Pointer(argv)))
		return
	}
	nPattern = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))

	zRep = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8)))
	if zRep == uintptr(0) {
		return
	}
	nRep = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8)))

	nOut = I64(nStr + 1)

	zOut = contextMalloc(tls, context, nOut)
	if zOut == uintptr(0) {
		return
	}
	loopLimit = nStr - nPattern
	cntExpand = uint32(0)
	for i = libc.AssignInt32(&j, 0); i <= loopLimit; i++ {
		if int32(*(*uint8)(unsafe.Pointer(zStr + uintptr(i)))) != int32(*(*uint8)(unsafe.Pointer(zPattern))) || libc.Xmemcmp(tls, zStr+uintptr(i), zPattern, uint64(nPattern)) != 0 {
			*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncInt32(&j, 1)))) = *(*uint8)(unsafe.Pointer(zStr + uintptr(i)))
		} else {
			if nRep > nPattern {
				nOut = nOut + I64(nRep-nPattern)

				if nOut-int64(1) > I64(*(*int32)(unsafe.Pointer(db + 136))) {
					Xsqlite3_result_error_toobig(tls, context)
					Xsqlite3_free(tls, zOut)
					return
				}
				cntExpand++
				if cntExpand&(cntExpand-uint32(1)) == uint32(0) {
					var zOld uintptr
					zOld = zOut
					zOut = Xsqlite3Realloc(tls, zOut, uint64(I64(int32(nOut))+(nOut-I64(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, uint64(nRep))
			j = j + nRep
			i = i + (nPattern - 1)
		}
	}

	libc.Xmemcpy(tls, zOut+uintptr(j), zStr+uintptr(i), uint64(nStr-i))
	j = j + (nStr - i)

	*(*uint8)(unsafe.Pointer(zOut + uintptr(j))) = uint8(0)
	Xsqlite3_result_text(tls, context, zOut, j, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
}

func trimFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var zIn uintptr
	var zCharSet uintptr
	var nIn uint32
	var flags int32
	var i int32
	var aLen uintptr = uintptr(0)
	var azChar uintptr = uintptr(0)
	var nChar int32

	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == 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 == 1 {
		nChar = 1
		aLen = uintptr(unsafe.Pointer(&lenOne))
		azChar = uintptr(unsafe.Pointer(&azOne))
		zCharSet = uintptr(0)
	} else if libc.AssignUintptr(&zCharSet, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))) == uintptr(0) {
		return
	} else {
		var z uintptr
		z = zCharSet
		nChar = 0
		for ; *(*uint8)(unsafe.Pointer(z)) != 0; nChar++ {
			{
				if int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1)))) >= 0xc0 {
					for int32(*(*uint8)(unsafe.Pointer(z)))&0xc0 == 0x80 {
						z++
					}
				}
			}

		}
		if nChar > 0 {
			azChar = contextMalloc(tls, context,
				int64(uint64(I64(nChar))*(uint64(unsafe.Sizeof(uintptr(0)))+uint64(unsafe.Sizeof(uint32(0))))))
			if azChar == uintptr(0) {
				return
			}
			aLen = azChar + uintptr(nChar)*8
			z = zCharSet
			nChar = 0
			for ; *(*uint8)(unsafe.Pointer(z)) != 0; nChar++ {
				*(*uintptr)(unsafe.Pointer(azChar + uintptr(nChar)*8)) = z
				{
					if int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1)))) >= 0xc0 {
						for int32(*(*uint8)(unsafe.Pointer(z)))&0xc0 == 0x80 {
							z++
						}
					}
				}

				*(*uint32)(unsafe.Pointer(aLen + uintptr(nChar)*4)) = uint32((int64(z) - int64(*(*uintptr)(unsafe.Pointer(azChar + uintptr(nChar)*8)))) / 1)
			}
		}
	}
	if nChar > 0 {
		flags = int32(Xsqlite3_user_data(tls, context))
		if flags&1 != 0 {
			for nIn > uint32(0) {
				var len uint32 = uint32(0)
				for i = 0; i < nChar; i++ {
					len = *(*uint32)(unsafe.Pointer(aLen + uintptr(i)*4))
					if len <= nIn && libc.Xmemcmp(tls, zIn, *(*uintptr)(unsafe.Pointer(azChar + uintptr(i)*8)), uint64(len)) == 0 {
						break
					}
				}
				if i >= nChar {
					break
				}
				zIn += uintptr(len)
				nIn = nIn - len
			}
		}
		if flags&2 != 0 {
			for nIn > uint32(0) {
				var len uint32 = uint32(0)
				for i = 0; i < nChar; i++ {
					len = *(*uint32)(unsafe.Pointer(aLen + uintptr(i)*4))
					if len <= nIn && libc.Xmemcmp(tls, zIn+uintptr(nIn-len), *(*uintptr)(unsafe.Pointer(azChar + uintptr(i)*8)), uint64(len)) == 0 {
						break
					}
				}
				if i >= nChar {
					break
				}
				nIn = nIn - len
			}
		}
		if zCharSet != 0 {
			Xsqlite3_free(tls, azChar)
		}
	}
	Xsqlite3_result_text(tls, context, zIn, int32(nIn), libc.UintptrFromInt32(-1))
}

var lenOne = [1]uint32{uint32(1)}
var azOne = [1]uintptr{ts + 14304}

func soundexFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zIn uintptr
	var i int32
	var j int32

	zIn = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zIn == uintptr(0) {
		zIn = ts + 1636
	}
	for i = 0; *(*U8)(unsafe.Pointer(zIn + uintptr(i))) != 0 && !(int32(Xsqlite3CtypeMap[*(*U8)(unsafe.Pointer(zIn + uintptr(i)))])&0x02 != 0); i++ {
	}
	if *(*U8)(unsafe.Pointer(zIn + uintptr(i))) != 0 {
		var prevcode U8 = iCode[int32(*(*U8)(unsafe.Pointer(zIn + uintptr(i))))&0x7f]
		*(*uint8)(unsafe.Pointer(bp)) = uint8(int32(*(*U8)(unsafe.Pointer(zIn + uintptr(i)))) & ^(int32(Xsqlite3CtypeMap[*(*U8)(unsafe.Pointer(zIn + uintptr(i)))]) & 0x20))
		for j = 1; j < 4 && *(*U8)(unsafe.Pointer(zIn + uintptr(i))) != 0; i++ {
			var code int32 = int32(iCode[int32(*(*U8)(unsafe.Pointer(zIn + uintptr(i))))&0x7f])
			if code > 0 {
				if code != int32(prevcode) {
					prevcode = U8(code)
					*(*uint8)(unsafe.Pointer(bp + uintptr(libc.PostIncInt32(&j, 1)))) = uint8(code + '0')
				}
			} else {
				prevcode = U8(0)
			}
		}
		for j < 4 {
			*(*uint8)(unsafe.Pointer(bp + uintptr(libc.PostIncInt32(&j, 1)))) = uint8('0')
		}
		*(*uint8)(unsafe.Pointer(bp + uintptr(j))) = uint8(0)
		Xsqlite3_result_text(tls, context, bp, 4, libc.UintptrFromInt32(-1))
	} else {
		Xsqlite3_result_text(tls, context, ts+18369, 4, uintptr(0))
	}
}

var iCode = [128]uint8{
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(1), uint8(2), uint8(3), uint8(0), uint8(1), uint8(2), uint8(0), uint8(0), uint8(2), uint8(2), uint8(4), uint8(5), uint8(5), uint8(0),
	uint8(1), uint8(2), uint8(6), uint8(2), uint8(3), uint8(0), uint8(1), uint8(0), uint8(2), uint8(0), uint8(2), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(1), uint8(2), uint8(3), uint8(0), uint8(1), uint8(2), uint8(0), uint8(0), uint8(2), uint8(2), uint8(4), uint8(5), uint8(5), uint8(0),
	uint8(1), uint8(2), uint8(6), uint8(2), uint8(3), uint8(0), uint8(1), uint8(0), uint8(2), uint8(0), uint8(2), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
}

func loadExt(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zFile uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	var zProc uintptr
	var db uintptr = Xsqlite3_context_db_handle(tls, context)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)

	if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LoadExtFunc) == uint64(0) {
		Xsqlite3_result_error(tls, context, ts+15509, -1)
		return
	}

	if argc == 2 {
		zProc = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	} 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)), -1)
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
}

type SumCtx1 = struct {
	FrSum        float64
	FiSum        I64
	Fcnt         I64
	Foverflow    U8
	Fapprox      U8
	F__ccgo_pad1 [6]byte
}

type SumCtx = SumCtx1

func sumStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	var type1 int32

	_ = argc
	p = Xsqlite3_aggregate_context(tls, context, int32(unsafe.Sizeof(SumCtx{})))
	type1 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if p != 0 && type1 != SQLITE_NULL {
		(*SumCtx)(unsafe.Pointer(p)).Fcnt++
		if type1 == SQLITE_INTEGER {
			var v I64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
			*(*float64)(unsafe.Pointer(p)) += float64(v)
			if int32((*SumCtx)(unsafe.Pointer(p)).Fapprox)|int32((*SumCtx)(unsafe.Pointer(p)).Foverflow) == 0 && Xsqlite3AddInt64(tls, p+8, v) != 0 {
				(*SumCtx)(unsafe.Pointer(p)).Fapprox = libc.AssignPtrUint8(p+24, U8(1))
			}
		} else {
			*(*float64)(unsafe.Pointer(p)) += Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
			(*SumCtx)(unsafe.Pointer(p)).Fapprox = U8(1)
		}
	}
}

func sumInverse(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	var type1 int32

	_ = argc
	p = Xsqlite3_aggregate_context(tls, context, int32(unsafe.Sizeof(SumCtx{})))
	type1 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))

	if p != 0 && type1 != SQLITE_NULL {
		(*SumCtx)(unsafe.Pointer(p)).Fcnt--

		if type1 == SQLITE_INTEGER && int32((*SumCtx)(unsafe.Pointer(p)).Fapprox) == 0 {
			var v I64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
			*(*float64)(unsafe.Pointer(p)) -= float64(v)
			*(*I64)(unsafe.Pointer(p + 8)) -= v
		} else {
			*(*float64)(unsafe.Pointer(p)) -= Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
		}
	}
}

func sumFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, context, 0)
	if p != 0 && (*SumCtx)(unsafe.Pointer(p)).Fcnt > int64(0) {
		if (*SumCtx)(unsafe.Pointer(p)).Foverflow != 0 {
			Xsqlite3_result_error(tls, context, ts+18259, -1)
		} else if (*SumCtx)(unsafe.Pointer(p)).Fapprox != 0 {
			Xsqlite3_result_double(tls, context, (*SumCtx)(unsafe.Pointer(p)).FrSum)
		} else {
			Xsqlite3_result_int64(tls, context, (*SumCtx)(unsafe.Pointer(p)).FiSum)
		}
	}
}

func avgFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, context, 0)
	if p != 0 && (*SumCtx)(unsafe.Pointer(p)).Fcnt > int64(0) {
		Xsqlite3_result_double(tls, context, (*SumCtx)(unsafe.Pointer(p)).FrSum/float64((*SumCtx)(unsafe.Pointer(p)).Fcnt))
	}
}

func totalFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, context, 0)

	Xsqlite3_result_double(tls, context, func() float64 {
		if p != 0 {
			return (*SumCtx)(unsafe.Pointer(p)).FrSum
		}
		return float64(0)
	}())
}

type CountCtx1 = struct{ Fn I64 }

type CountCtx = CountCtx1

func countStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, context, int32(unsafe.Sizeof(CountCtx{})))
	if (argc == 0 || SQLITE_NULL != Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))) && p != 0 {
		(*CountCtx)(unsafe.Pointer(p)).Fn++
	}

}

func countFinalize(tls *libc.TLS, context uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, context, 0)
	Xsqlite3_result_int64(tls, context, func() int64 {
		if p != 0 {
			return (*CountCtx)(unsafe.Pointer(p)).Fn
		}
		return int64(0)
	}())
}

func countInverse(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, ctx, int32(unsafe.Sizeof(CountCtx{})))

	if (argc == 0 || SQLITE_NULL != Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv)))) && p != 0 {
		(*CountCtx)(unsafe.Pointer(p)).Fn--
	}
}

func minmaxStep(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	var pArg uintptr = *(*uintptr)(unsafe.Pointer(argv))
	var pBest uintptr
	_ = NotUsed

	pBest = Xsqlite3_aggregate_context(tls, context, int32(unsafe.Sizeof(Mem{})))
	if !(pBest != 0) {
		return
	}

	if Xsqlite3_value_type(tls, pArg) == SQLITE_NULL {
		if (*Mem)(unsafe.Pointer(pBest)).Fflags != 0 {
			sqlite3SkipAccumulatorLoad(tls, context)
		}
	} else if (*Mem)(unsafe.Pointer(pBest)).Fflags != 0 {
		var max int32
		var cmp int32
		var pColl uintptr = sqlite3GetFuncCollSeq(tls, context)

		max = libc.Bool32(Xsqlite3_user_data(tls, context) != uintptr(0))
		cmp = Xsqlite3MemCompare(tls, pBest, pArg, pColl)
		if max != 0 && cmp < 0 || !(max != 0) && cmp > 0 {
			Xsqlite3VdbeMemCopy(tls, pBest, pArg)
		} else {
			sqlite3SkipAccumulatorLoad(tls, context)
		}
	} else {
		(*Mem)(unsafe.Pointer(pBest)).Fdb = Xsqlite3_context_db_handle(tls, context)
		Xsqlite3VdbeMemCopy(tls, pBest, pArg)
	}
}

func minMaxValueFinalize(tls *libc.TLS, context uintptr, bValue int32) {
	var pRes uintptr
	pRes = Xsqlite3_aggregate_context(tls, context, 0)
	if pRes != 0 {
		if (*Sqlite3_value)(unsafe.Pointer(pRes)).Fflags != 0 {
			Xsqlite3_result_value(tls, context, pRes)
		}
		if bValue == 0 {
			Xsqlite3VdbeMemRelease(tls, pRes)
		}
	}
}

func minMaxValue(tls *libc.TLS, context uintptr) {
	minMaxValueFinalize(tls, context, 1)
}

func minMaxFinalize(tls *libc.TLS, context uintptr) {
	minMaxValueFinalize(tls, context, 0)
}

type GroupConcatCtx = struct {
	Fstr             StrAccum
	FnAccum          int32
	FnFirstSepLength int32
	FpnSepLengths    uintptr
}

func groupConcatStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var zVal uintptr
	var pGCC uintptr
	var zSep uintptr
	var nVal int32
	var nSep int32

	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == SQLITE_NULL {
		return
	}
	pGCC = Xsqlite3_aggregate_context(tls, context, int32(unsafe.Sizeof(GroupConcatCtx{})))
	if pGCC != 0 {
		var db uintptr = Xsqlite3_context_db_handle(tls, context)
		var firstTerm int32 = libc.Bool32((*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FmxAlloc == U32(0))
		(*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FmxAlloc = U32(*(*int32)(unsafe.Pointer(db + 136)))
		if argc == 1 {
			if !(firstTerm != 0) {
				Xsqlite3_str_appendchar(tls, pGCC, 1, uint8(','))
			} else {
				(*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength = 1
			}
		} else if !(firstTerm != 0) {
			zSep = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
			nSep = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
			if zSep != 0 {
				Xsqlite3_str_append(tls, pGCC, zSep, nSep)
			} else {
				nSep = 0
			}
			if nSep != (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength || (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths != uintptr(0) {
				var pnsl uintptr = (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths
				if pnsl == uintptr(0) {
					pnsl = Xsqlite3_malloc64(tls, uint64((*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum+1)*uint64(unsafe.Sizeof(int32(0))))
					if pnsl != uintptr(0) {
						var i int32 = 0
						var nA int32 = (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum - 1
						for i < nA {
							*(*int32)(unsafe.Pointer(pnsl + uintptr(libc.PostIncInt32(&i, 1))*4)) = (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength
						}
					}
				} else {
					pnsl = Xsqlite3_realloc64(tls, pnsl, uint64((*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum)*uint64(unsafe.Sizeof(int32(0))))
				}
				if pnsl != uintptr(0) {
					if (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum > 0 {
						*(*int32)(unsafe.Pointer(pnsl + uintptr((*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum-1)*4)) = nSep
					}
					(*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths = pnsl
				} else {
					Xsqlite3StrAccumSetError(tls, pGCC, uint8(SQLITE_NOMEM))
				}
			}
		} else {
			(*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
		}
		*(*int32)(unsafe.Pointer(pGCC + 32)) += 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 pGCC uintptr

	_ = argc
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == SQLITE_NULL {
		return
	}
	pGCC = Xsqlite3_aggregate_context(tls, context, int32(unsafe.Sizeof(GroupConcatCtx{})))

	if pGCC != 0 {
		var nVS int32

		Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		nVS = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
		*(*int32)(unsafe.Pointer(pGCC + 32)) -= 1
		if (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths != uintptr(0) {
			if (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum > 0 {
				nVS = nVS + *(*int32)(unsafe.Pointer((*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths))
				libc.Xmemmove(tls, (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths, (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths+uintptr(1)*4,
					uint64((*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnAccum-1)*uint64(unsafe.Sizeof(int32(0))))
			}
		} else {
			nVS = nVS + (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FnFirstSepLength
		}
		if nVS >= int32((*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar) {
			(*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar = U32(0)
		} else {
			*(*U32)(unsafe.Pointer(pGCC + 24)) -= U32(nVS)
			libc.Xmemmove(tls, (*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FzText, (*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FzText+uintptr(nVS), uint64((*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar))
		}
		if (*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FnChar == U32(0) {
			(*GroupConcatCtx)(unsafe.Pointer(pGCC)).Fstr.FmxAlloc = U32(0)
			Xsqlite3_free(tls, (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths)
			(*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths = uintptr(0)
		}
	}
}

func groupConcatFinalize(tls *libc.TLS, context uintptr) {
	var pGCC uintptr = Xsqlite3_aggregate_context(tls, context, 0)
	if pGCC != 0 {
		Xsqlite3ResultStrAccum(tls, context, pGCC)
		Xsqlite3_free(tls, (*GroupConcatCtx)(unsafe.Pointer(pGCC)).FpnSepLengths)
	}
}

func groupConcatValue(tls *libc.TLS, context uintptr) {
	var pGCC uintptr = Xsqlite3_aggregate_context(tls, context, 0)
	if pGCC != 0 {
		var pAccum uintptr = pGCC
		if int32((*StrAccum)(unsafe.Pointer(pAccum)).FaccError) == SQLITE_TOOBIG {
			Xsqlite3_result_error_toobig(tls, context)
		} else if int32((*StrAccum)(unsafe.Pointer(pAccum)).FaccError) == SQLITE_NOMEM {
			Xsqlite3_result_error_nomem(tls, context)
		} else {
			var zText uintptr = Xsqlite3_str_value(tls, pAccum)
			Xsqlite3_result_text(tls, context, zText, int32((*StrAccum)(unsafe.Pointer(pAccum)).FnChar), libc.UintptrFromInt32(-1))
		}
	}
}

func Xsqlite3RegisterPerConnectionBuiltinFunctions(tls *libc.TLS, db uintptr) {
	var rc int32 = Xsqlite3_overload_function(tls, db, ts+18374, 2)

	if rc == SQLITE_NOMEM {
		Xsqlite3OomFault(tls, db)
	}
}

func Xsqlite3RegisterLikeFunctions(tls *libc.TLS, db uintptr, caseSensitive int32) {
	var pInfo uintptr
	var flags int32
	if caseSensitive != 0 {
		pInfo = uintptr(unsafe.Pointer(&likeInfoAlt))
		flags = SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE
	} else {
		pInfo = uintptr(unsafe.Pointer(&likeInfoNorm))
		flags = SQLITE_FUNC_LIKE
	}
	Xsqlite3CreateFunc(tls, db, ts+18380, 2, SQLITE_UTF8, pInfo, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	}{likeFunc})), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
	Xsqlite3CreateFunc(tls, db, ts+18380, 3, SQLITE_UTF8, pInfo, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	}{likeFunc})), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
	*(*U32)(unsafe.Pointer(Xsqlite3FindFunction(tls, db, ts+18380, 2, uint8(SQLITE_UTF8), uint8(0)) + 4)) |= U32(flags)
	*(*U32)(unsafe.Pointer(Xsqlite3FindFunction(tls, db, ts+18380, 3, uint8(SQLITE_UTF8), uint8(0)) + 4)) |= U32(flags)
}

func Xsqlite3IsLikeFunction(tls *libc.TLS, db uintptr, pExpr uintptr, pIsNocase uintptr, aWc uintptr) int32 {
	var pDef uintptr
	var nExpr int32

	if !(int32(*(*uintptr)(unsafe.Pointer(pExpr + 32))) != 0) {
		return 0
	}
	nExpr = (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr

	pDef = Xsqlite3FindFunction(tls, db, *(*uintptr)(unsafe.Pointer(pExpr + 8)), nExpr, uint8(SQLITE_UTF8), uint8(0))
	if pDef == uintptr(0) || (*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_LIKE) == U32(0) {
		return 0
	}

	libc.Xmemcpy(tls, aWc, (*FuncDef)(unsafe.Pointer(pDef)).FpUserData, uint64(3))

	if nExpr < 3 {
		*(*uint8)(unsafe.Pointer(aWc + 3)) = uint8(0)
	} else {
		var pEscape uintptr = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8 + 2*32)).FpExpr
		var zEscape uintptr
		if int32((*Expr)(unsafe.Pointer(pEscape)).Fop) != TK_STRING {
			return 0
		}

		zEscape = *(*uintptr)(unsafe.Pointer(pEscape + 8))
		if int32(*(*uint8)(unsafe.Pointer(zEscape))) == 0 || int32(*(*uint8)(unsafe.Pointer(zEscape + 1))) != 0 {
			return 0
		}
		if int32(*(*uint8)(unsafe.Pointer(zEscape))) == int32(*(*uint8)(unsafe.Pointer(aWc))) {
			return 0
		}
		if int32(*(*uint8)(unsafe.Pointer(zEscape))) == int32(*(*uint8)(unsafe.Pointer(aWc + 1))) {
			return 0
		}
		*(*uint8)(unsafe.Pointer(aWc + 3)) = *(*uint8)(unsafe.Pointer(zEscape))
	}

	*(*int32)(unsafe.Pointer(pIsNocase)) = libc.Bool32((*FuncDef)(unsafe.Pointer(pDef)).FfuncFlags&U32(SQLITE_FUNC_CASE) == U32(0))
	return 1
}

func ceilingFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	switch Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case SQLITE_INTEGER:
		{
			Xsqlite3_result_int64(tls, context, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv))))
			break

		}
	case SQLITE_FLOAT:
		{
			var x uintptr = Xsqlite3_user_data(tls, context)
			Xsqlite3_result_double(tls, context, (*struct {
				f func(*libc.TLS, float64) float64
			})(unsafe.Pointer(&struct{ uintptr }{x})).f(tls, Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))))
			break

		}
	default:
		{
			break

		}
	}
}

func xCeil(tls *libc.TLS, x float64) float64 {
	return libc.Xceil(tls, x)
}

func xFloor(tls *libc.TLS, x float64) float64 {
	return libc.Xfloor(tls, x)
}

func logFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var x float64
	var b float64
	var ans float64

	switch Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
	case SQLITE_INTEGER:
		fallthrough
	case SQLITE_FLOAT:
		x = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if x <= 0.0 {
			return
		}
		break
	default:
		return
	}
	if argc == 2 {
		switch Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv))) {
		case SQLITE_INTEGER:
			fallthrough
		case SQLITE_FLOAT:
			b = libc.Xlog(tls, x)
			if b <= 0.0 {
				return
			}
			x = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
			if x <= 0.0 {
				return
			}
			break
			fallthrough
		default:
			return
		}
		ans = libc.Xlog(tls, x) / b
	} else {
		switch int32(Xsqlite3_user_data(tls, context)) {
		case 1:
			ans = libc.Xlog10(tls, x)
			break
			fallthrough
		case 2:
			ans = libc.Xlog2(tls, x)
			break
			fallthrough
		default:
			ans = libc.Xlog(tls, x)
			break
		}
	}
	Xsqlite3_result_double(tls, context, ans)
}

func degToRad(tls *libc.TLS, x float64) float64 {
	return x * (float64(3.14159265358979323846) / 180.0)
}

func radToDeg(tls *libc.TLS, x float64) float64 {
	return x * (float64(180.0) / 3.14159265358979323846)
}

func math1Func(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var type0 int32
	var v0 float64
	var ans float64
	var x uintptr

	type0 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if type0 != SQLITE_INTEGER && type0 != SQLITE_FLOAT {
		return
	}
	v0 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	x = Xsqlite3_user_data(tls, context)
	ans = (*struct {
		f func(*libc.TLS, float64) float64
	})(unsafe.Pointer(&struct{ uintptr }{x})).f(tls, v0)
	Xsqlite3_result_double(tls, context, ans)
}

func math2Func(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var type0 int32
	var type1 int32
	var v0 float64
	var v1 float64
	var ans float64
	var x uintptr

	type0 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if type0 != SQLITE_INTEGER && type0 != SQLITE_FLOAT {
		return
	}
	type1 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	if type1 != SQLITE_INTEGER && type1 != SQLITE_FLOAT {
		return
	}
	v0 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	v1 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	x = Xsqlite3_user_data(tls, context)
	ans = (*struct {
		f func(*libc.TLS, float64, float64) float64
	})(unsafe.Pointer(&struct{ uintptr }{x})).f(tls, v0, v1)
	Xsqlite3_result_double(tls, context, ans)
}

func piFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = argv
	Xsqlite3_result_double(tls, context, 3.14159265358979323846)
}

func signFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var type0 int32
	var x float64
	_ = argc

	type0 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if type0 != SQLITE_INTEGER && type0 != SQLITE_FLOAT {
		return
	}
	x = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	Xsqlite3_result_int(tls, context, func() int32 {
		if x < 0.0 {
			return -1
		}
		return func() int32 {
			if x > 0.0 {
				return +1
			}
			return 0
		}()
	}())
}

func Xsqlite3RegisterBuiltinFunctions(tls *libc.TLS) {
	Xsqlite3AlterFunctions(tls)
	Xsqlite3WindowFunctions(tls)
	Xsqlite3RegisterDateTimeFunctions(tls)
	Xsqlite3RegisterJsonFunctions(tls)
	Xsqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&aBuiltinFunc)), int32(uint64(unsafe.Sizeof(aBuiltinFunc))/uint64(unsafe.Sizeof(FuncDef{}))))

}

var aBuiltinFunc = [103]FuncDef{
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INTERNAL | SQLITE_FUNC_TEST | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | 0), FpUserData: uintptr(int64(INLINEFUNC_implies_nonnull_row)), FxSFunc: 0, FzName: ts + 18385},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INTERNAL | SQLITE_FUNC_TEST | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | 0), FpUserData: uintptr(int64(INLINEFUNC_expr_compare)), FxSFunc: 0, FzName: ts + 18405},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INTERNAL | SQLITE_FUNC_TEST | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | 0), FpUserData: uintptr(int64(INLINEFUNC_expr_implies_expr)), FxSFunc: 0, FzName: ts + 18418},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INTERNAL | SQLITE_FUNC_TEST | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | 0), FpUserData: uintptr(int64(INLINEFUNC_affinity)), FxSFunc: 0, FzName: ts + 18436},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18445},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_DIRECTONLY | SQLITE_FUNC_UNSAFE), FxSFunc: 0, FzName: ts + 18453},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_DIRECTONLY | SQLITE_FUNC_UNSAFE), FxSFunc: 0, FzName: ts + 18453},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 18468},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 18494},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | SQLITE_FUNC_UNLIKELY), FpUserData: uintptr(int64(INLINEFUNC_unlikely)), FxSFunc: 0, FzName: ts + 18519},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | SQLITE_FUNC_UNLIKELY), FpUserData: uintptr(int64(INLINEFUNC_unlikely)), FxSFunc: 0, FzName: ts + 18528},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | SQLITE_FUNC_UNLIKELY), FpUserData: uintptr(int64(INLINEFUNC_unlikely)), FxSFunc: 0, FzName: ts + 18539},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | 0), FpUserData: uintptr(int64(INLINEFUNC_sqlite_offset)), FxSFunc: 0, FzName: ts + 18546},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(1)), FxSFunc: 0, FzName: ts + 18560},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(1)), FxSFunc: 0, FzName: ts + 18560},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(2)), FxSFunc: 0, FzName: ts + 18566},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(2)), FxSFunc: 0, FzName: ts + 18566},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(3)), FxSFunc: 0, FzName: ts + 18572},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(3)), FxSFunc: 0, FzName: ts + 18572},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 1*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18577},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 1*SQLITE_FUNC_NEEDCOLL), FzName: ts + 18577},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 1*SQLITE_FUNC_NEEDCOLL | SQLITE_FUNC_MINMAX | SQLITE_FUNC_ANYORDER), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FzName: ts + 18577},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 1*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(1)), FxSFunc: 0, FzName: ts + 18581},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 1*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(1)), FzName: ts + 18581},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 1*SQLITE_FUNC_NEEDCOLL | SQLITE_FUNC_MINMAX | SQLITE_FUNC_ANYORDER), FpUserData: uintptr(int64(1)), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FzName: ts + 18581},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | SQLITE_FUNC_TYPEOF), FxSFunc: 0, FzName: ts + 18585},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | SQLITE_FUNC_TYPEOF), FxSFunc: 0, FzName: ts + 18592},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | SQLITE_FUNC_LENGTH), FxSFunc: 0, FzName: ts + 18600},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18607},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18613},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18620},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18627},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18635},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18640},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18644},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18644},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18650},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18656},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18662},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18666},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18666},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | 0), FxSFunc: 0, FzName: ts + 18672},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18679},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18686},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 1*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18697},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 18704},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_SLOCHNG | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 18719},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18736},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18747},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18753},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18771},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18779},
	{FnArg: int8(3), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18793},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18801},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18810},
	{FnArg: int8(3), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18810},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18817},
	{FnArg: int8(3), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18817},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 18827},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 18831},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 18837},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | SQLITE_FUNC_COUNT | SQLITE_FUNC_ANYORDER), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 18841},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | SQLITE_FUNC_ANYORDER), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 18841},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 18847},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 18847},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | SQLITE_FUNC_LIKE | SQLITE_FUNC_CASE), FpUserData: 0, FxSFunc: 0, FzName: ts + 18860},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | SQLITE_FUNC_LIKE), FpUserData: 0, FxSFunc: 0, FzName: ts + 18380},
	{FnArg: int8(3), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | SQLITE_FUNC_LIKE), FpUserData: 0, FxSFunc: 0, FzName: ts + 18380},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FzName: ts + 9801},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FzName: ts + 9801},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18865},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18870},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18878},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18884},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18890},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(1)), FxSFunc: 0, FzName: ts + 18893},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(1)), FxSFunc: 0, FzName: ts + 18897},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FpUserData: uintptr(int64(2)), FxSFunc: 0, FzName: ts + 18903},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 18893},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18908},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18912},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18916},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18922},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18926},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18931},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18936},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18941},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18947},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18951},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18955},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18959},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18964},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18969},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18974},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18980},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18986},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18992},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 18997},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: 0, FxSFunc: 0, FzName: ts + 19005},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 19013},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_FUNC_CONSTANT | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL), FxSFunc: 0, FzName: ts + 19016},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | 0), FxSFunc: 0, FzName: ts + 9801},
	{FnArg: int8(3), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_INLINE | SQLITE_FUNC_CONSTANT | 0), FpUserData: uintptr(int64(INLINEFUNC_iif)), FxSFunc: 0, FzName: ts + 19021}}

func Xsqlite3FkLocateIndex(tls *libc.TLS, pParse uintptr, pParent uintptr, pFKey uintptr, ppIdx uintptr, paiCol uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pIdx uintptr = uintptr(0)
	var aiCol uintptr = uintptr(0)
	var nCol int32 = (*FKey)(unsafe.Pointer(pFKey)).FnCol
	var zKey uintptr = (*sColMap)(unsafe.Pointer(pFKey + 64)).FzCol

	if nCol == 1 {
		if int32((*Table)(unsafe.Pointer(pParent)).FiPKey) >= 0 {
			if !(zKey != 0) {
				return 0
			}
			if !(Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pParent)).FaCol+uintptr((*Table)(unsafe.Pointer(pParent)).FiPKey)*24)).FzCnName, zKey) != 0) {
				return 0
			}
		}
	} else if paiCol != 0 {
		aiCol = Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(nCol)*uint64(unsafe.Sizeof(int32(0))))
		if !(aiCol != 0) {
			return 1
		}
		*(*uintptr)(unsafe.Pointer(paiCol)) = aiCol
	}

	for pIdx = (*Table)(unsafe.Pointer(pParent)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
		if int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) == nCol && int32((*Index)(unsafe.Pointer(pIdx)).FonError) != OE_None && (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
			if zKey == uintptr(0) {
				if int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
					if aiCol != 0 {
						var i int32
						for i = 0; i < nCol; i++ {
							*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) = (*sColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16)).FiFrom
						}
					}
					break
				}
			} else {
				var i int32
				var j int32
				for i = 0; i < nCol; i++ {
					var iCol I16 = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))
					var zDfltColl uintptr
					var zIdxCol uintptr

					if int32(iCol) < 0 {
						break
					}

					zDfltColl = Xsqlite3ColumnColl(tls, (*Table)(unsafe.Pointer(pParent)).FaCol+uintptr(iCol)*24)
					if !(zDfltColl != 0) {
						zDfltColl = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
					}
					if Xsqlite3StrICmp(tls, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*8)), zDfltColl) != 0 {
						break
					}

					zIdxCol = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pParent)).FaCol + uintptr(iCol)*24)).FzCnName
					for j = 0; j < nCol; j++ {
						if Xsqlite3StrICmp(tls, (*sColMap)(unsafe.Pointer(pFKey+64+uintptr(j)*16)).FzCol, zIdxCol) == 0 {
							if aiCol != 0 {
								*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) = (*sColMap)(unsafe.Pointer(pFKey + 64 + uintptr(j)*16)).FiFrom
							}
							break
						}
					}
					if j == nCol {
						break
					}
				}
				if i == nCol {
					break
				}
			}
		}
	}

	if !(pIdx != 0) {
		if !(int32((*Parse)(unsafe.Pointer(pParse)).FdisableTriggers) != 0) {
			Xsqlite3ErrorMsg(tls, pParse,
				ts+19025,
				libc.VaList(bp, (*Table)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName, (*FKey)(unsafe.Pointer(pFKey)).FzTo))
		}
		Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, aiCol)
		return 1
	}

	*(*uintptr)(unsafe.Pointer(ppIdx)) = pIdx
	return 0
}

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 int32
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var iCur int32 = (*Parse)(unsafe.Pointer(pParse)).FnTab - 1
	var iOk int32 = Xsqlite3VdbeMakeLabel(tls, pParse)

	if nIncr < 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_FkIfZero, int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred), iOk)

	}
	for i = 0; i < (*FKey)(unsafe.Pointer(pFKey)).FnCol; i++ {
		var iReg int32 = int32(Xsqlite3TableColumnToStorage(tls, (*FKey)(unsafe.Pointer(pFKey)).FpFrom, int16(*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4))))) + regData + 1
		Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, iReg, iOk)
	}

	if isIgnore == 0 {
		if pIdx == uintptr(0) {
			var iMustBeInt int32
			var regTemp int32 = Xsqlite3GetTempReg(tls, pParse)

			Xsqlite3VdbeAddOp2(tls, v, OP_SCopy,
				int32(Xsqlite3TableColumnToStorage(tls, (*FKey)(unsafe.Pointer(pFKey)).FpFrom, int16(*(*int32)(unsafe.Pointer(aiCol)))))+1+regData, regTemp)
			iMustBeInt = Xsqlite3VdbeAddOp2(tls, v, OP_MustBeInt, regTemp, 0)

			if pTab == (*FKey)(unsafe.Pointer(pFKey)).FpFrom && nIncr == 1 {
				Xsqlite3VdbeAddOp3(tls, v, OP_Eq, regData, iOk, regTemp)
				Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
			}

			Xsqlite3OpenTable(tls, pParse, iCur, iDb, pTab, OP_OpenRead)
			Xsqlite3VdbeAddOp3(tls, v, OP_NotExists, iCur, 0, regTemp)
			Xsqlite3VdbeGoto(tls, v, iOk)
			Xsqlite3VdbeJumpHere(tls, v, Xsqlite3VdbeCurrentAddr(tls, v)-2)
			Xsqlite3VdbeJumpHere(tls, v, iMustBeInt)
			Xsqlite3ReleaseTempReg(tls, pParse, regTemp)
		} else {
			var nCol int32 = (*FKey)(unsafe.Pointer(pFKey)).FnCol
			var regTemp int32 = Xsqlite3GetTempRange(tls, pParse, nCol)

			Xsqlite3VdbeAddOp3(tls, v, OP_OpenRead, iCur, int32((*Index)(unsafe.Pointer(pIdx)).Ftnum), iDb)
			Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
			for i = 0; i < nCol; i++ {
				Xsqlite3VdbeAddOp2(tls, v, OP_Copy,
					int32(Xsqlite3TableColumnToStorage(tls, (*FKey)(unsafe.Pointer(pFKey)).FpFrom, int16(*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)))))+1+regData,
					regTemp+i)
			}

			if pTab == (*FKey)(unsafe.Pointer(pFKey)).FpFrom && nIncr == 1 {
				var iJump int32 = Xsqlite3VdbeCurrentAddr(tls, v) + nCol + 1
				for i = 0; i < nCol; i++ {
					var iChild int32 = int32(Xsqlite3TableColumnToStorage(tls, (*FKey)(unsafe.Pointer(pFKey)).FpFrom, int16(*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4))))) +
						1 + regData
					var iParent int32 = 1 + regData
					iParent = iParent + int32(Xsqlite3TableColumnToStorage(tls, (*Index)(unsafe.Pointer(pIdx)).FpTable,
						*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))))

					if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) {
						iParent = regData
					}
					Xsqlite3VdbeAddOp3(tls, v, OP_Ne, iChild, iJump, iParent)
					Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_JUMPIFNULL))
				}
				Xsqlite3VdbeGoto(tls, v, iOk)
			}

			Xsqlite3VdbeAddOp4(tls, v, OP_Affinity, regTemp, nCol, 0,
				Xsqlite3IndexAffinityStr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pIdx), nCol)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, iCur, iOk, regTemp, nCol)

			Xsqlite3ReleaseTempRange(tls, pParse, regTemp, nCol)
		}
	}

	if !(int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred) != 0) && !((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_DeferFKs) != 0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FpToplevel) != 0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FisMultiWrite) != 0) {
		Xsqlite3HaltConstraint(tls, pParse, SQLITE_CONSTRAINT|int32(3)<<8,
			OE_Abort, uintptr(0), int8(-1), uint8(P5_ConstraintFK))
	} else {
		if nIncr > 0 && int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred) == 0 {
			Xsqlite3MayAbort(tls, pParse)
		}
		Xsqlite3VdbeAddOp2(tls, v, OP_FkCounter, int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred), nIncr)
	}

	Xsqlite3VdbeResolveLabel(tls, v, iOk)
	Xsqlite3VdbeAddOp1(tls, v, OP_Close, iCur)
}

func exprTableRegister(tls *libc.TLS, pParse uintptr, pTab uintptr, regBase int32, iCol I16) uintptr {
	var pExpr uintptr
	var pCol uintptr
	var zColl uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	pExpr = Xsqlite3Expr(tls, db, TK_REGISTER, uintptr(0))
	if pExpr != 0 {
		if int32(iCol) >= 0 && int32(iCol) != int32((*Table)(unsafe.Pointer(pTab)).FiPKey) {
			pCol = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24
			(*Expr)(unsafe.Pointer(pExpr)).FiTable = regBase + int32(Xsqlite3TableColumnToStorage(tls, pTab, iCol)) + 1
			(*Expr)(unsafe.Pointer(pExpr)).FaffExpr = (*Column)(unsafe.Pointer(pCol)).Faffinity
			zColl = Xsqlite3ColumnColl(tls, pCol)
			if zColl == uintptr(0) {
				zColl = (*CollSeq)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpDfltColl)).FzName
			}
			pExpr = Xsqlite3ExprAddCollateString(tls, pParse, pExpr, zColl)
		} else {
			(*Expr)(unsafe.Pointer(pExpr)).FiTable = regBase
			(*Expr)(unsafe.Pointer(pExpr)).FaffExpr = uint8(SQLITE_AFF_INTEGER)
		}
	}
	return pExpr
}

func exprTableColumn(tls *libc.TLS, db uintptr, pTab uintptr, iCursor int32, iCol I16) uintptr {
	var pExpr uintptr = Xsqlite3Expr(tls, db, TK_COLUMN, uintptr(0))
	if pExpr != 0 {
		*(*uintptr)(unsafe.Pointer(pExpr + 64)) = pTab
		(*Expr)(unsafe.Pointer(pExpr)).FiTable = iCursor
		(*Expr)(unsafe.Pointer(pExpr)).FiColumn = iCol
	}
	return pExpr
}

func fkScanChildren(tls *libc.TLS, pParse uintptr, pSrc uintptr, pTab uintptr, pIdx uintptr, pFKey uintptr, aiCol uintptr, regData int32, nIncr int32) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var i int32
	var pWhere uintptr = uintptr(0)

	var pWInfo uintptr
	var iFkIfZero int32 = 0
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)

	if nIncr < 0 {
		iFkIfZero = Xsqlite3VdbeAddOp2(tls, v, OP_FkIfZero, int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred), 0)

	}

	for i = 0; i < (*FKey)(unsafe.Pointer(pFKey)).FnCol; i++ {
		var pLeft uintptr
		var pRight uintptr
		var pEq uintptr
		var iCol I16
		var zCol uintptr

		if pIdx != 0 {
			iCol = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))
		} else {
			iCol = int16(-1)
		}
		pLeft = exprTableRegister(tls, pParse, pTab, regData, iCol)
		if aiCol != 0 {
			iCol = int16(*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)))
		} else {
			iCol = int16((*sColMap)(unsafe.Pointer(pFKey + 64)).FiFrom)
		}

		zCol = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iCol)*24)).FzCnName
		pRight = Xsqlite3Expr(tls, db, TK_ID, zCol)
		pEq = Xsqlite3PExpr(tls, pParse, TK_EQ, pLeft, pRight)
		pWhere = Xsqlite3ExprAnd(tls, pParse, pWhere, pEq)
	}

	if pTab == (*FKey)(unsafe.Pointer(pFKey)).FpFrom && nIncr > 0 {
		var pNe uintptr
		var pLeft uintptr
		var pRight uintptr
		if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
			pLeft = exprTableRegister(tls, pParse, pTab, regData, int16(-1))
			pRight = exprTableColumn(tls, db, pTab, (*SrcItem)(unsafe.Pointer(pSrc+8)).FiCursor, int16(-1))
			pNe = Xsqlite3PExpr(tls, pParse, TK_NE, pLeft, pRight)
		} else {
			var pEq uintptr
			var pAll uintptr = uintptr(0)

			for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol); i++ {
				var iCol I16 = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))

				pLeft = exprTableRegister(tls, pParse, pTab, regData, iCol)
				pRight = Xsqlite3Expr(tls, db, TK_ID, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24)).FzCnName)
				pEq = Xsqlite3PExpr(tls, pParse, TK_IS, pLeft, pRight)
				pAll = Xsqlite3ExprAnd(tls, pParse, pAll, pEq)
			}
			pNe = Xsqlite3PExpr(tls, pParse, TK_NOT, pAll, uintptr(0))
		}
		pWhere = Xsqlite3ExprAnd(tls, pParse, pWhere, pNe)
	}

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp)).FpSrcList = pSrc
	(*NameContext)(unsafe.Pointer(bp)).FpParse = pParse
	Xsqlite3ResolveExprNames(tls, bp, pWhere)

	if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 {
		pWInfo = Xsqlite3WhereBegin(tls, pParse, pSrc, pWhere, uintptr(0), uintptr(0), uintptr(0), uint16(0), 0)
		Xsqlite3VdbeAddOp2(tls, v, OP_FkCounter, int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred), nIncr)
		if pWInfo != 0 {
			Xsqlite3WhereEnd(tls, pWInfo)
		}
	}

	Xsqlite3ExprDelete(tls, db, pWhere)
	if iFkIfZero != 0 {
		Xsqlite3VdbeJumpHereOrPopInst(tls, v, iFkIfZero)
	}
}

func Xsqlite3FkReferences(tls *libc.TLS, pTab uintptr) uintptr {
	return Xsqlite3HashFind(tls, (*Table)(unsafe.Pointer(pTab)).FpSchema+80, (*Table)(unsafe.Pointer(pTab)).FzName)
}

func fkTriggerDelete(tls *libc.TLS, dbMem uintptr, p uintptr) {
	if p != 0 {
		var pStep uintptr = (*Trigger)(unsafe.Pointer(p)).Fstep_list
		Xsqlite3ExprDelete(tls, dbMem, (*TriggerStep)(unsafe.Pointer(pStep)).FpWhere)
		Xsqlite3ExprListDelete(tls, dbMem, (*TriggerStep)(unsafe.Pointer(pStep)).FpExprList)
		Xsqlite3SelectDelete(tls, dbMem, (*TriggerStep)(unsafe.Pointer(pStep)).FpSelect)
		Xsqlite3ExprDelete(tls, dbMem, (*Trigger)(unsafe.Pointer(p)).FpWhen)
		Xsqlite3DbFree(tls, dbMem, p)
	}
}

func Xsqlite3FkClearTriggerCache(tls *libc.TLS, db uintptr, iDb int32) {
	var k uintptr
	var pHash uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema + 8
	for k = (*Hash)(unsafe.Pointer(pHash)).Ffirst; k != 0; k = (*HashElem)(unsafe.Pointer(k)).Fnext {
		var pTab uintptr = (*HashElem)(unsafe.Pointer(k)).Fdata
		var pFKey uintptr
		if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM) {
			continue
		}
		for pFKey = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8)); pFKey != 0; pFKey = (*FKey)(unsafe.Pointer(pFKey)).FpNextFrom {
			fkTriggerDelete(tls, db, *(*uintptr)(unsafe.Pointer(pFKey + 48)))
			*(*uintptr)(unsafe.Pointer(pFKey + 48)) = uintptr(0)
			fkTriggerDelete(tls, db, *(*uintptr)(unsafe.Pointer(pFKey + 48 + 1*8)))
			*(*uintptr)(unsafe.Pointer(pFKey + 48 + 1*8)) = uintptr(0)
		}
	}
}

func Xsqlite3FkDropTable(tls *libc.TLS, pParse uintptr, pName uintptr, pTab uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM {
		var iSkip int32 = 0
		var v uintptr = Xsqlite3GetVdbe(tls, pParse)

		if Xsqlite3FkReferences(tls, pTab) == uintptr(0) {
			var p uintptr
			for p = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8)); p != 0; p = (*FKey)(unsafe.Pointer(p)).FpNextFrom {
				if (*FKey)(unsafe.Pointer(p)).FisDeferred != 0 || (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0 {
					break
				}
			}
			if !(p != 0) {
				return
			}
			iSkip = Xsqlite3VdbeMakeLabel(tls, pParse)
			Xsqlite3VdbeAddOp2(tls, v, OP_FkIfZero, 1, iSkip)
		}

		(*Parse)(unsafe.Pointer(pParse)).FdisableTriggers = U8(1)
		Xsqlite3DeleteFrom(tls, pParse, Xsqlite3SrcListDup(tls, db, pName, 0), uintptr(0), uintptr(0), uintptr(0))
		(*Parse)(unsafe.Pointer(pParse)).FdisableTriggers = U8(0)

		if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) == uint64(0) {
			Xsqlite3VdbeAddOp2(tls, v, OP_FkIfZero, 0, Xsqlite3VdbeCurrentAddr(tls, v)+2)

			Xsqlite3HaltConstraint(tls, pParse, SQLITE_CONSTRAINT|int32(3)<<8,
				OE_Abort, uintptr(0), int8(-1), uint8(P5_ConstraintFK))
		}

		if iSkip != 0 {
			Xsqlite3VdbeResolveLabel(tls, v, iSkip)
		}
	}
}

func fkChildIsModified(tls *libc.TLS, pTab uintptr, p uintptr, aChange uintptr, bChngRowid int32) int32 {
	var i int32
	for i = 0; i < (*FKey)(unsafe.Pointer(p)).FnCol; i++ {
		var iChildKey int32 = (*sColMap)(unsafe.Pointer(p + 64 + uintptr(i)*16)).FiFrom
		if *(*int32)(unsafe.Pointer(aChange + uintptr(iChildKey)*4)) >= 0 {
			return 1
		}
		if iChildKey == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) && bChngRowid != 0 {
			return 1
		}
	}
	return 0
}

func fkParentIsModified(tls *libc.TLS, pTab uintptr, p uintptr, aChange uintptr, bChngRowid int32) int32 {
	var i int32
	for i = 0; i < (*FKey)(unsafe.Pointer(p)).FnCol; i++ {
		var zKey uintptr = (*sColMap)(unsafe.Pointer(p + 64 + uintptr(i)*16)).FzCol
		var iKey int32
		for iKey = 0; iKey < int32((*Table)(unsafe.Pointer(pTab)).FnCol); iKey++ {
			if *(*int32)(unsafe.Pointer(aChange + uintptr(iKey)*4)) >= 0 || iKey == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) && bChngRowid != 0 {
				var pCol uintptr = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iKey)*24
				if zKey != 0 {
					if 0 == Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName, zKey) {
						return 1
					}
				} else if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_PRIMKEY != 0 {
					return 1
				}
			}
		}
	}
	return 0
}

func isSetNullAction(tls *libc.TLS, pParse uintptr, pFKey uintptr) int32 {
	var pTop uintptr = func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}()
	if (*Parse)(unsafe.Pointer(pTop)).FpTriggerPrg != 0 {
		var p uintptr = (*TriggerPrg)(unsafe.Pointer((*Parse)(unsafe.Pointer(pTop)).FpTriggerPrg)).FpTrigger
		if p == *(*uintptr)(unsafe.Pointer(pFKey + 48)) && int32(*(*U8)(unsafe.Pointer(pFKey + 45))) == OE_SetNull ||
			p == *(*uintptr)(unsafe.Pointer(pFKey + 48 + 1*8)) && int32(*(*U8)(unsafe.Pointer(pFKey + 45 + 1))) == OE_SetNull {
			return 1
		}
	}
	return 0
}

func Xsqlite3FkCheck(tls *libc.TLS, pParse uintptr, pTab uintptr, regOld int32, regNew int32, aChange uintptr, bChngRowid int32) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pFKey uintptr
	var iDb int32
	var zDb uintptr
	var isIgnoreErrors int32 = int32((*Parse)(unsafe.Pointer(pParse)).FdisableTriggers)

	if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) == uint64(0) {
		return
	}
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM) {
		return
	}

	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName

	for pFKey = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8)); pFKey != 0; pFKey = (*FKey)(unsafe.Pointer(pFKey)).FpNextFrom {
		var pTo uintptr
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		var aiCol uintptr

		var i int32
		var bIgnore int32 = 0

		if aChange != 0 &&
			Xsqlite3_stricmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName, (*FKey)(unsafe.Pointer(pFKey)).FzTo) != 0 &&
			fkChildIsModified(tls, pTab, pFKey, aChange, bChngRowid) == 0 {
			continue
		}

		if (*Parse)(unsafe.Pointer(pParse)).FdisableTriggers != 0 {
			pTo = Xsqlite3FindTable(tls, db, (*FKey)(unsafe.Pointer(pFKey)).FzTo, zDb)
		} else {
			pTo = Xsqlite3LocateTable(tls, pParse, uint32(0), (*FKey)(unsafe.Pointer(pFKey)).FzTo, zDb)
		}
		if !(pTo != 0) || Xsqlite3FkLocateIndex(tls, pParse, pTo, pFKey, bp, bp+8) != 0 {
			if !(isIgnoreErrors != 0) || (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				return
			}
			if pTo == uintptr(0) {
				var v uintptr = Xsqlite3GetVdbe(tls, pParse)
				var iJump int32 = Xsqlite3VdbeCurrentAddr(tls, v) + (*FKey)(unsafe.Pointer(pFKey)).FnCol + 1
				for i = 0; i < (*FKey)(unsafe.Pointer(pFKey)).FnCol; i++ {
					var iFromCol int32
					var iReg int32
					iFromCol = (*sColMap)(unsafe.Pointer(pFKey + 64 + uintptr(i)*16)).FiFrom
					iReg = int32(Xsqlite3TableColumnToStorage(tls, (*FKey)(unsafe.Pointer(pFKey)).FpFrom, int16(iFromCol))) + regOld + 1
					Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, iReg, iJump)
				}
				Xsqlite3VdbeAddOp2(tls, v, OP_FkCounter, int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred), -1)
			}
			continue
		}

		if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
			aiCol = *(*uintptr)(unsafe.Pointer(bp + 8))
		} else {
			*(*int32)(unsafe.Pointer(bp + 16)) = (*sColMap)(unsafe.Pointer(pFKey + 64)).FiFrom
			aiCol = bp + 16
		}
		for i = 0; i < (*FKey)(unsafe.Pointer(pFKey)).FnCol; i++ {
			if *(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) {
				*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) = -1
			}

			if (*Sqlite3)(unsafe.Pointer(db)).FxAuth != 0 {
				var rcauth int32
				var zCol uintptr = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTo)).FaCol + uintptr(func() int32 {
					if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
						return int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaiColumn + uintptr(i)*2)))
					}
					return int32((*Table)(unsafe.Pointer(pTo)).FiPKey)
				}())*24)).FzCnName
				rcauth = Xsqlite3AuthReadCol(tls, pParse, (*Table)(unsafe.Pointer(pTo)).FzName, zCol, iDb)
				bIgnore = libc.Bool32(rcauth == SQLITE_IGNORE)
			}
		}

		Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTo)).Ftnum, uint8(0), (*Table)(unsafe.Pointer(pTo)).FzName)
		(*Parse)(unsafe.Pointer(pParse)).FnTab++

		if regOld != 0 {
			fkLookupParent(tls, pParse, iDb, pTo, *(*uintptr)(unsafe.Pointer(bp)), pFKey, aiCol, regOld, -1, bIgnore)
		}
		if regNew != 0 && !(isSetNullAction(tls, pParse, pFKey) != 0) {
			fkLookupParent(tls, pParse, iDb, pTo, *(*uintptr)(unsafe.Pointer(bp)), pFKey, aiCol, regNew, +1, bIgnore)
		}

		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}

	for pFKey = Xsqlite3FkReferences(tls, pTab); pFKey != 0; pFKey = (*FKey)(unsafe.Pointer(pFKey)).FpNextTo {
		*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
		var pSrc uintptr
		*(*uintptr)(unsafe.Pointer(bp + 32)) = uintptr(0)

		if aChange != 0 && fkParentIsModified(tls, pTab, pFKey, aChange, bChngRowid) == 0 {
			continue
		}

		if !(int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred) != 0) && !((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0) &&
			!(int32((*Parse)(unsafe.Pointer(pParse)).FpToplevel) != 0) && !(int32((*Parse)(unsafe.Pointer(pParse)).FisMultiWrite) != 0) {
			continue
		}

		if Xsqlite3FkLocateIndex(tls, pParse, pTab, pFKey, bp+24, bp+32) != 0 {
			if !(isIgnoreErrors != 0) || (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				return
			}
			continue
		}

		pSrc = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
		if pSrc != 0 {
			var pItem uintptr = pSrc + 8
			(*SrcItem)(unsafe.Pointer(pItem)).FpTab = (*FKey)(unsafe.Pointer(pFKey)).FpFrom
			(*SrcItem)(unsafe.Pointer(pItem)).FzName = (*Table)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName
			(*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpTab)).FnTabRef++
			(*SrcItem)(unsafe.Pointer(pItem)).FiCursor = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)

			if regNew != 0 {
				fkScanChildren(tls, pParse, pSrc, pTab, *(*uintptr)(unsafe.Pointer(bp + 24)), pFKey, *(*uintptr)(unsafe.Pointer(bp + 32)), regNew, -1)
			}
			if regOld != 0 {
				var eAction int32 = int32(*(*U8)(unsafe.Pointer(pFKey + 45 + uintptr(libc.Bool32(aChange != uintptr(0))))))
				fkScanChildren(tls, pParse, pSrc, pTab, *(*uintptr)(unsafe.Pointer(bp + 24)), pFKey, *(*uintptr)(unsafe.Pointer(bp + 32)), regOld, 1)

				if !(int32((*FKey)(unsafe.Pointer(pFKey)).FisDeferred) != 0) && eAction != OE_Cascade && eAction != OE_SetNull {
					Xsqlite3MayAbort(tls, pParse)
				}
			}
			(*SrcItem)(unsafe.Pointer(pItem)).FzName = uintptr(0)
			Xsqlite3SrcListDelete(tls, db, pSrc)
		}
		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 32)))
	}
}

func Xsqlite3FkOldmask(tls *libc.TLS, pParse uintptr, pTab uintptr) U32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var mask U32 = U32(0)
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM {
		var p uintptr
		var i int32
		for p = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8)); p != 0; p = (*FKey)(unsafe.Pointer(p)).FpNextFrom {
			for i = 0; i < (*FKey)(unsafe.Pointer(p)).FnCol; i++ {
				mask = mask | func() uint32 {
					if (*sColMap)(unsafe.Pointer(p+64+uintptr(i)*16)).FiFrom > 31 {
						return 0xffffffff
					}
					return U32(1) << (*sColMap)(unsafe.Pointer(p+64+uintptr(i)*16)).FiFrom
				}()
			}
		}
		for p = Xsqlite3FkReferences(tls, pTab); p != 0; p = (*FKey)(unsafe.Pointer(p)).FpNextTo {
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			Xsqlite3FkLocateIndex(tls, pParse, pTab, p, bp, uintptr(0))
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				for i = 0; i < int32((*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnKeyCol); i++ {
					mask = mask | func() uint32 {
						if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaiColumn + uintptr(i)*2))) > 31 {
							return 0xffffffff
						}
						return U32(1) << int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaiColumn + uintptr(i)*2)))
					}()
				}
			}
		}
	}
	return mask
}

func Xsqlite3FkRequired(tls *libc.TLS, pParse uintptr, pTab uintptr, aChange uintptr, chngRowid int32) int32 {
	var eRet int32 = 1
	var bHaveFK int32 = 0
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_ForeignKeys) != 0 && int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM {
		if !(aChange != 0) {
			bHaveFK = libc.Bool32(Xsqlite3FkReferences(tls, pTab) != 0 || *(*uintptr)(unsafe.Pointer(pTab + 64 + 8)) != 0)
		} else {
			var p uintptr

			for p = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8)); p != 0; p = (*FKey)(unsafe.Pointer(p)).FpNextFrom {
				if fkChildIsModified(tls, pTab, p, aChange, chngRowid) != 0 {
					if 0 == Xsqlite3_stricmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName, (*FKey)(unsafe.Pointer(p)).FzTo) {
						eRet = 2
					}
					bHaveFK = 1
				}
			}

			for p = Xsqlite3FkReferences(tls, pTab); p != 0; p = (*FKey)(unsafe.Pointer(p)).FpNextTo {
				if fkParentIsModified(tls, pTab, p, aChange, chngRowid) != 0 {
					if int32(*(*U8)(unsafe.Pointer(p + 45 + 1))) != OE_None {
						return 2
					}
					bHaveFK = 1
				}
			}
		}
	}
	if bHaveFK != 0 {
		return eRet
	}
	return 0
}

func fkActionTrigger(tls *libc.TLS, pParse uintptr, pTab uintptr, pFKey uintptr, pChanges uintptr) uintptr {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var action int32
	var pTrigger uintptr
	var iAction int32 = libc.Bool32(pChanges != uintptr(0))

	action = int32(*(*U8)(unsafe.Pointer(pFKey + 45 + uintptr(iAction))))
	if action == OE_Restrict && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_DeferFKs) != 0 {
		return uintptr(0)
	}
	pTrigger = *(*uintptr)(unsafe.Pointer(pFKey + 48 + uintptr(iAction)*8))

	if action != OE_None && !(pTrigger != 0) {
		var zFrom uintptr
		var nFrom int32
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		var pStep uintptr = uintptr(0)
		var pWhere uintptr = uintptr(0)
		var pList uintptr = uintptr(0)
		var pSelect uintptr = uintptr(0)
		var i int32
		var pWhen uintptr = uintptr(0)

		if Xsqlite3FkLocateIndex(tls, pParse, pTab, pFKey, bp, bp+8) != 0 {
			return uintptr(0)
		}

		for i = 0; i < (*FKey)(unsafe.Pointer(pFKey)).FnCol; i++ {
			*(*Token)(unsafe.Pointer(bp + 48)) = Token{Fz: ts + 9667, Fn: uint32(3)}
			*(*Token)(unsafe.Pointer(bp + 64)) = Token{Fz: ts + 9663, Fn: uint32(3)}

			var iFromCol int32
			var pEq uintptr

			if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
				iFromCol = *(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + uintptr(i)*4))
			} else {
				iFromCol = (*sColMap)(unsafe.Pointer(pFKey + 64)).FiFrom
			}

			Xsqlite3TokenInit(tls, bp+16,
				(*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(func() int32 {
					if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
						return int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaiColumn + uintptr(i)*2)))
					}
					return int32((*Table)(unsafe.Pointer(pTab)).FiPKey)
				}())*24)).FzCnName)
			Xsqlite3TokenInit(tls, bp+32, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol+uintptr(iFromCol)*24)).FzCnName)

			pEq = Xsqlite3PExpr(tls, pParse, TK_EQ,
				Xsqlite3PExpr(tls, pParse, TK_DOT,
					Xsqlite3ExprAlloc(tls, db, TK_ID, bp+48, 0),
					Xsqlite3ExprAlloc(tls, db, TK_ID, bp+16, 0)),
				Xsqlite3ExprAlloc(tls, db, TK_ID, bp+32, 0))
			pWhere = Xsqlite3ExprAnd(tls, pParse, pWhere, pEq)

			if pChanges != 0 {
				pEq = Xsqlite3PExpr(tls, pParse, TK_IS,
					Xsqlite3PExpr(tls, pParse, TK_DOT,
						Xsqlite3ExprAlloc(tls, db, TK_ID, bp+48, 0),
						Xsqlite3ExprAlloc(tls, db, TK_ID, bp+16, 0)),
					Xsqlite3PExpr(tls, pParse, TK_DOT,
						Xsqlite3ExprAlloc(tls, db, TK_ID, bp+64, 0),
						Xsqlite3ExprAlloc(tls, db, TK_ID, bp+16, 0)))
				pWhen = Xsqlite3ExprAnd(tls, pParse, pWhen, pEq)
			}

			if action != OE_Restrict && (action != OE_Cascade || pChanges != 0) {
				var pNew uintptr
				if action == OE_Cascade {
					pNew = Xsqlite3PExpr(tls, pParse, TK_DOT,
						Xsqlite3ExprAlloc(tls, db, TK_ID, bp+64, 0),
						Xsqlite3ExprAlloc(tls, db, TK_ID, bp+16, 0))
				} else if action == OE_SetDflt {
					var pCol uintptr = (*Table)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpFrom)).FaCol + uintptr(iFromCol)*24
					var pDflt uintptr
					if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_GENERATED != 0 {
						pDflt = uintptr(0)
					} else {
						pDflt = Xsqlite3ColumnExpr(tls, (*FKey)(unsafe.Pointer(pFKey)).FpFrom, pCol)
					}
					if pDflt != 0 {
						pNew = Xsqlite3ExprDup(tls, db, pDflt, 0)
					} else {
						pNew = Xsqlite3ExprAlloc(tls, db, TK_NULL, uintptr(0), 0)
					}
				} else {
					pNew = Xsqlite3ExprAlloc(tls, db, TK_NULL, uintptr(0), 0)
				}
				pList = Xsqlite3ExprListAppend(tls, pParse, pList, pNew)
				Xsqlite3ExprListSetName(tls, pParse, pList, bp+32, 0)
			}
		}
		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8)))

		zFrom = (*Table)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpFrom)).FzName
		nFrom = Xsqlite3Strlen30(tls, zFrom)

		if action == OE_Restrict {
			var iDb int32 = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

			var pRaise uintptr

			(*Token)(unsafe.Pointer(bp + 96)).Fz = zFrom
			(*Token)(unsafe.Pointer(bp + 96)).Fn = uint32(nFrom)
			(*Token)(unsafe.Pointer(bp + 80)).Fz = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
			(*Token)(unsafe.Pointer(bp + 80)).Fn = uint32(Xsqlite3Strlen30(tls, (*Token)(unsafe.Pointer(bp+80)).Fz))

			pRaise = Xsqlite3Expr(tls, db, TK_RAISE, ts+8061)
			if pRaise != 0 {
				(*Expr)(unsafe.Pointer(pRaise)).FaffExpr = uint8(OE_Abort)
			}
			pSelect = Xsqlite3SelectNew(tls, pParse,
				Xsqlite3ExprListAppend(tls, pParse, uintptr(0), pRaise),
				Xsqlite3SrcListAppend(tls, pParse, uintptr(0), bp+80, bp+96),
				pWhere,
				uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
			pWhere = uintptr(0)
		}

		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)

		pTrigger = Xsqlite3DbMallocZero(tls, db,
			uint64(unsafe.Sizeof(Trigger{}))+uint64(unsafe.Sizeof(TriggerStep{}))+uint64(nFrom)+uint64(1))
		if pTrigger != 0 {
			pStep = libc.AssignPtrUintptr(pTrigger+56, pTrigger+1*72)
			(*TriggerStep)(unsafe.Pointer(pStep)).FzTarget = pStep + 1*96
			libc.Xmemcpy(tls, (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget, zFrom, uint64(nFrom))

			(*TriggerStep)(unsafe.Pointer(pStep)).FpWhere = Xsqlite3ExprDup(tls, db, pWhere, EXPRDUP_REDUCE)
			(*TriggerStep)(unsafe.Pointer(pStep)).FpExprList = Xsqlite3ExprListDup(tls, db, pList, EXPRDUP_REDUCE)
			(*TriggerStep)(unsafe.Pointer(pStep)).FpSelect = Xsqlite3SelectDup(tls, db, pSelect, EXPRDUP_REDUCE)
			if pWhen != 0 {
				pWhen = Xsqlite3PExpr(tls, pParse, TK_NOT, pWhen, uintptr(0))
				(*Trigger)(unsafe.Pointer(pTrigger)).FpWhen = Xsqlite3ExprDup(tls, db, pWhen, EXPRDUP_REDUCE)
			}
		}

		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable--
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = func() uint16 {
			if (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
				return uint16(0)
			}
			return (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue
		}()

		Xsqlite3ExprDelete(tls, db, pWhere)
		Xsqlite3ExprDelete(tls, db, pWhen)
		Xsqlite3ExprListDelete(tls, db, pList)
		Xsqlite3SelectDelete(tls, db, pSelect)
		if int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 1 {
			fkTriggerDelete(tls, db, pTrigger)
			return uintptr(0)
		}

		{
			switch action {
			case OE_Restrict:
				(*TriggerStep)(unsafe.Pointer(pStep)).Fop = U8(TK_SELECT)
				break
				fallthrough
			case OE_Cascade:
				if !(pChanges != 0) {
					(*TriggerStep)(unsafe.Pointer(pStep)).Fop = U8(TK_DELETE)
					break
				}
				fallthrough
			default:
				(*TriggerStep)(unsafe.Pointer(pStep)).Fop = U8(TK_UPDATE)
			}
		}
		(*TriggerStep)(unsafe.Pointer(pStep)).FpTrig = pTrigger
		(*Trigger)(unsafe.Pointer(pTrigger)).FpSchema = (*Table)(unsafe.Pointer(pTab)).FpSchema
		(*Trigger)(unsafe.Pointer(pTrigger)).FpTabSchema = (*Table)(unsafe.Pointer(pTab)).FpSchema
		*(*uintptr)(unsafe.Pointer(pFKey + 48 + uintptr(iAction)*8)) = pTrigger
		(*Trigger)(unsafe.Pointer(pTrigger)).Fop = func() uint8 {
			if pChanges != 0 {
				return uint8(TK_UPDATE)
			}
			return uint8(TK_DELETE)
		}()
	}

	return pTrigger
}

func Xsqlite3FkActions(tls *libc.TLS, pParse uintptr, pTab uintptr, pChanges uintptr, regOld int32, aChange uintptr, bChngRowid int32) {
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_ForeignKeys) != 0 {
		var pFKey uintptr
		for pFKey = Xsqlite3FkReferences(tls, pTab); pFKey != 0; pFKey = (*FKey)(unsafe.Pointer(pFKey)).FpNextTo {
			if aChange == uintptr(0) || fkParentIsModified(tls, pTab, pFKey, aChange, bChngRowid) != 0 {
				var pAct uintptr = fkActionTrigger(tls, pParse, pTab, pFKey, pChanges)
				if pAct != 0 {
					Xsqlite3CodeRowTriggerDirect(tls, pParse, pAct, pTab, regOld, OE_Abort, 0)
				}
			}
		}
	}
}

func Xsqlite3FkDelete(tls *libc.TLS, db uintptr, pTab uintptr) {
	var pFKey uintptr
	var pNext uintptr

	for pFKey = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8)); pFKey != 0; pFKey = pNext {
		if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			if (*FKey)(unsafe.Pointer(pFKey)).FpPrevTo != 0 {
				(*FKey)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpPrevTo)).FpNextTo = (*FKey)(unsafe.Pointer(pFKey)).FpNextTo
			} else {
				var p uintptr = (*FKey)(unsafe.Pointer(pFKey)).FpNextTo
				var z uintptr = func() uintptr {
					if p != 0 {
						return (*FKey)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpNextTo)).FzTo
					}
					return (*FKey)(unsafe.Pointer(pFKey)).FzTo
				}()
				Xsqlite3HashInsert(tls, (*Table)(unsafe.Pointer(pTab)).FpSchema+80, z, p)
			}
			if (*FKey)(unsafe.Pointer(pFKey)).FpNextTo != 0 {
				(*FKey)(unsafe.Pointer((*FKey)(unsafe.Pointer(pFKey)).FpNextTo)).FpPrevTo = (*FKey)(unsafe.Pointer(pFKey)).FpPrevTo
			}
		}

		fkTriggerDelete(tls, db, *(*uintptr)(unsafe.Pointer(pFKey + 48)))
		fkTriggerDelete(tls, db, *(*uintptr)(unsafe.Pointer(pFKey + 48 + 1*8)))

		pNext = (*FKey)(unsafe.Pointer(pFKey)).FpNextFrom
		Xsqlite3DbFree(tls, db, pFKey)
	}
}

func Xsqlite3OpenTable(tls *libc.TLS, pParse uintptr, iCur int32, iDb int32, pTab uintptr, opcode int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var v uintptr

	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab)).Ftnum,
		func() uint8 {
			if opcode == OP_OpenWrite {
				return uint8(1)
			}
			return uint8(0)
		}(), (*Table)(unsafe.Pointer(pTab)).FzName)
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
		Xsqlite3VdbeAddOp4Int(tls, v, opcode, iCur, int32((*Table)(unsafe.Pointer(pTab)).Ftnum), iDb, int32((*Table)(unsafe.Pointer(pTab)).FnNVCol))
		Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
	} else {
		var pPk uintptr = Xsqlite3PrimaryKeyIndex(tls, pTab)

		Xsqlite3VdbeAddOp3(tls, v, opcode, iCur, int32((*Index)(unsafe.Pointer(pPk)).Ftnum), iDb)
		Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
		Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+8, (*Table)(unsafe.Pointer(pTab)).FzName))
	}
}

func Xsqlite3IndexAffinityStr(tls *libc.TLS, db uintptr, pIdx uintptr) uintptr {
	if !(int32((*Index)(unsafe.Pointer(pIdx)).FzColAff) != 0) {
		var n int32
		var pTab uintptr = (*Index)(unsafe.Pointer(pIdx)).FpTable
		(*Index)(unsafe.Pointer(pIdx)).FzColAff = Xsqlite3DbMallocRaw(tls, uintptr(0), uint64(int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)+1))
		if !(int32((*Index)(unsafe.Pointer(pIdx)).FzColAff) != 0) {
			Xsqlite3OomFault(tls, db)
			return uintptr(0)
		}
		for n = 0; n < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn); n++ {
			var x I16 = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2))
			var aff uint8
			if int32(x) >= 0 {
				aff = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(x)*24)).Faffinity
			} else if int32(x) == -1 {
				aff = uint8(SQLITE_AFF_INTEGER)
			} else {
				aff = Xsqlite3ExprAffinity(tls, (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr+8+uintptr(n)*32)).FpExpr)
			}
			if int32(aff) < SQLITE_AFF_BLOB {
				aff = uint8(SQLITE_AFF_BLOB)
			}
			if int32(aff) > SQLITE_AFF_NUMERIC {
				aff = uint8(SQLITE_AFF_NUMERIC)
			}
			*(*uint8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FzColAff + uintptr(n))) = aff
		}
		*(*uint8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FzColAff + uintptr(n))) = uint8(0)
	}

	return (*Index)(unsafe.Pointer(pIdx)).FzColAff
}

func Xsqlite3TableAffinityStr(tls *libc.TLS, db uintptr, pTab uintptr) uintptr {
	var zColAff uintptr
	zColAff = Xsqlite3DbMallocRaw(tls, db, uint64(int32((*Table)(unsafe.Pointer(pTab)).FnCol)+1))
	if zColAff != 0 {
		var i int32
		var j int32
		for i = libc.AssignInt32(&j, 0); i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
			if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL == 0 {
				*(*uint8)(unsafe.Pointer(zColAff + uintptr(libc.PostIncInt32(&j, 1)))) = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*24)).Faffinity
			}
		}
		for __ccgo := true; __ccgo; __ccgo = j >= 0 && int32(*(*uint8)(unsafe.Pointer(zColAff + uintptr(j)))) <= SQLITE_AFF_BLOB {
			*(*uint8)(unsafe.Pointer(zColAff + uintptr(libc.PostDecInt32(&j, 1)))) = uint8(0)
		}
	}
	return zColAff
}

func Xsqlite3TableAffinity(tls *libc.TLS, v uintptr, pTab uintptr, iReg int32) {
	var i int32
	var zColAff uintptr
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Strict) != 0 {
		if iReg == 0 {
			var pPrev uintptr
			Xsqlite3VdbeAppendP4(tls, v, pTab, -5)
			pPrev = Xsqlite3VdbeGetLastOp(tls, v)

			(*VdbeOp)(unsafe.Pointer(pPrev)).Fopcode = U8(OP_TypeCheck)
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, (*VdbeOp)(unsafe.Pointer(pPrev)).Fp1, (*VdbeOp)(unsafe.Pointer(pPrev)).Fp2, (*VdbeOp)(unsafe.Pointer(pPrev)).Fp3)
		} else {
			Xsqlite3VdbeAddOp2(tls, v, OP_TypeCheck, iReg, int32((*Table)(unsafe.Pointer(pTab)).FnNVCol))
			Xsqlite3VdbeAppendP4(tls, v, pTab, -5)
		}
		return
	}
	zColAff = (*Table)(unsafe.Pointer(pTab)).FzColAff
	if zColAff == uintptr(0) {
		zColAff = Xsqlite3TableAffinityStr(tls, uintptr(0), pTab)
		if !(zColAff != 0) {
			Xsqlite3OomFault(tls, Xsqlite3VdbeDb(tls, v))
			return
		}
		(*Table)(unsafe.Pointer(pTab)).FzColAff = zColAff
	}

	i = int32(libc.Xstrlen(tls, zColAff) & uint64(0x3fffffff))
	if i != 0 {
		if iReg != 0 {
			Xsqlite3VdbeAddOp4(tls, v, OP_Affinity, iReg, i, 0, zColAff, i)
		} else {
			Xsqlite3VdbeChangeP4(tls, v, -1, zColAff, i)
		}
	}
}

func readsTable(tls *libc.TLS, p uintptr, iDb int32, pTab uintptr) int32 {
	var v uintptr = Xsqlite3GetVdbe(tls, p)
	var i int32
	var iEnd int32 = Xsqlite3VdbeCurrentAddr(tls, v)
	var pVTab uintptr
	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
		pVTab = Xsqlite3GetVTable(tls, (*Parse)(unsafe.Pointer(p)).Fdb, pTab)
	} else {
		pVTab = uintptr(0)
	}

	for i = 1; i < iEnd; i++ {
		var pOp uintptr = Xsqlite3VdbeGetOp(tls, v, i)

		if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_OpenRead && (*VdbeOp)(unsafe.Pointer(pOp)).Fp3 == iDb {
			var pIndex uintptr
			var tnum Pgno = Pgno((*VdbeOp)(unsafe.Pointer(pOp)).Fp2)
			if tnum == (*Table)(unsafe.Pointer(pTab)).Ftnum {
				return 1
			}
			for pIndex = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIndex != 0; pIndex = (*Index)(unsafe.Pointer(pIndex)).FpNext {
				if tnum == (*Index)(unsafe.Pointer(pIndex)).Ftnum {
					return 1
				}
			}
		}
		if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_VOpen && *(*uintptr)(unsafe.Pointer(pOp + 16)) == pVTab {
			return 1
		}
	}
	return 0
}

func exprColumnFlagUnion(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN && int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) >= 0 {
		*(*U16)(unsafe.Pointer(pWalker + 36)) |= U16(int32((*Column)(unsafe.Pointer((*Table1)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalker + 40)))).FaCol + uintptr((*Expr)(unsafe.Pointer(pExpr)).FiColumn)*24)).FcolFlags))
	}
	return WRC_Continue
}

func Xsqlite3ComputeGeneratedColumns(tls *libc.TLS, pParse uintptr, iRegStore int32, pTab uintptr) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var i int32

	var pRedo uintptr
	var eProgress int32
	var pOp uintptr

	Xsqlite3TableAffinity(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, pTab, iRegStore)
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasStored) != U32(0) {
		pOp = Xsqlite3VdbeGetLastOp(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe)
		if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Affinity {
			var ii int32
			var jj int32
			var zP4 uintptr = *(*uintptr)(unsafe.Pointer(pOp + 16))

			for ii = libc.AssignInt32(&jj, 0); *(*uint8)(unsafe.Pointer(zP4 + uintptr(jj))) != 0; ii++ {
				if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(ii)*24)).FcolFlags)&COLFLAG_VIRTUAL != 0 {
					continue
				}
				if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(ii)*24)).FcolFlags)&COLFLAG_STORED != 0 {
					*(*uint8)(unsafe.Pointer(zP4 + uintptr(jj))) = uint8(SQLITE_AFF_NONE)
				}
				jj++
			}
		} else if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_TypeCheck {
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp3 = 1
		}
	}

	for i = 0; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
		if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_GENERATED != 0 {
			*(*U16)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*24 + 16)) |= U16(COLFLAG_NOTAVAIL)
		}
	}

	*(*uintptr)(unsafe.Pointer(bp + 8 + 40)) = pTab
	(*Walker)(unsafe.Pointer(bp + 8)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{exprColumnFlagUnion}))
	(*Walker)(unsafe.Pointer(bp + 8)).FxSelectCallback = uintptr(0)
	(*Walker)(unsafe.Pointer(bp + 8)).FxSelectCallback2 = uintptr(0)

	(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = -iRegStore
	for __ccgo := true; __ccgo; __ccgo = pRedo != 0 && eProgress != 0 {
		eProgress = 0
		pRedo = uintptr(0)
		for i = 0; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
			var pCol uintptr = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*24
			if int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_NOTAVAIL != 0 {
				var x int32
				*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_BUSY)
				(*Walker)(unsafe.Pointer(bp + 8)).FeCode = U16(0)
				Xsqlite3WalkExpr(tls, bp+8, Xsqlite3ColumnExpr(tls, pTab, pCol))
				*(*U16)(unsafe.Pointer(pCol + 16)) &= libc.Uint16FromInt32(libc.CplInt32(COLFLAG_BUSY))
				if int32((*Walker)(unsafe.Pointer(bp+8)).FeCode)&COLFLAG_NOTAVAIL != 0 {
					pRedo = pCol
					continue
				}
				eProgress = 1

				x = int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(i))) + iRegStore
				Xsqlite3ExprCodeGeneratedColumn(tls, pParse, pTab, pCol, x)
				*(*U16)(unsafe.Pointer(pCol + 16)) &= libc.Uint16FromInt32(libc.CplInt32(COLFLAG_NOTAVAIL))
			}
		}
	}
	if pRedo != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+11318, libc.VaList(bp, (*Column)(unsafe.Pointer(pRedo)).FzCnName))
	}
	(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = 0
}

func autoIncBegin(tls *libc.TLS, pParse uintptr, iDb int32, pTab uintptr) int32 {
	var memId int32 = 0

	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Autoincrement) != U32(0) &&
		(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmDbFlags&U32(DBFLAG_Vacuum) == U32(0) {
		var pToplevel uintptr = func() uintptr {
			if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
				return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
			}
			return pParse
		}()
		var pInfo uintptr
		var pSeqTab uintptr = (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*32)).FpSchema)).FpSeqTab

		if pSeqTab == uintptr(0) ||
			!((*Table)(unsafe.Pointer(pSeqTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) ||
			int32((*Table)(unsafe.Pointer(pSeqTab)).FeTabType) == TABTYP_VTAB ||
			int32((*Table)(unsafe.Pointer(pSeqTab)).FnCol) != 2 {
			(*Parse)(unsafe.Pointer(pParse)).FnErr++
			(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_CORRUPT | int32(2)<<8
			return 0
		}

		pInfo = (*Parse)(unsafe.Pointer(pToplevel)).FpAinc
		for pInfo != 0 && (*AutoincInfo)(unsafe.Pointer(pInfo)).FpTab != pTab {
			pInfo = (*AutoincInfo)(unsafe.Pointer(pInfo)).FpNext
		}
		if pInfo == uintptr(0) {
			pInfo = Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(AutoincInfo{})))
			Xsqlite3ParserAddCleanup(tls, pToplevel, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr)
			}{Xsqlite3DbFree})), pInfo)

			if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
				return 0
			}
			(*AutoincInfo)(unsafe.Pointer(pInfo)).FpNext = (*Parse)(unsafe.Pointer(pToplevel)).FpAinc
			(*Parse)(unsafe.Pointer(pToplevel)).FpAinc = pInfo
			(*AutoincInfo)(unsafe.Pointer(pInfo)).FpTab = pTab
			(*AutoincInfo)(unsafe.Pointer(pInfo)).FiDb = iDb
			(*Parse)(unsafe.Pointer(pToplevel)).FnMem++
			(*AutoincInfo)(unsafe.Pointer(pInfo)).FregCtr = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pToplevel)).FnMem, 1)
			*(*int32)(unsafe.Pointer(pToplevel + 56)) += 2
		}
		memId = (*AutoincInfo)(unsafe.Pointer(pInfo)).FregCtr
	}
	return memId
}

func Xsqlite3AutoincrementBegin(tls *libc.TLS, pParse uintptr) {
	var p uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pDb uintptr
	var memId int32
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	for p = (*Parse)(unsafe.Pointer(pParse)).FpAinc; p != 0; p = (*AutoincInfo)(unsafe.Pointer(p)).FpNext {
		var aOp uintptr
		pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*AutoincInfo)(unsafe.Pointer(p)).FiDb)*32
		memId = (*AutoincInfo)(unsafe.Pointer(p)).FregCtr

		Xsqlite3OpenTable(tls, pParse, 0, (*AutoincInfo)(unsafe.Pointer(p)).FiDb, (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab, OP_OpenRead)
		Xsqlite3VdbeLoadString(tls, v, memId-1, (*Table)(unsafe.Pointer((*AutoincInfo)(unsafe.Pointer(p)).FpTab)).FzName)
		aOp = Xsqlite3VdbeAddOpList(tls, v, int32(uint64(unsafe.Sizeof(autoInc))/uint64(unsafe.Sizeof(VdbeOpList{}))), uintptr(unsafe.Pointer(&autoInc)), iLn1)
		if aOp == uintptr(0) {
			break
		}
		(*VdbeOp)(unsafe.Pointer(aOp)).Fp2 = memId
		(*VdbeOp)(unsafe.Pointer(aOp)).Fp3 = memId + 2
		(*VdbeOp)(unsafe.Pointer(aOp + 2*32)).Fp3 = memId
		(*VdbeOp)(unsafe.Pointer(aOp + 3*32)).Fp1 = memId - 1
		(*VdbeOp)(unsafe.Pointer(aOp + 3*32)).Fp3 = memId
		(*VdbeOp)(unsafe.Pointer(aOp + 3*32)).Fp5 = U16(SQLITE_JUMPIFNULL)
		(*VdbeOp)(unsafe.Pointer(aOp + 4*32)).Fp2 = memId + 1
		(*VdbeOp)(unsafe.Pointer(aOp + 5*32)).Fp3 = memId
		(*VdbeOp)(unsafe.Pointer(aOp + 6*32)).Fp1 = memId
		(*VdbeOp)(unsafe.Pointer(aOp + 7*32)).Fp2 = memId + 2
		(*VdbeOp)(unsafe.Pointer(aOp + 7*32)).Fp1 = memId
		(*VdbeOp)(unsafe.Pointer(aOp + 10*32)).Fp2 = memId
		if (*Parse)(unsafe.Pointer(pParse)).FnTab == 0 {
			(*Parse)(unsafe.Pointer(pParse)).FnTab = 1
		}
	}
}

var iLn1 int32 = 0
var autoInc = [12]VdbeOpList{
	{Fopcode: U8(OP_Null)},
	{Fopcode: U8(OP_Rewind), Fp2: int8(10)},
	{Fopcode: U8(OP_Column)},
	{Fopcode: U8(OP_Ne), Fp2: int8(9)},
	{Fopcode: U8(OP_Rowid)},
	{Fopcode: U8(OP_Column), Fp2: int8(1)},
	{Fopcode: U8(OP_AddImm)},
	{Fopcode: U8(OP_Copy)},
	{Fopcode: U8(OP_Goto), Fp2: int8(11)},
	{Fopcode: U8(OP_Next), Fp2: int8(2)},
	{Fopcode: U8(OP_Integer)},
	{Fopcode: U8(OP_Close)},
}

func autoIncStep(tls *libc.TLS, pParse uintptr, memId int32, regRowid int32) {
	if memId > 0 {
		Xsqlite3VdbeAddOp2(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, OP_MemMax, memId, regRowid)
	}
}

func autoIncrementEnd(tls *libc.TLS, pParse uintptr) {
	var p uintptr
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	for p = (*Parse)(unsafe.Pointer(pParse)).FpAinc; p != 0; p = (*AutoincInfo)(unsafe.Pointer(p)).FpNext {
		var aOp uintptr
		var pDb uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*AutoincInfo)(unsafe.Pointer(p)).FiDb)*32
		var iRec int32
		var memId int32 = (*AutoincInfo)(unsafe.Pointer(p)).FregCtr

		iRec = Xsqlite3GetTempReg(tls, pParse)

		Xsqlite3VdbeAddOp3(tls, v, OP_Le, memId+2, Xsqlite3VdbeCurrentAddr(tls, v)+7, memId)

		Xsqlite3OpenTable(tls, pParse, 0, (*AutoincInfo)(unsafe.Pointer(p)).FiDb, (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).FpSeqTab, OP_OpenWrite)
		aOp = Xsqlite3VdbeAddOpList(tls, v, int32(uint64(unsafe.Sizeof(autoIncEnd))/uint64(unsafe.Sizeof(VdbeOpList{}))), uintptr(unsafe.Pointer(&autoIncEnd)), iLn2)
		if aOp == uintptr(0) {
			break
		}
		(*VdbeOp)(unsafe.Pointer(aOp)).Fp1 = memId + 1
		(*VdbeOp)(unsafe.Pointer(aOp + 1*32)).Fp2 = memId + 1
		(*VdbeOp)(unsafe.Pointer(aOp + 2*32)).Fp1 = memId - 1
		(*VdbeOp)(unsafe.Pointer(aOp + 2*32)).Fp3 = iRec
		(*VdbeOp)(unsafe.Pointer(aOp + 3*32)).Fp2 = iRec
		(*VdbeOp)(unsafe.Pointer(aOp + 3*32)).Fp3 = memId + 1
		(*VdbeOp)(unsafe.Pointer(aOp + 3*32)).Fp5 = U16(OPFLAG_APPEND)
		Xsqlite3ReleaseTempReg(tls, pParse, iRec)
	}
}

var iLn2 int32 = 0
var autoIncEnd = [5]VdbeOpList{
	{Fopcode: U8(OP_NotNull), Fp2: int8(2)},
	{Fopcode: U8(OP_NewRowid)},
	{Fopcode: U8(OP_MakeRecord), Fp2: int8(2)},
	{Fopcode: U8(OP_Insert)},
	{Fopcode: U8(OP_Close)},
}

func Xsqlite3AutoincrementEnd(tls *libc.TLS, pParse uintptr) {
	if (*Parse)(unsafe.Pointer(pParse)).FpAinc != 0 {
		autoIncrementEnd(tls, pParse)
	}
}

func Xsqlite3Insert(tls *libc.TLS, pParse uintptr, pTabList uintptr, pSelect uintptr, pColumn uintptr, onError int32, pUpsert uintptr) {
	bp := tls.Alloc(188)
	defer tls.Free(188)

	var db uintptr
	var pTab uintptr
	var i int32
	var j int32
	var v uintptr
	var pIdx uintptr
	var nColumn int32
	var nHidden int32

	var ipkColumn int32
	var endOfLoop int32
	var srcTab int32
	var addrInsTop int32
	var addrCont int32

	var iDb int32
	var useTempTable U8
	var appendFlag U8
	var withoutRowid U8
	var bIdListInOrder U8
	var pList uintptr
	var iRegStore int32

	var regFromSelect int32
	var regAutoinc int32
	var regRowCount int32
	var regIns int32
	var regRowid int32
	var regData int32
	var aRegIdx uintptr

	var isView int32
	var pTrigger uintptr

	var regRec int32
	var regTempRowid int32
	var addrL int32

	var regYield int32
	var addrTop int32
	var rc int32

	var nIdx int32
	var pNx uintptr
	var pX uintptr
	var y int32
	var k int32
	var colFlags U32
	var addr1 int32
	var regCols int32
	var pIpk uintptr
	var addr11 int32
	var pVTab uintptr

	var bUseSeek int32
	nHidden = 0
	*(*int32)(unsafe.Pointer(bp + 176)) = 0
	*(*int32)(unsafe.Pointer(bp + 180)) = 0
	ipkColumn = -1
	srcTab = 0
	addrInsTop = 0
	addrCont = 0
	useTempTable = U8(0)
	appendFlag = U8(0)
	pList = uintptr(0)
	regFromSelect = 0
	regAutoinc = 0
	regRowCount = 0
	aRegIdx = uintptr(0)

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __1
	}
	goto insert_cleanup
__1:
	;
	(*SelectDest)(unsafe.Pointer(bp + 80)).FiSDParm = 0

	if !(pSelect != 0 && (*Select)(unsafe.Pointer(pSelect)).FselFlags&U32(SF_Values) != U32(0) && (*Select)(unsafe.Pointer(pSelect)).FpPrior == uintptr(0)) {
		goto __2
	}
	pList = (*Select)(unsafe.Pointer(pSelect)).FpEList
	(*Select)(unsafe.Pointer(pSelect)).FpEList = uintptr(0)
	Xsqlite3SelectDelete(tls, db, pSelect)
	pSelect = uintptr(0)
__2:
	;
	pTab = Xsqlite3SrcListLookup(tls, pParse, pTabList)
	if !(pTab == uintptr(0)) {
		goto __3
	}
	goto insert_cleanup
__3:
	;
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_INSERT, (*Table)(unsafe.Pointer(pTab)).FzName, uintptr(0),
		(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName) != 0) {
		goto __4
	}
	goto insert_cleanup
__4:
	;
	withoutRowid = libc.BoolUint8(!((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)))

	pTrigger = Xsqlite3TriggersExist(tls, pParse, pTab, TK_INSERT, uintptr(0), bp+72)
	isView = libc.Bool32(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW)

	if !(Xsqlite3ViewGetColumnNames(tls, pParse, pTab) != 0) {
		goto __5
	}
	goto insert_cleanup
__5:
	;
	if !(Xsqlite3IsReadOnly(tls, pParse, pTab, *(*int32)(unsafe.Pointer(bp + 72))) != 0) {
		goto __6
	}
	goto insert_cleanup
__6:
	;
	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v == uintptr(0)) {
		goto __7
	}
	goto insert_cleanup
__7:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0) {
		goto __8
	}
	Xsqlite3VdbeCountChanges(tls, v)
__8:
	;
	Xsqlite3BeginWriteOperation(tls, pParse, libc.Bool32(pSelect != 0 || pTrigger != 0), iDb)

	if !(pColumn == uintptr(0) &&
		pSelect != uintptr(0) &&
		pTrigger == uintptr(0) &&
		xferOptimization(tls, pParse, pTab, pSelect, onError, iDb) != 0) {
		goto __9
	}

	goto insert_end
__9:
	;
	regAutoinc = autoIncBegin(tls, pParse, iDb, pTab)

	regRowid = libc.AssignInt32(&regIns, (*Parse)(unsafe.Pointer(pParse)).FnMem+1)
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32((*Table)(unsafe.Pointer(pTab)).FnCol) + 1
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __10
	}
	regRowid++
	(*Parse)(unsafe.Pointer(pParse)).FnMem++
__10:
	;
	regData = regRowid + 1

	bIdListInOrder = U8(libc.Bool32((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_OOOHidden|TF_HasStored) == U32(0)))
	if !(pColumn != 0) {
		goto __11
	}

	(*IdList)(unsafe.Pointer(pColumn)).FeU4 = U8(EU4_IDX)
	i = 0
__12:
	if !(i < (*IdList)(unsafe.Pointer(pColumn)).FnId) {
		goto __14
	}
	*(*int32)(unsafe.Pointer(pColumn + 8 + uintptr(i)*16 + 8)) = -1
	goto __13
__13:
	i++
	goto __12
	goto __14
__14:
	;
	i = 0
__15:
	if !(i < (*IdList)(unsafe.Pointer(pColumn)).FnId) {
		goto __17
	}
	j = 0
__18:
	if !(j < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __20
	}
	if !(Xsqlite3StrICmp(tls, (*IdList_item)(unsafe.Pointer(pColumn+8+uintptr(i)*16)).FzName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FzCnName) == 0) {
		goto __21
	}
	*(*int32)(unsafe.Pointer(pColumn + 8 + uintptr(i)*16 + 8)) = j
	if !(i != j) {
		goto __22
	}
	bIdListInOrder = U8(0)
__22:
	;
	if !(j == int32((*Table)(unsafe.Pointer(pTab)).FiPKey)) {
		goto __23
	}
	ipkColumn = i
__23:
	;
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FcolFlags)&(COLFLAG_STORED|COLFLAG_VIRTUAL) != 0) {
		goto __24
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+19070,
		libc.VaList(bp, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FzCnName))
	goto insert_cleanup
__24:
	;
	goto __20
__21:
	;
	goto __19
__19:
	j++
	goto __18
	goto __20
__20:
	;
	if !(j >= int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __25
	}
	if !(Xsqlite3IsRowid(tls, (*IdList_item)(unsafe.Pointer(pColumn+8+uintptr(i)*16)).FzName) != 0 && !(withoutRowid != 0)) {
		goto __26
	}
	ipkColumn = i
	bIdListInOrder = U8(0)
	goto __27
__26:
	Xsqlite3ErrorMsg(tls, pParse, ts+19111,
		libc.VaList(bp+8, pTabList+8, (*IdList_item)(unsafe.Pointer(pColumn+8+uintptr(i)*16)).FzName))
	(*Parse)(unsafe.Pointer(pParse)).FcheckSchema = U8(1)
	goto insert_cleanup
__27:
	;
__25:
	;
	goto __16
__16:
	i++
	goto __15
	goto __17
__17:
	;
__11:
	;
	if !(pSelect != 0) {
		goto __28
	}

	regYield = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	addrTop = Xsqlite3VdbeCurrentAddr(tls, v) + 1
	Xsqlite3VdbeAddOp3(tls, v, OP_InitCoroutine, regYield, 0, addrTop)
	Xsqlite3SelectDestInit(tls, bp+80, SRT_Coroutine, regYield)
	(*SelectDest)(unsafe.Pointer(bp + 80)).FiSdst = func() int32 {
		if bIdListInOrder != 0 {
			return regData
		}
		return 0
	}()
	(*SelectDest)(unsafe.Pointer(bp + 80)).FnSdst = int32((*Table)(unsafe.Pointer(pTab)).FnCol)
	rc = Xsqlite3Select(tls, pParse, pSelect, bp+80)
	regFromSelect = (*SelectDest)(unsafe.Pointer(bp + 80)).FiSdst

	if !(rc != 0 || (*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __30
	}
	goto insert_cleanup
__30:
	;
	Xsqlite3VdbeEndCoroutine(tls, v, regYield)
	Xsqlite3VdbeJumpHere(tls, v, addrTop-1)

	nColumn = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpEList)).FnExpr

	if !(pTrigger != 0 || readsTable(tls, pParse, iDb, pTab) != 0) {
		goto __31
	}
	useTempTable = U8(1)
__31:
	;
	if !(useTempTable != 0) {
		goto __32
	}

	srcTab = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	regRec = Xsqlite3GetTempReg(tls, pParse)
	regTempRowid = Xsqlite3GetTempReg(tls, pParse)
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, srcTab, nColumn)
	addrL = Xsqlite3VdbeAddOp1(tls, v, OP_Yield, (*SelectDest)(unsafe.Pointer(bp+80)).FiSDParm)
	Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regFromSelect, nColumn, regRec)
	Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, srcTab, regTempRowid)
	Xsqlite3VdbeAddOp3(tls, v, OP_Insert, srcTab, regRec, regTempRowid)
	Xsqlite3VdbeGoto(tls, v, addrL)
	Xsqlite3VdbeJumpHere(tls, v, addrL)
	Xsqlite3ReleaseTempReg(tls, pParse, regRec)
	Xsqlite3ReleaseTempReg(tls, pParse, regTempRowid)
__32:
	;
	goto __29
__28:
	libc.Xmemset(tls, bp+120, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp + 120)).FpParse = pParse
	srcTab = -1

	if !(pList != 0) {
		goto __33
	}
	nColumn = (*ExprList)(unsafe.Pointer(pList)).FnExpr
	if !(Xsqlite3ResolveExprListNames(tls, bp+120, pList) != 0) {
		goto __35
	}
	goto insert_cleanup
__35:
	;
	goto __34
__33:
	nColumn = 0
__34:
	;
__29:
	;
	if !(pColumn == uintptr(0) && nColumn > 0) {
		goto __36
	}
	ipkColumn = int32((*Table)(unsafe.Pointer(pTab)).FiPKey)
	if !(ipkColumn >= 0 && (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated) != U32(0)) {
		goto __37
	}

	i = ipkColumn - 1
__38:
	if !(i >= 0) {
		goto __40
	}
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_GENERATED != 0) {
		goto __41
	}

	ipkColumn--
__41:
	;
	goto __39
__39:
	i--
	goto __38
	goto __40
__40:
	;
__37:
	;
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated|TF_HasHidden) != U32(0)) {
		goto __42
	}
	i = 0
__43:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __45
	}
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_NOINSERT != 0) {
		goto __46
	}
	nHidden++
__46:
	;
	goto __44
__44:
	i++
	goto __43
	goto __45
__45:
	;
__42:
	;
	if !(nColumn != int32((*Table)(unsafe.Pointer(pTab)).FnCol)-nHidden) {
		goto __47
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+19143,
		libc.VaList(bp+24, pTabList+8, int32((*Table)(unsafe.Pointer(pTab)).FnCol)-nHidden, nColumn))
	goto insert_cleanup
__47:
	;
__36:
	;
	if !(pColumn != uintptr(0) && nColumn != (*IdList)(unsafe.Pointer(pColumn)).FnId) {
		goto __48
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+19195, libc.VaList(bp+48, nColumn, (*IdList)(unsafe.Pointer(pColumn)).FnId))
	goto insert_cleanup
__48:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&(uint64(0x00001)<<32) != uint64(0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) != 0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FpTriggerTab) != 0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FbReturning) != 0)) {
		goto __49
	}
	regRowCount = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regRowCount)
__49:
	;
	if !!(isView != 0) {
		goto __50
	}
	nIdx = Xsqlite3OpenTableAndIndices(tls, pParse, pTab, OP_OpenWrite, uint8(0), -1, uintptr(0),
		bp+176, bp+180)
	aRegIdx = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(int32(0)))*uint64(nIdx+2))
	if !(aRegIdx == uintptr(0)) {
		goto __51
	}
	goto insert_cleanup
__51:
	;
	i = 0
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__52:
	if !(i < nIdx) {
		goto __54
	}

	*(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)) = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
	goto __53
__53:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	i++
	goto __52
	goto __54
__54:
	;
	*(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)) = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
__50:
	;
	if !(pUpsert != 0) {
		goto __55
	}
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __56
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+19220,
		libc.VaList(bp+64, (*Table)(unsafe.Pointer(pTab)).FzName))
	goto insert_cleanup
__56:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		goto __57
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+19266, 0)
	goto insert_cleanup
__57:
	;
	if !(Xsqlite3HasExplicitNulls(tls, pParse, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget) != 0) {
		goto __58
	}
	goto insert_cleanup
__58:
	;
	(*SrcItem)(unsafe.Pointer(pTabList + 8)).FiCursor = *(*int32)(unsafe.Pointer(bp + 176))
	pNx = pUpsert
__59:
	(*Upsert)(unsafe.Pointer(pNx)).FpUpsertSrc = pTabList
	(*Upsert)(unsafe.Pointer(pNx)).FregData = regData
	(*Upsert)(unsafe.Pointer(pNx)).FiDataCur = *(*int32)(unsafe.Pointer(bp + 176))
	(*Upsert)(unsafe.Pointer(pNx)).FiIdxCur = *(*int32)(unsafe.Pointer(bp + 180))
	if !((*Upsert)(unsafe.Pointer(pNx)).FpUpsertTarget != 0) {
		goto __62
	}
	if !(Xsqlite3UpsertAnalyzeTarget(tls, pParse, pTabList, pNx) != 0) {
		goto __63
	}
	goto insert_cleanup
__63:
	;
__62:
	;
	pNx = (*Upsert)(unsafe.Pointer(pNx)).FpNextUpsert
	goto __60
__60:
	if pNx != uintptr(0) {
		goto __59
	}
	goto __61
__61:
	;
__55:
	;
	if !(useTempTable != 0) {
		goto __64
	}

	addrInsTop = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, srcTab)
	addrCont = Xsqlite3VdbeCurrentAddr(tls, v)
	goto __65
__64:
	if !(pSelect != 0) {
		goto __66
	}

	addrInsTop = libc.AssignInt32(&addrCont, Xsqlite3VdbeAddOp1(tls, v, OP_Yield, (*SelectDest)(unsafe.Pointer(bp+80)).FiSDParm))

	if !(ipkColumn >= 0) {
		goto __67
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_Copy, regFromSelect+ipkColumn, regRowid)
__67:
	;
__66:
	;
__65:
	;
	nHidden = 0
	iRegStore = regData
	i = 0
__68:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __70
	}

	if !(i == int32((*Table)(unsafe.Pointer(pTab)).FiPKey)) {
		goto __71
	}

	Xsqlite3VdbeAddOp1(tls, v, OP_SoftNull, iRegStore)
	goto __69
__71:
	;
	if !(libc.AssignUint32(&colFlags, U32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags))&U32(COLFLAG_NOINSERT) != U32(0)) {
		goto __72
	}
	nHidden++
	if !(colFlags&U32(COLFLAG_VIRTUAL) != U32(0)) {
		goto __73
	}

	iRegStore--
	goto __69
	goto __74
__73:
	if !(colFlags&U32(COLFLAG_STORED) != U32(0)) {
		goto __75
	}

	if !(*(*int32)(unsafe.Pointer(bp + 72))&TRIGGER_BEFORE != 0) {
		goto __77
	}
	Xsqlite3VdbeAddOp1(tls, v, OP_SoftNull, iRegStore)
__77:
	;
	goto __69
	goto __76
__75:
	if !(pColumn == uintptr(0)) {
		goto __78
	}

	Xsqlite3ExprCodeFactorable(tls, pParse,
		Xsqlite3ColumnExpr(tls, pTab, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24),
		iRegStore)
	goto __69
__78:
	;
__76:
	;
__74:
	;
__72:
	;
	if !(pColumn != 0) {
		goto __79
	}

	j = 0
__81:
	if !(j < (*IdList)(unsafe.Pointer(pColumn)).FnId && *(*int32)(unsafe.Pointer(pColumn + 8 + uintptr(j)*16 + 8)) != i) {
		goto __83
	}
	goto __82
__82:
	j++
	goto __81
	goto __83
__83:
	;
	if !(j >= (*IdList)(unsafe.Pointer(pColumn)).FnId) {
		goto __84
	}

	Xsqlite3ExprCodeFactorable(tls, pParse,
		Xsqlite3ColumnExpr(tls, pTab, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24),
		iRegStore)
	goto __69
__84:
	;
	k = j
	goto __80
__79:
	if !(nColumn == 0) {
		goto __85
	}

	Xsqlite3ExprCodeFactorable(tls, pParse,
		Xsqlite3ColumnExpr(tls, pTab, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24),
		iRegStore)
	goto __69
	goto __86
__85:
	k = i - nHidden
__86:
	;
__80:
	;
	if !(useTempTable != 0) {
		goto __87
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, srcTab, k, iRegStore)
	goto __88
__87:
	if !(pSelect != 0) {
		goto __89
	}
	if !(regFromSelect != regData) {
		goto __91
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_SCopy, regFromSelect+k, iRegStore)
__91:
	;
	goto __90
__89:
	pX = (*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(k)*32)).FpExpr
	y = Xsqlite3ExprCodeTarget(tls, pParse, pX, iRegStore)
	if !(y != iRegStore) {
		goto __92
	}
	Xsqlite3VdbeAddOp2(tls, v,
		func() int32 {
			if (*Expr)(unsafe.Pointer(pX)).Fflags&U32(EP_Subquery) != U32(0) {
				return OP_Copy
			}
			return OP_SCopy
		}(), y, iRegStore)
__92:
	;
__90:
	;
__88:
	;
	goto __69
__69:
	i++
	iRegStore++
	goto __68
	goto __70
__70:
	;
	endOfLoop = Xsqlite3VdbeMakeLabel(tls, pParse)
	if !(*(*int32)(unsafe.Pointer(bp + 72))&TRIGGER_BEFORE != 0) {
		goto __93
	}
	regCols = Xsqlite3GetTempRange(tls, pParse, int32((*Table)(unsafe.Pointer(pTab)).FnCol)+1)

	if !(ipkColumn < 0) {
		goto __94
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, -1, regCols)
	goto __95
__94:
	;
	if !(useTempTable != 0) {
		goto __96
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, srcTab, ipkColumn, regCols)
	goto __97
__96:
	;
	Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(ipkColumn)*32)).FpExpr, regCols)
__97:
	;
	addr1 = Xsqlite3VdbeAddOp1(tls, v, OP_NotNull, regCols)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, -1, regCols)
	Xsqlite3VdbeJumpHere(tls, v, addr1)
	Xsqlite3VdbeAddOp1(tls, v, OP_MustBeInt, regCols)
__95:
	;
	Xsqlite3VdbeAddOp3(tls, v, OP_Copy, regRowid+1, regCols+1, int32((*Table)(unsafe.Pointer(pTab)).FnNVCol)-1)

	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated) != 0) {
		goto __98
	}

	Xsqlite3ComputeGeneratedColumns(tls, pParse, regCols+1, pTab)
__98:
	;
	if !!(isView != 0) {
		goto __99
	}
	Xsqlite3TableAffinity(tls, v, pTab, regCols+1)
__99:
	;
	Xsqlite3CodeRowTrigger(tls, pParse, pTrigger, TK_INSERT, uintptr(0), TRIGGER_BEFORE,
		pTab, regCols-int32((*Table)(unsafe.Pointer(pTab)).FnCol)-1, onError, endOfLoop)

	Xsqlite3ReleaseTempRange(tls, pParse, regCols, int32((*Table)(unsafe.Pointer(pTab)).FnCol)+1)
__93:
	;
	if !!(isView != 0) {
		goto __100
	}
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __101
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regIns)
__101:
	;
	if !(ipkColumn >= 0) {
		goto __102
	}

	if !(useTempTable != 0) {
		goto __104
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, srcTab, ipkColumn, regRowid)
	goto __105
__104:
	if !(pSelect != 0) {
		goto __106
	}

	goto __107
__106:
	pIpk = (*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(ipkColumn)*32)).FpExpr
	if !(int32((*Expr)(unsafe.Pointer(pIpk)).Fop) == TK_NULL && !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB)) {
		goto __108
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_NewRowid, *(*int32)(unsafe.Pointer(bp + 176)), regRowid, regAutoinc)
	appendFlag = U8(1)
	goto __109
__108:
	Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(ipkColumn)*32)).FpExpr, regRowid)
__109:
	;
__107:
	;
__105:
	;
	if !!(appendFlag != 0) {
		goto __110
	}
	if !!(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __111
	}
	addr11 = Xsqlite3VdbeAddOp1(tls, v, OP_NotNull, regRowid)
	Xsqlite3VdbeAddOp3(tls, v, OP_NewRowid, *(*int32)(unsafe.Pointer(bp + 176)), regRowid, regAutoinc)
	Xsqlite3VdbeJumpHere(tls, v, addr11)
	goto __112
__111:
	addr11 = Xsqlite3VdbeCurrentAddr(tls, v)
	Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, regRowid, addr11+2)
__112:
	;
	Xsqlite3VdbeAddOp1(tls, v, OP_MustBeInt, regRowid)
__110:
	;
	goto __103
__102:
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB || withoutRowid != 0) {
		goto __113
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regRowid)
	goto __114
__113:
	Xsqlite3VdbeAddOp3(tls, v, OP_NewRowid, *(*int32)(unsafe.Pointer(bp + 176)), regRowid, regAutoinc)
	appendFlag = U8(1)
__114:
	;
__103:
	;
	autoIncStep(tls, pParse, regAutoinc, regRowid)

	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated) != 0) {
		goto __115
	}
	Xsqlite3ComputeGeneratedColumns(tls, pParse, regRowid+1, pTab)
__115:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __116
	}
	pVTab = Xsqlite3GetVTable(tls, db, pTab)
	Xsqlite3VtabMakeWritable(tls, pParse, pTab)
	Xsqlite3VdbeAddOp4(tls, v, OP_VUpdate, 1, int32((*Table)(unsafe.Pointer(pTab)).FnCol)+2, regIns, pVTab, -11)
	Xsqlite3VdbeChangeP5(tls, v, func() uint16 {
		if onError == OE_Default {
			return uint16(OE_Abort)
		}
		return uint16(onError)
	}())
	Xsqlite3MayAbort(tls, pParse)
	goto __117
__116:
	*(*int32)(unsafe.Pointer(bp + 184)) = 0
	Xsqlite3GenerateConstraintChecks(tls, pParse, pTab, aRegIdx, *(*int32)(unsafe.Pointer(bp + 176)), *(*int32)(unsafe.Pointer(bp + 180)),
		regIns, 0, uint8(libc.Bool32(ipkColumn >= 0)), uint8(onError), endOfLoop, bp+184, uintptr(0), pUpsert)
	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != 0) {
		goto __118
	}
	Xsqlite3FkCheck(tls, pParse, pTab, 0, regIns, uintptr(0), 0)
__118:
	;
	bUseSeek = libc.Bool32(*(*int32)(unsafe.Pointer(bp + 184)) == 0 || !(Xsqlite3VdbeHasSubProgram(tls, v) != 0))
	Xsqlite3CompleteInsertion(tls, pParse, pTab, *(*int32)(unsafe.Pointer(bp + 176)), *(*int32)(unsafe.Pointer(bp + 180)),
		regIns, aRegIdx, 0, int32(appendFlag), bUseSeek)
__117:
	;
__100:
	;
	if !(regRowCount != 0) {
		goto __119
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, regRowCount, 1)
__119:
	;
	if !(pTrigger != 0) {
		goto __120
	}

	Xsqlite3CodeRowTrigger(tls, pParse, pTrigger, TK_INSERT, uintptr(0), TRIGGER_AFTER,
		pTab, regData-2-int32((*Table)(unsafe.Pointer(pTab)).FnCol), onError, endOfLoop)
__120:
	;
	Xsqlite3VdbeResolveLabel(tls, v, endOfLoop)
	if !(useTempTable != 0) {
		goto __121
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, srcTab, addrCont)
	Xsqlite3VdbeJumpHere(tls, v, addrInsTop)
	Xsqlite3VdbeAddOp1(tls, v, OP_Close, srcTab)
	goto __122
__121:
	if !(pSelect != 0) {
		goto __123
	}
	Xsqlite3VdbeGoto(tls, v, addrCont)
	Xsqlite3VdbeJumpHere(tls, v, addrInsTop)
__123:
	;
__122:
	;
insert_end:
	if !(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0)) {
		goto __124
	}
	Xsqlite3AutoincrementEnd(tls, pParse)
__124:
	;
	if !(regRowCount != 0) {
		goto __125
	}
	Xsqlite3CodeChangeCount(tls, v, regRowCount, ts+19287)
__125:
	;
insert_cleanup:
	Xsqlite3SrcListDelete(tls, db, pTabList)
	Xsqlite3ExprListDelete(tls, db, pList)
	Xsqlite3UpsertDelete(tls, db, pUpsert)
	Xsqlite3SelectDelete(tls, db, pSelect)
	Xsqlite3IdListDelete(tls, db, pColumn)
	if !(aRegIdx != 0) {
		goto __126
	}
	Xsqlite3DbNNFreeNN(tls, db, aRegIdx)
__126:
}

func checkConstraintExprNode(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN {
		if int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) >= 0 {
			if *(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalker + 40)) + uintptr((*Expr)(unsafe.Pointer(pExpr)).FiColumn)*4)) >= 0 {
				*(*U16)(unsafe.Pointer(pWalker + 36)) |= U16(CKCNSTRNT_COLUMN)
			}
		} else {
			*(*U16)(unsafe.Pointer(pWalker + 36)) |= U16(CKCNSTRNT_ROWID)
		}
	}
	return WRC_Continue
}

func Xsqlite3ExprReferencesUpdatedColumn(tls *libc.TLS, pExpr uintptr, aiChng uintptr, chngRowid int32) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(bp)).FeCode = U16(0)
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{checkConstraintExprNode}))
	*(*uintptr)(unsafe.Pointer(bp + 40)) = aiChng
	Xsqlite3WalkExpr(tls, bp, pExpr)
	if !(chngRowid != 0) {
		*(*U16)(unsafe.Pointer(bp + 36)) &= libc.Uint16FromInt32(libc.CplInt32(CKCNSTRNT_ROWID))
	}

	return libc.Bool32(int32((*Walker)(unsafe.Pointer(bp)).FeCode) != 0)
}

type IndexListTerm1 = struct {
	Fp           uintptr
	Fix          int32
	F__ccgo_pad1 [4]byte
}

type IndexListTerm = IndexListTerm1
type IndexIterator1 = struct {
	FeType int32
	Fi     int32
	Fu     struct {
		Flx          struct{ FpIdx uintptr }
		F__ccgo_pad1 [8]byte
	}
}

type IndexIterator = IndexIterator1

func indexIteratorFirst(tls *libc.TLS, pIter uintptr, pIx uintptr) uintptr {
	if (*IndexIterator)(unsafe.Pointer(pIter)).FeType != 0 {
		*(*int32)(unsafe.Pointer(pIx)) = (*IndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIter + 8 + 8)))).Fix
		return (*IndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIter + 8 + 8)))).Fp
	} else {
		*(*int32)(unsafe.Pointer(pIx)) = 0
		return *(*uintptr)(unsafe.Pointer(pIter + 8))
	}
	return uintptr(0)
}

func indexIteratorNext(tls *libc.TLS, pIter uintptr, pIx uintptr) uintptr {
	if (*IndexIterator)(unsafe.Pointer(pIter)).FeType != 0 {
		var i int32 = libc.PreIncInt32(&(*IndexIterator)(unsafe.Pointer(pIter)).Fi, 1)
		if i >= *(*int32)(unsafe.Pointer(pIter + 8)) {
			*(*int32)(unsafe.Pointer(pIx)) = i
			return uintptr(0)
		}
		*(*int32)(unsafe.Pointer(pIx)) = (*IndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIter + 8 + 8)) + uintptr(i)*16)).Fix
		return (*IndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIter + 8 + 8)) + uintptr(i)*16)).Fp
	} else {
		*(*int32)(unsafe.Pointer(pIx))++
		*(*uintptr)(unsafe.Pointer(pIter + 8)) = (*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIter + 8)))).FpNext
		return *(*uintptr)(unsafe.Pointer(pIter + 8))
	}
	return uintptr(0)
}

func Xsqlite3GenerateConstraintChecks(tls *libc.TLS, pParse uintptr, pTab uintptr, aRegIdx uintptr, iDataCur int32, iIdxCur int32, regNewData int32, regOldData int32, pkChng U8, overrideError U8, ignoreDest int32, pbMayReplace uintptr, aiChng uintptr, pUpsert uintptr) {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var v uintptr
	var pIdx uintptr
	var pPk uintptr = uintptr(0)
	var db uintptr
	var i int32

	var nCol int32
	var onError int32
	var seenReplace int32 = 0
	var nPkField int32
	var pUpsertClause uintptr = uintptr(0)
	var isUpdate U8
	var bAffinityDone U8 = U8(0)
	var upsertIpkReturn int32 = 0
	var upsertIpkDelay int32 = 0
	var ipkTop int32 = 0
	var ipkBottom int32 = 0

	var regTrigCnt int32
	var addrRecheck int32 = 0
	var lblRecheckOk int32 = 0
	var pTrigger uintptr
	var nReplaceTrig int32 = 0

	isUpdate = U8(libc.Bool32(regOldData != 0))
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	nCol = int32((*Table)(unsafe.Pointer(pTab)).FnCol)

	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
		pPk = uintptr(0)
		nPkField = 1
	} else {
		pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)
		nPkField = int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
	}

	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasNotNull) != 0 {
		var b2ndPass int32 = 0
		var nSeenReplace int32 = 0
		var nGenerated int32 = 0
		for 1 != 0 {
			for i = 0; i < nCol; i++ {
				var iReg int32
				var pCol uintptr = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*24
				var isGenerated int32
				onError = int32(*(*uint8)(unsafe.Pointer(pCol + 8)) & 0xf >> 0)
				if onError == OE_None {
					continue
				}
				if i == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) {
					continue
				}
				isGenerated = int32((*Column)(unsafe.Pointer(pCol)).FcolFlags) & COLFLAG_GENERATED
				if isGenerated != 0 && !(b2ndPass != 0) {
					nGenerated++
					continue
				}
				if aiChng != 0 && *(*int32)(unsafe.Pointer(aiChng + uintptr(i)*4)) < 0 && !(isGenerated != 0) {
					continue
				}
				if int32(overrideError) != OE_Default {
					onError = int32(overrideError)
				} else if onError == OE_Default {
					onError = OE_Abort
				}
				if onError == OE_Replace {
					if b2ndPass != 0 ||
						int32((*Column)(unsafe.Pointer(pCol)).FiDflt) == 0 {
						onError = OE_Abort
					} else {
					}
				} else if b2ndPass != 0 && !(isGenerated != 0) {
					continue
				}

				iReg = int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(i))) + regNewData + 1
				{
					switch onError {
					case OE_Replace:
						{
							var addr1 int32 = Xsqlite3VdbeAddOp1(tls, v, OP_NotNull, iReg)

							nSeenReplace++
							Xsqlite3ExprCodeCopy(tls, pParse,
								Xsqlite3ColumnExpr(tls, pTab, pCol), iReg)
							Xsqlite3VdbeJumpHere(tls, v, addr1)
							break

						}
						fallthrough
					case OE_Abort:
						Xsqlite3MayAbort(tls, pParse)
						fallthrough
					case OE_Rollback:
						fallthrough
					case OE_Fail:
						{
							var zMsg uintptr = Xsqlite3MPrintf(tls, db, ts+11397, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName,
								(*Column)(unsafe.Pointer(pCol)).FzCnName))

							Xsqlite3VdbeAddOp3(tls, v, OP_HaltIfNull, SQLITE_CONSTRAINT|int32(5)<<8,
								onError, iReg)
							Xsqlite3VdbeAppendP4(tls, v, zMsg, -6)
							Xsqlite3VdbeChangeP5(tls, v, uint16(P5_ConstraintNotNull))

							break

						}
						fallthrough
					default:
						{
							Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, iReg, ignoreDest)

							break

						}
					}
				}
			}
			if nGenerated == 0 && nSeenReplace == 0 {
				break
			}
			if b2ndPass != 0 {
				break
			}
			b2ndPass = 1
			if nSeenReplace > 0 && (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated) != U32(0) {
				Xsqlite3ComputeGeneratedColumns(tls, pParse, regNewData+1, pTab)
			}
		}
	}

	if (*Table)(unsafe.Pointer(pTab)).FpCheck != 0 && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_IgnoreChecks) == uint64(0) {
		var pCheck uintptr = (*Table)(unsafe.Pointer(pTab)).FpCheck
		(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + 1)
		if int32(overrideError) != OE_Default {
			onError = int32(overrideError)
		} else {
			onError = OE_Abort
		}
		for i = 0; i < (*ExprList)(unsafe.Pointer(pCheck)).FnExpr; i++ {
			var allOk int32
			var pCopy uintptr
			var pExpr uintptr = (*ExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(i)*32)).FpExpr
			if aiChng != 0 &&
				!(Xsqlite3ExprReferencesUpdatedColumn(tls, pExpr, aiChng, int32(pkChng)) != 0) {
				continue
			}
			if int32(bAffinityDone) == 0 {
				Xsqlite3TableAffinity(tls, v, pTab, regNewData+1)
				bAffinityDone = U8(1)
			}
			allOk = Xsqlite3VdbeMakeLabel(tls, pParse)

			pCopy = Xsqlite3ExprDup(tls, db, pExpr, 0)
			if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
				Xsqlite3ExprIfTrue(tls, pParse, pCopy, allOk, SQLITE_JUMPIFNULL)
			}
			Xsqlite3ExprDelete(tls, db, pCopy)
			if onError == OE_Ignore {
				Xsqlite3VdbeGoto(tls, v, ignoreDest)
			} else {
				var zName uintptr = (*ExprList_item)(unsafe.Pointer(pCheck + 8 + uintptr(i)*32)).FzEName

				if onError == OE_Replace {
					onError = OE_Abort
				}
				Xsqlite3HaltConstraint(tls, pParse, SQLITE_CONSTRAINT|int32(1)<<8,
					onError, zName, int8(P4_TRANSIENT),
					uint8(P5_ConstraintCheck))
			}
			Xsqlite3VdbeResolveLabel(tls, v, allOk)
		}
		(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = 0
	}

	(*IndexIterator)(unsafe.Pointer(bp + 72)).FeType = 0
	(*IndexIterator)(unsafe.Pointer(bp + 72)).Fi = 0
	*(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 72 + 8)) = (*Table)(unsafe.Pointer(pTab)).FpIndex
	if pUpsert != 0 {
		if (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget == uintptr(0) {
			if int32((*Upsert)(unsafe.Pointer(pUpsert)).FisDoUpdate) == 0 {
				overrideError = U8(OE_Ignore)
				pUpsert = uintptr(0)
			} else {
				overrideError = U8(OE_Update)
			}
		} else if (*Table)(unsafe.Pointer(pTab)).FpIndex != uintptr(0) {
			var nIdx int32
			var jj int32
			var nByte U64
			var pTerm uintptr
			var bUsed uintptr
			nIdx = 0
			pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
		__1:
			if !(pIdx != 0) {
				goto __3
			}
			{
			}
			goto __2
		__2:
			pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
			nIdx++
			goto __1
			goto __3
		__3:
			;
			(*IndexIterator)(unsafe.Pointer(bp + 72)).FeType = 1
			*(*int32)(unsafe.Pointer(bp + 72 + 8)) = nIdx
			nByte = (uint64(unsafe.Sizeof(IndexListTerm{}))+uint64(1))*uint64(nIdx) + uint64(nIdx)
			*(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8)) = Xsqlite3DbMallocZero(tls, db, nByte)
			if *(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8)) == uintptr(0) {
				return
			}
			bUsed = *(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8)) + uintptr(nIdx)*16
			(*Upsert)(unsafe.Pointer(pUpsert)).FpToFree = *(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8))
			i = 0
			pTerm = pUpsert
			for ; pTerm != 0; pTerm = (*Upsert)(unsafe.Pointer(pTerm)).FpNextUpsert {
				if (*Upsert)(unsafe.Pointer(pTerm)).FpUpsertTarget == uintptr(0) {
					break
				}
				if (*Upsert)(unsafe.Pointer(pTerm)).FpUpsertIdx == uintptr(0) {
					continue
				}
				jj = 0
				pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
				for pIdx != uintptr(0) && pIdx != (*Upsert)(unsafe.Pointer(pTerm)).FpUpsertIdx {
					pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
					jj++
				}
				if *(*U8)(unsafe.Pointer(bUsed + uintptr(jj))) != 0 {
					continue
				}
				*(*U8)(unsafe.Pointer(bUsed + uintptr(jj))) = U8(1)
				(*IndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8)) + uintptr(i)*16)).Fp = pIdx
				(*IndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8)) + uintptr(i)*16)).Fix = jj
				i++
			}
			jj = 0
			pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
		__4:
			if !(pIdx != 0) {
				goto __6
			}
			{
				if *(*U8)(unsafe.Pointer(bUsed + uintptr(jj))) != 0 {
					goto __5
				}
				(*IndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8)) + uintptr(i)*16)).Fp = pIdx
				(*IndexListTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 72 + 8 + 8)) + uintptr(i)*16)).Fix = jj
				i++

			}
			goto __5
		__5:
			pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
			jj++
			goto __4
			goto __6
		__6:
		}
	}

	if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_RecTriggers|SQLITE_ForeignKeys) == uint64(0) {
		pTrigger = uintptr(0)
		regTrigCnt = 0
	} else {
		if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_RecTriggers) != 0 {
			pTrigger = Xsqlite3TriggersExist(tls, pParse, pTab, TK_DELETE, uintptr(0), uintptr(0))
			regTrigCnt = libc.Bool32(pTrigger != uintptr(0) || Xsqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0) != 0)
		} else {
			pTrigger = uintptr(0)
			regTrigCnt = Xsqlite3FkRequired(tls, pParse, pTab, uintptr(0), 0)
		}
		if regTrigCnt != 0 {
			regTrigCnt = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regTrigCnt)
			Xsqlite3VdbeComment(tls, v, ts+19301, 0)
			lblRecheckOk = Xsqlite3VdbeMakeLabel(tls, pParse)
			addrRecheck = lblRecheckOk
		}
	}

	if pkChng != 0 && pPk == uintptr(0) {
		var addrRowidOk int32 = Xsqlite3VdbeMakeLabel(tls, pParse)

		onError = int32((*Table)(unsafe.Pointer(pTab)).FkeyConf)
		if int32(overrideError) != OE_Default {
			onError = int32(overrideError)
		} else if onError == OE_Default {
			onError = OE_Abort
		}

		if pUpsert != 0 {
			pUpsertClause = Xsqlite3UpsertOfIndex(tls, pUpsert, uintptr(0))
			if pUpsertClause != uintptr(0) {
				if int32((*Upsert)(unsafe.Pointer(pUpsertClause)).FisDoUpdate) == 0 {
					onError = OE_Ignore
				} else {
					onError = OE_Update
				}
			}
			if pUpsertClause != pUpsert {
				upsertIpkDelay = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
			}
		}

		if onError == OE_Replace &&
			onError != int32(overrideError) &&
			(*Table)(unsafe.Pointer(pTab)).FpIndex != 0 &&
			!(upsertIpkDelay != 0) {
			ipkTop = Xsqlite3VdbeAddOp0(tls, v, OP_Goto) + 1
			Xsqlite3VdbeComment(tls, v, ts+19315, 0)
		}

		if isUpdate != 0 {
			Xsqlite3VdbeAddOp3(tls, v, OP_Eq, regNewData, addrRowidOk, regOldData)
			Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))

		}

		Xsqlite3VdbeNoopComment(tls, v, ts+19344, 0)

		Xsqlite3VdbeAddOp3(tls, v, OP_NotExists, iDataCur, addrRowidOk, regNewData)

		switch onError {
		default:
			{
				onError = OE_Abort

			}
			fallthrough
		case OE_Rollback:
			fallthrough
		case OE_Abort:
			fallthrough
		case OE_Fail:
			{
				Xsqlite3RowidConstraint(tls, pParse, onError, pTab)
				break

			}
			fallthrough
		case OE_Replace:
			{
				if regTrigCnt != 0 {
					Xsqlite3MultiWrite(tls, pParse)
					Xsqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, iDataCur, iIdxCur,
						regNewData, int16(1), uint8(0), uint8(OE_Replace), uint8(1), -1)
					Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, regTrigCnt, 1)
					nReplaceTrig++
				} else {
					Xsqlite3VdbeAddOp2(tls, v, OP_Delete, iDataCur, OPFLAG_ISNOOP)
					Xsqlite3VdbeAppendP4(tls, v, pTab, -5)
					if (*Table)(unsafe.Pointer(pTab)).FpIndex != 0 {
						Xsqlite3MultiWrite(tls, pParse)
						Xsqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, uintptr(0), -1)
					}
				}
				seenReplace = 1
				break

			}
			fallthrough
		case OE_Update:
			{
				Xsqlite3UpsertDoUpdate(tls, pParse, pUpsert, pTab, uintptr(0), iDataCur)

			}
			fallthrough
		case OE_Ignore:
			{
				Xsqlite3VdbeGoto(tls, v, ignoreDest)
				break

			}
		}
		Xsqlite3VdbeResolveLabel(tls, v, addrRowidOk)
		if pUpsert != 0 && pUpsertClause != pUpsert {
			upsertIpkReturn = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
		} else if ipkTop != 0 {
			ipkBottom = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
			Xsqlite3VdbeJumpHere(tls, v, ipkTop-1)
		}
	}

	for pIdx = indexIteratorFirst(tls, bp+72, bp+96); pIdx != 0; pIdx = indexIteratorNext(tls, bp+72, bp+96) {
		var regIdx int32
		var regR int32
		var iThisCur int32
		var addrUniqueOk int32
		var addrConflictCk int32

		if *(*int32)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(bp + 96)))*4)) == 0 {
			continue
		}
		if pUpsert != 0 {
			pUpsertClause = Xsqlite3UpsertOfIndex(tls, pUpsert, pIdx)
			if upsertIpkDelay != 0 && pUpsertClause == pUpsert {
				Xsqlite3VdbeJumpHere(tls, v, upsertIpkDelay)
			}
		}
		addrUniqueOk = Xsqlite3VdbeMakeLabel(tls, pParse)
		if int32(bAffinityDone) == 0 {
			Xsqlite3TableAffinity(tls, v, pTab, regNewData+1)
			bAffinityDone = U8(1)
		}
		Xsqlite3VdbeNoopComment(tls, v, ts+19371, libc.VaList(bp+16, (*Index)(unsafe.Pointer(pIdx)).FzName))
		iThisCur = iIdxCur + *(*int32)(unsafe.Pointer(bp + 96))

		if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, *(*int32)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(bp + 96)))*4)))
			(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + 1)
			Xsqlite3ExprIfFalseDup(tls, pParse, (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere, addrUniqueOk,
				SQLITE_JUMPIFNULL)
			(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = 0
		}

		regIdx = *(*int32)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(bp + 96)))*4)) + 1
		for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn); i++ {
			var iField int32 = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
			var x int32
			if iField == -2 {
				(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = -(regNewData + 1)
				Xsqlite3ExprCodeCopy(tls, pParse, (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr+8+uintptr(i)*32)).FpExpr, regIdx+i)
				(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = 0
				Xsqlite3VdbeComment(tls, v, ts+19385, libc.VaList(bp+24, (*Index)(unsafe.Pointer(pIdx)).FzName, i))
			} else if iField == -1 || iField == int32((*Table)(unsafe.Pointer(pTab)).FiPKey) {
				x = regNewData
				Xsqlite3VdbeAddOp2(tls, v, OP_IntCopy, x, regIdx+i)
				Xsqlite3VdbeComment(tls, v, ts+11466, 0)
			} else {
				x = int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(iField))) + regNewData + 1
				Xsqlite3VdbeAddOp2(tls, v, OP_SCopy, x, regIdx+i)
				Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+40, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iField)*24)).FzCnName))
			}
		}
		Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regIdx, int32((*Index)(unsafe.Pointer(pIdx)).FnColumn), *(*int32)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(bp + 96)))*4)))
		Xsqlite3VdbeComment(tls, v, ts+19398, libc.VaList(bp+48, (*Index)(unsafe.Pointer(pIdx)).FzName))

		if isUpdate != 0 && pPk == pIdx && int32(pkChng) == 0 {
			Xsqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
			continue
		}

		onError = int32((*Index)(unsafe.Pointer(pIdx)).FonError)
		if onError == OE_None {
			Xsqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
			continue
		}
		if int32(overrideError) != OE_Default {
			onError = int32(overrideError)
		} else if onError == OE_Default {
			onError = OE_Abort
		}

		if pUpsertClause != 0 {
			if int32((*Upsert)(unsafe.Pointer(pUpsertClause)).FisDoUpdate) == 0 {
				onError = OE_Ignore
			} else {
				onError = OE_Update
			}
		}

		addrConflictCk = Xsqlite3VdbeAddOp4Int(tls, v, OP_NoConflict, iThisCur, addrUniqueOk,
			regIdx, int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol))

		if pIdx == pPk {
			regR = regIdx
		} else {
			regR = Xsqlite3GetTempRange(tls, pParse, nPkField)
		}
		if isUpdate != 0 || onError == OE_Replace {
			if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
				Xsqlite3VdbeAddOp2(tls, v, OP_IdxRowid, iThisCur, regR)

				if isUpdate != 0 {
					Xsqlite3VdbeAddOp3(tls, v, OP_Eq, regR, addrUniqueOk, regOldData)
					Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))

				}
			} else {
				var x int32

				if pIdx != pPk {
					for i = 0; i < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol); i++ {
						x = int32(Xsqlite3TableColumnToIndex(tls, pIdx, *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
						Xsqlite3VdbeAddOp3(tls, v, OP_Column, iThisCur, x, regR+i)
						Xsqlite3VdbeComment(tls, v, ts+11397, libc.VaList(bp+56, (*Table)(unsafe.Pointer(pTab)).FzName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))*24)).FzCnName))
					}
				}
				if isUpdate != 0 {
					var addrJump int32 = Xsqlite3VdbeCurrentAddr(tls, v) + int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
					var op int32 = OP_Ne
					var regCmp int32 = func() int32 {
						if int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
							return regIdx
						}
						return regR
					}()

					for i = 0; i < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol); i++ {
						var p4 uintptr = Xsqlite3LocateCollSeq(tls, pParse, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FazColl + uintptr(i)*8)))
						x = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))

						if i == int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)-1 {
							addrJump = addrUniqueOk
							op = OP_Eq
						}
						x = int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(x)))
						Xsqlite3VdbeAddOp4(tls, v, op,
							regOldData+1+x, addrJump, regCmp+i, p4, -2)
						Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))

					}
				}
			}
		}

		switch onError {
		case OE_Rollback:
			fallthrough
		case OE_Abort:
			fallthrough
		case OE_Fail:
			{
				Xsqlite3UniqueConstraint(tls, pParse, onError, pIdx)
				break

			}
		case OE_Update:
			{
				Xsqlite3UpsertDoUpdate(tls, pParse, pUpsert, pTab, pIdx, iIdxCur+*(*int32)(unsafe.Pointer(bp + 96)))

			}
			fallthrough
		case OE_Ignore:
			{
				Xsqlite3VdbeGoto(tls, v, ignoreDest)
				break

			}
		default:
			{
				var nConflictCk int32

				nConflictCk = Xsqlite3VdbeCurrentAddr(tls, v) - addrConflictCk

				if regTrigCnt != 0 {
					Xsqlite3MultiWrite(tls, pParse)
					nReplaceTrig++
				}
				if pTrigger != 0 && isUpdate != 0 {
					Xsqlite3VdbeAddOp1(tls, v, OP_CursorLock, iDataCur)
				}
				Xsqlite3GenerateRowDelete(tls, pParse, pTab, pTrigger, iDataCur, iIdxCur,
					regR, int16(nPkField), uint8(0), uint8(OE_Replace),
					func() uint8 {
						if pIdx == pPk {
							return uint8(ONEPASS_SINGLE)
						}
						return uint8(ONEPASS_OFF)
					}(), iThisCur)
				if pTrigger != 0 && isUpdate != 0 {
					Xsqlite3VdbeAddOp1(tls, v, OP_CursorUnlock, iDataCur)
				}
				if regTrigCnt != 0 {
					var addrBypass int32

					Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, regTrigCnt, 1)
					addrBypass = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
					Xsqlite3VdbeComment(tls, v, ts+19405, 0)

					Xsqlite3VdbeResolveLabel(tls, v, lblRecheckOk)
					lblRecheckOk = Xsqlite3VdbeMakeLabel(tls, pParse)
					if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
						Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, regIdx-1, lblRecheckOk)

					}

					for nConflictCk > 0 {
						*(*VdbeOp)(unsafe.Pointer(bp + 104)) = *(*VdbeOp)(unsafe.Pointer(Xsqlite3VdbeGetOp(tls, v, addrConflictCk)))
						if int32((*VdbeOp)(unsafe.Pointer(bp+104)).Fopcode) != OP_IdxRowid {
							var p2 int32
							var zP4 uintptr
							if int32(Xsqlite3OpcodeProperty[(*VdbeOp)(unsafe.Pointer(bp+104)).Fopcode])&OPFLG_JUMP != 0 {
								p2 = lblRecheckOk
							} else {
								p2 = (*VdbeOp)(unsafe.Pointer(bp + 104)).Fp2
							}
							if int32((*VdbeOp)(unsafe.Pointer(bp+104)).Fp4type) == -3 {
								zP4 = uintptr(int64(*(*int32)(unsafe.Pointer(bp + 104 + 16))))
							} else {
								zP4 = *(*uintptr)(unsafe.Pointer(bp + 104 + 16))
							}
							Xsqlite3VdbeAddOp4(tls, v, int32((*VdbeOp)(unsafe.Pointer(bp+104)).Fopcode), (*VdbeOp)(unsafe.Pointer(bp+104)).Fp1, p2, (*VdbeOp)(unsafe.Pointer(bp+104)).Fp3, zP4, int32((*VdbeOp)(unsafe.Pointer(bp+104)).Fp4type))
							Xsqlite3VdbeChangeP5(tls, v, (*VdbeOp)(unsafe.Pointer(bp+104)).Fp5)

						}
						nConflictCk--
						addrConflictCk++
					}

					Xsqlite3UniqueConstraint(tls, pParse, OE_Abort, pIdx)

					Xsqlite3VdbeJumpHere(tls, v, addrBypass)
				}
				seenReplace = 1
				break

			}
		}
		Xsqlite3VdbeResolveLabel(tls, v, addrUniqueOk)
		if regR != regIdx {
			Xsqlite3ReleaseTempRange(tls, pParse, regR, nPkField)
		}
		if pUpsertClause != 0 &&
			upsertIpkReturn != 0 &&
			Xsqlite3UpsertNextIsIPK(tls, pUpsertClause) != 0 {
			Xsqlite3VdbeGoto(tls, v, upsertIpkDelay+1)
			Xsqlite3VdbeJumpHere(tls, v, upsertIpkReturn)
			upsertIpkReturn = 0
		}
	}

	if ipkTop != 0 {
		Xsqlite3VdbeGoto(tls, v, ipkTop)
		Xsqlite3VdbeComment(tls, v, ts+19420, 0)

		Xsqlite3VdbeJumpHere(tls, v, ipkBottom)
	}

	if nReplaceTrig != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_IfNot, regTrigCnt, lblRecheckOk)

		if !(pPk != 0) {
			if isUpdate != 0 {
				Xsqlite3VdbeAddOp3(tls, v, OP_Eq, regNewData, addrRecheck, regOldData)
				Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))

			}
			Xsqlite3VdbeAddOp3(tls, v, OP_NotExists, iDataCur, addrRecheck, regNewData)

			Xsqlite3RowidConstraint(tls, pParse, OE_Abort, pTab)
		} else {
			Xsqlite3VdbeGoto(tls, v, addrRecheck)
		}
		Xsqlite3VdbeResolveLabel(tls, v, lblRecheckOk)
	}

	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
		var regRec int32 = *(*int32)(unsafe.Pointer(aRegIdx + uintptr(*(*int32)(unsafe.Pointer(bp + 96)))*4))
		Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regNewData+1, int32((*Table)(unsafe.Pointer(pTab)).FnNVCol), regRec)

		if !(bAffinityDone != 0) {
			Xsqlite3TableAffinity(tls, v, pTab, 0)
		}
	}

	*(*int32)(unsafe.Pointer(pbMayReplace)) = seenReplace

}

func codeWithoutRowidPreupdate(tls *libc.TLS, pParse uintptr, pTab uintptr, iCur int32, regData int32) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var r int32 = Xsqlite3GetTempReg(tls, pParse)

	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, r)
	Xsqlite3VdbeAddOp4(tls, v, OP_Insert, iCur, regData, r, pTab, -5)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_ISNOOP))
	Xsqlite3ReleaseTempReg(tls, pParse, r)
}

func Xsqlite3CompleteInsertion(tls *libc.TLS, pParse uintptr, pTab uintptr, iDataCur int32, iIdxCur int32, regNewData int32, aRegIdx uintptr, update_flags int32, appendBias int32, useSeekResult int32) {
	var v uintptr
	var pIdx uintptr
	var pik_flags U8
	var i int32

	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	i = 0
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__1:
	if !(pIdx != 0) {
		goto __3
	}
	{
		if *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)) == 0 {
			goto __2
		}
		if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)), Xsqlite3VdbeCurrentAddr(tls, v)+2)

		}
		pik_flags = func() uint8 {
			if useSeekResult != 0 {
				return uint8(OPFLAG_USESEEKRESULT)
			}
			return uint8(0)
		}()
		if int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY && !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
			pik_flags = U8(int32(pik_flags) | OPFLAG_NCHANGE)
			pik_flags = U8(int32(pik_flags) | update_flags&OPFLAG_SAVEPOSITION)
			if update_flags == 0 {
				codeWithoutRowidPreupdate(tls, pParse, pTab, iIdxCur+i, *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)))
			}
		}
		Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iIdxCur+i, *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)),
			*(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4))+1,
			func() int32 {
				if uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x8>>3)) != 0 {
					return int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
				}
				return int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
			}())
		Xsqlite3VdbeChangeP5(tls, v, uint16(pik_flags))

	}
	goto __2
__2:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	i++
	goto __1
	goto __3
__3:
	;
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		return
	}
	if (*Parse)(unsafe.Pointer(pParse)).Fnested != 0 {
		pik_flags = U8(0)
	} else {
		pik_flags = U8(OPFLAG_NCHANGE)
		pik_flags = U8(int32(pik_flags) | func() int32 {
			if update_flags != 0 {
				return update_flags
			}
			return OPFLAG_LASTROWID
		}())
	}
	if appendBias != 0 {
		pik_flags = U8(int32(pik_flags) | OPFLAG_APPEND)
	}
	if useSeekResult != 0 {
		pik_flags = U8(int32(pik_flags) | OPFLAG_USESEEKRESULT)
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iDataCur, *(*int32)(unsafe.Pointer(aRegIdx + uintptr(i)*4)), regNewData)
	if !(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) != 0) {
		Xsqlite3VdbeAppendP4(tls, v, pTab, -5)
	}
	Xsqlite3VdbeChangeP5(tls, v, uint16(pik_flags))
}

func Xsqlite3OpenTableAndIndices(tls *libc.TLS, pParse uintptr, pTab uintptr, op int32, p5 U8, iBase int32, aToOpen uintptr, piDataCur uintptr, piIdxCur uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var i int32
	var iDb int32
	var iDataCur int32
	var pIdx uintptr
	var v uintptr

	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
		*(*int32)(unsafe.Pointer(piDataCur)) = libc.AssignPtrInt32(piIdxCur, -999)
		return 0
	}
	iDb = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Table)(unsafe.Pointer(pTab)).FpSchema)
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	if iBase < 0 {
		iBase = (*Parse)(unsafe.Pointer(pParse)).FnTab
	}
	iDataCur = libc.PostIncInt32(&iBase, 1)
	if piDataCur != 0 {
		*(*int32)(unsafe.Pointer(piDataCur)) = iDataCur
	}
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) && (aToOpen == uintptr(0) || *(*U8)(unsafe.Pointer(aToOpen)) != 0) {
		Xsqlite3OpenTable(tls, pParse, iDataCur, iDb, pTab, op)
	} else {
		Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab)).Ftnum, uint8(libc.Bool32(op == OP_OpenWrite)), (*Table)(unsafe.Pointer(pTab)).FzName)
	}
	if piIdxCur != 0 {
		*(*int32)(unsafe.Pointer(piIdxCur)) = iBase
	}
	i = 0
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__1:
	if !(pIdx != 0) {
		goto __3
	}
	{
		var iIdxCur int32 = libc.PostIncInt32(&iBase, 1)

		if int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY && !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
			if piDataCur != 0 {
				*(*int32)(unsafe.Pointer(piDataCur)) = iIdxCur
			}
			p5 = U8(0)
		}
		if aToOpen == uintptr(0) || *(*U8)(unsafe.Pointer(aToOpen + uintptr(i+1))) != 0 {
			Xsqlite3VdbeAddOp3(tls, v, op, iIdxCur, int32((*Index)(unsafe.Pointer(pIdx)).Ftnum), iDb)
			Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
			Xsqlite3VdbeChangeP5(tls, v, uint16(p5))
			Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp, (*Index)(unsafe.Pointer(pIdx)).FzName))
		}

	}
	goto __2
__2:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	i++
	goto __1
	goto __3
__3:
	;
	if iBase > (*Parse)(unsafe.Pointer(pParse)).FnTab {
		(*Parse)(unsafe.Pointer(pParse)).FnTab = iBase
	}
	return i
}

var Xsqlite3_xferopt_count int32

func xferCompatibleIndex(tls *libc.TLS, pDest uintptr, pSrc uintptr) int32 {
	var i int32

	if int32((*Index)(unsafe.Pointer(pDest)).FnKeyCol) != int32((*Index)(unsafe.Pointer(pSrc)).FnKeyCol) || int32((*Index)(unsafe.Pointer(pDest)).FnColumn) != int32((*Index)(unsafe.Pointer(pSrc)).FnColumn) {
		return 0
	}
	if int32((*Index)(unsafe.Pointer(pDest)).FonError) != int32((*Index)(unsafe.Pointer(pSrc)).FonError) {
		return 0
	}
	for i = 0; i < int32((*Index)(unsafe.Pointer(pSrc)).FnKeyCol); i++ {
		if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pSrc)).FaiColumn + uintptr(i)*2))) != int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pDest)).FaiColumn + uintptr(i)*2))) {
			return 0
		}
		if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pSrc)).FaiColumn + uintptr(i)*2))) == -2 {
			if Xsqlite3ExprCompare(tls, uintptr(0), (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pSrc)).FaColExpr+8+uintptr(i)*32)).FpExpr,
				(*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pDest)).FaColExpr+8+uintptr(i)*32)).FpExpr, -1) != 0 {
				return 0
			}
		}
		if int32(*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pSrc)).FaSortOrder + uintptr(i)))) != int32(*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pDest)).FaSortOrder + uintptr(i)))) {
			return 0
		}
		if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pSrc)).FazColl + uintptr(i)*8)), *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pDest)).FazColl + uintptr(i)*8))) != 0 {
			return 0
		}
	}
	if Xsqlite3ExprCompare(tls, uintptr(0), (*Index)(unsafe.Pointer(pSrc)).FpPartIdxWhere, (*Index)(unsafe.Pointer(pDest)).FpPartIdxWhere, -1) != 0 {
		return 0
	}

	return 1
}

func xferOptimization(tls *libc.TLS, pParse uintptr, pDest uintptr, pSelect uintptr, onError int32, iDbDest int32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pEList uintptr
	var pSrc uintptr
	var pSrcIdx uintptr
	var pDestIdx uintptr
	var pItem uintptr
	var i int32
	var iDbSrc int32
	var iSrc int32
	var iDest int32
	var addr1 int32
	var addr2 int32
	var emptyDestTest int32 = 0
	var emptySrcTest int32 = 0
	var v uintptr
	var regAutoinc int32
	var destHasUniqueIdx int32 = 0
	var regData int32
	var regRowid int32

	if (*Parse)(unsafe.Pointer(pParse)).FpWith != 0 || (*Select)(unsafe.Pointer(pSelect)).FpWith != 0 {
		return 0
	}
	if int32((*Table)(unsafe.Pointer(pDest)).FeTabType) == TABTYP_VTAB {
		return 0
	}
	if onError == OE_Default {
		if int32((*Table)(unsafe.Pointer(pDest)).FiPKey) >= 0 {
			onError = int32((*Table)(unsafe.Pointer(pDest)).FkeyConf)
		}
		if onError == OE_Default {
			onError = OE_Abort
		}
	}

	if (*SrcList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpSrc)).FnSrc != 1 {
		return 0
	}
	if (*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpSrc+8)).FpSelect != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSelect)).FpWhere != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSelect)).FpOrderBy != 0 {
		return 0
	}

	if (*Select)(unsafe.Pointer(pSelect)).FpGroupBy != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSelect)).FpLimit != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSelect)).FselFlags&U32(SF_Distinct) != 0 {
		return 0
	}
	pEList = (*Select)(unsafe.Pointer(pSelect)).FpEList

	if (*ExprList)(unsafe.Pointer(pEList)).FnExpr != 1 {
		return 0
	}

	if int32((*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pEList+8)).FpExpr)).Fop) != TK_ASTERISK {
		return 0
	}

	pItem = (*Select)(unsafe.Pointer(pSelect)).FpSrc + 8
	pSrc = Xsqlite3LocateTableItem(tls, pParse, uint32(0), pItem)
	if pSrc == uintptr(0) {
		return 0
	}
	if (*Table)(unsafe.Pointer(pSrc)).Ftnum == (*Table)(unsafe.Pointer(pDest)).Ftnum && (*Table)(unsafe.Pointer(pSrc)).FpSchema == (*Table)(unsafe.Pointer(pDest)).FpSchema {
		return 0
	}
	if libc.Bool32((*Table)(unsafe.Pointer(pDest)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) != libc.Bool32((*Table)(unsafe.Pointer(pSrc)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		return 0
	}
	if !(int32((*Table)(unsafe.Pointer(pSrc)).FeTabType) == TABTYP_NORM) {
		return 0
	}
	if int32((*Table)(unsafe.Pointer(pDest)).FnCol) != int32((*Table)(unsafe.Pointer(pSrc)).FnCol) {
		return 0
	}
	if int32((*Table)(unsafe.Pointer(pDest)).FiPKey) != int32((*Table)(unsafe.Pointer(pSrc)).FiPKey) {
		return 0
	}
	if (*Table)(unsafe.Pointer(pDest)).FtabFlags&U32(TF_Strict) != U32(0) && (*Table)(unsafe.Pointer(pSrc)).FtabFlags&U32(TF_Strict) == U32(0) {
		return 0
	}
	for i = 0; i < int32((*Table)(unsafe.Pointer(pDest)).FnCol); i++ {
		var pDestCol uintptr = (*Table)(unsafe.Pointer(pDest)).FaCol + uintptr(i)*24
		var pSrcCol uintptr = (*Table)(unsafe.Pointer(pSrc)).FaCol + uintptr(i)*24

		if int32((*Column)(unsafe.Pointer(pDestCol)).FcolFlags)&COLFLAG_GENERATED != int32((*Column)(unsafe.Pointer(pSrcCol)).FcolFlags)&COLFLAG_GENERATED {
			return 0
		}

		if int32((*Column)(unsafe.Pointer(pDestCol)).FcolFlags)&COLFLAG_GENERATED != 0 {
			if Xsqlite3ExprCompare(tls, uintptr(0),
				Xsqlite3ColumnExpr(tls, pSrc, pSrcCol),
				Xsqlite3ColumnExpr(tls, pDest, pDestCol), -1) != 0 {
				return 0
			}
		}
		if int32((*Column)(unsafe.Pointer(pDestCol)).Faffinity) != int32((*Column)(unsafe.Pointer(pSrcCol)).Faffinity) {
			return 0
		}
		if Xsqlite3_stricmp(tls, Xsqlite3ColumnColl(tls, pDestCol),
			Xsqlite3ColumnColl(tls, pSrcCol)) != 0 {
			return 0
		}
		if uint32(int32(*(*uint8)(unsafe.Pointer(pDestCol + 8))&0xf>>0)) != 0 && !(int32(*(*uint8)(unsafe.Pointer(pSrcCol + 8))&0xf>>0) != 0) {
			return 0
		}

		if int32((*Column)(unsafe.Pointer(pDestCol)).FcolFlags)&COLFLAG_GENERATED == 0 && i > 0 {
			var pDestExpr uintptr = Xsqlite3ColumnExpr(tls, pDest, pDestCol)
			var pSrcExpr uintptr = Xsqlite3ColumnExpr(tls, pSrc, pSrcCol)

			if libc.Bool32(pDestExpr == uintptr(0)) != libc.Bool32(pSrcExpr == uintptr(0)) ||
				pDestExpr != uintptr(0) && libc.Xstrcmp(tls, *(*uintptr)(unsafe.Pointer(pDestExpr + 8)),
					*(*uintptr)(unsafe.Pointer(pSrcExpr + 8))) != 0 {
				return 0
			}
		}
	}
	for pDestIdx = (*Table)(unsafe.Pointer(pDest)).FpIndex; pDestIdx != 0; pDestIdx = (*Index)(unsafe.Pointer(pDestIdx)).FpNext {
		if int32((*Index)(unsafe.Pointer(pDestIdx)).FonError) != OE_None {
			destHasUniqueIdx = 1
		}
		for pSrcIdx = (*Table)(unsafe.Pointer(pSrc)).FpIndex; pSrcIdx != 0; pSrcIdx = (*Index)(unsafe.Pointer(pSrcIdx)).FpNext {
			if xferCompatibleIndex(tls, pDestIdx, pSrcIdx) != 0 {
				break
			}
		}
		if pSrcIdx == uintptr(0) {
			return 0
		}
		if (*Index)(unsafe.Pointer(pSrcIdx)).Ftnum == (*Index)(unsafe.Pointer(pDestIdx)).Ftnum && (*Table)(unsafe.Pointer(pSrc)).FpSchema == (*Table)(unsafe.Pointer(pDest)).FpSchema &&
			Xsqlite3FaultSim(tls, 411) == SQLITE_OK {
			return 0
		}
	}
	if (*Table)(unsafe.Pointer(pDest)).FpCheck != 0 && Xsqlite3ExprListCompare(tls, (*Table)(unsafe.Pointer(pSrc)).FpCheck, (*Table)(unsafe.Pointer(pDest)).FpCheck, -1) != 0 {
		return 0
	}

	if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ForeignKeys) != uint64(0) && *(*uintptr)(unsafe.Pointer(pDest + 64 + 8)) != uintptr(0) {
		return 0
	}
	if (*Sqlite3)(unsafe.Pointer(db)).Fflags&(uint64(0x00001)<<32) != uint64(0) {
		return 0
	}

	Xsqlite3_xferopt_count++
	iDbSrc = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pSrc)).FpSchema)
	v = Xsqlite3GetVdbe(tls, pParse)
	Xsqlite3CodeVerifySchema(tls, pParse, iDbSrc)
	iSrc = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	iDest = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	regAutoinc = autoIncBegin(tls, pParse, iDbDest, pDest)
	regData = Xsqlite3GetTempReg(tls, pParse)
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regData)
	regRowid = Xsqlite3GetTempReg(tls, pParse)
	Xsqlite3OpenTable(tls, pParse, iDest, iDbDest, pDest, OP_OpenWrite)

	if (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_Vacuum) == U32(0) && (int32((*Table)(unsafe.Pointer(pDest)).FiPKey) < 0 && (*Table)(unsafe.Pointer(pDest)).FpIndex != uintptr(0) ||
		destHasUniqueIdx != 0 ||
		onError != OE_Abort && onError != OE_Rollback) {
		addr1 = Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, iDest, 0)
		emptyDestTest = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
		Xsqlite3VdbeJumpHere(tls, v, addr1)
	}
	if (*Table)(unsafe.Pointer(pSrc)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
		var insFlags U8
		Xsqlite3OpenTable(tls, pParse, iSrc, iDbSrc, pSrc, OP_OpenRead)
		emptySrcTest = Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, iSrc, 0)
		if int32((*Table)(unsafe.Pointer(pDest)).FiPKey) >= 0 {
			addr1 = Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iSrc, regRowid)
			if (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_Vacuum) == U32(0) {
				addr2 = Xsqlite3VdbeAddOp3(tls, v, OP_NotExists, iDest, 0, regRowid)

				Xsqlite3RowidConstraint(tls, pParse, onError, pDest)
				Xsqlite3VdbeJumpHere(tls, v, addr2)
			}
			autoIncStep(tls, pParse, regAutoinc, regRowid)
		} else if (*Table)(unsafe.Pointer(pDest)).FpIndex == uintptr(0) && !((*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_VacuumInto) != 0) {
			addr1 = Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, iDest, regRowid)
		} else {
			addr1 = Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iSrc, regRowid)

		}

		if (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_Vacuum) != 0 {
			Xsqlite3VdbeAddOp1(tls, v, OP_SeekEnd, iDest)
			insFlags = U8(OPFLAG_APPEND | OPFLAG_USESEEKRESULT | OPFLAG_PREFORMAT)
		} else {
			insFlags = U8(OPFLAG_NCHANGE | OPFLAG_LASTROWID | OPFLAG_APPEND | OPFLAG_PREFORMAT)
		}
		if (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_Vacuum) == U32(0) {
			Xsqlite3VdbeAddOp3(tls, v, OP_RowData, iSrc, regData, 1)
			insFlags = libc.Uint8FromInt32(int32(insFlags) & libc.CplInt32(OPFLAG_PREFORMAT))
		} else {
			Xsqlite3VdbeAddOp3(tls, v, OP_RowCell, iDest, iSrc, regRowid)
		}
		Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iDest, regData, regRowid)
		if (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_Vacuum) == U32(0) {
			Xsqlite3VdbeChangeP4(tls, v, -1, pDest, -5)
		}
		Xsqlite3VdbeChangeP5(tls, v, uint16(insFlags))

		Xsqlite3VdbeAddOp2(tls, v, OP_Next, iSrc, addr1)
		Xsqlite3VdbeAddOp2(tls, v, OP_Close, iSrc, 0)
		Xsqlite3VdbeAddOp2(tls, v, OP_Close, iDest, 0)
	} else {
		Xsqlite3TableLock(tls, pParse, iDbDest, (*Table)(unsafe.Pointer(pDest)).Ftnum, uint8(1), (*Table)(unsafe.Pointer(pDest)).FzName)
		Xsqlite3TableLock(tls, pParse, iDbSrc, (*Table)(unsafe.Pointer(pSrc)).Ftnum, uint8(0), (*Table)(unsafe.Pointer(pSrc)).FzName)
	}
	for pDestIdx = (*Table)(unsafe.Pointer(pDest)).FpIndex; pDestIdx != 0; pDestIdx = (*Index)(unsafe.Pointer(pDestIdx)).FpNext {
		var idxInsFlags U8 = U8(0)
		for pSrcIdx = (*Table)(unsafe.Pointer(pSrc)).FpIndex; pSrcIdx != 0; pSrcIdx = (*Index)(unsafe.Pointer(pSrcIdx)).FpNext {
			if xferCompatibleIndex(tls, pDestIdx, pSrcIdx) != 0 {
				break
			}
		}

		Xsqlite3VdbeAddOp3(tls, v, OP_OpenRead, iSrc, int32((*Index)(unsafe.Pointer(pSrcIdx)).Ftnum), iDbSrc)
		Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pSrcIdx)
		Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp, (*Index)(unsafe.Pointer(pSrcIdx)).FzName))
		Xsqlite3VdbeAddOp3(tls, v, OP_OpenWrite, iDest, int32((*Index)(unsafe.Pointer(pDestIdx)).Ftnum), iDbDest)
		Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pDestIdx)
		Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_BULKCSR))
		Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+8, (*Index)(unsafe.Pointer(pDestIdx)).FzName))
		addr1 = Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, iSrc, 0)
		if (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_Vacuum) != 0 {
			for i = 0; i < int32((*Index)(unsafe.Pointer(pSrcIdx)).FnColumn); i++ {
				var zColl uintptr = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pSrcIdx)).FazColl + uintptr(i)*8))
				if Xsqlite3_stricmp(tls, uintptr(unsafe.Pointer(&Xsqlite3StrBINARY)), zColl) != 0 {
					break
				}
			}
			if i == int32((*Index)(unsafe.Pointer(pSrcIdx)).FnColumn) {
				idxInsFlags = U8(OPFLAG_USESEEKRESULT | OPFLAG_PREFORMAT)
				Xsqlite3VdbeAddOp1(tls, v, OP_SeekEnd, iDest)
				Xsqlite3VdbeAddOp2(tls, v, OP_RowCell, iDest, iSrc)
			}
		} else if !((*Table)(unsafe.Pointer(pSrc)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) && int32(*(*uint16)(unsafe.Pointer(pDestIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
			idxInsFlags = U8(int32(idxInsFlags) | OPFLAG_NCHANGE)
		}
		if int32(idxInsFlags) != OPFLAG_USESEEKRESULT|OPFLAG_PREFORMAT {
			Xsqlite3VdbeAddOp3(tls, v, OP_RowData, iSrc, regData, 1)
			if (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_Vacuum) == U32(0) &&
				!((*Table)(unsafe.Pointer(pDest)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) &&
				int32(*(*uint16)(unsafe.Pointer(pDestIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
				codeWithoutRowidPreupdate(tls, pParse, pDest, iDest, regData)
			}
		}
		Xsqlite3VdbeAddOp2(tls, v, OP_IdxInsert, iDest, regData)
		Xsqlite3VdbeChangeP5(tls, v, uint16(int32(idxInsFlags)|OPFLAG_APPEND))
		Xsqlite3VdbeAddOp2(tls, v, OP_Next, iSrc, addr1+1)
		Xsqlite3VdbeJumpHere(tls, v, addr1)
		Xsqlite3VdbeAddOp2(tls, v, OP_Close, iSrc, 0)
		Xsqlite3VdbeAddOp2(tls, v, OP_Close, iDest, 0)
	}
	if emptySrcTest != 0 {
		Xsqlite3VdbeJumpHere(tls, v, emptySrcTest)
	}
	Xsqlite3ReleaseTempReg(tls, pParse, regRowid)
	Xsqlite3ReleaseTempReg(tls, pParse, regData)
	if emptyDestTest != 0 {
		Xsqlite3AutoincrementEnd(tls, pParse)
		Xsqlite3VdbeAddOp2(tls, v, OP_Halt, SQLITE_OK, 0)
		Xsqlite3VdbeJumpHere(tls, v, emptyDestTest)
		Xsqlite3VdbeAddOp2(tls, v, OP_Close, iDest, 0)
		return 0
	} else {
		return 1
	}
	return int32(0)
}

func Xsqlite3_exec(tls *libc.TLS, db uintptr, zSql uintptr, xCallback Sqlite3_callback, pArg uintptr, pzErrMsg uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32

	var azCols uintptr
	var callbackIsInit int32
	var i int32
	var nCol int32
	var azVals uintptr
	rc = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	azCols = uintptr(0)

	if !!(Xsqlite3SafetyCheckOk(tls, db) != 0) {
		goto __1
	}
	return Xsqlite3MisuseError(tls, 131931)
__1:
	;
	if !(zSql == uintptr(0)) {
		goto __2
	}
	zSql = ts + 1636
__2:
	;
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	Xsqlite3Error(tls, db, SQLITE_OK)
__3:
	if !(rc == SQLITE_OK && *(*uint8)(unsafe.Pointer(zSql)) != 0) {
		goto __4
	}
	nCol = 0
	azVals = uintptr(0)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = Xsqlite3_prepare_v2(tls, db, zSql, -1, bp, bp+8)

	if !(rc != SQLITE_OK) {
		goto __5
	}
	goto __3
__5:
	;
	if !!(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
		goto __6
	}

	zSql = *(*uintptr)(unsafe.Pointer(bp + 8))
	goto __3
__6:
	;
	callbackIsInit = 0

__7:
	if !(1 != 0) {
		goto __8
	}
	rc = Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))

	if !(xCallback != 0 && (SQLITE_ROW == rc || SQLITE_DONE == rc && !(callbackIsInit != 0) &&
		(*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NullCallback) != 0)) {
		goto __9
	}
	if !!(callbackIsInit != 0) {
		goto __10
	}
	nCol = Xsqlite3_column_count(tls, *(*uintptr)(unsafe.Pointer(bp)))
	azCols = Xsqlite3DbMallocRaw(tls, db, uint64(2*nCol+1)*uint64(unsafe.Sizeof(uintptr(0))))
	if !(azCols == uintptr(0)) {
		goto __11
	}
	goto exec_out
__11:
	;
	i = 0
__12:
	if !(i < nCol) {
		goto __14
	}
	*(*uintptr)(unsafe.Pointer(azCols + uintptr(i)*8)) = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp)), i)

	goto __13
__13:
	i++
	goto __12
	goto __14
__14:
	;
	callbackIsInit = 1
__10:
	;
	if !(rc == SQLITE_ROW) {
		goto __15
	}
	azVals = azCols + uintptr(nCol)*8
	i = 0
__16:
	if !(i < nCol) {
		goto __18
	}
	*(*uintptr)(unsafe.Pointer(azVals + uintptr(i)*8)) = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), i)
	if !(!(int32(*(*uintptr)(unsafe.Pointer(azVals + uintptr(i)*8))) != 0) && Xsqlite3_column_type(tls, *(*uintptr)(unsafe.Pointer(bp)), i) != SQLITE_NULL) {
		goto __19
	}
	Xsqlite3OomFault(tls, db)
	goto exec_out
__19:
	;
	goto __17
__17:
	i++
	goto __16
	goto __18
__18:
	;
	*(*uintptr)(unsafe.Pointer(azVals + uintptr(i)*8)) = uintptr(0)
__15:
	;
	if !((*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{xCallback})).f(tls, pArg, nCol, azVals, azCols) != 0) {
		goto __20
	}

	rc = SQLITE_ABORT
	Xsqlite3VdbeFinalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	Xsqlite3Error(tls, db, SQLITE_ABORT)
	goto exec_out
__20:
	;
__9:
	;
	if !(rc != SQLITE_ROW) {
		goto __21
	}
	rc = Xsqlite3VdbeFinalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	zSql = *(*uintptr)(unsafe.Pointer(bp + 8))
__22:
	if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zSql))])&0x01 != 0) {
		goto __23
	}
	zSql++
	goto __22
__23:
	;
	goto __8
__21:
	;
	goto __7
__8:
	;
	Xsqlite3DbFree(tls, db, azCols)
	azCols = uintptr(0)
	goto __3
__4:
	;
exec_out:
	if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
		goto __24
	}
	Xsqlite3VdbeFinalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
__24:
	;
	Xsqlite3DbFree(tls, db, azCols)

	rc = Xsqlite3ApiExit(tls, db, rc)
	if !(rc != SQLITE_OK && pzErrMsg != 0) {
		goto __25
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3DbStrDup(tls, uintptr(0), Xsqlite3_errmsg(tls, db))
	if !(*(*uintptr)(unsafe.Pointer(pzErrMsg)) == uintptr(0)) {
		goto __27
	}
	rc = SQLITE_NOMEM
	Xsqlite3Error(tls, db, SQLITE_NOMEM)
__27:
	;
	goto __26
__25:
	if !(pzErrMsg != 0) {
		goto __28
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = uintptr(0)
__28:
	;
__26:
	;
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

type Sqlite3_loadext_entry = uintptr

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

func sqlite3LoadExtension(tls *libc.TLS, db uintptr, zFile uintptr, zProc uintptr, pzErrMsg uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var pVfs uintptr
	var handle uintptr
	var xInit Sqlite3_loadext_entry

	var zEntry uintptr
	var zAltEntry uintptr
	var aHandle uintptr
	var nMsg U64
	var ii int32
	var rc int32
	var zAltFile uintptr
	var iFile int32
	var iEntry int32
	var c int32
	var ncFile int32
	pVfs = (*Sqlite3)(unsafe.Pointer(db)).FpVfs
	*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
	zAltEntry = uintptr(0)
	nMsg = libc.Xstrlen(tls, zFile)

	if !(pzErrMsg != 0) {
		goto __1
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = uintptr(0)
__1:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_LoadExtension) == uint64(0)) {
		goto __2
	}
	if !(pzErrMsg != 0) {
		goto __3
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+15509, 0)
__3:
	;
	return SQLITE_ERROR
__2:
	;
	if zProc != 0 {
		zEntry = zProc
	} else {
		zEntry = ts + 19435
	}

	if !(nMsg > uint64(FILENAME_MAX)) {
		goto __4
	}
	goto extension_not_found
__4:
	;
	handle = Xsqlite3OsDlOpen(tls, pVfs, zFile)
	ii = 0
__5:
	if !(ii < int32(uint64(unsafe.Sizeof(azEndings))/uint64(unsafe.Sizeof(uintptr(0)))) && handle == uintptr(0)) {
		goto __7
	}
	zAltFile = Xsqlite3_mprintf(tls, ts+11397, libc.VaList(bp, zFile, azEndings[ii]))
	if !(zAltFile == uintptr(0)) {
		goto __8
	}
	return SQLITE_NOMEM
__8:
	;
	handle = Xsqlite3OsDlOpen(tls, pVfs, zAltFile)
	Xsqlite3_free(tls, zAltFile)
	goto __6
__6:
	ii++
	goto __5
	goto __7
__7:
	;
	if !(handle == uintptr(0)) {
		goto __9
	}
	goto extension_not_found
__9:
	;
	xInit = Xsqlite3OsDlSym(tls, pVfs, handle, zEntry)

	if !(xInit == uintptr(0) && zProc == uintptr(0)) {
		goto __10
	}
	ncFile = Xsqlite3Strlen30(tls, zFile)
	zAltEntry = Xsqlite3_malloc64(tls, uint64(ncFile+30))
	if !(zAltEntry == uintptr(0)) {
		goto __11
	}
	Xsqlite3OsDlClose(tls, pVfs, handle)
	return SQLITE_NOMEM
__11:
	;
	libc.Xmemcpy(tls, zAltEntry, ts+19458, uint64(8))
	iFile = ncFile - 1
__12:
	if !(iFile >= 0 && !(int32(*(*uint8)(unsafe.Pointer(zFile + uintptr(iFile)))) == '/')) {
		goto __14
	}
	goto __13
__13:
	iFile--
	goto __12
	goto __14
__14:
	;
	iFile++
	if !(Xsqlite3_strnicmp(tls, zFile+uintptr(iFile), ts+19467, 3) == 0) {
		goto __15
	}
	iFile = iFile + 3
__15:
	;
	iEntry = 8
__16:
	if !(libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(zFile + uintptr(iFile))))) != 0 && c != '.') {
		goto __18
	}
	if !(int32(Xsqlite3CtypeMap[uint8(c)])&0x02 != 0) {
		goto __19
	}
	*(*uint8)(unsafe.Pointer(zAltEntry + uintptr(libc.PostIncInt32(&iEntry, 1)))) = Xsqlite3UpperToLower[uint32(c)]
__19:
	;
	goto __17
__17:
	iFile++
	goto __16
	goto __18
__18:
	;
	libc.Xmemcpy(tls, zAltEntry+uintptr(iEntry), ts+19471, uint64(6))
	zEntry = zAltEntry
	xInit = Xsqlite3OsDlSym(tls, pVfs, handle, zEntry)
__10:
	;
	if !(xInit == uintptr(0)) {
		goto __20
	}
	if !(pzErrMsg != 0) {
		goto __21
	}
	nMsg = nMsg + (libc.Xstrlen(tls, zEntry) + uint64(300))
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = libc.AssignPtrUintptr(bp+56, Xsqlite3_malloc64(tls, nMsg))
	if !(*(*uintptr)(unsafe.Pointer(bp + 56)) != 0) {
		goto __22
	}

	Xsqlite3_snprintf(tls, int32(nMsg), *(*uintptr)(unsafe.Pointer(bp + 56)),
		ts+19477, libc.VaList(bp+16, zEntry, zFile))
	Xsqlite3OsDlError(tls, pVfs, int32(nMsg-uint64(1)), *(*uintptr)(unsafe.Pointer(bp + 56)))
__22:
	;
__21:
	;
	Xsqlite3OsDlClose(tls, pVfs, handle)
	Xsqlite3_free(tls, zAltEntry)
	return SQLITE_ERROR
__20:
	;
	Xsqlite3_free(tls, zAltEntry)
	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{xInit})).f(tls, db, bp+56, uintptr(unsafe.Pointer(&sqlite3Apis)))
	if !(rc != 0) {
		goto __23
	}
	if !(rc == SQLITE_OK|int32(1)<<8) {
		goto __24
	}
	return SQLITE_OK
__24:
	;
	if !(pzErrMsg != 0) {
		goto __25
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+19520, libc.VaList(bp+32, *(*uintptr)(unsafe.Pointer(bp + 56))))
__25:
	;
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 56)))
	Xsqlite3OsDlClose(tls, pVfs, handle)
	return SQLITE_ERROR
__23:
	;
	aHandle = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(handle))*uint64((*Sqlite3)(unsafe.Pointer(db)).FnExtension+1))
	if !(aHandle == uintptr(0)) {
		goto __26
	}
	return SQLITE_NOMEM
__26:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FnExtension > 0) {
		goto __27
	}
	libc.Xmemcpy(tls, aHandle, (*Sqlite3)(unsafe.Pointer(db)).FaExtension, uint64(unsafe.Sizeof(handle))*uint64((*Sqlite3)(unsafe.Pointer(db)).FnExtension))
__27:
	;
	Xsqlite3DbFree(tls, db, (*Sqlite3)(unsafe.Pointer(db)).FaExtension)
	(*Sqlite3)(unsafe.Pointer(db)).FaExtension = aHandle

	*(*uintptr)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaExtension + uintptr(libc.PostIncInt32(&(*Sqlite3)(unsafe.Pointer(db)).FnExtension, 1))*8)) = handle
	return SQLITE_OK

extension_not_found:
	if !(pzErrMsg != 0) {
		goto __28
	}
	nMsg = nMsg + uint64(300)
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = libc.AssignPtrUintptr(bp+56, Xsqlite3_malloc64(tls, nMsg))
	if !(*(*uintptr)(unsafe.Pointer(bp + 56)) != 0) {
		goto __29
	}

	Xsqlite3_snprintf(tls, int32(nMsg), *(*uintptr)(unsafe.Pointer(bp + 56)),
		ts+19552, libc.VaList(bp+40, FILENAME_MAX, zFile))
	Xsqlite3OsDlError(tls, pVfs, int32(nMsg-uint64(1)), *(*uintptr)(unsafe.Pointer(bp + 56)))
__29:
	;
__28:
	;
	return SQLITE_ERROR
}

var azEndings = [1]uintptr{
	ts + 19589,
}

func Xsqlite3_load_extension(tls *libc.TLS, db uintptr, zFile uintptr, zProc uintptr, pzErrMsg uintptr) int32 {
	var rc int32
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	rc = sqlite3LoadExtension(tls, db, zFile, zProc, pzErrMsg)
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3CloseExtensions(tls *libc.TLS, db uintptr) {
	var i int32

	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnExtension; i++ {
		Xsqlite3OsDlClose(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, *(*uintptr)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaExtension + uintptr(i)*8)))
	}
	Xsqlite3DbFree(tls, db, (*Sqlite3)(unsafe.Pointer(db)).FaExtension)
}

func Xsqlite3_enable_load_extension(tls *libc.TLS, db uintptr, onoff int32) int32 {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if onoff != 0 {
		*(*U64)(unsafe.Pointer(db + 48)) |= uint64(SQLITE_LoadExtension | SQLITE_LoadExtFunc)
	} else {
		*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(SQLITE_LoadExtension | SQLITE_LoadExtFunc))
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

type sqlite3AutoExtList = struct {
	FnExt        U32
	F__ccgo_pad1 [4]byte
	FaExt        uintptr
}

type Sqlite3AutoExtList = sqlite3AutoExtList

var sqlite3Autoext = sqlite3AutoExtList{}

func Xsqlite3_auto_extension(tls *libc.TLS, xInit uintptr) int32 {
	var rc int32 = SQLITE_OK
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	} else {
		var i U32
		var mutex uintptr = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)

		Xsqlite3_mutex_enter(tls, mutex)
		for i = U32(0); i < sqlite3Autoext.FnExt; i++ {
			if *(*uintptr)(unsafe.Pointer(sqlite3Autoext.FaExt + uintptr(i)*8)) == xInit {
				break
			}
		}
		if i == sqlite3Autoext.FnExt {
			var nByte U64 = uint64(sqlite3Autoext.FnExt+U32(1)) * uint64(unsafe.Sizeof(uintptr(0)))
			var aNew uintptr
			aNew = Xsqlite3_realloc64(tls, sqlite3Autoext.FaExt, nByte)
			if aNew == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				sqlite3Autoext.FaExt = aNew
				*(*uintptr)(unsafe.Pointer(sqlite3Autoext.FaExt + uintptr(sqlite3Autoext.FnExt)*8)) = xInit
				sqlite3Autoext.FnExt++
			}
		}
		Xsqlite3_mutex_leave(tls, mutex)

		return rc
	}
	return int32(0)
}

func Xsqlite3_cancel_auto_extension(tls *libc.TLS, xInit uintptr) int32 {
	var mutex uintptr = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	var i int32
	var n int32 = 0

	Xsqlite3_mutex_enter(tls, mutex)
	for i = int32(sqlite3Autoext.FnExt) - 1; i >= 0; i-- {
		if *(*uintptr)(unsafe.Pointer(sqlite3Autoext.FaExt + uintptr(i)*8)) == xInit {
			sqlite3Autoext.FnExt--
			*(*uintptr)(unsafe.Pointer(sqlite3Autoext.FaExt + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer(sqlite3Autoext.FaExt + uintptr(sqlite3Autoext.FnExt)*8))
			n++
			break
		}
	}
	Xsqlite3_mutex_leave(tls, mutex)
	return n
}

func Xsqlite3_reset_auto_extension(tls *libc.TLS) {
	if Xsqlite3_initialize(tls) == SQLITE_OK {
		var mutex uintptr = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)

		Xsqlite3_mutex_enter(tls, mutex)
		Xsqlite3_free(tls, sqlite3Autoext.FaExt)
		sqlite3Autoext.FaExt = uintptr(0)
		sqlite3Autoext.FnExt = U32(0)
		Xsqlite3_mutex_leave(tls, mutex)
	}
}

func Xsqlite3AutoLoadExtensions(tls *libc.TLS, db uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var i U32
	var go1 int32 = 1
	var rc int32
	var xInit Sqlite3_loadext_entry

	if sqlite3Autoext.FnExt == U32(0) {
		return
	}
	for i = U32(0); go1 != 0; i++ {
		var mutex uintptr = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
		var pThunk uintptr = 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)*8))
		}
		Xsqlite3_mutex_leave(tls, mutex)
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		if xInit != 0 && libc.AssignInt32(&rc, (*struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{xInit})).f(tls, db, bp+8, pThunk)) != 0 {
			Xsqlite3ErrorWithMsg(tls, db, rc,
				ts+19592, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(bp + 8))))
			go1 = 0
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}
}

var pragCName = [57]uintptr{
	ts + 7982,
	ts + 19631,
	ts + 9499,
	ts + 19635,
	ts + 19640,
	ts + 19643,
	ts + 19653,
	ts + 19663,
	ts + 19669,
	ts + 19673,
	ts + 19678,
	ts + 19683,
	ts + 19691,
	ts + 19702,
	ts + 19705,
	ts + 19712,
	ts + 19673,
	ts + 19678,
	ts + 19719,
	ts + 19724,
	ts + 19727,
	ts + 19734,
	ts + 19669,
	ts + 19673,
	ts + 19740,
	ts + 19745,
	ts + 19750,
	ts + 19673,
	ts + 19754,
	ts + 19678,
	ts + 19762,
	ts + 19766,
	ts + 19771,
	ts + 14907,
	ts + 14903,
	ts + 19777,
	ts + 19782,
	ts + 19787,
	ts + 19631,
	ts + 19673,
	ts + 19792,
	ts + 19799,
	ts + 19806,
	ts + 9499,
	ts + 11466,
	ts + 7985,
	ts + 19814,
	ts + 19631,
	ts + 19673,
	ts + 19819,
	ts + 19824,
	ts + 18893,
	ts + 19829,
	ts + 19842,
	ts + 19851,
	ts + 19858,
	ts + 19869,
}

type PragmaName1 = struct {
	FzName       uintptr
	FePragTyp    U8
	FmPragFlg    U8
	FiPragCName  U8
	FnPragCName  U8
	F__ccgo_pad1 [4]byte
	FiArg        U64
}

type PragmaName = PragmaName1

var aPragmaName = [67]PragmaName{
	{FzName: ts + 19877,
		FePragTyp: U8(PragTyp_ANALYSIS_LIMIT),
		FmPragFlg: U8(PragFlg_Result0)},
	{FzName: ts + 19892,
		FePragTyp: U8(PragTyp_HEADER_VALUE),
		FmPragFlg: U8(PragFlg_NoColumns1 | PragFlg_Result0),
		FiArg:     uint64(BTREE_APPLICATION_ID)},
	{FzName: ts + 19907,
		FePragTyp: U8(PragTyp_AUTO_VACUUM),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq | PragFlg_NoColumns1)},
	{FzName: ts + 19919,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_AutoIndex)},
	{FzName: ts + 19935,
		FePragTyp:   U8(PragTyp_BUSY_TIMEOUT),
		FmPragFlg:   U8(PragFlg_Result0),
		FiPragCName: U8(56), FnPragCName: U8(1)},
	{FzName: ts + 19858,
		FePragTyp: U8(PragTyp_CACHE_SIZE),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq | PragFlg_NoColumns1)},
	{FzName: ts + 19948,
		FePragTyp: U8(PragTyp_CACHE_SPILL),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_SchemaReq | PragFlg_NoColumns1)},
	{FzName: ts + 19960,
		FePragTyp: U8(PragTyp_CASE_SENSITIVE_LIKE),
		FmPragFlg: U8(PragFlg_NoColumns)},
	{FzName: ts + 19980,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_CellSizeCk)},
	{FzName: ts + 19996,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_CkptFullFSync)},
	{FzName: ts + 20017,
		FePragTyp:   U8(PragTyp_COLLATION_LIST),
		FmPragFlg:   U8(PragFlg_Result0),
		FiPragCName: U8(38), FnPragCName: U8(2)},
	{FzName: ts + 20032,
		FePragTyp: U8(PragTyp_COMPILE_OPTIONS),
		FmPragFlg: U8(PragFlg_Result0)},
	{FzName: ts + 20048,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(0x00001) << 32},
	{FzName: ts + 20062,
		FePragTyp: U8(PragTyp_HEADER_VALUE),
		FmPragFlg: U8(PragFlg_ReadOnly | PragFlg_Result0),
		FiArg:     uint64(BTREE_DATA_VERSION)},
	{FzName: ts + 20075,
		FePragTyp:   U8(PragTyp_DATABASE_LIST),
		FmPragFlg:   U8(PragFlg_Result0),
		FiPragCName: U8(47), FnPragCName: U8(3)},
	{FzName: ts + 20089,
		FePragTyp:   U8(PragTyp_DEFAULT_CACHE_SIZE),
		FmPragFlg:   U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq | PragFlg_NoColumns1),
		FiPragCName: U8(55), FnPragCName: U8(1)},
	{FzName: ts + 20108,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_DeferFKs)},
	{FzName: ts + 20127,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_NullCallback)},
	{FzName: ts + 20150,
		FePragTyp: U8(PragTyp_ENCODING),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1)},
	{FzName: ts + 20159,
		FePragTyp:   U8(PragTyp_FOREIGN_KEY_CHECK),
		FmPragFlg:   U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_Result1 | PragFlg_SchemaOpt),
		FiPragCName: U8(43), FnPragCName: U8(4)},
	{FzName: ts + 20177,
		FePragTyp: U8(PragTyp_FOREIGN_KEY_LIST),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt), FnPragCName: U8(8)},
	{FzName: ts + 20194,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_ForeignKeys)},
	{FzName: ts + 20207,
		FePragTyp: U8(PragTyp_HEADER_VALUE),
		FmPragFlg: U8(PragFlg_ReadOnly | PragFlg_Result0)},
	{FzName: ts + 20222,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_FullColNames)},
	{FzName: ts + 20240,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_FullFSync)},
	{FzName: ts + 20250,
		FePragTyp:   U8(PragTyp_FUNCTION_LIST),
		FmPragFlg:   U8(PragFlg_Result0),
		FiPragCName: U8(27), FnPragCName: U8(6)},
	{FzName: ts + 20264,
		FePragTyp: U8(PragTyp_HARD_HEAP_LIMIT),
		FmPragFlg: U8(PragFlg_Result0)},
	{FzName: ts + 20280,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_IgnoreChecks)},
	{FzName: ts + 20305,
		FePragTyp: U8(PragTyp_INCREMENTAL_VACUUM),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_NoColumns)},
	{FzName: ts + 20324,
		FePragTyp:   U8(PragTyp_INDEX_INFO),
		FmPragFlg:   U8(PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt),
		FiPragCName: U8(21), FnPragCName: U8(3)},
	{FzName: ts + 20335,
		FePragTyp:   U8(PragTyp_INDEX_LIST),
		FmPragFlg:   U8(PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt),
		FiPragCName: U8(38), FnPragCName: U8(5)},
	{FzName: ts + 20346,
		FePragTyp:   U8(PragTyp_INDEX_INFO),
		FmPragFlg:   U8(PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt),
		FiPragCName: U8(21), FnPragCName: U8(6),
		FiArg: uint64(1)},
	{FzName: ts + 20358,
		FePragTyp: U8(PragTyp_INTEGRITY_CHECK),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_Result1 | PragFlg_SchemaOpt)},
	{FzName: ts + 20374,
		FePragTyp: U8(PragTyp_JOURNAL_MODE),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq)},
	{FzName: ts + 20387,
		FePragTyp: U8(PragTyp_JOURNAL_SIZE_LIMIT),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_SchemaReq)},
	{FzName: ts + 20406,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_LegacyAlter)},
	{FzName: ts + 20425,
		FePragTyp:   U8(PragTyp_LOCK_STATUS),
		FmPragFlg:   U8(PragFlg_Result0),
		FiPragCName: U8(53), FnPragCName: U8(2)},
	{FzName: ts + 20437,
		FePragTyp: U8(PragTyp_LOCKING_MODE),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_SchemaReq)},
	{FzName: ts + 20450,
		FePragTyp: U8(PragTyp_PAGE_COUNT),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq)},
	{FzName: ts + 20465,
		FePragTyp: U8(PragTyp_MMAP_SIZE)},
	{FzName: ts + 20475,
		FePragTyp:   U8(PragTyp_MODULE_LIST),
		FmPragFlg:   U8(PragFlg_Result0),
		FiPragCName: U8(9), FnPragCName: U8(1)},
	{FzName: ts + 20487,
		FePragTyp: U8(PragTyp_OPTIMIZE),
		FmPragFlg: U8(PragFlg_Result1 | PragFlg_NeedSchema)},
	{FzName: ts + 20496,
		FePragTyp: U8(PragTyp_PAGE_COUNT),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq)},
	{FzName: ts + 20507,
		FePragTyp: U8(PragTyp_PAGE_SIZE),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_SchemaReq | PragFlg_NoColumns1)},
	{FzName: ts + 20517,
		FePragTyp:   U8(PragTyp_PRAGMA_LIST),
		FmPragFlg:   U8(PragFlg_Result0),
		FiPragCName: U8(9), FnPragCName: U8(1)},
	{FzName: ts + 20529,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_QueryOnly)},
	{FzName: ts + 20540,
		FePragTyp: U8(PragTyp_INTEGRITY_CHECK),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_Result1 | PragFlg_SchemaOpt)},
	{FzName: ts + 20552,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_ReadUncommit)},
	{FzName: ts + 20569,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_RecTriggers)},
	{FzName: ts + 20588,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_ReverseOrder)},
	{FzName: ts + 20614,
		FePragTyp: U8(PragTyp_HEADER_VALUE),
		FmPragFlg: U8(PragFlg_NoColumns1 | PragFlg_Result0),
		FiArg:     uint64(BTREE_SCHEMA_VERSION)},
	{FzName: ts + 20629,
		FePragTyp: U8(PragTyp_SECURE_DELETE),
		FmPragFlg: U8(PragFlg_Result0)},
	{FzName: ts + 20643,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_ShortColNames)},
	{FzName: ts + 20662,
		FePragTyp: U8(PragTyp_SHRINK_MEMORY),
		FmPragFlg: U8(PragFlg_NoColumns)},
	{FzName: ts + 20676,
		FePragTyp: U8(PragTyp_SOFT_HEAP_LIMIT),
		FmPragFlg: U8(PragFlg_Result0)},
	{FzName: ts + 20692,
		FePragTyp: U8(PragTyp_SYNCHRONOUS),
		FmPragFlg: U8(PragFlg_NeedSchema | PragFlg_Result0 | PragFlg_SchemaReq | PragFlg_NoColumns1)},
	{FzName: ts + 20704,
		FePragTyp:   U8(PragTyp_TABLE_INFO),
		FmPragFlg:   U8(PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt),
		FiPragCName: U8(8), FnPragCName: U8(6)},
	{FzName: ts + 20715,
		FePragTyp:   U8(PragTyp_TABLE_LIST),
		FmPragFlg:   U8(PragFlg_NeedSchema | PragFlg_Result1),
		FiPragCName: U8(15), FnPragCName: U8(6)},
	{FzName: ts + 20726,
		FePragTyp:   U8(PragTyp_TABLE_INFO),
		FmPragFlg:   U8(PragFlg_NeedSchema | PragFlg_Result1 | PragFlg_SchemaOpt),
		FiPragCName: U8(8), FnPragCName: U8(7),
		FiArg: uint64(1)},
	{FzName: ts + 20738,
		FePragTyp: U8(PragTyp_TEMP_STORE),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1)},
	{FzName: ts + 20749,
		FePragTyp: U8(PragTyp_TEMP_STORE_DIRECTORY),
		FmPragFlg: U8(PragFlg_NoColumns1)},
	{FzName: ts + 20770,
		FePragTyp: U8(PragTyp_THREADS),
		FmPragFlg: U8(PragFlg_Result0)},
	{FzName: ts + 20778,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_TrustedSchema)},
	{FzName: ts + 20793,
		FePragTyp: U8(PragTyp_HEADER_VALUE),
		FmPragFlg: U8(PragFlg_NoColumns1 | PragFlg_Result0),
		FiArg:     uint64(BTREE_USER_VERSION)},
	{FzName: ts + 20806,
		FePragTyp: U8(PragTyp_WAL_AUTOCHECKPOINT)},
	{FzName: ts + 20825,
		FePragTyp:   U8(PragTyp_WAL_CHECKPOINT),
		FmPragFlg:   U8(PragFlg_NeedSchema),
		FiPragCName: U8(50), FnPragCName: U8(3)},
	{FzName: ts + 20840,
		FePragTyp: U8(PragTyp_FLAG),
		FmPragFlg: U8(PragFlg_Result0 | PragFlg_NoColumns1),
		FiArg:     uint64(SQLITE_WriteSchema | SQLITE_NoSchemaError)},
}

func getSafetyLevel(tls *libc.TLS, z uintptr, omitFull int32, dflt U8) U8 {
	var i int32
	var n int32
	if int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z))])&0x04 != 0 {
		return U8(Xsqlite3Atoi(tls, z))
	}
	n = Xsqlite3Strlen30(tls, z)
	for i = 0; i < int32(uint64(unsafe.Sizeof(iLength))/uint64(unsafe.Sizeof(U8(0)))); i++ {
		if int32(iLength[i]) == n && Xsqlite3_strnicmp(tls, uintptr(unsafe.Pointer(&zText))+uintptr(iOffset[i]), z, n) == 0 &&
			(!(omitFull != 0) || int32(iValue[i]) <= 1) {
			return iValue[i]
		}
	}
	return dflt
}

var zText = *(*[25]uint8)(unsafe.Pointer(ts + 20856))
var iOffset = [8]U8{U8(0), U8(1), U8(2), U8(4), U8(9), U8(12), U8(15), U8(20)}
var iLength = [8]U8{U8(2), U8(2), U8(3), U8(5), U8(3), U8(4), U8(5), U8(4)}
var iValue = [8]U8{U8(1), U8(0), U8(0), U8(0), U8(1), U8(1), U8(3), U8(2)}

func Xsqlite3GetBoolean(tls *libc.TLS, z uintptr, dflt U8) U8 {
	return U8(libc.Bool32(int32(getSafetyLevel(tls, z, 1, dflt)) != 0))
}

func getLockingMode(tls *libc.TLS, z uintptr) int32 {
	if z != 0 {
		if 0 == Xsqlite3StrICmp(tls, z, ts+20881) {
			return PAGER_LOCKINGMODE_EXCLUSIVE
		}
		if 0 == Xsqlite3StrICmp(tls, z, ts+20891) {
			return PAGER_LOCKINGMODE_NORMAL
		}
	}
	return -1
}

func getAutoVacuum(tls *libc.TLS, z uintptr) int32 {
	var i int32
	if 0 == Xsqlite3StrICmp(tls, z, ts+11374) {
		return BTREE_AUTOVACUUM_NONE
	}
	if 0 == Xsqlite3StrICmp(tls, z, ts+20898) {
		return BTREE_AUTOVACUUM_FULL
	}
	if 0 == Xsqlite3StrICmp(tls, z, ts+20903) {
		return BTREE_AUTOVACUUM_INCR
	}
	i = Xsqlite3Atoi(tls, z)
	return int32(func() uint8 {
		if i >= 0 && i <= 2 {
			return uint8(i)
		}
		return uint8(0)
	}())
}

func getTempStore(tls *libc.TLS, z uintptr) int32 {
	if int32(*(*uint8)(unsafe.Pointer(z))) >= '0' && int32(*(*uint8)(unsafe.Pointer(z))) <= '2' {
		return int32(*(*uint8)(unsafe.Pointer(z))) - '0'
	} else if Xsqlite3StrICmp(tls, z, ts+19819) == 0 {
		return 1
	} else if Xsqlite3StrICmp(tls, z, ts+20915) == 0 {
		return 2
	} else {
		return 0
	}
	return int32(0)
}

func invalidateTempStorage(tls *libc.TLS, pParse uintptr) int32 {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpBt != uintptr(0) {
		if !(int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit) != 0) ||
			Xsqlite3BtreeTxnState(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpBt) != SQLITE_TXN_NONE {
			Xsqlite3ErrorMsg(tls, pParse,
				ts+20922, 0)
			return SQLITE_ERROR
		}
		Xsqlite3BtreeClose(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpBt)
		(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + 1*32)).FpBt = uintptr(0)
		Xsqlite3ResetAllSchemasOfConnection(tls, db)
	}
	return SQLITE_OK
}

func changeTempStorage(tls *libc.TLS, pParse uintptr, zStorageType uintptr) int32 {
	var ts int32 = getTempStore(tls, zStorageType)
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if int32((*Sqlite3)(unsafe.Pointer(db)).Ftemp_store) == ts {
		return SQLITE_OK
	}
	if invalidateTempStorage(tls, pParse) != SQLITE_OK {
		return SQLITE_ERROR
	}
	(*Sqlite3)(unsafe.Pointer(db)).Ftemp_store = U8(ts)
	return SQLITE_OK
}

func setPragmaResultColumnNames(tls *libc.TLS, v uintptr, pPragma uintptr) {
	var n U8 = (*PragmaName)(unsafe.Pointer(pPragma)).FnPragCName
	Xsqlite3VdbeSetNumCols(tls, v, func() int32 {
		if int32(n) == 0 {
			return 1
		}
		return int32(n)
	}())
	if int32(n) == 0 {
		Xsqlite3VdbeSetColName(tls, v, 0, COLNAME_NAME, (*PragmaName)(unsafe.Pointer(pPragma)).FzName, uintptr(0))
	} else {
		var i int32
		var j int32
		i = 0
		j = int32((*PragmaName)(unsafe.Pointer(pPragma)).FiPragCName)
	__1:
		if !(i < int32(n)) {
			goto __3
		}
		{
			Xsqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, pragCName[j], uintptr(0))

		}
		goto __2
	__2:
		i++
		j++
		goto __1
		goto __3
	__3:
	}
}

func returnSingleInt(tls *libc.TLS, v uintptr, value I64) {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*I64)(unsafe.Pointer(bp)) = value

	Xsqlite3VdbeAddOp4Dup8(tls, v, OP_Int64, 0, 1, 0, bp, -13)
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, 1, 1)
}

func returnSingleText(tls *libc.TLS, v uintptr, zValue uintptr) {
	if zValue != 0 {
		Xsqlite3VdbeLoadString(tls, v, 1, zValue)
		Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, 1, 1)
	}
}

func setAllPagerFlags(tls *libc.TLS, db uintptr) {
	if (*Sqlite3)(unsafe.Pointer(db)).FautoCommit != 0 {
		var pDb uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaDb
		var n int32 = (*Sqlite3)(unsafe.Pointer(db)).FnDb

		for libc.PostDecInt32(&n, 1) > 0 {
			if (*Db)(unsafe.Pointer(pDb)).FpBt != 0 {
				Xsqlite3BtreeSetPagerFlags(tls, (*Db)(unsafe.Pointer(pDb)).FpBt,
					uint32(U64((*Db)(unsafe.Pointer(pDb)).Fsafety_level)|(*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK)))
			}
			pDb += 32
		}
	}
}

func actionName(tls *libc.TLS, action U8) uintptr {
	var zName uintptr
	switch int32(action) {
	case OE_SetNull:
		zName = ts + 20984
		break
	case OE_SetDflt:
		zName = ts + 20993
		break
	case OE_Cascade:
		zName = ts + 21005
		break
	case OE_Restrict:
		zName = ts + 21013
		break
	default:
		zName = ts + 21022
		break
	}
	return zName
}

func Xsqlite3JournalModename(tls *libc.TLS, eMode int32) uintptr {
	if eMode == int32(uint64(unsafe.Sizeof(azModeName))/uint64(unsafe.Sizeof(uintptr(0)))) {
		return uintptr(0)
	}
	return azModeName[eMode]
}

var azModeName = [6]uintptr{
	ts + 21032, ts + 21039, ts + 21047, ts + 21051, ts + 20915, ts + 21060,
}

func pragmaLocate(tls *libc.TLS, zName uintptr) uintptr {
	var upr int32
	var lwr int32
	var mid int32 = 0
	var rc int32
	lwr = 0
	upr = int32(uint64(unsafe.Sizeof(aPragmaName))/uint64(unsafe.Sizeof(PragmaName{}))) - 1
	for lwr <= upr {
		mid = (lwr + upr) / 2
		rc = Xsqlite3_stricmp(tls, zName, aPragmaName[mid].FzName)
		if rc == 0 {
			break
		}
		if rc < 0 {
			upr = mid - 1
		} else {
			lwr = mid + 1
		}
	}
	if lwr > upr {
		return uintptr(0)
	}
	return uintptr(unsafe.Pointer(&aPragmaName)) + uintptr(mid)*24
}

func pragmaFunclistLine(tls *libc.TLS, v uintptr, p uintptr, isBuiltin int32, showInternFuncs int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var mask U32 = U32(SQLITE_DETERMINISTIC | SQLITE_DIRECTONLY | SQLITE_SUBTYPE | SQLITE_INNOCUOUS | SQLITE_FUNC_INTERNAL)
	if showInternFuncs != 0 {
		mask = 0xffffffff
	}
	for ; p != 0; p = (*FuncDef)(unsafe.Pointer(p)).FpNext {
		var zType uintptr

		if (*FuncDef)(unsafe.Pointer(p)).FxSFunc == uintptr(0) {
			continue
		}
		if (*FuncDef)(unsafe.Pointer(p)).FfuncFlags&U32(SQLITE_FUNC_INTERNAL) != U32(0) &&
			showInternFuncs == 0 {
			continue
		}
		if (*FuncDef)(unsafe.Pointer(p)).FxValue != uintptr(0) {
			zType = ts + 21064
		} else if (*FuncDef)(unsafe.Pointer(p)).FxFinalize != uintptr(0) {
			zType = ts + 21066
		} else {
			zType = ts + 10732
		}
		Xsqlite3VdbeMultiLoad(tls, v, 1, ts+21068,
			libc.VaList(bp, (*FuncDef)(unsafe.Pointer(p)).FzName, isBuiltin,
				zType, azEnc[(*FuncDef)(unsafe.Pointer(p)).FfuncFlags&U32(SQLITE_FUNC_ENCMASK)],
				int32((*FuncDef)(unsafe.Pointer(p)).FnArg),
				(*FuncDef)(unsafe.Pointer(p)).FfuncFlags&mask^U32(SQLITE_INNOCUOUS)))
	}
}

var azEnc = [4]uintptr{uintptr(0), ts + 21075, ts + 21080, ts + 21088}

func integrityCheckResultRow(tls *libc.TLS, v uintptr) int32 {
	var addr int32
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, 3, 1)
	addr = Xsqlite3VdbeAddOp3(tls, v, OP_IfPos, 1, Xsqlite3VdbeCurrentAddr(tls, v)+2, 1)

	Xsqlite3VdbeAddOp0(tls, v, OP_Halt)
	return addr
}

func Xsqlite3Pragma(tls *libc.TLS, pParse uintptr, pId1 uintptr, pId2 uintptr, pValue uintptr, minusFlag int32) {
	bp := tls.Alloc(692)
	defer tls.Free(692)

	var zLeft uintptr
	var zRight uintptr
	var zDb uintptr

	var iDb int32
	var rc int32
	var db uintptr
	var pDb uintptr
	var v uintptr
	var pPragma uintptr
	var size int32
	var aOp uintptr
	var size1 int32
	var pBt uintptr
	var ii int32
	var pBt1 uintptr
	var b int32
	var iReg int32

	var ii1 int32
	var pPager uintptr
	var zRet uintptr
	var eMode int32
	var zMode uintptr
	var n int32
	var eMode1 int32
	var ii2 int32
	var pPager1 uintptr

	var aOp1 uintptr
	var iAddr int32
	var eAuto int32
	var pBt2 uintptr

	var addr int32
	var size2 int32

	var ii3 int32

	var iLevel int32
	var mask U64
	var isHidden int32
	var pColExpr uintptr
	var i int32
	var k int32
	var nHidden int32
	var pCol uintptr
	var pPk uintptr
	var pTab uintptr

	var zSql uintptr
	var pTab1 uintptr
	var pTab2 uintptr
	var zType uintptr
	var k1 uintptr
	var pHash uintptr
	var initNCol int32
	var ii4 int32
	var cnum I16
	var iIdxDb int32
	var i1 int32
	var mx int32
	var pIdx uintptr
	var pTab3 uintptr

	var iTabDb int32
	var pIdx1 uintptr
	var pTab4 uintptr
	var i2 int32
	var i3 int32
	var pColl uintptr
	var i4 int32
	var p uintptr
	var i5 int32
	var j uintptr
	var p1 uintptr
	var showInternFunc int32
	var pMod uintptr
	var j1 uintptr
	var i6 int32
	var j2 int32
	var iTabDb1 int32
	var i7 int32
	var pFK uintptr
	var pTab5 uintptr
	var iCol int32
	var jmp int32
	var pFK1 uintptr
	var pTab6 uintptr
	var pParent uintptr

	var i8 int32
	var j3 int32
	var k2 uintptr
	var x1 int32
	var regResult int32
	var regRow int32
	var addrTop int32
	var addrOk int32

	var pTab7 uintptr
	var pIdx3 uintptr
	var nIdx int32
	var pTab8 uintptr
	var pIdx4 uintptr

	var a1 int32
	var zErr uintptr

	var jmp2 int32
	var zErr1 uintptr
	var pCol1 uintptr
	var labelError int32
	var labelOk int32
	var p11 int32
	var p3 int32
	var p4 int32
	var doTypeCheck int32
	var addrCkFault int32
	var addrCkOk int32
	var zErr2 uintptr
	var k3 int32
	var pCheck uintptr
	var jmp7 int32
	var jmp6 int32
	var iCol1 int32
	var uniqOk int32
	var jmp61 int32
	var jmp21 int32

	var jmp4 int32
	var jmp5 int32
	var label6 int32
	var kk int32
	var ckUniq int32
	var pTab9 uintptr
	var pIdx5 uintptr
	var pPk1 uintptr
	var pPrior uintptr
	var loopTop int32

	var r1 int32
	var bStrict int32
	var r2 int32
	var mxCol int32
	var x2 uintptr
	var pTbls uintptr
	var aRoot uintptr
	var cnt int32
	var mxIdx int32
	var aOp2 uintptr
	var i9 int32
	var j4 int32
	var addr1 int32

	var pObjTab uintptr

	var isQuick int32
	var enc U8
	var pEnc uintptr
	var aOp3 uintptr
	var aOp4 uintptr
	var iCookie int32
	var i10 int32
	var zOpt uintptr
	var iBt int32
	var eMode2 int32
	var r11 int32
	var iDbLast int32
	var iTabCur int32
	var k4 uintptr
	var pSchema uintptr
	var pTab10 uintptr
	var pIdx6 uintptr
	var szThreshold LogEst
	var zSubSql uintptr
	var opMask U32

	var iPrior Sqlite3_int64

	var pBt3 uintptr
	var zState uintptr

	var i11 int32
	zLeft = uintptr(0)
	zRight = uintptr(0)
	zDb = uintptr(0)
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	v = Xsqlite3GetVdbe(tls, pParse)

	if !(v == uintptr(0)) {
		goto __1
	}
	return
__1:
	;
	Xsqlite3VdbeRunOnlyOnce(tls, v)
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 2

	iDb = Xsqlite3TwoPartName(tls, pParse, pId1, pId2, bp+496)
	if !(iDb < 0) {
		goto __2
	}
	return
__2:
	;
	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32

	if !(iDb == 1 && Xsqlite3OpenTempDatabase(tls, pParse) != 0) {
		goto __3
	}
	return
__3:
	;
	zLeft = Xsqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp + 496)))
	if !!(zLeft != 0) {
		goto __4
	}
	return
__4:
	;
	if !(minusFlag != 0) {
		goto __5
	}
	zRight = Xsqlite3MPrintf(tls, db, ts+21096, libc.VaList(bp, pValue))
	goto __6
__5:
	zRight = Xsqlite3NameFromToken(tls, db, pValue)
__6:
	;
	if (*Token)(unsafe.Pointer(pId2)).Fn > uint32(0) {
		zDb = (*Db)(unsafe.Pointer(pDb)).FzDbSName
	} else {
		zDb = uintptr(0)
	}
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) != 0) {
		goto __7
	}
	goto pragma_out
__7:
	;
	*(*uintptr)(unsafe.Pointer(bp + 504)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 504 + 1*8)) = zLeft
	*(*uintptr)(unsafe.Pointer(bp + 504 + 2*8)) = zRight
	*(*uintptr)(unsafe.Pointer(bp + 504 + 3*8)) = uintptr(0)
	(*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	rc = Xsqlite3_file_control(tls, db, zDb, SQLITE_FCNTL_PRAGMA, bp+504)
	if !(rc == SQLITE_OK) {
		goto __8
	}
	Xsqlite3VdbeSetNumCols(tls, v, 1)
	Xsqlite3VdbeSetColName(tls, v, 0, COLNAME_NAME, *(*uintptr)(unsafe.Pointer(bp + 504)), libc.UintptrFromInt32(-1))
	returnSingleText(tls, v, *(*uintptr)(unsafe.Pointer(bp + 504)))
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 504)))
	goto pragma_out
__8:
	;
	if !(rc != SQLITE_NOTFOUND) {
		goto __9
	}
	if !(*(*uintptr)(unsafe.Pointer(bp + 504)) != 0) {
		goto __10
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+1684, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(bp + 504))))
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 504)))
__10:
	;
	(*Parse)(unsafe.Pointer(pParse)).FnErr++
	(*Parse)(unsafe.Pointer(pParse)).Frc = rc
	goto pragma_out
__9:
	;
	pPragma = pragmaLocate(tls, zLeft)
	if !(pPragma == uintptr(0)) {
		goto __11
	}

	goto pragma_out
__11:
	;
	if !(int32((*PragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&PragFlg_NeedSchema != 0) {
		goto __12
	}
	if !(Xsqlite3ReadSchema(tls, pParse) != 0) {
		goto __13
	}
	goto pragma_out
__13:
	;
__12:
	;
	if !(int32((*PragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&PragFlg_NoColumns == 0 &&
		(int32((*PragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&PragFlg_NoColumns1 == 0 || zRight == uintptr(0))) {
		goto __14
	}
	setPragmaResultColumnNames(tls, v, pPragma)
__14:
	;
	switch int32((*PragmaName)(unsafe.Pointer(pPragma)).FePragTyp) {
	case PragTyp_DEFAULT_CACHE_SIZE:
		goto __16

	case PragTyp_PAGE_SIZE:
		goto __17

	case PragTyp_SECURE_DELETE:
		goto __18

	case PragTyp_PAGE_COUNT:
		goto __19

	case PragTyp_LOCKING_MODE:
		goto __20

	case PragTyp_JOURNAL_MODE:
		goto __21

	case PragTyp_JOURNAL_SIZE_LIMIT:
		goto __22

	case PragTyp_AUTO_VACUUM:
		goto __23

	case PragTyp_INCREMENTAL_VACUUM:
		goto __24

	case PragTyp_CACHE_SIZE:
		goto __25

	case PragTyp_CACHE_SPILL:
		goto __26

	case PragTyp_MMAP_SIZE:
		goto __27

	case PragTyp_TEMP_STORE:
		goto __28

	case PragTyp_TEMP_STORE_DIRECTORY:
		goto __29

	case PragTyp_SYNCHRONOUS:
		goto __30

	case PragTyp_FLAG:
		goto __31

	case PragTyp_TABLE_INFO:
		goto __32

	case PragTyp_TABLE_LIST:
		goto __33

	case PragTyp_INDEX_INFO:
		goto __34

	case PragTyp_INDEX_LIST:
		goto __35

	case PragTyp_DATABASE_LIST:
		goto __36

	case PragTyp_COLLATION_LIST:
		goto __37

	case PragTyp_FUNCTION_LIST:
		goto __38

	case PragTyp_MODULE_LIST:
		goto __39

	case PragTyp_PRAGMA_LIST:
		goto __40

	case PragTyp_FOREIGN_KEY_LIST:
		goto __41

	case PragTyp_FOREIGN_KEY_CHECK:
		goto __42

	case PragTyp_CASE_SENSITIVE_LIKE:
		goto __43

	case PragTyp_INTEGRITY_CHECK:
		goto __44

	case PragTyp_ENCODING:
		goto __45

	case PragTyp_HEADER_VALUE:
		goto __46

	case PragTyp_COMPILE_OPTIONS:
		goto __47

	case PragTyp_WAL_CHECKPOINT:
		goto __48

	case PragTyp_WAL_AUTOCHECKPOINT:
		goto __49

	case PragTyp_SHRINK_MEMORY:
		goto __50

	case PragTyp_OPTIMIZE:
		goto __51

	default:
		goto __52

	case PragTyp_SOFT_HEAP_LIMIT:
		goto __53

	case PragTyp_HARD_HEAP_LIMIT:
		goto __54

	case PragTyp_THREADS:
		goto __55

	case PragTyp_ANALYSIS_LIMIT:
		goto __56

	case PragTyp_LOCK_STATUS:
		goto __57
	}
	goto __15

__16:
	Xsqlite3VdbeUsesBtree(tls, v, iDb)
	if !!(zRight != 0) {
		goto __58
	}
	*(*int32)(unsafe.Pointer(pParse + 56)) += 2

	aOp = Xsqlite3VdbeAddOpList(tls, v, int32(uint64(unsafe.Sizeof(getCacheSize))/uint64(unsafe.Sizeof(VdbeOpList{}))), uintptr(unsafe.Pointer(&getCacheSize)), iLn3)
	if !(0 != 0) {
		goto __60
	}
	goto __15
__60:
	;
	(*VdbeOp)(unsafe.Pointer(aOp)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp + 1*32)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp + 6*32)).Fp1 = -2000
	goto __59
__58:
	size = Xsqlite3AbsInt32(tls, Xsqlite3Atoi(tls, zRight))
	Xsqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	Xsqlite3VdbeAddOp3(tls, v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, size)

	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size = size
	Xsqlite3BtreeSetCacheSize(tls, (*Db)(unsafe.Pointer(pDb)).FpBt, (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size)
__59:
	;
	goto __15

__17:
	pBt = (*Db)(unsafe.Pointer(pDb)).FpBt

	if !!(zRight != 0) {
		goto __61
	}
	if pBt != 0 {
		size1 = Xsqlite3BtreeGetPageSize(tls, pBt)
	} else {
		size1 = 0
	}
	returnSingleInt(tls, v, int64(size1))
	goto __62
__61:
	(*Sqlite3)(unsafe.Pointer(db)).FnextPagesize = Xsqlite3Atoi(tls, zRight)
	if !(SQLITE_NOMEM == Xsqlite3BtreeSetPageSize(tls, pBt, (*Sqlite3)(unsafe.Pointer(db)).FnextPagesize, 0, 0)) {
		goto __63
	}
	Xsqlite3OomFault(tls, db)
__63:
	;
__62:
	;
	goto __15

__18:
	pBt1 = (*Db)(unsafe.Pointer(pDb)).FpBt
	b = -1

	if !(zRight != 0) {
		goto __64
	}
	if !(Xsqlite3_stricmp(tls, zRight, ts+21100) == 0) {
		goto __65
	}
	b = 2
	goto __66
__65:
	b = int32(Xsqlite3GetBoolean(tls, zRight, uint8(0)))
__66:
	;
__64:
	;
	if !((*Token)(unsafe.Pointer(pId2)).Fn == uint32(0) && b >= 0) {
		goto __67
	}
	ii = 0
__68:
	if !(ii < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __70
	}
	Xsqlite3BtreeSecureDelete(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii)*32)).FpBt, b)
	goto __69
__69:
	ii++
	goto __68
	goto __70
__70:
	;
__67:
	;
	b = Xsqlite3BtreeSecureDelete(tls, pBt1, b)
	returnSingleInt(tls, v, int64(b))
	goto __15

__19:
	*(*I64)(unsafe.Pointer(bp + 536)) = int64(0)
	Xsqlite3CodeVerifySchema(tls, pParse, iDb)
	iReg = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	if !(int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(zLeft))]) == 'p') {
		goto __71
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Pagecount, iDb, iReg)
	goto __72
__71:
	if !(zRight != 0 && Xsqlite3DecOrHexToI64(tls, zRight, bp+536) == 0) {
		goto __73
	}
	if !(*(*I64)(unsafe.Pointer(bp + 536)) < int64(0)) {
		goto __75
	}
	*(*I64)(unsafe.Pointer(bp + 536)) = int64(0)
	goto __76
__75:
	if !(*(*I64)(unsafe.Pointer(bp + 536)) > int64(0xfffffffe)) {
		goto __77
	}
	*(*I64)(unsafe.Pointer(bp + 536)) = int64(0xfffffffe)
__77:
	;
__76:
	;
	goto __74
__73:
	*(*I64)(unsafe.Pointer(bp + 536)) = int64(0)
__74:
	;
	Xsqlite3VdbeAddOp3(tls, v, OP_MaxPgcnt, iDb, iReg, int32(*(*I64)(unsafe.Pointer(bp + 536))))
__72:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, iReg, 1)
	goto __15

__20:
	zRet = ts + 20891
	eMode = getLockingMode(tls, zRight)

	if !((*Token)(unsafe.Pointer(pId2)).Fn == uint32(0) && eMode == -1) {
		goto __78
	}

	eMode = int32((*Sqlite3)(unsafe.Pointer(db)).FdfltLockMode)
	goto __79
__78:
	if !((*Token)(unsafe.Pointer(pId2)).Fn == uint32(0)) {
		goto __80
	}

	ii1 = 2
__81:
	if !(ii1 < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __83
	}
	pPager = Xsqlite3BtreePager(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii1)*32)).FpBt)
	Xsqlite3PagerLockingMode(tls, pPager, eMode)
	goto __82
__82:
	ii1++
	goto __81
	goto __83
__83:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FdfltLockMode = U8(eMode)
__80:
	;
	pPager = Xsqlite3BtreePager(tls, (*Db)(unsafe.Pointer(pDb)).FpBt)
	eMode = Xsqlite3PagerLockingMode(tls, pPager, eMode)
__79:
	;
	if !(eMode == PAGER_LOCKINGMODE_EXCLUSIVE) {
		goto __84
	}
	zRet = ts + 20881
__84:
	;
	returnSingleText(tls, v, zRet)
	goto __15

__21:
	if !(zRight == uintptr(0)) {
		goto __85
	}

	eMode1 = -1
	goto __86
__85:
	n = Xsqlite3Strlen30(tls, zRight)
	eMode1 = 0
__87:
	if !(libc.AssignUintptr(&zMode, Xsqlite3JournalModename(tls, eMode1)) != uintptr(0)) {
		goto __89
	}
	if !(Xsqlite3_strnicmp(tls, zRight, zMode, n) == 0) {
		goto __90
	}
	goto __89
__90:
	;
	goto __88
__88:
	eMode1++
	goto __87
	goto __89
__89:
	;
	if !!(zMode != 0) {
		goto __91
	}

	eMode1 = -1
__91:
	;
	if !(eMode1 == PAGER_JOURNALMODE_OFF && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) != uint64(0)) {
		goto __92
	}

	eMode1 = -1
__92:
	;
__86:
	;
	if !(eMode1 == -1 && (*Token)(unsafe.Pointer(pId2)).Fn == uint32(0)) {
		goto __93
	}

	iDb = 0
	(*Token)(unsafe.Pointer(pId2)).Fn = uint32(1)
__93:
	;
	ii2 = (*Sqlite3)(unsafe.Pointer(db)).FnDb - 1
__94:
	if !(ii2 >= 0) {
		goto __96
	}
	if !((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii2)*32)).FpBt != 0 && (ii2 == iDb || (*Token)(unsafe.Pointer(pId2)).Fn == uint32(0))) {
		goto __97
	}
	Xsqlite3VdbeUsesBtree(tls, v, ii2)
	Xsqlite3VdbeAddOp3(tls, v, OP_JournalMode, ii2, 1, eMode1)
__97:
	;
	goto __95
__95:
	ii2--
	goto __94
	goto __96
__96:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, 1, 1)
	goto __15

__22:
	pPager1 = Xsqlite3BtreePager(tls, (*Db)(unsafe.Pointer(pDb)).FpBt)
	*(*I64)(unsafe.Pointer(bp + 544)) = int64(-2)
	if !(zRight != 0) {
		goto __98
	}
	Xsqlite3DecOrHexToI64(tls, zRight, bp+544)
	if !(*(*I64)(unsafe.Pointer(bp + 544)) < int64(-1)) {
		goto __99
	}
	*(*I64)(unsafe.Pointer(bp + 544)) = int64(-1)
__99:
	;
__98:
	;
	*(*I64)(unsafe.Pointer(bp + 544)) = Xsqlite3PagerJournalSizeLimit(tls, pPager1, *(*I64)(unsafe.Pointer(bp + 544)))
	returnSingleInt(tls, v, *(*I64)(unsafe.Pointer(bp + 544)))
	goto __15

__23:
	pBt2 = (*Db)(unsafe.Pointer(pDb)).FpBt

	if !!(zRight != 0) {
		goto __100
	}
	returnSingleInt(tls, v, int64(Xsqlite3BtreeGetAutoVacuum(tls, pBt2)))
	goto __101
__100:
	eAuto = getAutoVacuum(tls, zRight)

	(*Sqlite3)(unsafe.Pointer(db)).FnextAutovac = int8(U8(eAuto))

	rc = Xsqlite3BtreeSetAutoVacuum(tls, pBt2, eAuto)
	if !(rc == SQLITE_OK && (eAuto == 1 || eAuto == 2)) {
		goto __102
	}
	iAddr = Xsqlite3VdbeCurrentAddr(tls, v)

	aOp1 = Xsqlite3VdbeAddOpList(tls, v, int32(uint64(unsafe.Sizeof(setMeta6))/uint64(unsafe.Sizeof(VdbeOpList{}))), uintptr(unsafe.Pointer(&setMeta6)), iLn4)
	if !(0 != 0) {
		goto __103
	}
	goto __15
__103:
	;
	(*VdbeOp)(unsafe.Pointer(aOp1)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp1 + 1*32)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp1 + 2*32)).Fp2 = iAddr + 4
	(*VdbeOp)(unsafe.Pointer(aOp1 + 4*32)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp1 + 4*32)).Fp3 = eAuto - 1
	Xsqlite3VdbeUsesBtree(tls, v, iDb)
__102:
	;
__101:
	;
	goto __15

__24:
	*(*int32)(unsafe.Pointer(bp + 552)) = 0
	if !(zRight == uintptr(0) || !(Xsqlite3GetInt32(tls, zRight, bp+552) != 0) || *(*int32)(unsafe.Pointer(bp + 552)) <= 0) {
		goto __104
	}
	*(*int32)(unsafe.Pointer(bp + 552)) = 0x7fffffff
__104:
	;
	Xsqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, *(*int32)(unsafe.Pointer(bp + 552)), 1)
	addr = Xsqlite3VdbeAddOp1(tls, v, OP_IncrVacuum, iDb)
	Xsqlite3VdbeAddOp1(tls, v, OP_ResultRow, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, 1, -1)
	Xsqlite3VdbeAddOp2(tls, v, OP_IfPos, 1, addr)
	Xsqlite3VdbeJumpHere(tls, v, addr)
	goto __15

__25:
	;
	if !!(zRight != 0) {
		goto __105
	}
	returnSingleInt(tls, v, int64((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size))
	goto __106
__105:
	size2 = Xsqlite3Atoi(tls, zRight)
	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size = size2
	Xsqlite3BtreeSetCacheSize(tls, (*Db)(unsafe.Pointer(pDb)).FpBt, (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size)
__106:
	;
	goto __15

__26:
	;
	if !!(zRight != 0) {
		goto __107
	}
	returnSingleInt(tls, v,
		func() int64 {
			if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_CacheSpill) == uint64(0) {
				return int64(0)
			}
			return int64(Xsqlite3BtreeSetSpillSize(tls, (*Db)(unsafe.Pointer(pDb)).FpBt, 0))
		}())
	goto __108
__107:
	*(*int32)(unsafe.Pointer(bp + 556)) = 1
	if !(Xsqlite3GetInt32(tls, zRight, bp+556) != 0) {
		goto __109
	}
	Xsqlite3BtreeSetSpillSize(tls, (*Db)(unsafe.Pointer(pDb)).FpBt, *(*int32)(unsafe.Pointer(bp + 556)))
__109:
	;
	if !(Xsqlite3GetBoolean(tls, zRight, uint8(libc.Bool32(*(*int32)(unsafe.Pointer(bp + 556)) != 0))) != 0) {
		goto __110
	}
	*(*U64)(unsafe.Pointer(db + 48)) |= uint64(SQLITE_CacheSpill)
	goto __111
__110:
	*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(SQLITE_CacheSpill))
__111:
	;
	setAllPagerFlags(tls, db)
__108:
	;
	goto __15

__27:
	;
	if !(zRight != 0) {
		goto __112
	}
	Xsqlite3DecOrHexToI64(tls, zRight, bp+560)
	if !(*(*Sqlite3_int64)(unsafe.Pointer(bp + 560)) < int64(0)) {
		goto __113
	}
	*(*Sqlite3_int64)(unsafe.Pointer(bp + 560)) = Xsqlite3Config.FszMmap
__113:
	;
	if !((*Token)(unsafe.Pointer(pId2)).Fn == uint32(0)) {
		goto __114
	}
	(*Sqlite3)(unsafe.Pointer(db)).FszMmap = *(*Sqlite3_int64)(unsafe.Pointer(bp + 560))
__114:
	;
	ii3 = (*Sqlite3)(unsafe.Pointer(db)).FnDb - 1
__115:
	if !(ii3 >= 0) {
		goto __117
	}
	if !((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii3)*32)).FpBt != 0 && (ii3 == iDb || (*Token)(unsafe.Pointer(pId2)).Fn == uint32(0))) {
		goto __118
	}
	Xsqlite3BtreeSetMmapLimit(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii3)*32)).FpBt, *(*Sqlite3_int64)(unsafe.Pointer(bp + 560)))
__118:
	;
	goto __116
__116:
	ii3--
	goto __115
	goto __117
__117:
	;
__112:
	;
	*(*Sqlite3_int64)(unsafe.Pointer(bp + 560)) = int64(-1)
	rc = Xsqlite3_file_control(tls, db, zDb, SQLITE_FCNTL_MMAP_SIZE, bp+560)
	if !(rc == SQLITE_OK) {
		goto __119
	}
	returnSingleInt(tls, v, *(*Sqlite3_int64)(unsafe.Pointer(bp + 560)))
	goto __120
__119:
	if !(rc != SQLITE_NOTFOUND) {
		goto __121
	}
	(*Parse)(unsafe.Pointer(pParse)).FnErr++
	(*Parse)(unsafe.Pointer(pParse)).Frc = rc
__121:
	;
__120:
	;
	goto __15

__28:
	if !!(zRight != 0) {
		goto __122
	}
	returnSingleInt(tls, v, int64((*Sqlite3)(unsafe.Pointer(db)).Ftemp_store))
	goto __123
__122:
	changeTempStorage(tls, pParse, zRight)
__123:
	;
	goto __15

__29:
	Xsqlite3_mutex_enter(tls, Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_VFS1))
	if !!(zRight != 0) {
		goto __124
	}
	returnSingleText(tls, v, Xsqlite3_temp_directory)
	goto __125
__124:
	if !(*(*uint8)(unsafe.Pointer(zRight)) != 0) {
		goto __126
	}
	rc = Xsqlite3OsAccess(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, zRight, SQLITE_ACCESS_READWRITE, bp+568)
	if !(rc != SQLITE_OK || *(*int32)(unsafe.Pointer(bp + 568)) == 0) {
		goto __127
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+21105, 0)
	Xsqlite3_mutex_leave(tls, Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_VFS1))
	goto pragma_out
__127:
	;
__126:
	;
	if !(SQLITE_TEMP_STORE == 0 ||
		SQLITE_TEMP_STORE == 1 && int32((*Sqlite3)(unsafe.Pointer(db)).Ftemp_store) <= 1 ||
		SQLITE_TEMP_STORE == 2 && int32((*Sqlite3)(unsafe.Pointer(db)).Ftemp_store) == 1) {
		goto __128
	}
	invalidateTempStorage(tls, pParse)
__128:
	;
	Xsqlite3_free(tls, Xsqlite3_temp_directory)
	if !(*(*uint8)(unsafe.Pointer(zRight)) != 0) {
		goto __129
	}
	Xsqlite3_temp_directory = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+16, zRight))
	goto __130
__129:
	Xsqlite3_temp_directory = uintptr(0)
__130:
	;
__125:
	;
	Xsqlite3_mutex_leave(tls, Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_VFS1))
	goto __15

__30:
	if !!(zRight != 0) {
		goto __131
	}
	returnSingleInt(tls, v, int64(int32((*Db)(unsafe.Pointer(pDb)).Fsafety_level)-1))
	goto __132
__131:
	if !!(int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit) != 0) {
		goto __133
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+21130, 0)
	goto __134
__133:
	if !(iDb != 1) {
		goto __135
	}
	iLevel = (int32(getSafetyLevel(tls, zRight, 0, uint8(1))) + 1) & PAGER_SYNCHRONOUS_MASK
	if !(iLevel == 0) {
		goto __136
	}
	iLevel = 1
__136:
	;
	(*Db)(unsafe.Pointer(pDb)).Fsafety_level = U8(iLevel)
	(*Db)(unsafe.Pointer(pDb)).FbSyncSet = U8(1)
	setAllPagerFlags(tls, db)
__135:
	;
__134:
	;
__132:
	;
	goto __15

__31:
	if !(zRight == uintptr(0)) {
		goto __137
	}
	setPragmaResultColumnNames(tls, v, pPragma)
	returnSingleInt(tls, v, int64(libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Fflags&(*PragmaName)(unsafe.Pointer(pPragma)).FiArg != uint64(0))))
	goto __138
__137:
	mask = (*PragmaName)(unsafe.Pointer(pPragma)).FiArg
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit) == 0) {
		goto __139
	}

	mask = mask & libc.Uint64FromInt32(libc.CplInt32(SQLITE_ForeignKeys))
__139:
	;
	if !(Xsqlite3GetBoolean(tls, zRight, uint8(0)) != 0) {
		goto __140
	}
	*(*U64)(unsafe.Pointer(db + 48)) |= mask
	goto __141
__140:
	*(*U64)(unsafe.Pointer(db + 48)) &= ^mask
	if !(mask == uint64(SQLITE_DeferFKs)) {
		goto __142
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = int64(0)
__142:
	;
	if !(mask&uint64(SQLITE_WriteSchema) != uint64(0) &&
		Xsqlite3_stricmp(tls, zRight, ts+21183) == 0) {
		goto __143
	}

	Xsqlite3ResetAllSchemasOfConnection(tls, db)
__143:
	;
__141:
	;
	Xsqlite3VdbeAddOp0(tls, v, OP_Expire)
	setAllPagerFlags(tls, db)
__138:
	;
	goto __15

__32:
	if !(zRight != 0) {
		goto __144
	}
	Xsqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
	pTab = Xsqlite3LocateTable(tls, pParse, uint32(LOCATE_NOERR), zRight, zDb)
	if !(pTab != 0) {
		goto __145
	}
	nHidden = 0
	pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 7
	Xsqlite3ViewGetColumnNames(tls, pParse, pTab)
	i = 0
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol
__146:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __148
	}
	isHidden = 0
	if !(int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_NOINSERT != 0) {
		goto __149
	}
	if !((*PragmaName)(unsafe.Pointer(pPragma)).FiArg == uint64(0)) {
		goto __150
	}
	nHidden++
	goto __147
__150:
	;
	if !(int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_VIRTUAL != 0) {
		goto __151
	}
	isHidden = 2
	goto __152
__151:
	if !(int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_STORED != 0) {
		goto __153
	}
	isHidden = 3
	goto __154
__153:
	;
	isHidden = 1
__154:
	;
__152:
	;
__149:
	;
	if !(int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_PRIMKEY == 0) {
		goto __155
	}
	k = 0
	goto __156
__155:
	if !(pPk == uintptr(0)) {
		goto __157
	}
	k = 1
	goto __158
__157:
	k = 1
__159:
	if !(k <= int32((*Table)(unsafe.Pointer(pTab)).FnCol) && int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(k-1)*2))) != i) {
		goto __161
	}
	goto __160
__160:
	k++
	goto __159
	goto __161
__161:
	;
__158:
	;
__156:
	;
	pColExpr = Xsqlite3ColumnExpr(tls, pTab, pCol)

	Xsqlite3VdbeMultiLoad(tls, v, 1, func() uintptr {
		if (*PragmaName)(unsafe.Pointer(pPragma)).FiArg != 0 {
			return ts + 21189
		}
		return ts + 21197
	}(),
		libc.VaList(bp+24, i-nHidden,
			(*Column)(unsafe.Pointer(pCol)).FzCnName,
			Xsqlite3ColumnType(tls, pCol, ts+1636),
			func() int32 {
				if uint32(int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0)) != 0 {
					return 1
				}
				return 0
			}(),
			func() uintptr {
				if isHidden >= 2 || pColExpr == uintptr(0) {
					return uintptr(0)
				}
				return *(*uintptr)(unsafe.Pointer(pColExpr + 8))
			}(),
			k,
			isHidden))
	goto __147
__147:
	i++
	pCol += 24
	goto __146
	goto __148
__148:
	;
__145:
	;
__144:
	;
	goto __15

__33:
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 6
	Xsqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
	ii4 = 0
__162:
	if !(ii4 < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __164
	}
	if !(zDb != 0 && Xsqlite3_stricmp(tls, zDb, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii4)*32)).FzDbSName) != 0) {
		goto __165
	}
	goto __163
__165:
	;
	pHash = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii4)*32)).FpSchema + 8
	initNCol = int32((*Hash)(unsafe.Pointer(pHash)).Fcount)
__166:
	if !(libc.PostDecInt32(&initNCol, 1) != 0) {
		goto __167
	}
	k1 = (*Hash)(unsafe.Pointer(pHash)).Ffirst
__168:
	if !(1 != 0) {
		goto __170
	}
	if !(k1 == uintptr(0)) {
		goto __171
	}
	initNCol = 0
	goto __170
__171:
	;
	pTab1 = (*HashElem)(unsafe.Pointer(k1)).Fdata
	if !(int32((*Table)(unsafe.Pointer(pTab1)).FnCol) == 0) {
		goto __172
	}
	zSql = Xsqlite3MPrintf(tls, db, ts+21204, libc.VaList(bp+80, (*Table)(unsafe.Pointer(pTab1)).FzName))
	if !(zSql != 0) {
		goto __173
	}
	*(*uintptr)(unsafe.Pointer(bp + 576)) = uintptr(0)
	Xsqlite3_prepare(tls, db, zSql, -1, bp+576, uintptr(0))
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 576)))
	Xsqlite3DbFree(tls, db, zSql)
__173:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __174
	}
	Xsqlite3ErrorMsg(tls, (*Sqlite3)(unsafe.Pointer(db)).FpParse, ts+1572, 0)
	(*Parse)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FpParse)).Frc = SQLITE_NOMEM
__174:
	;
	pHash = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii4)*32)).FpSchema + 8
	goto __170
__172:
	;
	goto __169
__169:
	k1 = (*HashElem)(unsafe.Pointer(k1)).Fnext
	goto __168
	goto __170
__170:
	;
	goto __166
__167:
	;
	k1 = (*Hash)(unsafe.Pointer(pHash)).Ffirst
__175:
	if !(k1 != 0) {
		goto __177
	}
	pTab2 = (*HashElem)(unsafe.Pointer(k1)).Fdata
	if !(zRight != 0 && Xsqlite3_stricmp(tls, zRight, (*Table)(unsafe.Pointer(pTab2)).FzName) != 0) {
		goto __178
	}
	goto __176
__178:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab2)).FeTabType) == TABTYP_VIEW) {
		goto __179
	}
	zType = ts + 13875
	goto __180
__179:
	if !(int32((*Table)(unsafe.Pointer(pTab2)).FeTabType) == TABTYP_VTAB) {
		goto __181
	}
	zType = ts + 16149
	goto __182
__181:
	if !((*Table)(unsafe.Pointer(pTab2)).FtabFlags&U32(TF_Shadow) != 0) {
		goto __183
	}
	zType = ts + 21220
	goto __184
__183:
	zType = ts + 9499
__184:
	;
__182:
	;
__180:
	;
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+21227,
		libc.VaList(bp+88, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(ii4)*32)).FzDbSName,
			Xsqlite3PreferredTableName(tls, (*Table)(unsafe.Pointer(pTab2)).FzName),
			zType,
			int32((*Table)(unsafe.Pointer(pTab2)).FnCol),
			libc.Bool32((*Table)(unsafe.Pointer(pTab2)).FtabFlags&U32(TF_WithoutRowid) != U32(0)),
			libc.Bool32((*Table)(unsafe.Pointer(pTab2)).FtabFlags&U32(TF_Strict) != U32(0))))
	goto __176
__176:
	k1 = (*HashElem)(unsafe.Pointer(k1)).Fnext
	goto __175
	goto __177
__177:
	;
	goto __163
__163:
	ii4++
	goto __162
	goto __164
__164:
	;
	goto __15

__34:
	if !(zRight != 0) {
		goto __185
	}
	pIdx = Xsqlite3FindIndex(tls, db, zRight, zDb)
	if !(pIdx == uintptr(0)) {
		goto __186
	}

	pTab3 = Xsqlite3LocateTable(tls, pParse, uint32(LOCATE_NOERR), zRight, zDb)
	if !(pTab3 != 0 && !((*Table)(unsafe.Pointer(pTab3)).FtabFlags&U32(TF_WithoutRowid) == U32(0))) {
		goto __187
	}
	pIdx = Xsqlite3PrimaryKeyIndex(tls, pTab3)
__187:
	;
__186:
	;
	if !(pIdx != 0) {
		goto __188
	}
	iIdxDb = Xsqlite3SchemaToIndex(tls, db, (*Index)(unsafe.Pointer(pIdx)).FpSchema)
	if !((*PragmaName)(unsafe.Pointer(pPragma)).FiArg != 0) {
		goto __189
	}

	mx = int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 6
	goto __190
__189:
	mx = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 3
__190:
	;
	pTab3 = (*Index)(unsafe.Pointer(pIdx)).FpTable
	Xsqlite3CodeVerifySchema(tls, pParse, iIdxDb)

	i1 = 0
__191:
	if !(i1 < mx) {
		goto __193
	}
	cnum = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i1)*2))
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+21234, libc.VaList(bp+136, i1, int32(cnum),
		func() uintptr {
			if int32(cnum) < 0 {
				return uintptr(0)
			}
			return (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab3)).FaCol + uintptr(cnum)*24)).FzCnName
		}()))
	if !((*PragmaName)(unsafe.Pointer(pPragma)).FiArg != 0) {
		goto __194
	}
	Xsqlite3VdbeMultiLoad(tls, v, 4, ts+21239,
		libc.VaList(bp+160, int32(*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i1)))),
			*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(i1)*8)),
			libc.Bool32(i1 < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol))))
__194:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, 1, (*Parse)(unsafe.Pointer(pParse)).FnMem)
	goto __192
__192:
	i1++
	goto __191
	goto __193
__193:
	;
__188:
	;
__185:
	;
	goto __15

__35:
	if !(zRight != 0) {
		goto __195
	}
	pTab4 = Xsqlite3FindTable(tls, db, zRight, zDb)
	if !(pTab4 != 0) {
		goto __196
	}
	iTabDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab4)).FpSchema)
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 5
	Xsqlite3CodeVerifySchema(tls, pParse, iTabDb)
	pIdx1 = (*Table)(unsafe.Pointer(pTab4)).FpIndex
	i2 = 0
__197:
	if !(pIdx1 != 0) {
		goto __199
	}
	*(*[3]uintptr)(unsafe.Pointer(bp + 584)) = [3]uintptr{ts + 21244, ts + 21246, ts + 19702}
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+21248,
		libc.VaList(bp+184, i2,
			(*Index)(unsafe.Pointer(pIdx1)).FzName,
			libc.Bool32(int32((*Index)(unsafe.Pointer(pIdx1)).FonError) != OE_None),
			*(*uintptr)(unsafe.Pointer(bp + 584 + uintptr(uint32(int32(*(*uint16)(unsafe.Pointer(pIdx1 + 100))&0x3>>0)))*8)),
			libc.Bool32((*Index)(unsafe.Pointer(pIdx1)).FpPartIdxWhere != uintptr(0))))
	goto __198
__198:
	pIdx1 = (*Index)(unsafe.Pointer(pIdx1)).FpNext
	i2++
	goto __197
	goto __199
__199:
	;
__196:
	;
__195:
	;
	goto __15

__36:
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 3
	i3 = 0
__200:
	if !(i3 < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __202
	}
	if !((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i3)*32)).FpBt == uintptr(0)) {
		goto __203
	}
	goto __201
__203:
	;
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+21254,
		libc.VaList(bp+224, i3,
			(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i3)*32)).FzDbSName,
			Xsqlite3BtreeGetFilename(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i3)*32)).FpBt)))
	goto __201
__201:
	i3++
	goto __200
	goto __202
__202:
	;
	goto __15

__37:
	i4 = 0
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 2
	p = (*Hash)(unsafe.Pointer(db + 648)).Ffirst
__204:
	if !(p != 0) {
		goto __206
	}
	pColl = (*HashElem)(unsafe.Pointer(p)).Fdata
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+21258, libc.VaList(bp+248, libc.PostIncInt32(&i4, 1), (*CollSeq)(unsafe.Pointer(pColl)).FzName))
	goto __205
__205:
	p = (*HashElem)(unsafe.Pointer(p)).Fnext
	goto __204
	goto __206
__206:
	;
	goto __15

__38:
	showInternFunc = libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_InternalFunc) != U32(0))
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 6
	i5 = 0
__207:
	if !(i5 < SQLITE_FUNC_HASH_SZ) {
		goto __209
	}
	p1 = *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&Xsqlite3BuiltinFunctions)) + uintptr(i5)*8))
__210:
	if !(p1 != 0) {
		goto __212
	}

	pragmaFunclistLine(tls, v, p1, 1, showInternFunc)
	goto __211
__211:
	p1 = *(*uintptr)(unsafe.Pointer(p1 + 64))
	goto __210
	goto __212
__212:
	;
	goto __208
__208:
	i5++
	goto __207
	goto __209
__209:
	;
	j = (*Hash)(unsafe.Pointer(db + 624)).Ffirst
__213:
	if !(j != 0) {
		goto __215
	}
	p1 = (*HashElem)(unsafe.Pointer(j)).Fdata

	pragmaFunclistLine(tls, v, p1, 0, showInternFunc)
	goto __214
__214:
	j = (*HashElem)(unsafe.Pointer(j)).Fnext
	goto __213
	goto __215
__215:
	;
	goto __15

__39:
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 1
	j1 = (*Hash)(unsafe.Pointer(db + 576)).Ffirst
__216:
	if !(j1 != 0) {
		goto __218
	}
	pMod = (*HashElem)(unsafe.Pointer(j1)).Fdata
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+10732, libc.VaList(bp+264, (*Module)(unsafe.Pointer(pMod)).FzName))
	goto __217
__217:
	j1 = (*HashElem)(unsafe.Pointer(j1)).Fnext
	goto __216
	goto __218
__218:
	;
	goto __15

__40:
	i6 = 0
__219:
	if !(i6 < int32(uint64(unsafe.Sizeof(aPragmaName))/uint64(unsafe.Sizeof(PragmaName{})))) {
		goto __221
	}
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+10732, libc.VaList(bp+272, aPragmaName[i6].FzName))
	goto __220
__220:
	i6++
	goto __219
	goto __221
__221:
	;
	goto __15

__41:
	if !(zRight != 0) {
		goto __222
	}
	pTab5 = Xsqlite3FindTable(tls, db, zRight, zDb)
	if !(pTab5 != 0 && int32((*Table)(unsafe.Pointer(pTab5)).FeTabType) == TABTYP_NORM) {
		goto __223
	}
	pFK = *(*uintptr)(unsafe.Pointer(pTab5 + 64 + 8))
	if !(pFK != 0) {
		goto __224
	}
	iTabDb1 = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab5)).FpSchema)
	i7 = 0
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 8
	Xsqlite3CodeVerifySchema(tls, pParse, iTabDb1)
__225:
	if !(pFK != 0) {
		goto __226
	}
	j2 = 0
__227:
	if !(j2 < (*FKey)(unsafe.Pointer(pFK)).FnCol) {
		goto __229
	}
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+21261,
		libc.VaList(bp+280, i7,
			j2,
			(*FKey)(unsafe.Pointer(pFK)).FzTo,
			(*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab5)).FaCol+uintptr((*sColMap)(unsafe.Pointer(pFK+64+uintptr(j2)*16)).FiFrom)*24)).FzCnName,
			(*sColMap)(unsafe.Pointer(pFK+64+uintptr(j2)*16)).FzCol,
			actionName(tls, *(*U8)(unsafe.Pointer(pFK + 45 + 1))),
			actionName(tls, *(*U8)(unsafe.Pointer(pFK + 45))),
			ts+5886))
	goto __228
__228:
	j2++
	goto __227
	goto __229
__229:
	;
	i7++
	pFK = (*FKey)(unsafe.Pointer(pFK)).FpNextFrom
	goto __225
__226:
	;
__224:
	;
__223:
	;
__222:
	;
	goto __15

__42:
	regResult = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += 4
	regRow = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	k2 = (*Hash)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema + 8)).Ffirst
__230:
	if !(k2 != 0) {
		goto __231
	}
	if !(zRight != 0) {
		goto __232
	}
	pTab6 = Xsqlite3LocateTable(tls, pParse, uint32(0), zRight, zDb)
	k2 = uintptr(0)
	goto __233
__232:
	pTab6 = (*HashElem)(unsafe.Pointer(k2)).Fdata
	k2 = (*HashElem)(unsafe.Pointer(k2)).Fnext
__233:
	;
	if !(pTab6 == uintptr(0) || !(int32((*Table)(unsafe.Pointer(pTab6)).FeTabType) == TABTYP_NORM) || *(*uintptr)(unsafe.Pointer(pTab6 + 64 + 8)) == uintptr(0)) {
		goto __234
	}
	goto __230
__234:
	;
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab6)).FpSchema)
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	Xsqlite3CodeVerifySchema(tls, pParse, iDb)
	Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab6)).Ftnum, uint8(0), (*Table)(unsafe.Pointer(pTab6)).FzName)
	if !(int32((*Table)(unsafe.Pointer(pTab6)).FnCol)+regRow > (*Parse)(unsafe.Pointer(pParse)).FnMem) {
		goto __235
	}
	(*Parse)(unsafe.Pointer(pParse)).FnMem = int32((*Table)(unsafe.Pointer(pTab6)).FnCol) + regRow
__235:
	;
	Xsqlite3OpenTable(tls, pParse, 0, iDb, pTab6, OP_OpenRead)
	Xsqlite3VdbeLoadString(tls, v, regResult, (*Table)(unsafe.Pointer(pTab6)).FzName)

	i8 = 1
	pFK1 = *(*uintptr)(unsafe.Pointer(pTab6 + 64 + 8))
__236:
	if !(pFK1 != 0) {
		goto __238
	}
	pParent = Xsqlite3FindTable(tls, db, (*FKey)(unsafe.Pointer(pFK1)).FzTo, zDb)
	if !(pParent == uintptr(0)) {
		goto __239
	}
	goto __237
__239:
	;
	*(*uintptr)(unsafe.Pointer(bp + 608)) = uintptr(0)
	Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pParent)).Ftnum, uint8(0), (*Table)(unsafe.Pointer(pParent)).FzName)
	x1 = Xsqlite3FkLocateIndex(tls, pParse, pParent, pFK1, bp+608, uintptr(0))
	if !(x1 == 0) {
		goto __240
	}
	if !(*(*uintptr)(unsafe.Pointer(bp + 608)) == uintptr(0)) {
		goto __242
	}
	Xsqlite3OpenTable(tls, pParse, i8, iDb, pParent, OP_OpenRead)
	goto __243
__242:
	Xsqlite3VdbeAddOp3(tls, v, OP_OpenRead, i8, int32((*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 608)))).Ftnum), iDb)
	Xsqlite3VdbeSetP4KeyInfo(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 608)))
__243:
	;
	goto __241
__240:
	k2 = uintptr(0)
	goto __238
__241:
	;
	goto __237
__237:
	i8++
	pFK1 = (*FKey)(unsafe.Pointer(pFK1)).FpNextFrom
	goto __236
	goto __238
__238:
	;
	if !(pFK1 != 0) {
		goto __244
	}
	goto __231
__244:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FnTab < i8) {
		goto __245
	}
	(*Parse)(unsafe.Pointer(pParse)).FnTab = i8
__245:
	;
	addrTop = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, 0)

	i8 = 1
	pFK1 = *(*uintptr)(unsafe.Pointer(pTab6 + 64 + 8))
__246:
	if !(pFK1 != 0) {
		goto __248
	}
	pParent = Xsqlite3FindTable(tls, db, (*FKey)(unsafe.Pointer(pFK1)).FzTo, zDb)
	*(*uintptr)(unsafe.Pointer(bp + 608)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 616)) = uintptr(0)
	if !(pParent != 0) {
		goto __249
	}
	x1 = Xsqlite3FkLocateIndex(tls, pParse, pParent, pFK1, bp+608, bp+616)

__249:
	;
	addrOk = Xsqlite3VdbeMakeLabel(tls, pParse)

	if !(regRow+(*FKey)(unsafe.Pointer(pFK1)).FnCol > (*Parse)(unsafe.Pointer(pParse)).FnMem) {
		goto __250
	}
	(*Parse)(unsafe.Pointer(pParse)).FnMem = regRow + (*FKey)(unsafe.Pointer(pFK1)).FnCol
__250:
	;
	j3 = 0
__251:
	if !(j3 < (*FKey)(unsafe.Pointer(pFK1)).FnCol) {
		goto __253
	}
	if *(*uintptr)(unsafe.Pointer(bp + 616)) != 0 {
		iCol = *(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 616)) + uintptr(j3)*4))
	} else {
		iCol = (*sColMap)(unsafe.Pointer(pFK1 + 64 + uintptr(j3)*16)).FiFrom
	}
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab6, 0, iCol, regRow+j3)
	Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, regRow+j3, addrOk)
	goto __252
__252:
	j3++
	goto __251
	goto __253
__253:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp + 608)) != 0) {
		goto __254
	}
	Xsqlite3VdbeAddOp4(tls, v, OP_Affinity, regRow, (*FKey)(unsafe.Pointer(pFK1)).FnCol, 0,
		Xsqlite3IndexAffinityStr(tls, db, *(*uintptr)(unsafe.Pointer(bp + 608))), (*FKey)(unsafe.Pointer(pFK1)).FnCol)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, i8, addrOk, regRow, (*FKey)(unsafe.Pointer(pFK1)).FnCol)

	goto __255
__254:
	if !(pParent != 0) {
		goto __256
	}
	jmp = Xsqlite3VdbeCurrentAddr(tls, v) + 2
	Xsqlite3VdbeAddOp3(tls, v, OP_SeekRowid, i8, jmp, regRow)
	Xsqlite3VdbeGoto(tls, v, addrOk)

__256:
	;
__255:
	;
	if !((*Table)(unsafe.Pointer(pTab6)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __257
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, 0, regResult+1)
	goto __258
__257:
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regResult+1)
__258:
	;
	Xsqlite3VdbeMultiLoad(tls, v, regResult+2, ts+21270, libc.VaList(bp+344, (*FKey)(unsafe.Pointer(pFK1)).FzTo, i8-1))
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, regResult, 4)
	Xsqlite3VdbeResolveLabel(tls, v, addrOk)
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 616)))
	goto __247
__247:
	i8++
	pFK1 = (*FKey)(unsafe.Pointer(pFK1)).FpNextFrom
	goto __246
	goto __248
__248:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, 0, addrTop+1)
	Xsqlite3VdbeJumpHere(tls, v, addrTop)
	goto __230
__231:
	;
	goto __15

__43:
	if !(zRight != 0) {
		goto __259
	}
	Xsqlite3RegisterLikeFunctions(tls, db, int32(Xsqlite3GetBoolean(tls, zRight, uint8(0))))
__259:
	;
	goto __15

__44:
	pObjTab = uintptr(0)

	isQuick = libc.Bool32(int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(zLeft))]) == 'q')

	if !((*Token)(unsafe.Pointer(pId2)).Fz == uintptr(0)) {
		goto __260
	}
	iDb = -1
__260:
	;
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 6

	*(*int32)(unsafe.Pointer(bp + 624)) = SQLITE_INTEGRITY_CHECK_ERROR_MAX
	if !(zRight != 0) {
		goto __261
	}
	if !(Xsqlite3GetInt32(tls, zRight, bp+624) != 0) {
		goto __262
	}
	if !(*(*int32)(unsafe.Pointer(bp + 624)) <= 0) {
		goto __264
	}
	*(*int32)(unsafe.Pointer(bp + 624)) = SQLITE_INTEGRITY_CHECK_ERROR_MAX
__264:
	;
	goto __263
__262:
	pObjTab = Xsqlite3LocateTable(tls, pParse, uint32(0), zRight,
		func() uintptr {
			if iDb >= 0 {
				return (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
			}
			return uintptr(0)
		}())
__263:
	;
__261:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, *(*int32)(unsafe.Pointer(bp + 624))-1, 1)

	i9 = 0
__265:
	if !(i9 < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __267
	}
	cnt = 0
	mxIdx = 0

	if !(0 != 0 && i9 == 1) {
		goto __268
	}
	goto __266
__268:
	;
	if !(iDb >= 0 && i9 != iDb) {
		goto __269
	}
	goto __266
__269:
	;
	Xsqlite3CodeVerifySchema(tls, pParse, i9)

	pTbls = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i9)*32)).FpSchema + 8
	cnt = 0
	x2 = (*Hash)(unsafe.Pointer(pTbls)).Ffirst
__270:
	if !(x2 != 0) {
		goto __272
	}
	pTab7 = (*HashElem)(unsafe.Pointer(x2)).Fdata
	if !(pObjTab != 0 && pObjTab != pTab7) {
		goto __273
	}
	goto __271
__273:
	;
	if !((*Table)(unsafe.Pointer(pTab7)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __274
	}
	cnt++
__274:
	;
	nIdx = 0
	pIdx3 = (*Table)(unsafe.Pointer(pTab7)).FpIndex
__275:
	if !(pIdx3 != 0) {
		goto __277
	}
	cnt++
	goto __276
__276:
	pIdx3 = (*Index)(unsafe.Pointer(pIdx3)).FpNext
	nIdx++
	goto __275
	goto __277
__277:
	;
	if !(nIdx > mxIdx) {
		goto __278
	}
	mxIdx = nIdx
__278:
	;
	goto __271
__271:
	x2 = (*HashElem)(unsafe.Pointer(x2)).Fnext
	goto __270
	goto __272
__272:
	;
	if !(cnt == 0) {
		goto __279
	}
	goto __266
__279:
	;
	if !(pObjTab != 0) {
		goto __280
	}
	cnt++
__280:
	;
	aRoot = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(int32(0)))*uint64(cnt+1))
	if !(aRoot == uintptr(0)) {
		goto __281
	}
	goto __267
__281:
	;
	cnt = 0
	if !(pObjTab != 0) {
		goto __282
	}
	*(*int32)(unsafe.Pointer(aRoot + uintptr(libc.PreIncInt32(&cnt, 1))*4)) = 0
__282:
	;
	x2 = (*Hash)(unsafe.Pointer(pTbls)).Ffirst
__283:
	if !(x2 != 0) {
		goto __285
	}
	pTab8 = (*HashElem)(unsafe.Pointer(x2)).Fdata
	if !(pObjTab != 0 && pObjTab != pTab8) {
		goto __286
	}
	goto __284
__286:
	;
	if !((*Table)(unsafe.Pointer(pTab8)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __287
	}
	*(*int32)(unsafe.Pointer(aRoot + uintptr(libc.PreIncInt32(&cnt, 1))*4)) = int32((*Table)(unsafe.Pointer(pTab8)).Ftnum)
__287:
	;
	pIdx4 = (*Table)(unsafe.Pointer(pTab8)).FpIndex
__288:
	if !(pIdx4 != 0) {
		goto __290
	}
	*(*int32)(unsafe.Pointer(aRoot + uintptr(libc.PreIncInt32(&cnt, 1))*4)) = int32((*Index)(unsafe.Pointer(pIdx4)).Ftnum)
	goto __289
__289:
	pIdx4 = (*Index)(unsafe.Pointer(pIdx4)).FpNext
	goto __288
	goto __290
__290:
	;
	goto __284
__284:
	x2 = (*HashElem)(unsafe.Pointer(x2)).Fnext
	goto __283
	goto __285
__285:
	;
	*(*int32)(unsafe.Pointer(aRoot)) = cnt

	(*Parse)(unsafe.Pointer(pParse)).FnMem = func() int32 {
		if (*Parse)(unsafe.Pointer(pParse)).FnMem > 8+mxIdx {
			return (*Parse)(unsafe.Pointer(pParse)).FnMem
		}
		return 8 + mxIdx
	}()
	Xsqlite3ClearTempRegCache(tls, pParse)

	Xsqlite3VdbeAddOp4(tls, v, OP_IntegrityCk, 2, cnt, 1, aRoot, -14)
	Xsqlite3VdbeChangeP5(tls, v, uint16(U8(i9)))
	addr1 = Xsqlite3VdbeAddOp1(tls, v, OP_IsNull, 2)
	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, 3, 0,
		Xsqlite3MPrintf(tls, db, ts+21274, libc.VaList(bp+360, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i9)*32)).FzDbSName)),
		-6)
	Xsqlite3VdbeAddOp3(tls, v, OP_Concat, 2, 3, 3)
	integrityCheckResultRow(tls, v)
	Xsqlite3VdbeJumpHere(tls, v, addr1)

	x2 = (*Hash)(unsafe.Pointer(pTbls)).Ffirst
__291:
	if !(x2 != 0) {
		goto __293
	}
	pTab9 = (*HashElem)(unsafe.Pointer(x2)).Fdata
	pPrior = uintptr(0)
	r1 = -1

	if !!(int32((*Table)(unsafe.Pointer(pTab9)).FeTabType) == TABTYP_NORM) {
		goto __294
	}
	goto __292
__294:
	;
	if !(pObjTab != 0 && pObjTab != pTab9) {
		goto __295
	}
	goto __292
__295:
	;
	if !(isQuick != 0 || (*Table)(unsafe.Pointer(pTab9)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __296
	}
	pPk1 = uintptr(0)
	r2 = 0
	goto __297
__296:
	pPk1 = Xsqlite3PrimaryKeyIndex(tls, pTab9)
	r2 = Xsqlite3GetTempRange(tls, pParse, int32((*Index)(unsafe.Pointer(pPk1)).FnKeyCol))
	Xsqlite3VdbeAddOp3(tls, v, OP_Null, 1, r2, r2+int32((*Index)(unsafe.Pointer(pPk1)).FnKeyCol)-1)
__297:
	;
	Xsqlite3OpenTableAndIndices(tls, pParse, pTab9, OP_OpenRead, uint8(0),
		1, uintptr(0), bp+628, bp+632)

	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, 7)
	j4 = 0
	pIdx5 = (*Table)(unsafe.Pointer(pTab9)).FpIndex
__298:
	if !(pIdx5 != 0) {
		goto __300
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, 8+j4)
	goto __299
__299:
	pIdx5 = (*Index)(unsafe.Pointer(pIdx5)).FpNext
	j4++
	goto __298
	goto __300
__300:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, *(*int32)(unsafe.Pointer(bp + 628)), 0)
	loopTop = Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, 7, 1)

	if !((*Table)(unsafe.Pointer(pTab9)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __301
	}
	mxCol = -1
	j4 = 0
__303:
	if !(j4 < int32((*Table)(unsafe.Pointer(pTab9)).FnCol)) {
		goto __305
	}
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab9)).FaCol+uintptr(j4)*24)).FcolFlags)&COLFLAG_VIRTUAL == 0) {
		goto __306
	}
	mxCol++
__306:
	;
	goto __304
__304:
	j4++
	goto __303
	goto __305
__305:
	;
	if !(mxCol == int32((*Table)(unsafe.Pointer(pTab9)).FiPKey)) {
		goto __307
	}
	mxCol--
__307:
	;
	goto __302
__301:
	mxCol = int32((*Index)(unsafe.Pointer(Xsqlite3PrimaryKeyIndex(tls, pTab9))).FnColumn) - 1
__302:
	;
	if !(mxCol >= 0) {
		goto __308
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, *(*int32)(unsafe.Pointer(bp + 628)), mxCol, 3)
	Xsqlite3VdbeTypeofColumn(tls, v, 3)
__308:
	;
	if !!(isQuick != 0) {
		goto __309
	}
	if !(pPk1 != 0) {
		goto __310
	}
	a1 = Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxGT, *(*int32)(unsafe.Pointer(bp + 628)), 0, r2, int32((*Index)(unsafe.Pointer(pPk1)).FnKeyCol))

	Xsqlite3VdbeAddOp1(tls, v, OP_IsNull, r2)
	zErr = Xsqlite3MPrintf(tls, db,
		ts+21298,
		libc.VaList(bp+368, (*Table)(unsafe.Pointer(pTab9)).FzName))
	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, 3, 0, zErr, -6)
	integrityCheckResultRow(tls, v)
	Xsqlite3VdbeJumpHere(tls, v, a1)
	Xsqlite3VdbeJumpHere(tls, v, a1+1)
	j4 = 0
__311:
	if !(j4 < int32((*Index)(unsafe.Pointer(pPk1)).FnKeyCol)) {
		goto __313
	}
	Xsqlite3ExprCodeLoadIndexColumn(tls, pParse, pPk1, *(*int32)(unsafe.Pointer(bp + 628)), j4, r2+j4)
	goto __312
__312:
	j4++
	goto __311
	goto __313
__313:
	;
__310:
	;
__309:
	;
	bStrict = libc.Bool32((*Table)(unsafe.Pointer(pTab9)).FtabFlags&U32(TF_Strict) != U32(0))
	j4 = 0
__314:
	if !(j4 < int32((*Table)(unsafe.Pointer(pTab9)).FnCol)) {
		goto __316
	}
	pCol1 = (*Table)(unsafe.Pointer(pTab9)).FaCol + uintptr(j4)*24

	if !(j4 == int32((*Table)(unsafe.Pointer(pTab9)).FiPKey)) {
		goto __317
	}
	goto __315
__317:
	;
	if !(bStrict != 0) {
		goto __318
	}
	doTypeCheck = libc.Bool32(int32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf0>>4) > COLTYPE_ANY)
	goto __319
__318:
	doTypeCheck = libc.Bool32(int32((*Column)(unsafe.Pointer(pCol1)).Faffinity) > SQLITE_AFF_BLOB)
__319:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf>>0) == 0 && !(doTypeCheck != 0)) {
		goto __320
	}
	goto __315
__320:
	;
	p4 = SQLITE_NULL
	if !(int32((*Column)(unsafe.Pointer(pCol1)).FcolFlags)&COLFLAG_VIRTUAL != 0) {
		goto __321
	}
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab9, *(*int32)(unsafe.Pointer(bp + 628)), j4, 3)
	p11 = -1
	p3 = 3
	goto __322
__321:
	if !((*Column)(unsafe.Pointer(pCol1)).FiDflt != 0) {
		goto __323
	}
	*(*uintptr)(unsafe.Pointer(bp + 640)) = uintptr(0)
	Xsqlite3ValueFromExpr(tls, db, Xsqlite3ColumnExpr(tls, pTab9, pCol1), (*Sqlite3)(unsafe.Pointer(db)).Fenc,
		(*Column)(unsafe.Pointer(pCol1)).Faffinity, bp+640)
	if !(*(*uintptr)(unsafe.Pointer(bp + 640)) != 0) {
		goto __324
	}
	p4 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp + 640)))
	Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp + 640)))
__324:
	;
__323:
	;
	p11 = *(*int32)(unsafe.Pointer(bp + 628))
	if !!((*Table)(unsafe.Pointer(pTab9)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __325
	}

	p3 = int32(Xsqlite3TableColumnToIndex(tls, Xsqlite3PrimaryKeyIndex(tls, pTab9), int16(j4)))
	goto __326
__325:
	p3 = int32(Xsqlite3TableColumnToStorage(tls, pTab9, int16(j4)))

__326:
	;
__322:
	;
	labelError = Xsqlite3VdbeMakeLabel(tls, pParse)
	labelOk = Xsqlite3VdbeMakeLabel(tls, pParse)
	if !(uint32(int32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf>>0)) != 0) {
		goto __327
	}

	jmp2 = Xsqlite3VdbeAddOp4Int(tls, v, OP_IsType, p11, labelOk, p3, p4)
	Xsqlite3VdbeChangeP5(tls, v, uint16(0x0f))

	zErr1 = Xsqlite3MPrintf(tls, db, ts+21334, libc.VaList(bp+376, (*Table)(unsafe.Pointer(pTab9)).FzName,
		(*Column)(unsafe.Pointer(pCol1)).FzCnName))
	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, 3, 0, zErr1, -6)
	if !(doTypeCheck != 0) {
		goto __328
	}
	Xsqlite3VdbeGoto(tls, v, labelError)
	Xsqlite3VdbeJumpHere(tls, v, jmp2)
	goto __329
__328:
	;
__329:
	;
__327:
	;
	if !(bStrict != 0 && doTypeCheck != 0) {
		goto __330
	}
	Xsqlite3VdbeAddOp4Int(tls, v, OP_IsType, p11, labelOk, p3, p4)

	Xsqlite3VdbeChangeP5(tls, v, uint16(aStdTypeMask[(int32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf0>>4)-1)&0xf<<28>>28]))

	zErr1 = Xsqlite3MPrintf(tls, db, ts+21354,
		libc.VaList(bp+392, Xsqlite3StdType[(int32(*(*uint8)(unsafe.Pointer(pCol1 + 8))&0xf0>>4)-1)&0xf<<28>>28],
			(*Table)(unsafe.Pointer(pTab9)).FzName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab9)).FaCol+uintptr(j4)*24)).FzCnName))
	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, 3, 0, zErr1, -6)
	goto __331
__330:
	if !(!(bStrict != 0) && int32((*Column)(unsafe.Pointer(pCol1)).Faffinity) == SQLITE_AFF_TEXT) {
		goto __332
	}

	Xsqlite3VdbeAddOp4Int(tls, v, OP_IsType, p11, labelOk, p3, p4)
	Xsqlite3VdbeChangeP5(tls, v, uint16(0x1c))

	zErr1 = Xsqlite3MPrintf(tls, db, ts+21376,
		libc.VaList(bp+416, (*Table)(unsafe.Pointer(pTab9)).FzName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab9)).FaCol+uintptr(j4)*24)).FzCnName))
	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, 3, 0, zErr1, -6)
	goto __333
__332:
	if !(!(bStrict != 0) && int32((*Column)(unsafe.Pointer(pCol1)).Faffinity) >= SQLITE_AFF_NUMERIC) {
		goto __334
	}

	Xsqlite3VdbeAddOp4Int(tls, v, OP_IsType, p11, labelOk, p3, p4)
	Xsqlite3VdbeChangeP5(tls, v, uint16(0x1b))

	if !(p11 >= 0) {
		goto __335
	}
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab9, *(*int32)(unsafe.Pointer(bp + 628)), j4, 3)
__335:
	;
	Xsqlite3VdbeAddOp4(tls, v, OP_Affinity, 3, 1, 0, ts+21399, -1)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_IsType, -1, labelOk, 3, p4)
	Xsqlite3VdbeChangeP5(tls, v, uint16(0x1c))

	zErr1 = Xsqlite3MPrintf(tls, db, ts+21401,
		libc.VaList(bp+432, (*Table)(unsafe.Pointer(pTab9)).FzName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab9)).FaCol+uintptr(j4)*24)).FzCnName))
	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, 3, 0, zErr1, -6)
__334:
	;
__333:
	;
__331:
	;
	Xsqlite3VdbeResolveLabel(tls, v, labelError)
	integrityCheckResultRow(tls, v)
	Xsqlite3VdbeResolveLabel(tls, v, labelOk)
	goto __315
__315:
	j4++
	goto __314
	goto __316
__316:
	;
	if !((*Table)(unsafe.Pointer(pTab9)).FpCheck != 0 && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_IgnoreChecks) == uint64(0)) {
		goto __336
	}
	pCheck = Xsqlite3ExprListDup(tls, db, (*Table)(unsafe.Pointer(pTab9)).FpCheck, 0)
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0) {
		goto __337
	}
	addrCkFault = Xsqlite3VdbeMakeLabel(tls, pParse)
	addrCkOk = Xsqlite3VdbeMakeLabel(tls, pParse)
	(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = *(*int32)(unsafe.Pointer(bp + 628)) + 1
	k3 = (*ExprList)(unsafe.Pointer(pCheck)).FnExpr - 1
__338:
	if !(k3 > 0) {
		goto __340
	}
	Xsqlite3ExprIfFalse(tls, pParse, (*ExprList_item)(unsafe.Pointer(pCheck+8+uintptr(k3)*32)).FpExpr, addrCkFault, 0)
	goto __339
__339:
	k3--
	goto __338
	goto __340
__340:
	;
	Xsqlite3ExprIfTrue(tls, pParse, (*ExprList_item)(unsafe.Pointer(pCheck+8)).FpExpr, addrCkOk,
		SQLITE_JUMPIFNULL)
	Xsqlite3VdbeResolveLabel(tls, v, addrCkFault)
	(*Parse)(unsafe.Pointer(pParse)).FiSelfTab = 0
	zErr2 = Xsqlite3MPrintf(tls, db, ts+21421,
		libc.VaList(bp+448, (*Table)(unsafe.Pointer(pTab9)).FzName))
	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, 3, 0, zErr2, -6)
	integrityCheckResultRow(tls, v)
	Xsqlite3VdbeResolveLabel(tls, v, addrCkOk)
__337:
	;
	Xsqlite3ExprListDelete(tls, db, pCheck)
__336:
	;
	if !!(isQuick != 0) {
		goto __341
	}

	j4 = 0
	pIdx5 = (*Table)(unsafe.Pointer(pTab9)).FpIndex
__342:
	if !(pIdx5 != 0) {
		goto __344
	}
	ckUniq = Xsqlite3VdbeMakeLabel(tls, pParse)
	if !(pPk1 == pIdx5) {
		goto __345
	}
	goto __343
__345:
	;
	r1 = Xsqlite3GenerateIndexKey(tls, pParse, pIdx5, *(*int32)(unsafe.Pointer(bp + 628)), 0, 0, bp+648,
		pPrior, r1)
	pPrior = pIdx5
	Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, 8+j4, 1)

	jmp21 = Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, *(*int32)(unsafe.Pointer(bp + 632))+j4, ckUniq, r1,
		int32((*Index)(unsafe.Pointer(pIdx5)).FnColumn))
	Xsqlite3VdbeLoadString(tls, v, 3, ts+21451)
	Xsqlite3VdbeAddOp3(tls, v, OP_Concat, 7, 3, 3)
	Xsqlite3VdbeLoadString(tls, v, 4, ts+21456)
	Xsqlite3VdbeAddOp3(tls, v, OP_Concat, 4, 3, 3)
	jmp5 = Xsqlite3VdbeLoadString(tls, v, 4, (*Index)(unsafe.Pointer(pIdx5)).FzName)
	Xsqlite3VdbeAddOp3(tls, v, OP_Concat, 4, 3, 3)
	jmp4 = integrityCheckResultRow(tls, v)
	Xsqlite3VdbeJumpHere(tls, v, jmp21)

	if !((*Table)(unsafe.Pointer(pTab9)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __346
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_IdxRowid, *(*int32)(unsafe.Pointer(bp + 632))+j4, 3)
	jmp7 = Xsqlite3VdbeAddOp3(tls, v, OP_Eq, 3, 0, r1+int32((*Index)(unsafe.Pointer(pIdx5)).FnColumn)-1)

	Xsqlite3VdbeLoadString(tls, v, 3,
		ts+21477)
	Xsqlite3VdbeAddOp3(tls, v, OP_Concat, 7, 3, 3)
	Xsqlite3VdbeLoadString(tls, v, 4, ts+21513)
	Xsqlite3VdbeGoto(tls, v, jmp5-1)
	Xsqlite3VdbeJumpHere(tls, v, jmp7)
__346:
	;
	label6 = 0
	kk = 0
__347:
	if !(kk < int32((*Index)(unsafe.Pointer(pIdx5)).FnKeyCol)) {
		goto __349
	}
	if !(*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx5)).FazColl + uintptr(kk)*8)) == uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))) {
		goto __350
	}
	goto __348
__350:
	;
	if !(label6 == 0) {
		goto __351
	}
	label6 = Xsqlite3VdbeMakeLabel(tls, pParse)
__351:
	;
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, *(*int32)(unsafe.Pointer(bp + 632))+j4, kk, 3)
	Xsqlite3VdbeAddOp3(tls, v, OP_Ne, 3, label6, r1+kk)
	goto __348
__348:
	kk++
	goto __347
	goto __349
__349:
	;
	if !(label6 != 0) {
		goto __352
	}
	jmp6 = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
	Xsqlite3VdbeResolveLabel(tls, v, label6)
	Xsqlite3VdbeLoadString(tls, v, 3, ts+21451)
	Xsqlite3VdbeAddOp3(tls, v, OP_Concat, 7, 3, 3)
	Xsqlite3VdbeLoadString(tls, v, 4, ts+21524)
	Xsqlite3VdbeGoto(tls, v, jmp5-1)
	Xsqlite3VdbeJumpHere(tls, v, jmp6)
__352:
	;
	if !(int32((*Index)(unsafe.Pointer(pIdx5)).FonError) != OE_None) {
		goto __353
	}
	uniqOk = Xsqlite3VdbeMakeLabel(tls, pParse)
	kk = 0
__354:
	if !(kk < int32((*Index)(unsafe.Pointer(pIdx5)).FnKeyCol)) {
		goto __356
	}
	iCol1 = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx5)).FaiColumn + uintptr(kk)*2)))

	if !(iCol1 >= 0 && uint32(int32(*(*uint8)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab9)).FaCol + uintptr(iCol1)*24 + 8))&0xf>>0)) != 0) {
		goto __357
	}
	goto __355
__357:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, r1+kk, uniqOk)

	goto __355
__355:
	kk++
	goto __354
	goto __356
__356:
	;
	jmp61 = Xsqlite3VdbeAddOp1(tls, v, OP_Next, *(*int32)(unsafe.Pointer(bp + 632))+j4)
	Xsqlite3VdbeGoto(tls, v, uniqOk)
	Xsqlite3VdbeJumpHere(tls, v, jmp61)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxGT, *(*int32)(unsafe.Pointer(bp + 632))+j4, uniqOk, r1,
		int32((*Index)(unsafe.Pointer(pIdx5)).FnKeyCol))
	Xsqlite3VdbeLoadString(tls, v, 3, ts+21551)
	Xsqlite3VdbeGoto(tls, v, jmp5)
	Xsqlite3VdbeResolveLabel(tls, v, uniqOk)
__353:
	;
	Xsqlite3VdbeJumpHere(tls, v, jmp4)
	Xsqlite3ResolvePartIdxLabel(tls, pParse, *(*int32)(unsafe.Pointer(bp + 648)))
	goto __343
__343:
	pIdx5 = (*Index)(unsafe.Pointer(pIdx5)).FpNext
	j4++
	goto __342
	goto __344
__344:
	;
__341:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, *(*int32)(unsafe.Pointer(bp + 628)), loopTop)
	Xsqlite3VdbeJumpHere(tls, v, loopTop-1)
	if !!(isQuick != 0) {
		goto __358
	}
	Xsqlite3VdbeLoadString(tls, v, 2, ts+21578)
	j4 = 0
	pIdx5 = (*Table)(unsafe.Pointer(pTab9)).FpIndex
__359:
	if !(pIdx5 != 0) {
		goto __361
	}
	if !(pPk1 == pIdx5) {
		goto __362
	}
	goto __360
__362:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Count, *(*int32)(unsafe.Pointer(bp + 632))+j4, 3)
	addr1 = Xsqlite3VdbeAddOp3(tls, v, OP_Eq, 8+j4, 0, 3)
	Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NOTNULL))
	Xsqlite3VdbeLoadString(tls, v, 4, (*Index)(unsafe.Pointer(pIdx5)).FzName)
	Xsqlite3VdbeAddOp3(tls, v, OP_Concat, 4, 2, 3)
	integrityCheckResultRow(tls, v)
	Xsqlite3VdbeJumpHere(tls, v, addr1)
	goto __360
__360:
	pIdx5 = (*Index)(unsafe.Pointer(pIdx5)).FpNext
	j4++
	goto __359
	goto __361
__361:
	;
	if !(pPk1 != 0) {
		goto __363
	}
	Xsqlite3ReleaseTempRange(tls, pParse, r2, int32((*Index)(unsafe.Pointer(pPk1)).FnKeyCol))
__363:
	;
__358:
	;
	goto __292
__292:
	x2 = (*HashElem)(unsafe.Pointer(x2)).Fnext
	goto __291
	goto __293
__293:
	;
	goto __266
__266:
	i9++
	goto __265
	goto __267
__267:
	;
	aOp2 = Xsqlite3VdbeAddOpList(tls, v, int32(uint64(unsafe.Sizeof(endCode))/uint64(unsafe.Sizeof(VdbeOpList{}))), uintptr(unsafe.Pointer(&endCode)), iLn5)
	if !(aOp2 != 0) {
		goto __364
	}
	(*VdbeOp)(unsafe.Pointer(aOp2)).Fp2 = 1 - *(*int32)(unsafe.Pointer(bp + 624))
	(*VdbeOp)(unsafe.Pointer(aOp2 + 2*32)).Fp4type = int8(-1)
	*(*uintptr)(unsafe.Pointer(aOp2 + 2*32 + 16)) = ts + 6208
	(*VdbeOp)(unsafe.Pointer(aOp2 + 5*32)).Fp4type = int8(-1)
	*(*uintptr)(unsafe.Pointer(aOp2 + 5*32 + 16)) = Xsqlite3ErrStr(tls, SQLITE_CORRUPT)
__364:
	;
	Xsqlite3VdbeChangeP3(tls, v, 0, Xsqlite3VdbeCurrentAddr(tls, v)-2)

	goto __15

__45:
	if !!(zRight != 0) {
		goto __365
	}
	if !(Xsqlite3ReadSchema(tls, pParse) != 0) {
		goto __367
	}
	goto pragma_out
__367:
	;
	returnSingleText(tls, v, encnames1[(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fenc].FzName)
	goto __366
__365:
	if !((*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_EncodingFixed) == U32(0)) {
		goto __368
	}
	pEnc = uintptr(unsafe.Pointer(&encnames1))
__369:
	if !((*EncName)(unsafe.Pointer(pEnc)).FzName != 0) {
		goto __371
	}
	if !(0 == Xsqlite3StrICmp(tls, zRight, (*EncName)(unsafe.Pointer(pEnc)).FzName)) {
		goto __372
	}
	if (*EncName)(unsafe.Pointer(pEnc)).Fenc != 0 {
		enc = (*EncName)(unsafe.Pointer(pEnc)).Fenc
	} else {
		enc = uint8(SQLITE_UTF16LE)
	}
	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema)).Fenc = enc
	Xsqlite3SetTextEncoding(tls, db, enc)
	goto __371
__372:
	;
	goto __370
__370:
	pEnc += 16
	goto __369
	goto __371
__371:
	;
	if !!(int32((*EncName)(unsafe.Pointer(pEnc)).FzName) != 0) {
		goto __373
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+21607, libc.VaList(bp+456, zRight))
__373:
	;
__368:
	;
__366:
	;
	goto __15

__46:
	iCookie = int32((*PragmaName)(unsafe.Pointer(pPragma)).FiArg)
	Xsqlite3VdbeUsesBtree(tls, v, iDb)
	if !(zRight != 0 && int32((*PragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&PragFlg_ReadOnly == 0) {
		goto __374
	}

	aOp3 = Xsqlite3VdbeAddOpList(tls, v, int32(uint64(unsafe.Sizeof(setCookie))/uint64(unsafe.Sizeof(VdbeOpList{}))), uintptr(unsafe.Pointer(&setCookie)), 0)
	if !(0 != 0) {
		goto __376
	}
	goto __15
__376:
	;
	(*VdbeOp)(unsafe.Pointer(aOp3)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp3 + 1*32)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp3 + 1*32)).Fp2 = iCookie
	(*VdbeOp)(unsafe.Pointer(aOp3 + 1*32)).Fp3 = Xsqlite3Atoi(tls, zRight)
	(*VdbeOp)(unsafe.Pointer(aOp3 + 1*32)).Fp5 = U16(1)
	if !(iCookie == BTREE_SCHEMA_VERSION && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_Defensive) != uint64(0)) {
		goto __377
	}

	(*VdbeOp)(unsafe.Pointer(aOp3 + 1*32)).Fopcode = U8(OP_Noop)
__377:
	;
	goto __375
__374:
	;
	aOp4 = Xsqlite3VdbeAddOpList(tls, v, int32(uint64(unsafe.Sizeof(readCookie))/uint64(unsafe.Sizeof(VdbeOpList{}))), uintptr(unsafe.Pointer(&readCookie)), 0)
	if !(0 != 0) {
		goto __378
	}
	goto __15
__378:
	;
	(*VdbeOp)(unsafe.Pointer(aOp4)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp4 + 1*32)).Fp1 = iDb
	(*VdbeOp)(unsafe.Pointer(aOp4 + 1*32)).Fp3 = iCookie
	Xsqlite3VdbeReusable(tls, v)
__375:
	;
	goto __15

__47:
	i10 = 0
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 1
__379:
	if !(libc.AssignUintptr(&zOpt, Xsqlite3_compileoption_get(tls, libc.PostIncInt32(&i10, 1))) != uintptr(0)) {
		goto __380
	}
	Xsqlite3VdbeLoadString(tls, v, 1, zOpt)
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, 1, 1)
	goto __379
__380:
	;
	Xsqlite3VdbeReusable(tls, v)

	goto __15

__48:
	iBt = func() int32 {
		if (*Token)(unsafe.Pointer(pId2)).Fz != 0 {
			return iDb
		}
		return SQLITE_MAX_ATTACHED + 2
	}()
	eMode2 = SQLITE_CHECKPOINT_PASSIVE
	if !(zRight != 0) {
		goto __381
	}
	if !(Xsqlite3StrICmp(tls, zRight, ts+20898) == 0) {
		goto __382
	}
	eMode2 = SQLITE_CHECKPOINT_FULL
	goto __383
__382:
	if !(Xsqlite3StrICmp(tls, zRight, ts+21632) == 0) {
		goto __384
	}
	eMode2 = SQLITE_CHECKPOINT_RESTART
	goto __385
__384:
	if !(Xsqlite3StrICmp(tls, zRight, ts+21051) == 0) {
		goto __386
	}
	eMode2 = SQLITE_CHECKPOINT_TRUNCATE
__386:
	;
__385:
	;
__383:
	;
__381:
	;
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 3
	Xsqlite3VdbeAddOp3(tls, v, OP_Checkpoint, iBt, eMode2, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, 1, 3)

	goto __15

__49:
	if !(zRight != 0) {
		goto __387
	}
	Xsqlite3_wal_autocheckpoint(tls, db, Xsqlite3Atoi(tls, zRight))
__387:
	;
	returnSingleInt(tls, v,
		func() int64 {
			if (*Sqlite3)(unsafe.Pointer(db)).FxWalCallback == *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr, int32) int32
			}{Xsqlite3WalDefaultHook})) {
				return int64(int32((*Sqlite3)(unsafe.Pointer(db)).FpWalArg))
			}
			return int64(0)
		}())

	goto __15

__50:
	Xsqlite3_db_release_memory(tls, db)
	goto __15

__51:
	if !(zRight != 0) {
		goto __388
	}
	opMask = U32(Xsqlite3Atoi(tls, zRight))
	if !(opMask&U32(0x02) == U32(0)) {
		goto __390
	}
	goto __15
__390:
	;
	goto __389
__388:
	opMask = U32(0xfffe)
__389:
	;
	iTabCur = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	iDbLast = func() int32 {
		if zDb != 0 {
			return iDb
		}
		return (*Sqlite3)(unsafe.Pointer(db)).FnDb - 1
	}()
__391:
	if !(iDb <= iDbLast) {
		goto __393
	}
	if !(iDb == 1) {
		goto __394
	}
	goto __392
__394:
	;
	Xsqlite3CodeVerifySchema(tls, pParse, iDb)
	pSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
	k4 = (*Hash)(unsafe.Pointer(pSchema + 8)).Ffirst
__395:
	if !(k4 != 0) {
		goto __397
	}
	pTab10 = (*HashElem)(unsafe.Pointer(k4)).Fdata

	if !((*Table)(unsafe.Pointer(pTab10)).FtabFlags&U32(TF_StatsUsed) == U32(0)) {
		goto __398
	}
	goto __396
__398:
	;
	szThreshold = LogEst(int32((*Table)(unsafe.Pointer(pTab10)).FnRowLogEst) + 46)
	pIdx6 = (*Table)(unsafe.Pointer(pTab10)).FpIndex
__399:
	if !(pIdx6 != 0) {
		goto __401
	}
	if !!(int32(*(*uint16)(unsafe.Pointer(pIdx6 + 100))&0x80>>7) != 0) {
		goto __402
	}
	szThreshold = int16(0)
	goto __401
__402:
	;
	goto __400
__400:
	pIdx6 = (*Index)(unsafe.Pointer(pIdx6)).FpNext
	goto __399
	goto __401
__401:
	;
	if !(szThreshold != 0) {
		goto __403
	}
	Xsqlite3OpenTable(tls, pParse, iTabCur, iDb, pTab10, OP_OpenRead)
	Xsqlite3VdbeAddOp3(tls, v, OP_IfSmaller, iTabCur,
		int32(U32(Xsqlite3VdbeCurrentAddr(tls, v)+2)+opMask&U32(1)), int32(szThreshold))

__403:
	;
	zSubSql = Xsqlite3MPrintf(tls, db, ts+21640,
		libc.VaList(bp+464, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName, (*Table)(unsafe.Pointer(pTab10)).FzName))
	if !(opMask&U32(0x01) != 0) {
		goto __404
	}
	r11 = Xsqlite3GetTempReg(tls, pParse)
	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, r11, 0, zSubSql, -6)
	Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, r11, 1)
	goto __405
__404:
	Xsqlite3VdbeAddOp4(tls, v, OP_SqlExec, 0, 0, 0, zSubSql, -6)
__405:
	;
	goto __396
__396:
	k4 = (*HashElem)(unsafe.Pointer(k4)).Fnext
	goto __395
	goto __397
__397:
	;
	goto __392
__392:
	iDb++
	goto __391
	goto __393
__393:
	;
	Xsqlite3VdbeAddOp0(tls, v, OP_Expire)
	goto __15

__52:
	;
	if !(zRight != 0) {
		goto __406
	}
	Xsqlite3_busy_timeout(tls, db, Xsqlite3Atoi(tls, zRight))
__406:
	;
	returnSingleInt(tls, v, int64((*Sqlite3)(unsafe.Pointer(db)).FbusyTimeout))
	goto __15

__53:
	if !(zRight != 0 && Xsqlite3DecOrHexToI64(tls, zRight, bp+656) == SQLITE_OK) {
		goto __407
	}
	Xsqlite3_soft_heap_limit64(tls, *(*Sqlite3_int64)(unsafe.Pointer(bp + 656)))
__407:
	;
	returnSingleInt(tls, v, Xsqlite3_soft_heap_limit64(tls, int64(-1)))
	goto __15

__54:
	if !(zRight != 0 && Xsqlite3DecOrHexToI64(tls, zRight, bp+664) == SQLITE_OK) {
		goto __408
	}
	iPrior = Xsqlite3_hard_heap_limit64(tls, int64(-1))
	if !(*(*Sqlite3_int64)(unsafe.Pointer(bp + 664)) > int64(0) && (iPrior == int64(0) || iPrior > *(*Sqlite3_int64)(unsafe.Pointer(bp + 664)))) {
		goto __409
	}
	Xsqlite3_hard_heap_limit64(tls, *(*Sqlite3_int64)(unsafe.Pointer(bp + 664)))
__409:
	;
__408:
	;
	returnSingleInt(tls, v, Xsqlite3_hard_heap_limit64(tls, int64(-1)))
	goto __15

__55:
	if !(zRight != 0 &&
		Xsqlite3DecOrHexToI64(tls, zRight, bp+672) == SQLITE_OK &&
		*(*Sqlite3_int64)(unsafe.Pointer(bp + 672)) >= int64(0)) {
		goto __410
	}
	Xsqlite3_limit(tls, db, SQLITE_LIMIT_WORKER_THREADS, int32(*(*Sqlite3_int64)(unsafe.Pointer(bp + 672))&int64(0x7fffffff)))
__410:
	;
	returnSingleInt(tls, v, int64(Xsqlite3_limit(tls, db, SQLITE_LIMIT_WORKER_THREADS, -1)))
	goto __15

__56:
	if !(zRight != 0 &&
		Xsqlite3DecOrHexToI64(tls, zRight, bp+680) == SQLITE_OK &&
		*(*Sqlite3_int64)(unsafe.Pointer(bp + 680)) >= int64(0)) {
		goto __411
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnAnalysisLimit = int32(*(*Sqlite3_int64)(unsafe.Pointer(bp + 680)) & int64(0x7fffffff))
__411:
	;
	returnSingleInt(tls, v, int64((*Sqlite3)(unsafe.Pointer(db)).FnAnalysisLimit))
	goto __15

__57:
	(*Parse)(unsafe.Pointer(pParse)).FnMem = 2
	i11 = 0
__412:
	if !(i11 < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __414
	}
	zState = ts + 21658
	if !((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i11)*32)).FzDbSName == uintptr(0)) {
		goto __415
	}
	goto __413
__415:
	;
	pBt3 = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i11)*32)).FpBt
	if !(pBt3 == uintptr(0) || Xsqlite3BtreePager(tls, pBt3) == uintptr(0)) {
		goto __416
	}
	zState = ts + 21666
	goto __417
__416:
	if !(Xsqlite3_file_control(tls, db, func() uintptr {
		if i11 != 0 {
			return (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i11)*32)).FzDbSName
		}
		return uintptr(0)
	}(),
		SQLITE_FCNTL_LOCKSTATE, bp+688) == SQLITE_OK) {
		goto __418
	}
	zState = azLockName[*(*int32)(unsafe.Pointer(bp + 688))]
__418:
	;
__417:
	;
	Xsqlite3VdbeMultiLoad(tls, v, 1, ts+21673, libc.VaList(bp+480, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i11)*32)).FzDbSName, zState))
	goto __413
__413:
	i11++
	goto __412
	goto __414
__414:
	;
	goto __15

__15:
	;
	if !(int32((*PragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&PragFlg_NoColumns1 != 0 && zRight != 0) {
		goto __419
	}

__419:
	;
pragma_out:
	Xsqlite3DbFree(tls, db, zLeft)
	Xsqlite3DbFree(tls, db, zRight)
}

type EncName = struct {
	FzName       uintptr
	Fenc         U8
	F__ccgo_pad1 [7]byte
}

var iLn3 int32 = 0
var getCacheSize = [9]VdbeOpList{
	{Fopcode: U8(OP_Transaction)},
	{Fopcode: U8(OP_ReadCookie), Fp2: int8(1), Fp3: int8(BTREE_DEFAULT_CACHE_SIZE)},
	{Fopcode: U8(OP_IfPos), Fp1: int8(1), Fp2: int8(8)},
	{Fopcode: U8(OP_Integer), Fp2: int8(2)},
	{Fopcode: U8(OP_Subtract), Fp1: int8(1), Fp2: int8(2), Fp3: int8(1)},
	{Fopcode: U8(OP_IfPos), Fp1: int8(1), Fp2: int8(8)},
	{Fopcode: U8(OP_Integer), Fp2: int8(1)},
	{Fopcode: U8(OP_Noop)},
	{Fopcode: U8(OP_ResultRow), Fp1: int8(1), Fp2: int8(1)},
}
var iLn4 int32 = 0
var setMeta6 = [5]VdbeOpList{
	{Fopcode: U8(OP_Transaction), Fp2: int8(1)},
	{Fopcode: U8(OP_ReadCookie), Fp2: int8(1), Fp3: int8(BTREE_LARGEST_ROOT_PAGE)},
	{Fopcode: U8(OP_If), Fp1: int8(1)},
	{Fopcode: U8(OP_Halt), Fp2: int8(OE_Abort)},
	{Fopcode: U8(OP_SetCookie), Fp2: int8(BTREE_INCR_VACUUM)},
}
var aStdTypeMask = [6]uint8{
	uint8(0x1f),
	uint8(0x18),
	uint8(0x11),
	uint8(0x11),
	uint8(0x13),
	uint8(0x14),
}
var iLn5 int32 = 0
var endCode = [7]VdbeOpList{
	{Fopcode: U8(OP_AddImm), Fp1: int8(1)},
	{Fopcode: U8(OP_IfNotZero), Fp1: int8(1), Fp2: int8(4)},
	{Fopcode: U8(OP_String8), Fp2: int8(3)},
	{Fopcode: U8(OP_ResultRow), Fp1: int8(3), Fp2: int8(1)},
	{Fopcode: U8(OP_Halt)},
	{Fopcode: U8(OP_String8), Fp2: int8(3)},
	{Fopcode: U8(OP_Goto), Fp2: int8(3)},
}
var encnames1 = [9]EncName{
	{FzName: ts + 21676, Fenc: U8(SQLITE_UTF8)},
	{FzName: ts + 21681, Fenc: U8(SQLITE_UTF8)},
	{FzName: ts + 21687, Fenc: U8(SQLITE_UTF16LE)},
	{FzName: ts + 21696, Fenc: U8(SQLITE_UTF16BE)},
	{FzName: ts + 21705, Fenc: U8(SQLITE_UTF16LE)},
	{FzName: ts + 21713, Fenc: U8(SQLITE_UTF16BE)},
	{FzName: ts + 21721},
	{FzName: ts + 21728},
	{},
}
var setCookie = [2]VdbeOpList{
	{Fopcode: U8(OP_Transaction), Fp2: int8(1)},
	{Fopcode: U8(OP_SetCookie)},
}
var readCookie = [3]VdbeOpList{
	{Fopcode: U8(OP_Transaction)},
	{Fopcode: U8(OP_ReadCookie), Fp2: int8(1)},
	{Fopcode: U8(OP_ResultRow), Fp1: int8(1), Fp2: int8(1)},
}
var azLockName = [5]uintptr{
	ts + 21734, ts + 21743, ts + 21750, ts + 21759, ts + 20881,
}

type PragmaVtab1 = struct {
	Fbase        Sqlite3_vtab
	Fdb          uintptr
	FpName       uintptr
	FnHidden     U8
	FiHidden     U8
	F__ccgo_pad1 [6]byte
}

type PragmaVtab = PragmaVtab1
type PragmaVtabCursor1 = struct {
	Fbase    Sqlite3_vtab_cursor
	FpPragma uintptr
	FiRowid  Sqlite_int64
	FazArg   [2]uintptr
}

type PragmaVtabCursor = PragmaVtabCursor1

func pragmaVtabConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(264)
	defer tls.Free(264)

	var pPragma uintptr = pAux
	var pTab uintptr = uintptr(0)
	var rc int32
	var i int32
	var j int32
	var cSep uint8 = uint8('(')

	_ = argc
	_ = argv
	Xsqlite3StrAccumInit(tls, bp+32, uintptr(0), bp+64, int32(unsafe.Sizeof([200]uint8{})), 0)
	Xsqlite3_str_appendall(tls, bp+32, ts+21767)
	i = 0
	j = int32((*PragmaName)(unsafe.Pointer(pPragma)).FiPragCName)
__1:
	if !(i < int32((*PragmaName)(unsafe.Pointer(pPragma)).FnPragCName)) {
		goto __3
	}
	{
		Xsqlite3_str_appendf(tls, bp+32, ts+21782, libc.VaList(bp, int32(cSep), pragCName[j]))
		cSep = uint8(',')

	}
	goto __2
__2:
	i++
	j++
	goto __1
	goto __3
__3:
	;
	if i == 0 {
		Xsqlite3_str_appendf(tls, bp+32, ts+21789, libc.VaList(bp+16, (*PragmaName)(unsafe.Pointer(pPragma)).FzName))
		i++
	}
	j = 0
	if int32((*PragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&PragFlg_Result1 != 0 {
		Xsqlite3_str_appendall(tls, bp+32, ts+21795)
		j++
	}
	if int32((*PragmaName)(unsafe.Pointer(pPragma)).FmPragFlg)&(PragFlg_SchemaOpt|PragFlg_SchemaReq) != 0 {
		Xsqlite3_str_appendall(tls, bp+32, ts+21807)
		j++
	}
	Xsqlite3_str_append(tls, bp+32, ts+7885, 1)
	Xsqlite3StrAccumFinish(tls, bp+32)

	rc = Xsqlite3_declare_vtab(tls, db, bp+64)
	if rc == SQLITE_OK {
		pTab = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(PragmaVtab{})))
		if pTab == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			libc.Xmemset(tls, pTab, 0, uint64(unsafe.Sizeof(PragmaVtab{})))
			(*PragmaVtab)(unsafe.Pointer(pTab)).FpName = pPragma
			(*PragmaVtab)(unsafe.Pointer(pTab)).Fdb = db
			(*PragmaVtab)(unsafe.Pointer(pTab)).FiHidden = U8(i)
			(*PragmaVtab)(unsafe.Pointer(pTab)).FnHidden = U8(j)
		}
	} else {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+24, Xsqlite3_errmsg(tls, db)))
	}

	*(*uintptr)(unsafe.Pointer(ppVtab)) = pTab
	return rc
}

func pragmaVtabDisconnect(tls *libc.TLS, pVtab uintptr) int32 {
	var pTab uintptr = pVtab
	Xsqlite3_free(tls, pTab)
	return SQLITE_OK
}

func pragmaVtabBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pTab uintptr = tab
	var pConstraint uintptr
	var i int32
	var j int32

	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(1)
	if int32((*PragmaVtab)(unsafe.Pointer(pTab)).FnHidden) == 0 {
		return SQLITE_OK
	}
	pConstraint = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 1*4)) = 0
	i = 0
__1:
	if !(i < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
		goto __3
	}
	{
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(pConstraint)).Fusable) == 0 {
			goto __2
		}
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(pConstraint)).Fop) != SQLITE_INDEX_CONSTRAINT_EQ {
			goto __2
		}
		if (*sqlite3_index_constraint)(unsafe.Pointer(pConstraint)).FiColumn < int32((*PragmaVtab)(unsafe.Pointer(pTab)).FiHidden) {
			goto __2
		}
		j = (*sqlite3_index_constraint)(unsafe.Pointer(pConstraint)).FiColumn - int32((*PragmaVtab)(unsafe.Pointer(pTab)).FiHidden)

		*(*int32)(unsafe.Pointer(bp + uintptr(j)*4)) = i + 1

	}
	goto __2
__2:
	i++
	pConstraint += 12
	goto __1
	goto __3
__3:
	;
	if *(*int32)(unsafe.Pointer(bp)) == 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(2147483647)
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(2147483647)
		return SQLITE_OK
	}
	j = *(*int32)(unsafe.Pointer(bp)) - 1
	(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(j)*8)).FargvIndex = 1
	(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(j)*8)).Fomit = uint8(1)
	if *(*int32)(unsafe.Pointer(bp + 1*4)) == 0 {
		return SQLITE_OK
	}
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(20)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(20)
	j = *(*int32)(unsafe.Pointer(bp + 1*4)) - 1
	(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(j)*8)).FargvIndex = 2
	(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(j)*8)).Fomit = uint8(1)
	return SQLITE_OK
}

func pragmaVtabOpen(tls *libc.TLS, pVtab uintptr, ppCursor uintptr) int32 {
	var pCsr uintptr
	pCsr = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(PragmaVtabCursor{})))
	if pCsr == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pCsr, 0, uint64(unsafe.Sizeof(PragmaVtabCursor{})))
	(*PragmaVtabCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVtab
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCsr
	return SQLITE_OK
}

func pragmaVtabCursorClear(tls *libc.TLS, pCsr uintptr) {
	var i int32
	Xsqlite3_finalize(tls, (*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma)
	(*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma = uintptr(0)
	for i = 0; i < int32(uint64(unsafe.Sizeof([2]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0)))); i++ {
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(pCsr + 24 + uintptr(i)*8)))
		*(*uintptr)(unsafe.Pointer(pCsr + 24 + uintptr(i)*8)) = uintptr(0)
	}
}

func pragmaVtabClose(tls *libc.TLS, cur uintptr) int32 {
	var pCsr uintptr = cur
	pragmaVtabCursorClear(tls, pCsr)
	Xsqlite3_free(tls, pCsr)
	return SQLITE_OK
}

func pragmaVtabNext(tls *libc.TLS, pVtabCursor uintptr) int32 {
	var pCsr uintptr = pVtabCursor
	var rc int32 = SQLITE_OK

	(*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FiRowid++

	if SQLITE_ROW != Xsqlite3_step(tls, (*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma) {
		rc = Xsqlite3_finalize(tls, (*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma)
		(*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma = uintptr(0)
		pragmaVtabCursorClear(tls, pCsr)
	}
	return rc
}

func pragmaVtabFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var pCsr uintptr = pVtabCursor
	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	var rc int32
	var i int32
	var j int32

	var zSql uintptr

	_ = idxNum
	_ = idxStr
	pragmaVtabCursorClear(tls, pCsr)
	if int32((*PragmaName)(unsafe.Pointer((*PragmaVtab)(unsafe.Pointer(pTab)).FpName)).FmPragFlg)&PragFlg_Result1 != 0 {
		j = 0
	} else {
		j = 1
	}
	i = 0
__1:
	if !(i < argc) {
		goto __3
	}
	{
		var zText uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))

		if zText != 0 {
			*(*uintptr)(unsafe.Pointer(pCsr + 24 + uintptr(j)*8)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, zText))
			if *(*uintptr)(unsafe.Pointer(pCsr + 24 + uintptr(j)*8)) == uintptr(0) {
				return SQLITE_NOMEM
			}
		}

	}
	goto __2
__2:
	i++
	j++
	goto __1
	goto __3
__3:
	;
	Xsqlite3StrAccumInit(tls, bp+32, uintptr(0), uintptr(0), 0, *(*int32)(unsafe.Pointer((*PragmaVtab)(unsafe.Pointer(pTab)).Fdb + 136 + 1*4)))
	Xsqlite3_str_appendall(tls, bp+32, ts+21822)
	if *(*uintptr)(unsafe.Pointer(pCsr + 24 + 1*8)) != 0 {
		Xsqlite3_str_appendf(tls, bp+32, ts+21830, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(pCsr + 24 + 1*8))))
	}
	Xsqlite3_str_appendall(tls, bp+32, (*PragmaName)(unsafe.Pointer((*PragmaVtab)(unsafe.Pointer(pTab)).FpName)).FzName)
	if *(*uintptr)(unsafe.Pointer(pCsr + 24)) != 0 {
		Xsqlite3_str_appendf(tls, bp+32, ts+21834, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(pCsr + 24))))
	}
	zSql = Xsqlite3StrAccumFinish(tls, bp+32)
	if zSql == uintptr(0) {
		return SQLITE_NOMEM
	}
	rc = Xsqlite3_prepare_v2(tls, (*PragmaVtab)(unsafe.Pointer(pTab)).Fdb, zSql, -1, pCsr+8, uintptr(0))
	Xsqlite3_free(tls, zSql)
	if rc != SQLITE_OK {
		(*PragmaVtab)(unsafe.Pointer(pTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+24, Xsqlite3_errmsg(tls, (*PragmaVtab)(unsafe.Pointer(pTab)).Fdb)))
		return rc
	}
	return pragmaVtabNext(tls, pVtabCursor)
}

func pragmaVtabEof(tls *libc.TLS, pVtabCursor uintptr) int32 {
	var pCsr uintptr = pVtabCursor
	return libc.Bool32((*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma == uintptr(0))
}

func pragmaVtabColumn(tls *libc.TLS, pVtabCursor uintptr, ctx uintptr, i int32) int32 {
	var pCsr uintptr = pVtabCursor
	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	if i < int32((*PragmaVtab)(unsafe.Pointer(pTab)).FiHidden) {
		Xsqlite3_result_value(tls, ctx, Xsqlite3_column_value(tls, (*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FpPragma, i))
	} else {
		Xsqlite3_result_text(tls, ctx, *(*uintptr)(unsafe.Pointer(pCsr + 24 + uintptr(i-int32((*PragmaVtab)(unsafe.Pointer(pTab)).FiHidden))*8)), -1, libc.UintptrFromInt32(-1))
	}
	return SQLITE_OK
}

func pragmaVtabRowid(tls *libc.TLS, pVtabCursor uintptr, p uintptr) int32 {
	var pCsr uintptr = pVtabCursor
	*(*Sqlite_int64)(unsafe.Pointer(p)) = (*PragmaVtabCursor)(unsafe.Pointer(pCsr)).FiRowid
	return SQLITE_OK
}

var pragmaVtabModule = Sqlite3_module{
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
}

func Xsqlite3PragmaVtabRegister(tls *libc.TLS, db uintptr, zName uintptr) uintptr {
	var pName uintptr

	pName = pragmaLocate(tls, zName+uintptr(7))
	if pName == uintptr(0) {
		return uintptr(0)
	}
	if int32((*PragmaName)(unsafe.Pointer(pName)).FmPragFlg)&(PragFlg_Result0|PragFlg_Result1) == 0 {
		return uintptr(0)
	}

	return Xsqlite3VtabCreateModule(tls, db, zName, uintptr(unsafe.Pointer(&pragmaVtabModule)), pName, uintptr(0))
}

func corruptSchema(tls *libc.TLS, pData uintptr, azObj uintptr, zExtra uintptr) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var db uintptr = (*InitData)(unsafe.Pointer(pData)).Fdb
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*InitData)(unsafe.Pointer(pData)).Frc = SQLITE_NOMEM
	} else if *(*uintptr)(unsafe.Pointer((*InitData)(unsafe.Pointer(pData)).FpzErrMsg)) != uintptr(0) {
	} else if (*InitData)(unsafe.Pointer(pData)).FmInitFlags&U32(INITFLAG_AlterMask) != 0 {
		*(*uintptr)(unsafe.Pointer((*InitData)(unsafe.Pointer(pData)).FpzErrMsg)) = Xsqlite3MPrintf(tls, db,
			ts+21838, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(azObj)), *(*uintptr)(unsafe.Pointer(azObj + 1*8)),
				azAlterType[(*InitData)(unsafe.Pointer(pData)).FmInitFlags&U32(INITFLAG_AlterMask)-U32(1)],
				zExtra))
		(*InitData)(unsafe.Pointer(pData)).Frc = SQLITE_ERROR
	} else if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_WriteSchema) != 0 {
		(*InitData)(unsafe.Pointer(pData)).Frc = Xsqlite3CorruptError(tls, 137249)
	} else {
		var z uintptr
		var zObj uintptr
		if *(*uintptr)(unsafe.Pointer(azObj + 1*8)) != 0 {
			zObj = *(*uintptr)(unsafe.Pointer(azObj + 1*8))
		} else {
			zObj = ts + 7933
		}
		z = Xsqlite3MPrintf(tls, db, ts+21866, libc.VaList(bp+32, zObj))
		if zExtra != 0 && *(*uint8)(unsafe.Pointer(zExtra)) != 0 {
			z = Xsqlite3MPrintf(tls, db, ts+21897, libc.VaList(bp+40, z, zExtra))
		}
		*(*uintptr)(unsafe.Pointer((*InitData)(unsafe.Pointer(pData)).FpzErrMsg)) = z
		(*InitData)(unsafe.Pointer(pData)).Frc = Xsqlite3CorruptError(tls, 137256)
	}
}

var azAlterType = [3]uintptr{
	ts + 21905,
	ts + 21912,
	ts + 21924,
}

func Xsqlite3IndexHasDuplicateRootPage(tls *libc.TLS, pIndex uintptr) int32 {
	var p uintptr
	for p = (*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FpTable)).FpIndex; p != 0; p = (*Index)(unsafe.Pointer(p)).FpNext {
		if (*Index)(unsafe.Pointer(p)).Ftnum == (*Index)(unsafe.Pointer(pIndex)).Ftnum && p != pIndex {
			return 1
		}
	}
	return 0
}

func Xsqlite3InitCallback(tls *libc.TLS, pInit uintptr, argc int32, argv uintptr, NotUsed uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pData uintptr = pInit
	var db uintptr = (*InitData)(unsafe.Pointer(pData)).Fdb
	var iDb int32 = (*InitData)(unsafe.Pointer(pData)).FiDb

	_ = NotUsed
	_ = argc

	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_EncodingFixed)
	if argv == uintptr(0) {
		return 0
	}
	(*InitData)(unsafe.Pointer(pData)).FnInitRow++
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		corruptSchema(tls, pData, argv, uintptr(0))
		return 1
	}

	if *(*uintptr)(unsafe.Pointer(argv + 3*8)) == uintptr(0) {
		corruptSchema(tls, pData, argv, uintptr(0))
	} else if *(*uintptr)(unsafe.Pointer(argv + 4*8)) != 0 &&
		'c' == int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(argv + 4*8))))]) &&
		'r' == int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(argv + 4*8)) + 1))]) {
		var rc int32
		var saved_iDb U8 = (*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb

		(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = U8(iDb)
		if Xsqlite3GetUInt32(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8)), db+192) == 0 ||
			(*Sqlite3)(unsafe.Pointer(db)).Finit.FnewTnum > (*InitData)(unsafe.Pointer(pData)).FmxPage && (*InitData)(unsafe.Pointer(pData)).FmxPage > Pgno(0) {
			if Xsqlite3Config.FbExtraSchemaChecks != 0 {
				corruptSchema(tls, pData, argv, ts+17562)
			}
		}
		libc.SetBitFieldPtr8Uint32(db+192+8, uint32(0), 0, 0x1)
		(*Sqlite3)(unsafe.Pointer(db)).Finit.FazInit = argv
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		sqlite3Prepare(tls, db, *(*uintptr)(unsafe.Pointer(argv + 4*8)), -1, uint32(0), uintptr(0), bp, uintptr(0))
		rc = (*Sqlite3)(unsafe.Pointer(db)).FerrCode

		(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = saved_iDb

		if SQLITE_OK != rc {
			if uint32(int32(*(*uint8)(unsafe.Pointer(db + 192 + 8))&0x1>>0)) != 0 {
			} else {
				if rc > (*InitData)(unsafe.Pointer(pData)).Frc {
					(*InitData)(unsafe.Pointer(pData)).Frc = rc
				}
				if rc == SQLITE_NOMEM {
					Xsqlite3OomFault(tls, db)
				} else if rc != SQLITE_INTERRUPT && rc&0xFF != SQLITE_LOCKED {
					corruptSchema(tls, pData, argv, Xsqlite3_errmsg(tls, db))
				}
			}
		}
		(*Sqlite3)(unsafe.Pointer(db)).Finit.FazInit = uintptr(unsafe.Pointer(&Xsqlite3StdType))
		Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	} else if *(*uintptr)(unsafe.Pointer(argv + 1*8)) == uintptr(0) || *(*uintptr)(unsafe.Pointer(argv + 4*8)) != uintptr(0) && int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(argv + 4*8))))) != 0 {
		corruptSchema(tls, pData, argv, uintptr(0))
	} else {
		var pIndex uintptr
		pIndex = Xsqlite3FindIndex(tls, db, *(*uintptr)(unsafe.Pointer(argv + 1*8)), (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName)
		if pIndex == uintptr(0) {
			corruptSchema(tls, pData, argv, ts+21935)
		} else if Xsqlite3GetUInt32(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8)), pIndex+88) == 0 ||
			(*Index)(unsafe.Pointer(pIndex)).Ftnum < Pgno(2) ||
			(*Index)(unsafe.Pointer(pIndex)).Ftnum > (*InitData)(unsafe.Pointer(pData)).FmxPage ||
			Xsqlite3IndexHasDuplicateRootPage(tls, pIndex) != 0 {
			if Xsqlite3Config.FbExtraSchemaChecks != 0 {
				corruptSchema(tls, pData, argv, ts+17562)
			}
		}
	}
	return 0
}

func Xsqlite3InitOne(tls *libc.TLS, db uintptr, iDb int32, pzErrMsg uintptr, mFlags U32) int32 {
	bp := tls.Alloc(124)
	defer tls.Free(124)

	var rc int32
	var i int32
	var size int32
	var pDb uintptr

	var zSchemaTabName uintptr
	var openedTransaction int32
	var mask int32
	var encoding U8
	var xAuth Sqlite3_xauth
	var zSql uintptr
	openedTransaction = 0
	mask = int32((*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_EncodingFixed) | libc.Uint32FromInt32(libc.CplInt32(DBFLAG_EncodingFixed)))

	(*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy = U8(1)

	*(*uintptr)(unsafe.Pointer(bp + 16)) = ts + 9499
	*(*uintptr)(unsafe.Pointer(bp + 16 + 1*8)) = libc.AssignUintptr(&zSchemaTabName, func() uintptr {
		if !(0 != 0) && iDb == 1 {
			return ts + 9604
		}
		return ts + 8808
	}())
	*(*uintptr)(unsafe.Pointer(bp + 16 + 2*8)) = *(*uintptr)(unsafe.Pointer(bp + 16 + 1*8))
	*(*uintptr)(unsafe.Pointer(bp + 16 + 3*8)) = ts + 11251
	*(*uintptr)(unsafe.Pointer(bp + 16 + 4*8)) = ts + 21948
	*(*uintptr)(unsafe.Pointer(bp + 16 + 5*8)) = uintptr(0)
	(*InitData)(unsafe.Pointer(bp + 64)).Fdb = db
	(*InitData)(unsafe.Pointer(bp + 64)).FiDb = iDb
	(*InitData)(unsafe.Pointer(bp + 64)).Frc = SQLITE_OK
	(*InitData)(unsafe.Pointer(bp + 64)).FpzErrMsg = pzErrMsg
	(*InitData)(unsafe.Pointer(bp + 64)).FmInitFlags = mFlags
	(*InitData)(unsafe.Pointer(bp + 64)).FnInitRow = U32(0)
	(*InitData)(unsafe.Pointer(bp + 64)).FmxPage = Pgno(0)
	Xsqlite3InitCallback(tls, bp+64, 5, bp+16, uintptr(0))
	*(*U32)(unsafe.Pointer(db + 44)) &= U32(mask)
	if !((*InitData)(unsafe.Pointer(bp+64)).Frc != 0) {
		goto __1
	}
	rc = (*InitData)(unsafe.Pointer(bp + 64)).Frc
	goto error_out
__1:
	;
	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	if !((*Db)(unsafe.Pointer(pDb)).FpBt == uintptr(0)) {
		goto __2
	}

	*(*U16)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema + 114)) |= U16(DB_SchemaLoaded)
	rc = SQLITE_OK
	goto error_out
__2:
	;
	Xsqlite3BtreeEnter(tls, (*Db)(unsafe.Pointer(pDb)).FpBt)
	if !(Xsqlite3BtreeTxnState(tls, (*Db)(unsafe.Pointer(pDb)).FpBt) == SQLITE_TXN_NONE) {
		goto __3
	}
	rc = Xsqlite3BtreeBeginTrans(tls, (*Db)(unsafe.Pointer(pDb)).FpBt, 0, uintptr(0))
	if !(rc != SQLITE_OK) {
		goto __4
	}
	Xsqlite3SetString(tls, pzErrMsg, db, Xsqlite3ErrStr(tls, rc))
	goto initone_error_out
__4:
	;
	openedTransaction = 1
__3:
	;
	i = 0
__5:
	if !(i < int32(uint64(unsafe.Sizeof([5]int32{}))/uint64(unsafe.Sizeof(int32(0))))) {
		goto __7
	}
	Xsqlite3BtreeGetMeta(tls, (*Db)(unsafe.Pointer(pDb)).FpBt, i+1, bp+104+uintptr(i)*4)
	goto __6
__6:
	i++
	goto __5
	goto __7
__7:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ResetDatabase) != uint64(0)) {
		goto __8
	}
	libc.Xmemset(tls, bp+104, 0, uint64(unsafe.Sizeof([5]int32{})))
__8:
	;
	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fschema_cookie = *(*int32)(unsafe.Pointer(bp + 104))

	if !(*(*int32)(unsafe.Pointer(bp + 104 + 4*4)) != 0) {
		goto __9
	}
	if !(iDb == 0 && (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_EncodingFixed) == U32(0)) {
		goto __10
	}

	encoding = U8(int32(U8(*(*int32)(unsafe.Pointer(bp + 104 + 4*4)))) & 3)
	if !(int32(encoding) == 0) {
		goto __12
	}
	encoding = U8(SQLITE_UTF8)
__12:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive > 0 && int32(encoding) != int32((*Sqlite3)(unsafe.Pointer(db)).Fenc)) {
		goto __13
	}
	rc = SQLITE_LOCKED
	goto initone_error_out
	goto __14
__13:
	Xsqlite3SetTextEncoding(tls, db, encoding)
__14:
	;
	goto __11
__10:
	if !(*(*int32)(unsafe.Pointer(bp + 104 + 4*4))&3 != int32((*Sqlite3)(unsafe.Pointer(db)).Fenc)) {
		goto __15
	}
	Xsqlite3SetString(tls, pzErrMsg, db,
		ts+15190)
	rc = SQLITE_ERROR
	goto initone_error_out
__15:
	;
__11:
	;
__9:
	;
	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fenc = (*Sqlite3)(unsafe.Pointer(db)).Fenc

	if !((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size == 0) {
		goto __16
	}
	size = Xsqlite3AbsInt32(tls, *(*int32)(unsafe.Pointer(bp + 104 + 2*4)))
	if !(size == 0) {
		goto __17
	}
	size = -2000
__17:
	;
	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size = size
	Xsqlite3BtreeSetCacheSize(tls, (*Db)(unsafe.Pointer(pDb)).FpBt, (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Fcache_size)
__16:
	;
	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format = U8(*(*int32)(unsafe.Pointer(bp + 104 + 1*4)))
	if !(int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) == 0) {
		goto __18
	}
	(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format = U8(1)
__18:
	;
	if !(int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer(pDb)).FpSchema)).Ffile_format) > SQLITE_MAX_FILE_FORMAT) {
		goto __19
	}
	Xsqlite3SetString(tls, pzErrMsg, db, ts+22020)
	rc = SQLITE_ERROR
	goto initone_error_out
__19:
	;
	if !(iDb == 0 && *(*int32)(unsafe.Pointer(bp + 104 + 1*4)) >= 4) {
		goto __20
	}
	*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(SQLITE_LegacyFileFmt))
__20:
	;
	(*InitData)(unsafe.Pointer(bp + 64)).FmxPage = Xsqlite3BtreeLastPage(tls, (*Db)(unsafe.Pointer(pDb)).FpBt)

	zSql = Xsqlite3MPrintf(tls, db,
		ts+22044,
		libc.VaList(bp, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName, zSchemaTabName))

	xAuth = (*Sqlite3)(unsafe.Pointer(db)).FxAuth
	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = uintptr(0)
	rc = Xsqlite3_exec(tls, db, zSql, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
	}{Xsqlite3InitCallback})), bp+64, uintptr(0))
	(*Sqlite3)(unsafe.Pointer(db)).FxAuth = xAuth

	if !(rc == SQLITE_OK) {
		goto __21
	}
	rc = (*InitData)(unsafe.Pointer(bp + 64)).Frc
__21:
	;
	Xsqlite3DbFree(tls, db, zSql)
	if !(rc == SQLITE_OK) {
		goto __22
	}
	Xsqlite3AnalysisLoad(tls, db, iDb)
__22:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __23
	}
	rc = SQLITE_NOMEM
	Xsqlite3ResetAllSchemasOfConnection(tls, db)
	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32
	goto __24
__23:
	if !(rc == SQLITE_OK || (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_NoSchemaError) != 0 && rc != SQLITE_NOMEM) {
		goto __25
	}

	*(*U16)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema + 114)) |= U16(DB_SchemaLoaded)
	rc = SQLITE_OK
__25:
	;
__24:
	;
initone_error_out:
	if !(openedTransaction != 0) {
		goto __26
	}
	Xsqlite3BtreeCommit(tls, (*Db)(unsafe.Pointer(pDb)).FpBt)
__26:
	;
	Xsqlite3BtreeLeave(tls, (*Db)(unsafe.Pointer(pDb)).FpBt)

error_out:
	if !(rc != 0) {
		goto __27
	}
	if !(rc == SQLITE_NOMEM || rc == SQLITE_IOERR|int32(12)<<8) {
		goto __28
	}
	Xsqlite3OomFault(tls, db)
__28:
	;
	Xsqlite3ResetOneSchema(tls, db, iDb)
__27:
	;
	(*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy = U8(0)
	return rc
}

func Xsqlite3Init(tls *libc.TLS, db uintptr, pzErrMsg uintptr) int32 {
	var i int32
	var rc int32
	var commit_internal int32 = libc.BoolInt32(!((*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_SchemaChange) != 0))

	(*Sqlite3)(unsafe.Pointer(db)).Fenc = (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema)).Fenc

	if !(int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema)).FschemaFlags)&DB_SchemaLoaded == DB_SchemaLoaded) {
		rc = Xsqlite3InitOne(tls, db, 0, pzErrMsg, uint32(0))
		if rc != 0 {
			return rc
		}
	}

	for i = (*Sqlite3)(unsafe.Pointer(db)).FnDb - 1; i > 0; i-- {
		if !(int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpSchema)).FschemaFlags)&DB_SchemaLoaded == DB_SchemaLoaded) {
			rc = Xsqlite3InitOne(tls, db, i, pzErrMsg, uint32(0))
			if rc != 0 {
				return rc
			}
		}
	}
	if commit_internal != 0 {
		Xsqlite3CommitInternalChanges(tls, db)
	}
	return SQLITE_OK
}

func Xsqlite3ReadSchema(tls *libc.TLS, pParse uintptr) int32 {
	var rc int32 = SQLITE_OK
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) {
		rc = Xsqlite3Init(tls, db, pParse+8)
		if rc != SQLITE_OK {
			(*Parse)(unsafe.Pointer(pParse)).Frc = rc
			(*Parse)(unsafe.Pointer(pParse)).FnErr++
		} else if (*Sqlite3)(unsafe.Pointer(db)).FnoSharedCache != 0 {
			*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaKnownOk)
		}
	}
	return rc
}

func schemaIsValid(tls *libc.TLS, pParse uintptr) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var iDb int32
	var rc int32

	for iDb = 0; iDb < (*Sqlite3)(unsafe.Pointer(db)).FnDb; iDb++ {
		var openedTransaction int32 = 0
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpBt
		if pBt == uintptr(0) {
			continue
		}

		if Xsqlite3BtreeTxnState(tls, pBt) == SQLITE_TXN_NONE {
			rc = Xsqlite3BtreeBeginTrans(tls, pBt, 0, uintptr(0))
			if rc == SQLITE_NOMEM || rc == SQLITE_IOERR|int32(12)<<8 {
				Xsqlite3OomFault(tls, db)
				(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
			}
			if rc != SQLITE_OK {
				return
			}
			openedTransaction = 1
		}

		Xsqlite3BtreeGetMeta(tls, pBt, BTREE_SCHEMA_VERSION, bp)

		if *(*int32)(unsafe.Pointer(bp)) != (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema)).Fschema_cookie {
			if int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema)).FschemaFlags)&DB_SchemaLoaded == DB_SchemaLoaded {
				(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_SCHEMA
			}
			Xsqlite3ResetOneSchema(tls, db, iDb)
		}

		if openedTransaction != 0 {
			Xsqlite3BtreeCommit(tls, pBt)
		}
	}
}

func Xsqlite3SchemaToIndex(tls *libc.TLS, db uintptr, pSchema uintptr) int32 {
	var i int32 = -32768

	if pSchema != 0 {
		for i = 0; 1 != 0; i++ {
			if (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpSchema == pSchema {
				break
			}
		}

	}
	return i
}

func Xsqlite3ParseObjectReset(tls *libc.TLS, pParse uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if (*Parse)(unsafe.Pointer(pParse)).FaTableLock != 0 {
		Xsqlite3DbNNFreeNN(tls, db, (*Parse)(unsafe.Pointer(pParse)).FaTableLock)
	}
	for (*Parse)(unsafe.Pointer(pParse)).FpCleanup != 0 {
		var pCleanup uintptr = (*Parse)(unsafe.Pointer(pParse)).FpCleanup
		(*Parse)(unsafe.Pointer(pParse)).FpCleanup = (*ParseCleanup)(unsafe.Pointer(pCleanup)).FpNext
		(*struct {
			f func(*libc.TLS, uintptr, uintptr)
		})(unsafe.Pointer(&struct{ uintptr }{(*ParseCleanup)(unsafe.Pointer(pCleanup)).FxCleanup})).f(tls, db, (*ParseCleanup)(unsafe.Pointer(pCleanup)).FpPtr)
		Xsqlite3DbNNFreeNN(tls, db, pCleanup)
	}
	if (*Parse)(unsafe.Pointer(pParse)).FaLabel != 0 {
		Xsqlite3DbNNFreeNN(tls, db, (*Parse)(unsafe.Pointer(pParse)).FaLabel)
	}
	if (*Parse)(unsafe.Pointer(pParse)).FpConstExpr != 0 {
		Xsqlite3ExprListDelete(tls, db, (*Parse)(unsafe.Pointer(pParse)).FpConstExpr)
	}

	*(*U32)(unsafe.Pointer(db + 440)) -= U32((*Parse)(unsafe.Pointer(pParse)).FdisableLookaside)
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = func() uint16 {
		if (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable != 0 {
			return uint16(0)
		}
		return (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue
	}()

	(*Sqlite3)(unsafe.Pointer(db)).FpParse = (*Parse)(unsafe.Pointer(pParse)).FpOuterParse
	(*Parse)(unsafe.Pointer(pParse)).Fdb = uintptr(0)
	(*Parse)(unsafe.Pointer(pParse)).FdisableLookaside = U8(0)
}

func Xsqlite3ParserAddCleanup(tls *libc.TLS, pParse uintptr, xCleanup uintptr, pPtr uintptr) uintptr {
	var pCleanup uintptr = Xsqlite3DbMallocRaw(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(ParseCleanup{})))
	if pCleanup != 0 {
		(*ParseCleanup)(unsafe.Pointer(pCleanup)).FpNext = (*Parse)(unsafe.Pointer(pParse)).FpCleanup
		(*Parse)(unsafe.Pointer(pParse)).FpCleanup = pCleanup
		(*ParseCleanup)(unsafe.Pointer(pCleanup)).FpPtr = pPtr
		(*ParseCleanup)(unsafe.Pointer(pCleanup)).FxCleanup = xCleanup
	} else {
		(*struct {
			f func(*libc.TLS, uintptr, uintptr)
		})(unsafe.Pointer(&struct{ uintptr }{xCleanup})).f(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pPtr)
		pPtr = uintptr(0)
	}
	return pPtr
}

func Xsqlite3ParseObjectInit(tls *libc.TLS, pParse uintptr, db uintptr) {
	libc.Xmemset(tls, pParse+uintptr(uint64(uintptr(0)+8)), 0, uint64(uintptr(0)+228)-uint64(uintptr(0)+8))
	libc.Xmemset(tls, pParse+uintptr(uint64(uintptr(0)+288)), 0, uint64(unsafe.Sizeof(Parse{}))-uint64(uintptr(0)+288))

	(*Parse)(unsafe.Pointer(pParse)).FpOuterParse = (*Sqlite3)(unsafe.Pointer(db)).FpParse
	(*Sqlite3)(unsafe.Pointer(db)).FpParse = pParse
	(*Parse)(unsafe.Pointer(pParse)).Fdb = db
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+1572, 0)
	}
}

func sqlite3Prepare(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags U32, pReprepare uintptr, ppStmt uintptr, pzTail uintptr) int32 {
	bp := tls.Alloc(440)
	defer tls.Free(440)

	var rc int32
	var i int32

	var zDb uintptr
	var pBt uintptr
	var zSqlCopy uintptr
	var mxLen int32
	var pT uintptr
	rc = SQLITE_OK

	libc.Xmemset(tls, bp+16+uintptr(uint64(uintptr(0)+8)), 0, uint64(uintptr(0)+228)-uint64(uintptr(0)+8))
	libc.Xmemset(tls, bp+16+uintptr(uint64(uintptr(0)+288)), 0, uint64(unsafe.Sizeof(Parse{}))-uint64(uintptr(0)+288))
	(*Parse)(unsafe.Pointer(bp + 16)).FpOuterParse = (*Sqlite3)(unsafe.Pointer(db)).FpParse
	(*Sqlite3)(unsafe.Pointer(db)).FpParse = bp + 16
	(*Parse)(unsafe.Pointer(bp + 16)).Fdb = db
	(*Parse)(unsafe.Pointer(bp + 16)).FpReprepare = pReprepare

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __1
	}
	Xsqlite3ErrorMsg(tls, bp+16, ts+1572, 0)
__1:
	;
	if !(prepFlags&U32(SQLITE_PREPARE_PERSISTENT) != 0) {
		goto __2
	}
	(*Parse)(unsafe.Pointer(bp+16)).FdisableLookaside++
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)
__2:
	;
	(*Parse)(unsafe.Pointer(bp + 16)).FprepFlags = U8(prepFlags & U32(0xff))

	if !!(int32((*Sqlite3)(unsafe.Pointer(db)).FnoSharedCache) != 0) {
		goto __3
	}
	i = 0
__4:
	if !(i < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __6
	}
	pBt = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
	if !(pBt != 0) {
		goto __7
	}

	rc = Xsqlite3BtreeSchemaLocked(tls, pBt)
	if !(rc != 0) {
		goto __8
	}
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FzDbSName
	Xsqlite3ErrorWithMsg(tls, db, rc, ts+22078, libc.VaList(bp, zDb))

	goto end_prepare
__8:
	;
__7:
	;
	goto __5
__5:
	i++
	goto __4
	goto __6
__6:
	;
__3:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FpDisconnect != 0) {
		goto __9
	}
	Xsqlite3VtabUnlockList(tls, db)
__9:
	;
	if !(nBytes >= 0 && (nBytes == 0 || int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(nBytes-1)))) != 0)) {
		goto __10
	}
	mxLen = *(*int32)(unsafe.Pointer(db + 136 + 1*4))

	if !(nBytes > mxLen) {
		goto __12
	}
	Xsqlite3ErrorWithMsg(tls, db, SQLITE_TOOBIG, ts+22108, 0)
	rc = Xsqlite3ApiExit(tls, db, SQLITE_TOOBIG)
	goto end_prepare
__12:
	;
	zSqlCopy = Xsqlite3DbStrNDup(tls, db, zSql, uint64(nBytes))
	if !(zSqlCopy != 0) {
		goto __13
	}
	Xsqlite3RunParser(tls, bp+16, zSqlCopy)
	(*Parse)(unsafe.Pointer(bp + 16)).FzTail = zSql + uintptr((int64((*Parse)(unsafe.Pointer(bp+16)).FzTail)-int64(zSqlCopy))/1)
	Xsqlite3DbFree(tls, db, zSqlCopy)
	goto __14
__13:
	(*Parse)(unsafe.Pointer(bp + 16)).FzTail = zSql + uintptr(nBytes)
__14:
	;
	goto __11
__10:
	Xsqlite3RunParser(tls, bp+16, zSql)
__11:
	;
	if !(pzTail != 0) {
		goto __15
	}
	*(*uintptr)(unsafe.Pointer(pzTail)) = (*Parse)(unsafe.Pointer(bp + 16)).FzTail
__15:
	;
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) == 0) {
		goto __16
	}
	Xsqlite3VdbeSetSql(tls, (*Parse)(unsafe.Pointer(bp+16)).FpVdbe, zSql, int32((int64((*Parse)(unsafe.Pointer(bp+16)).FzTail)-int64(zSql))/1), uint8(prepFlags))
__16:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __17
	}
	(*Parse)(unsafe.Pointer(bp + 16)).Frc = SQLITE_NOMEM
	(*Parse)(unsafe.Pointer(bp + 16)).FcheckSchema = U8(0)
__17:
	;
	if !((*Parse)(unsafe.Pointer(bp+16)).Frc != SQLITE_OK && (*Parse)(unsafe.Pointer(bp+16)).Frc != SQLITE_DONE) {
		goto __18
	}
	if !((*Parse)(unsafe.Pointer(bp+16)).FcheckSchema != 0 && int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) == 0) {
		goto __20
	}
	schemaIsValid(tls, bp+16)
__20:
	;
	if !((*Parse)(unsafe.Pointer(bp+16)).FpVdbe != 0) {
		goto __21
	}
	Xsqlite3VdbeFinalize(tls, (*Parse)(unsafe.Pointer(bp+16)).FpVdbe)
__21:
	;
	rc = (*Parse)(unsafe.Pointer(bp + 16)).Frc
	if !((*Parse)(unsafe.Pointer(bp+16)).FzErrMsg != 0) {
		goto __22
	}
	Xsqlite3ErrorWithMsg(tls, db, rc, ts+1684, libc.VaList(bp+8, (*Parse)(unsafe.Pointer(bp+16)).FzErrMsg))
	Xsqlite3DbFree(tls, db, (*Parse)(unsafe.Pointer(bp+16)).FzErrMsg)
	goto __23
__22:
	Xsqlite3Error(tls, db, rc)
__23:
	;
	goto __19
__18:
	;
	*(*uintptr)(unsafe.Pointer(ppStmt)) = (*Parse)(unsafe.Pointer(bp + 16)).FpVdbe
	rc = SQLITE_OK
	Xsqlite3ErrorClear(tls, db)
__19:
	;
__24:
	if !((*Parse)(unsafe.Pointer(bp+16)).FpTriggerPrg != 0) {
		goto __25
	}
	pT = (*Parse)(unsafe.Pointer(bp + 16)).FpTriggerPrg
	(*Parse)(unsafe.Pointer(bp + 16)).FpTriggerPrg = (*TriggerPrg)(unsafe.Pointer(pT)).FpNext
	Xsqlite3DbFree(tls, db, pT)
	goto __24
__25:
	;
end_prepare:
	Xsqlite3ParseObjectReset(tls, bp+16)
	return rc
}

func sqlite3LockAndPrepare(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags U32, pOld uintptr, ppStmt uintptr, pzTail uintptr) int32 {
	var rc int32
	var cnt int32 = 0

	*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	if !(Xsqlite3SafetyCheckOk(tls, db) != 0) || zSql == uintptr(0) {
		return Xsqlite3MisuseError(tls, 138048)
	}
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	Xsqlite3BtreeEnterAll(tls, db)
	for __ccgo := true; __ccgo; __ccgo = rc == SQLITE_ERROR|int32(2)<<8 && libc.PostIncInt32(&cnt, 1) < SQLITE_MAX_PREPARE_RETRY ||
		rc == SQLITE_SCHEMA && func() int32 { Xsqlite3ResetOneSchema(tls, db, -1); return libc.PostIncInt32(&cnt, 1) }() == 0 {
		rc = sqlite3Prepare(tls, db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail)

		if rc == SQLITE_OK || (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			break
		}
	}
	Xsqlite3BtreeLeaveAll(tls, db)
	rc = Xsqlite3ApiExit(tls, db, rc)

	(*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3Reprepare(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	var zSql uintptr
	var db uintptr
	var prepFlags U8

	zSql = Xsqlite3_sql(tls, p)

	db = Xsqlite3VdbeDb(tls, p)

	prepFlags = Xsqlite3VdbePrepareFlags(tls, p)
	rc = sqlite3LockAndPrepare(tls, db, zSql, -1, uint32(prepFlags), p, bp, uintptr(0))
	if rc != 0 {
		if rc == SQLITE_NOMEM {
			Xsqlite3OomFault(tls, db)
		}

		return rc
	} else {
	}
	Xsqlite3VdbeSwap(tls, *(*uintptr)(unsafe.Pointer(bp)), p)
	Xsqlite3TransferBindings(tls, *(*uintptr)(unsafe.Pointer(bp)), p)
	Xsqlite3VdbeResetStepResult(tls, *(*uintptr)(unsafe.Pointer(bp)))
	Xsqlite3VdbeFinalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return SQLITE_OK
}

func Xsqlite3_prepare(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, ppStmt uintptr, pzTail uintptr) int32 {
	var rc int32
	rc = sqlite3LockAndPrepare(tls, db, zSql, nBytes, uint32(0), uintptr(0), ppStmt, pzTail)

	return rc
}

func Xsqlite3_prepare_v2(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, ppStmt uintptr, pzTail uintptr) int32 {
	var rc int32

	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) int32 {
	var rc int32

	rc = sqlite3LockAndPrepare(tls, db, zSql, nBytes,
		uint32(SQLITE_PREPARE_SAVESQL)|prepFlags&uint32(SQLITE_PREPARE_MASK),
		uintptr(0), ppStmt, pzTail)

	return rc
}

func sqlite3Prepare16(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags U32, ppStmt uintptr, pzTail uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zSql8 uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32 = SQLITE_OK

	*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	if !(Xsqlite3SafetyCheckOk(tls, db) != 0) || zSql == uintptr(0) {
		return Xsqlite3MisuseError(tls, 138196)
	}
	if nBytes >= 0 {
		var sz int32
		var z uintptr = zSql
		for sz = 0; sz < nBytes && (int32(*(*uint8)(unsafe.Pointer(z + uintptr(sz)))) != 0 || int32(*(*uint8)(unsafe.Pointer(z + uintptr(sz+1)))) != 0); sz = sz + 2 {
		}
		nBytes = sz
	}
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	zSql8 = Xsqlite3Utf16to8(tls, db, zSql, nBytes, uint8(SQLITE_UTF16LE))
	if zSql8 != 0 {
		rc = sqlite3LockAndPrepare(tls, db, zSql8, -1, prepFlags, uintptr(0), ppStmt, bp)
	}

	if *(*uintptr)(unsafe.Pointer(bp)) != 0 && pzTail != 0 {
		var chars_parsed int32 = Xsqlite3Utf8CharLen(tls, zSql8, int32((int64(*(*uintptr)(unsafe.Pointer(bp)))-int64(zSql8))/1))
		*(*uintptr)(unsafe.Pointer(pzTail)) = zSql + uintptr(Xsqlite3Utf16ByteLen(tls, zSql, chars_parsed))
	}
	Xsqlite3DbFree(tls, db, zSql8)
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_prepare16(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, ppStmt uintptr, pzTail uintptr) int32 {
	var rc int32
	rc = sqlite3Prepare16(tls, db, zSql, nBytes, uint32(0), ppStmt, pzTail)

	return rc
}

func Xsqlite3_prepare16_v2(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, ppStmt uintptr, pzTail uintptr) int32 {
	var rc int32
	rc = sqlite3Prepare16(tls, db, zSql, nBytes, uint32(SQLITE_PREPARE_SAVESQL), ppStmt, pzTail)

	return rc
}

func Xsqlite3_prepare16_v3(tls *libc.TLS, db uintptr, zSql uintptr, nBytes int32, prepFlags uint32, ppStmt uintptr, pzTail uintptr) int32 {
	var rc int32
	rc = sqlite3Prepare16(tls, db, zSql, nBytes,
		uint32(SQLITE_PREPARE_SAVESQL)|prepFlags&uint32(SQLITE_PREPARE_MASK),
		ppStmt, pzTail)

	return rc
}

type DistinctCtx1 = struct {
	FisTnct      U8
	FeTnctType   U8
	F__ccgo_pad1 [2]byte
	FtabTnct     int32
	FaddrTnct    int32
}

type DistinctCtx = DistinctCtx1

type SortCtx1 = struct {
	FpOrderBy         uintptr
	FnOBSat           int32
	FiECursor         int32
	FregReturn        int32
	FlabelBkOut       int32
	FaddrSortIndex    int32
	FlabelDone        int32
	FlabelOBLopt      int32
	FsortFlags        U8
	F__ccgo_pad1      [3]byte
	FpDeferredRowLoad uintptr
}

type SortCtx = SortCtx1
type RowLoadInfo1 = struct {
	FregResult   int32
	FecelFlags   U8
	F__ccgo_pad1 [3]byte
}

func clearSelect(tls *libc.TLS, db uintptr, p uintptr, bFree int32) {
	for p != 0 {
		var pPrior uintptr = (*Select)(unsafe.Pointer(p)).FpPrior
		Xsqlite3ExprListDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpEList)
		Xsqlite3SrcListDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpSrc)
		Xsqlite3ExprDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpWhere)
		Xsqlite3ExprListDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpGroupBy)
		Xsqlite3ExprDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpHaving)
		Xsqlite3ExprListDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpOrderBy)
		Xsqlite3ExprDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpLimit)
		if (*Select)(unsafe.Pointer(p)).FpWith != 0 {
			Xsqlite3WithDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpWith)
		}
		if (*Select)(unsafe.Pointer(p)).FpWinDefn != 0 {
			Xsqlite3WindowListDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpWinDefn)
		}
		for (*Select)(unsafe.Pointer(p)).FpWin != 0 {
			Xsqlite3WindowUnlinkFromSelect(tls, (*Select)(unsafe.Pointer(p)).FpWin)
		}
		if bFree != 0 {
			Xsqlite3DbNNFreeNN(tls, db, p)
		}
		p = pPrior
		bFree = 1
	}
}

func Xsqlite3SelectDestInit(tls *libc.TLS, pDest uintptr, eDest int32, iParm int32) {
	(*SelectDest)(unsafe.Pointer(pDest)).FeDest = U8(eDest)
	(*SelectDest)(unsafe.Pointer(pDest)).FiSDParm = iParm
	(*SelectDest)(unsafe.Pointer(pDest)).FiSDParm2 = 0
	(*SelectDest)(unsafe.Pointer(pDest)).FzAffSdst = uintptr(0)
	(*SelectDest)(unsafe.Pointer(pDest)).FiSdst = 0
	(*SelectDest)(unsafe.Pointer(pDest)).FnSdst = 0
}

func Xsqlite3SelectNew(tls *libc.TLS, pParse uintptr, pEList uintptr, pSrc uintptr, pWhere uintptr, pGroupBy uintptr, pHaving uintptr, pOrderBy uintptr, selFlags U32, pLimit uintptr) uintptr {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	var pNew uintptr
	var pAllocated uintptr

	pAllocated = libc.AssignUintptr(&pNew, Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(Select{}))))
	if pNew == uintptr(0) {
		pNew = bp
	}
	if pEList == uintptr(0) {
		pEList = Xsqlite3ExprListAppend(tls, pParse, uintptr(0),
			Xsqlite3Expr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_ASTERISK, uintptr(0)))
	}
	(*Select)(unsafe.Pointer(pNew)).FpEList = pEList
	(*Select)(unsafe.Pointer(pNew)).Fop = U8(TK_SELECT)
	(*Select)(unsafe.Pointer(pNew)).FselFlags = selFlags
	(*Select)(unsafe.Pointer(pNew)).FiLimit = 0
	(*Select)(unsafe.Pointer(pNew)).FiOffset = 0
	(*Select)(unsafe.Pointer(pNew)).FselId = U32(libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnSelect, 1))
	*(*int32)(unsafe.Pointer(pNew + 20)) = -1
	*(*int32)(unsafe.Pointer(pNew + 20 + 1*4)) = -1
	(*Select)(unsafe.Pointer(pNew)).FnSelectRow = int16(0)
	if pSrc == uintptr(0) {
		pSrc = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(SrcList{})))
	}
	(*Select)(unsafe.Pointer(pNew)).FpSrc = pSrc
	(*Select)(unsafe.Pointer(pNew)).FpWhere = pWhere
	(*Select)(unsafe.Pointer(pNew)).FpGroupBy = pGroupBy
	(*Select)(unsafe.Pointer(pNew)).FpHaving = pHaving
	(*Select)(unsafe.Pointer(pNew)).FpOrderBy = pOrderBy
	(*Select)(unsafe.Pointer(pNew)).FpPrior = uintptr(0)
	(*Select)(unsafe.Pointer(pNew)).FpNext = uintptr(0)
	(*Select)(unsafe.Pointer(pNew)).FpLimit = pLimit
	(*Select)(unsafe.Pointer(pNew)).FpWith = uintptr(0)
	(*Select)(unsafe.Pointer(pNew)).FpWin = uintptr(0)
	(*Select)(unsafe.Pointer(pNew)).FpWinDefn = uintptr(0)
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		clearSelect(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pNew, libc.Bool32(pNew != bp))
		pAllocated = uintptr(0)
	} else {
	}
	return pAllocated
}

func Xsqlite3SelectDelete(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		clearSelect(tls, db, p, 1)
	}
}

func findRightmost(tls *libc.TLS, p uintptr) uintptr {
	for (*Select)(unsafe.Pointer(p)).FpNext != 0 {
		p = (*Select)(unsafe.Pointer(p)).FpNext
	}
	return p
}

func Xsqlite3JoinType(tls *libc.TLS, pParse uintptr, pA uintptr, pB uintptr, pC uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var jointype int32 = 0

	var p uintptr
	var i int32
	var j int32
	*(*uintptr)(unsafe.Pointer(bp + 40)) = pA
	*(*uintptr)(unsafe.Pointer(bp + 40 + 1*8)) = pB
	*(*uintptr)(unsafe.Pointer(bp + 40 + 2*8)) = pC
	for i = 0; i < 3 && *(*uintptr)(unsafe.Pointer(bp + 40 + uintptr(i)*8)) != 0; i++ {
		p = *(*uintptr)(unsafe.Pointer(bp + 40 + uintptr(i)*8))
		for j = 0; j < int32(uint64(unsafe.Sizeof(aKeyword))/uint64(unsafe.Sizeof(struct {
			Fi     U8
			FnChar U8
			Fcode  U8
		}{}))); j++ {
			if (*Token)(unsafe.Pointer(p)).Fn == uint32(aKeyword[j].FnChar) &&
				Xsqlite3_strnicmp(tls, (*Token)(unsafe.Pointer(p)).Fz, uintptr(unsafe.Pointer(&zKeyText))+uintptr(aKeyword[j].Fi), int32((*Token)(unsafe.Pointer(p)).Fn)) == 0 {
				jointype = jointype | int32(aKeyword[j].Fcode)
				break
			}
		}

		if j >= int32(uint64(unsafe.Sizeof(aKeyword))/uint64(unsafe.Sizeof(struct {
			Fi     U8
			FnChar U8
			Fcode  U8
		}{}))) {
			jointype = jointype | JT_ERROR
			break
		}
	}
	if jointype&(JT_INNER|JT_OUTER) == JT_INNER|JT_OUTER || jointype&JT_ERROR != 0 || jointype&(JT_OUTER|JT_LEFT|JT_RIGHT) == JT_OUTER {
		var zSp1 uintptr = ts + 14304
		var zSp2 uintptr = ts + 14304
		if pB == uintptr(0) {
			zSp1++
		}
		if pC == uintptr(0) {
			zSp2++
		}
		Xsqlite3ErrorMsg(tls, pParse,
			ts+22127, libc.VaList(bp, pA, zSp1, pB, zSp2, pC))
		jointype = JT_INNER
	}
	return jointype
}

var zKeyText = *(*[34]uint8)(unsafe.Pointer(ts + 22157))
var aKeyword = [7]struct {
	Fi     U8
	FnChar U8
	Fcode  U8
}{
	{FnChar: U8(7), Fcode: U8(JT_NATURAL)},
	{Fi: U8(6), FnChar: U8(4), Fcode: U8(JT_LEFT | JT_OUTER)},
	{Fi: U8(10), FnChar: U8(5), Fcode: U8(JT_OUTER)},
	{Fi: U8(14), FnChar: U8(5), Fcode: U8(JT_RIGHT | JT_OUTER)},
	{Fi: U8(19), FnChar: U8(4), Fcode: U8(JT_LEFT | JT_RIGHT | JT_OUTER)},
	{Fi: U8(23), FnChar: U8(5), Fcode: U8(JT_INNER)},
	{Fi: U8(28), FnChar: U8(5), Fcode: U8(JT_INNER | JT_CROSS)},
}

func Xsqlite3ColumnIndex(tls *libc.TLS, pTab uintptr, zCol uintptr) int32 {
	var i int32
	var h U8 = Xsqlite3StrIHash(tls, zCol)
	var pCol uintptr
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol
	i = 0
__1:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __3
	}
	{
		if int32((*Column)(unsafe.Pointer(pCol)).FhName) == int32(h) && Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName, zCol) == 0 {
			return i
		}

	}
	goto __2
__2:
	pCol += 24
	i++
	goto __1
	goto __3
__3:
	;
	return -1
}

func Xsqlite3SrcItemColumnUsed(tls *libc.TLS, pItem uintptr, iCol int32) {
	if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x2000>>13)) != 0 {
		var pResults uintptr

		pResults = (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpSelect)).FpEList

		libc.SetBitFieldPtr16Uint32(pResults+8+uintptr(iCol)*32+16+4, uint32(1), 6, 0x40)
	}
}

func tableAndColumnIndex(tls *libc.TLS, pSrc uintptr, iStart int32, iEnd int32, zCol uintptr, piTab uintptr, piCol uintptr, bIgnoreHidden int32) int32 {
	var i int32
	var iCol int32

	for i = iStart; i <= iEnd; i++ {
		iCol = Xsqlite3ColumnIndex(tls, (*SrcItem)(unsafe.Pointer(pSrc+8+uintptr(i)*104)).FpTab, zCol)
		if iCol >= 0 &&
			(bIgnoreHidden == 0 || libc.Bool32(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pSrc+8+uintptr(i)*104)).FpTab)).FaCol+uintptr(iCol)*24)).FcolFlags)&COLFLAG_HIDDEN != 0) == 0) {
			if piTab != 0 {
				Xsqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(i)*104, iCol)
				*(*int32)(unsafe.Pointer(piTab)) = i
				*(*int32)(unsafe.Pointer(piCol)) = iCol
			}
			return 1
		}
	}
	return 0
}

func Xsqlite3SetJoinExpr(tls *libc.TLS, p uintptr, iTable int32, joinFlag U32) {
	for p != 0 {
		*(*U32)(unsafe.Pointer(p + 4)) |= joinFlag

		*(*int32)(unsafe.Pointer(p + 52)) = iTable
		if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_FUNCTION {
			if *(*uintptr)(unsafe.Pointer(p + 32)) != 0 {
				var i int32
				for i = 0; i < (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32)))).FnExpr; i++ {
					Xsqlite3SetJoinExpr(tls, (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32))+8+uintptr(i)*32)).FpExpr, iTable, joinFlag)
				}
			}
		}
		Xsqlite3SetJoinExpr(tls, (*Expr)(unsafe.Pointer(p)).FpLeft, iTable, joinFlag)
		p = (*Expr)(unsafe.Pointer(p)).FpRight
	}
}

func unsetJoinExpr(tls *libc.TLS, p uintptr, iTable int32, nullable int32) {
	for p != 0 {
		if iTable < 0 || (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_OuterON) != U32(0) && *(*int32)(unsafe.Pointer(p + 52)) == iTable {
			*(*U32)(unsafe.Pointer(p + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_OuterON | EP_InnerON))
			if iTable >= 0 {
				*(*U32)(unsafe.Pointer(p + 4)) |= U32(EP_InnerON)
			}
		}
		if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_COLUMN && (*Expr)(unsafe.Pointer(p)).FiTable == iTable && !(nullable != 0) {
			*(*U32)(unsafe.Pointer(p + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_CanBeNull))
		}
		if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_FUNCTION {
			if *(*uintptr)(unsafe.Pointer(p + 32)) != 0 {
				var i int32
				for i = 0; i < (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32)))).FnExpr; i++ {
					unsetJoinExpr(tls, (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 32))+8+uintptr(i)*32)).FpExpr, iTable, nullable)
				}
			}
		}
		unsetJoinExpr(tls, (*Expr)(unsafe.Pointer(p)).FpLeft, iTable, nullable)
		p = (*Expr)(unsafe.Pointer(p)).FpRight
	}
}

func sqlite3ProcessJoin(tls *libc.TLS, pParse uintptr, p uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pSrc uintptr
	var i int32
	var j int32
	var pLeft uintptr
	var pRight uintptr

	pSrc = (*Select)(unsafe.Pointer(p)).FpSrc
	pLeft = pSrc + 8
	pRight = pLeft + 1*104
	i = 0
__1:
	if !(i < (*SrcList)(unsafe.Pointer(pSrc)).FnSrc-1) {
		goto __3
	}
	{
		var pRightTab uintptr = (*SrcItem)(unsafe.Pointer(pRight)).FpTab
		var joinType U32

		if (*SrcItem)(unsafe.Pointer(pLeft)).FpTab == uintptr(0) || pRightTab == uintptr(0) {
			goto __2
		}
		if int32((*SrcItem)(unsafe.Pointer(pRight)).Ffg.Fjointype)&JT_OUTER != 0 {
			joinType = uint32(EP_OuterON)
		} else {
			joinType = uint32(EP_InnerON)
		}

		if int32((*SrcItem)(unsafe.Pointer(pRight)).Ffg.Fjointype)&JT_NATURAL != 0 {
			var pUsing uintptr = uintptr(0)
			if uint32(int32(*(*uint16)(unsafe.Pointer(pRight + 60 + 4))&0x400>>10)) != 0 || *(*uintptr)(unsafe.Pointer(pRight + 72)) != 0 {
				Xsqlite3ErrorMsg(tls, pParse,
					ts+22191, libc.VaList(bp, 0))
				return 1
			}
			for j = 0; j < int32((*Table)(unsafe.Pointer(pRightTab)).FnCol); j++ {
				var zName uintptr

				if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pRightTab)).FaCol+uintptr(j)*24)).FcolFlags)&COLFLAG_HIDDEN != 0 {
					continue
				}
				zName = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pRightTab)).FaCol + uintptr(j)*24)).FzCnName
				if tableAndColumnIndex(tls, pSrc, 0, i, zName, uintptr(0), uintptr(0), 1) != 0 {
					pUsing = Xsqlite3IdListAppend(tls, pParse, pUsing, uintptr(0))
					if pUsing != 0 {
						(*IdList_item)(unsafe.Pointer(pUsing + 8 + uintptr((*IdList)(unsafe.Pointer(pUsing)).FnId-1)*16)).FzName = Xsqlite3DbStrDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, zName)
					}
				}
			}
			if pUsing != 0 {
				libc.SetBitFieldPtr16Uint32(pRight+60+4, uint32(1), 10, 0x400)
				libc.SetBitFieldPtr16Uint32(pRight+60+4, uint32(1), 12, 0x1000)
				*(*uintptr)(unsafe.Pointer(pRight + 72)) = pUsing
			}
			if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
				return 1
			}
		}

		if uint32(int32(*(*uint16)(unsafe.Pointer(pRight + 60 + 4))&0x400>>10)) != 0 {
			var pList uintptr = *(*uintptr)(unsafe.Pointer(pRight + 72))
			var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

			for j = 0; j < (*IdList)(unsafe.Pointer(pList)).FnId; j++ {
				var zName uintptr

				var iRightCol int32
				var pE1 uintptr
				var pE2 uintptr
				var pEq uintptr

				zName = (*IdList_item)(unsafe.Pointer(pList + 8 + uintptr(j)*16)).FzName
				iRightCol = Xsqlite3ColumnIndex(tls, pRightTab, zName)
				if iRightCol < 0 ||
					tableAndColumnIndex(tls, pSrc, 0, i, zName, bp+24, bp+28,
						int32(*(*uint16)(unsafe.Pointer(pRight + 60 + 4))&0x1000>>12)) == 0 {
					Xsqlite3ErrorMsg(tls, pParse,
						ts+22241, libc.VaList(bp+8, zName))
					return 1
				}
				pE1 = Xsqlite3CreateColumnExpr(tls, db, pSrc, *(*int32)(unsafe.Pointer(bp + 24)), *(*int32)(unsafe.Pointer(bp + 28)))
				Xsqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(*(*int32)(unsafe.Pointer(bp + 24)))*104, *(*int32)(unsafe.Pointer(bp + 28)))
				if int32((*SrcItem)(unsafe.Pointer(pSrc+8)).Ffg.Fjointype)&JT_LTORJ != 0 {
					var pFuncArgs uintptr = uintptr(0)
					for tableAndColumnIndex(tls, pSrc, *(*int32)(unsafe.Pointer(bp + 24))+1, i, zName, bp+24, bp+28,
						int32(*(*uint16)(unsafe.Pointer(pRight + 60 + 4))&0x1000>>12)) != 0 {
						if int32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(*(*int32)(unsafe.Pointer(bp + 24)))*104 + 60 + 4))&0x400>>10) == 0 ||
							Xsqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(*(*int32)(unsafe.Pointer(bp + 24)))*104 + 72)), zName) < 0 {
							Xsqlite3ErrorMsg(tls, pParse, ts+22305,
								libc.VaList(bp+16, zName))
							break
						}
						pFuncArgs = Xsqlite3ExprListAppend(tls, pParse, pFuncArgs, pE1)
						pE1 = Xsqlite3CreateColumnExpr(tls, db, pSrc, *(*int32)(unsafe.Pointer(bp + 24)), *(*int32)(unsafe.Pointer(bp + 28)))
						Xsqlite3SrcItemColumnUsed(tls, pSrc+8+uintptr(*(*int32)(unsafe.Pointer(bp + 24)))*104, *(*int32)(unsafe.Pointer(bp + 28)))
					}
					if pFuncArgs != 0 {
						pFuncArgs = Xsqlite3ExprListAppend(tls, pParse, pFuncArgs, pE1)
						pE1 = Xsqlite3ExprFunction(tls, pParse, pFuncArgs, uintptr(unsafe.Pointer(&tkCoalesce)), 0)
					}
				}
				pE2 = Xsqlite3CreateColumnExpr(tls, db, pSrc, i+1, iRightCol)
				Xsqlite3SrcItemColumnUsed(tls, pRight, iRightCol)
				pEq = Xsqlite3PExpr(tls, pParse, TK_EQ, pE1, pE2)

				if pEq != 0 {
					*(*U32)(unsafe.Pointer(pEq + 4)) |= joinType

					*(*int32)(unsafe.Pointer(pEq + 52)) = (*Expr)(unsafe.Pointer(pE2)).FiTable
				}
				(*Select)(unsafe.Pointer(p)).FpWhere = Xsqlite3ExprAnd(tls, pParse, (*Select)(unsafe.Pointer(p)).FpWhere, pEq)
			}
		} else if *(*uintptr)(unsafe.Pointer(pRight + 72)) != 0 {
			Xsqlite3SetJoinExpr(tls, *(*uintptr)(unsafe.Pointer(pRight + 72)), (*SrcItem)(unsafe.Pointer(pRight)).FiCursor, joinType)
			(*Select)(unsafe.Pointer(p)).FpWhere = Xsqlite3ExprAnd(tls, pParse, (*Select)(unsafe.Pointer(p)).FpWhere, *(*uintptr)(unsafe.Pointer(pRight + 72)))
			*(*uintptr)(unsafe.Pointer(pRight + 72)) = uintptr(0)
			libc.SetBitFieldPtr16Uint32(pRight+60+4, uint32(1), 11, 0x800)
		}

	}
	goto __2
__2:
	i++
	pRight += 104
	pLeft += 104
	goto __1
	goto __3
__3:
	;
	return 0
}

var tkCoalesce = Token{Fz: ts + 9801, Fn: uint32(8)}

type RowLoadInfo = RowLoadInfo1

func innerLoopLoadRow(tls *libc.TLS, pParse uintptr, pSelect uintptr, pInfo uintptr) {
	Xsqlite3ExprCodeExprList(tls, pParse, (*Select)(unsafe.Pointer(pSelect)).FpEList, (*RowLoadInfo)(unsafe.Pointer(pInfo)).FregResult,
		0, (*RowLoadInfo)(unsafe.Pointer(pInfo)).FecelFlags)
}

func makeSorterRecord(tls *libc.TLS, pParse uintptr, pSort uintptr, pSelect uintptr, regBase int32, nBase int32) int32 {
	var nOBSat int32 = (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var regOut int32 = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	if (*SortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad != 0 {
		innerLoopLoadRow(tls, pParse, pSelect, (*SortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad)
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regOut)
	return regOut
}

func pushOntoSorter(tls *libc.TLS, pParse uintptr, pSort uintptr, pSelect uintptr, regData int32, regOrigData int32, nData int32, nPrefixReg int32) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var bSeq int32 = libc.Bool32(int32((*SortCtx)(unsafe.Pointer(pSort)).FsortFlags)&SORTFLAG_UseSorter == 0)
	var nExpr int32 = (*ExprList)(unsafe.Pointer((*SortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr
	var nBase int32 = nExpr + bSeq + nData
	var regBase int32
	var regRecord int32 = 0
	var nOBSat int32 = (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat
	var op int32
	var iLimit int32
	var iSkip int32 = 0

	if nPrefixReg != 0 {
		regBase = regData - nPrefixReg
	} else {
		regBase = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nBase
	}

	if (*Select)(unsafe.Pointer(pSelect)).FiOffset != 0 {
		iLimit = (*Select)(unsafe.Pointer(pSelect)).FiOffset + 1
	} else {
		iLimit = (*Select)(unsafe.Pointer(pSelect)).FiLimit
	}
	(*SortCtx)(unsafe.Pointer(pSort)).FlabelDone = Xsqlite3VdbeMakeLabel(tls, pParse)
	Xsqlite3ExprCodeExprList(tls, pParse, (*SortCtx)(unsafe.Pointer(pSort)).FpOrderBy, regBase, regOrigData,
		uint8(SQLITE_ECEL_DUP|func() int32 {
			if regOrigData != 0 {
				return SQLITE_ECEL_REF
			}
			return 0
		}()))
	if bSeq != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_Sequence, (*SortCtx)(unsafe.Pointer(pSort)).FiECursor, regBase+nExpr)
	}
	if nPrefixReg == 0 && nData > 0 {
		Xsqlite3ExprCodeMove(tls, pParse, regData, regBase+nExpr+bSeq, nData)
	}
	if nOBSat > 0 {
		var regPrevKey int32
		var addrFirst int32
		var addrJmp int32
		var pOp uintptr
		var nKey int32
		var pKI uintptr

		regRecord = makeSorterRecord(tls, pParse, pSort, pSelect, regBase, nBase)
		regPrevKey = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat
		nKey = nExpr - (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat + bSeq
		if bSeq != 0 {
			addrFirst = Xsqlite3VdbeAddOp1(tls, v, OP_IfNot, regBase+nExpr)
		} else {
			addrFirst = Xsqlite3VdbeAddOp1(tls, v, OP_SequenceTest, (*SortCtx)(unsafe.Pointer(pSort)).FiECursor)
		}

		Xsqlite3VdbeAddOp3(tls, v, OP_Compare, regPrevKey, regBase, (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat)
		pOp = Xsqlite3VdbeGetOp(tls, v, (*SortCtx)(unsafe.Pointer(pSort)).FaddrSortIndex)
		if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
			return
		}
		(*VdbeOp)(unsafe.Pointer(pOp)).Fp2 = nKey + nData
		pKI = *(*uintptr)(unsafe.Pointer(pOp + 16))
		libc.Xmemset(tls, (*KeyInfo)(unsafe.Pointer(pKI)).FaSortFlags, 0, uint64((*KeyInfo)(unsafe.Pointer(pKI)).FnKeyField))
		Xsqlite3VdbeChangeP4(tls, v, -1, pKI, -8)

		*(*uintptr)(unsafe.Pointer(pOp + 16)) = Xsqlite3KeyInfoFromExprList(tls, pParse, (*SortCtx)(unsafe.Pointer(pSort)).FpOrderBy, nOBSat,
			int32((*KeyInfo)(unsafe.Pointer(pKI)).FnAllField)-int32((*KeyInfo)(unsafe.Pointer(pKI)).FnKeyField)-1)
		pOp = uintptr(0)
		addrJmp = Xsqlite3VdbeCurrentAddr(tls, v)
		Xsqlite3VdbeAddOp3(tls, v, OP_Jump, addrJmp+1, 0, addrJmp+1)
		(*SortCtx)(unsafe.Pointer(pSort)).FlabelBkOut = Xsqlite3VdbeMakeLabel(tls, pParse)
		(*SortCtx)(unsafe.Pointer(pSort)).FregReturn = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*SortCtx)(unsafe.Pointer(pSort)).FregReturn, (*SortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
		Xsqlite3VdbeAddOp1(tls, v, OP_ResetSorter, (*SortCtx)(unsafe.Pointer(pSort)).FiECursor)
		if iLimit != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_IfNot, iLimit, (*SortCtx)(unsafe.Pointer(pSort)).FlabelDone)

		}
		Xsqlite3VdbeJumpHere(tls, v, addrFirst)
		Xsqlite3ExprCodeMove(tls, pParse, regBase, regPrevKey, (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat)
		Xsqlite3VdbeJumpHere(tls, v, addrJmp)
	}
	if iLimit != 0 {
		var iCsr int32 = (*SortCtx)(unsafe.Pointer(pSort)).FiECursor
		Xsqlite3VdbeAddOp2(tls, v, OP_IfNotZero, iLimit, Xsqlite3VdbeCurrentAddr(tls, v)+4)

		Xsqlite3VdbeAddOp2(tls, v, OP_Last, iCsr, 0)
		iSkip = Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxLE,
			iCsr, 0, regBase+nOBSat, nExpr-nOBSat)

		Xsqlite3VdbeAddOp1(tls, v, OP_Delete, iCsr)
	}
	if regRecord == 0 {
		regRecord = makeSorterRecord(tls, pParse, pSort, pSelect, regBase, nBase)
	}
	if int32((*SortCtx)(unsafe.Pointer(pSort)).FsortFlags)&SORTFLAG_UseSorter != 0 {
		op = OP_SorterInsert
	} else {
		op = OP_IdxInsert
	}
	Xsqlite3VdbeAddOp4Int(tls, v, op, (*SortCtx)(unsafe.Pointer(pSort)).FiECursor, regRecord,
		regBase+nOBSat, nBase-nOBSat)
	if iSkip != 0 {
		Xsqlite3VdbeChangeP2(tls, v, iSkip,
			func() int32 {
				if (*SortCtx)(unsafe.Pointer(pSort)).FlabelOBLopt != 0 {
					return (*SortCtx)(unsafe.Pointer(pSort)).FlabelOBLopt
				}
				return Xsqlite3VdbeCurrentAddr(tls, v)
			}())
	}
}

func codeOffset(tls *libc.TLS, v uintptr, iOffset int32, iContinue int32) {
	if iOffset > 0 {
		Xsqlite3VdbeAddOp3(tls, v, OP_IfPos, iOffset, iContinue, 1)
		Xsqlite3VdbeComment(tls, v, ts+22342, 0)
	}
}

func codeDistinct(tls *libc.TLS, pParse uintptr, eTnctType int32, iTab int32, addrRepeat int32, pEList uintptr, regElem int32) int32 {
	var iRet int32 = 0
	var nResultCol int32 = (*ExprList)(unsafe.Pointer(pEList)).FnExpr
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	switch eTnctType {
	case WHERE_DISTINCT_ORDERED:
		{
			var i int32
			var iJump int32
			var regPrev int32

			iRet = libc.AssignInt32(&regPrev, (*Parse)(unsafe.Pointer(pParse)).FnMem+1)
			*(*int32)(unsafe.Pointer(pParse + 56)) += nResultCol

			iJump = Xsqlite3VdbeCurrentAddr(tls, v) + nResultCol
			for i = 0; i < nResultCol; i++ {
				var pColl uintptr = Xsqlite3ExprCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(i)*32)).FpExpr)
				if i < nResultCol-1 {
					Xsqlite3VdbeAddOp3(tls, v, OP_Ne, regElem+i, iJump, regPrev+i)

				} else {
					Xsqlite3VdbeAddOp3(tls, v, OP_Eq, regElem+i, addrRepeat, regPrev+i)

				}
				Xsqlite3VdbeChangeP4(tls, v, -1, pColl, -2)
				Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
			}

			Xsqlite3VdbeAddOp3(tls, v, OP_Copy, regElem, regPrev, nResultCol-1)
			break

		}

	case WHERE_DISTINCT_UNIQUE:
		{
			break

		}

	default:
		{
			var r1 int32 = Xsqlite3GetTempReg(tls, pParse)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, iTab, addrRepeat, regElem, nResultCol)

			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regElem, nResultCol, r1)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iTab, r1, regElem, nResultCol)
			Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
			Xsqlite3ReleaseTempReg(tls, pParse, r1)
			iRet = iTab
			break

		}
	}

	return iRet
}

func fixDistinctOpenEph(tls *libc.TLS, pParse uintptr, eTnctType int32, iVal int32, iOpenEphAddr int32) {
	if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 &&
		(eTnctType == WHERE_DISTINCT_UNIQUE || eTnctType == WHERE_DISTINCT_ORDERED) {
		var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
		Xsqlite3VdbeChangeToNoop(tls, v, iOpenEphAddr)
		if int32((*VdbeOp)(unsafe.Pointer(Xsqlite3VdbeGetOp(tls, v, iOpenEphAddr+1))).Fopcode) == OP_Explain {
			Xsqlite3VdbeChangeToNoop(tls, v, iOpenEphAddr+1)
		}
		if eTnctType == WHERE_DISTINCT_ORDERED {
			var pOp uintptr = Xsqlite3VdbeGetOp(tls, v, iOpenEphAddr)
			(*VdbeOp)(unsafe.Pointer(pOp)).Fopcode = U8(OP_Null)
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp1 = 1
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp2 = iVal
		}
	}
}

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 v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var i int32
	var hasDistinct int32
	var eDest int32 = int32((*SelectDest)(unsafe.Pointer(pDest)).FeDest)
	var iParm int32 = (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm
	var nResultCol int32
	var nPrefixReg int32 = 0

	var regResult int32
	var regOrig int32

	if pDistinct != 0 {
		hasDistinct = int32((*DistinctCtx)(unsafe.Pointer(pDistinct)).FeTnctType)
	} else {
		hasDistinct = WHERE_DISTINCT_NOOP
	}
	if pSort != 0 && (*SortCtx)(unsafe.Pointer(pSort)).FpOrderBy == uintptr(0) {
		pSort = uintptr(0)
	}
	if pSort == uintptr(0) && !(hasDistinct != 0) {
		codeOffset(tls, v, (*Select)(unsafe.Pointer(p)).FiOffset, iContinue)
	}

	nResultCol = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr

	if (*SelectDest)(unsafe.Pointer(pDest)).FiSdst == 0 {
		if pSort != 0 {
			nPrefixReg = (*ExprList)(unsafe.Pointer((*SortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr
			if !(int32((*SortCtx)(unsafe.Pointer(pSort)).FsortFlags)&SORTFLAG_UseSorter != 0) {
				nPrefixReg++
			}
			*(*int32)(unsafe.Pointer(pParse + 56)) += nPrefixReg
		}
		(*SelectDest)(unsafe.Pointer(pDest)).FiSdst = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nResultCol
	} else if (*SelectDest)(unsafe.Pointer(pDest)).FiSdst+nResultCol > (*Parse)(unsafe.Pointer(pParse)).FnMem {
		*(*int32)(unsafe.Pointer(pParse + 56)) += nResultCol
	}
	(*SelectDest)(unsafe.Pointer(pDest)).FnSdst = nResultCol
	regOrig = libc.AssignInt32(&regResult, (*SelectDest)(unsafe.Pointer(pDest)).FiSdst)
	if srcTab >= 0 {
		for i = 0; i < nResultCol; i++ {
			Xsqlite3VdbeAddOp3(tls, v, OP_Column, srcTab, i, regResult+i)
			Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp, (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList+8+uintptr(i)*32)).FzEName))
		}
	} else if eDest != SRT_Exists {
		var ecelFlags U8
		var pEList uintptr
		if eDest == SRT_Mem || eDest == SRT_Output || eDest == SRT_Coroutine {
			ecelFlags = U8(SQLITE_ECEL_DUP)
		} else {
			ecelFlags = U8(0)
		}
		if pSort != 0 && hasDistinct == 0 && eDest != SRT_EphemTab && eDest != SRT_Table {
			ecelFlags = U8(int32(ecelFlags) | (SQLITE_ECEL_OMITREF | SQLITE_ECEL_REF))

			for i = (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat; i < (*ExprList)(unsafe.Pointer((*SortCtx)(unsafe.Pointer(pSort)).FpOrderBy)).FnExpr; i++ {
				var j int32
				if libc.AssignInt32(&j, int32(*(*U16)(unsafe.Pointer((*SortCtx)(unsafe.Pointer(pSort)).FpOrderBy + 8 + uintptr(i)*32 + 24)))) > 0 {
					*(*U16)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList + 8 + uintptr(j-1)*32 + 24)) = U16(i + 1 - (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat)
				}
			}

			pEList = (*Select)(unsafe.Pointer(p)).FpEList
			for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
				if int32(*(*U16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 24))) > 0 {
					nResultCol--
					regOrig = 0
				}
			}

		}
		(*RowLoadInfo)(unsafe.Pointer(bp + 8)).FregResult = regResult
		(*RowLoadInfo)(unsafe.Pointer(bp + 8)).FecelFlags = ecelFlags
		if (*Select)(unsafe.Pointer(p)).FiLimit != 0 &&
			int32(ecelFlags)&SQLITE_ECEL_OMITREF != 0 &&
			nPrefixReg > 0 {
			(*SortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad = bp + 8
			regOrig = 0
		} else {
			innerLoopLoadRow(tls, pParse, p, bp+8)
		}
	}

	if hasDistinct != 0 {
		var eType int32 = int32((*DistinctCtx)(unsafe.Pointer(pDistinct)).FeTnctType)
		var iTab int32 = (*DistinctCtx)(unsafe.Pointer(pDistinct)).FtabTnct

		iTab = codeDistinct(tls, pParse, eType, iTab, iContinue, (*Select)(unsafe.Pointer(p)).FpEList, regResult)
		fixDistinctOpenEph(tls, pParse, eType, iTab, (*DistinctCtx)(unsafe.Pointer(pDistinct)).FaddrTnct)
		if pSort == uintptr(0) {
			codeOffset(tls, v, (*Select)(unsafe.Pointer(p)).FiOffset, iContinue)
		}
	}

	switch eDest {
	case SRT_Union:
		{
			var r1 int32
			r1 = Xsqlite3GetTempReg(tls, pParse)
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regResult, nResultCol, r1)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iParm, r1, regResult, nResultCol)
			Xsqlite3ReleaseTempReg(tls, pParse, r1)
			break

		}

	case SRT_Except:
		{
			Xsqlite3VdbeAddOp3(tls, v, OP_IdxDelete, iParm, regResult, nResultCol)
			break

		}

	case SRT_Fifo:
		fallthrough
	case SRT_DistFifo:
		fallthrough
	case SRT_Table:
		fallthrough
	case SRT_EphemTab:
		{
			var r1 int32 = Xsqlite3GetTempRange(tls, pParse, nPrefixReg+1)

			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regResult, nResultCol, r1+nPrefixReg)
			if eDest == SRT_DistFifo {
				var addr int32 = Xsqlite3VdbeCurrentAddr(tls, v) + 4
				Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, iParm+1, addr, r1, 0)

				Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iParm+1, r1, regResult, nResultCol)

			}
			if pSort != 0 {
				pushOntoSorter(tls, pParse, pSort, p, r1+nPrefixReg, regOrig, 1, nPrefixReg)
			} else {
				var r2 int32 = Xsqlite3GetTempReg(tls, pParse)
				Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, iParm, r2)
				Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iParm, r1, r2)
				Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
				Xsqlite3ReleaseTempReg(tls, pParse, r2)
			}
			Xsqlite3ReleaseTempRange(tls, pParse, r1, nPrefixReg+1)
			break

		}

	case SRT_Upfrom:
		{
			if pSort != 0 {
				pushOntoSorter(tls,
					pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
			} else {
				var i2 int32 = (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm2
				var r1 int32 = Xsqlite3GetTempReg(tls, pParse)

				Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, regResult, iBreak)

				Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord,
					regResult+libc.Bool32(i2 < 0), nResultCol-libc.Bool32(i2 < 0), r1)
				if i2 < 0 {
					Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iParm, r1, regResult)
				} else {
					Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iParm, r1, regResult, i2)
				}
			}
			break

		}

	case SRT_Set:
		{
			if pSort != 0 {
				pushOntoSorter(tls,
					pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
			} else {
				var r1 int32 = Xsqlite3GetTempReg(tls, pParse)

				Xsqlite3VdbeAddOp4(tls, v, OP_MakeRecord, regResult, nResultCol,
					r1, (*SelectDest)(unsafe.Pointer(pDest)).FzAffSdst, nResultCol)
				Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iParm, r1, regResult, nResultCol)
				Xsqlite3ReleaseTempReg(tls, pParse, r1)
			}
			break

		}

	case SRT_Exists:
		{
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, iParm)

			break

		}

	case SRT_Mem:
		{
			if pSort != 0 {
				pushOntoSorter(tls,
					pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg)
			} else {
			}
			break

		}

	case SRT_Coroutine:
		fallthrough
	case SRT_Output:
		{
			if pSort != 0 {
				pushOntoSorter(tls, pParse, pSort, p, regResult, regOrig, nResultCol,
					nPrefixReg)
			} else if eDest == SRT_Coroutine {
				Xsqlite3VdbeAddOp1(tls, v, OP_Yield, (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm)
			} else {
				Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, regResult, nResultCol)
			}
			break

		}

	case SRT_DistQueue:
		fallthrough
	case SRT_Queue:
		{
			var nKey int32
			var r1 int32
			var r2 int32
			var r3 int32
			var addrTest int32 = 0
			var pSO uintptr
			pSO = (*SelectDest)(unsafe.Pointer(pDest)).FpOrderBy

			nKey = (*ExprList)(unsafe.Pointer(pSO)).FnExpr
			r1 = Xsqlite3GetTempReg(tls, pParse)
			r2 = Xsqlite3GetTempRange(tls, pParse, nKey+2)
			r3 = r2 + nKey + 1
			if eDest == SRT_DistQueue {
				addrTest = Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, iParm+1, 0,
					regResult, nResultCol)

			}
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regResult, nResultCol, r3)
			if eDest == SRT_DistQueue {
				Xsqlite3VdbeAddOp2(tls, v, OP_IdxInsert, iParm+1, r3)
				Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
			}
			for i = 0; i < nKey; i++ {
				Xsqlite3VdbeAddOp2(tls, v, OP_SCopy,
					regResult+int32(*(*U16)(unsafe.Pointer(pSO + 8 + uintptr(i)*32 + 24)))-1,
					r2+i)
			}
			Xsqlite3VdbeAddOp2(tls, v, OP_Sequence, iParm, r2+nKey)
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, r2, nKey+2, r1)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iParm, r1, r2, nKey+2)
			if addrTest != 0 {
				Xsqlite3VdbeJumpHere(tls, v, addrTest)
			}
			Xsqlite3ReleaseTempReg(tls, pParse, r1)
			Xsqlite3ReleaseTempRange(tls, pParse, r2, nKey+2)
			break

		}

	default:
		{
			break

		}
	}

	if pSort == uintptr(0) && (*Select)(unsafe.Pointer(p)).FiLimit != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_DecrJumpZero, (*Select)(unsafe.Pointer(p)).FiLimit, iBreak)
	}
}

func Xsqlite3KeyInfoAlloc(tls *libc.TLS, db uintptr, N int32, X int32) uintptr {
	var nExtra int32 = int32(uint64(N+X)*(uint64(unsafe.Sizeof(uintptr(0)))+uint64(1)) - uint64(unsafe.Sizeof(uintptr(0))))
	var p uintptr = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(KeyInfo{}))+uint64(nExtra))
	if p != 0 {
		(*KeyInfo)(unsafe.Pointer(p)).FaSortFlags = p + 32 + uintptr(N+X)*8
		(*KeyInfo)(unsafe.Pointer(p)).FnKeyField = U16(N)
		(*KeyInfo)(unsafe.Pointer(p)).FnAllField = U16(N + X)
		(*KeyInfo)(unsafe.Pointer(p)).Fenc = (*Sqlite3)(unsafe.Pointer(db)).Fenc
		(*KeyInfo)(unsafe.Pointer(p)).Fdb = db
		(*KeyInfo)(unsafe.Pointer(p)).FnRef = U32(1)
		libc.Xmemset(tls, p+1*40, 0, uint64(nExtra))
	} else {
		return Xsqlite3OomFault(tls, db)
	}
	return p
}

func Xsqlite3KeyInfoUnref(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*KeyInfo)(unsafe.Pointer(p)).FnRef--
		if (*KeyInfo)(unsafe.Pointer(p)).FnRef == U32(0) {
			Xsqlite3DbNNFreeNN(tls, (*KeyInfo)(unsafe.Pointer(p)).Fdb, p)
		}
	}
}

func Xsqlite3KeyInfoRef(tls *libc.TLS, p uintptr) uintptr {
	if p != 0 {
		(*KeyInfo)(unsafe.Pointer(p)).FnRef++
	}
	return p
}

func Xsqlite3KeyInfoFromExprList(tls *libc.TLS, pParse uintptr, pList uintptr, iStart int32, nExtra int32) uintptr {
	var nExpr int32
	var pInfo uintptr
	var pItem uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var i int32

	nExpr = (*ExprList)(unsafe.Pointer(pList)).FnExpr
	pInfo = Xsqlite3KeyInfoAlloc(tls, db, nExpr-iStart, nExtra+1)
	if pInfo != 0 {
		i = iStart
		pItem = pList + 8 + uintptr(iStart)*32
	__1:
		if !(i < nExpr) {
			goto __3
		}
		{
			*(*uintptr)(unsafe.Pointer(pInfo + 32 + uintptr(i-iStart)*8)) = Xsqlite3ExprNNCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pInfo)).FaSortFlags + uintptr(i-iStart))) = (*ExprList_item)(unsafe.Pointer(pItem)).Ffg.FsortFlags

		}
		goto __2
	__2:
		i++
		pItem += 32
		goto __1
		goto __3
	__3:
	}
	return pInfo
}

func Xsqlite3SelectOpName(tls *libc.TLS, id int32) uintptr {
	var z uintptr
	switch id {
	case TK_ALL:
		z = ts + 22349
		break
	case TK_INTERSECT:
		z = ts + 22359
		break
	case TK_EXCEPT:
		z = ts + 22369
		break
	default:
		z = ts + 22376
		break
	}
	return z
}

func explainTempTable(tls *libc.TLS, pParse uintptr, zUsage uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+22382, libc.VaList(bp, zUsage))
}

func generateSortTail(tls *libc.TLS, pParse uintptr, p uintptr, pSort uintptr, nColumn int32, pDest uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var addrBreak int32 = (*SortCtx)(unsafe.Pointer(pSort)).FlabelDone
	var addrContinue int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
	var addr int32
	var addrOnce int32 = 0
	var iTab int32
	var pOrderBy uintptr = (*SortCtx)(unsafe.Pointer(pSort)).FpOrderBy
	var eDest int32 = int32((*SelectDest)(unsafe.Pointer(pDest)).FeDest)
	var iParm int32 = (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm
	var regRow int32
	var regRowid int32
	var iCol int32
	var nKey int32
	var iSortTab int32
	var i int32
	var bSeq int32
	var nRefKey int32 = 0
	var aOutEx uintptr = (*Select)(unsafe.Pointer(p)).FpEList + 8

	Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+22405, libc.VaList(bp, func() uintptr {
		if (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat > 0 {
			return ts + 22436
		}
		return ts + 1636
	}()))

	if (*SortCtx)(unsafe.Pointer(pSort)).FlabelBkOut != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*SortCtx)(unsafe.Pointer(pSort)).FregReturn, (*SortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
		Xsqlite3VdbeGoto(tls, v, addrBreak)
		Xsqlite3VdbeResolveLabel(tls, v, (*SortCtx)(unsafe.Pointer(pSort)).FlabelBkOut)
	}

	iTab = (*SortCtx)(unsafe.Pointer(pSort)).FiECursor
	if eDest == SRT_Output || eDest == SRT_Coroutine || eDest == SRT_Mem {
		if eDest == SRT_Mem && (*Select)(unsafe.Pointer(p)).FiOffset != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*SelectDest)(unsafe.Pointer(pDest)).FiSdst)
		}
		regRowid = 0
		regRow = (*SelectDest)(unsafe.Pointer(pDest)).FiSdst
	} else {
		regRowid = Xsqlite3GetTempReg(tls, pParse)
		if eDest == SRT_EphemTab || eDest == SRT_Table {
			regRow = Xsqlite3GetTempReg(tls, pParse)
			nColumn = 0
		} else {
			regRow = Xsqlite3GetTempRange(tls, pParse, nColumn)
		}
	}
	nKey = (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr - (*SortCtx)(unsafe.Pointer(pSort)).FnOBSat
	if int32((*SortCtx)(unsafe.Pointer(pSort)).FsortFlags)&SORTFLAG_UseSorter != 0 {
		var regSortOut int32 = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		iSortTab = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
		if (*SortCtx)(unsafe.Pointer(pSort)).FlabelBkOut != 0 {
			addrOnce = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
		}
		Xsqlite3VdbeAddOp3(tls, v, OP_OpenPseudo, iSortTab, regSortOut,
			nKey+1+nColumn+nRefKey)
		if addrOnce != 0 {
			Xsqlite3VdbeJumpHere(tls, v, addrOnce)
		}
		addr = 1 + Xsqlite3VdbeAddOp2(tls, v, OP_SorterSort, iTab, addrBreak)

		Xsqlite3VdbeAddOp3(tls, v, OP_SorterData, iTab, regSortOut, iSortTab)
		bSeq = 0
	} else {
		addr = 1 + Xsqlite3VdbeAddOp2(tls, v, OP_Sort, iTab, addrBreak)
		codeOffset(tls, v, (*Select)(unsafe.Pointer(p)).FiOffset, addrContinue)
		iSortTab = iTab
		bSeq = 1
		if (*Select)(unsafe.Pointer(p)).FiOffset > 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, (*Select)(unsafe.Pointer(p)).FiLimit, -1)
		}
	}
	i = 0
	iCol = nKey + bSeq - 1
	for ; i < nColumn; i++ {
		if int32(*(*U16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24))) == 0 {
			iCol++
		}
	}
	for i = nColumn - 1; i >= 0; i-- {
		{
			var iRead int32
			if *(*U16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24)) != 0 {
				iRead = int32(*(*U16)(unsafe.Pointer(aOutEx + uintptr(i)*32 + 24))) - 1
			} else {
				iRead = libc.PostDecInt32(&iCol, 1)
			}
			Xsqlite3VdbeAddOp3(tls, v, OP_Column, iSortTab, iRead, regRow+i)
			Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+8, (*ExprList_item)(unsafe.Pointer(aOutEx+uintptr(i)*32)).FzEName))

		}
	}

	switch eDest {
	case SRT_Table:
		fallthrough
	case SRT_EphemTab:
		{
			Xsqlite3VdbeAddOp3(tls, v, OP_Column, iSortTab, nKey+bSeq, regRow)
			Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, iParm, regRowid)
			Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iParm, regRow, regRowid)
			Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
			break

		}
	case SRT_Set:
		{
			Xsqlite3VdbeAddOp4(tls, v, OP_MakeRecord, regRow, nColumn, regRowid,
				(*SelectDest)(unsafe.Pointer(pDest)).FzAffSdst, nColumn)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iParm, regRowid, regRow, nColumn)
			break

		}
	case SRT_Mem:
		{
			break

		}
	case SRT_Upfrom:
		{
			var i2 int32 = (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm2
			var r1 int32 = Xsqlite3GetTempReg(tls, pParse)
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regRow+libc.Bool32(i2 < 0), nColumn-libc.Bool32(i2 < 0), r1)
			if i2 < 0 {
				Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iParm, r1, regRow)
			} else {
				Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iParm, r1, regRow, i2)
			}
			break

		}
	default:
		{
			if eDest == SRT_Output {
				Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, (*SelectDest)(unsafe.Pointer(pDest)).FiSdst, nColumn)
			} else {
				Xsqlite3VdbeAddOp1(tls, v, OP_Yield, (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm)
			}
			break

		}
	}
	if regRowid != 0 {
		if eDest == SRT_Set {
			Xsqlite3ReleaseTempRange(tls, pParse, regRow, nColumn)
		} else {
			Xsqlite3ReleaseTempReg(tls, pParse, regRow)
		}
		Xsqlite3ReleaseTempReg(tls, pParse, regRowid)
	}

	Xsqlite3VdbeResolveLabel(tls, v, addrContinue)
	if int32((*SortCtx)(unsafe.Pointer(pSort)).FsortFlags)&SORTFLAG_UseSorter != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_SorterNext, iTab, addr)
	} else {
		Xsqlite3VdbeAddOp2(tls, v, OP_Next, iTab, addr)
	}

	if (*SortCtx)(unsafe.Pointer(pSort)).FregReturn != 0 {
		Xsqlite3VdbeAddOp1(tls, v, OP_Return, (*SortCtx)(unsafe.Pointer(pSort)).FregReturn)
	}
	Xsqlite3VdbeResolveLabel(tls, v, addrBreak)
}

func columnTypeImpl(tls *libc.TLS, pNC uintptr, pExpr uintptr, pzOrigDb uintptr, pzOrigTab uintptr, pzOrigCol uintptr) uintptr {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var zType uintptr = uintptr(0)
	var j int32
	*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 72)) = uintptr(0)

	switch int32((*Expr)(unsafe.Pointer(pExpr)).Fop) {
	case TK_COLUMN:
		{
			var pTab uintptr = uintptr(0)
			var pS uintptr = uintptr(0)
			var iCol int32 = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)
			for pNC != 0 && !(pTab != 0) {
				var pTabList uintptr = (*NameContext)(unsafe.Pointer(pNC)).FpSrcList
				for j = 0; j < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc && (*SrcItem)(unsafe.Pointer(pTabList+8+uintptr(j)*104)).FiCursor != (*Expr)(unsafe.Pointer(pExpr)).FiTable; j++ {
				}
				if j < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc {
					pTab = (*SrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*104)).FpTab
					pS = (*SrcItem)(unsafe.Pointer(pTabList + 8 + uintptr(j)*104)).FpSelect
				} else {
					pNC = (*NameContext)(unsafe.Pointer(pNC)).FpNext
				}
			}

			if pTab == uintptr(0) {
				break
			}

			if pS != 0 {
				if iCol < (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pS)).FpEList)).FnExpr &&
					iCol >= 0 {
					var p uintptr = (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(pS)).FpEList + 8 + uintptr(iCol)*32)).FpExpr
					(*NameContext)(unsafe.Pointer(bp)).FpSrcList = (*Select)(unsafe.Pointer(pS)).FpSrc
					(*NameContext)(unsafe.Pointer(bp)).FpNext = pNC
					(*NameContext)(unsafe.Pointer(bp)).FpParse = (*NameContext)(unsafe.Pointer(pNC)).FpParse
					zType = columnTypeImpl(tls, bp, p, bp+56, bp+64, bp+72)
				}
			} else {
				if iCol < 0 {
					iCol = int32((*Table)(unsafe.Pointer(pTab)).FiPKey)
				}

				if iCol < 0 {
					zType = ts + 1201
					*(*uintptr)(unsafe.Pointer(bp + 72)) = ts + 11466
				} else {
					*(*uintptr)(unsafe.Pointer(bp + 72)) = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24)).FzCnName
					zType = Xsqlite3ColumnType(tls, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24, uintptr(0))
				}
				*(*uintptr)(unsafe.Pointer(bp + 64)) = (*Table)(unsafe.Pointer(pTab)).FzName
				if (*NameContext)(unsafe.Pointer(pNC)).FpParse != 0 && (*Table)(unsafe.Pointer(pTab)).FpSchema != 0 {
					var iDb int32 = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer((*NameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb, (*Table)(unsafe.Pointer(pTab)).FpSchema)
					*(*uintptr)(unsafe.Pointer(bp + 56)) = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer((*NameContext)(unsafe.Pointer(pNC)).FpParse)).Fdb)).FaDb + uintptr(iDb)*32)).FzDbSName
				}
			}
			break

		}
	case TK_SELECT:
		{
			var pS uintptr
			var p uintptr

			pS = *(*uintptr)(unsafe.Pointer(pExpr + 32))
			p = (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(pS)).FpEList + 8)).FpExpr
			(*NameContext)(unsafe.Pointer(bp + 80)).FpSrcList = (*Select)(unsafe.Pointer(pS)).FpSrc
			(*NameContext)(unsafe.Pointer(bp + 80)).FpNext = pNC
			(*NameContext)(unsafe.Pointer(bp + 80)).FpParse = (*NameContext)(unsafe.Pointer(pNC)).FpParse
			zType = columnTypeImpl(tls, bp+80, p, bp+56, bp+64, bp+72)
			break

		}
	}

	if pzOrigDb != 0 {
		*(*uintptr)(unsafe.Pointer(pzOrigDb)) = *(*uintptr)(unsafe.Pointer(bp + 56))
		*(*uintptr)(unsafe.Pointer(pzOrigTab)) = *(*uintptr)(unsafe.Pointer(bp + 64))
		*(*uintptr)(unsafe.Pointer(pzOrigCol)) = *(*uintptr)(unsafe.Pointer(bp + 72))
	}
	return zType
}

func generateColumnTypes(tls *libc.TLS, pParse uintptr, pTabList uintptr, pEList uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var i int32

	(*NameContext)(unsafe.Pointer(bp)).FpSrcList = pTabList
	(*NameContext)(unsafe.Pointer(bp)).FpParse = pParse
	(*NameContext)(unsafe.Pointer(bp)).FpNext = uintptr(0)
	for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
		var p uintptr = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32)).FpExpr
		var zType uintptr
		*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 72)) = uintptr(0)
		zType = columnTypeImpl(tls, bp, p, bp+56, bp+64, bp+72)

		Xsqlite3VdbeSetColName(tls, v, i, COLNAME_DATABASE, *(*uintptr)(unsafe.Pointer(bp + 56)), libc.UintptrFromInt32(-1))
		Xsqlite3VdbeSetColName(tls, v, i, COLNAME_TABLE, *(*uintptr)(unsafe.Pointer(bp + 64)), libc.UintptrFromInt32(-1))
		Xsqlite3VdbeSetColName(tls, v, i, COLNAME_COLUMN, *(*uintptr)(unsafe.Pointer(bp + 72)), libc.UintptrFromInt32(-1))
		Xsqlite3VdbeSetColName(tls, v, i, COLNAME_DECLTYPE, zType, libc.UintptrFromInt32(-1))
	}
}

func Xsqlite3GenerateColumnNames(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var i int32
	var pTab uintptr
	var pTabList uintptr
	var pEList uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var fullName int32
	var srcName int32

	if (*Parse)(unsafe.Pointer(pParse)).Fexplain != 0 {
		return
	}

	if (*Parse)(unsafe.Pointer(pParse)).FcolNamesSet != 0 {
		return
	}

	for (*Select)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		pSelect = (*Select)(unsafe.Pointer(pSelect)).FpPrior
	}

	pTabList = (*Select)(unsafe.Pointer(pSelect)).FpSrc
	pEList = (*Select)(unsafe.Pointer(pSelect)).FpEList

	(*Parse)(unsafe.Pointer(pParse)).FcolNamesSet = U8(1)
	fullName = libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_FullColNames) != uint64(0))
	srcName = libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ShortColNames) != uint64(0) || fullName != 0)
	Xsqlite3VdbeSetNumCols(tls, v, (*ExprList)(unsafe.Pointer(pEList)).FnExpr)
	for i = 0; i < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; i++ {
		var p uintptr = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32)).FpExpr

		if (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(i)*32)).FzEName != 0 && int32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*32 + 16 + 4))&0x3>>0) == ENAME_NAME {
			var zName uintptr = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32)).FzEName
			Xsqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName, libc.UintptrFromInt32(-1))
		} else if srcName != 0 && int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_COLUMN {
			var zCol uintptr
			var iCol int32 = int32((*Expr)(unsafe.Pointer(p)).FiColumn)
			pTab = *(*uintptr)(unsafe.Pointer(p + 64))

			if iCol < 0 {
				iCol = int32((*Table)(unsafe.Pointer(pTab)).FiPKey)
			}

			if iCol < 0 {
				zCol = ts + 11466
			} else {
				zCol = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24)).FzCnName
			}
			if fullName != 0 {
				var zName uintptr = uintptr(0)
				zName = Xsqlite3MPrintf(tls, db, ts+11397, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName, zCol))
				Xsqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zName, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})))
			} else {
				Xsqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, zCol, libc.UintptrFromInt32(-1))
			}
		} else {
			var z uintptr = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*32)).FzEName
			if z == uintptr(0) {
				z = Xsqlite3MPrintf(tls, db, ts+22451, libc.VaList(bp+16, i+1))
			} else {
				z = Xsqlite3DbStrDup(tls, db, z)
			}
			Xsqlite3VdbeSetColName(tls, v, i, COLNAME_NAME, z, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3OomClear})))
		}
	}
	generateColumnTypes(tls, pParse, pTabList, pEList)
}

func Xsqlite3ColumnsFromExprList(tls *libc.TLS, pParse uintptr, pEList uintptr, pnCol uintptr, paCol uintptr) int32 {
	bp := tls.Alloc(60)
	defer tls.Free(60)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var i int32
	var j int32

	var aCol uintptr
	var pCol uintptr
	var nCol int32
	var zName uintptr
	var nName int32

	var pTab uintptr

	Xsqlite3HashInit(tls, bp+32)
	if pEList != 0 {
		nCol = (*ExprList)(unsafe.Pointer(pEList)).FnExpr
		aCol = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Column{}))*uint64(nCol))

		if nCol > 32767 {
			nCol = 32767
		}
	} else {
		nCol = 0
		aCol = uintptr(0)
	}

	*(*I16)(unsafe.Pointer(pnCol)) = I16(nCol)
	*(*uintptr)(unsafe.Pointer(paCol)) = aCol

	i = 0
	pCol = aCol
__1:
	if !(i < nCol && !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0)) {
		goto __3
	}
	{
		var pX uintptr = pEList + 8 + uintptr(i)*32
		var pCollide uintptr

		if libc.AssignUintptr(&zName, (*ExprList_item)(unsafe.Pointer(pX)).FzEName) != uintptr(0) && int32(*(*uint16)(unsafe.Pointer(pX + 16 + 4))&0x3>>0) == ENAME_NAME {
		} else {
			var pColExpr uintptr = Xsqlite3ExprSkipCollateAndLikely(tls, (*ExprList_item)(unsafe.Pointer(pX)).FpExpr)
			for pColExpr != uintptr(0) && int32((*Expr)(unsafe.Pointer(pColExpr)).Fop) == TK_DOT {
				pColExpr = (*Expr)(unsafe.Pointer(pColExpr)).FpRight

			}
			if int32((*Expr)(unsafe.Pointer(pColExpr)).Fop) == TK_COLUMN &&
				(*Expr)(unsafe.Pointer(pColExpr)).Fflags&U32(EP_WinFunc|EP_Subrtn) == U32(0) &&
				*(*uintptr)(unsafe.Pointer(pColExpr + 64)) != uintptr(0) {
				var iCol int32 = int32((*Expr)(unsafe.Pointer(pColExpr)).FiColumn)
				pTab = *(*uintptr)(unsafe.Pointer(pColExpr + 64))
				if iCol < 0 {
					iCol = int32((*Table)(unsafe.Pointer(pTab)).FiPKey)
				}
				if iCol >= 0 {
					zName = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24)).FzCnName
				} else {
					zName = ts + 11466
				}
			} else if int32((*Expr)(unsafe.Pointer(pColExpr)).Fop) == TK_ID {
				zName = *(*uintptr)(unsafe.Pointer(pColExpr + 8))
			} else {
			}
		}
		if zName != 0 && !(Xsqlite3IsTrueOrFalse(tls, zName) != 0) {
			zName = Xsqlite3DbStrDup(tls, db, zName)
		} else {
			zName = Xsqlite3MPrintf(tls, db, ts+22451, libc.VaList(bp, i+1))
		}

		*(*U32)(unsafe.Pointer(bp + 56)) = U32(0)
		for zName != 0 && libc.AssignUintptr(&pCollide, Xsqlite3HashFind(tls, bp+32, zName)) != uintptr(0) {
			if uint32(int32(*(*uint16)(unsafe.Pointer(pCollide + 16 + 4))&0x80>>7)) != 0 {
				*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_NOEXPAND)
			}
			nName = Xsqlite3Strlen30(tls, zName)
			if nName > 0 {
				for j = nName - 1; j > 0 && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zName + uintptr(j)))])&0x04 != 0; j-- {
				}
				if int32(*(*uint8)(unsafe.Pointer(zName + uintptr(j)))) == ':' {
					nName = j
				}
			}
			zName = Xsqlite3MPrintf(tls, db, ts+22460, libc.VaList(bp+8, nName, zName, libc.PreIncUint32(&*(*U32)(unsafe.Pointer(bp + 56)), 1)))
			Xsqlite3ProgressCheck(tls, pParse)
			if *(*U32)(unsafe.Pointer(bp + 56)) > U32(3) {
				Xsqlite3_randomness(tls, int32(unsafe.Sizeof(U32(0))), bp+56)
			}
		}
		(*Column)(unsafe.Pointer(pCol)).FzCnName = zName
		(*Column)(unsafe.Pointer(pCol)).FhName = Xsqlite3StrIHash(tls, zName)
		if uint32(int32(*(*uint16)(unsafe.Pointer(pX + 16 + 4))&0x100>>8)) != 0 {
			*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_NOEXPAND)
		}

		if zName != 0 && Xsqlite3HashInsert(tls, bp+32, zName, pX) == pX {
			Xsqlite3OomFault(tls, db)
		}

	}
	goto __2
__2:
	i++
	pCol += 24
	goto __1
	goto __3
__3:
	;
	Xsqlite3HashClear(tls, bp+32)
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		for j = 0; j < i; j++ {
			Xsqlite3DbFree(tls, db, (*Column)(unsafe.Pointer(aCol+uintptr(j)*24)).FzCnName)
		}
		Xsqlite3DbFree(tls, db, aCol)
		*(*uintptr)(unsafe.Pointer(paCol)) = uintptr(0)
		*(*I16)(unsafe.Pointer(pnCol)) = int16(0)
		return (*Parse)(unsafe.Pointer(pParse)).Frc
	}
	return SQLITE_OK
}

func Xsqlite3SubqueryColumnTypes(tls *libc.TLS, pParse uintptr, pTab uintptr, pSelect uintptr, aff uint8) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pCol uintptr
	var pColl uintptr
	var i int32
	var j int32
	var p uintptr
	var a uintptr

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return
	}
	for (*Select)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		pSelect = (*Select)(unsafe.Pointer(pSelect)).FpPrior
	}
	a = (*Select)(unsafe.Pointer(pSelect)).FpEList + 8
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp)).FpSrcList = (*Select)(unsafe.Pointer(pSelect)).FpSrc
	i = 0
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol
__1:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __3
	}
	{
		var zType uintptr
		var n I64
		*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(int32((*Column)(unsafe.Pointer(pCol)).FcolFlags) & COLFLAG_NOINSERT)
		p = (*ExprList_item)(unsafe.Pointer(a + uintptr(i)*32)).FpExpr

		(*Column)(unsafe.Pointer(pCol)).Faffinity = Xsqlite3ExprAffinity(tls, p)
		if int32((*Column)(unsafe.Pointer(pCol)).Faffinity) <= SQLITE_AFF_NONE {
			(*Column)(unsafe.Pointer(pCol)).Faffinity = aff
		}
		if int32((*Column)(unsafe.Pointer(pCol)).Faffinity) >= SQLITE_AFF_TEXT && (*Select)(unsafe.Pointer(pSelect)).FpNext != 0 {
			var m int32 = 0
			var pS2 uintptr
			m = 0
			pS2 = (*Select)(unsafe.Pointer(pSelect)).FpNext
			for ; pS2 != 0; pS2 = (*Select)(unsafe.Pointer(pS2)).FpNext {
				m = m | Xsqlite3ExprDataType(tls, (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(pS2)).FpEList+8+uintptr(i)*32)).FpExpr)
			}
			if int32((*Column)(unsafe.Pointer(pCol)).Faffinity) == SQLITE_AFF_TEXT && m&0x01 != 0 {
				(*Column)(unsafe.Pointer(pCol)).Faffinity = uint8(SQLITE_AFF_BLOB)
			} else if int32((*Column)(unsafe.Pointer(pCol)).Faffinity) >= SQLITE_AFF_NUMERIC && m&0x02 != 0 {
				(*Column)(unsafe.Pointer(pCol)).Faffinity = uint8(SQLITE_AFF_BLOB)
			}
			if int32((*Column)(unsafe.Pointer(pCol)).Faffinity) >= SQLITE_AFF_NUMERIC && int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_CAST {
				(*Column)(unsafe.Pointer(pCol)).Faffinity = uint8(SQLITE_AFF_FLEXNUM)
			}
		}
		zType = columnTypeImpl(tls, bp, p, uintptr(0), uintptr(0), uintptr(0))
		if zType == uintptr(0) || int32((*Column)(unsafe.Pointer(pCol)).Faffinity) != int32(Xsqlite3AffinityType(tls, zType, uintptr(0))) {
			if int32((*Column)(unsafe.Pointer(pCol)).Faffinity) == SQLITE_AFF_NUMERIC ||
				int32((*Column)(unsafe.Pointer(pCol)).Faffinity) == SQLITE_AFF_FLEXNUM {
				zType = ts + 22468
			} else {
				zType = uintptr(0)
				for j = 1; j < SQLITE_N_STDTYPE; j++ {
					if int32(Xsqlite3StdTypeAffinity[j]) == int32((*Column)(unsafe.Pointer(pCol)).Faffinity) {
						zType = Xsqlite3StdType[j]
						break
					}
				}
			}
		}
		if zType != 0 {
			var m I64 = I64(Xsqlite3Strlen30(tls, zType))
			n = I64(Xsqlite3Strlen30(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName))
			(*Column)(unsafe.Pointer(pCol)).FzCnName = Xsqlite3DbReallocOrFree(tls, db, (*Column)(unsafe.Pointer(pCol)).FzCnName, uint64(n+m+int64(2)))
			if (*Column)(unsafe.Pointer(pCol)).FzCnName != 0 {
				libc.Xmemcpy(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName+uintptr(n+int64(1)), zType, uint64(m+int64(1)))
				*(*U16)(unsafe.Pointer(pCol + 16)) |= U16(COLFLAG_HASTYPE)
			} else {
				*(*U16)(unsafe.Pointer(pCol + 16)) &= libc.Uint16FromInt32(libc.CplInt32(COLFLAG_HASTYPE | COLFLAG_HASCOLL))
			}
		}
		pColl = Xsqlite3ExprCollSeq(tls, pParse, p)
		if pColl != 0 {
			Xsqlite3ColumnSetColl(tls, db, pCol, (*CollSeq)(unsafe.Pointer(pColl)).FzName)
		}

	}
	goto __2
__2:
	i++
	pCol += 24
	goto __1
	goto __3
__3:
	;
	(*Table)(unsafe.Pointer(pTab)).FszTabRow = int16(1)
}

func Xsqlite3ResultSetOfSelect(tls *libc.TLS, pParse uintptr, pSelect uintptr, aff uint8) uintptr {
	var pTab uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var savedFlags U64

	savedFlags = (*Sqlite3)(unsafe.Pointer(db)).Fflags
	*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(SQLITE_FullColNames))
	*(*U64)(unsafe.Pointer(db + 48)) |= uint64(SQLITE_ShortColNames)
	Xsqlite3SelectPrep(tls, pParse, pSelect, uintptr(0))
	(*Sqlite3)(unsafe.Pointer(db)).Fflags = savedFlags
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return uintptr(0)
	}
	for (*Select)(unsafe.Pointer(pSelect)).FpPrior != 0 {
		pSelect = (*Select)(unsafe.Pointer(pSelect)).FpPrior
	}
	pTab = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Table{})))
	if pTab == uintptr(0) {
		return uintptr(0)
	}
	(*Table)(unsafe.Pointer(pTab)).FnTabRef = U32(1)
	(*Table)(unsafe.Pointer(pTab)).FzName = uintptr(0)
	(*Table)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
	Xsqlite3ColumnsFromExprList(tls, pParse, (*Select)(unsafe.Pointer(pSelect)).FpEList, pTab+54, pTab+8)
	Xsqlite3SubqueryColumnTypes(tls, pParse, pTab, pSelect, aff)
	(*Table)(unsafe.Pointer(pTab)).FiPKey = int16(-1)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		Xsqlite3DeleteTable(tls, db, pTab)
		return uintptr(0)
	}
	return pTab
}

func Xsqlite3GetVdbe(tls *libc.TLS, pParse uintptr) uintptr {
	if (*Parse)(unsafe.Pointer(pParse)).FpVdbe != 0 {
		return (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	}
	if (*Parse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) &&
		(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&U32(SQLITE_FactorOutConst) == U32(0) {
		(*Parse)(unsafe.Pointer(pParse)).FokConstFactor = U8(1)
	}
	return Xsqlite3VdbeCreate(tls, pParse)
}

func computeLimitRegisters(tls *libc.TLS, pParse uintptr, p uintptr, iBreak int32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var v uintptr = uintptr(0)
	var iLimit int32 = 0
	var iOffset int32

	var pLimit uintptr = (*Select)(unsafe.Pointer(p)).FpLimit

	if (*Select)(unsafe.Pointer(p)).FiLimit != 0 {
		return
	}

	if pLimit != 0 {
		(*Select)(unsafe.Pointer(p)).FiLimit = libc.AssignInt32(&iLimit, libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1))
		v = Xsqlite3GetVdbe(tls, pParse)

		if Xsqlite3ExprIsInteger(tls, (*Expr)(unsafe.Pointer(pLimit)).FpLeft, bp) != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer, *(*int32)(unsafe.Pointer(bp)), iLimit)
			Xsqlite3VdbeComment(tls, v, ts+22472, 0)
			if *(*int32)(unsafe.Pointer(bp)) == 0 {
				Xsqlite3VdbeGoto(tls, v, iBreak)
			} else if *(*int32)(unsafe.Pointer(bp)) >= 0 && int32((*Select)(unsafe.Pointer(p)).FnSelectRow) > int32(Xsqlite3LogEst(tls, U64(*(*int32)(unsafe.Pointer(bp))))) {
				(*Select)(unsafe.Pointer(p)).FnSelectRow = Xsqlite3LogEst(tls, U64(*(*int32)(unsafe.Pointer(bp))))
				*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_FixedLimit)
			}
		} else {
			Xsqlite3ExprCode(tls, pParse, (*Expr)(unsafe.Pointer(pLimit)).FpLeft, iLimit)
			Xsqlite3VdbeAddOp1(tls, v, OP_MustBeInt, iLimit)
			Xsqlite3VdbeComment(tls, v, ts+22472, 0)
			Xsqlite3VdbeAddOp2(tls, v, OP_IfNot, iLimit, iBreak)
		}
		if (*Expr)(unsafe.Pointer(pLimit)).FpRight != 0 {
			(*Select)(unsafe.Pointer(p)).FiOffset = libc.AssignInt32(&iOffset, libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1))
			(*Parse)(unsafe.Pointer(pParse)).FnMem++
			Xsqlite3ExprCode(tls, pParse, (*Expr)(unsafe.Pointer(pLimit)).FpRight, iOffset)
			Xsqlite3VdbeAddOp1(tls, v, OP_MustBeInt, iOffset)
			Xsqlite3VdbeComment(tls, v, ts+22486, 0)
			Xsqlite3VdbeAddOp3(tls, v, OP_OffsetLimit, iLimit, iOffset+1, iOffset)
			Xsqlite3VdbeComment(tls, v, ts+22501, 0)
		}
	}
}

func multiSelectCollSeq(tls *libc.TLS, pParse uintptr, p uintptr, iCol int32) uintptr {
	var pRet uintptr
	if (*Select)(unsafe.Pointer(p)).FpPrior != 0 {
		pRet = multiSelectCollSeq(tls, pParse, (*Select)(unsafe.Pointer(p)).FpPrior, iCol)
	} else {
		pRet = uintptr(0)
	}

	if pRet == uintptr(0) && iCol < (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr {
		pRet = Xsqlite3ExprCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList+8+uintptr(iCol)*32)).FpExpr)
	}
	return pRet
}

func multiSelectOrderByKeyInfo(tls *libc.TLS, pParse uintptr, p uintptr, nExtra int32) uintptr {
	var pOrderBy uintptr = (*Select)(unsafe.Pointer(p)).FpOrderBy
	var nOrderBy int32
	if pOrderBy != uintptr(0) {
		nOrderBy = (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr
	} else {
		nOrderBy = 0
	}
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pRet uintptr = Xsqlite3KeyInfoAlloc(tls, db, nOrderBy+nExtra, 1)
	if pRet != 0 {
		var i int32
		for i = 0; i < nOrderBy; i++ {
			var pItem uintptr = pOrderBy + 8 + uintptr(i)*32
			var pTerm uintptr = (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr
			var pColl uintptr

			if (*Expr)(unsafe.Pointer(pTerm)).Fflags&U32(EP_Collate) != 0 {
				pColl = Xsqlite3ExprCollSeq(tls, pParse, pTerm)
			} else {
				pColl = multiSelectCollSeq(tls, pParse, p, int32(*(*U16)(unsafe.Pointer(pItem + 24)))-1)
				if pColl == uintptr(0) {
					pColl = (*Sqlite3)(unsafe.Pointer(db)).FpDfltColl
				}
				(*ExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32)).FpExpr = Xsqlite3ExprAddCollateString(tls, pParse, pTerm, (*CollSeq)(unsafe.Pointer(pColl)).FzName)
			}

			*(*uintptr)(unsafe.Pointer(pRet + 32 + uintptr(i)*8)) = pColl
			*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pRet)).FaSortFlags + uintptr(i))) = (*ExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32)).Ffg.FsortFlags
		}
	}

	return pRet
}

func generateWithRecursiveQuery(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var pSrc uintptr
	var nCol int32
	var v uintptr
	var pSetup uintptr
	var pFirstRec uintptr
	var addrTop int32
	var addrCont int32
	var addrBreak int32
	var iCurrent int32
	var regCurrent int32
	var iQueue int32
	var iDistinct int32
	var eDest int32

	var i int32
	var rc int32
	var pOrderBy uintptr
	var pLimit uintptr
	var regLimit int32
	var regOffset int32
	var pKeyInfo uintptr
	pSrc = (*Select)(unsafe.Pointer(p)).FpSrc
	nCol = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	iCurrent = 0
	iDistinct = 0
	eDest = SRT_Fifo

	if !((*Select)(unsafe.Pointer(p)).FpWin != 0) {
		goto __1
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+22514, 0)
	return
__1:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_RECURSIVE, uintptr(0), uintptr(0), uintptr(0)) != 0) {
		goto __2
	}
	return
__2:
	;
	addrBreak = Xsqlite3VdbeMakeLabel(tls, pParse)
	(*Select)(unsafe.Pointer(p)).FnSelectRow = int16(320)
	computeLimitRegisters(tls, pParse, p, addrBreak)
	pLimit = (*Select)(unsafe.Pointer(p)).FpLimit
	regLimit = (*Select)(unsafe.Pointer(p)).FiLimit
	regOffset = (*Select)(unsafe.Pointer(p)).FiOffset
	(*Select)(unsafe.Pointer(p)).FpLimit = uintptr(0)
	(*Select)(unsafe.Pointer(p)).FiLimit = libc.AssignPtrInt32(p+12, 0)
	pOrderBy = (*Select)(unsafe.Pointer(p)).FpOrderBy

	i = 0
__3:
	if !(i < (*SrcList)(unsafe.Pointer(pSrc)).FnSrc) {
		goto __5
	}
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104 + 60 + 4))&0x40>>6)) != 0) {
		goto __6
	}
	iCurrent = (*SrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104)).FiCursor
	goto __5
__6:
	;
	goto __4
__4:
	i++
	goto __3
	goto __5
__5:
	;
	iQueue = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	if !(int32((*Select)(unsafe.Pointer(p)).Fop) == TK_UNION) {
		goto __7
	}
	if pOrderBy != 0 {
		eDest = SRT_DistQueue
	} else {
		eDest = SRT_DistFifo
	}
	iDistinct = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	goto __8
__7:
	if pOrderBy != 0 {
		eDest = SRT_Queue
	} else {
		eDest = SRT_Fifo
	}
__8:
	;
	Xsqlite3SelectDestInit(tls, bp, eDest, iQueue)

	regCurrent = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp3(tls, v, OP_OpenPseudo, iCurrent, regCurrent, nCol)
	if !(pOrderBy != 0) {
		goto __9
	}
	pKeyInfo = multiSelectOrderByKeyInfo(tls, pParse, p, 1)
	Xsqlite3VdbeAddOp4(tls, v, OP_OpenEphemeral, iQueue, (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr+2, 0,
		pKeyInfo, -8)
	(*SelectDest)(unsafe.Pointer(bp)).FpOrderBy = pOrderBy
	goto __10
__9:
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, iQueue, nCol)
__10:
	;
	Xsqlite3VdbeComment(tls, v, ts+22563, 0)
	if !(iDistinct != 0) {
		goto __11
	}
	*(*int32)(unsafe.Pointer(p + 20)) = Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, iDistinct, 0)
	*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_UsesEphemeral)
__11:
	;
	(*Select)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)

	pFirstRec = p
__12:
	if !(pFirstRec != uintptr(0)) {
		goto __14
	}
	if !((*Select)(unsafe.Pointer(pFirstRec)).FselFlags&U32(SF_Aggregate) != 0) {
		goto __15
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+22575, 0)
	goto end_of_recursive_query
__15:
	;
	(*Select)(unsafe.Pointer(pFirstRec)).Fop = U8(TK_ALL)
	if !((*Select)(unsafe.Pointer((*Select)(unsafe.Pointer(pFirstRec)).FpPrior)).FselFlags&U32(SF_Recursive) == U32(0)) {
		goto __16
	}
	goto __14
__16:
	;
	goto __13
__13:
	pFirstRec = (*Select)(unsafe.Pointer(pFirstRec)).FpPrior
	goto __12
	goto __14
__14:
	;
	pSetup = (*Select)(unsafe.Pointer(pFirstRec)).FpPrior
	(*Select)(unsafe.Pointer(pSetup)).FpNext = uintptr(0)
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22617, 0)
	rc = Xsqlite3Select(tls, pParse, pSetup, bp)
	(*Select)(unsafe.Pointer(pSetup)).FpNext = p
	if !(rc != 0) {
		goto __17
	}
	goto end_of_recursive_query
__17:
	;
	addrTop = Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, iQueue, addrBreak)

	Xsqlite3VdbeAddOp1(tls, v, OP_NullRow, iCurrent)
	if !(pOrderBy != 0) {
		goto __18
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, iQueue, (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr+1, regCurrent)
	goto __19
__18:
	Xsqlite3VdbeAddOp2(tls, v, OP_RowData, iQueue, regCurrent)
__19:
	;
	Xsqlite3VdbeAddOp1(tls, v, OP_Delete, iQueue)

	addrCont = Xsqlite3VdbeMakeLabel(tls, pParse)
	codeOffset(tls, v, regOffset, addrCont)
	selectInnerLoop(tls, pParse, p, iCurrent,
		uintptr(0), uintptr(0), pDest, addrCont, addrBreak)
	if !(regLimit != 0) {
		goto __20
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_DecrJumpZero, regLimit, addrBreak)

__20:
	;
	Xsqlite3VdbeResolveLabel(tls, v, addrCont)

	(*Select)(unsafe.Pointer(pFirstRec)).FpPrior = uintptr(0)
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22623, 0)
	Xsqlite3Select(tls, pParse, p, bp)

	(*Select)(unsafe.Pointer(pFirstRec)).FpPrior = pSetup

	Xsqlite3VdbeGoto(tls, v, addrTop)
	Xsqlite3VdbeResolveLabel(tls, v, addrBreak)

end_of_recursive_query:
	Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Select)(unsafe.Pointer(p)).FpOrderBy)
	(*Select)(unsafe.Pointer(p)).FpOrderBy = pOrderBy
	(*Select)(unsafe.Pointer(p)).FpLimit = pLimit
	return
}

func multiSelectValues(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var nRow int32 = 1
	var rc int32 = 0
	var bShowAll int32 = libc.Bool32((*Select)(unsafe.Pointer(p)).FpLimit == uintptr(0))

	for __ccgo := true; __ccgo; __ccgo = 1 != 0 {
		if (*Select)(unsafe.Pointer(p)).FpWin != 0 {
			return -1
		}
		if (*Select)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
			break
		}

		p = (*Select)(unsafe.Pointer(p)).FpPrior
		nRow = nRow + bShowAll
	}
	Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+22638, libc.VaList(bp, nRow, func() uintptr {
		if nRow == 1 {
			return ts + 1636
		}
		return ts + 22661
	}()))
	for p != 0 {
		selectInnerLoop(tls, pParse, p, -1, uintptr(0), uintptr(0), pDest, 1, 1)
		if !(bShowAll != 0) {
			break
		}
		(*Select)(unsafe.Pointer(p)).FnSelectRow = LogEst(nRow)
		p = (*Select)(unsafe.Pointer(p)).FpNext
	}
	return rc
}

func hasAnchor(tls *libc.TLS, p uintptr) int32 {
	for p != 0 && (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Recursive) != U32(0) {
		p = (*Select)(unsafe.Pointer(p)).FpPrior
	}
	return libc.Bool32(p != uintptr(0))
}

func multiSelect(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) int32 {
	bp := tls.Alloc(144)
	defer tls.Free(144)

	var rc int32
	var pPrior uintptr
	var v uintptr

	var pDelete uintptr
	var db uintptr
	var addr int32

	var iCont int32
	var iBreak int32
	var iStart int32
	var unionTab int32
	var op U8
	var priorOp int32
	var pLimit uintptr
	var addr1 int32

	var tab1 int32
	var tab2 int32
	var iCont1 int32
	var iBreak1 int32
	var iStart1 int32
	var pLimit1 uintptr
	var addr2 int32

	var r1 int32
	var addr3 int32
	var i int32
	var pKeyInfo uintptr
	var pLoop uintptr
	var apColl uintptr
	var nCol int32
	rc = SQLITE_OK
	pDelete = uintptr(0)

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	pPrior = (*Select)(unsafe.Pointer(p)).FpPrior
	*(*SelectDest)(unsafe.Pointer(bp + 16)) = *(*SelectDest)(unsafe.Pointer(pDest))

	v = Xsqlite3GetVdbe(tls, pParse)

	if !(int32((*SelectDest)(unsafe.Pointer(bp+16)).FeDest) == SRT_EphemTab) {
		goto __1
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, (*SelectDest)(unsafe.Pointer(bp+16)).FiSDParm, (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr)
	(*SelectDest)(unsafe.Pointer(bp + 16)).FeDest = U8(SRT_Table)
__1:
	;
	if !((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_MultiValue) != 0) {
		goto __2
	}
	rc = multiSelectValues(tls, pParse, p, bp+16)
	if !(rc >= 0) {
		goto __3
	}
	goto multi_select_end
__3:
	;
	rc = SQLITE_OK
__2:
	;
	if !((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Recursive) != U32(0) && hasAnchor(tls, p) != 0) {
		goto __4
	}
	generateWithRecursiveQuery(tls, pParse, p, bp+16)
	goto __5
__4:
	if !((*Select)(unsafe.Pointer(p)).FpOrderBy != 0) {
		goto __6
	}
	return multiSelectOrderBy(tls, pParse, p, pDest)
	goto __7
__6:
	if !((*Select)(unsafe.Pointer(pPrior)).FpPrior == uintptr(0)) {
		goto __8
	}
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22663, 0)
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22678, 0)
__8:
	;
	switch int32((*Select)(unsafe.Pointer(p)).Fop) {
	case TK_ALL:
		goto __10
	case TK_EXCEPT:
		goto __11
	case TK_UNION:
		goto __12
	default:
		goto __13
	}
	goto __9
__10:
	addr = 0
	*(*int32)(unsafe.Pointer(bp + 56)) = 0

	(*Select)(unsafe.Pointer(pPrior)).FiLimit = (*Select)(unsafe.Pointer(p)).FiLimit
	(*Select)(unsafe.Pointer(pPrior)).FiOffset = (*Select)(unsafe.Pointer(p)).FiOffset
	(*Select)(unsafe.Pointer(pPrior)).FpLimit = (*Select)(unsafe.Pointer(p)).FpLimit

	rc = Xsqlite3Select(tls, pParse, pPrior, bp+16)
	(*Select)(unsafe.Pointer(pPrior)).FpLimit = uintptr(0)
	if !(rc != 0) {
		goto __14
	}
	goto multi_select_end
__14:
	;
	(*Select)(unsafe.Pointer(p)).FpPrior = uintptr(0)
	(*Select)(unsafe.Pointer(p)).FiLimit = (*Select)(unsafe.Pointer(pPrior)).FiLimit
	(*Select)(unsafe.Pointer(p)).FiOffset = (*Select)(unsafe.Pointer(pPrior)).FiOffset
	if !((*Select)(unsafe.Pointer(p)).FiLimit != 0) {
		goto __15
	}
	addr = Xsqlite3VdbeAddOp1(tls, v, OP_IfNot, (*Select)(unsafe.Pointer(p)).FiLimit)
	Xsqlite3VdbeComment(tls, v, ts+22697, 0)
	if !((*Select)(unsafe.Pointer(p)).FiOffset != 0) {
		goto __16
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_OffsetLimit,
		(*Select)(unsafe.Pointer(p)).FiLimit, (*Select)(unsafe.Pointer(p)).FiOffset+1, (*Select)(unsafe.Pointer(p)).FiOffset)
__16:
	;
__15:
	;
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22349, 0)

	rc = Xsqlite3Select(tls, pParse, p, bp+16)

	pDelete = (*Select)(unsafe.Pointer(p)).FpPrior
	(*Select)(unsafe.Pointer(p)).FpPrior = pPrior
	(*Select)(unsafe.Pointer(p)).FnSelectRow = Xsqlite3LogEstAdd(tls, (*Select)(unsafe.Pointer(p)).FnSelectRow, (*Select)(unsafe.Pointer(pPrior)).FnSelectRow)
	if !((*Select)(unsafe.Pointer(p)).FpLimit != 0 &&
		Xsqlite3ExprIsInteger(tls, (*Expr)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpLimit)).FpLeft, bp+56) != 0 &&
		*(*int32)(unsafe.Pointer(bp + 56)) > 0 && int32((*Select)(unsafe.Pointer(p)).FnSelectRow) > int32(Xsqlite3LogEst(tls, U64(*(*int32)(unsafe.Pointer(bp + 56)))))) {
		goto __17
	}
	(*Select)(unsafe.Pointer(p)).FnSelectRow = Xsqlite3LogEst(tls, U64(*(*int32)(unsafe.Pointer(bp + 56))))
__17:
	;
	if !(addr != 0) {
		goto __18
	}
	Xsqlite3VdbeJumpHere(tls, v, addr)
__18:
	;
	goto __9

__11:
__12:
	op = U8(0)

	priorOp = SRT_Union
	if !(int32((*SelectDest)(unsafe.Pointer(bp+16)).FeDest) == priorOp) {
		goto __19
	}

	unionTab = (*SelectDest)(unsafe.Pointer(bp + 16)).FiSDParm
	goto __20
__19:
	unionTab = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)

	addr1 = Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, unionTab, 0)

	*(*int32)(unsafe.Pointer(p + 20)) = addr1
	*(*U32)(unsafe.Pointer(findRightmost(tls, p) + 4)) |= U32(SF_UsesEphemeral)

__20:
	;
	Xsqlite3SelectDestInit(tls, bp+64, priorOp, unionTab)

	rc = Xsqlite3Select(tls, pParse, pPrior, bp+64)
	if !(rc != 0) {
		goto __21
	}
	goto multi_select_end
__21:
	;
	if !(int32((*Select)(unsafe.Pointer(p)).Fop) == TK_EXCEPT) {
		goto __22
	}
	op = U8(SRT_Except)
	goto __23
__22:
	;
	op = U8(SRT_Union)
__23:
	;
	(*Select)(unsafe.Pointer(p)).FpPrior = uintptr(0)
	pLimit = (*Select)(unsafe.Pointer(p)).FpLimit
	(*Select)(unsafe.Pointer(p)).FpLimit = uintptr(0)
	(*SelectDest)(unsafe.Pointer(bp + 64)).FeDest = op
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22725, libc.VaList(bp, Xsqlite3SelectOpName(tls, int32((*Select)(unsafe.Pointer(p)).Fop))))

	rc = Xsqlite3Select(tls, pParse, p, bp+64)

	pDelete = (*Select)(unsafe.Pointer(p)).FpPrior
	(*Select)(unsafe.Pointer(p)).FpPrior = pPrior
	(*Select)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
	if !(int32((*Select)(unsafe.Pointer(p)).Fop) == TK_UNION) {
		goto __24
	}
	(*Select)(unsafe.Pointer(p)).FnSelectRow = Xsqlite3LogEstAdd(tls, (*Select)(unsafe.Pointer(p)).FnSelectRow, (*Select)(unsafe.Pointer(pPrior)).FnSelectRow)
__24:
	;
	Xsqlite3ExprDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpLimit)
	(*Select)(unsafe.Pointer(p)).FpLimit = pLimit
	(*Select)(unsafe.Pointer(p)).FiLimit = 0
	(*Select)(unsafe.Pointer(p)).FiOffset = 0

	if !(int32((*SelectDest)(unsafe.Pointer(bp+16)).FeDest) != priorOp && int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0) {
		goto __25
	}
	iBreak = Xsqlite3VdbeMakeLabel(tls, pParse)
	iCont = Xsqlite3VdbeMakeLabel(tls, pParse)
	computeLimitRegisters(tls, pParse, p, iBreak)
	Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, unionTab, iBreak)
	iStart = Xsqlite3VdbeCurrentAddr(tls, v)
	selectInnerLoop(tls, pParse, p, unionTab,
		uintptr(0), uintptr(0), bp+16, iCont, iBreak)
	Xsqlite3VdbeResolveLabel(tls, v, iCont)
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, unionTab, iStart)
	Xsqlite3VdbeResolveLabel(tls, v, iBreak)
	Xsqlite3VdbeAddOp2(tls, v, OP_Close, unionTab, 0)
__25:
	;
	goto __9

__13:
	;
	tab1 = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	tab2 = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)

	addr2 = Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, tab1, 0)

	*(*int32)(unsafe.Pointer(p + 20)) = addr2
	*(*U32)(unsafe.Pointer(findRightmost(tls, p) + 4)) |= U32(SF_UsesEphemeral)

	Xsqlite3SelectDestInit(tls, bp+104, SRT_Union, tab1)

	rc = Xsqlite3Select(tls, pParse, pPrior, bp+104)
	if !(rc != 0) {
		goto __26
	}
	goto multi_select_end
__26:
	;
	addr2 = Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, tab2, 0)

	*(*int32)(unsafe.Pointer(p + 20 + 1*4)) = addr2
	(*Select)(unsafe.Pointer(p)).FpPrior = uintptr(0)
	pLimit1 = (*Select)(unsafe.Pointer(p)).FpLimit
	(*Select)(unsafe.Pointer(p)).FpLimit = uintptr(0)
	(*SelectDest)(unsafe.Pointer(bp + 104)).FiSDParm = tab2
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22725, libc.VaList(bp+8, Xsqlite3SelectOpName(tls, int32((*Select)(unsafe.Pointer(p)).Fop))))

	rc = Xsqlite3Select(tls, pParse, p, bp+104)

	pDelete = (*Select)(unsafe.Pointer(p)).FpPrior
	(*Select)(unsafe.Pointer(p)).FpPrior = pPrior
	if !(int32((*Select)(unsafe.Pointer(p)).FnSelectRow) > int32((*Select)(unsafe.Pointer(pPrior)).FnSelectRow)) {
		goto __27
	}
	(*Select)(unsafe.Pointer(p)).FnSelectRow = (*Select)(unsafe.Pointer(pPrior)).FnSelectRow
__27:
	;
	Xsqlite3ExprDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpLimit)
	(*Select)(unsafe.Pointer(p)).FpLimit = pLimit1

	if !(rc != 0) {
		goto __28
	}
	goto __9
__28:
	;
	iBreak1 = Xsqlite3VdbeMakeLabel(tls, pParse)
	iCont1 = Xsqlite3VdbeMakeLabel(tls, pParse)
	computeLimitRegisters(tls, pParse, p, iBreak1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, tab1, iBreak1)
	r1 = Xsqlite3GetTempReg(tls, pParse)
	iStart1 = Xsqlite3VdbeAddOp2(tls, v, OP_RowData, tab1, r1)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_NotFound, tab2, iCont1, r1, 0)

	Xsqlite3ReleaseTempReg(tls, pParse, r1)
	selectInnerLoop(tls, pParse, p, tab1,
		uintptr(0), uintptr(0), bp+16, iCont1, iBreak1)
	Xsqlite3VdbeResolveLabel(tls, v, iCont1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, tab1, iStart1)
	Xsqlite3VdbeResolveLabel(tls, v, iBreak1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Close, tab2, 0)
	Xsqlite3VdbeAddOp2(tls, v, OP_Close, tab1, 0)
	goto __9

__9:
	;
	if !((*Select)(unsafe.Pointer(p)).FpNext == uintptr(0)) {
		goto __29
	}
	Xsqlite3VdbeExplainPop(tls, pParse)
__29:
	;
__7:
	;
__5:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __30
	}
	goto multi_select_end
__30:
	;
	if !((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_UsesEphemeral) != 0) {
		goto __31
	}

	nCol = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr
	pKeyInfo = Xsqlite3KeyInfoAlloc(tls, db, nCol, 1)
	if !!(pKeyInfo != 0) {
		goto __32
	}
	rc = SQLITE_NOMEM
	goto multi_select_end
__32:
	;
	i = 0
	apColl = pKeyInfo + 32
__33:
	if !(i < nCol) {
		goto __35
	}
	*(*uintptr)(unsafe.Pointer(apColl)) = multiSelectCollSeq(tls, pParse, p, i)
	if !(uintptr(0) == *(*uintptr)(unsafe.Pointer(apColl))) {
		goto __36
	}
	*(*uintptr)(unsafe.Pointer(apColl)) = (*Sqlite3)(unsafe.Pointer(db)).FpDfltColl
__36:
	;
	goto __34
__34:
	i++
	apColl += 8
	goto __33
	goto __35
__35:
	;
	pLoop = p
__37:
	if !(pLoop != 0) {
		goto __39
	}
	i = 0
__40:
	if !(i < 2) {
		goto __42
	}
	addr3 = *(*int32)(unsafe.Pointer(pLoop + 20 + uintptr(i)*4))
	if !(addr3 < 0) {
		goto __43
	}

	goto __42
__43:
	;
	Xsqlite3VdbeChangeP2(tls, v, addr3, nCol)
	Xsqlite3VdbeChangeP4(tls, v, addr3, Xsqlite3KeyInfoRef(tls, pKeyInfo),
		-8)
	*(*int32)(unsafe.Pointer(pLoop + 20 + uintptr(i)*4)) = -1
	goto __41
__41:
	i++
	goto __40
	goto __42
__42:
	;
	goto __38
__38:
	pLoop = (*Select)(unsafe.Pointer(pLoop)).FpPrior
	goto __37
	goto __39
__39:
	;
	Xsqlite3KeyInfoUnref(tls, pKeyInfo)
__31:
	;
multi_select_end:
	(*SelectDest)(unsafe.Pointer(pDest)).FiSdst = (*SelectDest)(unsafe.Pointer(bp + 16)).FiSdst
	(*SelectDest)(unsafe.Pointer(pDest)).FnSdst = (*SelectDest)(unsafe.Pointer(bp + 16)).FnSdst
	if !(pDelete != 0) {
		goto __44
	}
	Xsqlite3ParserAddCleanup(tls, pParse,
		*(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{Xsqlite3SelectDelete})),
		pDelete)
__44:
	;
	return rc
}

func Xsqlite3SelectWrongNumTermsError(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Values) != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+22746, 0)
	} else {
		Xsqlite3ErrorMsg(tls, pParse,
			ts+22792,
			libc.VaList(bp, Xsqlite3SelectOpName(tls, int32((*Select)(unsafe.Pointer(p)).Fop))))
	}
}

func generateOutputSubroutine(tls *libc.TLS, pParse uintptr, p uintptr, pIn uintptr, pDest uintptr, regReturn int32, regPrev int32, pKeyInfo uintptr, iBreak int32) int32 {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var iContinue int32
	var addr int32

	addr = Xsqlite3VdbeCurrentAddr(tls, v)
	iContinue = Xsqlite3VdbeMakeLabel(tls, pParse)

	if regPrev != 0 {
		var addr1 int32
		var addr2 int32
		addr1 = Xsqlite3VdbeAddOp1(tls, v, OP_IfNot, regPrev)
		addr2 = Xsqlite3VdbeAddOp4(tls, v, OP_Compare, (*SelectDest)(unsafe.Pointer(pIn)).FiSdst, regPrev+1, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst,
			Xsqlite3KeyInfoRef(tls, pKeyInfo), -8)
		Xsqlite3VdbeAddOp3(tls, v, OP_Jump, addr2+2, iContinue, addr2+2)
		Xsqlite3VdbeJumpHere(tls, v, addr1)
		Xsqlite3VdbeAddOp3(tls, v, OP_Copy, (*SelectDest)(unsafe.Pointer(pIn)).FiSdst, regPrev+1, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst-1)
		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, regPrev)
	}
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		return 0
	}

	codeOffset(tls, v, (*Select)(unsafe.Pointer(p)).FiOffset, iContinue)

	switch int32((*SelectDest)(unsafe.Pointer(pDest)).FeDest) {
	case SRT_EphemTab:
		{
			var r1 int32 = Xsqlite3GetTempReg(tls, pParse)
			var r2 int32 = Xsqlite3GetTempReg(tls, pParse)
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, (*SelectDest)(unsafe.Pointer(pIn)).FiSdst, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst, r1)
			Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm, r2)
			Xsqlite3VdbeAddOp3(tls, v, OP_Insert, (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm, r1, r2)
			Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_APPEND))
			Xsqlite3ReleaseTempReg(tls, pParse, r2)
			Xsqlite3ReleaseTempReg(tls, pParse, r1)
			break

		}

	case SRT_Set:
		{
			var r1 int32

			r1 = Xsqlite3GetTempReg(tls, pParse)
			Xsqlite3VdbeAddOp4(tls, v, OP_MakeRecord, (*SelectDest)(unsafe.Pointer(pIn)).FiSdst, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst,
				r1, (*SelectDest)(unsafe.Pointer(pDest)).FzAffSdst, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm, r1,
				(*SelectDest)(unsafe.Pointer(pIn)).FiSdst, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst)
			Xsqlite3ReleaseTempReg(tls, pParse, r1)
			break

		}

	case SRT_Mem:
		{
			Xsqlite3ExprCodeMove(tls, pParse, (*SelectDest)(unsafe.Pointer(pIn)).FiSdst, (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst)

			break

		}

	case SRT_Coroutine:
		{
			if (*SelectDest)(unsafe.Pointer(pDest)).FiSdst == 0 {
				(*SelectDest)(unsafe.Pointer(pDest)).FiSdst = Xsqlite3GetTempRange(tls, pParse, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst)
				(*SelectDest)(unsafe.Pointer(pDest)).FnSdst = (*SelectDest)(unsafe.Pointer(pIn)).FnSdst
			}
			Xsqlite3ExprCodeMove(tls, pParse, (*SelectDest)(unsafe.Pointer(pIn)).FiSdst, (*SelectDest)(unsafe.Pointer(pDest)).FiSdst, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst)
			Xsqlite3VdbeAddOp1(tls, v, OP_Yield, (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm)
			break

		}

	default:
		{
			Xsqlite3VdbeAddOp2(tls, v, OP_ResultRow, (*SelectDest)(unsafe.Pointer(pIn)).FiSdst, (*SelectDest)(unsafe.Pointer(pIn)).FnSdst)
			break

		}
	}

	if (*Select)(unsafe.Pointer(p)).FiLimit != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_DecrJumpZero, (*Select)(unsafe.Pointer(p)).FiLimit, iBreak)
	}

	Xsqlite3VdbeResolveLabel(tls, v, iContinue)
	Xsqlite3VdbeAddOp1(tls, v, OP_Return, regReturn)

	return addr
}

func multiSelectOrderBy(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) int32 {
	bp := tls.Alloc(88)
	defer tls.Free(88)

	var i int32
	var j int32
	var pPrior uintptr
	var pSplit uintptr
	var nSelect int32
	var v uintptr

	var regAddrA int32
	var regAddrB int32
	var addrSelectA int32
	var addrSelectB int32
	var regOutA int32
	var regOutB int32
	var addrOutA int32
	var addrOutB int32 = 0
	var addrEofA int32
	var addrEofA_noB int32
	var addrEofB int32
	var addrAltB int32
	var addrAeqB int32
	var addrAgtB int32
	var regLimitA int32
	var regLimitB int32
	var regPrev int32
	var savedLimit int32
	var savedOffset int32
	var labelCmpr int32
	var labelEnd int32
	var addr1 int32
	var op int32
	var pKeyDup uintptr = uintptr(0)
	var pKeyMerge uintptr
	var db uintptr
	var pOrderBy uintptr
	var nOrderBy int32
	var aPermute uintptr

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	labelEnd = Xsqlite3VdbeMakeLabel(tls, pParse)
	labelCmpr = Xsqlite3VdbeMakeLabel(tls, pParse)

	op = int32((*Select)(unsafe.Pointer(p)).Fop)

	pOrderBy = (*Select)(unsafe.Pointer(p)).FpOrderBy

	nOrderBy = (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr

	if op != TK_ALL {
		for i = 1; int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 && i <= (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr; i++ {
			var pItem uintptr
			j = 0
			pItem = pOrderBy + 8
		__1:
			if !(j < nOrderBy) {
				goto __3
			}
			{
				if int32(*(*U16)(unsafe.Pointer(pItem + 24))) == i {
					goto __3
				}

			}
			goto __2
		__2:
			j++
			pItem += 32
			goto __1
			goto __3
		__3:
			;
			if j == nOrderBy {
				var pNew uintptr = Xsqlite3Expr(tls, db, TK_INTEGER, uintptr(0))
				if pNew == uintptr(0) {
					return SQLITE_NOMEM
				}
				*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(EP_IntValue)
				*(*int32)(unsafe.Pointer(pNew + 8)) = i
				(*Select)(unsafe.Pointer(p)).FpOrderBy = libc.AssignUintptr(&pOrderBy, Xsqlite3ExprListAppend(tls, pParse, pOrderBy, pNew))
				if pOrderBy != 0 {
					*(*U16)(unsafe.Pointer(pOrderBy + 8 + uintptr(libc.PostIncInt32(&nOrderBy, 1))*32 + 24)) = U16(i)
				}
			}
		}
	}

	aPermute = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(U32(0)))*uint64(nOrderBy+1))
	if aPermute != 0 {
		var pItem uintptr
		*(*U32)(unsafe.Pointer(aPermute)) = U32(nOrderBy)
		i = 1
		pItem = pOrderBy + 8
	__4:
		if !(i <= nOrderBy) {
			goto __6
		}
		{
			*(*U32)(unsafe.Pointer(aPermute + uintptr(i)*4)) = U32(int32(*(*U16)(unsafe.Pointer(pItem + 24))) - 1)

		}
		goto __5
	__5:
		i++
		pItem += 32
		goto __4
		goto __6
	__6:
		;
		pKeyMerge = multiSelectOrderByKeyInfo(tls, pParse, p, 1)
	} else {
		pKeyMerge = uintptr(0)
	}

	if op == TK_ALL {
		regPrev = 0
	} else {
		var nExpr int32 = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr

		regPrev = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nExpr + 1
		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regPrev)
		pKeyDup = Xsqlite3KeyInfoAlloc(tls, db, nExpr, 1)
		if pKeyDup != 0 {
			for i = 0; i < nExpr; i++ {
				*(*uintptr)(unsafe.Pointer(pKeyDup + 32 + uintptr(i)*8)) = multiSelectCollSeq(tls, pParse, p, i)
				*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pKeyDup)).FaSortFlags + uintptr(i))) = U8(0)
			}
		}
	}

	nSelect = 1
	if (op == TK_ALL || op == TK_UNION) &&
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_BalancedMerge) == U32(0) {
		for pSplit = p; (*Select)(unsafe.Pointer(pSplit)).FpPrior != uintptr(0) && int32((*Select)(unsafe.Pointer(pSplit)).Fop) == op; pSplit = (*Select)(unsafe.Pointer(pSplit)).FpPrior {
			nSelect++

		}
	}
	if nSelect <= 3 {
		pSplit = p
	} else {
		pSplit = p
		for i = 2; i < nSelect; i = i + 2 {
			pSplit = (*Select)(unsafe.Pointer(pSplit)).FpPrior
		}
	}
	pPrior = (*Select)(unsafe.Pointer(pSplit)).FpPrior

	(*Select)(unsafe.Pointer(pSplit)).FpPrior = uintptr(0)
	(*Select)(unsafe.Pointer(pPrior)).FpNext = uintptr(0)

	(*Select)(unsafe.Pointer(pPrior)).FpOrderBy = Xsqlite3ExprListDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pOrderBy, 0)
	Xsqlite3ResolveOrderGroupBy(tls, pParse, p, (*Select)(unsafe.Pointer(p)).FpOrderBy, ts+10438)
	Xsqlite3ResolveOrderGroupBy(tls, pParse, pPrior, (*Select)(unsafe.Pointer(pPrior)).FpOrderBy, ts+10438)

	computeLimitRegisters(tls, pParse, p, labelEnd)
	if (*Select)(unsafe.Pointer(p)).FiLimit != 0 && op == TK_ALL {
		regLimitA = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		regLimitB = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		Xsqlite3VdbeAddOp2(tls, v, OP_Copy, func() int32 {
			if (*Select)(unsafe.Pointer(p)).FiOffset != 0 {
				return (*Select)(unsafe.Pointer(p)).FiOffset + 1
			}
			return (*Select)(unsafe.Pointer(p)).FiLimit
		}(),
			regLimitA)
		Xsqlite3VdbeAddOp2(tls, v, OP_Copy, regLimitA, regLimitB)
	} else {
		regLimitA = libc.AssignInt32(&regLimitB, 0)
	}
	Xsqlite3ExprDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpLimit)
	(*Select)(unsafe.Pointer(p)).FpLimit = uintptr(0)

	regAddrA = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	regAddrB = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	regOutA = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	regOutB = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3SelectDestInit(tls, bp+8, SRT_Coroutine, regAddrA)
	Xsqlite3SelectDestInit(tls, bp+48, SRT_Coroutine, regAddrB)

	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22874, libc.VaList(bp, Xsqlite3SelectOpName(tls, int32((*Select)(unsafe.Pointer(p)).Fop))))

	addrSelectA = Xsqlite3VdbeCurrentAddr(tls, v) + 1
	addr1 = Xsqlite3VdbeAddOp3(tls, v, OP_InitCoroutine, regAddrA, 0, addrSelectA)
	Xsqlite3VdbeComment(tls, v, ts+22885, 0)
	(*Select)(unsafe.Pointer(pPrior)).FiLimit = regLimitA
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22897, 0)
	Xsqlite3Select(tls, pParse, pPrior, bp+8)
	Xsqlite3VdbeEndCoroutine(tls, v, regAddrA)
	Xsqlite3VdbeJumpHere(tls, v, addr1)

	addrSelectB = Xsqlite3VdbeCurrentAddr(tls, v) + 1
	addr1 = Xsqlite3VdbeAddOp3(tls, v, OP_InitCoroutine, regAddrB, 0, addrSelectB)
	Xsqlite3VdbeComment(tls, v, ts+22902, 0)
	savedLimit = (*Select)(unsafe.Pointer(p)).FiLimit
	savedOffset = (*Select)(unsafe.Pointer(p)).FiOffset
	(*Select)(unsafe.Pointer(p)).FiLimit = regLimitB
	(*Select)(unsafe.Pointer(p)).FiOffset = 0
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+22915, 0)
	Xsqlite3Select(tls, pParse, p, bp+48)
	(*Select)(unsafe.Pointer(p)).FiLimit = savedLimit
	(*Select)(unsafe.Pointer(p)).FiOffset = savedOffset
	Xsqlite3VdbeEndCoroutine(tls, v, regAddrB)

	Xsqlite3VdbeNoopComment(tls, v, ts+22921, 0)
	addrOutA = generateOutputSubroutine(tls, pParse,
		p, bp+8, pDest, regOutA,
		regPrev, pKeyDup, labelEnd)

	if op == TK_ALL || op == TK_UNION {
		Xsqlite3VdbeNoopComment(tls, v, ts+22942, 0)
		addrOutB = generateOutputSubroutine(tls, pParse,
			p, bp+48, pDest, regOutB,
			regPrev, pKeyDup, labelEnd)
	}
	Xsqlite3KeyInfoUnref(tls, pKeyDup)

	if op == TK_EXCEPT || op == TK_INTERSECT {
		addrEofA_noB = libc.AssignInt32(&addrEofA, labelEnd)
	} else {
		Xsqlite3VdbeNoopComment(tls, v, ts+22963, 0)
		addrEofA = Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regOutB, addrOutB)
		addrEofA_noB = Xsqlite3VdbeAddOp2(tls, v, OP_Yield, regAddrB, labelEnd)

		Xsqlite3VdbeGoto(tls, v, addrEofA)
		(*Select)(unsafe.Pointer(p)).FnSelectRow = Xsqlite3LogEstAdd(tls, (*Select)(unsafe.Pointer(p)).FnSelectRow, (*Select)(unsafe.Pointer(pPrior)).FnSelectRow)
	}

	if op == TK_INTERSECT {
		addrEofB = addrEofA
		if int32((*Select)(unsafe.Pointer(p)).FnSelectRow) > int32((*Select)(unsafe.Pointer(pPrior)).FnSelectRow) {
			(*Select)(unsafe.Pointer(p)).FnSelectRow = (*Select)(unsafe.Pointer(pPrior)).FnSelectRow
		}
	} else {
		Xsqlite3VdbeNoopComment(tls, v, ts+22980, 0)
		addrEofB = Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regOutA, addrOutA)
		Xsqlite3VdbeAddOp2(tls, v, OP_Yield, regAddrA, labelEnd)
		Xsqlite3VdbeGoto(tls, v, addrEofB)
	}

	Xsqlite3VdbeNoopComment(tls, v, ts+22997, 0)
	addrAltB = Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regOutA, addrOutA)
	Xsqlite3VdbeAddOp2(tls, v, OP_Yield, regAddrA, addrEofA)
	Xsqlite3VdbeGoto(tls, v, labelCmpr)

	if op == TK_ALL {
		addrAeqB = addrAltB
	} else if op == TK_INTERSECT {
		addrAeqB = addrAltB
		addrAltB++
	} else {
		Xsqlite3VdbeNoopComment(tls, v, ts+23015, 0)
		addrAeqB = Xsqlite3VdbeAddOp2(tls, v, OP_Yield, regAddrA, addrEofA)
		Xsqlite3VdbeGoto(tls, v, labelCmpr)
	}

	Xsqlite3VdbeNoopComment(tls, v, ts+23033, 0)
	addrAgtB = Xsqlite3VdbeCurrentAddr(tls, v)
	if op == TK_ALL || op == TK_UNION {
		Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regOutB, addrOutB)
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Yield, regAddrB, addrEofB)
	Xsqlite3VdbeGoto(tls, v, labelCmpr)

	Xsqlite3VdbeJumpHere(tls, v, addr1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Yield, regAddrA, addrEofA_noB)
	Xsqlite3VdbeAddOp2(tls, v, OP_Yield, regAddrB, addrEofB)

	Xsqlite3VdbeResolveLabel(tls, v, labelCmpr)
	Xsqlite3VdbeAddOp4(tls, v, OP_Permutation, 0, 0, 0, aPermute, -14)
	Xsqlite3VdbeAddOp4(tls, v, OP_Compare, (*SelectDest)(unsafe.Pointer(bp+8)).FiSdst, (*SelectDest)(unsafe.Pointer(bp+48)).FiSdst, nOrderBy,
		pKeyMerge, -8)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_PERMUTE))
	Xsqlite3VdbeAddOp3(tls, v, OP_Jump, addrAltB, addrAeqB, addrAgtB)

	Xsqlite3VdbeResolveLabel(tls, v, labelEnd)

	if (*Select)(unsafe.Pointer(pSplit)).FpPrior != 0 {
		Xsqlite3ParserAddCleanup(tls, pParse,
			*(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr)
			}{Xsqlite3SelectDelete})), (*Select)(unsafe.Pointer(pSplit)).FpPrior)
	}
	(*Select)(unsafe.Pointer(pSplit)).FpPrior = pPrior
	(*Select)(unsafe.Pointer(pPrior)).FpNext = pSplit
	Xsqlite3ExprListDelete(tls, db, (*Select)(unsafe.Pointer(pPrior)).FpOrderBy)
	(*Select)(unsafe.Pointer(pPrior)).FpOrderBy = uintptr(0)

	Xsqlite3VdbeExplainPop(tls, pParse)
	return libc.Bool32((*Parse)(unsafe.Pointer(pParse)).FnErr != 0)
}

type SubstContext1 = struct {
	FpParse      uintptr
	FiTable      int32
	FiNewTable   int32
	FisOuterJoin int32
	F__ccgo_pad1 [4]byte
	FpEList      uintptr
	FpCList      uintptr
}

type SubstContext = SubstContext1

func substExpr(tls *libc.TLS, pSubst uintptr, pExpr uintptr) uintptr {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	if pExpr == uintptr(0) {
		return uintptr(0)
	}
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_InnerON) != U32(0) &&
		*(*int32)(unsafe.Pointer(pExpr + 52)) == (*SubstContext)(unsafe.Pointer(pSubst)).FiTable {
		*(*int32)(unsafe.Pointer(pExpr + 52)) = (*SubstContext)(unsafe.Pointer(pSubst)).FiNewTable
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN &&
		(*Expr)(unsafe.Pointer(pExpr)).FiTable == (*SubstContext)(unsafe.Pointer(pSubst)).FiTable &&
		!((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_FixedCol) != U32(0)) {
		{
			var pNew uintptr
			var iColumn int32 = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)
			var pCopy uintptr = (*ExprList_item)(unsafe.Pointer((*SubstContext)(unsafe.Pointer(pSubst)).FpEList + 8 + uintptr(iColumn)*32)).FpExpr

			if Xsqlite3ExprIsVector(tls, pCopy) != 0 {
				Xsqlite3VectorErrorMsg(tls, (*SubstContext)(unsafe.Pointer(pSubst)).FpParse, pCopy)
			} else {
				var db uintptr = (*Parse)(unsafe.Pointer((*SubstContext)(unsafe.Pointer(pSubst)).FpParse)).Fdb
				if (*SubstContext)(unsafe.Pointer(pSubst)).FisOuterJoin != 0 &&
					(int32((*Expr)(unsafe.Pointer(pCopy)).Fop) != TK_COLUMN || (*Expr)(unsafe.Pointer(pCopy)).FiTable != (*SubstContext)(unsafe.Pointer(pSubst)).FiNewTable) {
					libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Expr{})))
					(*Expr)(unsafe.Pointer(bp)).Fop = U8(TK_IF_NULL_ROW)
					(*Expr)(unsafe.Pointer(bp)).FpLeft = pCopy
					(*Expr)(unsafe.Pointer(bp)).FiTable = (*SubstContext)(unsafe.Pointer(pSubst)).FiNewTable
					(*Expr)(unsafe.Pointer(bp)).FiColumn = int16(-99)
					(*Expr)(unsafe.Pointer(bp)).Fflags = U32(EP_IfNullRow)
					pCopy = bp
				}

				pNew = Xsqlite3ExprDup(tls, db, pCopy, 0)
				if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
					Xsqlite3ExprDelete(tls, db, pNew)
					return pExpr
				}
				if (*SubstContext)(unsafe.Pointer(pSubst)).FisOuterJoin != 0 {
					*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(EP_CanBeNull)
				}
				if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_InnerON) != U32(0) {
					Xsqlite3SetJoinExpr(tls, pNew, *(*int32)(unsafe.Pointer(pExpr + 52)),
						(*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_InnerON))
				}
				Xsqlite3ExprDelete(tls, db, pExpr)
				pExpr = pNew
				if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_TRUEFALSE {
					*(*int32)(unsafe.Pointer(pExpr + 8)) = Xsqlite3ExprTruthValue(tls, pExpr)
					(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_INTEGER)
					*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_IntValue)
				}

				{
					var pNat uintptr = Xsqlite3ExprCollSeq(tls, (*SubstContext)(unsafe.Pointer(pSubst)).FpParse, pExpr)
					var pColl uintptr = Xsqlite3ExprCollSeq(tls, (*SubstContext)(unsafe.Pointer(pSubst)).FpParse,
						(*ExprList_item)(unsafe.Pointer((*SubstContext)(unsafe.Pointer(pSubst)).FpCList+8+uintptr(iColumn)*32)).FpExpr)
					if pNat != pColl || int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_COLUMN && int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_COLLATE {
						pExpr = Xsqlite3ExprAddCollateString(tls, (*SubstContext)(unsafe.Pointer(pSubst)).FpParse, pExpr,
							func() uintptr {
								if pColl != 0 {
									return (*CollSeq)(unsafe.Pointer(pColl)).FzName
								}
								return ts + 1181
							}())
					}

				}
				*(*U32)(unsafe.Pointer(pExpr + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_Collate))
			}

		}
	} else {
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_IF_NULL_ROW && (*Expr)(unsafe.Pointer(pExpr)).FiTable == (*SubstContext)(unsafe.Pointer(pSubst)).FiTable {
			(*Expr)(unsafe.Pointer(pExpr)).FiTable = (*SubstContext)(unsafe.Pointer(pSubst)).FiNewTable
		}
		(*Expr)(unsafe.Pointer(pExpr)).FpLeft = substExpr(tls, pSubst, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
		(*Expr)(unsafe.Pointer(pExpr)).FpRight = substExpr(tls, pSubst, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
			substSelect(tls, pSubst, *(*uintptr)(unsafe.Pointer(pExpr + 32)), 1)
		} else {
			substExprList(tls, pSubst, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
		}
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
			var pWin uintptr = *(*uintptr)(unsafe.Pointer(pExpr + 64))
			(*Window)(unsafe.Pointer(pWin)).FpFilter = substExpr(tls, pSubst, (*Window)(unsafe.Pointer(pWin)).FpFilter)
			substExprList(tls, pSubst, (*Window)(unsafe.Pointer(pWin)).FpPartition)
			substExprList(tls, pSubst, (*Window)(unsafe.Pointer(pWin)).FpOrderBy)
		}
	}
	return pExpr
}

func substExprList(tls *libc.TLS, pSubst uintptr, pList uintptr) {
	var i int32
	if pList == uintptr(0) {
		return
	}
	for i = 0; i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
		(*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32)).FpExpr = substExpr(tls, pSubst, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr)
	}
}

func substSelect(tls *libc.TLS, pSubst uintptr, p uintptr, doPrior int32) {
	var pSrc uintptr
	var pItem uintptr
	var i int32
	if !(p != 0) {
		return
	}
	for __ccgo := true; __ccgo; __ccgo = doPrior != 0 && libc.AssignUintptr(&p, (*Select)(unsafe.Pointer(p)).FpPrior) != uintptr(0) {
		substExprList(tls, pSubst, (*Select)(unsafe.Pointer(p)).FpEList)
		substExprList(tls, pSubst, (*Select)(unsafe.Pointer(p)).FpGroupBy)
		substExprList(tls, pSubst, (*Select)(unsafe.Pointer(p)).FpOrderBy)
		(*Select)(unsafe.Pointer(p)).FpHaving = substExpr(tls, pSubst, (*Select)(unsafe.Pointer(p)).FpHaving)
		(*Select)(unsafe.Pointer(p)).FpWhere = substExpr(tls, pSubst, (*Select)(unsafe.Pointer(p)).FpWhere)
		pSrc = (*Select)(unsafe.Pointer(p)).FpSrc

		i = (*SrcList)(unsafe.Pointer(pSrc)).FnSrc
		pItem = pSrc + 8
	__1:
		if !(i > 0) {
			goto __3
		}
		{
			substSelect(tls, pSubst, (*SrcItem)(unsafe.Pointer(pItem)).FpSelect, 1)
			if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x4>>2)) != 0 {
				substExprList(tls, pSubst, *(*uintptr)(unsafe.Pointer(pItem + 88)))
			}

		}
		goto __2
	__2:
		i--
		pItem += 104
		goto __1
		goto __3
	__3:
	}
}

func recomputeColumnsUsedExpr(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var pItem uintptr
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_COLUMN {
		return WRC_Continue
	}
	pItem = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	if (*SrcItem)(unsafe.Pointer(pItem)).FiCursor != (*Expr)(unsafe.Pointer(pExpr)).FiTable {
		return WRC_Continue
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) < 0 {
		return WRC_Continue
	}
	*(*Bitmask)(unsafe.Pointer(pItem + 80)) |= Xsqlite3ExprColUsed(tls, pExpr)
	return WRC_Continue
}

func recomputeColumnsUsed(tls *libc.TLS, pSelect uintptr, pSrcItem uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if (*SrcItem)(unsafe.Pointer(pSrcItem)).FpTab == uintptr(0) {
		return
	}
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{recomputeColumnsUsedExpr}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3SelectWalkNoop}))
	*(*uintptr)(unsafe.Pointer(bp + 40)) = pSrcItem
	(*SrcItem)(unsafe.Pointer(pSrcItem)).FcolUsed = uint64(0)
	Xsqlite3WalkSelect(tls, bp, pSelect)
}

func srclistRenumberCursors(tls *libc.TLS, pParse uintptr, aCsrMap uintptr, pSrc uintptr, iExcept int32) {
	var i int32
	var pItem uintptr
	i = 0
	pItem = pSrc + 8
__1:
	if !(i < (*SrcList)(unsafe.Pointer(pSrc)).FnSrc) {
		goto __3
	}
	{
		if i != iExcept {
			var p uintptr

			if !(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x40>>6) != 0) || *(*int32)(unsafe.Pointer(aCsrMap + uintptr((*SrcItem)(unsafe.Pointer(pItem)).FiCursor+1)*4)) == 0 {
				*(*int32)(unsafe.Pointer(aCsrMap + uintptr((*SrcItem)(unsafe.Pointer(pItem)).FiCursor+1)*4)) = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
			}
			(*SrcItem)(unsafe.Pointer(pItem)).FiCursor = *(*int32)(unsafe.Pointer(aCsrMap + uintptr((*SrcItem)(unsafe.Pointer(pItem)).FiCursor+1)*4))
			for p = (*SrcItem)(unsafe.Pointer(pItem)).FpSelect; p != 0; p = (*Select)(unsafe.Pointer(p)).FpPrior {
				srclistRenumberCursors(tls, pParse, aCsrMap, (*Select)(unsafe.Pointer(p)).FpSrc, -1)
			}
		}

	}
	goto __2
__2:
	i++
	pItem += 104
	goto __1
	goto __3
__3:
}

func renumberCursorDoMapping(tls *libc.TLS, pWalker uintptr, piCursor uintptr) {
	var aCsrMap uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	var iCsr int32 = *(*int32)(unsafe.Pointer(piCursor))
	if iCsr < *(*int32)(unsafe.Pointer(aCsrMap)) && *(*int32)(unsafe.Pointer(aCsrMap + uintptr(iCsr+1)*4)) > 0 {
		*(*int32)(unsafe.Pointer(piCursor)) = *(*int32)(unsafe.Pointer(aCsrMap + uintptr(iCsr+1)*4))
	}
}

func renumberCursorsCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var op int32 = int32((*Expr)(unsafe.Pointer(pExpr)).Fop)
	if op == TK_COLUMN || op == TK_IF_NULL_ROW {
		renumberCursorDoMapping(tls, pWalker, pExpr+44)
	}
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0) {
		renumberCursorDoMapping(tls, pWalker, pExpr+52)
	}
	return WRC_Continue
}

func renumberCursors(tls *libc.TLS, pParse uintptr, p uintptr, iExcept int32, aCsrMap uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	srclistRenumberCursors(tls, pParse, aCsrMap, (*Select)(unsafe.Pointer(p)).FpSrc, iExcept)
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	*(*uintptr)(unsafe.Pointer(bp + 40)) = aCsrMap
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{renumberCursorsCb}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3SelectWalkNoop}))
	Xsqlite3WalkSelect(tls, bp, p)
}

func findLeftmostExprlist(tls *libc.TLS, pSel uintptr) uintptr {
	for (*Select)(unsafe.Pointer(pSel)).FpPrior != 0 {
		pSel = (*Select)(unsafe.Pointer(pSel)).FpPrior
	}
	return (*Select)(unsafe.Pointer(pSel)).FpEList
}

func compoundHasDifferentAffinities(tls *libc.TLS, p uintptr) int32 {
	var ii int32
	var pList uintptr

	pList = (*Select)(unsafe.Pointer(p)).FpEList
	for ii = 0; ii < (*ExprList)(unsafe.Pointer(pList)).FnExpr; ii++ {
		var aff uint8
		var pSub1 uintptr

		aff = Xsqlite3ExprAffinity(tls, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(ii)*32)).FpExpr)
		for pSub1 = (*Select)(unsafe.Pointer(p)).FpPrior; pSub1 != 0; pSub1 = (*Select)(unsafe.Pointer(pSub1)).FpPrior {
			if int32(Xsqlite3ExprAffinity(tls, (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(pSub1)).FpEList+8+uintptr(ii)*32)).FpExpr)) != int32(aff) {
				return 1
			}
		}
	}
	return 0
}

func flattenSubquery(tls *libc.TLS, pParse uintptr, p uintptr, iFrom int32, isAgg int32) int32 {
	bp := tls.Alloc(88)
	defer tls.Free(88)

	var zSavedAuthContext uintptr = (*Parse)(unsafe.Pointer(pParse)).FzAuthContext
	var pParent uintptr
	var pSub uintptr
	var pSub1 uintptr
	var pSrc uintptr
	var pSubSrc uintptr
	var iParent int32
	var iNewParent int32 = -1
	var isOuterJoin int32 = 0
	var i int32
	var pWhere uintptr
	var pSubitem uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	var aCsrMap uintptr = uintptr(0)

	if (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_QueryFlattener) != U32(0) {
		return 0
	}
	pSrc = (*Select)(unsafe.Pointer(p)).FpSrc

	pSubitem = pSrc + 8 + uintptr(iFrom)*104
	iParent = (*SrcItem)(unsafe.Pointer(pSubitem)).FiCursor
	pSub = (*SrcItem)(unsafe.Pointer(pSubitem)).FpSelect

	if (*Select)(unsafe.Pointer(p)).FpWin != 0 || (*Select)(unsafe.Pointer(pSub)).FpWin != 0 {
		return 0
	}

	pSubSrc = (*Select)(unsafe.Pointer(pSub)).FpSrc

	if (*Select)(unsafe.Pointer(pSub)).FpLimit != 0 && (*Select)(unsafe.Pointer(p)).FpLimit != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSub)).FpLimit != 0 && (*Expr)(unsafe.Pointer((*Select)(unsafe.Pointer(pSub)).FpLimit)).FpRight != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Compound) != U32(0) && (*Select)(unsafe.Pointer(pSub)).FpLimit != 0 {
		return 0
	}
	if (*SrcList)(unsafe.Pointer(pSubSrc)).FnSrc == 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSub)).FselFlags&U32(SF_Distinct) != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSub)).FpLimit != 0 && ((*SrcList)(unsafe.Pointer(pSrc)).FnSrc > 1 || isAgg != 0) {
		return 0
	}
	if (*Select)(unsafe.Pointer(p)).FpOrderBy != 0 && (*Select)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
		return 0
	}
	if isAgg != 0 && (*Select)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSub)).FpLimit != 0 && (*Select)(unsafe.Pointer(p)).FpWhere != 0 {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSub)).FpLimit != 0 && (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct) != U32(0) {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSub)).FselFlags&U32(SF_Recursive) != 0 {
		return 0
	}

	if int32((*SrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype)&(JT_OUTER|JT_LTORJ) != 0 {
		if (*SrcList)(unsafe.Pointer(pSubSrc)).FnSrc > 1 ||
			int32((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pSubSrc+8)).FpTab)).FeTabType) == TABTYP_VTAB ||
			(*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct) != U32(0) ||
			int32((*SrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype)&JT_RIGHT != 0 {
			return 0
		}
		isOuterJoin = 1
	}

	if iFrom > 0 && int32((*SrcItem)(unsafe.Pointer(pSubSrc+8)).Ffg.Fjointype)&JT_LTORJ != 0 {
		return 0
	}
	if uint32(int32(*(*uint16)(unsafe.Pointer(pSubitem + 60 + 4))&0x100>>8)) != 0 && int32((*CteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSubitem + 96)))).FeM10d) == M10d_Yes {
		return 0
	}

	if (*Select)(unsafe.Pointer(pSub)).FpPrior != 0 {
		var ii int32
		if (*Select)(unsafe.Pointer(pSub)).FpOrderBy != 0 {
			return 0
		}
		if isAgg != 0 || (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct) != U32(0) || isOuterJoin > 0 {
			return 0
		}
		for pSub1 = pSub; pSub1 != 0; pSub1 = (*Select)(unsafe.Pointer(pSub1)).FpPrior {
			if (*Select)(unsafe.Pointer(pSub1)).FselFlags&U32(SF_Distinct|SF_Aggregate) != U32(0) ||
				(*Select)(unsafe.Pointer(pSub1)).FpPrior != 0 && int32((*Select)(unsafe.Pointer(pSub1)).Fop) != TK_ALL ||
				(*SrcList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSub1)).FpSrc)).FnSrc < 1 ||
				(*Select)(unsafe.Pointer(pSub1)).FpWin != 0 {
				return 0
			}
			if iFrom > 0 && int32((*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(pSub1)).FpSrc+8)).Ffg.Fjointype)&JT_LTORJ != 0 {
				return 0
			}

		}

		if (*Select)(unsafe.Pointer(p)).FpOrderBy != 0 {
			for ii = 0; ii < (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpOrderBy)).FnExpr; ii++ {
				if int32(*(*U16)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpOrderBy + 8 + uintptr(ii)*32 + 24))) == 0 {
					return 0
				}
			}
		}

		if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Recursive) != 0 {
			return 0
		}

		if compoundHasDifferentAffinities(tls, pSub) != 0 {
			return 0
		}

		if (*SrcList)(unsafe.Pointer(pSrc)).FnSrc > 1 {
			if (*Parse)(unsafe.Pointer(pParse)).FnSelect > 500 {
				return 0
			}
			if (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_FlttnUnionAll) != U32(0) {
				return 0
			}
			aCsrMap = Xsqlite3DbMallocZero(tls, db, uint64(I64((*Parse)(unsafe.Pointer(pParse)).FnTab)+int64(1))*uint64(unsafe.Sizeof(int32(0))))
			if aCsrMap != 0 {
				*(*int32)(unsafe.Pointer(aCsrMap)) = (*Parse)(unsafe.Pointer(pParse)).FnTab
			}
		}
	}

	(*Parse)(unsafe.Pointer(pParse)).FzAuthContext = (*SrcItem)(unsafe.Pointer(pSubitem)).FzName
	Xsqlite3AuthCheck(tls, pParse, SQLITE_SELECT, uintptr(0), uintptr(0), uintptr(0))

	(*Parse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedAuthContext

	pSub1 = (*SrcItem)(unsafe.Pointer(pSubitem)).FpSelect
	Xsqlite3DbFree(tls, db, (*SrcItem)(unsafe.Pointer(pSubitem)).FzDatabase)
	Xsqlite3DbFree(tls, db, (*SrcItem)(unsafe.Pointer(pSubitem)).FzName)
	Xsqlite3DbFree(tls, db, (*SrcItem)(unsafe.Pointer(pSubitem)).FzAlias)
	(*SrcItem)(unsafe.Pointer(pSubitem)).FzDatabase = uintptr(0)
	(*SrcItem)(unsafe.Pointer(pSubitem)).FzName = uintptr(0)
	(*SrcItem)(unsafe.Pointer(pSubitem)).FzAlias = uintptr(0)
	(*SrcItem)(unsafe.Pointer(pSubitem)).FpSelect = uintptr(0)

	for pSub = (*Select)(unsafe.Pointer(pSub)).FpPrior; pSub != 0; pSub = (*Select)(unsafe.Pointer(pSub)).FpPrior {
		var pNew uintptr
		var pOrderBy uintptr = (*Select)(unsafe.Pointer(p)).FpOrderBy
		var pLimit uintptr = (*Select)(unsafe.Pointer(p)).FpLimit
		var pPrior uintptr = (*Select)(unsafe.Pointer(p)).FpPrior
		var pItemTab uintptr = (*SrcItem)(unsafe.Pointer(pSubitem)).FpTab
		(*SrcItem)(unsafe.Pointer(pSubitem)).FpTab = uintptr(0)
		(*Select)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
		(*Select)(unsafe.Pointer(p)).FpPrior = uintptr(0)
		(*Select)(unsafe.Pointer(p)).FpLimit = uintptr(0)
		pNew = Xsqlite3SelectDup(tls, db, p, 0)
		(*Select)(unsafe.Pointer(p)).FpLimit = pLimit
		(*Select)(unsafe.Pointer(p)).FpOrderBy = pOrderBy
		(*Select)(unsafe.Pointer(p)).Fop = U8(TK_ALL)
		(*SrcItem)(unsafe.Pointer(pSubitem)).FpTab = pItemTab
		if pNew == uintptr(0) {
			(*Select)(unsafe.Pointer(p)).FpPrior = pPrior
		} else {
			(*Select)(unsafe.Pointer(pNew)).FselId = U32(libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnSelect, 1))
			if aCsrMap != 0 && int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
				renumberCursors(tls, pParse, pNew, iFrom, aCsrMap)
			}
			(*Select)(unsafe.Pointer(pNew)).FpPrior = pPrior
			if pPrior != 0 {
				(*Select)(unsafe.Pointer(pPrior)).FpNext = pNew
			}
			(*Select)(unsafe.Pointer(pNew)).FpNext = p
			(*Select)(unsafe.Pointer(p)).FpPrior = pNew

		}

	}
	Xsqlite3DbFree(tls, db, aCsrMap)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*SrcItem)(unsafe.Pointer(pSubitem)).FpSelect = pSub1
		return 1
	}

	if (*SrcItem)(unsafe.Pointer(pSubitem)).FpTab != uintptr(0) {
		var pTabToDel uintptr = (*SrcItem)(unsafe.Pointer(pSubitem)).FpTab
		if (*Table)(unsafe.Pointer(pTabToDel)).FnTabRef == U32(1) {
			var pToplevel uintptr = func() uintptr {
				if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
					return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
				}
				return pParse
			}()
			Xsqlite3ParserAddCleanup(tls, pToplevel,
				*(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr)
				}{Xsqlite3DeleteTable})),
				pTabToDel)

		} else {
			(*Table)(unsafe.Pointer(pTabToDel)).FnTabRef--
		}
		(*SrcItem)(unsafe.Pointer(pSubitem)).FpTab = uintptr(0)
	}

	pSub = pSub1
	pParent = p
__1:
	if !(pParent != 0) {
		goto __3
	}
	{
		var nSubSrc int32
		var jointype U8 = U8(0)
		var ltorj U8 = U8(int32((*SrcItem)(unsafe.Pointer(pSrc+8+uintptr(iFrom)*104)).Ffg.Fjointype) & JT_LTORJ)

		pSubSrc = (*Select)(unsafe.Pointer(pSub)).FpSrc
		nSubSrc = (*SrcList)(unsafe.Pointer(pSubSrc)).FnSrc
		pSrc = (*Select)(unsafe.Pointer(pParent)).FpSrc

		if pParent == p {
			jointype = (*SrcItem)(unsafe.Pointer(pSubitem)).Ffg.Fjointype
		}

		if nSubSrc > 1 {
			pSrc = Xsqlite3SrcListEnlarge(tls, pParse, pSrc, nSubSrc-1, iFrom+1)
			if pSrc == uintptr(0) {
				goto __3
			}
			(*Select)(unsafe.Pointer(pParent)).FpSrc = pSrc
		}

		for i = 0; i < nSubSrc; i++ {
			var pItem uintptr = pSrc + 8 + uintptr(i+iFrom)*104
			if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x400>>10)) != 0 {
				Xsqlite3IdListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 72)))
			}

			*(*SrcItem)(unsafe.Pointer(pItem)) = *(*SrcItem)(unsafe.Pointer(pSubSrc + 8 + uintptr(i)*104))
			*(*U8)(unsafe.Pointer(pItem + 60)) |= U8(int32(ltorj))
			iNewParent = (*SrcItem)(unsafe.Pointer(pSubSrc + 8 + uintptr(i)*104)).FiCursor
			libc.Xmemset(tls, pSubSrc+8+uintptr(i)*104, 0, uint64(unsafe.Sizeof(SrcItem{})))
		}
		*(*U8)(unsafe.Pointer(pSrc + 8 + uintptr(iFrom)*104 + 60)) &= U8(JT_LTORJ)
		*(*U8)(unsafe.Pointer(pSrc + 8 + uintptr(iFrom)*104 + 60)) |= U8(int32(jointype) | int32(ltorj))

		if (*Select)(unsafe.Pointer(pSub)).FpOrderBy != 0 && (*Select)(unsafe.Pointer(pParent)).FselFlags&U32(SF_NoopOrderBy) == U32(0) {
			var pOrderBy uintptr = (*Select)(unsafe.Pointer(pSub)).FpOrderBy
			for i = 0; i < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr; i++ {
				*(*U16)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32 + 24)) = U16(0)
			}

			(*Select)(unsafe.Pointer(pParent)).FpOrderBy = pOrderBy
			(*Select)(unsafe.Pointer(pSub)).FpOrderBy = uintptr(0)
		}
		pWhere = (*Select)(unsafe.Pointer(pSub)).FpWhere
		(*Select)(unsafe.Pointer(pSub)).FpWhere = uintptr(0)
		if isOuterJoin > 0 {
			Xsqlite3SetJoinExpr(tls, pWhere, iNewParent, uint32(EP_OuterON))
		}
		if pWhere != 0 {
			if (*Select)(unsafe.Pointer(pParent)).FpWhere != 0 {
				(*Select)(unsafe.Pointer(pParent)).FpWhere = Xsqlite3PExpr(tls, pParse, TK_AND, pWhere, (*Select)(unsafe.Pointer(pParent)).FpWhere)
			} else {
				(*Select)(unsafe.Pointer(pParent)).FpWhere = pWhere
			}
		}
		if int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
			(*SubstContext)(unsafe.Pointer(bp)).FpParse = pParse
			(*SubstContext)(unsafe.Pointer(bp)).FiTable = iParent
			(*SubstContext)(unsafe.Pointer(bp)).FiNewTable = iNewParent
			(*SubstContext)(unsafe.Pointer(bp)).FisOuterJoin = isOuterJoin
			(*SubstContext)(unsafe.Pointer(bp)).FpEList = (*Select)(unsafe.Pointer(pSub)).FpEList
			(*SubstContext)(unsafe.Pointer(bp)).FpCList = findLeftmostExprlist(tls, pSub)
			substSelect(tls, bp, pParent, 0)
		}

		*(*U32)(unsafe.Pointer(pParent + 4)) |= (*Select)(unsafe.Pointer(pSub)).FselFlags & U32(SF_Compound)

		if (*Select)(unsafe.Pointer(pSub)).FpLimit != 0 {
			(*Select)(unsafe.Pointer(pParent)).FpLimit = (*Select)(unsafe.Pointer(pSub)).FpLimit
			(*Select)(unsafe.Pointer(pSub)).FpLimit = uintptr(0)
		}

		for i = 0; i < nSubSrc; i++ {
			recomputeColumnsUsed(tls, pParent, pSrc+8+uintptr(i+iFrom)*104)
		}

	}
	goto __2
__2:
	pParent = (*Select)(unsafe.Pointer(pParent)).FpPrior
	pSub = (*Select)(unsafe.Pointer(pSub)).FpPrior
	goto __1
	goto __3
__3:
	;
	Xsqlite3AggInfoPersistWalkerInit(tls, bp+40, pParse)
	Xsqlite3WalkSelect(tls, bp+40, pSub1)
	Xsqlite3SelectDelete(tls, db, pSub1)

	return 1
}

type WhereConst = WhereConst1

func constInsert(tls *libc.TLS, pConst uintptr, pColumn uintptr, pValue uintptr, pExpr uintptr) {
	var i int32

	if (*Expr)(unsafe.Pointer(pColumn)).Fflags&U32(EP_FixedCol) != U32(0) {
		return
	}
	if int32(Xsqlite3ExprAffinity(tls, pValue)) != 0 {
		return
	}
	if !(Xsqlite3IsBinary(tls, Xsqlite3ExprCompareCollSeq(tls, (*WhereConst)(unsafe.Pointer(pConst)).FpParse, pExpr)) != 0) {
		return
	}

	for i = 0; i < (*WhereConst)(unsafe.Pointer(pConst)).FnConst; i++ {
		var pE2 uintptr = *(*uintptr)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr(i*2)*8))

		if (*Expr)(unsafe.Pointer(pE2)).FiTable == (*Expr)(unsafe.Pointer(pColumn)).FiTable &&
			int32((*Expr)(unsafe.Pointer(pE2)).FiColumn) == int32((*Expr)(unsafe.Pointer(pColumn)).FiColumn) {
			return
		}
	}
	if int32(Xsqlite3ExprAffinity(tls, pColumn)) == SQLITE_AFF_BLOB {
		(*WhereConst)(unsafe.Pointer(pConst)).FbHasAffBlob = 1
	}

	(*WhereConst)(unsafe.Pointer(pConst)).FnConst++
	(*WhereConst)(unsafe.Pointer(pConst)).FapExpr = Xsqlite3DbReallocOrFree(tls, (*Parse)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FpParse)).Fdb, (*WhereConst)(unsafe.Pointer(pConst)).FapExpr,
		uint64((*WhereConst)(unsafe.Pointer(pConst)).FnConst*2)*uint64(unsafe.Sizeof(uintptr(0))))
	if (*WhereConst)(unsafe.Pointer(pConst)).FapExpr == uintptr(0) {
		(*WhereConst)(unsafe.Pointer(pConst)).FnConst = 0
	} else {
		*(*uintptr)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr((*WhereConst)(unsafe.Pointer(pConst)).FnConst*2-2)*8)) = pColumn
		*(*uintptr)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr((*WhereConst)(unsafe.Pointer(pConst)).FnConst*2-1)*8)) = pValue
	}
}

func findConstInWhere(tls *libc.TLS, pConst uintptr, pExpr uintptr) {
	var pRight uintptr
	var pLeft uintptr
	if pExpr == uintptr(0) {
		return
	}
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&(*WhereConst)(unsafe.Pointer(pConst)).FmExcludeOn != U32(0) {
		return
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AND {
		findConstInWhere(tls, pConst, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
		findConstInWhere(tls, pConst, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
		return
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_EQ {
		return
	}
	pRight = (*Expr)(unsafe.Pointer(pExpr)).FpRight
	pLeft = (*Expr)(unsafe.Pointer(pExpr)).FpLeft

	if int32((*Expr)(unsafe.Pointer(pRight)).Fop) == TK_COLUMN && Xsqlite3ExprIsConstant(tls, pLeft) != 0 {
		constInsert(tls, pConst, pRight, pLeft, pExpr)
	}
	if int32((*Expr)(unsafe.Pointer(pLeft)).Fop) == TK_COLUMN && Xsqlite3ExprIsConstant(tls, pRight) != 0 {
		constInsert(tls, pConst, pLeft, pRight, pExpr)
	}
}

func propagateConstantExprRewriteOne(tls *libc.TLS, pConst uintptr, pExpr uintptr, bIgnoreAffBlob int32) int32 {
	var i int32
	if *(*U8)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FpOomFault)) != 0 {
		return WRC_Prune
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_COLUMN {
		return WRC_Continue
	}
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&(U32(EP_FixedCol)|(*WhereConst)(unsafe.Pointer(pConst)).FmExcludeOn) != U32(0) {
		return WRC_Continue
	}
	for i = 0; i < (*WhereConst)(unsafe.Pointer(pConst)).FnConst; i++ {
		var pColumn uintptr = *(*uintptr)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr(i*2)*8))
		if pColumn == pExpr {
			continue
		}
		if (*Expr)(unsafe.Pointer(pColumn)).FiTable != (*Expr)(unsafe.Pointer(pExpr)).FiTable {
			continue
		}
		if int32((*Expr)(unsafe.Pointer(pColumn)).FiColumn) != int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) {
			continue
		}
		if bIgnoreAffBlob != 0 && int32(Xsqlite3ExprAffinity(tls, pColumn)) == SQLITE_AFF_BLOB {
			break
		}

		(*WhereConst)(unsafe.Pointer(pConst)).FnChng++
		*(*U32)(unsafe.Pointer(pExpr + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_Leaf))
		*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_FixedCol)

		(*Expr)(unsafe.Pointer(pExpr)).FpLeft = Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FpParse)).Fdb, *(*uintptr)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FapExpr + uintptr(i*2+1)*8)), 0)
		if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FpParse)).Fdb)).FmallocFailed != 0 {
			return WRC_Prune
		}
		break
	}
	return WRC_Prune
}

func propagateConstantExprRewrite(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var pConst uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))

	if (*WhereConst)(unsafe.Pointer(pConst)).FbHasAffBlob != 0 {
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) >= TK_EQ && int32((*Expr)(unsafe.Pointer(pExpr)).Fop) <= TK_GE ||
			int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_IS {
			propagateConstantExprRewriteOne(tls, pConst, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, 0)
			if *(*U8)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(pConst)).FpOomFault)) != 0 {
				return WRC_Prune
			}
			if int32(Xsqlite3ExprAffinity(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)) != SQLITE_AFF_TEXT {
				propagateConstantExprRewriteOne(tls, pConst, (*Expr)(unsafe.Pointer(pExpr)).FpRight, 0)
			}
		}
	}
	return propagateConstantExprRewriteOne(tls, pConst, pExpr, (*WhereConst)(unsafe.Pointer(pConst)).FbHasAffBlob)
}

func propagateConstants(tls *libc.TLS, pParse uintptr, p uintptr) int32 {
	bp := tls.Alloc(88)
	defer tls.Free(88)

	var nChng int32 = 0
	(*WhereConst)(unsafe.Pointer(bp)).FpParse = pParse
	(*WhereConst)(unsafe.Pointer(bp)).FpOomFault = (*Parse)(unsafe.Pointer(pParse)).Fdb + 103
	for __ccgo := true; __ccgo; __ccgo = (*WhereConst)(unsafe.Pointer(bp)).FnChng != 0 {
		(*WhereConst)(unsafe.Pointer(bp)).FnConst = 0
		(*WhereConst)(unsafe.Pointer(bp)).FnChng = 0
		(*WhereConst)(unsafe.Pointer(bp)).FapExpr = uintptr(0)
		(*WhereConst)(unsafe.Pointer(bp)).FbHasAffBlob = 0
		if (*Select)(unsafe.Pointer(p)).FpSrc != uintptr(0) &&
			(*SrcList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc)).FnSrc > 0 &&
			int32((*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc+8)).Ffg.Fjointype)&JT_LTORJ != 0 {
			(*WhereConst)(unsafe.Pointer(bp)).FmExcludeOn = U32(EP_InnerON | EP_OuterON)
		} else {
			(*WhereConst)(unsafe.Pointer(bp)).FmExcludeOn = U32(EP_OuterON)
		}
		findConstInWhere(tls, bp, (*Select)(unsafe.Pointer(p)).FpWhere)
		if (*WhereConst)(unsafe.Pointer(bp)).FnConst != 0 {
			libc.Xmemset(tls, bp+40, 0, uint64(unsafe.Sizeof(Walker{})))
			(*Walker)(unsafe.Pointer(bp + 40)).FpParse = pParse
			(*Walker)(unsafe.Pointer(bp + 40)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			}{propagateConstantExprRewrite}))
			(*Walker)(unsafe.Pointer(bp + 40)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			}{Xsqlite3SelectWalkNoop}))
			(*Walker)(unsafe.Pointer(bp + 40)).FxSelectCallback2 = uintptr(0)
			(*Walker)(unsafe.Pointer(bp + 40)).FwalkerDepth = 0
			*(*uintptr)(unsafe.Pointer(bp + 40 + 40)) = bp
			Xsqlite3WalkExpr(tls, bp+40, (*Select)(unsafe.Pointer(p)).FpWhere)
			Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer((*WhereConst)(unsafe.Pointer(bp)).FpParse)).Fdb, (*WhereConst)(unsafe.Pointer(bp)).FapExpr)
			nChng = nChng + (*WhereConst)(unsafe.Pointer(bp)).FnChng
		}
	}
	return nChng
}

func pushDownWindowCheck(tls *libc.TLS, pParse uintptr, pSubq uintptr, pExpr uintptr) int32 {
	return Xsqlite3ExprIsConstantOrGroupBy(tls, pParse, pExpr, (*Window)(unsafe.Pointer((*Select)(unsafe.Pointer(pSubq)).FpWin)).FpPartition)
}

func pushDownWhereTerms(tls *libc.TLS, pParse uintptr, pSubq uintptr, pWhere uintptr, pSrc uintptr) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var pNew uintptr
	var nChng int32 = 0
	if pWhere == uintptr(0) {
		return 0
	}
	if (*Select)(unsafe.Pointer(pSubq)).FselFlags&U32(SF_Recursive|SF_MultiPart) != 0 {
		return 0
	}
	if int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(JT_LTORJ|JT_RIGHT) != 0 {
		return 0
	}

	if (*Select)(unsafe.Pointer(pSubq)).FpPrior != 0 {
		var pSel uintptr
		var notUnionAll int32 = 0
		for pSel = pSubq; pSel != 0; pSel = (*Select)(unsafe.Pointer(pSel)).FpPrior {
			var op U8 = (*Select)(unsafe.Pointer(pSel)).Fop

			if int32(op) != TK_ALL && int32(op) != TK_SELECT {
				notUnionAll = 1
			}
			if (*Select)(unsafe.Pointer(pSel)).FpWin != 0 {
				return 0
			}
		}
		if compoundHasDifferentAffinities(tls, pSubq) != 0 {
			return 0
		}
		if notUnionAll != 0 {
			for pSel = pSubq; pSel != 0; pSel = (*Select)(unsafe.Pointer(pSel)).FpPrior {
				var ii int32
				var pList uintptr = (*Select)(unsafe.Pointer(pSel)).FpEList

				for ii = 0; ii < (*ExprList)(unsafe.Pointer(pList)).FnExpr; ii++ {
					var pColl uintptr = Xsqlite3ExprCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(ii)*32)).FpExpr)
					if !(Xsqlite3IsBinary(tls, pColl) != 0) {
						return 0
					}
				}
			}
		}
	} else {
		if (*Select)(unsafe.Pointer(pSubq)).FpWin != 0 && (*Window)(unsafe.Pointer((*Select)(unsafe.Pointer(pSubq)).FpWin)).FpPartition == uintptr(0) {
			return 0
		}
	}

	if (*Select)(unsafe.Pointer(pSubq)).FpLimit != uintptr(0) {
		return 0
	}
	for int32((*Expr)(unsafe.Pointer(pWhere)).Fop) == TK_AND {
		nChng = nChng + pushDownWhereTerms(tls, pParse, pSubq, (*Expr)(unsafe.Pointer(pWhere)).FpRight, pSrc)
		pWhere = (*Expr)(unsafe.Pointer(pWhere)).FpLeft
	}

	if Xsqlite3ExprIsTableConstraint(tls, pWhere, pSrc) != 0 {
		nChng++
		*(*U32)(unsafe.Pointer(pSubq + 4)) |= U32(SF_PushDown)
		for pSubq != 0 {
			pNew = Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pWhere, 0)
			unsetJoinExpr(tls, pNew, -1, 1)
			(*SubstContext)(unsafe.Pointer(bp)).FpParse = pParse
			(*SubstContext)(unsafe.Pointer(bp)).FiTable = (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor
			(*SubstContext)(unsafe.Pointer(bp)).FiNewTable = (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor
			(*SubstContext)(unsafe.Pointer(bp)).FisOuterJoin = 0
			(*SubstContext)(unsafe.Pointer(bp)).FpEList = (*Select)(unsafe.Pointer(pSubq)).FpEList
			(*SubstContext)(unsafe.Pointer(bp)).FpCList = findLeftmostExprlist(tls, pSubq)
			pNew = substExpr(tls, bp, pNew)
			if (*Select)(unsafe.Pointer(pSubq)).FpWin != 0 && 0 == pushDownWindowCheck(tls, pParse, pSubq, pNew) {
				Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pNew)
				nChng--
				break
			}
			if (*Select)(unsafe.Pointer(pSubq)).FselFlags&U32(SF_Aggregate) != 0 {
				(*Select)(unsafe.Pointer(pSubq)).FpHaving = Xsqlite3ExprAnd(tls, pParse, (*Select)(unsafe.Pointer(pSubq)).FpHaving, pNew)
			} else {
				(*Select)(unsafe.Pointer(pSubq)).FpWhere = Xsqlite3ExprAnd(tls, pParse, (*Select)(unsafe.Pointer(pSubq)).FpWhere, pNew)
			}
			pSubq = (*Select)(unsafe.Pointer(pSubq)).FpPrior
		}
	}
	return nChng
}

func minMaxQuery(tls *libc.TLS, db uintptr, pFunc uintptr, ppMinMax uintptr) U8 {
	var eRet int32 = WHERE_ORDERBY_NORMAL
	var pEList uintptr
	var zFunc uintptr
	var pOrderBy uintptr
	var sortFlags U8 = U8(0)

	pEList = *(*uintptr)(unsafe.Pointer(pFunc + 32))
	if pEList == uintptr(0) ||
		(*ExprList)(unsafe.Pointer(pEList)).FnExpr != 1 ||
		(*Expr)(unsafe.Pointer(pFunc)).Fflags&U32(EP_WinFunc) != U32(0) ||
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_MinMaxOpt) != U32(0) {
		return U8(eRet)
	}

	zFunc = *(*uintptr)(unsafe.Pointer(pFunc + 8))
	if Xsqlite3StrICmp(tls, zFunc, ts+18577) == 0 {
		eRet = WHERE_ORDERBY_MIN
		if Xsqlite3ExprCanBeNull(tls, (*ExprList_item)(unsafe.Pointer(pEList+8)).FpExpr) != 0 {
			sortFlags = U8(KEYINFO_ORDER_BIGNULL)
		}
	} else if Xsqlite3StrICmp(tls, zFunc, ts+18581) == 0 {
		eRet = WHERE_ORDERBY_MAX
		sortFlags = U8(KEYINFO_ORDER_DESC)
	} else {
		return U8(eRet)
	}
	*(*uintptr)(unsafe.Pointer(ppMinMax)) = libc.AssignUintptr(&pOrderBy, Xsqlite3ExprListDup(tls, db, pEList, 0))

	if pOrderBy != 0 {
		(*ExprList_item)(unsafe.Pointer(pOrderBy + 8)).Ffg.FsortFlags = sortFlags
	}
	return U8(eRet)
}

func isSimpleCount(tls *libc.TLS, p uintptr, pAggInfo uintptr) uintptr {
	var pTab uintptr
	var pExpr uintptr

	if (*Select)(unsafe.Pointer(p)).FpWhere != 0 ||
		(*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr != 1 ||
		(*SrcList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc)).FnSrc != 1 ||
		(*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc+8)).FpSelect != 0 ||
		(*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc != 1 ||
		(*Select)(unsafe.Pointer(p)).FpHaving != 0 {
		return uintptr(0)
	}
	pTab = (*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FpTab

	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM) {
		return uintptr(0)
	}
	pExpr = (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList + 8)).FpExpr

	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_AGG_FUNCTION {
		return uintptr(0)
	}
	if (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo != pAggInfo {
		return uintptr(0)
	}
	if (*FuncDef)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FpFunc)).FfuncFlags&U32(SQLITE_FUNC_COUNT) == U32(0) {
		return uintptr(0)
	}

	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Distinct|EP_WinFunc) != U32(0) {
		return uintptr(0)
	}

	return pTab
}

func Xsqlite3IndexedByLookup(tls *libc.TLS, pParse uintptr, pFrom uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTab uintptr = (*SrcItem)(unsafe.Pointer(pFrom)).FpTab
	var zIndexedBy uintptr = *(*uintptr)(unsafe.Pointer(pFrom + 88))
	var pIdx uintptr

	for pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIdx != 0 && Xsqlite3StrICmp(tls, (*Index)(unsafe.Pointer(pIdx)).FzName, zIndexedBy) != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
	}
	if !(pIdx != 0) {
		Xsqlite3ErrorMsg(tls, pParse, ts+23051, libc.VaList(bp, zIndexedBy, 0))
		(*Parse)(unsafe.Pointer(pParse)).FcheckSchema = U8(1)
		return SQLITE_ERROR
	}

	*(*uintptr)(unsafe.Pointer(pFrom + 96)) = pIdx
	return SQLITE_OK
}

func convertCompoundSelectToSubquery(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var i int32
	var pNew uintptr
	var pX uintptr
	var db uintptr
	var a uintptr
	var pNewSrc uintptr
	var pParse uintptr

	if (*Select)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
		return WRC_Continue
	}
	if (*Select)(unsafe.Pointer(p)).FpOrderBy == uintptr(0) {
		return WRC_Continue
	}
	for pX = p; pX != 0 && (int32((*Select)(unsafe.Pointer(pX)).Fop) == TK_ALL || int32((*Select)(unsafe.Pointer(pX)).Fop) == TK_SELECT); pX = (*Select)(unsafe.Pointer(pX)).FpPrior {
	}
	if pX == uintptr(0) {
		return WRC_Continue
	}
	a = (*Select)(unsafe.Pointer(p)).FpOrderBy + 8

	if *(*U16)(unsafe.Pointer(a + 24)) != 0 {
		return WRC_Continue
	}
	for i = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpOrderBy)).FnExpr - 1; i >= 0; i-- {
		if (*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(a+uintptr(i)*32)).FpExpr)).Fflags&U32(EP_Collate) != 0 {
			break
		}
	}
	if i < 0 {
		return WRC_Continue
	}

	pParse = (*Walker)(unsafe.Pointer(pWalker)).FpParse
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	pNew = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Select{})))
	if pNew == uintptr(0) {
		return WRC_Abort
	}
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Token{})))
	pNewSrc = Xsqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp, pNew, uintptr(0))
	if pNewSrc == uintptr(0) {
		return WRC_Abort
	}
	*(*Select)(unsafe.Pointer(pNew)) = *(*Select)(unsafe.Pointer(p))
	(*Select)(unsafe.Pointer(p)).FpSrc = pNewSrc
	(*Select)(unsafe.Pointer(p)).FpEList = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), Xsqlite3Expr(tls, db, TK_ASTERISK, uintptr(0)))
	(*Select)(unsafe.Pointer(p)).Fop = U8(TK_SELECT)
	(*Select)(unsafe.Pointer(p)).FpWhere = uintptr(0)
	(*Select)(unsafe.Pointer(pNew)).FpGroupBy = uintptr(0)
	(*Select)(unsafe.Pointer(pNew)).FpHaving = uintptr(0)
	(*Select)(unsafe.Pointer(pNew)).FpOrderBy = uintptr(0)
	(*Select)(unsafe.Pointer(p)).FpPrior = uintptr(0)
	(*Select)(unsafe.Pointer(p)).FpNext = uintptr(0)
	(*Select)(unsafe.Pointer(p)).FpWith = uintptr(0)
	(*Select)(unsafe.Pointer(p)).FpWinDefn = uintptr(0)
	*(*U32)(unsafe.Pointer(p + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_Compound))

	*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_Converted)

	(*Select)(unsafe.Pointer((*Select)(unsafe.Pointer(pNew)).FpPrior)).FpNext = pNew
	(*Select)(unsafe.Pointer(pNew)).FpLimit = uintptr(0)
	return WRC_Continue
}

func cannotBeFunction(tls *libc.TLS, pParse uintptr, pFrom uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 60 + 4))&0x4>>2)) != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+23069, libc.VaList(bp, (*SrcItem)(unsafe.Pointer(pFrom)).FzName))
		return 1
	}
	return 0
}

func searchWith(tls *libc.TLS, pWith uintptr, pItem uintptr, ppContext uintptr) uintptr {
	var zName uintptr = (*SrcItem)(unsafe.Pointer(pItem)).FzName
	var p uintptr

	for p = pWith; p != 0; p = (*With)(unsafe.Pointer(p)).FpOuter {
		var i int32
		for i = 0; i < (*With)(unsafe.Pointer(p)).FnCte; i++ {
			if Xsqlite3StrICmp(tls, zName, (*Cte)(unsafe.Pointer(p+16+uintptr(i)*48)).FzName) == 0 {
				*(*uintptr)(unsafe.Pointer(ppContext)) = p
				return p + 16 + uintptr(i)*48
			}
		}
		if (*With)(unsafe.Pointer(p)).FbView != 0 {
			break
		}
	}
	return uintptr(0)
}

func Xsqlite3WithPush(tls *libc.TLS, pParse uintptr, pWith uintptr, bFree U8) uintptr {
	if pWith != 0 {
		if bFree != 0 {
			pWith = Xsqlite3ParserAddCleanup(tls, pParse,
				*(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr)
				}{Xsqlite3WithDelete})),
				pWith)
			if pWith == uintptr(0) {
				return uintptr(0)
			}
		}
		if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 {
			(*With)(unsafe.Pointer(pWith)).FpOuter = (*Parse)(unsafe.Pointer(pParse)).FpWith
			(*Parse)(unsafe.Pointer(pParse)).FpWith = pWith
		}
	}
	return pWith
}

func resolveFromTermToCte(tls *libc.TLS, pParse uintptr, pWalker uintptr, pFrom uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var pCte uintptr

	if (*Parse)(unsafe.Pointer(pParse)).FpWith == uintptr(0) {
		return 0
	}
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return 0
	}
	if (*SrcItem)(unsafe.Pointer(pFrom)).FzDatabase != uintptr(0) {
		return 0
	}
	if uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 60 + 4))&0x200>>9)) != 0 {
		return 0
	}
	pCte = searchWith(tls, (*Parse)(unsafe.Pointer(pParse)).FpWith, pFrom, bp+48)
	if pCte != 0 {
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		var pTab uintptr
		var pEList uintptr
		var pSel uintptr
		var pLeft uintptr
		var pRecTerm uintptr
		var bMayRecursive int32
		var pSavedWith uintptr
		var iRecTab int32 = -1
		var pCteUse uintptr

		if (*Cte)(unsafe.Pointer(pCte)).FzCteErr != 0 {
			Xsqlite3ErrorMsg(tls, pParse, (*Cte)(unsafe.Pointer(pCte)).FzCteErr, libc.VaList(bp, (*Cte)(unsafe.Pointer(pCte)).FzName))
			return 2
		}
		if cannotBeFunction(tls, pParse, pFrom) != 0 {
			return 2
		}

		pTab = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Table{})))
		if pTab == uintptr(0) {
			return 2
		}
		pCteUse = (*Cte)(unsafe.Pointer(pCte)).FpUse
		if pCteUse == uintptr(0) {
			(*Cte)(unsafe.Pointer(pCte)).FpUse = libc.AssignUintptr(&pCteUse, Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(CteUse{}))))
			if pCteUse == uintptr(0) ||
				Xsqlite3ParserAddCleanup(tls, pParse, *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr)
				}{Xsqlite3DbFree})), pCteUse) == uintptr(0) {
				Xsqlite3DbFree(tls, db, pTab)
				return 2
			}
			(*CteUse)(unsafe.Pointer(pCteUse)).FeM10d = (*Cte)(unsafe.Pointer(pCte)).FeM10d
		}
		(*SrcItem)(unsafe.Pointer(pFrom)).FpTab = pTab
		(*Table)(unsafe.Pointer(pTab)).FnTabRef = U32(1)
		(*Table)(unsafe.Pointer(pTab)).FzName = Xsqlite3DbStrDup(tls, db, (*Cte)(unsafe.Pointer(pCte)).FzName)
		(*Table)(unsafe.Pointer(pTab)).FiPKey = int16(-1)
		(*Table)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)
		*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_Ephemeral | TF_NoVisibleRowid)
		(*SrcItem)(unsafe.Pointer(pFrom)).FpSelect = Xsqlite3SelectDup(tls, db, (*Cte)(unsafe.Pointer(pCte)).FpSelect, 0)
		if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			return 2
		}
		*(*U32)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pFrom)).FpSelect + 4)) |= U32(SF_CopyCte)

		if uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 60 + 4))&0x2>>1)) != 0 {
			Xsqlite3ErrorMsg(tls, pParse, ts+23092, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(pFrom + 88))))
			return 2
		}
		libc.SetBitFieldPtr16Uint32(pFrom+60+4, uint32(1), 8, 0x100)
		*(*uintptr)(unsafe.Pointer(pFrom + 96)) = pCteUse
		(*CteUse)(unsafe.Pointer(pCteUse)).FnUse++

		pRecTerm = libc.AssignUintptr(&pSel, (*SrcItem)(unsafe.Pointer(pFrom)).FpSelect)
		bMayRecursive = libc.Bool32(int32((*Select)(unsafe.Pointer(pSel)).Fop) == TK_ALL || int32((*Select)(unsafe.Pointer(pSel)).Fop) == TK_UNION)
		for bMayRecursive != 0 && int32((*Select)(unsafe.Pointer(pRecTerm)).Fop) == int32((*Select)(unsafe.Pointer(pSel)).Fop) {
			var i int32
			var pSrc uintptr = (*Select)(unsafe.Pointer(pRecTerm)).FpSrc

			for i = 0; i < (*SrcList)(unsafe.Pointer(pSrc)).FnSrc; i++ {
				var pItem uintptr = pSrc + 8 + uintptr(i)*104
				if (*SrcItem)(unsafe.Pointer(pItem)).FzDatabase == uintptr(0) &&
					(*SrcItem)(unsafe.Pointer(pItem)).FzName != uintptr(0) &&
					0 == Xsqlite3StrICmp(tls, (*SrcItem)(unsafe.Pointer(pItem)).FzName, (*Cte)(unsafe.Pointer(pCte)).FzName) {
					(*SrcItem)(unsafe.Pointer(pItem)).FpTab = pTab
					(*Table)(unsafe.Pointer(pTab)).FnTabRef++
					libc.SetBitFieldPtr16Uint32(pItem+60+4, uint32(1), 6, 0x40)
					if (*Select)(unsafe.Pointer(pRecTerm)).FselFlags&U32(SF_Recursive) != 0 {
						Xsqlite3ErrorMsg(tls, pParse,
							ts+23112, libc.VaList(bp+16, (*Cte)(unsafe.Pointer(pCte)).FzName))
						return 2
					}
					*(*U32)(unsafe.Pointer(pRecTerm + 4)) |= U32(SF_Recursive)
					if iRecTab < 0 {
						iRecTab = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
					}
					(*SrcItem)(unsafe.Pointer(pItem)).FiCursor = iRecTab
				}
			}
			if (*Select)(unsafe.Pointer(pRecTerm)).FselFlags&U32(SF_Recursive) == U32(0) {
				break
			}
			pRecTerm = (*Select)(unsafe.Pointer(pRecTerm)).FpPrior
		}

		(*Cte)(unsafe.Pointer(pCte)).FzCteErr = ts + 23155
		pSavedWith = (*Parse)(unsafe.Pointer(pParse)).FpWith
		(*Parse)(unsafe.Pointer(pParse)).FpWith = *(*uintptr)(unsafe.Pointer(bp + 48))
		if (*Select)(unsafe.Pointer(pSel)).FselFlags&U32(SF_Recursive) != 0 {
			var rc int32

			(*Select)(unsafe.Pointer(pRecTerm)).FpWith = (*Select)(unsafe.Pointer(pSel)).FpWith
			rc = Xsqlite3WalkSelect(tls, pWalker, pRecTerm)
			(*Select)(unsafe.Pointer(pRecTerm)).FpWith = uintptr(0)
			if rc != 0 {
				(*Parse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return 2
			}
		} else {
			if Xsqlite3WalkSelect(tls, pWalker, pSel) != 0 {
				(*Parse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return 2
			}
		}
		(*Parse)(unsafe.Pointer(pParse)).FpWith = *(*uintptr)(unsafe.Pointer(bp + 48))

		for pLeft = pSel; (*Select)(unsafe.Pointer(pLeft)).FpPrior != 0; pLeft = (*Select)(unsafe.Pointer(pLeft)).FpPrior {
		}
		pEList = (*Select)(unsafe.Pointer(pLeft)).FpEList
		if (*Cte)(unsafe.Pointer(pCte)).FpCols != 0 {
			if pEList != 0 && (*ExprList)(unsafe.Pointer(pEList)).FnExpr != (*ExprList)(unsafe.Pointer((*Cte)(unsafe.Pointer(pCte)).FpCols)).FnExpr {
				Xsqlite3ErrorMsg(tls, pParse, ts+23178,
					libc.VaList(bp+24, (*Cte)(unsafe.Pointer(pCte)).FzName, (*ExprList)(unsafe.Pointer(pEList)).FnExpr, (*ExprList)(unsafe.Pointer((*Cte)(unsafe.Pointer(pCte)).FpCols)).FnExpr))
				(*Parse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
				return 2
			}
			pEList = (*Cte)(unsafe.Pointer(pCte)).FpCols
		}

		Xsqlite3ColumnsFromExprList(tls, pParse, pEList, pTab+54, pTab+8)
		if bMayRecursive != 0 {
			if (*Select)(unsafe.Pointer(pSel)).FselFlags&U32(SF_Recursive) != 0 {
				(*Cte)(unsafe.Pointer(pCte)).FzCteErr = ts + 23216
			} else {
				(*Cte)(unsafe.Pointer(pCte)).FzCteErr = ts + 23250
			}
			Xsqlite3WalkSelect(tls, pWalker, pSel)
		}
		(*Cte)(unsafe.Pointer(pCte)).FzCteErr = uintptr(0)
		(*Parse)(unsafe.Pointer(pParse)).FpWith = pSavedWith
		return 1
	}
	return 0
}

func Xsqlite3SelectPopWith(tls *libc.TLS, pWalker uintptr, p uintptr) {
	var pParse uintptr = (*Walker)(unsafe.Pointer(pWalker)).FpParse
	if (*Parse)(unsafe.Pointer(pParse)).FpWith != 0 && (*Select)(unsafe.Pointer(p)).FpPrior == uintptr(0) {
		var pWith uintptr = (*Select)(unsafe.Pointer(findRightmost(tls, p))).FpWith
		if pWith != uintptr(0) {
			(*Parse)(unsafe.Pointer(pParse)).FpWith = (*With)(unsafe.Pointer(pWith)).FpOuter
		}
	}
}

func Xsqlite3ExpandSubquery(tls *libc.TLS, pParse uintptr, pFrom uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pSel uintptr = (*SrcItem)(unsafe.Pointer(pFrom)).FpSelect
	var pTab uintptr

	(*SrcItem)(unsafe.Pointer(pFrom)).FpTab = libc.AssignUintptr(&pTab, Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(Table{}))))
	if pTab == uintptr(0) {
		return SQLITE_NOMEM
	}
	(*Table)(unsafe.Pointer(pTab)).FnTabRef = U32(1)
	if (*SrcItem)(unsafe.Pointer(pFrom)).FzAlias != 0 {
		(*Table)(unsafe.Pointer(pTab)).FzName = Xsqlite3DbStrDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*SrcItem)(unsafe.Pointer(pFrom)).FzAlias)
	} else {
		(*Table)(unsafe.Pointer(pTab)).FzName = Xsqlite3MPrintf(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, ts+23288, libc.VaList(bp, pFrom))
	}
	for (*Select)(unsafe.Pointer(pSel)).FpPrior != 0 {
		pSel = (*Select)(unsafe.Pointer(pSel)).FpPrior
	}
	Xsqlite3ColumnsFromExprList(tls, pParse, (*Select)(unsafe.Pointer(pSel)).FpEList, pTab+54, pTab+8)
	(*Table)(unsafe.Pointer(pTab)).FiPKey = int16(-1)
	(*Table)(unsafe.Pointer(pTab)).FnRowLogEst = int16(200)

	*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_Ephemeral | TF_NoVisibleRowid)
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return SQLITE_ERROR
	}
	return SQLITE_OK
}

func inAnyUsingClause(tls *libc.TLS, zName uintptr, pBase uintptr, N int32) int32 {
	for N > 0 {
		N--
		pBase += 104
		if int32(*(*uint16)(unsafe.Pointer(pBase + 60 + 4))&0x400>>10) == 0 {
			continue
		}
		if *(*uintptr)(unsafe.Pointer(pBase + 72)) == uintptr(0) {
			continue
		}
		if Xsqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pBase + 72)), zName) >= 0 {
			return 1
		}
	}
	return 0
}

func selectExpander(tls *libc.TLS, pWalker uintptr, p uintptr) int32 {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var pParse uintptr = (*Walker)(unsafe.Pointer(pWalker)).FpParse
	var i int32
	var j int32
	var k int32
	var rc int32
	var pTabList uintptr
	var pEList uintptr
	var pFrom uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pE uintptr
	var pRight uintptr
	var pExpr uintptr
	var selFlags U16 = U16((*Select)(unsafe.Pointer(p)).FselFlags)
	var elistFlags U32 = U32(0)

	*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_Expanded)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return WRC_Abort
	}

	if int32(selFlags)&SF_Expanded != 0 {
		return WRC_Prune
	}
	if (*Walker)(unsafe.Pointer(pWalker)).FeCode != 0 {
		(*Select)(unsafe.Pointer(p)).FselId = U32(libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnSelect, 1))
	}
	pTabList = (*Select)(unsafe.Pointer(p)).FpSrc
	pEList = (*Select)(unsafe.Pointer(p)).FpEList
	if (*Parse)(unsafe.Pointer(pParse)).FpWith != 0 && (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_View) != 0 {
		if (*Select)(unsafe.Pointer(p)).FpWith == uintptr(0) {
			(*Select)(unsafe.Pointer(p)).FpWith = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(With{})))
			if (*Select)(unsafe.Pointer(p)).FpWith == uintptr(0) {
				return WRC_Abort
			}
		}
		(*With)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpWith)).FbView = 1
	}
	Xsqlite3WithPush(tls, pParse, (*Select)(unsafe.Pointer(p)).FpWith, uint8(0))

	Xsqlite3SrcListAssignCursors(tls, pParse, pTabList)

	i = 0
	pFrom = pTabList + 8
__1:
	if !(i < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc) {
		goto __3
	}
	{
		var pTab uintptr

		if (*SrcItem)(unsafe.Pointer(pFrom)).FpTab != 0 {
			goto __2
		}

		if (*SrcItem)(unsafe.Pointer(pFrom)).FzName == uintptr(0) {
			var pSel uintptr = (*SrcItem)(unsafe.Pointer(pFrom)).FpSelect

			if Xsqlite3WalkSelect(tls, pWalker, pSel) != 0 {
				return WRC_Abort
			}
			if Xsqlite3ExpandSubquery(tls, pParse, pFrom) != 0 {
				return WRC_Abort
			}
		} else if libc.AssignInt32(&rc, resolveFromTermToCte(tls, pParse, pWalker, pFrom)) != 0 {
			if rc > 1 {
				return WRC_Abort
			}
			pTab = (*SrcItem)(unsafe.Pointer(pFrom)).FpTab

		} else {
			(*SrcItem)(unsafe.Pointer(pFrom)).FpTab = libc.AssignUintptr(&pTab, Xsqlite3LocateTableItem(tls, pParse, uint32(0), pFrom))
			if pTab == uintptr(0) {
				return WRC_Abort
			}
			if (*Table)(unsafe.Pointer(pTab)).FnTabRef >= U32(0xffff) {
				Xsqlite3ErrorMsg(tls, pParse, ts+23292,
					libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
				(*SrcItem)(unsafe.Pointer(pFrom)).FpTab = uintptr(0)
				return WRC_Abort
			}
			(*Table)(unsafe.Pointer(pTab)).FnTabRef++
			if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) && cannotBeFunction(tls, pParse, pFrom) != 0 {
				return WRC_Abort
			}
			if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_NORM) {
				var nCol I16
				var eCodeOrig U8 = U8((*Walker)(unsafe.Pointer(pWalker)).FeCode)
				if Xsqlite3ViewGetColumnNames(tls, pParse, pTab) != 0 {
					return WRC_Abort
				}

				if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW {
					if (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_EnableView) == uint64(0) &&
						(*Table)(unsafe.Pointer(pTab)).FpSchema != (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema {
						Xsqlite3ErrorMsg(tls, pParse, ts+23331,
							libc.VaList(bp+8, (*Table)(unsafe.Pointer(pTab)).FzName))
					}
					(*SrcItem)(unsafe.Pointer(pFrom)).FpSelect = Xsqlite3SelectDup(tls, db, *(*uintptr)(unsafe.Pointer(pTab + 64)), 0)
				} else if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB &&
					uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 60 + 4))&0x80>>7)) != 0 &&
					*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)) != uintptr(0) &&
					int32((*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)))).FeVtabRisk) > libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_TrustedSchema) != uint64(0)) {
					Xsqlite3ErrorMsg(tls, pParse, ts+18146,
						libc.VaList(bp+16, (*Table)(unsafe.Pointer(pTab)).FzName))
				}

				nCol = (*Table)(unsafe.Pointer(pTab)).FnCol
				(*Table)(unsafe.Pointer(pTab)).FnCol = int16(-1)
				(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(1)
				Xsqlite3WalkSelect(tls, pWalker, (*SrcItem)(unsafe.Pointer(pFrom)).FpSelect)
				(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(eCodeOrig)
				(*Table)(unsafe.Pointer(pTab)).FnCol = nCol
			}
		}

		if uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 60 + 4))&0x2>>1)) != 0 && Xsqlite3IndexedByLookup(tls, pParse, pFrom) != 0 {
			return WRC_Abort
		}

	}
	goto __2
__2:
	i++
	pFrom += 104
	goto __1
	goto __3
__3:
	;
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 || sqlite3ProcessJoin(tls, pParse, p) != 0 {
		return WRC_Abort
	}

	for k = 0; k < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; k++ {
		pE = (*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(k)*32)).FpExpr
		if int32((*Expr)(unsafe.Pointer(pE)).Fop) == TK_ASTERISK {
			break
		}

		if int32((*Expr)(unsafe.Pointer(pE)).Fop) == TK_DOT && int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pE)).FpRight)).Fop) == TK_ASTERISK {
			break
		}
		elistFlags = elistFlags | (*Expr)(unsafe.Pointer(pE)).Fflags
	}
	if k < (*ExprList)(unsafe.Pointer(pEList)).FnExpr {
		var a uintptr = pEList + 8
		var pNew uintptr = uintptr(0)
		var flags int32 = int32((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags)
		var longNames int32 = libc.Bool32(flags&SQLITE_FullColNames != 0 &&
			flags&SQLITE_ShortColNames == 0)

		for k = 0; k < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; k++ {
			pE = (*ExprList_item)(unsafe.Pointer(a + uintptr(k)*32)).FpExpr
			elistFlags = elistFlags | (*Expr)(unsafe.Pointer(pE)).Fflags
			pRight = (*Expr)(unsafe.Pointer(pE)).FpRight

			if int32((*Expr)(unsafe.Pointer(pE)).Fop) != TK_ASTERISK &&
				(int32((*Expr)(unsafe.Pointer(pE)).Fop) != TK_DOT || int32((*Expr)(unsafe.Pointer(pRight)).Fop) != TK_ASTERISK) {
				pNew = Xsqlite3ExprListAppend(tls, pParse, pNew, (*ExprList_item)(unsafe.Pointer(a+uintptr(k)*32)).FpExpr)
				if pNew != 0 {
					(*ExprList_item)(unsafe.Pointer(pNew + 8 + uintptr((*ExprList)(unsafe.Pointer(pNew)).FnExpr-1)*32)).FzEName = (*ExprList_item)(unsafe.Pointer(a + uintptr(k)*32)).FzEName
					libc.SetBitFieldPtr16Uint32(pNew+8+uintptr((*ExprList)(unsafe.Pointer(pNew)).FnExpr-1)*32+16+4, uint32(int32(*(*uint16)(unsafe.Pointer(a + uintptr(k)*32 + 16 + 4))&0x3>>0)), 0, 0x3)
					(*ExprList_item)(unsafe.Pointer(a + uintptr(k)*32)).FzEName = uintptr(0)
				}
				(*ExprList_item)(unsafe.Pointer(a + uintptr(k)*32)).FpExpr = uintptr(0)
			} else {
				var tableSeen int32 = 0
				var zTName uintptr = uintptr(0)
				if int32((*Expr)(unsafe.Pointer(pE)).Fop) == TK_DOT {
					zTName = *(*uintptr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pE)).FpLeft + 8))
				}
				i = 0
				pFrom = pTabList + 8
			__4:
				if !(i < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc) {
					goto __6
				}
				{
					var pTab uintptr = (*SrcItem)(unsafe.Pointer(pFrom)).FpTab
					var pNestedFrom uintptr
					var zTabName uintptr
					var zSchemaName uintptr = uintptr(0)
					var iDb int32
					var pUsing uintptr

					if libc.AssignUintptr(&zTabName, (*SrcItem)(unsafe.Pointer(pFrom)).FzAlias) == uintptr(0) {
						zTabName = (*Table)(unsafe.Pointer(pTab)).FzName
					}
					if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
						goto __6
					}

					if uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 60 + 4))&0x2000>>13)) != 0 {
						pNestedFrom = (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pFrom)).FpSelect)).FpEList

					} else {
						if zTName != 0 && Xsqlite3StrICmp(tls, zTName, zTabName) != 0 {
							goto __5
						}
						pNestedFrom = uintptr(0)
						iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)
						if iDb >= 0 {
							zSchemaName = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
						} else {
							zSchemaName = ts + 9661
						}
					}
					if i+1 < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc &&
						uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 1*104 + 60 + 4))&0x400>>10)) != 0 &&
						int32(selFlags)&SF_NestedFrom != 0 {
						var ii int32
						pUsing = *(*uintptr)(unsafe.Pointer(pFrom + 1*104 + 72))
						for ii = 0; ii < (*IdList)(unsafe.Pointer(pUsing)).FnId; ii++ {
							var zUName uintptr = (*IdList_item)(unsafe.Pointer(pUsing + 8 + uintptr(ii)*16)).FzName
							pRight = Xsqlite3Expr(tls, db, TK_ID, zUName)
							pNew = Xsqlite3ExprListAppend(tls, pParse, pNew, pRight)
							if pNew != 0 {
								var pX uintptr = pNew + 8 + uintptr((*ExprList)(unsafe.Pointer(pNew)).FnExpr-1)*32

								(*ExprList_item)(unsafe.Pointer(pX)).FzEName = Xsqlite3MPrintf(tls, db, ts+23362, libc.VaList(bp+24, zUName))
								libc.SetBitFieldPtr16Uint32(pX+16+4, uint32(ENAME_TAB), 0, 0x3)
								libc.SetBitFieldPtr16Uint32(pX+16+4, uint32(1), 7, 0x80)
							}
						}
					} else {
						pUsing = uintptr(0)
					}
					for j = 0; j < int32((*Table)(unsafe.Pointer(pTab)).FnCol); j++ {
						var zName uintptr = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*24)).FzCnName
						var pX uintptr

						if zTName != 0 &&
							pNestedFrom != 0 &&
							Xsqlite3MatchEName(tls, pNestedFrom+8+uintptr(j)*32, uintptr(0), zTName, uintptr(0)) == 0 {
							continue
						}

						if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_IncludeHidden) == U32(0) &&
							int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FcolFlags)&COLFLAG_HIDDEN != 0 {
							continue
						}
						if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FcolFlags)&COLFLAG_NOEXPAND != 0 &&
							zTName == uintptr(0) &&
							int32(selFlags)&SF_NestedFrom == 0 {
							continue
						}
						tableSeen = 1

						if i > 0 && zTName == uintptr(0) && int32(selFlags)&SF_NestedFrom == 0 {
							if uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 60 + 4))&0x400>>10)) != 0 &&
								Xsqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 72)), zName) >= 0 {
								continue
							}
						}
						pRight = Xsqlite3Expr(tls, db, TK_ID, zName)
						if (*SrcList)(unsafe.Pointer(pTabList)).FnSrc > 1 &&
							(int32((*SrcItem)(unsafe.Pointer(pFrom)).Ffg.Fjointype)&JT_LTORJ == 0 ||
								int32(selFlags)&SF_NestedFrom != 0 ||
								!(inAnyUsingClause(tls, zName, pFrom, (*SrcList)(unsafe.Pointer(pTabList)).FnSrc-i-1) != 0)) ||
							int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
							var pLeft uintptr
							pLeft = Xsqlite3Expr(tls, db, TK_ID, zTabName)
							pExpr = Xsqlite3PExpr(tls, pParse, TK_DOT, pLeft, pRight)
							if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && (*Expr)(unsafe.Pointer(pE)).FpLeft != 0 {
								Xsqlite3RenameTokenRemap(tls, pParse, pLeft, (*Expr)(unsafe.Pointer(pE)).FpLeft)
							}
							if zSchemaName != 0 {
								pLeft = Xsqlite3Expr(tls, db, TK_ID, zSchemaName)
								pExpr = Xsqlite3PExpr(tls, pParse, TK_DOT, pLeft, pExpr)
							}
						} else {
							pExpr = pRight
						}
						pNew = Xsqlite3ExprListAppend(tls, pParse, pNew, pExpr)
						if pNew == uintptr(0) {
							break
						}
						pX = pNew + 8 + uintptr((*ExprList)(unsafe.Pointer(pNew)).FnExpr-1)*32

						if int32(selFlags)&SF_NestedFrom != 0 && !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
							if pNestedFrom != 0 {
								(*ExprList_item)(unsafe.Pointer(pX)).FzEName = Xsqlite3DbStrDup(tls, db, (*ExprList_item)(unsafe.Pointer(pNestedFrom+8+uintptr(j)*32)).FzEName)

							} else {
								(*ExprList_item)(unsafe.Pointer(pX)).FzEName = Xsqlite3MPrintf(tls, db, ts+23367,
									libc.VaList(bp+32, zSchemaName, zTabName, zName))

							}
							libc.SetBitFieldPtr16Uint32(pX+16+4, uint32(ENAME_TAB), 0, 0x3)
							if uint32(int32(*(*uint16)(unsafe.Pointer(pFrom + 60 + 4))&0x400>>10)) != 0 &&
								Xsqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pFrom + 72)), zName) >= 0 ||
								pUsing != 0 && Xsqlite3IdListIndex(tls, pUsing, zName) >= 0 ||
								int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FcolFlags)&COLFLAG_NOEXPAND != 0 {
								libc.SetBitFieldPtr16Uint32(pX+16+4, uint32(1), 8, 0x100)
							}
						} else if longNames != 0 {
							(*ExprList_item)(unsafe.Pointer(pX)).FzEName = Xsqlite3MPrintf(tls, db, ts+11397, libc.VaList(bp+56, zTabName, zName))
							libc.SetBitFieldPtr16Uint32(pX+16+4, uint32(ENAME_NAME), 0, 0x3)
						} else {
							(*ExprList_item)(unsafe.Pointer(pX)).FzEName = Xsqlite3DbStrDup(tls, db, zName)
							libc.SetBitFieldPtr16Uint32(pX+16+4, uint32(ENAME_NAME), 0, 0x3)
						}
					}

				}
				goto __5
			__5:
				i++
				pFrom += 104
				goto __4
				goto __6
			__6:
				;
				if !(tableSeen != 0) {
					if zTName != 0 {
						Xsqlite3ErrorMsg(tls, pParse, ts+23376, libc.VaList(bp+72, zTName))
					} else {
						Xsqlite3ErrorMsg(tls, pParse, ts+23394, 0)
					}
				}
			}
		}
		Xsqlite3ExprListDelete(tls, db, pEList)
		(*Select)(unsafe.Pointer(p)).FpEList = pNew
	}
	if (*Select)(unsafe.Pointer(p)).FpEList != 0 {
		if (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr > *(*int32)(unsafe.Pointer(db + 136 + 2*4)) {
			Xsqlite3ErrorMsg(tls, pParse, ts+23414, 0)
			return WRC_Abort
		}
		if elistFlags&U32(EP_HasFunc|EP_Subquery) != U32(0) {
			*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_ComplexResult)
		}
	}
	return WRC_Continue
}

func sqlite3SelectExpand(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3ExprWalkNoop}))
	(*Walker)(unsafe.Pointer(bp)).FpParse = pParse
	if (*Parse)(unsafe.Pointer(pParse)).FhasCompound != 0 {
		(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		}{convertCompoundSelectToSubquery}))
		(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = uintptr(0)
		Xsqlite3WalkSelect(tls, bp, pSelect)
	}
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{selectExpander}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr)
	}{Xsqlite3SelectPopWith}))
	(*Walker)(unsafe.Pointer(bp)).FeCode = U16(0)
	Xsqlite3WalkSelect(tls, bp, pSelect)
}

func selectAddSubqueryTypeInfo(tls *libc.TLS, pWalker uintptr, p uintptr) {
	var pParse uintptr
	var i int32
	var pTabList uintptr
	var pFrom uintptr

	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_HasTypeInfo) != 0 {
		return
	}
	*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_HasTypeInfo)
	pParse = (*Walker)(unsafe.Pointer(pWalker)).FpParse
	pTabList = (*Select)(unsafe.Pointer(p)).FpSrc
	i = 0
	pFrom = pTabList + 8
__1:
	if !(i < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc) {
		goto __3
	}
	{
		var pTab uintptr = (*SrcItem)(unsafe.Pointer(pFrom)).FpTab

		if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Ephemeral) != U32(0) {
			var pSel uintptr = (*SrcItem)(unsafe.Pointer(pFrom)).FpSelect
			if pSel != 0 {
				Xsqlite3SubqueryColumnTypes(tls, pParse, pTab, pSel, uint8(SQLITE_AFF_NONE))
			}
		}

	}
	goto __2
__2:
	i++
	pFrom += 104
	goto __1
	goto __3
__3:
}

func sqlite3SelectAddTypeInfo(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3SelectWalkNoop}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr)
	}{selectAddSubqueryTypeInfo}))
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3ExprWalkNoop}))
	(*Walker)(unsafe.Pointer(bp)).FpParse = pParse
	Xsqlite3WalkSelect(tls, bp, pSelect)
}

func Xsqlite3SelectPrep(tls *libc.TLS, pParse uintptr, p uintptr, pOuterNC uintptr) {
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		return
	}
	if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_HasTypeInfo) != 0 {
		return
	}
	sqlite3SelectExpand(tls, pParse, p)
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	Xsqlite3ResolveSelectNames(tls, pParse, p, pOuterNC)
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	sqlite3SelectAddTypeInfo(tls, pParse, p)
}

func analyzeAggFuncArgs(tls *libc.TLS, pAggInfo uintptr, pNC uintptr) {
	var i int32

	*(*int32)(unsafe.Pointer(pNC + 40)) |= NC_InAggFunc
	for i = 0; i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc; i++ {
		var pExpr uintptr = (*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*24)).FpFExpr

		Xsqlite3ExprAnalyzeAggList(tls, pNC, *(*uintptr)(unsafe.Pointer(pExpr + 32)))

		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
			Xsqlite3ExprAnalyzeAggregates(tls, pNC, (*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 64)))).FpFilter)
		}
	}
	*(*int32)(unsafe.Pointer(pNC + 40)) &= libc.CplInt32(NC_InAggFunc)
}

func optimizeAggregateUseOfIndexedExpr(tls *libc.TLS, pParse uintptr, pSelect uintptr, pAggInfo uintptr, pNC uintptr) {
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn = (*AggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator
	if int32((*AggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn) > 0 {
		if (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn == 0 {
			(*AggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn = U16((*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpGroupBy)).FnExpr)
		} else {
			(*AggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn = U16(int32((*AggInfo_col)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol+uintptr((*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn-1)*24)).FiSorterColumn) + 1)
		}
	}
	analyzeAggFuncArgs(tls, pAggInfo, pNC)
	_ = pSelect
	_ = pParse
}

func aggregateIdxEprRefToColCallback(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var pAggInfo uintptr
	var pCol uintptr
	_ = pWalker
	if (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
		return WRC_Continue
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AGG_COLUMN {
		return WRC_Continue
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AGG_FUNCTION {
		return WRC_Continue
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_IF_NULL_ROW {
		return WRC_Continue
	}
	pAggInfo = (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo

	pCol = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr((*Expr)(unsafe.Pointer(pExpr)).FiAgg)*24
	(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_AGG_COLUMN)
	(*Expr)(unsafe.Pointer(pExpr)).FiTable = (*AggInfo_col)(unsafe.Pointer(pCol)).FiTable
	(*Expr)(unsafe.Pointer(pExpr)).FiColumn = (*AggInfo_col)(unsafe.Pointer(pCol)).FiColumn
	return WRC_Prune
}

func aggregateConvertIndexedExprRefToColumn(tls *libc.TLS, pAggInfo uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var i int32

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{aggregateIdxEprRefToColCallback}))
	for i = 0; i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc; i++ {
		Xsqlite3WalkExpr(tls, bp, (*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc+uintptr(i)*24)).FpFExpr)
	}
}

func assignAggregateRegisters(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn + (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc
}

func resetAccumulator(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var i int32
	var pFunc uintptr
	var nReg int32 = (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc + (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn

	if nReg == 0 {
		return
	}
	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Null, 0, (*AggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg,
		(*AggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg+nReg-1)
	pFunc = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
	i = 0
__1:
	if !(i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
		goto __3
	}
	{
		if (*AggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct >= 0 {
			var pE uintptr = (*AggInfo_func)(unsafe.Pointer(pFunc)).FpFExpr

			if *(*uintptr)(unsafe.Pointer(pE + 32)) == uintptr(0) || (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pE + 32)))).FnExpr != 1 {
				Xsqlite3ErrorMsg(tls, pParse,
					ts+23445, 0)
				(*AggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct = -1
			} else {
				var pKeyInfo uintptr = Xsqlite3KeyInfoFromExprList(tls, pParse, *(*uintptr)(unsafe.Pointer(pE + 32)), 0, 0)
				(*AggInfo_func)(unsafe.Pointer(pFunc)).FiDistAddr = Xsqlite3VdbeAddOp4(tls, v, OP_OpenEphemeral,
					(*AggInfo_func)(unsafe.Pointer(pFunc)).FiDistinct, 0, 0, pKeyInfo, -8)
				Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+23496, libc.VaList(bp, (*FuncDef)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer(pFunc)).FpFunc)).FzName))
			}
		}

	}
	goto __2
__2:
	i++
	pFunc += 24
	goto __1
	goto __3
__3:
}

func finalizeAggFunctions(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var i int32
	var pF uintptr
	i = 0
	pF = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
__1:
	if !(i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
		goto __3
	}
	{
		var pList uintptr

		pList = *(*uintptr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer(pF)).FpFExpr + 32))
		Xsqlite3VdbeAddOp2(tls, v, OP_AggFinal, func() int32 {
			return (*AggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg + (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn + i
		}(),
			func() int32 {
				if pList != 0 {
					return (*ExprList)(unsafe.Pointer(pList)).FnExpr
				}
				return 0
			}())
		Xsqlite3VdbeAppendP4(tls, v, (*AggInfo_func)(unsafe.Pointer(pF)).FpFunc, -7)

	}
	goto __2
__2:
	i++
	pF += 24
	goto __1
	goto __3
__3:
}

func updateAccumulator(tls *libc.TLS, pParse uintptr, regAcc int32, pAggInfo uintptr, eDistinctType int32) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var i int32
	var regHit int32 = 0
	var addrHitTest int32 = 0
	var pF uintptr
	var pC uintptr

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return
	}
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = U8(1)
	i = 0
	pF = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
__1:
	if !(i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
		goto __3
	}
	{
		var nArg int32
		var addrNext int32 = 0
		var regAgg int32
		var pList uintptr

		pList = *(*uintptr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer(pF)).FpFExpr + 32))
		if (*Expr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer(pF)).FpFExpr)).Fflags&U32(EP_WinFunc) != U32(0) {
			var pFilter uintptr = (*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer(pF)).FpFExpr + 64)))).FpFilter
			if (*AggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0 &&
				(*FuncDef)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer(pF)).FpFunc)).FfuncFlags&U32(SQLITE_FUNC_NEEDCOLL) != 0 &&
				regAcc != 0 {
				if regHit == 0 {
					regHit = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
				}

				Xsqlite3VdbeAddOp2(tls, v, OP_Copy, regAcc, regHit)
			}
			addrNext = Xsqlite3VdbeMakeLabel(tls, pParse)
			Xsqlite3ExprIfFalse(tls, pParse, pFilter, addrNext, SQLITE_JUMPIFNULL)
		}
		if pList != 0 {
			nArg = (*ExprList)(unsafe.Pointer(pList)).FnExpr
			regAgg = Xsqlite3GetTempRange(tls, pParse, nArg)
			Xsqlite3ExprCodeExprList(tls, pParse, pList, regAgg, 0, uint8(SQLITE_ECEL_DUP))
		} else {
			nArg = 0
			regAgg = 0
		}
		if (*AggInfo_func)(unsafe.Pointer(pF)).FiDistinct >= 0 && pList != 0 {
			if addrNext == 0 {
				addrNext = Xsqlite3VdbeMakeLabel(tls, pParse)
			}
			(*AggInfo_func)(unsafe.Pointer(pF)).FiDistinct = codeDistinct(tls, pParse, eDistinctType,
				(*AggInfo_func)(unsafe.Pointer(pF)).FiDistinct, addrNext, pList, regAgg)
		}
		if (*FuncDef)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer(pF)).FpFunc)).FfuncFlags&U32(SQLITE_FUNC_NEEDCOLL) != 0 {
			var pColl uintptr = uintptr(0)
			var pItem uintptr
			var j int32

			j = 0
			pItem = pList + 8
		__4:
			if !(!(pColl != 0) && j < nArg) {
				goto __6
			}
			{
				pColl = Xsqlite3ExprCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(pItem)).FpExpr)

			}
			goto __5
		__5:
			j++
			pItem += 32
			goto __4
			goto __6
		__6:
			;
			if !(pColl != 0) {
				pColl = (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FpDfltColl
			}
			if regHit == 0 && (*AggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0 {
				regHit = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
			}
			Xsqlite3VdbeAddOp4(tls, v, OP_CollSeq, regHit, 0, 0, pColl, -2)
		}
		Xsqlite3VdbeAddOp3(tls, v, OP_AggStep, 0, regAgg, func() int32 {
			return (*AggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg + (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn + i
		}())
		Xsqlite3VdbeAppendP4(tls, v, (*AggInfo_func)(unsafe.Pointer(pF)).FpFunc, -7)
		Xsqlite3VdbeChangeP5(tls, v, uint16(U8(nArg)))
		Xsqlite3ReleaseTempRange(tls, pParse, regAgg, nArg)
		if addrNext != 0 {
			Xsqlite3VdbeResolveLabel(tls, v, addrNext)
		}

	}
	goto __2
__2:
	i++
	pF += 24
	goto __1
	goto __3
__3:
	;
	if regHit == 0 && (*AggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0 {
		regHit = regAcc
	}
	if regHit != 0 {
		addrHitTest = Xsqlite3VdbeAddOp1(tls, v, OP_If, regHit)
	}
	i = 0
	pC = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol
__7:
	if !(i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator) {
		goto __9
	}
	{
		Xsqlite3ExprCode(tls, pParse, (*AggInfo_col)(unsafe.Pointer(pC)).FpCExpr, func() int32 { ; return (*AggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg + i }())

	}
	goto __8
__8:
	i++
	pC += 24
	goto __7
	goto __9
__9:
	;
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = U8(0)
	if addrHitTest != 0 {
		Xsqlite3VdbeJumpHereOrPopInst(tls, v, addrHitTest)
	}
}

func explainSimpleCount(tls *libc.TLS, pParse uintptr, pTab uintptr, pIdx uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	if int32((*Parse)(unsafe.Pointer(pParse)).Fexplain) == 2 {
		var bCover int32 = libc.Bool32(pIdx != uintptr(0) && ((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) || !(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY)))
		Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+23529,
			libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName,
				func() uintptr {
					if bCover != 0 {
						return ts + 23541
					}
					return ts + 1636
				}(),
				func() uintptr {
					if bCover != 0 {
						return (*Index)(unsafe.Pointer(pIdx)).FzName
					}
					return ts + 1636
				}()))
	}
}

func havingToWhereExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_AND {
		var pS uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))

		if Xsqlite3ExprIsConstantOrGroupBy(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse, pExpr, (*Select)(unsafe.Pointer(pS)).FpGroupBy) != 0 &&
			libc.Bool32((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_IsFalse) == U32(EP_IsFalse)) == 0 &&
			(*Expr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
			var db uintptr = (*Parse)(unsafe.Pointer((*Walker)(unsafe.Pointer(pWalker)).FpParse)).Fdb
			var pNew uintptr = Xsqlite3Expr(tls, db, TK_INTEGER, ts+11251)
			if pNew != 0 {
				var pWhere uintptr = (*Select)(unsafe.Pointer(pS)).FpWhere
				{
					var t = *(*Expr)(unsafe.Pointer(pNew))
					*(*Expr)(unsafe.Pointer(pNew)) = *(*Expr)(unsafe.Pointer(pExpr))
					*(*Expr)(unsafe.Pointer(pExpr)) = t
				}

				pNew = Xsqlite3ExprAnd(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse, pWhere, pNew)
				(*Select)(unsafe.Pointer(pS)).FpWhere = pNew
				(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(1)
			}
		}
		return WRC_Prune
	}
	return WRC_Continue
}

func havingToWhere(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(bp)).FpParse = pParse
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{havingToWhereExprCb}))
	*(*uintptr)(unsafe.Pointer(bp + 40)) = p
	Xsqlite3WalkExpr(tls, bp, (*Select)(unsafe.Pointer(p)).FpHaving)
}

func isSelfJoinView(tls *libc.TLS, pTabList uintptr, pThis uintptr, iFirst int32, iEnd int32) uintptr {
	var pItem uintptr

	if (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pThis)).FpSelect)).FselFlags&U32(SF_PushDown) != 0 {
		return uintptr(0)
	}
	for iFirst < iEnd {
		var pS1 uintptr
		pItem = pTabList + 8 + uintptr(libc.PostIncInt32(&iFirst, 1))*104
		if (*SrcItem)(unsafe.Pointer(pItem)).FpSelect == uintptr(0) {
			continue
		}
		if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x20>>5)) != 0 {
			continue
		}
		if (*SrcItem)(unsafe.Pointer(pItem)).FzName == uintptr(0) {
			continue
		}

		if (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpTab)).FpSchema != (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pThis)).FpTab)).FpSchema {
			continue
		}
		if Xsqlite3_stricmp(tls, (*SrcItem)(unsafe.Pointer(pItem)).FzName, (*SrcItem)(unsafe.Pointer(pThis)).FzName) != 0 {
			continue
		}
		pS1 = (*SrcItem)(unsafe.Pointer(pItem)).FpSelect
		if (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpTab)).FpSchema == uintptr(0) && (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pThis)).FpSelect)).FselId != (*Select)(unsafe.Pointer(pS1)).FselId {
			continue
		}
		if (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpSelect)).FselFlags&U32(SF_PushDown) != 0 {
			continue
		}
		return pItem
	}
	return uintptr(0)
}

func agginfoFree(tls *libc.TLS, db uintptr, p uintptr) {
	Xsqlite3DbFree(tls, db, (*AggInfo)(unsafe.Pointer(p)).FaCol)
	Xsqlite3DbFree(tls, db, (*AggInfo)(unsafe.Pointer(p)).FaFunc)
	Xsqlite3DbFreeNN(tls, db, p)
}

func sameSrcAlias(tls *libc.TLS, p0 uintptr, pSrc uintptr) int32 {
	var i int32
	for i = 0; i < (*SrcList)(unsafe.Pointer(pSrc)).FnSrc; i++ {
		var p1 uintptr = pSrc + 8 + uintptr(i)*104
		if p1 == p0 {
			continue
		}
		if (*SrcItem)(unsafe.Pointer(p0)).FpTab == (*SrcItem)(unsafe.Pointer(p1)).FpTab && 0 == Xsqlite3_stricmp(tls, (*SrcItem)(unsafe.Pointer(p0)).FzAlias, (*SrcItem)(unsafe.Pointer(p1)).FzAlias) {
			return 1
		}
		if (*SrcItem)(unsafe.Pointer(p1)).FpSelect != 0 &&
			(*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(p1)).FpSelect)).FselFlags&U32(SF_NestedFrom) != U32(0) &&
			sameSrcAlias(tls, p0, (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(p1)).FpSelect)).FpSrc) != 0 {
			return 1
		}
	}
	return 0
}

func fromClauseTermCanBeCoroutine(tls *libc.TLS, pParse uintptr, pTabList uintptr, i int32, selFlags int32) int32 {
	var pItem uintptr = pTabList + 8 + uintptr(i)*104
	if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x100>>8)) != 0 {
		var pCteUse uintptr = *(*uintptr)(unsafe.Pointer(pItem + 96))
		if int32((*CteUse)(unsafe.Pointer(pCteUse)).FeM10d) == M10d_Yes {
			return 0
		}
		if (*CteUse)(unsafe.Pointer(pCteUse)).FnUse >= 2 && int32((*CteUse)(unsafe.Pointer(pCteUse)).FeM10d) != M10d_No {
			return 0
		}
	}
	if int32((*SrcItem)(unsafe.Pointer(pTabList+8)).Ffg.Fjointype)&JT_LTORJ != 0 {
		return 0
	}
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&U32(SQLITE_Coroutines) != U32(0) {
		return 0
	}
	if isSelfJoinView(tls, pTabList, pItem, i+1, (*SrcList)(unsafe.Pointer(pTabList)).FnSrc) != uintptr(0) {
		return 0
	}
	if i == 0 {
		if (*SrcList)(unsafe.Pointer(pTabList)).FnSrc == 1 {
			return 1
		}
		if int32((*SrcItem)(unsafe.Pointer(pTabList+8+1*104)).Ffg.Fjointype)&JT_CROSS != 0 {
			return 1
		}
		if selFlags&SF_UpdateFrom != 0 {
			return 0
		}
		return 1
	}
	if selFlags&SF_UpdateFrom != 0 {
		return 0
	}
	for 1 != 0 {
		if int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(JT_OUTER|JT_CROSS) != 0 {
			return 0
		}
		if i == 0 {
			break
		}
		i--
		pItem -= 104
		if (*SrcItem)(unsafe.Pointer(pItem)).FpSelect != uintptr(0) {
			return 0
		}
	}
	return 1
}

func Xsqlite3Select(tls *libc.TLS, pParse uintptr, p uintptr, pDest uintptr) int32 {
	bp := tls.Alloc(256)
	defer tls.Free(256)

	var i int32
	var j int32
	var pWInfo uintptr
	var v uintptr
	var isAgg int32
	var pEList uintptr
	var pTabList uintptr
	var pWhere uintptr
	var pGroupBy uintptr
	var pHaving uintptr
	var pAggInfo uintptr
	var rc int32

	var iEnd int32
	var db uintptr

	var minMaxFlag U8
	var p0 uintptr
	var pItem uintptr
	var pSub uintptr
	var pTab uintptr

	var addrTop int32

	var pCteUse uintptr
	var pCteUse1 uintptr

	var topAddr int32
	var onceAddr int32
	var pItem1 uintptr
	var pPrior uintptr

	var pSub1 uintptr
	var zSavedAuthContext uintptr
	var pKeyInfo uintptr

	var ii int32
	var addrGosub int32
	var iCont int32
	var iBreak int32
	var regGosub int32

	var wctrlFlags U16
	var pWin uintptr
	var sortFlags U8
	var ii1 int32
	var k int32
	var pItem2 uintptr
	var pExpr uintptr
	var pCol uintptr

	var regBase int32
	var regRecord int32
	var nCol int32
	var nGroupBy int32
	var pF uintptr
	var pKeyInfo1 uintptr
	var addr1 int32
	var addrOutputRow int32
	var regOutputRow int32
	var addrSetAbort int32
	var addrTopOfLoop int32
	var addrSortingIdx int32
	var addrReset int32
	var regReset int32
	var pDistinct uintptr
	var distFlag U16
	var eDist int32

	var iDb int32
	var iCsr int32
	var pIdx uintptr
	var pKeyInfo2 uintptr
	var pBest uintptr
	var iRoot Pgno
	var pF1 uintptr
	var regAcc int32
	var pDistinct1 uintptr
	var distFlag1 U16
	var eDist1 int32
	var pTab1 uintptr

	var iAMem int32
	var iBMem int32
	var iUseFlag int32

	var iAbortFlag int32
	var groupBySort int32
	var addrEnd int32
	var sortPTab int32
	var sortOut int32
	var orderByGrp int32
	pEList = uintptr(0)
	pAggInfo = uintptr(0)
	rc = 1
	*(*uintptr)(unsafe.Pointer(bp + 248)) = uintptr(0)

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	v = Xsqlite3GetVdbe(tls, pParse)
	if !(p == uintptr(0) || (*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __1
	}
	return 1
__1:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_SELECT, uintptr(0), uintptr(0), uintptr(0)) != 0) {
		goto __2
	}
	return 1
__2:
	;
	if !(int32((*SelectDest)(unsafe.Pointer(pDest)).FeDest) <= SRT_DistQueue) {
		goto __3
	}

	if !((*Select)(unsafe.Pointer(p)).FpOrderBy != 0) {
		goto __4
	}
	Xsqlite3ParserAddCleanup(tls, pParse,
		*(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{Xsqlite3ExprListDelete})),
		(*Select)(unsafe.Pointer(p)).FpOrderBy)

	(*Select)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
__4:
	;
	*(*U32)(unsafe.Pointer(p + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_Distinct))
	*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_NoopOrderBy)
__3:
	;
	Xsqlite3SelectPrep(tls, pParse, p, uintptr(0))
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __5
	}
	goto select_end
__5:
	;
	if !((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_UFSrcCheck) != 0) {
		goto __6
	}
	p0 = (*Select)(unsafe.Pointer(p)).FpSrc + 8
	if !(sameSrcAlias(tls, p0, (*Select)(unsafe.Pointer(p)).FpSrc) != 0) {
		goto __7
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+23564,
		libc.VaList(bp, func() uintptr {
			if (*SrcItem)(unsafe.Pointer(p0)).FzAlias != 0 {
				return (*SrcItem)(unsafe.Pointer(p0)).FzAlias
			}
			return (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(p0)).FpTab)).FzName
		}()))
	goto select_end
__7:
	;
	*(*U32)(unsafe.Pointer(p + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_UFSrcCheck))
__6:
	;
	if !(int32((*SelectDest)(unsafe.Pointer(pDest)).FeDest) == SRT_Output) {
		goto __8
	}
	Xsqlite3GenerateColumnNames(tls, pParse, p)
__8:
	;
	if !(Xsqlite3WindowRewrite(tls, pParse, p) != 0) {
		goto __9
	}

	goto select_end
__9:
	;
	pTabList = (*Select)(unsafe.Pointer(p)).FpSrc
	isAgg = libc.Bool32((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Aggregate) != U32(0))
	libc.Xmemset(tls, bp+88, 0, uint64(unsafe.Sizeof(SortCtx{})))
	(*SortCtx)(unsafe.Pointer(bp + 88)).FpOrderBy = (*Select)(unsafe.Pointer(p)).FpOrderBy

	i = 0
__10:
	if !(!(int32((*Select)(unsafe.Pointer(p)).FpPrior) != 0) && i < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc) {
		goto __12
	}
	pItem = pTabList + 8 + uintptr(i)*104
	pSub = (*SrcItem)(unsafe.Pointer(pItem)).FpSelect
	pTab = (*SrcItem)(unsafe.Pointer(pItem)).FpTab

	if !(int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(JT_LEFT|JT_RIGHT) == JT_LEFT &&
		Xsqlite3ExprImpliesNonNullRow(tls, (*Select)(unsafe.Pointer(p)).FpWhere, (*SrcItem)(unsafe.Pointer(pItem)).FiCursor) != 0 &&
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_SimplifyJoin) == U32(0)) {
		goto __13
	}

	*(*U8)(unsafe.Pointer(pItem + 60)) &= libc.Uint8FromInt32(libc.CplInt32(JT_LEFT | JT_OUTER))

	unsetJoinExpr(tls, (*Select)(unsafe.Pointer(p)).FpWhere, (*SrcItem)(unsafe.Pointer(pItem)).FiCursor,
		int32((*SrcItem)(unsafe.Pointer(pTabList+8)).Ffg.Fjointype)&JT_LTORJ)
__13:
	;
	if !(pSub == uintptr(0)) {
		goto __14
	}
	goto __11
__14:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FnCol) != (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSub)).FpEList)).FnExpr) {
		goto __15
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+23618,
		libc.VaList(bp+8, int32((*Table)(unsafe.Pointer(pTab)).FnCol), (*Table)(unsafe.Pointer(pTab)).FzName, (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(pSub)).FpEList)).FnExpr))
	goto select_end
__15:
	;
	if !((*Select)(unsafe.Pointer(pSub)).FselFlags&U32(SF_Aggregate) != U32(0)) {
		goto __16
	}
	goto __11
__16:
	;
	if !((*Select)(unsafe.Pointer(pSub)).FpOrderBy != uintptr(0) &&
		((*Select)(unsafe.Pointer(p)).FpOrderBy != uintptr(0) || (*SrcList)(unsafe.Pointer(pTabList)).FnSrc > 1) &&
		(*Select)(unsafe.Pointer(pSub)).FpLimit == uintptr(0) &&
		(*Select)(unsafe.Pointer(pSub)).FselFlags&U32(SF_OrderByReqd) == U32(0) &&
		(*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_OrderByReqd) == U32(0) &&
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_OmitOrderBy) == U32(0)) {
		goto __17
	}

	Xsqlite3ParserAddCleanup(tls, pParse,
		*(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{Xsqlite3ExprListDelete})),
		(*Select)(unsafe.Pointer(pSub)).FpOrderBy)
	(*Select)(unsafe.Pointer(pSub)).FpOrderBy = uintptr(0)
__17:
	;
	if !((*Select)(unsafe.Pointer(pSub)).FpOrderBy != uintptr(0) &&
		i == 0 &&
		(*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_ComplexResult) != U32(0) &&
		((*SrcList)(unsafe.Pointer(pTabList)).FnSrc == 1 ||
			int32((*SrcItem)(unsafe.Pointer(pTabList+8+1*104)).Ffg.Fjointype)&(JT_OUTER|JT_CROSS) != 0)) {
		goto __18
	}
	goto __11
__18:
	;
	if !(flattenSubquery(tls, pParse, p, i, isAgg) != 0) {
		goto __19
	}
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __20
	}
	goto select_end
__20:
	;
	i = -1
__19:
	;
	pTabList = (*Select)(unsafe.Pointer(p)).FpSrc
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __21
	}
	goto select_end
__21:
	;
	if !!(int32((*SelectDest)(unsafe.Pointer(pDest)).FeDest) <= SRT_Fifo) {
		goto __22
	}
	(*SortCtx)(unsafe.Pointer(bp + 88)).FpOrderBy = (*Select)(unsafe.Pointer(p)).FpOrderBy
__22:
	;
	goto __11
__11:
	i++
	goto __10
	goto __12
__12:
	;
	if !((*Select)(unsafe.Pointer(p)).FpPrior != 0) {
		goto __23
	}
	rc = multiSelect(tls, pParse, p, pDest)
	if !((*Select)(unsafe.Pointer(p)).FpNext == uintptr(0)) {
		goto __24
	}
	Xsqlite3VdbeExplainPop(tls, pParse)
__24:
	;
	return rc
__23:
	;
	if !((*Select)(unsafe.Pointer(p)).FpWhere != uintptr(0) &&
		int32((*Expr)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpWhere)).Fop) == TK_AND &&
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_PropagateConst) == U32(0) &&
		propagateConstants(tls, pParse, p) != 0) {
		goto __25
	}
	goto __26
__25:
	;
__26:
	;
	i = 0
__27:
	if !(i < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc) {
		goto __29
	}
	pItem1 = pTabList + 8 + uintptr(i)*104

	if !((*SrcItem)(unsafe.Pointer(pItem1)).FcolUsed == uint64(0) && (*SrcItem)(unsafe.Pointer(pItem1)).FzName != uintptr(0)) {
		goto __30
	}
	Xsqlite3AuthCheck(tls, pParse, SQLITE_READ, (*SrcItem)(unsafe.Pointer(pItem1)).FzName, ts+1636, (*SrcItem)(unsafe.Pointer(pItem1)).FzDatabase)
__30:
	;
	pSub1 = (*SrcItem)(unsafe.Pointer(pItem1)).FpSelect
	if !(pSub1 == uintptr(0)) {
		goto __31
	}
	goto __28
__31:
	;
	*(*int32)(unsafe.Pointer(pParse + 316)) += Xsqlite3SelectExprHeight(tls, p)

	if !((*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_PushDown) == U32(0) &&
		(int32(*(*uint16)(unsafe.Pointer(pItem1 + 60 + 4))&0x100>>8) == 0 ||
			int32((*CteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 96)))).FeM10d) != M10d_Yes && (*CteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 96)))).FnUse < 2) &&
		pushDownWhereTerms(tls, pParse, pSub1, (*Select)(unsafe.Pointer(p)).FpWhere, pItem1) != 0) {
		goto __32
	}

	goto __33
__32:
	;
__33:
	;
	zSavedAuthContext = (*Parse)(unsafe.Pointer(pParse)).FzAuthContext
	(*Parse)(unsafe.Pointer(pParse)).FzAuthContext = (*SrcItem)(unsafe.Pointer(pItem1)).FzName

	if !(fromClauseTermCanBeCoroutine(tls, pParse, pTabList, i, int32((*Select)(unsafe.Pointer(p)).FselFlags)) != 0) {
		goto __34
	}

	addrTop = Xsqlite3VdbeCurrentAddr(tls, v) + 1

	(*SrcItem)(unsafe.Pointer(pItem1)).FregReturn = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp3(tls, v, OP_InitCoroutine, (*SrcItem)(unsafe.Pointer(pItem1)).FregReturn, 0, addrTop)
	Xsqlite3VdbeComment(tls, v, ts+23288, libc.VaList(bp+32, pItem1))
	(*SrcItem)(unsafe.Pointer(pItem1)).FaddrFillSub = addrTop
	Xsqlite3SelectDestInit(tls, bp+136, SRT_Coroutine, (*SrcItem)(unsafe.Pointer(pItem1)).FregReturn)
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+23658, libc.VaList(bp+40, pItem1))
	Xsqlite3Select(tls, pParse, pSub1, bp+136)
	(*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem1)).FpTab)).FnRowLogEst = (*Select)(unsafe.Pointer(pSub1)).FnSelectRow
	libc.SetBitFieldPtr16Uint32(pItem1+60+4, uint32(1), 5, 0x20)
	(*SrcItem)(unsafe.Pointer(pItem1)).FregResult = (*SelectDest)(unsafe.Pointer(bp + 136)).FiSdst
	Xsqlite3VdbeEndCoroutine(tls, v, (*SrcItem)(unsafe.Pointer(pItem1)).FregReturn)
	Xsqlite3VdbeJumpHere(tls, v, addrTop-1)
	Xsqlite3ClearTempRegCache(tls, pParse)
	goto __35
__34:
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pItem1 + 60 + 4))&0x100>>8)) != 0 && (*CteUse)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem1 + 96)))).FaddrM9e > 0) {
		goto __36
	}

	pCteUse = *(*uintptr)(unsafe.Pointer(pItem1 + 96))
	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*CteUse)(unsafe.Pointer(pCteUse)).FregRtn, (*CteUse)(unsafe.Pointer(pCteUse)).FaddrM9e)
	if !((*SrcItem)(unsafe.Pointer(pItem1)).FiCursor != (*CteUse)(unsafe.Pointer(pCteUse)).FiCur) {
		goto __38
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, (*SrcItem)(unsafe.Pointer(pItem1)).FiCursor, (*CteUse)(unsafe.Pointer(pCteUse)).FiCur)
	Xsqlite3VdbeComment(tls, v, ts+23288, libc.VaList(bp+48, pItem1))
__38:
	;
	(*Select)(unsafe.Pointer(pSub1)).FnSelectRow = (*CteUse)(unsafe.Pointer(pCteUse)).FnRowEst
	goto __37
__36:
	if !(libc.AssignUintptr(&pPrior, isSelfJoinView(tls, pTabList, pItem1, 0, i)) != uintptr(0)) {
		goto __39
	}

	if !((*SrcItem)(unsafe.Pointer(pPrior)).FaddrFillSub != 0) {
		goto __41
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*SrcItem)(unsafe.Pointer(pPrior)).FregReturn, (*SrcItem)(unsafe.Pointer(pPrior)).FaddrFillSub)
__41:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, (*SrcItem)(unsafe.Pointer(pItem1)).FiCursor, (*SrcItem)(unsafe.Pointer(pPrior)).FiCursor)
	(*Select)(unsafe.Pointer(pSub1)).FnSelectRow = (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pPrior)).FpSelect)).FnSelectRow
	goto __40
__39:
	onceAddr = 0

	(*SrcItem)(unsafe.Pointer(pItem1)).FregReturn = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	topAddr = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
	(*SrcItem)(unsafe.Pointer(pItem1)).FaddrFillSub = topAddr + 1
	libc.SetBitFieldPtr16Uint32(pItem1+60+4, uint32(1), 4, 0x10)
	if !(int32(*(*uint16)(unsafe.Pointer(pItem1 + 60 + 4))&0x8>>3) == 0) {
		goto __42
	}

	onceAddr = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
	Xsqlite3VdbeComment(tls, v, ts+23673, libc.VaList(bp+56, pItem1))
	goto __43
__42:
	Xsqlite3VdbeNoopComment(tls, v, ts+23673, libc.VaList(bp+64, pItem1))
__43:
	;
	Xsqlite3SelectDestInit(tls, bp+136, SRT_EphemTab, (*SrcItem)(unsafe.Pointer(pItem1)).FiCursor)

	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+23689, libc.VaList(bp+72, pItem1))
	Xsqlite3Select(tls, pParse, pSub1, bp+136)
	(*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem1)).FpTab)).FnRowLogEst = (*Select)(unsafe.Pointer(pSub1)).FnSelectRow
	if !(onceAddr != 0) {
		goto __44
	}
	Xsqlite3VdbeJumpHere(tls, v, onceAddr)
__44:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Return, (*SrcItem)(unsafe.Pointer(pItem1)).FregReturn, topAddr+1)
	Xsqlite3VdbeComment(tls, v, ts+23705, libc.VaList(bp+80, pItem1))

	Xsqlite3VdbeJumpHere(tls, v, topAddr)
	Xsqlite3ClearTempRegCache(tls, pParse)
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pItem1 + 60 + 4))&0x100>>8)) != 0 && int32(*(*uint16)(unsafe.Pointer(pItem1 + 60 + 4))&0x8>>3) == 0) {
		goto __45
	}
	pCteUse1 = *(*uintptr)(unsafe.Pointer(pItem1 + 96))
	(*CteUse)(unsafe.Pointer(pCteUse1)).FaddrM9e = (*SrcItem)(unsafe.Pointer(pItem1)).FaddrFillSub
	(*CteUse)(unsafe.Pointer(pCteUse1)).FregRtn = (*SrcItem)(unsafe.Pointer(pItem1)).FregReturn
	(*CteUse)(unsafe.Pointer(pCteUse1)).FiCur = (*SrcItem)(unsafe.Pointer(pItem1)).FiCursor
	(*CteUse)(unsafe.Pointer(pCteUse1)).FnRowEst = (*Select)(unsafe.Pointer(pSub1)).FnSelectRow
__45:
	;
__40:
	;
__37:
	;
__35:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __46
	}
	goto select_end
__46:
	;
	*(*int32)(unsafe.Pointer(pParse + 316)) -= Xsqlite3SelectExprHeight(tls, p)
	(*Parse)(unsafe.Pointer(pParse)).FzAuthContext = zSavedAuthContext
	goto __28
__28:
	i++
	goto __27
	goto __29
__29:
	;
	pEList = (*Select)(unsafe.Pointer(p)).FpEList
	pWhere = (*Select)(unsafe.Pointer(p)).FpWhere
	pGroupBy = (*Select)(unsafe.Pointer(p)).FpGroupBy
	pHaving = (*Select)(unsafe.Pointer(p)).FpHaving
	(*DistinctCtx)(unsafe.Pointer(bp + 176)).FisTnct = U8(libc.Bool32((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct) != U32(0)))

	if !((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct|SF_Aggregate) == U32(SF_Distinct) &&
		Xsqlite3ExprListCompare(tls, (*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy, pEList, -1) == 0 &&
		(*Select)(unsafe.Pointer(p)).FpWin == uintptr(0)) {
		goto __47
	}
	*(*U32)(unsafe.Pointer(p + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_Distinct))
	pGroupBy = libc.AssignPtrUintptr(p+56, Xsqlite3ExprListDup(tls, db, pEList, 0))
	*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_Aggregate)

	(*DistinctCtx)(unsafe.Pointer(bp + 176)).FisTnct = U8(2)

__47:
	;
	if !((*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy != 0) {
		goto __48
	}
	pKeyInfo = Xsqlite3KeyInfoFromExprList(tls,
		pParse, (*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy, 0, (*ExprList)(unsafe.Pointer(pEList)).FnExpr)
	(*SortCtx)(unsafe.Pointer(bp + 88)).FiECursor = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	(*SortCtx)(unsafe.Pointer(bp + 88)).FaddrSortIndex = Xsqlite3VdbeAddOp4(tls, v, OP_OpenEphemeral,
		(*SortCtx)(unsafe.Pointer(bp+88)).FiECursor, (*ExprList)(unsafe.Pointer((*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy)).FnExpr+1+(*ExprList)(unsafe.Pointer(pEList)).FnExpr, 0,
		pKeyInfo, -8)
	goto __49
__48:
	(*SortCtx)(unsafe.Pointer(bp + 88)).FaddrSortIndex = -1
__49:
	;
	if !(int32((*SelectDest)(unsafe.Pointer(pDest)).FeDest) == SRT_EphemTab) {
		goto __50
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, (*SelectDest)(unsafe.Pointer(pDest)).FiSDParm, (*ExprList)(unsafe.Pointer(pEList)).FnExpr)
	if !((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_NestedFrom) != 0) {
		goto __51
	}
	ii = (*ExprList)(unsafe.Pointer(pEList)).FnExpr - 1
__52:
	if !(ii > 0 && int32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32 + 16 + 4))&0x40>>6) == 0) {
		goto __54
	}
	Xsqlite3ExprDelete(tls, db, (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(ii)*32)).FpExpr)
	Xsqlite3DbFree(tls, db, (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(ii)*32)).FzEName)
	(*ExprList)(unsafe.Pointer(pEList)).FnExpr--
	goto __53
__53:
	ii--
	goto __52
	goto __54
__54:
	;
	ii = 0
__55:
	if !(ii < (*ExprList)(unsafe.Pointer(pEList)).FnExpr) {
		goto __57
	}
	if !(int32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32 + 16 + 4))&0x40>>6) == 0) {
		goto __58
	}
	(*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(ii)*32)).FpExpr)).Fop = U8(TK_NULL)
__58:
	;
	goto __56
__56:
	ii++
	goto __55
	goto __57
__57:
	;
__51:
	;
__50:
	;
	iEnd = Xsqlite3VdbeMakeLabel(tls, pParse)
	if !((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_FixedLimit) == U32(0)) {
		goto __59
	}
	(*Select)(unsafe.Pointer(p)).FnSelectRow = int16(320)
__59:
	;
	if !((*Select)(unsafe.Pointer(p)).FpLimit != 0) {
		goto __60
	}
	computeLimitRegisters(tls, pParse, p, iEnd)
__60:
	;
	if !((*Select)(unsafe.Pointer(p)).FiLimit == 0 && (*SortCtx)(unsafe.Pointer(bp+88)).FaddrSortIndex >= 0) {
		goto __61
	}
	Xsqlite3VdbeChangeOpcode(tls, v, (*SortCtx)(unsafe.Pointer(bp+88)).FaddrSortIndex, uint8(OP_SorterOpen))
	*(*U8)(unsafe.Pointer(bp + 88 + 36)) |= U8(SORTFLAG_UseSorter)
__61:
	;
	if !((*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct) != 0) {
		goto __62
	}
	(*DistinctCtx)(unsafe.Pointer(bp + 176)).FtabTnct = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	(*DistinctCtx)(unsafe.Pointer(bp + 176)).FaddrTnct = Xsqlite3VdbeAddOp4(tls, v, OP_OpenEphemeral,
		(*DistinctCtx)(unsafe.Pointer(bp+176)).FtabTnct, 0, 0,
		Xsqlite3KeyInfoFromExprList(tls, pParse, (*Select)(unsafe.Pointer(p)).FpEList, 0, 0),
		-8)
	Xsqlite3VdbeChangeP5(tls, v, uint16(BTREE_UNORDERED))
	(*DistinctCtx)(unsafe.Pointer(bp + 176)).FeTnctType = U8(WHERE_DISTINCT_UNORDERED)
	goto __63
__62:
	(*DistinctCtx)(unsafe.Pointer(bp + 176)).FeTnctType = U8(WHERE_DISTINCT_NOOP)
__63:
	;
	if !(!(isAgg != 0) && pGroupBy == uintptr(0)) {
		goto __64
	}

	wctrlFlags = U16(func() uint32 {
		if (*DistinctCtx)(unsafe.Pointer(bp+176)).FisTnct != 0 {
			return uint32(WHERE_WANT_DISTINCT)
		}
		return uint32(0)
	}() |
		(*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_FixedLimit))
	pWin = (*Select)(unsafe.Pointer(p)).FpWin
	if !(pWin != 0) {
		goto __66
	}
	Xsqlite3WindowCodeInit(tls, pParse, p)
__66:
	;
	pWInfo = Xsqlite3WhereBegin(tls, pParse, pTabList, pWhere, (*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy,
		(*Select)(unsafe.Pointer(p)).FpEList, p, wctrlFlags, int32((*Select)(unsafe.Pointer(p)).FnSelectRow))
	if !(pWInfo == uintptr(0)) {
		goto __67
	}
	goto select_end
__67:
	;
	if !(int32(Xsqlite3WhereOutputRowCount(tls, pWInfo)) < int32((*Select)(unsafe.Pointer(p)).FnSelectRow)) {
		goto __68
	}
	(*Select)(unsafe.Pointer(p)).FnSelectRow = Xsqlite3WhereOutputRowCount(tls, pWInfo)
__68:
	;
	if !((*DistinctCtx)(unsafe.Pointer(bp+176)).FisTnct != 0 && Xsqlite3WhereIsDistinct(tls, pWInfo) != 0) {
		goto __69
	}
	(*DistinctCtx)(unsafe.Pointer(bp + 176)).FeTnctType = U8(Xsqlite3WhereIsDistinct(tls, pWInfo))
__69:
	;
	if !((*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy != 0) {
		goto __70
	}
	(*SortCtx)(unsafe.Pointer(bp + 88)).FnOBSat = Xsqlite3WhereIsOrdered(tls, pWInfo)
	(*SortCtx)(unsafe.Pointer(bp + 88)).FlabelOBLopt = Xsqlite3WhereOrderByLimitOptLabel(tls, pWInfo)
	if !((*SortCtx)(unsafe.Pointer(bp+88)).FnOBSat == (*ExprList)(unsafe.Pointer((*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy)).FnExpr) {
		goto __71
	}
	(*SortCtx)(unsafe.Pointer(bp + 88)).FpOrderBy = uintptr(0)
__71:
	;
__70:
	;
	if !((*SortCtx)(unsafe.Pointer(bp+88)).FaddrSortIndex >= 0 && (*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy == uintptr(0)) {
		goto __72
	}
	Xsqlite3VdbeChangeToNoop(tls, v, (*SortCtx)(unsafe.Pointer(bp+88)).FaddrSortIndex)
__72:
	;
	if !(pWin != 0) {
		goto __73
	}
	addrGosub = Xsqlite3VdbeMakeLabel(tls, pParse)
	iCont = Xsqlite3VdbeMakeLabel(tls, pParse)
	iBreak = Xsqlite3VdbeMakeLabel(tls, pParse)
	regGosub = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)

	Xsqlite3WindowCodeStep(tls, pParse, p, pWInfo, regGosub, addrGosub)

	Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, iBreak)
	Xsqlite3VdbeResolveLabel(tls, v, addrGosub)
	Xsqlite3VdbeNoopComment(tls, v, ts+23713, 0)
	(*SortCtx)(unsafe.Pointer(bp + 88)).FlabelOBLopt = 0
	selectInnerLoop(tls, pParse, p, -1, bp+88, bp+176, pDest, iCont, iBreak)
	Xsqlite3VdbeResolveLabel(tls, v, iCont)
	Xsqlite3VdbeAddOp1(tls, v, OP_Return, regGosub)
	Xsqlite3VdbeComment(tls, v, ts+23735, 0)
	Xsqlite3VdbeResolveLabel(tls, v, iBreak)
	goto __74
__73:
	selectInnerLoop(tls, pParse, p, -1, bp+88, bp+176, pDest,
		Xsqlite3WhereContinueLabel(tls, pWInfo),
		Xsqlite3WhereBreakLabel(tls, pWInfo))

	Xsqlite3WhereEnd(tls, pWInfo)
__74:
	;
	goto __65
__64:
	sortPTab = 0
	sortOut = 0
	orderByGrp = 0

	if !(pGroupBy != 0) {
		goto __75
	}

	k = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpEList)).FnExpr
	pItem2 = (*Select)(unsafe.Pointer(p)).FpEList + 8
__77:
	if !(k > 0) {
		goto __79
	}
	*(*U16)(unsafe.Pointer(pItem2 + 24 + 2)) = U16(0)
	goto __78
__78:
	k--
	pItem2 += 32
	goto __77
	goto __79
__79:
	;
	k = (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr
	pItem2 = pGroupBy + 8
__80:
	if !(k > 0) {
		goto __82
	}
	*(*U16)(unsafe.Pointer(pItem2 + 24 + 2)) = U16(0)
	goto __81
__81:
	k--
	pItem2 += 32
	goto __80
	goto __82
__82:
	;
	if !(int32((*Select)(unsafe.Pointer(p)).FnSelectRow) > 66) {
		goto __83
	}
	(*Select)(unsafe.Pointer(p)).FnSelectRow = int16(66)
__83:
	;
	if !((*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy != 0 && (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr == (*ExprList)(unsafe.Pointer((*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy)).FnExpr) {
		goto __84
	}

	ii1 = 0
__85:
	if !(ii1 < (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
		goto __87
	}
	sortFlags = U8(int32((*ExprList_item)(unsafe.Pointer((*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy+8+uintptr(ii1)*32)).Ffg.FsortFlags) & KEYINFO_ORDER_DESC)
	(*ExprList_item)(unsafe.Pointer(pGroupBy + 8 + uintptr(ii1)*32)).Ffg.FsortFlags = sortFlags
	goto __86
__86:
	ii1++
	goto __85
	goto __87
__87:
	;
	if !(Xsqlite3ExprListCompare(tls, pGroupBy, (*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy, -1) == 0) {
		goto __88
	}
	orderByGrp = 1
__88:
	;
__84:
	;
	goto __76
__75:
	;
	(*Select)(unsafe.Pointer(p)).FnSelectRow = int16(0)
__76:
	;
	addrEnd = Xsqlite3VdbeMakeLabel(tls, pParse)

	pAggInfo = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(AggInfo{})))
	if !(pAggInfo != 0) {
		goto __89
	}
	Xsqlite3ParserAddCleanup(tls, pParse,
		*(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{agginfoFree})), pAggInfo)

__89:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __90
	}
	goto select_end
__90:
	;
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FselId = (*Select)(unsafe.Pointer(p)).FselId
	libc.Xmemset(tls, bp+192, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp + 192)).FpParse = pParse
	(*NameContext)(unsafe.Pointer(bp + 192)).FpSrcList = pTabList
	*(*uintptr)(unsafe.Pointer(bp + 192 + 16)) = pAggInfo

	(*AggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn = func() uint16 {
		if pGroupBy != 0 {
			return uint16((*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr)
		}
		return uint16(0)
	}()
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FpGroupBy = pGroupBy
	Xsqlite3ExprAnalyzeAggList(tls, bp+192, pEList)
	Xsqlite3ExprAnalyzeAggList(tls, bp+192, (*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy)
	if !(pHaving != 0) {
		goto __91
	}
	if !(pGroupBy != 0) {
		goto __92
	}

	havingToWhere(tls, pParse, p)
	pWhere = (*Select)(unsafe.Pointer(p)).FpWhere
__92:
	;
	Xsqlite3ExprAnalyzeAggregates(tls, bp+192, pHaving)
__91:
	;
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator = (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn
	if !((*Select)(unsafe.Pointer(p)).FpGroupBy == uintptr(0) && (*Select)(unsafe.Pointer(p)).FpHaving == uintptr(0) && (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == 1) {
		goto __93
	}
	minMaxFlag = minMaxQuery(tls, db, (*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FpFExpr, bp+248)
	goto __94
__93:
	minMaxFlag = U8(WHERE_ORDERBY_NORMAL)
__94:
	;
	analyzeAggFuncArgs(tls, pAggInfo, bp+192)
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __95
	}
	goto select_end
__95:
	;
	if !(pGroupBy != 0) {
		goto __96
	}
	pDistinct = uintptr(0)
	distFlag = U16(0)
	eDist = WHERE_DISTINCT_NOOP

	if !((*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == 1 &&
		(*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FiDistinct >= 0 &&
		(*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FpFExpr != uintptr(0) &&
		(*Expr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FpFExpr)).Fflags&U32(EP_xIsSelect) == U32(0) &&
		*(*uintptr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FpFExpr + 32)) != uintptr(0)) {
		goto __98
	}
	pExpr = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FpFExpr + 32)) + 8)).FpExpr
	pExpr = Xsqlite3ExprDup(tls, db, pExpr, 0)
	pDistinct = Xsqlite3ExprListDup(tls, db, pGroupBy, 0)
	pDistinct = Xsqlite3ExprListAppend(tls, pParse, pDistinct, pExpr)
	if pDistinct != 0 {
		distFlag = uint16(WHERE_WANT_DISTINCT | WHERE_AGG_DISTINCT)
	} else {
		distFlag = uint16(0)
	}
__98:
	;
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	pKeyInfo1 = Xsqlite3KeyInfoFromExprList(tls, pParse, pGroupBy,
		0, (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn)
	addrSortingIdx = Xsqlite3VdbeAddOp4(tls, v, OP_SorterOpen,
		(*AggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, int32((*AggInfo)(unsafe.Pointer(pAggInfo)).FnSortingColumn),
		0, pKeyInfo1, -8)

	iUseFlag = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	iAbortFlag = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	regOutputRow = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	addrOutputRow = Xsqlite3VdbeMakeLabel(tls, pParse)
	regReset = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	addrReset = Xsqlite3VdbeMakeLabel(tls, pParse)
	iAMem = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr
	iBMem = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, iAbortFlag)
	Xsqlite3VdbeComment(tls, v, ts+23761, 0)
	Xsqlite3VdbeAddOp3(tls, v, OP_Null, 0, iAMem, iAMem+(*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr-1)

	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regReset, addrReset)

	pWInfo = Xsqlite3WhereBegin(tls, pParse, pTabList, pWhere, pGroupBy, pDistinct,
		p, uint16(func() int32 {
			if int32((*DistinctCtx)(unsafe.Pointer(bp+176)).FisTnct) == 2 {
				return WHERE_DISTINCTBY
			}
			return WHERE_GROUPBY
		}()|
			func() int32 {
				if orderByGrp != 0 {
					return WHERE_SORTBYGROUP
				}
				return 0
			}()|int32(distFlag)), 0)
	if !(pWInfo == uintptr(0)) {
		goto __99
	}
	Xsqlite3ExprListDelete(tls, db, pDistinct)
	goto select_end
__99:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FpIdxEpr != 0) {
		goto __100
	}
	optimizeAggregateUseOfIndexedExpr(tls, pParse, p, pAggInfo, bp+192)
__100:
	;
	assignAggregateRegisters(tls, pParse, pAggInfo)
	eDist = Xsqlite3WhereIsDistinct(tls, pWInfo)

	if !(Xsqlite3WhereIsOrdered(tls, pWInfo) == (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
		goto __101
	}

	groupBySort = 0
	goto __102
__101:
	explainTempTable(tls, pParse,
		func() uintptr {
			if (*DistinctCtx)(unsafe.Pointer(bp+176)).FisTnct != 0 && (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct) == U32(0) {
				return ts + 23778
			}
			return ts + 23787
		}())

	groupBySort = 1
	nGroupBy = (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr
	nCol = nGroupBy
	j = nGroupBy
	i = 0
__103:
	if !(i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
		goto __105
	}
	if !(int32((*AggInfo_col)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol+uintptr(i)*24)).FiSorterColumn) >= j) {
		goto __106
	}
	nCol++
	j++
__106:
	;
	goto __104
__104:
	i++
	goto __103
	goto __105
__105:
	;
	regBase = Xsqlite3GetTempRange(tls, pParse, nCol)
	Xsqlite3ExprCodeExprList(tls, pParse, pGroupBy, regBase, 0, uint8(0))
	j = nGroupBy
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = U8(1)
	i = 0
__107:
	if !(i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn) {
		goto __109
	}
	pCol = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaCol + uintptr(i)*24
	if !(int32((*AggInfo_col)(unsafe.Pointer(pCol)).FiSorterColumn) >= j) {
		goto __110
	}
	Xsqlite3ExprCode(tls, pParse, (*AggInfo_col)(unsafe.Pointer(pCol)).FpCExpr, j+regBase)
	j++
__110:
	;
	goto __108
__108:
	i++
	goto __107
	goto __109
__109:
	;
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = U8(0)
	regRecord = Xsqlite3GetTempReg(tls, pParse)
	Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regBase, nCol, regRecord)
	Xsqlite3VdbeAddOp2(tls, v, OP_SorterInsert, (*AggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, regRecord)
	Xsqlite3ReleaseTempReg(tls, pParse, regRecord)
	Xsqlite3ReleaseTempRange(tls, pParse, regBase, nCol)

	Xsqlite3WhereEnd(tls, pWInfo)
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdxPTab = libc.AssignInt32(&sortPTab, libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1))
	sortOut = Xsqlite3GetTempReg(tls, pParse)
	Xsqlite3VdbeAddOp3(tls, v, OP_OpenPseudo, sortPTab, sortOut, nCol)
	Xsqlite3VdbeAddOp2(tls, v, OP_SorterSort, (*AggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, addrEnd)
	Xsqlite3VdbeComment(tls, v, ts+23796, 0)
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FuseSortingIdx = U8(1)
__102:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FpIdxEpr != 0) {
		goto __111
	}
	aggregateConvertIndexedExprRefToColumn(tls, pAggInfo)
__111:
	;
	if !(orderByGrp != 0 && (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_GroupByOrder) == U32(0) &&
		(groupBySort != 0 || Xsqlite3WhereIsSorted(tls, pWInfo) != 0)) {
		goto __112
	}
	(*SortCtx)(unsafe.Pointer(bp + 88)).FpOrderBy = uintptr(0)
	Xsqlite3VdbeChangeToNoop(tls, v, (*SortCtx)(unsafe.Pointer(bp+88)).FaddrSortIndex)
__112:
	;
	addrTopOfLoop = Xsqlite3VdbeCurrentAddr(tls, v)
	if !(groupBySort != 0) {
		goto __113
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_SorterData, (*AggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx,
		sortOut, sortPTab)
__113:
	;
	j = 0
__114:
	if !(j < (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
		goto __116
	}
	if !(groupBySort != 0) {
		goto __117
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, sortPTab, j, iBMem+j)
	goto __118
__117:
	(*AggInfo)(unsafe.Pointer(pAggInfo)).FdirectMode = U8(1)
	Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pGroupBy+8+uintptr(j)*32)).FpExpr, iBMem+j)
__118:
	;
	goto __115
__115:
	j++
	goto __114
	goto __116
__116:
	;
	Xsqlite3VdbeAddOp4(tls, v, OP_Compare, iAMem, iBMem, (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr,
		Xsqlite3KeyInfoRef(tls, pKeyInfo1), -8)
	addr1 = Xsqlite3VdbeCurrentAddr(tls, v)
	Xsqlite3VdbeAddOp3(tls, v, OP_Jump, addr1+1, 0, addr1+1)

	Xsqlite3ExprCodeMove(tls, pParse, iBMem, iAMem, (*ExprList)(unsafe.Pointer(pGroupBy)).FnExpr)
	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regOutputRow, addrOutputRow)
	Xsqlite3VdbeComment(tls, v, ts+23810, 0)
	Xsqlite3VdbeAddOp2(tls, v, OP_IfPos, iAbortFlag, addrEnd)
	Xsqlite3VdbeComment(tls, v, ts+23825, 0)
	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regReset, addrReset)
	Xsqlite3VdbeComment(tls, v, ts+23842, 0)

	Xsqlite3VdbeJumpHere(tls, v, addr1)
	updateAccumulator(tls, pParse, iUseFlag, pAggInfo, eDist)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, iUseFlag)
	Xsqlite3VdbeComment(tls, v, ts+23860, 0)

	if !(groupBySort != 0) {
		goto __119
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_SorterNext, (*AggInfo)(unsafe.Pointer(pAggInfo)).FsortingIdx, addrTopOfLoop)

	goto __120
__119:
	;
	Xsqlite3WhereEnd(tls, pWInfo)
	Xsqlite3VdbeChangeToNoop(tls, v, addrSortingIdx)
__120:
	;
	Xsqlite3ExprListDelete(tls, db, pDistinct)

	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regOutputRow, addrOutputRow)
	Xsqlite3VdbeComment(tls, v, ts+23889, 0)

	Xsqlite3VdbeGoto(tls, v, addrEnd)

	addrSetAbort = Xsqlite3VdbeCurrentAddr(tls, v)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, iAbortFlag)
	Xsqlite3VdbeComment(tls, v, ts+23906, 0)
	Xsqlite3VdbeAddOp1(tls, v, OP_Return, regOutputRow)
	Xsqlite3VdbeResolveLabel(tls, v, addrOutputRow)
	addrOutputRow = Xsqlite3VdbeCurrentAddr(tls, v)
	Xsqlite3VdbeAddOp2(tls, v, OP_IfPos, iUseFlag, addrOutputRow+2)

	Xsqlite3VdbeComment(tls, v, ts+23921, 0)
	Xsqlite3VdbeAddOp1(tls, v, OP_Return, regOutputRow)
	finalizeAggFunctions(tls, pParse, pAggInfo)
	Xsqlite3ExprIfFalse(tls, pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL)
	selectInnerLoop(tls, pParse, p, -1, bp+88,
		bp+176, pDest,
		addrOutputRow+1, addrSetAbort)
	Xsqlite3VdbeAddOp1(tls, v, OP_Return, regOutputRow)
	Xsqlite3VdbeComment(tls, v, ts+23958, 0)

	Xsqlite3VdbeResolveLabel(tls, v, addrReset)
	resetAccumulator(tls, pParse, pAggInfo)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, iUseFlag)
	Xsqlite3VdbeComment(tls, v, ts+23987, 0)
	Xsqlite3VdbeAddOp1(tls, v, OP_Return, regReset)

	if !(int32(distFlag) != 0 && eDist != WHERE_DISTINCT_NOOP) {
		goto __121
	}
	pF = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
	fixDistinctOpenEph(tls, pParse, eDist, (*AggInfo_func)(unsafe.Pointer(pF)).FiDistinct, (*AggInfo_func)(unsafe.Pointer(pF)).FiDistAddr)
__121:
	;
	goto __97
__96:
	if !(libc.AssignUintptr(&pTab1, isSimpleCount(tls, p, pAggInfo)) != uintptr(0)) {
		goto __122
	}

	iDb = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Table)(unsafe.Pointer(pTab1)).FpSchema)
	iCsr = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	pKeyInfo2 = uintptr(0)
	pBest = uintptr(0)
	iRoot = (*Table)(unsafe.Pointer(pTab1)).Ftnum

	Xsqlite3CodeVerifySchema(tls, pParse, iDb)
	Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab1)).Ftnum, uint8(0), (*Table)(unsafe.Pointer(pTab1)).FzName)

	if !!((*Table)(unsafe.Pointer(pTab1)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __124
	}
	pBest = Xsqlite3PrimaryKeyIndex(tls, pTab1)
__124:
	;
	if !!(int32(*(*uint16)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8 + 60 + 4))&0x1>>0) != 0) {
		goto __125
	}
	pIdx = (*Table)(unsafe.Pointer(pTab1)).FpIndex
__126:
	if !(pIdx != 0) {
		goto __128
	}
	if !(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x4>>2) == 0 &&
		int32((*Index)(unsafe.Pointer(pIdx)).FszIdxRow) < int32((*Table)(unsafe.Pointer(pTab1)).FszTabRow) &&
		(*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) &&
		(!(pBest != 0) || int32((*Index)(unsafe.Pointer(pIdx)).FszIdxRow) < int32((*Index)(unsafe.Pointer(pBest)).FszIdxRow))) {
		goto __129
	}
	pBest = pIdx
__129:
	;
	goto __127
__127:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	goto __126
	goto __128
__128:
	;
__125:
	;
	if !(pBest != 0) {
		goto __130
	}
	iRoot = (*Index)(unsafe.Pointer(pBest)).Ftnum
	pKeyInfo2 = Xsqlite3KeyInfoOfIndex(tls, pParse, pBest)
__130:
	;
	Xsqlite3VdbeAddOp4Int(tls, v, OP_OpenRead, iCsr, int32(iRoot), iDb, 1)
	if !(pKeyInfo2 != 0) {
		goto __131
	}
	Xsqlite3VdbeChangeP4(tls, v, -1, pKeyInfo2, -8)
__131:
	;
	assignAggregateRegisters(tls, pParse, pAggInfo)
	Xsqlite3VdbeAddOp2(tls, v, OP_Count, iCsr, func() int32 {
		return (*AggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg + (*AggInfo)(unsafe.Pointer(pAggInfo)).FnColumn + 0
	}())
	Xsqlite3VdbeAddOp1(tls, v, OP_Close, iCsr)
	explainSimpleCount(tls, pParse, pTab1, pBest)
	goto __123
__122:
	regAcc = 0
	pDistinct1 = uintptr(0)
	distFlag1 = U16(0)

	if !((*AggInfo)(unsafe.Pointer(pAggInfo)).FnAccumulator != 0) {
		goto __132
	}
	i = 0
__134:
	if !(i < (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
		goto __136
	}
	if !((*Expr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc+uintptr(i)*24)).FpFExpr)).Fflags&U32(EP_WinFunc) != U32(0)) {
		goto __137
	}
	goto __135
__137:
	;
	if !((*FuncDef)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc+uintptr(i)*24)).FpFunc)).FfuncFlags&U32(SQLITE_FUNC_NEEDCOLL) != 0) {
		goto __138
	}
	goto __136
__138:
	;
	goto __135
__135:
	i++
	goto __134
	goto __136
__136:
	;
	if !(i == (*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
		goto __139
	}
	regAcc = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regAcc)
__139:
	;
	goto __133
__132:
	if !((*AggInfo)(unsafe.Pointer(pAggInfo)).FnFunc == 1 && (*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FiDistinct >= 0) {
		goto __140
	}

	pDistinct1 = *(*uintptr)(unsafe.Pointer((*AggInfo_func)(unsafe.Pointer((*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc)).FpFExpr + 32))
	if pDistinct1 != 0 {
		distFlag1 = uint16(WHERE_WANT_DISTINCT | WHERE_AGG_DISTINCT)
	} else {
		distFlag1 = uint16(0)
	}
__140:
	;
__133:
	;
	assignAggregateRegisters(tls, pParse, pAggInfo)

	resetAccumulator(tls, pParse, pAggInfo)

	pWInfo = Xsqlite3WhereBegin(tls, pParse, pTabList, pWhere, *(*uintptr)(unsafe.Pointer(bp + 248)),
		pDistinct1, p, uint16(int32(minMaxFlag)|int32(distFlag1)), 0)
	if !(pWInfo == uintptr(0)) {
		goto __141
	}
	goto select_end
__141:
	;
	eDist1 = Xsqlite3WhereIsDistinct(tls, pWInfo)
	updateAccumulator(tls, pParse, regAcc, pAggInfo, eDist1)
	if !(eDist1 != WHERE_DISTINCT_NOOP) {
		goto __142
	}
	pF1 = (*AggInfo)(unsafe.Pointer(pAggInfo)).FaFunc
	if !(pF1 != 0) {
		goto __143
	}
	fixDistinctOpenEph(tls, pParse, eDist1, (*AggInfo_func)(unsafe.Pointer(pF1)).FiDistinct, (*AggInfo_func)(unsafe.Pointer(pF1)).FiDistAddr)
__143:
	;
__142:
	;
	if !(regAcc != 0) {
		goto __144
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, regAcc)
__144:
	;
	if !(minMaxFlag != 0) {
		goto __145
	}
	Xsqlite3WhereMinMaxOptEarlyOut(tls, v, pWInfo)
__145:
	;
	Xsqlite3WhereEnd(tls, pWInfo)
	finalizeAggFunctions(tls, pParse, pAggInfo)
__123:
	;
	(*SortCtx)(unsafe.Pointer(bp + 88)).FpOrderBy = uintptr(0)
	Xsqlite3ExprIfFalse(tls, pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL)
	selectInnerLoop(tls, pParse, p, -1, uintptr(0), uintptr(0),
		pDest, addrEnd, addrEnd)
__97:
	;
	Xsqlite3VdbeResolveLabel(tls, v, addrEnd)

__65:
	;
	if !(int32((*DistinctCtx)(unsafe.Pointer(bp+176)).FeTnctType) == WHERE_DISTINCT_UNORDERED) {
		goto __146
	}
	explainTempTable(tls, pParse, ts+23778)
__146:
	;
	if !((*SortCtx)(unsafe.Pointer(bp+88)).FpOrderBy != 0) {
		goto __147
	}

	generateSortTail(tls, pParse, p, bp+88, (*ExprList)(unsafe.Pointer(pEList)).FnExpr, pDest)
__147:
	;
	Xsqlite3VdbeResolveLabel(tls, v, iEnd)

	rc = libc.Bool32((*Parse)(unsafe.Pointer(pParse)).FnErr > 0)

select_end:
	;
	Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(bp + 248)))

	Xsqlite3VdbeExplainPop(tls, pParse)
	return rc
}

type TabResult1 = struct {
	FazResult    uintptr
	FzErrMsg     uintptr
	FnAlloc      U32
	FnRow        U32
	FnColumn     U32
	FnData       U32
	Frc          int32
	F__ccgo_pad1 [4]byte
}

type TabResult = TabResult1

func sqlite3_get_table_cb(tls *libc.TLS, pArg uintptr, nCol int32, argv uintptr, colv uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p uintptr
	var need int32
	var i int32
	var z uintptr
	var azNew uintptr
	var n int32
	p = pArg

	if !((*TabResult)(unsafe.Pointer(p)).FnRow == U32(0) && argv != uintptr(0)) {
		goto __1
	}
	need = nCol * 2
	goto __2
__1:
	need = nCol
__2:
	;
	if !((*TabResult)(unsafe.Pointer(p)).FnData+U32(need) > (*TabResult)(unsafe.Pointer(p)).FnAlloc) {
		goto __3
	}
	(*TabResult)(unsafe.Pointer(p)).FnAlloc = (*TabResult)(unsafe.Pointer(p)).FnAlloc*U32(2) + U32(need)
	azNew = Xsqlite3Realloc(tls, (*TabResult)(unsafe.Pointer(p)).FazResult, uint64(unsafe.Sizeof(uintptr(0)))*uint64((*TabResult)(unsafe.Pointer(p)).FnAlloc))
	if !(azNew == uintptr(0)) {
		goto __4
	}
	goto malloc_failed
__4:
	;
	(*TabResult)(unsafe.Pointer(p)).FazResult = azNew
__3:
	;
	if !((*TabResult)(unsafe.Pointer(p)).FnRow == U32(0)) {
		goto __5
	}
	(*TabResult)(unsafe.Pointer(p)).FnColumn = U32(nCol)
	i = 0
__7:
	if !(i < nCol) {
		goto __9
	}
	z = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(colv + uintptr(i)*8))))
	if !(z == uintptr(0)) {
		goto __10
	}
	goto malloc_failed
__10:
	;
	*(*uintptr)(unsafe.Pointer((*TabResult)(unsafe.Pointer(p)).FazResult + uintptr(libc.PostIncUint32(&(*TabResult)(unsafe.Pointer(p)).FnData, 1))*8)) = z
	goto __8
__8:
	i++
	goto __7
	goto __9
__9:
	;
	goto __6
__5:
	if !(int32((*TabResult)(unsafe.Pointer(p)).FnColumn) != nCol) {
		goto __11
	}
	Xsqlite3_free(tls, (*TabResult)(unsafe.Pointer(p)).FzErrMsg)
	(*TabResult)(unsafe.Pointer(p)).FzErrMsg = Xsqlite3_mprintf(tls,
		ts+24014, 0)
	(*TabResult)(unsafe.Pointer(p)).Frc = SQLITE_ERROR
	return 1
__11:
	;
__6:
	;
	if !(argv != uintptr(0)) {
		goto __12
	}
	i = 0
__13:
	if !(i < nCol) {
		goto __15
	}
	if !(*(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)) == uintptr(0)) {
		goto __16
	}
	z = uintptr(0)
	goto __17
__16:
	n = Xsqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8))) + 1
	z = Xsqlite3_malloc64(tls, uint64(n))
	if !(z == uintptr(0)) {
		goto __18
	}
	goto malloc_failed
__18:
	;
	libc.Xmemcpy(tls, z, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)), uint64(n))
__17:
	;
	*(*uintptr)(unsafe.Pointer((*TabResult)(unsafe.Pointer(p)).FazResult + uintptr(libc.PostIncUint32(&(*TabResult)(unsafe.Pointer(p)).FnData, 1))*8)) = z
	goto __14
__14:
	i++
	goto __13
	goto __15
__15:
	;
	(*TabResult)(unsafe.Pointer(p)).FnRow++
__12:
	;
	return 0

malloc_failed:
	(*TabResult)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
	return 1
}

func Xsqlite3_get_table(tls *libc.TLS, db uintptr, zSql uintptr, pazResult uintptr, pnRow uintptr, pnColumn uintptr, pzErrMsg uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var rc int32

	*(*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)
	}
	(*TabResult)(unsafe.Pointer(bp + 8)).FzErrMsg = uintptr(0)
	(*TabResult)(unsafe.Pointer(bp + 8)).FnRow = U32(0)
	(*TabResult)(unsafe.Pointer(bp + 8)).FnColumn = U32(0)
	(*TabResult)(unsafe.Pointer(bp + 8)).FnData = U32(1)
	(*TabResult)(unsafe.Pointer(bp + 8)).FnAlloc = U32(20)
	(*TabResult)(unsafe.Pointer(bp + 8)).Frc = SQLITE_OK
	(*TabResult)(unsafe.Pointer(bp + 8)).FazResult = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(uintptr(0)))*uint64((*TabResult)(unsafe.Pointer(bp+8)).FnAlloc))
	if (*TabResult)(unsafe.Pointer(bp+8)).FazResult == uintptr(0) {
		(*Sqlite3)(unsafe.Pointer(db)).FerrCode = SQLITE_NOMEM
		return SQLITE_NOMEM
	}
	*(*uintptr)(unsafe.Pointer((*TabResult)(unsafe.Pointer(bp + 8)).FazResult)) = uintptr(0)
	rc = Xsqlite3_exec(tls, db, zSql, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
	}{sqlite3_get_table_cb})), bp+8, pzErrMsg)

	*(*uintptr)(unsafe.Pointer((*TabResult)(unsafe.Pointer(bp + 8)).FazResult)) = uintptr(int64((*TabResult)(unsafe.Pointer(bp + 8)).FnData))
	if rc&0xff == SQLITE_ABORT {
		Xsqlite3_free_table(tls, (*TabResult)(unsafe.Pointer(bp+8)).FazResult+1*8)
		if (*TabResult)(unsafe.Pointer(bp+8)).FzErrMsg != 0 {
			if pzErrMsg != 0 {
				Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(pzErrMsg)))
				*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, (*TabResult)(unsafe.Pointer(bp+8)).FzErrMsg))
			}
			Xsqlite3_free(tls, (*TabResult)(unsafe.Pointer(bp+8)).FzErrMsg)
		}
		(*Sqlite3)(unsafe.Pointer(db)).FerrCode = (*TabResult)(unsafe.Pointer(bp + 8)).Frc
		return (*TabResult)(unsafe.Pointer(bp + 8)).Frc
	}
	Xsqlite3_free(tls, (*TabResult)(unsafe.Pointer(bp+8)).FzErrMsg)
	if rc != SQLITE_OK {
		Xsqlite3_free_table(tls, (*TabResult)(unsafe.Pointer(bp+8)).FazResult+1*8)
		return rc
	}
	if (*TabResult)(unsafe.Pointer(bp+8)).FnAlloc > (*TabResult)(unsafe.Pointer(bp+8)).FnData {
		var azNew uintptr
		azNew = Xsqlite3Realloc(tls, (*TabResult)(unsafe.Pointer(bp+8)).FazResult, uint64(unsafe.Sizeof(uintptr(0)))*uint64((*TabResult)(unsafe.Pointer(bp+8)).FnData))
		if azNew == uintptr(0) {
			Xsqlite3_free_table(tls, (*TabResult)(unsafe.Pointer(bp+8)).FazResult+1*8)
			(*Sqlite3)(unsafe.Pointer(db)).FerrCode = SQLITE_NOMEM
			return SQLITE_NOMEM
		}
		(*TabResult)(unsafe.Pointer(bp + 8)).FazResult = azNew
	}
	*(*uintptr)(unsafe.Pointer(pazResult)) = (*TabResult)(unsafe.Pointer(bp+8)).FazResult + 1*8
	if pnColumn != 0 {
		*(*int32)(unsafe.Pointer(pnColumn)) = int32((*TabResult)(unsafe.Pointer(bp + 8)).FnColumn)
	}
	if pnRow != 0 {
		*(*int32)(unsafe.Pointer(pnRow)) = int32((*TabResult)(unsafe.Pointer(bp + 8)).FnRow)
	}
	return rc
}

func Xsqlite3_free_table(tls *libc.TLS, azResult uintptr) {
	if azResult != 0 {
		var i int32
		var n int32
		azResult -= 8

		n = int32(*(*uintptr)(unsafe.Pointer(azResult)))
		for i = 1; i < n; i++ {
			if *(*uintptr)(unsafe.Pointer(azResult + uintptr(i)*8)) != 0 {
				Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(azResult + uintptr(i)*8)))
			}
		}
		Xsqlite3_free(tls, azResult)
	}
}

func Xsqlite3DeleteTriggerStep(tls *libc.TLS, db uintptr, pTriggerStep uintptr) {
	for pTriggerStep != 0 {
		var pTmp uintptr = pTriggerStep
		pTriggerStep = (*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpNext

		Xsqlite3ExprDelete(tls, db, (*TriggerStep)(unsafe.Pointer(pTmp)).FpWhere)
		Xsqlite3ExprListDelete(tls, db, (*TriggerStep)(unsafe.Pointer(pTmp)).FpExprList)
		Xsqlite3SelectDelete(tls, db, (*TriggerStep)(unsafe.Pointer(pTmp)).FpSelect)
		Xsqlite3IdListDelete(tls, db, (*TriggerStep)(unsafe.Pointer(pTmp)).FpIdList)
		Xsqlite3UpsertDelete(tls, db, (*TriggerStep)(unsafe.Pointer(pTmp)).FpUpsert)
		Xsqlite3SrcListDelete(tls, db, (*TriggerStep)(unsafe.Pointer(pTmp)).FpFrom)
		Xsqlite3DbFree(tls, db, (*TriggerStep)(unsafe.Pointer(pTmp)).FzSpan)

		Xsqlite3DbFree(tls, db, pTmp)
	}
}

func Xsqlite3TriggerList(tls *libc.TLS, pParse uintptr, pTab uintptr) uintptr {
	var pTmpSchema uintptr
	var pList uintptr
	var p uintptr

	pTmpSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FaDb + 1*32)).FpSchema
	p = (*Hash)(unsafe.Pointer(pTmpSchema + 56)).Ffirst
	pList = (*Table)(unsafe.Pointer(pTab)).FpTrigger
	for p != 0 {
		var pTrig uintptr = (*HashElem)(unsafe.Pointer(p)).Fdata
		if (*Trigger)(unsafe.Pointer(pTrig)).FpTabSchema == (*Table)(unsafe.Pointer(pTab)).FpSchema &&
			(*Trigger)(unsafe.Pointer(pTrig)).Ftable != 0 &&
			0 == Xsqlite3StrICmp(tls, (*Trigger)(unsafe.Pointer(pTrig)).Ftable, (*Table)(unsafe.Pointer(pTab)).FzName) &&
			((*Trigger)(unsafe.Pointer(pTrig)).FpTabSchema != pTmpSchema || (*Trigger)(unsafe.Pointer(pTrig)).FbReturning != 0) {
			(*Trigger)(unsafe.Pointer(pTrig)).FpNext = pList
			pList = pTrig
		} else if int32((*Trigger)(unsafe.Pointer(pTrig)).Fop) == TK_RETURNING {
			(*Trigger)(unsafe.Pointer(pTrig)).Ftable = (*Table)(unsafe.Pointer(pTab)).FzName
			(*Trigger)(unsafe.Pointer(pTrig)).FpTabSchema = (*Table)(unsafe.Pointer(pTab)).FpSchema
			(*Trigger)(unsafe.Pointer(pTrig)).FpNext = pList
			pList = pTrig
		}
		p = (*HashElem)(unsafe.Pointer(p)).Fnext
	}
	return pList
}

func Xsqlite3BeginTrigger(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(136)
	defer tls.Free(136)

	var pTrigger uintptr
	var pTab uintptr
	var zName uintptr
	var db uintptr
	var iDb int32

	var iTabDb int32
	var code int32
	var zDb uintptr
	var zDbTrig uintptr
	pTrigger = uintptr(0)
	zName = uintptr(0)
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !(isTemp != 0) {
		goto __1
	}

	if !((*Token)(unsafe.Pointer(pName2)).Fn > uint32(0)) {
		goto __3
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+24079, 0)
	goto trigger_cleanup
__3:
	;
	iDb = 1
	*(*uintptr)(unsafe.Pointer(bp + 32)) = pName1
	goto __2
__1:
	iDb = Xsqlite3TwoPartName(tls, pParse, pName1, pName2, bp+32)
	if !(iDb < 0) {
		goto __4
	}
	goto trigger_cleanup
__4:
	;
__2:
	;
	if !(!(pTableName != 0) || (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __5
	}
	goto trigger_cleanup
__5:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0 && iDb != 1) {
		goto __6
	}
	Xsqlite3DbFree(tls, db, (*SrcItem)(unsafe.Pointer(pTableName+8)).FzDatabase)
	(*SrcItem)(unsafe.Pointer(pTableName + 8)).FzDatabase = uintptr(0)
__6:
	;
	pTab = Xsqlite3SrcListLookup(tls, pParse, pTableName)
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) == 0 && (*Token)(unsafe.Pointer(pName2)).Fn == uint32(0) && pTab != 0 &&
		(*Table)(unsafe.Pointer(pTab)).FpSchema == (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema) {
		goto __7
	}
	iDb = 1
__7:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __8
	}
	goto trigger_cleanup
__8:
	;
	Xsqlite3FixInit(tls, bp+40, pParse, iDb, ts+24125, *(*uintptr)(unsafe.Pointer(bp + 32)))
	if !(Xsqlite3FixSrcList(tls, bp+40, pTableName) != 0) {
		goto __9
	}
	goto trigger_cleanup
__9:
	;
	pTab = Xsqlite3SrcListLookup(tls, pParse, pTableName)
	if !!(pTab != 0) {
		goto __10
	}

	goto trigger_orphan_error
__10:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __11
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+24133, 0)
	goto trigger_orphan_error
__11:
	;
	zName = Xsqlite3NameFromToken(tls, db, *(*uintptr)(unsafe.Pointer(bp + 32)))
	if !(zName == uintptr(0)) {
		goto __12
	}

	goto trigger_cleanup
__12:
	;
	if !(Xsqlite3CheckObjectName(tls, pParse, zName, ts+24125, (*Table)(unsafe.Pointer(pTab)).FzName) != 0) {
		goto __13
	}
	goto trigger_cleanup
__13:
	;
	if !!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __14
	}
	if !(Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema+56, zName) != 0) {
		goto __15
	}
	if !!(noErr != 0) {
		goto __16
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+24174, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(bp + 32))))
	goto __17
__16:
	;
	Xsqlite3CodeVerifySchema(tls, pParse, iDb)

__17:
	;
	goto trigger_cleanup
__15:
	;
__14:
	;
	if !(Xsqlite3_strnicmp(tls, (*Table)(unsafe.Pointer(pTab)).FzName, ts+9596, 7) == 0) {
		goto __18
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+24200, 0)
	goto trigger_cleanup
__18:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW && tr_tm != TK_INSTEAD) {
		goto __19
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+24238,
		libc.VaList(bp+8, func() uintptr {
			if tr_tm == TK_BEFORE {
				return ts + 24275
			}
			return ts + 24282
		}(), pTableName+8))
	goto trigger_orphan_error
__19:
	;
	if !(!(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) && tr_tm == TK_INSTEAD) {
		goto __20
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+24288, libc.VaList(bp+24, pTableName+8))
	goto trigger_orphan_error
__20:
	;
	if !!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __21
	}
	iTabDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)
	code = SQLITE_CREATE_TRIGGER
	zDb = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iTabDb)*32)).FzDbSName
	if isTemp != 0 {
		zDbTrig = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + 1*32)).FzDbSName
	} else {
		zDbTrig = zDb
	}
	if !(iTabDb == 1 || isTemp != 0) {
		goto __22
	}
	code = SQLITE_CREATE_TEMP_TRIGGER
__22:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, code, zName, (*Table)(unsafe.Pointer(pTab)).FzName, zDbTrig) != 0) {
		goto __23
	}
	goto trigger_cleanup
__23:
	;
	if !(Xsqlite3AuthCheck(tls, pParse, SQLITE_INSERT, func() uintptr {
		if !(0 != 0) && iTabDb == 1 {
			return ts + 9604
		}
		return ts + 8808
	}(), uintptr(0), zDb) != 0) {
		goto __24
	}
	goto trigger_cleanup
__24:
	;
__21:
	;
	if !(tr_tm == TK_INSTEAD) {
		goto __25
	}
	tr_tm = TK_BEFORE
__25:
	;
	pTrigger = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Trigger{})))
	if !(pTrigger == uintptr(0)) {
		goto __26
	}
	goto trigger_cleanup
__26:
	;
	(*Trigger)(unsafe.Pointer(pTrigger)).FzName = zName
	zName = uintptr(0)
	(*Trigger)(unsafe.Pointer(pTrigger)).Ftable = Xsqlite3DbStrDup(tls, db, (*SrcItem)(unsafe.Pointer(pTableName+8)).FzName)
	(*Trigger)(unsafe.Pointer(pTrigger)).FpSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpSchema
	(*Trigger)(unsafe.Pointer(pTrigger)).FpTabSchema = (*Table)(unsafe.Pointer(pTab)).FpSchema
	(*Trigger)(unsafe.Pointer(pTrigger)).Fop = U8(op)
	(*Trigger)(unsafe.Pointer(pTrigger)).Ftr_tm = func() uint8 {
		if tr_tm == TK_BEFORE {
			return uint8(TRIGGER_BEFORE)
		}
		return uint8(TRIGGER_AFTER)
	}()
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __27
	}
	Xsqlite3RenameTokenRemap(tls, pParse, (*Trigger)(unsafe.Pointer(pTrigger)).Ftable, (*SrcItem)(unsafe.Pointer(pTableName+8)).FzName)
	(*Trigger)(unsafe.Pointer(pTrigger)).FpWhen = pWhen
	pWhen = uintptr(0)
	goto __28
__27:
	(*Trigger)(unsafe.Pointer(pTrigger)).FpWhen = Xsqlite3ExprDup(tls, db, pWhen, EXPRDUP_REDUCE)
__28:
	;
	(*Trigger)(unsafe.Pointer(pTrigger)).FpColumns = pColumns
	pColumns = uintptr(0)

	(*Parse)(unsafe.Pointer(pParse)).FpNewTrigger = pTrigger

trigger_cleanup:
	Xsqlite3DbFree(tls, db, zName)
	Xsqlite3SrcListDelete(tls, db, pTableName)
	Xsqlite3IdListDelete(tls, db, pColumns)
	Xsqlite3ExprDelete(tls, db, pWhen)
	if !!(int32((*Parse)(unsafe.Pointer(pParse)).FpNewTrigger) != 0) {
		goto __29
	}
	Xsqlite3DeleteTrigger(tls, db, pTrigger)
	goto __30
__29:
	;
__30:
	;
	return

trigger_orphan_error:
	if !(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb) == 1) {
		goto __31
	}

	libc.SetBitFieldPtr8Uint32(db+192+8, uint32(1), 0, 0x1)
__31:
	;
	goto trigger_cleanup
}

func Xsqlite3FinishTrigger(tls *libc.TLS, pParse uintptr, pStepList uintptr, pAll uintptr) {
	bp := tls.Alloc(168)
	defer tls.Free(168)

	var pTrig uintptr
	var zName uintptr
	var db uintptr

	var iDb int32

	var pStep uintptr
	var v uintptr
	var z uintptr
	var pTab uintptr
	var pLink uintptr
	var pHash uintptr
	pTrig = (*Parse)(unsafe.Pointer(pParse)).FpNewTrigger
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	(*Parse)(unsafe.Pointer(pParse)).FpNewTrigger = uintptr(0)
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0 || !(pTrig != 0)) {
		goto __1
	}
	goto triggerfinish_cleanup
__1:
	;
	zName = (*Trigger)(unsafe.Pointer(pTrig)).FzName
	iDb = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Trigger)(unsafe.Pointer(pTrig)).FpSchema)
	(*Trigger)(unsafe.Pointer(pTrig)).Fstep_list = pStepList
__2:
	if !(pStepList != 0) {
		goto __3
	}
	(*TriggerStep)(unsafe.Pointer(pStepList)).FpTrig = pTrig
	pStepList = (*TriggerStep)(unsafe.Pointer(pStepList)).FpNext
	goto __2
__3:
	;
	Xsqlite3TokenInit(tls, bp+56, (*Trigger)(unsafe.Pointer(pTrig)).FzName)
	Xsqlite3FixInit(tls, bp+72, pParse, iDb, ts+24125, bp+56)
	if !(Xsqlite3FixTriggerStep(tls, bp+72, (*Trigger)(unsafe.Pointer(pTrig)).Fstep_list) != 0 ||
		Xsqlite3FixExpr(tls, bp+72, (*Trigger)(unsafe.Pointer(pTrig)).FpWhen) != 0) {
		goto __4
	}
	goto triggerfinish_cleanup
__4:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		goto __5
	}

	(*Parse)(unsafe.Pointer(pParse)).FpNewTrigger = pTrig
	pTrig = uintptr(0)
	goto __6
__5:
	if !!(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) {
		goto __7
	}

	if !(Xsqlite3ReadOnlyShadowTables(tls, db) != 0) {
		goto __8
	}
	pStep = (*Trigger)(unsafe.Pointer(pTrig)).Fstep_list
__9:
	if !(pStep != 0) {
		goto __11
	}
	if !((*TriggerStep)(unsafe.Pointer(pStep)).FzTarget != uintptr(0) &&
		Xsqlite3ShadowTableName(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget) != 0) {
		goto __12
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+24334,
		libc.VaList(bp, (*Trigger)(unsafe.Pointer(pTrig)).FzName, (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget))
	goto triggerfinish_cleanup
__12:
	;
	goto __10
__10:
	pStep = (*TriggerStep)(unsafe.Pointer(pStep)).FpNext
	goto __9
	goto __11
__11:
	;
__8:
	;
	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v == uintptr(0)) {
		goto __13
	}
	goto triggerfinish_cleanup
__13:
	;
	Xsqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	z = Xsqlite3DbStrNDup(tls, db, (*Token)(unsafe.Pointer(pAll)).Fz, uint64((*Token)(unsafe.Pointer(pAll)).Fn))

	Xsqlite3NestedParse(tls, pParse,
		ts+24382,
		libc.VaList(bp+16, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName, zName,
			(*Trigger)(unsafe.Pointer(pTrig)).Ftable, z))
	Xsqlite3DbFree(tls, db, z)
	Xsqlite3ChangeCookie(tls, pParse, iDb)
	Xsqlite3VdbeAddParseSchemaOp(tls, v, iDb,
		Xsqlite3MPrintf(tls, db, ts+24457, libc.VaList(bp+48, zName)), uint16(0))
__7:
	;
__6:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy != 0) {
		goto __14
	}
	pLink = pTrig
	pHash = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema + 56

	pTrig = Xsqlite3HashInsert(tls, pHash, zName, pTrig)
	if !(pTrig != 0) {
		goto __15
	}
	Xsqlite3OomFault(tls, db)
	goto __16
__15:
	if !((*Trigger)(unsafe.Pointer(pLink)).FpSchema == (*Trigger)(unsafe.Pointer(pLink)).FpTabSchema) {
		goto __17
	}
	pTab = Xsqlite3HashFind(tls, (*Trigger)(unsafe.Pointer(pLink)).FpTabSchema+8, (*Trigger)(unsafe.Pointer(pLink)).Ftable)

	(*Trigger)(unsafe.Pointer(pLink)).FpNext = (*Table)(unsafe.Pointer(pTab)).FpTrigger
	(*Table)(unsafe.Pointer(pTab)).FpTrigger = pLink
__17:
	;
__16:
	;
__14:
	;
triggerfinish_cleanup:
	Xsqlite3DeleteTrigger(tls, db, pTrig)

	Xsqlite3DeleteTriggerStep(tls, db, pStepList)
}

func triggerSpanDup(tls *libc.TLS, db uintptr, zStart uintptr, zEnd uintptr) uintptr {
	var z uintptr = Xsqlite3DbSpanDup(tls, db, zStart, zEnd)
	var i int32
	if z != 0 {
		for i = 0; *(*uint8)(unsafe.Pointer(z + uintptr(i))) != 0; i++ {
			if int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x01 != 0 {
				*(*uint8)(unsafe.Pointer(z + uintptr(i))) = uint8(' ')
			}
		}
	}
	return z
}

func Xsqlite3TriggerSelectStep(tls *libc.TLS, db uintptr, pSelect uintptr, zStart uintptr, zEnd uintptr) uintptr {
	var pTriggerStep uintptr = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(TriggerStep{})))
	if pTriggerStep == uintptr(0) {
		Xsqlite3SelectDelete(tls, db, pSelect)
		return uintptr(0)
	}
	(*TriggerStep)(unsafe.Pointer(pTriggerStep)).Fop = U8(TK_SELECT)
	(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpSelect = pSelect
	(*TriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = U8(OE_Default)
	(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FzSpan = triggerSpanDup(tls, db, zStart, zEnd)
	return pTriggerStep
}

func triggerStepAllocate(tls *libc.TLS, pParse uintptr, op U8, pName uintptr, zStart uintptr, zEnd uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pTriggerStep uintptr

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return uintptr(0)
	}
	pTriggerStep = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(TriggerStep{}))+uint64((*Token)(unsafe.Pointer(pName)).Fn)+uint64(1))
	if pTriggerStep != 0 {
		var z uintptr = pTriggerStep + 1*96
		libc.Xmemcpy(tls, z, (*Token)(unsafe.Pointer(pName)).Fz, uint64((*Token)(unsafe.Pointer(pName)).Fn))
		Xsqlite3Dequote(tls, z)
		(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FzTarget = z
		(*TriggerStep)(unsafe.Pointer(pTriggerStep)).Fop = op
		(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FzSpan = triggerSpanDup(tls, db, zStart, zEnd)
		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			Xsqlite3RenameTokenMap(tls, pParse, (*TriggerStep)(unsafe.Pointer(pTriggerStep)).FzTarget, pName)
		}
	}
	return pTriggerStep
}

func Xsqlite3TriggerInsertStep(tls *libc.TLS, pParse uintptr, pTableName uintptr, pColumn uintptr, pSelect uintptr, orconf U8, pUpsert uintptr, zStart uintptr, zEnd uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pTriggerStep uintptr

	pTriggerStep = triggerStepAllocate(tls, pParse, uint8(TK_INSERT), pTableName, zStart, zEnd)
	if pTriggerStep != 0 {
		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpSelect = pSelect
			pSelect = uintptr(0)
		} else {
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpSelect = Xsqlite3SelectDup(tls, db, pSelect, EXPRDUP_REDUCE)
		}
		(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpIdList = pColumn
		(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpUpsert = pUpsert
		(*TriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = orconf
		if pUpsert != 0 {
			Xsqlite3HasExplicitNulls(tls, pParse, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
		}
	} else {
		Xsqlite3IdListDelete(tls, db, pColumn)

		Xsqlite3UpsertDelete(tls, db, pUpsert)
	}
	Xsqlite3SelectDelete(tls, db, pSelect)

	return pTriggerStep
}

func Xsqlite3TriggerUpdateStep(tls *libc.TLS, pParse uintptr, pTableName uintptr, pFrom uintptr, pEList uintptr, pWhere uintptr, orconf U8, zStart uintptr, zEnd uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pTriggerStep uintptr

	pTriggerStep = triggerStepAllocate(tls, pParse, uint8(TK_UPDATE), pTableName, zStart, zEnd)
	if pTriggerStep != 0 {
		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpExprList = pEList
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpWhere = pWhere
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpFrom = pFrom
			pEList = uintptr(0)
			pWhere = uintptr(0)
			pFrom = uintptr(0)
		} else {
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpExprList = Xsqlite3ExprListDup(tls, db, pEList, EXPRDUP_REDUCE)
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpWhere = Xsqlite3ExprDup(tls, db, pWhere, EXPRDUP_REDUCE)
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpFrom = Xsqlite3SrcListDup(tls, db, pFrom, EXPRDUP_REDUCE)
		}
		(*TriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = orconf
	}
	Xsqlite3ExprListDelete(tls, db, pEList)
	Xsqlite3ExprDelete(tls, db, pWhere)
	Xsqlite3SrcListDelete(tls, db, pFrom)
	return pTriggerStep
}

func Xsqlite3TriggerDeleteStep(tls *libc.TLS, pParse uintptr, pTableName uintptr, pWhere uintptr, zStart uintptr, zEnd uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pTriggerStep uintptr

	pTriggerStep = triggerStepAllocate(tls, pParse, uint8(TK_DELETE), pTableName, zStart, zEnd)
	if pTriggerStep != 0 {
		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpWhere = pWhere
			pWhere = uintptr(0)
		} else {
			(*TriggerStep)(unsafe.Pointer(pTriggerStep)).FpWhere = Xsqlite3ExprDup(tls, db, pWhere, EXPRDUP_REDUCE)
		}
		(*TriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = U8(OE_Default)
	}
	Xsqlite3ExprDelete(tls, db, pWhere)
	return pTriggerStep
}

func Xsqlite3DeleteTrigger(tls *libc.TLS, db uintptr, pTrigger uintptr) {
	if pTrigger == uintptr(0) || (*Trigger)(unsafe.Pointer(pTrigger)).FbReturning != 0 {
		return
	}
	Xsqlite3DeleteTriggerStep(tls, db, (*Trigger)(unsafe.Pointer(pTrigger)).Fstep_list)
	Xsqlite3DbFree(tls, db, (*Trigger)(unsafe.Pointer(pTrigger)).FzName)
	Xsqlite3DbFree(tls, db, (*Trigger)(unsafe.Pointer(pTrigger)).Ftable)
	Xsqlite3ExprDelete(tls, db, (*Trigger)(unsafe.Pointer(pTrigger)).FpWhen)
	Xsqlite3IdListDelete(tls, db, (*Trigger)(unsafe.Pointer(pTrigger)).FpColumns)
	Xsqlite3DbFree(tls, db, pTrigger)
}

func Xsqlite3DropTrigger(tls *libc.TLS, pParse uintptr, pName uintptr, noErr int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pTrigger uintptr
	var i int32
	var zDb uintptr
	var zName uintptr
	var db uintptr
	var j int32
	pTrigger = uintptr(0)
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __1
	}
	goto drop_trigger_cleanup
__1:
	;
	if !(SQLITE_OK != Xsqlite3ReadSchema(tls, pParse)) {
		goto __2
	}
	goto drop_trigger_cleanup
__2:
	;
	zDb = (*SrcItem)(unsafe.Pointer(pName + 8)).FzDatabase
	zName = (*SrcItem)(unsafe.Pointer(pName + 8)).FzName

	i = OMIT_TEMPDB
__3:
	if !(i < (*Sqlite3)(unsafe.Pointer(db)).FnDb) {
		goto __5
	}
	if i < 2 {
		j = i ^ 1
	} else {
		j = i
	}
	if !(zDb != 0 && Xsqlite3DbIsNamed(tls, db, j, zDb) == 0) {
		goto __6
	}
	goto __4
__6:
	;
	pTrigger = Xsqlite3HashFind(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(j)*32)).FpSchema+56, zName)
	if !(pTrigger != 0) {
		goto __7
	}
	goto __5
__7:
	;
	goto __4
__4:
	i++
	goto __3
	goto __5
__5:
	;
	if !!(pTrigger != 0) {
		goto __8
	}
	if !!(noErr != 0) {
		goto __9
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+24486, libc.VaList(bp, pName+8))
	goto __10
__9:
	Xsqlite3CodeVerifyNamedSchema(tls, pParse, zDb)
__10:
	;
	(*Parse)(unsafe.Pointer(pParse)).FcheckSchema = U8(1)
	goto drop_trigger_cleanup
__8:
	;
	Xsqlite3DropTriggerPtr(tls, pParse, pTrigger)

drop_trigger_cleanup:
	Xsqlite3SrcListDelete(tls, db, pName)
}

func tableOfTrigger(tls *libc.TLS, pTrigger uintptr) uintptr {
	return Xsqlite3HashFind(tls, (*Trigger)(unsafe.Pointer(pTrigger)).FpTabSchema+8, (*Trigger)(unsafe.Pointer(pTrigger)).Ftable)
}

func Xsqlite3DropTriggerPtr(tls *libc.TLS, pParse uintptr, pTrigger uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTable uintptr
	var v uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var iDb int32

	iDb = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Trigger)(unsafe.Pointer(pTrigger)).FpSchema)

	pTable = tableOfTrigger(tls, pTrigger)

	if pTable != 0 {
		var code int32 = SQLITE_DROP_TRIGGER
		var zDb uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
		var zTab uintptr = func() uintptr {
			if !(0 != 0) && iDb == 1 {
				return ts + 9604
			}
			return ts + 8808
		}()
		if iDb == 1 {
			code = SQLITE_DROP_TEMP_TRIGGER
		}
		if Xsqlite3AuthCheck(tls, pParse, code, (*Trigger)(unsafe.Pointer(pTrigger)).FzName, (*Table)(unsafe.Pointer(pTable)).FzName, zDb) != 0 || Xsqlite3AuthCheck(tls, pParse, SQLITE_DELETE, zTab, uintptr(0), zDb) != 0 {
			return
		}
	}

	if libc.AssignUintptr(&v, Xsqlite3GetVdbe(tls, pParse)) != uintptr(0) {
		Xsqlite3NestedParse(tls, pParse,
			ts+24506,
			libc.VaList(bp, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName, (*Trigger)(unsafe.Pointer(pTrigger)).FzName))
		Xsqlite3ChangeCookie(tls, pParse, iDb)
		Xsqlite3VdbeAddOp4(tls, v, OP_DropTrigger, iDb, 0, 0, (*Trigger)(unsafe.Pointer(pTrigger)).FzName, 0)
	}
}

func Xsqlite3UnlinkAndDeleteTrigger(tls *libc.TLS, db uintptr, iDb int32, zName uintptr) {
	var pTrigger uintptr
	var pHash uintptr

	pHash = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema + 56
	pTrigger = Xsqlite3HashInsert(tls, pHash, zName, uintptr(0))
	if pTrigger != 0 {
		if (*Trigger)(unsafe.Pointer(pTrigger)).FpSchema == (*Trigger)(unsafe.Pointer(pTrigger)).FpTabSchema {
			var pTab uintptr = tableOfTrigger(tls, pTrigger)
			if pTab != 0 {
				var pp uintptr
				for pp = pTab + 88; *(*uintptr)(unsafe.Pointer(pp)) != 0; pp = *(*uintptr)(unsafe.Pointer(pp)) + 64 {
					if *(*uintptr)(unsafe.Pointer(pp)) == pTrigger {
						*(*uintptr)(unsafe.Pointer(pp)) = (*Trigger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext
						break
					}
				}
			}
		}
		Xsqlite3DeleteTrigger(tls, db, pTrigger)
		*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_SchemaChange)
	}
}

func checkColumnOverlap(tls *libc.TLS, pIdList uintptr, pEList uintptr) int32 {
	var e int32
	if pIdList == uintptr(0) || pEList == uintptr(0) {
		return 1
	}
	for e = 0; e < (*ExprList)(unsafe.Pointer(pEList)).FnExpr; e++ {
		if Xsqlite3IdListIndex(tls, pIdList, (*ExprList_item)(unsafe.Pointer(pEList+8+uintptr(e)*32)).FzEName) >= 0 {
			return 1
		}
	}
	return 0
}

func tempTriggersExist(tls *libc.TLS, db uintptr) int32 {
	if (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema == uintptr(0) {
		return 0
	}
	if (*Hash)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema+56)).Ffirst == uintptr(0) {
		return 0
	}
	return 1
}

func triggersReallyExist(tls *libc.TLS, pParse uintptr, pTab uintptr, op int32, pChanges uintptr, pMask uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var mask int32
	var pList uintptr
	var p uintptr
	mask = 0
	pList = uintptr(0)

	pList = Xsqlite3TriggerList(tls, pParse, pTab)

	if !(pList != uintptr(0)) {
		goto __1
	}
	p = pList
	if !((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_EnableTrigger) == uint64(0) &&
		(*Table)(unsafe.Pointer(pTab)).FpTrigger != uintptr(0)) {
		goto __2
	}

	if !(pList == (*Table)(unsafe.Pointer(pTab)).FpTrigger) {
		goto __3
	}
	pList = uintptr(0)
	goto exit_triggers_exist
__3:
	;
__4:
	if !((*Trigger)(unsafe.Pointer(p)).FpNext != 0 && (*Trigger)(unsafe.Pointer(p)).FpNext != (*Table)(unsafe.Pointer(pTab)).FpTrigger) {
		goto __5
	}
	p = (*Trigger)(unsafe.Pointer(p)).FpNext
	goto __4
__5:
	;
	(*Trigger)(unsafe.Pointer(p)).FpNext = uintptr(0)
	p = pList
__2:
	;
__6:
	if !(int32((*Trigger)(unsafe.Pointer(p)).Fop) == op && checkColumnOverlap(tls, (*Trigger)(unsafe.Pointer(p)).FpColumns, pChanges) != 0) {
		goto __9
	}
	mask = mask | int32((*Trigger)(unsafe.Pointer(p)).Ftr_tm)
	goto __10
__9:
	if !(int32((*Trigger)(unsafe.Pointer(p)).Fop) == TK_RETURNING) {
		goto __11
	}

	(*Trigger)(unsafe.Pointer(p)).Fop = U8(op)
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __13
	}
	if !(op != TK_INSERT) {
		goto __15
	}
	Xsqlite3ErrorMsg(tls, pParse,
		ts+24568,
		libc.VaList(bp, func() uintptr {
			if op == TK_DELETE {
				return ts + 24616
			}
			return ts + 24623
		}()))
__15:
	;
	(*Trigger)(unsafe.Pointer(p)).Ftr_tm = U8(TRIGGER_BEFORE)
	goto __14
__13:
	(*Trigger)(unsafe.Pointer(p)).Ftr_tm = U8(TRIGGER_AFTER)
__14:
	;
	mask = mask | int32((*Trigger)(unsafe.Pointer(p)).Ftr_tm)
	goto __12
__11:
	if !((*Trigger)(unsafe.Pointer(p)).FbReturning != 0 && int32((*Trigger)(unsafe.Pointer(p)).Fop) == TK_INSERT && op == TK_UPDATE &&
		(*Parse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0)) {
		goto __16
	}

	mask = mask | int32((*Trigger)(unsafe.Pointer(p)).Ftr_tm)
__16:
	;
__12:
	;
__10:
	;
	p = (*Trigger)(unsafe.Pointer(p)).FpNext
	goto __7
__7:
	if p != 0 {
		goto __6
	}
	goto __8
__8:
	;
__1:
	;
exit_triggers_exist:
	if !(pMask != 0) {
		goto __17
	}
	*(*int32)(unsafe.Pointer(pMask)) = mask
__17:
	;
	return func() uintptr {
		if mask != 0 {
			return pList
		}
		return uintptr(0)
	}()
}

func Xsqlite3TriggersExist(tls *libc.TLS, pParse uintptr, pTab uintptr, op int32, pChanges uintptr, pMask uintptr) uintptr {
	if (*Table)(unsafe.Pointer(pTab)).FpTrigger == uintptr(0) && !(tempTriggersExist(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb) != 0) ||
		(*Parse)(unsafe.Pointer(pParse)).FdisableTriggers != 0 {
		if pMask != 0 {
			*(*int32)(unsafe.Pointer(pMask)) = 0
		}
		return uintptr(0)
	}
	return triggersReallyExist(tls, pParse, pTab, op, pChanges, pMask)
}

func Xsqlite3TriggerStepSrc(tls *libc.TLS, pParse uintptr, pStep uintptr) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pSrc uintptr
	var zName uintptr = Xsqlite3DbStrDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FzTarget)
	pSrc = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))

	if pSrc != 0 {
		var pSchema uintptr = (*Trigger)(unsafe.Pointer((*TriggerStep)(unsafe.Pointer(pStep)).FpTrig)).FpSchema
		(*SrcItem)(unsafe.Pointer(pSrc + 8)).FzName = zName
		if pSchema != (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema {
			(*SrcItem)(unsafe.Pointer(pSrc + 8)).FpSchema = pSchema
		}
		if (*TriggerStep)(unsafe.Pointer(pStep)).FpFrom != 0 {
			var pDup uintptr = Xsqlite3SrcListDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FpFrom, 0)
			if pDup != 0 && (*SrcList)(unsafe.Pointer(pDup)).FnSrc > 1 && !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
				var pSubquery uintptr

				pSubquery = Xsqlite3SelectNew(tls, pParse, uintptr(0), pDup, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
				(*Token)(unsafe.Pointer(bp)).Fn = uint32(0)
				(*Token)(unsafe.Pointer(bp)).Fz = uintptr(0)
				pDup = Xsqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp, pSubquery, uintptr(0))
			}
			pSrc = Xsqlite3SrcListAppendList(tls, pParse, pSrc, pDup)
		}
	} else {
		Xsqlite3DbFree(tls, db, zName)
	}
	return pSrc
}

func isAsteriskTerm(tls *libc.TLS, pParse uintptr, pTerm uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pTerm)).Fop) == TK_ASTERISK {
		return 1
	}
	if int32((*Expr)(unsafe.Pointer(pTerm)).Fop) != TK_DOT {
		return 0
	}

	if int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pTerm)).FpRight)).Fop) != TK_ASTERISK {
		return 0
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+24630, 0)
	return 1
}

func sqlite3ExpandReturning(tls *libc.TLS, pParse uintptr, pList uintptr, pTab uintptr) uintptr {
	var pNew uintptr = uintptr(0)
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var i int32

	for i = 0; i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
		var pOldExpr uintptr = (*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*32)).FpExpr
		if pOldExpr == uintptr(0) {
			continue
		}
		if isAsteriskTerm(tls, pParse, pOldExpr) != 0 {
			var jj int32
			for jj = 0; jj < int32((*Table)(unsafe.Pointer(pTab)).FnCol); jj++ {
				var pNewExpr uintptr
				if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(jj)*24)).FcolFlags)&COLFLAG_HIDDEN != 0 {
					continue
				}
				pNewExpr = Xsqlite3Expr(tls, db, TK_ID, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(jj)*24)).FzCnName)
				pNew = Xsqlite3ExprListAppend(tls, pParse, pNew, pNewExpr)
				if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
					var pItem uintptr = pNew + 8 + uintptr((*ExprList)(unsafe.Pointer(pNew)).FnExpr-1)*32
					(*ExprList_item)(unsafe.Pointer(pItem)).FzEName = Xsqlite3DbStrDup(tls, db, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(jj)*24)).FzCnName)
					libc.SetBitFieldPtr16Uint32(pItem+16+4, uint32(ENAME_NAME), 0, 0x3)
				}
			}
		} else {
			var pNewExpr uintptr = Xsqlite3ExprDup(tls, db, pOldExpr, 0)
			pNew = Xsqlite3ExprListAppend(tls, pParse, pNew, pNewExpr)
			if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) && (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FzEName != uintptr(0) {
				var pItem uintptr = pNew + 8 + uintptr((*ExprList)(unsafe.Pointer(pNew)).FnExpr-1)*32
				(*ExprList_item)(unsafe.Pointer(pItem)).FzEName = Xsqlite3DbStrDup(tls, db, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FzEName)
				libc.SetBitFieldPtr16Uint32(pItem+16+4, uint32(int32(*(*uint16)(unsafe.Pointer(pList + 8 + uintptr(i)*32 + 16 + 4))&0x3>>0)), 0, 0x3)
			}
		}
	}
	return pNew
}

func codeReturningTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pTab uintptr, regIn int32) {
	bp := tls.Alloc(296)
	defer tls.Free(296)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pNew uintptr
	var pReturning uintptr

	pReturning = *(*uintptr)(unsafe.Pointer(pParse + 200))

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Select{})))
	libc.Xmemset(tls, bp+128, 0, uint64(unsafe.Sizeof(SrcList{})))
	(*Select)(unsafe.Pointer(bp)).FpEList = Xsqlite3ExprListDup(tls, db, (*Returning)(unsafe.Pointer(pReturning)).FpReturnEL, 0)
	(*Select)(unsafe.Pointer(bp)).FpSrc = bp + 128
	(*SrcList)(unsafe.Pointer(bp + 128)).FnSrc = 1
	(*SrcItem)(unsafe.Pointer(bp + 128 + 8)).FpTab = pTab
	(*SrcItem)(unsafe.Pointer(bp + 128 + 8)).FiCursor = -1
	Xsqlite3SelectPrep(tls, pParse, bp, uintptr(0))
	if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 {
		Xsqlite3GenerateColumnNames(tls, pParse, bp)
	}
	Xsqlite3ExprListDelete(tls, db, (*Select)(unsafe.Pointer(bp)).FpEList)
	pNew = sqlite3ExpandReturning(tls, pParse, (*Returning)(unsafe.Pointer(pReturning)).FpReturnEL, pTab)
	if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 {
		libc.Xmemset(tls, bp+240, 0, uint64(unsafe.Sizeof(NameContext{})))
		if (*Returning)(unsafe.Pointer(pReturning)).FnRetCol == 0 {
			(*Returning)(unsafe.Pointer(pReturning)).FnRetCol = (*ExprList)(unsafe.Pointer(pNew)).FnExpr
			(*Returning)(unsafe.Pointer(pReturning)).FiRetCur = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
		}
		(*NameContext)(unsafe.Pointer(bp + 240)).FpParse = pParse
		*(*int32)(unsafe.Pointer(bp + 240 + 16)) = regIn
		(*NameContext)(unsafe.Pointer(bp + 240)).FncFlags = NC_UBaseReg
		(*Parse)(unsafe.Pointer(pParse)).FeTriggerOp = (*Trigger)(unsafe.Pointer(pTrigger)).Fop
		(*Parse)(unsafe.Pointer(pParse)).FpTriggerTab = pTab
		if Xsqlite3ResolveExprListNames(tls, bp+240, pNew) == SQLITE_OK &&
			!(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
			var i int32
			var nCol int32 = (*ExprList)(unsafe.Pointer(pNew)).FnExpr
			var reg int32 = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
			*(*int32)(unsafe.Pointer(pParse + 56)) += nCol + 2
			(*Returning)(unsafe.Pointer(pReturning)).FiRetReg = reg
			for i = 0; i < nCol; i++ {
				var pCol uintptr = (*ExprList_item)(unsafe.Pointer(pNew + 8 + uintptr(i)*32)).FpExpr

				Xsqlite3ExprCodeFactorable(tls, pParse, pCol, reg+i)
				if int32(Xsqlite3ExprAffinity(tls, pCol)) == SQLITE_AFF_REAL {
					Xsqlite3VdbeAddOp1(tls, v, OP_RealAffinity, reg+i)
				}
			}
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, reg, i, reg+i)
			Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, (*Returning)(unsafe.Pointer(pReturning)).FiRetCur, reg+i+1)
			Xsqlite3VdbeAddOp3(tls, v, OP_Insert, (*Returning)(unsafe.Pointer(pReturning)).FiRetCur, reg+i, reg+i+1)
		}
	}
	Xsqlite3ExprListDelete(tls, db, pNew)
	(*Parse)(unsafe.Pointer(pParse)).FeTriggerOp = U8(0)
	(*Parse)(unsafe.Pointer(pParse)).FpTriggerTab = uintptr(0)
}

func codeTriggerProgram(tls *libc.TLS, pParse uintptr, pStepList uintptr, orconf int32) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var pStep uintptr
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	for pStep = pStepList; pStep != 0; pStep = (*TriggerStep)(unsafe.Pointer(pStep)).FpNext {
		(*Parse)(unsafe.Pointer(pParse)).FeOrconf = func() uint8 {
			if orconf == OE_Default {
				return (*TriggerStep)(unsafe.Pointer(pStep)).Forconf
			}
			return U8(orconf)
		}()

		if (*TriggerStep)(unsafe.Pointer(pStep)).FzSpan != 0 {
			Xsqlite3VdbeAddOp4(tls, v, OP_Trace, 0x7fffffff, 1, 0,
				Xsqlite3MPrintf(tls, db, ts+9005, libc.VaList(bp, (*TriggerStep)(unsafe.Pointer(pStep)).FzSpan)),
				-6)
		}

		switch int32((*TriggerStep)(unsafe.Pointer(pStep)).Fop) {
		case TK_UPDATE:
			{
				Xsqlite3Update(tls, pParse,
					Xsqlite3TriggerStepSrc(tls, pParse, pStep),
					Xsqlite3ExprListDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FpExprList, 0),
					Xsqlite3ExprDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FpWhere, 0),
					int32((*Parse)(unsafe.Pointer(pParse)).FeOrconf), uintptr(0), uintptr(0), uintptr(0))
				Xsqlite3VdbeAddOp0(tls, v, OP_ResetCount)
				break

			}
		case TK_INSERT:
			{
				Xsqlite3Insert(tls, pParse,
					Xsqlite3TriggerStepSrc(tls, pParse, pStep),
					Xsqlite3SelectDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FpSelect, 0),
					Xsqlite3IdListDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FpIdList),
					int32((*Parse)(unsafe.Pointer(pParse)).FeOrconf),
					Xsqlite3UpsertDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FpUpsert))
				Xsqlite3VdbeAddOp0(tls, v, OP_ResetCount)
				break

			}
		case TK_DELETE:
			{
				Xsqlite3DeleteFrom(tls, pParse,
					Xsqlite3TriggerStepSrc(tls, pParse, pStep),
					Xsqlite3ExprDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FpWhere, 0), uintptr(0), uintptr(0))
				Xsqlite3VdbeAddOp0(tls, v, OP_ResetCount)
				break

			}
		default:
			{
				var pSelect uintptr = Xsqlite3SelectDup(tls, db, (*TriggerStep)(unsafe.Pointer(pStep)).FpSelect, 0)
				Xsqlite3SelectDestInit(tls, bp+8, SRT_Discard, 0)
				Xsqlite3Select(tls, pParse, pSelect, bp+8)
				Xsqlite3SelectDelete(tls, db, pSelect)
				break

			}
		}
	}

	return 0
}

func onErrorText(tls *libc.TLS, onError int32) uintptr {
	switch onError {
	case OE_Abort:
		return ts + 24672
	case OE_Rollback:
		return ts + 24678
	case OE_Fail:
		return ts + 24687
	case OE_Replace:
		return ts + 18793
	case OE_Ignore:
		return ts + 24692
	case OE_Default:
		return ts + 24699
	}
	return ts + 24707
}

func transferParseError(tls *libc.TLS, pTo uintptr, pFrom uintptr) {
	if (*Parse)(unsafe.Pointer(pTo)).FnErr == 0 {
		(*Parse)(unsafe.Pointer(pTo)).FzErrMsg = (*Parse)(unsafe.Pointer(pFrom)).FzErrMsg
		(*Parse)(unsafe.Pointer(pTo)).FnErr = (*Parse)(unsafe.Pointer(pFrom)).FnErr
		(*Parse)(unsafe.Pointer(pTo)).Frc = (*Parse)(unsafe.Pointer(pFrom)).Frc
	} else {
		Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pFrom)).Fdb, (*Parse)(unsafe.Pointer(pFrom)).FzErrMsg)
	}
}

func codeRowTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pTab uintptr, orconf int32) uintptr {
	bp := tls.Alloc(560)
	defer tls.Free(560)

	var pTop uintptr = func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}()
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pPrg uintptr
	var pWhen uintptr = uintptr(0)
	var v uintptr

	var pProgram uintptr = uintptr(0)
	var iEndTrigger int32 = 0

	pPrg = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(TriggerPrg{})))
	if !(pPrg != 0) {
		return uintptr(0)
	}
	(*TriggerPrg)(unsafe.Pointer(pPrg)).FpNext = (*Parse)(unsafe.Pointer(pTop)).FpTriggerPrg
	(*Parse)(unsafe.Pointer(pTop)).FpTriggerPrg = pPrg
	(*TriggerPrg)(unsafe.Pointer(pPrg)).FpProgram = libc.AssignUintptr(&pProgram, Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(SubProgram{}))))
	if !(pProgram != 0) {
		return uintptr(0)
	}
	Xsqlite3VdbeLinkSubProgram(tls, (*Parse)(unsafe.Pointer(pTop)).FpVdbe, pProgram)
	(*TriggerPrg)(unsafe.Pointer(pPrg)).FpTrigger = pTrigger
	(*TriggerPrg)(unsafe.Pointer(pPrg)).Forconf = orconf
	*(*U32)(unsafe.Pointer(pPrg + 28)) = 0xffffffff
	*(*U32)(unsafe.Pointer(pPrg + 28 + 1*4)) = 0xffffffff

	Xsqlite3ParseObjectInit(tls, bp+80, db)
	libc.Xmemset(tls, bp+504, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp + 504)).FpParse = bp + 80
	(*Parse)(unsafe.Pointer(bp + 80)).FpTriggerTab = pTab
	(*Parse)(unsafe.Pointer(bp + 80)).FpToplevel = pTop
	(*Parse)(unsafe.Pointer(bp + 80)).FzAuthContext = (*Trigger)(unsafe.Pointer(pTrigger)).FzName
	(*Parse)(unsafe.Pointer(bp + 80)).FeTriggerOp = (*Trigger)(unsafe.Pointer(pTrigger)).Fop
	(*Parse)(unsafe.Pointer(bp + 80)).FnQueryLoop = (*Parse)(unsafe.Pointer(pParse)).FnQueryLoop
	(*Parse)(unsafe.Pointer(bp + 80)).FprepFlags = (*Parse)(unsafe.Pointer(pParse)).FprepFlags

	v = Xsqlite3GetVdbe(tls, bp+80)
	if v != 0 {
		Xsqlite3VdbeComment(tls, v, ts+24711, libc.VaList(bp, (*Trigger)(unsafe.Pointer(pTrigger)).FzName, onErrorText(tls, orconf), func() uintptr {
			if int32((*Trigger)(unsafe.Pointer(pTrigger)).Ftr_tm) == TRIGGER_BEFORE {
				return ts + 24275
			}
			return ts + 24282
		}(), func() uintptr {
			if int32((*Trigger)(unsafe.Pointer(pTrigger)).Fop) == TK_UPDATE {
				return ts + 24623
			}
			return ts + 1636
		}(), func() uintptr {
			if int32((*Trigger)(unsafe.Pointer(pTrigger)).Fop) == TK_INSERT {
				return ts + 24742
			}
			return ts + 1636
		}(), func() uintptr {
			if int32((*Trigger)(unsafe.Pointer(pTrigger)).Fop) == TK_DELETE {
				return ts + 24616
			}
			return ts + 1636
		}(), (*Table)(unsafe.Pointer(pTab)).FzName))
		if (*Trigger)(unsafe.Pointer(pTrigger)).FzName != 0 {
			Xsqlite3VdbeChangeP4(tls, v, -1,
				Xsqlite3MPrintf(tls, db, ts+24749, libc.VaList(bp+56, (*Trigger)(unsafe.Pointer(pTrigger)).FzName)), -6)
		}

		if (*Trigger)(unsafe.Pointer(pTrigger)).FpWhen != 0 {
			pWhen = Xsqlite3ExprDup(tls, db, (*Trigger)(unsafe.Pointer(pTrigger)).FpWhen, 0)
			if int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 &&
				SQLITE_OK == Xsqlite3ResolveExprNames(tls, bp+504, pWhen) {
				iEndTrigger = Xsqlite3VdbeMakeLabel(tls, bp+80)
				Xsqlite3ExprIfFalse(tls, bp+80, pWhen, iEndTrigger, SQLITE_JUMPIFNULL)
			}
			Xsqlite3ExprDelete(tls, db, pWhen)
		}

		codeTriggerProgram(tls, bp+80, (*Trigger)(unsafe.Pointer(pTrigger)).Fstep_list, orconf)

		if iEndTrigger != 0 {
			Xsqlite3VdbeResolveLabel(tls, v, iEndTrigger)
		}
		Xsqlite3VdbeAddOp0(tls, v, OP_Halt)
		Xsqlite3VdbeComment(tls, v, ts+24763, libc.VaList(bp+64, (*Trigger)(unsafe.Pointer(pTrigger)).FzName, onErrorText(tls, orconf)))
		transferParseError(tls, pParse, bp+80)

		if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 {
			(*SubProgram)(unsafe.Pointer(pProgram)).FaOp = Xsqlite3VdbeTakeOpArray(tls, v, pProgram+8, pTop+136)
		}
		(*SubProgram)(unsafe.Pointer(pProgram)).FnMem = (*Parse)(unsafe.Pointer(bp + 80)).FnMem
		(*SubProgram)(unsafe.Pointer(pProgram)).FnCsr = (*Parse)(unsafe.Pointer(bp + 80)).FnTab
		(*SubProgram)(unsafe.Pointer(pProgram)).Ftoken = pTrigger
		*(*U32)(unsafe.Pointer(pPrg + 28)) = (*Parse)(unsafe.Pointer(bp + 80)).Foldmask
		*(*U32)(unsafe.Pointer(pPrg + 28 + 1*4)) = (*Parse)(unsafe.Pointer(bp + 80)).Fnewmask
		Xsqlite3VdbeDelete(tls, v)
	} else {
		transferParseError(tls, pParse, bp+80)
	}

	Xsqlite3ParseObjectReset(tls, bp+80)
	return pPrg
}

func getRowTrigger(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pTab uintptr, orconf int32) uintptr {
	var pRoot uintptr = func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}()
	var pPrg uintptr

	for pPrg = (*Parse)(unsafe.Pointer(pRoot)).FpTriggerPrg; pPrg != 0 && ((*TriggerPrg)(unsafe.Pointer(pPrg)).FpTrigger != pTrigger || (*TriggerPrg)(unsafe.Pointer(pPrg)).Forconf != orconf); pPrg = (*TriggerPrg)(unsafe.Pointer(pPrg)).FpNext {
	}

	if !(pPrg != 0) {
		pPrg = codeRowTrigger(tls, pParse, pTrigger, pTab, orconf)
		(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FerrByteOffset = -1
	}

	return pPrg
}

func Xsqlite3CodeRowTriggerDirect(tls *libc.TLS, pParse uintptr, p uintptr, pTab uintptr, reg int32, orconf int32, ignoreJump int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var pPrg uintptr
	pPrg = getRowTrigger(tls, pParse, p, pTab, orconf)

	if pPrg != 0 {
		var bRecursive int32 = libc.Bool32((*Trigger)(unsafe.Pointer(p)).FzName != 0 && uint64(0) == (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_RecTriggers))

		Xsqlite3VdbeAddOp4(tls, v, OP_Program, reg, ignoreJump, libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1),
			(*TriggerPrg)(unsafe.Pointer(pPrg)).FpProgram, -4)
		Xsqlite3VdbeComment(tls, v, ts+24774, libc.VaList(bp, func() uintptr {
			if (*Trigger)(unsafe.Pointer(p)).FzName != 0 {
				return (*Trigger)(unsafe.Pointer(p)).FzName
			}
			return ts + 24786
		}(), onErrorText(tls, orconf)))

		Xsqlite3VdbeChangeP5(tls, v, uint16(U8(bRecursive)))
	}
}

func Xsqlite3CodeRowTrigger(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

	for p = pTrigger; p != 0; p = (*Trigger)(unsafe.Pointer(p)).FpNext {
		if (int32((*Trigger)(unsafe.Pointer(p)).Fop) == op || (*Trigger)(unsafe.Pointer(p)).FbReturning != 0 && int32((*Trigger)(unsafe.Pointer(p)).Fop) == TK_INSERT && op == TK_UPDATE) &&
			int32((*Trigger)(unsafe.Pointer(p)).Ftr_tm) == tr_tm &&
			checkColumnOverlap(tls, (*Trigger)(unsafe.Pointer(p)).FpColumns, pChanges) != 0 {
			if !(int32((*Trigger)(unsafe.Pointer(p)).FbReturning) != 0) {
				Xsqlite3CodeRowTriggerDirect(tls, pParse, p, pTab, reg, orconf, ignoreJump)
			} else if (*Parse)(unsafe.Pointer(pParse)).FpToplevel == uintptr(0) {
				codeReturningTrigger(tls, pParse, p, pTab, reg)
			}
		}
	}
}

func Xsqlite3TriggerColmask(tls *libc.TLS, pParse uintptr, pTrigger uintptr, pChanges uintptr, isNew int32, tr_tm int32, pTab uintptr, orconf int32) U32 {
	var op int32
	if pChanges != 0 {
		op = TK_UPDATE
	} else {
		op = TK_DELETE
	}
	var mask U32 = U32(0)
	var p uintptr

	for p = pTrigger; p != 0; p = (*Trigger)(unsafe.Pointer(p)).FpNext {
		if int32((*Trigger)(unsafe.Pointer(p)).Fop) == op &&
			tr_tm&int32((*Trigger)(unsafe.Pointer(p)).Ftr_tm) != 0 &&
			checkColumnOverlap(tls, (*Trigger)(unsafe.Pointer(p)).FpColumns, pChanges) != 0 {
			if (*Trigger)(unsafe.Pointer(p)).FbReturning != 0 {
				mask = 0xffffffff
			} else {
				var pPrg uintptr
				pPrg = getRowTrigger(tls, pParse, p, pTab, orconf)
				if pPrg != 0 {
					mask = mask | *(*U32)(unsafe.Pointer(pPrg + 28 + uintptr(isNew)*4))
				}
			}
		}
	}

	return mask
}

func Xsqlite3ColumnDefault(tls *libc.TLS, v uintptr, pTab uintptr, i int32, iReg int32) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pCol uintptr

	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*24
	if (*Column)(unsafe.Pointer(pCol)).FiDflt != 0 {
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
		var enc U8 = (*Sqlite3)(unsafe.Pointer(Xsqlite3VdbeDb(tls, v))).Fenc

		Xsqlite3VdbeComment(tls, v, ts+11397, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName, (*Column)(unsafe.Pointer(pCol)).FzCnName))

		Xsqlite3ValueFromExpr(tls, Xsqlite3VdbeDb(tls, v),
			Xsqlite3ColumnExpr(tls, pTab, pCol), enc,
			(*Column)(unsafe.Pointer(pCol)).Faffinity, bp+16)
		if *(*uintptr)(unsafe.Pointer(bp + 16)) != 0 {
			Xsqlite3VdbeAppendP4(tls, v, *(*uintptr)(unsafe.Pointer(bp + 16)), -10)
		}
	}
	if int32((*Column)(unsafe.Pointer(pCol)).Faffinity) == SQLITE_AFF_REAL && !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		Xsqlite3VdbeAddOp1(tls, v, OP_RealAffinity, iReg)
	}
}

func indexColumnIsBeingUpdated(tls *libc.TLS, pIdx uintptr, iCol int32, aXRef uintptr, chngRowid int32) int32 {
	var iIdxCol I16 = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iCol)*2))

	if int32(iIdxCol) >= 0 {
		return libc.Bool32(*(*int32)(unsafe.Pointer(aXRef + uintptr(iIdxCol)*4)) >= 0)
	}

	return Xsqlite3ExprReferencesUpdatedColumn(tls, (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr+8+uintptr(iCol)*32)).FpExpr,
		aXRef, chngRowid)
}

func indexWhereClauseMightChange(tls *libc.TLS, pIdx uintptr, aXRef uintptr, chngRowid int32) int32 {
	if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere == uintptr(0) {
		return 0
	}
	return Xsqlite3ExprReferencesUpdatedColumn(tls, (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere,
		aXRef, chngRowid)
}

func exprRowColumn(tls *libc.TLS, pParse uintptr, iCol int32) uintptr {
	var pRet uintptr = Xsqlite3PExpr(tls, pParse, TK_ROW, uintptr(0), uintptr(0))
	if pRet != 0 {
		(*Expr)(unsafe.Pointer(pRet)).FiColumn = YnVar(iCol + 1)
	}
	return pRet
}

func updateFromSelect(tls *libc.TLS, pParse uintptr, iEph int32, pPk uintptr, pChanges uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var i int32

	var pSelect uintptr = uintptr(0)
	var pList uintptr = uintptr(0)
	var pGrp uintptr = uintptr(0)
	var pLimit2 uintptr = uintptr(0)
	var pOrderBy2 uintptr = uintptr(0)
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pTab uintptr = (*SrcItem)(unsafe.Pointer(pTabList + 8)).FpTab
	var pSrc uintptr
	var pWhere2 uintptr
	var eDest int32

	_ = pOrderBy
	_ = pLimit

	pSrc = Xsqlite3SrcListDup(tls, db, pTabList, 0)
	pWhere2 = Xsqlite3ExprDup(tls, db, pWhere, 0)

	if pSrc != 0 {
		libc.SetBitFieldPtr16Uint32(pSrc+8+60+4, uint32(1), 9, 0x200)
		(*SrcItem)(unsafe.Pointer(pSrc + 8)).FiCursor = -1
		(*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pSrc+8)).FpTab)).FnTabRef--
		(*SrcItem)(unsafe.Pointer(pSrc + 8)).FpTab = uintptr(0)
	}
	if pPk != 0 {
		for i = 0; i < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol); i++ {
			var pNew uintptr = exprRowColumn(tls, pParse, int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
			pList = Xsqlite3ExprListAppend(tls, pParse, pList, pNew)
		}
		if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
			eDest = SRT_Table
		} else {
			eDest = SRT_Upfrom
		}
	} else if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW {
		for i = 0; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
			pList = Xsqlite3ExprListAppend(tls, pParse, pList, exprRowColumn(tls, pParse, i))
		}
		eDest = SRT_Table
	} else {
		if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
			eDest = SRT_Table
		} else {
			eDest = SRT_Upfrom
		}
		pList = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), Xsqlite3PExpr(tls, pParse, TK_ROW, uintptr(0), uintptr(0)))
	}

	if pChanges != 0 {
		for i = 0; i < (*ExprList)(unsafe.Pointer(pChanges)).FnExpr; i++ {
			pList = Xsqlite3ExprListAppend(tls, pParse, pList,
				Xsqlite3ExprDup(tls, db, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(i)*32)).FpExpr, 0))
		}
	}
	pSelect = Xsqlite3SelectNew(tls, pParse, pList,
		pSrc, pWhere2, pGrp, uintptr(0), pOrderBy2,
		uint32(SF_UFSrcCheck|SF_IncludeHidden|SF_UpdateFrom), pLimit2)
	if pSelect != 0 {
		*(*U32)(unsafe.Pointer(pSelect + 4)) |= U32(SF_OrderByReqd)
	}
	Xsqlite3SelectDestInit(tls, bp, eDest, iEph)
	(*SelectDest)(unsafe.Pointer(bp)).FiSDParm2 = func() int32 {
		if pPk != 0 {
			return int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
		}
		return -1
	}()
	Xsqlite3Select(tls, pParse, pSelect, bp)
	Xsqlite3SelectDelete(tls, db, pSelect)
}

func Xsqlite3Update(tls *libc.TLS, pParse uintptr, pTabList uintptr, pChanges uintptr, pWhere uintptr, onError int32, pOrderBy uintptr, pLimit uintptr, pUpsert uintptr) {
	bp := tls.Alloc(108)
	defer tls.Free(108)

	var i int32
	var j int32
	var k int32
	var pTab uintptr
	var addrTop int32
	var pWInfo uintptr
	var v uintptr
	var pIdx uintptr
	var pPk uintptr
	var nIdx int32
	var nAllIdx int32
	var iBaseCur int32
	var iDataCur int32
	var iIdxCur int32
	var db uintptr
	var aRegIdx uintptr
	var aXRef uintptr

	var aToOpen uintptr
	var chngPk U8
	var chngRowid U8
	var chngKey U8
	var pRowidExpr uintptr
	var iRowidExpr int32

	var iDb int32
	var eOnePass int32
	var hasFK int32
	var labelBreak int32
	var labelContinue int32
	var flags int32

	var isView int32
	var pTrigger uintptr

	var newmask int32
	var iEph int32
	var nKey int32

	var addrOpen int32
	var iPk int32
	var nPk I16

	var bFinishSeek int32
	var nChangeFrom int32

	var regRowCount int32
	var regOldRowid int32
	var regNewRowid int32
	var regNew int32
	var regOld int32
	var regRowSet int32
	var regKey int32
	var rc int32
	var hCol U8
	var bProgress int32
	var reg int32
	var pKeyInfo uintptr
	var nEphCol int32
	var iCur int32
	var addrOnce int32
	var colFlags U32
	var oldmask U32
	var nOff int32
	addrTop = 0
	pWInfo = uintptr(0)
	aRegIdx = uintptr(0)
	aXRef = uintptr(0)
	pRowidExpr = uintptr(0)
	iRowidExpr = -1
	iEph = 0
	nKey = 0
	addrOpen = 0
	iPk = 0
	nPk = int16(0)
	*(*int32)(unsafe.Pointer(bp + 104)) = 0
	bFinishSeek = 1
	nChangeFrom = 0
	regRowCount = 0
	regOldRowid = 0
	regNewRowid = 0
	regNew = 0
	regOld = 0
	regRowSet = 0
	regKey = 0

	libc.Xmemset(tls, bp+16, 0, uint64(unsafe.Sizeof(AuthContext{})))
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __1
	}
	goto update_cleanup
__1:
	;
	pTab = Xsqlite3SrcListLookup(tls, pParse, pTabList)
	if !(pTab == uintptr(0)) {
		goto __2
	}
	goto update_cleanup
__2:
	;
	iDb = Xsqlite3SchemaToIndex(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Table)(unsafe.Pointer(pTab)).FpSchema)

	pTrigger = Xsqlite3TriggersExist(tls, pParse, pTab, TK_UPDATE, pChanges, bp+32)
	isView = libc.Bool32(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW)

	if (*SrcList)(unsafe.Pointer(pTabList)).FnSrc > 1 {
		nChangeFrom = (*ExprList)(unsafe.Pointer(pChanges)).FnExpr
	} else {
		nChangeFrom = 0
	}

	if !(Xsqlite3ViewGetColumnNames(tls, pParse, pTab) != 0) {
		goto __3
	}
	goto update_cleanup
__3:
	;
	if !(Xsqlite3IsReadOnly(tls, pParse, pTab, *(*int32)(unsafe.Pointer(bp + 32))) != 0) {
		goto __4
	}
	goto update_cleanup
__4:
	;
	iBaseCur = libc.AssignInt32(&iDataCur, libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1))
	iIdxCur = iDataCur + 1
	if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
		pPk = uintptr(0)
	} else {
		pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)
	}

	nIdx = 0
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__5:
	if !(pIdx != 0) {
		goto __7
	}
	if !(pPk == pIdx) {
		goto __8
	}
	iDataCur = (*Parse)(unsafe.Pointer(pParse)).FnTab
__8:
	;
	(*Parse)(unsafe.Pointer(pParse)).FnTab++
	goto __6
__6:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	nIdx++
	goto __5
	goto __7
__7:
	;
	if !(pUpsert != 0) {
		goto __9
	}

	iDataCur = (*Upsert)(unsafe.Pointer(pUpsert)).FiDataCur
	iIdxCur = (*Upsert)(unsafe.Pointer(pUpsert)).FiIdxCur
	(*Parse)(unsafe.Pointer(pParse)).FnTab = iBaseCur
__9:
	;
	(*SrcItem)(unsafe.Pointer(pTabList + 8)).FiCursor = iDataCur

	aXRef = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(int32(0)))*uint64(int32((*Table)(unsafe.Pointer(pTab)).FnCol)+nIdx+1)+uint64(nIdx)+uint64(2))
	if !(aXRef == uintptr(0)) {
		goto __10
	}
	goto update_cleanup
__10:
	;
	aRegIdx = aXRef + uintptr((*Table)(unsafe.Pointer(pTab)).FnCol)*4
	aToOpen = aRegIdx + uintptr(nIdx)*4 + uintptr(1)*4
	libc.Xmemset(tls, aToOpen, 1, uint64(nIdx+1))
	*(*U8)(unsafe.Pointer(aToOpen + uintptr(nIdx+1))) = U8(0)
	i = 0
__11:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __13
	}
	*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) = -1
	goto __12
__12:
	i++
	goto __11
	goto __13
__13:
	;
	libc.Xmemset(tls, bp+40, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp + 40)).FpParse = pParse
	(*NameContext)(unsafe.Pointer(bp + 40)).FpSrcList = pTabList
	*(*uintptr)(unsafe.Pointer(bp + 40 + 16)) = pUpsert
	(*NameContext)(unsafe.Pointer(bp + 40)).FncFlags = NC_UUpsert

	v = Xsqlite3GetVdbe(tls, pParse)
	if !(v == uintptr(0)) {
		goto __14
	}
	goto update_cleanup
__14:
	;
	chngRowid = libc.AssignUint8(&chngPk, U8(0))
	i = 0
__15:
	if !(i < (*ExprList)(unsafe.Pointer(pChanges)).FnExpr) {
		goto __17
	}
	hCol = Xsqlite3StrIHash(tls, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(i)*32)).FzEName)

	if !(nChangeFrom == 0 && Xsqlite3ResolveExprNames(tls, bp+40, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(i)*32)).FpExpr) != 0) {
		goto __18
	}
	goto update_cleanup
__18:
	;
	j = 0
__19:
	if !(j < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __21
	}
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FhName) == int32(hCol) &&
		Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FzCnName, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(i)*32)).FzEName) == 0) {
		goto __22
	}
	if !(j == int32((*Table)(unsafe.Pointer(pTab)).FiPKey)) {
		goto __23
	}
	chngRowid = U8(1)
	pRowidExpr = (*ExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32)).FpExpr
	iRowidExpr = i
	goto __24
__23:
	if !(pPk != 0 && int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FcolFlags)&COLFLAG_PRIMKEY != 0) {
		goto __25
	}
	chngPk = U8(1)
	goto __26
__25:
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FcolFlags)&COLFLAG_GENERATED != 0) {
		goto __27
	}

	Xsqlite3ErrorMsg(tls, pParse,
		ts+24791,
		libc.VaList(bp, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FzCnName))
	goto update_cleanup
__27:
	;
__26:
	;
__24:
	;
	*(*int32)(unsafe.Pointer(aXRef + uintptr(j)*4)) = i
	goto __21
__22:
	;
	goto __20
__20:
	j++
	goto __19
	goto __21
__21:
	;
	if !(j >= int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __28
	}
	if !(pPk == uintptr(0) && Xsqlite3IsRowid(tls, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(i)*32)).FzEName) != 0) {
		goto __29
	}
	j = -1
	chngRowid = U8(1)
	pRowidExpr = (*ExprList_item)(unsafe.Pointer(pChanges + 8 + uintptr(i)*32)).FpExpr
	iRowidExpr = i
	goto __30
__29:
	Xsqlite3ErrorMsg(tls, pParse, ts+24827, libc.VaList(bp+8, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(i)*32)).FzEName))
	(*Parse)(unsafe.Pointer(pParse)).FcheckSchema = U8(1)
	goto update_cleanup
__30:
	;
__28:
	;
	rc = Xsqlite3AuthCheck(tls, pParse, SQLITE_UPDATE, (*Table)(unsafe.Pointer(pTab)).FzName,
		func() uintptr {
			if j < 0 {
				return ts + 10928
			}
			return (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(j)*24)).FzCnName
		}(),
		(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName)
	if !(rc == SQLITE_DENY) {
		goto __31
	}
	goto update_cleanup
	goto __32
__31:
	if !(rc == SQLITE_IGNORE) {
		goto __33
	}
	*(*int32)(unsafe.Pointer(aXRef + uintptr(j)*4)) = -1
__33:
	;
__32:
	;
	goto __16
__16:
	i++
	goto __15
	goto __17
__17:
	;
	chngKey = U8(int32(chngRowid) + int32(chngPk))

	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated) != 0) {
		goto __34
	}

__35:
	bProgress = 0
	i = 0
__38:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __40
	}
	if !(*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) >= 0) {
		goto __41
	}
	goto __39
__41:
	;
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_GENERATED == 0) {
		goto __42
	}
	goto __39
__42:
	;
	if !(Xsqlite3ExprReferencesUpdatedColumn(tls,
		Xsqlite3ColumnExpr(tls, pTab, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24),
		aXRef, int32(chngRowid)) != 0) {
		goto __43
	}
	*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) = 99999
	bProgress = 1
__43:
	;
	goto __39
__39:
	i++
	goto __38
	goto __40
__40:
	;
	goto __36
__36:
	if bProgress != 0 {
		goto __35
	}
	goto __37
__37:
	;
__34:
	;
	(*SrcItem)(unsafe.Pointer(pTabList + 8)).FcolUsed = func() uint64 {
		if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
			return libc.Uint64(libc.Uint64FromInt32(-1))
		}
		return uint64(0)
	}()

	hasFK = Xsqlite3FkRequired(tls, pParse, pTab, aXRef, int32(chngKey))

	if !(onError == OE_Replace) {
		goto __44
	}
	*(*int32)(unsafe.Pointer(bp + 104)) = 1
__44:
	;
	nAllIdx = 0
	pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex
__45:
	if !(pIdx != 0) {
		goto __47
	}
	if !(chngKey != 0 || hasFK > 1 || pIdx == pPk ||
		indexWhereClauseMightChange(tls, pIdx, aXRef, int32(chngRowid)) != 0) {
		goto __48
	}
	reg = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
	goto __49
__48:
	reg = 0
	i = 0
__50:
	if !(i < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)) {
		goto __52
	}
	if !(indexColumnIsBeingUpdated(tls, pIdx, i, aXRef, int32(chngRowid)) != 0) {
		goto __53
	}
	reg = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
	if !(onError == OE_Default && int32((*Index)(unsafe.Pointer(pIdx)).FonError) == OE_Replace) {
		goto __54
	}
	*(*int32)(unsafe.Pointer(bp + 104)) = 1
__54:
	;
	goto __52
__53:
	;
	goto __51
__51:
	i++
	goto __50
	goto __52
__52:
	;
__49:
	;
	if !(reg == 0) {
		goto __55
	}
	*(*U8)(unsafe.Pointer(aToOpen + uintptr(nAllIdx+1))) = U8(0)
__55:
	;
	*(*int32)(unsafe.Pointer(aRegIdx + uintptr(nAllIdx)*4)) = reg
	goto __46
__46:
	pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext
	nAllIdx++
	goto __45
	goto __47
__47:
	;
	*(*int32)(unsafe.Pointer(aRegIdx + uintptr(nAllIdx)*4)) = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	if !(*(*int32)(unsafe.Pointer(bp + 104)) != 0) {
		goto __56
	}

	libc.Xmemset(tls, aToOpen, 1, uint64(nIdx+1))
__56:
	;
	if !(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0) {
		goto __57
	}
	Xsqlite3VdbeCountChanges(tls, v)
__57:
	;
	Xsqlite3BeginWriteOperation(tls, pParse, libc.Bool32(pTrigger != 0 || hasFK != 0), iDb)

	if !!(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __58
	}

	regRowSet = *(*int32)(unsafe.Pointer(aRegIdx + uintptr(nAllIdx)*4))
	regOldRowid = libc.AssignInt32(&regNewRowid, libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1))
	if !(chngPk != 0 || pTrigger != 0 || hasFK != 0) {
		goto __59
	}
	regOld = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32((*Table)(unsafe.Pointer(pTab)).FnCol)
__59:
	;
	if !(chngKey != 0 || pTrigger != 0 || hasFK != 0) {
		goto __60
	}
	regNewRowid = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
__60:
	;
	regNew = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32((*Table)(unsafe.Pointer(pTab)).FnCol)
__58:
	;
	if !(isView != 0) {
		goto __61
	}
	Xsqlite3AuthContextPush(tls, pParse, bp+16, (*Table)(unsafe.Pointer(pTab)).FzName)
__61:
	;
	if !(nChangeFrom == 0 && isView != 0) {
		goto __62
	}
	Xsqlite3MaterializeView(tls, pParse, pTab,
		pWhere, pOrderBy, pLimit, iDataCur)
	pOrderBy = uintptr(0)
	pLimit = uintptr(0)
__62:
	;
	if !(nChangeFrom == 0 && Xsqlite3ResolveExprNames(tls, bp+40, pWhere) != 0) {
		goto __63
	}
	goto update_cleanup
__63:
	;
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __64
	}
	updateVirtualTable(tls, pParse, pTabList, pTab, pChanges, pRowidExpr, aXRef,
		pWhere, onError)
	goto update_cleanup
__64:
	;
	labelContinue = libc.AssignInt32(&labelBreak, Xsqlite3VdbeMakeLabel(tls, pParse))

	if !((*Sqlite3)(unsafe.Pointer(db)).Fflags&(uint64(0x00001)<<32) != uint64(0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FpTriggerTab) != 0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) != 0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FbReturning) != 0) &&
		pUpsert == uintptr(0)) {
		goto __65
	}
	regRowCount = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regRowCount)
__65:
	;
	if !(nChangeFrom == 0 && (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __66
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Null, 0, regRowSet, regOldRowid)
	iEph = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	addrOpen = Xsqlite3VdbeAddOp3(tls, v, OP_OpenEphemeral, iEph, 0, regRowSet)
	goto __67
__66:
	;
	if pPk != 0 {
		nPk = int16((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
	} else {
		nPk = int16(0)
	}
	iPk = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += int32(nPk)
	*(*int32)(unsafe.Pointer(pParse + 56)) += nChangeFrom
	regKey = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	if !(pUpsert == uintptr(0)) {
		goto __68
	}
	nEphCol = int32(nPk) + nChangeFrom + func() int32 {
		if isView != 0 {
			return int32((*Table)(unsafe.Pointer(pTab)).FnCol)
		}
		return 0
	}()
	iEph = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	if !(pPk != 0) {
		goto __69
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Null, 0, iPk, iPk+int32(nPk)-1)
__69:
	;
	addrOpen = Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, iEph, nEphCol)
	if !(pPk != 0) {
		goto __70
	}
	pKeyInfo = Xsqlite3KeyInfoOfIndex(tls, pParse, pPk)
	if !(pKeyInfo != 0) {
		goto __71
	}
	(*KeyInfo)(unsafe.Pointer(pKeyInfo)).FnAllField = U16(nEphCol)
	Xsqlite3VdbeAppendP4(tls, v, pKeyInfo, -8)
__71:
	;
__70:
	;
	if !(nChangeFrom != 0) {
		goto __72
	}
	updateFromSelect(tls,
		pParse, iEph, pPk, pChanges, pTabList, pWhere, pOrderBy, pLimit)
	if !(isView != 0) {
		goto __73
	}
	iDataCur = iEph
__73:
	;
__72:
	;
__68:
	;
__67:
	;
	if !(nChangeFrom != 0) {
		goto __74
	}
	Xsqlite3MultiWrite(tls, pParse)
	eOnePass = ONEPASS_OFF
	nKey = int32(nPk)
	regKey = iPk
	goto __75
__74:
	if !(pUpsert != 0) {
		goto __76
	}

	pWInfo = uintptr(0)
	eOnePass = ONEPASS_SINGLE
	Xsqlite3ExprIfFalse(tls, pParse, pWhere, labelBreak, SQLITE_JUMPIFNULL)
	bFinishSeek = 0
	goto __77
__76:
	flags = WHERE_ONEPASS_DESIRED
	if !(!(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) != 0) &&
		!(pTrigger != 0) &&
		!(hasFK != 0) &&
		!(chngKey != 0) &&
		!(*(*int32)(unsafe.Pointer(bp + 104)) != 0) &&
		(*NameContext)(unsafe.Pointer(bp+40)).FncFlags&NC_Subquery == 0) {
		goto __78
	}
	flags = flags | WHERE_ONEPASS_MULTIROW
__78:
	;
	pWInfo = Xsqlite3WhereBegin(tls, pParse, pTabList, pWhere, uintptr(0), uintptr(0), uintptr(0), uint16(flags), iIdxCur)
	if !(pWInfo == uintptr(0)) {
		goto __79
	}
	goto update_cleanup
__79:
	;
	eOnePass = Xsqlite3WhereOkOnePass(tls, pWInfo, bp+96)
	bFinishSeek = Xsqlite3WhereUsesDeferredSeek(tls, pWInfo)
	if !(eOnePass != ONEPASS_SINGLE) {
		goto __80
	}
	Xsqlite3MultiWrite(tls, pParse)
	if !(eOnePass == ONEPASS_MULTI) {
		goto __81
	}
	iCur = *(*int32)(unsafe.Pointer(bp + 96 + 1*4))
	if !(iCur >= 0 && iCur != iDataCur && *(*U8)(unsafe.Pointer(aToOpen + uintptr(iCur-iBaseCur))) != 0) {
		goto __82
	}
	eOnePass = ONEPASS_OFF
__82:
	;
__81:
	;
__80:
	;
__77:
	;
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __83
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iDataCur, regOldRowid)
	if !(eOnePass == ONEPASS_OFF) {
		goto __85
	}
	*(*int32)(unsafe.Pointer(aRegIdx + uintptr(nAllIdx)*4)) = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp3(tls, v, OP_Insert, iEph, regRowSet, regOldRowid)
	goto __86
__85:
	if !(addrOpen != 0) {
		goto __87
	}
	Xsqlite3VdbeChangeToNoop(tls, v, addrOpen)
__87:
	;
__86:
	;
	goto __84
__83:
	i = 0
__88:
	if !(i < int32(nPk)) {
		goto __90
	}

	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur,
		int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))), iPk+i)
	goto __89
__89:
	i++
	goto __88
	goto __90
__90:
	;
	if !(eOnePass != 0) {
		goto __91
	}
	if !(addrOpen != 0) {
		goto __93
	}
	Xsqlite3VdbeChangeToNoop(tls, v, addrOpen)
__93:
	;
	nKey = int32(nPk)
	regKey = iPk
	goto __92
__91:
	Xsqlite3VdbeAddOp4(tls, v, OP_MakeRecord, iPk, int32(nPk), regKey,
		Xsqlite3IndexAffinityStr(tls, db, pPk), int32(nPk))
	Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, iEph, regKey, iPk, int32(nPk))
__92:
	;
__84:
	;
__75:
	;
	if !(pUpsert == uintptr(0)) {
		goto __94
	}
	if !(nChangeFrom == 0 && eOnePass != ONEPASS_MULTI) {
		goto __95
	}
	Xsqlite3WhereEnd(tls, pWInfo)
__95:
	;
	if !!(isView != 0) {
		goto __96
	}
	addrOnce = 0

	if !(eOnePass != ONEPASS_OFF) {
		goto __97
	}
	if !(*(*int32)(unsafe.Pointer(bp + 96)) >= 0) {
		goto __98
	}
	*(*U8)(unsafe.Pointer(aToOpen + uintptr(*(*int32)(unsafe.Pointer(bp + 96))-iBaseCur))) = U8(0)
__98:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 96 + 1*4)) >= 0) {
		goto __99
	}
	*(*U8)(unsafe.Pointer(aToOpen + uintptr(*(*int32)(unsafe.Pointer(bp + 96 + 1*4))-iBaseCur))) = U8(0)
__99:
	;
__97:
	;
	if !(eOnePass == ONEPASS_MULTI && nIdx-libc.Bool32(*(*int32)(unsafe.Pointer(bp + 96 + 1*4)) >= 0) > 0) {
		goto __100
	}
	addrOnce = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
__100:
	;
	Xsqlite3OpenTableAndIndices(tls, pParse, pTab, OP_OpenWrite, uint8(0), iBaseCur,
		aToOpen, uintptr(0), uintptr(0))
	if !(addrOnce != 0) {
		goto __101
	}
	Xsqlite3VdbeJumpHereOrPopInst(tls, v, addrOnce)
__101:
	;
__96:
	;
	if !(eOnePass != ONEPASS_OFF) {
		goto __102
	}
	if !(*(*int32)(unsafe.Pointer(bp + 96)) != iDataCur &&
		*(*int32)(unsafe.Pointer(bp + 96 + 1*4)) != iDataCur) {
		goto __104
	}

	Xsqlite3VdbeAddOp4Int(tls, v, OP_NotFound, iDataCur, labelBreak, regKey, nKey)

__104:
	;
	if !(eOnePass != ONEPASS_SINGLE) {
		goto __105
	}
	labelContinue = Xsqlite3VdbeMakeLabel(tls, pParse)
__105:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, func() int32 {
		if pPk != 0 {
			return regKey
		}
		return regOldRowid
	}(), labelBreak)

	goto __103
__102:
	if !(pPk != 0 || nChangeFrom != 0) {
		goto __106
	}
	labelContinue = Xsqlite3VdbeMakeLabel(tls, pParse)
	Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, iEph, labelBreak)
	addrTop = Xsqlite3VdbeCurrentAddr(tls, v)
	if !(nChangeFrom != 0) {
		goto __108
	}
	if !!(isView != 0) {
		goto __110
	}
	if !(pPk != 0) {
		goto __111
	}
	i = 0
__113:
	if !(i < int32(nPk)) {
		goto __115
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, iEph, i, iPk+i)
	goto __114
__114:
	i++
	goto __113
	goto __115
__115:
	;
	Xsqlite3VdbeAddOp4Int(tls,
		v, OP_NotFound, iDataCur, labelContinue, iPk, int32(nPk))
	goto __112
__111:
	Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iEph, regOldRowid)
	Xsqlite3VdbeAddOp3(tls,
		v, OP_NotExists, iDataCur, labelContinue, regOldRowid)
__112:
	;
__110:
	;
	goto __109
__108:
	Xsqlite3VdbeAddOp2(tls, v, OP_RowData, iEph, regKey)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_NotFound, iDataCur, labelContinue, regKey, 0)

__109:
	;
	goto __107
__106:
	Xsqlite3VdbeAddOp2(tls, v, OP_Rewind, iEph, labelBreak)
	labelContinue = Xsqlite3VdbeMakeLabel(tls, pParse)
	addrTop = Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iEph, regOldRowid)

	Xsqlite3VdbeAddOp3(tls, v, OP_NotExists, iDataCur, labelContinue, regOldRowid)

__107:
	;
__103:
	;
__94:
	;
	if !(chngRowid != 0) {
		goto __116
	}

	if !(nChangeFrom == 0) {
		goto __117
	}
	Xsqlite3ExprCode(tls, pParse, pRowidExpr, regNewRowid)
	goto __118
__117:
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, iEph, iRowidExpr, regNewRowid)
__118:
	;
	Xsqlite3VdbeAddOp1(tls, v, OP_MustBeInt, regNewRowid)
__116:
	;
	if !(chngPk != 0 || hasFK != 0 || pTrigger != 0) {
		goto __119
	}
	oldmask = func() uint32 {
		if hasFK != 0 {
			return Xsqlite3FkOldmask(tls, pParse, pTab)
		}
		return uint32(0)
	}()
	oldmask = oldmask | Xsqlite3TriggerColmask(tls, pParse,
		pTrigger, pChanges, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onError)
	i = 0
__120:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __122
	}
	colFlags = U32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(i)*24)).FcolFlags)
	k = int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(i))) + regOld
	if !(oldmask == 0xffffffff ||
		i < 32 && oldmask&(uint32(1)<<i) != U32(0) ||
		colFlags&U32(COLFLAG_PRIMKEY) != U32(0)) {
		goto __123
	}

	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
	goto __124
__123:
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, k)
__124:
	;
	goto __121
__121:
	i++
	goto __120
	goto __122
__122:
	;
	if !(int32(chngRowid) == 0 && pPk == uintptr(0)) {
		goto __125
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Copy, regOldRowid, regNewRowid)
__125:
	;
__119:
	;
	newmask = int32(Xsqlite3TriggerColmask(tls,
		pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError))
	i = 0
	k = regNew
__126:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __128
	}
	if !(i == int32((*Table)(unsafe.Pointer(pTab)).FiPKey)) {
		goto __129
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, k)
	goto __130
__129:
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_GENERATED != 0) {
		goto __131
	}
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL != 0) {
		goto __133
	}
	k--
__133:
	;
	goto __132
__131:
	j = *(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4))
	if !(j >= 0) {
		goto __134
	}
	if !(nChangeFrom != 0) {
		goto __136
	}
	nOff = func() int32 {
		if isView != 0 {
			return int32((*Table)(unsafe.Pointer(pTab)).FnCol)
		}
		return int32(nPk)
	}()

	Xsqlite3VdbeAddOp3(tls, v, OP_Column, iEph, nOff+j, k)
	goto __137
__136:
	Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(j)*32)).FpExpr, k)
__137:
	;
	goto __135
__134:
	if !(0 == *(*int32)(unsafe.Pointer(bp + 32))&TRIGGER_BEFORE || i > 31 || uint32(newmask)&(uint32(1)<<i) != 0) {
		goto __138
	}

	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
	bFinishSeek = 0
	goto __139
__138:
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, k)
__139:
	;
__135:
	;
__132:
	;
__130:
	;
	goto __127
__127:
	i++
	k++
	goto __126
	goto __128
__128:
	;
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated) != 0) {
		goto __140
	}

	Xsqlite3ComputeGeneratedColumns(tls, pParse, regNew, pTab)
__140:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 32))&TRIGGER_BEFORE != 0) {
		goto __141
	}
	Xsqlite3TableAffinity(tls, v, pTab, regNew)
	Xsqlite3CodeRowTrigger(tls, pParse, pTrigger, TK_UPDATE, pChanges,
		TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue)

	if !!(isView != 0) {
		goto __142
	}

	if !(pPk != 0) {
		goto __143
	}
	Xsqlite3VdbeAddOp4Int(tls, v, OP_NotFound, iDataCur, labelContinue, regKey, nKey)

	goto __144
__143:
	Xsqlite3VdbeAddOp3(tls, v, OP_NotExists, iDataCur, labelContinue, regOldRowid)

__144:
	;
	i = 0
	k = regNew
__145:
	if !(i < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __147
	}
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_GENERATED != 0) {
		goto __148
	}
	if !(int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).FcolFlags)&COLFLAG_VIRTUAL != 0) {
		goto __150
	}
	k--
__150:
	;
	goto __149
__148:
	if !(*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) < 0 && i != int32((*Table)(unsafe.Pointer(pTab)).FiPKey)) {
		goto __151
	}
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iDataCur, i, k)
__151:
	;
__149:
	;
	goto __146
__146:
	i++
	k++
	goto __145
	goto __147
__147:
	;
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated) != 0) {
		goto __152
	}

	Xsqlite3ComputeGeneratedColumns(tls, pParse, regNew, pTab)
__152:
	;
__142:
	;
__141:
	;
	if !!(isView != 0) {
		goto __153
	}

	Xsqlite3GenerateConstraintChecks(tls, pParse, pTab, aRegIdx, iDataCur, iIdxCur,
		regNewRowid, regOldRowid, chngKey, uint8(onError), labelContinue, bp+104,
		aXRef, uintptr(0))

	if !(*(*int32)(unsafe.Pointer(bp + 104)) != 0 || chngKey != 0) {
		goto __154
	}
	if !(pPk != 0) {
		goto __155
	}
	Xsqlite3VdbeAddOp4Int(tls, v, OP_NotFound, iDataCur, labelContinue, regKey, nKey)
	goto __156
__155:
	Xsqlite3VdbeAddOp3(tls, v, OP_NotExists, iDataCur, labelContinue, regOldRowid)
__156:
	;
__154:
	;
	if !(hasFK != 0) {
		goto __157
	}
	Xsqlite3FkCheck(tls, pParse, pTab, regOldRowid, 0, aXRef, int32(chngKey))
__157:
	;
	Xsqlite3GenerateRowIndexDelete(tls, pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1)

	if !(bFinishSeek != 0) {
		goto __158
	}
	Xsqlite3VdbeAddOp1(tls, v, OP_FinishSeek, iDataCur)
__158:
	;
	Xsqlite3VdbeAddOp3(tls, v, OP_Delete, iDataCur,
		OPFLAG_ISUPDATE|func() int32 {
			if hasFK > 1 || chngKey != 0 {
				return 0
			}
			return OPFLAG_ISNOOP
		}(),
		regNewRowid)
	if !(eOnePass == ONEPASS_MULTI) {
		goto __159
	}

	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SAVEPOSITION))
__159:
	;
	if !!(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) != 0) {
		goto __160
	}
	Xsqlite3VdbeAppendP4(tls, v, pTab, -5)
__160:
	;
	if !(hasFK != 0) {
		goto __161
	}
	Xsqlite3FkCheck(tls, pParse, pTab, 0, regNewRowid, aXRef, int32(chngKey))
__161:
	;
	Xsqlite3CompleteInsertion(tls,
		pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx,
		OPFLAG_ISUPDATE|func() int32 {
			if eOnePass == ONEPASS_MULTI {
				return OPFLAG_SAVEPOSITION
			}
			return 0
		}(),
		0, 0)

	if !(hasFK != 0) {
		goto __162
	}
	Xsqlite3FkActions(tls, pParse, pTab, pChanges, regOldRowid, aXRef, int32(chngKey))
__162:
	;
__153:
	;
	if !(regRowCount != 0) {
		goto __163
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, regRowCount, 1)
__163:
	;
	Xsqlite3CodeRowTrigger(tls, pParse, pTrigger, TK_UPDATE, pChanges,
		TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue)

	if !(eOnePass == ONEPASS_SINGLE) {
		goto __164
	}

	goto __165
__164:
	if !(eOnePass == ONEPASS_MULTI) {
		goto __166
	}
	Xsqlite3VdbeResolveLabel(tls, v, labelContinue)
	Xsqlite3WhereEnd(tls, pWInfo)
	goto __167
__166:
	Xsqlite3VdbeResolveLabel(tls, v, labelContinue)
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, iEph, addrTop)
__167:
	;
__165:
	;
	Xsqlite3VdbeResolveLabel(tls, v, labelBreak)

	if !(int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0 && (*Parse)(unsafe.Pointer(pParse)).FpTriggerTab == uintptr(0) && pUpsert == uintptr(0)) {
		goto __168
	}
	Xsqlite3AutoincrementEnd(tls, pParse)
__168:
	;
	if !(regRowCount != 0) {
		goto __169
	}
	Xsqlite3CodeChangeCount(tls, v, regRowCount, ts+24846)
__169:
	;
update_cleanup:
	Xsqlite3AuthContextPop(tls, bp+16)
	Xsqlite3DbFree(tls, db, aXRef)
	Xsqlite3SrcListDelete(tls, db, pTabList)
	Xsqlite3ExprListDelete(tls, db, pChanges)
	Xsqlite3ExprDelete(tls, db, pWhere)
	return
}

func updateVirtualTable(tls *libc.TLS, pParse uintptr, pSrc uintptr, pTab uintptr, pChanges uintptr, pRowid uintptr, aXRef uintptr, pWhere uintptr, onError int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var ephemTab int32
	var i int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pVTab uintptr = Xsqlite3GetVTable(tls, db, pTab)
	var pWInfo uintptr = uintptr(0)
	var nArg int32 = 2 + int32((*Table)(unsafe.Pointer(pTab)).FnCol)
	var regArg int32
	var regRec int32
	var regRowid int32
	var iCsr int32 = (*SrcItem)(unsafe.Pointer(pSrc + 8)).FiCursor

	var eOnePass int32
	var addr int32

	ephemTab = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	addr = Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, ephemTab, nArg)
	regArg = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += nArg
	if (*SrcList)(unsafe.Pointer(pSrc)).FnSrc > 1 {
		var pPk uintptr = uintptr(0)
		var pRow uintptr
		var pList uintptr
		if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
			if pRowid != 0 {
				pRow = Xsqlite3ExprDup(tls, db, pRowid, 0)
			} else {
				pRow = Xsqlite3PExpr(tls, pParse, TK_ROW, uintptr(0), uintptr(0))
			}
		} else {
			var iPk I16
			pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)

			iPk = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn))
			if *(*int32)(unsafe.Pointer(aXRef + uintptr(iPk)*4)) >= 0 {
				pRow = Xsqlite3ExprDup(tls, db, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(*(*int32)(unsafe.Pointer(aXRef + uintptr(iPk)*4)))*32)).FpExpr, 0)
			} else {
				pRow = exprRowColumn(tls, pParse, int32(iPk))
			}
		}
		pList = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), pRow)

		for i = 0; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
			if *(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) >= 0 {
				pList = Xsqlite3ExprListAppend(tls, pParse, pList,
					Xsqlite3ExprDup(tls, db, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)))*32)).FpExpr, 0))
			} else {
				pList = Xsqlite3ExprListAppend(tls, pParse, pList, exprRowColumn(tls, pParse, i))
			}
		}

		updateFromSelect(tls, pParse, ephemTab, pPk, pList, pSrc, pWhere, uintptr(0), uintptr(0))
		Xsqlite3ExprListDelete(tls, db, pList)
		eOnePass = ONEPASS_OFF
	} else {
		regRec = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		regRowid = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)

		pWInfo = Xsqlite3WhereBegin(tls,
			pParse, pSrc, pWhere, uintptr(0), uintptr(0), uintptr(0), uint16(WHERE_ONEPASS_DESIRED), 0)
		if pWInfo == uintptr(0) {
			return
		}

		for i = 0; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
			if *(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)) >= 0 {
				Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pChanges+8+uintptr(*(*int32)(unsafe.Pointer(aXRef + uintptr(i)*4)))*32)).FpExpr, regArg+2+i)
			} else {
				Xsqlite3VdbeAddOp3(tls, v, OP_VColumn, iCsr, i, regArg+2+i)
				Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_NOCHNG))
			}
		}
		if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
			Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iCsr, regArg)
			if pRowid != 0 {
				Xsqlite3ExprCode(tls, pParse, pRowid, regArg+1)
			} else {
				Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iCsr, regArg+1)
			}
		} else {
			var pPk uintptr
			var iPk I16
			pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)

			iPk = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn))
			Xsqlite3VdbeAddOp3(tls, v, OP_VColumn, iCsr, int32(iPk), regArg)
			Xsqlite3VdbeAddOp2(tls, v, OP_SCopy, regArg+2+int32(iPk), regArg+1)
		}

		eOnePass = Xsqlite3WhereOkOnePass(tls, pWInfo, bp)

		if eOnePass != 0 {
			Xsqlite3VdbeChangeToNoop(tls, v, addr)
			Xsqlite3VdbeAddOp1(tls, v, OP_Close, iCsr)
		} else {
			Xsqlite3MultiWrite(tls, pParse)
			Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regArg, nArg, regRec)
			Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, ephemTab, regRowid)
			Xsqlite3VdbeAddOp3(tls, v, OP_Insert, ephemTab, regRec, regRowid)
		}
	}

	if eOnePass == ONEPASS_OFF {
		if (*SrcList)(unsafe.Pointer(pSrc)).FnSrc == 1 {
			Xsqlite3WhereEnd(tls, pWInfo)
		}

		addr = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, ephemTab)

		for i = 0; i < nArg; i++ {
			Xsqlite3VdbeAddOp3(tls, v, OP_Column, ephemTab, i, regArg+i)
		}
	}
	Xsqlite3VtabMakeWritable(tls, pParse, pTab)
	Xsqlite3VdbeAddOp4(tls, v, OP_VUpdate, 0, nArg, regArg, pVTab, -11)
	Xsqlite3VdbeChangeP5(tls, v, func() uint16 {
		if onError == OE_Default {
			return uint16(OE_Abort)
		}
		return uint16(onError)
	}())
	Xsqlite3MayAbort(tls, pParse)

	if eOnePass == ONEPASS_OFF {
		Xsqlite3VdbeAddOp2(tls, v, OP_Next, ephemTab, addr+1)
		Xsqlite3VdbeJumpHere(tls, v, addr)
		Xsqlite3VdbeAddOp2(tls, v, OP_Close, ephemTab, 0)
	} else {
		Xsqlite3WhereEnd(tls, pWInfo)
	}
}

func upsertDelete(tls *libc.TLS, db uintptr, p uintptr) {
	for __ccgo := true; __ccgo; __ccgo = p != 0 {
		var pNext uintptr = (*Upsert)(unsafe.Pointer(p)).FpNextUpsert
		Xsqlite3ExprListDelete(tls, db, (*Upsert)(unsafe.Pointer(p)).FpUpsertTarget)
		Xsqlite3ExprDelete(tls, db, (*Upsert)(unsafe.Pointer(p)).FpUpsertTargetWhere)
		Xsqlite3ExprListDelete(tls, db, (*Upsert)(unsafe.Pointer(p)).FpUpsertSet)
		Xsqlite3ExprDelete(tls, db, (*Upsert)(unsafe.Pointer(p)).FpUpsertWhere)
		Xsqlite3DbFree(tls, db, (*Upsert)(unsafe.Pointer(p)).FpToFree)
		Xsqlite3DbFree(tls, db, p)
		p = pNext
	}
}

func Xsqlite3UpsertDelete(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		upsertDelete(tls, db, p)
	}
}

func Xsqlite3UpsertDup(tls *libc.TLS, db uintptr, p uintptr) uintptr {
	if p == uintptr(0) {
		return uintptr(0)
	}
	return Xsqlite3UpsertNew(tls, db,
		Xsqlite3ExprListDup(tls, db, (*Upsert)(unsafe.Pointer(p)).FpUpsertTarget, 0),
		Xsqlite3ExprDup(tls, db, (*Upsert)(unsafe.Pointer(p)).FpUpsertTargetWhere, 0),
		Xsqlite3ExprListDup(tls, db, (*Upsert)(unsafe.Pointer(p)).FpUpsertSet, 0),
		Xsqlite3ExprDup(tls, db, (*Upsert)(unsafe.Pointer(p)).FpUpsertWhere, 0),
		Xsqlite3UpsertDup(tls, db, (*Upsert)(unsafe.Pointer(p)).FpNextUpsert))
}

func Xsqlite3UpsertNew(tls *libc.TLS, db uintptr, pTarget uintptr, pTargetWhere uintptr, pSet uintptr, pWhere uintptr, pNext uintptr) uintptr {
	var pNew uintptr
	pNew = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Upsert{})))
	if pNew == uintptr(0) {
		Xsqlite3ExprListDelete(tls, db, pTarget)
		Xsqlite3ExprDelete(tls, db, pTargetWhere)
		Xsqlite3ExprListDelete(tls, db, pSet)
		Xsqlite3ExprDelete(tls, db, pWhere)
		Xsqlite3UpsertDelete(tls, db, pNext)
		return uintptr(0)
	} else {
		(*Upsert)(unsafe.Pointer(pNew)).FpUpsertTarget = pTarget
		(*Upsert)(unsafe.Pointer(pNew)).FpUpsertTargetWhere = pTargetWhere
		(*Upsert)(unsafe.Pointer(pNew)).FpUpsertSet = pSet
		(*Upsert)(unsafe.Pointer(pNew)).FpUpsertWhere = pWhere
		(*Upsert)(unsafe.Pointer(pNew)).FisDoUpdate = U8(libc.Bool32(pSet != uintptr(0)))
		(*Upsert)(unsafe.Pointer(pNew)).FpNextUpsert = pNext
	}
	return pNew
}

func Xsqlite3UpsertAnalyzeTarget(tls *libc.TLS, pParse uintptr, pTabList uintptr, pUpsert uintptr) int32 {
	bp := tls.Alloc(232)
	defer tls.Free(232)

	var pTab uintptr
	var rc int32
	var iCursor int32
	var pIdx uintptr
	var pTarget uintptr
	var pTerm uintptr

	var nClause int32 = 0

	libc.Xmemset(tls, bp+16, 0, uint64(unsafe.Sizeof(NameContext{})))
	(*NameContext)(unsafe.Pointer(bp + 16)).FpParse = pParse
	(*NameContext)(unsafe.Pointer(bp + 16)).FpSrcList = pTabList
__1:
	if !(pUpsert != 0 && (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget != 0) {
		goto __3
	}
	{
		rc = Xsqlite3ResolveExprListNames(tls, bp+16, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
		if rc != 0 {
			return rc
		}
		rc = Xsqlite3ResolveExprNames(tls, bp+16, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
		if rc != 0 {
			return rc
		}

		pTab = (*SrcItem)(unsafe.Pointer(pTabList + 8)).FpTab
		pTarget = (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget
		iCursor = (*SrcItem)(unsafe.Pointer(pTabList + 8)).FiCursor
		if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) &&
			(*ExprList)(unsafe.Pointer(pTarget)).FnExpr == 1 &&
			int32((*Expr)(unsafe.Pointer(libc.AssignUintptr(&pTerm, (*ExprList_item)(unsafe.Pointer(pTarget+8)).FpExpr))).Fop) == TK_COLUMN &&
			int32((*Expr)(unsafe.Pointer(pTerm)).FiColumn) == -1 {
			goto __2
		}

		libc.Xmemset(tls, bp+72, 0, uint64(unsafe.Sizeof([2]Expr{})))
		(*Expr)(unsafe.Pointer(bp + 72)).Fop = U8(TK_COLLATE)
		(*Expr)(unsafe.Pointer(bp + 72)).FpLeft = bp + 72 + 1*72
		(*Expr)(unsafe.Pointer(bp + 72 + 1*72)).Fop = U8(TK_COLUMN)
		(*Expr)(unsafe.Pointer(bp + 72 + 1*72)).FiTable = (*SrcItem)(unsafe.Pointer(pTabList + 8)).FiCursor

		for pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
			var ii int32
			var jj int32
			var nn int32
			if !(int32((*Index)(unsafe.Pointer(pIdx)).FonError) != OE_None) {
				continue
			}
			if (*ExprList)(unsafe.Pointer(pTarget)).FnExpr != int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) {
				continue
			}
			if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
				if (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere == uintptr(0) {
					continue
				}
				if Xsqlite3ExprCompare(tls, pParse, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere,
					(*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere, iCursor) != 0 {
					continue
				}
			}
			nn = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
			for ii = 0; ii < nn; ii++ {
				var pExpr uintptr
				*(*uintptr)(unsafe.Pointer(bp + 72 + 8)) = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(ii)*8))
				if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(ii)*2))) == -2 {
					pExpr = (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(ii)*32)).FpExpr
					if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_COLLATE {
						(*Expr)(unsafe.Pointer(bp + 72)).FpLeft = pExpr
						pExpr = bp + 72
					}
				} else {
					(*Expr)(unsafe.Pointer(bp + 72)).FpLeft = bp + 72 + 1*72
					(*Expr)(unsafe.Pointer(bp + 72 + 1*72)).FiColumn = *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(ii)*2))
					pExpr = bp + 72
				}
				for jj = 0; jj < nn; jj++ {
					if Xsqlite3ExprCompare(tls, pParse, (*ExprList_item)(unsafe.Pointer(pTarget+8+uintptr(jj)*32)).FpExpr, pExpr, iCursor) < 2 {
						break
					}
				}
				if jj >= nn {
					break
				}
			}
			if ii < nn {
				continue
			}
			(*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertIdx = pIdx
			break
		}
		if (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertIdx == uintptr(0) {
			if nClause == 0 && (*Upsert)(unsafe.Pointer(pUpsert)).FpNextUpsert == uintptr(0) {
				*(*uint8)(unsafe.Pointer(bp + 216)) = uint8(0)
			} else {
				Xsqlite3_snprintf(tls, int32(unsafe.Sizeof([16]uint8{})), bp+216, ts+24859, libc.VaList(bp, nClause+1))
			}
			Xsqlite3ErrorMsg(tls, pParse,
				ts+24863, libc.VaList(bp+8, bp+216))
			return SQLITE_ERROR
		}

	}
	goto __2
__2:
	pUpsert = (*Upsert)(unsafe.Pointer(pUpsert)).FpNextUpsert
	nClause++
	goto __1
	goto __3
__3:
	;
	return SQLITE_OK
}

func Xsqlite3UpsertNextIsIPK(tls *libc.TLS, pUpsert uintptr) int32 {
	var pNext uintptr
	if pUpsert == uintptr(0) {
		return 0
	}
	pNext = (*Upsert)(unsafe.Pointer(pUpsert)).FpNextUpsert
	if pNext == uintptr(0) {
		return 1
	}
	if (*Upsert)(unsafe.Pointer(pNext)).FpUpsertTarget == uintptr(0) {
		return 1
	}
	if (*Upsert)(unsafe.Pointer(pNext)).FpUpsertIdx == uintptr(0) {
		return 1
	}
	return 0
}

func Xsqlite3UpsertOfIndex(tls *libc.TLS, pUpsert uintptr, pIdx uintptr) uintptr {
	for pUpsert != 0 &&
		(*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget != uintptr(0) &&
		(*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertIdx != pIdx {
		pUpsert = (*Upsert)(unsafe.Pointer(pUpsert)).FpNextUpsert
	}
	return pUpsert
}

func Xsqlite3UpsertDoUpdate(tls *libc.TLS, pParse uintptr, pUpsert uintptr, pTab uintptr, pIdx uintptr, iCur int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pSrc uintptr
	var iDataCur int32
	var i int32
	var pTop uintptr = pUpsert

	iDataCur = (*Upsert)(unsafe.Pointer(pUpsert)).FiDataCur
	pUpsert = Xsqlite3UpsertOfIndex(tls, pTop, pIdx)
	Xsqlite3VdbeNoopComment(tls, v, ts+24936, 0)
	if pIdx != 0 && iCur != iDataCur {
		if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
			var regRowid int32 = Xsqlite3GetTempReg(tls, pParse)
			Xsqlite3VdbeAddOp2(tls, v, OP_IdxRowid, iCur, regRowid)
			Xsqlite3VdbeAddOp3(tls, v, OP_SeekRowid, iDataCur, 0, regRowid)

			Xsqlite3ReleaseTempReg(tls, pParse, regRowid)
		} else {
			var pPk uintptr = Xsqlite3PrimaryKeyIndex(tls, pTab)
			var nPk int32 = int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
			var iPk int32 = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
			*(*int32)(unsafe.Pointer(pParse + 56)) += nPk
			for i = 0; i < nPk; i++ {
				var k int32

				k = int32(Xsqlite3TableColumnToIndex(tls, pIdx, *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2))))
				Xsqlite3VdbeAddOp3(tls, v, OP_Column, iCur, k, iPk+i)
				Xsqlite3VdbeComment(tls, v, ts+11397, libc.VaList(bp, (*Index)(unsafe.Pointer(pIdx)).FzName, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(i)*2)))*24)).FzCnName))
			}

			i = Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, iDataCur, 0, iPk, nPk)

			Xsqlite3VdbeAddOp4(tls, v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0,
				ts+15578, -1)
			Xsqlite3MayAbort(tls, pParse)
			Xsqlite3VdbeJumpHere(tls, v, i)
		}
	}

	pSrc = Xsqlite3SrcListDup(tls, db, (*Upsert)(unsafe.Pointer(pTop)).FpUpsertSrc, 0)

	for i = 0; i < int32((*Table)(unsafe.Pointer(pTab)).FnCol); i++ {
		if int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(i)*24)).Faffinity) == SQLITE_AFF_REAL {
			Xsqlite3VdbeAddOp1(tls, v, OP_RealAffinity, (*Upsert)(unsafe.Pointer(pTop)).FregData+i)
		}
	}
	Xsqlite3Update(tls, pParse, pSrc, Xsqlite3ExprListDup(tls, db, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertSet, 0),
		Xsqlite3ExprDup(tls, db, (*Upsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere, 0), OE_Abort, uintptr(0), uintptr(0), pUpsert)
	Xsqlite3VdbeNoopComment(tls, v, ts+24962, 0)
}

func execSql(tls *libc.TLS, db uintptr, pzErrMsg uintptr, zSql uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	rc = Xsqlite3_prepare_v2(tls, db, zSql, -1, bp, uintptr(0))
	if rc != SQLITE_OK {
		return rc
	}
	for SQLITE_ROW == libc.AssignInt32(&rc, Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))) {
		var zSubSql uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)

		if zSubSql != 0 &&
			(libc.Xstrncmp(tls, zSubSql, ts+24986, uint64(3)) == 0 || libc.Xstrncmp(tls, zSubSql, ts+24990, uint64(3)) == 0) {
			rc = execSql(tls, db, pzErrMsg, zSubSql)
			if rc != SQLITE_OK {
				break
			}
		}
	}

	if rc == SQLITE_DONE {
		rc = SQLITE_OK
	}
	if rc != 0 {
		Xsqlite3SetString(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) int32 {
	var z uintptr
	var ap Va_list
	_ = ap
	var rc int32
	ap = va
	z = Xsqlite3VMPrintf(tls, db, zSql, ap)
	_ = ap
	if z == uintptr(0) {
		return SQLITE_NOMEM
	}
	rc = execSql(tls, db, pzErrMsg, z)
	Xsqlite3DbFree(tls, db, z)
	return rc
}

func Xsqlite3Vacuum(tls *libc.TLS, pParse uintptr, pNm uintptr, pInto uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = pNm

	var v uintptr
	var iDb int32
	var iIntoReg int32
	v = Xsqlite3GetVdbe(tls, pParse)
	iDb = 0
	if !(v == uintptr(0)) {
		goto __1
	}
	goto build_vacuum_end
__1:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __2
	}
	goto build_vacuum_end
__2:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp)) != 0) {
		goto __3
	}

	iDb = Xsqlite3TwoPartName(tls, pParse, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp)), bp)
	if !(iDb < 0) {
		goto __4
	}
	goto build_vacuum_end
__4:
	;
__3:
	;
	if !(iDb != 1) {
		goto __5
	}
	iIntoReg = 0
	if !(pInto != 0 && Xsqlite3ResolveSelfReference(tls, pParse, uintptr(0), 0, pInto, uintptr(0)) == 0) {
		goto __6
	}
	iIntoReg = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3ExprCode(tls, pParse, pInto, iIntoReg)
__6:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Vacuum, iDb, iIntoReg)
	Xsqlite3VdbeUsesBtree(tls, v, iDb)
__5:
	;
build_vacuum_end:
	Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pInto)
	return
}

func Xsqlite3RunVacuum(tls *libc.TLS, pzErrMsg uintptr, db uintptr, iDb int32, pOut uintptr) int32 {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var rc int32
	var pMain uintptr
	var pTemp uintptr
	var saved_mDbFlags U32
	var saved_flags U64
	var saved_nChange I64
	var saved_nTotalChange I64
	var saved_openFlags U32
	var saved_mTrace U8
	var pDb uintptr
	var isMemDb int32
	var nRes int32
	var nDb int32
	var zDbMain uintptr
	var zOut uintptr
	var pgflags U32
	var id uintptr

	var i int32
	rc = SQLITE_OK
	pDb = uintptr(0)
	pgflags = U32(PAGER_SYNCHRONOUS_OFF)

	if !!(int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit) != 0) {
		goto __1
	}
	Xsqlite3SetString(tls, pzErrMsg, db, ts+24994)
	return SQLITE_ERROR
__1:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive > 1) {
		goto __2
	}
	Xsqlite3SetString(tls, pzErrMsg, db, ts+25034)
	return SQLITE_ERROR
__2:
	;
	saved_openFlags = (*Sqlite3)(unsafe.Pointer(db)).FopenFlags
	if !(pOut != 0) {
		goto __3
	}
	if !(Xsqlite3_value_type(tls, pOut) != SQLITE_TEXT) {
		goto __5
	}
	Xsqlite3SetString(tls, pzErrMsg, db, ts+25077)
	return SQLITE_ERROR
__5:
	;
	zOut = Xsqlite3_value_text(tls, pOut)
	*(*uint32)(unsafe.Pointer(db + 76)) &= libc.Uint32FromInt32(libc.CplInt32(SQLITE_OPEN_READONLY))
	*(*uint32)(unsafe.Pointer(db + 76)) |= uint32(SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE)
	goto __4
__3:
	zOut = ts + 1636
__4:
	;
	saved_flags = (*Sqlite3)(unsafe.Pointer(db)).Fflags
	saved_mDbFlags = (*Sqlite3)(unsafe.Pointer(db)).FmDbFlags
	saved_nChange = (*Sqlite3)(unsafe.Pointer(db)).FnChange
	saved_nTotalChange = (*Sqlite3)(unsafe.Pointer(db)).FnTotalChange
	saved_mTrace = (*Sqlite3)(unsafe.Pointer(db)).FmTrace
	*(*U64)(unsafe.Pointer(db + 48)) |= uint64(SQLITE_WriteSchema | SQLITE_IgnoreChecks)
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_PreferBuiltin | DBFLAG_Vacuum)
	*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(SQLITE_ForeignKeys|SQLITE_ReverseOrder|
		SQLITE_Defensive) | uint64(0x00001)<<32)
	(*Sqlite3)(unsafe.Pointer(db)).FmTrace = U8(0)

	zDbMain = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName
	pMain = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpBt
	isMemDb = Xsqlite3PagerIsMemdb(tls, Xsqlite3BtreePager(tls, pMain))

	nDb = (*Sqlite3)(unsafe.Pointer(db)).FnDb
	rc = execSqlF(tls, db, pzErrMsg, ts+25095, libc.VaList(bp, zOut))
	(*Sqlite3)(unsafe.Pointer(db)).FopenFlags = saved_openFlags
	if !(rc != SQLITE_OK) {
		goto __6
	}
	goto end_of_vacuum
__6:
	;
	pDb = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(nDb)*32

	pTemp = (*Db)(unsafe.Pointer(pDb)).FpBt
	if !(pOut != 0) {
		goto __7
	}
	id = Xsqlite3PagerFile(tls, Xsqlite3BtreePager(tls, pTemp))
	*(*I64)(unsafe.Pointer(bp + 40)) = int64(0)
	if !((*Sqlite3_file)(unsafe.Pointer(id)).FpMethods != uintptr(0) && (Xsqlite3OsFileSize(tls, id, bp+40) != SQLITE_OK || *(*I64)(unsafe.Pointer(bp + 40)) > int64(0))) {
		goto __8
	}
	rc = SQLITE_ERROR
	Xsqlite3SetString(tls, pzErrMsg, db, ts+25118)
	goto end_of_vacuum
__8:
	;
	*(*U32)(unsafe.Pointer(db + 44)) |= U32(DBFLAG_VacuumInto)

	pgflags = U32(U64((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).Fsafety_level) | (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK))
__7:
	;
	nRes = Xsqlite3BtreeGetRequestedReserve(tls, pMain)

	Xsqlite3BtreeSetCacheSize(tls, pTemp, (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FpSchema)).Fcache_size)
	Xsqlite3BtreeSetSpillSize(tls, pTemp, Xsqlite3BtreeSetSpillSize(tls, pMain, 0))
	Xsqlite3BtreeSetPagerFlags(tls, pTemp, pgflags|U32(PAGER_CACHESPILL))

	rc = execSql(tls, db, pzErrMsg, ts+17925)
	if !(rc != SQLITE_OK) {
		goto __9
	}
	goto end_of_vacuum
__9:
	;
	rc = Xsqlite3BtreeBeginTrans(tls, pMain, func() int32 {
		if pOut == uintptr(0) {
			return 2
		}
		return 0
	}(), uintptr(0))
	if !(rc != SQLITE_OK) {
		goto __10
	}
	goto end_of_vacuum
__10:
	;
	if !(Xsqlite3PagerGetJournalMode(tls, Xsqlite3BtreePager(tls, pMain)) ==
		PAGER_JOURNALMODE_WAL &&
		pOut == uintptr(0)) {
		goto __11
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnextPagesize = 0
__11:
	;
	if !(Xsqlite3BtreeSetPageSize(tls, pTemp, Xsqlite3BtreeGetPageSize(tls, pMain), nRes, 0) != 0 ||
		!(isMemDb != 0) && Xsqlite3BtreeSetPageSize(tls, pTemp, (*Sqlite3)(unsafe.Pointer(db)).FnextPagesize, nRes, 0) != 0 ||
		(*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __12
	}
	rc = SQLITE_NOMEM
	goto end_of_vacuum
__12:
	;
	Xsqlite3BtreeSetAutoVacuum(tls, pTemp, func() int32 {
		if int32((*Sqlite3)(unsafe.Pointer(db)).FnextAutovac) >= 0 {
			return int32((*Sqlite3)(unsafe.Pointer(db)).FnextAutovac)
		}
		return Xsqlite3BtreeGetAutoVacuum(tls, pMain)
	}())

	(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = U8(nDb)
	rc = execSqlF(tls, db, pzErrMsg,
		ts+25145,
		libc.VaList(bp+8, zDbMain))
	if !(rc != SQLITE_OK) {
		goto __13
	}
	goto end_of_vacuum
__13:
	;
	rc = execSqlF(tls, db, pzErrMsg,
		ts+25253,
		libc.VaList(bp+16, zDbMain))
	if !(rc != SQLITE_OK) {
		goto __14
	}
	goto end_of_vacuum
__14:
	;
	(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = U8(0)

	rc = execSqlF(tls, db, pzErrMsg,
		ts+25307,
		libc.VaList(bp+24, zDbMain))

	*(*U32)(unsafe.Pointer(db + 44)) &= libc.Uint32FromInt32(libc.CplInt32(DBFLAG_Vacuum))
	if !(rc != SQLITE_OK) {
		goto __15
	}
	goto end_of_vacuum
__15:
	;
	rc = execSqlF(tls, db, pzErrMsg,
		ts+25458,
		libc.VaList(bp+32, zDbMain))
	if !(rc != 0) {
		goto __16
	}
	goto end_of_vacuum
__16:
	;
	i = 0
__17:
	if !(i < int32(uint64(unsafe.Sizeof(aCopy))/uint64(unsafe.Sizeof(uint8(0))))) {
		goto __19
	}

	Xsqlite3BtreeGetMeta(tls, pMain, int32(aCopy[i]), bp+48)
	rc = Xsqlite3BtreeUpdateMeta(tls, pTemp, int32(aCopy[i]), *(*U32)(unsafe.Pointer(bp + 48))+U32(aCopy[i+1]))
	if !(rc != SQLITE_OK) {
		goto __20
	}
	goto end_of_vacuum
__20:
	;
	goto __18
__18:
	i = i + 2
	goto __17
	goto __19
__19:
	;
	if !(pOut == uintptr(0)) {
		goto __21
	}
	rc = Xsqlite3BtreeCopyFile(tls, pMain, pTemp)
__21:
	;
	if !(rc != SQLITE_OK) {
		goto __22
	}
	goto end_of_vacuum
__22:
	;
	rc = Xsqlite3BtreeCommit(tls, pTemp)
	if !(rc != SQLITE_OK) {
		goto __23
	}
	goto end_of_vacuum
__23:
	;
	if !(pOut == uintptr(0)) {
		goto __24
	}
	Xsqlite3BtreeSetAutoVacuum(tls, pMain, Xsqlite3BtreeGetAutoVacuum(tls, pTemp))
__24:
	;
	if !(pOut == uintptr(0)) {
		goto __25
	}
	nRes = Xsqlite3BtreeGetRequestedReserve(tls, pTemp)
	rc = Xsqlite3BtreeSetPageSize(tls, pMain, Xsqlite3BtreeGetPageSize(tls, pTemp), nRes, 1)
__25:
	;
end_of_vacuum:
	(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = U8(0)
	(*Sqlite3)(unsafe.Pointer(db)).FmDbFlags = saved_mDbFlags
	(*Sqlite3)(unsafe.Pointer(db)).Fflags = saved_flags
	(*Sqlite3)(unsafe.Pointer(db)).FnChange = saved_nChange
	(*Sqlite3)(unsafe.Pointer(db)).FnTotalChange = saved_nTotalChange
	(*Sqlite3)(unsafe.Pointer(db)).FmTrace = saved_mTrace
	Xsqlite3BtreeSetPageSize(tls, pMain, -1, 0, 1)

	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(1)

	if !(pDb != 0) {
		goto __26
	}
	Xsqlite3BtreeClose(tls, (*Db)(unsafe.Pointer(pDb)).FpBt)
	(*Db)(unsafe.Pointer(pDb)).FpBt = uintptr(0)
	(*Db)(unsafe.Pointer(pDb)).FpSchema = uintptr(0)
__26:
	;
	Xsqlite3ResetAllSchemasOfConnection(tls, db)

	return rc
}

var aCopy = [10]uint8{
	uint8(BTREE_SCHEMA_VERSION), uint8(1),
	uint8(BTREE_DEFAULT_CACHE_SIZE), uint8(0),
	uint8(BTREE_TEXT_ENCODING), uint8(0),
	uint8(BTREE_USER_VERSION), uint8(0),
	uint8(BTREE_APPLICATION_ID), uint8(0),
}

func Xsqlite3VtabCreateModule(tls *libc.TLS, db uintptr, zName uintptr, pModule uintptr, pAux uintptr, xDestroy uintptr) uintptr {
	var pMod uintptr
	var pDel uintptr
	var zCopy uintptr
	if pModule == uintptr(0) {
		zCopy = zName
		pMod = uintptr(0)
	} else {
		var nName int32 = Xsqlite3Strlen30(tls, zName)
		pMod = Xsqlite3Malloc(tls, uint64(unsafe.Sizeof(Module{}))+uint64(nName)+uint64(1))
		if pMod == uintptr(0) {
			Xsqlite3OomFault(tls, db)
			return uintptr(0)
		}
		zCopy = pMod + 1*48
		libc.Xmemcpy(tls, zCopy, zName, uint64(nName+1))
		(*Module)(unsafe.Pointer(pMod)).FzName = zCopy
		(*Module)(unsafe.Pointer(pMod)).FpModule = pModule
		(*Module)(unsafe.Pointer(pMod)).FpAux = pAux
		(*Module)(unsafe.Pointer(pMod)).FxDestroy = xDestroy
		(*Module)(unsafe.Pointer(pMod)).FpEpoTab = uintptr(0)
		(*Module)(unsafe.Pointer(pMod)).FnRefModule = 1
	}
	pDel = Xsqlite3HashInsert(tls, db+576, zCopy, pMod)
	if pDel != 0 {
		if pDel == pMod {
			Xsqlite3OomFault(tls, db)
			Xsqlite3DbFree(tls, db, pDel)
			pMod = uintptr(0)
		} else {
			Xsqlite3VtabEponymousTableClear(tls, db, pDel)
			Xsqlite3VtabModuleUnref(tls, db, pDel)
		}
	}
	return pMod
}

func createModule(tls *libc.TLS, db uintptr, zName uintptr, pModule uintptr, pAux uintptr, xDestroy uintptr) int32 {
	var rc int32 = SQLITE_OK

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	Xsqlite3VtabCreateModule(tls, db, zName, pModule, pAux, xDestroy)
	rc = Xsqlite3ApiExit(tls, db, rc)
	if rc != SQLITE_OK && xDestroy != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDestroy})).f(tls, pAux)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_create_module(tls *libc.TLS, db uintptr, zName uintptr, pModule uintptr, pAux uintptr) int32 {
	return createModule(tls, db, zName, pModule, pAux, uintptr(0))
}

func Xsqlite3_create_module_v2(tls *libc.TLS, db uintptr, zName uintptr, pModule uintptr, pAux uintptr, xDestroy uintptr) int32 {
	return createModule(tls, db, zName, pModule, pAux, xDestroy)
}

func Xsqlite3_drop_modules(tls *libc.TLS, db uintptr, azNames uintptr) int32 {
	var pThis uintptr
	var pNext uintptr
	for pThis = (*Hash)(unsafe.Pointer(db + 576)).Ffirst; pThis != 0; pThis = pNext {
		var pMod uintptr = (*HashElem)(unsafe.Pointer(pThis)).Fdata
		pNext = (*HashElem)(unsafe.Pointer(pThis)).Fnext
		if azNames != 0 {
			var ii int32
			for ii = 0; *(*uintptr)(unsafe.Pointer(azNames + uintptr(ii)*8)) != uintptr(0) && libc.Xstrcmp(tls, *(*uintptr)(unsafe.Pointer(azNames + uintptr(ii)*8)), (*Module)(unsafe.Pointer(pMod)).FzName) != 0; ii++ {
			}
			if *(*uintptr)(unsafe.Pointer(azNames + uintptr(ii)*8)) != uintptr(0) {
				continue
			}
		}
		createModule(tls, db, (*Module)(unsafe.Pointer(pMod)).FzName, uintptr(0), uintptr(0), uintptr(0))
	}
	return SQLITE_OK
}

func Xsqlite3VtabModuleUnref(tls *libc.TLS, db uintptr, pMod uintptr) {
	(*Module)(unsafe.Pointer(pMod)).FnRefModule--
	if (*Module)(unsafe.Pointer(pMod)).FnRefModule == 0 {
		if (*Module)(unsafe.Pointer(pMod)).FxDestroy != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Module)(unsafe.Pointer(pMod)).FxDestroy})).f(tls, (*Module)(unsafe.Pointer(pMod)).FpAux)
		}

		Xsqlite3DbFree(tls, db, pMod)
	}
}

func Xsqlite3VtabLock(tls *libc.TLS, pVTab uintptr) {
	(*VTable)(unsafe.Pointer(pVTab)).FnRef++
}

func Xsqlite3GetVTable(tls *libc.TLS, db uintptr, pTab uintptr) uintptr {
	var pVtab uintptr

	for pVtab = *(*uintptr)(unsafe.Pointer(pTab + 64 + 16)); pVtab != 0 && (*VTable)(unsafe.Pointer(pVtab)).Fdb != db; pVtab = (*VTable)(unsafe.Pointer(pVtab)).FpNext {
	}
	return pVtab
}

func Xsqlite3VtabUnlock(tls *libc.TLS, pVTab uintptr) {
	var db uintptr = (*VTable)(unsafe.Pointer(pVTab)).Fdb

	(*VTable)(unsafe.Pointer(pVTab)).FnRef--
	if (*VTable)(unsafe.Pointer(pVTab)).FnRef == 0 {
		var p uintptr = (*VTable)(unsafe.Pointer(pVTab)).FpVtab
		if p != 0 {
			(*struct {
				f func(*libc.TLS, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer((*Sqlite3_vtab)(unsafe.Pointer(p)).FpModule)).FxDisconnect})).f(tls, p)
		}
		Xsqlite3VtabModuleUnref(tls, (*VTable)(unsafe.Pointer(pVTab)).Fdb, (*VTable)(unsafe.Pointer(pVTab)).FpMod)
		Xsqlite3DbFree(tls, db, pVTab)
	}
}

func vtabDisconnectAll(tls *libc.TLS, db uintptr, p uintptr) uintptr {
	var pRet uintptr = uintptr(0)
	var pVTable uintptr

	pVTable = *(*uintptr)(unsafe.Pointer(p + 64 + 16))
	*(*uintptr)(unsafe.Pointer(p + 64 + 16)) = uintptr(0)

	for pVTable != 0 {
		var db2 uintptr = (*VTable)(unsafe.Pointer(pVTable)).Fdb
		var pNext uintptr = (*VTable)(unsafe.Pointer(pVTable)).FpNext

		if db2 == db {
			pRet = pVTable
			*(*uintptr)(unsafe.Pointer(p + 64 + 16)) = pRet
			(*VTable)(unsafe.Pointer(pRet)).FpNext = uintptr(0)
		} else {
			(*VTable)(unsafe.Pointer(pVTable)).FpNext = (*Sqlite3)(unsafe.Pointer(db2)).FpDisconnect
			(*Sqlite3)(unsafe.Pointer(db2)).FpDisconnect = pVTable
		}
		pVTable = pNext
	}

	return pRet
}

func Xsqlite3VtabDisconnect(tls *libc.TLS, db uintptr, p uintptr) {
	var ppVTab uintptr

	for ppVTab = p + 64 + 16; *(*uintptr)(unsafe.Pointer(ppVTab)) != 0; ppVTab = *(*uintptr)(unsafe.Pointer(ppVTab)) + 40 {
		if (*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppVTab)))).Fdb == db {
			var pVTab uintptr = *(*uintptr)(unsafe.Pointer(ppVTab))
			*(*uintptr)(unsafe.Pointer(ppVTab)) = (*VTable)(unsafe.Pointer(pVTab)).FpNext
			Xsqlite3VtabUnlock(tls, pVTab)
			break
		}
	}
}

func Xsqlite3VtabUnlockList(tls *libc.TLS, db uintptr) {
	var p uintptr = (*Sqlite3)(unsafe.Pointer(db)).FpDisconnect

	if p != 0 {
		(*Sqlite3)(unsafe.Pointer(db)).FpDisconnect = uintptr(0)
		Xsqlite3ExpirePreparedStatements(tls, db, 0)
		for __ccgo := true; __ccgo; __ccgo = p != 0 {
			var pNext uintptr = (*VTable)(unsafe.Pointer(p)).FpNext
			Xsqlite3VtabUnlock(tls, p)
			p = pNext
		}
	}
}

func Xsqlite3VtabClear(tls *libc.TLS, db uintptr, p uintptr) {
	if (*Sqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
		vtabDisconnectAll(tls, uintptr(0), p)
	}
	if *(*uintptr)(unsafe.Pointer(p + 64 + 8)) != 0 {
		var i int32
		for i = 0; i < *(*int32)(unsafe.Pointer(p + 64)); i++ {
			if i != 1 {
				Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64 + 8)) + uintptr(i)*8)))
			}
		}
		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(p + 64 + 8)))
	}
}

func addModuleArgument(tls *libc.TLS, pParse uintptr, pTable uintptr, zArg uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var nBytes Sqlite3_int64
	var azModuleArg uintptr
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	nBytes = Sqlite3_int64(uint64(unsafe.Sizeof(uintptr(0))) * uint64(2+*(*int32)(unsafe.Pointer(pTable + 64))))
	if *(*int32)(unsafe.Pointer(pTable + 64))+3 >= *(*int32)(unsafe.Pointer(db + 136 + 2*4)) {
		Xsqlite3ErrorMsg(tls, pParse, ts+15805, libc.VaList(bp, (*Table)(unsafe.Pointer(pTable)).FzName))
	}
	azModuleArg = Xsqlite3DbRealloc(tls, db, *(*uintptr)(unsafe.Pointer(pTable + 64 + 8)), uint64(nBytes))
	if azModuleArg == uintptr(0) {
		Xsqlite3DbFree(tls, db, zArg)
	} else {
		var i int32 = libc.PostIncInt32(&*(*int32)(unsafe.Pointer(pTable + 64)), 1)
		*(*uintptr)(unsafe.Pointer(azModuleArg + uintptr(i)*8)) = zArg
		*(*uintptr)(unsafe.Pointer(azModuleArg + uintptr(i+1)*8)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(pTable + 64 + 8)) = azModuleArg
	}
}

func Xsqlite3VtabBeginParse(tls *libc.TLS, pParse uintptr, pName1 uintptr, pName2 uintptr, pModuleName uintptr, ifNotExists int32) {
	var pTable uintptr
	var db uintptr

	Xsqlite3StartTable(tls, pParse, pName1, pName2, 0, 0, 1, ifNotExists)
	pTable = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	if pTable == uintptr(0) {
		return
	}

	(*Table)(unsafe.Pointer(pTable)).FeTabType = U8(TABTYP_VTAB)

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb

	addModuleArgument(tls, pParse, pTable, Xsqlite3NameFromToken(tls, db, pModuleName))
	addModuleArgument(tls, pParse, pTable, uintptr(0))
	addModuleArgument(tls, pParse, pTable, Xsqlite3DbStrDup(tls, db, (*Table)(unsafe.Pointer(pTable)).FzName))

	(*Parse)(unsafe.Pointer(pParse)).FsNameToken.Fn = uint32(int32((int64((*Token)(unsafe.Pointer(pModuleName)).Fz+uintptr((*Token)(unsafe.Pointer(pModuleName)).Fn)) - int64((*Parse)(unsafe.Pointer(pParse)).FsNameToken.Fz)) / 1))

	if *(*uintptr)(unsafe.Pointer(pTable + 64 + 8)) != 0 {
		var iDb int32 = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTable)).FpSchema)

		Xsqlite3AuthCheck(tls, pParse, SQLITE_CREATE_VTABLE, (*Table)(unsafe.Pointer(pTable)).FzName,
			*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTable + 64 + 8)))), (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FaDb+uintptr(iDb)*32)).FzDbSName)
	}
}

func addArgumentToVtab(tls *libc.TLS, pParse uintptr) {
	if (*Parse)(unsafe.Pointer(pParse)).FsArg.Fz != 0 && (*Parse)(unsafe.Pointer(pParse)).FpNewTable != 0 {
		var z uintptr = (*Parse)(unsafe.Pointer(pParse)).FsArg.Fz
		var n int32 = int32((*Parse)(unsafe.Pointer(pParse)).FsArg.Fn)
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		addModuleArgument(tls, pParse, (*Parse)(unsafe.Pointer(pParse)).FpNewTable, Xsqlite3DbStrNDup(tls, db, z, uint64(n)))
	}
}

func Xsqlite3VtabFinishParse(tls *libc.TLS, pParse uintptr, pEnd uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var pTab uintptr = (*Parse)(unsafe.Pointer(pParse)).FpNewTable
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb

	if pTab == uintptr(0) {
		return
	}

	addArgumentToVtab(tls, pParse)
	(*Parse)(unsafe.Pointer(pParse)).FsArg.Fz = uintptr(0)
	if *(*int32)(unsafe.Pointer(pTab + 64)) < 1 {
		return
	}

	if !(int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) != 0) {
		var zStmt uintptr
		var zWhere uintptr
		var iDb int32
		var iReg int32
		var v uintptr

		Xsqlite3MayAbort(tls, pParse)

		if pEnd != 0 {
			(*Parse)(unsafe.Pointer(pParse)).FsNameToken.Fn = uint32(int32((int64((*Token)(unsafe.Pointer(pEnd)).Fz)-int64((*Parse)(unsafe.Pointer(pParse)).FsNameToken.Fz))/1)) + (*Token)(unsafe.Pointer(pEnd)).Fn
		}
		zStmt = Xsqlite3MPrintf(tls, db, ts+25588, libc.VaList(bp, pParse+272))

		iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)
		Xsqlite3NestedParse(tls, pParse,
			ts+25612,
			libc.VaList(bp+8, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName,
				(*Table)(unsafe.Pointer(pTab)).FzName,
				(*Table)(unsafe.Pointer(pTab)).FzName,
				zStmt,
				(*Parse)(unsafe.Pointer(pParse)).FregRowid))
		v = Xsqlite3GetVdbe(tls, pParse)
		Xsqlite3ChangeCookie(tls, pParse, iDb)

		Xsqlite3VdbeAddOp0(tls, v, OP_Expire)
		zWhere = Xsqlite3MPrintf(tls, db, ts+25711, libc.VaList(bp+48, (*Table)(unsafe.Pointer(pTab)).FzName, zStmt))
		Xsqlite3VdbeAddParseSchemaOp(tls, v, iDb, zWhere, uint16(0))
		Xsqlite3DbFree(tls, db, zStmt)

		iReg = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		Xsqlite3VdbeLoadString(tls, v, iReg, (*Table)(unsafe.Pointer(pTab)).FzName)
		Xsqlite3VdbeAddOp2(tls, v, OP_VCreate, iDb, iReg)
	} else {
		var pOld uintptr
		var pSchema uintptr = (*Table)(unsafe.Pointer(pTab)).FpSchema
		var zName uintptr = (*Table)(unsafe.Pointer(pTab)).FzName

		Xsqlite3MarkAllShadowTablesOf(tls, db, pTab)
		pOld = Xsqlite3HashInsert(tls, pSchema+8, zName, pTab)
		if pOld != 0 {
			Xsqlite3OomFault(tls, db)

			return
		}
		(*Parse)(unsafe.Pointer(pParse)).FpNewTable = uintptr(0)
	}
}

func Xsqlite3VtabArgInit(tls *libc.TLS, pParse uintptr) {
	addArgumentToVtab(tls, pParse)
	(*Parse)(unsafe.Pointer(pParse)).FsArg.Fz = uintptr(0)
	(*Parse)(unsafe.Pointer(pParse)).FsArg.Fn = uint32(0)
}

func Xsqlite3VtabArgExtend(tls *libc.TLS, pParse uintptr, p uintptr) {
	var pArg uintptr = pParse + 384
	if (*Token)(unsafe.Pointer(pArg)).Fz == uintptr(0) {
		(*Token)(unsafe.Pointer(pArg)).Fz = (*Token)(unsafe.Pointer(p)).Fz
		(*Token)(unsafe.Pointer(pArg)).Fn = (*Token)(unsafe.Pointer(p)).Fn
	} else {
		(*Token)(unsafe.Pointer(pArg)).Fn = uint32(int32((int64((*Token)(unsafe.Pointer(p)).Fz+uintptr((*Token)(unsafe.Pointer(p)).Fn)) - int64((*Token)(unsafe.Pointer(pArg)).Fz)) / 1))
	}
}

func vtabCallConstructor(tls *libc.TLS, db uintptr, pTab uintptr, pMod uintptr, xConstruct uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var pVTable uintptr
	var rc int32
	var azArg uintptr
	var nArg int32 = *(*int32)(unsafe.Pointer(pTab + 64))
	*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)
	var zModuleName uintptr
	var iDb int32
	var pCtx uintptr

	azArg = *(*uintptr)(unsafe.Pointer(pTab + 64 + 8))

	for pCtx = (*Sqlite3)(unsafe.Pointer(db)).FpVtabCtx; pCtx != 0; pCtx = (*VtabCtx)(unsafe.Pointer(pCtx)).FpPrior {
		if (*VtabCtx)(unsafe.Pointer(pCtx)).FpTab == pTab {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3MPrintf(tls, db,
				ts+25730, libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName))
			return SQLITE_LOCKED
		}
	}

	zModuleName = Xsqlite3DbStrDup(tls, db, (*Table)(unsafe.Pointer(pTab)).FzName)
	if !(zModuleName != 0) {
		return SQLITE_NOMEM
	}

	pVTable = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(VTable{})))
	if !(pVTable != 0) {
		Xsqlite3OomFault(tls, db)
		Xsqlite3DbFree(tls, db, zModuleName)
		return SQLITE_NOMEM
	}
	(*VTable)(unsafe.Pointer(pVTable)).Fdb = db
	(*VTable)(unsafe.Pointer(pVTable)).FpMod = pMod
	(*VTable)(unsafe.Pointer(pVTable)).FeVtabRisk = U8(SQLITE_VTABRISK_Normal)

	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)
	*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 8)) + 1*8)) = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FzDbSName

	(*VtabCtx)(unsafe.Pointer(bp + 32)).FpTab = pTab
	(*VtabCtx)(unsafe.Pointer(bp + 32)).FpVTable = pVTable
	(*VtabCtx)(unsafe.Pointer(bp + 32)).FpPrior = (*Sqlite3)(unsafe.Pointer(db)).FpVtabCtx
	(*VtabCtx)(unsafe.Pointer(bp + 32)).FbDeclared = 0
	(*Sqlite3)(unsafe.Pointer(db)).FpVtabCtx = bp + 32
	(*Table)(unsafe.Pointer(pTab)).FnTabRef++
	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{xConstruct})).f(tls, db, (*Module)(unsafe.Pointer(pMod)).FpAux, nArg, azArg, pVTable+16, bp+64)
	Xsqlite3DeleteTable(tls, db, pTab)
	(*Sqlite3)(unsafe.Pointer(db)).FpVtabCtx = (*VtabCtx)(unsafe.Pointer(bp + 32)).FpPrior
	if rc == SQLITE_NOMEM {
		Xsqlite3OomFault(tls, db)
	}

	if SQLITE_OK != rc {
		if *(*uintptr)(unsafe.Pointer(bp + 64)) == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3MPrintf(tls, db, ts+25772, libc.VaList(bp+8, zModuleName))
		} else {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3MPrintf(tls, db, ts+1684, libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp + 64))))
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
		}
		Xsqlite3DbFree(tls, db, pVTable)
	} else if (*VTable)(unsafe.Pointer(pVTable)).FpVtab != 0 {
		libc.Xmemset(tls, (*VTable)(unsafe.Pointer(pVTable)).FpVtab, 0, uint64(unsafe.Sizeof(Sqlite3_vtab{})))
		(*Sqlite3_vtab)(unsafe.Pointer((*VTable)(unsafe.Pointer(pVTable)).FpVtab)).FpModule = (*Module)(unsafe.Pointer(pMod)).FpModule
		(*Module)(unsafe.Pointer(pMod)).FnRefModule++
		(*VTable)(unsafe.Pointer(pVTable)).FnRef = 1
		if (*VtabCtx)(unsafe.Pointer(bp+32)).FbDeclared == 0 {
			var zFormat uintptr = ts + 25802
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3MPrintf(tls, db, zFormat, libc.VaList(bp+24, (*Table)(unsafe.Pointer(pTab)).FzName))
			Xsqlite3VtabUnlock(tls, pVTable)
			rc = SQLITE_ERROR
		} else {
			var iCol int32
			var oooHidden U16 = U16(0)

			(*VTable)(unsafe.Pointer(pVTable)).FpNext = *(*uintptr)(unsafe.Pointer(pTab + 64 + 16))
			*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)) = pVTable

			for iCol = 0; iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol); iCol++ {
				var zType uintptr = Xsqlite3ColumnType(tls, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(iCol)*24, ts+1636)
				var nType int32
				var i int32 = 0
				nType = Xsqlite3Strlen30(tls, zType)
				for i = 0; i < nType; i++ {
					if 0 == Xsqlite3_strnicmp(tls, ts+19705, zType+uintptr(i), 6) &&
						(i == 0 || int32(*(*uint8)(unsafe.Pointer(zType + uintptr(i-1)))) == ' ') &&
						(int32(*(*uint8)(unsafe.Pointer(zType + uintptr(i+6)))) == 0 || int32(*(*uint8)(unsafe.Pointer(zType + uintptr(i+6)))) == ' ') {
						break
					}
				}
				if i < nType {
					var j int32
					var nDel int32 = 6 + func() int32 {
						if *(*uint8)(unsafe.Pointer(zType + uintptr(i+6))) != 0 {
							return 1
						}
						return 0
					}()
					for j = i; j+nDel <= nType; j++ {
						*(*uint8)(unsafe.Pointer(zType + uintptr(j))) = *(*uint8)(unsafe.Pointer(zType + uintptr(j+nDel)))
					}
					if int32(*(*uint8)(unsafe.Pointer(zType + uintptr(i)))) == 0 && i > 0 {
						*(*uint8)(unsafe.Pointer(zType + uintptr(i-1))) = uint8(0)
					}
					*(*U16)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24 + 16)) |= U16(COLFLAG_HIDDEN)
					*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_HasHidden)
					oooHidden = U16(TF_OOOHidden)
				} else {
					*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(oooHidden)
				}
			}
		}
	}

	Xsqlite3DbFree(tls, db, zModuleName)
	return rc
}

func Xsqlite3VtabCallConnect(tls *libc.TLS, pParse uintptr, pTab uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var zMod uintptr
	var pMod uintptr
	var rc int32

	if Xsqlite3GetVTable(tls, db, pTab) != 0 {
		return SQLITE_OK
	}

	zMod = *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 8))))
	pMod = Xsqlite3HashFind(tls, db+576, zMod)

	if !(pMod != 0) {
		var zModule uintptr = *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 8))))
		Xsqlite3ErrorMsg(tls, pParse, ts+25848, libc.VaList(bp, zModule))
		rc = SQLITE_ERROR
	} else {
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
		rc = vtabCallConstructor(tls, db, pTab, pMod, (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FxConnect, bp+16)
		if rc != SQLITE_OK {
			Xsqlite3ErrorMsg(tls, pParse, ts+1684, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(bp + 16))))
			(*Parse)(unsafe.Pointer(pParse)).Frc = rc
		}
		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 16)))
	}

	return rc
}

func growVTrans(tls *libc.TLS, db uintptr) int32 {
	var ARRAY_INCR int32 = 5

	if (*Sqlite3)(unsafe.Pointer(db)).FnVTrans%ARRAY_INCR == 0 {
		var aVTrans uintptr
		var nBytes Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(uintptr(0))) * uint64(Sqlite3_int64((*Sqlite3)(unsafe.Pointer(db)).FnVTrans)+Sqlite3_int64(ARRAY_INCR)))
		aVTrans = Xsqlite3DbRealloc(tls, db, (*Sqlite3)(unsafe.Pointer(db)).FaVTrans, uint64(nBytes))
		if !(aVTrans != 0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, aVTrans+uintptr((*Sqlite3)(unsafe.Pointer(db)).FnVTrans)*8, 0, uint64(unsafe.Sizeof(uintptr(0)))*uint64(ARRAY_INCR))
		(*Sqlite3)(unsafe.Pointer(db)).FaVTrans = aVTrans
	}

	return SQLITE_OK
}

func addToVTrans(tls *libc.TLS, db uintptr, pVTab uintptr) {
	*(*uintptr)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaVTrans + uintptr(libc.PostIncInt32(&(*Sqlite3)(unsafe.Pointer(db)).FnVTrans, 1))*8)) = pVTab
	Xsqlite3VtabLock(tls, pVTab)
}

func Xsqlite3VtabCallCreate(tls *libc.TLS, db uintptr, iDb int32, zTab uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var pTab uintptr
	var pMod uintptr
	var zMod uintptr

	pTab = Xsqlite3FindTable(tls, db, zTab, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName)

	zMod = *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTab + 64 + 8))))
	pMod = Xsqlite3HashFind(tls, db+576, zMod)

	if pMod == uintptr(0) || (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FxCreate == uintptr(0) || (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FxDestroy == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3MPrintf(tls, db, ts+25848, libc.VaList(bp, zMod))
		rc = SQLITE_ERROR
	} else {
		rc = vtabCallConstructor(tls, db, pTab, pMod, (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer(pMod)).FpModule)).FxCreate, pzErr)
	}

	if rc == SQLITE_OK && Xsqlite3GetVTable(tls, db, pTab) != 0 {
		rc = growVTrans(tls, db)
		if rc == SQLITE_OK {
			addToVTrans(tls, db, Xsqlite3GetVTable(tls, db, pTab))
		}
	}

	return rc
}

func Xsqlite3_declare_vtab(tls *libc.TLS, db uintptr, zCreateTable uintptr) int32 {
	bp := tls.Alloc(432)
	defer tls.Free(432)

	var pCtx uintptr
	var rc int32 = SQLITE_OK
	var pTab uintptr

	var initBusy int32

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pCtx = (*Sqlite3)(unsafe.Pointer(db)).FpVtabCtx
	if !(pCtx != 0) || (*VtabCtx)(unsafe.Pointer(pCtx)).FbDeclared != 0 {
		Xsqlite3Error(tls, db, SQLITE_MISUSE)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		return Xsqlite3MisuseError(tls, 151102)
	}
	pTab = (*VtabCtx)(unsafe.Pointer(pCtx)).FpTab

	Xsqlite3ParseObjectInit(tls, bp+8, db)
	(*Parse)(unsafe.Pointer(bp + 8)).FeParseMode = U8(PARSE_MODE_DECLARE_VTAB)
	(*Parse)(unsafe.Pointer(bp + 8)).FdisableTriggers = U8(1)

	initBusy = int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy)
	(*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy = U8(0)
	(*Parse)(unsafe.Pointer(bp + 8)).FnQueryLoop = U32(1)
	if SQLITE_OK == Xsqlite3RunParser(tls, bp+8, zCreateTable) &&
		(*Parse)(unsafe.Pointer(bp+8)).FpNewTable != uintptr(0) &&
		!(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) &&
		int32((*Table)(unsafe.Pointer((*Parse)(unsafe.Pointer(bp+8)).FpNewTable)).FeTabType) == TABTYP_NORM {
		if !(int32((*Table)(unsafe.Pointer(pTab)).FaCol) != 0) {
			var pNew uintptr = (*Parse)(unsafe.Pointer(bp + 8)).FpNewTable
			var pIdx uintptr
			(*Table)(unsafe.Pointer(pTab)).FaCol = (*Table)(unsafe.Pointer(pNew)).FaCol
			Xsqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pNew + 64 + 16)))
			(*Table)(unsafe.Pointer(pTab)).FnNVCol = libc.AssignPtrInt16(pTab+54, (*Table)(unsafe.Pointer(pNew)).FnCol)
			*(*U32)(unsafe.Pointer(pTab + 48)) |= (*Table)(unsafe.Pointer(pNew)).FtabFlags & U32(TF_WithoutRowid|TF_NoVisibleRowid)
			(*Table)(unsafe.Pointer(pNew)).FnCol = int16(0)
			(*Table)(unsafe.Pointer(pNew)).FaCol = uintptr(0)

			if !((*Table)(unsafe.Pointer(pNew)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) &&
				(*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer((*VTable)(unsafe.Pointer((*VtabCtx)(unsafe.Pointer(pCtx)).FpVTable)).FpMod)).FpModule)).FxUpdate != uintptr(0) &&
				int32((*Index)(unsafe.Pointer(Xsqlite3PrimaryKeyIndex(tls, pNew))).FnKeyCol) != 1 {
				rc = SQLITE_ERROR
			}
			pIdx = (*Table)(unsafe.Pointer(pNew)).FpIndex
			if pIdx != 0 {
				(*Table)(unsafe.Pointer(pTab)).FpIndex = pIdx
				(*Table)(unsafe.Pointer(pNew)).FpIndex = uintptr(0)
				(*Index)(unsafe.Pointer(pIdx)).FpTable = pTab
			}
		}
		(*VtabCtx)(unsafe.Pointer(pCtx)).FbDeclared = 1
	} else {
		Xsqlite3ErrorWithMsg(tls, db, SQLITE_ERROR,
			func() uintptr {
				if (*Parse)(unsafe.Pointer(bp+8)).FzErrMsg != 0 {
					return ts + 1684
				}
				return uintptr(0)
			}(), libc.VaList(bp, (*Parse)(unsafe.Pointer(bp+8)).FzErrMsg))
		Xsqlite3DbFree(tls, db, (*Parse)(unsafe.Pointer(bp+8)).FzErrMsg)
		rc = SQLITE_ERROR
	}
	(*Parse)(unsafe.Pointer(bp + 8)).FeParseMode = U8(PARSE_MODE_NORMAL)

	if (*Parse)(unsafe.Pointer(bp+8)).FpVdbe != 0 {
		Xsqlite3VdbeFinalize(tls, (*Parse)(unsafe.Pointer(bp+8)).FpVdbe)
	}
	Xsqlite3DeleteTable(tls, db, (*Parse)(unsafe.Pointer(bp+8)).FpNewTable)
	Xsqlite3ParseObjectReset(tls, bp+8)
	(*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy = U8(initBusy)

	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3VtabCallDestroy(tls *libc.TLS, db uintptr, iDb int32, zTab uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pTab uintptr

	pTab = Xsqlite3FindTable(tls, db, zTab, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName)
	if pTab != uintptr(0) &&
		int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB &&
		*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)) != uintptr(0) {
		var p uintptr
		var xDestroy uintptr
		for p = *(*uintptr)(unsafe.Pointer(pTab + 64 + 16)); p != 0; p = (*VTable)(unsafe.Pointer(p)).FpNext {
			if (*Sqlite3_vtab)(unsafe.Pointer((*VTable)(unsafe.Pointer(p)).FpVtab)).FnRef > 0 {
				return SQLITE_LOCKED
			}
		}
		p = vtabDisconnectAll(tls, db, pTab)
		xDestroy = (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer((*VTable)(unsafe.Pointer(p)).FpMod)).FpModule)).FxDestroy
		if xDestroy == uintptr(0) {
			xDestroy = (*Sqlite3_module)(unsafe.Pointer((*Module)(unsafe.Pointer((*VTable)(unsafe.Pointer(p)).FpMod)).FpModule)).FxDisconnect
		}

		(*Table)(unsafe.Pointer(pTab)).FnTabRef++
		rc = (*struct {
			f func(*libc.TLS, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{xDestroy})).f(tls, (*VTable)(unsafe.Pointer(p)).FpVtab)

		if rc == SQLITE_OK {
			(*VTable)(unsafe.Pointer(p)).FpVtab = uintptr(0)
			*(*uintptr)(unsafe.Pointer(pTab + 64 + 16)) = uintptr(0)
			Xsqlite3VtabUnlock(tls, p)
		}
		Xsqlite3DeleteTable(tls, db, pTab)
	}

	return rc
}

func callFinaliser(tls *libc.TLS, db uintptr, offset int32) {
	var i int32
	if (*Sqlite3)(unsafe.Pointer(db)).FaVTrans != 0 {
		var aVTrans uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaVTrans
		(*Sqlite3)(unsafe.Pointer(db)).FaVTrans = uintptr(0)
		for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnVTrans; i++ {
			var pVTab uintptr = *(*uintptr)(unsafe.Pointer(aVTrans + uintptr(i)*8))
			var p uintptr = (*VTable)(unsafe.Pointer(pVTab)).FpVtab
			if p != 0 {
				var x uintptr
				x = *(*uintptr)(unsafe.Pointer((*Sqlite3_vtab)(unsafe.Pointer(p)).FpModule + uintptr(offset)))
				if x != 0 {
					(*struct {
						f func(*libc.TLS, uintptr) int32
					})(unsafe.Pointer(&struct{ uintptr }{x})).f(tls, p)
				}
			}
			(*VTable)(unsafe.Pointer(pVTab)).FiSavepoint = 0
			Xsqlite3VtabUnlock(tls, pVTab)
		}
		Xsqlite3DbFree(tls, db, aVTrans)
		(*Sqlite3)(unsafe.Pointer(db)).FnVTrans = 0
	}
}

func Xsqlite3VtabSync(tls *libc.TLS, db uintptr, p uintptr) int32 {
	var i int32
	var rc int32 = SQLITE_OK
	var aVTrans uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaVTrans

	(*Sqlite3)(unsafe.Pointer(db)).FaVTrans = uintptr(0)
	for i = 0; rc == SQLITE_OK && i < (*Sqlite3)(unsafe.Pointer(db)).FnVTrans; i++ {
		var x uintptr
		var pVtab uintptr = (*VTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aVTrans + uintptr(i)*8)))).FpVtab
		if pVtab != 0 && libc.AssignUintptr(&x, (*Sqlite3_module)(unsafe.Pointer((*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule)).FxSync) != uintptr(0) {
			rc = (*struct {
				f func(*libc.TLS, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{x})).f(tls, pVtab)
			Xsqlite3VtabImportErrmsg(tls, p, pVtab)
		}
	}
	(*Sqlite3)(unsafe.Pointer(db)).FaVTrans = aVTrans
	return rc
}

func Xsqlite3VtabRollback(tls *libc.TLS, db uintptr) int32 {
	callFinaliser(tls, db, int32(uintptr(0)+136))
	return SQLITE_OK
}

func Xsqlite3VtabCommit(tls *libc.TLS, db uintptr) int32 {
	callFinaliser(tls, db, int32(uintptr(0)+128))
	return SQLITE_OK
}

func Xsqlite3VtabBegin(tls *libc.TLS, db uintptr, pVTab uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pModule uintptr

	if (*Sqlite3)(unsafe.Pointer(db)).FnVTrans > 0 && (*Sqlite3)(unsafe.Pointer(db)).FaVTrans == uintptr(0) {
		return SQLITE_LOCKED
	}
	if !(pVTab != 0) {
		return SQLITE_OK
	}
	pModule = (*Sqlite3_vtab)(unsafe.Pointer((*VTable)(unsafe.Pointer(pVTab)).FpVtab)).FpModule

	if (*Sqlite3_module)(unsafe.Pointer(pModule)).FxBegin != 0 {
		var i int32

		for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnVTrans; i++ {
			if *(*uintptr)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaVTrans + uintptr(i)*8)) == pVTab {
				return SQLITE_OK
			}
		}

		rc = growVTrans(tls, db)
		if rc == SQLITE_OK {
			rc = (*struct {
				f func(*libc.TLS, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule)).FxBegin})).f(tls, (*VTable)(unsafe.Pointer(pVTab)).FpVtab)
			if rc == SQLITE_OK {
				var iSvpt int32 = (*Sqlite3)(unsafe.Pointer(db)).FnStatement + (*Sqlite3)(unsafe.Pointer(db)).FnSavepoint
				addToVTrans(tls, db, pVTab)
				if iSvpt != 0 && (*Sqlite3_module)(unsafe.Pointer(pModule)).FxSavepoint != 0 {
					(*VTable)(unsafe.Pointer(pVTab)).FiSavepoint = iSvpt
					rc = (*struct {
						f func(*libc.TLS, uintptr, int32) int32
					})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pModule)).FxSavepoint})).f(tls, (*VTable)(unsafe.Pointer(pVTab)).FpVtab, iSvpt-1)
				}
			}
		}
	}
	return rc
}

func Xsqlite3VtabSavepoint(tls *libc.TLS, db uintptr, op int32, iSavepoint int32) int32 {
	var rc int32 = SQLITE_OK

	if (*Sqlite3)(unsafe.Pointer(db)).FaVTrans != 0 {
		var i int32
		for i = 0; rc == SQLITE_OK && i < (*Sqlite3)(unsafe.Pointer(db)).FnVTrans; i++ {
			var pVTab uintptr = *(*uintptr)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaVTrans + uintptr(i)*8))
			var pMod uintptr = (*Module)(unsafe.Pointer((*VTable)(unsafe.Pointer(pVTab)).FpMod)).FpModule
			if (*VTable)(unsafe.Pointer(pVTab)).FpVtab != 0 && (*Sqlite3_module)(unsafe.Pointer(pMod)).FiVersion >= 2 {
				var xMethod uintptr
				Xsqlite3VtabLock(tls, pVTab)
				switch op {
				case SAVEPOINT_BEGIN:
					xMethod = (*Sqlite3_module)(unsafe.Pointer(pMod)).FxSavepoint
					(*VTable)(unsafe.Pointer(pVTab)).FiSavepoint = iSavepoint + 1
					break
					fallthrough
				case SAVEPOINT_ROLLBACK:
					xMethod = (*Sqlite3_module)(unsafe.Pointer(pMod)).FxRollbackTo
					break
					fallthrough
				default:
					xMethod = (*Sqlite3_module)(unsafe.Pointer(pMod)).FxRelease
					break
				}
				if xMethod != 0 && (*VTable)(unsafe.Pointer(pVTab)).FiSavepoint > iSavepoint {
					rc = (*struct {
						f func(*libc.TLS, uintptr, int32) int32
					})(unsafe.Pointer(&struct{ uintptr }{xMethod})).f(tls, (*VTable)(unsafe.Pointer(pVTab)).FpVtab, iSavepoint)
				}
				Xsqlite3VtabUnlock(tls, pVTab)
			}
		}
	}
	return rc
}

func Xsqlite3VtabOverloadFunction(tls *libc.TLS, db uintptr, pDef uintptr, nArg int32, pExpr uintptr) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTab uintptr
	var pVtab uintptr
	var pMod uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	var pNew uintptr
	var rc int32 = 0

	if pExpr == uintptr(0) {
		return pDef
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_COLUMN {
		return pDef
	}

	pTab = *(*uintptr)(unsafe.Pointer(pExpr + 64))
	if pTab == uintptr(0) {
		return pDef
	}
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		return pDef
	}
	pVtab = (*VTable)(unsafe.Pointer(Xsqlite3GetVTable(tls, db, pTab))).FpVtab

	pMod = (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule
	if (*Sqlite3_module)(unsafe.Pointer(pMod)).FxFindFunction == uintptr(0) {
		return pDef
	}

	rc = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pMod)).FxFindFunction})).f(tls, pVtab, nArg, (*FuncDef)(unsafe.Pointer(pDef)).FzName, bp, bp+8)
	if rc == 0 {
		return pDef
	}

	pNew = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(FuncDef{}))+
		uint64(Xsqlite3Strlen30(tls, (*FuncDef)(unsafe.Pointer(pDef)).FzName))+uint64(1))
	if pNew == uintptr(0) {
		return pDef
	}
	*(*FuncDef)(unsafe.Pointer(pNew)) = *(*FuncDef)(unsafe.Pointer(pDef))
	(*FuncDef)(unsafe.Pointer(pNew)).FzName = pNew + 1*72
	libc.Xmemcpy(tls, pNew+1*72, (*FuncDef)(unsafe.Pointer(pDef)).FzName, uint64(Xsqlite3Strlen30(tls, (*FuncDef)(unsafe.Pointer(pDef)).FzName)+1))
	(*FuncDef)(unsafe.Pointer(pNew)).FxSFunc = *(*uintptr)(unsafe.Pointer(bp))
	(*FuncDef)(unsafe.Pointer(pNew)).FpUserData = *(*uintptr)(unsafe.Pointer(bp + 8))
	*(*U32)(unsafe.Pointer(pNew + 4)) |= U32(SQLITE_FUNC_EPHEM)
	return pNew
}

func Xsqlite3VtabMakeWritable(tls *libc.TLS, pParse uintptr, pTab uintptr) {
	var pToplevel uintptr = func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}()
	var i int32
	var n int32
	var apVtabLock uintptr

	for i = 0; i < (*Parse)(unsafe.Pointer(pToplevel)).FnVtabLock; i++ {
		if pTab == *(*uintptr)(unsafe.Pointer((*Parse)(unsafe.Pointer(pToplevel)).FapVtabLock + uintptr(i)*8)) {
			return
		}
	}
	n = int32(uint64((*Parse)(unsafe.Pointer(pToplevel)).FnVtabLock+1) * uint64(unsafe.Sizeof(uintptr(0))))
	apVtabLock = Xsqlite3Realloc(tls, (*Parse)(unsafe.Pointer(pToplevel)).FapVtabLock, uint64(n))
	if apVtabLock != 0 {
		(*Parse)(unsafe.Pointer(pToplevel)).FapVtabLock = apVtabLock
		*(*uintptr)(unsafe.Pointer((*Parse)(unsafe.Pointer(pToplevel)).FapVtabLock + uintptr(libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pToplevel)).FnVtabLock, 1))*8)) = pTab
	} else {
		Xsqlite3OomFault(tls, (*Parse)(unsafe.Pointer(pToplevel)).Fdb)
	}
}

func Xsqlite3VtabEponymousTableInit(tls *libc.TLS, pParse uintptr, pMod uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pModule uintptr = (*Module)(unsafe.Pointer(pMod)).FpModule
	var pTab uintptr
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	var rc int32
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if (*Module)(unsafe.Pointer(pMod)).FpEpoTab != 0 {
		return 1
	}
	if (*Sqlite3_module)(unsafe.Pointer(pModule)).FxCreate != uintptr(0) && (*Sqlite3_module)(unsafe.Pointer(pModule)).FxCreate != (*Sqlite3_module)(unsafe.Pointer(pModule)).FxConnect {
		return 0
	}
	pTab = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Table{})))
	if pTab == uintptr(0) {
		return 0
	}
	(*Table)(unsafe.Pointer(pTab)).FzName = Xsqlite3DbStrDup(tls, db, (*Module)(unsafe.Pointer(pMod)).FzName)
	if (*Table)(unsafe.Pointer(pTab)).FzName == uintptr(0) {
		Xsqlite3DbFree(tls, db, pTab)
		return 0
	}
	(*Module)(unsafe.Pointer(pMod)).FpEpoTab = pTab
	(*Table)(unsafe.Pointer(pTab)).FnTabRef = U32(1)
	(*Table)(unsafe.Pointer(pTab)).FeTabType = U8(TABTYP_VTAB)
	(*Table)(unsafe.Pointer(pTab)).FpSchema = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema

	(*Table)(unsafe.Pointer(pTab)).FiPKey = int16(-1)
	*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_Eponymous)
	addModuleArgument(tls, pParse, pTab, Xsqlite3DbStrDup(tls, db, (*Table)(unsafe.Pointer(pTab)).FzName))
	addModuleArgument(tls, pParse, pTab, uintptr(0))
	addModuleArgument(tls, pParse, pTab, Xsqlite3DbStrDup(tls, db, (*Table)(unsafe.Pointer(pTab)).FzName))
	rc = vtabCallConstructor(tls, db, pTab, pMod, (*Sqlite3_module)(unsafe.Pointer(pModule)).FxConnect, bp+8)
	if rc != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+1684, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(bp + 8))))
		Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8)))
		Xsqlite3VtabEponymousTableClear(tls, db, pMod)
	}
	return 1
}

func Xsqlite3VtabEponymousTableClear(tls *libc.TLS, db uintptr, pMod uintptr) {
	var pTab uintptr = (*Module)(unsafe.Pointer(pMod)).FpEpoTab
	if pTab != uintptr(0) {
		*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_Ephemeral)
		Xsqlite3DeleteTable(tls, db, pTab)
		(*Module)(unsafe.Pointer(pMod)).FpEpoTab = uintptr(0)
	}
}

func Xsqlite3_vtab_on_conflict(tls *libc.TLS, db uintptr) int32 {
	return int32(aMap[int32((*Sqlite3)(unsafe.Pointer(db)).FvtabOnConflict)-1])
}

var aMap = [5]uint8{
	uint8(SQLITE_ROLLBACK), uint8(SQLITE_ABORT), uint8(SQLITE_FAIL), uint8(SQLITE_IGNORE), uint8(SQLITE_REPLACE),
}

func Xsqlite3_vtab_config(tls *libc.TLS, db uintptr, op int32, va uintptr) int32 {
	var ap Va_list
	_ = ap
	var rc int32 = SQLITE_OK
	var p uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	p = (*Sqlite3)(unsafe.Pointer(db)).FpVtabCtx
	if !(p != 0) {
		rc = Xsqlite3MisuseError(tls, 151593)
	} else {
		ap = va
		switch op {
		case SQLITE_VTAB_CONSTRAINT_SUPPORT:
			{
				(*VTable)(unsafe.Pointer((*VtabCtx)(unsafe.Pointer(p)).FpVTable)).FbConstraint = U8(libc.VaInt32(&ap))
				break

			}
			fallthrough
		case SQLITE_VTAB_INNOCUOUS:
			{
				(*VTable)(unsafe.Pointer((*VtabCtx)(unsafe.Pointer(p)).FpVTable)).FeVtabRisk = U8(SQLITE_VTABRISK_Low)
				break

			}
			fallthrough
		case SQLITE_VTAB_DIRECTONLY:
			{
				(*VTable)(unsafe.Pointer((*VtabCtx)(unsafe.Pointer(p)).FpVTable)).FeVtabRisk = U8(SQLITE_VTABRISK_High)
				break

			}
			fallthrough
		default:
			{
				rc = Xsqlite3MisuseError(tls, 151611)
				break

			}
		}
		_ = ap
	}

	if rc != SQLITE_OK {
		Xsqlite3Error(tls, db, rc)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

type WhereClause1 = struct {
	FpWInfo      uintptr
	FpOuter      uintptr
	Fop          U8
	FhasOr       U8
	F__ccgo_pad1 [2]byte
	FnTerm       int32
	FnSlot       int32
	FnBase       int32
	Fa           uintptr
	FaStatic     [8]WhereTerm
}

type WhereClause = WhereClause1
type WhereMaskSet1 = struct {
	FbVarSelect int32
	Fn          int32
	Fix         [64]int32
}

type WhereMaskSet = WhereMaskSet1
type WhereOrInfo1 = struct {
	Fwc        WhereClause
	Findexable Bitmask
}

type WhereOrInfo = WhereOrInfo1
type WhereAndInfo1 = struct{ Fwc WhereClause }

type WhereAndInfo = WhereAndInfo1
type WhereLevel1 = struct {
	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       U8
	Fop          U8
	Fp3          U8
	Fp5          U8
	Fp1          int32
	Fp2          int32
	F__ccgo_pad1 [4]byte
	Fu           struct {
		Fin struct {
			FnIn         int32
			F__ccgo_pad1 [4]byte
			FaInLoop     uintptr
		}
	}
	FpWLoop   uintptr
	FnotReady Bitmask
}

type WhereLevel = WhereLevel1
type WhereLoop1 = struct {
	Fprereq   Bitmask
	FmaskSelf Bitmask
	FiTab     U8
	FiSortIdx U8
	FrSetup   LogEst
	FrRun     LogEst
	FnOut     LogEst
	Fu        struct {
		Fbtree struct {
			FnEq          U16
			FnBtm         U16
			FnTop         U16
			FnDistinctCol U16
			FpIndex       uintptr
		}
		F__ccgo_pad1 [16]byte
	}
	FwsFlags     U32
	FnLTerm      U16
	FnSkip       U16
	FnLSlot      U16
	F__ccgo_pad1 [6]byte
	FaLTerm      uintptr
	FpNextLoop   uintptr
	FaLTermSpace [3]uintptr
}

type WhereLoop = WhereLoop1
type WherePath1 = struct {
	FmaskLoop    Bitmask
	FrevLoop     Bitmask
	FnRow        LogEst
	FrCost       LogEst
	FrUnsorted   LogEst
	FisOrdered   I8
	F__ccgo_pad1 [1]byte
	FaLoop       uintptr
}

type WherePath = WherePath1
type WhereTerm1 = struct {
	FpExpr      uintptr
	FpWC        uintptr
	FtruthProb  LogEst
	FwtFlags    U16
	FeOperator  U16
	FnChild     U8
	FeMatchOp   U8
	FiParent    int32
	FleftCursor int32
	Fu          struct {
		F__ccgo_pad1 [0]uint64
		Fx           struct {
			FleftColumn int32
			FiField     int32
		}
	}
	FprereqRight Bitmask
	FprereqAll   Bitmask
}

type WhereTerm = WhereTerm1
type WhereLoopBuilder1 = struct {
	FpWInfo      uintptr
	FpWC         uintptr
	FpNew        uintptr
	FpOrSet      uintptr
	FpRec        uintptr
	FnRecValid   int32
	FbldFlags1   uint8
	FbldFlags2   uint8
	F__ccgo_pad1 [2]byte
	FiPlanLimit  uint32
	F__ccgo_pad2 [4]byte
}

type WhereLoopBuilder = WhereLoopBuilder1
type WhereScan1 = struct {
	FpOrigWC     uintptr
	FpWC         uintptr
	FzCollName   uintptr
	FpIdxExpr    uintptr
	Fk           int32
	FopMask      U32
	Fidxaff      uint8
	FiEquiv      uint8
	FnEquiv      uint8
	F__ccgo_pad1 [1]byte
	FaiCur       [11]int32
	FaiColumn    [11]I16
	F__ccgo_pad2 [2]byte
}

type WhereScan = WhereScan1
type WhereOrCost1 = struct {
	Fprereq      Bitmask
	FrRun        LogEst
	FnOut        LogEst
	F__ccgo_pad1 [4]byte
}

type WhereOrCost = WhereOrCost1
type WhereOrSet1 = struct {
	Fn           U16
	F__ccgo_pad1 [6]byte
	Fa           [3]WhereOrCost
}

type WhereOrSet = WhereOrSet1
type WhereMemBlock1 = struct {
	FpNext uintptr
	Fsz    U64
}

type WhereMemBlock = WhereMemBlock1
type WhereRightJoin1 = struct {
	FiMatch     int32
	FregBloom   int32
	FregReturn  int32
	FaddrSubrtn int32
	FendSubrtn  int32
}

type WhereRightJoin = WhereRightJoin1

type InLoop = struct {
	FiCur        int32
	FaddrInTop   int32
	FiBase       int32
	FnPrefix     int32
	FeEndLoopOp  U8
	F__ccgo_pad1 [3]byte
}

func explainIndexColumnName(tls *libc.TLS, pIdx uintptr, i int32) uintptr {
	i = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
	if i == -2 {
		return ts + 25867
	}
	if i == -1 {
		return ts + 11466
	}
	return (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(i)*24)).FzCnName
}

func explainAppendTerm(tls *libc.TLS, pStr uintptr, pIdx uintptr, nTerm int32, iTerm int32, bAnd int32, zOp uintptr) {
	var i int32

	if bAnd != 0 {
		Xsqlite3_str_append(tls, pStr, ts+25874, 5)
	}

	if nTerm > 1 {
		Xsqlite3_str_append(tls, pStr, ts+25880, 1)
	}
	for i = 0; i < nTerm; i++ {
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, ts+16195, 1)
		}
		Xsqlite3_str_appendall(tls, pStr, explainIndexColumnName(tls, pIdx, iTerm+i))
	}
	if nTerm > 1 {
		Xsqlite3_str_append(tls, pStr, ts+7885, 1)
	}

	Xsqlite3_str_append(tls, pStr, zOp, 1)

	if nTerm > 1 {
		Xsqlite3_str_append(tls, pStr, ts+25880, 1)
	}
	for i = 0; i < nTerm; i++ {
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, ts+16195, 1)
		}
		Xsqlite3_str_append(tls, pStr, ts+7933, 1)
	}
	if nTerm > 1 {
		Xsqlite3_str_append(tls, pStr, ts+7885, 1)
	}
}

func explainIndexRange(tls *libc.TLS, pStr uintptr, pLoop uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pIndex uintptr = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))
	var nEq U16 = *(*U16)(unsafe.Pointer(pLoop + 24))
	var nSkip U16 = (*WhereLoop)(unsafe.Pointer(pLoop)).FnSkip
	var i int32
	var j int32

	if int32(nEq) == 0 && (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT) == U32(0) {
		return
	}
	Xsqlite3_str_append(tls, pStr, ts+25882, 2)
	for i = 0; i < int32(nEq); i++ {
		var z uintptr = explainIndexColumnName(tls, pIndex, i)
		if i != 0 {
			Xsqlite3_str_append(tls, pStr, ts+25874, 5)
		}
		Xsqlite3_str_appendf(tls, pStr, func() uintptr {
			if i >= int32(nSkip) {
				return ts + 25885
			}
			return ts + 25890
		}(), libc.VaList(bp, z))
	}

	j = i
	if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_BTM_LIMIT) != 0 {
		explainAppendTerm(tls, pStr, pIndex, int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 2))), j, i, ts+25898)
		i = 1
	}
	if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_TOP_LIMIT) != 0 {
		explainAppendTerm(tls, pStr, pIndex, int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 4))), j, i, ts+25900)
	}
	Xsqlite3_str_append(tls, pStr, ts+7885, 1)
}

func Xsqlite3WhereExplainOneScan(tls *libc.TLS, pParse uintptr, pTabList uintptr, pLevel uintptr, wctrlFlags U16) int32 {
	bp := tls.Alloc(196)
	defer tls.Free(196)

	var ret int32 = 0
	if int32((*Parse)(unsafe.Pointer(func() uintptr {
		if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
			return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
		}
		return pParse
	}())).Fexplain) == 2 {
		var pItem uintptr = pTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104
		var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		var isSearch int32
		var pLoop uintptr
		var flags U32
		var zMsg uintptr

		pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		flags = (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags
		if flags&U32(WHERE_MULTI_OR) != 0 || int32(wctrlFlags)&WHERE_OR_SUBCLAUSE != 0 {
			return 0
		}

		isSearch = libc.Bool32(flags&U32(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT) != U32(0) ||
			flags&U32(WHERE_VIRTUALTABLE) == U32(0) && int32(*(*U16)(unsafe.Pointer(pLoop + 24))) > 0 ||
			int32(wctrlFlags)&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX) != 0)

		Xsqlite3StrAccumInit(tls, bp+64, db, bp+96, int32(unsafe.Sizeof([100]uint8{})), SQLITE_MAX_LENGTH)
		(*StrAccum)(unsafe.Pointer(bp + 64)).FprintfFlags = U8(SQLITE_PRINTF_INTERNAL)
		Xsqlite3_str_appendf(tls, bp+64, ts+25902, libc.VaList(bp, func() uintptr {
			if isSearch != 0 {
				return ts + 25908
			}
			return ts + 25915
		}(), pItem))
		if flags&U32(WHERE_IPK|WHERE_VIRTUALTABLE) == U32(0) {
			var zFmt uintptr = uintptr(0)
			var pIdx uintptr

			pIdx = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))

			if !((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) && int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
				if isSearch != 0 {
					zFmt = ts + 14360
				}
			} else if flags&U32(WHERE_PARTIALIDX) != 0 {
				zFmt = ts + 25920
			} else if flags&U32(WHERE_AUTO_INDEX) != 0 {
				zFmt = ts + 25953
			} else if flags&U32(WHERE_IDX_ONLY) != 0 {
				zFmt = ts + 25978
			} else {
				zFmt = ts + 25996
			}
			if zFmt != 0 {
				Xsqlite3_str_append(tls, bp+64, ts+26005, 7)
				Xsqlite3_str_appendf(tls, bp+64, zFmt, libc.VaList(bp+16, (*Index)(unsafe.Pointer(pIdx)).FzName))
				explainIndexRange(tls, bp+64, pLoop)
			}
		} else if flags&U32(WHERE_IPK) != U32(0) && flags&U32(WHERE_CONSTRAINT) != U32(0) {
			var cRangeOp uint8
			var zRowid uintptr = ts + 11466
			Xsqlite3_str_appendf(tls, bp+64, ts+26013, libc.VaList(bp+24, zRowid))
			if flags&U32(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) != 0 {
				cRangeOp = uint8('=')
			} else if flags&U32(WHERE_BOTH_LIMIT) == U32(WHERE_BOTH_LIMIT) {
				Xsqlite3_str_appendf(tls, bp+64, ts+26044, libc.VaList(bp+32, zRowid))
				cRangeOp = uint8('<')
			} else if flags&U32(WHERE_BTM_LIMIT) != 0 {
				cRangeOp = uint8('>')
			} else {
				cRangeOp = uint8('<')
			}
			Xsqlite3_str_appendf(tls, bp+64, ts+26054, libc.VaList(bp+40, int32(cRangeOp)))
		} else if flags&U32(WHERE_VIRTUALTABLE) != U32(0) {
			Xsqlite3_str_appendf(tls, bp+64, ts+26059,
				libc.VaList(bp+48, *(*int32)(unsafe.Pointer(pLoop + 24)), *(*uintptr)(unsafe.Pointer(pLoop + 24 + 16))))
		}
		if int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&JT_LEFT != 0 {
			Xsqlite3_str_appendf(tls, bp+64, ts+26086, 0)
		}
		zMsg = Xsqlite3StrAccumFinish(tls, bp+64)

		ret = Xsqlite3VdbeAddOp4(tls, v, OP_Explain, Xsqlite3VdbeCurrentAddr(tls, v),
			(*Parse)(unsafe.Pointer(pParse)).FaddrExplain, 0, zMsg, -6)
	}
	return ret
}

func Xsqlite3WhereExplainBloomFilter(tls *libc.TLS, pParse uintptr, pWInfo uintptr, pLevel uintptr) int32 {
	bp := tls.Alloc(156)
	defer tls.Free(156)

	var ret int32 = 0
	var pItem uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var zMsg uintptr
	var i int32
	var pLoop uintptr

	Xsqlite3StrAccumInit(tls, bp+24, db, bp+56, int32(unsafe.Sizeof([100]uint8{})), SQLITE_MAX_LENGTH)
	(*StrAccum)(unsafe.Pointer(bp + 24)).FprintfFlags = U8(SQLITE_PRINTF_INTERNAL)
	Xsqlite3_str_appendf(tls, bp+24, ts+26097, libc.VaList(bp, pItem))
	pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IPK) != 0 {
		var pTab uintptr = (*SrcItem)(unsafe.Pointer(pItem)).FpTab
		if int32((*Table)(unsafe.Pointer(pTab)).FiPKey) >= 0 {
			Xsqlite3_str_appendf(tls, bp+24, ts+25885, libc.VaList(bp+8, (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr((*Table)(unsafe.Pointer(pTab)).FiPKey)*24)).FzCnName))
		} else {
			Xsqlite3_str_appendf(tls, bp+24, ts+26118, 0)
		}
	} else {
		for i = int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnSkip); i < int32(*(*U16)(unsafe.Pointer(pLoop + 24))); i++ {
			var z uintptr = explainIndexColumnName(tls, *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8)), i)
			if i > int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnSkip) {
				Xsqlite3_str_append(tls, bp+24, ts+25874, 5)
			}
			Xsqlite3_str_appendf(tls, bp+24, ts+25885, libc.VaList(bp+16, z))
		}
	}
	Xsqlite3_str_append(tls, bp+24, ts+7885, 1)
	zMsg = Xsqlite3StrAccumFinish(tls, bp+24)
	ret = Xsqlite3VdbeAddOp4(tls, v, OP_Explain, Xsqlite3VdbeCurrentAddr(tls, v),
		(*Parse)(unsafe.Pointer(pParse)).FaddrExplain, 0, zMsg, -6)

	return ret
}

func disableTerm(tls *libc.TLS, pLevel uintptr, pTerm uintptr) {
	var nLoop int32 = 0

	for int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_CODED == 0 &&
		((*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin == 0 || (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&U32(EP_OuterON) != U32(0)) &&
		(*WhereLevel)(unsafe.Pointer(pLevel)).FnotReady&(*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll == uint64(0) {
		if nLoop != 0 && int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_LIKE != 0 {
			*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_LIKECOND)
		} else {
			*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_CODED)
		}
		if (*WhereTerm)(unsafe.Pointer(pTerm)).FiParent < 0 {
			break
		}
		pTerm = (*WhereClause)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpWC)).Fa + uintptr((*WhereTerm)(unsafe.Pointer(pTerm)).FiParent)*56

		(*WhereTerm)(unsafe.Pointer(pTerm)).FnChild--
		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FnChild) != 0 {
			break
		}
		nLoop++
	}
}

func codeApplyAffinity(tls *libc.TLS, pParse uintptr, base int32, n int32, zAff uintptr) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	if zAff == uintptr(0) {
		return
	}

	for n > 0 && int32(*(*uint8)(unsafe.Pointer(zAff))) <= SQLITE_AFF_BLOB {
		n--
		base++
		zAff++
	}
	for n > 1 && int32(*(*uint8)(unsafe.Pointer(zAff + uintptr(n-1)))) <= SQLITE_AFF_BLOB {
		n--
	}

	if n > 0 {
		Xsqlite3VdbeAddOp4(tls, v, OP_Affinity, base, n, 0, zAff, n)
	}
}

func updateRangeAffinityStr(tls *libc.TLS, pRight uintptr, n int32, zAff uintptr) {
	var i int32
	for i = 0; i < n; i++ {
		var p uintptr = Xsqlite3VectorFieldSubexpr(tls, pRight, i)
		if int32(Xsqlite3CompareAffinity(tls, p, *(*uint8)(unsafe.Pointer(zAff + uintptr(i))))) == SQLITE_AFF_BLOB ||
			Xsqlite3ExprNeedsNoAffinityChange(tls, p, *(*uint8)(unsafe.Pointer(zAff + uintptr(i)))) != 0 {
			*(*uint8)(unsafe.Pointer(zAff + uintptr(i))) = uint8(SQLITE_AFF_BLOB)
		}
	}
}

func removeUnindexableInClauseTerms(tls *libc.TLS, pParse uintptr, iEq int32, pLoop uintptr, pX uintptr) uintptr {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pSelect uintptr
	var pNew uintptr
	pNew = Xsqlite3ExprDup(tls, db, pX, 0)
	if int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) == 0 {
		for pSelect = *(*uintptr)(unsafe.Pointer(pNew + 32)); pSelect != 0; pSelect = (*Select)(unsafe.Pointer(pSelect)).FpPrior {
			var pOrigRhs uintptr
			var pOrigLhs uintptr = uintptr(0)
			var pRhs uintptr = uintptr(0)
			var pLhs uintptr = uintptr(0)
			var i int32

			pOrigRhs = (*Select)(unsafe.Pointer(pSelect)).FpEList

			if pSelect == *(*uintptr)(unsafe.Pointer(pNew + 32)) {
				pOrigLhs = *(*uintptr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pNew)).FpLeft + 32))
			}
			for i = iEq; i < int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm); i++ {
				if (*WhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*8)))).FpExpr == pX {
					var iField int32

					iField = *(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*8)) + 32 + 4)) - 1
					if (*ExprList_item)(unsafe.Pointer(pOrigRhs+8+uintptr(iField)*32)).FpExpr == uintptr(0) {
						continue
					}
					pRhs = Xsqlite3ExprListAppend(tls, pParse, pRhs, (*ExprList_item)(unsafe.Pointer(pOrigRhs+8+uintptr(iField)*32)).FpExpr)
					(*ExprList_item)(unsafe.Pointer(pOrigRhs + 8 + uintptr(iField)*32)).FpExpr = uintptr(0)
					if pOrigLhs != 0 {
						pLhs = Xsqlite3ExprListAppend(tls, pParse, pLhs, (*ExprList_item)(unsafe.Pointer(pOrigLhs+8+uintptr(iField)*32)).FpExpr)
						(*ExprList_item)(unsafe.Pointer(pOrigLhs + 8 + uintptr(iField)*32)).FpExpr = uintptr(0)
					}
				}
			}
			Xsqlite3ExprListDelete(tls, db, pOrigRhs)
			if pOrigLhs != 0 {
				Xsqlite3ExprListDelete(tls, db, pOrigLhs)
				*(*uintptr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pNew)).FpLeft + 32)) = pLhs
			}
			(*Select)(unsafe.Pointer(pSelect)).FpEList = pRhs
			if pLhs != 0 && (*ExprList)(unsafe.Pointer(pLhs)).FnExpr == 1 {
				var p uintptr = (*ExprList_item)(unsafe.Pointer(pLhs + 8)).FpExpr
				(*ExprList_item)(unsafe.Pointer(pLhs + 8)).FpExpr = uintptr(0)
				Xsqlite3ExprDelete(tls, db, (*Expr)(unsafe.Pointer(pNew)).FpLeft)
				(*Expr)(unsafe.Pointer(pNew)).FpLeft = p
			}
			if (*Select)(unsafe.Pointer(pSelect)).FpOrderBy != 0 {
				var pOrderBy uintptr = (*Select)(unsafe.Pointer(pSelect)).FpOrderBy
				for i = 0; i < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr; i++ {
					*(*U16)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32 + 24)) = U16(0)
				}
			}

		}
	}
	return pNew
}

func codeEqualityTerm(tls *libc.TLS, pParse uintptr, pTerm uintptr, pLevel uintptr, iEq int32, bRev int32, iTarget int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pX uintptr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var iReg int32

	if int32((*Expr)(unsafe.Pointer(pX)).Fop) == TK_EQ || int32((*Expr)(unsafe.Pointer(pX)).Fop) == TK_IS {
		iReg = Xsqlite3ExprCodeTarget(tls, pParse, (*Expr)(unsafe.Pointer(pX)).FpRight, iTarget)
	} else if int32((*Expr)(unsafe.Pointer(pX)).Fop) == TK_ISNULL {
		iReg = iTarget
		Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, iReg)
	} else {
		var eType int32 = IN_INDEX_NOOP

		var pIn uintptr
		var pLoop uintptr = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		var i int32
		var nEq int32 = 0
		var aiMap uintptr = uintptr(0)

		if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_VIRTUALTABLE) == U32(0) &&
			*(*uintptr)(unsafe.Pointer(pLoop + 24 + 8)) != uintptr(0) &&
			*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLoop + 24 + 8)))).FaSortOrder + uintptr(iEq))) != 0 {
			bRev = libc.BoolInt32(!(bRev != 0))
		}

		iReg = iTarget

		for i = 0; i < iEq; i++ {
			if *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*8)) != 0 && (*WhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*8)))).FpExpr == pX {
				disableTerm(tls, pLevel, pTerm)
				return iTarget
			}
		}
		for i = iEq; i < int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm); i++ {
			if (*WhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*8)))).FpExpr == pX {
				nEq++
			}
		}

		*(*int32)(unsafe.Pointer(bp)) = 0
		if !((*Expr)(unsafe.Pointer(pX)).Fflags&U32(EP_xIsSelect) != U32(0)) || (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pX + 32)))).FpEList)).FnExpr == 1 {
			eType = Xsqlite3FindInIndex(tls, pParse, pX, uint32(IN_INDEX_LOOP), uintptr(0), uintptr(0), bp)
		} else {
			var pExpr uintptr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if (*Expr)(unsafe.Pointer(pExpr)).FiTable == 0 || !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Subrtn) != U32(0)) {
				var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
				pX = removeUnindexableInClauseTerms(tls, pParse, iEq, pLoop, pX)
				if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
					aiMap = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(int32(0)))*uint64(nEq))
					eType = Xsqlite3FindInIndex(tls, pParse, pX, uint32(IN_INDEX_LOOP), uintptr(0), aiMap, bp)
					(*Expr)(unsafe.Pointer(pExpr)).FiTable = *(*int32)(unsafe.Pointer(bp))
				}
				Xsqlite3ExprDelete(tls, db, pX)
			} else {
				var n int32 = Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pX)).FpLeft)
				aiMap = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(int32(0)))*func() uint64 {
					if nEq > n {
						return uint64(nEq)
					}
					return uint64(n)
				}())
				eType = Xsqlite3FindInIndex(tls, pParse, pX, uint32(IN_INDEX_LOOP), uintptr(0), aiMap, bp)
			}
			pX = pExpr
		}

		if eType == IN_INDEX_INDEX_DESC {
			bRev = libc.BoolInt32(!(bRev != 0))
		}
		Xsqlite3VdbeAddOp2(tls, v, func() int32 {
			if bRev != 0 {
				return OP_Last
			}
			return OP_Rewind
		}(), *(*int32)(unsafe.Pointer(bp)), 0)

		*(*U32)(unsafe.Pointer(pLoop + 56)) |= U32(WHERE_IN_ABLE)
		if *(*int32)(unsafe.Pointer(pLevel + 72)) == 0 {
			(*WhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt = Xsqlite3VdbeMakeLabel(tls, pParse)
		}
		if iEq > 0 && (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IN_SEEKSCAN) == U32(0) {
			*(*U32)(unsafe.Pointer(pLoop + 56)) |= U32(WHERE_IN_EARLYOUT)
		}

		i = *(*int32)(unsafe.Pointer(pLevel + 72))
		*(*int32)(unsafe.Pointer(pLevel + 72)) += nEq
		*(*uintptr)(unsafe.Pointer(pLevel + 72 + 8)) = Xsqlite3WhereRealloc(tls, (*WhereClause)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpWC)).FpWInfo,
			*(*uintptr)(unsafe.Pointer(pLevel + 72 + 8)),
			uint64(unsafe.Sizeof(InLoop{}))*uint64(*(*int32)(unsafe.Pointer(pLevel + 72))))
		pIn = *(*uintptr)(unsafe.Pointer(pLevel + 72 + 8))
		if pIn != 0 {
			var iMap int32 = 0
			pIn += 20 * uintptr(i)
			for i = iEq; i < int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm); i++ {
				if (*WhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*8)))).FpExpr == pX {
					var iOut int32 = iReg + i - iEq
					if eType == IN_INDEX_ROWID {
						*(*int32)(unsafe.Pointer(pIn + 4)) = Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, *(*int32)(unsafe.Pointer(bp)), iOut)
					} else {
						var iCol int32
						if aiMap != 0 {
							iCol = *(*int32)(unsafe.Pointer(aiMap + uintptr(libc.PostIncInt32(&iMap, 1))*4))
						} else {
							iCol = 0
						}
						*(*int32)(unsafe.Pointer(pIn + 4)) = Xsqlite3VdbeAddOp3(tls, v, OP_Column, *(*int32)(unsafe.Pointer(bp)), iCol, iOut)
					}
					Xsqlite3VdbeAddOp1(tls, v, OP_IsNull, iOut)
					if i == iEq {
						*(*int32)(unsafe.Pointer(pIn)) = *(*int32)(unsafe.Pointer(bp))
						*(*U8)(unsafe.Pointer(pIn + 16)) = func() uint8 {
							if bRev != 0 {
								return uint8(OP_Prev)
							}
							return uint8(OP_Next)
						}()
						if iEq > 0 {
							*(*int32)(unsafe.Pointer(pIn + 8)) = iReg - i
							*(*int32)(unsafe.Pointer(pIn + 12)) = i
						} else {
							*(*int32)(unsafe.Pointer(pIn + 12)) = 0
						}
					} else {
						*(*U8)(unsafe.Pointer(pIn + 16)) = U8(OP_Noop)
					}
					pIn += 20
				}
			}

			if iEq > 0 &&
				(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IN_SEEKSCAN|WHERE_VIRTUALTABLE) == U32(0) {
				Xsqlite3VdbeAddOp3(tls, v, OP_SeekHit, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, 0, iEq)
			}
		} else {
			*(*int32)(unsafe.Pointer(pLevel + 72)) = 0
		}
		Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, aiMap)
	}

	if (*WhereLoop1)(unsafe.Pointer((*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FwsFlags&U32(WHERE_TRANSCONS) == U32(0) ||
		int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_EQUIV == 0 {
		disableTerm(tls, pLevel, pTerm)
	}

	return iReg
}

func codeAllEqualityTerms(tls *libc.TLS, pParse uintptr, pLevel uintptr, bRev int32, nExtraReg int32, pzAff uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var nEq U16
	var nSkip U16
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var pIdx uintptr
	var pTerm uintptr
	var pLoop uintptr
	var j int32
	var regBase int32
	var nReg int32
	var zAff uintptr

	pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop

	nEq = *(*U16)(unsafe.Pointer(pLoop + 24))
	nSkip = (*WhereLoop)(unsafe.Pointer(pLoop)).FnSkip
	pIdx = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))

	regBase = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	nReg = int32(*(*U16)(unsafe.Pointer(pLoop + 24))) + nExtraReg
	*(*int32)(unsafe.Pointer(pParse + 56)) += nReg

	zAff = Xsqlite3DbStrDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, Xsqlite3IndexAffinityStr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pIdx))

	if nSkip != 0 {
		var iIdxCur int32 = (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
		Xsqlite3VdbeAddOp3(tls, v, OP_Null, 0, regBase, regBase+int32(nSkip)-1)
		Xsqlite3VdbeAddOp1(tls, v, func() int32 {
			if bRev != 0 {
				return OP_Last
			}
			return OP_Rewind
		}(), iIdxCur)

		Xsqlite3VdbeComment(tls, v, ts+26126, libc.VaList(bp, (*Index)(unsafe.Pointer(pIdx)).FzName))
		j = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)

		(*WhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip = Xsqlite3VdbeAddOp4Int(tls, v, func() int32 {
			if bRev != 0 {
				return OP_SeekLT
			}
			return OP_SeekGT
		}(),
			iIdxCur, 0, regBase, int32(nSkip))

		Xsqlite3VdbeJumpHere(tls, v, j)
		for j = 0; j < int32(nSkip); j++ {
			Xsqlite3VdbeAddOp3(tls, v, OP_Column, iIdxCur, j, regBase+j)

			Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+8, explainIndexColumnName(tls, pIdx, j)))
		}
	}

	for j = int32(nSkip); j < int32(nEq); j++ {
		var r1 int32
		pTerm = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))

		r1 = codeEqualityTerm(tls, pParse, pTerm, pLevel, j, bRev, regBase+j)
		if r1 != regBase+j {
			if nReg == 1 {
				Xsqlite3ReleaseTempReg(tls, pParse, regBase)
				regBase = r1
			} else {
				Xsqlite3VdbeAddOp2(tls, v, OP_Copy, r1, regBase+j)
			}
		}
	}
	for j = int32(nSkip); j < int32(nEq); j++ {
		pTerm = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))
		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_IN != 0 {
			if (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&U32(EP_xIsSelect) != 0 {
				if zAff != 0 {
					*(*uint8)(unsafe.Pointer(zAff + uintptr(j))) = uint8(SQLITE_AFF_BLOB)
				}
			}
		} else if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_ISNULL == 0 {
			var pRight uintptr = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
			if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_IS == 0 && Xsqlite3ExprCanBeNull(tls, pRight) != 0 {
				Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, regBase+j, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)

			}
			if (*Parse)(unsafe.Pointer(pParse)).FnErr == 0 {
				if int32(Xsqlite3CompareAffinity(tls, pRight, *(*uint8)(unsafe.Pointer(zAff + uintptr(j))))) == SQLITE_AFF_BLOB {
					*(*uint8)(unsafe.Pointer(zAff + uintptr(j))) = uint8(SQLITE_AFF_BLOB)
				}
				if Xsqlite3ExprNeedsNoAffinityChange(tls, pRight, *(*uint8)(unsafe.Pointer(zAff + uintptr(j)))) != 0 {
					*(*uint8)(unsafe.Pointer(zAff + uintptr(j))) = uint8(SQLITE_AFF_BLOB)
				}
			}
		}
	}
	*(*uintptr)(unsafe.Pointer(pzAff)) = zAff
	return regBase
}

func codeDeferredSeek(tls *libc.TLS, pWInfo uintptr, pIdx uintptr, iCur int32, iIdxCur int32) {
	var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	libc.SetBitFieldPtr8Uint32(pWInfo+68, uint32(1), 0, 0x1)
	Xsqlite3VdbeAddOp3(tls, v, OP_DeferredSeek, iIdxCur, 0, iCur)
	if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN) != 0 &&
		(*Parse)(unsafe.Pointer(func() uintptr {
			if (*Parse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
				return (*Parse)(unsafe.Pointer(pParse)).FpToplevel
			}
			return pParse
		}())).FwriteMask == YDbMask(0) {
		var i int32
		var pTab uintptr = (*Index)(unsafe.Pointer(pIdx)).FpTable
		var ai uintptr = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(U32(0)))*uint64(int32((*Table)(unsafe.Pointer(pTab)).FnCol)+1))
		if ai != 0 {
			*(*U32)(unsafe.Pointer(ai)) = U32((*Table)(unsafe.Pointer(pTab)).FnCol)
			for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)-1; i++ {
				var x1 int32
				var x2 int32

				x1 = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
				x2 = int32(Xsqlite3TableColumnToStorage(tls, pTab, int16(x1)))

				if x1 >= 0 {
					*(*U32)(unsafe.Pointer(ai + uintptr(x2+1)*4)) = U32(i + 1)
				}
			}
			Xsqlite3VdbeChangeP4(tls, v, -1, ai, -14)
		}
	}
}

func codeExprOrVector(tls *libc.TLS, pParse uintptr, p uintptr, iReg int32, nReg int32) {
	if p != 0 && Xsqlite3ExprIsVector(tls, p) != 0 {
		if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_xIsSelect) != U32(0) {
			var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
			var iSelect int32

			iSelect = Xsqlite3CodeSubselect(tls, pParse, p)
			Xsqlite3VdbeAddOp3(tls, v, OP_Copy, iSelect, iReg, nReg-1)
		} else {
			var i int32
			var pList uintptr

			pList = *(*uintptr)(unsafe.Pointer(p + 32))

			for i = 0; i < nReg; i++ {
				Xsqlite3ExprCode(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr, iReg+i)
			}
		}
	} else {
		Xsqlite3ExprCode(tls, pParse, p, iReg)
	}
}

func whereApplyPartialIndexConstraints(tls *libc.TLS, pTruth uintptr, iTabCur int32, pWC uintptr) {
	var i int32
	var pTerm uintptr
	for int32((*Expr)(unsafe.Pointer(pTruth)).Fop) == TK_AND {
		whereApplyPartialIndexConstraints(tls, (*Expr)(unsafe.Pointer(pTruth)).FpLeft, iTabCur, pWC)
		pTruth = (*Expr)(unsafe.Pointer(pTruth)).FpRight
	}
	i = 0
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
__1:
	if !(i < (*WhereClause)(unsafe.Pointer(pWC)).FnTerm) {
		goto __3
	}
	{
		var pExpr uintptr
		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_CODED != 0 {
			goto __2
		}
		pExpr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
		if Xsqlite3ExprCompare(tls, uintptr(0), pExpr, pTruth, iTabCur) == 0 {
			*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_CODED)
		}

	}
	goto __2
__2:
	i++
	pTerm += 56
	goto __1
	goto __3
__3:
}

func filterPullDown(tls *libc.TLS, pParse uintptr, pWInfo uintptr, iLevel int32, addrNxt int32, notReady Bitmask) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	for libc.PreIncInt32(&iLevel, 1) < int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) {
		var pLevel uintptr = pWInfo + 856 + uintptr(iLevel)*104
		var pLoop uintptr = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		if (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter == 0 {
			continue
		}
		if (*WhereLoop1)(unsafe.Pointer((*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FnSkip != 0 {
			continue
		}

		if (*WhereLoop)(unsafe.Pointer(pLoop)).Fprereq&notReady != 0 {
			continue
		}

		(*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk = addrNxt
		if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IPK) != 0 {
			var pTerm uintptr = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))
			var regRowid int32

			regRowid = Xsqlite3GetTempReg(tls, pParse)
			regRowid = codeEqualityTerm(tls, pParse, pTerm, pLevel, 0, 0, regRowid)
			Xsqlite3VdbeAddOp2(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, OP_MustBeInt, regRowid, addrNxt)

			Xsqlite3VdbeAddOp4Int(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, OP_Filter, (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter,
				addrNxt, regRowid, 1)

		} else {
			var nEq U16 = *(*U16)(unsafe.Pointer(pLoop + 24))
			var r1 int32

			r1 = codeAllEqualityTerms(tls, pParse, pLevel, 0, 0, bp)
			codeApplyAffinity(tls, pParse, r1, int32(nEq), *(*uintptr)(unsafe.Pointer(bp)))
			Xsqlite3DbFree(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(bp)))
			Xsqlite3VdbeAddOp4Int(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, OP_Filter, (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter,
				addrNxt, r1, int32(nEq))

		}
		(*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter = 0
		(*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk = 0
	}
}

func Xsqlite3WhereCodeOneLoopStart(tls *libc.TLS, pParse uintptr, v uintptr, pWInfo uintptr, iLevel int32, pLevel uintptr, notReady Bitmask) Bitmask {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	var j int32
	var k int32
	var iCur int32
	var addrNxt int32
	var bRev int32
	var pLoop uintptr
	var pWC uintptr
	var pTerm uintptr
	var db uintptr
	var pTabItem uintptr
	var addrBrk int32
	var addrHalt int32
	var addrCont int32
	var iRowidReg int32
	var iReleaseReg int32
	var pIdx uintptr
	var iLoop int32
	var regYield int32
	var iTab int32
	var iCache int32
	var pRight uintptr
	var iTarget int32
	var iFld int32
	var pLeft uintptr
	var pCompare uintptr
	var pRight1 uintptr
	var pOp uintptr
	var iIn int32

	var iReg int32
	var addrNotFound int32
	var nConstraint int32
	var pX uintptr
	var r1 int32

	var op int32

	var pX1 uintptr

	var testOp int32
	var start int32
	var memEndValue int32
	var pStart uintptr
	var pEnd uintptr
	var t uintptr
	var t1 U8
	var t2 U8
	var pRight2 uintptr
	var pRight3 uintptr
	var pPk uintptr
	var nEq U16
	var nBtm U16
	var nTop U16
	var regBase int32
	var pRangeStart uintptr
	var pRangeEnd uintptr
	var startEq int32
	var endEq int32
	var start_constraints int32
	var nConstraint1 int32
	var iIdxCur int32
	var nExtraReg int32
	var op1 int32

	var zEndAff uintptr
	var bSeekPastNull U8
	var bStopAtNull U8
	var omitTable int32
	var regBignull int32
	var addrSeekScan int32
	var nNotReady int32
	var origSrc uintptr
	var pPk1 uintptr
	var pExpr uintptr
	var iTerm int32
	var iCol int32
	var pPk2 uintptr
	var nPk int32
	var iPk int32
	var r int32
	var iSet int32
	var pSubLoop uintptr
	var addrExplain int32
	_ = addrExplain
	var pSubWInfo uintptr
	var pOrExpr uintptr
	var pDelete uintptr
	var jmp1 int32
	var pOrTerm uintptr

	var pOrWc uintptr
	var pOrTab uintptr
	var pCov uintptr
	var iCovCur int32

	var regReturn int32
	var regRowset int32
	var regRowid int32
	var iLoopBody int32
	var iRetInit int32
	var untestedTerms int32
	var ii int32
	var pAndExpr uintptr
	var pTab uintptr
	var m Bitmask
	var pE uintptr
	var skipLikeAddr int32
	var iNext int32
	var pE1 uintptr

	var pAlt uintptr
	var iCol1 int32
	var iPk1 int32
	var pPk3 uintptr
	var pTab1 uintptr
	var nPk1 int32
	var r2 int32
	var jmp11 int32
	var pRJ uintptr

	var pRJ1 uintptr
	iRowidReg = 0
	iReleaseReg = 0
	pIdx = uintptr(0)

	pWC = pWInfo + 104
	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	pTabItem = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104
	iCur = (*SrcItem)(unsafe.Pointer(pTabItem)).FiCursor
	(*WhereLevel)(unsafe.Pointer(pLevel)).FnotReady = notReady & ^Xsqlite3WhereGetMask(tls, pWInfo+592, iCur)
	bRev = int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FrevMask >> iLevel & uint64(1))

	addrBrk = libc.AssignPtrInt32(pLevel+12, libc.AssignPtrInt32(pLevel+16, Xsqlite3VdbeMakeLabel(tls, pParse)))
	addrCont = libc.AssignPtrInt32(pLevel+24, Xsqlite3VdbeMakeLabel(tls, pParse))

	if !(int32((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom) > 0 && int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&JT_LEFT != 0) {
		goto __1
	}
	(*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
	Xsqlite3VdbeComment(tls, v, ts+26148, 0)
__1:
	;
	j = iLevel
__2:
	if !(j > 0) {
		goto __4
	}
	if !((*WhereLevel)(unsafe.Pointer(pWInfo+856+uintptr(j)*104)).FiLeftJoin != 0) {
		goto __5
	}
	goto __4
__5:
	;
	if !((*WhereLevel)(unsafe.Pointer(pWInfo+856+uintptr(j)*104)).FpRJ != 0) {
		goto __6
	}
	goto __4
__6:
	;
	goto __3
__3:
	j--
	goto __2
	goto __4
__4:
	;
	addrHalt = (*WhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(j)*104)).FaddrBrk

	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pTabItem + 60 + 4))&0x20>>5)) != 0) {
		goto __7
	}
	regYield = (*SrcItem)(unsafe.Pointer(pTabItem)).FregReturn
	Xsqlite3VdbeAddOp3(tls, v, OP_InitCoroutine, regYield, 0, (*SrcItem)(unsafe.Pointer(pTabItem)).FaddrFillSub)
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp2 = Xsqlite3VdbeAddOp2(tls, v, OP_Yield, regYield, addrBrk)

	Xsqlite3VdbeComment(tls, v, ts+26177, libc.VaList(bp, (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pTabItem)).FpTab)).FzName))
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = U8(OP_Goto)
	goto __8
__7:
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_VIRTUALTABLE) != U32(0)) {
		goto __9
	}
	nConstraint = int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm)

	iReg = Xsqlite3GetTempRange(tls, pParse, nConstraint+2)
	addrNotFound = (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk
	j = 0
__11:
	if !(j < nConstraint) {
		goto __13
	}
	iTarget = iReg + j + 2
	pTerm = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))
	if !(pTerm == uintptr(0)) {
		goto __14
	}
	goto __12
__14:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_IN != 0) {
		goto __15
	}
	if !(func() uint32 {
		if j <= 31 {
			return uint32(1) << j
		}
		return uint32(0)
	}()&*(*U32)(unsafe.Pointer(pLoop + 24 + 24)) != 0) {
		goto __17
	}
	iTab = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	iCache = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3CodeRhsOfIN(tls, pParse, (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr, iTab)
	Xsqlite3VdbeAddOp3(tls, v, OP_VInitIn, iTab, iTarget, iCache)
	goto __18
__17:
	codeEqualityTerm(tls, pParse, pTerm, pLevel, j, bRev, iTarget)
	addrNotFound = (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
__18:
	;
	goto __16
__15:
	pRight = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
	codeExprOrVector(tls, pParse, pRight, iTarget, 1)
	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) == SQLITE_INDEX_CONSTRAINT_OFFSET &&
		U32(int32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x2>>1)) != 0) {
		goto __19
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*Select)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FiOffset)
	Xsqlite3VdbeComment(tls, v, ts+26192, 0)
__19:
	;
__16:
	;
	goto __12
__12:
	j++
	goto __11
	goto __13
__13:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, *(*int32)(unsafe.Pointer(pLoop + 24)), iReg)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, nConstraint, iReg+1)
	Xsqlite3VdbeAddOp4(tls, v, OP_VFilter, iCur, addrNotFound, iReg,
		*(*uintptr)(unsafe.Pointer(pLoop + 24 + 16)),
		func() int32 {
			if U32(int32(*(*uint8)(unsafe.Pointer(pLoop + 24 + 4))&0x1>>0)) != 0 {
				return -6
			}
			return -1
		}())

	libc.SetBitFieldPtr8Uint32(pLoop+24+4, U32(0), 0, 0x1)

	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __20
	}
	*(*uintptr)(unsafe.Pointer(pLoop + 24 + 16)) = uintptr(0)
__20:
	;
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = func() uint8 {
		if (*WhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass != 0 {
			return uint8(OP_Noop)
		}
		return uint8(OP_VNext)
	}()
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp2 = Xsqlite3VdbeCurrentAddr(tls, v)

	j = 0
__21:
	if !(j < nConstraint) {
		goto __23
	}
	pTerm = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))
	if !(j < 16 && int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 8)))>>j&1 != 0) {
		goto __24
	}
	disableTerm(tls, pLevel, pTerm)
	goto __22
__24:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_IN != 0 &&
		func() uint32 {
			if j <= 31 {
				return uint32(1) << j
			}
			return uint32(0)
		}()&*(*U32)(unsafe.Pointer(pLoop + 24 + 24)) == uint32(0) &&
		!(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0)) {
		goto __25
	}

	iIn = 0
__26:
	if !(iIn < *(*int32)(unsafe.Pointer(pLevel + 72))) {
		goto __28
	}
	pOp = Xsqlite3VdbeGetOp(tls, v, *(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLevel + 72 + 8)) + uintptr(iIn)*20 + 4)))
	if !(int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Column && (*VdbeOp)(unsafe.Pointer(pOp)).Fp3 == iReg+j+2 ||
		int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Rowid && (*VdbeOp)(unsafe.Pointer(pOp)).Fp2 == iReg+j+2) {
		goto __29
	}

	Xsqlite3VdbeAddOp3(tls, v, int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode), (*VdbeOp)(unsafe.Pointer(pOp)).Fp1, (*VdbeOp)(unsafe.Pointer(pOp)).Fp2, (*VdbeOp)(unsafe.Pointer(pOp)).Fp3)
	goto __28
__29:
	;
	goto __27
__27:
	iIn++
	goto __26
	goto __28
__28:
	;
	pCompare = Xsqlite3PExpr(tls, pParse, TK_EQ, uintptr(0), uintptr(0))
	if !!(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
		goto __30
	}
	iFld = *(*int32)(unsafe.Pointer(pTerm + 32 + 4))
	pLeft = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft

	if !(iFld > 0) {
		goto __31
	}

	(*Expr)(unsafe.Pointer(pCompare)).FpLeft = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 32)) + 8 + uintptr(iFld-1)*32)).FpExpr
	goto __32
__31:
	(*Expr)(unsafe.Pointer(pCompare)).FpLeft = pLeft
__32:
	;
	(*Expr)(unsafe.Pointer(pCompare)).FpRight = libc.AssignUintptr(&pRight1, Xsqlite3Expr(tls, db, TK_REGISTER, uintptr(0)))
	if !(pRight1 != 0) {
		goto __33
	}
	(*Expr)(unsafe.Pointer(pRight1)).FiTable = iReg + j + 2
	Xsqlite3ExprIfFalse(tls,
		pParse, pCompare, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrCont, SQLITE_JUMPIFNULL)
__33:
	;
	(*Expr)(unsafe.Pointer(pCompare)).FpLeft = uintptr(0)
__30:
	;
	Xsqlite3ExprDelete(tls, db, pCompare)
__25:
	;
	goto __22
__22:
	j++
	goto __21
	goto __23
__23:
	;
	goto __10
__9:
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IPK) != U32(0) &&
		(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_COLUMN_IN|WHERE_COLUMN_EQ) != U32(0)) {
		goto __34
	}

	pTerm = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))

	iReleaseReg = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	iRowidReg = codeEqualityTerm(tls, pParse, pTerm, pLevel, 0, bRev, iReleaseReg)
	if !(iRowidReg != iReleaseReg) {
		goto __36
	}
	Xsqlite3ReleaseTempReg(tls, pParse, iReleaseReg)
__36:
	;
	addrNxt = (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0) {
		goto __37
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_MustBeInt, iRowidReg, addrNxt)

	Xsqlite3VdbeAddOp4Int(tls, v, OP_Filter, (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter, addrNxt,
		iRowidReg, 1)

	filterPullDown(tls, pParse, pWInfo, iLevel, addrNxt, notReady)
__37:
	;
	Xsqlite3VdbeAddOp3(tls, v, OP_SeekRowid, iCur, addrNxt, iRowidReg)

	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = U8(OP_Noop)
	goto __35
__34:
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IPK) != U32(0) &&
		(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_COLUMN_RANGE) != U32(0)) {
		goto __38
	}

	testOp = OP_Noop
	memEndValue = 0

	j = 0
	pStart = libc.AssignUintptr(&pEnd, uintptr(0))
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_BTM_LIMIT) != 0) {
		goto __40
	}
	pStart = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(libc.PostIncInt32(&j, 1))*8))
__40:
	;
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_TOP_LIMIT) != 0) {
		goto __41
	}
	pEnd = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(libc.PostIncInt32(&j, 1))*8))
__41:
	;
	if !(bRev != 0) {
		goto __42
	}
	pTerm = pStart
	pStart = pEnd
	pEnd = pTerm
__42:
	;
	if !(pStart != 0) {
		goto __43
	}

	*(*[4]U8)(unsafe.Pointer(bp + 24)) = [4]U8{
		U8(OP_SeekGT),
		U8(OP_SeekLE),
		U8(OP_SeekLT),
		U8(OP_SeekGE),
	}

	pX = (*WhereTerm)(unsafe.Pointer(pStart)).FpExpr

	if !(Xsqlite3ExprIsVector(tls, (*Expr)(unsafe.Pointer(pX)).FpRight) != 0) {
		goto __45
	}
	r1 = libc.AssignPtrInt32(bp+28, Xsqlite3GetTempReg(tls, pParse))
	codeExprOrVector(tls, pParse, (*Expr)(unsafe.Pointer(pX)).FpRight, r1, 1)

	op = int32(*(*U8)(unsafe.Pointer(bp + 24 + uintptr((int32((*Expr)(unsafe.Pointer(pX)).Fop)-TK_GT-1)&0x3|0x1))))

	goto __46
__45:
	r1 = Xsqlite3ExprCodeTemp(tls, pParse, (*Expr)(unsafe.Pointer(pX)).FpRight, bp+28)
	disableTerm(tls, pLevel, pStart)
	op = int32(*(*U8)(unsafe.Pointer(bp + 24 + uintptr(int32((*Expr)(unsafe.Pointer(pX)).Fop)-TK_GT))))
__46:
	;
	Xsqlite3VdbeAddOp3(tls, v, op, iCur, addrBrk, r1)
	Xsqlite3VdbeComment(tls, v, ts+19702, 0)

	Xsqlite3ReleaseTempReg(tls, pParse, *(*int32)(unsafe.Pointer(bp + 28)))
	goto __44
__43:
	Xsqlite3VdbeAddOp2(tls, v, func() int32 {
		if bRev != 0 {
			return OP_Last
		}
		return OP_Rewind
	}(), iCur, addrHalt)

__44:
	;
	if !(pEnd != 0) {
		goto __47
	}
	pX1 = (*WhereTerm)(unsafe.Pointer(pEnd)).FpExpr

	memEndValue = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	codeExprOrVector(tls, pParse, (*Expr)(unsafe.Pointer(pX1)).FpRight, memEndValue, 1)
	if !(0 == Xsqlite3ExprIsVector(tls, (*Expr)(unsafe.Pointer(pX1)).FpRight) &&
		(int32((*Expr)(unsafe.Pointer(pX1)).Fop) == TK_LT || int32((*Expr)(unsafe.Pointer(pX1)).Fop) == TK_GT)) {
		goto __48
	}
	if bRev != 0 {
		testOp = OP_Le
	} else {
		testOp = OP_Ge
	}
	goto __49
__48:
	if bRev != 0 {
		testOp = OP_Lt
	} else {
		testOp = OP_Gt
	}
__49:
	;
	if !(0 == Xsqlite3ExprIsVector(tls, (*Expr)(unsafe.Pointer(pX1)).FpRight)) {
		goto __50
	}
	disableTerm(tls, pLevel, pEnd)
__50:
	;
__47:
	;
	start = Xsqlite3VdbeCurrentAddr(tls, v)
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = func() uint8 {
		if bRev != 0 {
			return uint8(OP_Prev)
		}
		return uint8(OP_Next)
	}()
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp2 = start

	if !(testOp != OP_Noop) {
		goto __51
	}
	iRowidReg = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iCur, iRowidReg)
	Xsqlite3VdbeAddOp3(tls, v, testOp, memEndValue, addrBrk, iRowidReg)

	Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_AFF_NUMERIC|SQLITE_JUMPIFNULL))
__51:
	;
	goto __39
__38:
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_INDEXED) != 0) {
		goto __52
	}
	nEq = *(*U16)(unsafe.Pointer(pLoop + 24))
	nBtm = *(*U16)(unsafe.Pointer(pLoop + 24 + 2))
	nTop = *(*U16)(unsafe.Pointer(pLoop + 24 + 4))
	pRangeStart = uintptr(0)
	pRangeEnd = uintptr(0)
	nExtraReg = 0
	zEndAff = uintptr(0)
	bSeekPastNull = U8(0)
	bStopAtNull = U8(0)
	regBignull = 0
	addrSeekScan = 0

	pIdx = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))
	iIdxCur = (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur

	j = int32(nEq)
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_BTM_LIMIT) != 0) {
		goto __54
	}
	pRangeStart = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(libc.PostIncInt32(&j, 1))*8))
	nExtraReg = func() int32 {
		if nExtraReg > int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 2))) {
			return nExtraReg
		}
		return int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 2)))
	}()

__54:
	;
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_TOP_LIMIT) != 0) {
		goto __55
	}
	pRangeEnd = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(libc.PostIncInt32(&j, 1))*8))
	nExtraReg = func() int32 {
		if nExtraReg > int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 4))) {
			return nExtraReg
		}
		return int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 4)))
	}()
	if !(pRangeStart == uintptr(0)) {
		goto __56
	}
	j = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(nEq)*2)))
	if !(j >= 0 && int32(*(*uint8)(unsafe.Pointer((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(j)*24 + 8))&0xf>>0) == 0 || j == -2) {
		goto __57
	}
	bSeekPastNull = U8(1)
__57:
	;
__56:
	;
__55:
	;
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_TOP_LIMIT|WHERE_BTM_LIMIT) == U32(0) &&
		(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_BIGNULL_SORT) != U32(0)) {
		goto __58
	}

	nExtraReg = 1
	bSeekPastNull = U8(1)
	(*WhereLevel)(unsafe.Pointer(pLevel)).FregBignull = libc.AssignInt32(&regBignull, libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1))
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0) {
		goto __59
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regBignull)
__59:
	;
	(*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull = Xsqlite3VdbeMakeLabel(tls, pParse)
__58:
	;
	if !(int32(nEq) < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn) && bRev == libc.Bool32(int32(*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(nEq)))) == SQLITE_SO_ASC)) {
		goto __60
	}

	t = pRangeEnd
	pRangeEnd = pRangeStart
	pRangeStart = t

	t1 = bSeekPastNull
	bSeekPastNull = bStopAtNull
	bStopAtNull = t1

	t2 = U8(nBtm)
	nBtm = nTop
	nTop = U16(t2)

__60:
	;
	if !(iLevel > 0 && (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IN_SEEKSCAN) != U32(0)) {
		goto __61
	}

	Xsqlite3VdbeAddOp1(tls, v, OP_NullRow, iIdxCur)
__61:
	;
	regBase = codeAllEqualityTerms(tls, pParse, pLevel, bRev, nExtraReg, bp+32)

	if !(*(*uintptr)(unsafe.Pointer(bp + 32)) != 0 && nTop != 0) {
		goto __62
	}
	zEndAff = Xsqlite3DbStrDup(tls, db, *(*uintptr)(unsafe.Pointer(bp + 32))+uintptr(nEq))
__62:
	;
	addrNxt = func() int32 {
		if regBignull != 0 {
			return (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull
		}
		return (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt
	}()

	startEq = libc.Bool32(!(pRangeStart != 0) || int32((*WhereTerm)(unsafe.Pointer(pRangeStart)).FeOperator)&(int32(WO_EQ)<<(TK_LE-TK_EQ)|int32(WO_EQ)<<(TK_GE-TK_EQ)) != 0)
	endEq = libc.Bool32(!(pRangeEnd != 0) || int32((*WhereTerm)(unsafe.Pointer(pRangeEnd)).FeOperator)&(int32(WO_EQ)<<(TK_LE-TK_EQ)|int32(WO_EQ)<<(TK_GE-TK_EQ)) != 0)
	start_constraints = libc.Bool32(pRangeStart != 0 || int32(nEq) > 0)

	nConstraint1 = int32(nEq)
	if !(pRangeStart != 0) {
		goto __63
	}
	pRight2 = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pRangeStart)).FpExpr)).FpRight
	codeExprOrVector(tls, pParse, pRight2, regBase+int32(nEq), int32(nBtm))

	if !(int32((*WhereTerm)(unsafe.Pointer(pRangeStart)).FwtFlags)&TERM_VNULL == 0 &&
		Xsqlite3ExprCanBeNull(tls, pRight2) != 0) {
		goto __65
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, regBase+int32(nEq), addrNxt)

__65:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp + 32)) != 0) {
		goto __66
	}
	updateRangeAffinityStr(tls, pRight2, int32(nBtm), *(*uintptr)(unsafe.Pointer(bp + 32))+uintptr(nEq))
__66:
	;
	nConstraint1 = nConstraint1 + int32(nBtm)

	if !(Xsqlite3ExprIsVector(tls, pRight2) == 0) {
		goto __67
	}
	disableTerm(tls, pLevel, pRangeStart)
	goto __68
__67:
	startEq = 1
__68:
	;
	bSeekPastNull = U8(0)
	goto __64
__63:
	if !(bSeekPastNull != 0) {
		goto __69
	}
	startEq = 0
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regBase+int32(nEq))
	start_constraints = 1
	nConstraint1++
	goto __70
__69:
	if !(regBignull != 0) {
		goto __71
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regBase+int32(nEq))
	start_constraints = 1
	nConstraint1++
__71:
	;
__70:
	;
__64:
	;
	codeApplyAffinity(tls, pParse, regBase, nConstraint1-int32(bSeekPastNull), *(*uintptr)(unsafe.Pointer(bp + 32)))
	if !(int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnSkip) > 0 && nConstraint1 == int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnSkip)) {
		goto __72
	}

	goto __73
__72:
	if !(regBignull != 0) {
		goto __74
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, regBignull)
	Xsqlite3VdbeComment(tls, v, ts+26212, 0)
__74:
	;
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0) {
		goto __75
	}
	Xsqlite3VdbeAddOp4Int(tls, v, OP_Filter, (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter, addrNxt,
		regBase, int32(nEq))

	filterPullDown(tls, pParse, pWInfo, iLevel, addrNxt, notReady)
__75:
	;
	op1 = int32(aStartOp[start_constraints<<2+startEq<<1+bRev])

	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IN_SEEKSCAN) != U32(0) && op1 == OP_SeekGE) {
		goto __76
	}

	addrSeekScan = Xsqlite3VdbeAddOp1(tls, v, OP_SeekScan,
		(int32(*(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiRowLogEst)))+9)/10)
	if !(pRangeStart != 0) {
		goto __77
	}
	Xsqlite3VdbeChangeP5(tls, v, uint16(1))
	Xsqlite3VdbeChangeP2(tls, v, addrSeekScan, Xsqlite3VdbeCurrentAddr(tls, v)+1)
	addrSeekScan = 0
__77:
	;
__76:
	;
	Xsqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1)

	if !(regBignull != 0) {
		goto __78
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, Xsqlite3VdbeCurrentAddr(tls, v)+2)
	op1 = int32(aStartOp[libc.Bool32(nConstraint1 > 1)*4+2+bRev])
	Xsqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase,
		nConstraint1-startEq)

__78:
	;
__73:
	;
	nConstraint1 = int32(nEq)

	if !(pRangeEnd != 0) {
		goto __79
	}
	pRight3 = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pRangeEnd)).FpExpr)).FpRight
	if !(addrSeekScan != 0) {
		goto __81
	}

	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp2 = Xsqlite3VdbeCurrentAddr(tls, v)
__81:
	;
	codeExprOrVector(tls, pParse, pRight3, regBase+int32(nEq), int32(nTop))

	if !(int32((*WhereTerm)(unsafe.Pointer(pRangeEnd)).FwtFlags)&TERM_VNULL == 0 &&
		Xsqlite3ExprCanBeNull(tls, pRight3) != 0) {
		goto __82
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, regBase+int32(nEq), addrNxt)

__82:
	;
	if !(zEndAff != 0) {
		goto __83
	}
	updateRangeAffinityStr(tls, pRight3, int32(nTop), zEndAff)
	codeApplyAffinity(tls, pParse, regBase+int32(nEq), int32(nTop), zEndAff)
	goto __84
__83:
	;
__84:
	;
	nConstraint1 = nConstraint1 + int32(nTop)

	if !(Xsqlite3ExprIsVector(tls, pRight3) == 0) {
		goto __85
	}
	disableTerm(tls, pLevel, pRangeEnd)
	goto __86
__85:
	endEq = 1
__86:
	;
	goto __80
__79:
	if !(bStopAtNull != 0) {
		goto __87
	}
	if !(regBignull == 0) {
		goto __88
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regBase+int32(nEq))
	endEq = 0
__88:
	;
	nConstraint1++
__87:
	;
__80:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp + 32)) != 0) {
		goto __89
	}
	Xsqlite3DbNNFreeNN(tls, db, *(*uintptr)(unsafe.Pointer(bp + 32)))
__89:
	;
	if !(zEndAff != 0) {
		goto __90
	}
	Xsqlite3DbNNFreeNN(tls, db, zEndAff)
__90:
	;
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).Fp2 == 0) {
		goto __91
	}
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp2 = Xsqlite3VdbeCurrentAddr(tls, v)
__91:
	;
	if !(nConstraint1 != 0) {
		goto __92
	}
	if !(regBignull != 0) {
		goto __93
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_IfNot, regBignull, Xsqlite3VdbeCurrentAddr(tls, v)+3)
	Xsqlite3VdbeComment(tls, v, ts+26231, 0)

__93:
	;
	op1 = int32(aEndOp[bRev*2+endEq])
	Xsqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase, nConstraint1)

	if !(addrSeekScan != 0) {
		goto __94
	}
	Xsqlite3VdbeJumpHere(tls, v, addrSeekScan)
__94:
	;
__92:
	;
	if !(regBignull != 0) {
		goto __95
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_If, regBignull, Xsqlite3VdbeCurrentAddr(tls, v)+2)
	Xsqlite3VdbeComment(tls, v, ts+26253, 0)

	op1 = int32(aEndOp[bRev*2+int32(bSeekPastNull)])
	Xsqlite3VdbeAddOp4Int(tls, v, op1, iIdxCur, addrNxt, regBase,
		nConstraint1+int32(bSeekPastNull))

__95:
	;
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IN_EARLYOUT) != U32(0)) {
		goto __96
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_SeekHit, iIdxCur, int32(nEq), int32(nEq))
__96:
	;
	omitTable = libc.Bool32((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IDX_ONLY) != U32(0) &&
		int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN) == 0)
	if !(omitTable != 0) {
		goto __97
	}

	goto __98
__97:
	if !((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __99
	}
	codeDeferredSeek(tls, pWInfo, pIdx, iCur, iIdxCur)
	goto __100
__99:
	if !(iCur != iIdxCur) {
		goto __101
	}
	pPk = Xsqlite3PrimaryKeyIndex(tls, (*Index)(unsafe.Pointer(pIdx)).FpTable)
	iRowidReg = Xsqlite3GetTempRange(tls, pParse, int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol))
	j = 0
__102:
	if !(j < int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)) {
		goto __104
	}
	k = int32(Xsqlite3TableColumnToIndex(tls, pIdx, *(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(j)*2))))
	Xsqlite3VdbeAddOp3(tls, v, OP_Column, iIdxCur, k, iRowidReg+j)
	goto __103
__103:
	j++
	goto __102
	goto __104
__104:
	;
	Xsqlite3VdbeAddOp4Int(tls, v, OP_NotFound, iCur, addrCont,
		iRowidReg, int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol))
__101:
	;
__100:
	;
__98:
	;
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin == 0) {
		goto __105
	}

	if !((*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0) {
		goto __107
	}
	whereApplyPartialIndexConstraints(tls, (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere, iCur, pWC)
__107:
	;
	goto __106
__105:
	;
__106:
	;
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_ONEROW) != 0) {
		goto __108
	}
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = U8(OP_Noop)
	goto __109
__108:
	if !(bRev != 0) {
		goto __110
	}
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = U8(OP_Prev)
	goto __111
__110:
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = U8(OP_Next)
__111:
	;
__109:
	;
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iIdxCur
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp3 = func() uint8 {
		if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_UNQ_WANTED) != U32(0) {
			return uint8(1)
		}
		return uint8(0)
	}()
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_CONSTRAINT) == U32(0)) {
		goto __112
	}
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp5 = U8(SQLITE_STMTSTATUS_FULLSCAN_STEP)
	goto __113
__112:
	;
__113:
	;
	if !(omitTable != 0) {
		goto __114
	}
	pIdx = uintptr(0)
__114:
	;
	goto __53
__52:
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_MULTI_OR) != 0) {
		goto __115
	}
	pCov = uintptr(0)
	iCovCur = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)

	regReturn = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	regRowset = 0
	regRowid = 0
	iLoopBody = Xsqlite3VdbeMakeLabel(tls, pParse)
	untestedTerms = 0
	pAndExpr = uintptr(0)
	pTab = (*SrcItem)(unsafe.Pointer(pTabItem)).FpTab

	pTerm = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm))

	pOrWc = *(*uintptr)(unsafe.Pointer(pTerm + 32))
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = U8(OP_Return)
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp1 = regReturn

	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) > 1) {
		goto __117
	}
	nNotReady = int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - iLevel - 1
	pOrTab = Xsqlite3DbMallocRawNN(tls, db,
		uint64(unsafe.Sizeof(SrcList{}))+uint64(nNotReady)*uint64(unsafe.Sizeof(SrcItem{})))
	if !(pOrTab == uintptr(0)) {
		goto __119
	}
	return notReady
__119:
	;
	(*SrcList)(unsafe.Pointer(pOrTab)).FnAlloc = U32(U8(nNotReady + 1))
	(*SrcList)(unsafe.Pointer(pOrTab)).FnSrc = int32((*SrcList)(unsafe.Pointer(pOrTab)).FnAlloc)
	libc.Xmemcpy(tls, pOrTab+8, pTabItem, uint64(unsafe.Sizeof(SrcItem{})))
	origSrc = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
	k = 1
__120:
	if !(k <= nNotReady) {
		goto __122
	}
	libc.Xmemcpy(tls, pOrTab+8+uintptr(k)*104, origSrc+uintptr((*WhereLevel)(unsafe.Pointer(pLevel+uintptr(k)*104)).FiFrom)*104, uint64(unsafe.Sizeof(SrcItem{})))
	goto __121
__121:
	k++
	goto __120
	goto __122
__122:
	;
	goto __118
__117:
	pOrTab = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
__118:
	;
	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_DUPLICATES_OK == 0) {
		goto __123
	}
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __124
	}
	regRowset = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, regRowset)
	goto __125
__124:
	pPk1 = Xsqlite3PrimaryKeyIndex(tls, pTab)
	regRowset = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, regRowset, int32((*Index)(unsafe.Pointer(pPk1)).FnKeyCol))
	Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pPk1)
__125:
	;
	regRowid = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
__123:
	;
	iRetInit = Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regReturn)

	if !((*WhereClause)(unsafe.Pointer(pWC)).FnTerm > 1) {
		goto __126
	}
	iTerm = 0
__127:
	if !(iTerm < (*WhereClause)(unsafe.Pointer(pWC)).FnTerm) {
		goto __129
	}
	pExpr = (*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iTerm)*56)).FpExpr
	if !((*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(iTerm)*56 == pTerm) {
		goto __130
	}
	goto __128
__130:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(iTerm)*56)).FwtFlags)&(TERM_VIRTUAL|TERM_CODED|TERM_SLICE) != 0) {
		goto __131
	}
	goto __128
__131:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(iTerm)*56)).FeOperator)&WO_ALL == 0) {
		goto __132
	}
	goto __128
__132:
	;
	if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_Subquery) != U32(0)) {
		goto __133
	}
	goto __128
__133:
	;
	pExpr = Xsqlite3ExprDup(tls, db, pExpr, 0)
	pAndExpr = Xsqlite3ExprAnd(tls, pParse, pAndExpr, pExpr)
	goto __128
__128:
	iTerm++
	goto __127
	goto __129
__129:
	;
	if !(pAndExpr != 0) {
		goto __134
	}

	pAndExpr = Xsqlite3PExpr(tls, pParse, TK_AND|0x10000, uintptr(0), pAndExpr)
__134:
	;
__126:
	;
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+26275, 0)
	ii = 0
__135:
	if !(ii < (*WhereClause)(unsafe.Pointer(pOrWc)).FnTerm) {
		goto __137
	}
	pOrTerm = (*WhereClause)(unsafe.Pointer(pOrWc)).Fa + uintptr(ii)*56
	if !((*WhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCur || int32((*WhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&WO_AND != 0) {
		goto __138
	}
	pOrExpr = (*WhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr
	jmp1 = 0

	pDelete = libc.AssignUintptr(&pOrExpr, Xsqlite3ExprDup(tls, db, pOrExpr, 0))
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __139
	}
	Xsqlite3ExprDelete(tls, db, pDelete)
	goto __136
__139:
	;
	if !(pAndExpr != 0) {
		goto __140
	}
	(*Expr)(unsafe.Pointer(pAndExpr)).FpLeft = pOrExpr
	pOrExpr = pAndExpr
__140:
	;
	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+26290, libc.VaList(bp+8, ii+1))

	pSubWInfo = Xsqlite3WhereBegin(tls, pParse, pOrTab, pOrExpr, uintptr(0), uintptr(0), uintptr(0),
		uint16(WHERE_OR_SUBCLAUSE), iCovCur)

	if !(pSubWInfo != 0) {
		goto __141
	}
	addrExplain = Xsqlite3WhereExplainOneScan(tls,
		pParse, pOrTab, pSubWInfo+856, uint16(0))
	_ = addrExplain

	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_DUPLICATES_OK == 0) {
		goto __142
	}
	iSet = func() int32 {
		if ii == (*WhereClause)(unsafe.Pointer(pOrWc)).FnTerm-1 {
			return -1
		}
		return ii
	}()
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __143
	}
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, -1, regRowid)
	jmp1 = Xsqlite3VdbeAddOp4Int(tls, v, OP_RowSetTest, regRowset, 0,
		regRowid, iSet)

	goto __144
__143:
	pPk2 = Xsqlite3PrimaryKeyIndex(tls, pTab)
	nPk = int32((*Index)(unsafe.Pointer(pPk2)).FnKeyCol)

	r = Xsqlite3GetTempRange(tls, pParse, nPk)
	iPk = 0
__145:
	if !(iPk < nPk) {
		goto __147
	}
	iCol = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk2)).FaiColumn + uintptr(iPk)*2)))
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, iCol, r+iPk)
	goto __146
__146:
	iPk++
	goto __145
	goto __147
__147:
	;
	if !(iSet != 0) {
		goto __148
	}
	jmp1 = Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, regRowset, 0, r, nPk)

__148:
	;
	if !(iSet >= 0) {
		goto __149
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, r, nPk, regRowid)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, regRowset, regRowid,
		r, nPk)
	if !(iSet != 0) {
		goto __150
	}
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
__150:
	;
__149:
	;
	Xsqlite3ReleaseTempRange(tls, pParse, r, nPk)
__144:
	;
__142:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, regReturn, iLoopBody)

	if !(jmp1 != 0) {
		goto __151
	}
	Xsqlite3VdbeJumpHere(tls, v, jmp1)
__151:
	;
	if !(uint32(int32(*(*uint8)(unsafe.Pointer(pSubWInfo + 68))&0x2>>1)) != 0) {
		goto __152
	}
	untestedTerms = 1
__152:
	;
	pSubLoop = (*WhereLevel)(unsafe.Pointer(pSubWInfo + 856)).FpWLoop

	if !((*WhereLoop)(unsafe.Pointer(pSubLoop)).FwsFlags&U32(WHERE_INDEXED) != U32(0) &&
		(ii == 0 || *(*uintptr)(unsafe.Pointer(pSubLoop + 24 + 8)) == pCov) &&
		((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) || !(int32(*(*uint16)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSubLoop + 24 + 8)) + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY))) {
		goto __153
	}

	pCov = *(*uintptr)(unsafe.Pointer(pSubLoop + 24 + 8))
	goto __154
__153:
	pCov = uintptr(0)
__154:
	;
	if !(Xsqlite3WhereUsesDeferredSeek(tls, pSubWInfo) != 0) {
		goto __155
	}
	libc.SetBitFieldPtr8Uint32(pWInfo+68, uint32(1), 0, 0x1)
__155:
	;
	Xsqlite3WhereEnd(tls, pSubWInfo)
	Xsqlite3VdbeExplainPop(tls, pParse)
__141:
	;
	Xsqlite3ExprDelete(tls, db, pDelete)
__138:
	;
	goto __136
__136:
	ii++
	goto __135
	goto __137
__137:
	;
	Xsqlite3VdbeExplainPop(tls, pParse)

	*(*uintptr)(unsafe.Pointer(pLevel + 72)) = pCov
	if !(pCov != 0) {
		goto __156
	}
	(*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = iCovCur
__156:
	;
	if !(pAndExpr != 0) {
		goto __157
	}
	(*Expr)(unsafe.Pointer(pAndExpr)).FpLeft = uintptr(0)
	Xsqlite3ExprDelete(tls, db, pAndExpr)
__157:
	;
	Xsqlite3VdbeChangeP1(tls, v, iRetInit, Xsqlite3VdbeCurrentAddr(tls, v))
	Xsqlite3VdbeGoto(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
	Xsqlite3VdbeResolveLabel(tls, v, iLoopBody)

	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp2 = Xsqlite3VdbeCurrentAddr(tls, v)

	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) > 1) {
		goto __158
	}
	Xsqlite3DbFreeNN(tls, db, pOrTab)
__158:
	;
	if !!(untestedTerms != 0) {
		goto __159
	}
	disableTerm(tls, pLevel, pTerm)
__159:
	;
	goto __116
__115:
	;
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pTabItem + 60 + 4))&0x40>>6)) != 0) {
		goto __160
	}

	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = U8(OP_Noop)
	goto __161
__160:
	;
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fop = aStep[bRev]
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp1 = iCur
	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp2 = 1 + Xsqlite3VdbeAddOp2(tls, v, int32(aStart[bRev]), iCur, addrHalt)

	(*WhereLevel)(unsafe.Pointer(pLevel)).Fp5 = U8(SQLITE_STMTSTATUS_FULLSCAN_STEP)
__161:
	;
__116:
	;
__53:
	;
__39:
	;
__35:
	;
__10:
	;
__8:
	;
	iLoop = func() int32 {
		if pIdx != 0 {
			return 1
		}
		return 2
	}()
__162:
	iNext = 0
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
	j = (*WhereClause)(unsafe.Pointer(pWC)).FnTerm
__165:
	if !(j > 0) {
		goto __167
	}
	skipLikeAddr = 0

	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(TERM_VIRTUAL|TERM_CODED) != 0) {
		goto __168
	}
	goto __166
__168:
	;
	if !((*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*WhereLevel)(unsafe.Pointer(pLevel)).FnotReady != uint64(0)) {
		goto __169
	}

	libc.SetBitFieldPtr8Uint32(pWInfo+68, uint32(1), 1, 0x2)
	goto __166
__169:
	;
	pE = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr

	if !(int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ|JT_RIGHT) != 0) {
		goto __170
	}
	if !!((*Expr)(unsafe.Pointer(pE)).Fflags&U32(EP_OuterON|EP_InnerON) != U32(0)) {
		goto __171
	}

	goto __166
	goto __172
__171:
	if !(int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&JT_LEFT == JT_LEFT &&
		!((*Expr)(unsafe.Pointer(pE)).Fflags&U32(EP_OuterON) != U32(0))) {
		goto __173
	}
	goto __166
	goto __174
__173:
	m = Xsqlite3WhereGetMask(tls, pWInfo+592, *(*int32)(unsafe.Pointer(pE + 52)))
	if !(m&(*WhereLevel)(unsafe.Pointer(pLevel)).FnotReady != 0) {
		goto __175
	}

	goto __166
__175:
	;
__174:
	;
__172:
	;
__170:
	;
	if !(iLoop == 1 && !(Xsqlite3ExprCoveredByIndex(tls, pE, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, pIdx) != 0)) {
		goto __176
	}
	iNext = 2
	goto __166
__176:
	;
	if !(iLoop < 3 && int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_VARSELECT != 0) {
		goto __177
	}
	if !(iNext == 0) {
		goto __178
	}
	iNext = 3
__178:
	;
	goto __166
__177:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_LIKECOND != 0) {
		goto __179
	}

	goto __166
__179:
	;
	Xsqlite3ExprIfFalse(tls, pParse, pE, addrCont, SQLITE_JUMPIFNULL)
	if !(skipLikeAddr != 0) {
		goto __180
	}
	Xsqlite3VdbeJumpHere(tls, v, skipLikeAddr)
__180:
	;
	*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_CODED)
	goto __166
__166:
	j--
	pTerm += 56
	goto __165
	goto __167
__167:
	;
	iLoop = iNext
	goto __163
__163:
	if iLoop > 0 {
		goto __162
	}
	goto __164
__164:
	;
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
	j = (*WhereClause)(unsafe.Pointer(pWC)).FnBase
__181:
	if !(j > 0) {
		goto __183
	}
	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(TERM_VIRTUAL|TERM_CODED) != 0) {
		goto __184
	}
	goto __182
__184:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(WO_EQ|WO_IS) == 0) {
		goto __185
	}
	goto __182
__185:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_EQUIV == 0) {
		goto __186
	}
	goto __182
__186:
	;
	if !((*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != iCur) {
		goto __187
	}
	goto __182
__187:
	;
	if !(int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ|JT_RIGHT) != 0) {
		goto __188
	}
	goto __182
__188:
	;
	pE1 = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr

	pAlt = Xsqlite3WhereFindTerm(tls, pWC, iCur, *(*int32)(unsafe.Pointer(pTerm + 32)), notReady,
		uint32(WO_EQ|WO_IN|WO_IS), uintptr(0))
	if !(pAlt == uintptr(0)) {
		goto __189
	}
	goto __182
__189:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer(pAlt)).FwtFlags)&TERM_CODED != 0) {
		goto __190
	}
	goto __182
__190:
	;
	if !(int32((*WhereTerm)(unsafe.Pointer(pAlt)).FeOperator)&WO_IN != 0 &&
		(*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pAlt)).FpExpr)).Fflags&U32(EP_xIsSelect) != U32(0) &&
		(*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pAlt)).FpExpr + 32)))).FpEList)).FnExpr > 1) {
		goto __191
	}
	goto __182
__191:
	;
	*(*Expr)(unsafe.Pointer(bp + 40)) = *(*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pAlt)).FpExpr))
	(*Expr)(unsafe.Pointer(bp + 40)).FpLeft = (*Expr)(unsafe.Pointer(pE1)).FpLeft
	Xsqlite3ExprIfFalse(tls, pParse, bp+40, addrCont, SQLITE_JUMPIFNULL)
	*(*U16)(unsafe.Pointer(pAlt + 18)) |= U16(TERM_CODED)
	goto __182
__182:
	j--
	pTerm += 56
	goto __181
	goto __183
__183:
	;
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0) {
		goto __192
	}
	jmp11 = 0
	pRJ = (*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ

	pTab1 = (*SrcItem)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104)).FpTab
	if !((*Table)(unsafe.Pointer(pTab1)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __193
	}
	r2 = Xsqlite3GetTempRange(tls, pParse, 2)
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab1, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, -1, r2+1)
	nPk1 = 1
	goto __194
__193:
	pPk3 = Xsqlite3PrimaryKeyIndex(tls, pTab1)
	nPk1 = int32((*Index)(unsafe.Pointer(pPk3)).FnKeyCol)
	r2 = Xsqlite3GetTempRange(tls, pParse, nPk1+1)
	iPk1 = 0
__195:
	if !(iPk1 < nPk1) {
		goto __197
	}
	iCol1 = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk3)).FaiColumn + uintptr(iPk1)*2)))
	Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab1, iCur, iCol1, r2+1+iPk1)
	goto __196
__196:
	iPk1++
	goto __195
	goto __197
__197:
	;
__194:
	;
	jmp11 = Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, 0, r2+1, nPk1)

	Xsqlite3VdbeComment(tls, v, ts+26299, libc.VaList(bp+16, (*Table)(unsafe.Pointer(pTab1)).FzName))
	Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, r2+1, nPk1, r2)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_IdxInsert, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, r2, r2+1, nPk1)
	Xsqlite3VdbeAddOp4Int(tls, v, OP_FilterAdd, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom, 0, r2+1, nPk1)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
	Xsqlite3VdbeJumpHere(tls, v, jmp11)
	Xsqlite3ReleaseTempRange(tls, pParse, r2, nPk1+1)
__192:
	;
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0) {
		goto __198
	}
	(*WhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst = Xsqlite3VdbeCurrentAddr(tls, v)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, (*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)
	Xsqlite3VdbeComment(tls, v, ts+26316, 0)
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ == uintptr(0)) {
		goto __199
	}
	goto code_outer_join_constraints
__199:
	;
__198:
	;
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0) {
		goto __200
	}
	pRJ1 = (*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ
	Xsqlite3VdbeAddOp2(tls, v, OP_BeginSubrtn, 0, (*WhereRightJoin)(unsafe.Pointer(pRJ1)).FregReturn)
	(*WhereRightJoin)(unsafe.Pointer(pRJ1)).FaddrSubrtn = Xsqlite3VdbeCurrentAddr(tls, v)

	(*Parse)(unsafe.Pointer(pParse)).FwithinRJSubrtn++

code_outer_join_constraints:
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
	j = 0
__201:
	if !(j < (*WhereClause)(unsafe.Pointer(pWC)).FnBase) {
		goto __203
	}

	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(TERM_VIRTUAL|TERM_CODED) != 0) {
		goto __204
	}
	goto __202
__204:
	;
	if !((*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*WhereLevel)(unsafe.Pointer(pLevel)).FnotReady != uint64(0)) {
		goto __205
	}

	goto __202
__205:
	;
	if !(int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&JT_LTORJ != 0) {
		goto __206
	}
	goto __202
__206:
	;
	Xsqlite3ExprIfFalse(tls, pParse, (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr, addrCont, SQLITE_JUMPIFNULL)
	*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_CODED)
	goto __202
__202:
	j++
	pTerm += 56
	goto __201
	goto __203
__203:
	;
__200:
	;
	return (*WhereLevel)(unsafe.Pointer(pLevel)).FnotReady
}

var aStartOp = [8]U8{
	U8(0),
	U8(0),
	U8(OP_Rewind),
	U8(OP_Last),
	U8(OP_SeekGT),
	U8(OP_SeekLT),
	U8(OP_SeekGE),
	U8(OP_SeekLE),
}
var aEndOp = [4]U8{
	U8(OP_IdxGE),
	U8(OP_IdxGT),
	U8(OP_IdxLE),
	U8(OP_IdxLT),
}
var aStep = [2]U8{U8(OP_Next), U8(OP_Prev)}
var aStart = [2]U8{U8(OP_Rewind), U8(OP_Last)}

func Xsqlite3WhereRightJoinLoop(tls *libc.TLS, pWInfo uintptr, iLevel int32, pLevel uintptr) {
	bp := tls.Alloc(120)
	defer tls.Free(120)

	var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var pRJ uintptr = (*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ
	var pSubWhere uintptr = uintptr(0)
	var pWC uintptr = pWInfo + 104
	var pSubWInfo uintptr
	var pLoop uintptr = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	var pTabItem uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104

	var mAll Bitmask = uint64(0)
	var k int32

	Xsqlite3VdbeExplain(tls, pParse, uint8(1), ts+26337, libc.VaList(bp, (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pTabItem)).FpTab)).FzName))

	for k = 0; k < iLevel; k++ {
		var iIdxCur int32
		mAll = mAll | (*WhereLoop1)(unsafe.Pointer((*WhereLevel)(unsafe.Pointer(pWInfo+856+uintptr(k)*104)).FpWLoop)).FmaskSelf
		Xsqlite3VdbeAddOp1(tls, v, OP_NullRow, (*WhereLevel)(unsafe.Pointer(pWInfo+856+uintptr(k)*104)).FiTabCur)
		iIdxCur = (*WhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(k)*104)).FiIdxCur
		if iIdxCur != 0 {
			Xsqlite3VdbeAddOp1(tls, v, OP_NullRow, iIdxCur)
		}
	}
	if int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&JT_LTORJ == 0 {
		mAll = mAll | (*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
		for k = 0; k < (*WhereClause)(unsafe.Pointer(pWC)).FnTerm; k++ {
			var pTerm uintptr = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(k)*56
			if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&(TERM_VIRTUAL|TERM_SLICE) != 0 &&
				int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator) != WO_ROWVAL {
				break
			}
			if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll & ^mAll != 0 {
				continue
			}
			if (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&U32(EP_OuterON|EP_InnerON) != U32(0) {
				continue
			}
			pSubWhere = Xsqlite3ExprAnd(tls, pParse, pSubWhere,
				Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr, 0))
		}
	}
	(*SrcList)(unsafe.Pointer(bp + 8)).FnSrc = 1
	(*SrcList)(unsafe.Pointer(bp + 8)).FnAlloc = U32(1)
	libc.Xmemcpy(tls, bp+8+8, pTabItem, uint64(unsafe.Sizeof(SrcItem{})))
	(*SrcItem)(unsafe.Pointer(bp + 8 + 8)).Ffg.Fjointype = U8(0)

	(*Parse)(unsafe.Pointer(pParse)).FwithinRJSubrtn++
	pSubWInfo = Xsqlite3WhereBegin(tls, pParse, bp+8, pSubWhere, uintptr(0), uintptr(0), uintptr(0),
		uint16(WHERE_RIGHT_JOIN), 0)
	if pSubWInfo != 0 {
		var iCur int32 = (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
		var r int32 = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		var nPk int32
		var jmp int32
		var addrCont int32 = Xsqlite3WhereContinueLabel(tls, pSubWInfo)
		var pTab uintptr = (*SrcItem)(unsafe.Pointer(pTabItem)).FpTab
		if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) {
			Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, -1, r)
			nPk = 1
		} else {
			var iPk int32
			var pPk uintptr = Xsqlite3PrimaryKeyIndex(tls, pTab)
			nPk = int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol)
			*(*int32)(unsafe.Pointer(pParse + 56)) += nPk - 1
			for iPk = 0; iPk < nPk; iPk++ {
				var iCol int32 = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(iPk)*2)))
				Xsqlite3ExprCodeGetColumnOfTable(tls, v, pTab, iCur, iCol, r+iPk)
			}
		}
		jmp = Xsqlite3VdbeAddOp4Int(tls, v, OP_Filter, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom, 0, r, nPk)

		Xsqlite3VdbeAddOp4Int(tls, v, OP_Found, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, addrCont, r, nPk)

		Xsqlite3VdbeJumpHere(tls, v, jmp)
		Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FaddrSubrtn)
		Xsqlite3WhereEnd(tls, pSubWInfo)
	}
	Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pSubWhere)
	Xsqlite3VdbeExplainPop(tls, pParse)

	(*Parse)(unsafe.Pointer(pParse)).FwithinRJSubrtn--
}

func whereOrInfoDelete(tls *libc.TLS, db uintptr, p uintptr) {
	Xsqlite3WhereClauseClear(tls, p)
	Xsqlite3DbFree(tls, db, p)
}

func whereAndInfoDelete(tls *libc.TLS, db uintptr, p uintptr) {
	Xsqlite3WhereClauseClear(tls, p)
	Xsqlite3DbFree(tls, db, p)
}

func whereClauseInsert(tls *libc.TLS, pWC uintptr, p uintptr, wtFlags U16) int32 {
	var pTerm uintptr
	var idx int32

	if (*WhereClause)(unsafe.Pointer(pWC)).FnTerm >= (*WhereClause)(unsafe.Pointer(pWC)).FnSlot {
		var pOld uintptr = (*WhereClause)(unsafe.Pointer(pWC)).Fa
		var db uintptr = (*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse)).Fdb
		(*WhereClause)(unsafe.Pointer(pWC)).Fa = Xsqlite3WhereMalloc(tls, (*WhereClause)(unsafe.Pointer(pWC)).FpWInfo, uint64(unsafe.Sizeof(WhereTerm{}))*uint64((*WhereClause)(unsafe.Pointer(pWC)).FnSlot)*uint64(2))
		if (*WhereClause)(unsafe.Pointer(pWC)).Fa == uintptr(0) {
			if int32(wtFlags)&TERM_DYNAMIC != 0 {
				Xsqlite3ExprDelete(tls, db, p)
			}
			(*WhereClause)(unsafe.Pointer(pWC)).Fa = pOld
			return 0
		}
		libc.Xmemcpy(tls, (*WhereClause)(unsafe.Pointer(pWC)).Fa, pOld, uint64(unsafe.Sizeof(WhereTerm{}))*uint64((*WhereClause)(unsafe.Pointer(pWC)).FnTerm))
		(*WhereClause)(unsafe.Pointer(pWC)).FnSlot = (*WhereClause)(unsafe.Pointer(pWC)).FnSlot * 2
	}
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(libc.AssignInt32(&idx, libc.PostIncInt32(&(*WhereClause)(unsafe.Pointer(pWC)).FnTerm, 1)))*56
	if int32(wtFlags)&TERM_VIRTUAL == 0 {
		(*WhereClause)(unsafe.Pointer(pWC)).FnBase = (*WhereClause)(unsafe.Pointer(pWC)).FnTerm
	}
	if p != 0 && (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_Unlikely) != U32(0) {
		(*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb = LogEst(int32(Xsqlite3LogEst(tls, uint64((*Expr)(unsafe.Pointer(p)).FiTable))) - 270)
	} else {
		(*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb = int16(1)
	}
	(*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr = Xsqlite3ExprSkipCollateAndLikely(tls, p)
	(*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags = wtFlags
	(*WhereTerm)(unsafe.Pointer(pTerm)).FpWC = pWC
	(*WhereTerm)(unsafe.Pointer(pTerm)).FiParent = -1
	libc.Xmemset(tls, pTerm+20, 0,
		uint64(unsafe.Sizeof(WhereTerm{}))-uint64(uintptr(0)+20))
	return idx
}

func allowedOp(tls *libc.TLS, op int32) int32 {
	return libc.Bool32(op == TK_IN || op >= TK_EQ && op <= TK_GE || op == TK_ISNULL || op == TK_IS)
}

func exprCommute(tls *libc.TLS, pParse uintptr, pExpr uintptr) U16 {
	if int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == TK_VECTOR ||
		int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpRight)).Fop) == TK_VECTOR ||
		Xsqlite3BinaryCompareCollSeq(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, (*Expr)(unsafe.Pointer(pExpr)).FpRight) != Xsqlite3BinaryCompareCollSeq(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, (*Expr)(unsafe.Pointer(pExpr)).FpLeft) {
		*(*U32)(unsafe.Pointer(pExpr + 4)) ^= U32(EP_Commuted)
	}
	{
		var t uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpRight
		(*Expr)(unsafe.Pointer(pExpr)).FpRight = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
		(*Expr)(unsafe.Pointer(pExpr)).FpLeft = t
	}

	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) >= TK_GT {
		(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(int32((*Expr)(unsafe.Pointer(pExpr)).Fop) - TK_GT ^ 2 + TK_GT)
	}
	return U16(0)
}

func operatorMask(tls *libc.TLS, op int32) U16 {
	var c U16

	if op == TK_IN {
		c = U16(WO_IN)
	} else if op == TK_ISNULL {
		c = U16(WO_ISNULL)
	} else if op == TK_IS {
		c = U16(WO_IS)
	} else {
		c = U16(int32(WO_EQ) << (op - TK_EQ))
	}

	return c
}

func isLikeOrGlob(tls *libc.TLS, pParse uintptr, pExpr uintptr, ppPrefix uintptr, pisComplete uintptr, pnoCase uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var z uintptr = uintptr(0)
	var pRight uintptr
	var pLeft uintptr
	var pList uintptr
	var c U8
	var cnt int32

	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pVal uintptr = uintptr(0)
	var op int32
	var rc int32

	if !(Xsqlite3IsLikeFunction(tls, db, pExpr, pnoCase, bp) != 0) {
		return 0
	}

	pList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
	pLeft = (*ExprList_item)(unsafe.Pointer(pList + 8 + 1*32)).FpExpr

	pRight = Xsqlite3ExprSkipCollate(tls, (*ExprList_item)(unsafe.Pointer(pList+8)).FpExpr)
	op = int32((*Expr)(unsafe.Pointer(pRight)).Fop)
	if op == TK_VARIABLE && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_EnableQPSG) == uint64(0) {
		var pReprepare uintptr = (*Parse)(unsafe.Pointer(pParse)).FpReprepare
		var iCol int32 = int32((*Expr)(unsafe.Pointer(pRight)).FiColumn)
		pVal = Xsqlite3VdbeGetBoundValue(tls, pReprepare, iCol, uint8(SQLITE_AFF_BLOB))
		if pVal != 0 && Xsqlite3_value_type(tls, pVal) == SQLITE_TEXT {
			z = Xsqlite3_value_text(tls, pVal)
		}
		Xsqlite3VdbeSetVarmask(tls, (*Parse)(unsafe.Pointer(pParse)).FpVdbe, iCol)

	} else if op == TK_STRING {
		z = *(*uintptr)(unsafe.Pointer(pRight + 8))
	}
	if z != 0 {
		cnt = 0
		for int32(libc.AssignUint8(&c, *(*U8)(unsafe.Pointer(z + uintptr(cnt))))) != 0 && int32(c) != int32(*(*U8)(unsafe.Pointer(bp))) && int32(c) != int32(*(*U8)(unsafe.Pointer(bp + 1))) && int32(c) != int32(*(*U8)(unsafe.Pointer(bp + 2))) {
			cnt++
			if int32(c) == int32(*(*U8)(unsafe.Pointer(bp + 3))) && int32(*(*U8)(unsafe.Pointer(z + uintptr(cnt)))) != 0 {
				cnt++
			}
		}

		if cnt != 0 && 255 != int32(*(*U8)(unsafe.Pointer(z + uintptr(cnt-1)))) && (cnt > 1 || int32(*(*U8)(unsafe.Pointer(z))) != int32(*(*U8)(unsafe.Pointer(bp + 3)))) {
			var pPrefix uintptr

			*(*int32)(unsafe.Pointer(pisComplete)) = libc.Bool32(int32(c) == int32(*(*U8)(unsafe.Pointer(bp))) && int32(*(*U8)(unsafe.Pointer(z + uintptr(cnt+1)))) == 0)

			pPrefix = Xsqlite3Expr(tls, db, TK_STRING, z)
			if pPrefix != 0 {
				var iFrom int32
				var iTo int32
				var zNew uintptr

				zNew = *(*uintptr)(unsafe.Pointer(pPrefix + 8))
				*(*uint8)(unsafe.Pointer(zNew + uintptr(cnt))) = uint8(0)
				for iFrom = libc.AssignInt32(&iTo, 0); iFrom < cnt; iFrom++ {
					if int32(*(*uint8)(unsafe.Pointer(zNew + uintptr(iFrom)))) == int32(*(*U8)(unsafe.Pointer(bp + 3))) {
						iFrom++
					}
					*(*uint8)(unsafe.Pointer(zNew + uintptr(libc.PostIncInt32(&iTo, 1)))) = *(*uint8)(unsafe.Pointer(zNew + uintptr(iFrom)))
				}
				*(*uint8)(unsafe.Pointer(zNew + uintptr(iTo))) = uint8(0)

				if int32((*Expr)(unsafe.Pointer(pLeft)).Fop) != TK_COLUMN ||
					int32(Xsqlite3ExprAffinity(tls, pLeft)) != SQLITE_AFF_TEXT ||
					(*Expr)(unsafe.Pointer(pLeft)).Fflags&U32(EP_WinFunc|EP_Subrtn) == U32(0) &&
						*(*uintptr)(unsafe.Pointer(pLeft + 64)) != 0 &&
						int32((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 64)))).FeTabType) == TABTYP_VTAB {
					var isNum int32

					isNum = Xsqlite3AtoF(tls, zNew, bp+8, iTo, uint8(SQLITE_UTF8))
					if isNum <= 0 {
						if iTo == 1 && int32(*(*uint8)(unsafe.Pointer(zNew))) == '-' {
							isNum = +1
						} else {
							*(*uint8)(unsafe.Pointer(zNew + uintptr(iTo-1)))++
							isNum = Xsqlite3AtoF(tls, zNew, bp+8, iTo, uint8(SQLITE_UTF8))
							*(*uint8)(unsafe.Pointer(zNew + uintptr(iTo-1)))--
						}
					}
					if isNum > 0 {
						Xsqlite3ExprDelete(tls, db, pPrefix)
						Xsqlite3ValueFree(tls, pVal)
						return 0
					}
				}
			}
			*(*uintptr)(unsafe.Pointer(ppPrefix)) = pPrefix

			if op == TK_VARIABLE {
				var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
				Xsqlite3VdbeSetVarmask(tls, v, int32((*Expr)(unsafe.Pointer(pRight)).FiColumn))

				if *(*int32)(unsafe.Pointer(pisComplete)) != 0 && *(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pRight + 8)) + 1)) != 0 {
					var r1 int32 = Xsqlite3GetTempReg(tls, pParse)
					Xsqlite3ExprCodeTarget(tls, pParse, pRight, r1)
					Xsqlite3VdbeChangeP3(tls, v, Xsqlite3VdbeCurrentAddr(tls, v)-1, 0)
					Xsqlite3ReleaseTempReg(tls, pParse, r1)
				}
			}
		} else {
			z = uintptr(0)
		}
	}

	rc = libc.Bool32(z != uintptr(0))
	Xsqlite3ValueFree(tls, pVal)
	return rc
}

func isAuxiliaryVtabOperator(tls *libc.TLS, db uintptr, pExpr uintptr, peOp2 uintptr, ppLeft uintptr, ppRight uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_FUNCTION {
		var pList uintptr
		var pCol uintptr
		var i int32

		pList = *(*uintptr)(unsafe.Pointer(pExpr + 32))
		if pList == uintptr(0) || (*ExprList)(unsafe.Pointer(pList)).FnExpr != 2 {
			return 0
		}

		pCol = (*ExprList_item)(unsafe.Pointer(pList + 8 + 1*32)).FpExpr

		if int32((*Expr)(unsafe.Pointer(pCol)).Fop) == TK_COLUMN && int32((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCol + 64)))).FeTabType) == TABTYP_VTAB {
			for i = 0; i < int32(uint64(unsafe.Sizeof(aOp))/uint64(unsafe.Sizeof(Op2{}))); i++ {
				if Xsqlite3StrICmp(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), aOp[i].FzOp) == 0 {
					*(*uint8)(unsafe.Pointer(peOp2)) = aOp[i].FeOp2
					*(*uintptr)(unsafe.Pointer(ppRight)) = (*ExprList_item)(unsafe.Pointer(pList + 8)).FpExpr
					*(*uintptr)(unsafe.Pointer(ppLeft)) = pCol
					return 1
				}
			}
		}

		pCol = (*ExprList_item)(unsafe.Pointer(pList + 8)).FpExpr

		if int32((*Expr)(unsafe.Pointer(pCol)).Fop) == TK_COLUMN && int32((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pCol + 64)))).FeTabType) == TABTYP_VTAB {
			var pVtab uintptr
			var pMod uintptr

			pVtab = (*VTable)(unsafe.Pointer(Xsqlite3GetVTable(tls, db, *(*uintptr)(unsafe.Pointer(pCol + 64))))).FpVtab

			pMod = (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule
			if (*Sqlite3_module)(unsafe.Pointer(pMod)).FxFindFunction != uintptr(0) {
				i = (*struct {
					f func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer(pMod)).FxFindFunction})).f(tls, pVtab, 2, *(*uintptr)(unsafe.Pointer(pExpr + 8)), bp, bp+8)
				if i >= SQLITE_INDEX_CONSTRAINT_FUNCTION {
					*(*uint8)(unsafe.Pointer(peOp2)) = uint8(i)
					*(*uintptr)(unsafe.Pointer(ppRight)) = (*ExprList_item)(unsafe.Pointer(pList + 8 + 1*32)).FpExpr
					*(*uintptr)(unsafe.Pointer(ppLeft)) = pCol
					return 1
				}
			}
		}
	} else if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_NE || int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_ISNOT || int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_NOTNULL {
		var res int32 = 0
		var pLeft uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
		var pRight uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpRight

		if int32((*Expr)(unsafe.Pointer(pLeft)).Fop) == TK_COLUMN && int32((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 64)))).FeTabType) == TABTYP_VTAB {
			res++
		}

		if pRight != 0 && (int32((*Expr)(unsafe.Pointer(pRight)).Fop) == TK_COLUMN && int32((*Table)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pRight + 64)))).FeTabType) == TABTYP_VTAB) {
			res++
			{
				var t uintptr = pLeft
				pLeft = pRight
				pRight = t
			}

		}
		*(*uintptr)(unsafe.Pointer(ppLeft)) = pLeft
		*(*uintptr)(unsafe.Pointer(ppRight)) = pRight
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_NE {
			*(*uint8)(unsafe.Pointer(peOp2)) = uint8(SQLITE_INDEX_CONSTRAINT_NE)
		}
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_ISNOT {
			*(*uint8)(unsafe.Pointer(peOp2)) = uint8(SQLITE_INDEX_CONSTRAINT_ISNOT)
		}
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_NOTNULL {
			*(*uint8)(unsafe.Pointer(peOp2)) = uint8(SQLITE_INDEX_CONSTRAINT_ISNOTNULL)
		}
		return res
	}
	return 0
}

type Op2 = struct {
	FzOp         uintptr
	FeOp2        uint8
	F__ccgo_pad1 [7]byte
}

var aOp = [4]Op2{
	{FzOp: ts + 19663, FeOp2: uint8(SQLITE_INDEX_CONSTRAINT_MATCH)},
	{FzOp: ts + 18860, FeOp2: uint8(SQLITE_INDEX_CONSTRAINT_GLOB)},
	{FzOp: ts + 18380, FeOp2: uint8(SQLITE_INDEX_CONSTRAINT_LIKE)},
	{FzOp: ts + 26351, FeOp2: uint8(SQLITE_INDEX_CONSTRAINT_REGEXP)},
}

func transferJoinMarkings(tls *libc.TLS, pDerived uintptr, pBase uintptr) {
	if pDerived != 0 && (*Expr)(unsafe.Pointer(pBase)).Fflags&U32(EP_OuterON|EP_InnerON) != U32(0) {
		*(*U32)(unsafe.Pointer(pDerived + 4)) |= (*Expr)(unsafe.Pointer(pBase)).Fflags & U32(EP_OuterON|EP_InnerON)
		*(*int32)(unsafe.Pointer(pDerived + 52)) = *(*int32)(unsafe.Pointer(pBase + 52))
	}
}

func markTermAsChild(tls *libc.TLS, pWC uintptr, iChild int32, iParent int32) {
	(*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iChild)*56)).FiParent = iParent
	(*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iChild)*56)).FtruthProb = (*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iParent)*56)).FtruthProb
	(*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(iParent)*56)).FnChild++
}

func whereNthSubterm(tls *libc.TLS, pTerm uintptr, N int32) uintptr {
	if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator) != WO_AND {
		if N == 0 {
			return pTerm
		}
		return uintptr(0)
	}
	if N < (*WhereAndInfo)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTerm + 32)))).Fwc.FnTerm {
		return (*WhereAndInfo)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTerm + 32)))).Fwc.Fa + uintptr(N)*56
	}
	return uintptr(0)
}

func whereCombineDisjuncts(tls *libc.TLS, pSrc uintptr, pWC uintptr, pOne uintptr, pTwo uintptr) {
	var eOp U16 = U16(int32((*WhereTerm)(unsafe.Pointer(pOne)).FeOperator) | int32((*WhereTerm)(unsafe.Pointer(pTwo)).FeOperator))
	var db uintptr
	var pNew uintptr
	var op int32
	var idxNew int32

	if (int32((*WhereTerm)(unsafe.Pointer(pOne)).FwtFlags)|int32((*WhereTerm)(unsafe.Pointer(pTwo)).FwtFlags))&TERM_VNULL != 0 {
		return
	}
	if int32((*WhereTerm)(unsafe.Pointer(pOne)).FeOperator)&(WO_EQ|int32(WO_EQ)<<(TK_LT-TK_EQ)|int32(WO_EQ)<<(TK_LE-TK_EQ)|int32(WO_EQ)<<(TK_GT-TK_EQ)|int32(WO_EQ)<<(TK_GE-TK_EQ)) == 0 {
		return
	}
	if int32((*WhereTerm)(unsafe.Pointer(pTwo)).FeOperator)&(WO_EQ|int32(WO_EQ)<<(TK_LT-TK_EQ)|int32(WO_EQ)<<(TK_LE-TK_EQ)|int32(WO_EQ)<<(TK_GT-TK_EQ)|int32(WO_EQ)<<(TK_GE-TK_EQ)) == 0 {
		return
	}
	if int32(eOp)&(WO_EQ|int32(WO_EQ)<<(TK_LT-TK_EQ)|int32(WO_EQ)<<(TK_LE-TK_EQ)) != int32(eOp) &&
		int32(eOp)&(WO_EQ|int32(WO_EQ)<<(TK_GT-TK_EQ)|int32(WO_EQ)<<(TK_GE-TK_EQ)) != int32(eOp) {
		return
	}

	if Xsqlite3ExprCompare(tls, uintptr(0), (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pOne)).FpExpr)).FpLeft, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTwo)).FpExpr)).FpLeft, -1) != 0 {
		return
	}
	if Xsqlite3ExprCompare(tls, uintptr(0), (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pOne)).FpExpr)).FpRight, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTwo)).FpExpr)).FpRight, -1) != 0 {
		return
	}

	if int32(eOp)&(int32(eOp)-1) != 0 {
		if int32(eOp)&(int32(WO_EQ)<<(TK_LT-TK_EQ)|int32(WO_EQ)<<(TK_LE-TK_EQ)) != 0 {
			eOp = U16(int32(WO_EQ) << (TK_LE - TK_EQ))
		} else {
			eOp = U16(int32(WO_EQ) << (TK_GE - TK_EQ))
		}
	}
	db = (*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse)).Fdb
	pNew = Xsqlite3ExprDup(tls, db, (*WhereTerm)(unsafe.Pointer(pOne)).FpExpr, 0)
	if pNew == uintptr(0) {
		return
	}
	for op = TK_EQ; int32(eOp) != int32(WO_EQ)<<(op-TK_EQ); op++ {
	}
	(*Expr)(unsafe.Pointer(pNew)).Fop = U8(op)
	idxNew = whereClauseInsert(tls, pWC, pNew, uint16(TERM_VIRTUAL|TERM_DYNAMIC))
	exprAnalyze(tls, pSrc, pWC, idxNew)
}

func exprAnalyzeOrTerm(tls *libc.TLS, pSrc uintptr, pWC uintptr, idxTerm int32) {
	var pWInfo uintptr = (*WhereClause)(unsafe.Pointer(pWC)).FpWInfo
	var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pTerm uintptr = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
	var pExpr uintptr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
	var i int32
	var pOrWc uintptr
	var pOrTerm uintptr
	var pOrInfo uintptr
	var chngToIN Bitmask
	var indexable Bitmask

	*(*uintptr)(unsafe.Pointer(pTerm + 32)) = libc.AssignUintptr(&pOrInfo, Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(WhereOrInfo{}))))
	if pOrInfo == uintptr(0) {
		return
	}
	*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_ORINFO)
	pOrWc = pOrInfo
	libc.Xmemset(tls, pOrWc+40, 0, uint64(unsafe.Sizeof([8]WhereTerm{})))
	Xsqlite3WhereClauseInit(tls, pOrWc, pWInfo)
	Xsqlite3WhereSplit(tls, pOrWc, pExpr, uint8(TK_OR))
	Xsqlite3WhereExprAnalyze(tls, pSrc, pOrWc)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return
	}

	indexable = libc.CplUint64(uint64(0))
	chngToIN = libc.CplUint64(uint64(0))
	i = (*WhereClause)(unsafe.Pointer(pOrWc)).FnTerm - 1
	pOrTerm = (*WhereClause)(unsafe.Pointer(pOrWc)).Fa
__1:
	if !(i >= 0 && indexable != 0) {
		goto __3
	}
	{
		if int32((*WhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&WO_SINGLE == 0 {
			var pAndInfo uintptr

			chngToIN = uint64(0)
			pAndInfo = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(WhereAndInfo{})))
			if pAndInfo != 0 {
				var pAndWC uintptr
				var pAndTerm uintptr
				var j int32
				var b Bitmask = uint64(0)
				*(*uintptr)(unsafe.Pointer(pOrTerm + 32)) = pAndInfo
				*(*U16)(unsafe.Pointer(pOrTerm + 18)) |= U16(TERM_ANDINFO)
				(*WhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator = U16(WO_AND)
				(*WhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor = -1
				pAndWC = pAndInfo
				libc.Xmemset(tls, pAndWC+40, 0, uint64(unsafe.Sizeof([8]WhereTerm{})))
				Xsqlite3WhereClauseInit(tls, pAndWC, (*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)
				Xsqlite3WhereSplit(tls, pAndWC, (*WhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr, uint8(TK_AND))
				Xsqlite3WhereExprAnalyze(tls, pSrc, pAndWC)
				(*WhereClause)(unsafe.Pointer(pAndWC)).FpOuter = pWC
				if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
					j = 0
					pAndTerm = (*WhereClause)(unsafe.Pointer(pAndWC)).Fa
				__4:
					if !(j < (*WhereClause)(unsafe.Pointer(pAndWC)).FnTerm) {
						goto __6
					}
					{
						if allowedOp(tls, int32((*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pAndTerm)).FpExpr)).Fop)) != 0 ||
							int32((*WhereTerm)(unsafe.Pointer(pAndTerm)).FeOperator) == WO_AUX {
							b = b | Xsqlite3WhereGetMask(tls, pWInfo+592, (*WhereTerm)(unsafe.Pointer(pAndTerm)).FleftCursor)
						}

					}
					goto __5
				__5:
					j++
					pAndTerm += 56
					goto __4
					goto __6
				__6:
				}
				indexable = indexable & b
			}
		} else if int32((*WhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&TERM_COPIED != 0 {
		} else {
			var b Bitmask
			b = Xsqlite3WhereGetMask(tls, pWInfo+592, (*WhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor)
			if int32((*WhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&TERM_VIRTUAL != 0 {
				var pOther uintptr = (*WhereClause)(unsafe.Pointer(pOrWc)).Fa + uintptr((*WhereTerm)(unsafe.Pointer(pOrTerm)).FiParent)*56
				b = b | Xsqlite3WhereGetMask(tls, pWInfo+592, (*WhereTerm)(unsafe.Pointer(pOther)).FleftCursor)
			}
			indexable = indexable & b
			if int32((*WhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&WO_EQ == 0 {
				chngToIN = uint64(0)
			} else {
				chngToIN = chngToIN & b
			}
		}

	}
	goto __2
__2:
	i--
	pOrTerm += 56
	goto __1
	goto __3
__3:
	;
	(*WhereOrInfo)(unsafe.Pointer(pOrInfo)).Findexable = indexable
	(*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator = U16(WO_OR)
	(*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = -1
	if indexable != 0 {
		(*WhereClause)(unsafe.Pointer(pWC)).FhasOr = U8(1)
	}

	if indexable != 0 && (*WhereClause)(unsafe.Pointer(pOrWc)).FnTerm == 2 {
		var iOne int32 = 0
		var pOne uintptr
		for libc.AssignUintptr(&pOne, whereNthSubterm(tls, (*WhereClause)(unsafe.Pointer(pOrWc)).Fa, libc.PostIncInt32(&iOne, 1))) != uintptr(0) {
			var iTwo int32 = 0
			var pTwo uintptr
			for libc.AssignUintptr(&pTwo, whereNthSubterm(tls, (*WhereClause)(unsafe.Pointer(pOrWc)).Fa+1*56, libc.PostIncInt32(&iTwo, 1))) != uintptr(0) {
				whereCombineDisjuncts(tls, pSrc, pWC, pOne, pTwo)
			}
		}
	}

	if chngToIN != 0 {
		var okToChngToIN int32 = 0
		var iColumn int32 = -1
		var iCursor int32 = -1
		var j int32 = 0

		for j = 0; j < 2 && !(okToChngToIN != 0); j++ {
			var pLeft uintptr = uintptr(0)
			pOrTerm = (*WhereClause)(unsafe.Pointer(pOrWc)).Fa
			i = (*WhereClause)(unsafe.Pointer(pOrWc)).FnTerm - 1
		__7:
			if !(i >= 0) {
				goto __9
			}
			{
				*(*U16)(unsafe.Pointer(pOrTerm + 18)) &= libc.Uint16FromInt32(libc.CplInt32(TERM_OK))
				if (*WhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCursor {
					goto __8
				}
				if chngToIN&Xsqlite3WhereGetMask(tls, pWInfo+592,
					(*WhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor) == uint64(0) {
					goto __8
				}

				iColumn = *(*int32)(unsafe.Pointer(pOrTerm + 32))
				iCursor = (*WhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor
				pLeft = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft
				goto __9

			}
			goto __8
		__8:
			i--
			pOrTerm += 56
			goto __7
			goto __9
		__9:
			;
			if i < 0 {
				break
			}

			okToChngToIN = 1
		__10:
			if !(i >= 0 && okToChngToIN != 0) {
				goto __12
			}
			{
				if (*WhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor != iCursor {
					*(*U16)(unsafe.Pointer(pOrTerm + 18)) &= libc.Uint16FromInt32(libc.CplInt32(TERM_OK))
				} else if *(*int32)(unsafe.Pointer(pOrTerm + 32)) != iColumn || iColumn == -2 &&
					Xsqlite3ExprCompare(tls, pParse, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft, pLeft, -1) != 0 {
					okToChngToIN = 0
				} else {
					var affLeft int32
					var affRight int32

					affRight = int32(Xsqlite3ExprAffinity(tls, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpRight))
					affLeft = int32(Xsqlite3ExprAffinity(tls, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft))
					if affRight != 0 && affRight != affLeft {
						okToChngToIN = 0
					} else {
						*(*U16)(unsafe.Pointer(pOrTerm + 18)) |= U16(TERM_OK)
					}
				}

			}
			goto __11
		__11:
			i--
			pOrTerm += 56
			goto __10
			goto __12
		__12:
		}

		if okToChngToIN != 0 {
			var pDup uintptr
			var pList uintptr = uintptr(0)
			var pLeft uintptr = uintptr(0)
			var pNew uintptr

			i = (*WhereClause)(unsafe.Pointer(pOrWc)).FnTerm - 1
			pOrTerm = (*WhereClause)(unsafe.Pointer(pOrWc)).Fa
		__13:
			if !(i >= 0) {
				goto __15
			}
			{
				if int32((*WhereTerm)(unsafe.Pointer(pOrTerm)).FwtFlags)&TERM_OK == 0 {
					goto __14
				}

				pDup = Xsqlite3ExprDup(tls, db, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpRight, 0)
				pList = Xsqlite3ExprListAppend(tls, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse, pList, pDup)
				pLeft = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pOrTerm)).FpExpr)).FpLeft

			}
			goto __14
		__14:
			i--
			pOrTerm += 56
			goto __13
			goto __15
		__15:
			;
			pDup = Xsqlite3ExprDup(tls, db, pLeft, 0)
			pNew = Xsqlite3PExpr(tls, pParse, TK_IN, pDup, uintptr(0))
			if pNew != 0 {
				var idxNew int32
				transferJoinMarkings(tls, pNew, pExpr)

				*(*uintptr)(unsafe.Pointer(pNew + 32)) = pList
				idxNew = whereClauseInsert(tls, pWC, pNew, uint16(TERM_VIRTUAL|TERM_DYNAMIC))

				exprAnalyze(tls, pSrc, pWC, idxNew)

				markTermAsChild(tls, pWC, idxNew, idxTerm)
			} else {
				Xsqlite3ExprListDelete(tls, db, pList)
			}
		}
	}
}

func termIsEquivalence(tls *libc.TLS, pParse uintptr, pExpr uintptr) int32 {
	var aff1 uint8
	var aff2 uint8
	var pColl uintptr
	if !((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&U32(SQLITE_Transitive) == U32(0)) {
		return 0
	}
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_EQ && int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_IS {
		return 0
	}
	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0) {
		return 0
	}
	aff1 = Xsqlite3ExprAffinity(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
	aff2 = Xsqlite3ExprAffinity(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
	if int32(aff1) != int32(aff2) &&
		(!(int32(aff1) >= SQLITE_AFF_NUMERIC) || !(int32(aff2) >= SQLITE_AFF_NUMERIC)) {
		return 0
	}
	pColl = Xsqlite3ExprCompareCollSeq(tls, pParse, pExpr)
	if Xsqlite3IsBinary(tls, pColl) != 0 {
		return 1
	}
	return Xsqlite3ExprCollSeqMatch(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
}

func exprSelectUsage(tls *libc.TLS, pMaskSet uintptr, pS uintptr) Bitmask {
	var mask Bitmask = uint64(0)
	for pS != 0 {
		var pSrc uintptr = (*Select)(unsafe.Pointer(pS)).FpSrc
		mask = mask | Xsqlite3WhereExprListUsage(tls, pMaskSet, (*Select)(unsafe.Pointer(pS)).FpEList)
		mask = mask | Xsqlite3WhereExprListUsage(tls, pMaskSet, (*Select)(unsafe.Pointer(pS)).FpGroupBy)
		mask = mask | Xsqlite3WhereExprListUsage(tls, pMaskSet, (*Select)(unsafe.Pointer(pS)).FpOrderBy)
		mask = mask | Xsqlite3WhereExprUsage(tls, pMaskSet, (*Select)(unsafe.Pointer(pS)).FpWhere)
		mask = mask | Xsqlite3WhereExprUsage(tls, pMaskSet, (*Select)(unsafe.Pointer(pS)).FpHaving)
		if pSrc != uintptr(0) {
			var i int32
			for i = 0; i < (*SrcList)(unsafe.Pointer(pSrc)).FnSrc; i++ {
				mask = mask | exprSelectUsage(tls, pMaskSet, (*SrcItem)(unsafe.Pointer(pSrc+8+uintptr(i)*104)).FpSelect)
				if int32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104 + 60 + 4))&0x400>>10) == 0 {
					mask = mask | Xsqlite3WhereExprUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104 + 72)))
				}
				if uint32(int32(*(*uint16)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104 + 60 + 4))&0x4>>2)) != 0 {
					mask = mask | Xsqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*104 + 88)))
				}
			}
		}
		pS = (*Select)(unsafe.Pointer(pS)).FpPrior
	}
	return mask
}

func exprMightBeIndexed2(tls *libc.TLS, pFrom uintptr, aiCurCol uintptr, pExpr uintptr, j int32) int32 {
	var pIdx uintptr
	var i int32
	var iCur int32
	for __ccgo := true; __ccgo; __ccgo = libc.PreIncInt32(&j, 1) < (*SrcList)(unsafe.Pointer(pFrom)).FnSrc {
		iCur = (*SrcItem)(unsafe.Pointer(pFrom + 8 + uintptr(j)*104)).FiCursor
		for pIdx = (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pFrom + 8 + uintptr(j)*104)).FpTab)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
			if (*Index)(unsafe.Pointer(pIdx)).FaColExpr == uintptr(0) {
				continue
			}
			for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol); i++ {
				if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) != -2 {
					continue
				}

				if Xsqlite3ExprCompareSkip(tls, pExpr, (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr+8+uintptr(i)*32)).FpExpr, iCur) == 0 &&
					int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_STRING {
					*(*int32)(unsafe.Pointer(aiCurCol)) = iCur
					*(*int32)(unsafe.Pointer(aiCurCol + 1*4)) = -2
					return 1
				}
			}
		}
	}
	return 0
}

func exprMightBeIndexed(tls *libc.TLS, pFrom uintptr, aiCurCol uintptr, pExpr uintptr, op int32) int32 {
	var i int32

	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_VECTOR && (op >= TK_GT && op <= TK_GE) {
		pExpr = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8)).FpExpr
	}

	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN {
		*(*int32)(unsafe.Pointer(aiCurCol)) = (*Expr)(unsafe.Pointer(pExpr)).FiTable
		*(*int32)(unsafe.Pointer(aiCurCol + 1*4)) = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)
		return 1
	}

	for i = 0; i < (*SrcList)(unsafe.Pointer(pFrom)).FnSrc; i++ {
		var pIdx uintptr
		for pIdx = (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pFrom + 8 + uintptr(i)*104)).FpTab)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
			if (*Index)(unsafe.Pointer(pIdx)).FaColExpr != 0 {
				return exprMightBeIndexed2(tls, pFrom, aiCurCol, pExpr, i)
			}
		}
	}
	return 0
}

func exprAnalyze(tls *libc.TLS, pSrc uintptr, pWC uintptr, idxTerm int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var pWInfo uintptr = (*WhereClause)(unsafe.Pointer(pWC)).FpWInfo
	var pTerm uintptr
	var pMaskSet uintptr
	var pExpr uintptr
	var prereqLeft Bitmask
	var prereqAll Bitmask
	var extraRight Bitmask = uint64(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 16)) = 0
	*(*int32)(unsafe.Pointer(bp + 20)) = 0
	var op int32
	var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	*(*uint8)(unsafe.Pointer(bp + 24)) = uint8(0)
	var nLeft int32

	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return
	}

	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
	pMaskSet = pWInfo + 592
	pExpr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr

	(*WhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect = 0
	prereqLeft = Xsqlite3WhereExprUsage(tls, pMaskSet, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
	op = int32((*Expr)(unsafe.Pointer(pExpr)).Fop)
	if op == TK_IN {
		if Xsqlite3ExprCheckIN(tls, pParse, pExpr) != 0 {
			return
		}
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
			(*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = exprSelectUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
		} else {
			(*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = Xsqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pExpr + 32)))
		}
		prereqAll = prereqLeft | (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
	} else {
		(*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight = Xsqlite3WhereExprUsage(tls, pMaskSet, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
		if (*Expr)(unsafe.Pointer(pExpr)).FpLeft == uintptr(0) ||
			(*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect|EP_IfNullRow) != U32(0) ||
			*(*uintptr)(unsafe.Pointer(pExpr + 32)) != uintptr(0) {
			prereqAll = Xsqlite3WhereExprUsageNN(tls, pMaskSet, pExpr)
		} else {
			prereqAll = prereqLeft | (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
		}
	}
	if (*WhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect != 0 {
		*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_VARSELECT)
	}

	if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON|EP_InnerON) != U32(0) {
		var x Bitmask = Xsqlite3WhereGetMask(tls, pMaskSet, *(*int32)(unsafe.Pointer(pExpr + 52)))
		if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0) {
			prereqAll = prereqAll | x
			extraRight = x - uint64(1)

			if prereqAll>>1 >= x {
				Xsqlite3ErrorMsg(tls, pParse, ts+26358, 0)
				return
			}
		} else if prereqAll>>1 >= x {
			if (*SrcList)(unsafe.Pointer(pSrc)).FnSrc > 0 && int32((*SrcItem)(unsafe.Pointer(pSrc+8)).Ffg.Fjointype)&JT_LTORJ != 0 {
				Xsqlite3ErrorMsg(tls, pParse, ts+26358, 0)
				return
			}
			*(*U32)(unsafe.Pointer(pExpr + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_InnerON))
		}
	}
	(*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll = prereqAll
	(*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = -1
	(*WhereTerm)(unsafe.Pointer(pTerm)).FiParent = -1
	(*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator = U16(0)
	if allowedOp(tls, op) != 0 {
		var pLeft uintptr = Xsqlite3ExprSkipCollate(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)
		var pRight uintptr = Xsqlite3ExprSkipCollate(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight)
		var opMask U16
		if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&prereqLeft == uint64(0) {
			opMask = uint16(WO_ALL)
		} else {
			opMask = uint16(WO_EQUIV)
		}

		if *(*int32)(unsafe.Pointer(pTerm + 32 + 4)) > 0 {
			pLeft = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLeft + 32)) + 8 + uintptr(*(*int32)(unsafe.Pointer(pTerm + 32 + 4))-1)*32)).FpExpr
		}

		if exprMightBeIndexed(tls, pSrc, bp, pLeft, op) != 0 {
			(*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = *(*int32)(unsafe.Pointer(bp))

			*(*int32)(unsafe.Pointer(pTerm + 32)) = *(*int32)(unsafe.Pointer(bp + 1*4))
			(*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator = U16(int32(operatorMask(tls, op)) & int32(opMask))
		}
		if op == TK_IS {
			*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_IS)
		}
		if pRight != 0 &&
			exprMightBeIndexed(tls, pSrc, bp, pRight, op) != 0 &&
			!((*Expr)(unsafe.Pointer(pRight)).Fflags&U32(EP_FixedCol) != U32(0)) {
			var pNew uintptr
			var pDup uintptr
			var eExtraOp U16 = U16(0)

			if (*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor >= 0 {
				var idxNew int32
				pDup = Xsqlite3ExprDup(tls, db, pExpr, 0)
				if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
					Xsqlite3ExprDelete(tls, db, pDup)
					return
				}
				idxNew = whereClauseInsert(tls, pWC, pDup, uint16(TERM_VIRTUAL|TERM_DYNAMIC))
				if idxNew == 0 {
					return
				}
				pNew = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew)*56
				markTermAsChild(tls, pWC, idxNew, idxTerm)
				if op == TK_IS {
					*(*U16)(unsafe.Pointer(pNew + 18)) |= U16(TERM_IS)
				}
				pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
				*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_COPIED)

				if termIsEquivalence(tls, pParse, pDup) != 0 {
					*(*U16)(unsafe.Pointer(pTerm + 20)) |= U16(WO_EQUIV)
					eExtraOp = U16(WO_EQUIV)
				}
			} else {
				pDup = pExpr
				pNew = pTerm
			}
			*(*U16)(unsafe.Pointer(pNew + 18)) |= U16(int32(exprCommute(tls, pParse, pDup)))
			(*WhereTerm)(unsafe.Pointer(pNew)).FleftCursor = *(*int32)(unsafe.Pointer(bp))

			*(*int32)(unsafe.Pointer(pNew + 32)) = *(*int32)(unsafe.Pointer(bp + 1*4))

			(*WhereTerm)(unsafe.Pointer(pNew)).FprereqRight = prereqLeft | extraRight
			(*WhereTerm)(unsafe.Pointer(pNew)).FprereqAll = prereqAll
			(*WhereTerm)(unsafe.Pointer(pNew)).FeOperator = U16((int32(operatorMask(tls, int32((*Expr)(unsafe.Pointer(pDup)).Fop))) + int32(eExtraOp)) & int32(opMask))
		} else if op == TK_ISNULL &&
			!((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0)) &&
			0 == Xsqlite3ExprCanBeNull(tls, pLeft) {
			(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_TRUEFALSE)
			*(*uintptr)(unsafe.Pointer(pExpr + 8)) = ts + 10914
			*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_IsFalse)
			(*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll = uint64(0)
			(*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator = U16(0)
		}
	} else if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_BETWEEN && int32((*WhereClause)(unsafe.Pointer(pWC)).Fop) == TK_AND {
		var pList uintptr
		var i int32

		pList = *(*uintptr)(unsafe.Pointer(pExpr + 32))

		for i = 0; i < 2; i++ {
			var pNewExpr uintptr
			var idxNew int32
			pNewExpr = Xsqlite3PExpr(tls, pParse, int32(ops[i]),
				Xsqlite3ExprDup(tls, db, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, 0),
				Xsqlite3ExprDup(tls, db, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr, 0))
			transferJoinMarkings(tls, pNewExpr, pExpr)
			idxNew = whereClauseInsert(tls, pWC, pNewExpr, uint16(TERM_VIRTUAL|TERM_DYNAMIC))

			exprAnalyze(tls, pSrc, pWC, idxNew)
			pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
			markTermAsChild(tls, pWC, idxNew, idxTerm)
		}
	} else if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_OR {
		exprAnalyzeOrTerm(tls, pSrc, pWC, idxTerm)
		pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
	} else if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_NOTNULL {
		if int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == TK_COLUMN &&
			int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpLeft)).FiColumn) >= 0 &&
			!((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0)) {
			var pNewExpr uintptr
			var pLeft uintptr = (*Expr)(unsafe.Pointer(pExpr)).FpLeft
			var idxNew int32
			var pNewTerm uintptr

			pNewExpr = Xsqlite3PExpr(tls, pParse, TK_GT,
				Xsqlite3ExprDup(tls, db, pLeft, 0),
				Xsqlite3ExprAlloc(tls, db, TK_NULL, uintptr(0), 0))

			idxNew = whereClauseInsert(tls, pWC, pNewExpr,
				uint16(TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL))
			if idxNew != 0 {
				pNewTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew)*56
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FprereqRight = uint64(0)
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FleftCursor = (*Expr)(unsafe.Pointer(pLeft)).FiTable
				*(*int32)(unsafe.Pointer(pNewTerm + 32)) = int32((*Expr)(unsafe.Pointer(pLeft)).FiColumn)
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FeOperator = U16(int32(WO_EQ) << (TK_GT - TK_EQ))
				markTermAsChild(tls, pWC, idxNew, idxTerm)
				pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
				*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_COPIED)
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FprereqAll = (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll
			}
		}
	} else if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_FUNCTION &&
		int32((*WhereClause)(unsafe.Pointer(pWC)).Fop) == TK_AND &&
		isLikeOrGlob(tls, pParse, pExpr, bp+8, bp+16, bp+20) != 0 {
		var pLeft uintptr
		var pStr2 uintptr
		var pNewExpr1 uintptr
		var pNewExpr2 uintptr
		var idxNew1 int32
		var idxNew2 int32
		var zCollSeqName uintptr
		var wtFlags U16 = U16(TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC)

		pLeft = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)) + 8 + 1*32)).FpExpr
		pStr2 = Xsqlite3ExprDup(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8)), 0)

		if *(*int32)(unsafe.Pointer(bp + 20)) != 0 && !(int32((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed) != 0) {
			var i int32
			var c uint8
			*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_LIKE)
			for i = 0; int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + 8)) + uintptr(i))))) != 0; i++ {
				*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)) + 8)) + uintptr(i))) = uint8(int32(c) & ^(int32(Xsqlite3CtypeMap[c]) & 0x20))
				*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pStr2 + 8)) + uintptr(i))) = Xsqlite3UpperToLower[c]
			}
		}

		if !(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
			var c U8
			var pC uintptr
			pC = *(*uintptr)(unsafe.Pointer(pStr2 + 8)) + uintptr(Xsqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(pStr2 + 8)))-1)
			c = *(*U8)(unsafe.Pointer(pC))
			if *(*int32)(unsafe.Pointer(bp + 20)) != 0 {
				if int32(c) == 'A'-1 {
					*(*int32)(unsafe.Pointer(bp + 16)) = 0
				}
				c = Xsqlite3UpperToLower[c]
			}
			*(*U8)(unsafe.Pointer(pC)) = U8(int32(c) + 1)
		}
		zCollSeqName = func() uintptr {
			if *(*int32)(unsafe.Pointer(bp + 20)) != 0 {
				return ts + 26399
			}
			return uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
		}()
		pNewExpr1 = Xsqlite3ExprDup(tls, db, pLeft, 0)
		pNewExpr1 = Xsqlite3PExpr(tls, pParse, TK_GE,
			Xsqlite3ExprAddCollateString(tls, pParse, pNewExpr1, zCollSeqName),
			*(*uintptr)(unsafe.Pointer(bp + 8)))
		transferJoinMarkings(tls, pNewExpr1, pExpr)
		idxNew1 = whereClauseInsert(tls, pWC, pNewExpr1, wtFlags)

		pNewExpr2 = Xsqlite3ExprDup(tls, db, pLeft, 0)
		pNewExpr2 = Xsqlite3PExpr(tls, pParse, TK_LT,
			Xsqlite3ExprAddCollateString(tls, pParse, pNewExpr2, zCollSeqName),
			pStr2)
		transferJoinMarkings(tls, pNewExpr2, pExpr)
		idxNew2 = whereClauseInsert(tls, pWC, pNewExpr2, wtFlags)

		exprAnalyze(tls, pSrc, pWC, idxNew1)
		exprAnalyze(tls, pSrc, pWC, idxNew2)
		pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
		if *(*int32)(unsafe.Pointer(bp + 16)) != 0 {
			markTermAsChild(tls, pWC, idxNew1, idxTerm)
			markTermAsChild(tls, pWC, idxNew2, idxTerm)
		}
	}

	if (int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_EQ || int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_IS) &&
		libc.AssignInt32(&nLeft, Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft)) > 1 &&
		Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pExpr)).FpRight) == nLeft &&
		((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpLeft)).Fflags&U32(EP_xIsSelect) == U32(0) ||
			(*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpRight)).Fflags&U32(EP_xIsSelect) == U32(0)) &&
		int32((*WhereClause)(unsafe.Pointer(pWC)).Fop) == TK_AND {
		var i int32
		for i = 0; i < nLeft; i++ {
			var idxNew int32
			var pNew uintptr
			var pLeft uintptr = Xsqlite3ExprForVectorField(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpLeft, i, nLeft)
			var pRight uintptr = Xsqlite3ExprForVectorField(tls, pParse, (*Expr)(unsafe.Pointer(pExpr)).FpRight, i, nLeft)

			pNew = Xsqlite3PExpr(tls, pParse, int32((*Expr)(unsafe.Pointer(pExpr)).Fop), pLeft, pRight)
			transferJoinMarkings(tls, pNew, pExpr)
			idxNew = whereClauseInsert(tls, pWC, pNew, uint16(TERM_DYNAMIC|TERM_SLICE))
			exprAnalyze(tls, pSrc, pWC, idxNew)
		}
		pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
		*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_CODED | TERM_VIRTUAL)
		(*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator = U16(WO_ROWVAL)
	} else if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_IN &&
		*(*int32)(unsafe.Pointer(pTerm + 32 + 4)) == 0 &&
		int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(pExpr)).FpLeft)).Fop) == TK_VECTOR &&
		(*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) &&
		((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpPrior == uintptr(0) || (*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FselFlags&U32(SF_Values) != 0) &&
		(*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FpWin == uintptr(0) &&
		int32((*WhereClause)(unsafe.Pointer(pWC)).Fop) == TK_AND {
		var i int32
		for i = 0; i < Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer(pExpr)).FpLeft); i++ {
			var idxNew int32
			idxNew = whereClauseInsert(tls, pWC, pExpr, uint16(TERM_VIRTUAL|TERM_SLICE))
			*(*int32)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew)*56 + 32 + 4)) = i + 1
			exprAnalyze(tls, pSrc, pWC, idxNew)
			markTermAsChild(tls, pWC, idxNew, idxTerm)
		}
	} else if int32((*WhereClause)(unsafe.Pointer(pWC)).Fop) == TK_AND {
		*(*uintptr)(unsafe.Pointer(bp + 40)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 32)) = uintptr(0)
		var res int32 = isAuxiliaryVtabOperator(tls, db, pExpr, bp+24, bp+32, bp+40)
		for libc.PostDecInt32(&res, 1) > 0 {
			var idxNew int32
			var pNewTerm uintptr
			var prereqColumn Bitmask
			var prereqExpr Bitmask

			prereqExpr = Xsqlite3WhereExprUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(bp + 40)))
			prereqColumn = Xsqlite3WhereExprUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(bp + 32)))
			if prereqExpr&prereqColumn == uint64(0) {
				var pNewExpr uintptr
				pNewExpr = Xsqlite3PExpr(tls, pParse, TK_MATCH,
					uintptr(0), Xsqlite3ExprDup(tls, db, *(*uintptr)(unsafe.Pointer(bp + 40)), 0))
				if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0) && pNewExpr != 0 {
					*(*U32)(unsafe.Pointer(pNewExpr + 4)) |= U32(EP_OuterON)
					*(*int32)(unsafe.Pointer(pNewExpr + 52)) = *(*int32)(unsafe.Pointer(pExpr + 52))
				}
				idxNew = whereClauseInsert(tls, pWC, pNewExpr, uint16(TERM_VIRTUAL|TERM_DYNAMIC))

				pNewTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxNew)*56
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FprereqRight = prereqExpr
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FleftCursor = (*Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 32)))).FiTable
				*(*int32)(unsafe.Pointer(pNewTerm + 32)) = int32((*Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 32)))).FiColumn)
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FeOperator = U16(WO_AUX)
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FeMatchOp = *(*uint8)(unsafe.Pointer(bp + 24))
				markTermAsChild(tls, pWC, idxNew, idxTerm)
				pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
				*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_COPIED)
				(*WhereTerm)(unsafe.Pointer(pNewTerm)).FprereqAll = (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll
			}
			{
				var t uintptr = *(*uintptr)(unsafe.Pointer(bp + 32))
				*(*uintptr)(unsafe.Pointer(bp + 32)) = *(*uintptr)(unsafe.Pointer(bp + 40))
				*(*uintptr)(unsafe.Pointer(bp + 40)) = t
			}

		}
	}

	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idxTerm)*56
	*(*Bitmask)(unsafe.Pointer(pTerm + 40)) |= extraRight
}

var ops = [2]U8{U8(TK_GE), U8(TK_LE)}

func Xsqlite3WhereSplit(tls *libc.TLS, pWC uintptr, pExpr uintptr, op U8) {
	var pE2 uintptr = Xsqlite3ExprSkipCollateAndLikely(tls, pExpr)
	(*WhereClause)(unsafe.Pointer(pWC)).Fop = op

	if pE2 == uintptr(0) {
		return
	}
	if int32((*Expr)(unsafe.Pointer(pE2)).Fop) != int32(op) {
		whereClauseInsert(tls, pWC, pExpr, uint16(0))
	} else {
		Xsqlite3WhereSplit(tls, pWC, (*Expr)(unsafe.Pointer(pE2)).FpLeft, op)
		Xsqlite3WhereSplit(tls, pWC, (*Expr)(unsafe.Pointer(pE2)).FpRight, op)
	}
}

func whereAddLimitExpr(tls *libc.TLS, pWC uintptr, iReg int32, pExpr uintptr, iCsr int32, eMatchOp int32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pParse uintptr = (*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pNew uintptr
	*(*int32)(unsafe.Pointer(bp)) = 0

	if Xsqlite3ExprIsInteger(tls, pExpr, bp) != 0 && *(*int32)(unsafe.Pointer(bp)) >= 0 {
		var pVal uintptr = Xsqlite3Expr(tls, db, TK_INTEGER, uintptr(0))
		if pVal == uintptr(0) {
			return
		}
		*(*U32)(unsafe.Pointer(pVal + 4)) |= U32(EP_IntValue)
		*(*int32)(unsafe.Pointer(pVal + 8)) = *(*int32)(unsafe.Pointer(bp))
		pNew = Xsqlite3PExpr(tls, pParse, TK_MATCH, uintptr(0), pVal)
	} else {
		var pVal uintptr = Xsqlite3Expr(tls, db, TK_REGISTER, uintptr(0))
		if pVal == uintptr(0) {
			return
		}
		(*Expr)(unsafe.Pointer(pVal)).FiTable = iReg
		pNew = Xsqlite3PExpr(tls, pParse, TK_MATCH, uintptr(0), pVal)
	}
	if pNew != 0 {
		var pTerm uintptr
		var idx int32
		idx = whereClauseInsert(tls, pWC, pNew, uint16(TERM_DYNAMIC|TERM_VIRTUAL))
		pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(idx)*56
		(*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor = iCsr
		(*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator = U16(WO_AUX)
		(*WhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp = U8(eMatchOp)
	}
}

func Xsqlite3WhereAddLimit(tls *libc.TLS, pWC uintptr, p uintptr) {
	if (*Select)(unsafe.Pointer(p)).FpGroupBy == uintptr(0) &&
		(*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Distinct|SF_Aggregate) == U32(0) &&
		((*SrcList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc)).FnSrc == 1 && int32((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc+8)).FpTab)).FeTabType) == TABTYP_VTAB) {
		var pOrderBy uintptr = (*Select)(unsafe.Pointer(p)).FpOrderBy
		var iCsr int32 = (*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FiCursor
		var ii int32

		for ii = 0; ii < (*WhereClause)(unsafe.Pointer(pWC)).FnTerm; ii++ {
			if int32((*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(ii)*56)).FwtFlags)&TERM_CODED != 0 {
				continue
			}
			if (*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(ii)*56)).FnChild != 0 {
				continue
			}
			if (*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr(ii)*56)).FleftCursor != iCsr {
				return
			}
		}

		if pOrderBy != 0 {
			for ii = 0; ii < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr; ii++ {
				var pExpr uintptr = (*ExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(ii)*32)).FpExpr
				if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_COLUMN {
					return
				}
				if (*Expr)(unsafe.Pointer(pExpr)).FiTable != iCsr {
					return
				}
				if int32((*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(ii)*32)).Ffg.FsortFlags)&KEYINFO_ORDER_BIGNULL != 0 {
					return
				}
			}
		}

		whereAddLimitExpr(tls, pWC, (*Select)(unsafe.Pointer(p)).FiLimit, (*Expr)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpLimit)).FpLeft,
			iCsr, SQLITE_INDEX_CONSTRAINT_LIMIT)
		if (*Select)(unsafe.Pointer(p)).FiOffset > 0 {
			whereAddLimitExpr(tls, pWC, (*Select)(unsafe.Pointer(p)).FiOffset, (*Expr)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpLimit)).FpRight,
				iCsr, SQLITE_INDEX_CONSTRAINT_OFFSET)
		}
	}
}

func Xsqlite3WhereClauseInit(tls *libc.TLS, pWC uintptr, pWInfo uintptr) {
	(*WhereClause)(unsafe.Pointer(pWC)).FpWInfo = pWInfo
	(*WhereClause)(unsafe.Pointer(pWC)).FhasOr = U8(0)
	(*WhereClause)(unsafe.Pointer(pWC)).FpOuter = uintptr(0)
	(*WhereClause)(unsafe.Pointer(pWC)).FnTerm = 0
	(*WhereClause)(unsafe.Pointer(pWC)).FnBase = 0
	(*WhereClause)(unsafe.Pointer(pWC)).FnSlot = int32(uint64(unsafe.Sizeof([8]WhereTerm{})) / uint64(unsafe.Sizeof(WhereTerm{})))
	(*WhereClause)(unsafe.Pointer(pWC)).Fa = pWC + 40
}

func Xsqlite3WhereClauseClear(tls *libc.TLS, pWC uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse)).Fdb

	if (*WhereClause)(unsafe.Pointer(pWC)).FnTerm > 0 {
		var a uintptr = (*WhereClause)(unsafe.Pointer(pWC)).Fa
		var aLast uintptr = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*WhereClause)(unsafe.Pointer(pWC)).FnTerm-1)*56
		for 1 != 0 {
			if int32((*WhereTerm)(unsafe.Pointer(a)).FwtFlags)&TERM_DYNAMIC != 0 {
				Xsqlite3ExprDelete(tls, db, (*WhereTerm)(unsafe.Pointer(a)).FpExpr)
			}
			if int32((*WhereTerm)(unsafe.Pointer(a)).FwtFlags)&(TERM_ORINFO|TERM_ANDINFO) != 0 {
				if int32((*WhereTerm)(unsafe.Pointer(a)).FwtFlags)&TERM_ORINFO != 0 {
					whereOrInfoDelete(tls, db, *(*uintptr)(unsafe.Pointer(a + 32)))
				} else {
					whereAndInfoDelete(tls, db, *(*uintptr)(unsafe.Pointer(a + 32)))
				}
			}
			if a == aLast {
				break
			}
			a += 56
		}
	}
}

func sqlite3WhereExprUsageFull(tls *libc.TLS, pMaskSet uintptr, p uintptr) Bitmask {
	var mask Bitmask
	if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_IF_NULL_ROW {
		mask = Xsqlite3WhereGetMask(tls, pMaskSet, (*Expr)(unsafe.Pointer(p)).FiTable)
	} else {
		mask = uint64(0)
	}
	if (*Expr)(unsafe.Pointer(p)).FpLeft != 0 {
		mask = mask | Xsqlite3WhereExprUsageNN(tls, pMaskSet, (*Expr)(unsafe.Pointer(p)).FpLeft)
	}
	if (*Expr)(unsafe.Pointer(p)).FpRight != 0 {
		mask = mask | Xsqlite3WhereExprUsageNN(tls, pMaskSet, (*Expr)(unsafe.Pointer(p)).FpRight)

	} else if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_xIsSelect) != U32(0) {
		if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_VarSelect) != U32(0) {
			(*WhereMaskSet)(unsafe.Pointer(pMaskSet)).FbVarSelect = 1
		}
		mask = mask | exprSelectUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(p + 32)))
	} else if *(*uintptr)(unsafe.Pointer(p + 32)) != 0 {
		mask = mask | Xsqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(p + 32)))
	}
	if (int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_FUNCTION || int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_AGG_FUNCTION) && (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_WinFunc) != U32(0) {
		mask = mask | Xsqlite3WhereExprListUsage(tls, pMaskSet, (*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FpPartition)
		mask = mask | Xsqlite3WhereExprListUsage(tls, pMaskSet, (*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FpOrderBy)
		mask = mask | Xsqlite3WhereExprUsage(tls, pMaskSet, (*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 64)))).FpFilter)
	}
	return mask
}

func Xsqlite3WhereExprUsageNN(tls *libc.TLS, pMaskSet uintptr, p uintptr) Bitmask {
	if int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_COLUMN && !((*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_FixedCol) != U32(0)) {
		return Xsqlite3WhereGetMask(tls, pMaskSet, (*Expr)(unsafe.Pointer(p)).FiTable)
	} else if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_TokenOnly|EP_Leaf) != U32(0) {
		return uint64(0)
	}
	return sqlite3WhereExprUsageFull(tls, pMaskSet, p)
}

func Xsqlite3WhereExprUsage(tls *libc.TLS, pMaskSet uintptr, p uintptr) Bitmask {
	if p != 0 {
		return Xsqlite3WhereExprUsageNN(tls, pMaskSet, p)
	}
	return uint64(0)
}

func Xsqlite3WhereExprListUsage(tls *libc.TLS, pMaskSet uintptr, pList uintptr) Bitmask {
	var i int32
	var mask Bitmask = uint64(0)
	if pList != 0 {
		for i = 0; i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
			mask = mask | Xsqlite3WhereExprUsage(tls, pMaskSet, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr)
		}
	}
	return mask
}

func Xsqlite3WhereExprAnalyze(tls *libc.TLS, pTabList uintptr, pWC uintptr) {
	var i int32
	for i = (*WhereClause)(unsafe.Pointer(pWC)).FnTerm - 1; i >= 0; i-- {
		exprAnalyze(tls, pTabList, pWC, i)
	}
}

func Xsqlite3WhereTabFuncArgs(tls *libc.TLS, pParse uintptr, pItem uintptr, pWC uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTab uintptr
	var j int32
	var k int32
	var pArgs uintptr
	var pColRef uintptr
	var pTerm uintptr
	if int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x4>>2) == 0 {
		return
	}
	pTab = (*SrcItem)(unsafe.Pointer(pItem)).FpTab

	pArgs = *(*uintptr)(unsafe.Pointer(pItem + 88))
	if pArgs == uintptr(0) {
		return
	}
	for j = libc.AssignInt32(&k, 0); j < (*ExprList)(unsafe.Pointer(pArgs)).FnExpr; j++ {
		var pRhs uintptr
		var joinType U32
		for k < int32((*Table)(unsafe.Pointer(pTab)).FnCol) && int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(k)*24)).FcolFlags)&COLFLAG_HIDDEN == 0 {
			k++
		}
		if k >= int32((*Table)(unsafe.Pointer(pTab)).FnCol) {
			Xsqlite3ErrorMsg(tls, pParse, ts+26406,
				libc.VaList(bp, (*Table)(unsafe.Pointer(pTab)).FzName, j))
			return
		}
		pColRef = Xsqlite3ExprAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_COLUMN, uintptr(0), 0)
		if pColRef == uintptr(0) {
			return
		}
		(*Expr)(unsafe.Pointer(pColRef)).FiTable = (*SrcItem)(unsafe.Pointer(pItem)).FiCursor
		(*Expr)(unsafe.Pointer(pColRef)).FiColumn = YnVar(libc.PostIncInt32(&k, 1))

		*(*uintptr)(unsafe.Pointer(pColRef + 64)) = pTab
		*(*Bitmask)(unsafe.Pointer(pItem + 80)) |= Xsqlite3ExprColUsed(tls, pColRef)
		pRhs = Xsqlite3PExpr(tls, pParse, TK_UPLUS,
			Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*ExprList_item)(unsafe.Pointer(pArgs+8+uintptr(j)*32)).FpExpr, 0), uintptr(0))
		pTerm = Xsqlite3PExpr(tls, pParse, TK_EQ, pColRef, pRhs)
		if int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ|JT_RIGHT) != 0 {
			joinType = U32(EP_OuterON)
		} else {
			joinType = U32(EP_InnerON)
		}
		Xsqlite3SetJoinExpr(tls, pTerm, (*SrcItem)(unsafe.Pointer(pItem)).FiCursor, joinType)
		whereClauseInsert(tls, pWC, pTerm, uint16(TERM_DYNAMIC))
	}
}

type HiddenIndexInfo1 = struct {
	FpWC         uintptr
	FpParse      uintptr
	FeDistinct   int32
	FmIn         U32
	FmHandleIn   U32
	F__ccgo_pad1 [4]byte
	FaRhs        [1]uintptr
}

type HiddenIndexInfo = HiddenIndexInfo1

func Xsqlite3WhereOutputRowCount(tls *libc.TLS, pWInfo uintptr) LogEst {
	return (*WhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut
}

func Xsqlite3WhereIsDistinct(tls *libc.TLS, pWInfo uintptr) int32 {
	return int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct)
}

func Xsqlite3WhereIsOrdered(tls *libc.TLS, pWInfo uintptr) int32 {
	if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) < 0 {
		return 0
	}
	return int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat)
}

func Xsqlite3WhereOrderByLimitOptLabel(tls *libc.TLS, pWInfo uintptr) int32 {
	var pInner uintptr
	if !(int32(*(*uint8)(unsafe.Pointer(pWInfo + 68))&0x4>>2) != 0) {
		return (*WhereInfo)(unsafe.Pointer(pWInfo)).FiContinue
	}
	pInner = pWInfo + 856 + uintptr(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-1)*104

	if (*WhereLevel)(unsafe.Pointer(pInner)).FpRJ != 0 {
		return (*WhereInfo)(unsafe.Pointer(pWInfo)).FiContinue
	}
	return (*WhereLevel)(unsafe.Pointer(pInner)).FaddrNxt
}

func Xsqlite3WhereMinMaxOptEarlyOut(tls *libc.TLS, v uintptr, pWInfo uintptr) {
	var pInner uintptr
	var i int32
	if !(int32(*(*uint8)(unsafe.Pointer(pWInfo + 68))&0x4>>2) != 0) {
		return
	}
	if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == 0 {
		return
	}
	for i = int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - 1; i >= 0; i-- {
		pInner = pWInfo + 856 + uintptr(i)*104
		if (*WhereLoop1)(unsafe.Pointer((*WhereLevel)(unsafe.Pointer(pInner)).FpWLoop)).FwsFlags&U32(WHERE_COLUMN_IN) != U32(0) {
			Xsqlite3VdbeGoto(tls, v, (*WhereLevel)(unsafe.Pointer(pInner)).FaddrNxt)
			return
		}
	}
	Xsqlite3VdbeGoto(tls, v, (*WhereInfo)(unsafe.Pointer(pWInfo)).FiBreak)
}

func Xsqlite3WhereContinueLabel(tls *libc.TLS, pWInfo uintptr) int32 {
	return (*WhereInfo)(unsafe.Pointer(pWInfo)).FiContinue
}

func Xsqlite3WhereBreakLabel(tls *libc.TLS, pWInfo uintptr) int32 {
	return (*WhereInfo)(unsafe.Pointer(pWInfo)).FiBreak
}

func Xsqlite3WhereOkOnePass(tls *libc.TLS, pWInfo uintptr, aiCur uintptr) int32 {
	libc.Xmemcpy(tls, aiCur, pWInfo+40, uint64(unsafe.Sizeof(int32(0)))*uint64(2))
	return int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass)
}

func Xsqlite3WhereUsesDeferredSeek(tls *libc.TLS, pWInfo uintptr) int32 {
	return int32(*(*uint8)(unsafe.Pointer(pWInfo + 68)) & 0x1 >> 0)
}

func whereOrMove(tls *libc.TLS, pDest uintptr, pSrc uintptr) {
	(*WhereOrSet)(unsafe.Pointer(pDest)).Fn = (*WhereOrSet)(unsafe.Pointer(pSrc)).Fn
	libc.Xmemcpy(tls, pDest+8, pSrc+8, uint64((*WhereOrSet)(unsafe.Pointer(pDest)).Fn)*uint64(unsafe.Sizeof(WhereOrCost{})))
}

func whereOrInsert(tls *libc.TLS, pSet uintptr, prereq Bitmask, rRun LogEst, nOut LogEst) int32 {
	var i U16
	var p uintptr
	i = (*WhereOrSet)(unsafe.Pointer(pSet)).Fn
	p = pSet + 8
__1:
	if !(int32(i) > 0) {
		goto __3
	}
	if !(int32(rRun) <= int32((*WhereOrCost)(unsafe.Pointer(p)).FrRun) && prereq&(*WhereOrCost)(unsafe.Pointer(p)).Fprereq == prereq) {
		goto __4
	}
	goto whereOrInsert_done
__4:
	;
	if !(int32((*WhereOrCost)(unsafe.Pointer(p)).FrRun) <= int32(rRun) && (*WhereOrCost)(unsafe.Pointer(p)).Fprereq&prereq == (*WhereOrCost)(unsafe.Pointer(p)).Fprereq) {
		goto __5
	}
	return 0
__5:
	;
	goto __2
__2:
	i--
	p += 16
	goto __1
	goto __3
__3:
	;
	if !(int32((*WhereOrSet)(unsafe.Pointer(pSet)).Fn) < N_OR_COST) {
		goto __6
	}
	p = pSet + 8 + uintptr(libc.PostIncUint16(&(*WhereOrSet)(unsafe.Pointer(pSet)).Fn, 1))*16
	(*WhereOrCost)(unsafe.Pointer(p)).FnOut = nOut
	goto __7
__6:
	p = pSet + 8
	i = U16(1)
__8:
	if !(int32(i) < int32((*WhereOrSet)(unsafe.Pointer(pSet)).Fn)) {
		goto __10
	}
	if !(int32((*WhereOrCost)(unsafe.Pointer(p)).FrRun) > int32((*WhereOrCost)(unsafe.Pointer(pSet+8+uintptr(i)*16)).FrRun)) {
		goto __11
	}
	p = pSet + 8 + uintptr(i)*16
__11:
	;
	goto __9
__9:
	i++
	goto __8
	goto __10
__10:
	;
	if !(int32((*WhereOrCost)(unsafe.Pointer(p)).FrRun) <= int32(rRun)) {
		goto __12
	}
	return 0
__12:
	;
__7:
	;
whereOrInsert_done:
	(*WhereOrCost)(unsafe.Pointer(p)).Fprereq = prereq
	(*WhereOrCost)(unsafe.Pointer(p)).FrRun = rRun
	if !(int32((*WhereOrCost)(unsafe.Pointer(p)).FnOut) > int32(nOut)) {
		goto __13
	}
	(*WhereOrCost)(unsafe.Pointer(p)).FnOut = nOut
__13:
	;
	return 1
}

func Xsqlite3WhereGetMask(tls *libc.TLS, pMaskSet uintptr, iCursor int32) Bitmask {
	var i int32

	if *(*int32)(unsafe.Pointer(pMaskSet + 8)) == iCursor {
		return uint64(1)
	}
	for i = 1; i < (*WhereMaskSet)(unsafe.Pointer(pMaskSet)).Fn; i++ {
		if *(*int32)(unsafe.Pointer(pMaskSet + 8 + uintptr(i)*4)) == iCursor {
			return uint64(1) << i
		}
	}
	return uint64(0)
}

func Xsqlite3WhereMalloc(tls *libc.TLS, pWInfo uintptr, nByte U64) uintptr {
	var pBlock uintptr
	pBlock = Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb, nByte+U64(unsafe.Sizeof(WhereMemBlock{})))
	if pBlock != 0 {
		(*WhereMemBlock)(unsafe.Pointer(pBlock)).FpNext = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree
		(*WhereMemBlock)(unsafe.Pointer(pBlock)).Fsz = nByte
		(*WhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree = pBlock
		pBlock += 16
	}
	return pBlock
}

func Xsqlite3WhereRealloc(tls *libc.TLS, pWInfo uintptr, pOld uintptr, nByte U64) uintptr {
	var pNew uintptr = Xsqlite3WhereMalloc(tls, pWInfo, nByte)
	if pNew != 0 && pOld != 0 {
		var pOldBlk uintptr = pOld
		pOldBlk -= 16

		libc.Xmemcpy(tls, pNew, pOld, (*WhereMemBlock)(unsafe.Pointer(pOldBlk)).Fsz)
	}
	return pNew
}

func createMask(tls *libc.TLS, pMaskSet uintptr, iCursor int32) {
	*(*int32)(unsafe.Pointer(pMaskSet + 8 + uintptr(libc.PostIncInt32(&(*WhereMaskSet)(unsafe.Pointer(pMaskSet)).Fn, 1))*4)) = iCursor
}

func whereRightSubexprIsColumn(tls *libc.TLS, p uintptr) uintptr {
	p = Xsqlite3ExprSkipCollateAndLikely(tls, (*Expr)(unsafe.Pointer(p)).FpRight)
	if p != uintptr(0) && int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_COLUMN && !((*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_FixedCol) != U32(0)) {
		return p
	}
	return uintptr(0)
}

func whereScanNext(tls *libc.TLS, pScan uintptr) uintptr {
	var iCur int32
	var iColumn I16
	var pX uintptr
	var pWC uintptr
	var pTerm uintptr
	var k int32 = (*WhereScan)(unsafe.Pointer(pScan)).Fk

	pWC = (*WhereScan)(unsafe.Pointer(pScan)).FpWC
	for 1 != 0 {
		iColumn = *(*I16)(unsafe.Pointer(pScan + 88 + uintptr(int32((*WhereScan)(unsafe.Pointer(pScan)).FiEquiv)-1)*2))
		iCur = *(*int32)(unsafe.Pointer(pScan + 44 + uintptr(int32((*WhereScan)(unsafe.Pointer(pScan)).FiEquiv)-1)*4))

		for __ccgo := true; __ccgo; __ccgo = pWC != uintptr(0) {
			pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(k)*56
		__1:
			if !(k < (*WhereClause)(unsafe.Pointer(pWC)).FnTerm) {
				goto __3
			}
			{
				if (*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor == iCur &&
					*(*int32)(unsafe.Pointer(pTerm + 32)) == int32(iColumn) &&
					(int32(iColumn) != -2 ||
						Xsqlite3ExprCompareSkip(tls, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft,
							(*WhereScan)(unsafe.Pointer(pScan)).FpIdxExpr, iCur) == 0) &&
					(int32((*WhereScan)(unsafe.Pointer(pScan)).FiEquiv) <= 1 || !((*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&U32(EP_OuterON) != U32(0))) {
					if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_EQUIV != 0 &&
						int32((*WhereScan)(unsafe.Pointer(pScan)).FnEquiv) < int32(uint64(unsafe.Sizeof([11]int32{}))/uint64(unsafe.Sizeof(int32(0)))) &&
						libc.AssignUintptr(&pX, whereRightSubexprIsColumn(tls, (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)) != uintptr(0) {
						var j int32
						for j = 0; j < int32((*WhereScan)(unsafe.Pointer(pScan)).FnEquiv); j++ {
							if *(*int32)(unsafe.Pointer(pScan + 44 + uintptr(j)*4)) == (*Expr)(unsafe.Pointer(pX)).FiTable &&
								int32(*(*I16)(unsafe.Pointer(pScan + 88 + uintptr(j)*2))) == int32((*Expr)(unsafe.Pointer(pX)).FiColumn) {
								break
							}
						}
						if j == int32((*WhereScan)(unsafe.Pointer(pScan)).FnEquiv) {
							*(*int32)(unsafe.Pointer(pScan + 44 + uintptr(j)*4)) = (*Expr)(unsafe.Pointer(pX)).FiTable
							*(*I16)(unsafe.Pointer(pScan + 88 + uintptr(j)*2)) = (*Expr)(unsafe.Pointer(pX)).FiColumn
							(*WhereScan)(unsafe.Pointer(pScan)).FnEquiv++
						}
					}
					if U32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(*WhereScan)(unsafe.Pointer(pScan)).FopMask != U32(0) {
						if (*WhereScan)(unsafe.Pointer(pScan)).FzCollName != 0 && int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_ISNULL == 0 {
							var pColl uintptr
							var pParse uintptr = (*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse
							pX = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
							if !(Xsqlite3IndexAffinityOk(tls, pX, (*WhereScan)(unsafe.Pointer(pScan)).Fidxaff) != 0) {
								goto __2
							}

							pColl = Xsqlite3ExprCompareCollSeq(tls, pParse, pX)
							if pColl == uintptr(0) {
								pColl = (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FpDfltColl
							}
							if Xsqlite3StrICmp(tls, (*CollSeq)(unsafe.Pointer(pColl)).FzName, (*WhereScan)(unsafe.Pointer(pScan)).FzCollName) != 0 {
								goto __2
							}
						}
						if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(WO_EQ|WO_IS) != 0 &&
							func() bool {
								pX = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
								return pX != uintptr(0)
							}() &&
							int32((*Expr)(unsafe.Pointer(pX)).Fop) == TK_COLUMN &&
							(*Expr)(unsafe.Pointer(pX)).FiTable == *(*int32)(unsafe.Pointer(pScan + 44)) &&
							int32((*Expr)(unsafe.Pointer(pX)).FiColumn) == int32(*(*I16)(unsafe.Pointer(pScan + 88))) {
							goto __2
						}
						(*WhereScan)(unsafe.Pointer(pScan)).FpWC = pWC
						(*WhereScan)(unsafe.Pointer(pScan)).Fk = k + 1
						return pTerm
					}
				}

			}
			goto __2
		__2:
			k++
			pTerm += 56
			goto __1
			goto __3
		__3:
			;
			pWC = (*WhereClause)(unsafe.Pointer(pWC)).FpOuter
			k = 0
		}
		if int32((*WhereScan)(unsafe.Pointer(pScan)).FiEquiv) >= int32((*WhereScan)(unsafe.Pointer(pScan)).FnEquiv) {
			break
		}
		pWC = (*WhereScan)(unsafe.Pointer(pScan)).FpOrigWC
		k = 0
		(*WhereScan)(unsafe.Pointer(pScan)).FiEquiv++
	}
	return uintptr(0)
}

func whereScanInitIndexExpr(tls *libc.TLS, pScan uintptr) uintptr {
	(*WhereScan)(unsafe.Pointer(pScan)).Fidxaff = Xsqlite3ExprAffinity(tls, (*WhereScan)(unsafe.Pointer(pScan)).FpIdxExpr)
	return whereScanNext(tls, pScan)
}

func whereScanInit(tls *libc.TLS, pScan uintptr, pWC uintptr, iCur int32, iColumn int32, opMask U32, pIdx uintptr) uintptr {
	(*WhereScan)(unsafe.Pointer(pScan)).FpOrigWC = pWC
	(*WhereScan)(unsafe.Pointer(pScan)).FpWC = pWC
	(*WhereScan)(unsafe.Pointer(pScan)).FpIdxExpr = uintptr(0)
	(*WhereScan)(unsafe.Pointer(pScan)).Fidxaff = uint8(0)
	(*WhereScan)(unsafe.Pointer(pScan)).FzCollName = uintptr(0)
	(*WhereScan)(unsafe.Pointer(pScan)).FopMask = opMask
	(*WhereScan)(unsafe.Pointer(pScan)).Fk = 0
	*(*int32)(unsafe.Pointer(pScan + 44)) = iCur
	(*WhereScan)(unsafe.Pointer(pScan)).FnEquiv = uint8(1)
	(*WhereScan)(unsafe.Pointer(pScan)).FiEquiv = uint8(1)
	if pIdx != 0 {
		var j int32 = iColumn
		iColumn = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(j)*2)))
		if iColumn == int32((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FiPKey) {
			iColumn = -1
		} else if iColumn >= 0 {
			(*WhereScan)(unsafe.Pointer(pScan)).Fidxaff = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(iColumn)*24)).Faffinity
			(*WhereScan)(unsafe.Pointer(pScan)).FzCollName = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*8))
		} else if iColumn == -2 {
			(*WhereScan)(unsafe.Pointer(pScan)).FpIdxExpr = (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(j)*32)).FpExpr
			(*WhereScan)(unsafe.Pointer(pScan)).FzCollName = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(j)*8))
			*(*I16)(unsafe.Pointer(pScan + 88)) = int16(-2)
			return whereScanInitIndexExpr(tls, pScan)
		}
	} else if iColumn == -2 {
		return uintptr(0)
	}
	*(*I16)(unsafe.Pointer(pScan + 88)) = I16(iColumn)
	return whereScanNext(tls, pScan)
}

func Xsqlite3WhereFindTerm(tls *libc.TLS, pWC uintptr, iCur int32, iColumn int32, notReady Bitmask, op U32, pIdx uintptr) uintptr {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	var pResult uintptr = uintptr(0)
	var p uintptr

	p = whereScanInit(tls, bp, pWC, iCur, iColumn, op, pIdx)
	op = op & U32(WO_EQ|WO_IS)
	for p != 0 {
		if (*WhereTerm)(unsafe.Pointer(p)).FprereqRight&notReady == uint64(0) {
			if (*WhereTerm)(unsafe.Pointer(p)).FprereqRight == uint64(0) && U32((*WhereTerm)(unsafe.Pointer(p)).FeOperator)&op != U32(0) {
				return p
			}
			if pResult == uintptr(0) {
				pResult = p
			}
		}
		p = whereScanNext(tls, bp)
	}
	return pResult
}

func findIndexCol(tls *libc.TLS, pParse uintptr, pList uintptr, iBase int32, pIdx uintptr, iCol int32) int32 {
	var i int32
	var zColl uintptr = *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(iCol)*8))

	for i = 0; i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
		var p uintptr = Xsqlite3ExprSkipCollateAndLikely(tls, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr)
		if p != uintptr(0) &&
			(int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_COLUMN || int32((*Expr)(unsafe.Pointer(p)).Fop) == TK_AGG_COLUMN) &&
			int32((*Expr)(unsafe.Pointer(p)).FiColumn) == int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iCol)*2))) &&
			(*Expr)(unsafe.Pointer(p)).FiTable == iBase {
			var pColl uintptr = Xsqlite3ExprNNCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr)
			if 0 == Xsqlite3StrICmp(tls, (*CollSeq)(unsafe.Pointer(pColl)).FzName, zColl) {
				return i
			}
		}
	}

	return -1
}

func indexColumnNotNull(tls *libc.TLS, pIdx uintptr, iCol int32) int32 {
	var j int32

	j = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iCol)*2)))
	if j >= 0 {
		return int32(*(*uint8)(unsafe.Pointer((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(j)*24 + 8)) & 0xf >> 0)
	} else if j == -1 {
		return 1
	} else {
		return 0

	}
	return int32(0)
}

func isDistinctRedundant(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWC uintptr, pDistinct uintptr) int32 {
	var pTab uintptr
	var pIdx uintptr
	var i int32
	var iBase int32

	if (*SrcList)(unsafe.Pointer(pTabList)).FnSrc != 1 {
		return 0
	}
	iBase = (*SrcItem)(unsafe.Pointer(pTabList + 8)).FiCursor
	pTab = (*SrcItem)(unsafe.Pointer(pTabList + 8)).FpTab

	for i = 0; i < (*ExprList)(unsafe.Pointer(pDistinct)).FnExpr; i++ {
		var p uintptr = Xsqlite3ExprSkipCollateAndLikely(tls, (*ExprList_item)(unsafe.Pointer(pDistinct+8+uintptr(i)*32)).FpExpr)
		if p == uintptr(0) {
			continue
		}
		if int32((*Expr)(unsafe.Pointer(p)).Fop) != TK_COLUMN && int32((*Expr)(unsafe.Pointer(p)).Fop) != TK_AGG_COLUMN {
			continue
		}
		if (*Expr)(unsafe.Pointer(p)).FiTable == iBase && int32((*Expr)(unsafe.Pointer(p)).FiColumn) < 0 {
			return 1
		}
	}

	for pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
		if !(int32((*Index)(unsafe.Pointer(pIdx)).FonError) != OE_None) {
			continue
		}
		if (*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != 0 {
			continue
		}
		for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol); i++ {
			if uintptr(0) == Xsqlite3WhereFindTerm(tls, pWC, iBase, i, libc.CplUint64(uint64(0)), uint32(WO_EQ), pIdx) {
				if findIndexCol(tls, pParse, pDistinct, iBase, pIdx, i) < 0 {
					break
				}
				if indexColumnNotNull(tls, pIdx, i) == 0 {
					break
				}
			}
		}
		if i == int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) {
			return 1
		}
	}

	return 0
}

func estLog(tls *libc.TLS, N LogEst) LogEst {
	if int32(N) <= 10 {
		return int16(0)
	}
	return int16(int32(Xsqlite3LogEst(tls, uint64(N))) - 33)
}

func translateColumnToCopy(tls *libc.TLS, pParse uintptr, iStart int32, iTabCur int32, iRegister int32, iAutoidxCur int32) {
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var pOp uintptr = Xsqlite3VdbeGetOp(tls, v, iStart)
	var iEnd int32 = Xsqlite3VdbeCurrentAddr(tls, v)
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
		return
	}
__1:
	if !(iStart < iEnd) {
		goto __3
	}
	{
		if (*VdbeOp)(unsafe.Pointer(pOp)).Fp1 != iTabCur {
			goto __2
		}
		if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Column {
			(*VdbeOp)(unsafe.Pointer(pOp)).Fopcode = U8(OP_Copy)
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*VdbeOp)(unsafe.Pointer(pOp)).Fp2 + iRegister
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp2 = (*VdbeOp)(unsafe.Pointer(pOp)).Fp3
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp3 = 0
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp5 = U16(2)
		} else if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Rowid {
			(*VdbeOp)(unsafe.Pointer(pOp)).Fopcode = U8(OP_Sequence)
			(*VdbeOp)(unsafe.Pointer(pOp)).Fp1 = iAutoidxCur
		}

	}
	goto __2
__2:
	iStart++
	pOp += 32
	goto __1
	goto __3
__3:
}

func constraintCompatibleWithOuterJoin(tls *libc.TLS, pTerm uintptr, pSrc uintptr) int32 {
	if !((*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&U32(EP_OuterON|EP_InnerON) != U32(0)) ||
		*(*int32)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr + 52)) != (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor {
		return 0
	}
	if int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(JT_LEFT|JT_RIGHT) != 0 &&
		(*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&U32(EP_InnerON) != U32(0) {
		return 0
	}
	return 1
}

func termCanDriveIndex(tls *libc.TLS, pTerm uintptr, pSrc uintptr, notReady Bitmask) int32 {
	var aff uint8
	if (*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor {
		return 0
	}
	if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(WO_EQ|WO_IS) == 0 {
		return 0
	}

	if int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ|JT_RIGHT) != 0 &&
		!(constraintCompatibleWithOuterJoin(tls, pTerm, pSrc) != 0) {
		return 0
	}
	if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&notReady != uint64(0) {
		return 0
	}

	if *(*int32)(unsafe.Pointer(pTerm + 32)) < 0 {
		return 0
	}
	aff = (*Column)(unsafe.Pointer((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pSrc)).FpTab)).FaCol + uintptr(*(*int32)(unsafe.Pointer(pTerm + 32)))*24)).Faffinity
	if !(Xsqlite3IndexAffinityOk(tls, (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr, aff) != 0) {
		return 0
	}

	return 1
}

func constructAutomaticIndex(tls *libc.TLS, pParse uintptr, pWC uintptr, pSrc uintptr, notReady Bitmask, pLevel uintptr) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var nKeyCol int32
	var pTerm uintptr
	var pWCEnd uintptr
	var pIdx uintptr
	var v uintptr
	var addrInit int32
	var pTable uintptr
	var addrTop int32
	var regRecord int32
	var n int32
	var i int32
	var mxBitCol int32
	var pColl uintptr
	var pLoop uintptr

	var idxCols Bitmask
	var extraCols Bitmask
	var sentWarning U8
	var pPartial uintptr
	var iContinue int32
	var pTabItem uintptr
	var addrCounter int32
	var regBase int32
	var iCol int32
	var cMask Bitmask
	var pExpr uintptr
	var pX uintptr
	var iCol1 int32
	var cMask1 Bitmask
	var regYield int32
	sentWarning = U8(0)
	pPartial = uintptr(0)
	iContinue = 0
	addrCounter = 0

	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe

	addrInit = Xsqlite3VdbeAddOp0(tls, v, OP_Once)

	nKeyCol = 0
	pTable = (*SrcItem)(unsafe.Pointer(pSrc)).FpTab
	pWCEnd = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*WhereClause)(unsafe.Pointer(pWC)).FnTerm)*56
	pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	idxCols = uint64(0)
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
__1:
	if !(pTerm < pWCEnd) {
		goto __3
	}
	pExpr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr

	if !(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_VIRTUAL == 0 &&
		Xsqlite3ExprIsTableConstraint(tls, pExpr, pSrc) != 0) {
		goto __4
	}
	pPartial = Xsqlite3ExprAnd(tls, pParse, pPartial,
		Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0))
__4:
	;
	if !(termCanDriveIndex(tls, pTerm, pSrc, notReady) != 0) {
		goto __5
	}

	iCol = *(*int32)(unsafe.Pointer(pTerm + 32))
	if iCol >= int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) {
		cMask = uint64(1) << (int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) - 1)
	} else {
		cMask = uint64(1) << iCol
	}

	if !!(sentWarning != 0) {
		goto __6
	}
	Xsqlite3_log(tls, SQLITE_WARNING|int32(1)<<8,
		ts+26442, libc.VaList(bp, (*Table)(unsafe.Pointer(pTable)).FzName,
			(*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTable)).FaCol+uintptr(iCol)*24)).FzCnName))
	sentWarning = U8(1)
__6:
	;
	if !(idxCols&cMask == uint64(0)) {
		goto __7
	}
	if !(whereLoopResize(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pLoop, nKeyCol+1) != 0) {
		goto __8
	}
	goto end_auto_index_create
__8:
	;
	*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(libc.PostIncInt32(&nKeyCol, 1))*8)) = pTerm
	idxCols = idxCols | cMask
__7:
	;
__5:
	;
	goto __2
__2:
	pTerm += 56
	goto __1
	goto __3
__3:
	;
	*(*U16)(unsafe.Pointer(pLoop + 24)) = libc.AssignPtrUint16(pLoop+60, U16(nKeyCol))
	(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = U32(WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED |
		WHERE_AUTO_INDEX)

	extraCols = (*SrcItem)(unsafe.Pointer(pSrc)).FcolUsed & (^idxCols | uint64(1)<<(int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1))
	mxBitCol = func() int32 {
		if int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1 < int32((*Table)(unsafe.Pointer(pTable)).FnCol) {
			return int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) - 1
		}
		return int32((*Table)(unsafe.Pointer(pTable)).FnCol)
	}()

	i = 0
__9:
	if !(i < mxBitCol) {
		goto __11
	}
	if !(extraCols&(uint64(1)<<i) != 0) {
		goto __12
	}
	nKeyCol++
__12:
	;
	goto __10
__10:
	i++
	goto __9
	goto __11
__11:
	;
	if !((*SrcItem)(unsafe.Pointer(pSrc)).FcolUsed&(uint64(1)<<(int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1)) != 0) {
		goto __13
	}
	nKeyCol = nKeyCol + (int32((*Table)(unsafe.Pointer(pTable)).FnCol) - int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) + 1)
__13:
	;
	pIdx = Xsqlite3AllocateIndexObject(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, int16(nKeyCol+1), 0, bp+32)
	if !(pIdx == uintptr(0)) {
		goto __14
	}
	goto end_auto_index_create
__14:
	;
	*(*uintptr)(unsafe.Pointer(pLoop + 24 + 8)) = pIdx
	(*Index)(unsafe.Pointer(pIdx)).FzName = ts + 26468
	(*Index)(unsafe.Pointer(pIdx)).FpTable = pTable
	n = 0
	idxCols = uint64(0)
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
__15:
	if !(pTerm < pWCEnd) {
		goto __17
	}
	if !(termCanDriveIndex(tls, pTerm, pSrc, notReady) != 0) {
		goto __18
	}

	iCol1 = *(*int32)(unsafe.Pointer(pTerm + 32))
	if iCol1 >= int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) {
		cMask1 = uint64(1) << (int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) - 1)
	} else {
		cMask1 = uint64(1) << iCol1
	}

	if !(idxCols&cMask1 == uint64(0)) {
		goto __19
	}
	pX = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
	idxCols = idxCols | cMask1
	*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = I16(*(*int32)(unsafe.Pointer(pTerm + 32)))
	pColl = Xsqlite3ExprCompareCollSeq(tls, pParse, pX)

	*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*8)) = func() uintptr {
		if pColl != 0 {
			return (*CollSeq)(unsafe.Pointer(pColl)).FzName
		}
		return uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
	}()
	n++
__19:
	;
__18:
	;
	goto __16
__16:
	pTerm += 56
	goto __15
	goto __17
__17:
	;
	i = 0
__20:
	if !(i < mxBitCol) {
		goto __22
	}
	if !(extraCols&(uint64(1)<<i) != 0) {
		goto __23
	}
	*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = I16(i)
	*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*8)) = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
	n++
__23:
	;
	goto __21
__21:
	i++
	goto __20
	goto __22
__22:
	;
	if !((*SrcItem)(unsafe.Pointer(pSrc)).FcolUsed&(uint64(1)<<(int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1)) != 0) {
		goto __24
	}
	i = int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) - 1
__25:
	if !(i < int32((*Table)(unsafe.Pointer(pTable)).FnCol)) {
		goto __27
	}
	*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = I16(i)
	*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*8)) = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
	n++
	goto __26
__26:
	i++
	goto __25
	goto __27
__27:
	;
__24:
	;
	*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(n)*2)) = int16(-1)
	*(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(n)*8)) = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))

	(*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenAutoindex, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, nKeyCol+1)
	Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pIdx)
	Xsqlite3VdbeComment(tls, v, ts+19398, libc.VaList(bp+16, (*Table)(unsafe.Pointer(pTable)).FzName))
	if !((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&U32(SQLITE_BloomFilter) == U32(0)) {
		goto __28
	}
	(*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Blob, 10000, (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter)
__28:
	;
	pTabItem = (*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pTabItem + 60 + 4))&0x20>>5)) != 0) {
		goto __29
	}
	regYield = (*SrcItem)(unsafe.Pointer(pTabItem)).FregReturn
	addrCounter = Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, 0)
	Xsqlite3VdbeAddOp3(tls, v, OP_InitCoroutine, regYield, 0, (*SrcItem)(unsafe.Pointer(pTabItem)).FaddrFillSub)
	addrTop = Xsqlite3VdbeAddOp1(tls, v, OP_Yield, regYield)

	Xsqlite3VdbeComment(tls, v, ts+26177, libc.VaList(bp+24, (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pTabItem)).FpTab)).FzName))
	goto __30
__29:
	addrTop = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur)
__30:
	;
	if !(pPartial != 0) {
		goto __31
	}
	iContinue = Xsqlite3VdbeMakeLabel(tls, pParse)
	Xsqlite3ExprIfFalse(tls, pParse, pPartial, iContinue, SQLITE_JUMPIFNULL)
	*(*U32)(unsafe.Pointer(pLoop + 56)) |= U32(WHERE_PARTIALIDX)
__31:
	;
	regRecord = Xsqlite3GetTempReg(tls, pParse)
	regBase = Xsqlite3GenerateIndexKey(tls,
		pParse, pIdx, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, regRecord, 0, uintptr(0), uintptr(0), 0)
	if !((*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter != 0) {
		goto __32
	}
	Xsqlite3VdbeAddOp4Int(tls, v, OP_FilterAdd, (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter, 0,
		regBase, int32(*(*U16)(unsafe.Pointer(pLoop + 24))))
__32:
	;
	Xsqlite3VdbeAddOp2(tls, v, OP_IdxInsert, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, regRecord)
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
	if !(pPartial != 0) {
		goto __33
	}
	Xsqlite3VdbeResolveLabel(tls, v, iContinue)
__33:
	;
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pTabItem + 60 + 4))&0x20>>5)) != 0) {
		goto __34
	}
	Xsqlite3VdbeChangeP2(tls, v, addrCounter, regBase+n)

	translateColumnToCopy(tls, pParse, addrTop, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur,
		(*SrcItem)(unsafe.Pointer(pTabItem)).FregResult, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
	Xsqlite3VdbeGoto(tls, v, addrTop)
	libc.SetBitFieldPtr16Uint32(pTabItem+60+4, uint32(0), 5, 0x20)
	goto __35
__34:
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, addrTop+1)
	Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_STMTSTATUS_AUTOINDEX))
__35:
	;
	Xsqlite3VdbeJumpHere(tls, v, addrTop)
	Xsqlite3ReleaseTempReg(tls, pParse, regRecord)

	Xsqlite3VdbeJumpHere(tls, v, addrInit)

end_auto_index_create:
	Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pPartial)
}

func sqlite3ConstructBloomFilter(tls *libc.TLS, pWInfo uintptr, iLevel int32, pLevel uintptr, notReady Bitmask) {
	var addrOnce int32
	var addrTop int32
	var addrCont int32
	var pTerm uintptr
	var pWCEnd uintptr
	var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var pLoop uintptr = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	var iCur int32
	var saved_pIdxEpr uintptr

	saved_pIdxEpr = (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr
	(*Parse)(unsafe.Pointer(pParse)).FpIdxEpr = uintptr(0)

	addrOnce = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
	for __ccgo := true; __ccgo; __ccgo = iLevel < int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) {
		var pItem uintptr
		var pTab uintptr
		var sz U64
		Xsqlite3WhereExplainBloomFilter(tls, pParse, pWInfo, pLevel)
		addrCont = Xsqlite3VdbeMakeLabel(tls, pParse)
		iCur = (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
		(*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)

		pItem = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104

		pTab = (*SrcItem)(unsafe.Pointer(pItem)).FpTab

		sz = Xsqlite3LogEstToInt(tls, (*Table)(unsafe.Pointer(pTab)).FnRowLogEst)
		if sz < uint64(10000) {
			sz = uint64(10000)
		} else if sz > uint64(10000000) {
			sz = uint64(10000000)
		}
		Xsqlite3VdbeAddOp2(tls, v, OP_Blob, int32(sz), (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter)

		addrTop = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, iCur)
		pWCEnd = (*WhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa + uintptr((*WhereInfo)(unsafe.Pointer(pWInfo)).FsWC.FnTerm)*56
		for pTerm = (*WhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa; pTerm < pWCEnd; pTerm += 56 {
			var pExpr uintptr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_VIRTUAL == 0 &&
				Xsqlite3ExprIsTableConstraint(tls, pExpr, pItem) != 0 {
				Xsqlite3ExprIfFalse(tls, pParse, (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr, addrCont, SQLITE_JUMPIFNULL)
			}
		}
		if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IPK) != 0 {
			var r1 int32 = Xsqlite3GetTempReg(tls, pParse)
			Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iCur, r1)
			Xsqlite3VdbeAddOp4Int(tls, v, OP_FilterAdd, (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter, 0, r1, 1)
			Xsqlite3ReleaseTempReg(tls, pParse, r1)
		} else {
			var pIdx uintptr = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))
			var n int32 = int32(*(*U16)(unsafe.Pointer(pLoop + 24)))
			var r1 int32 = Xsqlite3GetTempRange(tls, pParse, n)
			var jj int32
			for jj = 0; jj < n; jj++ {
				Xsqlite3ExprCodeLoadIndexColumn(tls, pParse, pIdx, iCur, jj, r1+jj)
			}
			Xsqlite3VdbeAddOp4Int(tls, v, OP_FilterAdd, (*WhereLevel)(unsafe.Pointer(pLevel)).FregFilter, 0, r1, n)
			Xsqlite3ReleaseTempRange(tls, pParse, r1, n)
		}
		Xsqlite3VdbeResolveLabel(tls, v, addrCont)
		Xsqlite3VdbeAddOp2(tls, v, OP_Next, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur, addrTop+1)

		Xsqlite3VdbeJumpHere(tls, v, addrTop)
		*(*U32)(unsafe.Pointer(pLoop + 56)) &= libc.Uint32FromInt32(libc.CplInt32(WHERE_BLOOMFILTER))
		if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&U32(SQLITE_BloomPulldown) != U32(0) {
			break
		}
		for libc.PreIncInt32(&iLevel, 1) < int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) {
			var pTabItem uintptr
			pLevel = pWInfo + 856 + uintptr(iLevel)*104
			pTabItem = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104
			if int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ) != 0 {
				continue
			}
			pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
			if pLoop == uintptr(0) {
				continue
			}
			if (*WhereLoop)(unsafe.Pointer(pLoop)).Fprereq&notReady != 0 {
				continue
			}
			if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_BLOOMFILTER|WHERE_COLUMN_IN) ==
				U32(WHERE_BLOOMFILTER) {
				break
			}
		}
	}
	Xsqlite3VdbeJumpHere(tls, v, addrOnce)
	(*Parse)(unsafe.Pointer(pParse)).FpIdxEpr = saved_pIdxEpr
}

func allocateIndexInfo(tls *libc.TLS, pWInfo uintptr, pWC uintptr, mUnusable Bitmask, pSrc uintptr, pmNoOmit uintptr) uintptr {
	var i int32
	var j int32
	var nTerm int32
	var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	var pIdxCons uintptr
	var pIdxOrderBy uintptr
	var pUsage uintptr
	var pHidden uintptr
	var pTerm uintptr
	var nOrderBy int32
	var pIdxInfo uintptr
	var mNoOmit U16 = U16(0)
	var pTab uintptr
	var eDistinct int32 = 0
	var pOrderBy uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy

	pTab = (*SrcItem)(unsafe.Pointer(pSrc)).FpTab

	i = libc.AssignInt32(&nTerm, 0)
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
__1:
	if !(i < (*WhereClause)(unsafe.Pointer(pWC)).FnTerm) {
		goto __3
	}
	{
		*(*U16)(unsafe.Pointer(pTerm + 18)) &= libc.Uint16FromInt32(libc.CplInt32(TERM_OK))
		if (*WhereTerm)(unsafe.Pointer(pTerm)).FleftCursor != (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor {
			goto __2
		}
		if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&mUnusable != 0 {
			goto __2
		}

		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&libc.CplInt32(WO_EQUIV) == 0 {
			goto __2
		}
		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_VNULL != 0 {
			goto __2
		}

		if int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ|JT_RIGHT) != 0 &&
			!(constraintCompatibleWithOuterJoin(tls, pTerm, pSrc) != 0) {
			goto __2
		}
		nTerm++
		*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_OK)

	}
	goto __2
__2:
	i++
	pTerm += 56
	goto __1
	goto __3
__3:
	;
	nOrderBy = 0
	if pOrderBy != 0 {
		var n int32 = (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr
		for i = 0; i < n; i++ {
			var pExpr uintptr = (*ExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32)).FpExpr
			var pE2 uintptr

			if Xsqlite3ExprIsConstant(tls, pExpr) != 0 {
				continue
			}

			if int32((*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).Ffg.FsortFlags)&KEYINFO_ORDER_BIGNULL != 0 {
				break
			}

			if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN && (*Expr)(unsafe.Pointer(pExpr)).FiTable == (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor {
				continue
			}

			if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLLATE &&
				int32((*Expr)(unsafe.Pointer(libc.AssignUintptr(&pE2, (*Expr)(unsafe.Pointer(pExpr)).FpLeft))).Fop) == TK_COLUMN &&
				(*Expr)(unsafe.Pointer(pE2)).FiTable == (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor {
				var zColl uintptr

				(*Expr)(unsafe.Pointer(pExpr)).FiColumn = (*Expr)(unsafe.Pointer(pE2)).FiColumn
				if int32((*Expr)(unsafe.Pointer(pE2)).FiColumn) < 0 {
					continue
				}
				zColl = Xsqlite3ColumnColl(tls, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr((*Expr)(unsafe.Pointer(pE2)).FiColumn)*24)
				if zColl == uintptr(0) {
					zColl = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
				}
				if Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(pExpr + 8)), zColl) == 0 {
					continue
				}
			}

			break
		}
		if i == n {
			nOrderBy = n
			if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_DISTINCTBY != 0 {
				eDistinct = 2 + libc.Bool32(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_SORTBYGROUP != 0)
			} else if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_GROUPBY != 0 {
				eDistinct = 1
			}
		}
	}

	pIdxInfo = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(Sqlite3_index_info{}))+
		(uint64(unsafe.Sizeof(sqlite3_index_constraint{}))+uint64(unsafe.Sizeof(sqlite3_index_constraint_usage{})))*uint64(nTerm)+
		uint64(unsafe.Sizeof(sqlite3_index_orderby{}))*uint64(nOrderBy)+uint64(unsafe.Sizeof(HiddenIndexInfo1{}))+
		uint64(unsafe.Sizeof(uintptr(0)))*uint64(nTerm))
	if pIdxInfo == uintptr(0) {
		Xsqlite3ErrorMsg(tls, pParse, ts+1572, 0)
		return uintptr(0)
	}
	pHidden = pIdxInfo + 1*96
	pIdxCons = pHidden + 32 + uintptr(nTerm)*8
	pIdxOrderBy = pIdxCons + uintptr(nTerm)*12
	pUsage = pIdxOrderBy + uintptr(nOrderBy)*8
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint = pIdxCons
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy = pIdxOrderBy
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage = pUsage
	(*HiddenIndexInfo1)(unsafe.Pointer(pHidden)).FpWC = pWC
	(*HiddenIndexInfo1)(unsafe.Pointer(pHidden)).FpParse = pParse
	(*HiddenIndexInfo1)(unsafe.Pointer(pHidden)).FeDistinct = eDistinct
	(*HiddenIndexInfo1)(unsafe.Pointer(pHidden)).FmIn = U32(0)
	i = libc.AssignInt32(&j, 0)
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
__4:
	if !(i < (*WhereClause)(unsafe.Pointer(pWC)).FnTerm) {
		goto __6
	}
	{
		var op U16
		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_OK == 0 {
			goto __5
		}
		(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12)).FiColumn = *(*int32)(unsafe.Pointer(pTerm + 32))
		(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12)).FiTermOffset = i
		op = U16(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator) & WO_ALL)
		if int32(op) == WO_IN {
			if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_SLICE == 0 {
				*(*U32)(unsafe.Pointer(pHidden + 20)) |= func() uint32 {
					if j <= 31 {
						return uint32(1) << j
					}
					return uint32(0)
				}()
			}
			op = U16(WO_EQ)
		}
		if int32(op) == WO_AUX {
			(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12)).Fop = (*WhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp
		} else if int32(op)&(WO_ISNULL|WO_IS) != 0 {
			if int32(op) == WO_ISNULL {
				(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12)).Fop = uint8(SQLITE_INDEX_CONSTRAINT_ISNULL)
			} else {
				(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12)).Fop = uint8(SQLITE_INDEX_CONSTRAINT_IS)
			}
		} else {
			(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12)).Fop = U8(op)

			if int32(op)&(int32(WO_EQ)<<(TK_LT-TK_EQ)|int32(WO_EQ)<<(TK_LE-TK_EQ)|int32(WO_EQ)<<(TK_GT-TK_EQ)|int32(WO_EQ)<<(TK_GE-TK_EQ)) != 0 &&
				Xsqlite3ExprIsVector(tls, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight) != 0 {
				if j < 16 {
					mNoOmit = U16(int32(mNoOmit) | int32(1)<<j)
				}
				if int32(op) == int32(WO_EQ)<<(TK_LT-TK_EQ) {
					(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12)).Fop = uint8(int32(WO_EQ) << (TK_LE - TK_EQ))
				}
				if int32(op) == int32(WO_EQ)<<(TK_GT-TK_EQ) {
					(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons + uintptr(j)*12)).Fop = uint8(int32(WO_EQ) << (TK_GE - TK_EQ))
				}
			}
		}

		j++

	}
	goto __5
__5:
	i++
	pTerm += 56
	goto __4
	goto __6
__6:
	;
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint = j
	for i = libc.AssignInt32(&j, 0); i < nOrderBy; i++ {
		var pExpr uintptr = (*ExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32)).FpExpr
		if Xsqlite3ExprIsConstant(tls, pExpr) != 0 {
			continue
		}

		(*sqlite3_index_orderby)(unsafe.Pointer(pIdxOrderBy + uintptr(j)*8)).FiColumn = int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn)
		(*sqlite3_index_orderby)(unsafe.Pointer(pIdxOrderBy + uintptr(j)*8)).Fdesc = uint8(int32((*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).Ffg.FsortFlags) & KEYINFO_ORDER_DESC)
		j++
	}
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy = j

	*(*U16)(unsafe.Pointer(pmNoOmit)) = mNoOmit
	return pIdxInfo
}

func freeIndexInfo(tls *libc.TLS, db uintptr, pIdxInfo uintptr) {
	var pHidden uintptr
	var i int32

	pHidden = pIdxInfo + 1*96

	for i = 0; i < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint; i++ {
		Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(pHidden + 32 + uintptr(i)*8)))
		*(*uintptr)(unsafe.Pointer(pHidden + 32 + uintptr(i)*8)) = uintptr(0)
	}
	Xsqlite3DbFree(tls, db, pIdxInfo)
}

func vtabBestIndex(tls *libc.TLS, pParse uintptr, pTab uintptr, p uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pVtab uintptr = (*VTable)(unsafe.Pointer(Xsqlite3GetVTable(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pTab))).FpVtab
	var rc int32

	(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FnSchemaLock++
	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_module)(unsafe.Pointer((*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule)).FxBestIndex})).f(tls, pVtab, p)
	(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FnSchemaLock--

	if rc != SQLITE_OK && rc != SQLITE_CONSTRAINT {
		if rc == SQLITE_NOMEM {
			Xsqlite3OomFault(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb)
		} else if !(int32((*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg) != 0) {
			Xsqlite3ErrorMsg(tls, pParse, ts+1684, libc.VaList(bp, Xsqlite3ErrStr(tls, rc)))
		} else {
			Xsqlite3ErrorMsg(tls, pParse, ts+1684, libc.VaList(bp+8, (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg))
		}
	}
	Xsqlite3_free(tls, (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
	(*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = uintptr(0)
	return rc
}

func whereKeyStats(tls *libc.TLS, pParse uintptr, pIdx uintptr, pRec uintptr, roundUp int32, aStat uintptr) int32 {
	var aSample uintptr = (*Index)(unsafe.Pointer(pIdx)).FaSample
	var iCol int32
	var i int32
	var iSample int32
	var iMin int32 = 0
	var iTest int32
	var res int32
	var nField int32
	var iLower TRowcnt = uint64(0)

	_ = pParse

	if !((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) && int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY {
		nField = int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol)
	} else {
		nField = int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)
	}
	nField = func() int32 {
		if int32((*UnpackedRecord)(unsafe.Pointer(pRec)).FnField) < nField {
			return int32((*UnpackedRecord)(unsafe.Pointer(pRec)).FnField)
		}
		return nField
	}()
	iCol = 0
	iSample = (*Index)(unsafe.Pointer(pIdx)).FnSample * nField
	for __ccgo := true; __ccgo; __ccgo = res != 0 && iMin < iSample {
		var iSamp int32
		var n int32

		iTest = (iMin + iSample) / 2
		iSamp = iTest / nField
		if iSamp > 0 {
			for n = iTest%nField + 1; n < nField; n++ {
				if *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(iSamp-1)*40)).FanLt + uintptr(n-1)*8)) != *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(iSamp)*40)).FanLt + uintptr(n-1)*8)) {
					break
				}
			}
		} else {
			n = iTest + 1
		}

		(*UnpackedRecord)(unsafe.Pointer(pRec)).FnField = U16(n)
		res = Xsqlite3VdbeRecordCompare(tls, (*IndexSample)(unsafe.Pointer(aSample+uintptr(iSamp)*40)).Fn, (*IndexSample)(unsafe.Pointer(aSample+uintptr(iSamp)*40)).Fp, pRec)
		if res < 0 {
			iLower = *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(iSamp)*40)).FanLt + uintptr(n-1)*8)) + *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(iSamp)*40)).FanEq + uintptr(n-1)*8))
			iMin = iTest + 1
		} else if res == 0 && n < nField {
			iLower = *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(iSamp)*40)).FanLt + uintptr(n-1)*8))
			iMin = iTest + 1
			res = -1
		} else {
			iSample = iTest
			iCol = n - 1
		}
	}
	i = iSample / nField

	if res == 0 {
		*(*TRowcnt)(unsafe.Pointer(aStat)) = *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(i)*40)).FanLt + uintptr(iCol)*8))
		*(*TRowcnt)(unsafe.Pointer(aStat + 1*8)) = *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(i)*40)).FanEq + uintptr(iCol)*8))
	} else {
		var iUpper TRowcnt
		var iGap TRowcnt
		if i >= (*Index)(unsafe.Pointer(pIdx)).FnSample {
			iUpper = (*Index)(unsafe.Pointer(pIdx)).FnRowEst0
		} else {
			iUpper = *(*TRowcnt)(unsafe.Pointer((*IndexSample)(unsafe.Pointer(aSample+uintptr(i)*40)).FanLt + uintptr(iCol)*8))
		}

		if iLower >= iUpper {
			iGap = uint64(0)
		} else {
			iGap = iUpper - iLower
		}
		if roundUp != 0 {
			iGap = iGap * uint64(2) / uint64(3)
		} else {
			iGap = iGap / uint64(3)
		}
		*(*TRowcnt)(unsafe.Pointer(aStat)) = iLower + iGap
		*(*TRowcnt)(unsafe.Pointer(aStat + 1*8)) = *(*TRowcnt)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaAvgEq + uintptr(nField-1)*8))
	}

	(*UnpackedRecord)(unsafe.Pointer(pRec)).FnField = U16(nField)
	return i
}

func whereRangeAdjust(tls *libc.TLS, pTerm uintptr, nNew LogEst) LogEst {
	var nRet LogEst = nNew
	if pTerm != 0 {
		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb) <= 0 {
			nRet = LogEst(int32(nRet) + int32((*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb))
		} else if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_VNULL == 0 {
			nRet = int16(int32(nRet) - 20)
		}
	}
	return nRet
}

func Xsqlite3IndexColumnAffinity(tls *libc.TLS, db uintptr, pIdx uintptr, iCol int32) uint8 {
	if !(int32((*Index)(unsafe.Pointer(pIdx)).FzColAff) != 0) {
		if Xsqlite3IndexAffinityStr(tls, db, pIdx) == uintptr(0) {
			return uint8(SQLITE_AFF_BLOB)
		}
	}

	return *(*uint8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FzColAff + uintptr(iCol)))
}

func whereRangeSkipScanEst(tls *libc.TLS, pParse uintptr, pLower uintptr, pUpper uintptr, pLoop uintptr, pbDone uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var p uintptr = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))
	var nEq int32 = int32(*(*U16)(unsafe.Pointer(pLoop + 24)))
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var nLower int32 = -1
	var nUpper int32 = (*Index)(unsafe.Pointer(p)).FnSample + 1
	var rc int32 = SQLITE_OK
	var aff U8 = Xsqlite3IndexColumnAffinity(tls, db, p, nEq)
	var pColl uintptr

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)

	pColl = Xsqlite3LocateCollSeq(tls, pParse, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(p)).FazColl + uintptr(nEq)*8)))
	if pLower != 0 {
		rc = Xsqlite3Stat4ValueFromExpr(tls, pParse, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pLower)).FpExpr)).FpRight, aff, bp)
		nLower = 0
	}
	if pUpper != 0 && rc == SQLITE_OK {
		rc = Xsqlite3Stat4ValueFromExpr(tls, pParse, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pUpper)).FpExpr)).FpRight, aff, bp+8)
		if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
			nUpper = 0
		} else {
			nUpper = (*Index)(unsafe.Pointer(p)).FnSample
		}
	}

	if *(*uintptr)(unsafe.Pointer(bp)) != 0 || *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
		var i int32
		var nDiff int32
		for i = 0; rc == SQLITE_OK && i < (*Index)(unsafe.Pointer(p)).FnSample; i++ {
			rc = Xsqlite3Stat4Column(tls, db, (*IndexSample)(unsafe.Pointer((*Index)(unsafe.Pointer(p)).FaSample+uintptr(i)*40)).Fp, (*IndexSample)(unsafe.Pointer((*Index)(unsafe.Pointer(p)).FaSample+uintptr(i)*40)).Fn, nEq, bp+16)
			if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				var res int32 = Xsqlite3MemCompare(tls, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 16)), pColl)
				if res >= 0 {
					nLower++
				}
			}
			if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
				var res int32 = Xsqlite3MemCompare(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), *(*uintptr)(unsafe.Pointer(bp + 16)), pColl)
				if res >= 0 {
					nUpper++
				}
			}
		}
		nDiff = nUpper - nLower
		if nDiff <= 0 {
			nDiff = 1
		}

		if nDiff != 1 || pUpper == uintptr(0) || pLower == uintptr(0) {
			var nAdjust int32 = int32(Xsqlite3LogEst(tls, uint64((*Index)(unsafe.Pointer(p)).FnSample))) - int32(Xsqlite3LogEst(tls, uint64(nDiff)))
			*(*LogEst)(unsafe.Pointer(pLoop + 22)) -= LogEst(nAdjust)
			*(*int32)(unsafe.Pointer(pbDone)) = 1

		}

	} else {
	}

	Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))

	return rc
}

func whereRangeScanEst(tls *libc.TLS, pParse uintptr, pBuilder uintptr, pLower uintptr, pUpper uintptr, pLoop uintptr) int32 {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var rc int32 = SQLITE_OK
	var nOut int32 = int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnOut)
	var nNew LogEst

	var p uintptr = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))
	var nEq int32 = int32(*(*U16)(unsafe.Pointer(pLoop + 24)))

	if (*Index)(unsafe.Pointer(p)).FnSample > 0 && nEq < (*Index)(unsafe.Pointer(p)).FnSampleCol &&
		(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&U32(SQLITE_Stat4) == U32(0) {
		if nEq == (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid {
			*(*uintptr)(unsafe.Pointer(bp + 16)) = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec

			var nBtm int32 = int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 2)))
			var nTop int32 = int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 4)))

			var iLower TRowcnt
			var iUpper TRowcnt
			var iLwrIdx int32 = -2
			var iUprIdx int32 = -1

			if *(*uintptr)(unsafe.Pointer(bp + 16)) != 0 {
				(*UnpackedRecord)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FnField = U16((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid)
			}

			if nEq == 0 {
				iLower = uint64(0)
				iUpper = (*Index)(unsafe.Pointer(p)).FnRowEst0
			} else {
				whereKeyStats(tls, pParse, p, *(*uintptr)(unsafe.Pointer(bp + 16)), 0, bp)
				iLower = *(*TRowcnt)(unsafe.Pointer(bp))
				iUpper = *(*TRowcnt)(unsafe.Pointer(bp)) + *(*TRowcnt)(unsafe.Pointer(bp + 1*8))
			}

			if *(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(p)).FaSortOrder + uintptr(nEq))) != 0 {
				{
					var t uintptr = pLower
					pLower = pUpper
					pUpper = t
				}

				{
					var t int32 = nBtm
					nBtm = nTop
					nTop = t
				}

			}

			if pLower != 0 {
				var pExpr uintptr = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pLower)).FpExpr)).FpRight
				rc = Xsqlite3Stat4ProbeSetValue(tls, pParse, p, bp+16, pExpr, nBtm, nEq, bp+24)
				if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 24)) != 0 {
					var iNew TRowcnt
					var mask U16 = U16(int32(WO_EQ)<<(TK_GT-TK_EQ) | int32(WO_EQ)<<(TK_LE-TK_EQ))
					if Xsqlite3ExprVectorSize(tls, pExpr) > *(*int32)(unsafe.Pointer(bp + 24)) {
						mask = U16(int32(WO_EQ)<<(TK_LE-TK_EQ) | int32(WO_EQ)<<(TK_LT-TK_EQ))
					}
					iLwrIdx = whereKeyStats(tls, pParse, p, *(*uintptr)(unsafe.Pointer(bp + 16)), 0, bp)
					iNew = *(*TRowcnt)(unsafe.Pointer(bp)) + func() uint64 {
						if int32((*WhereTerm)(unsafe.Pointer(pLower)).FeOperator)&int32(mask) != 0 {
							return *(*TRowcnt)(unsafe.Pointer(bp + 1*8))
						}
						return uint64(0)
					}()
					if iNew > iLower {
						iLower = iNew
					}
					nOut--
					pLower = uintptr(0)
				}
			}

			if pUpper != 0 {
				var pExpr uintptr = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pUpper)).FpExpr)).FpRight
				rc = Xsqlite3Stat4ProbeSetValue(tls, pParse, p, bp+16, pExpr, nTop, nEq, bp+28)
				if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 28)) != 0 {
					var iNew TRowcnt
					var mask U16 = U16(int32(WO_EQ)<<(TK_GT-TK_EQ) | int32(WO_EQ)<<(TK_LE-TK_EQ))
					if Xsqlite3ExprVectorSize(tls, pExpr) > *(*int32)(unsafe.Pointer(bp + 28)) {
						mask = U16(int32(WO_EQ)<<(TK_LE-TK_EQ) | int32(WO_EQ)<<(TK_LT-TK_EQ))
					}
					iUprIdx = whereKeyStats(tls, pParse, p, *(*uintptr)(unsafe.Pointer(bp + 16)), 1, bp)
					iNew = *(*TRowcnt)(unsafe.Pointer(bp)) + func() uint64 {
						if int32((*WhereTerm)(unsafe.Pointer(pUpper)).FeOperator)&int32(mask) != 0 {
							return *(*TRowcnt)(unsafe.Pointer(bp + 1*8))
						}
						return uint64(0)
					}()
					if iNew < iUpper {
						iUpper = iNew
					}
					nOut--
					pUpper = uintptr(0)
				}
			}

			(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec = *(*uintptr)(unsafe.Pointer(bp + 16))
			if rc == SQLITE_OK {
				if iUpper > iLower {
					nNew = Xsqlite3LogEst(tls, iUpper-iLower)

					if iLwrIdx == iUprIdx {
						nNew = int16(int32(nNew) - 20)
					}
				} else {
					nNew = int16(10)
				}
				if int32(nNew) < nOut {
					nOut = 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(nOut))
	nNew = whereRangeAdjust(tls, pUpper, nNew)

	if pLower != 0 && int32((*WhereTerm)(unsafe.Pointer(pLower)).FtruthProb) > 0 && pUpper != 0 && int32((*WhereTerm)(unsafe.Pointer(pUpper)).FtruthProb) > 0 {
		nNew = int16(int32(nNew) - 20)
	}

	nOut = nOut - (libc.Bool32(pLower != uintptr(0)) + libc.Bool32(pUpper != uintptr(0)))
	if int32(nNew) < 10 {
		nNew = int16(10)
	}
	if int32(nNew) < nOut {
		nOut = int32(nNew)
	}
	(*WhereLoop)(unsafe.Pointer(pLoop)).FnOut = LogEst(nOut)
	return rc
}

func whereEqualScanEst(tls *libc.TLS, pParse uintptr, pBuilder uintptr, pExpr uintptr, pnRow uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var p uintptr = *(*uintptr)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew + 24 + 8))
	var nEq int32 = int32(*(*U16)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew + 24)))
	*(*uintptr)(unsafe.Pointer(bp)) = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec
	var rc int32

	if (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid < nEq-1 {
		return SQLITE_NOTFOUND
	}

	if nEq >= int32((*Index)(unsafe.Pointer(p)).FnColumn) {
		*(*TRowcnt)(unsafe.Pointer(pnRow)) = uint64(1)
		return SQLITE_OK
	}

	rc = Xsqlite3Stat4ProbeSetValue(tls, pParse, p, bp, pExpr, 1, nEq-1, bp+8)
	(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec = *(*uintptr)(unsafe.Pointer(bp))
	if rc != SQLITE_OK {
		return rc
	}
	if *(*int32)(unsafe.Pointer(bp + 8)) == 0 {
		return SQLITE_NOTFOUND
	}
	(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid = nEq

	whereKeyStats(tls, pParse, p, *(*uintptr)(unsafe.Pointer(bp)), 0, bp+16)

	*(*TRowcnt)(unsafe.Pointer(pnRow)) = *(*TRowcnt)(unsafe.Pointer(bp + 16 + 1*8))

	return rc
}

func whereInScanEst(tls *libc.TLS, pParse uintptr, pBuilder uintptr, pList uintptr, pnRow uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p uintptr = *(*uintptr)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew + 24 + 8))
	var nRow0 I64 = I64(Xsqlite3LogEstToInt(tls, *(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(p)).FaiRowLogEst))))
	var nRecValid int32 = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid
	var rc int32 = SQLITE_OK

	var nRowEst TRowcnt = uint64(0)
	var i int32

	for i = 0; rc == SQLITE_OK && i < (*ExprList)(unsafe.Pointer(pList)).FnExpr; i++ {
		*(*TRowcnt)(unsafe.Pointer(bp)) = TRowcnt(nRow0)
		rc = whereEqualScanEst(tls, pParse, pBuilder, (*ExprList_item)(unsafe.Pointer(pList+8+uintptr(i)*32)).FpExpr, bp)
		nRowEst = nRowEst + *(*TRowcnt)(unsafe.Pointer(bp))
		(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid = nRecValid
	}

	if rc == SQLITE_OK {
		if nRowEst > TRowcnt(nRow0) {
			nRowEst = TRowcnt(nRow0)
		}
		*(*TRowcnt)(unsafe.Pointer(pnRow)) = nRowEst

	}

	return rc
}

func whereLoopInit(tls *libc.TLS, p uintptr) {
	(*WhereLoop)(unsafe.Pointer(p)).FaLTerm = p + 88
	(*WhereLoop)(unsafe.Pointer(p)).FnLTerm = U16(0)
	(*WhereLoop)(unsafe.Pointer(p)).FnLSlot = U16(int32(uint64(unsafe.Sizeof([3]uintptr{})) / uint64(unsafe.Sizeof(uintptr(0)))))
	(*WhereLoop)(unsafe.Pointer(p)).FwsFlags = U32(0)
}

func whereLoopClearUnion(tls *libc.TLS, db uintptr, p uintptr) {
	if (*WhereLoop)(unsafe.Pointer(p)).FwsFlags&U32(WHERE_VIRTUALTABLE|WHERE_AUTO_INDEX) != 0 {
		if (*WhereLoop)(unsafe.Pointer(p)).FwsFlags&U32(WHERE_VIRTUALTABLE) != U32(0) && U32(int32(*(*uint8)(unsafe.Pointer(p + 24 + 4))&0x1>>0)) != 0 {
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(p + 24 + 16)))
			libc.SetBitFieldPtr8Uint32(p+24+4, U32(0), 0, 0x1)
			*(*uintptr)(unsafe.Pointer(p + 24 + 16)) = uintptr(0)
		} else if (*WhereLoop)(unsafe.Pointer(p)).FwsFlags&U32(WHERE_AUTO_INDEX) != U32(0) && *(*uintptr)(unsafe.Pointer(p + 24 + 8)) != uintptr(0) {
			Xsqlite3DbFree(tls, db, (*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 24 + 8)))).FzColAff)
			Xsqlite3DbFreeNN(tls, db, *(*uintptr)(unsafe.Pointer(p + 24 + 8)))
			*(*uintptr)(unsafe.Pointer(p + 24 + 8)) = uintptr(0)
		}
	}
}

func whereLoopClear(tls *libc.TLS, db uintptr, p uintptr) {
	if (*WhereLoop)(unsafe.Pointer(p)).FaLTerm != p+88 {
		Xsqlite3DbFreeNN(tls, db, (*WhereLoop)(unsafe.Pointer(p)).FaLTerm)
		(*WhereLoop)(unsafe.Pointer(p)).FaLTerm = p + 88
		(*WhereLoop)(unsafe.Pointer(p)).FnLSlot = U16(int32(uint64(unsafe.Sizeof([3]uintptr{})) / uint64(unsafe.Sizeof(uintptr(0)))))
	}
	whereLoopClearUnion(tls, db, p)
	(*WhereLoop)(unsafe.Pointer(p)).FnLTerm = U16(0)
	(*WhereLoop)(unsafe.Pointer(p)).FwsFlags = U32(0)
}

func whereLoopResize(tls *libc.TLS, db uintptr, p uintptr, n int32) int32 {
	var paNew uintptr
	if int32((*WhereLoop)(unsafe.Pointer(p)).FnLSlot) >= n {
		return SQLITE_OK
	}
	n = (n + 7) & libc.CplInt32(7)
	paNew = Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(uintptr(0)))*uint64(n))
	if paNew == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemcpy(tls, paNew, (*WhereLoop)(unsafe.Pointer(p)).FaLTerm, uint64(unsafe.Sizeof(uintptr(0)))*uint64((*WhereLoop)(unsafe.Pointer(p)).FnLSlot))
	if (*WhereLoop)(unsafe.Pointer(p)).FaLTerm != p+88 {
		Xsqlite3DbFreeNN(tls, db, (*WhereLoop)(unsafe.Pointer(p)).FaLTerm)
	}
	(*WhereLoop)(unsafe.Pointer(p)).FaLTerm = paNew
	(*WhereLoop)(unsafe.Pointer(p)).FnLSlot = U16(n)
	return SQLITE_OK
}

func whereLoopXfer(tls *libc.TLS, db uintptr, pTo uintptr, pFrom uintptr) int32 {
	whereLoopClearUnion(tls, db, pTo)
	if int32((*WhereLoop)(unsafe.Pointer(pFrom)).FnLTerm) > int32((*WhereLoop)(unsafe.Pointer(pTo)).FnLSlot) &&
		whereLoopResize(tls, db, pTo, int32((*WhereLoop)(unsafe.Pointer(pFrom)).FnLTerm)) != 0 {
		libc.Xmemset(tls, pTo, 0, uint64(uintptr(0)+64))
		return SQLITE_NOMEM
	}
	libc.Xmemcpy(tls, pTo, pFrom, uint64(uintptr(0)+64))
	libc.Xmemcpy(tls, (*WhereLoop)(unsafe.Pointer(pTo)).FaLTerm, (*WhereLoop)(unsafe.Pointer(pFrom)).FaLTerm, uint64((*WhereLoop)(unsafe.Pointer(pTo)).FnLTerm)*uint64(unsafe.Sizeof(uintptr(0))))
	if (*WhereLoop)(unsafe.Pointer(pFrom)).FwsFlags&U32(WHERE_VIRTUALTABLE) != 0 {
		libc.SetBitFieldPtr8Uint32(pFrom+24+4, U32(0), 0, 0x1)
	} else if (*WhereLoop)(unsafe.Pointer(pFrom)).FwsFlags&U32(WHERE_AUTO_INDEX) != U32(0) {
		*(*uintptr)(unsafe.Pointer(pFrom + 24 + 8)) = uintptr(0)
	}
	return SQLITE_OK
}

func whereLoopDelete(tls *libc.TLS, db uintptr, p uintptr) {
	whereLoopClear(tls, db, p)
	Xsqlite3DbNNFreeNN(tls, db, p)
}

func whereInfoFree(tls *libc.TLS, db uintptr, pWInfo uintptr) {
	Xsqlite3WhereClauseClear(tls, pWInfo+104)
	for (*WhereInfo)(unsafe.Pointer(pWInfo)).FpLoops != 0 {
		var p uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpLoops
		(*WhereInfo)(unsafe.Pointer(pWInfo)).FpLoops = (*WhereLoop)(unsafe.Pointer(p)).FpNextLoop
		whereLoopDelete(tls, db, p)
	}
	for (*WhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree != 0 {
		var pNext uintptr = (*WhereMemBlock)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree)).FpNext
		Xsqlite3DbNNFreeNN(tls, db, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree)
		(*WhereInfo)(unsafe.Pointer(pWInfo)).FpMemToFree = pNext
	}
	Xsqlite3DbNNFreeNN(tls, db, pWInfo)
}

func whereLoopCheaperProperSubset(tls *libc.TLS, pX uintptr, pY uintptr) int32 {
	var i int32
	var j int32
	if int32((*WhereLoop)(unsafe.Pointer(pX)).FnLTerm)-int32((*WhereLoop)(unsafe.Pointer(pX)).FnSkip) >= int32((*WhereLoop)(unsafe.Pointer(pY)).FnLTerm)-int32((*WhereLoop)(unsafe.Pointer(pY)).FnSkip) {
		return 0
	}
	if int32((*WhereLoop)(unsafe.Pointer(pX)).FrRun) > int32((*WhereLoop)(unsafe.Pointer(pY)).FrRun) && int32((*WhereLoop)(unsafe.Pointer(pX)).FnOut) > int32((*WhereLoop)(unsafe.Pointer(pY)).FnOut) {
		return 0
	}
	if int32((*WhereLoop)(unsafe.Pointer(pY)).FnSkip) > int32((*WhereLoop)(unsafe.Pointer(pX)).FnSkip) {
		return 0
	}
	for i = int32((*WhereLoop)(unsafe.Pointer(pX)).FnLTerm) - 1; i >= 0; i-- {
		if *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pX)).FaLTerm + uintptr(i)*8)) == uintptr(0) {
			continue
		}
		for j = int32((*WhereLoop)(unsafe.Pointer(pY)).FnLTerm) - 1; j >= 0; j-- {
			if *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pY)).FaLTerm + uintptr(j)*8)) == *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pX)).FaLTerm + uintptr(i)*8)) {
				break
			}
		}
		if j < 0 {
			return 0
		}
	}
	if (*WhereLoop)(unsafe.Pointer(pX)).FwsFlags&U32(WHERE_IDX_ONLY) != U32(0) &&
		(*WhereLoop)(unsafe.Pointer(pY)).FwsFlags&U32(WHERE_IDX_ONLY) == U32(0) {
		return 0
	}
	return 1
}

func whereLoopAdjustCost(tls *libc.TLS, p uintptr, pTemplate uintptr) {
	if (*WhereLoop)(unsafe.Pointer(pTemplate)).FwsFlags&U32(WHERE_INDEXED) == U32(0) {
		return
	}
	for ; p != 0; p = (*WhereLoop)(unsafe.Pointer(p)).FpNextLoop {
		if int32((*WhereLoop)(unsafe.Pointer(p)).FiTab) != int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FiTab) {
			continue
		}
		if (*WhereLoop)(unsafe.Pointer(p)).FwsFlags&U32(WHERE_INDEXED) == U32(0) {
			continue
		}
		if whereLoopCheaperProperSubset(tls, p, pTemplate) != 0 {
			(*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun = func() int16 {
				if int32((*WhereLoop)(unsafe.Pointer(p)).FrRun) < int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun) {
					return (*WhereLoop)(unsafe.Pointer(p)).FrRun
				}
				return (*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun
			}()
			(*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut = func() int16 {
				if int32((*WhereLoop)(unsafe.Pointer(p)).FnOut)-1 < int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut) {
					return int16(int32((*WhereLoop)(unsafe.Pointer(p)).FnOut) - 1)
				}
				return (*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut
			}()
		} else if whereLoopCheaperProperSubset(tls, pTemplate, p) != 0 {
			(*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun = func() int16 {
				if int32((*WhereLoop)(unsafe.Pointer(p)).FrRun) > int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun) {
					return (*WhereLoop)(unsafe.Pointer(p)).FrRun
				}
				return (*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun
			}()
			(*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut = func() int16 {
				if int32((*WhereLoop)(unsafe.Pointer(p)).FnOut)+1 > int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut) {
					return int16(int32((*WhereLoop)(unsafe.Pointer(p)).FnOut) + 1)
				}
				return (*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut
			}()
		}
	}
}

func whereLoopFindLesser(tls *libc.TLS, ppPrev uintptr, pTemplate uintptr) uintptr {
	var p uintptr
	p = *(*uintptr)(unsafe.Pointer(ppPrev))
__1:
	if !(p != 0) {
		goto __3
	}
	{
		if int32((*WhereLoop)(unsafe.Pointer(p)).FiTab) != int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FiTab) || int32((*WhereLoop)(unsafe.Pointer(p)).FiSortIdx) != int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FiSortIdx) {
			goto __2
		}

		if (*WhereLoop)(unsafe.Pointer(p)).FwsFlags&U32(WHERE_AUTO_INDEX) != U32(0) &&
			int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FnSkip) == 0 &&
			(*WhereLoop)(unsafe.Pointer(pTemplate)).FwsFlags&U32(WHERE_INDEXED) != U32(0) &&
			(*WhereLoop)(unsafe.Pointer(pTemplate)).FwsFlags&U32(WHERE_COLUMN_EQ) != U32(0) &&
			(*WhereLoop)(unsafe.Pointer(p)).Fprereq&(*WhereLoop)(unsafe.Pointer(pTemplate)).Fprereq == (*WhereLoop)(unsafe.Pointer(pTemplate)).Fprereq {
			goto __3
		}

		if (*WhereLoop)(unsafe.Pointer(p)).Fprereq&(*WhereLoop)(unsafe.Pointer(pTemplate)).Fprereq == (*WhereLoop)(unsafe.Pointer(p)).Fprereq &&
			int32((*WhereLoop)(unsafe.Pointer(p)).FrSetup) <= int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FrSetup) &&
			int32((*WhereLoop)(unsafe.Pointer(p)).FrRun) <= int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun) &&
			int32((*WhereLoop)(unsafe.Pointer(p)).FnOut) <= int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut) {
			return uintptr(0)
		}

		if (*WhereLoop)(unsafe.Pointer(p)).Fprereq&(*WhereLoop)(unsafe.Pointer(pTemplate)).Fprereq == (*WhereLoop)(unsafe.Pointer(pTemplate)).Fprereq &&
			int32((*WhereLoop)(unsafe.Pointer(p)).FrRun) >= int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun) &&
			int32((*WhereLoop)(unsafe.Pointer(p)).FnOut) >= int32((*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut) {
			goto __3
		}

	}
	goto __2
__2:
	ppPrev = p + 80
	p = *(*uintptr)(unsafe.Pointer(ppPrev))
	goto __1
	goto __3
__3:
	;
	return ppPrev
}

func whereLoopInsert(tls *libc.TLS, pBuilder uintptr, pTemplate uintptr) int32 {
	var ppPrev uintptr
	var p uintptr
	var pWInfo uintptr = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	var db uintptr = (*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb
	var rc int32

	if (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit == uint32(0) {
		if (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet != 0 {
			(*WhereOrSet)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet)).Fn = U16(0)
		}
		return SQLITE_DONE
	}
	(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit--

	whereLoopAdjustCost(tls, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpLoops, pTemplate)

	if (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet != uintptr(0) {
		if (*WhereLoop)(unsafe.Pointer(pTemplate)).FnLTerm != 0 {
			whereOrInsert(tls, (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet, (*WhereLoop)(unsafe.Pointer(pTemplate)).Fprereq, (*WhereLoop)(unsafe.Pointer(pTemplate)).FrRun,
				(*WhereLoop)(unsafe.Pointer(pTemplate)).FnOut)
		}
		return SQLITE_OK
	}

	ppPrev = whereLoopFindLesser(tls, pWInfo+80, pTemplate)

	if ppPrev == uintptr(0) {
		return SQLITE_OK
	} else {
		p = *(*uintptr)(unsafe.Pointer(ppPrev))
	}

	if p == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(ppPrev)) = libc.AssignUintptr(&p, Xsqlite3DbMallocRawNN(tls, db, uint64(unsafe.Sizeof(WhereLoop{}))))
		if p == uintptr(0) {
			return SQLITE_NOMEM
		}
		whereLoopInit(tls, p)
		(*WhereLoop)(unsafe.Pointer(p)).FpNextLoop = uintptr(0)
	} else {
		var ppTail uintptr = p + 80
		var pToDel uintptr
		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)) = (*WhereLoop)(unsafe.Pointer(pToDel)).FpNextLoop
			whereLoopDelete(tls, db, pToDel)
		}
	}
	rc = whereLoopXfer(tls, db, p, pTemplate)
	if (*WhereLoop)(unsafe.Pointer(p)).FwsFlags&U32(WHERE_VIRTUALTABLE) == U32(0) {
		var pIndex uintptr = *(*uintptr)(unsafe.Pointer(p + 24 + 8))
		if pIndex != 0 && int32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x3>>0) == SQLITE_IDXTYPE_IPK {
			*(*uintptr)(unsafe.Pointer(p + 24 + 8)) = uintptr(0)
		}
	}
	return rc
}

func whereLoopOutputAdjust(tls *libc.TLS, pWC uintptr, pLoop uintptr, nRow LogEst) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pTerm uintptr
	var pX uintptr
	var notAllowed Bitmask = ^((*WhereLoop)(unsafe.Pointer(pLoop)).Fprereq | (*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf)
	var i int32
	var j int32
	var iReduce LogEst = int16(0)

	i = (*WhereClause)(unsafe.Pointer(pWC)).FnBase
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
__1:
	if !(i > 0) {
		goto __3
	}
	{
		if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&notAllowed != uint64(0) {
			goto __2
		}
		if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf == uint64(0) {
			goto __2
		}
		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_VIRTUAL != 0 {
			goto __2
		}
		for j = int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm) - 1; j >= 0; j-- {
			pX = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8))
			if pX == uintptr(0) {
				continue
			}
			if pX == pTerm {
				break
			}
			if (*WhereTerm)(unsafe.Pointer(pX)).FiParent >= 0 && (*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr((*WhereTerm)(unsafe.Pointer(pX)).FiParent)*56 == pTerm {
				break
			}
		}
		if j < 0 {
			Xsqlite3ProgressCheck(tls, (*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse)
			if (*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf == (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll {
				if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&0x3f != 0 ||
					int32((*SrcItem)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpTabList+8+uintptr((*WhereLoop)(unsafe.Pointer(pLoop)).FiTab)*104)).Ffg.Fjointype)&
						(JT_LEFT|JT_LTORJ) == 0 {
					*(*U32)(unsafe.Pointer(pLoop + 56)) |= U32(WHERE_SELFCULL)
				}
			}
			if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb) <= 0 {
				*(*LogEst)(unsafe.Pointer(pLoop + 22)) += LogEst(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb))
			} else {
				(*WhereLoop)(unsafe.Pointer(pLoop)).FnOut--
				if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(WO_EQ|WO_IS) != 0 &&
					int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_HIGHTRUTH == 0 {
					var pRight uintptr = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
					*(*int32)(unsafe.Pointer(bp)) = 0

					if Xsqlite3ExprIsInteger(tls, pRight, bp) != 0 && *(*int32)(unsafe.Pointer(bp)) >= -1 && *(*int32)(unsafe.Pointer(bp)) <= 1 {
						*(*int32)(unsafe.Pointer(bp)) = 10
					} else {
						*(*int32)(unsafe.Pointer(bp)) = 20
					}
					if int32(iReduce) < *(*int32)(unsafe.Pointer(bp)) {
						*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_HEURTRUTH)
						iReduce = LogEst(*(*int32)(unsafe.Pointer(bp)))
					}
				}
			}
		}

	}
	goto __2
__2:
	i--
	pTerm += 56
	goto __1
	goto __3
__3:
	;
	if int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnOut) > int32(nRow)-int32(iReduce) {
		(*WhereLoop)(unsafe.Pointer(pLoop)).FnOut = LogEst(int32(nRow) - int32(iReduce))
	}
}

func whereRangeVectorLen(tls *libc.TLS, pParse uintptr, iCur int32, pIdx uintptr, nEq int32, pTerm uintptr) int32 {
	var nCmp int32 = Xsqlite3ExprVectorSize(tls, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft)
	var i int32

	nCmp = func() int32 {
		if nCmp < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn)-nEq {
			return nCmp
		}
		return int32((*Index)(unsafe.Pointer(pIdx)).FnColumn) - nEq
	}()
	for i = 1; i < nCmp; i++ {
		var aff uint8
		var idxaff uint8 = uint8(0)
		var pColl uintptr
		var pLhs uintptr
		var pRhs uintptr

		pLhs = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpLeft + 32)) + 8 + uintptr(i)*32)).FpExpr
		pRhs = (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight
		if (*Expr)(unsafe.Pointer(pRhs)).Fflags&U32(EP_xIsSelect) != U32(0) {
			pRhs = (*ExprList_item)(unsafe.Pointer((*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pRhs + 32)))).FpEList + 8 + uintptr(i)*32)).FpExpr
		} else {
			pRhs = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pRhs + 32)) + 8 + uintptr(i)*32)).FpExpr
		}

		if int32((*Expr)(unsafe.Pointer(pLhs)).Fop) != TK_COLUMN ||
			(*Expr)(unsafe.Pointer(pLhs)).FiTable != iCur ||
			int32((*Expr)(unsafe.Pointer(pLhs)).FiColumn) != int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i+nEq)*2))) ||
			int32(*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(i+nEq)))) != int32(*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaSortOrder + uintptr(nEq)))) {
			break
		}

		aff = Xsqlite3CompareAffinity(tls, pRhs, Xsqlite3ExprAffinity(tls, pLhs))
		idxaff = Xsqlite3TableColumnAffinity(tls, (*Index)(unsafe.Pointer(pIdx)).FpTable, int32((*Expr)(unsafe.Pointer(pLhs)).FiColumn))
		if int32(aff) != int32(idxaff) {
			break
		}

		pColl = Xsqlite3BinaryCompareCollSeq(tls, pParse, pLhs, pRhs)
		if pColl == uintptr(0) {
			break
		}
		if Xsqlite3StrICmp(tls, (*CollSeq)(unsafe.Pointer(pColl)).FzName, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FazColl + uintptr(i+nEq)*8))) != 0 {
			break
		}
	}
	return i
}

func whereLoopAddBtreeIndex(tls *libc.TLS, pBuilder uintptr, pSrc uintptr, pProbe uintptr, nInMul LogEst) int32 {
	bp := tls.Alloc(120)
	defer tls.Free(120)

	var pWInfo uintptr = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var pNew uintptr
	var pTerm uintptr
	var opMask int32

	var saved_prereq Bitmask
	var saved_nLTerm U16
	var saved_nEq U16
	var saved_nBtm U16
	var saved_nTop U16
	var saved_nSkip U16
	var saved_wsFlags U32
	var saved_nOut LogEst
	var rc int32 = SQLITE_OK
	var rSize LogEst
	var rLogSize LogEst
	var pTop uintptr = uintptr(0)
	var pBtm uintptr = uintptr(0)

	pNew = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew

	if (*Parse)(unsafe.Pointer(pParse)).FnErr != 0 {
		return (*Parse)(unsafe.Pointer(pParse)).Frc
	}

	if (*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags&U32(WHERE_BTM_LIMIT) != 0 {
		opMask = int32(WO_EQ)<<(TK_LT-TK_EQ) | int32(WO_EQ)<<(TK_LE-TK_EQ)
	} else {
		opMask = WO_EQ | WO_IN | int32(WO_EQ)<<(TK_GT-TK_EQ) | int32(WO_EQ)<<(TK_GE-TK_EQ) | int32(WO_EQ)<<(TK_LT-TK_EQ) | int32(WO_EQ)<<(TK_LE-TK_EQ) | WO_ISNULL | WO_IS
	}
	if uint32(int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x4>>2)) != 0 {
		opMask = opMask & libc.CplInt32(int32(WO_EQ)<<(TK_GT-TK_EQ)|int32(WO_EQ)<<(TK_GE-TK_EQ)|int32(WO_EQ)<<(TK_LT-TK_EQ)|int32(WO_EQ)<<(TK_LE-TK_EQ))
	}

	saved_nEq = *(*U16)(unsafe.Pointer(pNew + 24))
	saved_nBtm = *(*U16)(unsafe.Pointer(pNew + 24 + 2))
	saved_nTop = *(*U16)(unsafe.Pointer(pNew + 24 + 4))
	saved_nSkip = (*WhereLoop)(unsafe.Pointer(pNew)).FnSkip
	saved_nLTerm = (*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm
	saved_wsFlags = (*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags
	saved_prereq = (*WhereLoop)(unsafe.Pointer(pNew)).Fprereq
	saved_nOut = (*WhereLoop)(unsafe.Pointer(pNew)).FnOut
	pTerm = whereScanInit(tls, bp, (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC, (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor, int32(saved_nEq),
		uint32(opMask), pProbe)
	(*WhereLoop)(unsafe.Pointer(pNew)).FrSetup = int16(0)
	rSize = *(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst))
	rLogSize = estLog(tls, rSize)
	for ; rc == SQLITE_OK && pTerm != uintptr(0); pTerm = whereScanNext(tls, bp) {
		var eOp U16 = (*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator
		var rCostIdx LogEst
		var nOutUnadjusted LogEst
		var nIn int32 = 0
		var nRecValid int32 = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid
		if (int32(eOp) == WO_ISNULL || int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_VNULL != 0) &&
			indexColumnNotNull(tls, pProbe, int32(saved_nEq)) != 0 {
			continue
		}
		if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&(*WhereLoop)(unsafe.Pointer(pNew)).FmaskSelf != 0 {
			continue
		}

		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_LIKEOPT != 0 && int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator) == int32(WO_EQ)<<(TK_LT-TK_EQ) {
			continue
		}

		if int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ|JT_RIGHT) != 0 &&
			!(constraintCompatibleWithOuterJoin(tls, pTerm, pSrc) != 0) {
			continue
		}
		if int32((*Index)(unsafe.Pointer(pProbe)).FonError) != OE_None && int32(saved_nEq) == int32((*Index)(unsafe.Pointer(pProbe)).FnKeyCol)-1 {
			*(*uint8)(unsafe.Pointer(pBuilder + 44)) |= uint8(SQLITE_BLDF1_UNIQUE)
		} else {
			*(*uint8)(unsafe.Pointer(pBuilder + 44)) |= uint8(SQLITE_BLDF1_INDEXED)
		}
		(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = saved_wsFlags
		*(*U16)(unsafe.Pointer(pNew + 24)) = saved_nEq
		*(*U16)(unsafe.Pointer(pNew + 24 + 2)) = saved_nBtm
		*(*U16)(unsafe.Pointer(pNew + 24 + 4)) = saved_nTop
		(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm = saved_nLTerm
		if int32((*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm) >= int32((*WhereLoop)(unsafe.Pointer(pNew)).FnLSlot) &&
			whereLoopResize(tls, db, pNew, int32((*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+1) != 0 {
			break
		}
		*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(libc.PostIncUint16(&(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm, 1))*8)) = pTerm
		(*WhereLoop)(unsafe.Pointer(pNew)).Fprereq = (saved_prereq | (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight) & ^(*WhereLoop)(unsafe.Pointer(pNew)).FmaskSelf

		if int32(eOp)&WO_IN != 0 {
			var pExpr uintptr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
			if (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_xIsSelect) != U32(0) {
				var i int32
				nIn = 46

				for i = 0; i < int32((*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm)-1; i++ {
					if *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*8)) != 0 && (*WhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*8)))).FpExpr == pExpr {
						nIn = 0
					}
				}
			} else if *(*uintptr)(unsafe.Pointer(pExpr + 32)) != 0 && (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr != 0 {
				nIn = int32(Xsqlite3LogEst(tls, uint64((*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 32)))).FnExpr)))
			}
			if uint32(int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x80>>7)) != 0 && int32(rLogSize) >= 10 {
				var M LogEst
				var logK LogEst
				var x LogEst

				M = *(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(saved_nEq)*2))
				logK = estLog(tls, int16(nIn))

				x = LogEst(int32(M) + int32(logK) + 10 - (nIn + int32(rLogSize)))
				if int32(x) >= 0 {
				} else if int32(nInMul) < 2 && (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_SeekScan) == U32(0) {
					*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_IN_SEEKSCAN)
				} else {
					continue
				}
			}
			*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_COLUMN_IN)
		} else if int32(eOp)&(WO_EQ|WO_IS) != 0 {
			var iCol int32 = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiColumn + uintptr(saved_nEq)*2)))
			*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_COLUMN_EQ)

			if iCol == -1 ||
				iCol >= 0 && int32(nInMul) == 0 && int32(saved_nEq) == int32((*Index)(unsafe.Pointer(pProbe)).FnKeyCol)-1 {
				if iCol == -1 || uint32(int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x8>>3)) != 0 ||
					int32((*Index)(unsafe.Pointer(pProbe)).FnKeyCol) == 1 && (*Index)(unsafe.Pointer(pProbe)).FonError != 0 && int32(eOp) == WO_EQ {
					*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_ONEROW)
				} else {
					*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_UNQ_WANTED)
				}
			}
			if int32((*WhereScan)(unsafe.Pointer(bp)).FiEquiv) > 1 {
				*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_TRANSCONS)
			}
		} else if int32(eOp)&WO_ISNULL != 0 {
			*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_COLUMN_NULL)
		} else {
			var nVecLen int32 = whereRangeVectorLen(tls,
				pParse, (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor, pProbe, int32(saved_nEq), pTerm)
			if int32(eOp)&(int32(WO_EQ)<<(TK_GT-TK_EQ)|int32(WO_EQ)<<(TK_GE-TK_EQ)) != 0 {
				*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_COLUMN_RANGE | WHERE_BTM_LIMIT)
				*(*U16)(unsafe.Pointer(pNew + 24 + 2)) = U16(nVecLen)
				pBtm = pTerm
				pTop = uintptr(0)
				if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_LIKEOPT != 0 {
					pTop = pTerm + 1*56

					if whereLoopResize(tls, db, pNew, int32((*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+1) != 0 {
						break
					}
					*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(libc.PostIncUint16(&(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm, 1))*8)) = pTop
					*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_TOP_LIMIT)
					*(*U16)(unsafe.Pointer(pNew + 24 + 4)) = U16(1)
				}
			} else {
				*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_COLUMN_RANGE | WHERE_TOP_LIMIT)
				*(*U16)(unsafe.Pointer(pNew + 24 + 4)) = U16(nVecLen)
				pTop = pTerm
				if (*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags&U32(WHERE_BTM_LIMIT) != U32(0) {
					pBtm = *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(int32((*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm)-2)*8))
				} else {
					pBtm = uintptr(0)
				}
			}
		}

		if (*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags&U32(WHERE_COLUMN_RANGE) != 0 {
			whereRangeScanEst(tls, pParse, pBuilder, pBtm, pTop, pNew)
		} else {
			var nEq int32 = int32(libc.PreIncUint16(&*(*U16)(unsafe.Pointer(pNew + 24)), 1))

			if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb) <= 0 && int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiColumn + uintptr(saved_nEq)*2))) >= 0 {
				*(*LogEst)(unsafe.Pointer(pNew + 22)) += LogEst(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb))
				*(*LogEst)(unsafe.Pointer(pNew + 22)) -= LogEst(nIn)
			} else {
				*(*TRowcnt)(unsafe.Pointer(bp + 112)) = uint64(0)
				if int32(nInMul) == 0 &&
					(*Index)(unsafe.Pointer(pProbe)).FnSample != 0 &&
					int32(*(*U16)(unsafe.Pointer(pNew + 24))) <= (*Index)(unsafe.Pointer(pProbe)).FnSampleCol &&
					(int32(eOp)&WO_IN == 0 || (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&U32(EP_xIsSelect) == U32(0)) &&
					(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_Stat4) == U32(0) {
					var pExpr uintptr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
					if int32(eOp)&(WO_EQ|WO_ISNULL|WO_IS) != 0 {
						rc = whereEqualScanEst(tls, pParse, pBuilder, (*Expr)(unsafe.Pointer(pExpr)).FpRight, bp+112)
					} else {
						rc = whereInScanEst(tls, pParse, pBuilder, *(*uintptr)(unsafe.Pointer(pExpr + 32)), bp+112)
					}
					if rc == SQLITE_NOTFOUND {
						rc = SQLITE_OK
					}
					if rc != SQLITE_OK {
						break
					}
					if *(*TRowcnt)(unsafe.Pointer(bp + 112)) != 0 {
						(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = Xsqlite3LogEst(tls, *(*TRowcnt)(unsafe.Pointer(bp + 112)))
						if nEq == 1 &&
							int32((*WhereLoop)(unsafe.Pointer(pNew)).FnOut)+10 > int32(*(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst))) {
							*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_HIGHTRUTH)
							if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_HEURTRUTH != 0 {
								*(*uint8)(unsafe.Pointer(pBuilder + 45)) |= uint8(SQLITE_BLDF2_2NDPASS)
							}
						}
						if int32((*WhereLoop)(unsafe.Pointer(pNew)).FnOut) > int32(saved_nOut) {
							(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
						}
						*(*LogEst)(unsafe.Pointer(pNew + 22)) -= LogEst(nIn)
					}
				}
				if *(*TRowcnt)(unsafe.Pointer(bp + 112)) == uint64(0) {
					*(*LogEst)(unsafe.Pointer(pNew + 22)) += LogEst(int32(*(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(nEq)*2))) - int32(*(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(nEq-1)*2))))
					if int32(eOp)&WO_ISNULL != 0 {
						*(*LogEst)(unsafe.Pointer(pNew + 22)) += int16(10)
					}
				}
			}
		}

		if int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x3>>0) == SQLITE_IDXTYPE_IPK {
			rCostIdx = LogEst(int32((*WhereLoop)(unsafe.Pointer(pNew)).FnOut) + 16)
		} else {
			rCostIdx = LogEst(int32((*WhereLoop)(unsafe.Pointer(pNew)).FnOut) + 1 + 15*int32((*Index)(unsafe.Pointer(pProbe)).FszIdxRow)/int32((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pSrc)).FpTab)).FszTabRow))
		}
		(*WhereLoop)(unsafe.Pointer(pNew)).FrRun = Xsqlite3LogEstAdd(tls, rLogSize, rCostIdx)
		if (*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags&U32(WHERE_IDX_ONLY|WHERE_IPK|WHERE_EXPRIDX) == U32(0) {
			(*WhereLoop)(unsafe.Pointer(pNew)).FrRun = Xsqlite3LogEstAdd(tls, (*WhereLoop)(unsafe.Pointer(pNew)).FrRun, int16(int32((*WhereLoop)(unsafe.Pointer(pNew)).FnOut)+16))
		}

		nOutUnadjusted = (*WhereLoop)(unsafe.Pointer(pNew)).FnOut
		*(*LogEst)(unsafe.Pointer(pNew + 20)) += LogEst(int32(nInMul) + nIn)
		*(*LogEst)(unsafe.Pointer(pNew + 22)) += LogEst(int32(nInMul) + nIn)
		whereLoopOutputAdjust(tls, (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC, pNew, rSize)
		rc = whereLoopInsert(tls, pBuilder, pNew)

		if (*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags&U32(WHERE_COLUMN_RANGE) != 0 {
			(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
		} else {
			(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = nOutUnadjusted
		}

		if (*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags&U32(WHERE_TOP_LIMIT) == U32(0) &&
			int32(*(*U16)(unsafe.Pointer(pNew + 24))) < int32((*Index)(unsafe.Pointer(pProbe)).FnColumn) &&
			(int32(*(*U16)(unsafe.Pointer(pNew + 24))) < int32((*Index)(unsafe.Pointer(pProbe)).FnKeyCol) || int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x3>>0) != SQLITE_IDXTYPE_PRIMARYKEY) {
			if int32(*(*U16)(unsafe.Pointer(pNew + 24))) > 3 {
				Xsqlite3ProgressCheck(tls, pParse)
			}
			whereLoopAddBtreeIndex(tls, pBuilder, pSrc, pProbe, int16(int32(nInMul)+nIn))
		}
		(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
		(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid = nRecValid
	}
	(*WhereLoop)(unsafe.Pointer(pNew)).Fprereq = saved_prereq
	*(*U16)(unsafe.Pointer(pNew + 24)) = saved_nEq
	*(*U16)(unsafe.Pointer(pNew + 24 + 2)) = saved_nBtm
	*(*U16)(unsafe.Pointer(pNew + 24 + 4)) = saved_nTop
	(*WhereLoop)(unsafe.Pointer(pNew)).FnSkip = saved_nSkip
	(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = saved_wsFlags
	(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
	(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm = saved_nLTerm

	if int32(saved_nEq) == int32(saved_nSkip) &&
		int32(saved_nEq)+1 < int32((*Index)(unsafe.Pointer(pProbe)).FnKeyCol) &&
		int32(saved_nEq) == int32((*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm) &&
		int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x40>>6) == 0 &&
		int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x80>>7) != 0 &&
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_SkipScan) == U32(0) &&
		int32(*(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(int32(saved_nEq)+1)*2))) >= 42 &&
		libc.AssignInt32(&rc, whereLoopResize(tls, db, pNew, int32((*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm)+1)) == SQLITE_OK {
		var nIter LogEst
		*(*U16)(unsafe.Pointer(pNew + 24))++
		(*WhereLoop)(unsafe.Pointer(pNew)).FnSkip++
		*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(libc.PostIncUint16(&(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm, 1))*8)) = uintptr(0)
		*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_SKIPSCAN)
		nIter = LogEst(int32(*(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(saved_nEq)*2))) - int32(*(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst + uintptr(int32(saved_nEq)+1)*2))))
		*(*LogEst)(unsafe.Pointer(pNew + 22)) -= LogEst(int32(nIter))

		nIter = int16(int32(nIter) + 5)
		whereLoopAddBtreeIndex(tls, pBuilder, pSrc, pProbe, int16(int32(nIter)+int32(nInMul)))
		(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = saved_nOut
		*(*U16)(unsafe.Pointer(pNew + 24)) = saved_nEq
		(*WhereLoop)(unsafe.Pointer(pNew)).FnSkip = saved_nSkip
		(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = saved_wsFlags
	}

	return rc
}

func indexMightHelpWithOrderBy(tls *libc.TLS, pBuilder uintptr, pIndex uintptr, iCursor int32) int32 {
	var pOB uintptr
	var aColExpr uintptr
	var ii int32
	var jj int32

	if uint32(int32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x4>>2)) != 0 {
		return 0
	}
	if libc.AssignUintptr(&pOB, (*WhereInfo)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo)).FpOrderBy) == uintptr(0) {
		return 0
	}
	for ii = 0; ii < (*ExprList)(unsafe.Pointer(pOB)).FnExpr; ii++ {
		var pExpr uintptr = Xsqlite3ExprSkipCollateAndLikely(tls, (*ExprList_item)(unsafe.Pointer(pOB+8+uintptr(ii)*32)).FpExpr)
		if pExpr == uintptr(0) {
			continue
		}
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN && (*Expr)(unsafe.Pointer(pExpr)).FiTable == iCursor {
			if int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) < 0 {
				return 1
			}
			for jj = 0; jj < int32((*Index)(unsafe.Pointer(pIndex)).FnKeyCol); jj++ {
				if int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) == int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(jj)*2))) {
					return 1
				}
			}
		} else if libc.AssignUintptr(&aColExpr, (*Index)(unsafe.Pointer(pIndex)).FaColExpr) != uintptr(0) {
			for jj = 0; jj < int32((*Index)(unsafe.Pointer(pIndex)).FnKeyCol); jj++ {
				if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(jj)*2))) != -2 {
					continue
				}
				if Xsqlite3ExprCompareSkip(tls, pExpr, (*ExprList_item)(unsafe.Pointer(aColExpr+8+uintptr(jj)*32)).FpExpr, iCursor) == 0 {
					return 1
				}
			}
		}
	}
	return 0
}

func whereUsablePartialIndex(tls *libc.TLS, iTab int32, jointype U8, pWC uintptr, pWhere uintptr) int32 {
	var i int32
	var pTerm uintptr
	var pParse uintptr

	if int32(jointype)&JT_LTORJ != 0 {
		return 0
	}
	pParse = (*WhereInfo)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).FpWInfo)).FpParse
	for int32((*Expr)(unsafe.Pointer(pWhere)).Fop) == TK_AND {
		if !(whereUsablePartialIndex(tls, iTab, jointype, pWC, (*Expr)(unsafe.Pointer(pWhere)).FpLeft) != 0) {
			return 0
		}
		pWhere = (*Expr)(unsafe.Pointer(pWhere)).FpRight
	}
	if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Fflags&uint64(SQLITE_EnableQPSG) != 0 {
		pParse = uintptr(0)
	}
	i = 0
	pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa
__1:
	if !(i < (*WhereClause)(unsafe.Pointer(pWC)).FnTerm) {
		goto __3
	}
	{
		var pExpr uintptr
		pExpr = (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr
		if (!((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0)) || *(*int32)(unsafe.Pointer(pExpr + 52)) == iTab) &&
			(int32(jointype)&JT_OUTER == 0 || (*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_OuterON) != U32(0)) &&
			Xsqlite3ExprImpliesExpr(tls, pParse, pExpr, pWhere, iTab) != 0 &&
			int32((*WhereTerm)(unsafe.Pointer(pTerm)).FwtFlags)&TERM_VNULL == 0 {
			return 1
		}

	}
	goto __2
__2:
	i++
	pTerm += 56
	goto __1
	goto __3
__3:
	;
	return 0
}

func exprIsCoveredByIndex(tls *libc.TLS, pExpr uintptr, pIdx uintptr, iTabCur int32) int32 {
	var i int32
	for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn); i++ {
		if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) == -2 &&
			Xsqlite3ExprCompare(tls, uintptr(0), pExpr, (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr+8+uintptr(i)*32)).FpExpr, iTabCur) == 0 {
			return 1
		}
	}
	return 0
}

type CoveringIndexCheck = CoveringIndexCheck1

func whereIsCoveringIndexWalkCallback(tls *libc.TLS, pWalk uintptr, pExpr uintptr) int32 {
	var i int32
	var pIdx uintptr
	var aiColumn uintptr
	var nColumn U16
	var pCk uintptr

	pCk = *(*uintptr)(unsafe.Pointer(pWalk + 40))
	pIdx = (*CoveringIndexCheck)(unsafe.Pointer(pCk)).FpIdx
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_COLUMN || int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AGG_COLUMN {
		if (*Expr)(unsafe.Pointer(pExpr)).FiTable != (*CoveringIndexCheck)(unsafe.Pointer(pCk)).FiTabCur {
			return WRC_Continue
		}
		pIdx = (*CoveringIndexCheck1)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalk + 40)))).FpIdx
		aiColumn = (*Index)(unsafe.Pointer(pIdx)).FaiColumn
		nColumn = (*Index)(unsafe.Pointer(pIdx)).FnColumn
		for i = 0; i < int32(nColumn); i++ {
			if int32(*(*I16)(unsafe.Pointer(aiColumn + uintptr(i)*2))) == int32((*Expr)(unsafe.Pointer(pExpr)).FiColumn) {
				return WRC_Continue
			}
		}
		(*CoveringIndexCheck)(unsafe.Pointer(pCk)).FbUnidx = U8(1)
		return WRC_Abort
	} else if uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x800>>11)) != 0 &&
		exprIsCoveredByIndex(tls, pExpr, pIdx, (*CoveringIndexCheck1)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pWalk + 40)))).FiTabCur) != 0 {
		(*CoveringIndexCheck)(unsafe.Pointer(pCk)).FbExpr = U8(1)
		return WRC_Prune
	}
	return WRC_Continue
}

func whereIsCoveringIndex(tls *libc.TLS, pWInfo uintptr, pIdx uintptr, iTabCur int32) U32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var i int32
	var rc int32

	if (*WhereInfo)(unsafe.Pointer(pWInfo)).FpSelect == uintptr(0) {
		return U32(0)
	}
	if int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x800>>11) == 0 {
		for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn); i++ {
			if int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) >= int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1 {
				break
			}
		}
		if i >= int32((*Index)(unsafe.Pointer(pIdx)).FnColumn) {
			return U32(0)
		}
	}
	(*CoveringIndexCheck1)(unsafe.Pointer(bp + 48)).FpIdx = pIdx
	(*CoveringIndexCheck1)(unsafe.Pointer(bp + 48)).FiTabCur = iTabCur
	(*CoveringIndexCheck1)(unsafe.Pointer(bp + 48)).FbExpr = U8(0)
	(*CoveringIndexCheck1)(unsafe.Pointer(bp + 48)).FbUnidx = U8(0)
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{whereIsCoveringIndexWalkCallback}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3SelectWalkNoop}))
	*(*uintptr)(unsafe.Pointer(bp + 40)) = bp + 48
	Xsqlite3WalkSelect(tls, bp, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)
	if (*CoveringIndexCheck1)(unsafe.Pointer(bp+48)).FbUnidx != 0 {
		rc = 0
	} else if (*CoveringIndexCheck1)(unsafe.Pointer(bp+48)).FbExpr != 0 {
		rc = WHERE_EXPRIDX
	} else {
		rc = WHERE_IDX_ONLY
	}
	return U32(rc)
}

func whereLoopAddBtree(tls *libc.TLS, pBuilder uintptr, mPrereq Bitmask) int32 {
	bp := tls.Alloc(158)
	defer tls.Free(158)

	var pWInfo uintptr
	var pProbe uintptr

	*(*I16)(unsafe.Pointer(bp + 152)) = int16(-1)
	var pTabList uintptr
	var pSrc uintptr
	var pNew uintptr
	var rc int32 = SQLITE_OK
	var iSortIdx int32 = 1
	var b int32
	var rSize LogEst
	var pWC uintptr
	var pTab uintptr

	pNew = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	pWInfo = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	pTabList = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
	pSrc = pTabList + 8 + uintptr((*WhereLoop)(unsafe.Pointer(pNew)).FiTab)*104
	pTab = (*SrcItem)(unsafe.Pointer(pSrc)).FpTab
	pWC = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC

	if uint32(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x2>>1)) != 0 {
		pProbe = *(*uintptr)(unsafe.Pointer(pSrc + 96))
	} else if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		pProbe = (*Table)(unsafe.Pointer(pTab)).FpIndex
	} else {
		var pFirst uintptr
		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Index{})))
		(*Index)(unsafe.Pointer(bp)).FnKeyCol = U16(1)
		(*Index)(unsafe.Pointer(bp)).FnColumn = U16(1)
		(*Index)(unsafe.Pointer(bp)).FaiColumn = bp + 152
		(*Index)(unsafe.Pointer(bp)).FaiRowLogEst = bp + 154
		(*Index)(unsafe.Pointer(bp)).FonError = U8(OE_Replace)
		(*Index)(unsafe.Pointer(bp)).FpTable = pTab
		(*Index)(unsafe.Pointer(bp)).FszIdxRow = int16(3)
		libc.SetBitFieldPtr16Uint32(bp+100, uint32(SQLITE_IDXTYPE_IPK), 0, 0x3)
		*(*LogEst)(unsafe.Pointer(bp + 154)) = (*Table)(unsafe.Pointer(pTab)).FnRowLogEst
		*(*LogEst)(unsafe.Pointer(bp + 154 + 1*2)) = int16(0)
		pFirst = (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pSrc)).FpTab)).FpIndex
		if int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x1>>0) == 0 {
			(*Index)(unsafe.Pointer(bp)).FpNext = pFirst
		}
		pProbe = bp
	}
	rSize = (*Table)(unsafe.Pointer(pTab)).FnRowLogEst

	if !(int32((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet) != 0) &&
		int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(WHERE_RIGHT_JOIN|WHERE_OR_SUBCLAUSE) == 0 &&
		(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb)).Fflags&uint64(SQLITE_AutoIndex) != uint64(0) &&
		!(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x2>>1) != 0) &&
		!(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x1>>0) != 0) &&
		(*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) &&
		!(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x8>>3) != 0) &&
		!(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x40>>6) != 0) &&
		int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&JT_RIGHT == 0 {
		var rLogSize LogEst
		var pTerm uintptr
		var pWCEnd uintptr = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*WhereClause)(unsafe.Pointer(pWC)).FnTerm)*56
		rLogSize = estLog(tls, rSize)
		for pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa; rc == SQLITE_OK && pTerm < pWCEnd; pTerm += 56 {
			if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&(*WhereLoop)(unsafe.Pointer(pNew)).FmaskSelf != 0 {
				continue
			}
			if termCanDriveIndex(tls, pTerm, pSrc, uint64(0)) != 0 {
				*(*U16)(unsafe.Pointer(pNew + 24)) = U16(1)
				(*WhereLoop)(unsafe.Pointer(pNew)).FnSkip = U16(0)
				*(*uintptr)(unsafe.Pointer(pNew + 24 + 8)) = uintptr(0)
				(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm = U16(1)
				*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm)) = pTerm

				(*WhereLoop)(unsafe.Pointer(pNew)).FrSetup = LogEst(int32(rLogSize) + int32(rSize))
				if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) && (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Ephemeral) == U32(0) {
					*(*LogEst)(unsafe.Pointer(pNew + 18)) += int16(28)
				} else {
					*(*LogEst)(unsafe.Pointer(pNew + 18)) -= int16(25)

				}

				if int32((*WhereLoop)(unsafe.Pointer(pNew)).FrSetup) < 0 {
					(*WhereLoop)(unsafe.Pointer(pNew)).FrSetup = int16(0)
				}

				(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = int16(43)
				(*WhereLoop)(unsafe.Pointer(pNew)).FrRun = Xsqlite3LogEstAdd(tls, rLogSize, (*WhereLoop)(unsafe.Pointer(pNew)).FnOut)
				(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = U32(WHERE_AUTO_INDEX)
				(*WhereLoop)(unsafe.Pointer(pNew)).Fprereq = mPrereq | (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight
				rc = whereLoopInsert(tls, pBuilder, pNew)
			}
		}
	}

__1:
	if !(rc == SQLITE_OK && pProbe != 0) {
		goto __3
	}
	{
		if (*Index)(unsafe.Pointer(pProbe)).FpPartIdxWhere != uintptr(0) &&
			!(whereUsablePartialIndex(tls, (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor, (*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype, pWC,
				(*Index)(unsafe.Pointer(pProbe)).FpPartIdxWhere) != 0) {
			goto __2
		}
		if uint32(int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x100>>8)) != 0 {
			goto __2
		}
		rSize = *(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pProbe)).FaiRowLogEst))
		*(*U16)(unsafe.Pointer(pNew + 24)) = U16(0)
		*(*U16)(unsafe.Pointer(pNew + 24 + 2)) = U16(0)
		*(*U16)(unsafe.Pointer(pNew + 24 + 4)) = U16(0)
		(*WhereLoop)(unsafe.Pointer(pNew)).FnSkip = U16(0)
		(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm = U16(0)
		(*WhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = U8(0)
		(*WhereLoop)(unsafe.Pointer(pNew)).FrSetup = int16(0)
		(*WhereLoop)(unsafe.Pointer(pNew)).Fprereq = mPrereq
		(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = rSize
		*(*uintptr)(unsafe.Pointer(pNew + 24 + 8)) = pProbe
		b = indexMightHelpWithOrderBy(tls, pBuilder, pProbe, (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor)

		if int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x3>>0) == SQLITE_IDXTYPE_IPK {
			(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = U32(WHERE_IPK)

			(*WhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = func() uint8 {
				if b != 0 {
					return uint8(iSortIdx)
				}
				return uint8(0)
			}()

			(*WhereLoop)(unsafe.Pointer(pNew)).FrRun = LogEst(int32(rSize) + 16 - 2*libc.Bool32((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasStat4) != U32(0)))
			if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW || (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Ephemeral) != U32(0) {
				*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_VIEWSCAN)
			}

			whereLoopOutputAdjust(tls, pWC, pNew, rSize)
			rc = whereLoopInsert(tls, pBuilder, pNew)
			(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = rSize
			if rc != 0 {
				goto __3
			}
		} else {
			var m Bitmask
			if uint32(int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x20>>5)) != 0 {
				m = uint64(0)
				(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = U32(WHERE_IDX_ONLY | WHERE_INDEXED)
			} else {
				m = (*SrcItem)(unsafe.Pointer(pSrc)).FcolUsed & (*Index)(unsafe.Pointer(pProbe)).FcolNotIdxed
				(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = U32(WHERE_INDEXED)
				if m == uint64(1)<<(int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1) || uint32(int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x800>>11)) != 0 && !(int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x400>>10) != 0) && m != uint64(0) {
					var isCov U32 = whereIsCoveringIndex(tls, pWInfo, pProbe, (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor)
					if isCov == U32(0) {
					} else {
						m = uint64(0)
						*(*U32)(unsafe.Pointer(pNew + 56)) |= isCov
						if isCov&U32(WHERE_IDX_ONLY) != 0 {
						} else {
						}
					}
				} else if m == uint64(0) {
					(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = U32(WHERE_IDX_ONLY | WHERE_INDEXED)
				}
			}

			if b != 0 ||
				!((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) ||
				(*Index)(unsafe.Pointer(pProbe)).FpPartIdxWhere != uintptr(0) ||
				uint32(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x2>>1)) != 0 ||
				m == uint64(0) &&
					int32(*(*uint16)(unsafe.Pointer(pProbe + 100))&0x4>>2) == 0 &&
					int32((*Index)(unsafe.Pointer(pProbe)).FszIdxRow) < int32((*Table)(unsafe.Pointer(pTab)).FszTabRow) &&
					int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_ONEPASS_DESIRED == 0 &&
					Xsqlite3Config.FbUseCis != 0 &&
					(*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb)).FdbOptFlags&U32(SQLITE_CoverIdxScan) == U32(0) {
				(*WhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = func() uint8 {
					if b != 0 {
						return uint8(iSortIdx)
					}
					return uint8(0)
				}()

				(*WhereLoop)(unsafe.Pointer(pNew)).FrRun = LogEst(int32(rSize) + 1 + 15*int32((*Index)(unsafe.Pointer(pProbe)).FszIdxRow)/int32((*Table)(unsafe.Pointer(pTab)).FszTabRow))
				if m != uint64(0) {
					var nLookup LogEst = LogEst(int32(rSize) + 16)
					var ii int32
					var iCur int32 = (*SrcItem)(unsafe.Pointer(pSrc)).FiCursor
					var pWC2 uintptr = pWInfo + 104
					for ii = 0; ii < (*WhereClause)(unsafe.Pointer(pWC2)).FnTerm; ii++ {
						var pTerm uintptr = (*WhereClause)(unsafe.Pointer(pWC2)).Fa + uintptr(ii)*56
						if !(Xsqlite3ExprCoveredByIndex(tls, (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr, iCur, pProbe) != 0) {
							break
						}

						if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb) <= 0 {
							nLookup = LogEst(int32(nLookup) + int32((*WhereTerm)(unsafe.Pointer(pTerm)).FtruthProb))
						} else {
							nLookup--
							if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(WO_EQ|WO_IS) != 0 {
								nLookup = int16(int32(nLookup) - 19)
							}
						}
					}

					(*WhereLoop)(unsafe.Pointer(pNew)).FrRun = Xsqlite3LogEstAdd(tls, (*WhereLoop)(unsafe.Pointer(pNew)).FrRun, nLookup)
				}

				whereLoopOutputAdjust(tls, pWC, pNew, rSize)
				if int32((*SrcItem)(unsafe.Pointer(pSrc)).Ffg.Fjointype)&JT_RIGHT != 0 && (*Index)(unsafe.Pointer(pProbe)).FaColExpr != 0 {
				} else {
					rc = whereLoopInsert(tls, pBuilder, pNew)
				}
				(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = rSize
				if rc != 0 {
					goto __3
				}
			}
		}

		(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FbldFlags1 = uint8(0)
		rc = whereLoopAddBtreeIndex(tls, pBuilder, pSrc, pProbe, int16(0))
		if int32((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FbldFlags1) == SQLITE_BLDF1_INDEXED {
			*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_StatsUsed)
		}
		Xsqlite3Stat4ProbeFree(tls, (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec)
		(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FnRecValid = 0
		(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpRec = uintptr(0)

	}
	goto __2
__2:
	pProbe = func() uintptr {
		if uint32(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x2>>1)) != 0 {
			return uintptr(0)
		}
		return (*Index)(unsafe.Pointer(pProbe)).FpNext
	}()
	iSortIdx++
	goto __1
	goto __3
__3:
	;
	return rc
}

func isLimitTerm(tls *libc.TLS, pTerm uintptr) int32 {
	return libc.Bool32(int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) >= SQLITE_INDEX_CONSTRAINT_LIMIT &&
		int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) <= SQLITE_INDEX_CONSTRAINT_OFFSET)
}

func whereLoopAddVirtualOne(tls *libc.TLS, pBuilder uintptr, mPrereq Bitmask, mUsable Bitmask, mExclude U16, pIdxInfo uintptr, mNoOmit U16, pbIn uintptr, pbRetryLimit uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pWC uintptr = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	var pHidden uintptr = pIdxInfo + 1*96
	var pIdxCons uintptr
	var pUsage uintptr = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage
	var i int32
	var mxTerm int32
	var rc int32 = SQLITE_OK
	var pNew uintptr = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	var pParse uintptr = (*WhereInfo)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo)).FpParse
	var pSrc uintptr = (*WhereInfo)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo)).FpTabList + 8 + uintptr((*WhereLoop)(unsafe.Pointer(pNew)).FiTab)*104
	var nConstraint int32 = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint

	*(*int32)(unsafe.Pointer(pbIn)) = 0
	(*WhereLoop)(unsafe.Pointer(pNew)).Fprereq = mPrereq

	pIdxCons = *(*uintptr)(unsafe.Pointer(pIdxInfo + 8))
	i = 0
__1:
	if !(i < nConstraint) {
		goto __3
	}
	{
		var pTerm uintptr = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).FiTermOffset)*56
		(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable = uint8(0)
		if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight&mUsable == (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight &&
			int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&int32(mExclude) == 0 &&
			(pbRetryLimit != 0 || !(isLimitTerm(tls, pTerm) != 0)) {
			(*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable = uint8(1)
		}

	}
	goto __2
__2:
	i++
	pIdxCons += 12
	goto __1
	goto __3
__3:
	;
	libc.Xmemset(tls, pUsage, 0, uint64(unsafe.Sizeof(sqlite3_index_constraint_usage{}))*uint64(nConstraint))

	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = uintptr(0)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 0
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 0
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(1e99) / float64(2)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(25)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = 0
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FcolUsed = Sqlite3_uint64(Sqlite3_int64((*SrcItem)(unsafe.Pointer(pSrc)).FcolUsed))
	(*HiddenIndexInfo)(unsafe.Pointer(pHidden)).FmHandleIn = U32(0)

	rc = vtabBestIndex(tls, pParse, (*SrcItem)(unsafe.Pointer(pSrc)).FpTab, pIdxInfo)
	if rc != 0 {
		if rc == SQLITE_CONSTRAINT {
			return SQLITE_OK
		}
		return rc
	}

	mxTerm = -1

	libc.Xmemset(tls, (*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm, 0, uint64(unsafe.Sizeof(uintptr(0)))*uint64(nConstraint))
	libc.Xmemset(tls, pNew+24, 0, uint64(unsafe.Sizeof(struct {
		FidxNum      int32
		FneedFree    uint8
		F__ccgo_pad1 [1]byte
		FisOrdered   I8
		F__ccgo_pad2 [1]byte
		FomitMask    U16
		F__ccgo_pad3 [6]byte
		FidxStr      uintptr
		FmHandleIn   U32
		F__ccgo_pad4 [4]byte
	}{})))
	pIdxCons = *(*uintptr)(unsafe.Pointer(pIdxInfo + 8))
	i = 0
__4:
	if !(i < nConstraint) {
		goto __6
	}
	{
		var iTerm int32
		if libc.AssignInt32(&iTerm, (*sqlite3_index_constraint_usage)(unsafe.Pointer(pUsage+uintptr(i)*8)).FargvIndex-1) >= 0 {
			var pTerm uintptr
			var j int32 = (*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).FiTermOffset
			if iTerm >= nConstraint ||
				j < 0 ||
				j >= (*WhereClause)(unsafe.Pointer(pWC)).FnTerm ||
				*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(iTerm)*8)) != uintptr(0) ||
				int32((*sqlite3_index_constraint)(unsafe.Pointer(pIdxCons)).Fusable) == 0 {
				Xsqlite3ErrorMsg(tls, pParse, ts+26479, libc.VaList(bp, (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pSrc)).FpTab)).FzName))

				return SQLITE_ERROR
			}

			pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(j)*56
			*(*Bitmask)(unsafe.Pointer(pNew)) |= (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight

			*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(iTerm)*8)) = pTerm
			if iTerm > mxTerm {
				mxTerm = iTerm
			}

			if (*sqlite3_index_constraint_usage)(unsafe.Pointer(pUsage+uintptr(i)*8)).Fomit != 0 {
				if i < 16 && int32(1)<<i&int32(mNoOmit) == 0 {
					*(*U16)(unsafe.Pointer(pNew + 24 + 8)) |= U16(int32(1) << iTerm)
				} else {
				}
				if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeMatchOp) == SQLITE_INDEX_CONSTRAINT_OFFSET {
					libc.SetBitFieldPtr8Uint32(pNew+24+4, U32(1), 1, 0x2)
				}
			}
			if func() uint32 {
				if i <= 31 {
					return uint32(1) << i
				}
				return uint32(0)
			}()&(*HiddenIndexInfo)(unsafe.Pointer(pHidden)).FmHandleIn != 0 {
				*(*U32)(unsafe.Pointer(pNew + 24 + 24)) |= uint32(1) << iTerm
			} else if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_IN != 0 {
				(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 0
				*(*int32)(unsafe.Pointer(pIdxInfo + 80)) &= libc.CplInt32(SQLITE_INDEX_SCAN_UNIQUE)
				*(*int32)(unsafe.Pointer(pbIn)) = 1
			}

			if isLimitTerm(tls, pTerm) != 0 && *(*int32)(unsafe.Pointer(pbIn)) != 0 {
				if (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr != 0 {
					Xsqlite3_free(tls, (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr)
					(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = uintptr(0)
					(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = 0
				}
				*(*int32)(unsafe.Pointer(pbRetryLimit)) = 1
				return SQLITE_OK
			}
		}

	}
	goto __5
__5:
	i++
	pIdxCons += 12
	goto __4
	goto __6
__6:
	;
	(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm = U16(mxTerm + 1)
	for i = 0; i <= mxTerm; i++ {
		if *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm + uintptr(i)*8)) == uintptr(0) {
			Xsqlite3ErrorMsg(tls, pParse, ts+26479, libc.VaList(bp+8, (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pSrc)).FpTab)).FzName))

			return SQLITE_ERROR
		}
	}

	*(*int32)(unsafe.Pointer(pNew + 24)) = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum
	libc.SetBitFieldPtr8Uint32(pNew+24+4, U32((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr), 0, 0x1)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = 0
	*(*uintptr)(unsafe.Pointer(pNew + 24 + 16)) = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr
	*(*I8)(unsafe.Pointer(pNew + 24 + 6)) = func() int8 {
		if (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed != 0 {
			return int8((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy)
		}
		return int8(0)
	}()
	(*WhereLoop)(unsafe.Pointer(pNew)).FrSetup = int16(0)
	(*WhereLoop)(unsafe.Pointer(pNew)).FrRun = Xsqlite3LogEstFromDouble(tls, (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost)
	(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = Xsqlite3LogEst(tls, uint64((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows))

	if (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags&SQLITE_INDEX_SCAN_UNIQUE != 0 {
		*(*U32)(unsafe.Pointer(pNew + 56)) |= U32(WHERE_ONEROW)
	} else {
		*(*U32)(unsafe.Pointer(pNew + 56)) &= libc.Uint32FromInt32(libc.CplInt32(WHERE_ONEROW))
	}
	rc = whereLoopInsert(tls, pBuilder, pNew)
	if U32(int32(*(*uint8)(unsafe.Pointer(pNew + 24 + 4))&0x1>>0)) != 0 {
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(pNew + 24 + 16)))
		libc.SetBitFieldPtr8Uint32(pNew+24+4, U32(0), 0, 0x1)
	}

	return rc
}

func Xsqlite3_vtab_collation(tls *libc.TLS, pIdxInfo uintptr, iCons int32) uintptr {
	var pHidden uintptr = pIdxInfo + 1*96
	var zRet uintptr = uintptr(0)
	if iCons >= 0 && iCons < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint {
		var pC uintptr = uintptr(0)
		var iTerm int32 = (*sqlite3_index_constraint)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(iCons)*12)).FiTermOffset
		var pX uintptr = (*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer((*HiddenIndexInfo)(unsafe.Pointer(pHidden)).FpWC)).Fa + uintptr(iTerm)*56)).FpExpr
		if (*Expr)(unsafe.Pointer(pX)).FpLeft != 0 {
			pC = Xsqlite3ExprCompareCollSeq(tls, (*HiddenIndexInfo)(unsafe.Pointer(pHidden)).FpParse, pX)
		}
		zRet = func() uintptr {
			if pC != 0 {
				return (*CollSeq)(unsafe.Pointer(pC)).FzName
			}
			return uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
		}()
	}
	return zRet
}

func Xsqlite3_vtab_in(tls *libc.TLS, pIdxInfo uintptr, iCons int32, bHandle int32) int32 {
	var pHidden uintptr = pIdxInfo + 1*96
	var m U32 = func() uint32 {
		if iCons <= 31 {
			return uint32(1) << iCons
		}
		return uint32(0)
	}()
	if m&(*HiddenIndexInfo)(unsafe.Pointer(pHidden)).FmIn != 0 {
		if bHandle == 0 {
			*(*U32)(unsafe.Pointer(pHidden + 24)) &= ^m
		} else if bHandle > 0 {
			*(*U32)(unsafe.Pointer(pHidden + 24)) |= m
		}
		return 1
	}
	return 0
}

func Xsqlite3_vtab_rhs_value(tls *libc.TLS, pIdxInfo uintptr, iCons int32, ppVal uintptr) int32 {
	var pH uintptr = pIdxInfo + 1*96
	var pVal uintptr = uintptr(0)
	var rc int32 = SQLITE_OK
	if iCons < 0 || iCons >= (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint {
		rc = SQLITE_MISUSE
	} else {
		if *(*uintptr)(unsafe.Pointer(pH + 32 + uintptr(iCons)*8)) == uintptr(0) {
			var pTerm uintptr = (*WhereClause)(unsafe.Pointer((*HiddenIndexInfo)(unsafe.Pointer(pH)).FpWC)).Fa + uintptr((*sqlite3_index_constraint)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint+uintptr(iCons)*12)).FiTermOffset)*56
			rc = Xsqlite3ValueFromExpr(tls,
				(*Parse)(unsafe.Pointer((*HiddenIndexInfo)(unsafe.Pointer(pH)).FpParse)).Fdb, (*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).FpRight, (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer((*HiddenIndexInfo)(unsafe.Pointer(pH)).FpParse)).Fdb)).Fenc,
				uint8(SQLITE_AFF_BLOB), pH+32+uintptr(iCons)*8)

		}
		pVal = *(*uintptr)(unsafe.Pointer(pH + 32 + uintptr(iCons)*8))
	}
	*(*uintptr)(unsafe.Pointer(ppVal)) = pVal

	if rc == SQLITE_OK && pVal == uintptr(0) {
		rc = SQLITE_NOTFOUND
	}

	return rc
}

func Xsqlite3_vtab_distinct(tls *libc.TLS, pIdxInfo uintptr) int32 {
	var pHidden uintptr = pIdxInfo + 1*96

	return (*HiddenIndexInfo)(unsafe.Pointer(pHidden)).FeDistinct
}

func Xsqlite3VtabUsesAllSchemas(tls *libc.TLS, pIdxInfo uintptr) {
	var pHidden uintptr = pIdxInfo + 1*96
	var pParse uintptr = (*HiddenIndexInfo)(unsafe.Pointer(pHidden)).FpParse
	var nDb int32 = (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FnDb
	var i int32
	for i = 0; i < nDb; i++ {
		Xsqlite3CodeVerifySchema(tls, pParse, i)
	}
	if (*Parse)(unsafe.Pointer(pParse)).FwriteMask != YDbMask(0) {
		for i = 0; i < nDb; i++ {
			Xsqlite3BeginWriteOperation(tls, pParse, 0, i)
		}
	}
}

func whereLoopAddVirtual(tls *libc.TLS, pBuilder uintptr, mPrereq Bitmask, mUnusable Bitmask) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var rc int32 = SQLITE_OK
	var pWInfo uintptr
	var pParse uintptr
	var pWC uintptr
	var pSrc uintptr
	var p uintptr
	var nConstraint int32

	var pNew uintptr
	var mBest Bitmask

	*(*int32)(unsafe.Pointer(bp + 8)) = 0

	pWInfo = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	pParse = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	pWC = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	pNew = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	pSrc = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLoop)(unsafe.Pointer(pNew)).FiTab)*104

	p = allocateIndexInfo(tls, pWInfo, pWC, mUnusable, pSrc, bp)
	if p == uintptr(0) {
		return SQLITE_NOMEM
	}
	(*WhereLoop)(unsafe.Pointer(pNew)).FrSetup = int16(0)
	(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = U32(WHERE_VIRTUALTABLE)
	(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm = U16(0)
	libc.SetBitFieldPtr8Uint32(pNew+24+4, U32(0), 0, 0x1)
	nConstraint = (*Sqlite3_index_info)(unsafe.Pointer(p)).FnConstraint
	if whereLoopResize(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pNew, nConstraint) != 0 {
		freeIndexInfo(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, p)
		return SQLITE_NOMEM
	}

	rc = whereLoopAddVirtualOne(tls,
		pBuilder, mPrereq, libc.Uint64(libc.Uint64FromInt32(-1)), uint16(0), p, *(*U16)(unsafe.Pointer(bp)), bp+4, bp+8)
	if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
		rc = whereLoopAddVirtualOne(tls,
			pBuilder, mPrereq, libc.Uint64(libc.Uint64FromInt32(-1)), uint16(0), p, *(*U16)(unsafe.Pointer(bp)), bp+4, uintptr(0))
	}

	if rc == SQLITE_OK && (libc.AssignUint64(&mBest, (*WhereLoop)(unsafe.Pointer(pNew)).Fprereq & ^mPrereq) != uint64(0) || *(*int32)(unsafe.Pointer(bp + 4)) != 0) {
		var seenZero int32 = 0
		var seenZeroNoIN int32 = 0
		var mPrev Bitmask = uint64(0)
		var mBestNoIn Bitmask = uint64(0)

		if *(*int32)(unsafe.Pointer(bp + 4)) != 0 {
			rc = whereLoopAddVirtualOne(tls,
				pBuilder, mPrereq, libc.Uint64(libc.Uint64FromInt32(-1)), uint16(WO_IN), p, *(*U16)(unsafe.Pointer(bp)), bp+4, uintptr(0))

			mBestNoIn = (*WhereLoop)(unsafe.Pointer(pNew)).Fprereq & ^mPrereq
			if mBestNoIn == uint64(0) {
				seenZero = 1
				seenZeroNoIN = 1
			}
		}

		for rc == SQLITE_OK {
			var i int32
			var mNext Bitmask = libc.Uint64(libc.Uint64FromInt32(-1))

			for i = 0; i < nConstraint; i++ {
				var mThis Bitmask = (*WhereTerm)(unsafe.Pointer((*WhereClause)(unsafe.Pointer(pWC)).Fa+uintptr((*sqlite3_index_constraint)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(p)).FaConstraint+uintptr(i)*12)).FiTermOffset)*56)).FprereqRight & ^mPrereq
				if mThis > mPrev && mThis < mNext {
					mNext = mThis
				}
			}
			mPrev = mNext
			if mNext == libc.Uint64(libc.Uint64FromInt32(-1)) {
				break
			}
			if mNext == mBest || mNext == mBestNoIn {
				continue
			}

			rc = whereLoopAddVirtualOne(tls,
				pBuilder, mPrereq, mNext|mPrereq, uint16(0), p, *(*U16)(unsafe.Pointer(bp)), bp+4, uintptr(0))
			if (*WhereLoop)(unsafe.Pointer(pNew)).Fprereq == mPrereq {
				seenZero = 1
				if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
					seenZeroNoIN = 1
				}
			}
		}

		if rc == SQLITE_OK && seenZero == 0 {
			rc = whereLoopAddVirtualOne(tls,
				pBuilder, mPrereq, mPrereq, uint16(0), p, *(*U16)(unsafe.Pointer(bp)), bp+4, uintptr(0))
			if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
				seenZeroNoIN = 1
			}
		}

		if rc == SQLITE_OK && seenZeroNoIN == 0 {
			rc = whereLoopAddVirtualOne(tls,
				pBuilder, mPrereq, mPrereq, uint16(WO_IN), p, *(*U16)(unsafe.Pointer(bp)), bp+4, uintptr(0))
		}
	}

	if (*Sqlite3_index_info)(unsafe.Pointer(p)).FneedToFreeIdxStr != 0 {
		Xsqlite3_free(tls, (*Sqlite3_index_info)(unsafe.Pointer(p)).FidxStr)
	}
	freeIndexInfo(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, p)

	return rc
}

func whereLoopAddOr(tls *libc.TLS, pBuilder uintptr, mPrereq Bitmask, mUnusable Bitmask) int32 {
	bp := tls.Alloc(712)
	defer tls.Free(712)

	var pWInfo uintptr = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	var pWC uintptr
	var pNew uintptr
	var pTerm uintptr
	var pWCEnd uintptr
	var rc int32 = SQLITE_OK
	var iCur int32

	var pItem uintptr

	pWC = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC
	pWCEnd = (*WhereClause)(unsafe.Pointer(pWC)).Fa + uintptr((*WhereClause)(unsafe.Pointer(pWC)).FnTerm)*56
	pNew = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(WhereOrSet{})))
	pItem = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLoop)(unsafe.Pointer(pNew)).FiTab)*104
	iCur = (*SrcItem)(unsafe.Pointer(pItem)).FiCursor

	if int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&JT_RIGHT != 0 {
		return SQLITE_OK
	}

	for pTerm = (*WhereClause)(unsafe.Pointer(pWC)).Fa; pTerm < pWCEnd && rc == SQLITE_OK; pTerm += 56 {
		if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&WO_OR != 0 &&
			(*WhereOrInfo)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pTerm + 32)))).Findexable&(*WhereLoop)(unsafe.Pointer(pNew)).FmaskSelf != uint64(0) {
			var pOrWC uintptr = *(*uintptr)(unsafe.Pointer(pTerm + 32))
			var pOrWCEnd uintptr = (*WhereClause)(unsafe.Pointer(pOrWC)).Fa + uintptr((*WhereClause)(unsafe.Pointer(pOrWC)).FnTerm)*56
			var pOrTerm uintptr
			var once int32 = 1
			var i int32
			var j int32

			*(*WhereLoopBuilder)(unsafe.Pointer(bp + 600)) = *(*WhereLoopBuilder)(unsafe.Pointer(pBuilder))
			(*WhereLoopBuilder)(unsafe.Pointer(bp + 600)).FpOrSet = bp + 56

			for pOrTerm = (*WhereClause)(unsafe.Pointer(pOrWC)).Fa; pOrTerm < pOrWCEnd; pOrTerm += 56 {
				if int32((*WhereTerm)(unsafe.Pointer(pOrTerm)).FeOperator)&WO_AND != 0 {
					(*WhereLoopBuilder)(unsafe.Pointer(bp + 600)).FpWC = *(*uintptr)(unsafe.Pointer(pOrTerm + 32))
				} else if (*WhereTerm)(unsafe.Pointer(pOrTerm)).FleftCursor == iCur {
					(*WhereClause)(unsafe.Pointer(bp + 112)).FpWInfo = (*WhereClause)(unsafe.Pointer(pWC)).FpWInfo
					(*WhereClause)(unsafe.Pointer(bp + 112)).FpOuter = pWC
					(*WhereClause)(unsafe.Pointer(bp + 112)).Fop = U8(TK_AND)
					(*WhereClause)(unsafe.Pointer(bp + 112)).FnTerm = 1
					(*WhereClause)(unsafe.Pointer(bp + 112)).FnBase = 1
					(*WhereClause)(unsafe.Pointer(bp + 112)).Fa = pOrTerm
					(*WhereLoopBuilder)(unsafe.Pointer(bp + 600)).FpWC = bp + 112
				} else {
					continue
				}
				(*WhereOrSet)(unsafe.Pointer(bp + 56)).Fn = U16(0)
				if int32((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpTab)).FeTabType) == TABTYP_VTAB {
					rc = whereLoopAddVirtual(tls, bp+600, mPrereq, mUnusable)
				} else {
					rc = whereLoopAddBtree(tls, bp+600, mPrereq)
				}
				if rc == SQLITE_OK {
					rc = whereLoopAddOr(tls, bp+600, mPrereq, mUnusable)
				}

				if int32((*WhereOrSet)(unsafe.Pointer(bp+56)).Fn) == 0 {
					(*WhereOrSet)(unsafe.Pointer(bp)).Fn = U16(0)
					break
				} else if once != 0 {
					whereOrMove(tls, bp, bp+56)
					once = 0
				} else {
					whereOrMove(tls, bp+656, bp)
					(*WhereOrSet)(unsafe.Pointer(bp)).Fn = U16(0)
					for i = 0; i < int32((*WhereOrSet)(unsafe.Pointer(bp+656)).Fn); i++ {
						for j = 0; j < int32((*WhereOrSet)(unsafe.Pointer(bp+56)).Fn); j++ {
							whereOrInsert(tls, bp, (*WhereOrCost)(unsafe.Pointer(bp+656+8+uintptr(i)*16)).Fprereq|(*WhereOrCost)(unsafe.Pointer(bp+56+8+uintptr(j)*16)).Fprereq,
								Xsqlite3LogEstAdd(tls, (*WhereOrCost)(unsafe.Pointer(bp+656+8+uintptr(i)*16)).FrRun, (*WhereOrCost)(unsafe.Pointer(bp+56+8+uintptr(j)*16)).FrRun),
								Xsqlite3LogEstAdd(tls, (*WhereOrCost)(unsafe.Pointer(bp+656+8+uintptr(i)*16)).FnOut, (*WhereOrCost)(unsafe.Pointer(bp+56+8+uintptr(j)*16)).FnOut))
						}
					}
				}
			}
			(*WhereLoop)(unsafe.Pointer(pNew)).FnLTerm = U16(1)
			*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pNew)).FaLTerm)) = pTerm
			(*WhereLoop)(unsafe.Pointer(pNew)).FwsFlags = U32(WHERE_MULTI_OR)
			(*WhereLoop)(unsafe.Pointer(pNew)).FrSetup = int16(0)
			(*WhereLoop)(unsafe.Pointer(pNew)).FiSortIdx = U8(0)
			libc.Xmemset(tls, pNew+24, 0, uint64(unsafe.Sizeof(struct {
				Fbtree struct {
					FnEq          U16
					FnBtm         U16
					FnTop         U16
					FnDistinctCol U16
					FpIndex       uintptr
				}
				F__ccgo_pad1 [16]byte
			}{})))
			for i = 0; rc == SQLITE_OK && i < int32((*WhereOrSet)(unsafe.Pointer(bp)).Fn); i++ {
				(*WhereLoop)(unsafe.Pointer(pNew)).FrRun = LogEst(int32((*WhereOrCost)(unsafe.Pointer(bp+8+uintptr(i)*16)).FrRun) + 1)
				(*WhereLoop)(unsafe.Pointer(pNew)).FnOut = (*WhereOrCost)(unsafe.Pointer(bp + 8 + uintptr(i)*16)).FnOut
				(*WhereLoop)(unsafe.Pointer(pNew)).Fprereq = (*WhereOrCost)(unsafe.Pointer(bp + 8 + uintptr(i)*16)).Fprereq
				rc = whereLoopInsert(tls, pBuilder, pNew)
			}

		}
	}
	return rc
}

func whereLoopAddAll(tls *libc.TLS, pBuilder uintptr) int32 {
	var pWInfo uintptr = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	var mPrereq Bitmask = uint64(0)
	var mPrior Bitmask = uint64(0)
	var iTab int32
	var pTabList uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
	var pItem uintptr
	var pEnd uintptr = pTabList + 8 + uintptr((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)*104
	var db uintptr = (*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb
	var rc int32 = SQLITE_OK
	var bFirstPastRJ int32 = 0
	var hasRightJoin int32 = 0
	var pNew uintptr

	pNew = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew

	(*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit = uint32(SQLITE_QUERY_PLANNER_LIMIT)
	iTab = 0
	pItem = pTabList + 8
__1:
	if !(pItem < pEnd) {
		goto __3
	}
	{
		var mUnusable Bitmask = uint64(0)
		(*WhereLoop)(unsafe.Pointer(pNew)).FiTab = U8(iTab)
		*(*uint32)(unsafe.Pointer(pBuilder + 48)) += uint32(SQLITE_QUERY_PLANNER_LIMIT_INCR)
		(*WhereLoop)(unsafe.Pointer(pNew)).FmaskSelf = Xsqlite3WhereGetMask(tls, pWInfo+592, (*SrcItem)(unsafe.Pointer(pItem)).FiCursor)
		if bFirstPastRJ != 0 ||
			int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(JT_OUTER|JT_CROSS|JT_LTORJ) != 0 {
			if int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&JT_LTORJ != 0 {
				hasRightJoin = 1
			}
			mPrereq = mPrereq | mPrior
			bFirstPastRJ = libc.Bool32(int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&JT_RIGHT != 0)
		} else if !(hasRightJoin != 0) {
			mPrereq = uint64(0)
		}
		if int32((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pItem)).FpTab)).FeTabType) == TABTYP_VTAB {
			var p uintptr
			for p = pItem + 1*104; p < pEnd; p += 104 {
				if mUnusable != 0 || int32((*SrcItem)(unsafe.Pointer(p)).Ffg.Fjointype)&(JT_OUTER|JT_CROSS) != 0 {
					mUnusable = mUnusable | Xsqlite3WhereGetMask(tls, pWInfo+592, (*SrcItem)(unsafe.Pointer(p)).FiCursor)
				}
			}
			rc = whereLoopAddVirtual(tls, pBuilder, mPrereq, mUnusable)
		} else {
			rc = whereLoopAddBtree(tls, pBuilder, mPrereq)
		}
		if rc == SQLITE_OK && (*WhereClause)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWC)).FhasOr != 0 {
			rc = whereLoopAddOr(tls, pBuilder, mPrereq, mUnusable)
		}
		mPrior = mPrior | (*WhereLoop)(unsafe.Pointer(pNew)).FmaskSelf
		if rc != 0 || (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			if rc == SQLITE_DONE {
				Xsqlite3_log(tls, SQLITE_WARNING, ts+26505, 0)
				rc = SQLITE_OK
			} else {
				goto __3
			}
		}

	}
	goto __2
__2:
	iTab++
	pItem += 104
	goto __1
	goto __3
__3:
	;
	whereLoopClear(tls, db, pNew)
	return rc
}

func wherePathSatisfiesOrderBy(tls *libc.TLS, pWInfo uintptr, pOrderBy uintptr, pPath uintptr, wctrlFlags U16, nLoop U16, pLast uintptr, pRevMask uintptr) I8 {
	var revSet U8
	var rev U8
	var revIdx U8
	var isOrderDistinct U8
	var distinctColumns U8
	var isMatch U8
	var eqOpMask U16
	var nKeyCol U16
	var nColumn U16
	var nOrderBy U16
	var iLoop int32
	var i int32
	var j int32
	var iCur int32
	var iColumn int32
	var pLoop uintptr = uintptr(0)
	var pTerm uintptr
	var pOBExpr uintptr
	var pColl uintptr
	var pIndex uintptr
	var db uintptr = (*Parse)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb
	var obSat Bitmask = uint64(0)
	var obDone Bitmask
	var orderDistinctMask Bitmask
	var ready Bitmask

	if nLoop != 0 && (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_OrderByIdxJoin) != U32(0) {
		return int8(0)
	}

	nOrderBy = U16((*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr)

	if int32(nOrderBy) > int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))-1 {
		return int8(0)
	}
	isOrderDistinct = U8(1)
	obDone = uint64(1)<<int32(nOrderBy) - uint64(1)
	orderDistinctMask = uint64(0)
	ready = uint64(0)
	eqOpMask = U16(WO_EQ | WO_IS | WO_ISNULL)
	if int32(wctrlFlags)&(WHERE_ORDERBY_LIMIT|WHERE_ORDERBY_MAX|WHERE_ORDERBY_MIN) != 0 {
		eqOpMask = U16(int32(eqOpMask) | WO_IN)
	}
	for iLoop = 0; isOrderDistinct != 0 && obSat < obDone && iLoop <= int32(nLoop); iLoop++ {
		if iLoop > 0 {
			ready = ready | (*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
		}
		if iLoop < int32(nLoop) {
			pLoop = *(*uintptr)(unsafe.Pointer((*WherePath)(unsafe.Pointer(pPath)).FaLoop + uintptr(iLoop)*8))
			if int32(wctrlFlags)&WHERE_ORDERBY_LIMIT != 0 {
				continue
			}
		} else {
			pLoop = pLast
		}
		if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_VIRTUALTABLE) != 0 {
			if *(*I8)(unsafe.Pointer(pLoop + 24 + 6)) != 0 &&
				int32(wctrlFlags)&(WHERE_DISTINCTBY|WHERE_SORTBYGROUP) != WHERE_DISTINCTBY {
				obSat = obDone
			}
			break
		} else if int32(wctrlFlags)&WHERE_DISTINCTBY != 0 {
			*(*U16)(unsafe.Pointer(pLoop + 24 + 6)) = U16(0)
		}
		iCur = (*SrcItem)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLoop)(unsafe.Pointer(pLoop)).FiTab)*104)).FiCursor

		for i = 0; i < int32(nOrderBy); i++ {
			if uint64(1)<<i&obSat != 0 {
				continue
			}
			pOBExpr = Xsqlite3ExprSkipCollateAndLikely(tls, (*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).FpExpr)
			if pOBExpr == uintptr(0) {
				continue
			}
			if int32((*Expr)(unsafe.Pointer(pOBExpr)).Fop) != TK_COLUMN && int32((*Expr)(unsafe.Pointer(pOBExpr)).Fop) != TK_AGG_COLUMN {
				continue
			}
			if (*Expr)(unsafe.Pointer(pOBExpr)).FiTable != iCur {
				continue
			}
			pTerm = Xsqlite3WhereFindTerm(tls, pWInfo+104, iCur, int32((*Expr)(unsafe.Pointer(pOBExpr)).FiColumn),
				^ready, uint32(eqOpMask), uintptr(0))
			if pTerm == uintptr(0) {
				continue
			}
			if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator) == WO_IN {
				for j = 0; j < int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm) && pTerm != *(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8)); j++ {
				}
				if j >= int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm) {
					continue
				}
			}
			if int32((*WhereTerm)(unsafe.Pointer(pTerm)).FeOperator)&(WO_EQ|WO_IS) != 0 && int32((*Expr)(unsafe.Pointer(pOBExpr)).FiColumn) >= 0 {
				var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
				var pColl1 uintptr = Xsqlite3ExprNNCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).FpExpr)
				var pColl2 uintptr = Xsqlite3ExprCompareCollSeq(tls, pParse, (*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)

				if pColl2 == uintptr(0) || Xsqlite3StrICmp(tls, (*CollSeq)(unsafe.Pointer(pColl1)).FzName, (*CollSeq)(unsafe.Pointer(pColl2)).FzName) != 0 {
					continue
				}

			}
			obSat = obSat | uint64(1)<<i
		}

		if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_ONEROW) == U32(0) {
			if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IPK) != 0 {
				pIndex = uintptr(0)
				nKeyCol = U16(0)
				nColumn = U16(1)
			} else if libc.AssignUintptr(&pIndex, *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))) == uintptr(0) || uint32(int32(*(*uint16)(unsafe.Pointer(pIndex + 100))&0x4>>2)) != 0 {
				return int8(0)
			} else {
				nKeyCol = (*Index)(unsafe.Pointer(pIndex)).FnKeyCol
				nColumn = (*Index)(unsafe.Pointer(pIndex)).FnColumn

				isOrderDistinct = U8(libc.Bool32(int32((*Index)(unsafe.Pointer(pIndex)).FonError) != OE_None &&
					(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_SKIPSCAN) == U32(0)))
			}

			rev = libc.AssignUint8(&revSet, U8(0))
			distinctColumns = U8(0)
			for j = 0; j < int32(nColumn); j++ {
				var bOnce U8 = U8(1)

				if j < int32(*(*U16)(unsafe.Pointer(pLoop + 24))) && j >= int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnSkip) {
					var eOp U16 = (*WhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8)))).FeOperator

					if int32(eOp)&int32(eqOpMask) != 0 {
						if int32(eOp)&(WO_ISNULL|WO_IS) != 0 {
							isOrderDistinct = U8(0)
						}
						continue
					} else if int32(eOp)&WO_IN != 0 {
						var pX uintptr = (*WhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8)))).FpExpr
						for i = j + 1; i < int32(*(*U16)(unsafe.Pointer(pLoop + 24))); i++ {
							if (*WhereTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(i)*8)))).FpExpr == pX {
								bOnce = U8(0)
								break
							}
						}
					}
				}

				if pIndex != 0 {
					iColumn = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaiColumn + uintptr(j)*2)))
					revIdx = U8(int32(*(*U8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaSortOrder + uintptr(j)))) & KEYINFO_ORDER_DESC)
					if iColumn == int32((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FpTable)).FiPKey) {
						iColumn = -1
					}
				} else {
					iColumn = -1
					revIdx = U8(0)
				}

				if isOrderDistinct != 0 {
					if iColumn >= 0 &&
						j >= int32(*(*U16)(unsafe.Pointer(pLoop + 24))) &&
						int32(*(*uint8)(unsafe.Pointer((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FpTable)).FaCol + uintptr(iColumn)*24 + 8))&0xf>>0) == 0 {
						isOrderDistinct = U8(0)
					}
					if iColumn == -2 {
						isOrderDistinct = U8(0)
					}
				}

				isMatch = U8(0)
				for i = 0; bOnce != 0 && i < int32(nOrderBy); i++ {
					if uint64(1)<<i&obSat != 0 {
						continue
					}
					pOBExpr = Xsqlite3ExprSkipCollateAndLikely(tls, (*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).FpExpr)

					if pOBExpr == uintptr(0) {
						continue
					}
					if int32(wctrlFlags)&(WHERE_GROUPBY|WHERE_DISTINCTBY) == 0 {
						bOnce = U8(0)
					}
					if iColumn >= -1 {
						if int32((*Expr)(unsafe.Pointer(pOBExpr)).Fop) != TK_COLUMN && int32((*Expr)(unsafe.Pointer(pOBExpr)).Fop) != TK_AGG_COLUMN {
							continue
						}
						if (*Expr)(unsafe.Pointer(pOBExpr)).FiTable != iCur {
							continue
						}
						if int32((*Expr)(unsafe.Pointer(pOBExpr)).FiColumn) != iColumn {
							continue
						}
					} else {
						var pIxExpr uintptr = (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FaColExpr + 8 + uintptr(j)*32)).FpExpr
						if Xsqlite3ExprCompareSkip(tls, pOBExpr, pIxExpr, iCur) != 0 {
							continue
						}
					}
					if iColumn != -1 {
						pColl = Xsqlite3ExprNNCollSeq(tls, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse, (*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).FpExpr)
						if Xsqlite3StrICmp(tls, (*CollSeq)(unsafe.Pointer(pColl)).FzName, *(*uintptr)(unsafe.Pointer((*Index)(unsafe.Pointer(pIndex)).FazColl + uintptr(j)*8))) != 0 {
							continue
						}
					}
					if int32(wctrlFlags)&WHERE_DISTINCTBY != 0 {
						*(*U16)(unsafe.Pointer(pLoop + 24 + 6)) = U16(j + 1)
					}
					isMatch = U8(1)
					break
				}
				if isMatch != 0 && int32(wctrlFlags)&WHERE_GROUPBY == 0 {
					if revSet != 0 {
						if int32(rev)^int32(revIdx) !=
							int32((*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).Ffg.FsortFlags)&KEYINFO_ORDER_DESC {
							isMatch = U8(0)
						}
					} else {
						rev = U8(int32(revIdx) ^ int32((*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).Ffg.FsortFlags)&KEYINFO_ORDER_DESC)
						if rev != 0 {
							*(*Bitmask)(unsafe.Pointer(pRevMask)) |= uint64(1) << iLoop
						}
						revSet = U8(1)
					}
				}
				if isMatch != 0 && int32((*ExprList_item)(unsafe.Pointer(pOrderBy+8+uintptr(i)*32)).Ffg.FsortFlags)&KEYINFO_ORDER_BIGNULL != 0 {
					if j == int32(*(*U16)(unsafe.Pointer(pLoop + 24))) {
						*(*U32)(unsafe.Pointer(pLoop + 56)) |= U32(WHERE_BIGNULL_SORT)
					} else {
						isMatch = U8(0)
					}
				}
				if isMatch != 0 {
					if iColumn == -1 {
						distinctColumns = U8(1)
					}
					obSat = obSat | uint64(1)<<i
				} else {
					if j == 0 || j < int32(nKeyCol) {
						isOrderDistinct = U8(0)
					}
					break
				}
			}
			if distinctColumns != 0 {
				isOrderDistinct = U8(1)
			}
		}

		if isOrderDistinct != 0 {
			orderDistinctMask = orderDistinctMask | (*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
			for i = 0; i < int32(nOrderBy); i++ {
				var p uintptr
				var mTerm Bitmask
				if uint64(1)<<i&obSat != 0 {
					continue
				}
				p = (*ExprList_item)(unsafe.Pointer(pOrderBy + 8 + uintptr(i)*32)).FpExpr
				mTerm = Xsqlite3WhereExprUsage(tls, pWInfo+592, p)
				if mTerm == uint64(0) && !(Xsqlite3ExprIsConstant(tls, p) != 0) {
					continue
				}
				if mTerm & ^orderDistinctMask == uint64(0) {
					obSat = obSat | uint64(1)<<i
				}
			}
		}
	}
	if obSat == obDone {
		return I8(nOrderBy)
	}
	if !(isOrderDistinct != 0) {
		for i = int32(nOrderBy) - 1; i > 0; i-- {
			var m Bitmask
			if i < int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) {
				m = uint64(1)<<i - uint64(1)
			} else {
				m = uint64(0)
			}
			if obSat&m == m {
				return I8(i)
			}
		}
		return int8(0)
	}
	return int8(-1)
}

func Xsqlite3WhereIsSorted(tls *libc.TLS, pWInfo uintptr) int32 {
	return int32(*(*uint8)(unsafe.Pointer(pWInfo + 68)) & 0x8 >> 3)
}

func whereSortingCost(tls *libc.TLS, pWInfo uintptr, nRow LogEst, nOrderBy int32, nSorted int32) LogEst {
	var rSortCost LogEst
	var nCol LogEst

	nCol = Xsqlite3LogEst(tls, uint64(((*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FpEList)).FnExpr+59)/30))
	rSortCost = LogEst(int32(nRow) + int32(nCol))
	if nSorted > 0 {
		rSortCost = LogEst(int32(rSortCost) + (int32(Xsqlite3LogEst(tls, uint64((nOrderBy-nSorted)*100/nOrderBy))) - 66))
	}

	if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_USE_LIMIT != 0 {
		rSortCost = int16(int32(rSortCost) + 10)
		if nSorted != 0 {
			rSortCost = int16(int32(rSortCost) + 6)
		}
		if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FiLimit) < int32(nRow) {
			nRow = (*WhereInfo)(unsafe.Pointer(pWInfo)).FiLimit
		}
	} else if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_WANT_DISTINCT != 0 {
		if int32(nRow) > 10 {
			nRow = int16(int32(nRow) - 10)
		}
	}
	rSortCost = LogEst(int32(rSortCost) + int32(estLog(tls, nRow)))
	return rSortCost
}

func wherePathSolver(tls *libc.TLS, pWInfo uintptr, nRowEst LogEst) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var mxChoice int32
	var nLoop int32
	var pParse uintptr
	var iLoop int32
	var ii int32
	var jj int32
	var mxI int32 = 0
	var nOrderBy int32
	var mxCost LogEst = int16(0)
	var mxUnsorted LogEst = int16(0)
	var nTo int32
	var nFrom int32
	var aFrom uintptr
	var aTo uintptr
	var pFrom uintptr
	var pTo uintptr
	var pWLoop uintptr
	var pX uintptr
	var aSortCost uintptr = uintptr(0)
	var pSpace uintptr
	var nSpace int32

	pParse = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	nLoop = int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)

	if nLoop <= 1 {
		mxChoice = 1
	} else {
		mxChoice = func() int32 {
			if nLoop == 2 {
				return 5
			}
			return 10
		}()
	}

	if (*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy == uintptr(0) || int32(nRowEst) == 0 {
		nOrderBy = 0
	} else {
		nOrderBy = (*ExprList)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr
	}

	nSpace = int32((uint64(unsafe.Sizeof(WherePath{})) + uint64(unsafe.Sizeof(uintptr(0)))*uint64(nLoop)) * uint64(mxChoice) * uint64(2))
	nSpace = int32(uint64(nSpace) + uint64(unsafe.Sizeof(LogEst(0)))*uint64(nOrderBy))
	pSpace = Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(nSpace))
	if pSpace == uintptr(0) {
		return SQLITE_NOMEM
	}
	aTo = pSpace
	aFrom = aTo + uintptr(mxChoice)*32
	libc.Xmemset(tls, aFrom, 0, uint64(unsafe.Sizeof(WherePath{})))
	pX = aFrom + uintptr(mxChoice)*32
	ii = mxChoice * 2
	pFrom = aTo
__1:
	if !(ii > 0) {
		goto __3
	}
	{
		(*WherePath)(unsafe.Pointer(pFrom)).FaLoop = pX

	}
	goto __2
__2:
	ii--
	pFrom += 32
	pX += 8 * uintptr(nLoop)
	goto __1
	goto __3
__3:
	;
	if nOrderBy != 0 {
		aSortCost = pX
		libc.Xmemset(tls, aSortCost, 0, uint64(unsafe.Sizeof(LogEst(0)))*uint64(nOrderBy))
	}

	(*WherePath)(unsafe.Pointer(aFrom)).FnRow = func() int16 {
		if (*Parse)(unsafe.Pointer(pParse)).FnQueryLoop < U32(48) {
			return int16((*Parse)(unsafe.Pointer(pParse)).FnQueryLoop)
		}
		return int16(48)
	}()
	nFrom = 1

	if nOrderBy != 0 {
		(*WherePath)(unsafe.Pointer(aFrom)).FisOrdered = func() int8 {
			if nLoop > 0 {
				return int8(-1)
			}
			return int8(nOrderBy)
		}()
	}

	for iLoop = 0; iLoop < nLoop; iLoop++ {
		nTo = 0
		ii = 0
		pFrom = aFrom
	__4:
		if !(ii < nFrom) {
			goto __6
		}
		{
			for pWLoop = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpLoops; pWLoop != 0; pWLoop = (*WhereLoop)(unsafe.Pointer(pWLoop)).FpNextLoop {
				var nOut LogEst
				var rCost LogEst
				var rUnsorted LogEst
				var isOrdered I8
				var maskNew Bitmask

				if (*WhereLoop)(unsafe.Pointer(pWLoop)).Fprereq & ^(*WherePath)(unsafe.Pointer(pFrom)).FmaskLoop != uint64(0) {
					continue
				}
				if (*WhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf&(*WherePath)(unsafe.Pointer(pFrom)).FmaskLoop != uint64(0) {
					continue
				}
				if (*WhereLoop)(unsafe.Pointer(pWLoop)).FwsFlags&U32(WHERE_AUTO_INDEX) != U32(0) && int32((*WherePath)(unsafe.Pointer(pFrom)).FnRow) < 3 {
					continue
				}

				rUnsorted = Xsqlite3LogEstAdd(tls, (*WhereLoop)(unsafe.Pointer(pWLoop)).FrSetup, int16(int32((*WhereLoop)(unsafe.Pointer(pWLoop)).FrRun)+int32((*WherePath)(unsafe.Pointer(pFrom)).FnRow)))
				rUnsorted = Xsqlite3LogEstAdd(tls, rUnsorted, (*WherePath)(unsafe.Pointer(pFrom)).FrUnsorted)
				nOut = LogEst(int32((*WherePath)(unsafe.Pointer(pFrom)).FnRow) + int32((*WhereLoop)(unsafe.Pointer(pWLoop)).FnOut))
				maskNew = (*WherePath)(unsafe.Pointer(pFrom)).FmaskLoop | (*WhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf
				isOrdered = (*WherePath)(unsafe.Pointer(pFrom)).FisOrdered
				if int32(isOrdered) < 0 {
					*(*Bitmask)(unsafe.Pointer(bp)) = uint64(0)
					isOrdered = wherePathSatisfiesOrderBy(tls, pWInfo,
						(*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom, (*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags,
						uint16(iLoop), pWLoop, bp)
				} else {
					*(*Bitmask)(unsafe.Pointer(bp)) = (*WherePath)(unsafe.Pointer(pFrom)).FrevLoop
				}
				if int32(isOrdered) >= 0 && int32(isOrdered) < nOrderBy {
					if int32(*(*LogEst)(unsafe.Pointer(aSortCost + uintptr(isOrdered)*2))) == 0 {
						*(*LogEst)(unsafe.Pointer(aSortCost + uintptr(isOrdered)*2)) = whereSortingCost(tls,
							pWInfo, nRowEst, nOrderBy, int32(isOrdered))
					}

					rCost = LogEst(int32(Xsqlite3LogEstAdd(tls, rUnsorted, *(*LogEst)(unsafe.Pointer(aSortCost + uintptr(isOrdered)*2)))) + 3)

				} else {
					rCost = rUnsorted
					rUnsorted = int16(int32(rUnsorted) - 2)
				}

				if iLoop == 0 && (*WhereLoop)(unsafe.Pointer(pWLoop)).FwsFlags&U32(WHERE_VIEWSCAN) != U32(0) {
					rCost = int16(int32(rCost) + -10)
					nOut = int16(int32(nOut) + -30)
				}

				jj = 0
				pTo = aTo
			__7:
				if !(jj < nTo) {
					goto __9
				}
				{
					if (*WherePath)(unsafe.Pointer(pTo)).FmaskLoop == maskNew &&
						(int32((*WherePath)(unsafe.Pointer(pTo)).FisOrdered)^int32(isOrdered))&0x80 == 0 {
						goto __9
					}

				}
				goto __8
			__8:
				jj++
				pTo += 32
				goto __7
				goto __9
			__9:
				;
				if jj >= nTo {
					if nTo >= mxChoice &&
						(int32(rCost) > int32(mxCost) || int32(rCost) == int32(mxCost) && int32(rUnsorted) >= int32(mxUnsorted)) {
						continue
					}

					if nTo < mxChoice {
						jj = libc.PostIncInt32(&nTo, 1)
					} else {
						jj = mxI
					}
					pTo = aTo + uintptr(jj)*32
				} else {
					if int32((*WherePath)(unsafe.Pointer(pTo)).FrCost) < int32(rCost) ||
						int32((*WherePath)(unsafe.Pointer(pTo)).FrCost) == int32(rCost) &&
							(int32((*WherePath)(unsafe.Pointer(pTo)).FnRow) < int32(nOut) ||
								int32((*WherePath)(unsafe.Pointer(pTo)).FnRow) == int32(nOut) && int32((*WherePath)(unsafe.Pointer(pTo)).FrUnsorted) <= int32(rUnsorted)) {
						continue
					}

				}

				(*WherePath)(unsafe.Pointer(pTo)).FmaskLoop = (*WherePath)(unsafe.Pointer(pFrom)).FmaskLoop | (*WhereLoop)(unsafe.Pointer(pWLoop)).FmaskSelf
				(*WherePath)(unsafe.Pointer(pTo)).FrevLoop = *(*Bitmask)(unsafe.Pointer(bp))
				(*WherePath)(unsafe.Pointer(pTo)).FnRow = nOut
				(*WherePath)(unsafe.Pointer(pTo)).FrCost = rCost
				(*WherePath)(unsafe.Pointer(pTo)).FrUnsorted = rUnsorted
				(*WherePath)(unsafe.Pointer(pTo)).FisOrdered = isOrdered
				libc.Xmemcpy(tls, (*WherePath)(unsafe.Pointer(pTo)).FaLoop, (*WherePath)(unsafe.Pointer(pFrom)).FaLoop, uint64(unsafe.Sizeof(uintptr(0)))*uint64(iLoop))
				*(*uintptr)(unsafe.Pointer((*WherePath)(unsafe.Pointer(pTo)).FaLoop + uintptr(iLoop)*8)) = pWLoop
				if nTo >= mxChoice {
					mxI = 0
					mxCost = (*WherePath)(unsafe.Pointer(aTo)).FrCost
					mxUnsorted = (*WherePath)(unsafe.Pointer(aTo)).FnRow
					jj = 1
					pTo = aTo + 1*32
				__10:
					if !(jj < mxChoice) {
						goto __12
					}
					{
						if int32((*WherePath)(unsafe.Pointer(pTo)).FrCost) > int32(mxCost) ||
							int32((*WherePath)(unsafe.Pointer(pTo)).FrCost) == int32(mxCost) && int32((*WherePath)(unsafe.Pointer(pTo)).FrUnsorted) > int32(mxUnsorted) {
							mxCost = (*WherePath)(unsafe.Pointer(pTo)).FrCost
							mxUnsorted = (*WherePath)(unsafe.Pointer(pTo)).FrUnsorted
							mxI = jj
						}

					}
					goto __11
				__11:
					jj++
					pTo += 32
					goto __10
					goto __12
				__12:
				}
			}

		}
		goto __5
	__5:
		ii++
		pFrom += 32
		goto __4
		goto __6
	__6:
		;
		pFrom = aTo
		aTo = aFrom
		aFrom = pFrom
		nFrom = nTo
	}

	if nFrom == 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+26540, 0)
		Xsqlite3DbFreeNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pSpace)
		return SQLITE_ERROR
	}

	pFrom = aFrom
	for ii = 1; ii < nFrom; ii++ {
		if int32((*WherePath)(unsafe.Pointer(pFrom)).FrCost) > int32((*WherePath)(unsafe.Pointer(aFrom+uintptr(ii)*32)).FrCost) {
			pFrom = aFrom + uintptr(ii)*32
		}
	}

	for iLoop = 0; iLoop < nLoop; iLoop++ {
		var pLevel uintptr = pWInfo + 856 + uintptr(iLoop)*104
		(*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop = libc.AssignUintptr(&pWLoop, *(*uintptr)(unsafe.Pointer((*WherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(iLoop)*8)))
		(*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom = (*WhereLoop)(unsafe.Pointer(pWLoop)).FiTab
		(*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur = (*SrcItem)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104)).FiCursor
	}
	if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_WANT_DISTINCT != 0 &&
		int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_DISTINCTBY == 0 &&
		int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) == WHERE_DISTINCT_NOOP &&
		nRowEst != 0 {
		var rc int32 = int32(wherePathSatisfiesOrderBy(tls, pWInfo, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet, pFrom,
			uint16(WHERE_DISTINCTBY), uint16(nLoop-1), *(*uintptr)(unsafe.Pointer((*WherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-1)*8)), bp+8))
		if rc == (*ExprList)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet)).FnExpr {
			(*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = U8(WHERE_DISTINCT_ORDERED)
		}
	}
	libc.SetBitFieldPtr8Uint32(pWInfo+68, uint32(0), 2, 0x4)
	if (*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
		(*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = (*WherePath)(unsafe.Pointer(pFrom)).FisOrdered
		if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_DISTINCTBY != 0 {
			if int32((*WherePath)(unsafe.Pointer(pFrom)).FisOrdered) == (*ExprList)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
				(*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = U8(WHERE_DISTINCT_ORDERED)
			}
			if (*Select)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FpOrderBy != 0 &&
				int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) > (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FpOrderBy)).FnExpr {
				(*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = I8((*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpSelect)).FpOrderBy)).FnExpr)
			}
		} else {
			(*WhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = (*WherePath)(unsafe.Pointer(pFrom)).FrevLoop
			if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) <= 0 {
				(*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = int8(0)
				if nLoop > 0 {
					var wsFlags U32 = (*WhereLoop)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*WherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-1)*8)))).FwsFlags
					if wsFlags&U32(WHERE_ONEROW) == U32(0) &&
						wsFlags&U32(WHERE_IPK|WHERE_COLUMN_IN) != U32(WHERE_IPK|WHERE_COLUMN_IN) {
						*(*Bitmask)(unsafe.Pointer(bp + 16)) = uint64(0)
						var rc int32 = int32(wherePathSatisfiesOrderBy(tls, pWInfo, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy, pFrom,
							uint16(WHERE_ORDERBY_LIMIT), uint16(nLoop-1), *(*uintptr)(unsafe.Pointer((*WherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-1)*8)), bp+16))

						if rc == (*ExprList)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
							libc.SetBitFieldPtr8Uint32(pWInfo+68, uint32(1), 2, 0x4)
							(*WhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = *(*Bitmask)(unsafe.Pointer(bp + 16))
						}
					}
				}
			} else if nLoop != 0 &&
				int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == 1 &&
				int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX) != 0 {
				libc.SetBitFieldPtr8Uint32(pWInfo+68, uint32(1), 2, 0x4)
			}
		}
		if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_SORTBYGROUP != 0 &&
			int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat) == (*ExprList)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr && nLoop > 0 {
			*(*Bitmask)(unsafe.Pointer(bp + 24)) = uint64(0)
			var nOrder int32 = int32(wherePathSatisfiesOrderBy(tls, pWInfo, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy,
				pFrom, uint16(0), uint16(nLoop-1), *(*uintptr)(unsafe.Pointer((*WherePath)(unsafe.Pointer(pFrom)).FaLoop + uintptr(nLoop-1)*8)), bp+24))

			if nOrder == (*ExprList)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr {
				libc.SetBitFieldPtr8Uint32(pWInfo+68, uint32(1), 3, 0x8)
				(*WhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = *(*Bitmask)(unsafe.Pointer(bp + 24))
			}
		}
	}

	(*WhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut = (*WherePath)(unsafe.Pointer(pFrom)).FnRow

	Xsqlite3DbFreeNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pSpace)
	return SQLITE_OK
}

func whereShortCut(tls *libc.TLS, pBuilder uintptr) int32 {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	var pWInfo uintptr
	var pItem uintptr
	var pWC uintptr
	var pTerm uintptr
	var pLoop uintptr
	var iCur int32
	var j int32
	var pTab uintptr
	var pIdx uintptr

	pWInfo = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_OR_SUBCLAUSE != 0 {
		return 0
	}

	pItem = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8
	pTab = (*SrcItem)(unsafe.Pointer(pItem)).FpTab
	if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
		return 0
	}
	if uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x2>>1)) != 0 || uint32(int32(*(*uint16)(unsafe.Pointer(pItem + 60 + 4))&0x1>>0)) != 0 {
		return 0
	}
	iCur = (*SrcItem)(unsafe.Pointer(pItem)).FiCursor
	pWC = pWInfo + 104
	pLoop = (*WhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpNew
	(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = U32(0)
	(*WhereLoop)(unsafe.Pointer(pLoop)).FnSkip = U16(0)
	pTerm = whereScanInit(tls, bp, pWC, iCur, -1, uint32(WO_EQ|WO_IS), uintptr(0))
	for pTerm != 0 && (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight != 0 {
		pTerm = whereScanNext(tls, bp)
	}
	if pTerm != 0 {
		(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = U32(WHERE_COLUMN_EQ | WHERE_IPK | WHERE_ONEROW)
		*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm)) = pTerm
		(*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = U16(1)
		*(*U16)(unsafe.Pointer(pLoop + 24)) = U16(1)

		(*WhereLoop)(unsafe.Pointer(pLoop)).FrRun = int16(33)
	} else {
		for pIdx = (*Table)(unsafe.Pointer(pTab)).FpIndex; pIdx != 0; pIdx = (*Index)(unsafe.Pointer(pIdx)).FpNext {
			var opMask int32

			if !(int32((*Index)(unsafe.Pointer(pIdx)).FonError) != OE_None) ||
				(*Index)(unsafe.Pointer(pIdx)).FpPartIdxWhere != uintptr(0) ||
				int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) > int32(uint64(unsafe.Sizeof([3]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0)))) {
				continue
			}
			if uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x8>>3)) != 0 {
				opMask = WO_EQ | WO_IS
			} else {
				opMask = WO_EQ
			}
			for j = 0; j < int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol); j++ {
				pTerm = whereScanInit(tls, bp, pWC, iCur, j, uint32(opMask), pIdx)
				for pTerm != 0 && (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqRight != 0 {
					pTerm = whereScanNext(tls, bp)
				}
				if pTerm == uintptr(0) {
					break
				}

				*(*uintptr)(unsafe.Pointer((*WhereLoop)(unsafe.Pointer(pLoop)).FaLTerm + uintptr(j)*8)) = pTerm
			}
			if j != int32((*Index)(unsafe.Pointer(pIdx)).FnKeyCol) {
				continue
			}
			(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags = U32(WHERE_COLUMN_EQ | WHERE_ONEROW | WHERE_INDEXED)
			if uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x20>>5)) != 0 || (*SrcItem)(unsafe.Pointer(pItem)).FcolUsed&(*Index)(unsafe.Pointer(pIdx)).FcolNotIdxed == uint64(0) {
				*(*U32)(unsafe.Pointer(pLoop + 56)) |= U32(WHERE_IDX_ONLY)
			}
			(*WhereLoop)(unsafe.Pointer(pLoop)).FnLTerm = U16(j)
			*(*U16)(unsafe.Pointer(pLoop + 24)) = U16(j)
			*(*uintptr)(unsafe.Pointer(pLoop + 24 + 8)) = pIdx

			(*WhereLoop)(unsafe.Pointer(pLoop)).FrRun = int16(39)
			break
		}
	}
	if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags != 0 {
		(*WhereLoop)(unsafe.Pointer(pLoop)).FnOut = int16(1)
		(*WhereLevel)(unsafe.Pointer(pWInfo + 856)).FpWLoop = pLoop

		(*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf = uint64(1)
		(*WhereLevel)(unsafe.Pointer(pWInfo + 856)).FiTabCur = iCur
		(*WhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut = int16(1)
		if (*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
			(*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = I8((*ExprList)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)).FnExpr)
		}
		if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_WANT_DISTINCT != 0 {
			(*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = U8(WHERE_DISTINCT_UNIQUE)
		}
		if int32((*WhereScan)(unsafe.Pointer(bp)).FiEquiv) > 1 {
			*(*U32)(unsafe.Pointer(pLoop + 56)) |= U32(WHERE_TRANSCONS)
		}
		return 1
	}
	return 0
}

func exprNodeIsDeterministic(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_FUNCTION && libc.Bool32((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_ConstFunc) != U32(0)) == 0 {
		(*Walker)(unsafe.Pointer(pWalker)).FeCode = U16(0)
		return WRC_Abort
	}
	return WRC_Continue
}

func exprIsDeterministic(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	(*Walker)(unsafe.Pointer(bp)).FeCode = U16(1)
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{exprNodeIsDeterministic}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{Xsqlite3SelectWalkFail}))
	Xsqlite3WalkExpr(tls, bp, p)
	return int32((*Walker)(unsafe.Pointer(bp)).FeCode)
}

func whereOmitNoopJoin(tls *libc.TLS, pWInfo uintptr, notReady Bitmask) Bitmask {
	var i int32
	var tabUsed Bitmask

	tabUsed = Xsqlite3WhereExprListUsage(tls, pWInfo+592, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet)
	if (*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0 {
		tabUsed = tabUsed | Xsqlite3WhereExprListUsage(tls, pWInfo+592, (*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy)
	}
	for i = int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - 1; i >= 1; i-- {
		var pTerm uintptr
		var pEnd uintptr
		var pItem uintptr
		var pLoop uintptr
		pLoop = (*WhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(i)*104)).FpWLoop
		pItem = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLoop)(unsafe.Pointer(pLoop)).FiTab)*104
		if int32((*SrcItem)(unsafe.Pointer(pItem)).Ffg.Fjointype)&(JT_LEFT|JT_RIGHT) != JT_LEFT {
			continue
		}
		if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_WANT_DISTINCT == 0 &&
			(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_ONEROW) == U32(0) {
			continue
		}
		if tabUsed&(*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf != uint64(0) {
			continue
		}
		pEnd = (*WhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa + uintptr((*WhereInfo)(unsafe.Pointer(pWInfo)).FsWC.FnTerm)*56
		for pTerm = (*WhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa; pTerm < pEnd; pTerm += 56 {
			if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf != uint64(0) {
				if !((*Expr)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr)).Fflags&U32(EP_OuterON) != U32(0)) ||
					*(*int32)(unsafe.Pointer((*WhereTerm)(unsafe.Pointer(pTerm)).FpExpr + 52)) != (*SrcItem)(unsafe.Pointer(pItem)).FiCursor {
					break
				}
			}
		}
		if pTerm < pEnd {
			continue
		}

		notReady = notReady & ^(*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf
		for pTerm = (*WhereInfo)(unsafe.Pointer(pWInfo)).FsWC.Fa; pTerm < pEnd; pTerm += 56 {
			if (*WhereTerm)(unsafe.Pointer(pTerm)).FprereqAll&(*WhereLoop)(unsafe.Pointer(pLoop)).FmaskSelf != uint64(0) {
				*(*U16)(unsafe.Pointer(pTerm + 18)) |= U16(TERM_CODED)
			}
		}
		if i != int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-1 {
			var nByte int32 = int32(uint64(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-1-i) * uint64(unsafe.Sizeof(WhereLevel{})))
			libc.Xmemmove(tls, pWInfo+856+uintptr(i)*104, pWInfo+856+uintptr(i+1)*104, uint64(nByte))
		}
		(*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel--

	}
	return notReady
}

func whereCheckIfBloomFilterIsUseful(tls *libc.TLS, pWInfo uintptr) {
	var i int32
	var nSearch LogEst = int16(0)

	for i = 0; i < int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel); i++ {
		var pLoop uintptr = (*WhereLevel)(unsafe.Pointer(pWInfo + 856 + uintptr(i)*104)).FpWLoop
		var reqFlags uint32 = uint32(WHERE_SELFCULL | WHERE_COLUMN_EQ)
		var pItem uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList + 8 + uintptr((*WhereLoop)(unsafe.Pointer(pLoop)).FiTab)*104
		var pTab uintptr = (*SrcItem)(unsafe.Pointer(pItem)).FpTab
		if (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasStat1) == U32(0) {
			break
		}
		*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_StatsUsed)
		if i >= 1 &&
			(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&reqFlags == reqFlags &&
			(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IPK|WHERE_INDEXED) != U32(0) {
			if int32(nSearch) > int32((*Table)(unsafe.Pointer(pTab)).FnRowLogEst) {
				*(*U32)(unsafe.Pointer(pLoop + 56)) |= U32(WHERE_BLOOMFILTER)
				*(*U32)(unsafe.Pointer(pLoop + 56)) &= libc.Uint32FromInt32(libc.CplInt32(WHERE_IDX_ONLY))

			}
		}
		nSearch = LogEst(int32(nSearch) + int32((*WhereLoop)(unsafe.Pointer(pLoop)).FnOut))
	}
}

func whereIndexedExprCleanup(tls *libc.TLS, db uintptr, pObject uintptr) {
	var pParse uintptr = pObject
	for (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr != uintptr(0) {
		var p uintptr = (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr
		(*Parse)(unsafe.Pointer(pParse)).FpIdxEpr = (*IndexedExpr)(unsafe.Pointer(p)).FpIENext
		Xsqlite3ExprDelete(tls, db, (*IndexedExpr)(unsafe.Pointer(p)).FpExpr)
		Xsqlite3DbFreeNN(tls, db, p)
	}
}

func whereAddIndexedExpr(tls *libc.TLS, pParse uintptr, pIdx uintptr, iIdxCur int32, pTabItem uintptr) {
	var i int32
	var p uintptr
	var pTab uintptr

	pTab = (*Index)(unsafe.Pointer(pIdx)).FpTable
	for i = 0; i < int32((*Index)(unsafe.Pointer(pIdx)).FnColumn); i++ {
		var pExpr uintptr
		var j int32 = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2)))
		var bMaybeNullRow int32
		if j == -2 {
			pExpr = (*ExprList_item)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(i)*32)).FpExpr

			bMaybeNullRow = libc.Bool32(int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(JT_LEFT|JT_LTORJ|JT_RIGHT) != 0)
		} else if j >= 0 && int32((*Column)(unsafe.Pointer((*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)).FcolFlags)&COLFLAG_VIRTUAL != 0 {
			pExpr = Xsqlite3ColumnExpr(tls, pTab, (*Table)(unsafe.Pointer(pTab)).FaCol+uintptr(j)*24)
			bMaybeNullRow = 0
		} else {
			continue
		}
		if Xsqlite3ExprIsConstant(tls, pExpr) != 0 {
			continue
		}
		p = Xsqlite3DbMallocRaw(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(IndexedExpr{})))
		if p == uintptr(0) {
			break
		}
		(*IndexedExpr)(unsafe.Pointer(p)).FpIENext = (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr
		(*IndexedExpr)(unsafe.Pointer(p)).FpExpr = Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0)
		(*IndexedExpr)(unsafe.Pointer(p)).FiDataCur = (*SrcItem)(unsafe.Pointer(pTabItem)).FiCursor
		(*IndexedExpr)(unsafe.Pointer(p)).FiIdxCur = iIdxCur
		(*IndexedExpr)(unsafe.Pointer(p)).FiIdxCol = i
		(*IndexedExpr)(unsafe.Pointer(p)).FbMaybeNullRow = U8(bMaybeNullRow)
		if Xsqlite3IndexAffinityStr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pIdx) != 0 {
			(*IndexedExpr)(unsafe.Pointer(p)).Faff = *(*uint8)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FzColAff + uintptr(i)))
		}
		(*IndexedExpr)(unsafe.Pointer(p)).FzIdxName = (*Index)(unsafe.Pointer(pIdx)).FzName
		(*Parse)(unsafe.Pointer(pParse)).FpIdxEpr = p
		if (*IndexedExpr)(unsafe.Pointer(p)).FpIENext == uintptr(0) {
			Xsqlite3ParserAddCleanup(tls, pParse, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr)
			}{whereIndexedExprCleanup})), pParse)
		}
	}
}

func Xsqlite3WhereBegin(tls *libc.TLS, pParse uintptr, pTabList uintptr, pWhere uintptr, pOrderBy uintptr, pResultSet uintptr, pSelect uintptr, wctrlFlags U16, iAuxArg int32) uintptr {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var nByteWInfo int32
	var nTabList int32
	var pWInfo uintptr
	var v uintptr
	var notReady Bitmask

	var pMaskSet uintptr
	var pLevel uintptr
	var pLoop uintptr
	var ii int32
	var db uintptr
	var rc int32
	var bFordelete U8
	var pT uintptr
	var p uintptr
	var wsFlags int32
	var bOnerow int32
	var pVTab uintptr
	var iCur int32

	var b Bitmask
	var n int32
	var op int32
	var pJ uintptr
	var pIx uintptr
	var iIndexCur int32
	var op1 int32
	var pInfo uintptr
	var pPk uintptr
	var pRJ uintptr
	var pTab uintptr
	var iDb int32
	var pTabItem uintptr
	var iOnce int32
	var addrExplain int32
	_ = addrExplain
	var wsFlags1 int32
	var pSrc uintptr
	v = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	bFordelete = U8(0)

	db = (*Parse)(unsafe.Pointer(pParse)).Fdb
	libc.Xmemset(tls, bp+16, 0, uint64(unsafe.Sizeof(WhereLoopBuilder{})))

	if !(pOrderBy != 0 && (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr >= int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))) {
		goto __1
	}
	pOrderBy = uintptr(0)
__1:
	;
	if !((*SrcList)(unsafe.Pointer(pTabList)).FnSrc > int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))) {
		goto __2
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+26558, libc.VaList(bp, int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8))))
	return uintptr(0)
__2:
	;
	if int32(wctrlFlags)&WHERE_OR_SUBCLAUSE != 0 {
		nTabList = 1
	} else {
		nTabList = (*SrcList)(unsafe.Pointer(pTabList)).FnSrc
	}

	nByteWInfo = int32(uint64(unsafe.Sizeof(WhereInfo{})) + uint64(nTabList-1)*uint64(unsafe.Sizeof(WhereLevel{})))
	pWInfo = Xsqlite3DbMallocRawNN(tls, db, uint64(nByteWInfo)+uint64(unsafe.Sizeof(WhereLoop{})))
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __3
	}
	Xsqlite3DbFree(tls, db, pWInfo)
	pWInfo = uintptr(0)
	goto whereBeginError
__3:
	;
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse = pParse
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList = pTabList
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy = pOrderBy
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FpResultSet = pResultSet
	*(*int32)(unsafe.Pointer(pWInfo + 40)) = libc.AssignPtrInt32(pWInfo+40+1*4, -1)
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel = U8(nTabList)
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FiBreak = libc.AssignPtrInt32(pWInfo+48, Xsqlite3VdbeMakeLabel(tls, pParse))
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags = wctrlFlags
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FiLimit = LogEst(iAuxArg)
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop = int32((*Parse)(unsafe.Pointer(pParse)).FnQueryLoop)
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FpSelect = pSelect
	libc.Xmemset(tls, pWInfo+65, 0,
		uint64(uintptr(0)+104)-uint64(uintptr(0)+65))
	libc.Xmemset(tls, pWInfo+856, 0, uint64(unsafe.Sizeof(WhereLoop{}))+uint64(nTabList)*uint64(unsafe.Sizeof(WhereLevel{})))

	pMaskSet = pWInfo + 592
	(*WhereMaskSet)(unsafe.Pointer(pMaskSet)).Fn = 0
	*(*int32)(unsafe.Pointer(pMaskSet + 8)) = -99

	(*WhereLoopBuilder)(unsafe.Pointer(bp + 16)).FpWInfo = pWInfo
	(*WhereLoopBuilder)(unsafe.Pointer(bp + 16)).FpWC = pWInfo + 104
	(*WhereLoopBuilder)(unsafe.Pointer(bp + 16)).FpNew = pWInfo + uintptr(nByteWInfo)

	whereLoopInit(tls, (*WhereLoopBuilder)(unsafe.Pointer(bp+16)).FpNew)

	Xsqlite3WhereClauseInit(tls, pWInfo+104, pWInfo)
	Xsqlite3WhereSplit(tls, pWInfo+104, pWhere, uint8(TK_AND))

	if !(nTabList == 0) {
		goto __4
	}
	if !(pOrderBy != 0) {
		goto __6
	}
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = I8((*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr)
__6:
	;
	if !(int32(wctrlFlags)&WHERE_WANT_DISTINCT != 0 &&
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_DistinctOpt) == U32(0)) {
		goto __7
	}
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = U8(WHERE_DISTINCT_UNIQUE)
__7:
	;
	Xsqlite3VdbeExplain(tls, pParse, uint8(0), ts+26586, 0)
	goto __5
__4:
	ii = 0
__8:
	createMask(tls, pMaskSet, (*SrcItem)(unsafe.Pointer(pTabList+8+uintptr(ii)*104)).FiCursor)
	Xsqlite3WhereTabFuncArgs(tls, pParse, pTabList+8+uintptr(ii)*104, pWInfo+104)
	goto __9
__9:
	if libc.PreIncInt32(&ii, 1) < (*SrcList)(unsafe.Pointer(pTabList)).FnSrc {
		goto __8
	}
	goto __10
__10:
	;
__5:
	;
	Xsqlite3WhereExprAnalyze(tls, pTabList, pWInfo+104)
	if !(pSelect != 0 && (*Select)(unsafe.Pointer(pSelect)).FpLimit != 0) {
		goto __11
	}
	Xsqlite3WhereAddLimit(tls, pWInfo+104, pSelect)
__11:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __12
	}
	goto whereBeginError
__12:
	;
	ii = 0
__13:
	if !(ii < (*WhereClause)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(bp+16)).FpWC)).FnBase) {
		goto __15
	}
	pT = (*WhereClause)(unsafe.Pointer((*WhereLoopBuilder)(unsafe.Pointer(bp+16)).FpWC)).Fa + uintptr(ii)*56
	if !(int32((*WhereTerm)(unsafe.Pointer(pT)).FwtFlags)&TERM_VIRTUAL != 0) {
		goto __16
	}
	goto __14
__16:
	;
	if !((*WhereTerm)(unsafe.Pointer(pT)).FprereqAll == uint64(0) && (nTabList == 0 || exprIsDeterministic(tls, (*WhereTerm)(unsafe.Pointer(pT)).FpExpr) != 0)) {
		goto __17
	}
	Xsqlite3ExprIfFalse(tls, pParse, (*WhereTerm)(unsafe.Pointer(pT)).FpExpr, (*WhereInfo)(unsafe.Pointer(pWInfo)).FiBreak, SQLITE_JUMPIFNULL)
	*(*U16)(unsafe.Pointer(pT + 18)) |= U16(TERM_CODED)
__17:
	;
	goto __14
__14:
	ii++
	goto __13
	goto __15
__15:
	;
	if !(int32(wctrlFlags)&WHERE_WANT_DISTINCT != 0) {
		goto __18
	}
	if !((*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_DistinctOpt) != U32(0)) {
		goto __19
	}

	wctrlFlags = libc.Uint16FromInt32(int32(wctrlFlags) & libc.CplInt32(WHERE_WANT_DISTINCT))
	*(*U16)(unsafe.Pointer(pWInfo + 60)) &= libc.Uint16FromInt32(libc.CplInt32(WHERE_WANT_DISTINCT))
	goto __20
__19:
	if !(isDistinctRedundant(tls, pParse, pTabList, pWInfo+104, pResultSet) != 0) {
		goto __21
	}

	(*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = U8(WHERE_DISTINCT_UNIQUE)
	goto __22
__21:
	if !(pOrderBy == uintptr(0)) {
		goto __23
	}

	*(*U16)(unsafe.Pointer(pWInfo + 60)) |= U16(WHERE_DISTINCTBY)
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy = pResultSet
__23:
	;
__22:
	;
__20:
	;
__18:
	;
	if !(nTabList != 1 || whereShortCut(tls, bp+16) == 0) {
		goto __24
	}
	rc = whereLoopAddAll(tls, bp+16)
	if !(rc != 0) {
		goto __25
	}
	goto whereBeginError
__25:
	;
	if !(int32((*WhereLoopBuilder)(unsafe.Pointer(bp+16)).FbldFlags2)&SQLITE_BLDF2_2NDPASS != 0) {
		goto __26
	}

__27:
	if !((*WhereInfo)(unsafe.Pointer(pWInfo)).FpLoops != 0) {
		goto __28
	}
	p = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpLoops
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FpLoops = (*WhereLoop)(unsafe.Pointer(p)).FpNextLoop
	whereLoopDelete(tls, db, p)
	goto __27
__28:
	;
	rc = whereLoopAddAll(tls, bp+16)
	if !(rc != 0) {
		goto __29
	}
	goto whereBeginError
__29:
	;
__26:
	;
	wherePathSolver(tls, pWInfo, int16(0))
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __30
	}
	goto whereBeginError
__30:
	;
	if !((*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy != 0) {
		goto __31
	}
	wherePathSolver(tls, pWInfo, int16(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut)+1))
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __32
	}
	goto whereBeginError
__32:
	;
__31:
	;
__24:
	;
	if !((*WhereInfo)(unsafe.Pointer(pWInfo)).FpOrderBy == uintptr(0) && (*Sqlite3)(unsafe.Pointer(db)).Fflags&uint64(SQLITE_ReverseOrder) != uint64(0)) {
		goto __33
	}
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FrevMask = libc.Uint64(libc.Uint64FromInt32(-1))
__33:
	;
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __34
	}
	goto whereBeginError
__34:
	;
	notReady = libc.CplUint64(uint64(0))
	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) >= 2 &&
		pResultSet != uintptr(0) &&
		0 == int32(wctrlFlags)&WHERE_AGG_DISTINCT &&
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_OmitNoopJoin) == U32(0)) {
		goto __35
	}
	notReady = whereOmitNoopJoin(tls, pWInfo, notReady)
	nTabList = int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)

__35:
	;
	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) >= 2 &&
		(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_BloomFilter) == U32(0)) {
		goto __36
	}
	whereCheckIfBloomFilterIsUseful(tls, pWInfo)
__36:
	;
	*(*U32)(unsafe.Pointer((*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse + 208)) += U32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnRowOut)

	if !(int32(wctrlFlags)&WHERE_ONEPASS_DESIRED != 0) {
		goto __37
	}
	wsFlags = int32((*WhereLoop1)(unsafe.Pointer((*WhereLevel)(unsafe.Pointer(pWInfo + 856)).FpWLoop)).FwsFlags)
	bOnerow = libc.Bool32(wsFlags&WHERE_ONEROW != 0)

	if !(bOnerow != 0 || 0 != int32(wctrlFlags)&WHERE_ONEPASS_MULTIROW &&
		!(int32((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pTabList+8)).FpTab)).FeTabType) == TABTYP_VTAB) &&
		(0 == wsFlags&WHERE_MULTI_OR || int32(wctrlFlags)&WHERE_DUPLICATES_OK != 0)) {
		goto __38
	}
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass = func() uint8 {
		if bOnerow != 0 {
			return uint8(ONEPASS_SINGLE)
		}
		return uint8(ONEPASS_MULTI)
	}()
	if !((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pTabList+8)).FpTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) && wsFlags&WHERE_IDX_ONLY != 0) {
		goto __39
	}
	if !(int32(wctrlFlags)&WHERE_ONEPASS_MULTIROW != 0) {
		goto __40
	}
	bFordelete = U8(OPFLAG_FORDELETE)
__40:
	;
	(*WhereLoop1)(unsafe.Pointer((*WhereLevel)(unsafe.Pointer(pWInfo + 856)).FpWLoop)).FwsFlags = U32(wsFlags & libc.CplInt32(WHERE_IDX_ONLY))
__39:
	;
__38:
	;
__37:
	;
	ii = 0
	pLevel = pWInfo + 856
__41:
	if !(ii < nTabList) {
		goto __43
	}

	pTabItem = pTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104
	pTab = (*SrcItem)(unsafe.Pointer(pTabItem)).FpTab
	iDb = Xsqlite3SchemaToIndex(tls, db, (*Table)(unsafe.Pointer(pTab)).FpSchema)
	pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Ephemeral) != U32(0) || int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		goto __44
	}

	goto __45
__44:
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_VIRTUALTABLE) != U32(0)) {
		goto __46
	}
	pVTab = Xsqlite3GetVTable(tls, db, pTab)
	iCur = (*SrcItem)(unsafe.Pointer(pTabItem)).FiCursor
	Xsqlite3VdbeAddOp4(tls, v, OP_VOpen, iCur, 0, 0, pVTab, -11)
	goto __47
__46:
	if !(int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB) {
		goto __48
	}

	goto __49
__48:
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IDX_ONLY) == U32(0) &&
		int32(wctrlFlags)&WHERE_OR_SUBCLAUSE == 0 ||
		int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&(JT_LTORJ|JT_RIGHT) != 0) {
		goto __50
	}
	op = OP_OpenRead
	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) != ONEPASS_OFF) {
		goto __52
	}
	op = OP_OpenWrite
	*(*int32)(unsafe.Pointer(pWInfo + 40)) = (*SrcItem)(unsafe.Pointer(pTabItem)).FiCursor
__52:
	;
	Xsqlite3OpenTable(tls, pParse, (*SrcItem)(unsafe.Pointer(pTabItem)).FiCursor, iDb, pTab, op)

	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) == ONEPASS_OFF &&
		int32((*Table)(unsafe.Pointer(pTab)).FnCol) < int32(uint64(unsafe.Sizeof(Bitmask(0)))*uint64(8)) &&
		(*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_HasGenerated|TF_WithoutRowid) == U32(0) &&
		(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_AUTO_INDEX|WHERE_BLOOMFILTER) == U32(0)) {
		goto __53
	}

	b = (*SrcItem)(unsafe.Pointer(pTabItem)).FcolUsed
	n = 0
__54:
	if !(b != 0) {
		goto __56
	}
	goto __55
__55:
	b = b >> 1
	n++
	goto __54
	goto __56
__56:
	;
	Xsqlite3VdbeChangeP4(tls, v, -1, uintptr(int64(n)), -3)

__53:
	;
	Xsqlite3VdbeChangeP5(tls, v, uint16(bFordelete))

	goto __51
__50:
	Xsqlite3TableLock(tls, pParse, iDb, (*Table)(unsafe.Pointer(pTab)).Ftnum, uint8(0), (*Table)(unsafe.Pointer(pTab)).FzName)
__51:
	;
__49:
	;
__47:
	;
__45:
	;
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_INDEXED) != 0) {
		goto __57
	}
	pIx = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))
	op1 = OP_OpenRead

	if !(!((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) && int32(*(*uint16)(unsafe.Pointer(pIx + 100))&0x3>>0) == SQLITE_IDXTYPE_PRIMARYKEY &&
		int32(wctrlFlags)&WHERE_OR_SUBCLAUSE != 0) {
		goto __58
	}

	iIndexCur = (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur
	op1 = 0
	goto __59
__58:
	if !(int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) != ONEPASS_OFF) {
		goto __60
	}
	pJ = (*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pTabItem)).FpTab)).FpIndex
	iIndexCur = iAuxArg

__62:
	if !(pJ != 0 && pJ != pIx) {
		goto __63
	}
	iIndexCur++
	pJ = (*Index)(unsafe.Pointer(pJ)).FpNext
	goto __62
__63:
	;
	op1 = OP_OpenWrite
	*(*int32)(unsafe.Pointer(pWInfo + 40 + 1*4)) = iIndexCur
	goto __61
__60:
	if !(iAuxArg != 0 && int32(wctrlFlags)&WHERE_OR_SUBCLAUSE != 0) {
		goto __64
	}
	iIndexCur = iAuxArg
	op1 = OP_ReopenIdx
	goto __65
__64:
	iIndexCur = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pIx + 100))&0x800>>11)) != 0 && (*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags&U32(SQLITE_IndexedExpr) == U32(0)) {
		goto __66
	}
	whereAddIndexedExpr(tls, pParse, pIx, iIndexCur, pTabItem)
__66:
	;
__65:
	;
__61:
	;
__59:
	;
	(*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur = iIndexCur

	if !(op1 != 0) {
		goto __67
	}
	Xsqlite3VdbeAddOp3(tls, v, op1, iIndexCur, int32((*Index)(unsafe.Pointer(pIx)).Ftnum), iDb)
	Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pIx)
	if !((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_CONSTRAINT) != U32(0) &&
		(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_COLUMN_RANGE|WHERE_SKIPSCAN) == U32(0) &&
		(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_BIGNULL_SORT) == U32(0) &&
		(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IN_SEEKSCAN) == U32(0) &&
		int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FwctrlFlags)&WHERE_ORDERBY_MIN == 0 &&
		int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) != WHERE_DISTINCT_ORDERED) {
		goto __68
	}
	Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SEEKEQ))
__68:
	;
	Xsqlite3VdbeComment(tls, v, ts+1684, libc.VaList(bp+8, (*Index)(unsafe.Pointer(pIx)).FzName))
__67:
	;
__57:
	;
	if !(iDb >= 0) {
		goto __69
	}
	Xsqlite3CodeVerifySchema(tls, pParse, iDb)
__69:
	;
	if !(int32((*SrcItem)(unsafe.Pointer(pTabItem)).Ffg.Fjointype)&JT_RIGHT != 0 &&
		libc.AssignPtrUintptr(pLevel+48, Xsqlite3WhereMalloc(tls, pWInfo, uint64(unsafe.Sizeof(WhereRightJoin{})))) != uintptr(0)) {
		goto __70
	}
	pRJ = (*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ
	(*WhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
	(*WhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Blob, 65536, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FregBloom)
	(*WhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn)

	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
		goto __71
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, 1)
	pInfo = Xsqlite3KeyInfoAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, 1, 0)
	if !(pInfo != 0) {
		goto __73
	}
	*(*uintptr)(unsafe.Pointer(pInfo + 32)) = uintptr(0)
	*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pInfo)).FaSortFlags)) = U8(0)
	Xsqlite3VdbeAppendP4(tls, v, pInfo, -8)
__73:
	;
	goto __72
__71:
	pPk = Xsqlite3PrimaryKeyIndex(tls, pTab)
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FiMatch, int32((*Index)(unsafe.Pointer(pPk)).FnKeyCol))
	Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pPk)
__72:
	;
	*(*U32)(unsafe.Pointer(pLoop + 56)) &= libc.Uint32FromInt32(libc.CplInt32(WHERE_IDX_ONLY))

	(*WhereInfo)(unsafe.Pointer(pWInfo)).FnOBSat = int8(0)
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct = U8(WHERE_DISTINCT_UNORDERED)
__70:
	;
	goto __42
__42:
	ii++
	pLevel += 104
	goto __41
	goto __43
__43:
	;
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FiTop = Xsqlite3VdbeCurrentAddr(tls, v)
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __74
	}
	goto whereBeginError
__74:
	;
	ii = 0
__75:
	if !(ii < nTabList) {
		goto __77
	}
	if !((*Parse)(unsafe.Pointer(pParse)).FnErr != 0) {
		goto __78
	}
	goto whereBeginError
__78:
	;
	pLevel = pWInfo + 856 + uintptr(ii)*104
	wsFlags1 = int32((*WhereLoop1)(unsafe.Pointer((*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop)).FwsFlags)
	pSrc = pTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x10>>4)) != 0) {
		goto __79
	}
	if !(uint32(int32(*(*uint16)(unsafe.Pointer(pSrc + 60 + 4))&0x8>>3)) != 0) {
		goto __80
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*SrcItem)(unsafe.Pointer(pSrc)).FregReturn, (*SrcItem)(unsafe.Pointer(pSrc)).FaddrFillSub)
	goto __81
__80:
	iOnce = Xsqlite3VdbeAddOp0(tls, v, OP_Once)
	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*SrcItem)(unsafe.Pointer(pSrc)).FregReturn, (*SrcItem)(unsafe.Pointer(pSrc)).FaddrFillSub)
	Xsqlite3VdbeJumpHere(tls, v, iOnce)
__81:
	;
__79:
	;
	if !(wsFlags1&(WHERE_AUTO_INDEX|WHERE_BLOOMFILTER) != 0) {
		goto __82
	}
	if !(wsFlags1&WHERE_AUTO_INDEX != 0) {
		goto __83
	}
	constructAutomaticIndex(tls, pParse, pWInfo+104,
		pTabList+8+uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104, notReady, pLevel)
	goto __84
__83:
	sqlite3ConstructBloomFilter(tls, pWInfo, ii, pLevel, notReady)
__84:
	;
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __85
	}
	goto whereBeginError
__85:
	;
__82:
	;
	addrExplain = Xsqlite3WhereExplainOneScan(tls,
		pParse, pTabList, pLevel, wctrlFlags)
	(*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBody = Xsqlite3VdbeCurrentAddr(tls, v)
	notReady = Xsqlite3WhereCodeOneLoopStart(tls, pParse, v, pWInfo, ii, pLevel, notReady)
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FiContinue = (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrCont
	if !(wsFlags1&WHERE_MULTI_OR == 0 && int32(wctrlFlags)&WHERE_OR_SUBCLAUSE == 0) {
		goto __86
	}
	_ = addrExplain
__86:
	;
	goto __76
__76:
	ii++
	goto __75
	goto __77
__77:
	;
	(*WhereInfo)(unsafe.Pointer(pWInfo)).FiEndWhere = Xsqlite3VdbeCurrentAddr(tls, v)
	return pWInfo

whereBeginError:
	if !(pWInfo != 0) {
		goto __87
	}
	(*Parse)(unsafe.Pointer(pParse)).FnQueryLoop = U32((*WhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop)
	whereInfoFree(tls, db, pWInfo)
__87:
	;
	return uintptr(0)
}

func Xsqlite3WhereEnd(tls *libc.TLS, pWInfo uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pParse uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpParse
	var v uintptr = (*Parse)(unsafe.Pointer(pParse)).FpVdbe
	var i int32
	var pLevel uintptr
	var pLoop uintptr
	var pTabList uintptr = (*WhereInfo)(unsafe.Pointer(pWInfo)).FpTabList
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var iEnd int32 = Xsqlite3VdbeCurrentAddr(tls, v)
	var nRJ int32 = 0

	for i = int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel) - 1; i >= 0; i-- {
		var addr int32
		pLevel = pWInfo + 856 + uintptr(i)*104
		if (*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			var pRJ uintptr = (*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ
			Xsqlite3VdbeResolveLabel(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
			(*WhereLevel)(unsafe.Pointer(pLevel)).FaddrCont = 0
			(*WhereRightJoin)(unsafe.Pointer(pRJ)).FendSubrtn = Xsqlite3VdbeCurrentAddr(tls, v)
			Xsqlite3VdbeAddOp3(tls, v, OP_Return, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FregReturn, (*WhereRightJoin)(unsafe.Pointer(pRJ)).FaddrSubrtn, 1)

			nRJ++
		}
		pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop
		if int32((*WhereLevel)(unsafe.Pointer(pLevel)).Fop) != OP_Noop {
			var addrSeek int32 = 0
			var pIdx uintptr
			var n int32
			if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeDistinct) == WHERE_DISTINCT_ORDERED &&
				i == int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)-1 &&
				(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_INDEXED) != U32(0) &&
				uint32(int32(*(*uint16)(unsafe.Pointer(libc.AssignUintptr(&pIdx, *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))) + 100))&0x80>>7)) != 0 &&
				libc.AssignInt32(&n, int32(*(*U16)(unsafe.Pointer(pLoop + 24 + 6)))) > 0 &&
				int32(*(*LogEst)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FaiRowLogEst + uintptr(n)*2))) >= 36 {
				var r1 int32 = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
				var j int32
				var op int32
				for j = 0; j < n; j++ {
					Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, j, r1+j)
				}
				*(*int32)(unsafe.Pointer(pParse + 56)) += n + 1
				if int32((*WhereLevel)(unsafe.Pointer(pLevel)).Fop) == OP_Prev {
					op = OP_SeekLT
				} else {
					op = OP_SeekGT
				}
				addrSeek = Xsqlite3VdbeAddOp4Int(tls, v, op, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, 0, r1, n)

				Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 1, (*WhereLevel)(unsafe.Pointer(pLevel)).Fp2)
			}

			if (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrCont != 0 {
				Xsqlite3VdbeResolveLabel(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
			}
			Xsqlite3VdbeAddOp3(tls, v, int32((*WhereLevel)(unsafe.Pointer(pLevel)).Fop), (*WhereLevel)(unsafe.Pointer(pLevel)).Fp1, (*WhereLevel)(unsafe.Pointer(pLevel)).Fp2, int32((*WhereLevel)(unsafe.Pointer(pLevel)).Fp3))
			Xsqlite3VdbeChangeP5(tls, v, uint16((*WhereLevel)(unsafe.Pointer(pLevel)).Fp5))

			if (*WhereLevel)(unsafe.Pointer(pLevel)).FregBignull != 0 {
				Xsqlite3VdbeResolveLabel(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBignull)
				Xsqlite3VdbeAddOp2(tls, v, OP_DecrJumpZero, (*WhereLevel)(unsafe.Pointer(pLevel)).FregBignull, (*WhereLevel)(unsafe.Pointer(pLevel)).Fp2-1)

			}
			if addrSeek != 0 {
				Xsqlite3VdbeJumpHere(tls, v, addrSeek)
			}
		} else if (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrCont != 0 {
			Xsqlite3VdbeResolveLabel(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrCont)
		}
		if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IN_ABLE) != U32(0) && *(*int32)(unsafe.Pointer(pLevel + 72)) > 0 {
			var pIn uintptr
			var j int32
			Xsqlite3VdbeResolveLabel(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrNxt)
			j = *(*int32)(unsafe.Pointer(pLevel + 72))
			pIn = *(*uintptr)(unsafe.Pointer(pLevel + 72 + 8)) + uintptr(j-1)*20
		__1:
			if !(j > 0) {
				goto __3
			}
			{
				Xsqlite3VdbeJumpHere(tls, v, *(*int32)(unsafe.Pointer(pIn + 4))+1)
				if int32(*(*U8)(unsafe.Pointer(pIn + 16))) != OP_Noop {
					if *(*int32)(unsafe.Pointer(pIn + 12)) != 0 {
						var bEarlyOut int32 = libc.Bool32((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_VIRTUALTABLE) == U32(0) &&
							(*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_IN_EARLYOUT) != U32(0))
						if (*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
							Xsqlite3VdbeAddOp2(tls, v, OP_IfNotOpen, *(*int32)(unsafe.Pointer(pIn)),
								Xsqlite3VdbeCurrentAddr(tls, v)+2+bEarlyOut)

						}
						if bEarlyOut != 0 {
							Xsqlite3VdbeAddOp4Int(tls, v, OP_IfNoHope, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur,
								Xsqlite3VdbeCurrentAddr(tls, v)+2,
								*(*int32)(unsafe.Pointer(pIn + 8)), *(*int32)(unsafe.Pointer(pIn + 12)))

							Xsqlite3VdbeJumpHere(tls, v, *(*int32)(unsafe.Pointer(pIn + 4))+1)
						}
					}
					Xsqlite3VdbeAddOp2(tls, v, int32(*(*U8)(unsafe.Pointer(pIn + 16))), *(*int32)(unsafe.Pointer(pIn)), *(*int32)(unsafe.Pointer(pIn + 4)))

				}
				Xsqlite3VdbeJumpHere(tls, v, *(*int32)(unsafe.Pointer(pIn + 4))-1)

			}
			goto __2
		__2:
			j--
			pIn -= 20
			goto __1
			goto __3
		__3:
		}
		Xsqlite3VdbeResolveLabel(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBrk)
		if (*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			Xsqlite3VdbeAddOp3(tls, v, OP_Return, (*WhereRightJoin)(unsafe.Pointer((*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ)).FregReturn, 0, 1)

		}
		if (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip != 0 {
			Xsqlite3VdbeGoto(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip)
			Xsqlite3VdbeComment(tls, v, ts+26604, libc.VaList(bp, (*Index)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pLoop + 24 + 8)))).FzName))
			Xsqlite3VdbeJumpHere(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip)
			Xsqlite3VdbeJumpHere(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrSkip-2)
		}
		if (*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin != 0 {
			var ws int32 = int32((*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags)
			addr = Xsqlite3VdbeAddOp1(tls, v, OP_IfPos, (*WhereLevel)(unsafe.Pointer(pLevel)).FiLeftJoin)

			if ws&WHERE_IDX_ONLY == 0 {
				Xsqlite3VdbeAddOp1(tls, v, OP_NullRow, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur)
			}
			if ws&WHERE_INDEXED != 0 ||
				ws&WHERE_MULTI_OR != 0 && *(*uintptr)(unsafe.Pointer(pLevel + 72)) != 0 {
				if ws&WHERE_MULTI_OR != 0 {
					var pIx uintptr = *(*uintptr)(unsafe.Pointer(pLevel + 72))
					var iDb int32 = Xsqlite3SchemaToIndex(tls, db, (*Index)(unsafe.Pointer(pIx)).FpSchema)
					Xsqlite3VdbeAddOp3(tls, v, OP_ReopenIdx, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur, int32((*Index)(unsafe.Pointer(pIx)).Ftnum), iDb)
					Xsqlite3VdbeSetP4KeyInfo(tls, pParse, pIx)
				}
				Xsqlite3VdbeAddOp1(tls, v, OP_NullRow, (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur)
			}
			if int32((*WhereLevel)(unsafe.Pointer(pLevel)).Fop) == OP_Return {
				Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*WhereLevel)(unsafe.Pointer(pLevel)).Fp1, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst)
			} else {
				Xsqlite3VdbeGoto(tls, v, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrFirst)
			}
			Xsqlite3VdbeJumpHere(tls, v, addr)
		}

	}

	i = 0
	pLevel = pWInfo + 856
__4:
	if !(i < int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FnLevel)) {
		goto __6
	}
	{
		var k int32
		var last int32
		var pOp uintptr
		var pLastOp uintptr
		var pIdx uintptr = uintptr(0)
		var pTabItem uintptr = pTabList + 8 + uintptr((*WhereLevel)(unsafe.Pointer(pLevel)).FiFrom)*104
		var pTab uintptr = (*SrcItem)(unsafe.Pointer(pTabItem)).FpTab

		pLoop = (*WhereLevel)(unsafe.Pointer(pLevel)).FpWLoop

		if (*WhereLevel)(unsafe.Pointer(pLevel)).FpRJ != 0 {
			Xsqlite3WhereRightJoinLoop(tls, pWInfo, i, pLevel)
			goto __5
		}

		if uint32(int32(*(*uint16)(unsafe.Pointer(pTabItem + 60 + 4))&0x20>>5)) != 0 {
			translateColumnToCopy(tls, pParse, (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBody, (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur,
				(*SrcItem)(unsafe.Pointer(pTabItem)).FregResult, 0)
			goto __5
		}

		if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_INDEXED|WHERE_IDX_ONLY) != 0 {
			pIdx = *(*uintptr)(unsafe.Pointer(pLoop + 24 + 8))
		} else if (*WhereLoop)(unsafe.Pointer(pLoop)).FwsFlags&U32(WHERE_MULTI_OR) != 0 {
			pIdx = *(*uintptr)(unsafe.Pointer(pLevel + 72))
		}
		if pIdx != 0 &&
			!(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
			if int32((*WhereInfo)(unsafe.Pointer(pWInfo)).FeOnePass) == ONEPASS_OFF || !((*Table)(unsafe.Pointer((*Index)(unsafe.Pointer(pIdx)).FpTable)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
				last = iEnd
			} else {
				last = (*WhereInfo)(unsafe.Pointer(pWInfo)).FiEndWhere
			}
			if uint32(int32(*(*uint16)(unsafe.Pointer(pIdx + 100))&0x800>>11)) != 0 {
				var p uintptr = (*Parse)(unsafe.Pointer(pParse)).FpIdxEpr
				for p != 0 {
					if (*IndexedExpr)(unsafe.Pointer(p)).FiIdxCur == (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur {
						(*IndexedExpr)(unsafe.Pointer(p)).FiDataCur = -1
						(*IndexedExpr)(unsafe.Pointer(p)).FiIdxCur = -1
					}
					p = (*IndexedExpr)(unsafe.Pointer(p)).FpIENext
				}
			}
			k = (*WhereLevel)(unsafe.Pointer(pLevel)).FaddrBody + 1
			pOp = Xsqlite3VdbeGetOp(tls, v, k)
			pLastOp = pOp + uintptr(last-k)*32

			for __ccgo := true; __ccgo; __ccgo = libc.PreIncUintptr(&pOp, 32) < pLastOp {
				if (*VdbeOp)(unsafe.Pointer(pOp)).Fp1 != (*WhereLevel)(unsafe.Pointer(pLevel)).FiTabCur {
				} else if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Column ||
					int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Offset {
					var x int32 = (*VdbeOp)(unsafe.Pointer(pOp)).Fp2

					if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Offset {
					} else if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0)) {
						var pPk uintptr = Xsqlite3PrimaryKeyIndex(tls, pTab)
						x = int32(*(*I16)(unsafe.Pointer((*Index)(unsafe.Pointer(pPk)).FaiColumn + uintptr(x)*2)))

					} else {
						x = int32(Xsqlite3StorageColumnToTable(tls, pTab, int16(x)))
					}
					x = int32(Xsqlite3TableColumnToIndex(tls, pIdx, int16(x)))
					if x >= 0 {
						(*VdbeOp)(unsafe.Pointer(pOp)).Fp2 = x
						(*VdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur

					} else {
					}
				} else if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Rowid {
					(*VdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur
					(*VdbeOp)(unsafe.Pointer(pOp)).Fopcode = U8(OP_IdxRowid)

				} else if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_IfNullRow {
					(*VdbeOp)(unsafe.Pointer(pOp)).Fp1 = (*WhereLevel)(unsafe.Pointer(pLevel)).FiIdxCur

				}
			}
		}

	}
	goto __5
__5:
	i++
	pLevel += 104
	goto __4
	goto __6
__6:
	;
	Xsqlite3VdbeResolveLabel(tls, v, (*WhereInfo)(unsafe.Pointer(pWInfo)).FiBreak)

	(*Parse)(unsafe.Pointer(pParse)).FnQueryLoop = U32((*WhereInfo)(unsafe.Pointer(pWInfo)).FsavedNQueryLoop)
	whereInfoFree(tls, db, pWInfo)
	*(*U8)(unsafe.Pointer(pParse + 38)) -= U8(nRJ)
	return
}

func row_numberStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(I64(0))))
	if p != 0 {
		*(*I64)(unsafe.Pointer(p))++
	}
	_ = nArg
	_ = apArg
}

func row_numberValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(I64(0))))
	Xsqlite3_result_int64(tls, pCtx, func() int64 {
		if p != 0 {
			return *(*I64)(unsafe.Pointer(p))
		}
		return int64(0)
	}())
}

type CallCount = struct {
	FnValue I64
	FnStep  I64
	FnTotal I64
}

func dense_rankStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	if p != 0 {
		(*CallCount)(unsafe.Pointer(p)).FnStep = int64(1)
	}
	_ = nArg
	_ = apArg
}

func dense_rankValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	if p != 0 {
		if (*CallCount)(unsafe.Pointer(p)).FnStep != 0 {
			(*CallCount)(unsafe.Pointer(p)).FnValue++
			(*CallCount)(unsafe.Pointer(p)).FnStep = int64(0)
		}
		Xsqlite3_result_int64(tls, pCtx, (*CallCount)(unsafe.Pointer(p)).FnValue)
	}
}

type NthValueCtx = struct {
	FnStep  I64
	FpValue uintptr
}

func nth_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	var fVal float64
	var iVal I64
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(NthValueCtx{})))
	if !(p != 0) {
		goto __1
	}
	switch Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*8))) {
	case SQLITE_INTEGER:
		goto __3
	case SQLITE_FLOAT:
		goto __4
	default:
		goto __5
	}
	goto __2
__3:
	iVal = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*8)))
	goto __2
__4:
	fVal = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*8)))
	if !(float64(I64(fVal)) != fVal) {
		goto __6
	}
	goto error_out
__6:
	;
	iVal = I64(fVal)
	goto __2

__5:
	goto error_out
__2:
	;
	if !(iVal <= int64(0)) {
		goto __7
	}
	goto error_out
__7:
	;
	(*NthValueCtx)(unsafe.Pointer(p)).FnStep++
	if !(iVal == (*NthValueCtx)(unsafe.Pointer(p)).FnStep) {
		goto __8
	}
	(*NthValueCtx)(unsafe.Pointer(p)).FpValue = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(apArg)))
	if !!(int32((*NthValueCtx)(unsafe.Pointer(p)).FpValue) != 0) {
		goto __9
	}
	Xsqlite3_result_error_nomem(tls, pCtx)
__9:
	;
__8:
	;
__1:
	;
	_ = nArg
	_ = apArg
	return

error_out:
	Xsqlite3_result_error(tls,
		pCtx, ts+26625, -1)
}

func nth_valueFinalizeFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, 0)
	if p != 0 && (*NthValueCtx)(unsafe.Pointer(p)).FpValue != 0 {
		Xsqlite3_result_value(tls, pCtx, (*NthValueCtx)(unsafe.Pointer(p)).FpValue)
		Xsqlite3_value_free(tls, (*NthValueCtx)(unsafe.Pointer(p)).FpValue)
		(*NthValueCtx)(unsafe.Pointer(p)).FpValue = uintptr(0)
	}
}

func first_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(NthValueCtx{})))
	if p != 0 && (*NthValueCtx)(unsafe.Pointer(p)).FpValue == uintptr(0) {
		(*NthValueCtx)(unsafe.Pointer(p)).FpValue = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(apArg)))
		if !(int32((*NthValueCtx)(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 = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(NthValueCtx{})))
	if p != 0 && (*NthValueCtx)(unsafe.Pointer(p)).FpValue != 0 {
		Xsqlite3_result_value(tls, pCtx, (*NthValueCtx)(unsafe.Pointer(p)).FpValue)
		Xsqlite3_value_free(tls, (*NthValueCtx)(unsafe.Pointer(p)).FpValue)
		(*NthValueCtx)(unsafe.Pointer(p)).FpValue = uintptr(0)
	}
}

func rankStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	if p != 0 {
		(*CallCount)(unsafe.Pointer(p)).FnStep++
		if (*CallCount)(unsafe.Pointer(p)).FnValue == int64(0) {
			(*CallCount)(unsafe.Pointer(p)).FnValue = (*CallCount)(unsafe.Pointer(p)).FnStep
		}
	}
	_ = nArg
	_ = apArg
}

func rankValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	if p != 0 {
		Xsqlite3_result_int64(tls, pCtx, (*CallCount)(unsafe.Pointer(p)).FnValue)
		(*CallCount)(unsafe.Pointer(p)).FnValue = int64(0)
	}
}

func percent_rankStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	if p != 0 {
		(*CallCount)(unsafe.Pointer(p)).FnTotal++
	}
}

func percent_rankInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	(*CallCount)(unsafe.Pointer(p)).FnStep++
}

func percent_rankValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	if p != 0 {
		(*CallCount)(unsafe.Pointer(p)).FnValue = (*CallCount)(unsafe.Pointer(p)).FnStep
		if (*CallCount)(unsafe.Pointer(p)).FnTotal > int64(1) {
			var r float64 = float64((*CallCount)(unsafe.Pointer(p)).FnValue) / float64((*CallCount)(unsafe.Pointer(p)).FnTotal-int64(1))
			Xsqlite3_result_double(tls, pCtx, r)
		} else {
			Xsqlite3_result_double(tls, pCtx, 0.0)
		}
	}
}

func cume_distStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	if p != 0 {
		(*CallCount)(unsafe.Pointer(p)).FnTotal++
	}
}

func cume_distInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(CallCount{})))
	(*CallCount)(unsafe.Pointer(p)).FnStep++
}

func cume_distValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, 0)
	if p != 0 {
		var r float64 = float64((*CallCount)(unsafe.Pointer(p)).FnStep) / float64((*CallCount)(unsafe.Pointer(p)).FnTotal)
		Xsqlite3_result_double(tls, pCtx, r)
	}
}

type NtileCtx = struct {
	FnTotal I64
	FnParam I64
	FiRow   I64
}

func ntileStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = nArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(NtileCtx{})))
	if p != 0 {
		if (*NtileCtx)(unsafe.Pointer(p)).FnTotal == int64(0) {
			(*NtileCtx)(unsafe.Pointer(p)).FnParam = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apArg)))
			if (*NtileCtx)(unsafe.Pointer(p)).FnParam <= int64(0) {
				Xsqlite3_result_error(tls,
					pCtx, ts+26681, -1)
			}
		}
		(*NtileCtx)(unsafe.Pointer(p)).FnTotal++
	}
}

func ntileInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(NtileCtx{})))
	(*NtileCtx)(unsafe.Pointer(p)).FiRow++
}

func ntileValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(NtileCtx{})))
	if p != 0 && (*NtileCtx)(unsafe.Pointer(p)).FnParam > int64(0) {
		var nSize int32 = int32((*NtileCtx)(unsafe.Pointer(p)).FnTotal / (*NtileCtx)(unsafe.Pointer(p)).FnParam)
		if nSize == 0 {
			Xsqlite3_result_int64(tls, pCtx, (*NtileCtx)(unsafe.Pointer(p)).FiRow+int64(1))
		} else {
			var nLarge I64 = (*NtileCtx)(unsafe.Pointer(p)).FnTotal - (*NtileCtx)(unsafe.Pointer(p)).FnParam*I64(nSize)
			var iSmall I64 = nLarge * I64(nSize+1)
			var iRow I64 = (*NtileCtx)(unsafe.Pointer(p)).FiRow

			if iRow < iSmall {
				Xsqlite3_result_int64(tls, pCtx, int64(1)+iRow/I64(nSize+1))
			} else {
				Xsqlite3_result_int64(tls, pCtx, int64(1)+nLarge+(iRow-iSmall)/I64(nSize))
			}
		}
	}
}

type LastValueCtx = struct {
	FpVal        uintptr
	FnVal        int32
	F__ccgo_pad1 [4]byte
}

func last_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = nArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(LastValueCtx{})))
	if p != 0 {
		Xsqlite3_value_free(tls, (*LastValueCtx)(unsafe.Pointer(p)).FpVal)
		(*LastValueCtx)(unsafe.Pointer(p)).FpVal = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(apArg)))
		if (*LastValueCtx)(unsafe.Pointer(p)).FpVal == uintptr(0) {
			Xsqlite3_result_error_nomem(tls, pCtx)
		} else {
			(*LastValueCtx)(unsafe.Pointer(p)).FnVal++
		}
	}
}

func last_valueInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(LastValueCtx{})))
	if p != 0 {
		(*LastValueCtx)(unsafe.Pointer(p)).FnVal--
		if (*LastValueCtx)(unsafe.Pointer(p)).FnVal == 0 {
			Xsqlite3_value_free(tls, (*LastValueCtx)(unsafe.Pointer(p)).FpVal)
			(*LastValueCtx)(unsafe.Pointer(p)).FpVal = uintptr(0)
		}
	}
}

func last_valueValueFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, 0)
	if p != 0 && (*LastValueCtx)(unsafe.Pointer(p)).FpVal != 0 {
		Xsqlite3_result_value(tls, pCtx, (*LastValueCtx)(unsafe.Pointer(p)).FpVal)
	}
}

func last_valueFinalizeFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(unsafe.Sizeof(LastValueCtx{})))
	if p != 0 && (*LastValueCtx)(unsafe.Pointer(p)).FpVal != 0 {
		Xsqlite3_result_value(tls, pCtx, (*LastValueCtx)(unsafe.Pointer(p)).FpVal)
		Xsqlite3_value_free(tls, (*LastValueCtx)(unsafe.Pointer(p)).FpVal)
		(*LastValueCtx)(unsafe.Pointer(p)).FpVal = uintptr(0)
	}
}

var row_numberName = *(*[11]uint8)(unsafe.Pointer(ts + 26726))
var dense_rankName = *(*[11]uint8)(unsafe.Pointer(ts + 26737))
var rankName = *(*[5]uint8)(unsafe.Pointer(ts + 26748))
var percent_rankName = *(*[13]uint8)(unsafe.Pointer(ts + 26753))
var cume_distName = *(*[10]uint8)(unsafe.Pointer(ts + 26766))
var ntileName = *(*[6]uint8)(unsafe.Pointer(ts + 26776))
var last_valueName = *(*[11]uint8)(unsafe.Pointer(ts + 26782))
var nth_valueName = *(*[10]uint8)(unsafe.Pointer(ts + 26793))
var first_valueName = *(*[12]uint8)(unsafe.Pointer(ts + 26803))
var leadName = *(*[5]uint8)(unsafe.Pointer(ts + 26815))
var lagName = *(*[4]uint8)(unsafe.Pointer(ts + 26820))

func noopStepFunc(tls *libc.TLS, p uintptr, n int32, a uintptr) {
	_ = p
	_ = n
	_ = a

}

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

func Xsqlite3WindowFunctions(tls *libc.TLS) {
	Xsqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&aWindowFuncs)), int32(uint64(unsafe.Sizeof(aWindowFuncs))/uint64(unsafe.Sizeof(FuncDef{}))))
}

var aWindowFuncs = [15]FuncDef{
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(3), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0},
	{FnArg: int8(3), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | SQLITE_FUNC_WINDOW | 0), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: 0}}

func windowFind(tls *libc.TLS, pParse uintptr, pList uintptr, zName uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p uintptr
	for p = pList; p != 0; p = (*Window)(unsafe.Pointer(p)).FpNextWin {
		if Xsqlite3StrICmp(tls, (*Window)(unsafe.Pointer(p)).FzName, zName) == 0 {
			break
		}
	}
	if p == uintptr(0) {
		Xsqlite3ErrorMsg(tls, pParse, ts+26824, libc.VaList(bp, zName))
	}
	return p
}

func Xsqlite3WindowUpdate(tls *libc.TLS, pParse uintptr, pList uintptr, pWin uintptr, pFunc uintptr) {
	bp := tls.Alloc(192)
	defer tls.Free(192)

	if (*Window)(unsafe.Pointer(pWin)).FzName != 0 && int32((*Window)(unsafe.Pointer(pWin)).FeFrmType) == 0 {
		var p uintptr = windowFind(tls, pParse, pList, (*Window)(unsafe.Pointer(pWin)).FzName)
		if p == uintptr(0) {
			return
		}
		(*Window)(unsafe.Pointer(pWin)).FpPartition = Xsqlite3ExprListDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Window)(unsafe.Pointer(p)).FpPartition, 0)
		(*Window)(unsafe.Pointer(pWin)).FpOrderBy = Xsqlite3ExprListDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Window)(unsafe.Pointer(p)).FpOrderBy, 0)
		(*Window)(unsafe.Pointer(pWin)).FpStart = Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Window)(unsafe.Pointer(p)).FpStart, 0)
		(*Window)(unsafe.Pointer(pWin)).FpEnd = Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Window)(unsafe.Pointer(p)).FpEnd, 0)
		(*Window)(unsafe.Pointer(pWin)).FeStart = (*Window)(unsafe.Pointer(p)).FeStart
		(*Window)(unsafe.Pointer(pWin)).FeEnd = (*Window)(unsafe.Pointer(p)).FeEnd
		(*Window)(unsafe.Pointer(pWin)).FeFrmType = (*Window)(unsafe.Pointer(p)).FeFrmType
		(*Window)(unsafe.Pointer(pWin)).FeExclude = (*Window)(unsafe.Pointer(p)).FeExclude
	} else {
		Xsqlite3WindowChain(tls, pParse, pWin, pList)
	}
	if int32((*Window)(unsafe.Pointer(pWin)).FeFrmType) == TK_RANGE &&
		((*Window)(unsafe.Pointer(pWin)).FpStart != 0 || (*Window)(unsafe.Pointer(pWin)).FpEnd != 0) &&
		((*Window)(unsafe.Pointer(pWin)).FpOrderBy == uintptr(0) || (*ExprList)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpOrderBy)).FnExpr != 1) {
		Xsqlite3ErrorMsg(tls, pParse,
			ts+26843, 0)
	} else if (*FuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&U32(SQLITE_FUNC_WINDOW) != 0 {
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		if (*Window)(unsafe.Pointer(pWin)).FpFilter != 0 {
			Xsqlite3ErrorMsg(tls, pParse,
				ts+26914, 0)
		} else {
			*(*[8]WindowUpdate)(unsafe.Pointer(bp)) = [8]WindowUpdate{
				{FzFunc: uintptr(unsafe.Pointer(&row_numberName)), FeFrmType: TK_ROWS, FeStart: TK_UNBOUNDED, FeEnd: TK_CURRENT},
				{FzFunc: uintptr(unsafe.Pointer(&dense_rankName)), FeFrmType: TK_RANGE, FeStart: TK_UNBOUNDED, FeEnd: TK_CURRENT},
				{FzFunc: uintptr(unsafe.Pointer(&rankName)), FeFrmType: TK_RANGE, FeStart: TK_UNBOUNDED, FeEnd: TK_CURRENT},
				{FzFunc: uintptr(unsafe.Pointer(&percent_rankName)), FeFrmType: TK_GROUPS, FeStart: TK_CURRENT, FeEnd: TK_UNBOUNDED},
				{FzFunc: uintptr(unsafe.Pointer(&cume_distName)), FeFrmType: TK_GROUPS, FeStart: TK_FOLLOWING, FeEnd: TK_UNBOUNDED},
				{FzFunc: uintptr(unsafe.Pointer(&ntileName)), FeFrmType: TK_ROWS, FeStart: TK_CURRENT, FeEnd: TK_UNBOUNDED},
				{FzFunc: uintptr(unsafe.Pointer(&leadName)), FeFrmType: TK_ROWS, FeStart: TK_UNBOUNDED, FeEnd: TK_UNBOUNDED},
				{FzFunc: uintptr(unsafe.Pointer(&lagName)), FeFrmType: TK_ROWS, FeStart: TK_UNBOUNDED, FeEnd: TK_CURRENT},
			}
			var i int32
			for i = 0; i < int32(uint64(unsafe.Sizeof([8]WindowUpdate{}))/uint64(unsafe.Sizeof(WindowUpdate{}))); i++ {
				if (*FuncDef)(unsafe.Pointer(pFunc)).FzName == (*WindowUpdate)(unsafe.Pointer(bp+uintptr(i)*24)).FzFunc {
					Xsqlite3ExprDelete(tls, db, (*Window)(unsafe.Pointer(pWin)).FpStart)
					Xsqlite3ExprDelete(tls, db, (*Window)(unsafe.Pointer(pWin)).FpEnd)
					(*Window)(unsafe.Pointer(pWin)).FpEnd = libc.AssignPtrUintptr(pWin+40, uintptr(0))
					(*Window)(unsafe.Pointer(pWin)).FeFrmType = U8((*WindowUpdate)(unsafe.Pointer(bp + uintptr(i)*24)).FeFrmType)
					(*Window)(unsafe.Pointer(pWin)).FeStart = U8((*WindowUpdate)(unsafe.Pointer(bp + uintptr(i)*24)).FeStart)
					(*Window)(unsafe.Pointer(pWin)).FeEnd = U8((*WindowUpdate)(unsafe.Pointer(bp + uintptr(i)*24)).FeEnd)
					(*Window)(unsafe.Pointer(pWin)).FeExclude = U8(0)
					if int32((*Window)(unsafe.Pointer(pWin)).FeStart) == TK_FOLLOWING {
						(*Window)(unsafe.Pointer(pWin)).FpStart = Xsqlite3Expr(tls, db, TK_INTEGER, ts+11251)
					}
					break
				}
			}
		}
	}
	(*Window)(unsafe.Pointer(pWin)).FpWFunc = pFunc
}

type WindowUpdate = struct {
	FzFunc       uintptr
	FeFrmType    int32
	FeStart      int32
	FeEnd        int32
	F__ccgo_pad1 [4]byte
}

type WindowRewrite = WindowRewrite1

func selectWindowRewriteExprCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	var p uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	var pParse uintptr = (*Walker)(unsafe.Pointer(pWalker)).FpParse

	if (*WindowRewrite1)(unsafe.Pointer(p)).FpSubSelect != 0 {
		if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) != TK_COLUMN {
			return WRC_Continue
		} else {
			var nSrc int32 = (*SrcList)(unsafe.Pointer((*WindowRewrite1)(unsafe.Pointer(p)).FpSrc)).FnSrc
			var i int32
			for i = 0; i < nSrc; i++ {
				if (*Expr)(unsafe.Pointer(pExpr)).FiTable == (*SrcItem)(unsafe.Pointer((*WindowRewrite1)(unsafe.Pointer(p)).FpSrc+8+uintptr(i)*104)).FiCursor {
					break
				}
			}
			if i == nSrc {
				return WRC_Continue
			}
		}
	}

	{
		switch int32((*Expr)(unsafe.Pointer(pExpr)).Fop) {
		case TK_FUNCTION:
			if !((*Expr)(unsafe.Pointer(pExpr)).Fflags&U32(EP_WinFunc) != U32(0)) {
				break
			} else {
				var pWin uintptr
				for pWin = (*WindowRewrite1)(unsafe.Pointer(p)).FpWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
					if *(*uintptr)(unsafe.Pointer(pExpr + 64)) == pWin {
						return WRC_Prune
					}
				}
			}
			fallthrough

		case TK_AGG_FUNCTION:
			fallthrough
		case TK_COLUMN:
			{
				var iCol int32 = -1
				if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
					return WRC_Abort
				}
				if (*WindowRewrite1)(unsafe.Pointer(p)).FpSub != 0 {
					var i int32
					for i = 0; i < (*ExprList)(unsafe.Pointer((*WindowRewrite1)(unsafe.Pointer(p)).FpSub)).FnExpr; i++ {
						if 0 == Xsqlite3ExprCompare(tls, uintptr(0), (*ExprList_item)(unsafe.Pointer((*WindowRewrite1)(unsafe.Pointer(p)).FpSub+8+uintptr(i)*32)).FpExpr, pExpr, -1) {
							iCol = i
							break
						}
					}
				}
				if iCol < 0 {
					var pDup uintptr = Xsqlite3ExprDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr, 0)
					if pDup != 0 && int32((*Expr)(unsafe.Pointer(pDup)).Fop) == TK_AGG_FUNCTION {
						(*Expr)(unsafe.Pointer(pDup)).Fop = U8(TK_FUNCTION)
					}
					(*WindowRewrite1)(unsafe.Pointer(p)).FpSub = Xsqlite3ExprListAppend(tls, pParse, (*WindowRewrite1)(unsafe.Pointer(p)).FpSub, pDup)
				}
				if (*WindowRewrite1)(unsafe.Pointer(p)).FpSub != 0 {
					var f int32 = int32((*Expr)(unsafe.Pointer(pExpr)).Fflags & U32(EP_Collate))

					*(*U32)(unsafe.Pointer(pExpr + 4)) |= U32(EP_Static)
					Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
					*(*U32)(unsafe.Pointer(pExpr + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_Static))
					libc.Xmemset(tls, pExpr, 0, uint64(unsafe.Sizeof(Expr{})))

					(*Expr)(unsafe.Pointer(pExpr)).Fop = U8(TK_COLUMN)
					(*Expr)(unsafe.Pointer(pExpr)).FiColumn = func() int16 {
						if iCol < 0 {
							return int16((*ExprList)(unsafe.Pointer((*WindowRewrite1)(unsafe.Pointer(p)).FpSub)).FnExpr - 1)
						}
						return int16(iCol)
					}()
					(*Expr)(unsafe.Pointer(pExpr)).FiTable = (*Window)(unsafe.Pointer((*WindowRewrite1)(unsafe.Pointer(p)).FpWin)).FiEphCsr
					*(*uintptr)(unsafe.Pointer(pExpr + 64)) = (*WindowRewrite1)(unsafe.Pointer(p)).FpTab
					(*Expr)(unsafe.Pointer(pExpr)).Fflags = U32(f)
				}
				if (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0 {
					return WRC_Abort
				}
				break

			}

		default:
			break
		}
	}

	return WRC_Continue
}

func selectWindowRewriteSelectCb(tls *libc.TLS, pWalker uintptr, pSelect uintptr) int32 {
	var p uintptr = *(*uintptr)(unsafe.Pointer(pWalker + 40))
	var pSave uintptr = (*WindowRewrite1)(unsafe.Pointer(p)).FpSubSelect
	if pSave == pSelect {
		return WRC_Continue
	} else {
		(*WindowRewrite1)(unsafe.Pointer(p)).FpSubSelect = pSelect
		Xsqlite3WalkSelect(tls, pWalker, pSelect)
		(*WindowRewrite1)(unsafe.Pointer(p)).FpSubSelect = pSave
	}
	return WRC_Prune
}

func selectWindowRewriteEList(tls *libc.TLS, pParse uintptr, pWin uintptr, pSrc uintptr, pEList uintptr, pTab uintptr, ppSub uintptr) {
	bp := tls.Alloc(88)
	defer tls.Free(88)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
	libc.Xmemset(tls, bp+48, 0, uint64(unsafe.Sizeof(WindowRewrite{})))

	(*WindowRewrite)(unsafe.Pointer(bp + 48)).FpSub = *(*uintptr)(unsafe.Pointer(ppSub))
	(*WindowRewrite)(unsafe.Pointer(bp + 48)).FpWin = pWin
	(*WindowRewrite)(unsafe.Pointer(bp + 48)).FpSrc = pSrc
	(*WindowRewrite)(unsafe.Pointer(bp + 48)).FpTab = pTab

	(*Walker)(unsafe.Pointer(bp)).FpParse = pParse
	(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{selectWindowRewriteExprCb}))
	(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{selectWindowRewriteSelectCb}))
	*(*uintptr)(unsafe.Pointer(bp + 40)) = bp + 48

	Xsqlite3WalkExprList(tls, bp, pEList)

	*(*uintptr)(unsafe.Pointer(ppSub)) = (*WindowRewrite)(unsafe.Pointer(bp + 48)).FpSub
}

func exprListAppendList(tls *libc.TLS, pParse uintptr, pList uintptr, pAppend uintptr, bIntToNull int32) uintptr {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	if pAppend != 0 {
		var i int32
		var nInit int32
		if pList != 0 {
			nInit = (*ExprList)(unsafe.Pointer(pList)).FnExpr
		} else {
			nInit = 0
		}
		for i = 0; i < (*ExprList)(unsafe.Pointer(pAppend)).FnExpr; i++ {
			var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
			var pDup uintptr = Xsqlite3ExprDup(tls, db, (*ExprList_item)(unsafe.Pointer(pAppend+8+uintptr(i)*32)).FpExpr, 0)
			if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
				Xsqlite3ExprDelete(tls, db, pDup)
				break
			}
			if bIntToNull != 0 {
				var pSub uintptr
				pSub = Xsqlite3ExprSkipCollateAndLikely(tls, pDup)
				if Xsqlite3ExprIsInteger(tls, pSub, bp) != 0 {
					(*Expr)(unsafe.Pointer(pSub)).Fop = U8(TK_NULL)
					*(*U32)(unsafe.Pointer(pSub + 4)) &= libc.Uint32FromInt32(libc.CplInt32(EP_IntValue | EP_IsTrue | EP_IsFalse))
					*(*uintptr)(unsafe.Pointer(pSub + 8)) = uintptr(0)
				}
			}
			pList = Xsqlite3ExprListAppend(tls, pParse, pList, pDup)
			if pList != 0 {
				(*ExprList_item)(unsafe.Pointer(pList + 8 + uintptr(nInit+i)*32)).Ffg.FsortFlags = (*ExprList_item)(unsafe.Pointer(pAppend + 8 + uintptr(i)*32)).Ffg.FsortFlags
			}
		}
	}
	return pList
}

func sqlite3WindowExtraAggFuncDepth(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AGG_FUNCTION &&
		int32((*Expr)(unsafe.Pointer(pExpr)).Fop2) >= (*Walker)(unsafe.Pointer(pWalker)).FwalkerDepth {
		(*Expr)(unsafe.Pointer(pExpr)).Fop2++
	}
	return WRC_Continue
}

func disallowAggregatesInOrderByCb(tls *libc.TLS, pWalker uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if int32((*Expr)(unsafe.Pointer(pExpr)).Fop) == TK_AGG_FUNCTION && (*Expr)(unsafe.Pointer(pExpr)).FpAggInfo == uintptr(0) {
		Xsqlite3ErrorMsg(tls, (*Walker)(unsafe.Pointer(pWalker)).FpParse,
			ts+26977, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(pExpr + 8))))
	}
	return WRC_Continue
}

func Xsqlite3WindowRewrite(tls *libc.TLS, pParse uintptr, p uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var rc int32 = SQLITE_OK
	if (*Select)(unsafe.Pointer(p)).FpWin != 0 &&
		(*Select)(unsafe.Pointer(p)).FpPrior == uintptr(0) &&
		(*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_WinRewrite) == U32(0) &&
		!(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		var v uintptr = Xsqlite3GetVdbe(tls, pParse)
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		var pSub uintptr = uintptr(0)
		var pSrc uintptr = (*Select)(unsafe.Pointer(p)).FpSrc
		var pWhere uintptr = (*Select)(unsafe.Pointer(p)).FpWhere
		var pGroupBy uintptr = (*Select)(unsafe.Pointer(p)).FpGroupBy
		var pHaving uintptr = (*Select)(unsafe.Pointer(p)).FpHaving
		var pSort uintptr = uintptr(0)

		*(*uintptr)(unsafe.Pointer(bp + 48)) = uintptr(0)
		var pMWin uintptr = (*Select)(unsafe.Pointer(p)).FpWin
		var pWin uintptr
		var pTab uintptr

		var selFlags U32 = (*Select)(unsafe.Pointer(p)).FselFlags

		pTab = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Table{})))
		if pTab == uintptr(0) {
			return Xsqlite3ErrorToParser(tls, db, SQLITE_NOMEM)
		}
		Xsqlite3AggInfoPersistWalkerInit(tls, bp, pParse)
		Xsqlite3WalkSelect(tls, bp, p)
		if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_Aggregate) == U32(0) {
			(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			}{disallowAggregatesInOrderByCb}))
			(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = uintptr(0)
			Xsqlite3WalkExprList(tls, bp, (*Select)(unsafe.Pointer(p)).FpOrderBy)
		}

		(*Select)(unsafe.Pointer(p)).FpSrc = uintptr(0)
		(*Select)(unsafe.Pointer(p)).FpWhere = uintptr(0)
		(*Select)(unsafe.Pointer(p)).FpGroupBy = uintptr(0)
		(*Select)(unsafe.Pointer(p)).FpHaving = uintptr(0)
		*(*U32)(unsafe.Pointer(p + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_Aggregate))
		*(*U32)(unsafe.Pointer(p + 4)) |= U32(SF_WinRewrite)

		pSort = exprListAppendList(tls, pParse, uintptr(0), (*Window)(unsafe.Pointer(pMWin)).FpPartition, 1)
		pSort = exprListAppendList(tls, pParse, pSort, (*Window)(unsafe.Pointer(pMWin)).FpOrderBy, 1)
		if pSort != 0 && (*Select)(unsafe.Pointer(p)).FpOrderBy != 0 && (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpOrderBy)).FnExpr <= (*ExprList)(unsafe.Pointer(pSort)).FnExpr {
			var nSave int32 = (*ExprList)(unsafe.Pointer(pSort)).FnExpr
			(*ExprList)(unsafe.Pointer(pSort)).FnExpr = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpOrderBy)).FnExpr
			if Xsqlite3ExprListCompare(tls, pSort, (*Select)(unsafe.Pointer(p)).FpOrderBy, -1) == 0 {
				Xsqlite3ExprListDelete(tls, db, (*Select)(unsafe.Pointer(p)).FpOrderBy)
				(*Select)(unsafe.Pointer(p)).FpOrderBy = uintptr(0)
			}
			(*ExprList)(unsafe.Pointer(pSort)).FnExpr = nSave
		}

		(*Window)(unsafe.Pointer(pMWin)).FiEphCsr = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
		*(*int32)(unsafe.Pointer(pParse + 52)) += 3

		selectWindowRewriteEList(tls, pParse, pMWin, pSrc, (*Select)(unsafe.Pointer(p)).FpEList, pTab, bp+48)
		selectWindowRewriteEList(tls, pParse, pMWin, pSrc, (*Select)(unsafe.Pointer(p)).FpOrderBy, pTab, bp+48)
		(*Window)(unsafe.Pointer(pMWin)).FnBufferCol = func() int32 {
			if *(*uintptr)(unsafe.Pointer(bp + 48)) != 0 {
				return (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 48)))).FnExpr
			}
			return 0
		}()

		*(*uintptr)(unsafe.Pointer(bp + 48)) = exprListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 48)), (*Window)(unsafe.Pointer(pMWin)).FpPartition, 0)
		*(*uintptr)(unsafe.Pointer(bp + 48)) = exprListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 48)), (*Window)(unsafe.Pointer(pMWin)).FpOrderBy, 0)

		for pWin = pMWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
			var pArgs uintptr

			pArgs = *(*uintptr)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpOwner + 32))
			if (*FuncDef)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpWFunc)).FfuncFlags&U32(SQLITE_FUNC_SUBTYPE) != 0 {
				selectWindowRewriteEList(tls, pParse, pMWin, pSrc, pArgs, pTab, bp+48)
				(*Window)(unsafe.Pointer(pWin)).FiArgCol = func() int32 {
					if *(*uintptr)(unsafe.Pointer(bp + 48)) != 0 {
						return (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 48)))).FnExpr
					}
					return 0
				}()
				(*Window)(unsafe.Pointer(pWin)).FbExprArgs = U8(1)
			} else {
				(*Window)(unsafe.Pointer(pWin)).FiArgCol = func() int32 {
					if *(*uintptr)(unsafe.Pointer(bp + 48)) != 0 {
						return (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 48)))).FnExpr
					}
					return 0
				}()
				*(*uintptr)(unsafe.Pointer(bp + 48)) = exprListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 48)), pArgs, 0)
			}
			if (*Window)(unsafe.Pointer(pWin)).FpFilter != 0 {
				var pFilter uintptr = Xsqlite3ExprDup(tls, db, (*Window)(unsafe.Pointer(pWin)).FpFilter, 0)
				*(*uintptr)(unsafe.Pointer(bp + 48)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 48)), pFilter)
			}
			(*Window)(unsafe.Pointer(pWin)).FregAccum = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
			(*Window)(unsafe.Pointer(pWin)).FregResult = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
			Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*Window)(unsafe.Pointer(pWin)).FregAccum)
		}

		if *(*uintptr)(unsafe.Pointer(bp + 48)) == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(bp + 48)) = Xsqlite3ExprListAppend(tls, pParse, uintptr(0),
				Xsqlite3Expr(tls, db, TK_INTEGER, ts+10734))
		}

		pSub = Xsqlite3SelectNew(tls,
			pParse, *(*uintptr)(unsafe.Pointer(bp + 48)), pSrc, pWhere, pGroupBy, pHaving, pSort, uint32(0), uintptr(0))

		(*Select)(unsafe.Pointer(p)).FpSrc = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))

		if (*Select)(unsafe.Pointer(p)).FpSrc != 0 {
			var pTab2 uintptr
			(*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FpSelect = pSub
			libc.SetBitFieldPtr16Uint32((*Select)(unsafe.Pointer(p)).FpSrc+8+60+4, uint32(1), 3, 0x8)
			Xsqlite3SrcListAssignCursors(tls, pParse, (*Select)(unsafe.Pointer(p)).FpSrc)
			*(*U32)(unsafe.Pointer(pSub + 4)) |= U32(SF_Expanded | SF_OrderByReqd)
			pTab2 = Xsqlite3ResultSetOfSelect(tls, pParse, pSub, uint8(SQLITE_AFF_NONE))
			*(*U32)(unsafe.Pointer(pSub + 4)) |= selFlags & U32(SF_Aggregate)
			if pTab2 == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				libc.Xmemcpy(tls, pTab, pTab2, uint64(unsafe.Sizeof(Table{})))
				*(*U32)(unsafe.Pointer(pTab + 48)) |= U32(TF_Ephemeral)
				(*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FpTab = pTab
				pTab = pTab2
				libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Walker{})))
				(*Walker)(unsafe.Pointer(bp)).FxExprCallback = *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr) int32
				}{sqlite3WindowExtraAggFuncDepth}))
				(*Walker)(unsafe.Pointer(bp)).FxSelectCallback = *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr) int32
				}{Xsqlite3WalkerDepthIncrease}))
				(*Walker)(unsafe.Pointer(bp)).FxSelectCallback2 = *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr)
				}{Xsqlite3WalkerDepthDecrease}))
				Xsqlite3WalkSelect(tls, bp, pSub)
			}
		} else {
			Xsqlite3SelectDelete(tls, db, pSub)
		}
		if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
			rc = SQLITE_NOMEM
		}

		Xsqlite3ParserAddCleanup(tls, pParse, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{Xsqlite3DbFree})), pTab)
	}

	return rc
}

func Xsqlite3WindowUnlinkFromSelect(tls *libc.TLS, p uintptr) {
	if (*Window)(unsafe.Pointer(p)).FppThis != 0 {
		*(*uintptr)(unsafe.Pointer((*Window)(unsafe.Pointer(p)).FppThis)) = (*Window)(unsafe.Pointer(p)).FpNextWin
		if (*Window)(unsafe.Pointer(p)).FpNextWin != 0 {
			(*Window)(unsafe.Pointer((*Window)(unsafe.Pointer(p)).FpNextWin)).FppThis = (*Window)(unsafe.Pointer(p)).FppThis
		}
		(*Window)(unsafe.Pointer(p)).FppThis = uintptr(0)
	}
}

func Xsqlite3WindowDelete(tls *libc.TLS, db uintptr, p uintptr) {
	if p != 0 {
		Xsqlite3WindowUnlinkFromSelect(tls, p)
		Xsqlite3ExprDelete(tls, db, (*Window)(unsafe.Pointer(p)).FpFilter)
		Xsqlite3ExprListDelete(tls, db, (*Window)(unsafe.Pointer(p)).FpPartition)
		Xsqlite3ExprListDelete(tls, db, (*Window)(unsafe.Pointer(p)).FpOrderBy)
		Xsqlite3ExprDelete(tls, db, (*Window)(unsafe.Pointer(p)).FpEnd)
		Xsqlite3ExprDelete(tls, db, (*Window)(unsafe.Pointer(p)).FpStart)
		Xsqlite3DbFree(tls, db, (*Window)(unsafe.Pointer(p)).FzName)
		Xsqlite3DbFree(tls, db, (*Window)(unsafe.Pointer(p)).FzBase)
		Xsqlite3DbFree(tls, db, p)
	}
}

func Xsqlite3WindowListDelete(tls *libc.TLS, db uintptr, p uintptr) {
	for p != 0 {
		var pNext uintptr = (*Window)(unsafe.Pointer(p)).FpNextWin
		Xsqlite3WindowDelete(tls, db, p)
		p = pNext
	}
}

func sqlite3WindowOffsetExpr(tls *libc.TLS, pParse uintptr, pExpr uintptr) uintptr {
	if 0 == Xsqlite3ExprIsConstant(tls, pExpr) {
		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			Xsqlite3RenameExprUnmap(tls, pParse, pExpr)
		}
		Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pExpr)
		pExpr = Xsqlite3ExprAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_NULL, uintptr(0), 0)
	}
	return pExpr
}

func Xsqlite3WindowAlloc(tls *libc.TLS, pParse uintptr, eType int32, eStart int32, pStart uintptr, eEnd int32, pEnd uintptr, eExclude U8) uintptr {
	var pWin uintptr
	var bImplicitFrame int32
	pWin = uintptr(0)
	bImplicitFrame = 0

	if !(eType == 0) {
		goto __1
	}
	bImplicitFrame = 1
	eType = TK_RANGE
__1:
	;
	if !(eStart == TK_CURRENT && eEnd == TK_PRECEDING ||
		eStart == TK_FOLLOWING && (eEnd == TK_PRECEDING || eEnd == TK_CURRENT)) {
		goto __2
	}
	Xsqlite3ErrorMsg(tls, pParse, ts+27003, 0)
	goto windowAllocErr
__2:
	;
	pWin = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(Window{})))
	if !(pWin == uintptr(0)) {
		goto __3
	}
	goto windowAllocErr
__3:
	;
	(*Window)(unsafe.Pointer(pWin)).FeFrmType = U8(eType)
	(*Window)(unsafe.Pointer(pWin)).FeStart = U8(eStart)
	(*Window)(unsafe.Pointer(pWin)).FeEnd = U8(eEnd)
	if !(int32(eExclude) == 0 && (*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).FdbOptFlags&U32(SQLITE_WindowFunc) != U32(0)) {
		goto __4
	}
	eExclude = U8(TK_NO)
__4:
	;
	(*Window)(unsafe.Pointer(pWin)).FeExclude = eExclude
	(*Window)(unsafe.Pointer(pWin)).FbImplicitFrame = U8(bImplicitFrame)
	(*Window)(unsafe.Pointer(pWin)).FpEnd = sqlite3WindowOffsetExpr(tls, pParse, pEnd)
	(*Window)(unsafe.Pointer(pWin)).FpStart = sqlite3WindowOffsetExpr(tls, pParse, pStart)
	return pWin

windowAllocErr:
	Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pEnd)
	Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pStart)
	return uintptr(0)
}

func Xsqlite3WindowAssemble(tls *libc.TLS, pParse uintptr, pWin uintptr, pPartition uintptr, pOrderBy uintptr, pBase uintptr) uintptr {
	if pWin != 0 {
		(*Window)(unsafe.Pointer(pWin)).FpPartition = pPartition
		(*Window)(unsafe.Pointer(pWin)).FpOrderBy = pOrderBy
		if pBase != 0 {
			(*Window)(unsafe.Pointer(pWin)).FzBase = Xsqlite3DbStrNDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Token)(unsafe.Pointer(pBase)).Fz, uint64((*Token)(unsafe.Pointer(pBase)).Fn))
		}
	} else {
		Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pPartition)
		Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pOrderBy)
	}
	return pWin
}

func Xsqlite3WindowChain(tls *libc.TLS, pParse uintptr, pWin uintptr, pList uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Window)(unsafe.Pointer(pWin)).FzBase != 0 {
		var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
		var pExist uintptr = windowFind(tls, pParse, pList, (*Window)(unsafe.Pointer(pWin)).FzBase)
		if pExist != 0 {
			var zErr uintptr = uintptr(0)

			if (*Window)(unsafe.Pointer(pWin)).FpPartition != 0 {
				zErr = ts + 27035
			} else if (*Window)(unsafe.Pointer(pExist)).FpOrderBy != 0 && (*Window)(unsafe.Pointer(pWin)).FpOrderBy != 0 {
				zErr = ts + 27052
			} else if int32((*Window)(unsafe.Pointer(pExist)).FbImplicitFrame) == 0 {
				zErr = ts + 27068
			}
			if zErr != 0 {
				Xsqlite3ErrorMsg(tls, pParse,
					ts+27088, libc.VaList(bp, zErr, (*Window)(unsafe.Pointer(pWin)).FzBase))
			} else {
				(*Window)(unsafe.Pointer(pWin)).FpPartition = Xsqlite3ExprListDup(tls, db, (*Window)(unsafe.Pointer(pExist)).FpPartition, 0)
				if (*Window)(unsafe.Pointer(pExist)).FpOrderBy != 0 {
					(*Window)(unsafe.Pointer(pWin)).FpOrderBy = Xsqlite3ExprListDup(tls, db, (*Window)(unsafe.Pointer(pExist)).FpOrderBy, 0)
				}
				Xsqlite3DbFree(tls, db, (*Window)(unsafe.Pointer(pWin)).FzBase)
				(*Window)(unsafe.Pointer(pWin)).FzBase = uintptr(0)
			}
		}
	}
}

func Xsqlite3WindowAttach(tls *libc.TLS, pParse uintptr, p uintptr, pWin uintptr) {
	if p != 0 {
		*(*uintptr)(unsafe.Pointer(p + 64)) = pWin
		*(*U32)(unsafe.Pointer(p + 4)) |= U32(EP_WinFunc)
		(*Window)(unsafe.Pointer(pWin)).FpOwner = p
		if (*Expr)(unsafe.Pointer(p)).Fflags&U32(EP_Distinct) != 0 && int32((*Window)(unsafe.Pointer(pWin)).FeFrmType) != TK_FILTER {
			Xsqlite3ErrorMsg(tls, pParse,
				ts+27121, 0)
		}
	} else {
		Xsqlite3WindowDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pWin)
	}
}

func Xsqlite3WindowLink(tls *libc.TLS, pSel uintptr, pWin uintptr) {
	if pSel != 0 {
		if uintptr(0) == (*Select)(unsafe.Pointer(pSel)).FpWin || 0 == Xsqlite3WindowCompare(tls, uintptr(0), (*Select)(unsafe.Pointer(pSel)).FpWin, pWin, 0) {
			(*Window)(unsafe.Pointer(pWin)).FpNextWin = (*Select)(unsafe.Pointer(pSel)).FpWin
			if (*Select)(unsafe.Pointer(pSel)).FpWin != 0 {
				(*Window)(unsafe.Pointer((*Select)(unsafe.Pointer(pSel)).FpWin)).FppThis = pWin + 64
			}
			(*Select)(unsafe.Pointer(pSel)).FpWin = pWin
			(*Window)(unsafe.Pointer(pWin)).FppThis = pSel + 112
		} else {
			if Xsqlite3ExprListCompare(tls, (*Window)(unsafe.Pointer(pWin)).FpPartition, (*Window)(unsafe.Pointer((*Select)(unsafe.Pointer(pSel)).FpWin)).FpPartition, -1) != 0 {
				*(*U32)(unsafe.Pointer(pSel + 4)) |= U32(SF_MultiPart)
			}
		}
	}
}

func Xsqlite3WindowCompare(tls *libc.TLS, pParse uintptr, p1 uintptr, p2 uintptr, bFilter int32) int32 {
	var res int32
	if p1 == uintptr(0) || p2 == uintptr(0) {
		return 1
	}
	if int32((*Window)(unsafe.Pointer(p1)).FeFrmType) != int32((*Window)(unsafe.Pointer(p2)).FeFrmType) {
		return 1
	}
	if int32((*Window)(unsafe.Pointer(p1)).FeStart) != int32((*Window)(unsafe.Pointer(p2)).FeStart) {
		return 1
	}
	if int32((*Window)(unsafe.Pointer(p1)).FeEnd) != int32((*Window)(unsafe.Pointer(p2)).FeEnd) {
		return 1
	}
	if int32((*Window)(unsafe.Pointer(p1)).FeExclude) != int32((*Window)(unsafe.Pointer(p2)).FeExclude) {
		return 1
	}
	if Xsqlite3ExprCompare(tls, pParse, (*Window)(unsafe.Pointer(p1)).FpStart, (*Window)(unsafe.Pointer(p2)).FpStart, -1) != 0 {
		return 1
	}
	if Xsqlite3ExprCompare(tls, pParse, (*Window)(unsafe.Pointer(p1)).FpEnd, (*Window)(unsafe.Pointer(p2)).FpEnd, -1) != 0 {
		return 1
	}
	if libc.AssignInt32(&res, Xsqlite3ExprListCompare(tls, (*Window)(unsafe.Pointer(p1)).FpPartition, (*Window)(unsafe.Pointer(p2)).FpPartition, -1)) != 0 {
		return res
	}
	if libc.AssignInt32(&res, Xsqlite3ExprListCompare(tls, (*Window)(unsafe.Pointer(p1)).FpOrderBy, (*Window)(unsafe.Pointer(p2)).FpOrderBy, -1)) != 0 {
		return res
	}
	if bFilter != 0 {
		if libc.AssignInt32(&res, Xsqlite3ExprCompare(tls, pParse, (*Window)(unsafe.Pointer(p1)).FpFilter, (*Window)(unsafe.Pointer(p2)).FpFilter, -1)) != 0 {
			return res
		}
	}
	return 0
}

func Xsqlite3WindowCodeInit(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	var nEphExpr int32 = (*ExprList)(unsafe.Pointer((*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(pSelect)).FpSrc + 8)).FpSelect)).FpEList)).FnExpr
	var pMWin uintptr = (*Select)(unsafe.Pointer(pSelect)).FpWin
	var pWin uintptr
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)

	Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr, nEphExpr)
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr+1, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr)
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr+2, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr)
	Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr+3, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr)

	if (*Window)(unsafe.Pointer(pMWin)).FpPartition != 0 {
		var nExpr int32 = (*ExprList)(unsafe.Pointer((*Window)(unsafe.Pointer(pMWin)).FpPartition)).FnExpr
		(*Window)(unsafe.Pointer(pMWin)).FregPart = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nExpr
		Xsqlite3VdbeAddOp3(tls, v, OP_Null, 0, (*Window)(unsafe.Pointer(pMWin)).FregPart, (*Window)(unsafe.Pointer(pMWin)).FregPart+nExpr-1)
	}

	(*Window)(unsafe.Pointer(pMWin)).FregOne = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, (*Window)(unsafe.Pointer(pMWin)).FregOne)

	if (*Window)(unsafe.Pointer(pMWin)).FeExclude != 0 {
		(*Window)(unsafe.Pointer(pMWin)).FregStartRowid = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		(*Window)(unsafe.Pointer(pMWin)).FregEndRowid = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		(*Window)(unsafe.Pointer(pMWin)).FcsrApp = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, (*Window)(unsafe.Pointer(pMWin)).FregStartRowid)
		Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*Window)(unsafe.Pointer(pMWin)).FregEndRowid)
		Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, (*Window)(unsafe.Pointer(pMWin)).FcsrApp, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr)
		return
	}

	for pWin = pMWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
		var p uintptr = (*Window)(unsafe.Pointer(pWin)).FpWFunc
		if (*FuncDef)(unsafe.Pointer(p)).FfuncFlags&U32(SQLITE_FUNC_MINMAX) != 0 && int32((*Window)(unsafe.Pointer(pWin)).FeStart) != TK_UNBOUNDED {
			var pList uintptr
			var pKeyInfo uintptr

			pList = *(*uintptr)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpOwner + 32))
			pKeyInfo = Xsqlite3KeyInfoFromExprList(tls, pParse, pList, 0, 0)
			(*Window)(unsafe.Pointer(pWin)).FcsrApp = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
			(*Window)(unsafe.Pointer(pWin)).FregApp = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
			*(*int32)(unsafe.Pointer(pParse + 56)) += 3
			if pKeyInfo != 0 && int32(*(*uint8)(unsafe.Pointer((*FuncDef)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpWFunc)).FzName + 1))) == 'i' {
				*(*U8)(unsafe.Pointer((*KeyInfo)(unsafe.Pointer(pKeyInfo)).FaSortFlags)) = U8(KEYINFO_ORDER_DESC)
			}
			Xsqlite3VdbeAddOp2(tls, v, OP_OpenEphemeral, (*Window)(unsafe.Pointer(pWin)).FcsrApp, 2)
			Xsqlite3VdbeAppendP4(tls, v, pKeyInfo, -8)
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*Window)(unsafe.Pointer(pWin)).FregApp+1)
		} else if (*FuncDef)(unsafe.Pointer(p)).FzName == uintptr(unsafe.Pointer(&nth_valueName)) || (*FuncDef)(unsafe.Pointer(p)).FzName == uintptr(unsafe.Pointer(&first_valueName)) {
			(*Window)(unsafe.Pointer(pWin)).FregApp = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
			(*Window)(unsafe.Pointer(pWin)).FcsrApp = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
			*(*int32)(unsafe.Pointer(pParse + 56)) += 2
			Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, (*Window)(unsafe.Pointer(pWin)).FcsrApp, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr)
		} else if (*FuncDef)(unsafe.Pointer(p)).FzName == uintptr(unsafe.Pointer(&leadName)) || (*FuncDef)(unsafe.Pointer(p)).FzName == uintptr(unsafe.Pointer(&lagName)) {
			(*Window)(unsafe.Pointer(pWin)).FcsrApp = libc.PostIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnTab, 1)
			Xsqlite3VdbeAddOp2(tls, v, OP_OpenDup, (*Window)(unsafe.Pointer(pWin)).FcsrApp, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr)
		}
	}
}

func windowCheckValue(tls *libc.TLS, pParse uintptr, reg int32, eCond int32) {
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var regZero int32 = Xsqlite3GetTempReg(tls, pParse)

	Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regZero)
	if eCond >= WINDOW_STARTING_NUM {
		var regString int32 = Xsqlite3GetTempReg(tls, pParse)
		Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, regString, 0, ts+1636, -1)
		Xsqlite3VdbeAddOp3(tls, v, OP_Ge, regString, Xsqlite3VdbeCurrentAddr(tls, v)+2, reg)
		Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_AFF_NUMERIC|SQLITE_JUMPIFNULL))

	} else {
		Xsqlite3VdbeAddOp2(tls, v, OP_MustBeInt, reg, Xsqlite3VdbeCurrentAddr(tls, v)+2)

	}
	Xsqlite3VdbeAddOp3(tls, v, aOp1[eCond], regZero, Xsqlite3VdbeCurrentAddr(tls, v)+2, reg)
	Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_AFF_NUMERIC))

	Xsqlite3MayAbort(tls, pParse)
	Xsqlite3VdbeAddOp2(tls, v, OP_Halt, SQLITE_ERROR, OE_Abort)
	Xsqlite3VdbeAppendP4(tls, v, azErr[eCond], -1)
	Xsqlite3ReleaseTempReg(tls, pParse, regZero)
}

var azErr = [5]uintptr{
	ts + 27168,
	ts + 27221,
	ts + 26625,
	ts + 27272,
	ts + 27324,
}
var aOp1 = [5]int32{OP_Ge, OP_Ge, OP_Gt, OP_Ge, OP_Ge}

func windowArgCount(tls *libc.TLS, pWin uintptr) int32 {
	var pList uintptr

	pList = *(*uintptr)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpOwner + 32))
	return func() int32 {
		if pList != 0 {
			return (*ExprList)(unsafe.Pointer(pList)).FnExpr
		}
		return 0
	}()
}

type WindowCodeArg1 = struct {
	FpParse      uintptr
	FpMWin       uintptr
	FpVdbe       uintptr
	FaddrGosub   int32
	FregGosub    int32
	FregArg      int32
	FeDelete     int32
	FregRowid    int32
	Fstart       WindowCsrAndReg
	Fcurrent     WindowCsrAndReg
	Fend         WindowCsrAndReg
	F__ccgo_pad1 [4]byte
}

type WindowCodeArg = WindowCodeArg1
type WindowCsrAndReg1 = struct {
	Fcsr int32
	Freg int32
}

type WindowCsrAndReg = WindowCsrAndReg1

func windowReadPeerValues(tls *libc.TLS, p uintptr, csr int32, reg int32) {
	var pMWin uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpMWin
	var pOrderBy uintptr = (*Window)(unsafe.Pointer(pMWin)).FpOrderBy
	if pOrderBy != 0 {
		var v uintptr = Xsqlite3GetVdbe(tls, (*WindowCodeArg)(unsafe.Pointer(p)).FpParse)
		var pPart uintptr = (*Window)(unsafe.Pointer(pMWin)).FpPartition
		var iColOff int32 = (*Window)(unsafe.Pointer(pMWin)).FnBufferCol + func() int32 {
			if pPart != 0 {
				return (*ExprList)(unsafe.Pointer(pPart)).FnExpr
			}
			return 0
		}()
		var i int32
		for i = 0; i < (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr; i++ {
			Xsqlite3VdbeAddOp3(tls, v, OP_Column, csr, iColOff+i, reg+i)
		}
	}
}

func windowAggStep(tls *libc.TLS, p uintptr, pMWin uintptr, csr int32, bInverse int32, reg int32) {
	var pParse uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpParse
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var pWin uintptr
	for pWin = pMWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
		var pFunc uintptr = (*Window)(unsafe.Pointer(pWin)).FpWFunc
		var regArg int32
		var nArg int32
		if (*Window)(unsafe.Pointer(pWin)).FbExprArgs != 0 {
			nArg = 0
		} else {
			nArg = windowArgCount(tls, pWin)
		}
		var i int32

		for i = 0; i < nArg; i++ {
			if i != 1 || (*FuncDef)(unsafe.Pointer(pFunc)).FzName != uintptr(unsafe.Pointer(&nth_valueName)) {
				Xsqlite3VdbeAddOp3(tls, v, OP_Column, csr, (*Window)(unsafe.Pointer(pWin)).FiArgCol+i, reg+i)
			} else {
				Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr, (*Window)(unsafe.Pointer(pWin)).FiArgCol+i, reg+i)
			}
		}
		regArg = reg

		if (*Window)(unsafe.Pointer(pMWin)).FregStartRowid == 0 &&
			(*FuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&U32(SQLITE_FUNC_MINMAX) != 0 &&
			int32((*Window)(unsafe.Pointer(pWin)).FeStart) != TK_UNBOUNDED {
			var addrIsNull int32 = Xsqlite3VdbeAddOp1(tls, v, OP_IsNull, regArg)

			if bInverse == 0 {
				Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, (*Window)(unsafe.Pointer(pWin)).FregApp+1, 1)
				Xsqlite3VdbeAddOp2(tls, v, OP_SCopy, regArg, (*Window)(unsafe.Pointer(pWin)).FregApp)
				Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, (*Window)(unsafe.Pointer(pWin)).FregApp, 2, (*Window)(unsafe.Pointer(pWin)).FregApp+2)
				Xsqlite3VdbeAddOp2(tls, v, OP_IdxInsert, (*Window)(unsafe.Pointer(pWin)).FcsrApp, (*Window)(unsafe.Pointer(pWin)).FregApp+2)
			} else {
				Xsqlite3VdbeAddOp4Int(tls, v, OP_SeekGE, (*Window)(unsafe.Pointer(pWin)).FcsrApp, 0, regArg, 1)

				Xsqlite3VdbeAddOp1(tls, v, OP_Delete, (*Window)(unsafe.Pointer(pWin)).FcsrApp)
				Xsqlite3VdbeJumpHere(tls, v, Xsqlite3VdbeCurrentAddr(tls, v)-2)
			}
			Xsqlite3VdbeJumpHere(tls, v, addrIsNull)
		} else if (*Window)(unsafe.Pointer(pWin)).FregApp != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, (*Window)(unsafe.Pointer(pWin)).FregApp+1-bInverse, 1)
		} else if (*FuncDef)(unsafe.Pointer(pFunc)).FxSFunc != *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{noopStepFunc})) {
			var addrIf int32 = 0
			if (*Window)(unsafe.Pointer(pWin)).FpFilter != 0 {
				var regTmp int32

				regTmp = Xsqlite3GetTempReg(tls, pParse)
				Xsqlite3VdbeAddOp3(tls, v, OP_Column, csr, (*Window)(unsafe.Pointer(pWin)).FiArgCol+nArg, regTmp)
				addrIf = Xsqlite3VdbeAddOp3(tls, v, OP_IfNot, regTmp, 0, 1)

				Xsqlite3ReleaseTempReg(tls, pParse, regTmp)
			}

			if (*Window)(unsafe.Pointer(pWin)).FbExprArgs != 0 {
				var iOp int32 = Xsqlite3VdbeCurrentAddr(tls, v)
				var iEnd int32

				nArg = (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpOwner + 32)))).FnExpr
				regArg = Xsqlite3GetTempRange(tls, pParse, nArg)
				Xsqlite3ExprCodeExprList(tls, pParse, *(*uintptr)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpOwner + 32)), regArg, 0, uint8(0))

				for iEnd = Xsqlite3VdbeCurrentAddr(tls, v); iOp < iEnd; iOp++ {
					var pOp uintptr = Xsqlite3VdbeGetOp(tls, v, iOp)
					if int32((*VdbeOp)(unsafe.Pointer(pOp)).Fopcode) == OP_Column && (*VdbeOp)(unsafe.Pointer(pOp)).Fp1 == (*Window)(unsafe.Pointer(pMWin)).FiEphCsr {
						(*VdbeOp)(unsafe.Pointer(pOp)).Fp1 = csr
					}
				}
			}
			if (*FuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&U32(SQLITE_FUNC_NEEDCOLL) != 0 {
				var pColl uintptr

				pColl = Xsqlite3ExprNNCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpOwner + 32))+8)).FpExpr)
				Xsqlite3VdbeAddOp4(tls, v, OP_CollSeq, 0, 0, 0, pColl, -2)
			}
			Xsqlite3VdbeAddOp3(tls, v, func() int32 {
				if bInverse != 0 {
					return OP_AggInverse
				}
				return OP_AggStep
			}(),
				bInverse, regArg, (*Window)(unsafe.Pointer(pWin)).FregAccum)
			Xsqlite3VdbeAppendP4(tls, v, pFunc, -7)
			Xsqlite3VdbeChangeP5(tls, v, uint16(U8(nArg)))
			if (*Window)(unsafe.Pointer(pWin)).FbExprArgs != 0 {
				Xsqlite3ReleaseTempRange(tls, pParse, regArg, nArg)
			}
			if addrIf != 0 {
				Xsqlite3VdbeJumpHere(tls, v, addrIf)
			}
		}
	}
}

func windowAggFinal(tls *libc.TLS, p uintptr, bFin int32) {
	var pParse uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpParse
	var pMWin uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpMWin
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var pWin uintptr

	for pWin = pMWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
		if (*Window)(unsafe.Pointer(pMWin)).FregStartRowid == 0 &&
			(*FuncDef)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpWFunc)).FfuncFlags&U32(SQLITE_FUNC_MINMAX) != 0 &&
			int32((*Window)(unsafe.Pointer(pWin)).FeStart) != TK_UNBOUNDED {
			Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*Window)(unsafe.Pointer(pWin)).FregResult)
			Xsqlite3VdbeAddOp1(tls, v, OP_Last, (*Window)(unsafe.Pointer(pWin)).FcsrApp)

			Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*Window)(unsafe.Pointer(pWin)).FcsrApp, 0, (*Window)(unsafe.Pointer(pWin)).FregResult)
			Xsqlite3VdbeJumpHere(tls, v, Xsqlite3VdbeCurrentAddr(tls, v)-2)
		} else if (*Window)(unsafe.Pointer(pWin)).FregApp != 0 {
		} else {
			var nArg int32 = windowArgCount(tls, pWin)
			if bFin != 0 {
				Xsqlite3VdbeAddOp2(tls, v, OP_AggFinal, (*Window)(unsafe.Pointer(pWin)).FregAccum, nArg)
				Xsqlite3VdbeAppendP4(tls, v, (*Window)(unsafe.Pointer(pWin)).FpWFunc, -7)
				Xsqlite3VdbeAddOp2(tls, v, OP_Copy, (*Window)(unsafe.Pointer(pWin)).FregAccum, (*Window)(unsafe.Pointer(pWin)).FregResult)
				Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*Window)(unsafe.Pointer(pWin)).FregAccum)
			} else {
				Xsqlite3VdbeAddOp3(tls, v, OP_AggValue, (*Window)(unsafe.Pointer(pWin)).FregAccum, nArg, (*Window)(unsafe.Pointer(pWin)).FregResult)
				Xsqlite3VdbeAppendP4(tls, v, (*Window)(unsafe.Pointer(pWin)).FpWFunc, -7)
			}
		}
	}
}

func windowFullScan(tls *libc.TLS, p uintptr) {
	var pWin uintptr
	var pParse uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpParse
	var pMWin uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpMWin
	var v uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpVdbe

	var regCRowid int32 = 0
	var regCPeer int32 = 0
	var regRowid int32 = 0
	var regPeer int32 = 0

	var nPeer int32
	var lblNext int32
	var lblBrk int32
	var addrNext int32
	var csr int32

	csr = (*Window)(unsafe.Pointer(pMWin)).FcsrApp
	nPeer = func() int32 {
		if (*Window)(unsafe.Pointer(pMWin)).FpOrderBy != 0 {
			return (*ExprList)(unsafe.Pointer((*Window)(unsafe.Pointer(pMWin)).FpOrderBy)).FnExpr
		}
		return 0
	}()

	lblNext = Xsqlite3VdbeMakeLabel(tls, pParse)
	lblBrk = Xsqlite3VdbeMakeLabel(tls, pParse)

	regCRowid = Xsqlite3GetTempReg(tls, pParse)
	regRowid = Xsqlite3GetTempReg(tls, pParse)
	if nPeer != 0 {
		regCPeer = Xsqlite3GetTempRange(tls, pParse, nPeer)
		regPeer = Xsqlite3GetTempRange(tls, pParse, nPeer)
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr, regCRowid)
	windowReadPeerValues(tls, p, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr, regCPeer)

	for pWin = pMWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
		Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*Window)(unsafe.Pointer(pWin)).FregAccum)
	}

	Xsqlite3VdbeAddOp3(tls, v, OP_SeekGE, csr, lblBrk, (*Window)(unsafe.Pointer(pMWin)).FregStartRowid)

	addrNext = Xsqlite3VdbeCurrentAddr(tls, v)
	Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, csr, regRowid)
	Xsqlite3VdbeAddOp3(tls, v, OP_Gt, (*Window)(unsafe.Pointer(pMWin)).FregEndRowid, lblBrk, regRowid)

	if int32((*Window)(unsafe.Pointer(pMWin)).FeExclude) == TK_CURRENT {
		Xsqlite3VdbeAddOp3(tls, v, OP_Eq, regCRowid, lblNext, regRowid)

	} else if int32((*Window)(unsafe.Pointer(pMWin)).FeExclude) != TK_NO {
		var addr int32
		var addrEq int32 = 0
		var pKeyInfo uintptr = uintptr(0)

		if (*Window)(unsafe.Pointer(pMWin)).FpOrderBy != 0 {
			pKeyInfo = Xsqlite3KeyInfoFromExprList(tls, pParse, (*Window)(unsafe.Pointer(pMWin)).FpOrderBy, 0, 0)
		}
		if int32((*Window)(unsafe.Pointer(pMWin)).FeExclude) == TK_TIES {
			addrEq = Xsqlite3VdbeAddOp3(tls, v, OP_Eq, regCRowid, 0, regRowid)

		}
		if pKeyInfo != 0 {
			windowReadPeerValues(tls, p, csr, regPeer)
			Xsqlite3VdbeAddOp3(tls, v, OP_Compare, regPeer, regCPeer, nPeer)
			Xsqlite3VdbeAppendP4(tls, v, pKeyInfo, -8)
			addr = Xsqlite3VdbeCurrentAddr(tls, v) + 1
			Xsqlite3VdbeAddOp3(tls, v, OP_Jump, addr, lblNext, addr)

		} else {
			Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, lblNext)
		}
		if addrEq != 0 {
			Xsqlite3VdbeJumpHere(tls, v, addrEq)
		}
	}

	windowAggStep(tls, p, pMWin, csr, 0, (*WindowCodeArg)(unsafe.Pointer(p)).FregArg)

	Xsqlite3VdbeResolveLabel(tls, v, lblNext)
	Xsqlite3VdbeAddOp2(tls, v, OP_Next, csr, addrNext)

	Xsqlite3VdbeJumpHere(tls, v, addrNext-1)
	Xsqlite3VdbeJumpHere(tls, v, addrNext+1)
	Xsqlite3ReleaseTempReg(tls, pParse, regRowid)
	Xsqlite3ReleaseTempReg(tls, pParse, regCRowid)
	if nPeer != 0 {
		Xsqlite3ReleaseTempRange(tls, pParse, regPeer, nPeer)
		Xsqlite3ReleaseTempRange(tls, pParse, regCPeer, nPeer)
	}

	windowAggFinal(tls, p, 1)

}

func windowReturnOneRow(tls *libc.TLS, p uintptr) {
	var pMWin uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpMWin
	var v uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpVdbe

	if (*Window)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
		windowFullScan(tls, p)
	} else {
		var pParse uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpParse
		var pWin uintptr

		for pWin = pMWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
			var pFunc uintptr = (*Window)(unsafe.Pointer(pWin)).FpWFunc

			if (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&nth_valueName)) ||
				(*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&first_valueName)) {
				var csr int32 = (*Window)(unsafe.Pointer(pWin)).FcsrApp
				var lbl int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
				var tmpReg int32 = Xsqlite3GetTempReg(tls, pParse)
				Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*Window)(unsafe.Pointer(pWin)).FregResult)

				if (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&nth_valueName)) {
					Xsqlite3VdbeAddOp3(tls, v, OP_Column, (*Window)(unsafe.Pointer(pMWin)).FiEphCsr, (*Window)(unsafe.Pointer(pWin)).FiArgCol+1, tmpReg)
					windowCheckValue(tls, pParse, tmpReg, 2)
				} else {
					Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, tmpReg)
				}
				Xsqlite3VdbeAddOp3(tls, v, OP_Add, tmpReg, (*Window)(unsafe.Pointer(pWin)).FregApp, tmpReg)
				Xsqlite3VdbeAddOp3(tls, v, OP_Gt, (*Window)(unsafe.Pointer(pWin)).FregApp+1, lbl, tmpReg)

				Xsqlite3VdbeAddOp3(tls, v, OP_SeekRowid, csr, 0, tmpReg)

				Xsqlite3VdbeAddOp3(tls, v, OP_Column, csr, (*Window)(unsafe.Pointer(pWin)).FiArgCol, (*Window)(unsafe.Pointer(pWin)).FregResult)
				Xsqlite3VdbeResolveLabel(tls, v, lbl)
				Xsqlite3ReleaseTempReg(tls, pParse, tmpReg)
			} else if (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&leadName)) || (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&lagName)) {
				var nArg int32 = (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Window)(unsafe.Pointer(pWin)).FpOwner + 32)))).FnExpr
				var csr int32 = (*Window)(unsafe.Pointer(pWin)).FcsrApp
				var lbl int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
				var tmpReg int32 = Xsqlite3GetTempReg(tls, pParse)
				var iEph int32 = (*Window)(unsafe.Pointer(pMWin)).FiEphCsr

				if nArg < 3 {
					Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*Window)(unsafe.Pointer(pWin)).FregResult)
				} else {
					Xsqlite3VdbeAddOp3(tls, v, OP_Column, iEph, (*Window)(unsafe.Pointer(pWin)).FiArgCol+2, (*Window)(unsafe.Pointer(pWin)).FregResult)
				}
				Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, iEph, tmpReg)
				if nArg < 2 {
					var val int32 = func() int32 {
						if (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&leadName)) {
							return 1
						}
						return -1
					}()
					Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, tmpReg, val)
				} else {
					var op int32 = func() int32 {
						if (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&leadName)) {
							return OP_Add
						}
						return OP_Subtract
					}()
					var tmpReg2 int32 = Xsqlite3GetTempReg(tls, pParse)
					Xsqlite3VdbeAddOp3(tls, v, OP_Column, iEph, (*Window)(unsafe.Pointer(pWin)).FiArgCol+1, tmpReg2)
					Xsqlite3VdbeAddOp3(tls, v, op, tmpReg2, tmpReg, tmpReg)
					Xsqlite3ReleaseTempReg(tls, pParse, tmpReg2)
				}

				Xsqlite3VdbeAddOp3(tls, v, OP_SeekRowid, csr, lbl, tmpReg)

				Xsqlite3VdbeAddOp3(tls, v, OP_Column, csr, (*Window)(unsafe.Pointer(pWin)).FiArgCol, (*Window)(unsafe.Pointer(pWin)).FregResult)
				Xsqlite3VdbeResolveLabel(tls, v, lbl)
				Xsqlite3ReleaseTempReg(tls, pParse, tmpReg)
			}
		}
	}
	Xsqlite3VdbeAddOp2(tls, v, OP_Gosub, (*WindowCodeArg)(unsafe.Pointer(p)).FregGosub, (*WindowCodeArg)(unsafe.Pointer(p)).FaddrGosub)
}

func windowInitAccum(tls *libc.TLS, pParse uintptr, pMWin uintptr) int32 {
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var regArg int32
	var nArg int32 = 0
	var pWin uintptr
	for pWin = pMWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
		var pFunc uintptr = (*Window)(unsafe.Pointer(pWin)).FpWFunc

		Xsqlite3VdbeAddOp2(tls, v, OP_Null, 0, (*Window)(unsafe.Pointer(pWin)).FregAccum)
		nArg = func() int32 {
			if nArg > windowArgCount(tls, pWin) {
				return nArg
			}
			return windowArgCount(tls, pWin)
		}()
		if (*Window)(unsafe.Pointer(pMWin)).FregStartRowid == 0 {
			if (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&nth_valueName)) || (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&first_valueName)) {
				Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*Window)(unsafe.Pointer(pWin)).FregApp)
				Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*Window)(unsafe.Pointer(pWin)).FregApp+1)
			}

			if (*FuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&U32(SQLITE_FUNC_MINMAX) != 0 && (*Window)(unsafe.Pointer(pWin)).FcsrApp != 0 {
				Xsqlite3VdbeAddOp1(tls, v, OP_ResetSorter, (*Window)(unsafe.Pointer(pWin)).FcsrApp)
				Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*Window)(unsafe.Pointer(pWin)).FregApp+1)
			}
		}
	}
	regArg = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += nArg
	return regArg
}

func windowCacheFrame(tls *libc.TLS, pMWin uintptr) int32 {
	var pWin uintptr
	if (*Window)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
		return 1
	}
	for pWin = pMWin; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
		var pFunc uintptr = (*Window)(unsafe.Pointer(pWin)).FpWFunc
		if (*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&nth_valueName)) ||
			(*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&first_valueName)) ||
			(*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&leadName)) ||
			(*FuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&lagName)) {
			return 1
		}
	}
	return 0
}

func windowIfNewPeer(tls *libc.TLS, pParse uintptr, pOrderBy uintptr, regNew int32, regOld int32, addr int32) {
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	if pOrderBy != 0 {
		var nVal int32 = (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr
		var pKeyInfo uintptr = Xsqlite3KeyInfoFromExprList(tls, pParse, pOrderBy, 0, 0)
		Xsqlite3VdbeAddOp3(tls, v, OP_Compare, regOld, regNew, nVal)
		Xsqlite3VdbeAppendP4(tls, v, pKeyInfo, -8)
		Xsqlite3VdbeAddOp3(tls, v, OP_Jump,
			Xsqlite3VdbeCurrentAddr(tls, v)+1, addr, Xsqlite3VdbeCurrentAddr(tls, v)+1)

		Xsqlite3VdbeAddOp3(tls, v, OP_Copy, regNew, regOld, nVal-1)
	} else {
		Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addr)
	}
}

func windowCodeRangeTest(tls *libc.TLS, p uintptr, op int32, csr1 int32, regVal int32, csr2 int32, lbl int32) {
	var pParse uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpParse
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var pOrderBy uintptr = (*Window)(unsafe.Pointer((*WindowCodeArg)(unsafe.Pointer(p)).FpMWin)).FpOrderBy
	var reg1 int32 = Xsqlite3GetTempReg(tls, pParse)
	var reg2 int32 = Xsqlite3GetTempReg(tls, pParse)
	var regString int32 = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	var arith int32 = OP_Add
	var addrGe int32
	var addrDone int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
	var pColl uintptr

	windowReadPeerValues(tls, p, csr1, reg1)
	windowReadPeerValues(tls, p, csr2, reg2)

	if int32((*ExprList_item)(unsafe.Pointer(pOrderBy+8)).Ffg.FsortFlags)&KEYINFO_ORDER_DESC != 0 {
		switch op {
		case OP_Ge:
			op = OP_Le
			break
			fallthrough
		case OP_Gt:
			op = OP_Lt
			break
			fallthrough
		default:
			op = OP_Ge
			break
		}
		arith = OP_Subtract
	}

	if int32((*ExprList_item)(unsafe.Pointer(pOrderBy+8)).Ffg.FsortFlags)&KEYINFO_ORDER_BIGNULL != 0 {
		var addr int32 = Xsqlite3VdbeAddOp1(tls, v, OP_NotNull, reg1)
		switch op {
		case OP_Ge:
			Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, lbl)
			break
			fallthrough
		case OP_Gt:
			Xsqlite3VdbeAddOp2(tls, v, OP_NotNull, reg2, lbl)

			break
			fallthrough
		case OP_Le:
			Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, reg2, lbl)

			break
			fallthrough
		default:
			break
		}
		Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addrDone)

		Xsqlite3VdbeJumpHere(tls, v, addr)
		Xsqlite3VdbeAddOp2(tls, v, OP_IsNull, reg2,
			func() int32 {
				if op == OP_Gt || op == OP_Ge {
					return addrDone
				}
				return lbl
			}())

	}

	Xsqlite3VdbeAddOp4(tls, v, OP_String8, 0, regString, 0, ts+1636, -1)
	addrGe = Xsqlite3VdbeAddOp3(tls, v, OP_Ge, regString, 0, reg1)

	if op == OP_Ge && arith == OP_Add || op == OP_Le && arith == OP_Subtract {
		Xsqlite3VdbeAddOp3(tls, v, op, reg2, lbl, reg1)
	}
	Xsqlite3VdbeAddOp3(tls, v, arith, regVal, reg1, reg1)
	Xsqlite3VdbeJumpHere(tls, v, addrGe)

	Xsqlite3VdbeAddOp3(tls, v, op, reg2, lbl, reg1)
	pColl = Xsqlite3ExprNNCollSeq(tls, pParse, (*ExprList_item)(unsafe.Pointer(pOrderBy+8)).FpExpr)
	Xsqlite3VdbeAppendP4(tls, v, pColl, -2)
	Xsqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
	Xsqlite3VdbeResolveLabel(tls, v, addrDone)

	Xsqlite3ReleaseTempReg(tls, pParse, reg1)
	Xsqlite3ReleaseTempReg(tls, pParse, reg2)

}

func windowCodeOp(tls *libc.TLS, p uintptr, op int32, regCountdown int32, jumpOnEof int32) int32 {
	var csr int32
	var reg int32
	var pParse uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpParse
	var pMWin uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpMWin
	var ret int32 = 0
	var v uintptr = (*WindowCodeArg)(unsafe.Pointer(p)).FpVdbe
	var addrContinue int32 = 0
	var bPeer int32 = libc.Bool32(int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) != TK_ROWS)

	var lblDone int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
	var addrNextRange int32 = 0

	if op == WINDOW_AGGINVERSE && int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_UNBOUNDED {
		return 0
	}

	if regCountdown > 0 {
		if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE {
			addrNextRange = Xsqlite3VdbeCurrentAddr(tls, v)

			if op == WINDOW_AGGINVERSE {
				if int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_FOLLOWING {
					windowCodeRangeTest(tls,
						p, OP_Le, (*WindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Fcsr, regCountdown, (*WindowCodeArg)(unsafe.Pointer(p)).Fstart.Fcsr, lblDone)
				} else {
					windowCodeRangeTest(tls,
						p, OP_Ge, (*WindowCodeArg)(unsafe.Pointer(p)).Fstart.Fcsr, regCountdown, (*WindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Fcsr, lblDone)
				}
			} else {
				windowCodeRangeTest(tls,
					p, OP_Gt, (*WindowCodeArg)(unsafe.Pointer(p)).Fend.Fcsr, regCountdown, (*WindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Fcsr, lblDone)
			}
		} else {
			Xsqlite3VdbeAddOp3(tls, v, OP_IfPos, regCountdown, lblDone, 1)

		}
	}

	if op == WINDOW_RETURN_ROW && (*Window)(unsafe.Pointer(pMWin)).FregStartRowid == 0 {
		windowAggFinal(tls, p, 0)
	}
	addrContinue = Xsqlite3VdbeCurrentAddr(tls, v)

	if int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) && regCountdown != 0 &&
		int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE {
		var regRowid1 int32 = Xsqlite3GetTempReg(tls, pParse)
		var regRowid2 int32 = Xsqlite3GetTempReg(tls, pParse)
		if op == WINDOW_AGGINVERSE {
			Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, (*WindowCodeArg)(unsafe.Pointer(p)).Fstart.Fcsr, regRowid1)
			Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, (*WindowCodeArg)(unsafe.Pointer(p)).Fend.Fcsr, regRowid2)
			Xsqlite3VdbeAddOp3(tls, v, OP_Ge, regRowid2, lblDone, regRowid1)

		} else if (*WindowCodeArg)(unsafe.Pointer(p)).FregRowid != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_Rowid, (*WindowCodeArg)(unsafe.Pointer(p)).Fend.Fcsr, regRowid1)
			Xsqlite3VdbeAddOp3(tls, v, OP_Ge, (*WindowCodeArg)(unsafe.Pointer(p)).FregRowid, lblDone, regRowid1)

		}
		Xsqlite3ReleaseTempReg(tls, pParse, regRowid1)
		Xsqlite3ReleaseTempReg(tls, pParse, regRowid2)

	}

	switch op {
	case WINDOW_RETURN_ROW:
		csr = (*WindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Fcsr
		reg = (*WindowCodeArg)(unsafe.Pointer(p)).Fcurrent.Freg
		windowReturnOneRow(tls, p)
		break

	case WINDOW_AGGINVERSE:
		csr = (*WindowCodeArg)(unsafe.Pointer(p)).Fstart.Fcsr
		reg = (*WindowCodeArg)(unsafe.Pointer(p)).Fstart.Freg
		if (*Window)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, (*Window)(unsafe.Pointer(pMWin)).FregStartRowid, 1)
		} else {
			windowAggStep(tls, p, pMWin, csr, 1, (*WindowCodeArg)(unsafe.Pointer(p)).FregArg)
		}
		break

	default:
		csr = (*WindowCodeArg)(unsafe.Pointer(p)).Fend.Fcsr
		reg = (*WindowCodeArg)(unsafe.Pointer(p)).Fend.Freg
		if (*Window)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_AddImm, (*Window)(unsafe.Pointer(pMWin)).FregEndRowid, 1)
		} else {
			windowAggStep(tls, p, pMWin, csr, 0, (*WindowCodeArg)(unsafe.Pointer(p)).FregArg)
		}
		break
	}

	if op == (*WindowCodeArg)(unsafe.Pointer(p)).FeDelete {
		Xsqlite3VdbeAddOp1(tls, v, OP_Delete, csr)
		Xsqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_SAVEPOSITION))
	}

	if jumpOnEof != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_Next, csr, Xsqlite3VdbeCurrentAddr(tls, v)+2)

		ret = Xsqlite3VdbeAddOp0(tls, v, OP_Goto)
	} else {
		Xsqlite3VdbeAddOp2(tls, v, OP_Next, csr, Xsqlite3VdbeCurrentAddr(tls, v)+1+bPeer)

		if bPeer != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, lblDone)
		}
	}

	if bPeer != 0 {
		var nReg int32 = func() int32 {
			if (*Window)(unsafe.Pointer(pMWin)).FpOrderBy != 0 {
				return (*ExprList)(unsafe.Pointer((*Window)(unsafe.Pointer(pMWin)).FpOrderBy)).FnExpr
			}
			return 0
		}()
		var regTmp int32 = func() int32 {
			if nReg != 0 {
				return Xsqlite3GetTempRange(tls, pParse, nReg)
			}
			return 0
		}()
		windowReadPeerValues(tls, p, csr, regTmp)
		windowIfNewPeer(tls, pParse, (*Window)(unsafe.Pointer(pMWin)).FpOrderBy, regTmp, reg, addrContinue)
		Xsqlite3ReleaseTempRange(tls, pParse, regTmp, nReg)
	}

	if addrNextRange != 0 {
		Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addrNextRange)
	}
	Xsqlite3VdbeResolveLabel(tls, v, lblDone)
	return ret
}

func Xsqlite3WindowDup(tls *libc.TLS, db uintptr, pOwner uintptr, p uintptr) uintptr {
	var pNew uintptr = uintptr(0)
	if p != 0 {
		pNew = Xsqlite3DbMallocZero(tls, db, uint64(unsafe.Sizeof(Window{})))
		if pNew != 0 {
			(*Window)(unsafe.Pointer(pNew)).FzName = Xsqlite3DbStrDup(tls, db, (*Window)(unsafe.Pointer(p)).FzName)
			(*Window)(unsafe.Pointer(pNew)).FzBase = Xsqlite3DbStrDup(tls, db, (*Window)(unsafe.Pointer(p)).FzBase)
			(*Window)(unsafe.Pointer(pNew)).FpFilter = Xsqlite3ExprDup(tls, db, (*Window)(unsafe.Pointer(p)).FpFilter, 0)
			(*Window)(unsafe.Pointer(pNew)).FpWFunc = (*Window)(unsafe.Pointer(p)).FpWFunc
			(*Window)(unsafe.Pointer(pNew)).FpPartition = Xsqlite3ExprListDup(tls, db, (*Window)(unsafe.Pointer(p)).FpPartition, 0)
			(*Window)(unsafe.Pointer(pNew)).FpOrderBy = Xsqlite3ExprListDup(tls, db, (*Window)(unsafe.Pointer(p)).FpOrderBy, 0)
			(*Window)(unsafe.Pointer(pNew)).FeFrmType = (*Window)(unsafe.Pointer(p)).FeFrmType
			(*Window)(unsafe.Pointer(pNew)).FeEnd = (*Window)(unsafe.Pointer(p)).FeEnd
			(*Window)(unsafe.Pointer(pNew)).FeStart = (*Window)(unsafe.Pointer(p)).FeStart
			(*Window)(unsafe.Pointer(pNew)).FeExclude = (*Window)(unsafe.Pointer(p)).FeExclude
			(*Window)(unsafe.Pointer(pNew)).FregResult = (*Window)(unsafe.Pointer(p)).FregResult
			(*Window)(unsafe.Pointer(pNew)).FregAccum = (*Window)(unsafe.Pointer(p)).FregAccum
			(*Window)(unsafe.Pointer(pNew)).FiArgCol = (*Window)(unsafe.Pointer(p)).FiArgCol
			(*Window)(unsafe.Pointer(pNew)).FiEphCsr = (*Window)(unsafe.Pointer(p)).FiEphCsr
			(*Window)(unsafe.Pointer(pNew)).FbExprArgs = (*Window)(unsafe.Pointer(p)).FbExprArgs
			(*Window)(unsafe.Pointer(pNew)).FpStart = Xsqlite3ExprDup(tls, db, (*Window)(unsafe.Pointer(p)).FpStart, 0)
			(*Window)(unsafe.Pointer(pNew)).FpEnd = Xsqlite3ExprDup(tls, db, (*Window)(unsafe.Pointer(p)).FpEnd, 0)
			(*Window)(unsafe.Pointer(pNew)).FpOwner = pOwner
			(*Window)(unsafe.Pointer(pNew)).FbImplicitFrame = (*Window)(unsafe.Pointer(p)).FbImplicitFrame
		}
	}
	return pNew
}

func Xsqlite3WindowListDup(tls *libc.TLS, db uintptr, p uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pWin uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var pp uintptr = bp

	for pWin = p; pWin != 0; pWin = (*Window)(unsafe.Pointer(pWin)).FpNextWin {
		*(*uintptr)(unsafe.Pointer(pp)) = Xsqlite3WindowDup(tls, db, uintptr(0), pWin)
		if *(*uintptr)(unsafe.Pointer(pp)) == uintptr(0) {
			break
		}
		pp = *(*uintptr)(unsafe.Pointer(pp)) + 64
	}

	return *(*uintptr)(unsafe.Pointer(bp))
}

func windowExprGtZero(tls *libc.TLS, pParse uintptr, pExpr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var ret int32 = 0
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	Xsqlite3ValueFromExpr(tls, db, pExpr, (*Sqlite3)(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 = 1
	}
	Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return ret
}

func Xsqlite3WindowCodeStep(tls *libc.TLS, pParse uintptr, p uintptr, pWInfo uintptr, regGosub int32, addrGosub int32) {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var pMWin uintptr = (*Select)(unsafe.Pointer(p)).FpWin
	var pOrderBy uintptr = (*Window)(unsafe.Pointer(pMWin)).FpOrderBy
	var v uintptr = Xsqlite3GetVdbe(tls, pParse)
	var csrWrite int32
	var csrInput int32 = (*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FiCursor
	var nInput int32 = int32((*Table)(unsafe.Pointer((*SrcItem)(unsafe.Pointer((*Select)(unsafe.Pointer(p)).FpSrc + 8)).FpTab)).FnCol)
	var iInput int32
	var addrNe int32
	var addrGosubFlush int32 = 0
	var addrInteger int32 = 0
	var addrEmpty int32
	var regNew int32
	var regRecord int32
	var regNewPeer int32 = 0
	var regPeer int32 = 0
	var regFlushPart int32 = 0

	var lblWhereEnd int32
	var regStart int32 = 0
	var regEnd int32 = 0

	lblWhereEnd = Xsqlite3VdbeMakeLabel(tls, pParse)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(WindowCodeArg{})))
	(*WindowCodeArg)(unsafe.Pointer(bp)).FpParse = pParse
	(*WindowCodeArg)(unsafe.Pointer(bp)).FpMWin = pMWin
	(*WindowCodeArg)(unsafe.Pointer(bp)).FpVdbe = v
	(*WindowCodeArg)(unsafe.Pointer(bp)).FregGosub = regGosub
	(*WindowCodeArg)(unsafe.Pointer(bp)).FaddrGosub = addrGosub
	(*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr = (*Window)(unsafe.Pointer(pMWin)).FiEphCsr
	csrWrite = (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr + 1
	(*WindowCodeArg)(unsafe.Pointer(bp)).Fstart.Fcsr = (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr + 2
	(*WindowCodeArg)(unsafe.Pointer(bp)).Fend.Fcsr = (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr + 3

	switch int32((*Window)(unsafe.Pointer(pMWin)).FeStart) {
	case TK_FOLLOWING:
		if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) != TK_RANGE &&
			windowExprGtZero(tls, pParse, (*Window)(unsafe.Pointer(pMWin)).FpStart) != 0 {
			(*WindowCodeArg)(unsafe.Pointer(bp)).FeDelete = WINDOW_RETURN_ROW
		}
		break
	case TK_UNBOUNDED:
		if windowCacheFrame(tls, pMWin) == 0 {
			if int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) == TK_PRECEDING {
				if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) != TK_RANGE &&
					windowExprGtZero(tls, pParse, (*Window)(unsafe.Pointer(pMWin)).FpEnd) != 0 {
					(*WindowCodeArg)(unsafe.Pointer(bp)).FeDelete = WINDOW_AGGSTEP
				}
			} else {
				(*WindowCodeArg)(unsafe.Pointer(bp)).FeDelete = WINDOW_RETURN_ROW
			}
		}
		break
	default:
		(*WindowCodeArg)(unsafe.Pointer(bp)).FeDelete = WINDOW_AGGINVERSE
		break
	}

	regNew = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
	*(*int32)(unsafe.Pointer(pParse + 56)) += nInput
	regRecord = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	(*WindowCodeArg)(unsafe.Pointer(bp)).FregRowid = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)

	if int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_PRECEDING || int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_FOLLOWING {
		regStart = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	}
	if int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) == TK_PRECEDING || int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) == TK_FOLLOWING {
		regEnd = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
	}

	if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) != TK_ROWS {
		var nPeer int32 = func() int32 {
			if pOrderBy != 0 {
				return (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr
			}
			return 0
		}()
		regNewPeer = regNew + (*Window)(unsafe.Pointer(pMWin)).FnBufferCol
		if (*Window)(unsafe.Pointer(pMWin)).FpPartition != 0 {
			regNewPeer = regNewPeer + (*ExprList)(unsafe.Pointer((*Window)(unsafe.Pointer(pMWin)).FpPartition)).FnExpr
		}
		regPeer = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nPeer
		(*WindowCodeArg)(unsafe.Pointer(bp)).Fstart.Freg = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nPeer
		(*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Freg = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nPeer
		(*WindowCodeArg)(unsafe.Pointer(bp)).Fend.Freg = (*Parse)(unsafe.Pointer(pParse)).FnMem + 1
		*(*int32)(unsafe.Pointer(pParse + 56)) += nPeer
	}

	for iInput = 0; iInput < nInput; iInput++ {
		Xsqlite3VdbeAddOp3(tls, v, OP_Column, csrInput, iInput, regNew+iInput)
	}
	Xsqlite3VdbeAddOp3(tls, v, OP_MakeRecord, regNew, nInput, regRecord)

	if (*Window)(unsafe.Pointer(pMWin)).FpPartition != 0 {
		var addr int32
		var pPart uintptr = (*Window)(unsafe.Pointer(pMWin)).FpPartition
		var nPart int32 = (*ExprList)(unsafe.Pointer(pPart)).FnExpr
		var regNewPart int32 = regNew + (*Window)(unsafe.Pointer(pMWin)).FnBufferCol
		var pKeyInfo uintptr = Xsqlite3KeyInfoFromExprList(tls, pParse, pPart, 0, 0)

		regFlushPart = libc.PreIncInt32(&(*Parse)(unsafe.Pointer(pParse)).FnMem, 1)
		addr = Xsqlite3VdbeAddOp3(tls, v, OP_Compare, regNewPart, (*Window)(unsafe.Pointer(pMWin)).FregPart, nPart)
		Xsqlite3VdbeAppendP4(tls, v, pKeyInfo, -8)
		Xsqlite3VdbeAddOp3(tls, v, OP_Jump, addr+2, addr+4, addr+2)

		addrGosubFlush = Xsqlite3VdbeAddOp1(tls, v, OP_Gosub, regFlushPart)
		Xsqlite3VdbeComment(tls, v, ts+27374, 0)
		Xsqlite3VdbeAddOp3(tls, v, OP_Copy, regNewPart, (*Window)(unsafe.Pointer(pMWin)).FregPart, nPart-1)
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_NewRowid, csrWrite, (*WindowCodeArg)(unsafe.Pointer(bp)).FregRowid)
	Xsqlite3VdbeAddOp3(tls, v, OP_Insert, csrWrite, regRecord, (*WindowCodeArg)(unsafe.Pointer(bp)).FregRowid)
	addrNe = Xsqlite3VdbeAddOp3(tls, v, OP_Ne, (*Window)(unsafe.Pointer(pMWin)).FregOne, 0, (*WindowCodeArg)(unsafe.Pointer(bp)).FregRowid)

	(*WindowCodeArg)(unsafe.Pointer(bp)).FregArg = windowInitAccum(tls, pParse, pMWin)

	if regStart != 0 {
		Xsqlite3ExprCode(tls, pParse, (*Window)(unsafe.Pointer(pMWin)).FpStart, regStart)
		windowCheckValue(tls, pParse, regStart, 0+func() int32 {
			if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE {
				return 3
			}
			return 0
		}())
	}
	if regEnd != 0 {
		Xsqlite3ExprCode(tls, pParse, (*Window)(unsafe.Pointer(pMWin)).FpEnd, regEnd)
		windowCheckValue(tls, pParse, regEnd, 1+func() int32 {
			if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE {
				return 3
			}
			return 0
		}())
	}

	if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) != TK_RANGE && int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) && regStart != 0 {
		var op int32 = func() int32 {
			if int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_FOLLOWING {
				return OP_Ge
			}
			return OP_Le
		}()
		var addrGe int32 = Xsqlite3VdbeAddOp3(tls, v, op, regStart, 0, regEnd)

		windowAggFinal(tls, bp, 0)
		Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr)
		windowReturnOneRow(tls, bp)
		Xsqlite3VdbeAddOp1(tls, v, OP_ResetSorter, (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr)
		Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, lblWhereEnd)
		Xsqlite3VdbeJumpHere(tls, v, addrGe)
	}
	if int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_FOLLOWING && int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) != TK_RANGE && regEnd != 0 {
		Xsqlite3VdbeAddOp3(tls, v, OP_Subtract, regStart, regEnd, regStart)
	}

	if int32((*Window)(unsafe.Pointer(pMWin)).FeStart) != TK_UNBOUNDED {
		Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, (*WindowCodeArg)(unsafe.Pointer(bp)).Fstart.Fcsr)
	}
	Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr)
	Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, (*WindowCodeArg)(unsafe.Pointer(bp)).Fend.Fcsr)
	if regPeer != 0 && pOrderBy != 0 {
		Xsqlite3VdbeAddOp3(tls, v, OP_Copy, regNewPeer, regPeer, (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr-1)
		Xsqlite3VdbeAddOp3(tls, v, OP_Copy, regPeer, (*WindowCodeArg)(unsafe.Pointer(bp)).Fstart.Freg, (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr-1)
		Xsqlite3VdbeAddOp3(tls, v, OP_Copy, regPeer, (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Freg, (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr-1)
		Xsqlite3VdbeAddOp3(tls, v, OP_Copy, regPeer, (*WindowCodeArg)(unsafe.Pointer(bp)).Fend.Freg, (*ExprList)(unsafe.Pointer(pOrderBy)).FnExpr-1)
	}

	Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, lblWhereEnd)

	Xsqlite3VdbeJumpHere(tls, v, addrNe)

	if regPeer != 0 {
		windowIfNewPeer(tls, pParse, pOrderBy, regNewPeer, regPeer, lblWhereEnd)
	}
	if int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_FOLLOWING {
		windowCodeOp(tls, bp, WINDOW_AGGSTEP, 0, 0)
		if int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) != TK_UNBOUNDED {
			if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE {
				var lbl int32 = Xsqlite3VdbeMakeLabel(tls, pParse)
				var addrNext int32 = Xsqlite3VdbeCurrentAddr(tls, v)
				windowCodeRangeTest(tls, bp, OP_Ge, (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr, regEnd, (*WindowCodeArg)(unsafe.Pointer(bp)).Fend.Fcsr, lbl)
				windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 0)
				windowCodeOp(tls, bp, WINDOW_RETURN_ROW, 0, 0)
				Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addrNext)
				Xsqlite3VdbeResolveLabel(tls, v, lbl)
			} else {
				windowCodeOp(tls, bp, WINDOW_RETURN_ROW, regEnd, 0)
				windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 0)
			}
		}
	} else if int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) == TK_PRECEDING {
		var bRPS int32 = libc.Bool32(int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_PRECEDING && int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE)
		windowCodeOp(tls, bp, WINDOW_AGGSTEP, regEnd, 0)
		if bRPS != 0 {
			windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 0)
		}
		windowCodeOp(tls, bp, WINDOW_RETURN_ROW, 0, 0)
		if !(bRPS != 0) {
			windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 0)
		}
	} else {
		var addr int32 = 0
		windowCodeOp(tls, bp, WINDOW_AGGSTEP, 0, 0)
		if int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) != TK_UNBOUNDED {
			if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE {
				var lbl int32 = 0
				addr = Xsqlite3VdbeCurrentAddr(tls, v)
				if regEnd != 0 {
					lbl = Xsqlite3VdbeMakeLabel(tls, pParse)
					windowCodeRangeTest(tls, bp, OP_Ge, (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr, regEnd, (*WindowCodeArg)(unsafe.Pointer(bp)).Fend.Fcsr, lbl)
				}
				windowCodeOp(tls, bp, WINDOW_RETURN_ROW, 0, 0)
				windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 0)
				if regEnd != 0 {
					Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addr)
					Xsqlite3VdbeResolveLabel(tls, v, lbl)
				}
			} else {
				if regEnd != 0 {
					addr = Xsqlite3VdbeAddOp3(tls, v, OP_IfPos, regEnd, 0, 1)

				}
				windowCodeOp(tls, bp, WINDOW_RETURN_ROW, 0, 0)
				windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 0)
				if regEnd != 0 {
					Xsqlite3VdbeJumpHere(tls, v, addr)
				}
			}
		}
	}

	Xsqlite3VdbeResolveLabel(tls, v, lblWhereEnd)
	Xsqlite3WhereEnd(tls, pWInfo)

	if (*Window)(unsafe.Pointer(pMWin)).FpPartition != 0 {
		addrInteger = Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, regFlushPart)
		Xsqlite3VdbeJumpHere(tls, v, addrGosubFlush)
	}

	(*WindowCodeArg)(unsafe.Pointer(bp)).FregRowid = 0
	addrEmpty = Xsqlite3VdbeAddOp1(tls, v, OP_Rewind, csrWrite)

	if int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) == TK_PRECEDING {
		var bRPS int32 = libc.Bool32(int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_PRECEDING && int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE)
		windowCodeOp(tls, bp, WINDOW_AGGSTEP, regEnd, 0)
		if bRPS != 0 {
			windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 0)
		}
		windowCodeOp(tls, bp, WINDOW_RETURN_ROW, 0, 0)
	} else if int32((*Window)(unsafe.Pointer(pMWin)).FeStart) == TK_FOLLOWING {
		var addrStart int32
		var addrBreak1 int32
		var addrBreak2 int32
		var addrBreak3 int32
		windowCodeOp(tls, bp, WINDOW_AGGSTEP, 0, 0)
		if int32((*Window)(unsafe.Pointer(pMWin)).FeFrmType) == TK_RANGE {
			addrStart = Xsqlite3VdbeCurrentAddr(tls, v)
			addrBreak2 = windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 1)
			addrBreak1 = windowCodeOp(tls, bp, WINDOW_RETURN_ROW, 0, 1)
		} else if int32((*Window)(unsafe.Pointer(pMWin)).FeEnd) == TK_UNBOUNDED {
			addrStart = Xsqlite3VdbeCurrentAddr(tls, v)
			addrBreak1 = windowCodeOp(tls, bp, WINDOW_RETURN_ROW, regStart, 1)
			addrBreak2 = windowCodeOp(tls, bp, WINDOW_AGGINVERSE, 0, 1)
		} else {
			addrStart = Xsqlite3VdbeCurrentAddr(tls, v)
			addrBreak1 = windowCodeOp(tls, bp, WINDOW_RETURN_ROW, regEnd, 1)
			addrBreak2 = windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 1)
		}
		Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addrStart)
		Xsqlite3VdbeJumpHere(tls, v, addrBreak2)
		addrStart = Xsqlite3VdbeCurrentAddr(tls, v)
		addrBreak3 = windowCodeOp(tls, bp, WINDOW_RETURN_ROW, 0, 1)
		Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addrStart)
		Xsqlite3VdbeJumpHere(tls, v, addrBreak1)
		Xsqlite3VdbeJumpHere(tls, v, addrBreak3)
	} else {
		var addrBreak int32
		var addrStart int32
		windowCodeOp(tls, bp, WINDOW_AGGSTEP, 0, 0)
		addrStart = Xsqlite3VdbeCurrentAddr(tls, v)
		addrBreak = windowCodeOp(tls, bp, WINDOW_RETURN_ROW, 0, 1)
		windowCodeOp(tls, bp, WINDOW_AGGINVERSE, regStart, 0)
		Xsqlite3VdbeAddOp2(tls, v, OP_Goto, 0, addrStart)
		Xsqlite3VdbeJumpHere(tls, v, addrBreak)
	}
	Xsqlite3VdbeJumpHere(tls, v, addrEmpty)

	Xsqlite3VdbeAddOp1(tls, v, OP_ResetSorter, (*WindowCodeArg)(unsafe.Pointer(bp)).Fcurrent.Fcsr)
	if (*Window)(unsafe.Pointer(pMWin)).FpPartition != 0 {
		if (*Window)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 1, (*Window)(unsafe.Pointer(pMWin)).FregStartRowid)
			Xsqlite3VdbeAddOp2(tls, v, OP_Integer, 0, (*Window)(unsafe.Pointer(pMWin)).FregEndRowid)
		}
		Xsqlite3VdbeChangeP1(tls, v, addrInteger, Xsqlite3VdbeCurrentAddr(tls, v))
		Xsqlite3VdbeAddOp1(tls, v, OP_Return, regFlushPart)
	}
}

type TrigEvent = struct {
	Fa           int32
	F__ccgo_pad1 [4]byte
	Fb           uintptr
}

type FrameBound = struct {
	FeType       int32
	F__ccgo_pad1 [4]byte
	FpExpr       uintptr
}

func disableLookaside(tls *libc.TLS, pParse uintptr) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	(*Parse)(unsafe.Pointer(pParse)).FdisableLookaside++
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable++
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)
}

func parserDoubleLinkSelect(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Select)(unsafe.Pointer(p)).FpPrior != 0 {
		var pNext uintptr = uintptr(0)
		var pLoop uintptr = p
		var mxSelect int32
		var cnt int32 = 1
		for 1 != 0 {
			(*Select)(unsafe.Pointer(pLoop)).FpNext = pNext
			*(*U32)(unsafe.Pointer(pLoop + 4)) |= U32(SF_Compound)
			pNext = pLoop
			pLoop = (*Select)(unsafe.Pointer(pLoop)).FpPrior
			if pLoop == uintptr(0) {
				break
			}
			cnt++
			if (*Select)(unsafe.Pointer(pLoop)).FpOrderBy != 0 || (*Select)(unsafe.Pointer(pLoop)).FpLimit != 0 {
				Xsqlite3ErrorMsg(tls, pParse, ts+27395,
					libc.VaList(bp, func() uintptr {
						if (*Select)(unsafe.Pointer(pLoop)).FpOrderBy != uintptr(0) {
							return ts + 27437
						}
						return ts + 27446
					}(),
						Xsqlite3SelectOpName(tls, int32((*Select)(unsafe.Pointer(pNext)).Fop))))
				break
			}
		}
		if (*Select)(unsafe.Pointer(p)).FselFlags&U32(SF_MultiValue) == U32(0) && libc.AssignInt32(&mxSelect, *(*int32)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb + 136 + 4*4))) > 0 && cnt > mxSelect {
			Xsqlite3ErrorMsg(tls, pParse, ts+27452, 0)
		}
	}

}

func attachWithToSelect(tls *libc.TLS, pParse uintptr, pSelect uintptr, pWith uintptr) uintptr {
	if pSelect != 0 {
		(*Select)(unsafe.Pointer(pSelect)).FpWith = pWith
		parserDoubleLinkSelect(tls, pParse, pSelect)
	} else {
		Xsqlite3WithDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pWith)
	}
	return pSelect

}

func tokenExpr(tls *libc.TLS, pParse uintptr, op int32, t Token) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*Token)(unsafe.Pointer(bp)) = t

	var p uintptr = Xsqlite3DbMallocRawNN(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(Expr{}))+uint64((*Token)(unsafe.Pointer(bp)).Fn)+uint64(1))
	if p != 0 {
		(*Expr)(unsafe.Pointer(p)).Fop = U8(op)
		(*Expr)(unsafe.Pointer(p)).FaffExpr = uint8(0)
		(*Expr)(unsafe.Pointer(p)).Fflags = U32(EP_Leaf)

		(*Expr)(unsafe.Pointer(p)).FpLeft = libc.AssignPtrUintptr(p+24, uintptr(0))
		(*Expr)(unsafe.Pointer(p)).FpAggInfo = uintptr(0)
		libc.Xmemset(tls, p+32, 0, uint64(unsafe.Sizeof(struct{ FpList uintptr }{})))
		libc.Xmemset(tls, p+64, 0, uint64(unsafe.Sizeof(struct{ FpTab uintptr }{})))
		(*Expr)(unsafe.Pointer(p)).Fop2 = U8(0)
		(*Expr)(unsafe.Pointer(p)).FiTable = 0
		(*Expr)(unsafe.Pointer(p)).FiColumn = int16(0)
		*(*uintptr)(unsafe.Pointer(p + 8)) = p + 1*72
		libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(p + 8)), (*Token)(unsafe.Pointer(bp)).Fz, uint64((*Token)(unsafe.Pointer(bp)).Fn))
		*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8)) + uintptr((*Token)(unsafe.Pointer(bp)).Fn))) = uint8(0)
		*(*int32)(unsafe.Pointer(p + 52)) = int32((int64((*Token)(unsafe.Pointer(bp)).Fz) - int64((*Parse)(unsafe.Pointer(pParse)).FzTail)) / 1)
		if int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 8))))])&0x80 != 0 {
			Xsqlite3DequoteExpr(tls, p)
		}
		(*Expr)(unsafe.Pointer(p)).FnHeight = 1
		if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
			return Xsqlite3RenameTokenMap(tls, pParse, p, bp)
		}
	}
	return p

}

func binaryToUnaryIfNull(tls *libc.TLS, pParse uintptr, pY uintptr, pA uintptr, op int32) {
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	if pA != 0 && pY != 0 && int32((*Expr)(unsafe.Pointer(pY)).Fop) == TK_NULL && !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		(*Expr)(unsafe.Pointer(pA)).Fop = U8(op)
		Xsqlite3ExprDelete(tls, db, (*Expr)(unsafe.Pointer(pA)).FpRight)
		(*Expr)(unsafe.Pointer(pA)).FpRight = uintptr(0)
	}

}

func parserAddExprIdListTerm(tls *libc.TLS, pParse uintptr, pPrior uintptr, pIdToken uintptr, hasCollate int32, sortOrder int32) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var p uintptr = Xsqlite3ExprListAppend(tls, pParse, pPrior, uintptr(0))
	if (hasCollate != 0 || sortOrder != -1) &&
		int32((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Finit.Fbusy) == 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+27486,
			libc.VaList(bp, (*Token)(unsafe.Pointer(pIdToken)).Fn, (*Token)(unsafe.Pointer(pIdToken)).Fz))
	}
	Xsqlite3ExprListSetName(tls, pParse, p, pIdToken, 1)
	return p

}

type YYMINORTYPE = struct {
	F__ccgo_pad1 [0]uint64
	Fyyinit      int32
	F__ccgo_pad2 [12]byte
}

var yy_action = [2098]uint16{
	uint16(568), uint16(208), uint16(568), uint16(118), uint16(115), uint16(229), uint16(568), uint16(118), uint16(115), uint16(229),
	uint16(568), uint16(1314), uint16(377), uint16(1293), uint16(408), uint16(562), uint16(562), uint16(562), uint16(568), uint16(409),
	uint16(378), uint16(1314), uint16(1276), uint16(41), uint16(41), uint16(41), uint16(41), uint16(208), uint16(1526), uint16(71),
	uint16(71), uint16(971), uint16(419), uint16(41), uint16(41), uint16(491), uint16(303), uint16(279), uint16(303), uint16(972),
	uint16(397), uint16(71), uint16(71), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217), uint16(1050), uint16(1053),
	uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124), uint16(476), uint16(409),
	uint16(1241), uint16(1), uint16(1), uint16(575), uint16(2), uint16(1245), uint16(550), uint16(118), uint16(115), uint16(229),
	uint16(317), uint16(480), uint16(146), uint16(480), uint16(524), uint16(118), uint16(115), uint16(229), uint16(529), uint16(1327),
	uint16(417), uint16(523), uint16(142), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217), uint16(1050), uint16(1053),
	uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124), uint16(118), uint16(115),
	uint16(229), uint16(327), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120), uint16(120),
	uint16(120), uint16(119), uint16(116), uint16(444), uint16(284), uint16(284), uint16(284), uint16(284), uint16(442), uint16(442),
	uint16(442), uint16(1567), uint16(376), uint16(1569), uint16(1192), uint16(375), uint16(1163), uint16(565), uint16(1163), uint16(565),
	uint16(409), uint16(1567), uint16(537), uint16(259), uint16(226), uint16(444), uint16(101), uint16(145), uint16(449), uint16(316),
	uint16(559), uint16(240), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120), uint16(120),
	uint16(120), uint16(119), uint16(116), uint16(444), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217), uint16(1050),
	uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124), uint16(142),
	uint16(294), uint16(1192), uint16(339), uint16(448), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444),
	uint16(127), uint16(1192), uint16(1193), uint16(1194), uint16(148), uint16(441), uint16(440), uint16(568), uint16(119), uint16(116),
	uint16(444), uint16(124), uint16(124), uint16(124), uint16(124), uint16(117), uint16(122), uint16(122), uint16(122), uint16(122),
	uint16(121), uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(454), uint16(113),
	uint16(13), uint16(13), uint16(546), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120),
	uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(422), uint16(316), uint16(559), uint16(1192), uint16(1193),
	uint16(1194), uint16(149), uint16(1224), uint16(409), uint16(1224), uint16(124), uint16(124), uint16(124), uint16(124), uint16(122),
	uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116),
	uint16(444), uint16(465), uint16(342), uint16(1037), uint16(1037), uint16(1051), uint16(1054), uint16(125), uint16(126), uint16(80),
	uint16(1217), uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124),
	uint16(124), uint16(124), uint16(1279), uint16(522), uint16(222), uint16(1192), uint16(568), uint16(409), uint16(224), uint16(514),
	uint16(175), uint16(82), uint16(83), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120),
	uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(1007), uint16(16), uint16(16), uint16(1192), uint16(133),
	uint16(133), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040),
	uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124), uint16(122), uint16(122), uint16(122), uint16(122),
	uint16(121), uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(1041), uint16(546),
	uint16(1192), uint16(373), uint16(1192), uint16(1193), uint16(1194), uint16(252), uint16(1434), uint16(399), uint16(504), uint16(501),
	uint16(500), uint16(111), uint16(560), uint16(566), uint16(4), uint16(926), uint16(926), uint16(433), uint16(499), uint16(340),
	uint16(460), uint16(328), uint16(360), uint16(394), uint16(1237), uint16(1192), uint16(1193), uint16(1194), uint16(563), uint16(568),
	uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120), uint16(120), uint16(120), uint16(119),
	uint16(116), uint16(444), uint16(284), uint16(284), uint16(369), uint16(1580), uint16(1607), uint16(441), uint16(440), uint16(154),
	uint16(409), uint16(445), uint16(71), uint16(71), uint16(1286), uint16(565), uint16(1221), uint16(1192), uint16(1193), uint16(1194),
	uint16(85), uint16(1223), uint16(271), uint16(557), uint16(543), uint16(515), uint16(1561), uint16(568), uint16(98), uint16(1222),
	uint16(6), uint16(1278), uint16(472), uint16(142), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217), uint16(1050),
	uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124), uint16(550),
	uint16(13), uint16(13), uint16(1027), uint16(507), uint16(1224), uint16(1192), uint16(1224), uint16(549), uint16(109), uint16(109),
	uint16(222), uint16(568), uint16(1238), uint16(175), uint16(568), uint16(427), uint16(110), uint16(197), uint16(445), uint16(570),
	uint16(569), uint16(430), uint16(1552), uint16(1017), uint16(325), uint16(551), uint16(1192), uint16(270), uint16(287), uint16(368),
	uint16(510), uint16(363), uint16(509), uint16(257), uint16(71), uint16(71), uint16(543), uint16(71), uint16(71), uint16(359),
	uint16(316), uint16(559), uint16(1613), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120),
	uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(1017), uint16(1017), uint16(1019), uint16(1020), uint16(27),
	uint16(284), uint16(284), uint16(1192), uint16(1193), uint16(1194), uint16(1158), uint16(568), uint16(1612), uint16(409), uint16(901),
	uint16(190), uint16(550), uint16(356), uint16(565), uint16(550), uint16(937), uint16(533), uint16(517), uint16(1158), uint16(516),
	uint16(413), uint16(1158), uint16(552), uint16(1192), uint16(1193), uint16(1194), uint16(568), uint16(544), uint16(1554), uint16(51),
	uint16(51), uint16(214), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217), uint16(1050), uint16(1053), uint16(1040),
	uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124), uint16(1192), uint16(474), uint16(135),
	uint16(135), uint16(409), uint16(284), uint16(284), uint16(1490), uint16(505), uint16(121), uint16(121), uint16(120), uint16(120),
	uint16(120), uint16(119), uint16(116), uint16(444), uint16(1007), uint16(565), uint16(518), uint16(217), uint16(541), uint16(1561),
	uint16(316), uint16(559), uint16(142), uint16(6), uint16(532), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217),
	uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124),
	uint16(1555), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120), uint16(120), uint16(120),
	uint16(119), uint16(116), uint16(444), uint16(485), uint16(1192), uint16(1193), uint16(1194), uint16(482), uint16(281), uint16(1267),
	uint16(957), uint16(252), uint16(1192), uint16(373), uint16(504), uint16(501), uint16(500), uint16(1192), uint16(340), uint16(571),
	uint16(1192), uint16(571), uint16(409), uint16(292), uint16(499), uint16(957), uint16(876), uint16(191), uint16(480), uint16(316),
	uint16(559), uint16(384), uint16(290), uint16(380), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121),
	uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(125), uint16(126), uint16(80), uint16(1217),
	uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124),
	uint16(124), uint16(409), uint16(394), uint16(1136), uint16(1192), uint16(869), uint16(100), uint16(284), uint16(284), uint16(1192),
	uint16(1193), uint16(1194), uint16(373), uint16(1093), uint16(1192), uint16(1193), uint16(1194), uint16(1192), uint16(1193), uint16(1194),
	uint16(565), uint16(455), uint16(32), uint16(373), uint16(233), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217),
	uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124),
	uint16(1433), uint16(959), uint16(568), uint16(228), uint16(958), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121),
	uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(1158), uint16(228), uint16(1192),
	uint16(157), uint16(1192), uint16(1193), uint16(1194), uint16(1553), uint16(13), uint16(13), uint16(301), uint16(957), uint16(1232),
	uint16(1158), uint16(153), uint16(409), uint16(1158), uint16(373), uint16(1583), uint16(1176), uint16(5), uint16(369), uint16(1580),
	uint16(429), uint16(1238), uint16(3), uint16(957), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121),
	uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(125), uint16(126), uint16(80), uint16(1217),
	uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124),
	uint16(124), uint16(409), uint16(208), uint16(567), uint16(1192), uint16(1028), uint16(1192), uint16(1193), uint16(1194), uint16(1192),
	uint16(388), uint16(852), uint16(155), uint16(1552), uint16(286), uint16(402), uint16(1098), uint16(1098), uint16(488), uint16(568),
	uint16(465), uint16(342), uint16(1319), uint16(1319), uint16(1552), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217),
	uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124),
	uint16(129), uint16(568), uint16(13), uint16(13), uint16(374), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121),
	uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(302), uint16(568), uint16(453),
	uint16(528), uint16(1192), uint16(1193), uint16(1194), uint16(13), uint16(13), uint16(1192), uint16(1193), uint16(1194), uint16(1297),
	uint16(463), uint16(1267), uint16(409), uint16(1317), uint16(1317), uint16(1552), uint16(1012), uint16(453), uint16(452), uint16(200),
	uint16(299), uint16(71), uint16(71), uint16(1265), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121),
	uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(125), uint16(126), uint16(80), uint16(1217),
	uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124),
	uint16(124), uint16(409), uint16(227), uint16(1073), uint16(1158), uint16(284), uint16(284), uint16(419), uint16(312), uint16(278),
	uint16(278), uint16(285), uint16(285), uint16(1419), uint16(406), uint16(405), uint16(382), uint16(1158), uint16(565), uint16(568),
	uint16(1158), uint16(1196), uint16(565), uint16(1600), uint16(565), uint16(125), uint16(126), uint16(80), uint16(1217), uint16(1217),
	uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124), uint16(124),
	uint16(453), uint16(1482), uint16(13), uint16(13), uint16(1536), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121),
	uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(201), uint16(568), uint16(354),
	uint16(1586), uint16(575), uint16(2), uint16(1245), uint16(840), uint16(841), uint16(842), uint16(1562), uint16(317), uint16(1212),
	uint16(146), uint16(6), uint16(409), uint16(255), uint16(254), uint16(253), uint16(206), uint16(1327), uint16(9), uint16(1196),
	uint16(262), uint16(71), uint16(71), uint16(424), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121), uint16(121),
	uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(125), uint16(126), uint16(80), uint16(1217),
	uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124),
	uint16(124), uint16(568), uint16(284), uint16(284), uint16(568), uint16(1213), uint16(409), uint16(574), uint16(313), uint16(1245),
	uint16(349), uint16(1296), uint16(352), uint16(419), uint16(317), uint16(565), uint16(146), uint16(491), uint16(525), uint16(1643),
	uint16(395), uint16(371), uint16(491), uint16(1327), uint16(70), uint16(70), uint16(1295), uint16(71), uint16(71), uint16(240),
	uint16(1325), uint16(104), uint16(80), uint16(1217), uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123),
	uint16(123), uint16(124), uint16(124), uint16(124), uint16(124), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121),
	uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(1114), uint16(284), uint16(284),
	uint16(428), uint16(448), uint16(1525), uint16(1213), uint16(439), uint16(284), uint16(284), uint16(1489), uint16(1352), uint16(311),
	uint16(474), uint16(565), uint16(1115), uint16(971), uint16(491), uint16(491), uint16(217), uint16(1263), uint16(565), uint16(1538),
	uint16(568), uint16(972), uint16(207), uint16(568), uint16(1027), uint16(240), uint16(383), uint16(1116), uint16(519), uint16(122),
	uint16(122), uint16(122), uint16(122), uint16(121), uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116),
	uint16(444), uint16(1018), uint16(107), uint16(71), uint16(71), uint16(1017), uint16(13), uint16(13), uint16(912), uint16(568),
	uint16(1495), uint16(568), uint16(284), uint16(284), uint16(97), uint16(526), uint16(491), uint16(448), uint16(913), uint16(1326),
	uint16(1322), uint16(545), uint16(409), uint16(284), uint16(284), uint16(565), uint16(151), uint16(209), uint16(1495), uint16(1497),
	uint16(262), uint16(450), uint16(55), uint16(55), uint16(56), uint16(56), uint16(565), uint16(1017), uint16(1017), uint16(1019),
	uint16(443), uint16(332), uint16(409), uint16(527), uint16(12), uint16(295), uint16(125), uint16(126), uint16(80), uint16(1217),
	uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124),
	uint16(124), uint16(347), uint16(409), uint16(864), uint16(1534), uint16(1213), uint16(125), uint16(126), uint16(80), uint16(1217),
	uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124),
	uint16(124), uint16(1137), uint16(1641), uint16(474), uint16(1641), uint16(371), uint16(125), uint16(114), uint16(80), uint16(1217),
	uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123), uint16(124), uint16(124), uint16(124),
	uint16(124), uint16(1495), uint16(329), uint16(474), uint16(331), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121),
	uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(203), uint16(1419), uint16(568),
	uint16(1294), uint16(864), uint16(464), uint16(1213), uint16(436), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121),
	uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(553), uint16(1137), uint16(1642),
	uint16(539), uint16(1642), uint16(15), uint16(15), uint16(892), uint16(122), uint16(122), uint16(122), uint16(122), uint16(121),
	uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444), uint16(568), uint16(298), uint16(538),
	uint16(1135), uint16(1419), uint16(1559), uint16(1560), uint16(1331), uint16(409), uint16(6), uint16(6), uint16(1169), uint16(1268),
	uint16(415), uint16(320), uint16(284), uint16(284), uint16(1419), uint16(508), uint16(565), uint16(525), uint16(300), uint16(457),
	uint16(43), uint16(43), uint16(568), uint16(893), uint16(12), uint16(565), uint16(330), uint16(478), uint16(425), uint16(407),
	uint16(126), uint16(80), uint16(1217), uint16(1217), uint16(1050), uint16(1053), uint16(1040), uint16(1040), uint16(123), uint16(123),
	uint16(124), uint16(124), uint16(124), uint16(124), uint16(568), uint16(57), uint16(57), uint16(288), uint16(1192), uint16(1419),
	uint16(496), uint16(458), uint16(392), uint16(392), uint16(391), uint16(273), uint16(389), uint16(1135), uint16(1558), uint16(849),
	uint16(1169), uint16(407), uint16(6), uint16(568), uint16(321), uint16(1158), uint16(470), uint16(44), uint16(44), uint16(1557),
	uint16(1114), uint16(426), uint16(234), uint16(6), uint16(323), uint16(256), uint16(540), uint16(256), uint16(1158), uint16(431),
	uint16(568), uint16(1158), uint16(322), uint16(17), uint16(487), uint16(1115), uint16(58), uint16(58), uint16(122), uint16(122),
	uint16(122), uint16(122), uint16(121), uint16(121), uint16(120), uint16(120), uint16(120), uint16(119), uint16(116), uint16(444),
	uint16(1116), uint16(216), uint16(481), uint16(59), uint16(59), uint16(1192), uint16(1193), uint16(1194), uint16(111), uint16(560),
	uint16(324), uint16(4), uint16(236), uint16(456), uint16(526), uint16(568), uint16(237), uint16(456), uint16(568), uint16(437),
	uint16(168), uint16(556), uint16(420), uint16(141), uint16(479), uint16(563), uint16(568), uint16(293), uint16(568), uint16(1095),
	uint16(568), uint16(293), uint16(568), uint16(1095), uint16(531), uint16(568), uint16(872), uint16(8), uint16(60), uint16(60),
	uint16(235), uint16(61), uint16(61), uint16(568), uint16(414), uint16(568), uint16(414), uint16(568), uint16(445), uint16(62),
	uint16(62), uint16(45), uint16(45), uint16(46), uint16(46), uint16(47), uint16(47), uint16(199), uint16(49), uint16(49),
	uint16(557), uint16(568), uint16(359), uint16(568), uint16(100), uint16(486), uint16(50), uint16(50), uint16(63), uint16(63),
	uint16(64), uint16(64), uint16(561), uint16(415), uint16(535), uint16(410), uint16(568), uint16(1027), uint16(568), uint16(534),
	uint16(316), uint16(559), uint16(316), uint16(559), uint16(65), uint16(65), uint16(14), uint16(14), uint16(568), uint16(1027),
	uint16(568), uint16(512), uint16(932), uint16(872), uint16(1018), uint16(109), uint16(109), uint16(931), uint16(1017), uint16(66),
	uint16(66), uint16(131), uint16(131), uint16(110), uint16(451), uint16(445), uint16(570), uint16(569), uint16(416), uint16(177),
	uint16(1017), uint16(132), uint16(132), uint16(67), uint16(67), uint16(568), uint16(467), uint16(568), uint16(932), uint16(471),
	uint16(1364), uint16(283), uint16(226), uint16(931), uint16(315), uint16(1363), uint16(407), uint16(568), uint16(459), uint16(407),
	uint16(1017), uint16(1017), uint16(1019), uint16(239), uint16(407), uint16(86), uint16(213), uint16(1350), uint16(52), uint16(52),
	uint16(68), uint16(68), uint16(1017), uint16(1017), uint16(1019), uint16(1020), uint16(27), uint16(1585), uint16(1180), uint16(447),
	uint16(69), uint16(69), uint16(288), uint16(97), uint16(108), uint16(1541), uint16(106), uint16(392), uint16(392), uint16(391),
	uint16(273), uint16(389), uint16(568), uint16(879), uint16(849), uint16(883), uint16(568), uint16(111), uint16(560), uint16(466),
	uint16(4), uint16(568), uint16(152), uint16(30), uint16(38), uint16(568), uint16(1132), uint16(234), uint16(396), uint16(323),
	uint16(111), uint16(560), uint16(527), uint16(4), uint16(563), uint16(53), uint16(53), uint16(322), uint16(568), uint16(163),
	uint16(163), uint16(568), uint16(337), uint16(468), uint16(164), uint16(164), uint16(333), uint16(563), uint16(76), uint16(76),
	uint16(568), uint16(289), uint16(1514), uint16(568), uint16(31), uint16(1513), uint16(568), uint16(445), uint16(338), uint16(483),
	uint16(100), uint16(54), uint16(54), uint16(344), uint16(72), uint16(72), uint16(296), uint16(236), uint16(1080), uint16(557),
	uint16(445), uint16(879), uint16(1360), uint16(134), uint16(134), uint16(168), uint16(73), uint16(73), uint16(141), uint16(161),
	uint16(161), uint16(1574), uint16(557), uint16(535), uint16(568), uint16(319), uint16(568), uint16(348), uint16(536), uint16(1009),
	uint16(473), uint16(261), uint16(261), uint16(891), uint16(890), uint16(235), uint16(535), uint16(568), uint16(1027), uint16(568),
	uint16(475), uint16(534), uint16(261), uint16(367), uint16(109), uint16(109), uint16(521), uint16(136), uint16(136), uint16(130),
	uint16(130), uint16(1027), uint16(110), uint16(366), uint16(445), uint16(570), uint16(569), uint16(109), uint16(109), uint16(1017),
	uint16(162), uint16(162), uint16(156), uint16(156), uint16(568), uint16(110), uint16(1080), uint16(445), uint16(570), uint16(569),
	uint16(410), uint16(351), uint16(1017), uint16(568), uint16(353), uint16(316), uint16(559), uint16(568), uint16(343), uint16(568),
	uint16(100), uint16(497), uint16(357), uint16(258), uint16(100), uint16(898), uint16(899), uint16(140), uint16(140), uint16(355),
	uint16(1310), uint16(1017), uint16(1017), uint16(1019), uint16(1020), uint16(27), uint16(139), uint16(139), uint16(362), uint16(451),
	uint16(137), uint16(137), uint16(138), uint16(138), uint16(1017), uint16(1017), uint16(1019), uint16(1020), uint16(27), uint16(1180),
	uint16(447), uint16(568), uint16(372), uint16(288), uint16(111), uint16(560), uint16(1021), uint16(4), uint16(392), uint16(392),
	uint16(391), uint16(273), uint16(389), uint16(568), uint16(1141), uint16(849), uint16(568), uint16(1076), uint16(568), uint16(258),
	uint16(492), uint16(563), uint16(568), uint16(211), uint16(75), uint16(75), uint16(555), uint16(962), uint16(234), uint16(261),
	uint16(323), uint16(111), uint16(560), uint16(929), uint16(4), uint16(113), uint16(77), uint16(77), uint16(322), uint16(74),
	uint16(74), uint16(42), uint16(42), uint16(1373), uint16(445), uint16(48), uint16(48), uint16(1418), uint16(563), uint16(974),
	uint16(975), uint16(1092), uint16(1091), uint16(1092), uint16(1091), uint16(862), uint16(557), uint16(150), uint16(930), uint16(1346),
	uint16(113), uint16(1358), uint16(554), uint16(1424), uint16(1021), uint16(1275), uint16(1266), uint16(1254), uint16(236), uint16(1253),
	uint16(1255), uint16(445), uint16(1593), uint16(1343), uint16(308), uint16(276), uint16(168), uint16(309), uint16(11), uint16(141),
	uint16(393), uint16(310), uint16(232), uint16(557), uint16(1405), uint16(1027), uint16(335), uint16(291), uint16(1400), uint16(219),
	uint16(336), uint16(109), uint16(109), uint16(936), uint16(297), uint16(1410), uint16(235), uint16(341), uint16(477), uint16(110),
	uint16(502), uint16(445), uint16(570), uint16(569), uint16(1393), uint16(1409), uint16(1017), uint16(400), uint16(1293), uint16(365),
	uint16(223), uint16(1486), uint16(1027), uint16(1485), uint16(1355), uint16(1356), uint16(1354), uint16(1353), uint16(109), uint16(109),
	uint16(204), uint16(1596), uint16(1232), uint16(558), uint16(265), uint16(218), uint16(110), uint16(205), uint16(445), uint16(570),
	uint16(569), uint16(410), uint16(387), uint16(1017), uint16(1533), uint16(179), uint16(316), uint16(559), uint16(1017), uint16(1017),
	uint16(1019), uint16(1020), uint16(27), uint16(230), uint16(1531), uint16(1229), uint16(79), uint16(560), uint16(85), uint16(4),
	uint16(418), uint16(215), uint16(548), uint16(81), uint16(84), uint16(188), uint16(1406), uint16(173), uint16(181), uint16(461),
	uint16(451), uint16(35), uint16(462), uint16(563), uint16(183), uint16(1017), uint16(1017), uint16(1019), uint16(1020), uint16(27),
	uint16(184), uint16(1491), uint16(185), uint16(186), uint16(495), uint16(242), uint16(98), uint16(398), uint16(1412), uint16(36),
	uint16(1411), uint16(484), uint16(91), uint16(469), uint16(401), uint16(1414), uint16(445), uint16(192), uint16(1480), uint16(246),
	uint16(1502), uint16(490), uint16(346), uint16(277), uint16(248), uint16(196), uint16(493), uint16(511), uint16(557), uint16(350),
	uint16(1256), uint16(249), uint16(250), uint16(403), uint16(1313), uint16(1312), uint16(111), uint16(560), uint16(432), uint16(4),
	uint16(1311), uint16(1304), uint16(93), uint16(1611), uint16(883), uint16(1610), uint16(224), uint16(404), uint16(434), uint16(520),
	uint16(263), uint16(435), uint16(1579), uint16(563), uint16(1283), uint16(1282), uint16(364), uint16(1027), uint16(306), uint16(1281),
	uint16(264), uint16(1609), uint16(1565), uint16(109), uint16(109), uint16(370), uint16(1303), uint16(307), uint16(1564), uint16(438),
	uint16(128), uint16(110), uint16(1378), uint16(445), uint16(570), uint16(569), uint16(445), uint16(546), uint16(1017), uint16(10),
	uint16(1466), uint16(105), uint16(381), uint16(1377), uint16(34), uint16(572), uint16(99), uint16(1336), uint16(557), uint16(314),
	uint16(1186), uint16(530), uint16(272), uint16(274), uint16(379), uint16(210), uint16(1335), uint16(547), uint16(385), uint16(386),
	uint16(275), uint16(573), uint16(1251), uint16(1246), uint16(411), uint16(412), uint16(1518), uint16(165), uint16(178), uint16(1519),
	uint16(1017), uint16(1017), uint16(1019), uint16(1020), uint16(27), uint16(1517), uint16(1516), uint16(1027), uint16(78), uint16(147),
	uint16(166), uint16(220), uint16(221), uint16(109), uint16(109), uint16(836), uint16(304), uint16(167), uint16(446), uint16(212),
	uint16(318), uint16(110), uint16(231), uint16(445), uint16(570), uint16(569), uint16(144), uint16(1090), uint16(1017), uint16(1088),
	uint16(326), uint16(180), uint16(169), uint16(1212), uint16(182), uint16(334), uint16(238), uint16(915), uint16(241), uint16(1104),
	uint16(187), uint16(170), uint16(171), uint16(421), uint16(87), uint16(88), uint16(423), uint16(189), uint16(89), uint16(90),
	uint16(172), uint16(1107), uint16(243), uint16(1103), uint16(244), uint16(158), uint16(18), uint16(245), uint16(345), uint16(247),
	uint16(1017), uint16(1017), uint16(1019), uint16(1020), uint16(27), uint16(261), uint16(1096), uint16(193), uint16(1226), uint16(489),
	uint16(194), uint16(37), uint16(366), uint16(851), uint16(494), uint16(251), uint16(195), uint16(506), uint16(92), uint16(19),
	uint16(498), uint16(358), uint16(20), uint16(503), uint16(881), uint16(361), uint16(94), uint16(894), uint16(305), uint16(159),
	uint16(513), uint16(39), uint16(95), uint16(1174), uint16(160), uint16(1056), uint16(966), uint16(1143), uint16(96), uint16(174),
	uint16(1142), uint16(225), uint16(280), uint16(282), uint16(198), uint16(960), uint16(113), uint16(1164), uint16(1160), uint16(260),
	uint16(21), uint16(22), uint16(23), uint16(1162), uint16(1168), uint16(1167), uint16(1148), uint16(24), uint16(33), uint16(25),
	uint16(202), uint16(542), uint16(26), uint16(100), uint16(1071), uint16(102), uint16(1057), uint16(103), uint16(7), uint16(1055),
	uint16(1059), uint16(1113), uint16(1060), uint16(1112), uint16(266), uint16(267), uint16(28), uint16(40), uint16(390), uint16(1022),
	uint16(863), uint16(112), uint16(29), uint16(564), uint16(1182), uint16(1181), uint16(268), uint16(176), uint16(143), uint16(925),
	uint16(1242), uint16(1242), uint16(1242), uint16(1242), uint16(1242), uint16(1242), uint16(1242), uint16(1242), uint16(1242), uint16(1242),
	uint16(1242), uint16(1242), uint16(1242), uint16(1242), uint16(269), uint16(1602), uint16(1242), uint16(1601),
}
var yy_lookahead = [2283]uint16{
	uint16(193), uint16(193), uint16(193), uint16(274), uint16(275), uint16(276), uint16(193), uint16(274), uint16(275), uint16(276),
	uint16(193), uint16(223), uint16(219), uint16(225), uint16(206), uint16(210), uint16(211), uint16(212), uint16(193), uint16(19),
	uint16(219), uint16(233), uint16(216), uint16(216), uint16(217), uint16(216), uint16(217), uint16(193), uint16(295), uint16(216),
	uint16(217), uint16(31), uint16(193), uint16(216), uint16(217), uint16(193), uint16(228), uint16(213), uint16(230), uint16(39),
	uint16(206), uint16(216), uint16(217), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47), uint16(48), uint16(49),
	uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57), uint16(193), uint16(19),
	uint16(185), uint16(186), uint16(187), uint16(188), uint16(189), uint16(190), uint16(253), uint16(274), uint16(275), uint16(276),
	uint16(195), uint16(193), uint16(197), uint16(193), uint16(261), uint16(274), uint16(275), uint16(276), uint16(253), uint16(204),
	uint16(238), uint16(204), uint16(81), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47), uint16(48), uint16(49),
	uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57), uint16(274), uint16(275),
	uint16(276), uint16(262), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108), uint16(109),
	uint16(110), uint16(111), uint16(112), uint16(113), uint16(239), uint16(240), uint16(239), uint16(240), uint16(210), uint16(211),
	uint16(212), uint16(314), uint16(315), uint16(314), uint16(59), uint16(316), uint16(86), uint16(252), uint16(88), uint16(252),
	uint16(19), uint16(314), uint16(315), uint16(256), uint16(257), uint16(113), uint16(25), uint16(72), uint16(296), uint16(138),
	uint16(139), uint16(266), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108), uint16(109),
	uint16(110), uint16(111), uint16(112), uint16(113), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47), uint16(48),
	uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57), uint16(81),
	uint16(292), uint16(59), uint16(292), uint16(298), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113),
	uint16(69), uint16(116), uint16(117), uint16(118), uint16(72), uint16(106), uint16(107), uint16(193), uint16(111), uint16(112),
	uint16(113), uint16(54), uint16(55), uint16(56), uint16(57), uint16(58), uint16(102), uint16(103), uint16(104), uint16(105),
	uint16(106), uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(120), uint16(25),
	uint16(216), uint16(217), uint16(145), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108),
	uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(231), uint16(138), uint16(139), uint16(116), uint16(117),
	uint16(118), uint16(164), uint16(153), uint16(19), uint16(155), uint16(54), uint16(55), uint16(56), uint16(57), uint16(102),
	uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112),
	uint16(113), uint16(128), uint16(129), uint16(46), uint16(47), uint16(48), uint16(49), uint16(43), uint16(44), uint16(45),
	uint16(46), uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55),
	uint16(56), uint16(57), uint16(216), uint16(193), uint16(25), uint16(59), uint16(193), uint16(19), uint16(165), uint16(166),
	uint16(193), uint16(67), uint16(24), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108),
	uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(73), uint16(216), uint16(217), uint16(59), uint16(216),
	uint16(217), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47), uint16(48), uint16(49), uint16(50), uint16(51),
	uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57), uint16(102), uint16(103), uint16(104), uint16(105),
	uint16(106), uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(121), uint16(145),
	uint16(59), uint16(193), uint16(116), uint16(117), uint16(118), uint16(119), uint16(273), uint16(204), uint16(122), uint16(123),
	uint16(124), uint16(19), uint16(20), uint16(134), uint16(22), uint16(136), uint16(137), uint16(19), uint16(132), uint16(127),
	uint16(128), uint16(129), uint16(24), uint16(22), uint16(23), uint16(116), uint16(117), uint16(118), uint16(36), uint16(193),
	uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108), uint16(109), uint16(110), uint16(111),
	uint16(112), uint16(113), uint16(239), uint16(240), uint16(311), uint16(312), uint16(215), uint16(106), uint16(107), uint16(241),
	uint16(19), uint16(59), uint16(216), uint16(217), uint16(223), uint16(252), uint16(115), uint16(116), uint16(117), uint16(118),
	uint16(151), uint16(120), uint16(26), uint16(71), uint16(193), uint16(308), uint16(309), uint16(193), uint16(149), uint16(128),
	uint16(313), uint16(216), uint16(269), uint16(81), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47), uint16(48),
	uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57), uint16(253),
	uint16(216), uint16(217), uint16(100), uint16(95), uint16(153), uint16(59), uint16(155), uint16(261), uint16(106), uint16(107),
	uint16(25), uint16(193), uint16(101), uint16(193), uint16(193), uint16(231), uint16(114), uint16(25), uint16(116), uint16(117),
	uint16(118), uint16(113), uint16(304), uint16(121), uint16(193), uint16(204), uint16(59), uint16(119), uint16(120), uint16(121),
	uint16(122), uint16(123), uint16(124), uint16(125), uint16(216), uint16(217), uint16(193), uint16(216), uint16(217), uint16(131),
	uint16(138), uint16(139), uint16(230), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108),
	uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(153), uint16(154), uint16(155), uint16(156), uint16(157),
	uint16(239), uint16(240), uint16(116), uint16(117), uint16(118), uint16(76), uint16(193), uint16(23), uint16(19), uint16(25),
	uint16(22), uint16(253), uint16(23), uint16(252), uint16(253), uint16(108), uint16(87), uint16(204), uint16(89), uint16(261),
	uint16(198), uint16(92), uint16(261), uint16(116), uint16(117), uint16(118), uint16(193), uint16(306), uint16(307), uint16(216),
	uint16(217), uint16(150), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47), uint16(48), uint16(49), uint16(50),
	uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57), uint16(59), uint16(193), uint16(216),
	uint16(217), uint16(19), uint16(239), uint16(240), uint16(283), uint16(23), uint16(106), uint16(107), uint16(108), uint16(109),
	uint16(110), uint16(111), uint16(112), uint16(113), uint16(73), uint16(252), uint16(253), uint16(142), uint16(308), uint16(309),
	uint16(138), uint16(139), uint16(81), uint16(313), uint16(145), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47),
	uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57),
	uint16(307), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108), uint16(109), uint16(110),
	uint16(111), uint16(112), uint16(113), uint16(281), uint16(116), uint16(117), uint16(118), uint16(285), uint16(23), uint16(193),
	uint16(25), uint16(119), uint16(59), uint16(193), uint16(122), uint16(123), uint16(124), uint16(59), uint16(127), uint16(203),
	uint16(59), uint16(205), uint16(19), uint16(268), uint16(132), uint16(25), uint16(23), uint16(22), uint16(193), uint16(138),
	uint16(139), uint16(249), uint16(204), uint16(251), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107),
	uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(43), uint16(44), uint16(45), uint16(46),
	uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56),
	uint16(57), uint16(19), uint16(22), uint16(23), uint16(59), uint16(23), uint16(25), uint16(239), uint16(240), uint16(116),
	uint16(117), uint16(118), uint16(193), uint16(11), uint16(116), uint16(117), uint16(118), uint16(116), uint16(117), uint16(118),
	uint16(252), uint16(269), uint16(22), uint16(193), uint16(15), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47),
	uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57),
	uint16(273), uint16(143), uint16(193), uint16(118), uint16(143), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106),
	uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(76), uint16(118), uint16(59),
	uint16(241), uint16(116), uint16(117), uint16(118), uint16(304), uint16(216), uint16(217), uint16(292), uint16(143), uint16(60),
	uint16(89), uint16(241), uint16(19), uint16(92), uint16(193), uint16(193), uint16(23), uint16(22), uint16(311), uint16(312),
	uint16(231), uint16(101), uint16(22), uint16(143), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107),
	uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(43), uint16(44), uint16(45), uint16(46),
	uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56),
	uint16(57), uint16(19), uint16(193), uint16(193), uint16(59), uint16(23), uint16(116), uint16(117), uint16(118), uint16(59),
	uint16(201), uint16(21), uint16(241), uint16(304), uint16(22), uint16(206), uint16(127), uint16(128), uint16(129), uint16(193),
	uint16(128), uint16(129), uint16(235), uint16(236), uint16(304), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47),
	uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57),
	uint16(22), uint16(193), uint16(216), uint16(217), uint16(193), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106),
	uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(231), uint16(193), uint16(193),
	uint16(193), uint16(116), uint16(117), uint16(118), uint16(216), uint16(217), uint16(116), uint16(117), uint16(118), uint16(226),
	uint16(80), uint16(193), uint16(19), uint16(235), uint16(236), uint16(304), uint16(23), uint16(211), uint16(212), uint16(231),
	uint16(204), uint16(216), uint16(217), uint16(205), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107),
	uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(43), uint16(44), uint16(45), uint16(46),
	uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56),
	uint16(57), uint16(19), uint16(193), uint16(123), uint16(76), uint16(239), uint16(240), uint16(193), uint16(253), uint16(239),
	uint16(240), uint16(239), uint16(240), uint16(193), uint16(106), uint16(107), uint16(193), uint16(89), uint16(252), uint16(193),
	uint16(92), uint16(59), uint16(252), uint16(141), uint16(252), uint16(43), uint16(44), uint16(45), uint16(46), uint16(47),
	uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56), uint16(57),
	uint16(284), uint16(161), uint16(216), uint16(217), uint16(193), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106),
	uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(231), uint16(193), uint16(16),
	uint16(187), uint16(188), uint16(189), uint16(190), uint16(7), uint16(8), uint16(9), uint16(309), uint16(195), uint16(25),
	uint16(197), uint16(313), uint16(19), uint16(127), uint16(128), uint16(129), uint16(262), uint16(204), uint16(22), uint16(117),
	uint16(24), uint16(216), uint16(217), uint16(263), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106), uint16(107),
	uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(43), uint16(44), uint16(45), uint16(46),
	uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56),
	uint16(57), uint16(193), uint16(239), uint16(240), uint16(193), uint16(59), uint16(19), uint16(188), uint16(253), uint16(190),
	uint16(77), uint16(226), uint16(79), uint16(193), uint16(195), uint16(252), uint16(197), uint16(193), uint16(19), uint16(301),
	uint16(302), uint16(193), uint16(193), uint16(204), uint16(216), uint16(217), uint16(226), uint16(216), uint16(217), uint16(266),
	uint16(204), uint16(159), uint16(45), uint16(46), uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52),
	uint16(53), uint16(54), uint16(55), uint16(56), uint16(57), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106),
	uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(12), uint16(239), uint16(240),
	uint16(232), uint16(298), uint16(238), uint16(117), uint16(253), uint16(239), uint16(240), uint16(238), uint16(259), uint16(260),
	uint16(193), uint16(252), uint16(27), uint16(31), uint16(193), uint16(193), uint16(142), uint16(204), uint16(252), uint16(193),
	uint16(193), uint16(39), uint16(262), uint16(193), uint16(100), uint16(266), uint16(278), uint16(42), uint16(204), uint16(102),
	uint16(103), uint16(104), uint16(105), uint16(106), uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112),
	uint16(113), uint16(117), uint16(159), uint16(216), uint16(217), uint16(121), uint16(216), uint16(217), uint16(63), uint16(193),
	uint16(193), uint16(193), uint16(239), uint16(240), uint16(115), uint16(116), uint16(193), uint16(298), uint16(73), uint16(238),
	uint16(238), uint16(231), uint16(19), uint16(239), uint16(240), uint16(252), uint16(22), uint16(24), uint16(211), uint16(212),
	uint16(24), uint16(193), uint16(216), uint16(217), uint16(216), uint16(217), uint16(252), uint16(153), uint16(154), uint16(155),
	uint16(253), uint16(16), uint16(19), uint16(144), uint16(213), uint16(268), uint16(43), uint16(44), uint16(45), uint16(46),
	uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56),
	uint16(57), uint16(238), uint16(19), uint16(59), uint16(193), uint16(59), uint16(43), uint16(44), uint16(45), uint16(46),
	uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56),
	uint16(57), uint16(22), uint16(23), uint16(193), uint16(25), uint16(193), uint16(43), uint16(44), uint16(45), uint16(46),
	uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53), uint16(54), uint16(55), uint16(56),
	uint16(57), uint16(284), uint16(77), uint16(193), uint16(79), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106),
	uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(286), uint16(193), uint16(193),
	uint16(193), uint16(117), uint16(291), uint16(117), uint16(232), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106),
	uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(204), uint16(22), uint16(23),
	uint16(66), uint16(25), uint16(216), uint16(217), uint16(35), uint16(102), uint16(103), uint16(104), uint16(105), uint16(106),
	uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113), uint16(193), uint16(268), uint16(85),
	uint16(101), uint16(193), uint16(309), uint16(309), uint16(240), uint16(19), uint16(313), uint16(313), uint16(94), uint16(208),
	uint16(209), uint16(193), uint16(239), uint16(240), uint16(193), uint16(66), uint16(252), uint16(19), uint16(268), uint16(244),
	uint16(216), uint16(217), uint16(193), uint16(74), uint16(213), uint16(252), uint16(161), uint16(19), uint16(263), uint16(254),
	uint16(44), uint16(45), uint16(46), uint16(47), uint16(48), uint16(49), uint16(50), uint16(51), uint16(52), uint16(53),
	uint16(54), uint16(55), uint16(56), uint16(57), uint16(193), uint16(216), uint16(217), uint16(5), uint16(59), uint16(193),
	uint16(19), uint16(244), uint16(10), uint16(11), uint16(12), uint16(13), uint16(14), uint16(101), uint16(309), uint16(17),
	uint16(146), uint16(254), uint16(313), uint16(193), uint16(193), uint16(76), uint16(115), uint16(216), uint16(217), uint16(309),
	uint16(12), uint16(263), uint16(30), uint16(313), uint16(32), uint16(46), uint16(87), uint16(46), uint16(89), uint16(130),
	uint16(193), uint16(92), uint16(40), uint16(22), uint16(263), uint16(27), uint16(216), uint16(217), uint16(102), uint16(103),
	uint16(104), uint16(105), uint16(106), uint16(107), uint16(108), uint16(109), uint16(110), uint16(111), uint16(112), uint16(113),
	uint16(42), uint16(150), uint16(291), uint16(216), uint16(217), uint16(116), uint16(117), uint16(118), uint16(19), uint16(20),
	uint16(193), uint16(22), uint16(70), uint16(260), uint16(116), uint16(193), uint16(24), uint16(264), uint16(193), uint16(263),
	uint16(78), uint16(63), uint16(61), uint16(81), uint16(116), uint16(36), uint16(193), uint16(260), uint16(193), uint16(29),
	uint16(193), uint16(264), uint16(193), uint16(33), uint16(145), uint16(193), uint16(59), uint16(48), uint16(216), uint16(217),
	uint16(98), uint16(216), uint16(217), uint16(193), uint16(115), uint16(193), uint16(115), uint16(193), uint16(59), uint16(216),
	uint16(217), uint16(216), uint16(217), uint16(216), uint16(217), uint16(216), uint16(217), uint16(255), uint16(216), uint16(217),
	uint16(71), uint16(193), uint16(131), uint16(193), uint16(25), uint16(65), uint16(216), uint16(217), uint16(216), uint16(217),
	uint16(216), uint16(217), uint16(208), uint16(209), uint16(85), uint16(133), uint16(193), uint16(100), uint16(193), uint16(90),
	uint16(138), uint16(139), uint16(138), uint16(139), uint16(216), uint16(217), uint16(216), uint16(217), uint16(193), uint16(100),
	uint16(193), uint16(108), uint16(135), uint16(116), uint16(117), uint16(106), uint16(107), uint16(140), uint16(121), uint16(216),
	uint16(217), uint16(216), uint16(217), uint16(114), uint16(162), uint16(116), uint16(117), uint16(118), uint16(299), uint16(300),
	uint16(121), uint16(216), uint16(217), uint16(216), uint16(217), uint16(193), uint16(244), uint16(193), uint16(135), uint16(244),
	uint16(193), uint16(256), uint16(257), uint16(140), uint16(244), uint16(193), uint16(254), uint16(193), uint16(193), uint16(254),
	uint16(153), uint16(154), uint16(155), uint16(141), uint16(254), uint16(149), uint16(150), uint16(258), uint16(216), uint16(217),
	uint16(216), uint16(217), uint16(153), uint16(154), uint16(155), uint16(156), uint16(157), uint16(0), uint16(1), uint16(2),
	uint16(216), uint16(217), uint16(5), uint16(115), uint16(158), uint16(193), uint16(160), uint16(10), uint16(11), uint16(12),
	uint16(13), uint16(14), uint16(193), uint16(59), uint16(17), uint16(126), uint16(193), uint16(19), uint16(20), uint16(129),
	uint16(22), uint16(193), uint16(22), uint16(22), uint16(24), uint16(193), uint16(23), uint16(30), uint16(25), uint16(32),
	uint16(19), uint16(20), uint16(144), uint16(22), uint16(36), uint16(216), uint16(217), uint16(40), uint16(193), uint16(216),
	uint16(217), uint16(193), uint16(152), uint16(129), uint16(216), uint16(217), uint16(193), uint16(36), uint16(216), uint16(217),
	uint16(193), uint16(99), uint16(193), uint16(193), uint16(53), uint16(193), uint16(193), uint16(59), uint16(23), uint16(193),
	uint16(25), uint16(216), uint16(217), uint16(193), uint16(216), uint16(217), uint16(152), uint16(70), uint16(59), uint16(71),
	uint16(59), uint16(117), uint16(193), uint16(216), uint16(217), uint16(78), uint16(216), uint16(217), uint16(81), uint16(216),
	uint16(217), uint16(318), uint16(71), uint16(85), uint16(193), uint16(133), uint16(193), uint16(193), uint16(90), uint16(23),
	uint16(23), uint16(25), uint16(25), uint16(120), uint16(121), uint16(98), uint16(85), uint16(193), uint16(100), uint16(193),
	uint16(23), uint16(90), uint16(25), uint16(121), uint16(106), uint16(107), uint16(19), uint16(216), uint16(217), uint16(216),
	uint16(217), uint16(100), uint16(114), uint16(131), uint16(116), uint16(117), uint16(118), uint16(106), uint16(107), uint16(121),
	uint16(216), uint16(217), uint16(216), uint16(217), uint16(193), uint16(114), uint16(117), uint16(116), uint16(117), uint16(118),
	uint16(133), uint16(193), uint16(121), uint16(193), uint16(193), uint16(138), uint16(139), uint16(193), uint16(23), uint16(193),
	uint16(25), uint16(23), uint16(23), uint16(25), uint16(25), uint16(7), uint16(8), uint16(216), uint16(217), uint16(193),
	uint16(193), uint16(153), uint16(154), uint16(155), uint16(156), uint16(157), uint16(216), uint16(217), uint16(193), uint16(162),
	uint16(216), uint16(217), uint16(216), uint16(217), uint16(153), uint16(154), uint16(155), uint16(156), uint16(157), uint16(1),
	uint16(2), uint16(193), uint16(193), uint16(5), uint16(19), uint16(20), uint16(59), uint16(22), uint16(10), uint16(11),
	uint16(12), uint16(13), uint16(14), uint16(193), uint16(97), uint16(17), uint16(193), uint16(23), uint16(193), uint16(25),
	uint16(288), uint16(36), uint16(193), uint16(242), uint16(216), uint16(217), uint16(236), uint16(23), uint16(30), uint16(25),
	uint16(32), uint16(19), uint16(20), uint16(23), uint16(22), uint16(25), uint16(216), uint16(217), uint16(40), uint16(216),
	uint16(217), uint16(216), uint16(217), uint16(193), uint16(59), uint16(216), uint16(217), uint16(193), uint16(36), uint16(83),
	uint16(84), uint16(153), uint16(153), uint16(155), uint16(155), uint16(23), uint16(71), uint16(25), uint16(23), uint16(193),
	uint16(25), uint16(193), uint16(193), uint16(193), uint16(117), uint16(193), uint16(193), uint16(193), uint16(70), uint16(193),
	uint16(193), uint16(59), uint16(193), uint16(255), uint16(255), uint16(287), uint16(78), uint16(255), uint16(243), uint16(81),
	uint16(191), uint16(255), uint16(297), uint16(71), uint16(271), uint16(100), uint16(293), uint16(245), uint16(267), uint16(214),
	uint16(246), uint16(106), uint16(107), uint16(108), uint16(246), uint16(271), uint16(98), uint16(245), uint16(293), uint16(114),
	uint16(220), uint16(116), uint16(117), uint16(118), uint16(267), uint16(271), uint16(121), uint16(271), uint16(225), uint16(219),
	uint16(229), uint16(219), uint16(100), uint16(219), uint16(259), uint16(259), uint16(259), uint16(259), uint16(106), uint16(107),
	uint16(249), uint16(196), uint16(60), uint16(280), uint16(141), uint16(243), uint16(114), uint16(249), uint16(116), uint16(117),
	uint16(118), uint16(133), uint16(245), uint16(121), uint16(200), uint16(297), uint16(138), uint16(139), uint16(153), uint16(154),
	uint16(155), uint16(156), uint16(157), uint16(297), uint16(200), uint16(38), uint16(19), uint16(20), uint16(151), uint16(22),
	uint16(200), uint16(150), uint16(140), uint16(294), uint16(294), uint16(22), uint16(272), uint16(43), uint16(234), uint16(18),
	uint16(162), uint16(270), uint16(200), uint16(36), uint16(237), uint16(153), uint16(154), uint16(155), uint16(156), uint16(157),
	uint16(237), uint16(283), uint16(237), uint16(237), uint16(18), uint16(199), uint16(149), uint16(246), uint16(272), uint16(270),
	uint16(272), uint16(200), uint16(158), uint16(246), uint16(246), uint16(234), uint16(59), uint16(234), uint16(246), uint16(199),
	uint16(290), uint16(62), uint16(289), uint16(200), uint16(199), uint16(22), uint16(221), uint16(115), uint16(71), uint16(200),
	uint16(200), uint16(199), uint16(199), uint16(221), uint16(218), uint16(218), uint16(19), uint16(20), uint16(64), uint16(22),
	uint16(218), uint16(227), uint16(22), uint16(224), uint16(126), uint16(224), uint16(165), uint16(221), uint16(24), uint16(305),
	uint16(200), uint16(113), uint16(312), uint16(36), uint16(218), uint16(220), uint16(218), uint16(100), uint16(282), uint16(218),
	uint16(91), uint16(218), uint16(317), uint16(106), uint16(107), uint16(221), uint16(227), uint16(282), uint16(317), uint16(82),
	uint16(148), uint16(114), uint16(265), uint16(116), uint16(117), uint16(118), uint16(59), uint16(145), uint16(121), uint16(22),
	uint16(277), uint16(158), uint16(200), uint16(265), uint16(25), uint16(202), uint16(147), uint16(250), uint16(71), uint16(279),
	uint16(13), uint16(146), uint16(194), uint16(194), uint16(249), uint16(248), uint16(250), uint16(140), uint16(247), uint16(246),
	uint16(6), uint16(192), uint16(192), uint16(192), uint16(303), uint16(303), uint16(213), uint16(207), uint16(300), uint16(213),
	uint16(153), uint16(154), uint16(155), uint16(156), uint16(157), uint16(213), uint16(213), uint16(100), uint16(213), uint16(222),
	uint16(207), uint16(214), uint16(214), uint16(106), uint16(107), uint16(4), uint16(222), uint16(207), uint16(3), uint16(22),
	uint16(163), uint16(114), uint16(15), uint16(116), uint16(117), uint16(118), uint16(16), uint16(23), uint16(121), uint16(23),
	uint16(139), uint16(151), uint16(130), uint16(25), uint16(142), uint16(16), uint16(24), uint16(20), uint16(144), uint16(1),
	uint16(142), uint16(130), uint16(130), uint16(61), uint16(53), uint16(53), uint16(37), uint16(151), uint16(53), uint16(53),
	uint16(130), uint16(116), uint16(34), uint16(1), uint16(141), uint16(5), uint16(22), uint16(115), uint16(161), uint16(141),
	uint16(153), uint16(154), uint16(155), uint16(156), uint16(157), uint16(25), uint16(68), uint16(68), uint16(75), uint16(41),
	uint16(115), uint16(24), uint16(131), uint16(20), uint16(19), uint16(125), uint16(22), uint16(96), uint16(22), uint16(22),
	uint16(67), uint16(23), uint16(22), uint16(67), uint16(59), uint16(24), uint16(22), uint16(28), uint16(67), uint16(23),
	uint16(22), uint16(22), uint16(149), uint16(23), uint16(23), uint16(23), uint16(116), uint16(23), uint16(25), uint16(37),
	uint16(97), uint16(141), uint16(23), uint16(23), uint16(22), uint16(143), uint16(25), uint16(75), uint16(88), uint16(34),
	uint16(34), uint16(34), uint16(34), uint16(86), uint16(75), uint16(93), uint16(23), uint16(34), uint16(22), uint16(34),
	uint16(25), uint16(24), uint16(34), uint16(25), uint16(23), uint16(142), uint16(23), uint16(142), uint16(44), uint16(23),
	uint16(23), uint16(23), uint16(11), uint16(23), uint16(25), uint16(22), uint16(22), uint16(22), uint16(15), uint16(23),
	uint16(23), uint16(22), uint16(22), uint16(25), uint16(1), uint16(1), uint16(141), uint16(25), uint16(23), uint16(135),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(141), uint16(141), uint16(319), uint16(141), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319), uint16(319),
	uint16(319), uint16(319), uint16(319),
}
var yy_shift_ofst = [576]uint16{
	uint16(1648), uint16(1477), uint16(1272), uint16(322), uint16(322), uint16(1), uint16(1319), uint16(1478), uint16(1491), uint16(1837),
	uint16(1837), uint16(1837), uint16(471), uint16(0), uint16(0), uint16(214), uint16(1093), uint16(1837), uint16(1837), uint16(1837),
	uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837),
	uint16(271), uint16(271), uint16(1219), uint16(1219), uint16(216), uint16(88), uint16(1), uint16(1), uint16(1), uint16(1),
	uint16(1), uint16(40), uint16(111), uint16(258), uint16(361), uint16(469), uint16(512), uint16(583), uint16(622), uint16(693),
	uint16(732), uint16(803), uint16(842), uint16(913), uint16(1073), uint16(1093), uint16(1093), uint16(1093), uint16(1093), uint16(1093),
	uint16(1093), uint16(1093), uint16(1093), uint16(1093), uint16(1093), uint16(1093), uint16(1093), uint16(1093), uint16(1093), uint16(1093),
	uint16(1093), uint16(1093), uint16(1093), uint16(1113), uint16(1093), uint16(1216), uint16(957), uint16(957), uint16(1635), uint16(1662),
	uint16(1777), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837),
	uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837),
	uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837),
	uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837),
	uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837), uint16(1837),
	uint16(137), uint16(181), uint16(181), uint16(181), uint16(181), uint16(181), uint16(181), uint16(181), uint16(94), uint16(430),
	uint16(66), uint16(65), uint16(112), uint16(366), uint16(533), uint16(533), uint16(740), uint16(1261), uint16(533), uint16(533),
	uint16(79), uint16(79), uint16(533), uint16(412), uint16(412), uint16(412), uint16(77), uint16(412), uint16(123), uint16(113),
	uint16(113), uint16(22), uint16(22), uint16(2098), uint16(2098), uint16(328), uint16(328), uint16(328), uint16(239), uint16(468),
	uint16(468), uint16(468), uint16(468), uint16(1015), uint16(1015), uint16(409), uint16(366), uint16(1129), uint16(1186), uint16(533),
	uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533),
	uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(969),
	uint16(621), uint16(621), uint16(533), uint16(642), uint16(788), uint16(788), uint16(1228), uint16(1228), uint16(822), uint16(822),
	uint16(67), uint16(1274), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(1307),
	uint16(954), uint16(954), uint16(585), uint16(472), uint16(640), uint16(387), uint16(695), uint16(538), uint16(541), uint16(700),
	uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533),
	uint16(222), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533),
	uint16(533), uint16(533), uint16(533), uint16(1179), uint16(1179), uint16(1179), uint16(533), uint16(533), uint16(533), uint16(565),
	uint16(533), uint16(533), uint16(533), uint16(916), uint16(1144), uint16(533), uint16(533), uint16(1288), uint16(533), uint16(533),
	uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(533), uint16(639), uint16(1330), uint16(209), uint16(1076),
	uint16(1076), uint16(1076), uint16(1076), uint16(580), uint16(209), uint16(209), uint16(1313), uint16(768), uint16(917), uint16(649),
	uint16(1181), uint16(1316), uint16(405), uint16(1316), uint16(1238), uint16(249), uint16(1181), uint16(1181), uint16(249), uint16(1181),
	uint16(405), uint16(1238), uint16(1369), uint16(464), uint16(1259), uint16(1012), uint16(1012), uint16(1012), uint16(1368), uint16(1368),
	uint16(1368), uint16(1368), uint16(184), uint16(184), uint16(1326), uint16(904), uint16(1287), uint16(1480), uint16(1712), uint16(1712),
	uint16(1633), uint16(1633), uint16(1757), uint16(1757), uint16(1633), uint16(1647), uint16(1651), uint16(1783), uint16(1764), uint16(1791),
	uint16(1791), uint16(1791), uint16(1791), uint16(1633), uint16(1806), uint16(1677), uint16(1651), uint16(1651), uint16(1677), uint16(1783),
	uint16(1764), uint16(1677), uint16(1764), uint16(1677), uint16(1633), uint16(1806), uint16(1674), uint16(1779), uint16(1633), uint16(1806),
	uint16(1823), uint16(1633), uint16(1806), uint16(1633), uint16(1806), uint16(1823), uint16(1732), uint16(1732), uint16(1732), uint16(1794),
	uint16(1840), uint16(1840), uint16(1823), uint16(1732), uint16(1738), uint16(1732), uint16(1794), uint16(1732), uint16(1732), uint16(1701),
	uint16(1844), uint16(1758), uint16(1758), uint16(1823), uint16(1633), uint16(1789), uint16(1789), uint16(1807), uint16(1807), uint16(1742),
	uint16(1752), uint16(1877), uint16(1633), uint16(1743), uint16(1742), uint16(1759), uint16(1765), uint16(1677), uint16(1879), uint16(1897),
	uint16(1897), uint16(1914), uint16(1914), uint16(1914), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098),
	uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(2098), uint16(207),
	uint16(1095), uint16(331), uint16(620), uint16(903), uint16(806), uint16(1074), uint16(1483), uint16(1432), uint16(1481), uint16(1322),
	uint16(1370), uint16(1394), uint16(1515), uint16(1291), uint16(1546), uint16(1547), uint16(1557), uint16(1595), uint16(1598), uint16(1599),
	uint16(1434), uint16(1453), uint16(1618), uint16(1462), uint16(1567), uint16(1489), uint16(1644), uint16(1654), uint16(1616), uint16(1660),
	uint16(1548), uint16(1549), uint16(1682), uint16(1685), uint16(1597), uint16(742), uint16(1941), uint16(1945), uint16(1927), uint16(1787),
	uint16(1937), uint16(1940), uint16(1934), uint16(1936), uint16(1821), uint16(1810), uint16(1832), uint16(1938), uint16(1938), uint16(1942),
	uint16(1822), uint16(1947), uint16(1824), uint16(1949), uint16(1968), uint16(1828), uint16(1841), uint16(1938), uint16(1842), uint16(1912),
	uint16(1939), uint16(1938), uint16(1826), uint16(1921), uint16(1922), uint16(1925), uint16(1926), uint16(1850), uint16(1865), uint16(1948),
	uint16(1843), uint16(1982), uint16(1980), uint16(1964), uint16(1872), uint16(1827), uint16(1928), uint16(1970), uint16(1929), uint16(1923),
	uint16(1958), uint16(1848), uint16(1885), uint16(1977), uint16(1983), uint16(1985), uint16(1871), uint16(1880), uint16(1984), uint16(1943),
	uint16(1986), uint16(1987), uint16(1988), uint16(1990), uint16(1946), uint16(1955), uint16(1991), uint16(1911), uint16(1989), uint16(1994),
	uint16(1951), uint16(1992), uint16(1996), uint16(1873), uint16(1998), uint16(2000), uint16(2001), uint16(2002), uint16(2003), uint16(2004),
	uint16(1999), uint16(1933), uint16(1890), uint16(2009), uint16(2010), uint16(1910), uint16(2005), uint16(2012), uint16(1892), uint16(2011),
	uint16(2006), uint16(2007), uint16(2008), uint16(2013), uint16(1950), uint16(1962), uint16(1957), uint16(2014), uint16(1969), uint16(1952),
	uint16(2015), uint16(2023), uint16(2026), uint16(2027), uint16(2025), uint16(2028), uint16(2018), uint16(1913), uint16(1915), uint16(2031),
	uint16(2011), uint16(2033), uint16(2036), uint16(2037), uint16(2038), uint16(2039), uint16(2040), uint16(2043), uint16(2051), uint16(2044),
	uint16(2045), uint16(2046), uint16(2047), uint16(2049), uint16(2050), uint16(2048), uint16(1944), uint16(1935), uint16(1953), uint16(1954),
	uint16(1956), uint16(2052), uint16(2055), uint16(2053), uint16(2073), uint16(2074),
}
var yy_reduce_ofst = [409]int16{
	int16(-125), int16(733), int16(789), int16(241), int16(293), int16(-123), int16(-193), int16(-191), int16(-183), int16(-187),
	int16(166), int16(238), int16(133), int16(-207), int16(-199), int16(-267), int16(-176), int16(-6), int16(204), int16(489),
	int16(576), int16(-175), int16(598), int16(686), int16(615), int16(725), int16(860), int16(778), int16(781), int16(857),
	int16(616), int16(887), int16(87), int16(240), int16(-192), int16(408), int16(626), int16(796), int16(843), int16(854),
	int16(1003), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271),
	int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271),
	int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271),
	int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(80), int16(83),
	int16(313), int16(886), int16(888), int16(996), int16(1034), int16(1059), int16(1081), int16(1100), int16(1117), int16(1152),
	int16(1155), int16(1163), int16(1165), int16(1167), int16(1169), int16(1172), int16(1180), int16(1182), int16(1184), int16(1198),
	int16(1200), int16(1213), int16(1215), int16(1225), int16(1227), int16(1252), int16(1254), int16(1264), int16(1299), int16(1303),
	int16(1308), int16(1312), int16(1325), int16(1328), int16(1337), int16(1340), int16(1343), int16(1371), int16(1373), int16(1384),
	int16(1386), int16(1411), int16(1420), int16(1424), int16(1426), int16(1458), int16(1470), int16(1473), int16(1475), int16(1479),
	int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271), int16(-271),
	int16(-271), int16(138), int16(459), int16(396), int16(-158), int16(470), int16(302), int16(-212), int16(521), int16(201),
	int16(-195), int16(-92), int16(559), int16(630), int16(632), int16(630), int16(-271), int16(632), int16(901), int16(63),
	int16(407), int16(-271), int16(-271), int16(-271), int16(-271), int16(161), int16(161), int16(161), int16(251), int16(335),
	int16(847), int16(960), int16(980), int16(537), int16(588), int16(618), int16(628), int16(688), int16(688), int16(-166),
	int16(-161), int16(674), int16(790), int16(794), int16(799), int16(851), int16(852), int16(-122), int16(680), int16(-120),
	int16(995), int16(1038), int16(415), int16(1051), int16(893), int16(798), int16(962), int16(400), int16(1086), int16(779),
	int16(923), int16(924), int16(263), int16(1041), int16(979), int16(990), int16(1083), int16(1097), int16(1031), int16(1194),
	int16(362), int16(994), int16(1139), int16(1005), int16(1037), int16(1202), int16(1205), int16(1195), int16(1210), int16(-194),
	int16(56), int16(185), int16(-135), int16(232), int16(522), int16(560), int16(601), int16(617), int16(669), int16(683),
	int16(711), int16(856), int16(908), int16(941), int16(1048), int16(1101), int16(1147), int16(1257), int16(1262), int16(1265),
	int16(392), int16(1292), int16(1333), int16(1339), int16(1342), int16(1346), int16(1350), int16(1359), int16(1374), int16(1418),
	int16(1421), int16(1436), int16(1437), int16(593), int16(755), int16(770), int16(997), int16(1445), int16(1459), int16(1209),
	int16(1500), int16(1504), int16(1516), int16(1132), int16(1243), int16(1518), int16(1519), int16(1440), int16(1520), int16(560),
	int16(1522), int16(1523), int16(1524), int16(1526), int16(1527), int16(1529), int16(1382), int16(1438), int16(1431), int16(1468),
	int16(1469), int16(1472), int16(1476), int16(1209), int16(1431), int16(1431), int16(1485), int16(1525), int16(1539), int16(1435),
	int16(1463), int16(1471), int16(1492), int16(1487), int16(1443), int16(1494), int16(1474), int16(1484), int16(1498), int16(1486),
	int16(1502), int16(1455), int16(1530), int16(1531), int16(1533), int16(1540), int16(1542), int16(1544), int16(1505), int16(1506),
	int16(1507), int16(1508), int16(1521), int16(1528), int16(1493), int16(1537), int16(1532), int16(1575), int16(1488), int16(1496),
	int16(1584), int16(1594), int16(1509), int16(1510), int16(1600), int16(1538), int16(1534), int16(1541), int16(1574), int16(1577),
	int16(1583), int16(1585), int16(1586), int16(1612), int16(1626), int16(1581), int16(1556), int16(1558), int16(1587), int16(1559),
	int16(1601), int16(1588), int16(1603), int16(1592), int16(1631), int16(1640), int16(1550), int16(1553), int16(1643), int16(1645),
	int16(1625), int16(1649), int16(1652), int16(1650), int16(1653), int16(1632), int16(1636), int16(1637), int16(1642), int16(1634),
	int16(1639), int16(1641), int16(1646), int16(1656), int16(1655), int16(1658), int16(1659), int16(1661), int16(1663), int16(1560),
	int16(1564), int16(1596), int16(1605), int16(1664), int16(1670), int16(1565), int16(1571), int16(1627), int16(1638), int16(1657),
	int16(1665), int16(1623), int16(1702), int16(1630), int16(1666), int16(1667), int16(1671), int16(1673), int16(1703), int16(1718),
	int16(1719), int16(1729), int16(1730), int16(1731), int16(1621), int16(1622), int16(1628), int16(1720), int16(1713), int16(1716),
	int16(1722), int16(1723), int16(1733), int16(1717), int16(1724), int16(1727), int16(1728), int16(1725), int16(1740),
}
var yy_default = [576]uint16{
	uint16(1647), uint16(1647), uint16(1647), uint16(1475), uint16(1240), uint16(1351), uint16(1240), uint16(1240), uint16(1240), uint16(1475),
	uint16(1475), uint16(1475), uint16(1240), uint16(1381), uint16(1381), uint16(1528), uint16(1273), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1474), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1563), uint16(1563), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1390), uint16(1240), uint16(1397), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1476), uint16(1477), uint16(1240), uint16(1240), uint16(1240), uint16(1527), uint16(1529), uint16(1492), uint16(1404), uint16(1403),
	uint16(1402), uint16(1401), uint16(1510), uint16(1369), uint16(1395), uint16(1388), uint16(1392), uint16(1470), uint16(1471), uint16(1469),
	uint16(1473), uint16(1477), uint16(1476), uint16(1240), uint16(1391), uint16(1438), uint16(1454), uint16(1437), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1446), uint16(1453), uint16(1452), uint16(1451), uint16(1460), uint16(1450), uint16(1447), uint16(1440), uint16(1439), uint16(1441),
	uint16(1442), uint16(1240), uint16(1240), uint16(1264), uint16(1240), uint16(1240), uint16(1261), uint16(1315), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1547), uint16(1546), uint16(1240), uint16(1443), uint16(1240), uint16(1273), uint16(1432),
	uint16(1431), uint16(1457), uint16(1444), uint16(1456), uint16(1455), uint16(1535), uint16(1599), uint16(1598), uint16(1493), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1563), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1371),
	uint16(1563), uint16(1563), uint16(1240), uint16(1273), uint16(1563), uint16(1563), uint16(1372), uint16(1372), uint16(1269), uint16(1269),
	uint16(1375), uint16(1240), uint16(1542), uint16(1342), uint16(1342), uint16(1342), uint16(1342), uint16(1351), uint16(1342), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1532), uint16(1530), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1347), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1592), uint16(1240), uint16(1505), uint16(1329), uint16(1347),
	uint16(1347), uint16(1347), uint16(1347), uint16(1349), uint16(1330), uint16(1328), uint16(1341), uint16(1274), uint16(1247), uint16(1639),
	uint16(1407), uint16(1396), uint16(1348), uint16(1396), uint16(1636), uint16(1394), uint16(1407), uint16(1407), uint16(1394), uint16(1407),
	uint16(1348), uint16(1636), uint16(1290), uint16(1615), uint16(1285), uint16(1381), uint16(1381), uint16(1381), uint16(1371), uint16(1371),
	uint16(1371), uint16(1371), uint16(1375), uint16(1375), uint16(1472), uint16(1348), uint16(1341), uint16(1240), uint16(1639), uint16(1639),
	uint16(1357), uint16(1357), uint16(1638), uint16(1638), uint16(1357), uint16(1493), uint16(1623), uint16(1416), uint16(1318), uint16(1324),
	uint16(1324), uint16(1324), uint16(1324), uint16(1357), uint16(1258), uint16(1394), uint16(1623), uint16(1623), uint16(1394), uint16(1416),
	uint16(1318), uint16(1394), uint16(1318), uint16(1394), uint16(1357), uint16(1258), uint16(1509), uint16(1633), uint16(1357), uint16(1258),
	uint16(1483), uint16(1357), uint16(1258), uint16(1357), uint16(1258), uint16(1483), uint16(1316), uint16(1316), uint16(1316), uint16(1305),
	uint16(1240), uint16(1240), uint16(1483), uint16(1316), uint16(1290), uint16(1316), uint16(1305), uint16(1316), uint16(1316), uint16(1581),
	uint16(1240), uint16(1487), uint16(1487), uint16(1483), uint16(1357), uint16(1573), uint16(1573), uint16(1384), uint16(1384), uint16(1389),
	uint16(1375), uint16(1478), uint16(1357), uint16(1240), uint16(1389), uint16(1387), uint16(1385), uint16(1394), uint16(1308), uint16(1595),
	uint16(1595), uint16(1591), uint16(1591), uint16(1591), uint16(1644), uint16(1644), uint16(1542), uint16(1608), uint16(1273), uint16(1273),
	uint16(1273), uint16(1273), uint16(1608), uint16(1292), uint16(1292), uint16(1274), uint16(1274), uint16(1273), uint16(1608), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1603), uint16(1240), uint16(1537), uint16(1494), uint16(1361),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1548), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1421), uint16(1240), uint16(1243), uint16(1539), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1398), uint16(1399), uint16(1362),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1413), uint16(1240), uint16(1240),
	uint16(1240), uint16(1408), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1635), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1508), uint16(1507), uint16(1240),
	uint16(1240), uint16(1359), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1288), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1386),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1578), uint16(1376), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1626), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240),
	uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1240), uint16(1619), uint16(1332), uint16(1423), uint16(1240), uint16(1422),
	uint16(1426), uint16(1262), uint16(1240), uint16(1252), uint16(1240), uint16(1240),
}

var yyFallback = [185]uint16{
	uint16(0),
	uint16(0),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(0),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(0),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(59),
	uint16(0),
	uint16(0),
	uint16(59),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(59),
	uint16(59),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(59),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
	uint16(0),
}

type yyStackEntry = struct {
	Fstateno     uint16
	Fmajor       uint16
	F__ccgo_pad1 [4]byte
	Fminor       YYMINORTYPE
}

type YyStackEntry = yyStackEntry

type yyParser = struct {
	Fyytos      uintptr
	FpParse     uintptr
	Fyystack    [100]YyStackEntry
	FyystackEnd uintptr
}

type YyParser = yyParser

func Xsqlite3ParserInit(tls *libc.TLS, yypRawParser uintptr, pParse uintptr) {
	var yypParser uintptr = yypRawParser
	(*YyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
	(*YyParser)(unsafe.Pointer(yypParser)).Fyytos = yypParser + 16
	(*YyStackEntry)(unsafe.Pointer(yypParser + 16)).Fstateno = uint16(0)
	(*YyStackEntry)(unsafe.Pointer(yypParser + 16)).Fmajor = uint16(0)
	(*YyParser)(unsafe.Pointer(yypParser)).FyystackEnd = yypParser + 16 + 99*24
}

func yy_destructor(tls *libc.TLS, yypParser uintptr, yymajor uint16, yypminor uintptr) {
	var pParse uintptr = (*YyParser)(unsafe.Pointer(yypParser)).FpParse
	switch int32(yymajor) {
	case 204:
		fallthrough
	case 239:
		fallthrough
	case 240:
		fallthrough
	case 252:
		{
			Xsqlite3SelectDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 216:
		fallthrough
	case 217:
		fallthrough
	case 246:
		fallthrough
	case 248:
		fallthrough
	case 267:
		fallthrough
	case 278:
		fallthrough
	case 280:
		fallthrough
	case 283:
		fallthrough
	case 290:
		fallthrough
	case 295:
		fallthrough
	case 311:
		{
			Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 221:
		fallthrough
	case 231:
		fallthrough
	case 232:
		fallthrough
	case 244:
		fallthrough
	case 247:
		fallthrough
	case 249:
		fallthrough
	case 253:
		fallthrough
	case 254:
		fallthrough
	case 261:
		fallthrough
	case 268:
		fallthrough
	case 277:
		fallthrough
	case 279:
		fallthrough
	case 310:
		{
			Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 238:
		fallthrough
	case 245:
		fallthrough
	case 256:
		fallthrough
	case 257:
		fallthrough
	case 262:
		{
			Xsqlite3SrcListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 241:
		{
			Xsqlite3WithDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 251:
		fallthrough
	case 306:
		{
			Xsqlite3WindowListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 263:
		fallthrough
	case 270:
		{
			Xsqlite3IdListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 273:
		fallthrough
	case 307:
		fallthrough
	case 308:
		fallthrough
	case 309:
		fallthrough
	case 312:
		{
			Xsqlite3WindowDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 286:
		fallthrough
	case 291:
		{
			Xsqlite3DeleteTriggerStep(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yypminor)))
		}
		break
	case 288:
		{
			Xsqlite3IdListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*TrigEvent)(unsafe.Pointer(yypminor)).Fb)
		}
		break
	case 314:
		fallthrough
	case 315:
		fallthrough
	case 316:
		{
			Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*FrameBound)(unsafe.Pointer(yypminor)).FpExpr)
		}
		break

	default:
		break
	}
}

func yy_pop_parser_stack(tls *libc.TLS, pParser uintptr) {
	var yytos uintptr

	yytos = libc.PostDecUintptr(&(*YyParser)(unsafe.Pointer(pParser)).Fyytos, 24)
	yy_destructor(tls, pParser, (*YyStackEntry)(unsafe.Pointer(yytos)).Fmajor, yytos+8)
}

func Xsqlite3ParserFinalize(tls *libc.TLS, p uintptr) {
	var pParser uintptr = p
	for (*YyParser)(unsafe.Pointer(pParser)).Fyytos > pParser+16 {
		yy_pop_parser_stack(tls, pParser)
	}
}

func yy_find_shift_action(tls *libc.TLS, iLookAhead uint16, stateno uint16) uint16 {
	var i int32

	if int32(stateno) > YY_MAX_SHIFT {
		return stateno
	}

	for __ccgo := true; __ccgo; __ccgo = 1 != 0 {
		i = int32(yy_shift_ofst[stateno])

		i = i + int32(iLookAhead)

		if int32(yy_lookahead[i]) != int32(iLookAhead) {
			var iFallback uint16

			iFallback = yyFallback[iLookAhead]
			if int32(iFallback) != 0 {
				iLookAhead = iFallback
				continue
			}
			{
				var j int32 = i - int32(iLookAhead) + YYWILDCARD

				if int32(yy_lookahead[j]) == YYWILDCARD && int32(iLookAhead) > 0 {
					return yy_action[j]
				}

			}
			return yy_default[stateno]
		} else {
			return yy_action[i]
		}
	}
	return uint16(0)
}

func yy_find_reduce_action(tls *libc.TLS, stateno uint16, iLookAhead uint16) uint16 {
	var i int32

	i = int32(yy_reduce_ofst[stateno])

	i = i + int32(iLookAhead)

	return yy_action[i]
}

func yyStackOverflow(tls *libc.TLS, yypParser uintptr) {
	var pParse uintptr = (*YyParser)(unsafe.Pointer(yypParser)).FpParse
	for (*YyParser)(unsafe.Pointer(yypParser)).Fyytos > yypParser+16 {
		yy_pop_parser_stack(tls, yypParser)
	}

	Xsqlite3ErrorMsg(tls, pParse, ts+27524, 0)

	(*YyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
}

func yy_shift(tls *libc.TLS, yypParser uintptr, yyNewState uint16, yyMajor uint16, yyMinor Token) {
	var yytos uintptr
	(*YyParser)(unsafe.Pointer(yypParser)).Fyytos += 24
	if (*YyParser)(unsafe.Pointer(yypParser)).Fyytos > (*YyParser)(unsafe.Pointer(yypParser)).FyystackEnd {
		(*YyParser)(unsafe.Pointer(yypParser)).Fyytos -= 24
		yyStackOverflow(tls, yypParser)
		return
	}
	if int32(yyNewState) > YY_MAX_SHIFT {
		yyNewState = uint16(int32(yyNewState) + (YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE))
	}
	yytos = (*YyParser)(unsafe.Pointer(yypParser)).Fyytos
	(*YyStackEntry)(unsafe.Pointer(yytos)).Fstateno = yyNewState
	(*YyStackEntry)(unsafe.Pointer(yytos)).Fmajor = yyMajor
	*(*Token)(unsafe.Pointer(yytos + 8)) = yyMinor

}

var yyRuleInfoLhs = [405]uint16{
	uint16(189),
	uint16(189),
	uint16(188),
	uint16(190),
	uint16(191),
	uint16(191),
	uint16(191),
	uint16(191),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(195),
	uint16(197),
	uint16(199),
	uint16(199),
	uint16(198),
	uint16(198),
	uint16(196),
	uint16(196),
	uint16(203),
	uint16(203),
	uint16(205),
	uint16(205),
	uint16(206),
	uint16(208),
	uint16(208),
	uint16(208),
	uint16(209),
	uint16(213),
	uint16(214),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(224),
	uint16(224),
	uint16(220),
	uint16(220),
	uint16(222),
	uint16(222),
	uint16(225),
	uint16(225),
	uint16(225),
	uint16(225),
	uint16(226),
	uint16(226),
	uint16(226),
	uint16(226),
	uint16(226),
	uint16(223),
	uint16(223),
	uint16(227),
	uint16(227),
	uint16(227),
	uint16(202),
	uint16(229),
	uint16(230),
	uint16(230),
	uint16(230),
	uint16(230),
	uint16(230),
	uint16(233),
	uint16(218),
	uint16(218),
	uint16(234),
	uint16(234),
	uint16(235),
	uint16(235),
	uint16(190),
	uint16(237),
	uint16(237),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(204),
	uint16(204),
	uint16(204),
	uint16(239),
	uint16(242),
	uint16(242),
	uint16(242),
	uint16(240),
	uint16(240),
	uint16(252),
	uint16(252),
	uint16(243),
	uint16(243),
	uint16(243),
	uint16(254),
	uint16(244),
	uint16(244),
	uint16(244),
	uint16(255),
	uint16(255),
	uint16(245),
	uint16(245),
	uint16(257),
	uint16(257),
	uint16(256),
	uint16(256),
	uint16(256),
	uint16(256),
	uint16(256),
	uint16(200),
	uint16(200),
	uint16(238),
	uint16(238),
	uint16(262),
	uint16(262),
	uint16(262),
	uint16(262),
	uint16(258),
	uint16(258),
	uint16(258),
	uint16(258),
	uint16(259),
	uint16(259),
	uint16(259),
	uint16(264),
	uint16(260),
	uint16(260),
	uint16(249),
	uint16(249),
	uint16(231),
	uint16(231),
	uint16(219),
	uint16(219),
	uint16(219),
	uint16(265),
	uint16(265),
	uint16(265),
	uint16(247),
	uint16(247),
	uint16(248),
	uint16(248),
	uint16(250),
	uint16(250),
	uint16(250),
	uint16(250),
	uint16(190),
	uint16(246),
	uint16(246),
	uint16(267),
	uint16(267),
	uint16(267),
	uint16(267),
	uint16(190),
	uint16(268),
	uint16(268),
	uint16(268),
	uint16(268),
	uint16(190),
	uint16(190),
	uint16(271),
	uint16(271),
	uint16(271),
	uint16(271),
	uint16(271),
	uint16(271),
	uint16(272),
	uint16(269),
	uint16(269),
	uint16(270),
	uint16(270),
	uint16(263),
	uint16(263),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(216),
	uint16(216),
	uint16(216),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(216),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(274),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(275),
	uint16(275),
	uint16(217),
	uint16(276),
	uint16(276),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(217),
	uint16(279),
	uint16(279),
	uint16(280),
	uint16(280),
	uint16(278),
	uint16(278),
	uint16(261),
	uint16(253),
	uint16(253),
	uint16(277),
	uint16(277),
	uint16(190),
	uint16(281),
	uint16(281),
	uint16(221),
	uint16(221),
	uint16(232),
	uint16(232),
	uint16(282),
	uint16(282),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(283),
	uint16(283),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(211),
	uint16(212),
	uint16(190),
	uint16(285),
	uint16(287),
	uint16(287),
	uint16(287),
	uint16(288),
	uint16(288),
	uint16(288),
	uint16(290),
	uint16(290),
	uint16(286),
	uint16(286),
	uint16(292),
	uint16(293),
	uint16(293),
	uint16(291),
	uint16(291),
	uint16(291),
	uint16(291),
	uint16(217),
	uint16(217),
	uint16(236),
	uint16(236),
	uint16(236),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(295),
	uint16(295),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(296),
	uint16(190),
	uint16(190),
	uint16(190),
	uint16(298),
	uint16(300),
	uint16(301),
	uint16(301),
	uint16(302),
	uint16(266),
	uint16(266),
	uint16(305),
	uint16(305),
	uint16(305),
	uint16(304),
	uint16(241),
	uint16(241),
	uint16(306),
	uint16(306),
	uint16(307),
	uint16(308),
	uint16(308),
	uint16(308),
	uint16(308),
	uint16(308),
	uint16(308),
	uint16(309),
	uint16(309),
	uint16(309),
	uint16(313),
	uint16(315),
	uint16(315),
	uint16(316),
	uint16(316),
	uint16(314),
	uint16(314),
	uint16(317),
	uint16(317),
	uint16(318),
	uint16(318),
	uint16(318),
	uint16(251),
	uint16(273),
	uint16(273),
	uint16(273),
	uint16(312),
	uint16(312),
	uint16(311),
	uint16(185),
	uint16(186),
	uint16(186),
	uint16(187),
	uint16(187),
	uint16(187),
	uint16(192),
	uint16(192),
	uint16(192),
	uint16(194),
	uint16(194),
	uint16(190),
	uint16(203),
	uint16(201),
	uint16(201),
	uint16(193),
	uint16(193),
	uint16(193),
	uint16(208),
	uint16(209),
	uint16(210),
	uint16(210),
	uint16(207),
	uint16(207),
	uint16(215),
	uint16(215),
	uint16(215),
	uint16(202),
	uint16(228),
	uint16(228),
	uint16(229),
	uint16(233),
	uint16(235),
	uint16(239),
	uint16(240),
	uint16(254),
	uint16(255),
	uint16(264),
	uint16(272),
	uint16(217),
	uint16(274),
	uint16(261),
	uint16(284),
	uint16(284),
	uint16(284),
	uint16(284),
	uint16(284),
	uint16(211),
	uint16(289),
	uint16(289),
	uint16(292),
	uint16(293),
	uint16(294),
	uint16(294),
	uint16(297),
	uint16(297),
	uint16(299),
	uint16(299),
	uint16(300),
	uint16(303),
	uint16(303),
	uint16(303),
	uint16(266),
}

var yyRuleInfoNRhs = [405]int8{
	int8(-1),
	int8(-3),
	int8(-1),
	int8(-3),
	int8(0),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-2),
	int8(-2),
	int8(-2),
	int8(-3),
	int8(-5),
	int8(-6),
	int8(-1),
	int8(0),
	int8(-3),
	int8(-1),
	int8(0),
	int8(-5),
	int8(-2),
	int8(0),
	int8(-3),
	int8(-2),
	int8(-1),
	int8(-2),
	int8(0),
	int8(-4),
	int8(-6),
	int8(-2),
	int8(0),
	int8(0),
	int8(-2),
	int8(-3),
	int8(-4),
	int8(-4),
	int8(-4),
	int8(-3),
	int8(-3),
	int8(-5),
	int8(-2),
	int8(-4),
	int8(-4),
	int8(-1),
	int8(-2),
	int8(-3),
	int8(-4),
	int8(0),
	int8(-1),
	int8(0),
	int8(-2),
	int8(-2),
	int8(-3),
	int8(-3),
	int8(-3),
	int8(-2),
	int8(-2),
	int8(-1),
	int8(-1),
	int8(-2),
	int8(-3),
	int8(-2),
	int8(0),
	int8(-2),
	int8(-2),
	int8(0),
	int8(-1),
	int8(-2),
	int8(-7),
	int8(-5),
	int8(-5),
	int8(-10),
	int8(0),
	int8(0),
	int8(-3),
	int8(0),
	int8(-2),
	int8(-1),
	int8(-1),
	int8(-4),
	int8(-2),
	int8(0),
	int8(-9),
	int8(-4),
	int8(-1),
	int8(-3),
	int8(-4),
	int8(-1),
	int8(-3),
	int8(-1),
	int8(-2),
	int8(-1),
	int8(-9),
	int8(-10),
	int8(-4),
	int8(-5),
	int8(-1),
	int8(-1),
	int8(0),
	int8(0),
	int8(-5),
	int8(-3),
	int8(-5),
	int8(-2),
	int8(0),
	int8(0),
	int8(-2),
	int8(-2),
	int8(0),
	int8(-5),
	int8(-6),
	int8(-8),
	int8(-6),
	int8(-6),
	int8(0),
	int8(-2),
	int8(-1),
	int8(-3),
	int8(-1),
	int8(-3),
	int8(-5),
	int8(-3),
	int8(-1),
	int8(-2),
	int8(-3),
	int8(-4),
	int8(-2),
	int8(-4),
	int8(0),
	int8(0),
	int8(-3),
	int8(-2),
	int8(0),
	int8(-3),
	int8(-5),
	int8(-3),
	int8(-1),
	int8(-1),
	int8(0),
	int8(-2),
	int8(-2),
	int8(0),
	int8(0),
	int8(-3),
	int8(0),
	int8(-2),
	int8(0),
	int8(-2),
	int8(-4),
	int8(-4),
	int8(-6),
	int8(0),
	int8(-2),
	int8(0),
	int8(-2),
	int8(-2),
	int8(-4),
	int8(-9),
	int8(-5),
	int8(-7),
	int8(-3),
	int8(-5),
	int8(-7),
	int8(-8),
	int8(0),
	int8(-2),
	int8(-12),
	int8(-9),
	int8(-5),
	int8(-8),
	int8(-2),
	int8(-2),
	int8(-1),
	int8(0),
	int8(-3),
	int8(-3),
	int8(-1),
	int8(-3),
	int8(-1),
	int8(-1),
	int8(-3),
	int8(-5),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-3),
	int8(-6),
	int8(-5),
	int8(-4),
	int8(-6),
	int8(-5),
	int8(-1),
	int8(-5),
	int8(-3),
	int8(-3),
	int8(-3),
	int8(-3),
	int8(-3),
	int8(-3),
	int8(-3),
	int8(-3),
	int8(-2),
	int8(-3),
	int8(-5),
	int8(-2),
	int8(-3),
	int8(-3),
	int8(-4),
	int8(-6),
	int8(-5),
	int8(-2),
	int8(-2),
	int8(-2),
	int8(-3),
	int8(-1),
	int8(-2),
	int8(-5),
	int8(-1),
	int8(-2),
	int8(-5),
	int8(-3),
	int8(-5),
	int8(-5),
	int8(-4),
	int8(-5),
	int8(-5),
	int8(-4),
	int8(-2),
	int8(0),
	int8(-1),
	int8(0),
	int8(0),
	int8(-3),
	int8(-1),
	int8(0),
	int8(-3),
	int8(-12),
	int8(-1),
	int8(0),
	int8(0),
	int8(-3),
	int8(-5),
	int8(-3),
	int8(0),
	int8(-2),
	int8(-4),
	int8(-2),
	int8(-3),
	int8(-2),
	int8(0),
	int8(-3),
	int8(-5),
	int8(-6),
	int8(-5),
	int8(-6),
	int8(-2),
	int8(-2),
	int8(-5),
	int8(-11),
	int8(-1),
	int8(-2),
	int8(0),
	int8(-1),
	int8(-1),
	int8(-3),
	int8(0),
	int8(-2),
	int8(-3),
	int8(-2),
	int8(-3),
	int8(-3),
	int8(-2),
	int8(-9),
	int8(-8),
	int8(-6),
	int8(-3),
	int8(-4),
	int8(-6),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-4),
	int8(-6),
	int8(-3),
	int8(0),
	int8(-2),
	int8(-1),
	int8(-3),
	int8(-1),
	int8(-3),
	int8(-6),
	int8(-7),
	int8(-6),
	int8(-1),
	int8(-8),
	int8(-1),
	int8(-4),
	int8(-8),
	int8(0),
	int8(-1),
	int8(-3),
	int8(-1),
	int8(-2),
	int8(-3),
	int8(-1),
	int8(-2),
	int8(-3),
	int8(-6),
	int8(-1),
	int8(-3),
	int8(-1),
	int8(-3),
	int8(-5),
	int8(-5),
	int8(-6),
	int8(-4),
	int8(-5),
	int8(-1),
	int8(-2),
	int8(0),
	int8(-3),
	int8(-6),
	int8(-1),
	int8(-1),
	int8(-2),
	int8(-1),
	int8(-2),
	int8(-2),
	int8(-2),
	int8(0),
	int8(-2),
	int8(-2),
	int8(-2),
	int8(-1),
	int8(-2),
	int8(-2),
	int8(-1),
	int8(-1),
	int8(-4),
	int8(-2),
	int8(-5),
	int8(-1),
	int8(-2),
	int8(-1),
	int8(-1),
	int8(-2),
	int8(-3),
	int8(0),
	int8(-1),
	int8(-2),
	int8(-1),
	int8(0),
	int8(-2),
	int8(-1),
	int8(-4),
	int8(-2),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-2),
	int8(0),
	int8(-2),
	int8(-4),
	int8(-2),
	int8(-2),
	int8(-3),
	int8(-1),
	int8(0),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-2),
	int8(-1),
	int8(-1),
	int8(0),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(-1),
	int8(0),
	int8(-3),
	int8(-1),
	int8(0),
	int8(-1),
	int8(0),
	int8(0),
	int8(-1),
	int8(-1),
	int8(-3),
	int8(-2),
	int8(0),
	int8(-4),
	int8(-2),
	int8(0),
}

func yy_reduce(tls *libc.TLS, yypParser uintptr, yyruleno uint32, yyLookahead int32, yyLookaheadToken Token, pParse uintptr) uint16 {
	bp := tls.Alloc(160)
	defer tls.Free(160)

	var yygoto int32
	var yyact uint16
	var yymsp uintptr
	var yysize int32

	_ = yyLookahead
	_ = yyLookaheadToken
	yymsp = (*YyParser)(unsafe.Pointer(yypParser)).Fyytos

	{
		switch yyruleno {
		case uint32(0):
			{
				(*Parse)(unsafe.Pointer(pParse)).Fexplain = U8(1)
			}
			break
		case uint32(1):
			{
				(*Parse)(unsafe.Pointer(pParse)).Fexplain = U8(2)
			}
			break
		case uint32(2):
			{
				Xsqlite3FinishCoding(tls, pParse)
			}
			break
		case uint32(3):
			{
				Xsqlite3BeginTransaction(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(4):
			{
				*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = TK_DEFERRED
			}
			break
		case uint32(5):
			fallthrough
		case uint32(6):
			fallthrough
		case uint32(7):
			fallthrough
		case uint32(323):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = int32((*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor)
			}
			break
		case uint32(8):
			fallthrough
		case uint32(9):
			{
				Xsqlite3EndTransaction(tls, pParse, int32((*YyStackEntry)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24)).Fmajor))
			}
			break
		case uint32(10):
			{
				Xsqlite3Savepoint(tls, pParse, SAVEPOINT_BEGIN, yymsp+8)
			}
			break
		case uint32(11):
			{
				Xsqlite3Savepoint(tls, pParse, SAVEPOINT_RELEASE, yymsp+8)
			}
			break
		case uint32(12):
			{
				Xsqlite3Savepoint(tls, pParse, SAVEPOINT_ROLLBACK, yymsp+8)
			}
			break
		case uint32(13):
			{
				Xsqlite3StartTable(tls, pParse, yymsp+libc.UintptrFromInt32(-1)*24+8, yymsp+8, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), 0, 0, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
			}
			break
		case uint32(14):
			{
				disableLookaside(tls, pParse)
			}
			break
		case uint32(15):
			fallthrough
		case uint32(18):
			fallthrough
		case uint32(47):
			fallthrough
		case uint32(62):
			fallthrough
		case uint32(72):
			fallthrough
		case uint32(81):
			fallthrough
		case uint32(98):
			fallthrough
		case uint32(244):
			{
				*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = 0
			}
			break
		case uint32(16):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = 1
			}
			break
		case uint32(17):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = libc.Bool32(int32((*Sqlite3)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).Fdb)).Finit.Fbusy) == 0)
			}
			break
		case uint32(19):
			{
				Xsqlite3EndTable(tls, pParse, yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+libc.UintptrFromInt32(-1)*24+8, *(*U32)(unsafe.Pointer(yymsp + 8)), uintptr(0))
			}
			break
		case uint32(20):
			{
				Xsqlite3EndTable(tls, pParse, uintptr(0), uintptr(0), uint32(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				Xsqlite3SelectDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(21):
			{
				*(*U32)(unsafe.Pointer(yymsp + 1*24 + 8)) = U32(0)
			}
			break
		case uint32(22):
			{
				*(*U32)(unsafe.Pointer(bp + 40)) = *(*U32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) | *(*U32)(unsafe.Pointer(yymsp + 8))
			}
			*(*U32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*U32)(unsafe.Pointer(bp + 40))
			break
		case uint32(23):
			{
				if (*Token)(unsafe.Pointer(yymsp+8)).Fn == uint32(5) && Xsqlite3_strnicmp(tls, (*Token)(unsafe.Pointer(yymsp+8)).Fz, ts+11466, 5) == 0 {
					*(*U32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = U32(TF_WithoutRowid | TF_NoVisibleRowid)
				} else {
					*(*U32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = U32(0)
					Xsqlite3ErrorMsg(tls, pParse, ts+27546, libc.VaList(bp, (*Token)(unsafe.Pointer(yymsp+8)).Fn, (*Token)(unsafe.Pointer(yymsp+8)).Fz))
				}
			}
			break
		case uint32(24):
			{
				if (*Token)(unsafe.Pointer(yymsp+8)).Fn == uint32(6) && Xsqlite3_strnicmp(tls, (*Token)(unsafe.Pointer(yymsp+8)).Fz, ts+19727, 6) == 0 {
					*(*U32)(unsafe.Pointer(bp + 40)) = U32(TF_Strict)
				} else {
					*(*U32)(unsafe.Pointer(bp + 40)) = U32(0)
					Xsqlite3ErrorMsg(tls, pParse, ts+27546, libc.VaList(bp+16, (*Token)(unsafe.Pointer(yymsp+8)).Fn, (*Token)(unsafe.Pointer(yymsp+8)).Fz))
				}
			}
			*(*U32)(unsafe.Pointer(yymsp + 8)) = *(*U32)(unsafe.Pointer(bp + 40))
			break
		case uint32(25):
			{
				Xsqlite3AddColumn(tls, pParse, *(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*Token)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(26):
			fallthrough
		case uint32(65):
			fallthrough
		case uint32(104):
			{
				(*Token)(unsafe.Pointer(yymsp + 1*24 + 8)).Fn = uint32(0)
				(*Token)(unsafe.Pointer(yymsp + 1*24 + 8)).Fz = uintptr(0)
			}
			break
		case uint32(27):
			{
				(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)).Fn = uint32(int32((int64((*Token)(unsafe.Pointer(yymsp+8)).Fz+uintptr((*Token)(unsafe.Pointer(yymsp+8)).Fn)) - int64((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-3)*24+8)).Fz)) / 1))
			}
			break
		case uint32(28):
			{
				(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)).Fn = uint32(int32((int64((*Token)(unsafe.Pointer(yymsp+8)).Fz+uintptr((*Token)(unsafe.Pointer(yymsp+8)).Fn)) - int64((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-5)*24+8)).Fz)) / 1))
			}
			break
		case uint32(29):
			{
				(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)).Fn = (*Token)(unsafe.Pointer(yymsp+8)).Fn + uint32(int32((int64((*Token)(unsafe.Pointer(yymsp+8)).Fz)-int64((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fz))/1))
			}
			break
		case uint32(30):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = yyLookaheadToken.Fz
			}
			break
		case uint32(31):
			{
				*(*Token)(unsafe.Pointer(yymsp + 1*24 + 8)) = yyLookaheadToken
			}
			break
		case uint32(32):
			fallthrough
		case uint32(67):
			{
				(*Parse)(unsafe.Pointer(pParse)).FconstraintName = *(*Token)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(33):
			{
				Xsqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fz, (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fz+uintptr((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fn))
			}
			break
		case uint32(34):
			{
				Xsqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-2)*24+8)).Fz+uintptr(1), (*Token)(unsafe.Pointer(yymsp+8)).Fz)
			}
			break
		case uint32(35):
			{
				Xsqlite3AddDefaultValue(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-2)*24+8)).Fz, (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fz+uintptr((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fn))
			}
			break
		case uint32(36):
			{
				var p uintptr = Xsqlite3PExpr(tls, pParse, TK_UMINUS, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0))
				Xsqlite3AddDefaultValue(tls, pParse, p, (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-2)*24+8)).Fz, (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fz+uintptr((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fn))
			}
			break
		case uint32(37):
			{
				var p uintptr = tokenExpr(tls, pParse, TK_STRING, *(*Token)(unsafe.Pointer(yymsp + 8)))
				if p != 0 {
					Xsqlite3ExprIdToTrueFalse(tls, p)

				}
				Xsqlite3AddDefaultValue(tls, pParse, p, (*Token)(unsafe.Pointer(yymsp+8)).Fz, (*Token)(unsafe.Pointer(yymsp+8)).Fz+uintptr((*Token)(unsafe.Pointer(yymsp+8)).Fn))
			}
			break
		case uint32(38):
			{
				Xsqlite3AddNotNull(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(39):
			{
				Xsqlite3AddPrimaryKey(tls, pParse, uintptr(0), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
			}
			break
		case uint32(40):
			{
				Xsqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), uintptr(0), *(*int32)(unsafe.Pointer(yymsp + 8)), uintptr(0), uintptr(0), 0, 0,
					uint8(SQLITE_IDXTYPE_UNIQUE))
			}
			break
		case uint32(41):
			{
				Xsqlite3AddCheckConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-2)*24+8)).Fz, (*Token)(unsafe.Pointer(yymsp+8)).Fz)
			}
			break
		case uint32(42):
			{
				Xsqlite3CreateForeignKey(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-2)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(43):
			{
				Xsqlite3DeferForeignKey(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(44):
			{
				Xsqlite3AddCollateType(tls, pParse, yymsp+8)
			}
			break
		case uint32(45):
			{
				Xsqlite3AddGenerated(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uintptr(0))
			}
			break
		case uint32(46):
			{
				Xsqlite3AddGenerated(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), yymsp+8)
			}
			break
		case uint32(48):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = 1
			}
			break
		case uint32(49):
			{
				*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = OE_None * 0x0101
			}
			break
		case uint32(50):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) & ^*(*int32)(unsafe.Pointer(yymsp + 8 + 4)) | *(*int32)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(51):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = 0
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8 + 4)) = 0x000000
			}
			break
		case uint32(52):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = 0
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8 + 4)) = 0x000000
			}
			break
		case uint32(53):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + 8))
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8 + 4)) = 0x0000ff
			}
			break
		case uint32(54):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + 8)) << 8
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8 + 4)) = 0x00ff00
			}
			break
		case uint32(55):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = OE_SetNull
			}
			break
		case uint32(56):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = OE_SetDflt
			}
			break
		case uint32(57):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = OE_Cascade
			}
			break
		case uint32(58):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = OE_Restrict
			}
			break
		case uint32(59):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = OE_None
			}
			break
		case uint32(60):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = 0
			}
			break
		case uint32(61):
			fallthrough
		case uint32(76):
			fallthrough
		case uint32(171):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(63):
			fallthrough
		case uint32(80):
			fallthrough
		case uint32(216):
			fallthrough
		case uint32(219):
			fallthrough
		case uint32(245):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = 1
			}
			break
		case uint32(64):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = 0
			}
			break
		case uint32(66):
			{
				(*Parse)(unsafe.Pointer(pParse)).FconstraintName.Fn = uint32(0)
			}
			break
		case uint32(68):
			{
				Xsqlite3AddPrimaryKey(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), 0)
			}
			break
		case uint32(69):
			{
				Xsqlite3CreateIndex(tls, pParse, uintptr(0), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)), uintptr(0), uintptr(0), 0, 0,
					uint8(SQLITE_IDXTYPE_UNIQUE))
			}
			break
		case uint32(70):
			{
				Xsqlite3AddCheckConstraint(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-3)*24+8)).Fz, (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fz)
			}
			break
		case uint32(71):
			{
				Xsqlite3CreateForeignKey(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8)), yymsp+libc.UintptrFromInt32(-3)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
				Xsqlite3DeferForeignKey(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(73):
			fallthrough
		case uint32(75):
			{
				*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = OE_Default
			}
			break
		case uint32(74):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*int32)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(77):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = OE_Ignore
			}
			break
		case uint32(78):
			fallthrough
		case uint32(172):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = OE_Replace
			}
			break
		case uint32(79):
			{
				Xsqlite3DropTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), 0, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(82):
			{
				Xsqlite3CreateView(tls, pParse, yymsp+libc.UintptrFromInt32(-8)*24+8, yymsp+libc.UintptrFromInt32(-4)*24+8, yymsp+libc.UintptrFromInt32(-3)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)))
			}
			break
		case uint32(83):
			{
				Xsqlite3DropTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), 1, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(84):
			{
				*(*SelectDest)(unsafe.Pointer(bp + 56)) = SelectDest{FeDest: U8(SRT_Output)}
				Xsqlite3Select(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), bp+56)
				Xsqlite3SelectDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(85):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = attachWithToSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(86):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = attachWithToSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(87):
			{
				var p uintptr = *(*uintptr)(unsafe.Pointer(yymsp + 8))
				if p != 0 {
					parserDoubleLinkSelect(tls, pParse, p)
				}
				*(*uintptr)(unsafe.Pointer(yymsp + 8)) = p
			}
			break
		case uint32(88):
			{
				var pRhs uintptr = *(*uintptr)(unsafe.Pointer(yymsp + 8))
				var pLhs uintptr = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8))
				if pRhs != 0 && (*Select)(unsafe.Pointer(pRhs)).FpPrior != 0 {
					var pFrom uintptr

					(*Token)(unsafe.Pointer(bp + 96)).Fn = uint32(0)
					parserDoubleLinkSelect(tls, pParse, pRhs)
					pFrom = Xsqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp+96, pRhs, uintptr(0))
					pRhs = Xsqlite3SelectNew(tls, pParse, uintptr(0), pFrom, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
				}
				if pRhs != 0 {
					(*Select)(unsafe.Pointer(pRhs)).Fop = U8(*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
					(*Select)(unsafe.Pointer(pRhs)).FpPrior = pLhs
					if pLhs != 0 {
						*(*U32)(unsafe.Pointer(pLhs + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_MultiValue))
					}
					*(*U32)(unsafe.Pointer(pRhs + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_MultiValue))
					if *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) != TK_ALL {
						(*Parse)(unsafe.Pointer(pParse)).FhasCompound = U8(1)
					}
				} else {
					Xsqlite3SelectDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pLhs)
				}
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = pRhs
			}
			break
		case uint32(89):
			fallthrough
		case uint32(91):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = int32((*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor)
			}
			break
		case uint32(90):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = TK_ALL
			}
			break
		case uint32(92):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-8)*24 + 8)) = Xsqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uint32(*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8))), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(93):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-9)*24 + 8)) = Xsqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uint32(*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-8)*24 + 8))), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-9)*24 + 8)) != 0 {
					(*Select)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-9)*24 + 8)))).FpWinDefn = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8))
				} else {
					Xsqlite3WindowListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				}
			}
			break
		case uint32(94):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values), uintptr(0))
			}
			break
		case uint32(95):
			{
				var pRight uintptr
				var pLeft uintptr = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8))
				pRight = Xsqlite3SelectNew(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_Values|SF_MultiValue), uintptr(0))
				if pLeft != 0 {
					*(*U32)(unsafe.Pointer(pLeft + 4)) &= libc.Uint32FromInt32(libc.CplInt32(SF_MultiValue))
				}
				if pRight != 0 {
					(*Select)(unsafe.Pointer(pRight)).Fop = U8(TK_ALL)
					(*Select)(unsafe.Pointer(pRight)).FpPrior = pLeft
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = pRight
				} else {
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = pLeft
				}
			}
			break
		case uint32(96):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = SF_Distinct
			}
			break
		case uint32(97):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = SF_All
			}
			break
		case uint32(99):
			fallthrough
		case uint32(132):
			fallthrough
		case uint32(142):
			fallthrough
		case uint32(232):
			fallthrough
		case uint32(235):
			fallthrough
		case uint32(240):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
			}
			break
		case uint32(100):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				if (*Token)(unsafe.Pointer(yymsp+8)).Fn > uint32(0) {
					Xsqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), yymsp+8, 1)
				}
				Xsqlite3ExprListSetSpan(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(101):
			{
				var p uintptr = Xsqlite3Expr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_ASTERISK, uintptr(0))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), p)
			}
			break
		case uint32(102):
			{
				var pRight uintptr = Xsqlite3PExpr(tls, pParse, TK_ASTERISK, uintptr(0), uintptr(0))
				var pLeft uintptr = tokenExpr(tls, pParse, TK_ID, *(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				var pDot uintptr = Xsqlite3PExpr(tls, pParse, TK_DOT, pLeft, pRight)
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), pDot)
			}
			break
		case uint32(103):
			fallthrough
		case uint32(115):
			fallthrough
		case uint32(256):
			fallthrough
		case uint32(257):
			{
				*(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*Token)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(105):
			fallthrough
		case uint32(108):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
			}
			break
		case uint32(106):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
				Xsqlite3SrcListShiftJoinType(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(107):
			{
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) != 0 && (*SrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))).FnSrc > 0 {
					(*SrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) + 8 + uintptr((*SrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))).FnSrc-1)*104)).Ffg.Fjointype = U8(*(*int32)(unsafe.Pointer(yymsp + 8)))
				}
			}
			break
		case uint32(109):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), yymsp+libc.UintptrFromInt32(-3)*24+8, yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+libc.UintptrFromInt32(-1)*24+8, uintptr(0), yymsp+8)
			}
			break
		case uint32(110):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), yymsp+libc.UintptrFromInt32(-4)*24+8, yymsp+libc.UintptrFromInt32(-3)*24+8, yymsp+libc.UintptrFromInt32(-2)*24+8, uintptr(0), yymsp+8)
				Xsqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), yymsp+libc.UintptrFromInt32(-1)*24+8)
			}
			break
		case uint32(111):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8)) = Xsqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8)), yymsp+libc.UintptrFromInt32(-6)*24+8, yymsp+libc.UintptrFromInt32(-5)*24+8, yymsp+libc.UintptrFromInt32(-1)*24+8, uintptr(0), yymsp+8)
				Xsqlite3SrcListFuncArgs(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)))
			}
			break
		case uint32(112):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), uintptr(0), uintptr(0), yymsp+libc.UintptrFromInt32(-1)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), yymsp+8)

			}
			break
		case uint32(113):
			{
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) == uintptr(0) && (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fn == uint32(0) && (*OnOrUsing)(unsafe.Pointer(yymsp+8)).FpOn == uintptr(0) && (*OnOrUsing)(unsafe.Pointer(yymsp+8)).FpUsing == uintptr(0) {
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8))
				} else if (*SrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)))).FnSrc == 1 {
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), uintptr(0), uintptr(0), yymsp+libc.UintptrFromInt32(-1)*24+8, uintptr(0), yymsp+8)
					if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) != 0 {
						var pNew uintptr = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) + 8 + uintptr((*SrcList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)))).FnSrc-1)*104
						var pOld uintptr = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) + 8
						(*SrcItem)(unsafe.Pointer(pNew)).FzName = (*SrcItem)(unsafe.Pointer(pOld)).FzName
						(*SrcItem)(unsafe.Pointer(pNew)).FzDatabase = (*SrcItem)(unsafe.Pointer(pOld)).FzDatabase
						(*SrcItem)(unsafe.Pointer(pNew)).FpSelect = (*SrcItem)(unsafe.Pointer(pOld)).FpSelect
						if (*SrcItem)(unsafe.Pointer(pNew)).FpSelect != 0 && (*Select)(unsafe.Pointer((*SrcItem)(unsafe.Pointer(pNew)).FpSelect)).FselFlags&U32(SF_NestedFrom) != U32(0) {
							libc.SetBitFieldPtr16Uint32(pNew+60+4, uint32(1), 13, 0x2000)
						}
						if uint32(int32(*(*uint16)(unsafe.Pointer(pOld + 60 + 4))&0x4>>2)) != 0 {
							*(*uintptr)(unsafe.Pointer(pNew + 88)) = *(*uintptr)(unsafe.Pointer(pOld + 88))
							*(*uintptr)(unsafe.Pointer(pOld + 88)) = uintptr(0)
							libc.SetBitFieldPtr16Uint32(pOld+60+4, uint32(0), 2, 0x4)
							libc.SetBitFieldPtr16Uint32(pNew+60+4, uint32(1), 2, 0x4)
						}
						(*SrcItem)(unsafe.Pointer(pOld)).FzName = libc.AssignPtrUintptr(pOld+8, uintptr(0))
						(*SrcItem)(unsafe.Pointer(pOld)).FpSelect = uintptr(0)
					}
					Xsqlite3SrcListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)))
				} else {
					var pSubquery uintptr
					Xsqlite3SrcListShiftJoinType(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)))
					pSubquery = Xsqlite3SelectNew(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3SrcListAppendFromTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), uintptr(0), uintptr(0), yymsp+libc.UintptrFromInt32(-1)*24+8, pSubquery, yymsp+8)
				}

			}
			break
		case uint32(114):
			fallthrough
		case uint32(129):
			{
				(*Token)(unsafe.Pointer(yymsp + 1*24 + 8)).Fz = uintptr(0)
				(*Token)(unsafe.Pointer(yymsp + 1*24 + 8)).Fn = uint32(0)
			}
			break
		case uint32(116):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+8, uintptr(0))
				if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && *(*uintptr)(unsafe.Pointer(bp + 40)) != 0 {
					Xsqlite3RenameTokenMap(tls, pParse, (*SrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 40))+8)).FzName, yymsp+8)
				}
			}
			*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(117):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+8)
				if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && *(*uintptr)(unsafe.Pointer(bp + 40)) != 0 {
					Xsqlite3RenameTokenMap(tls, pParse, (*SrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 40))+8)).FzName, yymsp+8)
				}
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(118):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 8)) = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+8, uintptr(0))
			}
			break
		case uint32(119):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+8)
			}
			break
		case uint32(120):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-4)*24+8, yymsp+libc.UintptrFromInt32(-2)*24+8)
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) != 0 {
					(*SrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) + 8)).FzAlias = Xsqlite3NameFromToken(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, yymsp+8)
				}
			}
			break
		case uint32(121):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-2)*24+8, uintptr(0))
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) != 0 {
					(*SrcItem)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) + 8)).FzAlias = Xsqlite3NameFromToken(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, yymsp+8)
				}
			}
			break
		case uint32(122):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = JT_INNER
			}
			break
		case uint32(123):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = Xsqlite3JoinType(tls, pParse, yymsp+libc.UintptrFromInt32(-1)*24+8, uintptr(0), uintptr(0))
			}
			break
		case uint32(124):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3JoinType(tls, pParse, yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+libc.UintptrFromInt32(-1)*24+8, uintptr(0))
			}
			break
		case uint32(125):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3JoinType(tls, pParse, yymsp+libc.UintptrFromInt32(-3)*24+8, yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+libc.UintptrFromInt32(-1)*24+8)
			}
			break
		case uint32(126):
			{
				(*OnOrUsing)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)).FpOn = *(*uintptr)(unsafe.Pointer(yymsp + 8))
				(*OnOrUsing)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)).FpUsing = uintptr(0)
			}
			break
		case uint32(127):
			{
				(*OnOrUsing)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)).FpOn = uintptr(0)
				(*OnOrUsing)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)).FpUsing = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		case uint32(128):
			{
				(*OnOrUsing)(unsafe.Pointer(yymsp + 1*24 + 8)).FpOn = uintptr(0)
				(*OnOrUsing)(unsafe.Pointer(yymsp + 1*24 + 8)).FpUsing = uintptr(0)
			}
			break
		case uint32(130):
			{
				*(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*Token)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(131):
			{
				(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)).Fz = uintptr(0)
				(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)).Fn = uint32(1)
			}
			break
		case uint32(133):
			fallthrough
		case uint32(143):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(134):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				Xsqlite3ExprListSetSortOrder(tls, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(135):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				Xsqlite3ExprListSetSortOrder(tls, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(136):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = SQLITE_SO_ASC
			}
			break
		case uint32(137):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = SQLITE_SO_DESC
			}
			break
		case uint32(138):
			fallthrough
		case uint32(141):
			{
				*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = -1
			}
			break
		case uint32(139):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = SQLITE_SO_ASC
			}
			break
		case uint32(140):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = SQLITE_SO_DESC
			}
			break
		case uint32(144):
			fallthrough
		case uint32(146):
			fallthrough
		case uint32(151):
			fallthrough
		case uint32(153):
			fallthrough
		case uint32(229):
			fallthrough
		case uint32(231):
			fallthrough
		case uint32(250):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
			}
			break
		case uint32(145):
			fallthrough
		case uint32(152):
			fallthrough
		case uint32(154):
			fallthrough
		case uint32(228):
			fallthrough
		case uint32(249):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(147):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_LIMIT, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0))
			}
			break
		case uint32(148):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_LIMIT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(149):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_LIMIT, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
			}
			break
		case uint32(150):
			{
				Xsqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), yymsp+libc.UintptrFromInt32(-1)*24+8)
				Xsqlite3DeleteFrom(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0), uintptr(0))
			}
			break
		case uint32(155):
			{
				Xsqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = uintptr(0)
			}
			break
		case uint32(156):
			{
				Xsqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8))
			}
			break
		case uint32(157):
			{
				Xsqlite3SrcListIndexedBy(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), yymsp+libc.UintptrFromInt32(-4)*24+8)
				Xsqlite3ExprListCheckLength(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), ts+27573)
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) != 0 {
					var pFromClause uintptr = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
					if (*SrcList)(unsafe.Pointer(pFromClause)).FnSrc > 1 {
						var pSubquery uintptr

						pSubquery = Xsqlite3SelectNew(tls, pParse, uintptr(0), pFromClause, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(SF_NestedFrom), uintptr(0))
						(*Token)(unsafe.Pointer(bp + 112)).Fn = uint32(0)
						(*Token)(unsafe.Pointer(bp + 112)).Fz = uintptr(0)
						pFromClause = Xsqlite3SrcListAppendFromTerm(tls, pParse, uintptr(0), uintptr(0), uintptr(0), bp+112, pSubquery, uintptr(0))
					}
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3SrcListAppendList(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), pFromClause)
				}
				Xsqlite3Update(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8)), uintptr(0), uintptr(0), uintptr(0))
			}
			break
		case uint32(158):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				Xsqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), yymsp+libc.UintptrFromInt32(-2)*24+8, 1)
			}
			break
		case uint32(159):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8)) = Xsqlite3ExprListAppendVector(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(160):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				Xsqlite3ExprListSetName(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 40)), yymsp+libc.UintptrFromInt32(-2)*24+8, 1)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(161):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3ExprListAppendVector(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(162):
			{
				Xsqlite3Insert(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(163):
			{
				Xsqlite3Insert(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8)), uintptr(0))
			}
			break
		case uint32(164):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
			}
			break
		case uint32(165):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = uintptr(0)
				Xsqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(166):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-11)*24 + 8)) = Xsqlite3UpsertNew(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-8)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(167):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-8)*24 + 8)) = Xsqlite3UpsertNew(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(168):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3UpsertNew(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
			}
			break
		case uint32(169):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8)) = Xsqlite3UpsertNew(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uintptr(0))
			}
			break
		case uint32(170):
			{
				Xsqlite3AddReturning(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(173):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
			}
			break
		case uint32(174):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		case uint32(175):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3IdListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), yymsp+8)
			}
			break
		case uint32(176):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 8)) = Xsqlite3IdListAppend(tls, pParse, uintptr(0), yymsp+8)
			}
			break
		case uint32(177):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		case uint32(178):
			fallthrough
		case uint32(179):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 8)) = tokenExpr(tls, pParse, TK_ID, *(*Token)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(180):
			{
				var temp1 uintptr = tokenExpr(tls, pParse, TK_ID, *(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				var temp2 uintptr = tokenExpr(tls, pParse, TK_ID, *(*Token)(unsafe.Pointer(yymsp + 8)))
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3PExpr(tls, pParse, TK_DOT, temp1, temp2)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(181):
			{
				var temp1 uintptr = tokenExpr(tls, pParse, TK_ID, *(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))
				var temp2 uintptr = tokenExpr(tls, pParse, TK_ID, *(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				var temp3 uintptr = tokenExpr(tls, pParse, TK_ID, *(*Token)(unsafe.Pointer(yymsp + 8)))
				var temp4 uintptr = Xsqlite3PExpr(tls, pParse, TK_DOT, temp2, temp3)
				if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME {
					Xsqlite3RenameTokenRemap(tls, pParse, uintptr(0), temp1)
				}
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3PExpr(tls, pParse, TK_DOT, temp1, temp4)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(182):
			fallthrough
		case uint32(183):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 8)) = tokenExpr(tls, pParse, int32((*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor), *(*Token)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(184):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3ExprAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_INTEGER, yymsp+8, 1)
				if *(*uintptr)(unsafe.Pointer(bp + 40)) != 0 {
					*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 40)) + 52)) = int32((int64((*Token)(unsafe.Pointer(yymsp+8)).Fz) - int64((*Parse)(unsafe.Pointer(pParse)).FzTail)) / 1)
				}
			}
			*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(185):
			{
				if !(int32(*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(yymsp + 8)).Fz))) == '#' && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(yymsp+8)).Fz + 1))])&0x04 != 0) {
					var n U32 = (*Token)(unsafe.Pointer(yymsp + 8)).Fn
					*(*uintptr)(unsafe.Pointer(yymsp + 8)) = tokenExpr(tls, pParse, TK_VARIABLE, *(*Token)(unsafe.Pointer(yymsp + 8)))
					Xsqlite3ExprAssignVarNumber(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), n)
				} else {
					*(*Token)(unsafe.Pointer(bp + 128)) = *(*Token)(unsafe.Pointer(yymsp + 8))

					if int32((*Parse)(unsafe.Pointer(pParse)).Fnested) == 0 {
						Xsqlite3ErrorMsg(tls, pParse, ts+27582, libc.VaList(bp+32, bp+128))
						*(*uintptr)(unsafe.Pointer(yymsp + 8)) = uintptr(0)
					} else {
						*(*uintptr)(unsafe.Pointer(yymsp + 8)) = Xsqlite3PExpr(tls, pParse, TK_REGISTER, uintptr(0), uintptr(0))
						if *(*uintptr)(unsafe.Pointer(yymsp + 8)) != 0 {
							Xsqlite3GetInt32(tls, (*Token)(unsafe.Pointer(bp+128)).Fz+1, *(*uintptr)(unsafe.Pointer(yymsp + 8))+44)
						}
					}
				}
			}
			break
		case uint32(186):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3ExprAddCollateToken(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), yymsp+8, 1)
			}
			break
		case uint32(187):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3ExprAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_CAST, yymsp+libc.UintptrFromInt32(-1)*24+8, 1)
				Xsqlite3ExprAttachSubtrees(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), uintptr(0))
			}
			break
		case uint32(188):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), yymsp+libc.UintptrFromInt32(-4)*24+8, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(189):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-3)*24+8, 0)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(190):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3ExprFunction(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), yymsp+libc.UintptrFromInt32(-5)*24+8, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)))
				Xsqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 40)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(191):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-4)*24+8, 0)
				Xsqlite3WindowAttach(tls, pParse, *(*uintptr)(unsafe.Pointer(bp + 40)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(192):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3ExprFunction(tls, pParse, uintptr(0), yymsp+8, 0)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(193):
			{
				var pList uintptr = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_VECTOR, uintptr(0), uintptr(0))
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) != 0 {
					*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) + 32)) = pList
					if (*ExprList)(unsafe.Pointer(pList)).FnExpr != 0 {
						*(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) + 4)) |= (*Expr)(unsafe.Pointer((*ExprList_item)(unsafe.Pointer(pList+8)).FpExpr)).Fflags & U32(EP_Collate|EP_Subquery|EP_HasFunc)
					}
				} else {
					Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pList)
				}
			}
			break
		case uint32(194):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3ExprAnd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(195):
			fallthrough
		case uint32(196):
			fallthrough
		case uint32(197):
			fallthrough
		case uint32(198):
			fallthrough
		case uint32(199):
			fallthrough
		case uint32(200):
			fallthrough
		case uint32(201):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3PExpr(tls, pParse, int32((*YyStackEntry)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24)).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(202):
			{
				*(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*Token)(unsafe.Pointer(yymsp + 8))
				*(*uint32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8 + 8)) |= 0x80000000
			}
			break
		case uint32(203):
			{
				var pList uintptr
				var bNot int32 = int32((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fn & 0x80000000)
				*(*uint32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8 + 8)) &= uint32(0x7fffffff)
				pList = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				pList = Xsqlite3ExprListAppend(tls, pParse, pList, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3ExprFunction(tls, pParse, pList, yymsp+libc.UintptrFromInt32(-1)*24+8, 0)
				if bNot != 0 {
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_NOT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), uintptr(0))
				}
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) != 0 {
					*(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) + 4)) |= U32(EP_InfixFunc)
				}
			}
			break
		case uint32(204):
			{
				var pList uintptr
				var bNot int32 = int32((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-3)*24+8)).Fn & 0x80000000)
				*(*uint32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8 + 8)) &= uint32(0x7fffffff)
				pList = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				pList = Xsqlite3ExprListAppend(tls, pParse, pList, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))
				pList = Xsqlite3ExprListAppend(tls, pParse, pList, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3ExprFunction(tls, pParse, pList, yymsp+libc.UintptrFromInt32(-3)*24+8, 0)
				if bNot != 0 {
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_NOT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
				}
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) != 0 {
					*(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) + 4)) |= U32(EP_InfixFunc)
				}
			}
			break
		case uint32(205):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = Xsqlite3PExpr(tls, pParse, int32((*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uintptr(0))
			}
			break
		case uint32(206):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_NOTNULL, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), uintptr(0))
			}
			break
		case uint32(207):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_IS, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				binaryToUnaryIfNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), TK_ISNULL)
			}
			break
		case uint32(208):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_ISNOT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				binaryToUnaryIfNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), TK_NOTNULL)
			}
			break
		case uint32(209):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_IS, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				binaryToUnaryIfNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), TK_ISNULL)
			}
			break
		case uint32(210):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_ISNOT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				binaryToUnaryIfNull(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), TK_NOTNULL)
			}
			break
		case uint32(211):
			fallthrough
		case uint32(212):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = Xsqlite3PExpr(tls, pParse, int32((*YyStackEntry)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24)).Fmajor), *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0))
			}
			break
		case uint32(213):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = Xsqlite3PExpr(tls, pParse, func() int32 {
					if int32((*YyStackEntry)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24)).Fmajor) == TK_PLUS {
						return TK_UPLUS
					}
					return TK_UMINUS
				}(), *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0))

			}
			break
		case uint32(214):
			{
				var pList uintptr = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				pList = Xsqlite3ExprListAppend(tls, pParse, pList, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3ExprFunction(tls, pParse, pList, yymsp+libc.UintptrFromInt32(-1)*24+8, 0)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(215):
			fallthrough
		case uint32(218):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = 0
			}
			break
		case uint32(217):
			{
				var pList uintptr = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				pList = Xsqlite3ExprListAppend(tls, pParse, pList, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_BETWEEN, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) != 0 {
					*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) + 32)) = pList
				} else {
					Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, pList)
				}
				if *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) != 0 {
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_NOT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
				}
			}
			break
		case uint32(220):
			{
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) == uintptr(0) {
					Xsqlite3ExprUnmapAndDelete(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3Expr(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_STRING, func() uintptr {
						if *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) != 0 {
							return ts + 10909
						}
						return ts + 10914
					}())
					if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) != 0 {
						Xsqlite3ExprIdToTrueFalse(tls, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))
					}
				} else {
					var pRHS uintptr = (*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) + 8)).FpExpr
					if (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))).FnExpr == 1 && Xsqlite3ExprIsConstant(tls, pRHS) != 0 && int32((*Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))).Fop) != TK_VECTOR {
						(*ExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) + 8)).FpExpr = uintptr(0)
						Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
						pRHS = Xsqlite3PExpr(tls, pParse, TK_UPLUS, pRHS, uintptr(0))
						*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_EQ, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), pRHS)
					} else if (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))).FnExpr == 1 && int32((*Expr)(unsafe.Pointer(pRHS)).Fop) == TK_SELECT {
						*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_IN, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
						Xsqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(pRHS + 32)))
						*(*uintptr)(unsafe.Pointer(pRHS + 32)) = uintptr(0)
						Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
					} else {
						*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_IN, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
						if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) == uintptr(0) {
							Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
						} else if int32((*Expr)(unsafe.Pointer((*Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))).FpLeft)).Fop) == TK_VECTOR {
							var nExpr int32 = (*ExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))).FpLeft + 32)))).FnExpr
							var pSelectRHS uintptr = Xsqlite3ExprListToValues(tls, pParse, nExpr, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
							if pSelectRHS != 0 {
								parserDoubleLinkSelect(tls, pParse, pSelectRHS)
								Xsqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), pSelectRHS)
							}
						} else {
							*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) + 32)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
							Xsqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))
						}
					}
					if *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) != 0 {
						*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_NOT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
					}
				}

			}
			break
		case uint32(221):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_SELECT, uintptr(0), uintptr(0))
				Xsqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))

			}
			break
		case uint32(222):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_IN, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
				Xsqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
				if *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) != 0 {
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_NOT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
				}

			}
			break
		case uint32(223):
			{
				var pSrc uintptr = Xsqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+libc.UintptrFromInt32(-1)*24+8)
				var pSelect uintptr = Xsqlite3SelectNew(tls, pParse, uintptr(0), pSrc, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
				if *(*uintptr)(unsafe.Pointer(yymsp + 8)) != 0 {
					Xsqlite3SrcListFuncArgs(tls, pParse, func() uintptr {
						if pSelect != 0 {
							return pSrc
						}
						return uintptr(0)
					}(), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				}
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_IN, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
				Xsqlite3PExprAddSelect(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), pSelect)
				if *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) != 0 {
					*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_NOT, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), uintptr(0))
				}

			}
			break
		case uint32(224):
			{
				var p uintptr
				p = libc.AssignPtrUintptr(yymsp+libc.UintptrFromInt32(-3)*24+8, Xsqlite3PExpr(tls, pParse, TK_EXISTS, uintptr(0), uintptr(0)))
				Xsqlite3PExprAddSelect(tls, pParse, p, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))

			}
			break
		case uint32(225):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_CASE, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), uintptr(0))
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) != 0 {
					*(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) + 32)) = func() uintptr {
						if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) != 0 {
							return Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
						}
						return *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8))
					}()
					Xsqlite3ExprSetHeightAndFlags(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))
				} else {
					Xsqlite3ExprListDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
					Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
				}
			}
			break
		case uint32(226):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(227):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(230):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(233):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3ExprListAppend(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(234):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 8)) = Xsqlite3ExprListAppend(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(236):
			fallthrough
		case uint32(241):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		case uint32(237):
			{
				Xsqlite3CreateIndex(tls, pParse, yymsp+libc.UintptrFromInt32(-7)*24+8, yymsp+libc.UintptrFromInt32(-6)*24+8,
					Xsqlite3SrcListAppend(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-4)*24+8, uintptr(0)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-10)*24 + 8)),
					yymsp+libc.UintptrFromInt32(-11)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + 8)), SQLITE_SO_ASC, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-8)*24 + 8)), uint8(SQLITE_IDXTYPE_APPDEF))
				if int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME && (*Parse)(unsafe.Pointer(pParse)).FpNewIndex != 0 {
					Xsqlite3RenameTokenMap(tls, pParse, (*Index)(unsafe.Pointer((*Parse)(unsafe.Pointer(pParse)).FpNewIndex)).FzName, yymsp+libc.UintptrFromInt32(-4)*24+8)
				}
			}
			break
		case uint32(238):
			fallthrough
		case uint32(280):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = OE_Abort
			}
			break
		case uint32(239):
			{
				*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = OE_None
			}
			break
		case uint32(242):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = parserAddExprIdListTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), yymsp+libc.UintptrFromInt32(-2)*24+8, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(243):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = parserAddExprIdListTerm(tls, pParse, uintptr(0), yymsp+libc.UintptrFromInt32(-2)*24+8, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(246):
			{
				Xsqlite3DropIndex(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(247):
			{
				Xsqlite3Vacuum(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(248):
			{
				Xsqlite3Vacuum(tls, pParse, yymsp+libc.UintptrFromInt32(-1)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(251):
			{
				Xsqlite3Pragma(tls, pParse, yymsp+libc.UintptrFromInt32(-1)*24+8, yymsp+8, uintptr(0), 0)
			}
			break
		case uint32(252):
			{
				Xsqlite3Pragma(tls, pParse, yymsp+libc.UintptrFromInt32(-3)*24+8, yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+8, 0)
			}
			break
		case uint32(253):
			{
				Xsqlite3Pragma(tls, pParse, yymsp+libc.UintptrFromInt32(-4)*24+8, yymsp+libc.UintptrFromInt32(-3)*24+8, yymsp+libc.UintptrFromInt32(-1)*24+8, 0)
			}
			break
		case uint32(254):
			{
				Xsqlite3Pragma(tls, pParse, yymsp+libc.UintptrFromInt32(-3)*24+8, yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+8, 1)
			}
			break
		case uint32(255):
			{
				Xsqlite3Pragma(tls, pParse, yymsp+libc.UintptrFromInt32(-4)*24+8, yymsp+libc.UintptrFromInt32(-3)*24+8, yymsp+libc.UintptrFromInt32(-1)*24+8, 1)
			}
			break
		case uint32(258):
			{
				(*Token)(unsafe.Pointer(bp + 144)).Fz = (*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)).Fz
				(*Token)(unsafe.Pointer(bp + 144)).Fn = uint32(int32((int64((*Token)(unsafe.Pointer(yymsp+8)).Fz)-int64((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-3)*24+8)).Fz))/1)) + (*Token)(unsafe.Pointer(yymsp+8)).Fn
				Xsqlite3FinishTrigger(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), bp+144)
			}
			break
		case uint32(259):
			{
				Xsqlite3BeginTrigger(tls, pParse, yymsp+libc.UintptrFromInt32(-7)*24+8, yymsp+libc.UintptrFromInt32(-6)*24+8, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), (*TrigEvent)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-4)*24+8)).Fa, (*TrigEvent)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-4)*24+8)).Fb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-10)*24 + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-8)*24 + 8)))
				*(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-10)*24 + 8)) = func() Token1 {
					if (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-6)*24+8)).Fn == uint32(0) {
						return *(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8))
					}
					return *(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8))
				}()
			}
			break
		case uint32(260):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = int32((*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor)
			}
			break
		case uint32(261):
			{
				*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = TK_INSTEAD
			}
			break
		case uint32(262):
			{
				*(*int32)(unsafe.Pointer(yymsp + 1*24 + 8)) = TK_BEFORE
			}
			break
		case uint32(263):
			fallthrough
		case uint32(264):
			{
				(*TrigEvent)(unsafe.Pointer(yymsp + 8)).Fa = int32((*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor)
				(*TrigEvent)(unsafe.Pointer(yymsp + 8)).Fb = uintptr(0)
			}
			break
		case uint32(265):
			{
				(*TrigEvent)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)).Fa = TK_UPDATE
				(*TrigEvent)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)).Fb = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(266):
			fallthrough
		case uint32(285):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = uintptr(0)
			}
			break
		case uint32(267):
			fallthrough
		case uint32(286):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(268):
			{
				(*TriggerStep)(unsafe.Pointer((*TriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))).FpLast)).FpNext = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
				(*TriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))).FpLast = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		case uint32(269):
			{
				(*TriggerStep)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))).FpLast = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		case uint32(270):
			{
				*(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*Token)(unsafe.Pointer(yymsp + 8))
				Xsqlite3ErrorMsg(tls, pParse,
					ts+27606, 0)
			}
			break
		case uint32(271):
			{
				Xsqlite3ErrorMsg(tls, pParse,
					ts+27701, 0)
			}
			break
		case uint32(272):
			{
				Xsqlite3ErrorMsg(tls, pParse,
					ts+27785, 0)
			}
			break
		case uint32(273):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3TriggerUpdateStep(tls, pParse, yymsp+libc.UintptrFromInt32(-6)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uint8(*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8))), (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-8)*24+8)).Fz, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-8)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(274):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3TriggerInsertStep(tls, pParse, yymsp+libc.UintptrFromInt32(-4)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), uint8(*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-6)*24 + 8))), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-7)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(275):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3TriggerDeleteStep(tls, pParse, yymsp+libc.UintptrFromInt32(-3)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-5)*24+8)).Fz, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(276):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3TriggerSelectStep(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(277):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3PExpr(tls, pParse, TK_RAISE, uintptr(0), uintptr(0))
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) != 0 {
					(*Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)))).FaffExpr = uint8(OE_Ignore)
				}
			}
			break
		case uint32(278):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3ExprAlloc(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, TK_RAISE, yymsp+libc.UintptrFromInt32(-1)*24+8, 1)
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) != 0 {
					(*Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)))).FaffExpr = uint8(*(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)))
				}
			}
			break
		case uint32(279):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = OE_Rollback
			}
			break
		case uint32(281):
			{
				*(*int32)(unsafe.Pointer(yymsp + 8)) = OE_Fail
			}
			break
		case uint32(282):
			{
				Xsqlite3DropTrigger(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(283):
			{
				Xsqlite3Attach(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(284):
			{
				Xsqlite3Detach(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(287):
			{
				Xsqlite3Reindex(tls, pParse, uintptr(0), uintptr(0))
			}
			break
		case uint32(288):
			{
				Xsqlite3Reindex(tls, pParse, yymsp+libc.UintptrFromInt32(-1)*24+8, yymsp+8)
			}
			break
		case uint32(289):
			{
				Xsqlite3Analyze(tls, pParse, uintptr(0), uintptr(0))
			}
			break
		case uint32(290):
			{
				Xsqlite3Analyze(tls, pParse, yymsp+libc.UintptrFromInt32(-1)*24+8, yymsp+8)
			}
			break
		case uint32(291):
			{
				Xsqlite3AlterRenameTable(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), yymsp+8)
			}
			break
		case uint32(292):
			{
				(*Token)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)).Fn = uint32(int32((int64((*Parse)(unsafe.Pointer(pParse)).FsLastToken.Fz)-int64((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).Fz))/1)) + (*Parse)(unsafe.Pointer(pParse)).FsLastToken.Fn
				Xsqlite3AlterFinishAddColumn(tls, pParse, yymsp+libc.UintptrFromInt32(-1)*24+8)
			}
			break
		case uint32(293):
			{
				Xsqlite3AlterDropColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)), yymsp+8)
			}
			break
		case uint32(294):
			{
				disableLookaside(tls, pParse)
				Xsqlite3AlterBeginAddColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(295):
			{
				Xsqlite3AlterRenameColumn(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+8)
			}
			break
		case uint32(296):
			{
				Xsqlite3VtabFinishParse(tls, pParse, uintptr(0))
			}
			break
		case uint32(297):
			{
				Xsqlite3VtabFinishParse(tls, pParse, yymsp+8)
			}
			break
		case uint32(298):
			{
				Xsqlite3VtabBeginParse(tls, pParse, yymsp+libc.UintptrFromInt32(-3)*24+8, yymsp+libc.UintptrFromInt32(-2)*24+8, yymsp+8, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)))
			}
			break
		case uint32(299):
			{
				Xsqlite3VtabArgInit(tls, pParse)
			}
			break
		case uint32(300):
			fallthrough
		case uint32(301):
			fallthrough
		case uint32(302):
			{
				Xsqlite3VtabArgExtend(tls, pParse, yymsp+8)
			}
			break
		case uint32(303):
			fallthrough
		case uint32(304):
			{
				Xsqlite3WithPush(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uint8(1))
			}
			break
		case uint32(305):
			{
				*(*U8)(unsafe.Pointer(yymsp + 8)) = U8(M10d_Any)
			}
			break
		case uint32(306):
			{
				*(*U8)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = U8(M10d_Yes)
			}
			break
		case uint32(307):
			{
				*(*U8)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = U8(M10d_No)
			}
			break
		case uint32(308):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = Xsqlite3CteNew(tls, pParse, yymsp+libc.UintptrFromInt32(-5)*24+8, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*U8)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)))
			}
			break
		case uint32(309):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 8)) = Xsqlite3WithAdd(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(310):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = Xsqlite3WithAdd(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + 8)))
			}
			break
		case uint32(311):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(312):
			{
				Xsqlite3WindowChain(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
				(*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 8)))).FpNextWin = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8))
				*(*uintptr)(unsafe.Pointer(bp + 40)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(313):
			{
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) != 0 {
					(*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))).FzName = Xsqlite3DbStrNDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-4)*24+8)).Fz, uint64((*Token)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-4)*24+8)).Fn))
				}
				*(*uintptr)(unsafe.Pointer(bp + 40)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(314):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = Xsqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uintptr(0))
			}
			break
		case uint32(315):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), yymsp+libc.UintptrFromInt32(-5)*24+8)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(316):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = Xsqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), uintptr(0))
			}
			break
		case uint32(317):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0), *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)), yymsp+libc.UintptrFromInt32(-4)*24+8)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(318):
			fallthrough
		case uint32(337):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(319):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3WindowAssemble(tls, pParse, *(*uintptr)(unsafe.Pointer(yymsp + 8)), uintptr(0), uintptr(0), yymsp+libc.UintptrFromInt32(-1)*24+8)
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(320):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + 1*24 + 8)) = Xsqlite3WindowAlloc(tls, pParse, 0, TK_UNBOUNDED, uintptr(0), TK_CURRENT, uintptr(0), uint8(0))
			}
			break
		case uint32(321):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3WindowAlloc(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)), (*FrameBound)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).FeType, (*FrameBound)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).FpExpr, TK_CURRENT, uintptr(0), *(*U8)(unsafe.Pointer(yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(322):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3WindowAlloc(tls, pParse, *(*int32)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)), (*FrameBound)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-3)*24+8)).FeType, (*FrameBound)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-3)*24+8)).FpExpr, (*FrameBound)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).FeType, (*FrameBound)(unsafe.Pointer(yymsp+libc.UintptrFromInt32(-1)*24+8)).FpExpr, *(*U8)(unsafe.Pointer(yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-5)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(324):
			fallthrough
		case uint32(326):
			{
				*(*FrameBound)(unsafe.Pointer(bp + 40)) = *(*FrameBound)(unsafe.Pointer(yymsp + 8))
			}
			*(*FrameBound)(unsafe.Pointer(yymsp + 8)) = *(*FrameBound)(unsafe.Pointer(bp + 40))
			break
		case uint32(325):
			fallthrough
		case uint32(327):
			fallthrough
		case uint32(329):
			{
				(*FrameBound)(unsafe.Pointer(bp + 40)).FeType = int32((*YyStackEntry)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24)).Fmajor)
				(*FrameBound)(unsafe.Pointer(bp + 40)).FpExpr = uintptr(0)
			}
			*(*FrameBound)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*FrameBound)(unsafe.Pointer(bp + 40))
			break
		case uint32(328):
			{
				(*FrameBound)(unsafe.Pointer(bp + 40)).FeType = int32((*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor)
				(*FrameBound)(unsafe.Pointer(bp + 40)).FpExpr = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			*(*FrameBound)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*FrameBound)(unsafe.Pointer(bp + 40))
			break
		case uint32(330):
			{
				*(*U8)(unsafe.Pointer(yymsp + 1*24 + 8)) = U8(0)
			}
			break
		case uint32(331):
			{
				*(*U8)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*U8)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(332):
			fallthrough
		case uint32(333):
			{
				*(*U8)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = U8((*YyStackEntry)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24)).Fmajor)
			}
			break
		case uint32(334):
			{
				*(*U8)(unsafe.Pointer(yymsp + 8)) = U8((*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor)
			}
			break
		case uint32(335):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			break
		case uint32(336):
			{
				if *(*uintptr)(unsafe.Pointer(yymsp + 8)) != 0 {
					(*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + 8)))).FpFilter = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
				} else {
					Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
				}
				*(*uintptr)(unsafe.Pointer(bp + 40)) = *(*uintptr)(unsafe.Pointer(yymsp + 8))
			}
			*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(338):
			{
				*(*uintptr)(unsafe.Pointer(bp + 40)) = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(Window{})))
				if *(*uintptr)(unsafe.Pointer(bp + 40)) != 0 {
					(*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 40)))).FeFrmType = U8(TK_FILTER)
					(*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 40)))).FpFilter = *(*uintptr)(unsafe.Pointer(yymsp + 8))
				} else {
					Xsqlite3ExprDelete(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(yymsp + 8)))
				}
			}
			*(*uintptr)(unsafe.Pointer(yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp + 40))
			break
		case uint32(339):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))

			}
			break
		case uint32(340):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = Xsqlite3DbMallocZero(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, uint64(unsafe.Sizeof(Window{})))
				if *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)) != 0 {
					(*Window)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8)))).FzName = Xsqlite3DbStrNDup(tls, (*Parse)(unsafe.Pointer(pParse)).Fdb, (*Token)(unsafe.Pointer(yymsp+8)).Fz, uint64((*Token)(unsafe.Pointer(yymsp+8)).Fn))
				}
			}
			break
		case uint32(341):
			{
				*(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = *(*uintptr)(unsafe.Pointer(yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		default:
			break

		}
	}

	yygoto = int32(yyRuleInfoLhs[yyruleno])
	yysize = int32(yyRuleInfoNRhs[yyruleno])
	yyact = yy_find_reduce_action(tls, (*YyStackEntry)(unsafe.Pointer(yymsp+uintptr(yysize)*24)).Fstateno, uint16(yygoto))

	yymsp += 24 * uintptr(yysize+1)
	(*YyParser)(unsafe.Pointer(yypParser)).Fyytos = yymsp
	(*YyStackEntry)(unsafe.Pointer(yymsp)).Fstateno = yyact
	(*YyStackEntry)(unsafe.Pointer(yymsp)).Fmajor = uint16(yygoto)

	return yyact
}

func yy_syntax_error(tls *libc.TLS, yypParser uintptr, yymajor int32, yyminor Token) {
	bp := tls.Alloc(24)
	defer tls.Free(24)
	*(*Token)(unsafe.Pointer(bp + 8)) = yyminor

	var pParse uintptr = (*YyParser)(unsafe.Pointer(yypParser)).FpParse

	_ = yymajor
	if *(*uint8)(unsafe.Pointer((*Token)(unsafe.Pointer(bp + 8)).Fz)) != 0 {
		Xsqlite3ErrorMsg(tls, pParse, ts+27582, libc.VaList(bp, bp+8))
	} else {
		Xsqlite3ErrorMsg(tls, pParse, ts+27870, 0)
	}

	(*YyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
}

func yy_accept(tls *libc.TLS, yypParser uintptr) {
	var pParse uintptr = (*YyParser)(unsafe.Pointer(yypParser)).FpParse

	(*YyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
}

func Xsqlite3Parser(tls *libc.TLS, yyp uintptr, yymajor int32, yyminor Token) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var yyact uint16
	var yypParser uintptr = yyp
	var pParse uintptr = (*YyParser)(unsafe.Pointer(yypParser)).FpParse

	yyact = (*YyStackEntry)(unsafe.Pointer((*YyParser)(unsafe.Pointer(yypParser)).Fyytos)).Fstateno

	for 1 != 0 {
		yyact = yy_find_shift_action(tls, uint16(yymajor), yyact)
		if int32(yyact) >= YY_MIN_REDUCE {
			var yyruleno uint32 = uint32(int32(yyact) - YY_MIN_REDUCE)

			if int32(yyRuleInfoNRhs[yyruleno]) == 0 {
				if (*YyParser)(unsafe.Pointer(yypParser)).Fyytos >= (*YyParser)(unsafe.Pointer(yypParser)).FyystackEnd {
					yyStackOverflow(tls, yypParser)
					break
				}
			}
			yyact = yy_reduce(tls, yypParser, yyruleno, yymajor, yyminor, pParse)
		} else if int32(yyact) <= YY_MAX_SHIFTREDUCE {
			yy_shift(tls, yypParser, yyact, uint16(yymajor), yyminor)
			break
		} else if int32(yyact) == YY_ACCEPT_ACTION {
			(*YyParser)(unsafe.Pointer(yypParser)).Fyytos -= 24
			yy_accept(tls, yypParser)
			return
		} else {
			*(*Token)(unsafe.Pointer(bp)) = yyminor

			yy_syntax_error(tls, yypParser, yymajor, yyminor)
			yy_destructor(tls, yypParser, uint16(yymajor), bp)
			break
		}
	}
	return
}

func Xsqlite3ParserFallback(tls *libc.TLS, iToken int32) int32 {
	return int32(yyFallback[iToken])
}

var aiClass = [256]uint8{
	uint8(29), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(7), uint8(7), uint8(28), uint8(7), uint8(7), uint8(28), uint8(28),
	uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28), uint8(28),
	uint8(7), uint8(15), uint8(8), uint8(5), uint8(4), uint8(22), uint8(24), uint8(8), uint8(17), uint8(18), uint8(21), uint8(20), uint8(23), uint8(11), uint8(26), uint8(16),
	uint8(3), uint8(3), uint8(3), uint8(3), uint8(3), uint8(3), uint8(3), uint8(3), uint8(3), uint8(3), uint8(5), uint8(19), uint8(12), uint8(14), uint8(13), uint8(6),
	uint8(5), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1),
	uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(0), uint8(2), uint8(2), uint8(9), uint8(28), uint8(28), uint8(28), uint8(2),
	uint8(8), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1),
	uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(0), uint8(2), uint8(2), uint8(28), uint8(10), uint8(28), uint8(25), uint8(28),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(30),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
}

var zKWText = [666]uint8{
	uint8('R'), uint8('E'), uint8('I'), uint8('N'), uint8('D'), uint8('E'), uint8('X'), uint8('E'), uint8('D'), uint8('E'), uint8('S'), uint8('C'), uint8('A'), uint8('P'), uint8('E'), uint8('A'), uint8('C'), uint8('H'),
	uint8('E'), uint8('C'), uint8('K'), uint8('E'), uint8('Y'), uint8('B'), uint8('E'), uint8('F'), uint8('O'), uint8('R'), uint8('E'), uint8('I'), uint8('G'), uint8('N'), uint8('O'), uint8('R'), uint8('E'), uint8('G'),
	uint8('E'), uint8('X'), uint8('P'), uint8('L'), uint8('A'), uint8('I'), uint8('N'), uint8('S'), uint8('T'), uint8('E'), uint8('A'), uint8('D'), uint8('D'), uint8('A'), uint8('T'), uint8('A'), uint8('B'), uint8('A'),
	uint8('S'), uint8('E'), uint8('L'), uint8('E'), uint8('C'), uint8('T'), uint8('A'), uint8('B'), uint8('L'), uint8('E'), uint8('F'), uint8('T'), uint8('H'), uint8('E'), uint8('N'), uint8('D'), uint8('E'), uint8('F'),
	uint8('E'), uint8('R'), uint8('R'), uint8('A'), uint8('B'), uint8('L'), uint8('E'), uint8('L'), uint8('S'), uint8('E'), uint8('X'), uint8('C'), uint8('L'), uint8('U'), uint8('D'), uint8('E'), uint8('L'), uint8('E'),
	uint8('T'), uint8('E'), uint8('M'), uint8('P'), uint8('O'), uint8('R'), uint8('A'), uint8('R'), uint8('Y'), uint8('I'), uint8('S'), uint8('N'), uint8('U'), uint8('L'), uint8('L'), uint8('S'), uint8('A'), uint8('V'),
	uint8('E'), uint8('P'), uint8('O'), uint8('I'), uint8('N'), uint8('T'), uint8('E'), uint8('R'), uint8('S'), uint8('E'), uint8('C'), uint8('T'), uint8('I'), uint8('E'), uint8('S'), uint8('N'), uint8('O'), uint8('T'),
	uint8('N'), uint8('U'), uint8('L'), uint8('L'), uint8('I'), uint8('K'), uint8('E'), uint8('X'), uint8('C'), uint8('E'), uint8('P'), uint8('T'), uint8('R'), uint8('A'), uint8('N'), uint8('S'), uint8('A'), uint8('C'),
	uint8('T'), uint8('I'), uint8('O'), uint8('N'), uint8('A'), uint8('T'), uint8('U'), uint8('R'), uint8('A'), uint8('L'), uint8('T'), uint8('E'), uint8('R'), uint8('A'), uint8('I'), uint8('S'), uint8('E'), uint8('X'),
	uint8('C'), uint8('L'), uint8('U'), uint8('S'), uint8('I'), uint8('V'), uint8('E'), uint8('X'), uint8('I'), uint8('S'), uint8('T'), uint8('S'), uint8('C'), uint8('O'), uint8('N'), uint8('S'), uint8('T'), uint8('R'),
	uint8('A'), uint8('I'), uint8('N'), uint8('T'), uint8('O'), uint8('F'), uint8('F'), uint8('S'), uint8('E'), uint8('T'), uint8('R'), uint8('I'), uint8('G'), uint8('G'), uint8('E'), uint8('R'), uint8('A'), uint8('N'),
	uint8('G'), uint8('E'), uint8('N'), uint8('E'), uint8('R'), uint8('A'), uint8('T'), uint8('E'), uint8('D'), uint8('E'), uint8('T'), uint8('A'), uint8('C'), uint8('H'), uint8('A'), uint8('V'), uint8('I'), uint8('N'),
	uint8('G'), uint8('L'), uint8('O'), uint8('B'), uint8('E'), uint8('G'), uint8('I'), uint8('N'), uint8('N'), uint8('E'), uint8('R'), uint8('E'), uint8('F'), uint8('E'), uint8('R'), uint8('E'), uint8('N'), uint8('C'),
	uint8('E'), uint8('S'), uint8('U'), uint8('N'), uint8('I'), uint8('Q'), uint8('U'), uint8('E'), uint8('R'), uint8('Y'), uint8('W'), uint8('I'), uint8('T'), uint8('H'), uint8('O'), uint8('U'), uint8('T'), uint8('E'),
	uint8('R'), uint8('E'), uint8('L'), uint8('E'), uint8('A'), uint8('S'), uint8('E'), uint8('A'), uint8('T'), uint8('T'), uint8('A'), uint8('C'), uint8('H'), uint8('B'), uint8('E'), uint8('T'), uint8('W'), uint8('E'),
	uint8('E'), uint8('N'), uint8('O'), uint8('T'), uint8('H'), uint8('I'), uint8('N'), uint8('G'), uint8('R'), uint8('O'), uint8('U'), uint8('P'), uint8('S'), uint8('C'), uint8('A'), uint8('S'), uint8('C'), uint8('A'),
	uint8('D'), uint8('E'), uint8('F'), uint8('A'), uint8('U'), uint8('L'), uint8('T'), uint8('C'), uint8('A'), uint8('S'), uint8('E'), uint8('C'), uint8('O'), uint8('L'), uint8('L'), uint8('A'), uint8('T'), uint8('E'),
	uint8('C'), uint8('R'), uint8('E'), uint8('A'), uint8('T'), uint8('E'), uint8('C'), uint8('U'), uint8('R'), uint8('R'), uint8('E'), uint8('N'), uint8('T'), uint8('_'), uint8('D'), uint8('A'), uint8('T'), uint8('E'),
	uint8('I'), uint8('M'), uint8('M'), uint8('E'), uint8('D'), uint8('I'), uint8('A'), uint8('T'), uint8('E'), uint8('J'), uint8('O'), uint8('I'), uint8('N'), uint8('S'), uint8('E'), uint8('R'), uint8('T'), uint8('M'),
	uint8('A'), uint8('T'), uint8('C'), uint8('H'), uint8('P'), uint8('L'), uint8('A'), uint8('N'), uint8('A'), uint8('L'), uint8('Y'), uint8('Z'), uint8('E'), uint8('P'), uint8('R'), uint8('A'), uint8('G'), uint8('M'),
	uint8('A'), uint8('T'), uint8('E'), uint8('R'), uint8('I'), uint8('A'), uint8('L'), uint8('I'), uint8('Z'), uint8('E'), uint8('D'), uint8('E'), uint8('F'), uint8('E'), uint8('R'), uint8('R'), uint8('E'), uint8('D'),
	uint8('I'), uint8('S'), uint8('T'), uint8('I'), uint8('N'), uint8('C'), uint8('T'), uint8('U'), uint8('P'), uint8('D'), uint8('A'), uint8('T'), uint8('E'), uint8('V'), uint8('A'), uint8('L'), uint8('U'), uint8('E'),
	uint8('S'), uint8('V'), uint8('I'), uint8('R'), uint8('T'), uint8('U'), uint8('A'), uint8('L'), uint8('W'), uint8('A'), uint8('Y'), uint8('S'), uint8('W'), uint8('H'), uint8('E'), uint8('N'), uint8('W'), uint8('H'),
	uint8('E'), uint8('R'), uint8('E'), uint8('C'), uint8('U'), uint8('R'), uint8('S'), uint8('I'), uint8('V'), uint8('E'), uint8('A'), uint8('B'), uint8('O'), uint8('R'), uint8('T'), uint8('A'), uint8('F'), uint8('T'),
	uint8('E'), uint8('R'), uint8('E'), uint8('N'), uint8('A'), uint8('M'), uint8('E'), uint8('A'), uint8('N'), uint8('D'), uint8('R'), uint8('O'), uint8('P'), uint8('A'), uint8('R'), uint8('T'), uint8('I'), uint8('T'),
	uint8('I'), uint8('O'), uint8('N'), uint8('A'), uint8('U'), uint8('T'), uint8('O'), uint8('I'), uint8('N'), uint8('C'), uint8('R'), uint8('E'), uint8('M'), uint8('E'), uint8('N'), uint8('T'), uint8('C'), uint8('A'),
	uint8('S'), uint8('T'), uint8('C'), uint8('O'), uint8('L'), uint8('U'), uint8('M'), uint8('N'), uint8('C'), uint8('O'), uint8('M'), uint8('M'), uint8('I'), uint8('T'), uint8('C'), uint8('O'), uint8('N'), uint8('F'),
	uint8('L'), uint8('I'), uint8('C'), uint8('T'), uint8('C'), uint8('R'), uint8('O'), uint8('S'), uint8('S'), uint8('C'), uint8('U'), uint8('R'), uint8('R'), uint8('E'), uint8('N'), uint8('T'), uint8('_'), uint8('T'),
	uint8('I'), uint8('M'), uint8('E'), uint8('S'), uint8('T'), uint8('A'), uint8('M'), uint8('P'), uint8('R'), uint8('E'), uint8('C'), uint8('E'), uint8('D'), uint8('I'), uint8('N'), uint8('G'), uint8('F'), uint8('A'),
	uint8('I'), uint8('L'), uint8('A'), uint8('S'), uint8('T'), uint8('F'), uint8('I'), uint8('L'), uint8('T'), uint8('E'), uint8('R'), uint8('E'), uint8('P'), uint8('L'), uint8('A'), uint8('C'), uint8('E'), uint8('F'),
	uint8('I'), uint8('R'), uint8('S'), uint8('T'), uint8('F'), uint8('O'), uint8('L'), uint8('L'), uint8('O'), uint8('W'), uint8('I'), uint8('N'), uint8('G'), uint8('F'), uint8('R'), uint8('O'), uint8('M'), uint8('F'),
	uint8('U'), uint8('L'), uint8('L'), uint8('I'), uint8('M'), uint8('I'), uint8('T'), uint8('I'), uint8('F'), uint8('O'), uint8('R'), uint8('D'), uint8('E'), uint8('R'), uint8('E'), uint8('S'), uint8('T'), uint8('R'),
	uint8('I'), uint8('C'), uint8('T'), uint8('O'), uint8('T'), uint8('H'), uint8('E'), uint8('R'), uint8('S'), uint8('O'), uint8('V'), uint8('E'), uint8('R'), uint8('E'), uint8('T'), uint8('U'), uint8('R'), uint8('N'),
	uint8('I'), uint8('N'), uint8('G'), uint8('R'), uint8('I'), uint8('G'), uint8('H'), uint8('T'), uint8('R'), uint8('O'), uint8('L'), uint8('L'), uint8('B'), uint8('A'), uint8('C'), uint8('K'), uint8('R'), uint8('O'),
	uint8('W'), uint8('S'), uint8('U'), uint8('N'), uint8('B'), uint8('O'), uint8('U'), uint8('N'), uint8('D'), uint8('E'), uint8('D'), uint8('U'), uint8('N'), uint8('I'), uint8('O'), uint8('N'), uint8('U'), uint8('S'),
	uint8('I'), uint8('N'), uint8('G'), uint8('V'), uint8('A'), uint8('C'), uint8('U'), uint8('U'), uint8('M'), uint8('V'), uint8('I'), uint8('E'), uint8('W'), uint8('I'), uint8('N'), uint8('D'), uint8('O'), uint8('W'),
	uint8('B'), uint8('Y'), uint8('I'), uint8('N'), uint8('I'), uint8('T'), uint8('I'), uint8('A'), uint8('L'), uint8('L'), uint8('Y'), uint8('P'), uint8('R'), uint8('I'), uint8('M'), uint8('A'), uint8('R'), uint8('Y'),
}

var aKWHash = [127]uint8{
	uint8(84), uint8(92), uint8(134), uint8(82), uint8(105), uint8(29), uint8(0), uint8(0), uint8(94), uint8(0), uint8(85), uint8(72), uint8(0),
	uint8(53), uint8(35), uint8(86), uint8(15), uint8(0), uint8(42), uint8(97), uint8(54), uint8(89), uint8(135), uint8(19), uint8(0), uint8(0),
	uint8(140), uint8(0), uint8(40), uint8(129), uint8(0), uint8(22), uint8(107), uint8(0), uint8(9), uint8(0), uint8(0), uint8(123), uint8(80),
	uint8(0), uint8(78), uint8(6), uint8(0), uint8(65), uint8(103), uint8(147), uint8(0), uint8(136), uint8(115), uint8(0), uint8(0), uint8(48),
	uint8(0), uint8(90), uint8(24), uint8(0), uint8(17), uint8(0), uint8(27), uint8(70), uint8(23), uint8(26), uint8(5), uint8(60), uint8(142),
	uint8(110), uint8(122), uint8(0), uint8(73), uint8(91), uint8(71), uint8(145), uint8(61), uint8(120), uint8(74), uint8(0), uint8(49), uint8(0),
	uint8(11), uint8(41), uint8(0), uint8(113), uint8(0), uint8(0), uint8(0), uint8(109), uint8(10), uint8(111), uint8(116), uint8(125), uint8(14),
	uint8(50), uint8(124), uint8(0), uint8(100), uint8(0), uint8(18), uint8(121), uint8(144), uint8(56), uint8(130), uint8(139), uint8(88), uint8(83),
	uint8(37), uint8(30), uint8(126), uint8(0), uint8(0), uint8(108), uint8(51), uint8(131), uint8(128), uint8(0), uint8(34), uint8(0), uint8(0),
	uint8(132), uint8(0), uint8(98), uint8(38), uint8(39), uint8(0), uint8(20), uint8(45), uint8(117), uint8(93),
}

var aKWNext = [147]uint8{
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(4), uint8(0), uint8(43), uint8(0), uint8(0), uint8(106), uint8(114), uint8(0), uint8(0),
	uint8(0), uint8(2), uint8(0), uint8(0), uint8(143), uint8(0), uint8(0), uint8(0), uint8(13), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(141), uint8(0), uint8(0), uint8(119), uint8(52), uint8(0), uint8(0), uint8(137), uint8(12), uint8(0), uint8(0), uint8(62), uint8(0),
	uint8(138), uint8(0), uint8(133), uint8(0), uint8(0), uint8(36), uint8(0), uint8(0), uint8(28), uint8(77), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(59), uint8(0), uint8(47), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(69), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(146), uint8(3), uint8(0), uint8(58), uint8(0), uint8(1),
	uint8(75), uint8(0), uint8(0), uint8(0), uint8(31), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(127), uint8(0), uint8(104),
	uint8(0), uint8(64), uint8(66), uint8(63), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(46), uint8(0), uint8(16), uint8(8),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(81), uint8(101), uint8(0),
	uint8(112), uint8(21), uint8(7), uint8(67), uint8(0), uint8(79), uint8(96), uint8(118), uint8(0), uint8(0), uint8(68), uint8(0), uint8(0),
	uint8(99), uint8(44), uint8(0), uint8(55), uint8(0), uint8(76), uint8(0), uint8(95), uint8(32), uint8(33), uint8(57), uint8(25), uint8(0),
	uint8(102), uint8(0), uint8(0), uint8(87),
}

var aKWLen = [147]uint8{
	uint8(7), uint8(7), uint8(5), uint8(4), uint8(6), uint8(4), uint8(5), uint8(3), uint8(6), uint8(7), uint8(3), uint8(6), uint8(6),
	uint8(7), uint8(7), uint8(3), uint8(8), uint8(2), uint8(6), uint8(5), uint8(4), uint8(4), uint8(3), uint8(10), uint8(4), uint8(7),
	uint8(6), uint8(9), uint8(4), uint8(2), uint8(6), uint8(5), uint8(9), uint8(9), uint8(4), uint8(7), uint8(3), uint8(2), uint8(4),
	uint8(4), uint8(6), uint8(11), uint8(6), uint8(2), uint8(7), uint8(5), uint8(5), uint8(9), uint8(6), uint8(10), uint8(4), uint8(6),
	uint8(2), uint8(3), uint8(7), uint8(5), uint8(9), uint8(6), uint8(6), uint8(4), uint8(5), uint8(5), uint8(10), uint8(6), uint8(5),
	uint8(7), uint8(4), uint8(5), uint8(7), uint8(6), uint8(7), uint8(7), uint8(6), uint8(5), uint8(7), uint8(3), uint8(7), uint8(4),
	uint8(7), uint8(6), uint8(12), uint8(9), uint8(4), uint8(6), uint8(5), uint8(4), uint8(7), uint8(6), uint8(12), uint8(8), uint8(8),
	uint8(2), uint8(6), uint8(6), uint8(7), uint8(6), uint8(4), uint8(5), uint8(9), uint8(5), uint8(5), uint8(6), uint8(3), uint8(4),
	uint8(9), uint8(13), uint8(2), uint8(2), uint8(4), uint8(6), uint8(6), uint8(8), uint8(5), uint8(17), uint8(12), uint8(7), uint8(9),
	uint8(4), uint8(4), uint8(6), uint8(7), uint8(5), uint8(9), uint8(4), uint8(4), uint8(5), uint8(2), uint8(5), uint8(8), uint8(6),
	uint8(4), uint8(9), uint8(5), uint8(8), uint8(4), uint8(3), uint8(9), uint8(5), uint8(5), uint8(6), uint8(4), uint8(6), uint8(2),
	uint8(2), uint8(9), uint8(3), uint8(7),
}

var aKWOffset = [147]uint16{
	uint16(0), uint16(2), uint16(2), uint16(8), uint16(9), uint16(14), uint16(16), uint16(20), uint16(23), uint16(25), uint16(25), uint16(29), uint16(33),
	uint16(36), uint16(41), uint16(46), uint16(48), uint16(53), uint16(54), uint16(59), uint16(62), uint16(65), uint16(67), uint16(69), uint16(78), uint16(81),
	uint16(86), uint16(90), uint16(90), uint16(94), uint16(99), uint16(101), uint16(105), uint16(111), uint16(119), uint16(123), uint16(123), uint16(123), uint16(126),
	uint16(129), uint16(132), uint16(137), uint16(142), uint16(146), uint16(147), uint16(152), uint16(156), uint16(160), uint16(168), uint16(174), uint16(181), uint16(184),
	uint16(184), uint16(187), uint16(189), uint16(195), uint16(198), uint16(206), uint16(211), uint16(216), uint16(219), uint16(222), uint16(226), uint16(236), uint16(239),
	uint16(244), uint16(244), uint16(248), uint16(252), uint16(259), uint16(265), uint16(271), uint16(277), uint16(277), uint16(283), uint16(284), uint16(288), uint16(295),
	uint16(299), uint16(306), uint16(312), uint16(324), uint16(333), uint16(335), uint16(341), uint16(346), uint16(348), uint16(355), uint16(359), uint16(370), uint16(377),
	uint16(378), uint16(385), uint16(391), uint16(397), uint16(402), uint16(408), uint16(412), uint16(415), uint16(424), uint16(429), uint16(433), uint16(439), uint16(441),
	uint16(444), uint16(453), uint16(455), uint16(457), uint16(466), uint16(470), uint16(476), uint16(482), uint16(490), uint16(495), uint16(495), uint16(495), uint16(511),
	uint16(520), uint16(523), uint16(527), uint16(532), uint16(539), uint16(544), uint16(553), uint16(557), uint16(560), uint16(565), uint16(567), uint16(571), uint16(579),
	uint16(585), uint16(588), uint16(597), uint16(602), uint16(610), uint16(610), uint16(614), uint16(623), uint16(628), uint16(633), uint16(639), uint16(642), uint16(645),
	uint16(648), uint16(650), uint16(655), uint16(659),
}

var aKWCode = [147]uint8{
	uint8(TK_REINDEX), uint8(TK_INDEXED), uint8(TK_INDEX), uint8(TK_DESC), uint8(TK_ESCAPE),
	uint8(TK_EACH), uint8(TK_CHECK), uint8(TK_KEY), uint8(TK_BEFORE), uint8(TK_FOREIGN),
	uint8(TK_FOR), uint8(TK_IGNORE), uint8(TK_LIKE_KW), uint8(TK_EXPLAIN), uint8(TK_INSTEAD),
	uint8(TK_ADD), uint8(TK_DATABASE), uint8(TK_AS), uint8(TK_SELECT), uint8(TK_TABLE),
	uint8(TK_JOIN_KW), uint8(TK_THEN), uint8(TK_END), uint8(TK_DEFERRABLE), uint8(TK_ELSE),
	uint8(TK_EXCLUDE), uint8(TK_DELETE), uint8(TK_TEMP), uint8(TK_TEMP), uint8(TK_OR),
	uint8(TK_ISNULL), uint8(TK_NULLS), uint8(TK_SAVEPOINT), uint8(TK_INTERSECT), uint8(TK_TIES),
	uint8(TK_NOTNULL), uint8(TK_NOT), uint8(TK_NO), uint8(TK_NULL), uint8(TK_LIKE_KW),
	uint8(TK_EXCEPT), uint8(TK_TRANSACTION), uint8(TK_ACTION), uint8(TK_ON), uint8(TK_JOIN_KW),
	uint8(TK_ALTER), uint8(TK_RAISE), uint8(TK_EXCLUSIVE), uint8(TK_EXISTS), uint8(TK_CONSTRAINT),
	uint8(TK_INTO), uint8(TK_OFFSET), uint8(TK_OF), uint8(TK_SET), uint8(TK_TRIGGER),
	uint8(TK_RANGE), uint8(TK_GENERATED), uint8(TK_DETACH), uint8(TK_HAVING), uint8(TK_LIKE_KW),
	uint8(TK_BEGIN), uint8(TK_JOIN_KW), uint8(TK_REFERENCES), uint8(TK_UNIQUE), uint8(TK_QUERY),
	uint8(TK_WITHOUT), uint8(TK_WITH), uint8(TK_JOIN_KW), uint8(TK_RELEASE), uint8(TK_ATTACH),
	uint8(TK_BETWEEN), uint8(TK_NOTHING), uint8(TK_GROUPS), uint8(TK_GROUP), uint8(TK_CASCADE),
	uint8(TK_ASC), uint8(TK_DEFAULT), uint8(TK_CASE), uint8(TK_COLLATE), uint8(TK_CREATE),
	uint8(TK_CTIME_KW), uint8(TK_IMMEDIATE), uint8(TK_JOIN), uint8(TK_INSERT), uint8(TK_MATCH),
	uint8(TK_PLAN), uint8(TK_ANALYZE), uint8(TK_PRAGMA), uint8(TK_MATERIALIZED), uint8(TK_DEFERRED),
	uint8(TK_DISTINCT), uint8(TK_IS), uint8(TK_UPDATE), uint8(TK_VALUES), uint8(TK_VIRTUAL),
	uint8(TK_ALWAYS), uint8(TK_WHEN), uint8(TK_WHERE), uint8(TK_RECURSIVE), uint8(TK_ABORT),
	uint8(TK_AFTER), uint8(TK_RENAME), uint8(TK_AND), uint8(TK_DROP), uint8(TK_PARTITION),
	uint8(TK_AUTOINCR), uint8(TK_TO), uint8(TK_IN), uint8(TK_CAST), uint8(TK_COLUMNKW),
	uint8(TK_COMMIT), uint8(TK_CONFLICT), uint8(TK_JOIN_KW), uint8(TK_CTIME_KW), uint8(TK_CTIME_KW),
	uint8(TK_CURRENT), uint8(TK_PRECEDING), uint8(TK_FAIL), uint8(TK_LAST), uint8(TK_FILTER),
	uint8(TK_REPLACE), uint8(TK_FIRST), uint8(TK_FOLLOWING), uint8(TK_FROM), uint8(TK_JOIN_KW),
	uint8(TK_LIMIT), uint8(TK_IF), uint8(TK_ORDER), uint8(TK_RESTRICT), uint8(TK_OTHERS),
	uint8(TK_OVER), uint8(TK_RETURNING), uint8(TK_JOIN_KW), uint8(TK_ROLLBACK), uint8(TK_ROWS),
	uint8(TK_ROW), uint8(TK_UNBOUNDED), uint8(TK_UNION), uint8(TK_USING), uint8(TK_VACUUM),
	uint8(TK_VIEW), uint8(TK_WINDOW), uint8(TK_DO), uint8(TK_BY), uint8(TK_INITIALLY),
	uint8(TK_ALL), uint8(TK_PRIMARY),
}

func keywordCode(tls *libc.TLS, z uintptr, n int32, pType uintptr) int32 {
	var i int32
	var j int32
	var zKW uintptr
	if n >= 2 {
		i = (int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(z))])*4 ^ int32(Xsqlite3UpperToLower[*(*uint8)(unsafe.Pointer(z + uintptr(n-1)))])*3 ^ n*1) % 127
		for i = int32(aKWHash[i]) - 1; i >= 0; i = int32(aKWNext[i]) - 1 {
			if int32(aKWLen[i]) != n {
				continue
			}
			zKW = uintptr(unsafe.Pointer(&zKWText)) + uintptr(aKWOffset[i])
			if int32(*(*uint8)(unsafe.Pointer(z)))&libc.CplInt32(0x20) != int32(*(*uint8)(unsafe.Pointer(zKW))) {
				continue
			}
			if int32(*(*uint8)(unsafe.Pointer(z + 1)))&libc.CplInt32(0x20) != int32(*(*uint8)(unsafe.Pointer(zKW + 1))) {
				continue
			}
			j = 2
			for j < n && int32(*(*uint8)(unsafe.Pointer(z + uintptr(j))))&libc.CplInt32(0x20) == int32(*(*uint8)(unsafe.Pointer(zKW + uintptr(j)))) {
				j++
			}
			if j < n {
				continue
			}

			*(*int32)(unsafe.Pointer(pType)) = int32(aKWCode[i])
			break
		}
	}
	return n
}

func Xsqlite3KeywordCode(tls *libc.TLS, z uintptr, n int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = TK_ID
	keywordCode(tls, z, n, bp)
	return *(*int32)(unsafe.Pointer(bp))
}

func Xsqlite3_keyword_name(tls *libc.TLS, i int32, pzName uintptr, pnName uintptr) int32 {
	if i < 0 || i >= SQLITE_N_KEYWORD {
		return SQLITE_ERROR
	}
	*(*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) int32 {
	return SQLITE_N_KEYWORD
}

func Xsqlite3_keyword_check(tls *libc.TLS, zName uintptr, nName int32) int32 {
	return libc.Bool32(TK_ID != Xsqlite3KeywordCode(tls, zName, nName))
}

func Xsqlite3IsIdChar(tls *libc.TLS, c U8) int32 {
	return libc.Bool32(int32(Xsqlite3CtypeMap[c])&0x46 != 0)
}

func getToken(tls *libc.TLS, pz uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var z uintptr = *(*uintptr)(unsafe.Pointer(pz))

	for __ccgo := true; __ccgo; __ccgo = *(*int32)(unsafe.Pointer(bp)) == TK_SPACE {
		z += uintptr(Xsqlite3GetToken(tls, z, bp))
	}
	if *(*int32)(unsafe.Pointer(bp)) == TK_ID ||
		*(*int32)(unsafe.Pointer(bp)) == TK_STRING ||
		*(*int32)(unsafe.Pointer(bp)) == TK_JOIN_KW ||
		*(*int32)(unsafe.Pointer(bp)) == TK_WINDOW ||
		*(*int32)(unsafe.Pointer(bp)) == TK_OVER ||
		Xsqlite3ParserFallback(tls, *(*int32)(unsafe.Pointer(bp))) == TK_ID {
		*(*int32)(unsafe.Pointer(bp)) = TK_ID
	}
	*(*uintptr)(unsafe.Pointer(pz)) = z
	return *(*int32)(unsafe.Pointer(bp))
}

func analyzeWindowKeyword(tls *libc.TLS, z uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = z

	var t int32
	t = getToken(tls, bp)
	if t != TK_ID {
		return TK_ID
	}
	t = getToken(tls, bp)
	if t != TK_AS {
		return TK_ID
	}
	return TK_WINDOW
}

func analyzeOverKeyword(tls *libc.TLS, z uintptr, lastToken int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = z

	if lastToken == TK_RP {
		var t int32 = getToken(tls, bp)
		if t == TK_LP || t == TK_ID {
			return TK_OVER
		}
	}
	return TK_ID
}

func analyzeFilterKeyword(tls *libc.TLS, z uintptr, lastToken int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = z

	if lastToken == TK_RP && getToken(tls, bp) == TK_LP {
		return TK_FILTER
	}
	return TK_ID
}

func Xsqlite3GetToken(tls *libc.TLS, z uintptr, tokenType uintptr) int32 {
	var i int32
	var c int32
	switch int32(aiClass[*(*uint8)(unsafe.Pointer(z))]) {
	case CC_SPACE:
		{
			for i = 1; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x01 != 0; i++ {
			}
			*(*int32)(unsafe.Pointer(tokenType)) = TK_SPACE
			return i

		}
	case CC_MINUS:
		{
			if int32(*(*uint8)(unsafe.Pointer(z + 1))) == '-' {
				for i = 2; libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))) != 0 && c != '\n'; i++ {
				}
				*(*int32)(unsafe.Pointer(tokenType)) = TK_SPACE
				return i
			} else if int32(*(*uint8)(unsafe.Pointer(z + 1))) == '>' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_PTR
				return 2 + libc.Bool32(int32(*(*uint8)(unsafe.Pointer(z + 2))) == '>')
			}
			*(*int32)(unsafe.Pointer(tokenType)) = TK_MINUS
			return 1

		}
	case CC_LP:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_LP
			return 1

		}
	case CC_RP:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_RP
			return 1

		}
	case CC_SEMI:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_SEMI
			return 1

		}
	case CC_PLUS:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_PLUS
			return 1

		}
	case CC_STAR:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_STAR
			return 1

		}
	case CC_SLASH:
		{
			if int32(*(*uint8)(unsafe.Pointer(z + 1))) != '*' || int32(*(*uint8)(unsafe.Pointer(z + 2))) == 0 {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_SLASH
				return 1
			}
			i = 3
			c = int32(*(*uint8)(unsafe.Pointer(z + 2)))
			for ; (c != '*' || int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) != '/') && libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))) != 0; i++ {
			}
			if c != 0 {
				i++
			}
			*(*int32)(unsafe.Pointer(tokenType)) = TK_SPACE
			return i

		}
	case CC_PERCENT:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_REM
			return 1

		}
	case CC_EQ:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_EQ
			return 1 + libc.Bool32(int32(*(*uint8)(unsafe.Pointer(z + 1))) == '=')

		}
	case CC_LT:
		{
			if libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z + 1)))) == '=' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_LE
				return 2
			} else if c == '>' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_NE
				return 2
			} else if c == '<' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_LSHIFT
				return 2
			} else {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_LT
				return 1
			}

		}
		fallthrough
	case CC_GT:
		{
			if libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z + 1)))) == '=' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_GE
				return 2
			} else if c == '>' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_RSHIFT
				return 2
			} else {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_GT
				return 1
			}

		}
		fallthrough
	case CC_BANG:
		{
			if int32(*(*uint8)(unsafe.Pointer(z + 1))) != '=' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_ILLEGAL
				return 1
			} else {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_NE
				return 2
			}

		}
		fallthrough
	case CC_PIPE:
		{
			if int32(*(*uint8)(unsafe.Pointer(z + 1))) != '|' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_BITOR
				return 1
			} else {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_CONCAT
				return 2
			}

		}
		fallthrough
	case CC_COMMA:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_COMMA
			return 1

		}
	case CC_AND:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_BITAND
			return 1

		}
	case CC_TILDA:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_BITNOT
			return 1

		}
	case CC_QUOTE:
		{
			var delim int32 = int32(*(*uint8)(unsafe.Pointer(z)))

			for i = 1; libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))) != 0; i++ {
				if c == delim {
					if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+1)))) == delim {
						i++
					} else {
						break
					}
				}
			}
			if c == '\'' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_STRING
				return i + 1
			} else if c != 0 {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_ID
				return i + 1
			} else {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_ILLEGAL
				return i
			}

		}
		fallthrough
	case CC_DOT:
		{
			if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + 1))])&0x04 != 0) {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_DOT
				return 1
			}

		}
		fallthrough
	case CC_DIGIT:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_INTEGER
			if int32(*(*uint8)(unsafe.Pointer(z))) == '0' && (int32(*(*uint8)(unsafe.Pointer(z + 1))) == 'x' || int32(*(*uint8)(unsafe.Pointer(z + 1))) == 'X') && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + 2))])&0x08 != 0 {
				for i = 3; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x08 != 0; i++ {
				}
				return i
			}
			for i = 0; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x04 != 0; i++ {
			}
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == '.' {
				i++
				for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x04 != 0 {
					i++
				}
				*(*int32)(unsafe.Pointer(tokenType)) = TK_FLOAT
			}
			if (int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == 'e' || int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) == 'E') && (int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i+1)))])&0x04 != 0 ||
				(int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+1)))) == '+' || int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+1)))) == '-') && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i+2)))])&0x04 != 0) {
				i = i + 2
				for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x04 != 0 {
					i++
				}
				*(*int32)(unsafe.Pointer(tokenType)) = TK_FLOAT
			}
			for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x46 != 0 {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_ILLEGAL
				i++
			}
			return i

		}
	case CC_QUOTE2:
		{
			i = 1
			c = int32(*(*uint8)(unsafe.Pointer(z)))
			for ; c != ']' && libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))) != 0; i++ {
			}
			*(*int32)(unsafe.Pointer(tokenType)) = func() int32 {
				if c == ']' {
					return TK_ID
				}
				return TK_ILLEGAL
			}()
			return i

		}
	case CC_VARNUM:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_VARIABLE
			for i = 1; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x04 != 0; i++ {
			}
			return i

		}
	case CC_DOLLAR:
		fallthrough
	case CC_VARALPHA:
		{
			var n int32 = 0

			*(*int32)(unsafe.Pointer(tokenType)) = TK_VARIABLE
			for i = 1; libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))) != 0; i++ {
				if int32(Xsqlite3CtypeMap[uint8(c)])&0x46 != 0 {
					n++
				} else if c == '(' && n > 0 {
					for __ccgo := true; __ccgo; __ccgo = libc.AssignInt32(&c, int32(*(*uint8)(unsafe.Pointer(z + uintptr(i))))) != 0 && !(int32(Xsqlite3CtypeMap[uint8(c)])&0x01 != 0) && c != ')' {
						i++
					}
					if c == ')' {
						i++
					} else {
						*(*int32)(unsafe.Pointer(tokenType)) = TK_ILLEGAL
					}
					break
				} else if c == ':' && int32(*(*uint8)(unsafe.Pointer(z + uintptr(i+1)))) == ':' {
					i++
				} else {
					break
				}
			}
			if n == 0 {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_ILLEGAL
			}
			return i

		}
	case CC_KYWD0:
		{
			for i = 1; int32(aiClass[*(*uint8)(unsafe.Pointer(z + uintptr(i)))]) <= CC_KYWD; i++ {
			}
			if int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x46 != 0 {
				i++
				break
			}
			*(*int32)(unsafe.Pointer(tokenType)) = TK_ID
			return keywordCode(tls, z, i, tokenType)

		}
	case CC_X:
		{
			if int32(*(*uint8)(unsafe.Pointer(z + 1))) == '\'' {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_BLOB
				for i = 2; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x08 != 0; i++ {
				}
				if int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) != '\'' || i%2 != 0 {
					*(*int32)(unsafe.Pointer(tokenType)) = TK_ILLEGAL
					for *(*uint8)(unsafe.Pointer(z + uintptr(i))) != 0 && int32(*(*uint8)(unsafe.Pointer(z + uintptr(i)))) != '\'' {
						i++
					}
				}
				if *(*uint8)(unsafe.Pointer(z + uintptr(i))) != 0 {
					i++
				}
				return i
			}

		}
		fallthrough
	case CC_KYWD:
		fallthrough
	case CC_ID:
		{
			i = 1
			break

		}
	case CC_BOM:
		{
			if int32(*(*uint8)(unsafe.Pointer(z + 1))) == 0xbb && int32(*(*uint8)(unsafe.Pointer(z + 2))) == 0xbf {
				*(*int32)(unsafe.Pointer(tokenType)) = TK_SPACE
				return 3
			}
			i = 1
			break

		}
	case CC_NUL:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_ILLEGAL
			return 0

		}
	default:
		{
			*(*int32)(unsafe.Pointer(tokenType)) = TK_ILLEGAL
			return 1

		}
	}
	for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x46 != 0 {
		i++
	}
	*(*int32)(unsafe.Pointer(tokenType)) = TK_ID
	return i
}

func Xsqlite3RunParser(tls *libc.TLS, pParse uintptr, zSql uintptr) int32 {
	bp := tls.Alloc(2480)
	defer tls.Free(2480)

	var nErr int32 = 0
	var pEngine uintptr
	var n int32 = 0

	var lastTokenParsed int32 = -1
	var db uintptr = (*Parse)(unsafe.Pointer(pParse)).Fdb
	var mxSqlLen int32
	var pParentParse uintptr = uintptr(0)

	mxSqlLen = *(*int32)(unsafe.Pointer(db + 136 + 1*4))
	if (*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0 {
		libc.AtomicStoreNInt32(db+432, int32(0), 0)
	}
	(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_OK
	(*Parse)(unsafe.Pointer(pParse)).FzTail = zSql
	pEngine = bp + 32
	Xsqlite3ParserInit(tls, pEngine, pParse)

	pParentParse = (*Sqlite3)(unsafe.Pointer(db)).FpParse
	(*Sqlite3)(unsafe.Pointer(db)).FpParse = pParse
	for 1 != 0 {
		n = Xsqlite3GetToken(tls, zSql, bp+2456)
		mxSqlLen = mxSqlLen - n
		if mxSqlLen < 0 {
			(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_TOOBIG
			(*Parse)(unsafe.Pointer(pParse)).FnErr++
			break
		}
		if *(*int32)(unsafe.Pointer(bp + 2456)) >= TK_WINDOW {
			if libc.AtomicLoadNInt32(db+432, 0) != 0 {
				(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_INTERRUPT
				(*Parse)(unsafe.Pointer(pParse)).FnErr++
				break
			}
			if *(*int32)(unsafe.Pointer(bp + 2456)) == TK_SPACE {
				zSql += uintptr(n)
				continue
			}
			if int32(*(*uint8)(unsafe.Pointer(zSql))) == 0 {
				if lastTokenParsed == TK_SEMI {
					*(*int32)(unsafe.Pointer(bp + 2456)) = 0
				} else if lastTokenParsed == 0 {
					break
				} else {
					*(*int32)(unsafe.Pointer(bp + 2456)) = TK_SEMI
				}
				n = 0
			} else if *(*int32)(unsafe.Pointer(bp + 2456)) == TK_WINDOW {
				*(*int32)(unsafe.Pointer(bp + 2456)) = analyzeWindowKeyword(tls, zSql+6)
			} else if *(*int32)(unsafe.Pointer(bp + 2456)) == TK_OVER {
				*(*int32)(unsafe.Pointer(bp + 2456)) = analyzeOverKeyword(tls, zSql+4, lastTokenParsed)
			} else if *(*int32)(unsafe.Pointer(bp + 2456)) == TK_FILTER {
				*(*int32)(unsafe.Pointer(bp + 2456)) = analyzeFilterKeyword(tls, zSql+6, lastTokenParsed)
			} else {
				(*Token)(unsafe.Pointer(bp + 2464)).Fz = zSql
				(*Token)(unsafe.Pointer(bp + 2464)).Fn = uint32(n)
				Xsqlite3ErrorMsg(tls, pParse, ts+27887, libc.VaList(bp, bp+2464))
				break
			}
		}
		(*Parse)(unsafe.Pointer(pParse)).FsLastToken.Fz = zSql
		(*Parse)(unsafe.Pointer(pParse)).FsLastToken.Fn = uint32(n)
		Xsqlite3Parser(tls, pEngine, *(*int32)(unsafe.Pointer(bp + 2456)), (*Parse)(unsafe.Pointer(pParse)).FsLastToken)
		lastTokenParsed = *(*int32)(unsafe.Pointer(bp + 2456))
		zSql += uintptr(n)

		if (*Parse)(unsafe.Pointer(pParse)).Frc != SQLITE_OK {
			break
		}
	}

	Xsqlite3ParserFinalize(tls, pEngine)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		(*Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
	}
	if (*Parse)(unsafe.Pointer(pParse)).FzErrMsg != 0 || (*Parse)(unsafe.Pointer(pParse)).Frc != SQLITE_OK && (*Parse)(unsafe.Pointer(pParse)).Frc != SQLITE_DONE {
		if (*Parse)(unsafe.Pointer(pParse)).FzErrMsg == uintptr(0) {
			(*Parse)(unsafe.Pointer(pParse)).FzErrMsg = Xsqlite3MPrintf(tls, db, ts+1684, libc.VaList(bp+8, Xsqlite3ErrStr(tls, (*Parse)(unsafe.Pointer(pParse)).Frc)))
		}
		Xsqlite3_log(tls, (*Parse)(unsafe.Pointer(pParse)).Frc, ts+27912, libc.VaList(bp+16, (*Parse)(unsafe.Pointer(pParse)).FzErrMsg, (*Parse)(unsafe.Pointer(pParse)).FzTail))
		nErr++
	}
	(*Parse)(unsafe.Pointer(pParse)).FzTail = zSql
	Xsqlite3_free(tls, (*Parse)(unsafe.Pointer(pParse)).FapVtabLock)

	if (*Parse)(unsafe.Pointer(pParse)).FpNewTable != 0 && !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) != PARSE_MODE_NORMAL) {
		Xsqlite3DeleteTable(tls, db, (*Parse)(unsafe.Pointer(pParse)).FpNewTable)
	}
	if (*Parse)(unsafe.Pointer(pParse)).FpNewTrigger != 0 && !(int32((*Parse)(unsafe.Pointer(pParse)).FeParseMode) >= PARSE_MODE_RENAME) {
		Xsqlite3DeleteTrigger(tls, db, (*Parse)(unsafe.Pointer(pParse)).FpNewTrigger)
	}
	if (*Parse)(unsafe.Pointer(pParse)).FpVList != 0 {
		Xsqlite3DbNNFreeNN(tls, db, (*Parse)(unsafe.Pointer(pParse)).FpVList)
	}
	(*Sqlite3)(unsafe.Pointer(db)).FpParse = pParentParse

	return nErr
}

func Xsqlite3_complete(tls *libc.TLS, zSql uintptr) int32 {
	var state U8 = U8(0)
	var token U8

	for *(*uint8)(unsafe.Pointer(zSql)) != 0 {
		switch int32(*(*uint8)(unsafe.Pointer(zSql))) {
		case ';':
			{
				token = U8(TkSEMI)
				break

			}
		case ' ':
			fallthrough
		case '\r':
			fallthrough
		case '\t':
			fallthrough
		case '\n':
			fallthrough
		case '\f':
			{
				token = U8(TkWS)
				break

			}
		case '/':
			{
				if int32(*(*uint8)(unsafe.Pointer(zSql + 1))) != '*' {
					token = U8(TkOTHER)
					break
				}
				zSql += uintptr(2)
				for *(*uint8)(unsafe.Pointer(zSql)) != 0 && (int32(*(*uint8)(unsafe.Pointer(zSql))) != '*' || int32(*(*uint8)(unsafe.Pointer(zSql + 1))) != '/') {
					zSql++
				}
				if int32(*(*uint8)(unsafe.Pointer(zSql))) == 0 {
					return 0
				}
				zSql++
				token = U8(TkWS)
				break

			}
		case '-':
			{
				if int32(*(*uint8)(unsafe.Pointer(zSql + 1))) != '-' {
					token = U8(TkOTHER)
					break
				}
				for *(*uint8)(unsafe.Pointer(zSql)) != 0 && int32(*(*uint8)(unsafe.Pointer(zSql))) != '\n' {
					zSql++
				}
				if int32(*(*uint8)(unsafe.Pointer(zSql))) == 0 {
					return libc.Bool32(int32(state) == 1)
				}
				token = U8(TkWS)
				break

			}
		case '[':
			{
				zSql++
				for *(*uint8)(unsafe.Pointer(zSql)) != 0 && int32(*(*uint8)(unsafe.Pointer(zSql))) != ']' {
					zSql++
				}
				if int32(*(*uint8)(unsafe.Pointer(zSql))) == 0 {
					return 0
				}
				token = U8(TkOTHER)
				break

			}
		case '`':
			fallthrough
		case '"':
			fallthrough
		case '\'':
			{
				var c int32 = int32(*(*uint8)(unsafe.Pointer(zSql)))
				zSql++
				for *(*uint8)(unsafe.Pointer(zSql)) != 0 && int32(*(*uint8)(unsafe.Pointer(zSql))) != c {
					zSql++
				}
				if int32(*(*uint8)(unsafe.Pointer(zSql))) == 0 {
					return 0
				}
				token = U8(TkOTHER)
				break

			}
		default:
			{
				if int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zSql))])&0x46 != 0 {
					var nId int32
					for nId = 1; int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zSql + uintptr(nId)))])&0x46 != 0; nId++ {
					}
					switch int32(*(*uint8)(unsafe.Pointer(zSql))) {
					case 'c':
						fallthrough
					case 'C':
						{
							if nId == 6 && Xsqlite3_strnicmp(tls, zSql, ts+27923, 6) == 0 {
								token = U8(TkCREATE)
							} else {
								token = U8(TkOTHER)
							}
							break

						}
						fallthrough
					case 't':
						fallthrough
					case 'T':
						{
							if nId == 7 && Xsqlite3_strnicmp(tls, zSql, ts+24125, 7) == 0 {
								token = U8(TkTRIGGER)
							} else if nId == 4 && Xsqlite3_strnicmp(tls, zSql, ts+27930, 4) == 0 {
								token = U8(TkTEMP)
							} else if nId == 9 && Xsqlite3_strnicmp(tls, zSql, ts+27935, 9) == 0 {
								token = U8(TkTEMP)
							} else {
								token = U8(TkOTHER)
							}
							break

						}
						fallthrough
					case 'e':
						fallthrough
					case 'E':
						{
							if nId == 3 && Xsqlite3_strnicmp(tls, zSql, ts+27945, 3) == 0 {
								token = U8(TkEND)
							} else if nId == 7 && Xsqlite3_strnicmp(tls, zSql, ts+27949, 7) == 0 {
								token = U8(TkEXPLAIN)
							} else {
								token = U8(TkOTHER)
							}
							break

						}
						fallthrough
					default:
						{
							token = U8(TkOTHER)
							break

						}
					}
					zSql += uintptr(nId - 1)
				} else {
					token = U8(TkOTHER)
				}
				break

			}
		}
		state = *(*U8)(unsafe.Pointer(uintptr(unsafe.Pointer(&trans)) + uintptr(state)*8 + uintptr(token)))
		zSql++
	}
	return libc.Bool32(int32(state) == 1)
}

var trans = [8][8]U8{
	{U8(1), U8(0), U8(2), U8(3), U8(4), U8(2), U8(2), U8(2)},
	{U8(1), U8(1), U8(2), U8(3), U8(4), U8(2), U8(2), U8(2)},
	{U8(1), U8(2), U8(2), U8(2), U8(2), U8(2), U8(2), U8(2)},
	{U8(1), U8(3), U8(3), U8(2), U8(4), U8(2), U8(2), U8(2)},
	{U8(1), U8(4), U8(2), U8(2), U8(2), U8(4), U8(5), U8(2)},
	{U8(6), U8(5), U8(5), U8(5), U8(5), U8(5), U8(5), U8(5)},
	{U8(6), U8(6), U8(5), U8(5), U8(5), U8(5), U8(5), U8(7)},
	{U8(1), U8(7), U8(5), U8(5), U8(5), U8(5), U8(5), U8(5)},
}

func Xsqlite3_complete16(tls *libc.TLS, zSql uintptr) int32 {
	var pVal uintptr
	var zSql8 uintptr
	var rc int32

	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	pVal = Xsqlite3ValueNew(tls, uintptr(0))
	Xsqlite3ValueSetStr(tls, pVal, -1, zSql, uint8(SQLITE_UTF16LE), uintptr(0))
	zSql8 = Xsqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
	if zSql8 != 0 {
		rc = Xsqlite3_complete(tls, zSql8)
	} else {
		rc = SQLITE_NOMEM
	}
	Xsqlite3ValueFree(tls, pVal)
	return rc & 0xff
}

func sqlite3TestExtInit(tls *libc.TLS, db uintptr) int32 {
	_ = db
	return Xsqlite3FaultSim(tls, 500)
}

var sqlite3BuiltinExtensions = [8]uintptr{
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
}

func Xsqlite3_libversion(tls *libc.TLS) uintptr {
	return uintptr(unsafe.Pointer(&Xsqlite3_version))
}

func Xsqlite3_libversion_number(tls *libc.TLS) int32 {
	return SQLITE_VERSION_NUMBER
}

func Xsqlite3_threadsafe(tls *libc.TLS) int32 {
	return SQLITE_THREADSAFE
}

var Xsqlite3OSTrace int32 = SQLITE_DEBUG_OS_TRACE

var Xsqlite3_temp_directory uintptr = uintptr(0)

var Xsqlite3_data_directory uintptr = uintptr(0)

var mu mutex

func init() { mu.recursive = true }

func Xsqlite3_initialize(tls *libc.TLS) int32 {
	mu.enter(tls.ID)
	defer mu.leave(tls.ID)

	var pMainMtx uintptr
	var rc int32

	if Xsqlite3Config.FisInit != 0 {
		return SQLITE_OK
	}

	rc = Xsqlite3MutexInit(tls)
	if rc != 0 {
		return rc
	}

	pMainMtx = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN)
	Xsqlite3_mutex_enter(tls, pMainMtx)
	Xsqlite3Config.FisMutexInit = 1
	if !(Xsqlite3Config.FisMallocInit != 0) {
		rc = Xsqlite3MallocInit(tls)
	}
	if rc == SQLITE_OK {
		Xsqlite3Config.FisMallocInit = 1
		if !(int32(Xsqlite3Config.FpInitMutex) != 0) {
			Xsqlite3Config.FpInitMutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_RECURSIVE)
			if Xsqlite3Config.FbCoreMutex != 0 && !(int32(Xsqlite3Config.FpInitMutex) != 0) {
				rc = SQLITE_NOMEM
			}
		}
	}
	if rc == SQLITE_OK {
		Xsqlite3Config.FnRefInitMutex++
	}
	Xsqlite3_mutex_leave(tls, pMainMtx)

	if rc != SQLITE_OK {
		return rc
	}

	Xsqlite3_mutex_enter(tls, Xsqlite3Config.FpInitMutex)
	if Xsqlite3Config.FisInit == 0 && Xsqlite3Config.FinProgress == 0 {
		Xsqlite3Config.FinProgress = 1
		libc.Xmemset(tls, uintptr(unsafe.Pointer(&Xsqlite3BuiltinFunctions)), 0, uint64(unsafe.Sizeof(Xsqlite3BuiltinFunctions)))
		Xsqlite3RegisterBuiltinFunctions(tls)
		if Xsqlite3Config.FisPCacheInit == 0 {
			rc = Xsqlite3PcacheInitialize(tls)
		}
		if rc == SQLITE_OK {
			Xsqlite3Config.FisPCacheInit = 1
			rc = Xsqlite3OsInit(tls)
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3MemdbInit(tls)
		}
		if rc == SQLITE_OK {
			Xsqlite3PCacheBufferSetup(tls, Xsqlite3Config.FpPage,
				Xsqlite3Config.FszPage, Xsqlite3Config.FnPage)

			Xsqlite3Config.FisInit = 1
		}
		Xsqlite3Config.FinProgress = 0
	}
	Xsqlite3_mutex_leave(tls, Xsqlite3Config.FpInitMutex)

	Xsqlite3_mutex_enter(tls, pMainMtx)
	Xsqlite3Config.FnRefInitMutex--
	if Xsqlite3Config.FnRefInitMutex <= 0 {
		Xsqlite3_mutex_free(tls, Xsqlite3Config.FpInitMutex)
		Xsqlite3Config.FpInitMutex = uintptr(0)
	}
	Xsqlite3_mutex_leave(tls, pMainMtx)

	return rc
}

func Xsqlite3_shutdown(tls *libc.TLS) int32 {
	if Xsqlite3Config.FisInit != 0 {
		Xsqlite3_os_end(tls)
		Xsqlite3_reset_auto_extension(tls)
		Xsqlite3Config.FisInit = 0
	}
	if Xsqlite3Config.FisPCacheInit != 0 {
		Xsqlite3PcacheShutdown(tls)
		Xsqlite3Config.FisPCacheInit = 0
	}
	if Xsqlite3Config.FisMallocInit != 0 {
		Xsqlite3MallocEnd(tls)
		Xsqlite3Config.FisMallocInit = 0

		Xsqlite3_data_directory = uintptr(0)
		Xsqlite3_temp_directory = uintptr(0)
	}
	if Xsqlite3Config.FisMutexInit != 0 {
		Xsqlite3MutexEnd(tls)
		Xsqlite3Config.FisMutexInit = 0
	}

	return SQLITE_OK
}

func Xsqlite3_config(tls *libc.TLS, op int32, va uintptr) int32 {
	var ap Va_list
	_ = ap
	var rc int32 = SQLITE_OK

	if Xsqlite3Config.FisInit != 0 {
		return Xsqlite3MisuseError(tls, 174426)
	}

	ap = va
	switch op {
	case SQLITE_CONFIG_SINGLETHREAD:
		{
			Xsqlite3Config.FbCoreMutex = U8(0)
			Xsqlite3Config.FbFullMutex = U8(0)
			break

		}
	case SQLITE_CONFIG_MULTITHREAD:
		{
			Xsqlite3Config.FbCoreMutex = U8(1)
			Xsqlite3Config.FbFullMutex = U8(0)
			break

		}
	case SQLITE_CONFIG_SERIALIZED:
		{
			Xsqlite3Config.FbCoreMutex = U8(1)
			Xsqlite3Config.FbFullMutex = U8(1)
			break

		}
	case SQLITE_CONFIG_MUTEX:
		{
			Xsqlite3Config.Fmutex = *(*Sqlite3_mutex_methods)(unsafe.Pointer(libc.VaUintptr(&ap)))
			break

		}
	case SQLITE_CONFIG_GETMUTEX:
		{
			*(*Sqlite3_mutex_methods)(unsafe.Pointer(libc.VaUintptr(&ap))) = Xsqlite3Config.Fmutex
			break

		}

	case SQLITE_CONFIG_MALLOC:
		{
			Xsqlite3Config.Fm = *(*Sqlite3_mem_methods)(unsafe.Pointer(libc.VaUintptr(&ap)))
			break

		}
	case SQLITE_CONFIG_GETMALLOC:
		{
			if Xsqlite3Config.Fm.FxMalloc == uintptr(0) {
				Xsqlite3MemSetDefault(tls)
			}
			*(*Sqlite3_mem_methods)(unsafe.Pointer(libc.VaUintptr(&ap))) = Xsqlite3Config.Fm
			break

		}
	case SQLITE_CONFIG_MEMSTATUS:
		{
			Xsqlite3Config.FbMemstat = libc.VaInt32(&ap)
			break

		}
	case SQLITE_CONFIG_SMALL_MALLOC:
		{
			Xsqlite3Config.FbSmallMalloc = U8(libc.VaInt32(&ap))
			break

		}
	case SQLITE_CONFIG_PAGECACHE:
		{
			Xsqlite3Config.FpPage = libc.VaUintptr(&ap)
			Xsqlite3Config.FszPage = libc.VaInt32(&ap)
			Xsqlite3Config.FnPage = libc.VaInt32(&ap)
			break

		}
	case SQLITE_CONFIG_PCACHE_HDRSZ:
		{
			*(*int32)(unsafe.Pointer(libc.VaUintptr(&ap))) = Xsqlite3HeaderSizeBtree(tls) + Xsqlite3HeaderSizePcache(tls) + Xsqlite3HeaderSizePcache1(tls)
			break

		}

	case SQLITE_CONFIG_PCACHE:
		{
			break

		}
	case SQLITE_CONFIG_GETPCACHE:
		{
			rc = SQLITE_ERROR
			break

		}

	case SQLITE_CONFIG_PCACHE2:
		{
			Xsqlite3Config.Fpcache2 = *(*Sqlite3_pcache_methods2)(unsafe.Pointer(libc.VaUintptr(&ap)))
			break

		}
	case SQLITE_CONFIG_GETPCACHE2:
		{
			if Xsqlite3Config.Fpcache2.FxInit == uintptr(0) {
				Xsqlite3PCacheSetDefault(tls)
			}
			*(*Sqlite3_pcache_methods2)(unsafe.Pointer(libc.VaUintptr(&ap))) = Xsqlite3Config.Fpcache2
			break

		}

	case SQLITE_CONFIG_LOOKASIDE:
		{
			Xsqlite3Config.FszLookaside = libc.VaInt32(&ap)
			Xsqlite3Config.FnLookaside = libc.VaInt32(&ap)
			break

		}

	case SQLITE_CONFIG_LOG:
		{
			Xsqlite3Config.FxLog = libc.VaUintptr(&ap)
			Xsqlite3Config.FpLogArg = libc.VaUintptr(&ap)
			break

		}

	case SQLITE_CONFIG_URI:
		{
			Xsqlite3Config.FbOpenUri = U8(libc.VaInt32(&ap))
			break

		}

	case SQLITE_CONFIG_COVERING_INDEX_SCAN:
		{
			Xsqlite3Config.FbUseCis = U8(libc.VaInt32(&ap))
			break

		}

	case SQLITE_CONFIG_MMAP_SIZE:
		{
			var szMmap Sqlite3_int64 = libc.VaInt64(&ap)
			var mxMmap Sqlite3_int64 = libc.VaInt64(&ap)

			if mxMmap < int64(0) || mxMmap > int64(SQLITE_MAX_MMAP_SIZE) {
				mxMmap = int64(SQLITE_MAX_MMAP_SIZE)
			}
			if szMmap < int64(0) {
				szMmap = int64(SQLITE_DEFAULT_MMAP_SIZE)
			}
			if szMmap > mxMmap {
				szMmap = mxMmap
			}
			Xsqlite3Config.FmxMmap = mxMmap
			Xsqlite3Config.FszMmap = szMmap
			break

		}

	case SQLITE_CONFIG_PMASZ:
		{
			Xsqlite3Config.FszPma = libc.VaUint32(&ap)
			break

		}

	case SQLITE_CONFIG_STMTJRNL_SPILL:
		{
			Xsqlite3Config.FnStmtSpill = libc.VaInt32(&ap)
			break

		}

	case SQLITE_CONFIG_MEMDB_MAXSIZE:
		{
			Xsqlite3Config.FmxMemdbSize = libc.VaInt64(&ap)
			break

		}

	default:
		{
			rc = SQLITE_ERROR
			break

		}
	}
	_ = ap
	return rc
}

func setupLookaside(tls *libc.TLS, db uintptr, pBuf uintptr, sz int32, cnt int32) int32 {
	var pStart uintptr
	var szAlloc Sqlite3_int64 = Sqlite3_int64(sz) * Sqlite3_int64(cnt)
	var nBig int32
	var nSm int32

	if Xsqlite3LookasideUsed(tls, db, uintptr(0)) > 0 {
		return SQLITE_BUSY
	}

	if (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbMalloced != 0 {
		Xsqlite3_free(tls, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart)
	}

	sz = sz & libc.CplInt32(7)
	if sz <= int32(unsafe.Sizeof(uintptr(0))) {
		sz = 0
	}
	if cnt < 0 {
		cnt = 0
	}
	if sz == 0 || cnt == 0 {
		sz = 0
		pStart = uintptr(0)
	} else if pBuf == uintptr(0) {
		Xsqlite3BeginBenignMalloc(tls)
		pStart = Xsqlite3Malloc(tls, uint64(szAlloc))
		Xsqlite3EndBenignMalloc(tls)
		if pStart != 0 {
			szAlloc = Sqlite3_int64(Xsqlite3MallocSize(tls, pStart))
		}
	} else {
		pStart = pBuf
	}
	if sz >= LOOKASIDE_SMALL*3 {
		nBig = int32(szAlloc / Sqlite3_int64(3*LOOKASIDE_SMALL+sz))
		nSm = int32((szAlloc - Sqlite3_int64(sz*nBig)) / int64(LOOKASIDE_SMALL))
	} else if sz >= LOOKASIDE_SMALL*2 {
		nBig = int32(szAlloc / Sqlite3_int64(LOOKASIDE_SMALL+sz))
		nSm = int32((szAlloc - Sqlite3_int64(sz*nBig)) / int64(LOOKASIDE_SMALL))
	} else if sz > 0 {
		nBig = int32(szAlloc / Sqlite3_int64(sz))
		nSm = 0
	} else {
		nBig = libc.AssignInt32(&nSm, 0)
	}
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart = pStart
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpInit = uintptr(0)
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = uintptr(0)
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(sz)
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue = U16(sz)
	if pStart != 0 {
		var i int32
		var p uintptr

		p = pStart
		for i = 0; i < nBig; i++ {
			(*LookasideSlot)(unsafe.Pointer(p)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpInit
			(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpInit = p
			p = p + uintptr(sz)
		}
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle = p
		for i = 0; i < nSm; i++ {
			(*LookasideSlot)(unsafe.Pointer(p)).FpNext = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit
			(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = p
			p = p + 128
		}

		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = p
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = U32(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbMalloced = func() uint8 {
			if pBuf == uintptr(0) {
				return uint8(1)
			}
			return uint8(0)
		}()
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FnSlot = U32(nBig + nSm)
	} else {
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallInit = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = U32(1)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbMalloced = U8(0)
		(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FnSlot = U32(0)
	}
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd = (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd

	return SQLITE_OK
}

func Xsqlite3_db_mutex(tls *libc.TLS, db uintptr) uintptr {
	return (*Sqlite3)(unsafe.Pointer(db)).Fmutex
}

func Xsqlite3_db_release_memory(tls *libc.TLS, db uintptr) int32 {
	var i int32

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	Xsqlite3BtreeEnterAll(tls, db)
	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if pBt != 0 {
			var pPager uintptr = Xsqlite3BtreePager(tls, pBt)
			Xsqlite3PagerShrink(tls, pPager)
		}
	}
	Xsqlite3BtreeLeaveAll(tls, db)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

func Xsqlite3_db_cacheflush(tls *libc.TLS, db uintptr) int32 {
	var i int32
	var rc int32 = SQLITE_OK
	var bSeenBusy int32 = 0

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	Xsqlite3BtreeEnterAll(tls, db)
	for i = 0; rc == SQLITE_OK && i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if pBt != 0 && Xsqlite3BtreeTxnState(tls, pBt) == SQLITE_TXN_WRITE {
			var pPager uintptr = Xsqlite3BtreePager(tls, pBt)
			rc = Xsqlite3PagerFlush(tls, pPager)
			if rc == SQLITE_BUSY {
				bSeenBusy = 1
				rc = SQLITE_OK
			}
		}
	}
	Xsqlite3BtreeLeaveAll(tls, db)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return func() int32 {
		if rc == SQLITE_OK && bSeenBusy != 0 {
			return SQLITE_BUSY
		}
		return rc
	}()
}

func Xsqlite3_db_config(tls *libc.TLS, db uintptr, op int32, va uintptr) int32 {
	var ap Va_list
	_ = ap
	var rc int32
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	ap = va
	switch op {
	case SQLITE_DBCONFIG_MAINDBNAME:
		{
			(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FzDbSName = libc.VaUintptr(&ap)
			rc = SQLITE_OK
			break

		}
	case SQLITE_DBCONFIG_LOOKASIDE:
		{
			var pBuf uintptr = libc.VaUintptr(&ap)
			var sz int32 = libc.VaInt32(&ap)
			var cnt int32 = libc.VaInt32(&ap)
			rc = setupLookaside(tls, db, pBuf, sz, cnt)
			break

		}
	default:
		{
			var i uint32
			rc = SQLITE_ERROR
			for i = uint32(0); i < uint32(int32(uint64(unsafe.Sizeof(aFlagOp))/uint64(unsafe.Sizeof(struct {
				Fop   int32
				Fmask U32
			}{})))); i++ {
				if aFlagOp[i].Fop == op {
					var onoff int32 = libc.VaInt32(&ap)
					var pRes uintptr = libc.VaUintptr(&ap)
					var oldFlags U64 = (*Sqlite3)(unsafe.Pointer(db)).Fflags
					if onoff > 0 {
						*(*U64)(unsafe.Pointer(db + 48)) |= U64(aFlagOp[i].Fmask)
					} else if onoff == 0 {
						*(*U64)(unsafe.Pointer(db + 48)) &= ^U64(aFlagOp[i].Fmask)
					}
					if oldFlags != (*Sqlite3)(unsafe.Pointer(db)).Fflags {
						Xsqlite3ExpirePreparedStatements(tls, db, 0)
					}
					if pRes != 0 {
						*(*int32)(unsafe.Pointer(pRes)) = libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).Fflags&U64(aFlagOp[i].Fmask) != uint64(0))
					}
					rc = SQLITE_OK
					break
				}
			}
			break

		}
	}
	_ = ap
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

var aFlagOp = [16]struct {
	Fop   int32
	Fmask U32
}{
	{Fop: SQLITE_DBCONFIG_ENABLE_FKEY, Fmask: U32(SQLITE_ForeignKeys)},
	{Fop: SQLITE_DBCONFIG_ENABLE_TRIGGER, Fmask: U32(SQLITE_EnableTrigger)},
	{Fop: SQLITE_DBCONFIG_ENABLE_VIEW, Fmask: SQLITE_EnableView},
	{Fop: SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, Fmask: U32(SQLITE_Fts3Tokenizer)},
	{Fop: SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, Fmask: U32(SQLITE_LoadExtension)},
	{Fop: SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, Fmask: U32(SQLITE_NoCkptOnClose)},
	{Fop: SQLITE_DBCONFIG_ENABLE_QPSG, Fmask: U32(SQLITE_EnableQPSG)},
	{Fop: SQLITE_DBCONFIG_TRIGGER_EQP, Fmask: U32(SQLITE_TriggerEQP)},
	{Fop: SQLITE_DBCONFIG_RESET_DATABASE, Fmask: U32(SQLITE_ResetDatabase)},
	{Fop: SQLITE_DBCONFIG_DEFENSIVE, Fmask: U32(SQLITE_Defensive)},
	{Fop: SQLITE_DBCONFIG_WRITABLE_SCHEMA, Fmask: U32(SQLITE_WriteSchema | SQLITE_NoSchemaError)},
	{Fop: SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, Fmask: U32(SQLITE_LegacyAlter)},
	{Fop: SQLITE_DBCONFIG_DQS_DDL, Fmask: U32(SQLITE_DqsDDL)},
	{Fop: SQLITE_DBCONFIG_DQS_DML, Fmask: U32(SQLITE_DqsDML)},
	{Fop: SQLITE_DBCONFIG_LEGACY_FILE_FORMAT, Fmask: U32(SQLITE_LegacyFileFmt)},
	{Fop: SQLITE_DBCONFIG_TRUSTED_SCHEMA, Fmask: U32(SQLITE_TrustedSchema)},
}

func binCollFunc(tls *libc.TLS, NotUsed uintptr, nKey1 int32, pKey1 uintptr, nKey2 int32, pKey2 uintptr) int32 {
	var rc int32
	var n int32
	_ = NotUsed
	if nKey1 < nKey2 {
		n = nKey1
	} else {
		n = nKey2
	}

	rc = libc.Xmemcmp(tls, pKey1, pKey2, uint64(n))
	if rc == 0 {
		rc = nKey1 - nKey2
	}
	return rc
}

func rtrimCollFunc(tls *libc.TLS, pUser uintptr, nKey1 int32, pKey1 uintptr, nKey2 int32, pKey2 uintptr) int32 {
	var pK1 uintptr = pKey1
	var pK2 uintptr = pKey2
	for nKey1 != 0 && int32(*(*U8)(unsafe.Pointer(pK1 + uintptr(nKey1-1)))) == ' ' {
		nKey1--
	}
	for nKey2 != 0 && int32(*(*U8)(unsafe.Pointer(pK2 + uintptr(nKey2-1)))) == ' ' {
		nKey2--
	}
	return binCollFunc(tls, pUser, nKey1, pKey1, nKey2, pKey2)
}

func Xsqlite3IsBinary(tls *libc.TLS, p uintptr) int32 {
	return libc.Bool32(p == uintptr(0) || (*CollSeq)(unsafe.Pointer(p)).FxCmp == *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
	}{binCollFunc})))
}

func nocaseCollatingFunc(tls *libc.TLS, NotUsed uintptr, nKey1 int32, pKey1 uintptr, nKey2 int32, pKey2 uintptr) int32 {
	var r int32 = Xsqlite3_strnicmp(tls,
		pKey1, pKey2, func() int32 {
			if nKey1 < nKey2 {
				return nKey1
			}
			return nKey2
		}())
	_ = NotUsed
	if 0 == r {
		r = nKey1 - nKey2
	}
	return r
}

func Xsqlite3_last_insert_rowid(tls *libc.TLS, db uintptr) Sqlite_int64 {
	return (*Sqlite3)(unsafe.Pointer(db)).FlastRowid
}

func Xsqlite3_set_last_insert_rowid(tls *libc.TLS, db uintptr, iRowid Sqlite3_int64) {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Sqlite3)(unsafe.Pointer(db)).FlastRowid = iRowid
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
}

func Xsqlite3_changes64(tls *libc.TLS, db uintptr) Sqlite3_int64 {
	return (*Sqlite3)(unsafe.Pointer(db)).FnChange
}

func Xsqlite3_changes(tls *libc.TLS, db uintptr) int32 {
	return int32(Xsqlite3_changes64(tls, db))
}

func Xsqlite3_total_changes64(tls *libc.TLS, db uintptr) Sqlite3_int64 {
	return (*Sqlite3)(unsafe.Pointer(db)).FnTotalChange
}

func Xsqlite3_total_changes(tls *libc.TLS, db uintptr) int32 {
	return int32(Xsqlite3_total_changes64(tls, db))
}

func Xsqlite3CloseSavepoints(tls *libc.TLS, db uintptr) {
	for (*Sqlite3)(unsafe.Pointer(db)).FpSavepoint != 0 {
		var pTmp uintptr = (*Sqlite3)(unsafe.Pointer(db)).FpSavepoint
		(*Sqlite3)(unsafe.Pointer(db)).FpSavepoint = (*Savepoint)(unsafe.Pointer(pTmp)).FpNext
		Xsqlite3DbFree(tls, db, pTmp)
	}
	(*Sqlite3)(unsafe.Pointer(db)).FnSavepoint = 0
	(*Sqlite3)(unsafe.Pointer(db)).FnStatement = 0
	(*Sqlite3)(unsafe.Pointer(db)).FisTransactionSavepoint = U8(0)
}

func functionDestroy(tls *libc.TLS, db uintptr, p uintptr) {
	var pDestructor uintptr

	pDestructor = *(*uintptr)(unsafe.Pointer(p + 64))
	if pDestructor != 0 {
		(*FuncDestructor)(unsafe.Pointer(pDestructor)).FnRef--
		if (*FuncDestructor)(unsafe.Pointer(pDestructor)).FnRef == 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*FuncDestructor)(unsafe.Pointer(pDestructor)).FxDestroy})).f(tls, (*FuncDestructor)(unsafe.Pointer(pDestructor)).FpUserData)
			Xsqlite3DbFree(tls, db, pDestructor)
		}
	}
}

func disconnectAllVtab(tls *libc.TLS, db uintptr) {
	var i int32
	var p uintptr
	Xsqlite3BtreeEnterAll(tls, db)
	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pSchema uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpSchema
		if pSchema != 0 {
			for p = (*Hash)(unsafe.Pointer(pSchema + 8)).Ffirst; p != 0; p = (*HashElem)(unsafe.Pointer(p)).Fnext {
				var pTab uintptr = (*HashElem)(unsafe.Pointer(p)).Fdata
				if int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VTAB {
					Xsqlite3VtabDisconnect(tls, db, pTab)
				}
			}
		}
	}
	for p = (*Hash)(unsafe.Pointer(db + 576)).Ffirst; p != 0; p = (*HashElem)(unsafe.Pointer(p)).Fnext {
		var pMod uintptr = (*HashElem)(unsafe.Pointer(p)).Fdata
		if (*Module)(unsafe.Pointer(pMod)).FpEpoTab != 0 {
			Xsqlite3VtabDisconnect(tls, db, (*Module)(unsafe.Pointer(pMod)).FpEpoTab)
		}
	}
	Xsqlite3VtabUnlockList(tls, db)
	Xsqlite3BtreeLeaveAll(tls, db)
}

func connectionIsBusy(tls *libc.TLS, db uintptr) int32 {
	var j int32

	if (*Sqlite3)(unsafe.Pointer(db)).FpVdbe != 0 {
		return 1
	}
	for j = 0; j < (*Sqlite3)(unsafe.Pointer(db)).FnDb; j++ {
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*32)).FpBt
		if pBt != 0 && Xsqlite3BtreeIsInBackup(tls, pBt) != 0 {
			return 1
		}
	}
	return 0
}

func sqlite3Close(tls *libc.TLS, db uintptr, forceZombie int32) int32 {
	if !(db != 0) {
		return SQLITE_OK
	}
	if !(Xsqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return Xsqlite3MisuseError(tls, 175200)
	}
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if int32((*Sqlite3)(unsafe.Pointer(db)).FmTrace)&SQLITE_TRACE_CLOSE != 0 {
		(*struct {
			f func(*libc.TLS, U32, uintptr, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(db + 248))})).f(tls, uint32(SQLITE_TRACE_CLOSE), (*Sqlite3)(unsafe.Pointer(db)).FpTraceArg, db, uintptr(0))
	}

	disconnectAllVtab(tls, db)

	Xsqlite3VtabRollback(tls, db)

	if !(forceZombie != 0) && connectionIsBusy(tls, db) != 0 {
		Xsqlite3ErrorWithMsg(tls, db, SQLITE_BUSY,
			ts+27957, 0)
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		return SQLITE_BUSY
	}

	(*Sqlite3)(unsafe.Pointer(db)).FeOpenState = U8(SQLITE_STATE_ZOMBIE)
	Xsqlite3LeaveMutexAndCloseZombie(tls, db)
	return SQLITE_OK
}

func Xsqlite3_txn_state(tls *libc.TLS, db uintptr, zSchema uintptr) int32 {
	var iDb int32
	var nDb int32
	var iTxn int32 = -1
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if zSchema != 0 {
		nDb = libc.AssignInt32(&iDb, Xsqlite3FindDbName(tls, db, zSchema))
		if iDb < 0 {
			nDb--
		}
	} else {
		iDb = 0
		nDb = (*Sqlite3)(unsafe.Pointer(db)).FnDb - 1
	}
	for ; iDb <= nDb; iDb++ {
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpBt
		var x int32
		if pBt != uintptr(0) {
			x = Xsqlite3BtreeTxnState(tls, pBt)
		} else {
			x = SQLITE_TXN_NONE
		}
		if x > iTxn {
			iTxn = x
		}
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return iTxn
}

func Xsqlite3_close(tls *libc.TLS, db uintptr) int32 {
	return sqlite3Close(tls, db, 0)
}

func Xsqlite3_close_v2(tls *libc.TLS, db uintptr) int32 {
	return sqlite3Close(tls, db, 1)
}

func Xsqlite3LeaveMutexAndCloseZombie(tls *libc.TLS, db uintptr) {
	var i uintptr
	var j int32

	if int32((*Sqlite3)(unsafe.Pointer(db)).FeOpenState) != SQLITE_STATE_ZOMBIE || connectionIsBusy(tls, db) != 0 {
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		return
	}

	Xsqlite3RollbackAll(tls, db, SQLITE_OK)

	Xsqlite3CloseSavepoints(tls, db)

	for j = 0; j < (*Sqlite3)(unsafe.Pointer(db)).FnDb; j++ {
		var pDb uintptr = (*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*32
		if (*Db1)(unsafe.Pointer(pDb)).FpBt != 0 {
			Xsqlite3BtreeClose(tls, (*Db1)(unsafe.Pointer(pDb)).FpBt)
			(*Db1)(unsafe.Pointer(pDb)).FpBt = uintptr(0)
			if j != 1 {
				(*Db1)(unsafe.Pointer(pDb)).FpSchema = uintptr(0)
			}
		}
	}

	if (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema != 0 {
		Xsqlite3SchemaClear(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema)
	}
	Xsqlite3VtabUnlockList(tls, db)

	Xsqlite3CollapseDatabaseArray(tls, db)

	Xsqlite3ConnectionClosed(tls, db)

	for i = (*Hash)(unsafe.Pointer(db + 624)).Ffirst; i != 0; i = (*HashElem)(unsafe.Pointer(i)).Fnext {
		var pNext uintptr
		var p uintptr
		p = (*HashElem)(unsafe.Pointer(i)).Fdata
		for __ccgo := true; __ccgo; __ccgo = p != 0 {
			functionDestroy(tls, db, p)
			pNext = (*FuncDef)(unsafe.Pointer(p)).FpNext
			Xsqlite3DbFree(tls, db, p)
			p = pNext
		}
	}
	Xsqlite3HashClear(tls, db+624)
	for i = (*Hash)(unsafe.Pointer(db + 648)).Ffirst; i != 0; i = (*HashElem)(unsafe.Pointer(i)).Fnext {
		var pColl uintptr = (*HashElem)(unsafe.Pointer(i)).Fdata

		for j = 0; j < 3; j++ {
			if (*CollSeq)(unsafe.Pointer(pColl+uintptr(j)*40)).FxDel != 0 {
				(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*CollSeq)(unsafe.Pointer(pColl + uintptr(j)*40)).FxDel})).f(tls, (*CollSeq)(unsafe.Pointer(pColl+uintptr(j)*40)).FpUser)
			}
		}
		Xsqlite3DbFree(tls, db, pColl)
	}
	Xsqlite3HashClear(tls, db+648)
	for i = (*Hash)(unsafe.Pointer(db + 576)).Ffirst; i != 0; i = (*HashElem)(unsafe.Pointer(i)).Fnext {
		var pMod uintptr = (*HashElem)(unsafe.Pointer(i)).Fdata
		Xsqlite3VtabEponymousTableClear(tls, db, pMod)
		Xsqlite3VtabModuleUnref(tls, db, pMod)
	}
	Xsqlite3HashClear(tls, db+576)

	Xsqlite3Error(tls, db, SQLITE_OK)
	Xsqlite3ValueFree(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr)
	Xsqlite3CloseExtensions(tls, db)

	(*Sqlite3)(unsafe.Pointer(db)).FeOpenState = U8(SQLITE_STATE_ERROR)

	Xsqlite3DbFree(tls, db, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+1*32)).FpSchema)
	if (*Sqlite3)(unsafe.Pointer(db)).FxAutovacDestr != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxAutovacDestr})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpAutovacPagesArg)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Sqlite3)(unsafe.Pointer(db)).FeOpenState = U8(SQLITE_STATE_CLOSED)
	Xsqlite3_mutex_free(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)

	if (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbMalloced != 0 {
		Xsqlite3_free(tls, (*Sqlite3)(unsafe.Pointer(db)).Flookaside.FpStart)
	}
	Xsqlite3_free(tls, db)
}

func Xsqlite3RollbackAll(tls *libc.TLS, db uintptr, tripCode int32) {
	var i int32
	var inTrans int32 = 0
	var schemaChange int32

	Xsqlite3BeginBenignMalloc(tls)

	Xsqlite3BtreeEnterAll(tls, db)
	schemaChange = libc.Bool32((*Sqlite3)(unsafe.Pointer(db)).FmDbFlags&U32(DBFLAG_SchemaChange) != U32(0) && int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) == 0)

	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var p uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if p != 0 {
			if Xsqlite3BtreeTxnState(tls, p) == SQLITE_TXN_WRITE {
				inTrans = 1
			}
			Xsqlite3BtreeRollback(tls, p, tripCode, libc.BoolInt32(!(schemaChange != 0)))
		}
	}
	Xsqlite3VtabRollback(tls, db)
	Xsqlite3EndBenignMalloc(tls)

	if schemaChange != 0 {
		Xsqlite3ExpirePreparedStatements(tls, db, 0)
		Xsqlite3ResetAllSchemasOfConnection(tls, db)
	}
	Xsqlite3BtreeLeaveAll(tls, db)

	(*Sqlite3)(unsafe.Pointer(db)).FnDeferredCons = int64(0)
	(*Sqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = int64(0)
	*(*U64)(unsafe.Pointer(db + 48)) &= libc.CplUint64(uint64(SQLITE_DeferFKs) | uint64(0x00002)<<32)

	if (*Sqlite3)(unsafe.Pointer(db)).FxRollbackCallback != 0 && (inTrans != 0 || !(int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit) != 0)) {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxRollbackCallback})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpRollbackArg)
	}
}

func Xsqlite3ErrName(tls *libc.TLS, rc int32) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zName uintptr = uintptr(0)
	var i int32
	var origRc int32 = rc
	i = 0
__1:
	if !(i < 2 && zName == uintptr(0)) {
		goto __3
	}
	{
		switch rc {
		case SQLITE_OK:
			zName = ts + 28025
			break
		case SQLITE_ERROR:
			zName = ts + 28035
			break
		case SQLITE_ERROR | int32(3)<<8:
			zName = ts + 28048
			break
		case SQLITE_INTERNAL:
			zName = ts + 28070
			break
		case SQLITE_PERM:
			zName = ts + 28086
			break
		case SQLITE_ABORT:
			zName = ts + 28098
			break
		case SQLITE_ABORT | int32(2)<<8:
			zName = ts + 28111
			break
		case SQLITE_BUSY:
			zName = ts + 28133
			break
		case SQLITE_BUSY | int32(1)<<8:
			zName = ts + 28145
			break
		case SQLITE_BUSY | int32(2)<<8:
			zName = ts + 28166
			break
		case SQLITE_LOCKED:
			zName = ts + 28187
			break
		case SQLITE_LOCKED | int32(1)<<8:
			zName = ts + 28201
			break
		case SQLITE_NOMEM:
			zName = ts + 28227
			break
		case SQLITE_READONLY:
			zName = ts + 28240
			break
		case SQLITE_READONLY | int32(1)<<8:
			zName = ts + 28256
			break
		case SQLITE_READONLY | int32(5)<<8:
			zName = ts + 28281
			break
		case SQLITE_READONLY | int32(3)<<8:
			zName = ts + 28306
			break
		case SQLITE_READONLY | int32(4)<<8:
			zName = ts + 28331
			break
		case SQLITE_READONLY | int32(6)<<8:
			zName = ts + 28355
			break
		case SQLITE_INTERRUPT:
			zName = ts + 28381
			break
		case SQLITE_IOERR:
			zName = ts + 28398
			break
		case SQLITE_IOERR | int32(1)<<8:
			zName = ts + 28411
			break
		case SQLITE_IOERR | int32(2)<<8:
			zName = ts + 28429
			break
		case SQLITE_IOERR | int32(3)<<8:
			zName = ts + 28453
			break
		case SQLITE_IOERR | int32(4)<<8:
			zName = ts + 28472
			break
		case SQLITE_IOERR | int32(5)<<8:
			zName = ts + 28491
			break
		case SQLITE_IOERR | int32(6)<<8:
			zName = ts + 28514
			break
		case SQLITE_IOERR | int32(7)<<8:
			zName = ts + 28536
			break
		case SQLITE_IOERR | int32(8)<<8:
			zName = ts + 28555
			break
		case SQLITE_IOERR | int32(9)<<8:
			zName = ts + 28575
			break
		case SQLITE_IOERR | int32(10)<<8:
			zName = ts + 28595
			break
		case SQLITE_IOERR | int32(12)<<8:
			zName = ts + 28615
			break
		case SQLITE_IOERR | int32(13)<<8:
			zName = ts + 28634
			break
		case SQLITE_IOERR | int32(14)<<8:
			zName = ts + 28654
			break
		case SQLITE_IOERR | int32(15)<<8:
			zName = ts + 28685
			break
		case SQLITE_IOERR | int32(16)<<8:
			zName = ts + 28703
			break
		case SQLITE_IOERR | int32(17)<<8:
			zName = ts + 28722
			break
		case SQLITE_IOERR | int32(18)<<8:
			zName = ts + 28745
			break
		case SQLITE_IOERR | int32(19)<<8:
			zName = ts + 28766
			break
		case SQLITE_IOERR | int32(20)<<8:
			zName = ts + 28787
			break
		case SQLITE_IOERR | int32(21)<<8:
			zName = ts + 28808
			break
		case SQLITE_IOERR | int32(22)<<8:
			zName = ts + 28828
			break
		case SQLITE_IOERR | int32(23)<<8:
			zName = ts + 28846
			break
		case SQLITE_IOERR | int32(24)<<8:
			zName = ts + 28872
			break
		case SQLITE_IOERR | int32(25)<<8:
			zName = ts + 28890
			break
		case SQLITE_IOERR | int32(26)<<8:
			zName = ts + 28915
			break
		case SQLITE_CORRUPT:
			zName = ts + 28937
			break
		case SQLITE_CORRUPT | int32(1)<<8:
			zName = ts + 28952
			break
		case SQLITE_NOTFOUND:
			zName = ts + 28972
			break
		case SQLITE_FULL:
			zName = ts + 28988
			break
		case SQLITE_CANTOPEN:
			zName = ts + 29000
			break
		case SQLITE_CANTOPEN | int32(1)<<8:
			zName = ts + 29016
			break
		case SQLITE_CANTOPEN | int32(2)<<8:
			zName = ts + 29042
			break
		case SQLITE_CANTOPEN | int32(3)<<8:
			zName = ts + 29064
			break
		case SQLITE_CANTOPEN | int32(4)<<8:
			zName = ts + 29089
			break
		case SQLITE_CANTOPEN | int32(6)<<8:
			zName = ts + 29114
			break
		case SQLITE_PROTOCOL:
			zName = ts + 29138
			break
		case SQLITE_EMPTY:
			zName = ts + 29154
			break
		case SQLITE_SCHEMA:
			zName = ts + 29167
			break
		case SQLITE_TOOBIG:
			zName = ts + 29181
			break
		case SQLITE_CONSTRAINT:
			zName = ts + 29195
			break
		case SQLITE_CONSTRAINT | int32(8)<<8:
			zName = ts + 29213
			break
		case SQLITE_CONSTRAINT | int32(7)<<8:
			zName = ts + 29238
			break
		case SQLITE_CONSTRAINT | int32(3)<<8:
			zName = ts + 29264
			break
		case SQLITE_CONSTRAINT | int32(1)<<8:
			zName = ts + 29293
			break
		case SQLITE_CONSTRAINT | int32(6)<<8:
			zName = ts + 29317
			break
		case SQLITE_CONSTRAINT | int32(5)<<8:
			zName = ts + 29346
			break
		case SQLITE_CONSTRAINT | int32(2)<<8:
			zName = ts + 29372
			break
		case SQLITE_CONSTRAINT | int32(9)<<8:
			zName = ts + 29401
			break
		case SQLITE_CONSTRAINT | int32(4)<<8:
			zName = ts + 29424
			break
		case SQLITE_CONSTRAINT | int32(10)<<8:
			zName = ts + 29451
			break
		case SQLITE_MISMATCH:
			zName = ts + 29475
			break
		case SQLITE_MISUSE:
			zName = ts + 29491
			break
		case SQLITE_NOLFS:
			zName = ts + 29505
			break
		case SQLITE_AUTH:
			zName = ts + 29518
			break
		case SQLITE_FORMAT:
			zName = ts + 29530
			break
		case SQLITE_RANGE:
			zName = ts + 29544
			break
		case SQLITE_NOTADB:
			zName = ts + 29557
			break
		case SQLITE_ROW:
			zName = ts + 29571
			break
		case SQLITE_NOTICE:
			zName = ts + 29582
			break
		case SQLITE_NOTICE | int32(1)<<8:
			zName = ts + 29596
			break
		case SQLITE_NOTICE | int32(2)<<8:
			zName = ts + 29622
			break
		case SQLITE_NOTICE | int32(3)<<8:
			zName = ts + 29653
			break
		case SQLITE_WARNING:
			zName = ts + 29671
			break
		case SQLITE_WARNING | int32(1)<<8:
			zName = ts + 29686
			break
		case SQLITE_DONE:
			zName = ts + 29711
			break
		}

	}
	goto __2
__2:
	i++
	rc = rc & 0xff
	goto __1
	goto __3
__3:
	;
	if zName == uintptr(0) {
		Xsqlite3_snprintf(tls, int32(unsafe.Sizeof(zBuf)), uintptr(unsafe.Pointer(&zBuf)), ts+29723, libc.VaList(bp, origRc))
		zName = uintptr(unsafe.Pointer(&zBuf))
	}
	return zName
}

var zBuf [50]uint8

func Xsqlite3ErrStr(tls *libc.TLS, rc int32) uintptr {
	var zErr uintptr = ts + 29742
	switch rc {
	case SQLITE_ABORT | int32(2)<<8:
		{
			zErr = ts + 29756
			break

		}
	case SQLITE_ROW:
		{
			zErr = ts + 29778
			break

		}
	case SQLITE_DONE:
		{
			zErr = ts + 29800
			break

		}
	default:
		{
			rc = rc & 0xff
			if rc >= 0 && rc < int32(uint64(unsafe.Sizeof(aMsg))/uint64(unsafe.Sizeof(uintptr(0)))) && aMsg[rc] != uintptr(0) {
				zErr = aMsg[rc]
			}
			break

		}
	}
	return zErr
}

var aMsg = [29]uintptr{
	ts + 29823,
	ts + 29836,
	uintptr(0),
	ts + 29852,
	ts + 29877,
	ts + 29891,
	ts + 29910,
	ts + 1572,
	ts + 29935,
	ts + 29972,
	ts + 29984,
	ts + 29999,
	ts + 30032,
	ts + 30050,
	ts + 30075,
	ts + 30104,
	uintptr(0),
	ts + 8763,
	ts + 8259,
	ts + 30121,
	ts + 30139,
	ts + 30157,
	uintptr(0),
	ts + 30191,
	uintptr(0),
	ts + 30212,
	ts + 30238,
	ts + 30261,
	ts + 30282,
}

func sqliteDefaultBusyCallback(tls *libc.TLS, ptr uintptr, count int32) int32 {
	var db uintptr = ptr
	var tmout int32 = (*Sqlite3)(unsafe.Pointer(db)).FbusyTimeout
	var delay int32
	var prior int32

	if count < int32(uint64(unsafe.Sizeof(delays))/uint64(unsafe.Sizeof(U8(0)))) {
		delay = int32(delays[count])
		prior = int32(totals[count])
	} else {
		delay = int32(delays[int32(uint64(unsafe.Sizeof(delays))/uint64(unsafe.Sizeof(U8(0))))-1])
		prior = int32(totals[int32(uint64(unsafe.Sizeof(delays))/uint64(unsafe.Sizeof(U8(0))))-1]) + delay*(count-(int32(uint64(unsafe.Sizeof(delays))/uint64(unsafe.Sizeof(U8(0))))-1))
	}
	if prior+delay > tmout {
		delay = tmout - prior
		if delay <= 0 {
			return 0
		}
	}
	Xsqlite3OsSleep(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, delay*1000)
	return 1
}

var delays = [12]U8{U8(1), U8(2), U8(5), U8(10), U8(15), U8(20), U8(25), U8(25), U8(25), U8(50), U8(50), U8(100)}
var totals = [12]U8{U8(0), U8(1), U8(3), U8(8), U8(18), U8(33), U8(53), U8(78), U8(103), U8(128), U8(178), U8(228)}

func Xsqlite3InvokeBusyHandler(tls *libc.TLS, p uintptr) int32 {
	var rc int32
	if (*BusyHandler)(unsafe.Pointer(p)).FxBusyHandler == uintptr(0) || (*BusyHandler)(unsafe.Pointer(p)).FnBusy < 0 {
		return 0
	}
	rc = (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*BusyHandler)(unsafe.Pointer(p)).FxBusyHandler})).f(tls, (*BusyHandler)(unsafe.Pointer(p)).FpBusyArg, (*BusyHandler)(unsafe.Pointer(p)).FnBusy)
	if rc == 0 {
		(*BusyHandler)(unsafe.Pointer(p)).FnBusy = -1
	} else {
		(*BusyHandler)(unsafe.Pointer(p)).FnBusy++
	}
	return rc
}

func Xsqlite3_busy_handler(tls *libc.TLS, db uintptr, xBusy uintptr, pArg uintptr) int32 {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FxBusyHandler = xBusy
	(*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FpBusyArg = pArg
	(*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
	(*Sqlite3)(unsafe.Pointer(db)).FbusyTimeout = 0
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

func Xsqlite3_progress_handler(tls *libc.TLS, db uintptr, nOps int32, xProgress uintptr, pArg uintptr) {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if nOps > 0 {
		(*Sqlite3)(unsafe.Pointer(db)).FxProgress = xProgress
		(*Sqlite3)(unsafe.Pointer(db)).FnProgressOps = uint32(nOps)
		(*Sqlite3)(unsafe.Pointer(db)).FpProgressArg = pArg
	} else {
		(*Sqlite3)(unsafe.Pointer(db)).FxProgress = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).FnProgressOps = uint32(0)
		(*Sqlite3)(unsafe.Pointer(db)).FpProgressArg = uintptr(0)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
}

func Xsqlite3_busy_timeout(tls *libc.TLS, db uintptr, ms int32) int32 {
	if ms > 0 {
		Xsqlite3_busy_handler(tls, db, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32) int32
		}{sqliteDefaultBusyCallback})),
			db)
		(*Sqlite3)(unsafe.Pointer(db)).FbusyTimeout = ms
	} else {
		Xsqlite3_busy_handler(tls, db, uintptr(0), uintptr(0))
	}
	return SQLITE_OK
}

func Xsqlite3_interrupt(tls *libc.TLS, db uintptr) {
	libc.AtomicStoreNInt32(db+432, int32(1), 0)
}

func Xsqlite3_is_interrupted(tls *libc.TLS, db uintptr) int32 {
	return libc.Bool32(libc.AtomicLoadNInt32(db+432, 0) != 0)
}

func Xsqlite3CreateFunc(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) int32 {
	var p uintptr
	var extraFlags int32

	if zFunctionName == uintptr(0) ||
		xSFunc != uintptr(0) && xFinal != uintptr(0) ||
		libc.Bool32(xFinal == uintptr(0)) != libc.Bool32(xStep == uintptr(0)) ||
		libc.Bool32(xValue == uintptr(0)) != libc.Bool32(xInverse == uintptr(0)) ||
		(nArg < -1 || nArg > SQLITE_MAX_FUNCTION_ARG) ||
		255 < Xsqlite3Strlen30(tls, zFunctionName) {
		return Xsqlite3MisuseError(tls, 175847)
	}

	extraFlags = enc & (SQLITE_DETERMINISTIC | SQLITE_DIRECTONLY | SQLITE_SUBTYPE | SQLITE_INNOCUOUS)
	enc = enc & (SQLITE_FUNC_ENCMASK | SQLITE_ANY)

	extraFlags = extraFlags ^ SQLITE_FUNC_UNSAFE

	switch enc {
	case SQLITE_UTF16:
		enc = SQLITE_UTF16LE
		break
	case SQLITE_ANY:
		{
			var rc int32
			rc = Xsqlite3CreateFunc(tls, db, zFunctionName, nArg,
				SQLITE_UTF8|extraFlags^SQLITE_FUNC_UNSAFE,
				pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor)
			if rc == SQLITE_OK {
				rc = Xsqlite3CreateFunc(tls, db, zFunctionName, nArg,
					SQLITE_UTF16LE|extraFlags^SQLITE_FUNC_UNSAFE,
					pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor)
			}
			if rc != SQLITE_OK {
				return rc
			}
			enc = SQLITE_UTF16BE
			break

		}
	case SQLITE_UTF8:
		fallthrough
	case SQLITE_UTF16LE:
		fallthrough
	case SQLITE_UTF16BE:
		break
	default:
		enc = SQLITE_UTF8
		break
	}

	p = Xsqlite3FindFunction(tls, db, zFunctionName, nArg, U8(enc), uint8(0))
	if p != 0 && (*FuncDef)(unsafe.Pointer(p)).FfuncFlags&U32(SQLITE_FUNC_ENCMASK) == U32(enc) && int32((*FuncDef)(unsafe.Pointer(p)).FnArg) == nArg {
		if (*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive != 0 {
			Xsqlite3ErrorWithMsg(tls, db, SQLITE_BUSY,
				ts+30298, 0)

			return SQLITE_BUSY
		} else {
			Xsqlite3ExpirePreparedStatements(tls, db, 0)
		}
	} else if xSFunc == uintptr(0) && xFinal == uintptr(0) {
		return SQLITE_OK
	}

	p = Xsqlite3FindFunction(tls, db, zFunctionName, nArg, U8(enc), uint8(1))

	if !(p != 0) {
		return SQLITE_NOMEM
	}

	functionDestroy(tls, db, p)

	if pDestructor != 0 {
		(*FuncDestructor)(unsafe.Pointer(pDestructor)).FnRef++
	}
	*(*uintptr)(unsafe.Pointer(p + 64)) = pDestructor
	(*FuncDef)(unsafe.Pointer(p)).FfuncFlags = (*FuncDef)(unsafe.Pointer(p)).FfuncFlags&U32(SQLITE_FUNC_ENCMASK) | U32(extraFlags)

	(*FuncDef)(unsafe.Pointer(p)).FxSFunc = func() uintptr {
		if xSFunc != 0 {
			return xSFunc
		}
		return xStep
	}()
	(*FuncDef)(unsafe.Pointer(p)).FxFinalize = xFinal
	(*FuncDef)(unsafe.Pointer(p)).FxValue = xValue
	(*FuncDef)(unsafe.Pointer(p)).FxInverse = xInverse
	(*FuncDef)(unsafe.Pointer(p)).FpUserData = pUserData
	(*FuncDef)(unsafe.Pointer(p)).FnArg = I8(U16(nArg))
	return SQLITE_OK
}

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) int32 {
	var rc int32
	var pArg uintptr
	rc = SQLITE_ERROR
	pArg = uintptr(0)

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if !(xDestroy != 0) {
		goto __1
	}
	pArg = Xsqlite3Malloc(tls, uint64(unsafe.Sizeof(FuncDestructor{})))
	if !!(pArg != 0) {
		goto __2
	}
	Xsqlite3OomFault(tls, db)
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDestroy})).f(tls, p)
	goto out
__2:
	;
	(*FuncDestructor)(unsafe.Pointer(pArg)).FnRef = 0
	(*FuncDestructor)(unsafe.Pointer(pArg)).FxDestroy = xDestroy
	(*FuncDestructor)(unsafe.Pointer(pArg)).FpUserData = p
__1:
	;
	rc = Xsqlite3CreateFunc(tls, db, zFunc, nArg, enc, p,
		xSFunc, xStep, xFinal, xValue, xInverse, pArg)
	if !(pArg != 0 && (*FuncDestructor)(unsafe.Pointer(pArg)).FnRef == 0) {
		goto __3
	}

	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDestroy})).f(tls, p)
	Xsqlite3_free(tls, pArg)
__3:
	;
out:
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_create_function(tls *libc.TLS, db uintptr, zFunc uintptr, nArg int32, enc int32, p uintptr, xSFunc uintptr, xStep uintptr, xFinal uintptr) 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) 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) 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) int32 {
	var rc int32
	var zFunc8 uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)

	zFunc8 = Xsqlite3Utf16to8(tls, db, zFunctionName, -1, uint8(SQLITE_UTF16LE))
	rc = Xsqlite3CreateFunc(tls, db, zFunc8, nArg, eTextRep, p, xSFunc, xStep, xFinal, uintptr(0), uintptr(0), uintptr(0))
	Xsqlite3DbFree(tls, db, zFunc8)
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func sqlite3InvalidFunction(tls *libc.TLS, context uintptr, NotUsed int32, NotUsed2 uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zName uintptr = Xsqlite3_user_data(tls, context)
	var zErr uintptr
	_ = NotUsed
	_ = NotUsed2
	zErr = Xsqlite3_mprintf(tls,
		ts+30361, libc.VaList(bp, zName))
	Xsqlite3_result_error(tls, context, zErr, -1)
	Xsqlite3_free(tls, zErr)
}

func Xsqlite3_overload_function(tls *libc.TLS, db uintptr, zName uintptr, nArg int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	var zCopy uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	rc = libc.Bool32(Xsqlite3FindFunction(tls, db, zName, nArg, uint8(SQLITE_UTF8), uint8(0)) != uintptr(0))
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if rc != 0 {
		return SQLITE_OK
	}
	zCopy = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, zName))
	if zCopy == uintptr(0) {
		return SQLITE_NOMEM
	}
	return Xsqlite3_create_function_v2(tls, db, zName, nArg, SQLITE_UTF8,
		zCopy, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{sqlite3InvalidFunction})), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
}

func Xsqlite3_trace(tls *libc.TLS, db uintptr, xTrace uintptr, pArg uintptr) uintptr {
	var pOld uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pOld = (*Sqlite3)(unsafe.Pointer(db)).FpTraceArg
	(*Sqlite3)(unsafe.Pointer(db)).FmTrace = func() uint8 {
		if xTrace != 0 {
			return uint8(SQLITE_TRACE_LEGACY)
		}
		return uint8(0)
	}()
	*(*uintptr)(unsafe.Pointer(db + 248)) = xTrace
	(*Sqlite3)(unsafe.Pointer(db)).FpTraceArg = pArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return pOld
}

func Xsqlite3_trace_v2(tls *libc.TLS, db uintptr, mTrace uint32, xTrace uintptr, pArg uintptr) int32 {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if mTrace == uint32(0) {
		xTrace = uintptr(0)
	}
	if xTrace == uintptr(0) {
		mTrace = uint32(0)
	}
	(*Sqlite3)(unsafe.Pointer(db)).FmTrace = U8(mTrace)
	*(*uintptr)(unsafe.Pointer(db + 248)) = xTrace
	(*Sqlite3)(unsafe.Pointer(db)).FpTraceArg = pArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

func Xsqlite3_profile(tls *libc.TLS, db uintptr, xProfile uintptr, pArg uintptr) uintptr {
	var pOld uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pOld = (*Sqlite3)(unsafe.Pointer(db)).FpProfileArg
	(*Sqlite3)(unsafe.Pointer(db)).FxProfile = xProfile
	(*Sqlite3)(unsafe.Pointer(db)).FpProfileArg = pArg
	*(*U8)(unsafe.Pointer(db + 110)) &= U8(SQLITE_TRACE_NONLEGACY_MASK)
	if (*Sqlite3)(unsafe.Pointer(db)).FxProfile != 0 {
		*(*U8)(unsafe.Pointer(db + 110)) |= U8(SQLITE_TRACE_XPROFILE)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return pOld
}

func Xsqlite3_commit_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) uintptr {
	var pOld uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pOld = (*Sqlite3)(unsafe.Pointer(db)).FpCommitArg
	(*Sqlite3)(unsafe.Pointer(db)).FxCommitCallback = xCallback
	(*Sqlite3)(unsafe.Pointer(db)).FpCommitArg = pArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return pOld
}

func Xsqlite3_update_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) uintptr {
	var pRet uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pRet = (*Sqlite3)(unsafe.Pointer(db)).FpUpdateArg
	(*Sqlite3)(unsafe.Pointer(db)).FxUpdateCallback = xCallback
	(*Sqlite3)(unsafe.Pointer(db)).FpUpdateArg = pArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return pRet
}

func Xsqlite3_rollback_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) uintptr {
	var pRet uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pRet = (*Sqlite3)(unsafe.Pointer(db)).FpRollbackArg
	(*Sqlite3)(unsafe.Pointer(db)).FxRollbackCallback = xCallback
	(*Sqlite3)(unsafe.Pointer(db)).FpRollbackArg = pArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return pRet
}

func Xsqlite3_preupdate_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) uintptr {
	var pRet uintptr
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pRet = (*Sqlite3)(unsafe.Pointer(db)).FpPreUpdateArg
	(*Sqlite3)(unsafe.Pointer(db)).FxPreUpdateCallback = xCallback
	(*Sqlite3)(unsafe.Pointer(db)).FpPreUpdateArg = pArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return pRet
}

func Xsqlite3_autovacuum_pages(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr, xDestructor uintptr) int32 {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*Sqlite3)(unsafe.Pointer(db)).FxAutovacDestr != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3)(unsafe.Pointer(db)).FxAutovacDestr})).f(tls, (*Sqlite3)(unsafe.Pointer(db)).FpAutovacPagesArg)
	}
	(*Sqlite3)(unsafe.Pointer(db)).FxAutovacPages = xCallback
	(*Sqlite3)(unsafe.Pointer(db)).FpAutovacPagesArg = pArg
	(*Sqlite3)(unsafe.Pointer(db)).FxAutovacDestr = xDestructor
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

func Xsqlite3WalDefaultHook(tls *libc.TLS, pClientData uintptr, db uintptr, zDb uintptr, nFrame int32) int32 {
	if nFrame >= int32(pClientData) {
		Xsqlite3BeginBenignMalloc(tls)
		Xsqlite3_wal_checkpoint(tls, db, zDb)
		Xsqlite3EndBenignMalloc(tls)
	}
	return SQLITE_OK
}

func Xsqlite3_wal_autocheckpoint(tls *libc.TLS, db uintptr, nFrame int32) int32 {
	if nFrame > 0 {
		Xsqlite3_wal_hook(tls, db, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32) int32
		}{Xsqlite3WalDefaultHook})), uintptr(int64(nFrame)))
	} else {
		Xsqlite3_wal_hook(tls, db, uintptr(0), uintptr(0))
	}
	return SQLITE_OK
}

func Xsqlite3_wal_hook(tls *libc.TLS, db uintptr, xCallback uintptr, pArg uintptr) uintptr {
	var pRet uintptr
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pRet = (*Sqlite3)(unsafe.Pointer(db)).FpWalArg
	(*Sqlite3)(unsafe.Pointer(db)).FxWalCallback = xCallback
	(*Sqlite3)(unsafe.Pointer(db)).FpWalArg = pArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return pRet
}

func Xsqlite3_wal_checkpoint_v2(tls *libc.TLS, db uintptr, zDb uintptr, eMode int32, pnLog uintptr, pnCkpt uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	var iDb int32

	if pnLog != 0 {
		*(*int32)(unsafe.Pointer(pnLog)) = -1
	}
	if pnCkpt != 0 {
		*(*int32)(unsafe.Pointer(pnCkpt)) = -1
	}

	if eMode < SQLITE_CHECKPOINT_PASSIVE || eMode > SQLITE_CHECKPOINT_TRUNCATE {
		return SQLITE_MISUSE
	}

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if zDb != 0 && *(*uint8)(unsafe.Pointer(zDb)) != 0 {
		iDb = Xsqlite3FindDbName(tls, db, zDb)
	} else {
		iDb = SQLITE_MAX_ATTACHED + 2
	}
	if iDb < 0 {
		rc = SQLITE_ERROR
		Xsqlite3ErrorWithMsg(tls, db, SQLITE_ERROR, ts+30412, libc.VaList(bp, zDb))
	} else {
		(*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = 0
		rc = Xsqlite3Checkpoint(tls, db, iDb, eMode, pnLog, pnCkpt)
		Xsqlite3Error(tls, db, rc)
	}
	rc = Xsqlite3ApiExit(tls, db, rc)

	if (*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive == 0 {
		libc.AtomicStoreNInt32(db+432, int32(0), 0)
	}

	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_wal_checkpoint(tls *libc.TLS, db uintptr, zDb uintptr) int32 {
	return Xsqlite3_wal_checkpoint_v2(tls, db, zDb, SQLITE_CHECKPOINT_PASSIVE, uintptr(0), uintptr(0))
}

func Xsqlite3Checkpoint(tls *libc.TLS, db uintptr, iDb int32, eMode int32, pnLog uintptr, pnCkpt uintptr) int32 {
	var rc int32 = SQLITE_OK
	var i int32
	var bBusy int32 = 0

	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb && rc == SQLITE_OK; i++ {
		if i == iDb || iDb == SQLITE_MAX_ATTACHED+2 {
			rc = Xsqlite3BtreeCheckpoint(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(i)*32)).FpBt, eMode, pnLog, pnCkpt)
			pnLog = uintptr(0)
			pnCkpt = uintptr(0)
			if rc == SQLITE_BUSY {
				bBusy = 1
				rc = SQLITE_OK
			}
		}
	}

	if rc == SQLITE_OK && bBusy != 0 {
		return SQLITE_BUSY
	}
	return rc
}

func Xsqlite3TempInMemory(tls *libc.TLS, db uintptr) int32 {
	return libc.Bool32(int32((*Sqlite3)(unsafe.Pointer(db)).Ftemp_store) == 2)
}

func Xsqlite3_errmsg(tls *libc.TLS, db uintptr) uintptr {
	var z uintptr
	if !(db != 0) {
		return Xsqlite3ErrStr(tls, SQLITE_NOMEM)
	}
	if !(Xsqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return Xsqlite3ErrStr(tls, Xsqlite3MisuseError(tls, 176592))
	}
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		z = Xsqlite3ErrStr(tls, SQLITE_NOMEM)
	} else {
		if (*Sqlite3)(unsafe.Pointer(db)).FerrCode != 0 {
			z = Xsqlite3_value_text(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr)
		} else {
			z = uintptr(0)
		}

		if z == uintptr(0) {
			z = Xsqlite3ErrStr(tls, (*Sqlite3)(unsafe.Pointer(db)).FerrCode)
		}
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return z
}

func Xsqlite3_error_offset(tls *libc.TLS, db uintptr) int32 {
	var iOffset int32 = -1
	if db != 0 && Xsqlite3SafetyCheckSickOrOk(tls, db) != 0 && (*Sqlite3)(unsafe.Pointer(db)).FerrCode != 0 {
		Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
		iOffset = (*Sqlite3)(unsafe.Pointer(db)).FerrByteOffset
		Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	}
	return iOffset
}

func Xsqlite3_errmsg16(tls *libc.TLS, db uintptr) uintptr {
	var z uintptr
	if !(db != 0) {
		return uintptr(unsafe.Pointer(&outOfMem))
	}
	if !(Xsqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return uintptr(unsafe.Pointer(&misuse))
	}
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	if (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		z = uintptr(unsafe.Pointer(&outOfMem))
	} else {
		z = Xsqlite3_value_text16(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr)
		if z == uintptr(0) {
			Xsqlite3ErrorWithMsg(tls, db, (*Sqlite3)(unsafe.Pointer(db)).FerrCode, Xsqlite3ErrStr(tls, (*Sqlite3)(unsafe.Pointer(db)).FerrCode), 0)
			z = Xsqlite3_value_text16(tls, (*Sqlite3)(unsafe.Pointer(db)).FpErr)
		}

		Xsqlite3OomClear(tls, db)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return z
}

var outOfMem = [14]U16{
	U16('o'), U16('u'), U16('t'), U16(' '), U16('o'), U16('f'), U16(' '), U16('m'), U16('e'), U16('m'), U16('o'), U16('r'), U16('y'), U16(0),
}
var misuse = [34]U16{
	U16('b'), U16('a'), U16('d'), U16(' '), U16('p'), U16('a'), U16('r'), U16('a'), U16('m'), U16('e'), U16('t'), U16('e'), U16('r'), U16(' '),
	U16('o'), U16('r'), U16(' '), U16('o'), U16('t'), U16('h'), U16('e'), U16('r'), U16(' '), U16('A'), U16('P'), U16('I'), U16(' '),
	U16('m'), U16('i'), U16('s'), U16('u'), U16('s'), U16('e'), U16(0),
}

func Xsqlite3_errcode(tls *libc.TLS, db uintptr) int32 {
	if db != 0 && !(Xsqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return Xsqlite3MisuseError(tls, 176671)
	}
	if !(db != 0) || (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return SQLITE_NOMEM
	}
	return (*Sqlite3)(unsafe.Pointer(db)).FerrCode & (*Sqlite3)(unsafe.Pointer(db)).FerrMask
}

func Xsqlite3_extended_errcode(tls *libc.TLS, db uintptr) int32 {
	if db != 0 && !(Xsqlite3SafetyCheckSickOrOk(tls, db) != 0) {
		return Xsqlite3MisuseError(tls, 176680)
	}
	if !(db != 0) || (*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		return SQLITE_NOMEM
	}
	return (*Sqlite3)(unsafe.Pointer(db)).FerrCode
}

func Xsqlite3_system_errno(tls *libc.TLS, db uintptr) int32 {
	if db != 0 {
		return (*Sqlite3)(unsafe.Pointer(db)).FiSysErrno
	}
	return 0
}

func Xsqlite3_errstr(tls *libc.TLS, rc int32) uintptr {
	return Xsqlite3ErrStr(tls, rc)
}

func createCollation(tls *libc.TLS, db uintptr, zName uintptr, enc U8, pCtx uintptr, xCompare uintptr, xDel uintptr) int32 {
	var pColl uintptr
	var enc2 int32

	enc2 = int32(enc)

	if enc2 == SQLITE_UTF16 || enc2 == SQLITE_UTF16_ALIGNED {
		enc2 = SQLITE_UTF16LE
	}
	if enc2 < SQLITE_UTF8 || enc2 > SQLITE_UTF16BE {
		return Xsqlite3MisuseError(tls, 176728)
	}

	pColl = Xsqlite3FindCollSeq(tls, db, U8(enc2), zName, 0)
	if pColl != 0 && (*CollSeq)(unsafe.Pointer(pColl)).FxCmp != 0 {
		if (*Sqlite3)(unsafe.Pointer(db)).FnVdbeActive != 0 {
			Xsqlite3ErrorWithMsg(tls, db, SQLITE_BUSY,
				ts+30433, 0)
			return SQLITE_BUSY
		}
		Xsqlite3ExpirePreparedStatements(tls, db, 0)

		if int32((*CollSeq)(unsafe.Pointer(pColl)).Fenc)&libc.CplInt32(SQLITE_UTF16_ALIGNED) == enc2 {
			var aColl uintptr = Xsqlite3HashFind(tls, db+648, zName)
			var j int32
			for j = 0; j < 3; j++ {
				var p uintptr = aColl + uintptr(j)*40
				if int32((*CollSeq)(unsafe.Pointer(p)).Fenc) == int32((*CollSeq)(unsafe.Pointer(pColl)).Fenc) {
					if (*CollSeq)(unsafe.Pointer(p)).FxDel != 0 {
						(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*CollSeq)(unsafe.Pointer(p)).FxDel})).f(tls, (*CollSeq)(unsafe.Pointer(p)).FpUser)
					}
					(*CollSeq)(unsafe.Pointer(p)).FxCmp = uintptr(0)
				}
			}
		}
	}

	pColl = Xsqlite3FindCollSeq(tls, db, U8(enc2), zName, 1)
	if pColl == uintptr(0) {
		return SQLITE_NOMEM
	}
	(*CollSeq)(unsafe.Pointer(pColl)).FxCmp = xCompare
	(*CollSeq)(unsafe.Pointer(pColl)).FpUser = pCtx
	(*CollSeq)(unsafe.Pointer(pColl)).FxDel = xDel
	(*CollSeq)(unsafe.Pointer(pColl)).Fenc = U8(enc2 | int32(enc)&SQLITE_UTF16_ALIGNED)
	Xsqlite3Error(tls, db, SQLITE_OK)
	return SQLITE_OK
}

var aHardLimit = [12]int32{
	SQLITE_MAX_LENGTH,
	SQLITE_MAX_SQL_LENGTH,
	SQLITE_MAX_COLUMN,
	SQLITE_MAX_EXPR_DEPTH,
	SQLITE_MAX_COMPOUND_SELECT,
	SQLITE_MAX_VDBE_OP,
	SQLITE_MAX_FUNCTION_ARG,
	SQLITE_MAX_ATTACHED,
	SQLITE_MAX_LIKE_PATTERN_LENGTH,
	SQLITE_MAX_VARIABLE_NUMBER,
	SQLITE_MAX_TRIGGER_DEPTH,
	SQLITE_MAX_WORKER_THREADS,
}

func Xsqlite3_limit(tls *libc.TLS, db uintptr, limitId int32, newLimit int32) int32 {
	var oldLimit int32

	if limitId < 0 || limitId >= SQLITE_LIMIT_WORKER_THREADS+1 {
		return -1
	}
	oldLimit = *(*int32)(unsafe.Pointer(db + 136 + uintptr(limitId)*4))
	if newLimit >= 0 {
		if newLimit > aHardLimit[limitId] {
			newLimit = aHardLimit[limitId]
		} else if newLimit < 1 && limitId == SQLITE_LIMIT_LENGTH {
			newLimit = 1
		}
		*(*int32)(unsafe.Pointer(db + 136 + uintptr(limitId)*4)) = newLimit
	}
	return oldLimit
}

func Xsqlite3ParseUri(tls *libc.TLS, zDefaultVfs uintptr, zUri uintptr, pFlags uintptr, ppVfs uintptr, pzFile uintptr, pzErrMsg uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var rc int32
	var flags uint32
	var zVfs uintptr
	var zFile uintptr
	var c uint8
	var nUri int32
	var octet int32
	var z uintptr
	var i int32
	var mode int32
	var aMode uintptr
	var zModeType uintptr
	var mask int32
	var limit int32
	var nOpt int32
	var zVal uintptr
	var nVal int32
	var zOpt uintptr
	var eState int32
	var iIn int32
	var iOut int32
	var nByte U64
	rc = SQLITE_OK
	flags = *(*uint32)(unsafe.Pointer(pFlags))
	zVfs = zDefaultVfs
	nUri = Xsqlite3Strlen30(tls, zUri)

	if !((flags&uint32(SQLITE_OPEN_URI) != 0 ||
		Xsqlite3Config.FbOpenUri != 0) &&
		nUri >= 5 && libc.Xmemcmp(tls, zUri, ts+30501, uint64(5)) == 0) {
		goto __1
	}
	iOut = 0
	nByte = U64(nUri + 8)

	flags = flags | uint32(SQLITE_OPEN_URI)

	iIn = 0
__3:
	if !(iIn < nUri) {
		goto __5
	}
	nByte = nByte + U64(libc.Bool32(int32(*(*uint8)(unsafe.Pointer(zUri + uintptr(iIn)))) == '&'))
	goto __4
__4:
	iIn++
	goto __3
	goto __5
__5:
	;
	zFile = Xsqlite3_malloc64(tls, nByte)
	if !!(zFile != 0) {
		goto __6
	}
	return SQLITE_NOMEM
__6:
	;
	libc.Xmemset(tls, zFile, 0, uint64(4))
	zFile += uintptr(4)

	iIn = 5

	if !(int32(*(*uint8)(unsafe.Pointer(zUri + 5))) == '/' && int32(*(*uint8)(unsafe.Pointer(zUri + 6))) == '/') {
		goto __7
	}
	iIn = 7
__8:
	if !(*(*uint8)(unsafe.Pointer(zUri + uintptr(iIn))) != 0 && int32(*(*uint8)(unsafe.Pointer(zUri + uintptr(iIn)))) != '/') {
		goto __9
	}
	iIn++
	goto __8
__9:
	;
	if !(iIn != 7 && (iIn != 16 || libc.Xmemcmp(tls, ts+30507, zUri+7, uint64(9)) != 0)) {
		goto __10
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+30517,
		libc.VaList(bp, iIn-7, zUri+7))
	rc = SQLITE_ERROR
	goto parse_uri_out
__10:
	;
__7:
	;
	eState = 0
__11:
	if !(int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(zUri + uintptr(iIn))))) != 0 && int32(c) != '#') {
		goto __12
	}
	iIn++
	if !(int32(c) == '%' &&
		int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zUri + uintptr(iIn)))])&0x08 != 0 &&
		int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zUri + uintptr(iIn+1)))])&0x08 != 0) {
		goto __13
	}
	octet = int32(Xsqlite3HexToInt(tls, int32(*(*uint8)(unsafe.Pointer(zUri + uintptr(libc.PostIncInt32(&iIn, 1))))))) << 4
	octet = octet + int32(Xsqlite3HexToInt(tls, int32(*(*uint8)(unsafe.Pointer(zUri + uintptr(libc.PostIncInt32(&iIn, 1)))))))

	if !(octet == 0) {
		goto __15
	}

__16:
	if !(int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(zUri + uintptr(iIn))))) != 0 && int32(c) != '#' &&
		(eState != 0 || int32(c) != '?') &&
		(eState != 1 || int32(c) != '=' && int32(c) != '&') &&
		(eState != 2 || int32(c) != '&')) {
		goto __17
	}
	iIn++
	goto __16
__17:
	;
	goto __11
__15:
	;
	c = uint8(octet)
	goto __14
__13:
	if !(eState == 1 && (int32(c) == '&' || int32(c) == '=')) {
		goto __18
	}
	if !(int32(*(*uint8)(unsafe.Pointer(zFile + uintptr(iOut-1)))) == 0) {
		goto __20
	}

__21:
	if !(*(*uint8)(unsafe.Pointer(zUri + uintptr(iIn))) != 0 && int32(*(*uint8)(unsafe.Pointer(zUri + uintptr(iIn)))) != '#' && int32(*(*uint8)(unsafe.Pointer(zUri + uintptr(iIn-1)))) != '&') {
		goto __22
	}
	iIn++
	goto __21
__22:
	;
	goto __11
__20:
	;
	if !(int32(c) == '&') {
		goto __23
	}
	*(*uint8)(unsafe.Pointer(zFile + uintptr(libc.PostIncInt32(&iOut, 1)))) = uint8(0)
	goto __24
__23:
	eState = 2
__24:
	;
	c = uint8(0)
	goto __19
__18:
	if !(eState == 0 && int32(c) == '?' || eState == 2 && int32(c) == '&') {
		goto __25
	}
	c = uint8(0)
	eState = 1
__25:
	;
__19:
	;
__14:
	;
	*(*uint8)(unsafe.Pointer(zFile + uintptr(libc.PostIncInt32(&iOut, 1)))) = c
	goto __11
__12:
	;
	if !(eState == 1) {
		goto __26
	}
	*(*uint8)(unsafe.Pointer(zFile + uintptr(libc.PostIncInt32(&iOut, 1)))) = uint8(0)
__26:
	;
	libc.Xmemset(tls, zFile+uintptr(iOut), 0, uint64(4))

	zOpt = zFile + uintptr(Xsqlite3Strlen30(tls, zFile)+1)
__27:
	if !(*(*uint8)(unsafe.Pointer(zOpt)) != 0) {
		goto __28
	}
	nOpt = Xsqlite3Strlen30(tls, zOpt)
	zVal = zOpt + uintptr(nOpt+1)
	nVal = Xsqlite3Strlen30(tls, zVal)

	if !(nOpt == 3 && libc.Xmemcmp(tls, ts+30545, zOpt, uint64(3)) == 0) {
		goto __29
	}
	zVfs = zVal
	goto __30
__29:
	aMode = uintptr(0)
	zModeType = uintptr(0)
	mask = 0
	limit = 0

	if !(nOpt == 5 && libc.Xmemcmp(tls, ts+30549, zOpt, uint64(5)) == 0) {
		goto __31
	}

	mask = SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_PRIVATECACHE
	aMode = uintptr(unsafe.Pointer(&aCacheMode))
	limit = mask
	zModeType = ts + 30549
__31:
	;
	if !(nOpt == 4 && libc.Xmemcmp(tls, ts+30555, zOpt, uint64(4)) == 0) {
		goto __32
	}

	mask = SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE |
		SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY
	aMode = uintptr(unsafe.Pointer(&aOpenMode))
	limit = int32(uint32(mask) & flags)
	zModeType = ts + 5634
__32:
	;
	if !(aMode != 0) {
		goto __33
	}
	mode = 0
	i = 0
__34:
	if !((*OpenMode)(unsafe.Pointer(aMode+uintptr(i)*16)).Fz != 0) {
		goto __36
	}
	z = (*OpenMode)(unsafe.Pointer(aMode + uintptr(i)*16)).Fz
	if !(nVal == Xsqlite3Strlen30(tls, z) && 0 == libc.Xmemcmp(tls, zVal, z, uint64(nVal))) {
		goto __37
	}
	mode = (*OpenMode)(unsafe.Pointer(aMode + uintptr(i)*16)).Fmode
	goto __36
__37:
	;
	goto __35
__35:
	i++
	goto __34
	goto __36
__36:
	;
	if !(mode == 0) {
		goto __38
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+30560, libc.VaList(bp+16, zModeType, zVal))
	rc = SQLITE_ERROR
	goto parse_uri_out
__38:
	;
	if !(mode&libc.CplInt32(SQLITE_OPEN_MEMORY) > limit) {
		goto __39
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+30580,
		libc.VaList(bp+32, zModeType, zVal))
	rc = SQLITE_PERM
	goto parse_uri_out
__39:
	;
	flags = flags&uint32(^mask) | uint32(mode)
__33:
	;
__30:
	;
	zOpt = zVal + uintptr(nVal+1)
	goto __27
__28:
	;
	goto __2
__1:
	zFile = Xsqlite3_malloc64(tls, uint64(nUri+8))
	if !!(zFile != 0) {
		goto __40
	}
	return SQLITE_NOMEM
__40:
	;
	libc.Xmemset(tls, zFile, 0, uint64(4))
	zFile += uintptr(4)
	if !(nUri != 0) {
		goto __41
	}
	libc.Xmemcpy(tls, zFile, zUri, uint64(nUri))
__41:
	;
	libc.Xmemset(tls, zFile+uintptr(nUri), 0, uint64(4))
	flags = flags & libc.Uint32FromInt32(libc.CplInt32(SQLITE_OPEN_URI))
__2:
	;
	*(*uintptr)(unsafe.Pointer(ppVfs)) = Xsqlite3_vfs_find(tls, zVfs)
	if !(*(*uintptr)(unsafe.Pointer(ppVfs)) == uintptr(0)) {
		goto __42
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+30604, libc.VaList(bp+48, zVfs))
	rc = SQLITE_ERROR
__42:
	;
parse_uri_out:
	if !(rc != SQLITE_OK) {
		goto __43
	}
	Xsqlite3_free_filename(tls, zFile)
	zFile = uintptr(0)
__43:
	;
	*(*uint32)(unsafe.Pointer(pFlags)) = flags
	*(*uintptr)(unsafe.Pointer(pzFile)) = zFile
	return rc
}

type OpenMode = struct {
	Fz           uintptr
	Fmode        int32
	F__ccgo_pad1 [4]byte
}

var aCacheMode = [3]OpenMode{
	{Fz: ts + 21743, Fmode: SQLITE_OPEN_SHAREDCACHE},
	{Fz: ts + 30620, Fmode: SQLITE_OPEN_PRIVATECACHE},
	{},
}
var aOpenMode = [5]OpenMode{
	{Fz: ts + 30628, Fmode: SQLITE_OPEN_READONLY},
	{Fz: ts + 30631, Fmode: SQLITE_OPEN_READWRITE},
	{Fz: ts + 30634, Fmode: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE},
	{Fz: ts + 20915, Fmode: SQLITE_OPEN_MEMORY},
	{},
}

func uriParameter(tls *libc.TLS, zFilename uintptr, zParam uintptr) uintptr {
	zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
	for zFilename != uintptr(0) && *(*uint8)(unsafe.Pointer(zFilename)) != 0 {
		var x int32 = libc.Xstrcmp(tls, zFilename, zParam)
		zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
		if x == 0 {
			return zFilename
		}
		zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
	}
	return uintptr(0)
}

func openDatabase(tls *libc.TLS, zFilename uintptr, ppDb uintptr, flags uint32, zVfs uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	*(*uint32)(unsafe.Pointer(bp + 8)) = flags

	var db uintptr
	var rc int32
	var isThreadsafe int32

	var i int32
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)

	*(*uintptr)(unsafe.Pointer(ppDb)) = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if !(rc != 0) {
		goto __1
	}
	return rc
__1:
	;
	if !(int32(Xsqlite3Config.FbCoreMutex) == 0) {
		goto __2
	}
	isThreadsafe = 0
	goto __3
__2:
	if !(*(*uint32)(unsafe.Pointer(bp + 8))&uint32(SQLITE_OPEN_NOMUTEX) != 0) {
		goto __4
	}
	isThreadsafe = 0
	goto __5
__4:
	if !(*(*uint32)(unsafe.Pointer(bp + 8))&uint32(SQLITE_OPEN_FULLMUTEX) != 0) {
		goto __6
	}
	isThreadsafe = 1
	goto __7
__6:
	isThreadsafe = int32(Xsqlite3Config.FbFullMutex)
__7:
	;
__5:
	;
__3:
	;
	if !(*(*uint32)(unsafe.Pointer(bp + 8))&uint32(SQLITE_OPEN_PRIVATECACHE) != 0) {
		goto __8
	}
	*(*uint32)(unsafe.Pointer(bp + 8)) &= libc.Uint32FromInt32(libc.CplInt32(SQLITE_OPEN_SHAREDCACHE))
	goto __9
__8:
	if !(Xsqlite3Config.FsharedCacheEnabled != 0) {
		goto __10
	}
	*(*uint32)(unsafe.Pointer(bp + 8)) |= uint32(SQLITE_OPEN_SHAREDCACHE)
__10:
	;
__9:
	;
	*(*uint32)(unsafe.Pointer(bp + 8)) &= libc.Uint32FromInt32(libc.CplInt32(SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_MAIN_DB | SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_TRANSIENT_DB | SQLITE_OPEN_MAIN_JOURNAL | SQLITE_OPEN_TEMP_JOURNAL | SQLITE_OPEN_SUBJOURNAL | SQLITE_OPEN_SUPER_JOURNAL | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_WAL))

	db = Xsqlite3MallocZero(tls, uint64(unsafe.Sizeof(Sqlite3{})))
	if !(db == uintptr(0)) {
		goto __11
	}
	goto opendb_out
__11:
	;
	if !(isThreadsafe != 0) {
		goto __12
	}
	(*Sqlite3)(unsafe.Pointer(db)).Fmutex = Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_RECURSIVE)
	if !((*Sqlite3)(unsafe.Pointer(db)).Fmutex == uintptr(0)) {
		goto __13
	}
	Xsqlite3_free(tls, db)
	db = uintptr(0)
	goto opendb_out
__13:
	;
	if !(isThreadsafe == 0) {
		goto __14
	}

__14:
	;
__12:
	;
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Sqlite3)(unsafe.Pointer(db)).FerrMask = func() int32 {
		if *(*uint32)(unsafe.Pointer(bp + 8))&uint32(SQLITE_OPEN_EXRESCODE) != uint32(0) {
			return libc.Int32FromUint32(0xffffffff)
		}
		return 0xff
	}()
	(*Sqlite3)(unsafe.Pointer(db)).FnDb = 2
	(*Sqlite3)(unsafe.Pointer(db)).FeOpenState = U8(SQLITE_STATE_BUSY)
	(*Sqlite3)(unsafe.Pointer(db)).FaDb = db + 696
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = U32(1)
	(*Sqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = U16(0)

	libc.Xmemcpy(tls, db+136, uintptr(unsafe.Pointer(&aHardLimit)), uint64(unsafe.Sizeof([12]int32{})))
	*(*int32)(unsafe.Pointer(db + 136 + 11*4)) = SQLITE_DEFAULT_WORKER_THREADS
	(*Sqlite3)(unsafe.Pointer(db)).FautoCommit = U8(1)
	(*Sqlite3)(unsafe.Pointer(db)).FnextAutovac = int8(-1)
	(*Sqlite3)(unsafe.Pointer(db)).FszMmap = Xsqlite3Config.FszMmap
	(*Sqlite3)(unsafe.Pointer(db)).FnextPagesize = 0
	(*Sqlite3)(unsafe.Pointer(db)).Finit.FazInit = uintptr(unsafe.Pointer(&Xsqlite3StdType))
	*(*U64)(unsafe.Pointer(db + 48)) |= uint64(uint32(SQLITE_ShortColNames|
		SQLITE_EnableTrigger) |
		SQLITE_EnableView |
		uint32(SQLITE_CacheSpill) |
		uint32(SQLITE_TrustedSchema) |
		uint32(SQLITE_DqsDML) |
		uint32(SQLITE_DqsDDL) |
		uint32(SQLITE_AutoIndex))
	Xsqlite3HashInit(tls, db+648)
	Xsqlite3HashInit(tls, db+576)

	createCollation(tls, db, uintptr(unsafe.Pointer(&Xsqlite3StrBINARY)), uint8(SQLITE_UTF8), uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
	}{binCollFunc})), uintptr(0))
	createCollation(tls, db, uintptr(unsafe.Pointer(&Xsqlite3StrBINARY)), uint8(SQLITE_UTF16BE), uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
	}{binCollFunc})), uintptr(0))
	createCollation(tls, db, uintptr(unsafe.Pointer(&Xsqlite3StrBINARY)), uint8(SQLITE_UTF16LE), uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
	}{binCollFunc})), uintptr(0))
	createCollation(tls, db, ts+26399, uint8(SQLITE_UTF8), uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
	}{nocaseCollatingFunc})), uintptr(0))
	createCollation(tls, db, ts+30638, uint8(SQLITE_UTF8), uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32
	}{rtrimCollFunc})), uintptr(0))
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __15
	}
	goto opendb_out
__15:
	;
	(*Sqlite3)(unsafe.Pointer(db)).FopenFlags = *(*uint32)(unsafe.Pointer(bp + 8))

	if !(int32(1)<<(*(*uint32)(unsafe.Pointer(bp + 8))&uint32(7))&0x46 == 0) {
		goto __16
	}
	rc = Xsqlite3MisuseError(tls, 177397)
	goto __17
__16:
	rc = Xsqlite3ParseUri(tls, zVfs, zFilename, bp+8, db, bp+16, bp+24)
__17:
	;
	if !(rc != SQLITE_OK) {
		goto __18
	}
	if !(rc == SQLITE_NOMEM) {
		goto __19
	}
	Xsqlite3OomFault(tls, db)
__19:
	;
	Xsqlite3ErrorWithMsg(tls, db, rc, func() uintptr {
		if *(*uintptr)(unsafe.Pointer(bp + 24)) != 0 {
			return ts + 1684
		}
		return uintptr(0)
	}(), libc.VaList(bp, *(*uintptr)(unsafe.Pointer(bp + 24))))
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
	goto opendb_out
__18:
	;
	rc = Xsqlite3BtreeOpen(tls, (*Sqlite3)(unsafe.Pointer(db)).FpVfs, *(*uintptr)(unsafe.Pointer(bp + 16)), db, (*Sqlite3)(unsafe.Pointer(db)).FaDb+8, 0,
		int32(*(*uint32)(unsafe.Pointer(bp + 8))|uint32(SQLITE_OPEN_MAIN_DB)))
	if !(rc != SQLITE_OK) {
		goto __20
	}
	if !(rc == SQLITE_IOERR|int32(12)<<8) {
		goto __21
	}
	rc = SQLITE_NOMEM
__21:
	;
	Xsqlite3Error(tls, db, rc)
	goto opendb_out
__20:
	;
	Xsqlite3BtreeEnter(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpBt)
	(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema = Xsqlite3SchemaGet(tls, db, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpBt)
	if !!(int32((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed) != 0) {
		goto __22
	}
	Xsqlite3SetTextEncoding(tls, db, (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema)).Fenc)
__22:
	;
	Xsqlite3BtreeLeave(tls, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpBt)
	(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + 1*32)).FpSchema = Xsqlite3SchemaGet(tls, db, uintptr(0))

	(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FzDbSName = ts + 9656
	(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).Fsafety_level = U8(SQLITE_DEFAULT_SYNCHRONOUS + 1)
	(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + 1*32)).FzDbSName = ts + 27930
	(*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + 1*32)).Fsafety_level = U8(PAGER_SYNCHRONOUS_OFF)

	(*Sqlite3)(unsafe.Pointer(db)).FeOpenState = U8(SQLITE_STATE_OPEN)
	if !((*Sqlite3)(unsafe.Pointer(db)).FmallocFailed != 0) {
		goto __23
	}
	goto opendb_out
__23:
	;
	Xsqlite3Error(tls, db, SQLITE_OK)
	Xsqlite3RegisterPerConnectionBuiltinFunctions(tls, db)
	rc = Xsqlite3_errcode(tls, db)

	i = 0
__24:
	if !(rc == SQLITE_OK && i < int32(uint64(unsafe.Sizeof(sqlite3BuiltinExtensions))/uint64(unsafe.Sizeof(uintptr(0))))) {
		goto __26
	}
	rc = (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{sqlite3BuiltinExtensions[i]})).f(tls, db)
	goto __25
__25:
	i++
	goto __24
	goto __26
__26:
	;
	if !(rc == SQLITE_OK) {
		goto __27
	}
	Xsqlite3AutoLoadExtensions(tls, db)
	rc = Xsqlite3_errcode(tls, db)
	if !(rc != SQLITE_OK) {
		goto __28
	}
	goto opendb_out
__28:
	;
__27:
	;
	if !(rc != 0) {
		goto __29
	}
	Xsqlite3Error(tls, db, rc)
__29:
	;
	setupLookaside(tls, db, uintptr(0), Xsqlite3Config.FszLookaside,
		Xsqlite3Config.FnLookaside)

	Xsqlite3_wal_autocheckpoint(tls, db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT)

opendb_out:
	if !(db != 0) {
		goto __30
	}

	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
__30:
	;
	rc = Xsqlite3_errcode(tls, db)

	if !(rc&0xff == SQLITE_NOMEM) {
		goto __31
	}
	Xsqlite3_close(tls, db)
	db = uintptr(0)
	goto __32
__31:
	if !(rc != SQLITE_OK) {
		goto __33
	}
	(*Sqlite3)(unsafe.Pointer(db)).FeOpenState = U8(SQLITE_STATE_SICK)
__33:
	;
__32:
	;
	*(*uintptr)(unsafe.Pointer(ppDb)) = db
	Xsqlite3_free_filename(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	return rc
}

func Xsqlite3_open(tls *libc.TLS, zFilename uintptr, ppDb uintptr) int32 {
	return openDatabase(tls, zFilename, ppDb,
		uint32(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE), uintptr(0))
}

func Xsqlite3_open_v2(tls *libc.TLS, filename uintptr, ppDb uintptr, flags int32, zVfs uintptr) int32 {
	return openDatabase(tls, filename, ppDb, uint32(flags), zVfs)
}

func Xsqlite3_open16(tls *libc.TLS, zFilename uintptr, ppDb uintptr) int32 {
	var zFilename8 uintptr
	var pVal uintptr
	var rc int32

	*(*uintptr)(unsafe.Pointer(ppDb)) = uintptr(0)
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	}
	if zFilename == uintptr(0) {
		zFilename = ts + 30644
	}
	pVal = Xsqlite3ValueNew(tls, uintptr(0))
	Xsqlite3ValueSetStr(tls, pVal, -1, zFilename, uint8(SQLITE_UTF16LE), uintptr(0))
	zFilename8 = Xsqlite3ValueText(tls, pVal, uint8(SQLITE_UTF8))
	if zFilename8 != 0 {
		rc = openDatabase(tls, zFilename8, ppDb,
			uint32(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE), uintptr(0))

		if rc == SQLITE_OK && !(int32((*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppDb)))).FaDb)).FpSchema)).FschemaFlags)&DB_SchemaLoaded == DB_SchemaLoaded) {
			(*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ppDb)))).FaDb)).FpSchema)).Fenc = libc.AssignPtrUint8(*(*uintptr)(unsafe.Pointer(ppDb))+100, U8(SQLITE_UTF16LE))
		}
	} else {
		rc = SQLITE_NOMEM
	}
	Xsqlite3ValueFree(tls, pVal)

	return rc & 0xff
}

func Xsqlite3_create_collation(tls *libc.TLS, db uintptr, zName uintptr, enc int32, pCtx uintptr, xCompare uintptr) int32 {
	return Xsqlite3_create_collation_v2(tls, db, zName, enc, pCtx, xCompare, uintptr(0))
}

func Xsqlite3_create_collation_v2(tls *libc.TLS, db uintptr, zName uintptr, enc int32, pCtx uintptr, xCompare uintptr, xDel uintptr) int32 {
	var rc int32

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)

	rc = createCollation(tls, db, zName, U8(enc), pCtx, xCompare, xDel)
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_create_collation16(tls *libc.TLS, db uintptr, zName uintptr, enc int32, pCtx uintptr, xCompare uintptr) int32 {
	var rc int32 = SQLITE_OK
	var zName8 uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)

	zName8 = Xsqlite3Utf16to8(tls, db, zName, -1, uint8(SQLITE_UTF16LE))
	if zName8 != 0 {
		rc = createCollation(tls, db, zName8, U8(enc), pCtx, xCompare, uintptr(0))
		Xsqlite3DbFree(tls, db, zName8)
	}
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_collation_needed(tls *libc.TLS, db uintptr, pCollNeededArg uintptr, xCollNeeded uintptr) int32 {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Sqlite3)(unsafe.Pointer(db)).FxCollNeeded = xCollNeeded
	(*Sqlite3)(unsafe.Pointer(db)).FxCollNeeded16 = uintptr(0)
	(*Sqlite3)(unsafe.Pointer(db)).FpCollNeededArg = pCollNeededArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

func Xsqlite3_collation_needed16(tls *libc.TLS, db uintptr, pCollNeededArg uintptr, xCollNeeded16 uintptr) int32 {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Sqlite3)(unsafe.Pointer(db)).FxCollNeeded = uintptr(0)
	(*Sqlite3)(unsafe.Pointer(db)).FxCollNeeded16 = xCollNeeded16
	(*Sqlite3)(unsafe.Pointer(db)).FpCollNeededArg = pCollNeededArg
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

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

func Xsqlite3_get_autocommit(tls *libc.TLS, db uintptr) int32 {
	return int32((*Sqlite3)(unsafe.Pointer(db)).FautoCommit)
}

func Xsqlite3ReportError(tls *libc.TLS, iErr int32, lineno int32, zType uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	Xsqlite3_log(tls, iErr, ts+30647,
		libc.VaList(bp, zType, lineno, uintptr(20)+Xsqlite3_sourceid(tls)))
	return iErr
}

func Xsqlite3CorruptError(tls *libc.TLS, lineno int32) int32 {
	return Xsqlite3ReportError(tls, SQLITE_CORRUPT, lineno, ts+30672)
}

func Xsqlite3MisuseError(tls *libc.TLS, lineno int32) int32 {
	return Xsqlite3ReportError(tls, SQLITE_MISUSE, lineno, ts+30692)
}

func Xsqlite3CantopenError(tls *libc.TLS, lineno int32) int32 {
	return Xsqlite3ReportError(tls, SQLITE_CANTOPEN, lineno, ts+30699)
}

func Xsqlite3_thread_cleanup(tls *libc.TLS) {
}

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) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var rc int32

	var pTab uintptr
	var pCol uintptr
	var iCol int32
	var zDataType uintptr
	var zCollSeq uintptr
	var notnull int32
	var primarykey int32
	var autoinc int32
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
	pTab = uintptr(0)
	pCol = uintptr(0)
	iCol = 0
	zDataType = uintptr(0)
	zCollSeq = uintptr(0)
	notnull = 0
	primarykey = 0
	autoinc = 0

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	Xsqlite3BtreeEnterAll(tls, db)
	rc = Xsqlite3Init(tls, db, bp+24)
	if !(SQLITE_OK != rc) {
		goto __1
	}
	goto error_out
__1:
	;
	pTab = Xsqlite3FindTable(tls, db, zTableName, zDbName)
	if !(!(pTab != 0) || int32((*Table)(unsafe.Pointer(pTab)).FeTabType) == TABTYP_VIEW) {
		goto __2
	}
	pTab = uintptr(0)
	goto error_out
__2:
	;
	if !(zColumnName == uintptr(0)) {
		goto __3
	}

	goto __4
__3:
	iCol = 0
__5:
	if !(iCol < int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __7
	}
	pCol = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24
	if !(0 == Xsqlite3StrICmp(tls, (*Column)(unsafe.Pointer(pCol)).FzCnName, zColumnName)) {
		goto __8
	}
	goto __7
__8:
	;
	goto __6
__6:
	iCol++
	goto __5
	goto __7
__7:
	;
	if !(iCol == int32((*Table)(unsafe.Pointer(pTab)).FnCol)) {
		goto __9
	}
	if !((*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_WithoutRowid) == U32(0) && Xsqlite3IsRowid(tls, zColumnName) != 0) {
		goto __10
	}
	iCol = int32((*Table)(unsafe.Pointer(pTab)).FiPKey)
	if iCol >= 0 {
		pCol = (*Table)(unsafe.Pointer(pTab)).FaCol + uintptr(iCol)*24
	} else {
		pCol = uintptr(0)
	}
	goto __11
__10:
	pTab = uintptr(0)
	goto error_out
__11:
	;
__9:
	;
__4:
	;
	if !(pCol != 0) {
		goto __12
	}
	zDataType = Xsqlite3ColumnType(tls, pCol, uintptr(0))
	zCollSeq = Xsqlite3ColumnColl(tls, pCol)
	notnull = libc.Bool32(int32(*(*uint8)(unsafe.Pointer(pCol + 8))&0xf>>0) != 0)
	primarykey = libc.Bool32(int32((*Column)(unsafe.Pointer(pCol)).FcolFlags)&COLFLAG_PRIMKEY != 0)
	autoinc = libc.Bool32(int32((*Table)(unsafe.Pointer(pTab)).FiPKey) == iCol && (*Table)(unsafe.Pointer(pTab)).FtabFlags&U32(TF_Autoincrement) != U32(0))
	goto __13
__12:
	zDataType = ts + 1201
	primarykey = 1
__13:
	;
	if !!(zCollSeq != 0) {
		goto __14
	}
	zCollSeq = uintptr(unsafe.Pointer(&Xsqlite3StrBINARY))
__14:
	;
error_out:
	Xsqlite3BtreeLeaveAll(tls, db)

	if !(pzDataType != 0) {
		goto __15
	}
	*(*uintptr)(unsafe.Pointer(pzDataType)) = zDataType
__15:
	;
	if !(pzCollSeq != 0) {
		goto __16
	}
	*(*uintptr)(unsafe.Pointer(pzCollSeq)) = zCollSeq
__16:
	;
	if !(pNotNull != 0) {
		goto __17
	}
	*(*int32)(unsafe.Pointer(pNotNull)) = notnull
__17:
	;
	if !(pPrimaryKey != 0) {
		goto __18
	}
	*(*int32)(unsafe.Pointer(pPrimaryKey)) = primarykey
__18:
	;
	if !(pAutoinc != 0) {
		goto __19
	}
	*(*int32)(unsafe.Pointer(pAutoinc)) = autoinc
__19:
	;
	if !(SQLITE_OK == rc && !(pTab != 0)) {
		goto __20
	}
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 24)))
	*(*uintptr)(unsafe.Pointer(bp + 24)) = Xsqlite3MPrintf(tls, db, ts+30716, libc.VaList(bp, zTableName,
		zColumnName))
	rc = SQLITE_ERROR
__20:
	;
	Xsqlite3ErrorWithMsg(tls, db, rc, func() uintptr {
		if *(*uintptr)(unsafe.Pointer(bp + 24)) != 0 {
			return ts + 1684
		}
		return uintptr(0)
	}(), libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp + 24))))
	Xsqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(bp + 24)))
	rc = Xsqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_sleep(tls *libc.TLS, ms int32) int32 {
	var pVfs uintptr
	var rc int32
	pVfs = Xsqlite3_vfs_find(tls, uintptr(0))
	if pVfs == uintptr(0) {
		return 0
	}

	rc = Xsqlite3OsSleep(tls, pVfs, 1000*ms) / 1000
	return rc
}

func Xsqlite3_extended_result_codes(tls *libc.TLS, db uintptr, onoff int32) int32 {
	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	(*Sqlite3)(unsafe.Pointer(db)).FerrMask = func() int32 {
		if onoff != 0 {
			return libc.Int32FromUint32(0xffffffff)
		}
		return 0xff
	}()
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

func Xsqlite3_file_control(tls *libc.TLS, db uintptr, zDbName uintptr, op int32, pArg uintptr) int32 {
	var rc int32 = SQLITE_ERROR
	var pBtree uintptr

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	pBtree = Xsqlite3DbNameToBtree(tls, db, zDbName)
	if pBtree != 0 {
		var pPager uintptr
		var fd uintptr
		Xsqlite3BtreeEnter(tls, pBtree)
		pPager = Xsqlite3BtreePager(tls, pBtree)

		fd = Xsqlite3PagerFile(tls, pPager)

		if op == SQLITE_FCNTL_FILE_POINTER {
			*(*uintptr)(unsafe.Pointer(pArg)) = fd
			rc = SQLITE_OK
		} else if op == SQLITE_FCNTL_VFS_POINTER {
			*(*uintptr)(unsafe.Pointer(pArg)) = Xsqlite3PagerVfs(tls, pPager)
			rc = SQLITE_OK
		} else if op == SQLITE_FCNTL_JOURNAL_POINTER {
			*(*uintptr)(unsafe.Pointer(pArg)) = Xsqlite3PagerJrnlFile(tls, pPager)
			rc = SQLITE_OK
		} else if op == SQLITE_FCNTL_DATA_VERSION {
			*(*uint32)(unsafe.Pointer(pArg)) = Xsqlite3PagerDataVersion(tls, pPager)
			rc = SQLITE_OK
		} else if op == SQLITE_FCNTL_RESERVE_BYTES {
			var iNew int32 = *(*int32)(unsafe.Pointer(pArg))
			*(*int32)(unsafe.Pointer(pArg)) = Xsqlite3BtreeGetRequestedReserve(tls, pBtree)
			if iNew >= 0 && iNew <= 255 {
				Xsqlite3BtreeSetPageSize(tls, pBtree, 0, iNew, 0)
			}
			rc = SQLITE_OK
		} else if op == SQLITE_FCNTL_RESET_CACHE {
			Xsqlite3BtreeClearCache(tls, pBtree)
			rc = SQLITE_OK
		} else {
			var nSave int32 = (*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy
			rc = Xsqlite3OsFileControl(tls, fd, op, pArg)
			(*Sqlite3)(unsafe.Pointer(db)).FbusyHandler.FnBusy = nSave
		}
		Xsqlite3BtreeLeave(tls, pBtree)
	}
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3_test_control(tls *libc.TLS, op int32, va uintptr) int32 {
	var rc int32 = 0
	var ap Va_list
	_ = ap
	ap = va
	switch op {
	case SQLITE_TESTCTRL_PRNG_SAVE:
		{
			Xsqlite3PrngSaveState(tls)
			break

		}

	case SQLITE_TESTCTRL_PRNG_RESTORE:
		{
			Xsqlite3PrngRestoreState(tls)
			break

		}

	case SQLITE_TESTCTRL_PRNG_SEED:
		{
			var x int32 = libc.VaInt32(&ap)
			var y int32
			var db uintptr = libc.VaUintptr(&ap)

			if db != 0 && libc.AssignInt32(&y, (*Schema)(unsafe.Pointer((*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb)).FpSchema)).Fschema_cookie) != 0 {
				x = y
			}
			Xsqlite3Config.FiPrngSeed = uint32(x)
			Xsqlite3_randomness(tls, 0, uintptr(0))
			break

		}

	case SQLITE_TESTCTRL_BITVEC_TEST:
		{
			var sz int32 = libc.VaInt32(&ap)
			var aProg uintptr = libc.VaUintptr(&ap)
			rc = Xsqlite3BitvecBuiltinTest(tls, sz, aProg)
			break

		}

	case SQLITE_TESTCTRL_FAULT_INSTALL:
		{
			Xsqlite3Config.FxTestCallback = libc.VaUintptr(&ap)
			rc = Xsqlite3FaultSim(tls, 0)
			break

		}

	case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
		{
			var xBenignBegin uintptr
			var xBenignEnd uintptr
			xBenignBegin = libc.VaUintptr(&ap)
			xBenignEnd = libc.VaUintptr(&ap)
			Xsqlite3BenignMallocHooks(tls, xBenignBegin, xBenignEnd)
			break

		}

	case SQLITE_TESTCTRL_PENDING_BYTE:
		{
			rc = Xsqlite3PendingByte
			{
				var newVal uint32 = libc.VaUint32(&ap)
				if newVal != 0 {
					Xsqlite3PendingByte = int32(newVal)
				}

			}
			break

		}

	case SQLITE_TESTCTRL_ASSERT:
		{
			var x int32 = 0

			rc = x
			break

		}

	case SQLITE_TESTCTRL_ALWAYS:
		{
			var x int32 = libc.VaInt32(&ap)
			if x != 0 {
				rc = x
			} else {
				rc = 0
			}
			break

		}

	case SQLITE_TESTCTRL_BYTEORDER:
		{
			rc = SQLITE_BYTEORDER*100 + SQLITE_LITTLEENDIAN*10 + SQLITE_BIGENDIAN
			break

		}

	case SQLITE_TESTCTRL_OPTIMIZATIONS:
		{
			var db uintptr = libc.VaUintptr(&ap)
			(*Sqlite3)(unsafe.Pointer(db)).FdbOptFlags = libc.VaUint32(&ap)
			break

		}

	case SQLITE_TESTCTRL_LOCALTIME_FAULT:
		{
			Xsqlite3Config.FbLocaltimeFault = libc.VaInt32(&ap)
			if Xsqlite3Config.FbLocaltimeFault == 2 {
				Xsqlite3Config.FxAltLocaltime = libc.VaUintptr(&ap)
			} else {
				Xsqlite3Config.FxAltLocaltime = uintptr(0)
			}
			break

		}

	case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
		{
			var db uintptr = libc.VaUintptr(&ap)
			*(*U32)(unsafe.Pointer(db + 44)) ^= U32(DBFLAG_InternalFunc)
			break

		}

	case SQLITE_TESTCTRL_NEVER_CORRUPT:
		{
			Xsqlite3Config.FneverCorrupt = libc.VaInt32(&ap)
			break

		}

	case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS:
		{
			Xsqlite3Config.FbExtraSchemaChecks = U8(libc.VaInt32(&ap))
			break

		}

	case SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD:
		{
			Xsqlite3Config.FiOnceResetThreshold = libc.VaInt32(&ap)
			break

		}

	case SQLITE_TESTCTRL_VDBE_COVERAGE:
		{
			break

		}

	case SQLITE_TESTCTRL_SORTER_MMAP:
		{
			var db uintptr = libc.VaUintptr(&ap)
			(*Sqlite3)(unsafe.Pointer(db)).FnMaxSorterMmap = libc.VaInt32(&ap)
			break

		}

	case SQLITE_TESTCTRL_ISINIT:
		{
			if Xsqlite3Config.FisInit == 0 {
				rc = SQLITE_ERROR
			}
			break

		}

	case SQLITE_TESTCTRL_IMPOSTER:
		{
			var db uintptr = libc.VaUintptr(&ap)
			var iDb int32
			Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
			iDb = Xsqlite3FindDbName(tls, db, libc.VaUintptr(&ap))
			if iDb >= 0 {
				(*Sqlite3)(unsafe.Pointer(db)).Finit.FiDb = U8(iDb)
				(*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy = U8(libc.AssignBitFieldPtr8Uint32(db+192+8, uint32(libc.VaInt32(&ap)), 1, 1, 0x2))
				(*Sqlite3)(unsafe.Pointer(db)).Finit.FnewTnum = Pgno(libc.VaInt32(&ap))
				if int32((*Sqlite3)(unsafe.Pointer(db)).Finit.Fbusy) == 0 && (*Sqlite3)(unsafe.Pointer(db)).Finit.FnewTnum > Pgno(0) {
					Xsqlite3ResetAllSchemasOfConnection(tls, db)
				}
			}
			Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
			break

		}

	case SQLITE_TESTCTRL_RESULT_INTREAL:
		{
			var pCtx uintptr = libc.VaUintptr(&ap)
			Xsqlite3ResultIntReal(tls, pCtx)
			break

		}

	case SQLITE_TESTCTRL_SEEK_COUNT:
		{
			var db uintptr = libc.VaUintptr(&ap)
			_ = db
			var pn uintptr = libc.VaUintptr(&ap)
			*(*U64)(unsafe.Pointer(pn)) = uint64(0)
			_ = db
			break

		}

	case SQLITE_TESTCTRL_TRACEFLAGS:
		{
			var opTrace int32 = libc.VaInt32(&ap)
			var ptr uintptr = libc.VaUintptr(&ap)
			switch opTrace {
			case 0:
				*(*U32)(unsafe.Pointer(ptr)) = Xsqlite3TreeTrace
				break
			case 1:
				Xsqlite3TreeTrace = *(*U32)(unsafe.Pointer(ptr))
				break
			case 2:
				*(*U32)(unsafe.Pointer(ptr)) = Xsqlite3WhereTrace
				break
			case 3:
				Xsqlite3WhereTrace = *(*U32)(unsafe.Pointer(ptr))
				break
			}
			break

		}

	case SQLITE_TESTCTRL_LOGEST:
		{
			var rIn float64 = libc.VaFloat64(&ap)
			var rLogEst LogEst = Xsqlite3LogEstFromDouble(tls, rIn)
			var pI1 uintptr = libc.VaUintptr(&ap)
			var pU64 uintptr = libc.VaUintptr(&ap)
			var pI2 uintptr = libc.VaUintptr(&ap)
			*(*int32)(unsafe.Pointer(pI1)) = int32(rLogEst)
			*(*U64)(unsafe.Pointer(pU64)) = Xsqlite3LogEstToInt(tls, rLogEst)
			*(*int32)(unsafe.Pointer(pI2)) = int32(Xsqlite3LogEst(tls, *(*U64)(unsafe.Pointer(pU64))))
			break

		}

	}
	_ = ap
	return rc
}

func databaseName(tls *libc.TLS, zName uintptr) uintptr {
	for int32(*(*uint8)(unsafe.Pointer(zName + libc.UintptrFromInt32(-1)))) != 0 || int32(*(*uint8)(unsafe.Pointer(zName + libc.UintptrFromInt32(-2)))) != 0 || int32(*(*uint8)(unsafe.Pointer(zName + libc.UintptrFromInt32(-3)))) != 0 || int32(*(*uint8)(unsafe.Pointer(zName + libc.UintptrFromInt32(-4)))) != 0 {
		zName--
	}
	return zName
}

func appendText(tls *libc.TLS, p uintptr, z uintptr) uintptr {
	var n Size_t = libc.Xstrlen(tls, z)
	libc.Xmemcpy(tls, p, z, n+uint64(1))
	return p + uintptr(n) + uintptr(1)
}

func Xsqlite3_create_filename(tls *libc.TLS, zDatabase uintptr, zJournal uintptr, zWal uintptr, nParam int32, azParam uintptr) uintptr {
	var nByte Sqlite3_int64
	var i int32
	var pResult uintptr
	var p uintptr
	nByte = Sqlite3_int64(libc.Xstrlen(tls, zDatabase) + libc.Xstrlen(tls, zJournal) + libc.Xstrlen(tls, zWal) + uint64(10))
	for i = 0; i < nParam*2; i++ {
		nByte = Sqlite3_int64(uint64(nByte) + (libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(azParam + uintptr(i)*8))) + uint64(1)))
	}
	pResult = libc.AssignUintptr(&p, Xsqlite3_malloc64(tls, uint64(nByte)))
	if p == uintptr(0) {
		return uintptr(0)
	}
	libc.Xmemset(tls, p, 0, uint64(4))
	p += uintptr(4)
	p = appendText(tls, p, zDatabase)
	for i = 0; i < nParam*2; i++ {
		p = appendText(tls, p, *(*uintptr)(unsafe.Pointer(azParam + uintptr(i)*8)))
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&p, 1))) = uint8(0)
	p = appendText(tls, p, zJournal)
	p = appendText(tls, p, zWal)
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&p, 1))) = uint8(0)
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&p, 1))) = uint8(0)

	return pResult + uintptr(4)
}

func Xsqlite3_free_filename(tls *libc.TLS, p uintptr) {
	if p == uintptr(0) {
		return
	}
	p = databaseName(tls, p)
	Xsqlite3_free(tls, p-uintptr(4))
}

func Xsqlite3_uri_parameter(tls *libc.TLS, zFilename uintptr, zParam uintptr) uintptr {
	if zFilename == uintptr(0) || zParam == uintptr(0) {
		return uintptr(0)
	}
	zFilename = databaseName(tls, zFilename)
	return uriParameter(tls, zFilename, zParam)
}

func Xsqlite3_uri_key(tls *libc.TLS, zFilename uintptr, N int32) uintptr {
	if zFilename == uintptr(0) || N < 0 {
		return uintptr(0)
	}
	zFilename = databaseName(tls, zFilename)
	zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
	for zFilename != 0 && *(*uint8)(unsafe.Pointer(zFilename)) != 0 && libc.PostDecInt32(&N, 1) > 0 {
		zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
		zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
	}
	if *(*uint8)(unsafe.Pointer(zFilename)) != 0 {
		return zFilename
	}
	return uintptr(0)
}

func Xsqlite3_uri_boolean(tls *libc.TLS, zFilename uintptr, zParam uintptr, bDflt int32) int32 {
	var z uintptr = Xsqlite3_uri_parameter(tls, zFilename, zParam)
	bDflt = libc.Bool32(bDflt != 0)
	if z != 0 {
		return int32(Xsqlite3GetBoolean(tls, z, uint8(bDflt)))
	}
	return bDflt
}

func Xsqlite3_uri_int64(tls *libc.TLS, zFilename uintptr, zParam uintptr, bDflt Sqlite3_int64) Sqlite3_int64 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var z uintptr = Xsqlite3_uri_parameter(tls, zFilename, zParam)

	if z != 0 && Xsqlite3DecOrHexToI64(tls, z, bp) == 0 {
		bDflt = *(*Sqlite3_int64)(unsafe.Pointer(bp))
	}
	return bDflt
}

func Xsqlite3_filename_database(tls *libc.TLS, zFilename uintptr) uintptr {
	if zFilename == uintptr(0) {
		return uintptr(0)
	}
	return databaseName(tls, zFilename)
}

func Xsqlite3_filename_journal(tls *libc.TLS, zFilename uintptr) uintptr {
	if zFilename == uintptr(0) {
		return uintptr(0)
	}
	zFilename = databaseName(tls, zFilename)
	zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
	for zFilename != 0 && *(*uint8)(unsafe.Pointer(zFilename)) != 0 {
		zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
		zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
	}
	return zFilename + uintptr(1)
}

func Xsqlite3_filename_wal(tls *libc.TLS, zFilename uintptr) uintptr {
	zFilename = Xsqlite3_filename_journal(tls, zFilename)
	if zFilename != 0 {
		zFilename += uintptr(Xsqlite3Strlen30(tls, zFilename) + 1)
	}
	return zFilename
}

func Xsqlite3DbNameToBtree(tls *libc.TLS, db uintptr, zDbName uintptr) uintptr {
	var iDb int32
	if zDbName != 0 {
		iDb = Xsqlite3FindDbName(tls, db, zDbName)
	} else {
		iDb = 0
	}
	if iDb < 0 {
		return uintptr(0)
	}
	return (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*32)).FpBt
}

func Xsqlite3_db_name(tls *libc.TLS, db uintptr, N int32) uintptr {
	if N < 0 || N >= (*Sqlite3)(unsafe.Pointer(db)).FnDb {
		return uintptr(0)
	} else {
		return (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(N)*32)).FzDbSName
	}
	return uintptr(0)
}

func Xsqlite3_db_filename(tls *libc.TLS, db uintptr, zDbName uintptr) uintptr {
	var pBt uintptr
	pBt = Xsqlite3DbNameToBtree(tls, db, zDbName)
	if pBt != 0 {
		return Xsqlite3BtreeGetFilename(tls, pBt)
	}
	return uintptr(0)
}

func Xsqlite3_db_readonly(tls *libc.TLS, db uintptr, zDbName uintptr) int32 {
	var pBt uintptr
	pBt = Xsqlite3DbNameToBtree(tls, db, zDbName)
	if pBt != 0 {
		return Xsqlite3BtreeIsReadonly(tls, pBt)
	}
	return -1
}

func Xsqlite3_compileoption_used(tls *libc.TLS, zOptName uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var i int32
	var n int32

	var azCompileOpt uintptr

	azCompileOpt = Xsqlite3CompileOptions(tls, bp)

	if Xsqlite3_strnicmp(tls, zOptName, ts+30744, 7) == 0 {
		zOptName += uintptr(7)
	}
	n = Xsqlite3Strlen30(tls, zOptName)

	for i = 0; i < *(*int32)(unsafe.Pointer(bp)); i++ {
		if Xsqlite3_strnicmp(tls, zOptName, *(*uintptr)(unsafe.Pointer(azCompileOpt + uintptr(i)*8)), n) == 0 &&
			Xsqlite3IsIdChar(tls, *(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(azCompileOpt + uintptr(i)*8)) + uintptr(n)))) == 0 {
			return 1
		}
	}
	return 0
}

func Xsqlite3_compileoption_get(tls *libc.TLS, N int32) uintptr {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var azCompileOpt uintptr
	azCompileOpt = Xsqlite3CompileOptions(tls, bp)
	if N >= 0 && N < *(*int32)(unsafe.Pointer(bp)) {
		return *(*uintptr)(unsafe.Pointer(azCompileOpt + uintptr(N)*8))
	}
	return uintptr(0)
}

var sqlite3BlockedList uintptr = uintptr(0)

func removeFromBlockedList(tls *libc.TLS, db uintptr) {
	var pp uintptr

	for pp = uintptr(unsafe.Pointer(&sqlite3BlockedList)); *(*uintptr)(unsafe.Pointer(pp)) != 0; pp = *(*uintptr)(unsafe.Pointer(pp)) + 840 {
		if *(*uintptr)(unsafe.Pointer(pp)) == db {
			*(*uintptr)(unsafe.Pointer(pp)) = (*Sqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNextBlocked
			break
		}
	}
}

func addToBlockedList(tls *libc.TLS, db uintptr) {
	var pp uintptr

	for pp = uintptr(unsafe.Pointer(&sqlite3BlockedList)); *(*uintptr)(unsafe.Pointer(pp)) != 0 && (*Sqlite3)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FxUnlockNotify != (*Sqlite3)(unsafe.Pointer(db)).FxUnlockNotify; pp = *(*uintptr)(unsafe.Pointer(pp)) + 840 {
	}
	(*Sqlite3)(unsafe.Pointer(db)).FpNextBlocked = *(*uintptr)(unsafe.Pointer(pp))
	*(*uintptr)(unsafe.Pointer(pp)) = db
}

func enterMutex(tls *libc.TLS) {
	Xsqlite3_mutex_enter(tls, Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN))

}

func leaveMutex(tls *libc.TLS) {
	Xsqlite3_mutex_leave(tls, Xsqlite3MutexAlloc(tls, SQLITE_MUTEX_STATIC_MAIN))
}

func Xsqlite3_unlock_notify(tls *libc.TLS, db uintptr, xNotify uintptr, pArg uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*uintptr)(unsafe.Pointer(bp)) = pArg

	var rc int32 = SQLITE_OK

	Xsqlite3_mutex_enter(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	enterMutex(tls)

	if xNotify == uintptr(0) {
		removeFromBlockedList(tls, db)
		(*Sqlite3)(unsafe.Pointer(db)).FpBlockingConnection = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).FpUnlockConnection = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).FxUnlockNotify = uintptr(0)
		(*Sqlite3)(unsafe.Pointer(db)).FpUnlockArg = uintptr(0)
	} else if uintptr(0) == (*Sqlite3)(unsafe.Pointer(db)).FpBlockingConnection {
		(*struct {
			f func(*libc.TLS, uintptr, int32)
		})(unsafe.Pointer(&struct{ uintptr }{xNotify})).f(tls, bp, 1)
	} else {
		var p uintptr

		for p = (*Sqlite3)(unsafe.Pointer(db)).FpBlockingConnection; p != 0 && p != db; p = (*Sqlite3)(unsafe.Pointer(p)).FpUnlockConnection {
		}
		if p != 0 {
			rc = SQLITE_LOCKED
		} else {
			(*Sqlite3)(unsafe.Pointer(db)).FpUnlockConnection = (*Sqlite3)(unsafe.Pointer(db)).FpBlockingConnection
			(*Sqlite3)(unsafe.Pointer(db)).FxUnlockNotify = xNotify
			(*Sqlite3)(unsafe.Pointer(db)).FpUnlockArg = *(*uintptr)(unsafe.Pointer(bp))
			removeFromBlockedList(tls, db)
			addToBlockedList(tls, db)
		}
	}

	leaveMutex(tls)

	Xsqlite3ErrorWithMsg(tls, db, rc, func() uintptr {
		if rc != 0 {
			return ts + 30752
		}
		return uintptr(0)
	}(), 0)
	Xsqlite3_mutex_leave(tls, (*Sqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

func Xsqlite3ConnectionBlocked(tls *libc.TLS, db uintptr, pBlocker uintptr) {
	enterMutex(tls)
	if (*Sqlite3)(unsafe.Pointer(db)).FpBlockingConnection == uintptr(0) && (*Sqlite3)(unsafe.Pointer(db)).FpUnlockConnection == uintptr(0) {
		addToBlockedList(tls, db)
	}
	(*Sqlite3)(unsafe.Pointer(db)).FpBlockingConnection = pBlocker
	leaveMutex(tls)
}

func Xsqlite3ConnectionUnlocked(tls *libc.TLS, db uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	var xUnlockNotify uintptr = uintptr(0)
	var nArg int32 = 0
	var pp uintptr
	var aArg uintptr
	var aDyn uintptr = uintptr(0)

	aArg = bp
	enterMutex(tls)

	for pp = uintptr(unsafe.Pointer(&sqlite3BlockedList)); *(*uintptr)(unsafe.Pointer(pp)) != 0; {
		var p uintptr = *(*uintptr)(unsafe.Pointer(pp))

		if (*Sqlite3)(unsafe.Pointer(p)).FpBlockingConnection == db {
			(*Sqlite3)(unsafe.Pointer(p)).FpBlockingConnection = uintptr(0)
		}

		if (*Sqlite3)(unsafe.Pointer(p)).FpUnlockConnection == db {
			if (*Sqlite3)(unsafe.Pointer(p)).FxUnlockNotify != xUnlockNotify && nArg != 0 {
				(*struct {
					f func(*libc.TLS, uintptr, int32)
				})(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})).f(tls, aArg, nArg)
				nArg = 0
			}

			Xsqlite3BeginBenignMalloc(tls)

			if !(aDyn != 0) && nArg == int32(uint64(unsafe.Sizeof([16]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0)))) ||
				aDyn != 0 && nArg == int32(uint64(Xsqlite3MallocSize(tls, aDyn))/uint64(unsafe.Sizeof(uintptr(0)))) {
				var pNew uintptr = Xsqlite3Malloc(tls, uint64(nArg)*uint64(unsafe.Sizeof(uintptr(0)))*uint64(2))
				if pNew != 0 {
					libc.Xmemcpy(tls, pNew, aArg, uint64(nArg)*uint64(unsafe.Sizeof(uintptr(0))))
					Xsqlite3_free(tls, aDyn)
					aDyn = libc.AssignUintptr(&aArg, pNew)
				} else {
					(*struct {
						f func(*libc.TLS, uintptr, int32)
					})(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})).f(tls, aArg, nArg)
					nArg = 0
				}
			}
			Xsqlite3EndBenignMalloc(tls)

			*(*uintptr)(unsafe.Pointer(aArg + uintptr(libc.PostIncInt32(&nArg, 1))*8)) = (*Sqlite3)(unsafe.Pointer(p)).FpUnlockArg
			xUnlockNotify = (*Sqlite3)(unsafe.Pointer(p)).FxUnlockNotify
			(*Sqlite3)(unsafe.Pointer(p)).FpUnlockConnection = uintptr(0)
			(*Sqlite3)(unsafe.Pointer(p)).FxUnlockNotify = uintptr(0)
			(*Sqlite3)(unsafe.Pointer(p)).FpUnlockArg = uintptr(0)
		}

		if (*Sqlite3)(unsafe.Pointer(p)).FpBlockingConnection == uintptr(0) && (*Sqlite3)(unsafe.Pointer(p)).FpUnlockConnection == uintptr(0) {
			*(*uintptr)(unsafe.Pointer(pp)) = (*Sqlite3)(unsafe.Pointer(p)).FpNextBlocked
			(*Sqlite3)(unsafe.Pointer(p)).FpNextBlocked = uintptr(0)
		} else {
			pp = p + 840
		}
	}

	if nArg != 0 {
		(*struct {
			f func(*libc.TLS, uintptr, int32)
		})(unsafe.Pointer(&struct{ uintptr }{xUnlockNotify})).f(tls, aArg, nArg)
	}
	Xsqlite3_free(tls, aDyn)
	leaveMutex(tls)
}

func Xsqlite3ConnectionClosed(tls *libc.TLS, db uintptr) {
	Xsqlite3ConnectionUnlocked(tls, db)
	enterMutex(tls)
	removeFromBlockedList(tls, db)

	leaveMutex(tls)
}

var jsonIsSpace = [256]uint8{
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(1), uint8(1), uint8(0), uint8(0), uint8(1), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(1), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
}

type JsonString1 = struct {
	FpCtx        uintptr
	FzBuf        uintptr
	FnAlloc      U64
	FnUsed       U64
	FbStatic     U8
	FbErr        U8
	FzSpace      [100]uint8
	F__ccgo_pad1 [2]byte
}

type JsonString = JsonString1
type JsonNode1 = struct {
	FeType       U8
	FjnFlags     U8
	FeU          U8
	F__ccgo_pad1 [1]byte
	Fn           U32
	Fu           struct{ FzJContent uintptr }
}

type JsonNode = JsonNode1
type JsonParse1 = struct {
	FnNode       U32
	FnAlloc      U32
	FaNode       uintptr
	FzJson       uintptr
	FaUp         uintptr
	Foom         U8
	FnErr        U8
	FiDepth      U16
	FnJson       int32
	FiHold       U32
	F__ccgo_pad1 [4]byte
}

type JsonParse = JsonParse1

var jsonType = [8]uintptr{
	ts + 9106, ts + 10909, ts + 10914, ts + 9116, ts + 9111, ts + 11353, ts + 30775, ts + 30781,
}

func jsonZero(tls *libc.TLS, p uintptr) {
	(*JsonString)(unsafe.Pointer(p)).FzBuf = p + 34
	(*JsonString)(unsafe.Pointer(p)).FnAlloc = U64(unsafe.Sizeof([100]uint8{}))
	(*JsonString)(unsafe.Pointer(p)).FnUsed = uint64(0)
	(*JsonString)(unsafe.Pointer(p)).FbStatic = U8(1)
}

func jsonInit(tls *libc.TLS, p uintptr, pCtx uintptr) {
	(*JsonString)(unsafe.Pointer(p)).FpCtx = pCtx
	(*JsonString)(unsafe.Pointer(p)).FbErr = U8(0)
	jsonZero(tls, p)
}

func jsonReset(tls *libc.TLS, p uintptr) {
	if !(int32((*JsonString)(unsafe.Pointer(p)).FbStatic) != 0) {
		Xsqlite3_free(tls, (*JsonString)(unsafe.Pointer(p)).FzBuf)
	}
	jsonZero(tls, p)
}

func jsonOom(tls *libc.TLS, p uintptr) {
	(*JsonString)(unsafe.Pointer(p)).FbErr = U8(1)
	Xsqlite3_result_error_nomem(tls, (*JsonString)(unsafe.Pointer(p)).FpCtx)
	jsonReset(tls, p)
}

func jsonGrow(tls *libc.TLS, p uintptr, N U32) int32 {
	var nTotal U64
	if U64(N) < (*JsonString)(unsafe.Pointer(p)).FnAlloc {
		nTotal = (*JsonString)(unsafe.Pointer(p)).FnAlloc * uint64(2)
	} else {
		nTotal = (*JsonString)(unsafe.Pointer(p)).FnAlloc + U64(N) + uint64(10)
	}
	var zNew uintptr
	if (*JsonString)(unsafe.Pointer(p)).FbStatic != 0 {
		if (*JsonString)(unsafe.Pointer(p)).FbErr != 0 {
			return 1
		}
		zNew = Xsqlite3_malloc64(tls, nTotal)
		if zNew == uintptr(0) {
			jsonOom(tls, p)
			return SQLITE_NOMEM
		}
		libc.Xmemcpy(tls, zNew, (*JsonString)(unsafe.Pointer(p)).FzBuf, (*JsonString)(unsafe.Pointer(p)).FnUsed)
		(*JsonString)(unsafe.Pointer(p)).FzBuf = zNew
		(*JsonString)(unsafe.Pointer(p)).FbStatic = U8(0)
	} else {
		zNew = Xsqlite3_realloc64(tls, (*JsonString)(unsafe.Pointer(p)).FzBuf, nTotal)
		if zNew == uintptr(0) {
			jsonOom(tls, p)
			return SQLITE_NOMEM
		}
		(*JsonString)(unsafe.Pointer(p)).FzBuf = zNew
	}
	(*JsonString)(unsafe.Pointer(p)).FnAlloc = nTotal
	return SQLITE_OK
}

func jsonAppendRaw(tls *libc.TLS, p uintptr, zIn uintptr, N U32) {
	if N == U32(0) {
		return
	}
	if U64(N)+(*JsonString)(unsafe.Pointer(p)).FnUsed >= (*JsonString)(unsafe.Pointer(p)).FnAlloc && jsonGrow(tls, p, N) != 0 {
		return
	}
	libc.Xmemcpy(tls, (*JsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*JsonString)(unsafe.Pointer(p)).FnUsed), zIn, uint64(N))
	*(*U64)(unsafe.Pointer(p + 24)) += U64(N)
}

func jsonPrintf(tls *libc.TLS, N int32, p uintptr, zFormat uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	if (*JsonString)(unsafe.Pointer(p)).FnUsed+U64(N) >= (*JsonString)(unsafe.Pointer(p)).FnAlloc && jsonGrow(tls, p, uint32(N)) != 0 {
		return
	}
	ap = va
	Xsqlite3_vsnprintf(tls, N, (*JsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*JsonString)(unsafe.Pointer(p)).FnUsed), zFormat, ap)
	_ = ap
	*(*U64)(unsafe.Pointer(p + 24)) += U64(int32(libc.Xstrlen(tls, (*JsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*JsonString)(unsafe.Pointer(p)).FnUsed))))
}

func jsonAppendChar(tls *libc.TLS, p uintptr, c uint8) {
	if (*JsonString)(unsafe.Pointer(p)).FnUsed >= (*JsonString)(unsafe.Pointer(p)).FnAlloc && jsonGrow(tls, p, uint32(1)) != 0 {
		return
	}
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = c
}

func jsonAppendSeparator(tls *libc.TLS, p uintptr) {
	var c uint8
	if (*JsonString)(unsafe.Pointer(p)).FnUsed == uint64(0) {
		return
	}
	c = *(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr((*JsonString)(unsafe.Pointer(p)).FnUsed-uint64(1))))
	if int32(c) != '[' && int32(c) != '{' {
		jsonAppendChar(tls, p, uint8(','))
	}
}

func jsonAppendString(tls *libc.TLS, p uintptr, zIn uintptr, N U32) {
	var i U32
	var c uint8
	if !(zIn == uintptr(0) || U64(N)+(*JsonString)(unsafe.Pointer(p)).FnUsed+uint64(2) >= (*JsonString)(unsafe.Pointer(p)).FnAlloc && jsonGrow(tls, p, N+U32(2)) != 0) {
		goto __1
	}
	return
__1:
	;
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = uint8('"')
	i = U32(0)
__2:
	if !(i < N) {
		goto __4
	}
	c = *(*uint8)(unsafe.Pointer(zIn + uintptr(i)))
	if !(int32(c) == '"' || int32(c) == '\\') {
		goto __5
	}
json_simple_escape:
	if !((*JsonString)(unsafe.Pointer(p)).FnUsed+U64(N)+uint64(3)-U64(i) > (*JsonString)(unsafe.Pointer(p)).FnAlloc && jsonGrow(tls, p, N+U32(3)-i) != 0) {
		goto __7
	}
	return
__7:
	;
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = uint8('\\')
	goto __6
__5:
	if !(int32(c) <= 0x1f) {
		goto __8
	}

	if !(aSpecial[c] != 0) {
		goto __9
	}
	c = aSpecial[c]
	goto json_simple_escape
__9:
	;
	if !((*JsonString)(unsafe.Pointer(p)).FnUsed+U64(N)+uint64(7)+U64(i) > (*JsonString)(unsafe.Pointer(p)).FnAlloc && jsonGrow(tls, p, N+U32(7)-i) != 0) {
		goto __10
	}
	return
__10:
	;
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = uint8('\\')
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = uint8('u')
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = uint8('0')
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = uint8('0')
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = uint8('0' + int32(c)>>4)
	c = *(*uint8)(unsafe.Pointer(ts + 30788 + uintptr(int32(c)&0xf)))
__8:
	;
__6:
	;
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = c
	goto __3
__3:
	i++
	goto __2
	goto __4
__4:
	;
	*(*uint8)(unsafe.Pointer((*JsonString)(unsafe.Pointer(p)).FzBuf + uintptr(libc.PostIncUint64(&(*JsonString)(unsafe.Pointer(p)).FnUsed, 1)))) = uint8('"')

}

var aSpecial = [32]uint8{
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8('b'), uint8('t'), uint8('n'), uint8(0), uint8('f'), uint8('r'), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
}

func jsonAppendValue(tls *libc.TLS, p uintptr, pValue uintptr) {
	switch Xsqlite3_value_type(tls, pValue) {
	case SQLITE_NULL:
		{
			jsonAppendRaw(tls, p, ts+9106, uint32(4))
			break

		}
	case SQLITE_INTEGER:
		fallthrough
	case SQLITE_FLOAT:
		{
			var z uintptr = Xsqlite3_value_text(tls, pValue)
			var n U32 = U32(Xsqlite3_value_bytes(tls, pValue))
			jsonAppendRaw(tls, p, z, n)
			break

		}
	case SQLITE_TEXT:
		{
			var z uintptr = Xsqlite3_value_text(tls, pValue)
			var n U32 = U32(Xsqlite3_value_bytes(tls, pValue))
			if Xsqlite3_value_subtype(tls, pValue) == uint32(JSON_SUBTYPE) {
				jsonAppendRaw(tls, p, z, n)
			} else {
				jsonAppendString(tls, p, z, n)
			}
			break

		}
	default:
		{
			if int32((*JsonString)(unsafe.Pointer(p)).FbErr) == 0 {
				Xsqlite3_result_error(tls, (*JsonString)(unsafe.Pointer(p)).FpCtx, ts+30805, -1)
				(*JsonString)(unsafe.Pointer(p)).FbErr = U8(2)
				jsonReset(tls, p)
			}
			break

		}
	}
}

func jsonResult(tls *libc.TLS, p uintptr) {
	if int32((*JsonString)(unsafe.Pointer(p)).FbErr) == 0 {
		Xsqlite3_result_text64(tls, (*JsonString)(unsafe.Pointer(p)).FpCtx, (*JsonString)(unsafe.Pointer(p)).FzBuf, (*JsonString)(unsafe.Pointer(p)).FnUsed,
			func() uintptr {
				if (*JsonString)(unsafe.Pointer(p)).FbStatic != 0 {
					return libc.UintptrFromInt32(-1)
				}
				return *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free}))
			}(),
			uint8(SQLITE_UTF8))
		jsonZero(tls, p)
	}

}

func jsonNodeSize(tls *libc.TLS, pNode uintptr) U32 {
	if int32((*JsonNode)(unsafe.Pointer(pNode)).FeType) >= JSON_ARRAY {
		return (*JsonNode)(unsafe.Pointer(pNode)).Fn + U32(1)
	}
	return uint32(1)
}

func jsonParseReset(tls *libc.TLS, pParse uintptr) {
	Xsqlite3_free(tls, (*JsonParse)(unsafe.Pointer(pParse)).FaNode)
	(*JsonParse)(unsafe.Pointer(pParse)).FaNode = uintptr(0)
	(*JsonParse)(unsafe.Pointer(pParse)).FnNode = U32(0)
	(*JsonParse)(unsafe.Pointer(pParse)).FnAlloc = U32(0)
	Xsqlite3_free(tls, (*JsonParse)(unsafe.Pointer(pParse)).FaUp)
	(*JsonParse)(unsafe.Pointer(pParse)).FaUp = uintptr(0)
}

func jsonParseFree(tls *libc.TLS, pParse uintptr) {
	jsonParseReset(tls, pParse)
	Xsqlite3_free(tls, pParse)
}

func jsonRenderNode(tls *libc.TLS, pNode uintptr, pOut uintptr, aReplace uintptr) {
	if int32((*JsonNode)(unsafe.Pointer(pNode)).FjnFlags)&(JNODE_REPLACE|JNODE_PATCH) != 0 {
		if int32((*JsonNode)(unsafe.Pointer(pNode)).FjnFlags)&JNODE_REPLACE != 0 && aReplace != uintptr(0) {
			jsonAppendValue(tls, pOut, *(*uintptr)(unsafe.Pointer(aReplace + uintptr(*(*U32)(unsafe.Pointer(pNode + 8)))*8)))
			return
		}

		pNode = *(*uintptr)(unsafe.Pointer(pNode + 8))
	}
	switch int32((*JsonNode)(unsafe.Pointer(pNode)).FeType) {
	default:
		{
			jsonAppendRaw(tls, pOut, ts+9106, uint32(4))
			break

		}
	case JSON_TRUE:
		{
			jsonAppendRaw(tls, pOut, ts+10909, uint32(4))
			break

		}
	case JSON_FALSE:
		{
			jsonAppendRaw(tls, pOut, ts+10914, uint32(5))
			break

		}
	case JSON_STRING:
		{
			if int32((*JsonNode)(unsafe.Pointer(pNode)).FjnFlags)&JNODE_RAW != 0 {
				jsonAppendString(tls, pOut, *(*uintptr)(unsafe.Pointer(pNode + 8)), (*JsonNode)(unsafe.Pointer(pNode)).Fn)
				break
			}

		}
		fallthrough
	case JSON_REAL:
		fallthrough
	case JSON_INT:
		{
			jsonAppendRaw(tls, pOut, *(*uintptr)(unsafe.Pointer(pNode + 8)), (*JsonNode)(unsafe.Pointer(pNode)).Fn)
			break

		}
	case JSON_ARRAY:
		{
			var j U32 = U32(1)
			jsonAppendChar(tls, pOut, uint8('['))
			for {
				for j <= (*JsonNode)(unsafe.Pointer(pNode)).Fn {
					if int32((*JsonNode)(unsafe.Pointer(pNode+uintptr(j)*16)).FjnFlags)&JNODE_REMOVE == 0 {
						jsonAppendSeparator(tls, pOut)
						jsonRenderNode(tls, pNode+uintptr(j)*16, pOut, aReplace)
					}
					j = j + jsonNodeSize(tls, pNode+uintptr(j)*16)
				}
				if int32((*JsonNode)(unsafe.Pointer(pNode)).FjnFlags)&JNODE_APPEND == 0 {
					break
				}

				pNode = pNode + uintptr(*(*U32)(unsafe.Pointer(pNode + 8)))*16
				j = U32(1)
			}
			jsonAppendChar(tls, pOut, uint8(']'))
			break

		}
	case JSON_OBJECT:
		{
			var j U32 = U32(1)
			jsonAppendChar(tls, pOut, uint8('{'))
			for {
				for j <= (*JsonNode)(unsafe.Pointer(pNode)).Fn {
					if int32((*JsonNode)(unsafe.Pointer(pNode+uintptr(j+U32(1))*16)).FjnFlags)&JNODE_REMOVE == 0 {
						jsonAppendSeparator(tls, pOut)
						jsonRenderNode(tls, pNode+uintptr(j)*16, pOut, aReplace)
						jsonAppendChar(tls, pOut, uint8(':'))
						jsonRenderNode(tls, pNode+uintptr(j+U32(1))*16, pOut, aReplace)
					}
					j = j + (U32(1) + jsonNodeSize(tls, pNode+uintptr(j+U32(1))*16))
				}
				if int32((*JsonNode)(unsafe.Pointer(pNode)).FjnFlags)&JNODE_APPEND == 0 {
					break
				}

				pNode = pNode + uintptr(*(*U32)(unsafe.Pointer(pNode + 8)))*16
				j = U32(1)
			}
			jsonAppendChar(tls, pOut, uint8('}'))
			break

		}
	}
}

func jsonReturnJson(tls *libc.TLS, pNode uintptr, pCtx uintptr, aReplace uintptr) {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	jsonInit(tls, bp, pCtx)
	jsonRenderNode(tls, pNode, bp, aReplace)
	jsonResult(tls, bp)
	Xsqlite3_result_subtype(tls, pCtx, uint32(JSON_SUBTYPE))
}

func jsonHexToInt(tls *libc.TLS, h int32) U8 {
	h = h + 9*(1&(h>>6))
	return U8(h & 0xf)
}

func jsonHexToInt4(tls *libc.TLS, z uintptr) U32 {
	var v U32

	v = U32(int32(jsonHexToInt(tls, int32(*(*uint8)(unsafe.Pointer(z)))))<<12 +
		int32(jsonHexToInt(tls, int32(*(*uint8)(unsafe.Pointer(z + 1)))))<<8 +
		int32(jsonHexToInt(tls, int32(*(*uint8)(unsafe.Pointer(z + 2)))))<<4 +
		int32(jsonHexToInt(tls, int32(*(*uint8)(unsafe.Pointer(z + 3))))))
	return v
}

func jsonReturn(tls *libc.TLS, pNode uintptr, pCtx uintptr, aReplace uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var v uint32
	var i Sqlite3_int64
	var z uintptr

	var z1 uintptr
	var vlo U32
	var v1 U32
	var c uint8

	var i1 U32
	var n U32
	var z2 uintptr
	var zOut uintptr
	var j U32
	switch int32((*JsonNode)(unsafe.Pointer(pNode)).FeType) {
	default:
		goto __2
	case JSON_TRUE:
		goto __3
	case JSON_FALSE:
		goto __4
	case JSON_INT:
		goto __5
	case JSON_REAL:
		goto __6
	case JSON_STRING:
		goto __7
	case JSON_ARRAY:
		goto __8
	case JSON_OBJECT:
		goto __9
	}
	goto __1
__2:
	;
	Xsqlite3_result_null(tls, pCtx)
	goto __1

__3:
	Xsqlite3_result_int(tls, pCtx, 1)
	goto __1

__4:
	Xsqlite3_result_int(tls, pCtx, 0)
	goto __1

__5:
	i = int64(0)

	z = *(*uintptr)(unsafe.Pointer(pNode + 8))
	if !(int32(*(*uint8)(unsafe.Pointer(z))) == '-') {
		goto __10
	}
	z++
__10:
	;
__11:
	if !(int32(*(*uint8)(unsafe.Pointer(z))) >= '0' && int32(*(*uint8)(unsafe.Pointer(z))) <= '9') {
		goto __12
	}
	v = uint32(int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1)))) - '0')
	if !(i >= (int64(0xffffffff)|int64(0x7fffffff)<<32)/int64(10)) {
		goto __13
	}
	if !(i > (int64(0xffffffff)|int64(0x7fffffff)<<32)/int64(10)) {
		goto __14
	}
	goto int_as_real
__14:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(z))) >= '0' && int32(*(*uint8)(unsafe.Pointer(z))) <= '9') {
		goto __15
	}
	goto int_as_real
__15:
	;
	if !(v == uint32(9)) {
		goto __16
	}
	goto int_as_real
__16:
	;
	if !(v == uint32(8)) {
		goto __17
	}
	if !(int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 8))))) == '-') {
		goto __18
	}
	Xsqlite3_result_int64(tls, pCtx, int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32))
	goto int_done
	goto __19
__18:
	goto int_as_real
__19:
	;
__17:
	;
__13:
	;
	i = i*int64(10) + Sqlite3_int64(v)
	goto __11
__12:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 8))))) == '-') {
		goto __20
	}
	i = -i
__20:
	;
	Xsqlite3_result_int64(tls, pCtx, i)
int_done:
	goto __1
int_as_real:
	;
__6:
	;
	z1 = *(*uintptr)(unsafe.Pointer(pNode + 8))
	Xsqlite3AtoF(tls, z1, bp, Xsqlite3Strlen30(tls, z1), uint8(SQLITE_UTF8))
	Xsqlite3_result_double(tls, pCtx, *(*float64)(unsafe.Pointer(bp)))
	goto __1

__7:
	;
	if !(int32((*JsonNode)(unsafe.Pointer(pNode)).FjnFlags)&JNODE_ESCAPE == 0) {
		goto __21
	}

	Xsqlite3_result_text(tls, pCtx, *(*uintptr)(unsafe.Pointer(pNode + 8))+uintptr(1), int32((*JsonNode)(unsafe.Pointer(pNode)).Fn-U32(2)),
		libc.UintptrFromInt32(-1))
	goto __22
__21:
	n = (*JsonNode)(unsafe.Pointer(pNode)).Fn

	z2 = *(*uintptr)(unsafe.Pointer(pNode + 8))
	zOut = Xsqlite3_malloc(tls, int32(n+U32(1)))
	if !(zOut == uintptr(0)) {
		goto __23
	}
	Xsqlite3_result_error_nomem(tls, pCtx)
	goto __1
__23:
	;
	i1 = U32(1)
	j = U32(0)
__24:
	if !(i1 < n-U32(1)) {
		goto __26
	}
	c = *(*uint8)(unsafe.Pointer(z2 + uintptr(i1)))
	if !(int32(c) != '\\') {
		goto __27
	}
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = c
	goto __28
__27:
	c = *(*uint8)(unsafe.Pointer(z2 + uintptr(libc.PreIncUint32(&i1, 1))))
	if !(int32(c) == 'u') {
		goto __29
	}
	v1 = jsonHexToInt4(tls, z2+uintptr(i1)+uintptr(1))
	i1 = i1 + U32(4)
	if !(v1 == U32(0)) {
		goto __31
	}
	goto __26
__31:
	;
	if !(v1 <= U32(0x7f)) {
		goto __32
	}
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(v1)
	goto __33
__32:
	if !(v1 <= U32(0x7ff)) {
		goto __34
	}
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0xc0) | v1>>6)
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0x80) | v1&U32(0x3f))
	goto __35
__34:
	if !(v1&U32(0xfc00) == U32(0xd800) &&
		i1 < n-U32(6) &&
		int32(*(*uint8)(unsafe.Pointer(z2 + uintptr(i1+U32(1))))) == '\\' &&
		int32(*(*uint8)(unsafe.Pointer(z2 + uintptr(i1+U32(2))))) == 'u' &&
		libc.AssignUint32(&vlo, jsonHexToInt4(tls, z2+uintptr(i1)+uintptr(3)))&U32(0xfc00) == U32(0xdc00)) {
		goto __36
	}

	v1 = v1&U32(0x3ff)<<10 + vlo&U32(0x3ff) + U32(0x10000)
	i1 = i1 + U32(6)
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0xf0) | v1>>18)
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0x80) | v1>>12&U32(0x3f))
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0x80) | v1>>6&U32(0x3f))
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0x80) | v1&U32(0x3f))
	goto __37
__36:
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0xe0) | v1>>12)
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0x80) | v1>>6&U32(0x3f))
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = uint8(U32(0x80) | v1&U32(0x3f))
__37:
	;
__35:
	;
__33:
	;
	goto __30
__29:
	if !(int32(c) == 'b') {
		goto __38
	}
	c = uint8('\b')
	goto __39
__38:
	if !(int32(c) == 'f') {
		goto __40
	}
	c = uint8('\f')
	goto __41
__40:
	if !(int32(c) == 'n') {
		goto __42
	}
	c = uint8('\n')
	goto __43
__42:
	if !(int32(c) == 'r') {
		goto __44
	}
	c = uint8('\r')
	goto __45
__44:
	if !(int32(c) == 't') {
		goto __46
	}
	c = uint8('\t')
__46:
	;
__45:
	;
__43:
	;
__41:
	;
__39:
	;
	*(*uint8)(unsafe.Pointer(zOut + uintptr(libc.PostIncUint32(&j, 1)))) = c
__30:
	;
__28:
	;
	goto __25
__25:
	i1++
	goto __24
	goto __26
__26:
	;
	*(*uint8)(unsafe.Pointer(zOut + uintptr(j))) = uint8(0)
	Xsqlite3_result_text(tls, pCtx, zOut, int32(j), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
__22:
	;
	goto __1

__8:
__9:
	jsonReturnJson(tls, pNode, pCtx, aReplace)
	goto __1

__1:
}

func jsonParseAddNodeExpand(tls *libc.TLS, pParse uintptr, eType U32, n U32, zContent uintptr) int32 {
	var nNew U32
	var pNew uintptr

	if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		return -1
	}
	nNew = (*JsonParse)(unsafe.Pointer(pParse)).FnAlloc*U32(2) + U32(10)
	pNew = Xsqlite3_realloc64(tls, (*JsonParse)(unsafe.Pointer(pParse)).FaNode, uint64(unsafe.Sizeof(JsonNode{}))*uint64(nNew))
	if pNew == uintptr(0) {
		(*JsonParse)(unsafe.Pointer(pParse)).Foom = U8(1)
		return -1
	}
	(*JsonParse)(unsafe.Pointer(pParse)).FnAlloc = nNew
	(*JsonParse)(unsafe.Pointer(pParse)).FaNode = pNew

	return jsonParseAddNode(tls, pParse, eType, n, zContent)
}

func jsonParseAddNode(tls *libc.TLS, pParse uintptr, eType U32, n U32, zContent uintptr) int32 {
	var p uintptr
	if (*JsonParse)(unsafe.Pointer(pParse)).FaNode == uintptr(0) || (*JsonParse)(unsafe.Pointer(pParse)).FnNode >= (*JsonParse)(unsafe.Pointer(pParse)).FnAlloc {
		return jsonParseAddNodeExpand(tls, pParse, eType, n, zContent)
	}
	p = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr((*JsonParse)(unsafe.Pointer(pParse)).FnNode)*16
	(*JsonNode)(unsafe.Pointer(p)).FeType = U8(eType)
	(*JsonNode)(unsafe.Pointer(p)).FjnFlags = U8(0)

	(*JsonNode)(unsafe.Pointer(p)).Fn = n
	*(*uintptr)(unsafe.Pointer(p + 8)) = zContent
	return int32(libc.PostIncUint32(&(*JsonParse)(unsafe.Pointer(pParse)).FnNode, 1))
}

func jsonIs4Hex(tls *libc.TLS, z uintptr) int32 {
	var i int32
	for i = 0; i < 4; i++ {
		if !(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i)))])&0x08 != 0) {
			return 0
		}
	}
	return 1
}

func jsonParseValue(tls *libc.TLS, pParse uintptr, i U32) int32 {
	var c uint8
	var j U32
	var iThis int32
	var x int32
	var pNode uintptr
	var z uintptr = (*JsonParse)(unsafe.Pointer(pParse)).FzJson
	for jsonIsSpace[*(*uint8)(unsafe.Pointer(z + uintptr(i)))] != 0 {
		i++
	}
	if int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(z + uintptr(i))))) == '{' {
		iThis = jsonParseAddNode(tls, pParse, uint32(JSON_OBJECT), uint32(0), uintptr(0))
		if iThis < 0 {
			return -1
		}
		for j = i + U32(1); ; j++ {
			for jsonIsSpace[*(*uint8)(unsafe.Pointer(z + uintptr(j)))] != 0 {
				j++
			}
			if int32(libc.PreIncUint16(&(*JsonParse)(unsafe.Pointer(pParse)).FiDepth, 1)) > JSON_MAX_DEPTH {
				return -1
			}
			x = jsonParseValue(tls, pParse, j)
			if x < 0 {
				(*JsonParse)(unsafe.Pointer(pParse)).FiDepth--
				if x == -2 && (*JsonParse)(unsafe.Pointer(pParse)).FnNode == U32(iThis)+U32(1) {
					return int32(j + U32(1))
				}
				return -1
			}
			if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
				return -1
			}
			pNode = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr((*JsonParse)(unsafe.Pointer(pParse)).FnNode-U32(1))*16
			if int32((*JsonNode)(unsafe.Pointer(pNode)).FeType) != JSON_STRING {
				return -1
			}
			*(*U8)(unsafe.Pointer(pNode + 1)) |= U8(JNODE_LABEL)
			j = U32(x)
			for jsonIsSpace[*(*uint8)(unsafe.Pointer(z + uintptr(j)))] != 0 {
				j++
			}
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j)))) != ':' {
				return -1
			}
			j++
			x = jsonParseValue(tls, pParse, j)
			(*JsonParse)(unsafe.Pointer(pParse)).FiDepth--
			if x < 0 {
				return -1
			}
			j = U32(x)
			for jsonIsSpace[*(*uint8)(unsafe.Pointer(z + uintptr(j)))] != 0 {
				j++
			}
			c = *(*uint8)(unsafe.Pointer(z + uintptr(j)))
			if int32(c) == ',' {
				continue
			}
			if int32(c) != '}' {
				return -1
			}
			break
		}
		(*JsonNode)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iThis)*16)).Fn = (*JsonParse)(unsafe.Pointer(pParse)).FnNode - U32(iThis) - U32(1)
		return int32(j + U32(1))
	} else if int32(c) == '[' {
		iThis = jsonParseAddNode(tls, pParse, uint32(JSON_ARRAY), uint32(0), uintptr(0))
		if iThis < 0 {
			return -1
		}
		libc.Xmemset(tls, (*JsonParse)(unsafe.Pointer(pParse)).FaNode+uintptr(iThis)*16+8, 0, uint64(unsafe.Sizeof(struct{ FzJContent uintptr }{})))
		for j = i + U32(1); ; j++ {
			for jsonIsSpace[*(*uint8)(unsafe.Pointer(z + uintptr(j)))] != 0 {
				j++
			}
			if int32(libc.PreIncUint16(&(*JsonParse)(unsafe.Pointer(pParse)).FiDepth, 1)) > JSON_MAX_DEPTH {
				return -1
			}
			x = jsonParseValue(tls, pParse, j)
			(*JsonParse)(unsafe.Pointer(pParse)).FiDepth--
			if x < 0 {
				if x == -3 && (*JsonParse)(unsafe.Pointer(pParse)).FnNode == U32(iThis)+U32(1) {
					return int32(j + U32(1))
				}
				return -1
			}
			j = U32(x)
			for jsonIsSpace[*(*uint8)(unsafe.Pointer(z + uintptr(j)))] != 0 {
				j++
			}
			c = *(*uint8)(unsafe.Pointer(z + uintptr(j)))
			if int32(c) == ',' {
				continue
			}
			if int32(c) != ']' {
				return -1
			}
			break
		}
		(*JsonNode)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iThis)*16)).Fn = (*JsonParse)(unsafe.Pointer(pParse)).FnNode - U32(iThis) - U32(1)
		return int32(j + U32(1))
	} else if int32(c) == '"' {
		var jnFlags U8 = U8(0)
		j = i + U32(1)
		for {
			c = *(*uint8)(unsafe.Pointer(z + uintptr(j)))
			if int32(c)&libc.CplInt32(0x1f) == 0 {
				return -1
			}
			if int32(c) == '\\' {
				c = *(*uint8)(unsafe.Pointer(z + uintptr(libc.PreIncUint32(&j, 1))))
				if int32(c) == '"' || int32(c) == '\\' || int32(c) == '/' || int32(c) == 'b' || int32(c) == 'f' ||
					int32(c) == 'n' || int32(c) == 'r' || int32(c) == 't' ||
					int32(c) == 'u' && jsonIs4Hex(tls, z+uintptr(j)+uintptr(1)) != 0 {
					jnFlags = U8(JNODE_ESCAPE)
				} else {
					return -1
				}
			} else if int32(c) == '"' {
				break
			}
			j++
		}
		jsonParseAddNode(tls, pParse, uint32(JSON_STRING), j+U32(1)-i, z+uintptr(i))
		if !(int32((*JsonParse)(unsafe.Pointer(pParse)).Foom) != 0) {
			(*JsonNode)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr((*JsonParse)(unsafe.Pointer(pParse)).FnNode-U32(1))*16)).FjnFlags = jnFlags
		}
		return int32(j + U32(1))
	} else if int32(c) == 'n' &&
		libc.Xstrncmp(tls, z+uintptr(i), ts+9106, uint64(4)) == 0 &&
		!(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i+U32(4))))])&0x06 != 0) {
		jsonParseAddNode(tls, pParse, uint32(JSON_NULL), uint32(0), uintptr(0))
		return int32(i + U32(4))
	} else if int32(c) == 't' &&
		libc.Xstrncmp(tls, z+uintptr(i), ts+10909, uint64(4)) == 0 &&
		!(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i+U32(4))))])&0x06 != 0) {
		jsonParseAddNode(tls, pParse, uint32(JSON_TRUE), uint32(0), uintptr(0))
		return int32(i + U32(4))
	} else if int32(c) == 'f' &&
		libc.Xstrncmp(tls, z+uintptr(i), ts+10914, uint64(5)) == 0 &&
		!(int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(i+U32(5))))])&0x06 != 0) {
		jsonParseAddNode(tls, pParse, uint32(JSON_FALSE), uint32(0), uintptr(0))
		return int32(i + U32(5))
	} else if int32(c) == '-' || int32(c) >= '0' && int32(c) <= '9' {
		var seenDP U8 = U8(0)
		var seenE U8 = U8(0)

		if int32(c) <= '0' {
			if int32(c) == '-' {
				j = i + U32(1)
			} else {
				j = i
			}
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j)))) == '0' && int32(*(*uint8)(unsafe.Pointer(z + uintptr(j+U32(1))))) >= '0' && int32(*(*uint8)(unsafe.Pointer(z + uintptr(j+U32(1))))) <= '9' {
				return -1
			}
		}
		j = i + U32(1)
		for ; ; j++ {
			c = *(*uint8)(unsafe.Pointer(z + uintptr(j)))
			if int32(c) >= '0' && int32(c) <= '9' {
				continue
			}
			if int32(c) == '.' {
				if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-U32(1))))) == '-' {
					return -1
				}
				if seenDP != 0 {
					return -1
				}
				seenDP = U8(1)
				continue
			}
			if int32(c) == 'e' || int32(c) == 'E' {
				if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-U32(1))))) < '0' {
					return -1
				}
				if seenE != 0 {
					return -1
				}
				seenDP = libc.AssignUint8(&seenE, U8(1))
				c = *(*uint8)(unsafe.Pointer(z + uintptr(j+U32(1))))
				if int32(c) == '+' || int32(c) == '-' {
					j++
					c = *(*uint8)(unsafe.Pointer(z + uintptr(j+U32(1))))
				}
				if int32(c) < '0' || int32(c) > '9' {
					return -1
				}
				continue
			}
			break
		}
		if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-U32(1))))) < '0' {
			return -1
		}
		jsonParseAddNode(tls, pParse, func() uint32 {
			if seenDP != 0 {
				return uint32(JSON_REAL)
			}
			return uint32(JSON_INT)
		}(),
			j-i, z+uintptr(i))
		return int32(j)
	} else if int32(c) == '}' {
		return -2
	} else if int32(c) == ']' {
		return -3
	} else if int32(c) == 0 {
		return 0
	} else {
		return -1
	}
	return int32(0)
}

func jsonParse(tls *libc.TLS, pParse uintptr, pCtx uintptr, zJson uintptr) int32 {
	var i int32
	libc.Xmemset(tls, pParse, 0, uint64(unsafe.Sizeof(JsonParse{})))
	if zJson == uintptr(0) {
		return 1
	}
	(*JsonParse)(unsafe.Pointer(pParse)).FzJson = zJson
	i = jsonParseValue(tls, pParse, uint32(0))
	if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		i = -1
	}
	if i > 0 {
		for jsonIsSpace[*(*uint8)(unsafe.Pointer(zJson + uintptr(i)))] != 0 {
			i++
		}
		if *(*uint8)(unsafe.Pointer(zJson + uintptr(i))) != 0 {
			i = -1
		}
	}
	if i <= 0 {
		if pCtx != uintptr(0) {
			if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
				Xsqlite3_result_error_nomem(tls, pCtx)
			} else {
				Xsqlite3_result_error(tls, pCtx, ts+30834, -1)
			}
		}
		jsonParseReset(tls, pParse)
		return 1
	}
	return 0
}

func jsonParseFillInParentage(tls *libc.TLS, pParse uintptr, i U32, iParent U32) {
	var pNode uintptr = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(i)*16
	var j U32
	*(*U32)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaUp + uintptr(i)*4)) = iParent
	switch int32((*JsonNode)(unsafe.Pointer(pNode)).FeType) {
	case JSON_ARRAY:
		{
			for j = U32(1); j <= (*JsonNode)(unsafe.Pointer(pNode)).Fn; j = j + jsonNodeSize(tls, pNode+uintptr(j)*16) {
				jsonParseFillInParentage(tls, pParse, i+j, i)
			}
			break

		}
	case JSON_OBJECT:
		{
			for j = U32(1); j <= (*JsonNode)(unsafe.Pointer(pNode)).Fn; j = j + (jsonNodeSize(tls, pNode+uintptr(j)*16+uintptr(1)*16) + U32(1)) {
				*(*U32)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaUp + uintptr(i+j)*4)) = i
				jsonParseFillInParentage(tls, pParse, i+j+U32(1), i)
			}
			break

		}
	default:
		{
			break

		}
	}
}

func jsonParseFindParents(tls *libc.TLS, pParse uintptr) int32 {
	var aUp uintptr

	aUp = libc.AssignPtrUintptr(pParse+24, Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(U32(0)))*uint64((*JsonParse)(unsafe.Pointer(pParse)).FnNode)))
	if aUp == uintptr(0) {
		(*JsonParse)(unsafe.Pointer(pParse)).Foom = U8(1)
		return SQLITE_NOMEM
	}
	jsonParseFillInParentage(tls, pParse, uint32(0), uint32(0))
	return SQLITE_OK
}

func jsonParseCached(tls *libc.TLS, pCtx uintptr, argv uintptr, pErrCtx uintptr) uintptr {
	var zJson uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	var nJson int32 = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv)))
	var p uintptr
	var pMatch uintptr = uintptr(0)
	var iKey int32
	var iMinKey int32 = 0
	var iMinHold U32 = 0xffffffff
	var iMaxHold U32 = U32(0)
	if zJson == uintptr(0) {
		return uintptr(0)
	}
	for iKey = 0; iKey < JSON_CACHE_SZ; iKey++ {
		p = Xsqlite3_get_auxdata(tls, pCtx, -429938+iKey)
		if p == uintptr(0) {
			iMinKey = iKey
			break
		}
		if pMatch == uintptr(0) &&
			(*JsonParse)(unsafe.Pointer(p)).FnJson == nJson &&
			libc.Xmemcmp(tls, (*JsonParse)(unsafe.Pointer(p)).FzJson, zJson, uint64(nJson)) == 0 {
			(*JsonParse)(unsafe.Pointer(p)).FnErr = U8(0)
			pMatch = p
		} else if (*JsonParse)(unsafe.Pointer(p)).FiHold < iMinHold {
			iMinHold = (*JsonParse)(unsafe.Pointer(p)).FiHold
			iMinKey = iKey
		}
		if (*JsonParse)(unsafe.Pointer(p)).FiHold > iMaxHold {
			iMaxHold = (*JsonParse)(unsafe.Pointer(p)).FiHold
		}
	}
	if pMatch != 0 {
		(*JsonParse)(unsafe.Pointer(pMatch)).FnErr = U8(0)
		(*JsonParse)(unsafe.Pointer(pMatch)).FiHold = iMaxHold + U32(1)
		return pMatch
	}
	p = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(JsonParse{}))+uint64(nJson)+uint64(1))
	if p == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, pCtx)
		return uintptr(0)
	}
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(JsonParse{})))
	(*JsonParse)(unsafe.Pointer(p)).FzJson = p + 1*48
	libc.Xmemcpy(tls, (*JsonParse)(unsafe.Pointer(p)).FzJson, zJson, uint64(nJson+1))
	if jsonParse(tls, p, pErrCtx, (*JsonParse)(unsafe.Pointer(p)).FzJson) != 0 {
		Xsqlite3_free(tls, p)
		return uintptr(0)
	}
	(*JsonParse)(unsafe.Pointer(p)).FnJson = nJson
	(*JsonParse)(unsafe.Pointer(p)).FiHold = iMaxHold + U32(1)
	Xsqlite3_set_auxdata(tls, pCtx, -429938+iMinKey, p,
		*(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{jsonParseFree})))
	return Xsqlite3_get_auxdata(tls, pCtx, -429938+iMinKey)
}

func jsonLabelCompare(tls *libc.TLS, pNode uintptr, zKey uintptr, nKey U32) int32 {
	if int32((*JsonNode)(unsafe.Pointer(pNode)).FjnFlags)&JNODE_RAW != 0 {
		if (*JsonNode)(unsafe.Pointer(pNode)).Fn != nKey {
			return 0
		}
		return libc.Bool32(libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(pNode + 8)), zKey, uint64(nKey)) == 0)
	} else {
		if (*JsonNode)(unsafe.Pointer(pNode)).Fn != nKey+U32(2) {
			return 0
		}
		return libc.Bool32(libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(pNode + 8))+uintptr(1), zKey, uint64(nKey)) == 0)
	}
	return int32(0)
}

func jsonLookupStep(tls *libc.TLS, pParse uintptr, iRoot U32, zPath uintptr, pApnd uintptr, pzErr uintptr) uintptr {
	var i U32
	var j U32
	var nKey U32
	var zKey uintptr
	var pRoot uintptr = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iRoot)*16
	if int32(*(*uint8)(unsafe.Pointer(zPath))) == 0 {
		return pRoot
	}
	if int32((*JsonNode)(unsafe.Pointer(pRoot)).FjnFlags)&JNODE_REPLACE != 0 {
		return uintptr(0)
	}
	if int32(*(*uint8)(unsafe.Pointer(zPath))) == '.' {
		if int32((*JsonNode)(unsafe.Pointer(pRoot)).FeType) != JSON_OBJECT {
			return uintptr(0)
		}
		zPath++
		if int32(*(*uint8)(unsafe.Pointer(zPath))) == '"' {
			zKey = zPath + uintptr(1)
			for i = U32(1); *(*uint8)(unsafe.Pointer(zPath + uintptr(i))) != 0 && int32(*(*uint8)(unsafe.Pointer(zPath + uintptr(i)))) != '"'; i++ {
			}
			nKey = i - U32(1)
			if *(*uint8)(unsafe.Pointer(zPath + uintptr(i))) != 0 {
				i++
			} else {
				*(*uintptr)(unsafe.Pointer(pzErr)) = zPath
				return uintptr(0)
			}

		} else {
			zKey = zPath
			for i = U32(0); *(*uint8)(unsafe.Pointer(zPath + uintptr(i))) != 0 && int32(*(*uint8)(unsafe.Pointer(zPath + uintptr(i)))) != '.' && int32(*(*uint8)(unsafe.Pointer(zPath + uintptr(i)))) != '['; i++ {
			}
			nKey = i
			if nKey == U32(0) {
				*(*uintptr)(unsafe.Pointer(pzErr)) = zPath
				return uintptr(0)
			}
		}
		j = U32(1)
		for {
			for j <= (*JsonNode)(unsafe.Pointer(pRoot)).Fn {
				if jsonLabelCompare(tls, pRoot+uintptr(j)*16, zKey, nKey) != 0 {
					return jsonLookupStep(tls, pParse, iRoot+j+U32(1), zPath+uintptr(i), pApnd, pzErr)
				}
				j++
				j = j + jsonNodeSize(tls, pRoot+uintptr(j)*16)
			}
			if int32((*JsonNode)(unsafe.Pointer(pRoot)).FjnFlags)&JNODE_APPEND == 0 {
				break
			}

			iRoot = iRoot + *(*U32)(unsafe.Pointer(pRoot + 8))
			pRoot = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iRoot)*16
			j = U32(1)
		}
		if pApnd != 0 {
			var iStart U32
			var iLabel U32
			var pNode uintptr
			iStart = U32(jsonParseAddNode(tls, pParse, uint32(JSON_OBJECT), uint32(2), uintptr(0)))
			iLabel = U32(jsonParseAddNode(tls, pParse, uint32(JSON_STRING), nKey, zKey))
			zPath += uintptr(i)
			pNode = jsonLookupAppend(tls, pParse, zPath, pApnd, pzErr)
			if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
				return uintptr(0)
			}
			if pNode != 0 {
				pRoot = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iRoot)*16

				*(*U32)(unsafe.Pointer(pRoot + 8)) = iStart - iRoot
				*(*U8)(unsafe.Pointer(pRoot + 1)) |= U8(JNODE_APPEND)

				*(*U8)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iLabel)*16 + 1)) |= U8(JNODE_RAW)
			}
			return pNode
		}
	} else if int32(*(*uint8)(unsafe.Pointer(zPath))) == '[' {
		i = U32(0)
		j = U32(1)
		for int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zPath + uintptr(j)))])&0x04 != 0 {
			i = i*U32(10) + U32(*(*uint8)(unsafe.Pointer(zPath + uintptr(j)))) - U32('0')
			j++
		}
		if j < U32(2) || int32(*(*uint8)(unsafe.Pointer(zPath + uintptr(j)))) != ']' {
			if int32(*(*uint8)(unsafe.Pointer(zPath + 1))) == '#' {
				var pBase uintptr = pRoot
				var iBase int32 = int32(iRoot)
				if int32((*JsonNode)(unsafe.Pointer(pRoot)).FeType) != JSON_ARRAY {
					return uintptr(0)
				}
				for {
					for j <= (*JsonNode)(unsafe.Pointer(pBase)).Fn {
						if int32((*JsonNode)(unsafe.Pointer(pBase+uintptr(j)*16)).FjnFlags)&JNODE_REMOVE == 0 {
							i++
						}
						j = j + jsonNodeSize(tls, pBase+uintptr(j)*16)
					}
					if int32((*JsonNode)(unsafe.Pointer(pBase)).FjnFlags)&JNODE_APPEND == 0 {
						break
					}

					iBase = int32(U32(iBase) + *(*U32)(unsafe.Pointer(pBase + 8)))
					pBase = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iBase)*16
					j = U32(1)
				}
				j = U32(2)
				if int32(*(*uint8)(unsafe.Pointer(zPath + 2))) == '-' && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zPath + 3))])&0x04 != 0 {
					var x uint32 = uint32(0)
					j = U32(3)
					for __ccgo := true; __ccgo; __ccgo = int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zPath + uintptr(j)))])&0x04 != 0 {
						x = x*uint32(10) + uint32(*(*uint8)(unsafe.Pointer(zPath + uintptr(j)))) - uint32('0')
						j++
					}
					if x > i {
						return uintptr(0)
					}
					i = i - x
				}
				if int32(*(*uint8)(unsafe.Pointer(zPath + uintptr(j)))) != ']' {
					*(*uintptr)(unsafe.Pointer(pzErr)) = zPath
					return uintptr(0)
				}
			} else {
				*(*uintptr)(unsafe.Pointer(pzErr)) = zPath
				return uintptr(0)
			}
		}
		if int32((*JsonNode)(unsafe.Pointer(pRoot)).FeType) != JSON_ARRAY {
			return uintptr(0)
		}
		zPath += uintptr(j + U32(1))
		j = U32(1)
		for {
			for j <= (*JsonNode)(unsafe.Pointer(pRoot)).Fn && (i > U32(0) || int32((*JsonNode)(unsafe.Pointer(pRoot+uintptr(j)*16)).FjnFlags)&JNODE_REMOVE != 0) {
				if int32((*JsonNode)(unsafe.Pointer(pRoot+uintptr(j)*16)).FjnFlags)&JNODE_REMOVE == 0 {
					i--
				}
				j = j + jsonNodeSize(tls, pRoot+uintptr(j)*16)
			}
			if int32((*JsonNode)(unsafe.Pointer(pRoot)).FjnFlags)&JNODE_APPEND == 0 {
				break
			}

			iRoot = iRoot + *(*U32)(unsafe.Pointer(pRoot + 8))
			pRoot = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iRoot)*16
			j = U32(1)
		}
		if j <= (*JsonNode)(unsafe.Pointer(pRoot)).Fn {
			return jsonLookupStep(tls, pParse, iRoot+j, zPath, pApnd, pzErr)
		}
		if i == U32(0) && pApnd != 0 {
			var iStart U32
			var pNode uintptr
			iStart = U32(jsonParseAddNode(tls, pParse, uint32(JSON_ARRAY), uint32(1), uintptr(0)))
			pNode = jsonLookupAppend(tls, pParse, zPath, pApnd, pzErr)
			if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
				return uintptr(0)
			}
			if pNode != 0 {
				pRoot = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iRoot)*16

				*(*U32)(unsafe.Pointer(pRoot + 8)) = iStart - iRoot
				*(*U8)(unsafe.Pointer(pRoot + 1)) |= U8(JNODE_APPEND)

			}
			return pNode
		}
	} else {
		*(*uintptr)(unsafe.Pointer(pzErr)) = zPath
	}
	return uintptr(0)
}

func jsonLookupAppend(tls *libc.TLS, pParse uintptr, zPath uintptr, pApnd uintptr, pzErr uintptr) uintptr {
	*(*int32)(unsafe.Pointer(pApnd)) = 1
	if int32(*(*uint8)(unsafe.Pointer(zPath))) == 0 {
		jsonParseAddNode(tls, pParse, uint32(JSON_NULL), uint32(0), uintptr(0))
		if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
			return uintptr(0)
		}
		return (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr((*JsonParse)(unsafe.Pointer(pParse)).FnNode-U32(1))*16
	}
	if int32(*(*uint8)(unsafe.Pointer(zPath))) == '.' {
		jsonParseAddNode(tls, pParse, uint32(JSON_OBJECT), uint32(0), uintptr(0))
	} else if libc.Xstrncmp(tls, zPath, ts+30849, uint64(3)) == 0 {
		jsonParseAddNode(tls, pParse, uint32(JSON_ARRAY), uint32(0), uintptr(0))
	} else {
		return uintptr(0)
	}
	if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		return uintptr(0)
	}
	return jsonLookupStep(tls, pParse, (*JsonParse)(unsafe.Pointer(pParse)).FnNode-U32(1), zPath, pApnd, pzErr)
}

func jsonPathSyntaxError(tls *libc.TLS, zErr uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	return Xsqlite3_mprintf(tls, ts+30853, libc.VaList(bp, zErr))
}

func jsonLookup(tls *libc.TLS, pParse uintptr, zPath uintptr, pApnd uintptr, pCtx uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pNode uintptr
	var zMsg uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	pNode = uintptr(0)

	if !(zPath == uintptr(0)) {
		goto __1
	}
	return uintptr(0)
__1:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(zPath))) != '$') {
		goto __2
	}
	*(*uintptr)(unsafe.Pointer(bp)) = zPath
	goto lookup_err
__2:
	;
	zPath++
	pNode = jsonLookupStep(tls, pParse, uint32(0), zPath, pApnd, bp)
	if !(*(*uintptr)(unsafe.Pointer(bp)) == uintptr(0)) {
		goto __3
	}
	return pNode
__3:
	;
lookup_err:
	(*JsonParse)(unsafe.Pointer(pParse)).FnErr++

	zMsg = jsonPathSyntaxError(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if !(zMsg != 0) {
		goto __4
	}
	Xsqlite3_result_error(tls, pCtx, zMsg, -1)
	Xsqlite3_free(tls, zMsg)
	goto __5
__4:
	Xsqlite3_result_error_nomem(tls, pCtx)
__5:
	;
	return uintptr(0)
}

func jsonWrongNumArgs(tls *libc.TLS, pCtx uintptr, zFuncName uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var zMsg uintptr = Xsqlite3_mprintf(tls, ts+30879,
		libc.VaList(bp, zFuncName))
	Xsqlite3_result_error(tls, pCtx, zMsg, -1)
	Xsqlite3_free(tls, zMsg)
}

func jsonRemoveAllNulls(tls *libc.TLS, pNode uintptr) {
	var i int32
	var n int32

	n = int32((*JsonNode)(unsafe.Pointer(pNode)).Fn)
	for i = 2; i <= n; i = int32(U32(i) + (jsonNodeSize(tls, pNode+uintptr(i)*16) + U32(1))) {
		switch int32((*JsonNode)(unsafe.Pointer(pNode + uintptr(i)*16)).FeType) {
		case JSON_NULL:
			*(*U8)(unsafe.Pointer(pNode + uintptr(i)*16 + 1)) |= U8(JNODE_REMOVE)
			break
		case JSON_OBJECT:
			jsonRemoveAllNulls(tls, pNode+uintptr(i)*16)
			break
		}
	}
}

func jsonQuoteFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	_ = argc

	jsonInit(tls, bp, ctx)
	jsonAppendValue(tls, bp, *(*uintptr)(unsafe.Pointer(argv)))
	jsonResult(tls, bp)
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

func jsonArrayFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var i int32

	jsonInit(tls, bp, ctx)
	jsonAppendChar(tls, bp, uint8('['))
	for i = 0; i < argc; i++ {
		jsonAppendSeparator(tls, bp)
		jsonAppendValue(tls, bp, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
	}
	jsonAppendChar(tls, bp, uint8(']'))
	jsonResult(tls, bp)
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

func jsonArrayLengthFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var p uintptr
	var n Sqlite3_int64 = int64(0)
	var i U32
	var pNode uintptr

	p = jsonParseCached(tls, ctx, argv, ctx)
	if p == uintptr(0) {
		return
	}

	if argc == 2 {
		var zPath uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
		pNode = jsonLookup(tls, p, zPath, uintptr(0), ctx)
	} else {
		pNode = (*JsonParse)(unsafe.Pointer(p)).FaNode
	}
	if pNode == uintptr(0) {
		return
	}
	if int32((*JsonNode)(unsafe.Pointer(pNode)).FeType) == JSON_ARRAY {
		for i = U32(1); i <= (*JsonNode)(unsafe.Pointer(pNode)).Fn; n++ {
			i = i + jsonNodeSize(tls, pNode+uintptr(i)*16)
		}
	}
	Xsqlite3_result_int64(tls, ctx, n)
}

func jsonExtractFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var p uintptr
	var pNode uintptr
	var zPath uintptr
	var flags int32 = int32(Xsqlite3_user_data(tls, ctx))

	if argc < 2 {
		return
	}
	p = jsonParseCached(tls, ctx, argv, ctx)
	if p == uintptr(0) {
		return
	}
	if argc == 2 {
		zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
		if zPath == uintptr(0) {
			return
		}
		if flags&JSON_ABPATH != 0 {
			if int32(*(*uint8)(unsafe.Pointer(zPath))) != '$' {
				jsonInit(tls, bp, ctx)
				if int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(zPath))])&0x04 != 0 {
					jsonAppendRaw(tls, bp, ts+30922, uint32(2))
					jsonAppendRaw(tls, bp, zPath, uint32(int32(libc.Xstrlen(tls, zPath))))
					jsonAppendRaw(tls, bp, ts+7923, uint32(2))
				} else {
					jsonAppendRaw(tls, bp, ts+30925, uint32(1+libc.Bool32(int32(*(*uint8)(unsafe.Pointer(zPath))) != '[')))
					jsonAppendRaw(tls, bp, zPath, uint32(int32(libc.Xstrlen(tls, zPath))))
					jsonAppendChar(tls, bp, uint8(0))
				}
				if (*JsonString)(unsafe.Pointer(bp)).FbErr != 0 {
					pNode = uintptr(0)
				} else {
					pNode = jsonLookup(tls, p, (*JsonString)(unsafe.Pointer(bp)).FzBuf, uintptr(0), ctx)
				}
				jsonReset(tls, bp)
			} else {
				pNode = jsonLookup(tls, p, zPath, uintptr(0), ctx)
			}
			if pNode != 0 {
				if flags&JSON_JSON != 0 {
					jsonReturnJson(tls, pNode, ctx, uintptr(0))
				} else {
					jsonReturn(tls, pNode, ctx, uintptr(0))
					Xsqlite3_result_subtype(tls, ctx, uint32(0))
				}
			}
		} else {
			pNode = jsonLookup(tls, p, zPath, uintptr(0), ctx)
			if int32((*JsonParse)(unsafe.Pointer(p)).FnErr) == 0 && pNode != 0 {
				jsonReturn(tls, pNode, ctx, uintptr(0))
			}
		}
	} else {
		var i int32
		jsonInit(tls, bp, ctx)
		jsonAppendChar(tls, bp, uint8('['))
		for i = 1; i < argc; i++ {
			zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
			pNode = jsonLookup(tls, p, zPath, uintptr(0), ctx)
			if (*JsonParse)(unsafe.Pointer(p)).FnErr != 0 {
				break
			}
			jsonAppendSeparator(tls, bp)
			if pNode != 0 {
				jsonRenderNode(tls, pNode, bp, uintptr(0))
			} else {
				jsonAppendRaw(tls, bp, ts+9106, uint32(4))
			}
		}
		if i == argc {
			jsonAppendChar(tls, bp, uint8(']'))
			jsonResult(tls, bp)
			Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
		}
		jsonReset(tls, bp)
	}
}

func jsonMergePatch(tls *libc.TLS, pParse uintptr, iTarget U32, pPatch uintptr) uintptr {
	var i U32
	var j U32
	var iRoot U32
	var pTarget uintptr
	if int32((*JsonNode)(unsafe.Pointer(pPatch)).FeType) != JSON_OBJECT {
		return pPatch
	}

	pTarget = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iTarget)*16

	if int32((*JsonNode)(unsafe.Pointer(pTarget)).FeType) != JSON_OBJECT {
		jsonRemoveAllNulls(tls, pPatch)
		return pPatch
	}
	iRoot = iTarget
	for i = U32(1); i < (*JsonNode)(unsafe.Pointer(pPatch)).Fn; i = i + (jsonNodeSize(tls, pPatch+uintptr(i+U32(1))*16) + U32(1)) {
		var nKey U32
		var zKey uintptr

		nKey = (*JsonNode)(unsafe.Pointer(pPatch + uintptr(i)*16)).Fn
		zKey = *(*uintptr)(unsafe.Pointer(pPatch + uintptr(i)*16 + 8))

		for j = U32(1); j < (*JsonNode)(unsafe.Pointer(pTarget)).Fn; j = j + (jsonNodeSize(tls, pTarget+uintptr(j+U32(1))*16) + U32(1)) {
			if (*JsonNode)(unsafe.Pointer(pTarget+uintptr(j)*16)).Fn == nKey && libc.Xstrncmp(tls, *(*uintptr)(unsafe.Pointer(pTarget + uintptr(j)*16 + 8)), zKey, uint64(nKey)) == 0 {
				if int32((*JsonNode)(unsafe.Pointer(pTarget+uintptr(j+U32(1))*16)).FjnFlags)&(JNODE_REMOVE|JNODE_PATCH) != 0 {
					break
				}
				if int32((*JsonNode)(unsafe.Pointer(pPatch+uintptr(i+U32(1))*16)).FeType) == JSON_NULL {
					*(*U8)(unsafe.Pointer(pTarget + uintptr(j+U32(1))*16 + 1)) |= U8(JNODE_REMOVE)
				} else {
					var pNew uintptr = jsonMergePatch(tls, pParse, iTarget+j+U32(1), pPatch+uintptr(i+U32(1))*16)
					if pNew == uintptr(0) {
						return uintptr(0)
					}
					pTarget = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iTarget)*16
					if pNew != pTarget+uintptr(j+U32(1))*16 {
						*(*uintptr)(unsafe.Pointer(pTarget + uintptr(j+U32(1))*16 + 8)) = pNew
						*(*U8)(unsafe.Pointer(pTarget + uintptr(j+U32(1))*16 + 1)) |= U8(JNODE_PATCH)
					}
				}
				break
			}
		}
		if j >= (*JsonNode)(unsafe.Pointer(pTarget)).Fn && int32((*JsonNode)(unsafe.Pointer(pPatch+uintptr(i+U32(1))*16)).FeType) != JSON_NULL {
			var iStart int32
			var iPatch int32
			iStart = jsonParseAddNode(tls, pParse, uint32(JSON_OBJECT), uint32(2), uintptr(0))
			jsonParseAddNode(tls, pParse, uint32(JSON_STRING), nKey, zKey)
			iPatch = jsonParseAddNode(tls, pParse, uint32(JSON_TRUE), uint32(0), uintptr(0))
			if (*JsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
				return uintptr(0)
			}
			jsonRemoveAllNulls(tls, pPatch)
			pTarget = (*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iTarget)*16

			*(*U8)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iRoot)*16 + 1)) |= U8(JNODE_APPEND)

			*(*U32)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iRoot)*16 + 8)) = U32(iStart) - iRoot
			iRoot = U32(iStart)

			*(*U8)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iPatch)*16 + 1)) |= U8(JNODE_PATCH)
			*(*uintptr)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(pParse)).FaNode + uintptr(iPatch)*16 + 8)) = pPatch + uintptr(i+U32(1))*16
		}
	}
	return pTarget
}

func jsonPatchFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(96)
	defer tls.Free(96)

	var pResult uintptr

	_ = argc
	if jsonParse(tls, bp, ctx, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))) != 0 {
		return
	}
	if jsonParse(tls, bp+48, ctx, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))) != 0 {
		jsonParseReset(tls, bp)
		return
	}
	pResult = jsonMergePatch(tls, bp, uint32(0), (*JsonParse)(unsafe.Pointer(bp+48)).FaNode)

	if pResult != 0 {
		jsonReturnJson(tls, pResult, ctx, uintptr(0))
	} else {
		Xsqlite3_result_error_nomem(tls, ctx)
	}
	jsonParseReset(tls, bp)
	jsonParseReset(tls, bp+48)
}

func jsonObjectFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var i int32

	var z uintptr
	var n U32

	if argc&1 != 0 {
		Xsqlite3_result_error(tls, ctx,
			ts+30928, -1)
		return
	}
	jsonInit(tls, bp, ctx)
	jsonAppendChar(tls, bp, uint8('{'))
	for i = 0; i < argc; i = i + 2 {
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8))) != SQLITE_TEXT {
			Xsqlite3_result_error(tls, ctx, ts+30979, -1)
			jsonReset(tls, bp)
			return
		}
		jsonAppendSeparator(tls, bp)
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
		n = U32(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8))))
		jsonAppendString(tls, bp, z, n)
		jsonAppendChar(tls, bp, uint8(':'))
		jsonAppendValue(tls, bp, *(*uintptr)(unsafe.Pointer(argv + uintptr(i+1)*8)))
	}
	jsonAppendChar(tls, bp, uint8('}'))
	jsonResult(tls, bp)
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

func jsonRemoveFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var pNode uintptr
	var zPath uintptr
	var i U32

	if !(argc < 1) {
		goto __1
	}
	return
__1:
	;
	if !(jsonParse(tls, bp, ctx, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))) != 0) {
		goto __2
	}
	return
__2:
	;
	i = U32(1)
__3:
	if !(i < U32(argc)) {
		goto __5
	}
	zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
	if !(zPath == uintptr(0)) {
		goto __6
	}
	goto remove_done
__6:
	;
	pNode = jsonLookup(tls, bp, zPath, uintptr(0), ctx)
	if !((*JsonParse)(unsafe.Pointer(bp)).FnErr != 0) {
		goto __7
	}
	goto remove_done
__7:
	;
	if !(pNode != 0) {
		goto __8
	}
	*(*U8)(unsafe.Pointer(pNode + 1)) |= U8(JNODE_REMOVE)
__8:
	;
	goto __4
__4:
	i++
	goto __3
	goto __5
__5:
	;
	if !(int32((*JsonNode)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(bp)).FaNode)).FjnFlags)&JNODE_REMOVE == 0) {
		goto __9
	}
	jsonReturnJson(tls, (*JsonParse)(unsafe.Pointer(bp)).FaNode, ctx, uintptr(0))
__9:
	;
remove_done:
	jsonParseReset(tls, bp)
}

func jsonReplaceFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var pNode uintptr
	var zPath uintptr
	var i U32

	if !(argc < 1) {
		goto __1
	}
	return
__1:
	;
	if !(argc&1 == 0) {
		goto __2
	}
	jsonWrongNumArgs(tls, ctx, ts+18793)
	return
__2:
	;
	if !(jsonParse(tls, bp, ctx, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))) != 0) {
		goto __3
	}
	return
__3:
	;
	i = U32(1)
__4:
	if !(i < U32(argc)) {
		goto __6
	}
	zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
	pNode = jsonLookup(tls, bp, zPath, uintptr(0), ctx)
	if !((*JsonParse)(unsafe.Pointer(bp)).FnErr != 0) {
		goto __7
	}
	goto replace_err
__7:
	;
	if !(pNode != 0) {
		goto __8
	}

	*(*U8)(unsafe.Pointer(pNode + 1)) |= U8(int32(U8(JNODE_REPLACE)))

	*(*U32)(unsafe.Pointer(pNode + 8)) = i + U32(1)
__8:
	;
	goto __5
__5:
	i = i + U32(2)
	goto __4
	goto __6
__6:
	;
	if !(int32((*JsonNode)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(bp)).FaNode)).FjnFlags)&JNODE_REPLACE != 0) {
		goto __9
	}

	Xsqlite3_result_value(tls, ctx, *(*uintptr)(unsafe.Pointer(argv + uintptr(*(*U32)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(bp)).FaNode + 8)))*8)))
	goto __10
__9:
	jsonReturnJson(tls, (*JsonParse)(unsafe.Pointer(bp)).FaNode, ctx, argv)
__10:
	;
replace_err:
	jsonParseReset(tls, bp)
}

func jsonSetFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var pNode uintptr
	var zPath uintptr
	var i U32

	var bIsSet int32
	bIsSet = libc.Bool32(Xsqlite3_user_data(tls, ctx) != uintptr(0))

	if !(argc < 1) {
		goto __1
	}
	return
__1:
	;
	if !(argc&1 == 0) {
		goto __2
	}
	jsonWrongNumArgs(tls, ctx, func() uintptr {
		if bIsSet != 0 {
			return ts + 31013
		}
		return ts + 31017
	}())
	return
__2:
	;
	if !(jsonParse(tls, bp, ctx, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))) != 0) {
		goto __3
	}
	return
__3:
	;
	i = U32(1)
__4:
	if !(i < U32(argc)) {
		goto __6
	}
	zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
	*(*int32)(unsafe.Pointer(bp + 48)) = 0
	pNode = jsonLookup(tls, bp, zPath, bp+48, ctx)
	if !((*JsonParse)(unsafe.Pointer(bp)).Foom != 0) {
		goto __7
	}
	Xsqlite3_result_error_nomem(tls, ctx)
	goto jsonSetDone
	goto __8
__7:
	if !((*JsonParse)(unsafe.Pointer(bp)).FnErr != 0) {
		goto __9
	}
	goto jsonSetDone
	goto __10
__9:
	if !(pNode != 0 && (*(*int32)(unsafe.Pointer(bp + 48)) != 0 || bIsSet != 0)) {
		goto __11
	}

	*(*U8)(unsafe.Pointer(pNode + 1)) |= U8(int32(U8(JNODE_REPLACE)))
	*(*U32)(unsafe.Pointer(pNode + 8)) = i + U32(1)
__11:
	;
__10:
	;
__8:
	;
	goto __5
__5:
	i = i + U32(2)
	goto __4
	goto __6
__6:
	;
	if !(int32((*JsonNode)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(bp)).FaNode)).FjnFlags)&JNODE_REPLACE != 0) {
		goto __12
	}

	Xsqlite3_result_value(tls, ctx, *(*uintptr)(unsafe.Pointer(argv + uintptr(*(*U32)(unsafe.Pointer((*JsonParse)(unsafe.Pointer(bp)).FaNode + 8)))*8)))
	goto __13
__12:
	jsonReturnJson(tls, (*JsonParse)(unsafe.Pointer(bp)).FaNode, ctx, argv)
__13:
	;
jsonSetDone:
	jsonParseReset(tls, bp)
}

func jsonTypeFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var p uintptr
	var zPath uintptr
	var pNode uintptr

	p = jsonParseCached(tls, ctx, argv, ctx)
	if p == uintptr(0) {
		return
	}
	if argc == 2 {
		zPath = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
		pNode = jsonLookup(tls, p, zPath, uintptr(0), ctx)
	} else {
		pNode = (*JsonParse)(unsafe.Pointer(p)).FaNode
	}
	if pNode != 0 {
		Xsqlite3_result_text(tls, ctx, jsonType[(*JsonNode)(unsafe.Pointer(pNode)).FeType], -1, uintptr(0))
	}
}

func jsonValidFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var p uintptr
	_ = argc
	p = jsonParseCached(tls, ctx, argv, uintptr(0))
	Xsqlite3_result_int(tls, ctx, libc.Bool32(p != uintptr(0)))
}

func jsonArrayStep(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var pStr uintptr
	_ = argc
	pStr = Xsqlite3_aggregate_context(tls, ctx, int32(unsafe.Sizeof(JsonString{})))
	if pStr != 0 {
		if (*JsonString)(unsafe.Pointer(pStr)).FzBuf == uintptr(0) {
			jsonInit(tls, pStr, ctx)
			jsonAppendChar(tls, pStr, uint8('['))
		} else if (*JsonString)(unsafe.Pointer(pStr)).FnUsed > uint64(1) {
			jsonAppendChar(tls, pStr, uint8(','))
		}
		(*JsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
		jsonAppendValue(tls, pStr, *(*uintptr)(unsafe.Pointer(argv)))
	}
}

func jsonArrayCompute(tls *libc.TLS, ctx uintptr, isFinal int32) {
	var pStr uintptr
	pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
	if pStr != 0 {
		(*JsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
		jsonAppendChar(tls, pStr, uint8(']'))
		if (*JsonString)(unsafe.Pointer(pStr)).FbErr != 0 {
			if int32((*JsonString)(unsafe.Pointer(pStr)).FbErr) == 1 {
				Xsqlite3_result_error_nomem(tls, ctx)
			}

		} else if isFinal != 0 {
			Xsqlite3_result_text(tls, ctx, (*JsonString)(unsafe.Pointer(pStr)).FzBuf, int32((*JsonString)(unsafe.Pointer(pStr)).FnUsed),
				func() uintptr {
					if (*JsonString)(unsafe.Pointer(pStr)).FbStatic != 0 {
						return libc.UintptrFromInt32(-1)
					}
					return *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free}))
				}())
			(*JsonString)(unsafe.Pointer(pStr)).FbStatic = U8(1)
		} else {
			Xsqlite3_result_text(tls, ctx, (*JsonString)(unsafe.Pointer(pStr)).FzBuf, int32((*JsonString)(unsafe.Pointer(pStr)).FnUsed), libc.UintptrFromInt32(-1))
			(*JsonString)(unsafe.Pointer(pStr)).FnUsed--
		}
	} else {
		Xsqlite3_result_text(tls, ctx, ts+31024, 2, uintptr(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, 1)
}

func jsonGroupInverse(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var i uint32
	var inStr int32 = 0
	var nNest int32 = 0
	var z uintptr
	var c uint8
	var pStr uintptr
	_ = argc
	_ = argv
	pStr = Xsqlite3_aggregate_context(tls, ctx, 0)

	if !(pStr != 0) {
		return
	}
	z = (*JsonString)(unsafe.Pointer(pStr)).FzBuf
	for i = uint32(1); U64(i) < (*JsonString)(unsafe.Pointer(pStr)).FnUsed && (int32(libc.AssignUint8(&c, *(*uint8)(unsafe.Pointer(z + uintptr(i))))) != ',' || inStr != 0 || nNest != 0); i++ {
		if int32(c) == '"' {
			inStr = libc.BoolInt32(!(inStr != 0))
		} else if int32(c) == '\\' {
			i++
		} else if !(inStr != 0) {
			if int32(c) == '{' || int32(c) == '[' {
				nNest++
			}
			if int32(c) == '}' || int32(c) == ']' {
				nNest--
			}
		}
	}
	if U64(i) < (*JsonString)(unsafe.Pointer(pStr)).FnUsed {
		*(*U64)(unsafe.Pointer(pStr + 24)) -= U64(i)
		libc.Xmemmove(tls, z+1, z+uintptr(i+uint32(1)), (*JsonString)(unsafe.Pointer(pStr)).FnUsed-uint64(1))
		*(*uint8)(unsafe.Pointer(z + uintptr((*JsonString)(unsafe.Pointer(pStr)).FnUsed))) = uint8(0)
	} else {
		(*JsonString)(unsafe.Pointer(pStr)).FnUsed = uint64(1)
	}
}

func jsonObjectStep(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	var pStr uintptr
	var z uintptr
	var n U32
	_ = argc
	pStr = Xsqlite3_aggregate_context(tls, ctx, int32(unsafe.Sizeof(JsonString{})))
	if pStr != 0 {
		if (*JsonString)(unsafe.Pointer(pStr)).FzBuf == uintptr(0) {
			jsonInit(tls, pStr, ctx)
			jsonAppendChar(tls, pStr, uint8('{'))
		} else if (*JsonString)(unsafe.Pointer(pStr)).FnUsed > uint64(1) {
			jsonAppendChar(tls, pStr, uint8(','))
		}
		(*JsonString)(unsafe.Pointer(pStr)).FpCtx = ctx
		z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		n = U32(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
		jsonAppendString(tls, pStr, z, n)
		jsonAppendChar(tls, pStr, uint8(':'))
		jsonAppendValue(tls, pStr, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	}
}

func jsonObjectCompute(tls *libc.TLS, ctx uintptr, isFinal int32) {
	var pStr uintptr
	pStr = Xsqlite3_aggregate_context(tls, ctx, 0)
	if pStr != 0 {
		jsonAppendChar(tls, pStr, uint8('}'))
		if (*JsonString)(unsafe.Pointer(pStr)).FbErr != 0 {
			if int32((*JsonString)(unsafe.Pointer(pStr)).FbErr) == 1 {
				Xsqlite3_result_error_nomem(tls, ctx)
			}

		} else if isFinal != 0 {
			Xsqlite3_result_text(tls, ctx, (*JsonString)(unsafe.Pointer(pStr)).FzBuf, int32((*JsonString)(unsafe.Pointer(pStr)).FnUsed),
				func() uintptr {
					if (*JsonString)(unsafe.Pointer(pStr)).FbStatic != 0 {
						return libc.UintptrFromInt32(-1)
					}
					return *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free}))
				}())
			(*JsonString)(unsafe.Pointer(pStr)).FbStatic = U8(1)
		} else {
			Xsqlite3_result_text(tls, ctx, (*JsonString)(unsafe.Pointer(pStr)).FzBuf, int32((*JsonString)(unsafe.Pointer(pStr)).FnUsed), libc.UintptrFromInt32(-1))
			(*JsonString)(unsafe.Pointer(pStr)).FnUsed--
		}
	} else {
		Xsqlite3_result_text(tls, ctx, ts+31027, 2, uintptr(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, 1)
}

type JsonEachCursor1 = struct {
	Fbase        Sqlite3_vtab_cursor
	FiRowid      U32
	FiBegin      U32
	Fi           U32
	FiEnd        U32
	FeType       U8
	FbRecursive  U8
	F__ccgo_pad1 [6]byte
	FzJson       uintptr
	FzRoot       uintptr
	FsParse      JsonParse
}

type JsonEachCursor = JsonEachCursor1

func jsonEachConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	var pNew uintptr
	var rc int32

	_ = pzErr
	_ = argv
	_ = argc
	_ = pAux
	rc = Xsqlite3_declare_vtab(tls, db,
		ts+31030)
	if rc == SQLITE_OK {
		pNew = libc.AssignPtrUintptr(ppVtab, Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Sqlite3_vtab{}))))
		if pNew == uintptr(0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Sqlite3_vtab{})))
		Xsqlite3_vtab_config(tls, db, SQLITE_VTAB_INNOCUOUS, 0)
	}
	return rc
}

func jsonEachDisconnect(tls *libc.TLS, pVtab uintptr) int32 {
	Xsqlite3_free(tls, pVtab)
	return SQLITE_OK
}

func jsonEachOpenEach(tls *libc.TLS, p uintptr, ppCursor uintptr) int32 {
	var pCur uintptr

	_ = p
	pCur = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(JsonEachCursor{})))
	if pCur == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pCur, 0, uint64(unsafe.Sizeof(JsonEachCursor{})))
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return SQLITE_OK
}

func jsonEachOpenTree(tls *libc.TLS, p uintptr, ppCursor uintptr) int32 {
	var rc int32 = jsonEachOpenEach(tls, p, ppCursor)
	if rc == SQLITE_OK {
		var pCur uintptr = *(*uintptr)(unsafe.Pointer(ppCursor))
		(*JsonEachCursor)(unsafe.Pointer(pCur)).FbRecursive = U8(1)
	}
	return rc
}

func jsonEachCursorReset(tls *libc.TLS, p uintptr) {
	Xsqlite3_free(tls, (*JsonEachCursor)(unsafe.Pointer(p)).FzJson)
	Xsqlite3_free(tls, (*JsonEachCursor)(unsafe.Pointer(p)).FzRoot)
	jsonParseReset(tls, p+48)
	(*JsonEachCursor)(unsafe.Pointer(p)).FiRowid = U32(0)
	(*JsonEachCursor)(unsafe.Pointer(p)).Fi = U32(0)
	(*JsonEachCursor)(unsafe.Pointer(p)).FiEnd = U32(0)
	(*JsonEachCursor)(unsafe.Pointer(p)).FeType = U8(0)
	(*JsonEachCursor)(unsafe.Pointer(p)).FzJson = uintptr(0)
	(*JsonEachCursor)(unsafe.Pointer(p)).FzRoot = uintptr(0)
}

func jsonEachClose(tls *libc.TLS, cur uintptr) int32 {
	var p uintptr = cur
	jsonEachCursorReset(tls, p)
	Xsqlite3_free(tls, cur)
	return SQLITE_OK
}

func jsonEachEof(tls *libc.TLS, cur uintptr) int32 {
	var p uintptr = cur
	return libc.Bool32((*JsonEachCursor)(unsafe.Pointer(p)).Fi >= (*JsonEachCursor)(unsafe.Pointer(p)).FiEnd)
}

func jsonEachNext(tls *libc.TLS, cur uintptr) int32 {
	var p uintptr = cur
	if (*JsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 {
		if int32((*JsonNode)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode+uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi)*16)).FjnFlags)&JNODE_LABEL != 0 {
			(*JsonEachCursor)(unsafe.Pointer(p)).Fi++
		}
		(*JsonEachCursor)(unsafe.Pointer(p)).Fi++
		(*JsonEachCursor)(unsafe.Pointer(p)).FiRowid++
		if (*JsonEachCursor)(unsafe.Pointer(p)).Fi < (*JsonEachCursor)(unsafe.Pointer(p)).FiEnd {
			var iUp U32 = *(*U32)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaUp + uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi)*4))
			var pUp uintptr = (*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode + uintptr(iUp)*16
			(*JsonEachCursor)(unsafe.Pointer(p)).FeType = (*JsonNode)(unsafe.Pointer(pUp)).FeType
			if int32((*JsonNode)(unsafe.Pointer(pUp)).FeType) == JSON_ARRAY {
				if iUp == (*JsonEachCursor)(unsafe.Pointer(p)).Fi-U32(1) {
					*(*U32)(unsafe.Pointer(pUp + 8)) = U32(0)
				} else {
					*(*U32)(unsafe.Pointer(pUp + 8))++
				}
			}
		}
	} else {
		switch int32((*JsonEachCursor)(unsafe.Pointer(p)).FeType) {
		case JSON_ARRAY:
			{
				*(*U32)(unsafe.Pointer(p + 16)) += jsonNodeSize(tls, (*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode+uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi)*16)
				(*JsonEachCursor)(unsafe.Pointer(p)).FiRowid++
				break

			}
			fallthrough
		case JSON_OBJECT:
			{
				*(*U32)(unsafe.Pointer(p + 16)) += U32(1) + jsonNodeSize(tls, (*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode+uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi+U32(1))*16)
				(*JsonEachCursor)(unsafe.Pointer(p)).FiRowid++
				break

			}
			fallthrough
		default:
			{
				(*JsonEachCursor)(unsafe.Pointer(p)).Fi = (*JsonEachCursor)(unsafe.Pointer(p)).FiEnd
				break

			}
		}
	}
	return SQLITE_OK
}

func jsonAppendObjectPathElement(tls *libc.TLS, pStr uintptr, pNode uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var jj int32
	var nn int32
	var z uintptr

	z = *(*uintptr)(unsafe.Pointer(pNode + 8))
	nn = int32((*JsonNode)(unsafe.Pointer(pNode)).Fn)

	if nn > 2 && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + 1))])&0x02 != 0 {
		for jj = 2; jj < nn-1 && int32(Xsqlite3CtypeMap[*(*uint8)(unsafe.Pointer(z + uintptr(jj)))])&0x06 != 0; jj++ {
		}
		if jj == nn-1 {
			z++
			nn = nn - 2
		}
	}
	jsonPrintf(tls, nn+2, pStr, ts+31113, libc.VaList(bp, nn, z))
}

func jsonEachComputePath(tls *libc.TLS, p uintptr, pStr uintptr, i U32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pNode uintptr
	var pUp uintptr
	var iUp U32
	if i == U32(0) {
		jsonAppendChar(tls, pStr, uint8('$'))
		return
	}
	iUp = *(*U32)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaUp + uintptr(i)*4))
	jsonEachComputePath(tls, p, pStr, iUp)
	pNode = (*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode + uintptr(i)*16
	pUp = (*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode + uintptr(iUp)*16
	if int32((*JsonNode)(unsafe.Pointer(pUp)).FeType) == JSON_ARRAY {
		jsonPrintf(tls, 30, pStr, ts+31119, libc.VaList(bp, *(*U32)(unsafe.Pointer(pUp + 8))))
	} else {
		if int32((*JsonNode)(unsafe.Pointer(pNode)).FjnFlags)&JNODE_LABEL == 0 {
			pNode -= 16
		}
		jsonAppendObjectPathElement(tls, pStr, pNode)
	}
}

func jsonEachColumn(tls *libc.TLS, cur uintptr, ctx uintptr, i int32) int32 {
	bp := tls.Alloc(280)
	defer tls.Free(280)

	var p uintptr = cur
	var pThis uintptr = (*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode + uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi)*16
	switch i {
	case JEACH_KEY:
		{
			if (*JsonEachCursor)(unsafe.Pointer(p)).Fi == U32(0) {
				break
			}
			if int32((*JsonEachCursor)(unsafe.Pointer(p)).FeType) == JSON_OBJECT {
				jsonReturn(tls, pThis, ctx, uintptr(0))
			} else if int32((*JsonEachCursor)(unsafe.Pointer(p)).FeType) == JSON_ARRAY {
				var iKey U32
				if (*JsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 {
					if (*JsonEachCursor)(unsafe.Pointer(p)).FiRowid == U32(0) {
						break
					}

					iKey = *(*U32)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode + uintptr(*(*U32)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaUp + uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi)*4)))*16 + 8))
				} else {
					iKey = (*JsonEachCursor)(unsafe.Pointer(p)).FiRowid
				}
				Xsqlite3_result_int64(tls, ctx, Sqlite3_int64(iKey))
			}
			break

		}
	case JEACH_VALUE:
		{
			if int32((*JsonNode)(unsafe.Pointer(pThis)).FjnFlags)&JNODE_LABEL != 0 {
				pThis += 16
			}
			jsonReturn(tls, pThis, ctx, uintptr(0))
			break

		}
	case JEACH_TYPE:
		{
			if int32((*JsonNode)(unsafe.Pointer(pThis)).FjnFlags)&JNODE_LABEL != 0 {
				pThis += 16
			}
			Xsqlite3_result_text(tls, ctx, jsonType[(*JsonNode)(unsafe.Pointer(pThis)).FeType], -1, uintptr(0))
			break

		}
	case JEACH_ATOM:
		{
			if int32((*JsonNode)(unsafe.Pointer(pThis)).FjnFlags)&JNODE_LABEL != 0 {
				pThis += 16
			}
			if int32((*JsonNode)(unsafe.Pointer(pThis)).FeType) >= JSON_ARRAY {
				break
			}
			jsonReturn(tls, pThis, ctx, uintptr(0))
			break

		}
	case JEACH_ID:
		{
			Xsqlite3_result_int64(tls, ctx,
				Sqlite3_int64((*JsonEachCursor)(unsafe.Pointer(p)).Fi)+Sqlite3_int64(libc.Bool32(int32((*JsonNode)(unsafe.Pointer(pThis)).FjnFlags)&JNODE_LABEL != 0)))
			break

		}
	case JEACH_PARENT:
		{
			if (*JsonEachCursor)(unsafe.Pointer(p)).Fi > (*JsonEachCursor)(unsafe.Pointer(p)).FiBegin && (*JsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 {
				Xsqlite3_result_int64(tls, ctx, Sqlite3_int64(*(*U32)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaUp + uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi)*4))))
			}
			break

		}
	case JEACH_FULLKEY:
		{
			jsonInit(tls, bp+8, ctx)
			if (*JsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 {
				jsonEachComputePath(tls, p, bp+8, (*JsonEachCursor)(unsafe.Pointer(p)).Fi)
			} else {
				if (*JsonEachCursor)(unsafe.Pointer(p)).FzRoot != 0 {
					jsonAppendRaw(tls, bp+8, (*JsonEachCursor)(unsafe.Pointer(p)).FzRoot, uint32(int32(libc.Xstrlen(tls, (*JsonEachCursor)(unsafe.Pointer(p)).FzRoot))))
				} else {
					jsonAppendChar(tls, bp+8, uint8('$'))
				}
				if int32((*JsonEachCursor)(unsafe.Pointer(p)).FeType) == JSON_ARRAY {
					jsonPrintf(tls, 30, bp+8, ts+31119, libc.VaList(bp, (*JsonEachCursor)(unsafe.Pointer(p)).FiRowid))
				} else if int32((*JsonEachCursor)(unsafe.Pointer(p)).FeType) == JSON_OBJECT {
					jsonAppendObjectPathElement(tls, bp+8, pThis)
				}
			}
			jsonResult(tls, bp+8)
			break

		}
	case JEACH_PATH:
		{
			if (*JsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 {
				jsonInit(tls, bp+144, ctx)
				jsonEachComputePath(tls, p, bp+144, *(*U32)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaUp + uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi)*4)))
				jsonResult(tls, bp+144)
				break
			}

		}
		fallthrough
	default:
		{
			var zRoot uintptr = (*JsonEachCursor)(unsafe.Pointer(p)).FzRoot
			if zRoot == uintptr(0) {
				zRoot = ts + 31124
			}
			Xsqlite3_result_text(tls, ctx, zRoot, -1, uintptr(0))
			break

		}
	case JEACH_JSON:
		{
			Xsqlite3_result_text(tls, ctx, (*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FzJson, -1, uintptr(0))
			break

		}
	}
	return SQLITE_OK
}

func jsonEachRowid(tls *libc.TLS, cur uintptr, pRowid uintptr) int32 {
	var p uintptr = cur
	*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = Sqlite_int64((*JsonEachCursor)(unsafe.Pointer(p)).FiRowid)
	return SQLITE_OK
}

func jsonEachBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var i int32

	var unusableMask int32 = 0
	var idxMask int32 = 0
	var pConstraint uintptr

	_ = tab
	*(*int32)(unsafe.Pointer(bp)) = libc.AssignPtrInt32(bp+1*4, -1)
	pConstraint = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint
	i = 0
__1:
	if !(i < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
		goto __3
	}
	{
		var iCol int32
		var iMask int32
		if (*sqlite3_index_constraint)(unsafe.Pointer(pConstraint)).FiColumn < JEACH_JSON {
			goto __2
		}
		iCol = (*sqlite3_index_constraint)(unsafe.Pointer(pConstraint)).FiColumn - JEACH_JSON

		iMask = int32(1) << iCol
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(pConstraint)).Fusable) == 0 {
			unusableMask = unusableMask | iMask
		} else if int32((*sqlite3_index_constraint)(unsafe.Pointer(pConstraint)).Fop) == SQLITE_INDEX_CONSTRAINT_EQ {
			*(*int32)(unsafe.Pointer(bp + uintptr(iCol)*4)) = i
			idxMask = idxMask | iMask
		}

	}
	goto __2
__2:
	i++
	pConstraint += 12
	goto __1
	goto __3
__3:
	;
	if (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy > 0 &&
		(*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy)).FiColumn < 0 &&
		int32((*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy)).Fdesc) == 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 1
	}

	if unusableMask & ^idxMask != 0 {
		return SQLITE_CONSTRAINT
	}
	if *(*int32)(unsafe.Pointer(bp)) < 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 0
	} else {
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 1.0
		i = *(*int32)(unsafe.Pointer(bp))
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = 1
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).Fomit = uint8(1)
		if *(*int32)(unsafe.Pointer(bp + 1*4)) < 0 {
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 1
		} else {
			i = *(*int32)(unsafe.Pointer(bp + 1*4))
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = 2
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).Fomit = uint8(1)
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 3
		}
	}
	return SQLITE_OK
}

func jsonEachFilter(tls *libc.TLS, cur uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p uintptr = cur
	var z uintptr
	var zRoot uintptr = uintptr(0)
	var n Sqlite3_int64

	_ = idxStr
	_ = argc
	jsonEachCursorReset(tls, p)
	if idxNum == 0 {
		return SQLITE_OK
	}
	z = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if z == uintptr(0) {
		return SQLITE_OK
	}
	n = Sqlite3_int64(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv))))
	(*JsonEachCursor)(unsafe.Pointer(p)).FzJson = Xsqlite3_malloc64(tls, uint64(n+int64(1)))
	if (*JsonEachCursor)(unsafe.Pointer(p)).FzJson == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemcpy(tls, (*JsonEachCursor)(unsafe.Pointer(p)).FzJson, z, Size_t(n)+uint64(1))
	if jsonParse(tls, p+48, uintptr(0), (*JsonEachCursor)(unsafe.Pointer(p)).FzJson) != 0 {
		var rc int32 = SQLITE_NOMEM
		if int32((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.Foom) == 0 {
			Xsqlite3_free(tls, (*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg)
			(*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls, ts+30834, 0)
			if (*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg != 0 {
				rc = SQLITE_ERROR
			}
		}
		jsonEachCursorReset(tls, p)
		return rc
	} else if (*JsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 && jsonParseFindParents(tls, p+48) != 0 {
		jsonEachCursorReset(tls, p)
		return SQLITE_NOMEM
	} else {
		var pNode uintptr = uintptr(0)
		if idxNum == 3 {
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			zRoot = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
			if zRoot == uintptr(0) {
				return SQLITE_OK
			}
			n = Sqlite3_int64(Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))))
			(*JsonEachCursor)(unsafe.Pointer(p)).FzRoot = Xsqlite3_malloc64(tls, uint64(n+int64(1)))
			if (*JsonEachCursor)(unsafe.Pointer(p)).FzRoot == uintptr(0) {
				return SQLITE_NOMEM
			}
			libc.Xmemcpy(tls, (*JsonEachCursor)(unsafe.Pointer(p)).FzRoot, zRoot, Size_t(n)+uint64(1))
			if int32(*(*uint8)(unsafe.Pointer(zRoot))) != '$' {
				*(*uintptr)(unsafe.Pointer(bp)) = zRoot
			} else {
				pNode = jsonLookupStep(tls, p+48, uint32(0), (*JsonEachCursor)(unsafe.Pointer(p)).FzRoot+uintptr(1), uintptr(0), bp)
			}
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				Xsqlite3_free(tls, (*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg)
				(*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg = jsonPathSyntaxError(tls, *(*uintptr)(unsafe.Pointer(bp)))
				jsonEachCursorReset(tls, p)
				if (*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab)).FzErrMsg != 0 {
					return SQLITE_ERROR
				}
				return SQLITE_NOMEM
			} else if pNode == uintptr(0) {
				return SQLITE_OK
			}
		} else {
			pNode = (*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode
		}
		(*JsonEachCursor)(unsafe.Pointer(p)).FiBegin = libc.AssignPtrUint32(p+16, U32(int32((int64(pNode)-int64((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode))/16)))
		(*JsonEachCursor)(unsafe.Pointer(p)).FeType = (*JsonNode)(unsafe.Pointer(pNode)).FeType
		if int32((*JsonEachCursor)(unsafe.Pointer(p)).FeType) >= JSON_ARRAY {
			*(*U32)(unsafe.Pointer(pNode + 8)) = U32(0)
			(*JsonEachCursor)(unsafe.Pointer(p)).FiEnd = (*JsonEachCursor)(unsafe.Pointer(p)).Fi + (*JsonNode)(unsafe.Pointer(pNode)).Fn + U32(1)
			if (*JsonEachCursor)(unsafe.Pointer(p)).FbRecursive != 0 {
				(*JsonEachCursor)(unsafe.Pointer(p)).FeType = (*JsonNode)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode + uintptr(*(*U32)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaUp + uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi)*4)))*16)).FeType
				if (*JsonEachCursor)(unsafe.Pointer(p)).Fi > U32(0) && int32((*JsonNode)(unsafe.Pointer((*JsonEachCursor)(unsafe.Pointer(p)).FsParse.FaNode+uintptr((*JsonEachCursor)(unsafe.Pointer(p)).Fi-U32(1))*16)).FjnFlags)&JNODE_LABEL != 0 {
					(*JsonEachCursor)(unsafe.Pointer(p)).Fi--
				}
			} else {
				(*JsonEachCursor)(unsafe.Pointer(p)).Fi++
			}
		} else {
			(*JsonEachCursor)(unsafe.Pointer(p)).FiEnd = (*JsonEachCursor)(unsafe.Pointer(p)).Fi + U32(1)
		}
	}
	return SQLITE_OK
}

var jsonEachModule = Sqlite3_module{
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
}

var jsonTreeModule = Sqlite3_module{
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
}

func Xsqlite3RegisterJsonFunctions(tls *libc.TLS) {
	Xsqlite3InsertBuiltinFuncs(tls, uintptr(unsafe.Pointer(&aJsonFunc)), int32(uint64(unsafe.Sizeof(aJsonFunc))/uint64(unsafe.Sizeof(FuncDef{}))))
}

var aJsonFunc = [19]FuncDef{
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31126},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31131},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31142},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31142},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31160},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: uintptr(int64(JSON_JSON)), FxSFunc: 0, FzName: ts + 31173},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: uintptr(int64(JSON_SQL)), FxSFunc: 0, FzName: ts + 31176},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31180},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31192},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31204},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31215},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31226},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31238},
	{FnArg: int8(-1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FpUserData: uintptr(int64(JSON_ISSET)), FxSFunc: 0, FzName: ts + 31251},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31260},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31260},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_DETERMINISTIC | SQLITE_FUNC_CONSTANT | SQLITE_UTF8), FxSFunc: 0, FzName: ts + 31270},
	{FnArg: int8(1), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | SQLITE_SUBTYPE | SQLITE_UTF8 | SQLITE_DETERMINISTIC), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 31281},
	{FnArg: int8(2), FfuncFlags: U32(SQLITE_FUNC_BUILTIN | SQLITE_UTF8 | 0*SQLITE_FUNC_NEEDCOLL | SQLITE_SUBTYPE | SQLITE_UTF8 | SQLITE_DETERMINISTIC), FxSFunc: 0, FxFinalize: 0, FxValue: 0, FxInverse: 0, FzName: ts + 31298}}

func Xsqlite3JsonTableFunctions(tls *libc.TLS, db uintptr) int32 {
	var rc int32 = SQLITE_OK
	var i uint32
	for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(aMod))/uint64(unsafe.Sizeof(struct {
		FzName   uintptr
		FpModule uintptr
	}{})) && rc == SQLITE_OK; i++ {
		rc = Xsqlite3_create_module(tls, db, aMod[i].FzName, aMod[i].FpModule, uintptr(0))
	}
	return rc
}

var aMod = [2]struct {
	FzName   uintptr
	FpModule uintptr
}{
	{FzName: ts + 31316, FpModule: 0},
	{FzName: ts + 31326, FpModule: 0},
}

type Rtree1 = struct {
	Fbase            Sqlite3_vtab
	Fdb              uintptr
	FiNodeSize       int32
	FnDim            U8
	FnDim2           U8
	FeCoordType      U8
	FnBytesPerCell   U8
	FinWrTrans       U8
	FnAux            U8
	FnAuxNotNull     U8
	F__ccgo_pad1     [1]byte
	FiDepth          int32
	FzDb             uintptr
	FzName           uintptr
	FnBusy           U32
	F__ccgo_pad2     [4]byte
	FnRowEst         I64
	FnCursor         U32
	FnNodeRef        U32
	FzReadAuxSql     uintptr
	FpDeleted        uintptr
	FiReinsertHeight int32
	F__ccgo_pad3     [4]byte
	FpNodeBlob       uintptr
	FpWriteNode      uintptr
	FpDeleteNode     uintptr
	FpReadRowid      uintptr
	FpWriteRowid     uintptr
	FpDeleteRowid    uintptr
	FpReadParent     uintptr
	FpWriteParent    uintptr
	FpDeleteParent   uintptr
	FpWriteAux       uintptr
	FaHash           [97]uintptr
}

type Rtree = Rtree1
type RtreeCursor1 = struct {
	Fbase        Sqlite3_vtab_cursor
	FatEOF       U8
	FbPoint      U8
	FbAuxValid   U8
	F__ccgo_pad1 [1]byte
	FiStrategy   int32
	FnConstraint int32
	F__ccgo_pad2 [4]byte
	FaConstraint uintptr
	FnPointAlloc int32
	FnPoint      int32
	FmxLevel     int32
	F__ccgo_pad3 [4]byte
	FaPoint      uintptr
	FpReadAux    uintptr
	FsPoint      RtreeSearchPoint
	FaNode       [5]uintptr
	FanQueue     [41]U32
	F__ccgo_pad4 [4]byte
}

type RtreeCursor = RtreeCursor1
type RtreeNode1 = struct {
	FpParent uintptr
	FiNode   I64
	FnRef    int32
	FisDirty int32
	FzData   uintptr
	FpNext   uintptr
}

type RtreeNode = RtreeNode1
type RtreeCell1 = struct {
	FiRowid I64
	FaCoord [10]RtreeCoord
}

type RtreeCell = RtreeCell1
type RtreeConstraint1 = struct {
	FiCoord int32
	Fop     int32
	Fu      struct{ FrValue RtreeDValue }
	FpInfo  uintptr
}

type RtreeConstraint = RtreeConstraint1
type RtreeMatchArg1 = struct {
	FiSize       U32
	F__ccgo_pad1 [4]byte
	Fcb          RtreeGeomCallback
	FnParam      int32
	F__ccgo_pad2 [4]byte
	FapSqlParam  uintptr
	FaParam      [1]RtreeDValue
}

type RtreeMatchArg = RtreeMatchArg1
type RtreeGeomCallback1 = struct {
	FxGeom       uintptr
	FxQueryFunc  uintptr
	FxDestructor uintptr
	FpContext    uintptr
}

type RtreeGeomCallback = RtreeGeomCallback1
type RtreeCoord1 = struct{ Ff RtreeValue }

type RtreeCoord = RtreeCoord1
type RtreeSearchPoint1 = struct {
	FrScore      RtreeDValue
	Fid          Sqlite3_int64
	FiLevel      U8
	FeWithin     U8
	FiCell       U8
	F__ccgo_pad1 [5]byte
}

type RtreeSearchPoint = RtreeSearchPoint1

type RtreeDValue = float64
type RtreeValue = float32

func readInt16(tls *libc.TLS, p uintptr) int32 {
	return int32(*(*U8)(unsafe.Pointer(p)))<<8 + int32(*(*U8)(unsafe.Pointer(p + 1)))
}

func readCoord(tls *libc.TLS, p uintptr, pCoord uintptr) {
	*(*U32)(unsafe.Pointer(pCoord)) = libc.X__builtin_bswap32(tls, *(*U32)(unsafe.Pointer(p)))
}

func readInt64(tls *libc.TLS, p uintptr) I64 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	libc.Xmemcpy(tls, bp, p, uint64(8))
	return I64(libc.X__builtin_bswap64(tls, *(*U64)(unsafe.Pointer(bp))))
}

func writeInt16(tls *libc.TLS, p uintptr, i int32) {
	*(*U8)(unsafe.Pointer(p)) = U8(i >> 8 & 0xFF)
	*(*U8)(unsafe.Pointer(p + 1)) = U8(i >> 0 & 0xFF)
}

func writeCoord(tls *libc.TLS, p uintptr, pCoord uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*U32)(unsafe.Pointer(bp)) = libc.X__builtin_bswap32(tls, *(*U32)(unsafe.Pointer(pCoord)))
	libc.Xmemcpy(tls, p, bp, uint64(4))
	return 4
}

func writeInt64(tls *libc.TLS, p uintptr, i I64) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)
	*(*I64)(unsafe.Pointer(bp)) = i

	*(*I64)(unsafe.Pointer(bp)) = I64(libc.X__builtin_bswap64(tls, U64(*(*I64)(unsafe.Pointer(bp)))))
	libc.Xmemcpy(tls, p, bp, uint64(8))
	return 8
}

func nodeReference(tls *libc.TLS, p uintptr) {
	if p != 0 {
		(*RtreeNode)(unsafe.Pointer(p)).FnRef++
	}
}

func nodeZero(tls *libc.TLS, pRtree uintptr, p uintptr) {
	libc.Xmemset(tls, (*RtreeNode)(unsafe.Pointer(p)).FzData+2, 0, uint64((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize-2))
	(*RtreeNode)(unsafe.Pointer(p)).FisDirty = 1
}

func nodeHash(tls *libc.TLS, iNode I64) uint32 {
	return uint32(iNode) % uint32(HASHSIZE)
}

func nodeHashLookup(tls *libc.TLS, pRtree uintptr, iNode I64) uintptr {
	var p uintptr
	for p = *(*uintptr)(unsafe.Pointer(pRtree + 192 + uintptr(nodeHash(tls, iNode))*8)); p != 0 && (*RtreeNode)(unsafe.Pointer(p)).FiNode != iNode; p = (*RtreeNode)(unsafe.Pointer(p)).FpNext {
	}
	return p
}

func nodeHashInsert(tls *libc.TLS, pRtree uintptr, pNode uintptr) {
	var iHash int32

	iHash = int32(nodeHash(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode))
	(*RtreeNode)(unsafe.Pointer(pNode)).FpNext = *(*uintptr)(unsafe.Pointer(pRtree + 192 + uintptr(iHash)*8))
	*(*uintptr)(unsafe.Pointer(pRtree + 192 + uintptr(iHash)*8)) = pNode
}

func nodeHashDelete(tls *libc.TLS, pRtree uintptr, pNode uintptr) {
	var pp uintptr
	if (*RtreeNode)(unsafe.Pointer(pNode)).FiNode != int64(0) {
		pp = pRtree + 192 + uintptr(nodeHash(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode))*8
		for ; *(*uintptr)(unsafe.Pointer(pp)) != pNode; pp = *(*uintptr)(unsafe.Pointer(pp)) + 32 {
		}
		*(*uintptr)(unsafe.Pointer(pp)) = (*RtreeNode)(unsafe.Pointer(pNode)).FpNext
		(*RtreeNode)(unsafe.Pointer(pNode)).FpNext = uintptr(0)
	}
}

func nodeNew(tls *libc.TLS, pRtree uintptr, pParent uintptr) uintptr {
	var pNode uintptr
	pNode = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(RtreeNode{}))+uint64((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize))
	if pNode != 0 {
		libc.Xmemset(tls, pNode, 0, uint64(unsafe.Sizeof(RtreeNode{}))+uint64((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize))
		(*RtreeNode)(unsafe.Pointer(pNode)).FzData = pNode + 1*40
		(*RtreeNode)(unsafe.Pointer(pNode)).FnRef = 1
		(*Rtree)(unsafe.Pointer(pRtree)).FnNodeRef++
		(*RtreeNode)(unsafe.Pointer(pNode)).FpParent = pParent
		(*RtreeNode)(unsafe.Pointer(pNode)).FisDirty = 1
		nodeReference(tls, pParent)
	}
	return pNode
}

func nodeBlobReset(tls *libc.TLS, pRtree uintptr) {
	if (*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob != 0 && int32((*Rtree)(unsafe.Pointer(pRtree)).FinWrTrans) == 0 && (*Rtree)(unsafe.Pointer(pRtree)).FnCursor == U32(0) {
		var pBlob uintptr = (*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob
		(*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob = uintptr(0)
		Xsqlite3_blob_close(tls, pBlob)
	}
}

func nodeAcquire(tls *libc.TLS, pRtree uintptr, iNode I64, pParent uintptr, ppNode uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var pNode uintptr = uintptr(0)

	if libc.AssignUintptr(&pNode, nodeHashLookup(tls, pRtree, iNode)) != uintptr(0) {
		if pParent != 0 && pParent != (*RtreeNode)(unsafe.Pointer(pNode)).FpParent {
			return SQLITE_CORRUPT | int32(1)<<8
		}
		(*RtreeNode)(unsafe.Pointer(pNode)).FnRef++
		*(*uintptr)(unsafe.Pointer(ppNode)) = pNode
		return SQLITE_OK
	}

	if (*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob != 0 {
		var pBlob uintptr = (*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob
		(*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob = uintptr(0)
		rc = Xsqlite3_blob_reopen(tls, pBlob, iNode)
		(*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob = pBlob
		if rc != 0 {
			nodeBlobReset(tls, pRtree)
			if rc == SQLITE_NOMEM {
				return SQLITE_NOMEM
			}
		}
	}
	if (*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob == uintptr(0) {
		var zTab uintptr = Xsqlite3_mprintf(tls, ts+31336, libc.VaList(bp, (*Rtree)(unsafe.Pointer(pRtree)).FzName))
		if zTab == uintptr(0) {
			return SQLITE_NOMEM
		}
		rc = Xsqlite3_blob_open(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, zTab, ts+31344, iNode, 0,
			pRtree+112)
		Xsqlite3_free(tls, zTab)
	}
	if rc != 0 {
		nodeBlobReset(tls, pRtree)
		*(*uintptr)(unsafe.Pointer(ppNode)) = uintptr(0)

		if rc == SQLITE_ERROR {
			rc = SQLITE_CORRUPT | int32(1)<<8

		}
	} else if (*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize == Xsqlite3_blob_bytes(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob) {
		pNode = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(RtreeNode{}))+uint64((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize))
		if !(pNode != 0) {
			rc = SQLITE_NOMEM
		} else {
			(*RtreeNode)(unsafe.Pointer(pNode)).FpParent = pParent
			(*RtreeNode)(unsafe.Pointer(pNode)).FzData = pNode + 1*40
			(*RtreeNode)(unsafe.Pointer(pNode)).FnRef = 1
			(*Rtree)(unsafe.Pointer(pRtree)).FnNodeRef++
			(*RtreeNode)(unsafe.Pointer(pNode)).FiNode = iNode
			(*RtreeNode)(unsafe.Pointer(pNode)).FisDirty = 0
			(*RtreeNode)(unsafe.Pointer(pNode)).FpNext = uintptr(0)
			rc = Xsqlite3_blob_read(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpNodeBlob, (*RtreeNode)(unsafe.Pointer(pNode)).FzData,
				(*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize, 0)
		}
	}

	if rc == SQLITE_OK && pNode != 0 && iNode == int64(1) {
		(*Rtree)(unsafe.Pointer(pRtree)).FiDepth = readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData)
		if (*Rtree)(unsafe.Pointer(pRtree)).FiDepth > RTREE_MAX_DEPTH {
			rc = SQLITE_CORRUPT | int32(1)<<8

		}
	}

	if pNode != 0 && rc == SQLITE_OK {
		if readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2) > ((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize-4)/int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell) {
			rc = SQLITE_CORRUPT | int32(1)<<8

		}
	}

	if rc == SQLITE_OK {
		if pNode != uintptr(0) {
			nodeReference(tls, pParent)
			nodeHashInsert(tls, pRtree, pNode)
		} else {
			rc = SQLITE_CORRUPT | int32(1)<<8

		}
		*(*uintptr)(unsafe.Pointer(ppNode)) = pNode
	} else {
		if pNode != 0 {
			(*Rtree)(unsafe.Pointer(pRtree)).FnNodeRef--
			Xsqlite3_free(tls, pNode)
		}
		*(*uintptr)(unsafe.Pointer(ppNode)) = uintptr(0)
	}

	return rc
}

func nodeOverwriteCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr, iCell int32) {
	var ii int32
	var p uintptr = (*RtreeNode)(unsafe.Pointer(pNode)).FzData + uintptr(4+int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell)
	p += uintptr(writeInt64(tls, p, (*RtreeCell)(unsafe.Pointer(pCell)).FiRowid))
	for ii = 0; ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2); ii++ {
		p += uintptr(writeCoord(tls, p, pCell+8+uintptr(ii)*4))
	}
	(*RtreeNode)(unsafe.Pointer(pNode)).FisDirty = 1
}

func nodeDeleteCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32) {
	var pDst uintptr = (*RtreeNode)(unsafe.Pointer(pNode)).FzData + uintptr(4+int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell)
	var pSrc uintptr = pDst + uintptr((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)
	var nByte int32 = (readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2) - iCell - 1) * int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)
	libc.Xmemmove(tls, pDst, pSrc, uint64(nByte))
	writeInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2, readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2)-1)
	(*RtreeNode)(unsafe.Pointer(pNode)).FisDirty = 1
}

func nodeInsertCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr) int32 {
	var nCell int32
	var nMaxCell int32

	nMaxCell = ((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize - 4) / int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)
	nCell = readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2)

	if nCell < nMaxCell {
		nodeOverwriteCell(tls, pRtree, pNode, pCell, nCell)
		writeInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2, nCell+1)
		(*RtreeNode)(unsafe.Pointer(pNode)).FisDirty = 1
	}

	return libc.Bool32(nCell == nMaxCell)
}

func nodeWrite(tls *libc.TLS, pRtree uintptr, pNode uintptr) int32 {
	var rc int32 = SQLITE_OK
	if (*RtreeNode)(unsafe.Pointer(pNode)).FisDirty != 0 {
		var p uintptr = (*Rtree)(unsafe.Pointer(pRtree)).FpWriteNode
		if (*RtreeNode)(unsafe.Pointer(pNode)).FiNode != 0 {
			Xsqlite3_bind_int64(tls, p, 1, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode)
		} else {
			Xsqlite3_bind_null(tls, p, 1)
		}
		Xsqlite3_bind_blob(tls, p, 2, (*RtreeNode)(unsafe.Pointer(pNode)).FzData, (*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize, uintptr(0))
		Xsqlite3_step(tls, p)
		(*RtreeNode)(unsafe.Pointer(pNode)).FisDirty = 0
		rc = Xsqlite3_reset(tls, p)
		Xsqlite3_bind_null(tls, p, 2)
		if (*RtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(0) && rc == SQLITE_OK {
			(*RtreeNode)(unsafe.Pointer(pNode)).FiNode = Xsqlite3_last_insert_rowid(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb)
			nodeHashInsert(tls, pRtree, pNode)
		}
	}
	return rc
}

func nodeRelease(tls *libc.TLS, pRtree uintptr, pNode uintptr) int32 {
	var rc int32 = SQLITE_OK
	if pNode != 0 {
		(*RtreeNode)(unsafe.Pointer(pNode)).FnRef--
		if (*RtreeNode)(unsafe.Pointer(pNode)).FnRef == 0 {
			(*Rtree)(unsafe.Pointer(pRtree)).FnNodeRef--
			if (*RtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
				(*Rtree)(unsafe.Pointer(pRtree)).FiDepth = -1
			}
			if (*RtreeNode)(unsafe.Pointer(pNode)).FpParent != 0 {
				rc = nodeRelease(tls, pRtree, (*RtreeNode)(unsafe.Pointer(pNode)).FpParent)
			}
			if rc == SQLITE_OK {
				rc = nodeWrite(tls, pRtree, pNode)
			}
			nodeHashDelete(tls, pRtree, pNode)
			Xsqlite3_free(tls, pNode)
		}
	}
	return rc
}

func nodeGetRowid(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32) I64 {
	return readInt64(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+uintptr(4+int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell))
}

func nodeGetCoord(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32, iCoord int32, pCoord uintptr) {
	readCoord(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+uintptr(12+int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell+4*iCoord), pCoord)
}

func nodeGetCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32, pCell uintptr) {
	var pData uintptr
	var pCoord uintptr
	var ii int32 = 0
	(*RtreeCell)(unsafe.Pointer(pCell)).FiRowid = nodeGetRowid(tls, pRtree, pNode, iCell)
	pData = (*RtreeNode)(unsafe.Pointer(pNode)).FzData + uintptr(12+int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*iCell)
	pCoord = pCell + 8
	for __ccgo := true; __ccgo; __ccgo = ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2) {
		readCoord(tls, pData, pCoord+uintptr(ii)*4)
		readCoord(tls, pData+uintptr(4), pCoord+uintptr(ii+1)*4)
		pData += uintptr(8)
		ii = ii + 2
	}
}

func rtreeCreate(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	return rtreeInit(tls, db, pAux, argc, argv, ppVtab, pzErr, 1)
}

func rtreeConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	return rtreeInit(tls, db, pAux, argc, argv, ppVtab, pzErr, 0)
}

func rtreeReference(tls *libc.TLS, pRtree uintptr) {
	(*Rtree)(unsafe.Pointer(pRtree)).FnBusy++
}

func rtreeRelease(tls *libc.TLS, pRtree uintptr) {
	(*Rtree)(unsafe.Pointer(pRtree)).FnBusy--
	if (*Rtree)(unsafe.Pointer(pRtree)).FnBusy == U32(0) {
		(*Rtree)(unsafe.Pointer(pRtree)).FinWrTrans = U8(0)

		nodeBlobReset(tls, pRtree)

		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteNode)
		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteNode)
		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid)
		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteRowid)
		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadParent)
		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteParent)
		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteParent)
		Xsqlite3_finalize(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteAux)
		Xsqlite3_free(tls, (*Rtree)(unsafe.Pointer(pRtree)).FzReadAuxSql)
		Xsqlite3_free(tls, pRtree)
	}
}

func rtreeDisconnect(tls *libc.TLS, pVtab uintptr) int32 {
	rtreeRelease(tls, pVtab)
	return SQLITE_OK
}

func rtreeDestroy(tls *libc.TLS, pVtab uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var pRtree uintptr = pVtab
	var rc int32
	var zCreate uintptr = Xsqlite3_mprintf(tls,
		ts+31349,
		libc.VaList(bp, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName,
			(*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName,
			(*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName))
	if !(zCreate != 0) {
		rc = SQLITE_NOMEM
	} else {
		nodeBlobReset(tls, pRtree)
		rc = Xsqlite3_exec(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb, zCreate, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zCreate)
	}
	if rc == SQLITE_OK {
		rtreeRelease(tls, pRtree)
	}

	return rc
}

func rtreeOpen(tls *libc.TLS, pVTab uintptr, ppCursor uintptr) int32 {
	var rc int32 = SQLITE_NOMEM
	var pRtree uintptr = pVTab
	var pCsr uintptr

	pCsr = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(RtreeCursor{})))
	if pCsr != 0 {
		libc.Xmemset(tls, pCsr, 0, uint64(unsafe.Sizeof(RtreeCursor{})))
		(*RtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVTab
		rc = SQLITE_OK
		(*Rtree)(unsafe.Pointer(pRtree)).FnCursor++
	}
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCsr

	return rc
}

func resetCursor(tls *libc.TLS, pCsr uintptr) {
	var pRtree uintptr = (*RtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	var ii int32
	var pStmt uintptr
	if (*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint != 0 {
		var i int32
		for i = 0; i < (*RtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint; i++ {
			var pInfo uintptr = (*RtreeConstraint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint + uintptr(i)*24)).FpInfo
			if pInfo != 0 {
				if (*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FxDelUser != 0 {
					(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FxDelUser})).f(tls, (*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FpUser)
				}
				Xsqlite3_free(tls, pInfo)
			}
		}
		Xsqlite3_free(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint)
		(*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = uintptr(0)
	}
	for ii = 0; ii < RTREE_CACHE_SZ; ii++ {
		nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(pCsr + 88 + uintptr(ii)*8)))
	}
	Xsqlite3_free(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FaPoint)
	pStmt = (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux
	libc.Xmemset(tls, pCsr, 0, uint64(unsafe.Sizeof(RtreeCursor{})))
	(*RtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pRtree
	(*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux = pStmt

}

func rtreeClose(tls *libc.TLS, cur uintptr) int32 {
	var pRtree uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	var pCsr uintptr = cur

	resetCursor(tls, pCsr)
	Xsqlite3_finalize(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
	Xsqlite3_free(tls, pCsr)
	(*Rtree)(unsafe.Pointer(pRtree)).FnCursor--
	nodeBlobReset(tls, pRtree)
	return SQLITE_OK
}

func rtreeEof(tls *libc.TLS, cur uintptr) int32 {
	var pCsr uintptr = cur
	return int32((*RtreeCursor)(unsafe.Pointer(pCsr)).FatEOF)
}

func rtreeCallbackConstraint(tls *libc.TLS, pConstraint uintptr, eInt int32, pCellData uintptr, pSearch uintptr, prScore uintptr, peWithin uintptr) int32 {
	bp := tls.Alloc(92)
	defer tls.Free(92)

	var pInfo uintptr = (*RtreeConstraint)(unsafe.Pointer(pConstraint)).FpInfo
	var nCoord int32 = (*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FnCoord
	var rc int32

	if (*RtreeConstraint)(unsafe.Pointer(pConstraint)).Fop == RTREE_QUERY && int32((*RtreeSearchPoint)(unsafe.Pointer(pSearch)).FiLevel) == 1 {
		(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FiRowid = readInt64(tls, pCellData)
	}
	pCellData += uintptr(8)
	if eInt == 0 {
		switch nCoord {
		case 10:
			readCoord(tls, pCellData+uintptr(36), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 9*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData+uintptr(32), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 8*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			fallthrough
		case 8:
			readCoord(tls, pCellData+uintptr(28), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 7*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData+uintptr(24), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 6*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			fallthrough
		case 6:
			readCoord(tls, pCellData+uintptr(20), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 5*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData+uintptr(16), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 4*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			fallthrough
		case 4:
			readCoord(tls, pCellData+uintptr(12), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 3*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData+uintptr(8), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 2*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			fallthrough
		default:
			readCoord(tls, pCellData+uintptr(4), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 1*8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData, bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)) = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
		}
	} else {
		switch nCoord {
		case 10:
			readCoord(tls, pCellData+uintptr(36), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 9*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData+uintptr(32), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 8*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			fallthrough
		case 8:
			readCoord(tls, pCellData+uintptr(28), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 7*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData+uintptr(24), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 6*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			fallthrough
		case 6:
			readCoord(tls, pCellData+uintptr(20), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 5*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData+uintptr(16), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 4*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			fallthrough
		case 4:
			readCoord(tls, pCellData+uintptr(12), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 3*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData+uintptr(8), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 2*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			fallthrough
		default:
			readCoord(tls, pCellData+uintptr(4), bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8 + 1*8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			readCoord(tls, pCellData, bp)
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)) = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
		}
	}
	if (*RtreeConstraint)(unsafe.Pointer(pConstraint)).Fop == RTREE_MATCH {
		*(*int32)(unsafe.Pointer(bp + 88)) = 0
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(pConstraint + 8))})).f(tls, pInfo,
			nCoord, bp+8, bp+88)
		if *(*int32)(unsafe.Pointer(bp + 88)) == 0 {
			*(*int32)(unsafe.Pointer(peWithin)) = NOT_WITHIN
		}
		*(*Sqlite3_rtree_dbl)(unsafe.Pointer(prScore)) = 0.0
	} else {
		(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FaCoord = bp + 8
		(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FiLevel = int32((*RtreeSearchPoint)(unsafe.Pointer(pSearch)).FiLevel) - 1
		(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FrScore = libc.AssignPtrFloat64(pInfo+80, (*RtreeSearchPoint)(unsafe.Pointer(pSearch)).FrScore)
		(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FeWithin = libc.AssignPtrInt32(pInfo+88, int32((*RtreeSearchPoint)(unsafe.Pointer(pSearch)).FeWithin))
		rc = (*struct {
			f func(*libc.TLS, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{*(*uintptr)(unsafe.Pointer(pConstraint + 8))})).f(tls, pInfo)
		if (*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FeWithin < *(*int32)(unsafe.Pointer(peWithin)) {
			*(*int32)(unsafe.Pointer(peWithin)) = (*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FeWithin
		}
		if (*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FrScore < *(*Sqlite3_rtree_dbl)(unsafe.Pointer(prScore)) || *(*Sqlite3_rtree_dbl)(unsafe.Pointer(prScore)) < 0.0 {
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(prScore)) = (*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FrScore
		}
	}
	return rc
}

func rtreeNonleafConstraint(tls *libc.TLS, p uintptr, eInt int32, pCellData uintptr, peWithin uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var val Sqlite3_rtree_dbl

	pCellData += uintptr(8 + 4*((*RtreeConstraint)(unsafe.Pointer(p)).FiCoord&0xfe))

	switch (*RtreeConstraint)(unsafe.Pointer(p)).Fop {
	case RTREE_TRUE:
		return
	case RTREE_FALSE:
		break
	case RTREE_EQ:
		{
			*(*U32)(unsafe.Pointer(bp)) = libc.X__builtin_bswap32(tls, *(*U32)(unsafe.Pointer(pCellData)))
			if eInt != 0 {
				val = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
			} else {
				val = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
			}
		}

		if *(*RtreeDValue)(unsafe.Pointer(p + 8)) >= val {
			pCellData += uintptr(4)
			{
				*(*U32)(unsafe.Pointer(bp + 4)) = libc.X__builtin_bswap32(tls, *(*U32)(unsafe.Pointer(pCellData)))
				if eInt != 0 {
					val = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp + 4)))
				} else {
					val = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp + 4)))
				}
			}

			if *(*RtreeDValue)(unsafe.Pointer(p + 8)) <= val {
				return
			}
		}
		break
	case RTREE_LE:
		fallthrough
	case RTREE_LT:
		{
			*(*U32)(unsafe.Pointer(bp + 8)) = libc.X__builtin_bswap32(tls, *(*U32)(unsafe.Pointer(pCellData)))
			if eInt != 0 {
				val = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp + 8)))
			} else {
				val = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp + 8)))
			}
		}

		if *(*RtreeDValue)(unsafe.Pointer(p + 8)) >= val {
			return
		}
		break

	default:
		pCellData += uintptr(4)
		{
			*(*U32)(unsafe.Pointer(bp + 12)) = libc.X__builtin_bswap32(tls, *(*U32)(unsafe.Pointer(pCellData)))
			if eInt != 0 {
				val = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp + 12)))
			} else {
				val = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp + 12)))
			}
		}

		if *(*RtreeDValue)(unsafe.Pointer(p + 8)) <= val {
			return
		}
		break
	}
	*(*int32)(unsafe.Pointer(peWithin)) = NOT_WITHIN
}

func rtreeLeafConstraint(tls *libc.TLS, p uintptr, eInt int32, pCellData uintptr, peWithin uintptr) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var xN RtreeDValue

	pCellData += uintptr(8 + (*RtreeConstraint)(unsafe.Pointer(p)).FiCoord*4)

	{
		*(*U32)(unsafe.Pointer(bp)) = libc.X__builtin_bswap32(tls, *(*U32)(unsafe.Pointer(pCellData)))
		if eInt != 0 {
			xN = Sqlite3_rtree_dbl(*(*int32)(unsafe.Pointer(bp)))
		} else {
			xN = Sqlite3_rtree_dbl(*(*RtreeValue)(unsafe.Pointer(bp)))
		}
	}

	switch (*RtreeConstraint)(unsafe.Pointer(p)).Fop {
	case RTREE_TRUE:
		return
	case RTREE_FALSE:
		break
	case RTREE_LE:
		if xN <= *(*RtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
		break
	case RTREE_LT:
		if xN < *(*RtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
		break
	case RTREE_GE:
		if xN >= *(*RtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
		break
	case RTREE_GT:
		if xN > *(*RtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
		break
	default:
		if xN == *(*RtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
		break
	}
	*(*int32)(unsafe.Pointer(peWithin)) = NOT_WITHIN
}

func nodeRowidIndex(tls *libc.TLS, pRtree uintptr, pNode uintptr, iRowid I64, piIndex uintptr) int32 {
	var ii int32
	var nCell int32 = readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2)

	for ii = 0; ii < nCell; ii++ {
		if nodeGetRowid(tls, pRtree, pNode, ii) == iRowid {
			*(*int32)(unsafe.Pointer(piIndex)) = ii
			return SQLITE_OK
		}
	}

	return SQLITE_CORRUPT | int32(1)<<8
}

func nodeParentIndex(tls *libc.TLS, pRtree uintptr, pNode uintptr, piIndex uintptr) int32 {
	var pParent uintptr = (*RtreeNode)(unsafe.Pointer(pNode)).FpParent
	if pParent != 0 {
		return nodeRowidIndex(tls, pRtree, pParent, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode, piIndex)
	} else {
		*(*int32)(unsafe.Pointer(piIndex)) = -1
		return SQLITE_OK
	}
	return int32(0)
}

func rtreeSearchPointCompare(tls *libc.TLS, pA uintptr, pB uintptr) int32 {
	if (*RtreeSearchPoint)(unsafe.Pointer(pA)).FrScore < (*RtreeSearchPoint)(unsafe.Pointer(pB)).FrScore {
		return -1
	}
	if (*RtreeSearchPoint)(unsafe.Pointer(pA)).FrScore > (*RtreeSearchPoint)(unsafe.Pointer(pB)).FrScore {
		return +1
	}
	if int32((*RtreeSearchPoint)(unsafe.Pointer(pA)).FiLevel) < int32((*RtreeSearchPoint)(unsafe.Pointer(pB)).FiLevel) {
		return -1
	}
	if int32((*RtreeSearchPoint)(unsafe.Pointer(pA)).FiLevel) > int32((*RtreeSearchPoint)(unsafe.Pointer(pB)).FiLevel) {
		return +1
	}
	return 0
}

func rtreeSearchPointSwap(tls *libc.TLS, p uintptr, i int32, j int32) {
	var t = *(*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(i)*24))

	*(*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(i)*24)) = *(*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(j)*24))
	*(*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(j)*24)) = t
	i++
	j++
	if i < RTREE_CACHE_SZ {
		if j >= RTREE_CACHE_SZ {
			nodeRelease(tls, (*RtreeCursor)(unsafe.Pointer(p)).Fbase.FpVtab, *(*uintptr)(unsafe.Pointer(p + 88 + uintptr(i)*8)))
			*(*uintptr)(unsafe.Pointer(p + 88 + uintptr(i)*8)) = uintptr(0)
		} else {
			var pTemp uintptr = *(*uintptr)(unsafe.Pointer(p + 88 + uintptr(i)*8))
			*(*uintptr)(unsafe.Pointer(p + 88 + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer(p + 88 + uintptr(j)*8))
			*(*uintptr)(unsafe.Pointer(p + 88 + uintptr(j)*8)) = pTemp
		}
	}
}

func rtreeSearchPointFirst(tls *libc.TLS, pCur uintptr) uintptr {
	if (*RtreeCursor)(unsafe.Pointer(pCur)).FbPoint != 0 {
		return pCur + 64
	}
	if (*RtreeCursor)(unsafe.Pointer(pCur)).FnPoint != 0 {
		return (*RtreeCursor)(unsafe.Pointer(pCur)).FaPoint
	}
	return uintptr(0)
}

func rtreeNodeOfFirstSearchPoint(tls *libc.TLS, pCur uintptr, pRC uintptr) uintptr {
	var id Sqlite3_int64
	var ii int32 = 1 - int32((*RtreeCursor)(unsafe.Pointer(pCur)).FbPoint)

	if *(*uintptr)(unsafe.Pointer(pCur + 88 + uintptr(ii)*8)) == uintptr(0) {
		if ii != 0 {
			id = (*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(pCur)).FaPoint)).Fid
		} else {
			id = (*RtreeCursor)(unsafe.Pointer(pCur)).FsPoint.Fid
		}
		*(*int32)(unsafe.Pointer(pRC)) = nodeAcquire(tls, (*RtreeCursor)(unsafe.Pointer(pCur)).Fbase.FpVtab, id, uintptr(0), pCur+88+uintptr(ii)*8)
	}
	return *(*uintptr)(unsafe.Pointer(pCur + 88 + uintptr(ii)*8))
}

func rtreeEnqueue(tls *libc.TLS, pCur uintptr, rScore RtreeDValue, iLevel U8) uintptr {
	var i int32
	var j int32
	var pNew uintptr
	if (*RtreeCursor)(unsafe.Pointer(pCur)).FnPoint >= (*RtreeCursor)(unsafe.Pointer(pCur)).FnPointAlloc {
		var nNew int32 = (*RtreeCursor)(unsafe.Pointer(pCur)).FnPointAlloc*2 + 8
		pNew = Xsqlite3_realloc64(tls, (*RtreeCursor)(unsafe.Pointer(pCur)).FaPoint, uint64(nNew)*uint64(unsafe.Sizeof(RtreeSearchPoint{})))
		if pNew == uintptr(0) {
			return uintptr(0)
		}
		(*RtreeCursor)(unsafe.Pointer(pCur)).FaPoint = pNew
		(*RtreeCursor)(unsafe.Pointer(pCur)).FnPointAlloc = nNew
	}
	i = libc.PostIncInt32(&(*RtreeCursor)(unsafe.Pointer(pCur)).FnPoint, 1)
	pNew = (*RtreeCursor)(unsafe.Pointer(pCur)).FaPoint + uintptr(i)*24
	(*RtreeSearchPoint)(unsafe.Pointer(pNew)).FrScore = rScore
	(*RtreeSearchPoint)(unsafe.Pointer(pNew)).FiLevel = iLevel

	for i > 0 {
		var pParent uintptr
		j = (i - 1) / 2
		pParent = (*RtreeCursor)(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
}

func rtreeSearchPointNew(tls *libc.TLS, pCur uintptr, rScore RtreeDValue, iLevel U8) uintptr {
	var pNew uintptr
	var pFirst uintptr
	pFirst = rtreeSearchPointFirst(tls, pCur)
	*(*U32)(unsafe.Pointer(pCur + 128 + uintptr(iLevel)*4))++
	if pFirst == uintptr(0) ||
		(*RtreeSearchPoint)(unsafe.Pointer(pFirst)).FrScore > rScore ||
		(*RtreeSearchPoint)(unsafe.Pointer(pFirst)).FrScore == rScore && int32((*RtreeSearchPoint)(unsafe.Pointer(pFirst)).FiLevel) > int32(iLevel) {
		if (*RtreeCursor)(unsafe.Pointer(pCur)).FbPoint != 0 {
			var ii int32
			pNew = rtreeEnqueue(tls, pCur, rScore, iLevel)
			if pNew == uintptr(0) {
				return uintptr(0)
			}
			ii = int32((int64(pNew)-int64((*RtreeCursor)(unsafe.Pointer(pCur)).FaPoint))/24) + 1

			if ii < RTREE_CACHE_SZ {
				*(*uintptr)(unsafe.Pointer(pCur + 88 + uintptr(ii)*8)) = *(*uintptr)(unsafe.Pointer(pCur + 88))
			} else {
				nodeRelease(tls, (*RtreeCursor)(unsafe.Pointer(pCur)).Fbase.FpVtab, *(*uintptr)(unsafe.Pointer(pCur + 88)))
			}
			*(*uintptr)(unsafe.Pointer(pCur + 88)) = uintptr(0)
			*(*RtreeSearchPoint)(unsafe.Pointer(pNew)) = (*RtreeCursor)(unsafe.Pointer(pCur)).FsPoint
		}
		(*RtreeCursor)(unsafe.Pointer(pCur)).FsPoint.FrScore = rScore
		(*RtreeCursor)(unsafe.Pointer(pCur)).FsPoint.FiLevel = iLevel
		(*RtreeCursor)(unsafe.Pointer(pCur)).FbPoint = U8(1)
		return pCur + 64
	} else {
		return rtreeEnqueue(tls, pCur, rScore, iLevel)
	}
	return uintptr(0)
}

func rtreeSearchPointPop(tls *libc.TLS, p uintptr) {
	var i int32
	var j int32
	var k int32
	var n int32
	i = 1 - int32((*RtreeCursor)(unsafe.Pointer(p)).FbPoint)

	if *(*uintptr)(unsafe.Pointer(p + 88 + uintptr(i)*8)) != 0 {
		nodeRelease(tls, (*RtreeCursor)(unsafe.Pointer(p)).Fbase.FpVtab, *(*uintptr)(unsafe.Pointer(p + 88 + uintptr(i)*8)))
		*(*uintptr)(unsafe.Pointer(p + 88 + uintptr(i)*8)) = uintptr(0)
	}
	if (*RtreeCursor)(unsafe.Pointer(p)).FbPoint != 0 {
		*(*U32)(unsafe.Pointer(p + 128 + uintptr((*RtreeCursor)(unsafe.Pointer(p)).FsPoint.FiLevel)*4))--
		(*RtreeCursor)(unsafe.Pointer(p)).FbPoint = U8(0)
	} else if (*RtreeCursor)(unsafe.Pointer(p)).FnPoint != 0 {
		*(*U32)(unsafe.Pointer(p + 128 + uintptr((*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(p)).FaPoint)).FiLevel)*4))--
		n = libc.PreDecInt32(&(*RtreeCursor)(unsafe.Pointer(p)).FnPoint, 1)
		*(*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(p)).FaPoint)) = *(*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(p)).FaPoint + uintptr(n)*24))
		if n < RTREE_CACHE_SZ-1 {
			*(*uintptr)(unsafe.Pointer(p + 88 + 1*8)) = *(*uintptr)(unsafe.Pointer(p + 88 + uintptr(n+1)*8))
			*(*uintptr)(unsafe.Pointer(p + 88 + uintptr(n+1)*8)) = uintptr(0)
		}
		i = 0
		for libc.AssignInt32(&j, i*2+1) < n {
			k = j + 1
			if k < n && rtreeSearchPointCompare(tls, (*RtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(k)*24, (*RtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(j)*24) < 0 {
				if rtreeSearchPointCompare(tls, (*RtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(k)*24, (*RtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(i)*24) < 0 {
					rtreeSearchPointSwap(tls, p, i, k)
					i = k
				} else {
					break
				}
			} else {
				if rtreeSearchPointCompare(tls, (*RtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(j)*24, (*RtreeCursor)(unsafe.Pointer(p)).FaPoint+uintptr(i)*24) < 0 {
					rtreeSearchPointSwap(tls, p, i, j)
					i = j
				} else {
					break
				}
			}
		}
	}
}

func rtreeStepToLeaf(tls *libc.TLS, pCur uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var p uintptr
	var pRtree uintptr = (*RtreeCursor)(unsafe.Pointer(pCur)).Fbase.FpVtab
	var pNode uintptr

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var nCell int32
	var nConstraint int32 = (*RtreeCursor)(unsafe.Pointer(pCur)).FnConstraint
	var ii int32
	var eInt int32
	var x RtreeSearchPoint

	eInt = libc.Bool32(int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_INT32)
	for libc.AssignUintptr(&p, rtreeSearchPointFirst(tls, pCur)) != uintptr(0) && int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiLevel) > 0 {
		var pCellData uintptr
		pNode = rtreeNodeOfFirstSearchPoint(tls, pCur, bp)
		if *(*int32)(unsafe.Pointer(bp)) != 0 {
			return *(*int32)(unsafe.Pointer(bp))
		}
		nCell = readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2)

		pCellData = (*RtreeNode)(unsafe.Pointer(pNode)).FzData + uintptr(4+int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell))
		for int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell) < nCell {
			*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)) = Sqlite3_rtree_dbl(-1)
			*(*int32)(unsafe.Pointer(bp + 16)) = FULLY_WITHIN
			for ii = 0; ii < nConstraint; ii++ {
				var pConstraint uintptr = (*RtreeCursor)(unsafe.Pointer(pCur)).FaConstraint + uintptr(ii)*24
				if (*RtreeConstraint)(unsafe.Pointer(pConstraint)).Fop >= RTREE_MATCH {
					*(*int32)(unsafe.Pointer(bp)) = rtreeCallbackConstraint(tls, pConstraint, eInt, pCellData, p,
						bp+8, bp+16)
					if *(*int32)(unsafe.Pointer(bp)) != 0 {
						return *(*int32)(unsafe.Pointer(bp))
					}
				} else if int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiLevel) == 1 {
					rtreeLeafConstraint(tls, pConstraint, eInt, pCellData, bp+16)
				} else {
					rtreeNonleafConstraint(tls, pConstraint, eInt, pCellData, bp+16)
				}
				if *(*int32)(unsafe.Pointer(bp + 16)) == NOT_WITHIN {
					(*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell++
					pCellData += uintptr((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)
					break
				}
			}
			if *(*int32)(unsafe.Pointer(bp + 16)) == NOT_WITHIN {
				continue
			}
			(*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell++
			x.FiLevel = U8(int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiLevel) - 1)
			if x.FiLevel != 0 {
				x.Fid = readInt64(tls, pCellData)
				for ii = 0; ii < (*RtreeCursor)(unsafe.Pointer(pCur)).FnPoint; ii++ {
					if (*RtreeSearchPoint)(unsafe.Pointer((*RtreeCursor)(unsafe.Pointer(pCur)).FaPoint+uintptr(ii)*24)).Fid == x.Fid {
						return SQLITE_CORRUPT | int32(1)<<8
					}
				}
				x.FiCell = U8(0)
			} else {
				x.Fid = (*RtreeSearchPoint)(unsafe.Pointer(p)).Fid
				x.FiCell = U8(int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell) - 1)
			}
			if int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell) >= nCell {
				rtreeSearchPointPop(tls, pCur)
			}
			if *(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)) < 0.0 {
				*(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)) = 0.0
			}
			p = rtreeSearchPointNew(tls, pCur, *(*Sqlite3_rtree_dbl)(unsafe.Pointer(bp + 8)), x.FiLevel)
			if p == uintptr(0) {
				return SQLITE_NOMEM
			}
			(*RtreeSearchPoint)(unsafe.Pointer(p)).FeWithin = U8(*(*int32)(unsafe.Pointer(bp + 16)))
			(*RtreeSearchPoint)(unsafe.Pointer(p)).Fid = x.Fid
			(*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell = x.FiCell

			break
		}
		if int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell) >= nCell {
			rtreeSearchPointPop(tls, pCur)
		}
	}
	(*RtreeCursor)(unsafe.Pointer(pCur)).FatEOF = U8(libc.Bool32(p == uintptr(0)))
	return SQLITE_OK
}

func rtreeNext(tls *libc.TLS, pVtabCursor uintptr) int32 {
	var pCsr uintptr = pVtabCursor
	var rc int32 = SQLITE_OK

	if (*RtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid != 0 {
		(*RtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid = U8(0)
		Xsqlite3_reset(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
	}
	rtreeSearchPointPop(tls, pCsr)
	rc = rtreeStepToLeaf(tls, pCsr)
	return rc
}

func rtreeRowid(tls *libc.TLS, pVtabCursor uintptr, pRowid uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pCsr uintptr = pVtabCursor
	var p uintptr = rtreeSearchPointFirst(tls, pCsr)
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var pNode uintptr = rtreeNodeOfFirstSearchPoint(tls, pCsr, bp)
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && p != 0 {
		*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = nodeGetRowid(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab, pNode, int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell))
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func rtreeColumn(tls *libc.TLS, cur uintptr, ctx uintptr, i int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pRtree uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	var pCsr uintptr = cur
	var p uintptr = rtreeSearchPointFirst(tls, pCsr)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var pNode uintptr = 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_result_int64(tls, ctx, nodeGetRowid(tls, pRtree, pNode, int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell)))
	} else if i <= int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2) {
		nodeGetCoord(tls, pRtree, pNode, int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell), i-1, bp+4)
		if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
			Xsqlite3_result_double(tls, ctx, float64(*(*RtreeValue)(unsafe.Pointer(bp + 4))))
		} else {
			Xsqlite3_result_int(tls, ctx, *(*int32)(unsafe.Pointer(bp + 4)))
		}
	} else {
		if !(int32((*RtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid) != 0) {
			if (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v3(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb, (*Rtree)(unsafe.Pointer(pRtree)).FzReadAuxSql, -1, uint32(0),
					pCsr+56, uintptr(0))
				if *(*int32)(unsafe.Pointer(bp)) != 0 {
					return *(*int32)(unsafe.Pointer(bp))
				}
			}
			Xsqlite3_bind_int64(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux, 1,
				nodeGetRowid(tls, pRtree, pNode, int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell)))
			*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_step(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_ROW {
				(*RtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid = U8(1)
			} else {
				Xsqlite3_reset(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
				if *(*int32)(unsafe.Pointer(bp)) == SQLITE_DONE {
					*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
				}
				return *(*int32)(unsafe.Pointer(bp))
			}
		}
		Xsqlite3_result_value(tls, ctx,
			Xsqlite3_column_value(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux, i-int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2)+1))
	}
	return SQLITE_OK
}

func findLeafNode(tls *libc.TLS, pRtree uintptr, iRowid I64, ppLeaf uintptr, piNode uintptr) int32 {
	var rc int32
	*(*uintptr)(unsafe.Pointer(ppLeaf)) = uintptr(0)
	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid, 1, iRowid)
	if Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid) == SQLITE_ROW {
		var iNode I64 = Xsqlite3_column_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid, 0)
		if piNode != 0 {
			*(*Sqlite3_int64)(unsafe.Pointer(piNode)) = iNode
		}
		rc = nodeAcquire(tls, pRtree, iNode, uintptr(0), ppLeaf)
		Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid)
	} else {
		rc = Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid)
	}
	return rc
}

func deserializeGeometry(tls *libc.TLS, pValue uintptr, pCons uintptr) int32 {
	var pBlob uintptr
	var pSrc uintptr
	var pInfo uintptr

	pSrc = Xsqlite3_value_pointer(tls, pValue, ts+31431)
	if pSrc == uintptr(0) {
		return SQLITE_ERROR
	}
	pInfo = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Sqlite3_rtree_query_info{}))+uint64((*RtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize))
	if !(pInfo != 0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pInfo, 0, uint64(unsafe.Sizeof(Sqlite3_rtree_query_info{})))
	pBlob = pInfo + 1*112
	libc.Xmemcpy(tls, pBlob, pSrc, uint64((*RtreeMatchArg)(unsafe.Pointer(pSrc)).FiSize))
	(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FpContext = (*RtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FpContext
	(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FnParam = (*RtreeMatchArg)(unsafe.Pointer(pBlob)).FnParam
	(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FaParam = pBlob + 56
	(*Sqlite3_rtree_query_info)(unsafe.Pointer(pInfo)).FapSqlParam = (*RtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam

	if (*RtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom != 0 {
		*(*uintptr)(unsafe.Pointer(pCons + 8)) = (*RtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxGeom
	} else {
		(*RtreeConstraint)(unsafe.Pointer(pCons)).Fop = RTREE_QUERY
		*(*uintptr)(unsafe.Pointer(pCons + 8)) = (*RtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb.FxQueryFunc
	}
	(*RtreeConstraint)(unsafe.Pointer(pCons)).FpInfo = pInfo
	return SQLITE_OK
}

func rtreeFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pRtree uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	var pCsr uintptr = pVtabCursor
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
	var ii int32
	var rc int32 = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 16)) = 0

	rtreeReference(tls, pRtree)

	resetCursor(tls, pCsr)

	(*RtreeCursor)(unsafe.Pointer(pCsr)).FiStrategy = idxNum
	if idxNum == 1 {
		var p uintptr
		var iRowid I64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
		*(*I64)(unsafe.Pointer(bp + 8)) = int64(0)
		var eType int32 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv)))
		if eType == SQLITE_INTEGER ||
			eType == SQLITE_FLOAT && Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv))) == float64(iRowid) {
			rc = findLeafNode(tls, pRtree, iRowid, bp, bp+8)
		} else {
			rc = SQLITE_OK
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		}
		if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp)) != uintptr(0) {
			p = rtreeSearchPointNew(tls, pCsr, 0.0, uint8(0))

			*(*uintptr)(unsafe.Pointer(pCsr + 88)) = *(*uintptr)(unsafe.Pointer(bp))
			(*RtreeSearchPoint)(unsafe.Pointer(p)).Fid = *(*I64)(unsafe.Pointer(bp + 8))
			(*RtreeSearchPoint)(unsafe.Pointer(p)).FeWithin = U8(PARTLY_WITHIN)
			rc = nodeRowidIndex(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), iRowid, bp+16)
			(*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell = U8(*(*int32)(unsafe.Pointer(bp + 16)))

		} else {
			(*RtreeCursor)(unsafe.Pointer(pCsr)).FatEOF = U8(1)
		}
	} else {
		rc = nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp+24)
		if rc == SQLITE_OK && argc > 0 {
			(*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(RtreeConstraint{}))*uint64(argc))
			(*RtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint = argc
			if !(int32((*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint) != 0) {
				rc = SQLITE_NOMEM
			} else {
				libc.Xmemset(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint, 0, uint64(unsafe.Sizeof(RtreeConstraint{}))*uint64(argc))
				libc.Xmemset(tls, pCsr+128, 0, uint64(unsafe.Sizeof(U32(0)))*uint64((*Rtree)(unsafe.Pointer(pRtree)).FiDepth+1))

				for ii = 0; ii < argc; ii++ {
					var p uintptr = (*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint + uintptr(ii)*24
					var eType int32 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*8)))
					(*RtreeConstraint)(unsafe.Pointer(p)).Fop = int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(ii*2))))
					(*RtreeConstraint)(unsafe.Pointer(p)).FiCoord = int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(ii*2+1)))) - '0'
					if (*RtreeConstraint)(unsafe.Pointer(p)).Fop >= RTREE_MATCH {
						rc = deserializeGeometry(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*8)), p)
						if rc != SQLITE_OK {
							break
						}
						(*Sqlite3_rtree_query_info)(unsafe.Pointer((*RtreeConstraint)(unsafe.Pointer(p)).FpInfo)).FnCoord = int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2)
						(*Sqlite3_rtree_query_info)(unsafe.Pointer((*RtreeConstraint)(unsafe.Pointer(p)).FpInfo)).FanQueue = pCsr + 128
						(*Sqlite3_rtree_query_info)(unsafe.Pointer((*RtreeConstraint)(unsafe.Pointer(p)).FpInfo)).FmxLevel = (*Rtree)(unsafe.Pointer(pRtree)).FiDepth + 1
					} else if eType == SQLITE_INTEGER || eType == SQLITE_FLOAT {
						*(*RtreeDValue)(unsafe.Pointer(p + 8)) = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*8)))
					} else {
						*(*RtreeDValue)(unsafe.Pointer(p + 8)) = 0.0
						if eType == SQLITE_NULL {
							(*RtreeConstraint)(unsafe.Pointer(p)).Fop = RTREE_FALSE
						} else if (*RtreeConstraint)(unsafe.Pointer(p)).Fop == RTREE_LT || (*RtreeConstraint)(unsafe.Pointer(p)).Fop == RTREE_LE {
							(*RtreeConstraint)(unsafe.Pointer(p)).Fop = RTREE_TRUE
						} else {
							(*RtreeConstraint)(unsafe.Pointer(p)).Fop = RTREE_FALSE
						}
					}
				}
			}
		}
		if rc == SQLITE_OK {
			var pNew uintptr

			pNew = rtreeSearchPointNew(tls, pCsr, 0.0, U8((*Rtree)(unsafe.Pointer(pRtree)).FiDepth+1))
			if pNew == uintptr(0) {
				return SQLITE_NOMEM
			}
			(*RtreeSearchPoint)(unsafe.Pointer(pNew)).Fid = int64(1)
			(*RtreeSearchPoint)(unsafe.Pointer(pNew)).FiCell = U8(0)
			(*RtreeSearchPoint)(unsafe.Pointer(pNew)).FeWithin = U8(PARTLY_WITHIN)

			*(*uintptr)(unsafe.Pointer(pCsr + 88)) = *(*uintptr)(unsafe.Pointer(bp + 24))
			*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)

			rc = rtreeStepToLeaf(tls, pCsr)
		}
	}

	nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 24)))
	rtreeRelease(tls, pRtree)
	return rc
}

func rtreeBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) int32 {
	bp := tls.Alloc(49)
	defer tls.Free(49)

	var pRtree uintptr = tab
	var rc int32 = SQLITE_OK
	var ii int32
	var bMatch int32 = 0
	var nRow I64

	var iIdx int32 = 0

	libc.Xmemset(tls, bp+8, 0, uint64(unsafe.Sizeof([41]uint8{})))

	for ii = 0; ii < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint; ii++ {
		if int32((*sqlite3_index_constraint)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint+uintptr(ii)*12)).Fop) == SQLITE_INDEX_CONSTRAINT_MATCH {
			bMatch = 1
		}
	}

	for ii = 0; ii < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint && iIdx < int32(uint64(unsafe.Sizeof([41]uint8{}))-uint64(1)); ii++ {
		var p uintptr = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12

		if bMatch == 0 && (*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 &&
			(*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn <= 0 && int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_EQ {
			var jj int32
			for jj = 0; jj < ii; jj++ {
				(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8)).FargvIndex = 0
				(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8)).Fomit = uint8(0)
			}
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 1
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8)).FargvIndex = 1
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(jj)*8)).Fomit = uint8(1)

			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 30.0
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = SQLITE_INDEX_SCAN_UNIQUE
			return SQLITE_OK
		}

		if (*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 &&
			((*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn > 0 && (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn <= int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2) ||
				int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_MATCH) {
			var op U8
			switch int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) {
			case SQLITE_INDEX_CONSTRAINT_EQ:
				op = U8(RTREE_EQ)
				break
				fallthrough
			case SQLITE_INDEX_CONSTRAINT_GT:
				op = U8(RTREE_GT)
				break
				fallthrough
			case SQLITE_INDEX_CONSTRAINT_LE:
				op = U8(RTREE_LE)
				break
				fallthrough
			case SQLITE_INDEX_CONSTRAINT_LT:
				op = U8(RTREE_LT)
				break
				fallthrough
			case SQLITE_INDEX_CONSTRAINT_GE:
				op = U8(RTREE_GE)
				break
				fallthrough
			case SQLITE_INDEX_CONSTRAINT_MATCH:
				op = U8(RTREE_MATCH)
				break
				fallthrough
			default:
				op = U8(0)
				break
			}
			if op != 0 {
				*(*uint8)(unsafe.Pointer(bp + 8 + uintptr(libc.PostIncInt32(&iIdx, 1)))) = op
				*(*uint8)(unsafe.Pointer(bp + 8 + uintptr(libc.PostIncInt32(&iIdx, 1)))) = uint8((*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn - 1 + '0')
				(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8)).FargvIndex = iIdx / 2
				(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(ii)*8)).Fomit = uint8(1)
			}
		}
	}

	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 2
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FneedToFreeIdxStr = 1
	if iIdx > 0 && uintptr(0) == libc.AssignPtrUintptr(pIdxInfo+48, Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, bp+8))) {
		return SQLITE_NOMEM
	}

	nRow = (*Rtree)(unsafe.Pointer(pRtree)).FnRowEst >> (iIdx / 2)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 6.0 * float64(nRow)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = nRow

	return rc
}

func cellArea(tls *libc.TLS, pRtree uintptr, p uintptr) RtreeDValue {
	var area RtreeDValue = RtreeDValue(1)

	if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
		switch int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim) {
		case 5:
			area = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(p + 8 + 9*4)) - *(*RtreeValue)(unsafe.Pointer(p + 8 + 8*4)))
			fallthrough
		case 4:
			area = area * float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + 7*4))-*(*RtreeValue)(unsafe.Pointer(p + 8 + 6*4)))
			fallthrough
		case 3:
			area = area * float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + 5*4))-*(*RtreeValue)(unsafe.Pointer(p + 8 + 4*4)))
			fallthrough
		case 2:
			area = area * float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + 3*4))-*(*RtreeValue)(unsafe.Pointer(p + 8 + 2*4)))
			fallthrough
		default:
			area = area * float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + 1*4))-*(*RtreeValue)(unsafe.Pointer(p + 8)))
		}
	} else {
		switch int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim) {
		case 5:
			area = RtreeDValue(I64(*(*int32)(unsafe.Pointer(p + 8 + 9*4))) - I64(*(*int32)(unsafe.Pointer(p + 8 + 8*4))))
			fallthrough
		case 4:
			area = area * float64(I64(*(*int32)(unsafe.Pointer(p + 8 + 7*4)))-I64(*(*int32)(unsafe.Pointer(p + 8 + 6*4))))
			fallthrough
		case 3:
			area = area * float64(I64(*(*int32)(unsafe.Pointer(p + 8 + 5*4)))-I64(*(*int32)(unsafe.Pointer(p + 8 + 4*4))))
			fallthrough
		case 2:
			area = area * float64(I64(*(*int32)(unsafe.Pointer(p + 8 + 3*4)))-I64(*(*int32)(unsafe.Pointer(p + 8 + 2*4))))
			fallthrough
		default:
			area = area * float64(I64(*(*int32)(unsafe.Pointer(p + 8 + 1*4)))-I64(*(*int32)(unsafe.Pointer(p + 8))))
		}
	}
	return area
}

func cellMargin(tls *libc.TLS, pRtree uintptr, p uintptr) RtreeDValue {
	var margin RtreeDValue = RtreeDValue(0)
	var ii int32 = int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2) - 2
	for __ccgo := true; __ccgo; __ccgo = ii >= 0 {
		margin = margin + (func() float64 {
			if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				return float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + uintptr(ii+1)*4)))
			}
			return float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(ii+1)*4)))
		}() - func() float64 {
			if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
				return float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + uintptr(ii)*4)))
			}
			return float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(ii)*4)))
		}())
		ii = ii - 2
	}
	return margin
}

func cellUnion(tls *libc.TLS, pRtree uintptr, p1 uintptr, p2 uintptr) {
	var ii int32 = 0
	if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
		for __ccgo := true; __ccgo; __ccgo = ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2) {
			*(*RtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4)) = func() float32 {
				if *(*RtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4)) < *(*RtreeValue)(unsafe.Pointer(p2 + 8 + uintptr(ii)*4)) {
					return *(*RtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4))
				}
				return *(*RtreeValue)(unsafe.Pointer(p2 + 8 + uintptr(ii)*4))
			}()
			*(*RtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii+1)*4)) = func() float32 {
				if *(*RtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii+1)*4)) > *(*RtreeValue)(unsafe.Pointer(p2 + 8 + uintptr(ii+1)*4)) {
					return *(*RtreeValue)(unsafe.Pointer(p1 + 8 + uintptr(ii+1)*4))
				}
				return *(*RtreeValue)(unsafe.Pointer(p2 + 8 + uintptr(ii+1)*4))
			}()
			ii = ii + 2
		}
	} else {
		for __ccgo1 := true; __ccgo1; __ccgo1 = ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2) {
			*(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4)) = func() int32 {
				if *(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4)) < *(*int32)(unsafe.Pointer(p2 + 8 + uintptr(ii)*4)) {
					return *(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii)*4))
				}
				return *(*int32)(unsafe.Pointer(p2 + 8 + uintptr(ii)*4))
			}()
			*(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii+1)*4)) = func() int32 {
				if *(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii+1)*4)) > *(*int32)(unsafe.Pointer(p2 + 8 + uintptr(ii+1)*4)) {
					return *(*int32)(unsafe.Pointer(p1 + 8 + uintptr(ii+1)*4))
				}
				return *(*int32)(unsafe.Pointer(p2 + 8 + uintptr(ii+1)*4))
			}()
			ii = ii + 2
		}
	}
}

func cellContains(tls *libc.TLS, pRtree uintptr, p1 uintptr, p2 uintptr) int32 {
	var ii int32
	var isInt int32 = libc.Bool32(int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_INT32)
	for ii = 0; ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2); ii = ii + 2 {
		var a1 uintptr = p1 + 8 + uintptr(ii)*4
		var a2 uintptr = p2 + 8 + uintptr(ii)*4
		if !(isInt != 0) && (*(*RtreeValue)(unsafe.Pointer(a2)) < *(*RtreeValue)(unsafe.Pointer(a1)) || *(*RtreeValue)(unsafe.Pointer(a2 + 1*4)) > *(*RtreeValue)(unsafe.Pointer(a1 + 1*4))) ||
			isInt != 0 && (*(*int32)(unsafe.Pointer(a2)) < *(*int32)(unsafe.Pointer(a1)) || *(*int32)(unsafe.Pointer(a2 + 1*4)) > *(*int32)(unsafe.Pointer(a1 + 1*4))) {
			return 0
		}
	}
	return 1
}

func cellGrowth(tls *libc.TLS, pRtree uintptr, p uintptr, pCell uintptr) RtreeDValue {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var area RtreeDValue

	libc.Xmemcpy(tls, bp, p, uint64(unsafe.Sizeof(RtreeCell{})))
	area = cellArea(tls, pRtree, bp)
	cellUnion(tls, pRtree, bp, pCell)
	return cellArea(tls, pRtree, bp) - area
}

func cellOverlap(tls *libc.TLS, pRtree uintptr, p uintptr, aCell uintptr, nCell int32) RtreeDValue {
	var ii int32
	var overlap RtreeDValue = 0.0
	for ii = 0; ii < nCell; ii++ {
		var jj int32
		var o RtreeDValue = RtreeDValue(1)
		for jj = 0; jj < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2); jj = jj + 2 {
			var x1 RtreeDValue
			var x2 RtreeDValue
			x1 = func() float64 {
				if func() float64 {
					if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
						return float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + uintptr(jj)*4)))
					}
					return float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(jj)*4)))
				}() > func() float64 {
					if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
						return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj)*4)))
					}
					return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj)*4)))
				}() {
					return func() float64 {
						if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
							return float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + uintptr(jj)*4)))
						}
						return float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(jj)*4)))
					}()
				}
				return func() float64 {
					if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
						return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj)*4)))
					}
					return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj)*4)))
				}()
			}()
			x2 = func() float64 {
				if func() float64 {
					if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
						return float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + uintptr(jj+1)*4)))
					}
					return float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(jj+1)*4)))
				}() < func() float64 {
					if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
						return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj+1)*4)))
					}
					return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj+1)*4)))
				}() {
					return func() float64 {
						if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
							return float64(*(*RtreeValue)(unsafe.Pointer(p + 8 + uintptr(jj+1)*4)))
						}
						return float64(*(*int32)(unsafe.Pointer(p + 8 + uintptr(jj+1)*4)))
					}()
				}
				return func() float64 {
					if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
						return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj+1)*4)))
					}
					return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(jj+1)*4)))
				}()
			}()
			if x2 < x1 {
				o = RtreeDValue(0)
				break
			} else {
				o = o * (x2 - x1)
			}
		}
		overlap = overlap + o
	}
	return overlap
}

func sChooseLeaf(tls *libc.TLS, pRtree uintptr, pCell uintptr, iHeight int32, ppLeaf uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var rc int32
	var ii int32
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	rc = nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp)

	for ii = 0; rc == SQLITE_OK && ii < (*Rtree)(unsafe.Pointer(pRtree)).FiDepth-iHeight; ii++ {
		var iCell int32
		var iBest Sqlite3_int64 = int64(0)

		var fMinGrowth RtreeDValue = 0.0
		var fMinArea RtreeDValue = 0.0

		var nCell int32 = readInt16(tls, (*RtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzData+2)

		*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)

		var aCell uintptr = uintptr(0)

		for iCell = 0; iCell < nCell; iCell++ {
			var bBest int32 = 0
			var growth RtreeDValue
			var area RtreeDValue
			nodeGetCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), iCell, bp+8)
			growth = cellGrowth(tls, pRtree, bp+8, pCell)
			area = cellArea(tls, pRtree, bp+8)
			if iCell == 0 || growth < fMinGrowth || growth == fMinGrowth && area < fMinArea {
				bBest = 1
			}
			if bBest != 0 {
				fMinGrowth = growth
				fMinArea = area
				iBest = (*RtreeCell)(unsafe.Pointer(bp + 8)).FiRowid
			}
		}

		Xsqlite3_free(tls, aCell)
		rc = nodeAcquire(tls, pRtree, iBest, *(*uintptr)(unsafe.Pointer(bp)), bp+56)
		nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
		*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(bp + 56))
	}

	*(*uintptr)(unsafe.Pointer(ppLeaf)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
}

func sAdjustTree(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var p uintptr = pNode
	var cnt int32 = 0
	var rc int32
	for (*RtreeNode)(unsafe.Pointer(p)).FpParent != 0 {
		var pParent uintptr = (*RtreeNode)(unsafe.Pointer(p)).FpParent

		cnt++
		if cnt > 100 {
			return SQLITE_CORRUPT | int32(1)<<8
		}
		rc = nodeParentIndex(tls, pRtree, p, bp)
		if rc != SQLITE_OK {
			return SQLITE_CORRUPT | int32(1)<<8
		}

		nodeGetCell(tls, pRtree, pParent, *(*int32)(unsafe.Pointer(bp)), bp+8)
		if !(cellContains(tls, pRtree, bp+8, pCell) != 0) {
			cellUnion(tls, pRtree, bp+8, pCell)
			nodeOverwriteCell(tls, pRtree, pParent, bp+8, *(*int32)(unsafe.Pointer(bp)))
		}

		p = pParent
	}
	return SQLITE_OK
}

func rowidWrite(tls *libc.TLS, pRtree uintptr, iRowid Sqlite3_int64, iNode Sqlite3_int64) int32 {
	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid, 1, iRowid)
	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid, 2, iNode)
	Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
	return Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
}

func parentWrite(tls *libc.TLS, pRtree uintptr, iNode Sqlite3_int64, iPar Sqlite3_int64) int32 {
	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteParent, 1, iNode)
	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteParent, 2, iPar)
	Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteParent)
	return Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteParent)
}

func sSortByDistance(tls *libc.TLS, aIdx uintptr, nIdx int32, aDistance uintptr, aSpare uintptr) {
	if nIdx > 1 {
		var iLeft int32 = 0
		var iRight int32 = 0

		var nLeft int32 = nIdx / 2
		var nRight int32 = nIdx - nLeft
		var aLeft uintptr = aIdx
		var aRight uintptr = aIdx + uintptr(nLeft)*4

		sSortByDistance(tls, aLeft, nLeft, aDistance, aSpare)
		sSortByDistance(tls, aRight, nRight, aDistance, aSpare)

		libc.Xmemcpy(tls, aSpare, aLeft, uint64(unsafe.Sizeof(int32(0)))*uint64(nLeft))
		aLeft = aSpare

		for iLeft < nLeft || iRight < nRight {
			if iLeft == nLeft {
				*(*int32)(unsafe.Pointer(aIdx + uintptr(iLeft+iRight)*4)) = *(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4))
				iRight++
			} else if iRight == nRight {
				*(*int32)(unsafe.Pointer(aIdx + uintptr(iLeft+iRight)*4)) = *(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4))
				iLeft++
			} else {
				var fLeft RtreeDValue = *(*RtreeDValue)(unsafe.Pointer(aDistance + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*8))
				var fRight RtreeDValue = *(*RtreeDValue)(unsafe.Pointer(aDistance + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*8))
				if fLeft < fRight {
					*(*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++
				}
			}
		}

	}
}

func sSortByDimension(tls *libc.TLS, pRtree uintptr, aIdx uintptr, nIdx int32, iDim int32, aCell uintptr, aSpare uintptr) {
	if nIdx > 1 {
		var iLeft int32 = 0
		var iRight int32 = 0

		var nLeft int32 = nIdx / 2
		var nRight int32 = nIdx - nLeft
		var aLeft uintptr = aIdx
		var aRight uintptr = aIdx + uintptr(nLeft)*4

		sSortByDimension(tls, pRtree, aLeft, nLeft, iDim, aCell, aSpare)
		sSortByDimension(tls, pRtree, aRight, nRight, iDim, aCell, aSpare)

		libc.Xmemcpy(tls, aSpare, aLeft, uint64(unsafe.Sizeof(int32(0)))*uint64(nLeft))
		aLeft = aSpare
		for iLeft < nLeft || iRight < nRight {
			var xleft1 RtreeDValue = func() float64 {
				if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*2)*4)))
				}
				return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*2)*4)))
			}()
			var xleft2 RtreeDValue = func() float64 {
				if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*2+1)*4)))
				}
				return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aLeft + uintptr(iLeft)*4)))*48 + 8 + uintptr(iDim*2+1)*4)))
			}()
			var xright1 RtreeDValue = func() float64 {
				if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*2)*4)))
				}
				return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*2)*4)))
			}()
			var xright2 RtreeDValue = func() float64 {
				if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*2+1)*4)))
				}
				return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(*(*int32)(unsafe.Pointer(aRight + uintptr(iRight)*4)))*48 + 8 + uintptr(iDim*2+1)*4)))
			}()
			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++
			}
		}

	}
}

func splitNodeStartree(tls *libc.TLS, pRtree uintptr, aCell uintptr, nCell int32, pLeft uintptr, pRight uintptr, pBboxLeft uintptr, pBboxRight uintptr) int32 {
	bp := tls.Alloc(96)
	defer tls.Free(96)

	var aaSorted uintptr
	var aSpare uintptr
	var ii int32

	var iBestDim int32 = 0
	var iBestSplit int32 = 0
	var fBestMargin RtreeDValue = 0.0

	var nByte Sqlite3_int64 = Sqlite3_int64(uint64(int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim)+1) * (uint64(unsafe.Sizeof(uintptr(0))) + uint64(nCell)*uint64(unsafe.Sizeof(int32(0)))))

	aaSorted = Xsqlite3_malloc64(tls, uint64(nByte))
	if !(aaSorted != 0) {
		return SQLITE_NOMEM
	}

	aSpare = aaSorted + uintptr((*Rtree)(unsafe.Pointer(pRtree)).FnDim)*8 + uintptr(int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim)*nCell)*4
	libc.Xmemset(tls, aaSorted, 0, uint64(nByte))
	for ii = 0; ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim); ii++ {
		var jj int32
		*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*8)) = aaSorted + uintptr((*Rtree)(unsafe.Pointer(pRtree)).FnDim)*8 + uintptr(ii*nCell)*4
		for jj = 0; jj < nCell; jj++ {
			*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*8)) + uintptr(jj)*4)) = jj
		}
		sSortByDimension(tls, pRtree, *(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*8)), nCell, ii, aCell, aSpare)
	}

	for ii = 0; ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim); ii++ {
		var margin RtreeDValue = 0.0
		var fBestOverlap RtreeDValue = 0.0
		var fBestArea RtreeDValue = 0.0
		var iBestLeft int32 = 0
		var nLeft int32

		for nLeft = ((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize - 4) / int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell) / 3; nLeft <= nCell-((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize-4)/int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/3; nLeft++ {
			var kk int32
			var overlap RtreeDValue
			var area RtreeDValue

			libc.Xmemcpy(tls, bp, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*8)))))*48, uint64(unsafe.Sizeof(RtreeCell{})))
			libc.Xmemcpy(tls, bp+48, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*8)) + uintptr(nCell-1)*4)))*48, uint64(unsafe.Sizeof(RtreeCell{})))
			for kk = 1; kk < nCell-1; kk++ {
				if kk < nLeft {
					cellUnion(tls, pRtree, bp, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*8)) + uintptr(kk)*4)))*48)
				} else {
					cellUnion(tls, pRtree, bp+48, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(ii)*8)) + uintptr(kk)*4)))*48)
				}
			}
			margin = margin + cellMargin(tls, pRtree, bp)
			margin = margin + cellMargin(tls, pRtree, bp+48)
			overlap = cellOverlap(tls, pRtree, bp, bp+48, 1)
			area = cellArea(tls, pRtree, bp) + cellArea(tls, pRtree, bp+48)
			if nLeft == ((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize-4)/int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/3 ||
				overlap < fBestOverlap ||
				overlap == fBestOverlap && area < fBestArea {
				iBestLeft = nLeft
				fBestOverlap = overlap
				fBestArea = area
			}
		}

		if ii == 0 || margin < fBestMargin {
			iBestDim = ii
			fBestMargin = margin
			iBestSplit = iBestLeft
		}
	}

	libc.Xmemcpy(tls, pBboxLeft, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(iBestDim)*8)))))*48, uint64(unsafe.Sizeof(RtreeCell{})))
	libc.Xmemcpy(tls, pBboxRight, aCell+uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(iBestDim)*8)) + uintptr(iBestSplit)*4)))*48, uint64(unsafe.Sizeof(RtreeCell{})))
	for ii = 0; ii < nCell; ii++ {
		var pTarget uintptr
		if ii < iBestSplit {
			pTarget = pLeft
		} else {
			pTarget = pRight
		}
		var pBbox uintptr
		if ii < iBestSplit {
			pBbox = pBboxLeft
		} else {
			pBbox = pBboxRight
		}
		var pCell uintptr = aCell + uintptr(*(*int32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(aaSorted + uintptr(iBestDim)*8)) + uintptr(ii)*4)))*48
		nodeInsertCell(tls, pRtree, pTarget, pCell)
		cellUnion(tls, pRtree, pBbox, pCell)
	}

	Xsqlite3_free(tls, aaSorted)
	return SQLITE_OK
}

func updateMapping(tls *libc.TLS, pRtree uintptr, iRowid I64, pNode uintptr, iHeight int32) int32 {
	var xSetMapping uintptr
	xSetMapping = func() uintptr {
		if iHeight == 0 {
			return *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, Sqlite3_int64, Sqlite3_int64) int32
			}{rowidWrite}))
		}
		return *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, Sqlite3_int64, Sqlite3_int64) int32
		}{parentWrite}))
	}()
	if iHeight > 0 {
		var pChild uintptr = nodeHashLookup(tls, pRtree, iRowid)
		var p uintptr
		for p = pNode; p != 0; p = (*RtreeNode)(unsafe.Pointer(p)).FpParent {
			if p == pChild {
				return SQLITE_CORRUPT | int32(1)<<8
			}
		}
		if pChild != 0 {
			nodeRelease(tls, pRtree, (*RtreeNode)(unsafe.Pointer(pChild)).FpParent)
			nodeReference(tls, pNode)
			(*RtreeNode)(unsafe.Pointer(pChild)).FpParent = pNode
		}
	}
	if pNode == uintptr(0) {
		return SQLITE_ERROR
	}
	return (*struct {
		f func(*libc.TLS, uintptr, Sqlite3_int64, Sqlite3_int64) int32
	})(unsafe.Pointer(&struct{ uintptr }{xSetMapping})).f(tls, pRtree, iRowid, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode)
}

func sSplitNode(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr, iHeight int32) int32 {
	bp := tls.Alloc(100)
	defer tls.Free(100)

	var i int32
	var newCellIsRight int32
	var rc int32
	var nCell int32
	var aCell uintptr
	var aiUsed uintptr
	var pLeft uintptr
	var pRight uintptr

	var pParent uintptr

	var iRowid I64
	var iRowid1 I64
	newCellIsRight = 0
	rc = SQLITE_OK
	nCell = readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2)
	pLeft = uintptr(0)
	pRight = uintptr(0)

	aCell = Xsqlite3_malloc64(tls, (uint64(unsafe.Sizeof(RtreeCell{}))+uint64(unsafe.Sizeof(int32(0))))*uint64(nCell+1))
	if !!(aCell != 0) {
		goto __1
	}
	rc = SQLITE_NOMEM
	goto splitnode_out
__1:
	;
	aiUsed = aCell + uintptr(nCell+1)*48
	libc.Xmemset(tls, aiUsed, 0, uint64(unsafe.Sizeof(int32(0)))*uint64(nCell+1))
	i = 0
__2:
	if !(i < nCell) {
		goto __4
	}
	nodeGetCell(tls, pRtree, pNode, i, aCell+uintptr(i)*48)
	goto __3
__3:
	i++
	goto __2
	goto __4
__4:
	;
	nodeZero(tls, pRtree, pNode)
	libc.Xmemcpy(tls, aCell+uintptr(nCell)*48, pCell, uint64(unsafe.Sizeof(RtreeCell{})))
	nCell++

	if !((*RtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1)) {
		goto __5
	}
	pRight = nodeNew(tls, pRtree, pNode)
	pLeft = nodeNew(tls, pRtree, pNode)
	(*Rtree)(unsafe.Pointer(pRtree)).FiDepth++
	(*RtreeNode)(unsafe.Pointer(pNode)).FisDirty = 1
	writeInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData, (*Rtree)(unsafe.Pointer(pRtree)).FiDepth)
	goto __6
__5:
	pLeft = pNode
	pRight = nodeNew(tls, pRtree, (*RtreeNode)(unsafe.Pointer(pLeft)).FpParent)
	(*RtreeNode)(unsafe.Pointer(pLeft)).FnRef++
__6:
	;
	if !(!(pLeft != 0) || !(pRight != 0)) {
		goto __7
	}
	rc = SQLITE_NOMEM
	goto splitnode_out
__7:
	;
	libc.Xmemset(tls, (*RtreeNode)(unsafe.Pointer(pLeft)).FzData, 0, uint64((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize))
	libc.Xmemset(tls, (*RtreeNode)(unsafe.Pointer(pRight)).FzData, 0, uint64((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize))

	rc = splitNodeStartree(tls, pRtree, aCell, nCell, pLeft, pRight,
		bp, bp+48)
	if !(rc != SQLITE_OK) {
		goto __8
	}
	goto splitnode_out
__8:
	;
	if !(SQLITE_OK != libc.AssignInt32(&rc, nodeWrite(tls, pRtree, pRight)) ||
		int64(0) == (*RtreeNode)(unsafe.Pointer(pLeft)).FiNode && SQLITE_OK != libc.AssignInt32(&rc, nodeWrite(tls, pRtree, pLeft))) {
		goto __9
	}
	goto splitnode_out
__9:
	;
	(*RtreeCell)(unsafe.Pointer(bp + 48)).FiRowid = (*RtreeNode)(unsafe.Pointer(pRight)).FiNode
	(*RtreeCell)(unsafe.Pointer(bp)).FiRowid = (*RtreeNode)(unsafe.Pointer(pLeft)).FiNode

	if !((*RtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1)) {
		goto __10
	}
	rc = rtreeInsertCell(tls, pRtree, (*RtreeNode)(unsafe.Pointer(pLeft)).FpParent, bp, iHeight+1)
	if !(rc != SQLITE_OK) {
		goto __12
	}
	goto splitnode_out
__12:
	;
	goto __11
__10:
	pParent = (*RtreeNode)(unsafe.Pointer(pLeft)).FpParent
	rc = nodeParentIndex(tls, pRtree, pLeft, bp+96)
	if !(rc == SQLITE_OK) {
		goto __13
	}
	nodeOverwriteCell(tls, pRtree, pParent, bp, *(*int32)(unsafe.Pointer(bp + 96)))
	rc = sAdjustTree(tls, pRtree, pParent, bp)

__13:
	;
	if !(rc != SQLITE_OK) {
		goto __14
	}
	goto splitnode_out
__14:
	;
__11:
	;
	if !(libc.AssignInt32(&rc, rtreeInsertCell(tls, pRtree, (*RtreeNode)(unsafe.Pointer(pRight)).FpParent, bp+48, iHeight+1)) != 0) {
		goto __15
	}
	goto splitnode_out
__15:
	;
	i = 0
__16:
	if !(i < readInt16(tls, (*RtreeNode)(unsafe.Pointer(pRight)).FzData+2)) {
		goto __18
	}
	iRowid = nodeGetRowid(tls, pRtree, pRight, i)
	rc = updateMapping(tls, pRtree, iRowid, pRight, iHeight)
	if !(iRowid == (*RtreeCell)(unsafe.Pointer(pCell)).FiRowid) {
		goto __19
	}
	newCellIsRight = 1
__19:
	;
	if !(rc != SQLITE_OK) {
		goto __20
	}
	goto splitnode_out
__20:
	;
	goto __17
__17:
	i++
	goto __16
	goto __18
__18:
	;
	if !((*RtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1)) {
		goto __21
	}
	i = 0
__23:
	if !(i < readInt16(tls, (*RtreeNode)(unsafe.Pointer(pLeft)).FzData+2)) {
		goto __25
	}
	iRowid1 = nodeGetRowid(tls, pRtree, pLeft, i)
	rc = updateMapping(tls, pRtree, iRowid1, pLeft, iHeight)
	if !(rc != SQLITE_OK) {
		goto __26
	}
	goto splitnode_out
__26:
	;
	goto __24
__24:
	i++
	goto __23
	goto __25
__25:
	;
	goto __22
__21:
	if !(newCellIsRight == 0) {
		goto __27
	}
	rc = updateMapping(tls, pRtree, (*RtreeCell)(unsafe.Pointer(pCell)).FiRowid, pLeft, iHeight)
__27:
	;
__22:
	;
	if !(rc == SQLITE_OK) {
		goto __28
	}
	rc = nodeRelease(tls, pRtree, pRight)
	pRight = uintptr(0)
__28:
	;
	if !(rc == SQLITE_OK) {
		goto __29
	}
	rc = nodeRelease(tls, pRtree, pLeft)
	pLeft = uintptr(0)
__29:
	;
splitnode_out:
	nodeRelease(tls, pRtree, pRight)
	nodeRelease(tls, pRtree, pLeft)
	Xsqlite3_free(tls, aCell)
	return rc
}

func fixLeafParent(tls *libc.TLS, pRtree uintptr, pLeaf uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pChild uintptr = pLeaf
	for rc == SQLITE_OK && (*RtreeNode)(unsafe.Pointer(pChild)).FiNode != int64(1) && (*RtreeNode)(unsafe.Pointer(pChild)).FpParent == uintptr(0) {
		var rc2 int32 = SQLITE_OK
		Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadParent, 1, (*RtreeNode)(unsafe.Pointer(pChild)).FiNode)
		rc = Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadParent)
		if rc == SQLITE_ROW {
			var pTest uintptr
			var iNode I64

			iNode = Xsqlite3_column_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadParent, 0)
			for pTest = pLeaf; pTest != 0 && (*RtreeNode)(unsafe.Pointer(pTest)).FiNode != iNode; pTest = (*RtreeNode)(unsafe.Pointer(pTest)).FpParent {
			}
			if pTest == uintptr(0) {
				rc2 = nodeAcquire(tls, pRtree, iNode, uintptr(0), pChild)
			}
		}
		rc = Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadParent)
		if rc == SQLITE_OK {
			rc = rc2
		}
		if rc == SQLITE_OK && !(int32((*RtreeNode)(unsafe.Pointer(pChild)).FpParent) != 0) {
			rc = SQLITE_CORRUPT | int32(1)<<8
		}
		pChild = (*RtreeNode)(unsafe.Pointer(pChild)).FpParent
	}
	return rc
}

func removeNode(tls *libc.TLS, pRtree uintptr, pNode uintptr, iHeight int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32
	var rc2 int32
	var pParent uintptr = uintptr(0)

	rc = nodeParentIndex(tls, pRtree, pNode, bp)
	if rc == SQLITE_OK {
		pParent = (*RtreeNode)(unsafe.Pointer(pNode)).FpParent
		(*RtreeNode)(unsafe.Pointer(pNode)).FpParent = uintptr(0)
		rc = deleteCell(tls, pRtree, pParent, *(*int32)(unsafe.Pointer(bp)), iHeight+1)

	}
	rc2 = nodeRelease(tls, pRtree, pParent)
	if rc == SQLITE_OK {
		rc = rc2
	}
	if rc != SQLITE_OK {
		return rc
	}

	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteNode, 1, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode)
	Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteNode)
	if SQLITE_OK != libc.AssignInt32(&rc, Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteNode)) {
		return rc
	}

	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteParent, 1, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode)
	Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteParent)
	if SQLITE_OK != libc.AssignInt32(&rc, Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteParent)) {
		return rc
	}

	nodeHashDelete(tls, pRtree, pNode)
	(*RtreeNode)(unsafe.Pointer(pNode)).FiNode = I64(iHeight)
	(*RtreeNode)(unsafe.Pointer(pNode)).FpNext = (*Rtree)(unsafe.Pointer(pRtree)).FpDeleted
	(*RtreeNode)(unsafe.Pointer(pNode)).FnRef++
	(*Rtree)(unsafe.Pointer(pRtree)).FpDeleted = pNode

	return SQLITE_OK
}

func fixBoundingBox(tls *libc.TLS, pRtree uintptr, pNode uintptr) int32 {
	bp := tls.Alloc(100)
	defer tls.Free(100)

	var pParent uintptr = (*RtreeNode)(unsafe.Pointer(pNode)).FpParent
	var rc int32 = SQLITE_OK
	if pParent != 0 {
		var nCell int32 = readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2)

		nodeGetCell(tls, pRtree, pNode, 0, bp)
		for *(*int32)(unsafe.Pointer(bp + 96)) = 1; *(*int32)(unsafe.Pointer(bp + 96)) < nCell; *(*int32)(unsafe.Pointer(bp + 96))++ {
			nodeGetCell(tls, pRtree, pNode, *(*int32)(unsafe.Pointer(bp + 96)), bp+48)
			cellUnion(tls, pRtree, bp, bp+48)
		}
		(*RtreeCell)(unsafe.Pointer(bp)).FiRowid = (*RtreeNode)(unsafe.Pointer(pNode)).FiNode
		rc = nodeParentIndex(tls, pRtree, pNode, bp+96)
		if rc == SQLITE_OK {
			nodeOverwriteCell(tls, pRtree, pParent, bp, *(*int32)(unsafe.Pointer(bp + 96)))
			rc = fixBoundingBox(tls, pRtree, pParent)
		}
	}
	return rc
}

func deleteCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, iCell int32, iHeight int32) int32 {
	var pParent uintptr
	var rc int32

	if SQLITE_OK != libc.AssignInt32(&rc, fixLeafParent(tls, pRtree, pNode)) {
		return rc
	}

	nodeDeleteCell(tls, pRtree, pNode, iCell)

	pParent = (*RtreeNode)(unsafe.Pointer(pNode)).FpParent

	if pParent != 0 {
		if readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2) < ((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize-4)/int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/3 {
			rc = removeNode(tls, pRtree, pNode, iHeight)
		} else {
			rc = fixBoundingBox(tls, pRtree, pNode)
		}
	}

	return rc
}

func sReinsert(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr, iHeight int32) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var aOrder uintptr
	var aSpare uintptr
	var aCell uintptr
	var aDistance uintptr
	var nCell int32

	var iDim int32
	var ii int32
	var rc int32 = SQLITE_OK
	var n int32

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(RtreeDValue(0)))*uint64(RTREE_MAX_DIMENSIONS))

	nCell = readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2) + 1
	n = (nCell + 1) & libc.CplInt32(1)

	aCell = Xsqlite3_malloc64(tls, uint64(n)*(uint64(unsafe.Sizeof(RtreeCell{}))+uint64(unsafe.Sizeof(int32(0)))+uint64(unsafe.Sizeof(int32(0)))+uint64(unsafe.Sizeof(RtreeDValue(0)))))
	if !(aCell != 0) {
		return SQLITE_NOMEM
	}
	aOrder = aCell + uintptr(n)*48
	aSpare = aOrder + uintptr(n)*4
	aDistance = aSpare + uintptr(n)*4

	for ii = 0; ii < nCell; ii++ {
		if ii == nCell-1 {
			libc.Xmemcpy(tls, aCell+uintptr(ii)*48, pCell, uint64(unsafe.Sizeof(RtreeCell{})))
		} else {
			nodeGetCell(tls, pRtree, pNode, ii, aCell+uintptr(ii)*48)
		}
		*(*int32)(unsafe.Pointer(aOrder + uintptr(ii)*4)) = ii
		for iDim = 0; iDim < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim); iDim++ {
			*(*RtreeDValue)(unsafe.Pointer(bp + uintptr(iDim)*8)) += func() float64 {
				if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(iDim*2)*4)))
				}
				return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(iDim*2)*4)))
			}()
			*(*RtreeDValue)(unsafe.Pointer(bp + uintptr(iDim)*8)) += func() float64 {
				if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(iDim*2+1)*4)))
				}
				return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(iDim*2+1)*4)))
			}()
		}
	}
	for iDim = 0; iDim < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim); iDim++ {
		*(*RtreeDValue)(unsafe.Pointer(bp + uintptr(iDim)*8)) = *(*RtreeDValue)(unsafe.Pointer(bp + uintptr(iDim)*8)) / (float64(nCell) * RtreeDValue(2))
	}

	for ii = 0; ii < nCell; ii++ {
		*(*RtreeDValue)(unsafe.Pointer(aDistance + uintptr(ii)*8)) = 0.0
		for iDim = 0; iDim < int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim); iDim++ {
			var coord RtreeDValue = func() float64 {
				if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(iDim*2+1)*4)))
				}
				return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(iDim*2+1)*4)))
			}() - func() float64 {
				if int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32 {
					return float64(*(*RtreeValue)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(iDim*2)*4)))
				}
				return float64(*(*int32)(unsafe.Pointer(aCell + uintptr(ii)*48 + 8 + uintptr(iDim*2)*4)))
			}()
			*(*RtreeDValue)(unsafe.Pointer(aDistance + uintptr(ii)*8)) += (coord - *(*RtreeDValue)(unsafe.Pointer(bp + uintptr(iDim)*8))) * (coord - *(*RtreeDValue)(unsafe.Pointer(bp + uintptr(iDim)*8)))
		}
	}

	sSortByDistance(tls, aOrder, nCell, aDistance, aSpare)
	nodeZero(tls, pRtree, pNode)

	for ii = 0; rc == SQLITE_OK && ii < nCell-(((*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize-4)/int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)/3+1); ii++ {
		var p uintptr = aCell + uintptr(*(*int32)(unsafe.Pointer(aOrder + uintptr(ii)*4)))*48
		nodeInsertCell(tls, pRtree, pNode, p)
		if (*RtreeCell)(unsafe.Pointer(p)).FiRowid == (*RtreeCell)(unsafe.Pointer(pCell)).FiRowid {
			if iHeight == 0 {
				rc = rowidWrite(tls, pRtree, (*RtreeCell)(unsafe.Pointer(p)).FiRowid, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode)
			} else {
				rc = parentWrite(tls, pRtree, (*RtreeCell)(unsafe.Pointer(p)).FiRowid, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode)
			}
		}
	}
	if rc == SQLITE_OK {
		rc = fixBoundingBox(tls, pRtree, pNode)
	}
	for ; rc == SQLITE_OK && ii < nCell; ii++ {
		var p uintptr = aCell + uintptr(*(*int32)(unsafe.Pointer(aOrder + uintptr(ii)*4)))*48
		rc = sChooseLeaf(tls, pRtree, p, iHeight, bp+40)
		if rc == SQLITE_OK {
			var rc2 int32
			rc = rtreeInsertCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 40)), p, iHeight)
			rc2 = nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 40)))
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
	}

	Xsqlite3_free(tls, aCell)
	return rc
}

func rtreeInsertCell(tls *libc.TLS, pRtree uintptr, pNode uintptr, pCell uintptr, iHeight int32) int32 {
	var rc int32 = SQLITE_OK
	if iHeight > 0 {
		var pChild uintptr = nodeHashLookup(tls, pRtree, (*RtreeCell)(unsafe.Pointer(pCell)).FiRowid)
		if pChild != 0 {
			nodeRelease(tls, pRtree, (*RtreeNode)(unsafe.Pointer(pChild)).FpParent)
			nodeReference(tls, pNode)
			(*RtreeNode)(unsafe.Pointer(pChild)).FpParent = pNode
		}
	}
	if nodeInsertCell(tls, pRtree, pNode, pCell) != 0 {
		if iHeight <= (*Rtree)(unsafe.Pointer(pRtree)).FiReinsertHeight || (*RtreeNode)(unsafe.Pointer(pNode)).FiNode == int64(1) {
			rc = sSplitNode(tls, pRtree, pNode, pCell, iHeight)
		} else {
			(*Rtree)(unsafe.Pointer(pRtree)).FiReinsertHeight = iHeight
			rc = sReinsert(tls, pRtree, pNode, pCell, iHeight)
		}
	} else {
		rc = sAdjustTree(tls, pRtree, pNode, pCell)
		if rc == SQLITE_OK {
			if iHeight == 0 {
				rc = rowidWrite(tls, pRtree, (*RtreeCell)(unsafe.Pointer(pCell)).FiRowid, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode)
			} else {
				rc = parentWrite(tls, pRtree, (*RtreeCell)(unsafe.Pointer(pCell)).FiRowid, (*RtreeNode)(unsafe.Pointer(pNode)).FiNode)
			}
		}
	}
	return rc
}

func reinsertNodeContent(tls *libc.TLS, pRtree uintptr, pNode uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var ii int32
	var rc int32 = SQLITE_OK
	var nCell int32 = readInt16(tls, (*RtreeNode)(unsafe.Pointer(pNode)).FzData+2)

	for ii = 0; rc == SQLITE_OK && ii < nCell; ii++ {
		nodeGetCell(tls, pRtree, pNode, ii, bp)

		rc = sChooseLeaf(tls, pRtree, bp, int32((*RtreeNode)(unsafe.Pointer(pNode)).FiNode), bp+48)
		if rc == SQLITE_OK {
			var rc2 int32
			rc = rtreeInsertCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 48)), bp, int32((*RtreeNode)(unsafe.Pointer(pNode)).FiNode))
			rc2 = nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 48)))
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
	}
	return rc
}

func rtreeNewRowid(tls *libc.TLS, pRtree uintptr, piRowid uintptr) int32 {
	var rc int32
	Xsqlite3_bind_null(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid, 1)
	Xsqlite3_bind_null(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid, 2)
	Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
	rc = Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpWriteRowid)
	*(*I64)(unsafe.Pointer(piRowid)) = Xsqlite3_last_insert_rowid(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb)
	return rc
}

func rtreeDeleteRowid(tls *libc.TLS, pRtree uintptr, iDelete Sqlite3_int64) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var rc int32
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)

	rc = nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp)

	if rc == SQLITE_OK {
		rc = findLeafNode(tls, pRtree, iDelete, bp+8, uintptr(0))
	}

	if rc == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
		var rc2 int32
		rc = nodeRowidIndex(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 8)), iDelete, bp+16)
		if rc == SQLITE_OK {
			rc = deleteCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 8)), *(*int32)(unsafe.Pointer(bp + 16)), 0)
		}
		rc2 = nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 8)))
		if rc == SQLITE_OK {
			rc = rc2
		}
	}

	if rc == SQLITE_OK {
		Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteRowid, 1, iDelete)
		Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteRowid)
		rc = Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpDeleteRowid)
	}

	if rc == SQLITE_OK && (*Rtree)(unsafe.Pointer(pRtree)).FiDepth > 0 && readInt16(tls, (*RtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzData+2) == 1 {
		var rc2 int32
		*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
		var iChild I64 = nodeGetRowid(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), 0)
		rc = nodeAcquire(tls, pRtree, iChild, *(*uintptr)(unsafe.Pointer(bp)), bp+24)
		if rc == SQLITE_OK {
			rc = removeNode(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 24)), (*Rtree)(unsafe.Pointer(pRtree)).FiDepth-1)
		}
		rc2 = nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 24)))
		if rc == SQLITE_OK {
			rc = rc2
		}
		if rc == SQLITE_OK {
			(*Rtree)(unsafe.Pointer(pRtree)).FiDepth--
			writeInt16(tls, (*RtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzData, (*Rtree)(unsafe.Pointer(pRtree)).FiDepth)
			(*RtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FisDirty = 1
		}
	}

	for *(*uintptr)(unsafe.Pointer(bp + 8)) = (*Rtree)(unsafe.Pointer(pRtree)).FpDeleted; *(*uintptr)(unsafe.Pointer(bp + 8)) != 0; *(*uintptr)(unsafe.Pointer(bp + 8)) = (*Rtree)(unsafe.Pointer(pRtree)).FpDeleted {
		if rc == SQLITE_OK {
			rc = reinsertNodeContent(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 8)))
		}
		(*Rtree)(unsafe.Pointer(pRtree)).FpDeleted = (*RtreeNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpNext
		(*Rtree)(unsafe.Pointer(pRtree)).FnNodeRef--
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}

	if rc == SQLITE_OK {
		rc = nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
	} else {
		nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)))
	}

	return rc
}

func rtreeValueDown(tls *libc.TLS, v uintptr) RtreeValue {
	var d float64 = Xsqlite3_value_double(tls, v)
	var f float32 = float32(d)
	if float64(f) > d {
		f = float32(d * func() float64 {
			if d < float64(0) {
				return float64(1.0) + float64(1.0)/8388608.0
			}
			return float64(1.0) - float64(1.0)/8388608.0
		}())
	}
	return f
}

func rtreeValueUp(tls *libc.TLS, v uintptr) RtreeValue {
	var d float64 = Xsqlite3_value_double(tls, v)
	var f float32 = float32(d)
	if float64(f) < d {
		f = float32(d * func() float64 {
			if d < float64(0) {
				return float64(1.0) - float64(1.0)/8388608.0
			}
			return float64(1.0) + float64(1.0)/8388608.0
		}())
	}
	return f
}

func rtreeConstraintError(tls *libc.TLS, pRtree uintptr, iCol int32) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
	var zSql uintptr
	var rc int32

	zSql = Xsqlite3_mprintf(tls, ts+31445, libc.VaList(bp, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName))
	if zSql != 0 {
		rc = Xsqlite3_prepare_v2(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb, zSql, -1, bp+56, uintptr(0))
	} else {
		rc = SQLITE_NOMEM
	}
	Xsqlite3_free(tls, zSql)

	if rc == SQLITE_OK {
		if iCol == 0 {
			var zCol uintptr = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp + 56)), 0)
			(*Rtree)(unsafe.Pointer(pRtree)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls,
				ts+31465, libc.VaList(bp+16, (*Rtree)(unsafe.Pointer(pRtree)).FzName, zCol))
		} else {
			var zCol1 uintptr = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp + 56)), iCol)
			var zCol2 uintptr = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp + 56)), iCol+1)
			(*Rtree)(unsafe.Pointer(pRtree)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls,
				ts+31497, libc.VaList(bp+32, (*Rtree)(unsafe.Pointer(pRtree)).FzName, zCol1, zCol2))
		}
	}

	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 56)))
	return func() int32 {
		if rc == SQLITE_OK {
			return SQLITE_CONSTRAINT
		}
		return rc
	}()
}

func rtreeUpdate(tls *libc.TLS, pVtab uintptr, nData int32, aData uintptr, pRowid uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var pRtree uintptr
	var rc int32

	var bHaveRowid int32
	var steprc int32
	var ii int32
	var nn int32
	var rc2 int32
	var pUp uintptr
	var jj int32

	pRtree = pVtab
	rc = SQLITE_OK
	bHaveRowid = 0

	if !((*Rtree)(unsafe.Pointer(pRtree)).FnNodeRef != 0) {
		goto __1
	}

	return SQLITE_LOCKED | int32(2)<<8
__1:
	;
	rtreeReference(tls, pRtree)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(RtreeCell{})))

	if !(nData > 1) {
		goto __2
	}
	nn = nData - 4

	if !(nn > int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2)) {
		goto __3
	}
	nn = int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2)
__3:
	;
	if !(int32((*Rtree)(unsafe.Pointer(pRtree)).FeCoordType) == RTREE_COORD_REAL32) {
		goto __4
	}
	ii = 0
__6:
	if !(ii < nn) {
		goto __8
	}
	*(*RtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) = rtreeValueDown(tls, *(*uintptr)(unsafe.Pointer(aData + uintptr(ii+3)*8)))
	*(*RtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii+1)*4)) = rtreeValueUp(tls, *(*uintptr)(unsafe.Pointer(aData + uintptr(ii+4)*8)))
	if !(*(*RtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) > *(*RtreeValue)(unsafe.Pointer(bp + 8 + uintptr(ii+1)*4))) {
		goto __9
	}
	rc = rtreeConstraintError(tls, pRtree, ii+1)
	goto constraint
__9:
	;
	goto __7
__7:
	ii = ii + 2
	goto __6
	goto __8
__8:
	;
	goto __5
__4:
	ii = 0
__10:
	if !(ii < nn) {
		goto __12
	}
	*(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(aData + uintptr(ii+3)*8)))
	*(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii+1)*4)) = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(aData + uintptr(ii+4)*8)))
	if !(*(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii)*4)) > *(*int32)(unsafe.Pointer(bp + 8 + uintptr(ii+1)*4))) {
		goto __13
	}
	rc = rtreeConstraintError(tls, pRtree, ii+1)
	goto constraint
__13:
	;
	goto __11
__11:
	ii = ii + 2
	goto __10
	goto __12
__12:
	;
__5:
	;
	if !(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData + 2*8))) != SQLITE_NULL) {
		goto __14
	}
	(*RtreeCell)(unsafe.Pointer(bp)).FiRowid = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData + 2*8)))
	if !(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData))) == SQLITE_NULL ||
		Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData))) != (*RtreeCell)(unsafe.Pointer(bp)).FiRowid) {
		goto __15
	}
	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid, 1, (*RtreeCell)(unsafe.Pointer(bp)).FiRowid)
	steprc = Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid)
	rc = Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid)
	if !(SQLITE_ROW == steprc) {
		goto __16
	}
	if !(Xsqlite3_vtab_on_conflict(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb) == SQLITE_REPLACE) {
		goto __17
	}
	rc = rtreeDeleteRowid(tls, pRtree, (*RtreeCell)(unsafe.Pointer(bp)).FiRowid)
	goto __18
__17:
	rc = rtreeConstraintError(tls, pRtree, 0)
	goto constraint
__18:
	;
__16:
	;
__15:
	;
	bHaveRowid = 1
__14:
	;
__2:
	;
	if !(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData))) != SQLITE_NULL) {
		goto __19
	}
	rc = rtreeDeleteRowid(tls, pRtree, Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData))))
__19:
	;
	if !(rc == SQLITE_OK && nData > 1) {
		goto __20
	}

	*(*uintptr)(unsafe.Pointer(bp + 48)) = uintptr(0)

	if !(bHaveRowid == 0) {
		goto __21
	}
	rc = rtreeNewRowid(tls, pRtree, bp)
__21:
	;
	*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = (*RtreeCell)(unsafe.Pointer(bp)).FiRowid

	if !(rc == SQLITE_OK) {
		goto __22
	}
	rc = sChooseLeaf(tls, pRtree, bp, 0, bp+48)
__22:
	;
	if !(rc == SQLITE_OK) {
		goto __23
	}
	(*Rtree)(unsafe.Pointer(pRtree)).FiReinsertHeight = -1
	rc = rtreeInsertCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 48)), bp, 0)
	rc2 = nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 48)))
	if !(rc == SQLITE_OK) {
		goto __24
	}
	rc = rc2
__24:
	;
__23:
	;
	if !(rc == SQLITE_OK && (*Rtree)(unsafe.Pointer(pRtree)).FnAux != 0) {
		goto __25
	}
	pUp = (*Rtree)(unsafe.Pointer(pRtree)).FpWriteAux
	Xsqlite3_bind_int64(tls, pUp, 1, *(*Sqlite_int64)(unsafe.Pointer(pRowid)))
	jj = 0
__26:
	if !(jj < int32((*Rtree)(unsafe.Pointer(pRtree)).FnAux)) {
		goto __28
	}
	Xsqlite3_bind_value(tls, pUp, jj+2, *(*uintptr)(unsafe.Pointer(aData + uintptr(int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2)+3+jj)*8)))
	goto __27
__27:
	jj++
	goto __26
	goto __28
__28:
	;
	Xsqlite3_step(tls, pUp)
	rc = Xsqlite3_reset(tls, pUp)
__25:
	;
__20:
	;
constraint:
	rtreeRelease(tls, pRtree)
	return rc
}

func rtreeBeginTransaction(tls *libc.TLS, pVtab uintptr) int32 {
	var pRtree uintptr = pVtab

	(*Rtree)(unsafe.Pointer(pRtree)).FinWrTrans++
	return SQLITE_OK
}

func rtreeEndTransaction(tls *libc.TLS, pVtab uintptr) int32 {
	var pRtree uintptr = pVtab
	(*Rtree)(unsafe.Pointer(pRtree)).FinWrTrans = U8(0)
	nodeBlobReset(tls, pRtree)
	return SQLITE_OK
}

func rtreeRename(tls *libc.TLS, pVtab uintptr, zNewName uintptr) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var pRtree uintptr = pVtab
	var rc int32 = SQLITE_NOMEM
	var zSql uintptr = Xsqlite3_mprintf(tls,
		ts+31534, libc.VaList(bp, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName, zNewName, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName, zNewName, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName, zNewName))
	if zSql != 0 {
		nodeBlobReset(tls, pRtree)
		rc = Xsqlite3_exec(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb, zSql, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zSql)
	}
	return rc
}

func rtreeSavepoint(tls *libc.TLS, pVtab uintptr, iSavepoint int32) int32 {
	var pRtree uintptr = pVtab
	var iwt U8 = (*Rtree)(unsafe.Pointer(pRtree)).FinWrTrans
	_ = iSavepoint
	(*Rtree)(unsafe.Pointer(pRtree)).FinWrTrans = U8(0)
	nodeBlobReset(tls, pRtree)
	(*Rtree)(unsafe.Pointer(pRtree)).FinWrTrans = iwt
	return SQLITE_OK
}

func rtreeQueryStat1(tls *libc.TLS, db uintptr, pRtree uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var zFmt uintptr = ts + 31679
	var zSql uintptr

	var rc int32
	var nRow I64 = int64(RTREE_MIN_ROWEST)

	rc = Xsqlite3_table_column_metadata(tls,
		db, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, ts+14732, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0), uintptr(0))
	if rc != SQLITE_OK {
		(*Rtree)(unsafe.Pointer(pRtree)).FnRowEst = int64(RTREE_DEFAULT_ROWEST)
		if rc == SQLITE_ERROR {
			return SQLITE_OK
		}
		return rc
	}
	zSql = Xsqlite3_mprintf(tls, zFmt, libc.VaList(bp, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName))
	if zSql == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -1, bp+16, uintptr(0))
		if rc == SQLITE_OK {
			if Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) == SQLITE_ROW {
				nRow = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 0)
			}
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
		}
		Xsqlite3_free(tls, zSql)
	}
	(*Rtree)(unsafe.Pointer(pRtree)).FnRowEst = func() int64 {
		if nRow > int64(RTREE_MIN_ROWEST) {
			return nRow
		}
		return int64(RTREE_MIN_ROWEST)
	}()
	return rc
}

func rtreeShadowName(tls *libc.TLS, zName uintptr) int32 {
	var i uint32
	for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(azName1))/uint64(unsafe.Sizeof(uintptr(0))); i++ {
		if Xsqlite3_stricmp(tls, zName, azName1[i]) == 0 {
			return 1
		}
	}
	return 0
}

var azName1 = [3]uintptr{
	ts + 31735, ts + 7985, ts + 11466,
}

var rtreeModule = Sqlite3_module{
	FiVersion:    3,
	FxCreate:     0,
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxDestroy:    0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
	FxUpdate:     0,
	FxBegin:      0,
	FxSync:       0,
	FxCommit:     0,
	FxRollback:   0,
	FxRename:     0,
	FxSavepoint:  0,
	FxShadowName: 0,
}

func rtreeSqlInit(tls *libc.TLS, pRtree uintptr, db uintptr, zDb uintptr, zPrefix uintptr, isCreate int32) int32 {
	bp := tls.Alloc(232)
	defer tls.Free(232)

	var rc int32 = SQLITE_OK

	var i int32
	var f int32 = SQLITE_PREPARE_PERSISTENT | SQLITE_PREPARE_NO_VTAB

	(*Rtree)(unsafe.Pointer(pRtree)).Fdb = db

	if isCreate != 0 {
		var zCreate uintptr
		var p uintptr = Xsqlite3_str_new(tls, db)
		var ii int32
		Xsqlite3_str_appendf(tls, p,
			ts+31740,
			libc.VaList(bp, zDb, zPrefix))
		for ii = 0; ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnAux); ii++ {
			Xsqlite3_str_appendf(tls, p, ts+31802, libc.VaList(bp+16, ii))
		}
		Xsqlite3_str_appendf(tls, p,
			ts+31807,
			libc.VaList(bp+24, zDb, zPrefix))
		Xsqlite3_str_appendf(tls, p,
			ts+31871,
			libc.VaList(bp+40, zDb, zPrefix))
		Xsqlite3_str_appendf(tls, p,
			ts+31941,
			libc.VaList(bp+56, zDb, zPrefix, (*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize))
		zCreate = Xsqlite3_str_finish(tls, p)
		if !(zCreate != 0) {
			return SQLITE_NOMEM
		}
		rc = Xsqlite3_exec(tls, db, zCreate, uintptr(0), uintptr(0), uintptr(0))
		Xsqlite3_free(tls, zCreate)
		if rc != SQLITE_OK {
			return rc
		}
	}

	*(*uintptr)(unsafe.Pointer(bp + 168)) = pRtree + 120
	*(*uintptr)(unsafe.Pointer(bp + 168 + 1*8)) = pRtree + 128
	*(*uintptr)(unsafe.Pointer(bp + 168 + 2*8)) = pRtree + 136
	*(*uintptr)(unsafe.Pointer(bp + 168 + 3*8)) = pRtree + 144
	*(*uintptr)(unsafe.Pointer(bp + 168 + 4*8)) = pRtree + 152
	*(*uintptr)(unsafe.Pointer(bp + 168 + 5*8)) = pRtree + 160
	*(*uintptr)(unsafe.Pointer(bp + 168 + 6*8)) = pRtree + 168
	*(*uintptr)(unsafe.Pointer(bp + 168 + 7*8)) = pRtree + 176

	rc = rtreeQueryStat1(tls, db, pRtree)
	for i = 0; i < N_STATEMENT && rc == SQLITE_OK; i++ {
		var zSql uintptr
		var zFormat uintptr
		if i != 3 || int32((*Rtree)(unsafe.Pointer(pRtree)).FnAux) == 0 {
			zFormat = azSql[i]
		} else {
			zFormat = ts + 31990
		}
		zSql = Xsqlite3_mprintf(tls, zFormat, libc.VaList(bp+80, zDb, zPrefix))
		if zSql != 0 {
			rc = Xsqlite3_prepare_v3(tls, db, zSql, -1, uint32(f), *(*uintptr)(unsafe.Pointer(bp + 168 + uintptr(i)*8)), uintptr(0))
		} else {
			rc = SQLITE_NOMEM
		}
		Xsqlite3_free(tls, zSql)
	}
	if (*Rtree)(unsafe.Pointer(pRtree)).FnAux != 0 {
		(*Rtree)(unsafe.Pointer(pRtree)).FzReadAuxSql = Xsqlite3_mprintf(tls,
			ts+32098,
			libc.VaList(bp+96, zDb, zPrefix))
		if (*Rtree)(unsafe.Pointer(pRtree)).FzReadAuxSql == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			var p uintptr = Xsqlite3_str_new(tls, db)
			var ii int32
			var zSql uintptr
			Xsqlite3_str_appendf(tls, p, ts+32143, libc.VaList(bp+112, zDb, zPrefix))
			for ii = 0; ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnAux); ii++ {
				if ii != 0 {
					Xsqlite3_str_append(tls, p, ts+16195, 1)
				}
				if ii < int32((*Rtree)(unsafe.Pointer(pRtree)).FnAuxNotNull) {
					Xsqlite3_str_appendf(tls, p, ts+32170, libc.VaList(bp+128, ii, ii+2, ii))
				} else {
					Xsqlite3_str_appendf(tls, p, ts+32192, libc.VaList(bp+152, ii, ii+2))
				}
			}
			Xsqlite3_str_appendf(tls, p, ts+32200, 0)
			zSql = Xsqlite3_str_finish(tls, p)
			if zSql == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				rc = Xsqlite3_prepare_v3(tls, db, zSql, -1, uint32(f), pRtree+184, uintptr(0))
				Xsqlite3_free(tls, zSql)
			}
		}
	}

	return rc
}

var azSql = [8]uintptr{
	ts + 32216,
	ts + 32269,
	ts + 32314,
	ts + 32366,
	ts + 32420,
	ts + 32465,
	ts + 32523,
	ts + 32578,
}

func getIntFromStmt(tls *libc.TLS, db uintptr, zSql uintptr, piVal uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_NOMEM
	if zSql != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		rc = Xsqlite3_prepare_v2(tls, db, zSql, -1, bp, uintptr(0))
		if rc == SQLITE_OK {
			if 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
}

func getNodeSize(tls *libc.TLS, db uintptr, pRtree uintptr, isCreate int32, pzErr uintptr) int32 {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var rc int32
	var zSql uintptr
	if isCreate != 0 {
		*(*int32)(unsafe.Pointer(bp + 48)) = 0
		zSql = Xsqlite3_mprintf(tls, ts+32625, libc.VaList(bp, (*Rtree)(unsafe.Pointer(pRtree)).FzDb))
		rc = getIntFromStmt(tls, db, zSql, bp+48)
		if rc == SQLITE_OK {
			(*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize = *(*int32)(unsafe.Pointer(bp + 48)) - 64
			if 4+int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*RTREE_MAXCELLS < (*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize {
				(*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize = 4 + int32((*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell)*RTREE_MAXCELLS
			}
		} else {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+8, Xsqlite3_errmsg(tls, db)))
		}
	} else {
		zSql = Xsqlite3_mprintf(tls,
			ts+32645,
			libc.VaList(bp+16, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, (*Rtree)(unsafe.Pointer(pRtree)).FzName))
		rc = getIntFromStmt(tls, db, zSql, pRtree+32)
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+32, Xsqlite3_errmsg(tls, db)))
		} else if (*Rtree)(unsafe.Pointer(pRtree)).FiNodeSize < 512-64 {
			rc = SQLITE_CORRUPT | int32(1)<<8

			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+32702,
				libc.VaList(bp+40, (*Rtree)(unsafe.Pointer(pRtree)).FzName))
		}
	}

	Xsqlite3_free(tls, zSql)
	return rc
}

func rtreeTokenLength(tls *libc.TLS, z uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = 0
	return Xsqlite3GetToken(tls, z, bp)
}

func rtreeInit(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr, isCreate int32) int32 {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var rc int32
	var pRtree uintptr
	var nDb int32
	var nName int32
	var eCoordType int32
	var pSql uintptr
	var zSql uintptr
	var ii int32
	var iErr int32

	var zArg uintptr
	rc = SQLITE_OK
	eCoordType = func() int32 {
		if pAux != 0 {
			return RTREE_COORD_INT32
		}
		return RTREE_COORD_REAL32
	}()
	ii = 4
	*(*[5]uintptr)(unsafe.Pointer(bp + 96)) = [5]uintptr{
		uintptr(0),
		ts + 32737,
		ts + 32780,
		ts + 32815,
		ts + 32851,
	}

	if !(argc < 6 || argc > RTREE_MAX_AUX_COLUMN+3) {
		goto __1
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(bp + 96 + uintptr(2+libc.Bool32(argc >= 6))*8))))
	return SQLITE_ERROR
__1:
	;
	Xsqlite3_vtab_config(tls, db, SQLITE_VTAB_CONSTRAINT_SUPPORT, libc.VaList(bp+8, 1))

	nDb = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))))
	nName = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))))
	pRtree = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Rtree{}))+uint64(nDb)+uint64(nName)+uint64(2))
	if !!(pRtree != 0) {
		goto __2
	}
	return SQLITE_NOMEM
__2:
	;
	libc.Xmemset(tls, pRtree, 0, uint64(unsafe.Sizeof(Rtree{}))+uint64(nDb)+uint64(nName)+uint64(2))
	(*Rtree)(unsafe.Pointer(pRtree)).FnBusy = U32(1)
	(*Rtree)(unsafe.Pointer(pRtree)).Fbase.FpModule = uintptr(unsafe.Pointer(&rtreeModule))
	(*Rtree)(unsafe.Pointer(pRtree)).FzDb = pRtree + 1*968
	(*Rtree)(unsafe.Pointer(pRtree)).FzName = (*Rtree)(unsafe.Pointer(pRtree)).FzDb + uintptr(nDb+1)
	(*Rtree)(unsafe.Pointer(pRtree)).FeCoordType = U8(eCoordType)
	libc.Xmemcpy(tls, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, *(*uintptr)(unsafe.Pointer(argv + 1*8)), uint64(nDb))
	libc.Xmemcpy(tls, (*Rtree)(unsafe.Pointer(pRtree)).FzName, *(*uintptr)(unsafe.Pointer(argv + 2*8)), uint64(nName))

	pSql = Xsqlite3_str_new(tls, db)
	Xsqlite3_str_appendf(tls, pSql, ts+32888,
		libc.VaList(bp+16, rtreeTokenLength(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8))), *(*uintptr)(unsafe.Pointer(argv + 3*8))))
	ii = 4
__3:
	if !(ii < argc) {
		goto __5
	}
	zArg = *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*8))
	if !(int32(*(*uint8)(unsafe.Pointer(zArg))) == '+') {
		goto __6
	}
	(*Rtree)(unsafe.Pointer(pRtree)).FnAux++
	Xsqlite3_str_appendf(tls, pSql, ts+32912, libc.VaList(bp+32, rtreeTokenLength(tls, zArg+uintptr(1)), zArg+uintptr(1)))
	goto __7
__6:
	if !(int32((*Rtree)(unsafe.Pointer(pRtree)).FnAux) > 0) {
		goto __8
	}
	goto __5
	goto __9
__8:
	(*Rtree)(unsafe.Pointer(pRtree)).FnDim2++
	Xsqlite3_str_appendf(tls, pSql, azFormat[eCoordType],
		libc.VaList(bp+48, rtreeTokenLength(tls, zArg), zArg))
__9:
	;
__7:
	;
	goto __4
__4:
	ii++
	goto __3
	goto __5
__5:
	;
	Xsqlite3_str_appendf(tls, pSql, ts+32918, 0)
	zSql = Xsqlite3_str_finish(tls, pSql)
	if !!(zSql != 0) {
		goto __10
	}
	rc = SQLITE_NOMEM
	goto __11
__10:
	if !(ii < argc) {
		goto __12
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+64, *(*uintptr)(unsafe.Pointer(bp + 96 + 4*8))))
	rc = SQLITE_ERROR
	goto __13
__12:
	if !(SQLITE_OK != libc.AssignInt32(&rc, Xsqlite3_declare_vtab(tls, db, zSql))) {
		goto __14
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+72, Xsqlite3_errmsg(tls, db)))
__14:
	;
__13:
	;
__11:
	;
	Xsqlite3_free(tls, zSql)
	if !(rc != 0) {
		goto __15
	}
	goto rtreeInit_fail
__15:
	;
	(*Rtree)(unsafe.Pointer(pRtree)).FnDim = U8(int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2) / 2)
	if !(int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim) < 1) {
		goto __16
	}
	iErr = 2
	goto __17
__16:
	if !(int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2) > RTREE_MAX_DIMENSIONS*2) {
		goto __18
	}
	iErr = 3
	goto __19
__18:
	if !(int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2)%2 != 0) {
		goto __20
	}
	iErr = 1
	goto __21
__20:
	iErr = 0
__21:
	;
__19:
	;
__17:
	;
	if !(iErr != 0) {
		goto __22
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+80, *(*uintptr)(unsafe.Pointer(bp + 96 + uintptr(iErr)*8))))
	goto rtreeInit_fail
__22:
	;
	(*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell = U8(8 + int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2)*4)

	rc = getNodeSize(tls, db, pRtree, isCreate, pzErr)
	if !(rc != 0) {
		goto __23
	}
	goto rtreeInit_fail
__23:
	;
	rc = rtreeSqlInit(tls, pRtree, db, *(*uintptr)(unsafe.Pointer(argv + 1*8)), *(*uintptr)(unsafe.Pointer(argv + 2*8)), isCreate)
	if !(rc != 0) {
		goto __24
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+88, Xsqlite3_errmsg(tls, db)))
	goto rtreeInit_fail
__24:
	;
	*(*uintptr)(unsafe.Pointer(ppVtab)) = pRtree
	return SQLITE_OK

rtreeInit_fail:
	if !(rc == SQLITE_OK) {
		goto __25
	}
	rc = SQLITE_ERROR
__25:
	;
	rtreeRelease(tls, pRtree)
	return rc
}

var azFormat = [2]uintptr{ts + 32921, ts + 32932}

func rtreenode(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	bp := tls.Alloc(1072)
	defer tls.Free(1072)

	var ii int32
	var nData int32
	var errCode int32
	var pOut uintptr

	_ = nArg
	libc.Xmemset(tls, bp+16, 0, uint64(unsafe.Sizeof(RtreeNode{})))
	libc.Xmemset(tls, bp+56, 0, uint64(unsafe.Sizeof(Rtree{})))
	(*Rtree)(unsafe.Pointer(bp + 56)).FnDim = U8(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apArg))))
	if int32((*Rtree)(unsafe.Pointer(bp+56)).FnDim) < 1 || int32((*Rtree)(unsafe.Pointer(bp+56)).FnDim) > 5 {
		return
	}
	(*Rtree)(unsafe.Pointer(bp + 56)).FnDim2 = U8(int32((*Rtree)(unsafe.Pointer(bp+56)).FnDim) * 2)
	(*Rtree)(unsafe.Pointer(bp + 56)).FnBytesPerCell = U8(8 + 8*int32((*Rtree)(unsafe.Pointer(bp+56)).FnDim))
	(*RtreeNode)(unsafe.Pointer(bp + 16)).FzData = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*8)))
	if (*RtreeNode)(unsafe.Pointer(bp+16)).FzData == uintptr(0) {
		return
	}
	nData = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*8)))
	if nData < 4 {
		return
	}
	if nData < readInt16(tls, (*RtreeNode)(unsafe.Pointer(bp+16)).FzData+2)*int32((*Rtree)(unsafe.Pointer(bp+56)).FnBytesPerCell) {
		return
	}

	pOut = Xsqlite3_str_new(tls, uintptr(0))
	for ii = 0; ii < readInt16(tls, (*RtreeNode)(unsafe.Pointer(bp+16)).FzData+2); ii++ {
		var jj int32

		nodeGetCell(tls, bp+56, bp+16, ii, bp+1024)
		if ii > 0 {
			Xsqlite3_str_append(tls, pOut, ts+14304, 1)
		}
		Xsqlite3_str_appendf(tls, pOut, ts+32942, libc.VaList(bp, (*RtreeCell)(unsafe.Pointer(bp+1024)).FiRowid))
		for jj = 0; jj < int32((*Rtree)(unsafe.Pointer(bp+56)).FnDim2); jj++ {
			Xsqlite3_str_appendf(tls, pOut, ts+32948, libc.VaList(bp+8, float64(*(*RtreeValue)(unsafe.Pointer(bp + 1024 + 8 + uintptr(jj)*4)))))
		}
		Xsqlite3_str_append(tls, pOut, ts+32952, 1)
	}
	errCode = Xsqlite3_str_errcode(tls, pOut)
	Xsqlite3_result_text(tls, ctx, Xsqlite3_str_finish(tls, pOut), -1, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
	Xsqlite3_result_error_code(tls, ctx, errCode)
}

func rtreedepth(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	_ = nArg
	if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apArg))) != SQLITE_BLOB ||
		Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apArg))) < 2 {
		Xsqlite3_result_error(tls, ctx, ts+32954, -1)
	} else {
		var zBlob uintptr = 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)
		}
	}
}

type RtreeCheck1 = struct {
	Fdb            uintptr
	FzDb           uintptr
	FzTab          uintptr
	FbInt          int32
	FnDim          int32
	FpGetNode      uintptr
	FaCheckMapping [2]uintptr
	FnLeaf         int32
	FnNonLeaf      int32
	Frc            int32
	F__ccgo_pad1   [4]byte
	FzReport       uintptr
	FnErr          int32
	F__ccgo_pad2   [4]byte
}

type RtreeCheck = RtreeCheck1

func rtreeCheckReset(tls *libc.TLS, pCheck uintptr, pStmt uintptr) {
	var rc int32 = Xsqlite3_reset(tls, pStmt)
	if (*RtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		(*RtreeCheck)(unsafe.Pointer(pCheck)).Frc = rc
	}
}

func rtreeCheckPrepare(tls *libc.TLS, pCheck uintptr, zFmt uintptr, va uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var ap Va_list
	_ = ap
	var z uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)

	ap = va
	z = Xsqlite3_vmprintf(tls, zFmt, ap)

	if (*RtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		if z == uintptr(0) {
			(*RtreeCheck)(unsafe.Pointer(pCheck)).Frc = SQLITE_NOMEM
		} else {
			(*RtreeCheck)(unsafe.Pointer(pCheck)).Frc = Xsqlite3_prepare_v2(tls, (*RtreeCheck)(unsafe.Pointer(pCheck)).Fdb, z, -1, bp, uintptr(0))
		}
	}

	Xsqlite3_free(tls, z)
	_ = ap
	return *(*uintptr)(unsafe.Pointer(bp))
}

func rtreeCheckAppendMsg(tls *libc.TLS, pCheck uintptr, zFmt uintptr, va uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var ap Va_list
	_ = ap
	ap = va
	if (*RtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && (*RtreeCheck)(unsafe.Pointer(pCheck)).FnErr < RTREE_CHECK_MAX_ERROR {
		var z uintptr = Xsqlite3_vmprintf(tls, zFmt, ap)
		if z == uintptr(0) {
			(*RtreeCheck)(unsafe.Pointer(pCheck)).Frc = SQLITE_NOMEM
		} else {
			(*RtreeCheck)(unsafe.Pointer(pCheck)).FzReport = Xsqlite3_mprintf(tls, ts+32987,
				libc.VaList(bp, (*RtreeCheck)(unsafe.Pointer(pCheck)).FzReport, func() uintptr {
					if (*RtreeCheck)(unsafe.Pointer(pCheck)).FzReport != 0 {
						return ts + 6942
					}
					return ts + 1636
				}(), z))
			if (*RtreeCheck)(unsafe.Pointer(pCheck)).FzReport == uintptr(0) {
				(*RtreeCheck)(unsafe.Pointer(pCheck)).Frc = SQLITE_NOMEM
			}
		}
		(*RtreeCheck)(unsafe.Pointer(pCheck)).FnErr++
	}
	_ = ap
}

func rtreeCheckGetNode(tls *libc.TLS, pCheck uintptr, iNode I64, pnNode uintptr) uintptr {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pRet uintptr = uintptr(0)

	if (*RtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && (*RtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode == uintptr(0) {
		(*RtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode = rtreeCheckPrepare(tls, pCheck,
			ts+32994,
			libc.VaList(bp, (*RtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*RtreeCheck)(unsafe.Pointer(pCheck)).FzTab))
	}

	if (*RtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		Xsqlite3_bind_int64(tls, (*RtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 1, iNode)
		if Xsqlite3_step(tls, (*RtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode) == SQLITE_ROW {
			var nNode int32 = Xsqlite3_column_bytes(tls, (*RtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 0)
			var pNode uintptr = Xsqlite3_column_blob(tls, (*RtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode, 0)
			pRet = Xsqlite3_malloc64(tls, uint64(nNode))
			if pRet == uintptr(0) {
				(*RtreeCheck)(unsafe.Pointer(pCheck)).Frc = SQLITE_NOMEM
			} else {
				libc.Xmemcpy(tls, pRet, pNode, uint64(nNode))
				*(*int32)(unsafe.Pointer(pnNode)) = nNode
			}
		}
		rtreeCheckReset(tls, pCheck, (*RtreeCheck)(unsafe.Pointer(pCheck)).FpGetNode)
		if (*RtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK && pRet == uintptr(0) {
			rtreeCheckAppendMsg(tls, pCheck, ts+33039, libc.VaList(bp+16, iNode))
		}
	}

	return pRet
}

func rtreeCheckMapping(tls *libc.TLS, pCheck uintptr, bLeaf int32, iKey I64, iVal I64) {
	bp := tls.Alloc(96)
	defer tls.Free(96)

	var rc int32
	var pStmt uintptr
	*(*[2]uintptr)(unsafe.Pointer(bp + 80)) = [2]uintptr{
		ts + 33071,
		ts + 33125,
	}

	if *(*uintptr)(unsafe.Pointer(pCheck + 40 + uintptr(bLeaf)*8)) == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(pCheck + 40 + uintptr(bLeaf)*8)) = rtreeCheckPrepare(tls, pCheck,
			*(*uintptr)(unsafe.Pointer(bp + 80 + uintptr(bLeaf)*8)), libc.VaList(bp, (*RtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*RtreeCheck)(unsafe.Pointer(pCheck)).FzTab))
	}
	if (*RtreeCheck)(unsafe.Pointer(pCheck)).Frc != SQLITE_OK {
		return
	}

	pStmt = *(*uintptr)(unsafe.Pointer(pCheck + 40 + uintptr(bLeaf)*8))
	Xsqlite3_bind_int64(tls, pStmt, 1, iKey)
	rc = Xsqlite3_step(tls, pStmt)
	if rc == SQLITE_DONE {
		rtreeCheckAppendMsg(tls, pCheck, ts+33173,
			libc.VaList(bp+16, iKey, iVal, func() uintptr {
				if bLeaf != 0 {
					return ts + 33218
				}
				return ts + 33226
			}()))
	} else if rc == SQLITE_ROW {
		var ii I64 = Xsqlite3_column_int64(tls, pStmt, 0)
		if ii != iVal {
			rtreeCheckAppendMsg(tls, pCheck,
				ts+33235,
				libc.VaList(bp+40, iKey, ii, func() uintptr {
					if bLeaf != 0 {
						return ts + 33218
					}
					return ts + 33226
				}(), iKey, iVal))
		}
	}
	rtreeCheckReset(tls, pCheck, pStmt)
}

func rtreeCheckCellCoord(tls *libc.TLS, pCheck uintptr, iNode I64, iCell int32, pCell uintptr, pParent uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var i int32

	for i = 0; i < (*RtreeCheck)(unsafe.Pointer(pCheck)).FnDim; i++ {
		readCoord(tls, pCell+uintptr(4*2*i), bp+48)
		readCoord(tls, pCell+uintptr(4*(2*i+1)), bp+52)

		if func() int32 {
			if (*RtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
				return libc.Bool32(*(*int32)(unsafe.Pointer(bp + 48)) > *(*int32)(unsafe.Pointer(bp + 52)))
			}
			return libc.Bool32(*(*RtreeValue)(unsafe.Pointer(bp + 48)) > *(*RtreeValue)(unsafe.Pointer(bp + 52)))
		}() != 0 {
			rtreeCheckAppendMsg(tls, pCheck,
				ts+33293, libc.VaList(bp, i, iCell, iNode))
		}

		if pParent != 0 {
			readCoord(tls, pParent+uintptr(4*2*i), bp+56)
			readCoord(tls, pParent+uintptr(4*(2*i+1)), bp+60)

			if func() int32 {
				if (*RtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
					return libc.Bool32(*(*int32)(unsafe.Pointer(bp + 48)) < *(*int32)(unsafe.Pointer(bp + 56)))
				}
				return libc.Bool32(*(*RtreeValue)(unsafe.Pointer(bp + 48)) < *(*RtreeValue)(unsafe.Pointer(bp + 56)))
			}() != 0 ||
				func() int32 {
					if (*RtreeCheck)(unsafe.Pointer(pCheck)).FbInt != 0 {
						return libc.Bool32(*(*int32)(unsafe.Pointer(bp + 52)) > *(*int32)(unsafe.Pointer(bp + 60)))
					}
					return libc.Bool32(*(*RtreeValue)(unsafe.Pointer(bp + 52)) > *(*RtreeValue)(unsafe.Pointer(bp + 60)))
				}() != 0 {
				rtreeCheckAppendMsg(tls, pCheck,
					ts+33341, libc.VaList(bp+24, i, iCell, iNode))
			}
		}
	}
}

func rtreeCheckNode(tls *libc.TLS, pCheck uintptr, iDepth int32, aParent uintptr, iNode I64) {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var aNode uintptr = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 48)) = 0

	aNode = rtreeCheckGetNode(tls, pCheck, iNode, bp+48)
	if aNode != 0 {
		if *(*int32)(unsafe.Pointer(bp + 48)) < 4 {
			rtreeCheckAppendMsg(tls, pCheck,
				ts+33408, libc.VaList(bp, iNode, *(*int32)(unsafe.Pointer(bp + 48))))
		} else {
			var nCell int32
			var i int32
			if aParent == uintptr(0) {
				iDepth = readInt16(tls, aNode)
				if iDepth > RTREE_MAX_DEPTH {
					rtreeCheckAppendMsg(tls, pCheck, ts+33442, libc.VaList(bp+16, iDepth))
					Xsqlite3_free(tls, aNode)
					return
				}
			}
			nCell = readInt16(tls, aNode+2)
			if 4+nCell*(8+(*RtreeCheck)(unsafe.Pointer(pCheck)).FnDim*2*4) > *(*int32)(unsafe.Pointer(bp + 48)) {
				rtreeCheckAppendMsg(tls, pCheck,
					ts+33472,
					libc.VaList(bp+24, iNode, nCell, *(*int32)(unsafe.Pointer(bp + 48))))
			} else {
				for i = 0; i < nCell; i++ {
					var pCell uintptr = aNode + uintptr(4+i*(8+(*RtreeCheck)(unsafe.Pointer(pCheck)).FnDim*2*4))
					var iVal I64 = readInt64(tls, pCell)
					rtreeCheckCellCoord(tls, pCheck, iNode, i, pCell+8, aParent)

					if iDepth > 0 {
						rtreeCheckMapping(tls, pCheck, 0, iVal, iNode)
						rtreeCheckNode(tls, pCheck, iDepth-1, pCell+8, iVal)
						(*RtreeCheck)(unsafe.Pointer(pCheck)).FnNonLeaf++
					} else {
						rtreeCheckMapping(tls, pCheck, 1, iVal, iNode)
						(*RtreeCheck)(unsafe.Pointer(pCheck)).FnLeaf++
					}
				}
			}
		}
		Xsqlite3_free(tls, aNode)
	}
}

func rtreeCheckCount(tls *libc.TLS, pCheck uintptr, zTbl uintptr, nExpect I64) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if (*RtreeCheck)(unsafe.Pointer(pCheck)).Frc == SQLITE_OK {
		var pCount uintptr
		pCount = rtreeCheckPrepare(tls, pCheck, ts+33527,
			libc.VaList(bp, (*RtreeCheck)(unsafe.Pointer(pCheck)).FzDb, (*RtreeCheck)(unsafe.Pointer(pCheck)).FzTab, zTbl))
		if pCount != 0 {
			if Xsqlite3_step(tls, pCount) == SQLITE_ROW {
				var nActual I64 = Xsqlite3_column_int64(tls, pCount, 0)
				if nActual != nExpect {
					rtreeCheckAppendMsg(tls, pCheck,
						ts+33558, libc.VaList(bp+24, zTbl, nExpect, nActual))
				}
			}
			(*RtreeCheck)(unsafe.Pointer(pCheck)).Frc = Xsqlite3_finalize(tls, pCount)
		}
	}
}

func rtreeCheckTable(tls *libc.TLS, db uintptr, zDb uintptr, zTab uintptr, pzReport uintptr) int32 {
	bp := tls.Alloc(120)
	defer tls.Free(120)

	var pStmt uintptr = uintptr(0)
	var bEnd int32 = 0
	var nAux int32 = 0

	libc.Xmemset(tls, bp+32, 0, uint64(unsafe.Sizeof(RtreeCheck{})))
	(*RtreeCheck)(unsafe.Pointer(bp + 32)).Fdb = db
	(*RtreeCheck)(unsafe.Pointer(bp + 32)).FzDb = zDb
	(*RtreeCheck)(unsafe.Pointer(bp + 32)).FzTab = zTab

	if Xsqlite3_get_autocommit(tls, db) != 0 {
		(*RtreeCheck)(unsafe.Pointer(bp + 32)).Frc = Xsqlite3_exec(tls, db, ts+17925, uintptr(0), uintptr(0), uintptr(0))
		bEnd = 1
	}

	if (*RtreeCheck)(unsafe.Pointer(bp+32)).Frc == SQLITE_OK {
		pStmt = rtreeCheckPrepare(tls, bp+32, ts+33625, libc.VaList(bp, zDb, zTab))
		if pStmt != 0 {
			nAux = Xsqlite3_column_count(tls, pStmt) - 2
			Xsqlite3_finalize(tls, pStmt)
		} else if (*RtreeCheck)(unsafe.Pointer(bp+32)).Frc != SQLITE_NOMEM {
			(*RtreeCheck)(unsafe.Pointer(bp + 32)).Frc = SQLITE_OK
		}
	}

	pStmt = rtreeCheckPrepare(tls, bp+32, ts+31445, libc.VaList(bp+16, zDb, zTab))
	if pStmt != 0 {
		var rc int32
		(*RtreeCheck)(unsafe.Pointer(bp + 32)).FnDim = (Xsqlite3_column_count(tls, pStmt) - 1 - nAux) / 2
		if (*RtreeCheck)(unsafe.Pointer(bp+32)).FnDim < 1 {
			rtreeCheckAppendMsg(tls, bp+32, ts+33653, 0)
		} else if SQLITE_ROW == Xsqlite3_step(tls, pStmt) {
			(*RtreeCheck)(unsafe.Pointer(bp + 32)).FbInt = libc.Bool32(Xsqlite3_column_type(tls, pStmt, 1) == SQLITE_INTEGER)
		}
		rc = Xsqlite3_finalize(tls, pStmt)
		if rc != SQLITE_CORRUPT {
			(*RtreeCheck)(unsafe.Pointer(bp + 32)).Frc = rc
		}
	}

	if (*RtreeCheck)(unsafe.Pointer(bp+32)).FnDim >= 1 {
		if (*RtreeCheck)(unsafe.Pointer(bp+32)).Frc == SQLITE_OK {
			rtreeCheckNode(tls, bp+32, 0, uintptr(0), int64(1))
		}
		rtreeCheckCount(tls, bp+32, ts+33684, int64((*RtreeCheck)(unsafe.Pointer(bp+32)).FnLeaf))
		rtreeCheckCount(tls, bp+32, ts+33691, int64((*RtreeCheck)(unsafe.Pointer(bp+32)).FnNonLeaf))
	}

	Xsqlite3_finalize(tls, (*RtreeCheck)(unsafe.Pointer(bp+32)).FpGetNode)
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 40)))
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 40 + 1*8)))

	if bEnd != 0 {
		var rc int32 = Xsqlite3_exec(tls, db, ts+33699, uintptr(0), uintptr(0), uintptr(0))
		if (*RtreeCheck)(unsafe.Pointer(bp+32)).Frc == SQLITE_OK {
			(*RtreeCheck)(unsafe.Pointer(bp + 32)).Frc = rc
		}
	}
	*(*uintptr)(unsafe.Pointer(pzReport)) = (*RtreeCheck)(unsafe.Pointer(bp + 32)).FzReport
	return (*RtreeCheck)(unsafe.Pointer(bp + 32)).Frc
}

func rtreecheck(tls *libc.TLS, ctx uintptr, nArg int32, apArg uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if nArg != 1 && nArg != 2 {
		Xsqlite3_result_error(tls, ctx,
			ts+33703, -1)
	} else {
		var rc int32
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		var zDb uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apArg)))
		var zTab uintptr
		if nArg == 1 {
			zTab = zDb
			zDb = ts + 9656
		} else {
			zTab = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apArg + 1*8)))
		}
		rc = rtreeCheckTable(tls, Xsqlite3_context_db_handle(tls, ctx), zDb, zTab, bp)
		if rc == SQLITE_OK {
			Xsqlite3_result_text(tls, ctx, func() uintptr {
				if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
					return *(*uintptr)(unsafe.Pointer(bp))
				}
				return ts + 6208
			}(), -1, libc.UintptrFromInt32(-1))
		} else {
			Xsqlite3_result_error_code(tls, ctx, rc)
		}
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}
}

type GeoCoord = float32

type GeoPoly1 = struct {
	FnVertex int32
	Fhdr     [4]uint8
	Fa       [8]GeoCoord
}

type GeoPoly = GeoPoly1

type GeoParse1 = struct {
	Fz           uintptr
	FnVertex     int32
	FnAlloc      int32
	FnErr        int32
	F__ccgo_pad1 [4]byte
	Fa           uintptr
}

type GeoParse = GeoParse1

func geopolySwab32(tls *libc.TLS, a uintptr) {
	var t uint8 = *(*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
}

func geopolySkipSpace(tls *libc.TLS, p uintptr) uint8 {
	for jsonIsSpace[*(*uint8)(unsafe.Pointer((*GeoParse)(unsafe.Pointer(p)).Fz))] != 0 {
		(*GeoParse)(unsafe.Pointer(p)).Fz++
	}
	return *(*uint8)(unsafe.Pointer((*GeoParse)(unsafe.Pointer(p)).Fz))
}

func geopolyParseNumber(tls *libc.TLS, p uintptr, pVal uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var c uint8 = geopolySkipSpace(tls, p)
	var z uintptr = (*GeoParse)(unsafe.Pointer(p)).Fz
	var j int32 = 0
	var seenDP int32 = 0
	var seenE int32 = 0
	if int32(c) == '-' {
		j = 1
		c = *(*uint8)(unsafe.Pointer(z + uintptr(j)))
	}
	if int32(c) == '0' && int32(*(*uint8)(unsafe.Pointer(z + uintptr(j+1)))) >= '0' && int32(*(*uint8)(unsafe.Pointer(z + uintptr(j+1)))) <= '9' {
		return 0
	}
	for ; ; j++ {
		c = *(*uint8)(unsafe.Pointer(z + uintptr(j)))
		if int32(Xsqlite3CtypeMap[c])&0x04 != 0 {
			continue
		}
		if int32(c) == '.' {
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-1)))) == '-' {
				return 0
			}
			if seenDP != 0 {
				return 0
			}
			seenDP = 1
			continue
		}
		if int32(c) == 'e' || int32(c) == 'E' {
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-1)))) < '0' {
				return 0
			}
			if seenE != 0 {
				return -1
			}
			seenDP = libc.AssignInt32(&seenE, 1)
			c = *(*uint8)(unsafe.Pointer(z + uintptr(j+1)))
			if int32(c) == '+' || int32(c) == '-' {
				j++
				c = *(*uint8)(unsafe.Pointer(z + uintptr(j+1)))
			}
			if int32(c) < '0' || int32(c) > '9' {
				return 0
			}
			continue
		}
		break
	}
	if int32(*(*uint8)(unsafe.Pointer(z + uintptr(j-1)))) < '0' {
		return 0
	}
	if pVal != 0 {
		Xsqlite3AtoF(tls, (*GeoParse)(unsafe.Pointer(p)).Fz, bp, j, uint8(SQLITE_UTF8))
		*(*GeoCoord)(unsafe.Pointer(pVal)) = GeoCoord(*(*float64)(unsafe.Pointer(bp)))
	}
	*(*uintptr)(unsafe.Pointer(p)) += uintptr(j)
	return 1
}

func geopolyParseJson(tls *libc.TLS, z uintptr, pRc uintptr) uintptr {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var rc int32
	var aNew uintptr
	var ii int32
	var c uint8
	var pOut uintptr

	rc = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(GeoParse{})))
	(*GeoParse)(unsafe.Pointer(bp)).Fz = z
	if !(int32(geopolySkipSpace(tls, bp)) == '[') {
		goto __1
	}
	(*GeoParse)(unsafe.Pointer(bp)).Fz++
__2:
	if !(int32(geopolySkipSpace(tls, bp)) == '[') {
		goto __3
	}
	ii = 0
	(*GeoParse)(unsafe.Pointer(bp)).Fz++
	if !((*GeoParse)(unsafe.Pointer(bp)).FnVertex >= (*GeoParse)(unsafe.Pointer(bp)).FnAlloc) {
		goto __4
	}
	(*GeoParse)(unsafe.Pointer(bp)).FnAlloc = (*GeoParse)(unsafe.Pointer(bp)).FnAlloc*2 + 16
	aNew = Xsqlite3_realloc64(tls, (*GeoParse)(unsafe.Pointer(bp)).Fa, uint64((*GeoParse)(unsafe.Pointer(bp)).FnAlloc)*uint64(unsafe.Sizeof(GeoCoord(0)))*uint64(2))
	if !(aNew == uintptr(0)) {
		goto __5
	}
	rc = SQLITE_NOMEM
	(*GeoParse)(unsafe.Pointer(bp)).FnErr++
	goto __3
__5:
	;
	(*GeoParse)(unsafe.Pointer(bp)).Fa = aNew
__4:
	;
__6:
	if !(geopolyParseNumber(tls, bp, func() uintptr {
		if ii <= 1 {
			return (*GeoParse)(unsafe.Pointer(bp)).Fa + uintptr((*GeoParse)(unsafe.Pointer(bp)).FnVertex*2+ii)*4
		}
		return uintptr(0)
	}()) != 0) {
		goto __7
	}
	ii++
	if !(ii == 2) {
		goto __8
	}
	(*GeoParse)(unsafe.Pointer(bp)).FnVertex++
__8:
	;
	c = geopolySkipSpace(tls, bp)
	(*GeoParse)(unsafe.Pointer(bp)).Fz++
	if !(int32(c) == ',') {
		goto __9
	}
	goto __6
__9:
	;
	if !(int32(c) == ']' && ii >= 2) {
		goto __10
	}
	goto __7
__10:
	;
	(*GeoParse)(unsafe.Pointer(bp)).FnErr++
	rc = SQLITE_ERROR
	goto parse_json_err
	goto __6
__7:
	;
	if !(int32(geopolySkipSpace(tls, bp)) == ',') {
		goto __11
	}
	(*GeoParse)(unsafe.Pointer(bp)).Fz++
	goto __2
__11:
	;
	goto __3
	goto __2
__3:
	;
	if !(int32(geopolySkipSpace(tls, bp)) == ']' &&
		(*GeoParse)(unsafe.Pointer(bp)).FnVertex >= 4 &&
		*(*GeoCoord)(unsafe.Pointer((*GeoParse)(unsafe.Pointer(bp)).Fa)) == *(*GeoCoord)(unsafe.Pointer((*GeoParse)(unsafe.Pointer(bp)).Fa + uintptr((*GeoParse)(unsafe.Pointer(bp)).FnVertex*2-2)*4)) &&
		*(*GeoCoord)(unsafe.Pointer((*GeoParse)(unsafe.Pointer(bp)).Fa + 1*4)) == *(*GeoCoord)(unsafe.Pointer((*GeoParse)(unsafe.Pointer(bp)).Fa + uintptr((*GeoParse)(unsafe.Pointer(bp)).FnVertex*2-1)*4)) &&
		func() bool { (*GeoParse)(unsafe.Pointer(bp)).Fz++; return int32(geopolySkipSpace(tls, bp)) == 0 }()) {
		goto __12
	}
	*(*int32)(unsafe.Pointer(bp + 32)) = 1
	(*GeoParse)(unsafe.Pointer(bp)).FnVertex--
	pOut = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(GeoPoly{}))+uint64(unsafe.Sizeof(GeoCoord(0)))*uint64(2)*uint64(Sqlite3_int64((*GeoParse)(unsafe.Pointer(bp)).FnVertex)-int64(4)))
	*(*int32)(unsafe.Pointer(bp + 32)) = 1
	if !(pOut == uintptr(0)) {
		goto __14
	}
	goto parse_json_err
__14:
	;
	(*GeoPoly)(unsafe.Pointer(pOut)).FnVertex = (*GeoParse)(unsafe.Pointer(bp)).FnVertex
	libc.Xmemcpy(tls, pOut+8, (*GeoParse)(unsafe.Pointer(bp)).Fa, uint64((*GeoParse)(unsafe.Pointer(bp)).FnVertex*2)*uint64(unsafe.Sizeof(GeoCoord(0))))
	*(*uint8)(unsafe.Pointer(pOut + 4)) = *(*uint8)(unsafe.Pointer(bp + 32))
	*(*uint8)(unsafe.Pointer(pOut + 4 + 1)) = uint8((*GeoParse)(unsafe.Pointer(bp)).FnVertex >> 16 & 0xff)
	*(*uint8)(unsafe.Pointer(pOut + 4 + 2)) = uint8((*GeoParse)(unsafe.Pointer(bp)).FnVertex >> 8 & 0xff)
	*(*uint8)(unsafe.Pointer(pOut + 4 + 3)) = uint8((*GeoParse)(unsafe.Pointer(bp)).FnVertex & 0xff)
	Xsqlite3_free(tls, (*GeoParse)(unsafe.Pointer(bp)).Fa)
	if !(pRc != 0) {
		goto __15
	}
	*(*int32)(unsafe.Pointer(pRc)) = SQLITE_OK
__15:
	;
	return pOut
	goto __13
__12:
	(*GeoParse)(unsafe.Pointer(bp)).FnErr++
	rc = SQLITE_ERROR
__13:
	;
__1:
	;
parse_json_err:
	if !(pRc != 0) {
		goto __16
	}
	*(*int32)(unsafe.Pointer(pRc)) = rc
__16:
	;
	Xsqlite3_free(tls, (*GeoParse)(unsafe.Pointer(bp)).Fa)
	return uintptr(0)
}

func geopolyFuncParam(tls *libc.TLS, pCtx uintptr, pVal uintptr, pRc uintptr) uintptr {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var p uintptr = uintptr(0)
	var nByte int32

	if Xsqlite3_value_type(tls, pVal) == SQLITE_BLOB &&
		libc.AssignInt32(&nByte, Xsqlite3_value_bytes(tls, pVal)) >= int32(uint64(4)+uint64(6)*uint64(unsafe.Sizeof(GeoCoord(0)))) {
		var a uintptr = Xsqlite3_value_blob(tls, pVal)
		var nVertex int32
		if a == uintptr(0) {
			if pCtx != 0 {
				Xsqlite3_result_error_nomem(tls, pCtx)
			}
			return uintptr(0)
		}
		nVertex = int32(*(*uint8)(unsafe.Pointer(a + 1)))<<16 + int32(*(*uint8)(unsafe.Pointer(a + 2)))<<8 + int32(*(*uint8)(unsafe.Pointer(a + 3)))
		if (int32(*(*uint8)(unsafe.Pointer(a))) == 0 || int32(*(*uint8)(unsafe.Pointer(a))) == 1) &&
			uint64(nVertex*2)*uint64(unsafe.Sizeof(GeoCoord(0)))+uint64(4) == uint64(uint32(nByte)) {
			p = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(GeoPoly{}))+uint64((nVertex-1)*2)*uint64(unsafe.Sizeof(GeoCoord(0))))
			if p == uintptr(0) {
				if pRc != 0 {
					*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
				}
				if pCtx != 0 {
					Xsqlite3_result_error_nomem(tls, pCtx)
				}
			} else {
				*(*int32)(unsafe.Pointer(bp)) = 1
				(*GeoPoly)(unsafe.Pointer(p)).FnVertex = nVertex
				libc.Xmemcpy(tls, p+4, a, uint64(nByte))
				if int32(*(*uint8)(unsafe.Pointer(a))) != int32(*(*uint8)(unsafe.Pointer(bp))) {
					var ii int32
					for ii = 0; ii < nVertex; ii++ {
						geopolySwab32(tls, p+8+uintptr(ii*2)*4)
						geopolySwab32(tls, p+8+uintptr(ii*2+1)*4)
					}
					*(*uint8)(unsafe.Pointer(p + 4)) ^= uint8(1)
				}
			}
		}
		if pRc != 0 {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_OK
		}
		return p
	} else if Xsqlite3_value_type(tls, pVal) == SQLITE_TEXT {
		var zJson uintptr = Xsqlite3_value_text(tls, pVal)
		if zJson == uintptr(0) {
			if pRc != 0 {
				*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
			}
			return uintptr(0)
		}
		return geopolyParseJson(tls, zJson, pRc)
	} else {
		if pRc != 0 {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_ERROR
		}
		return uintptr(0)
	}
	return uintptr(0)
}

func geopolyBlobFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	_ = argc
	if p != 0 {
		Xsqlite3_result_blob(tls, context, p+4,
			4+8*(*GeoPoly)(unsafe.Pointer(p)).FnVertex, libc.UintptrFromInt32(-1))
		Xsqlite3_free(tls, p)
	}
}

func geopolyJsonFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var p uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	_ = argc
	if p != 0 {
		var db uintptr = Xsqlite3_context_db_handle(tls, context)
		var x uintptr = Xsqlite3_str_new(tls, db)
		var i int32
		Xsqlite3_str_append(tls, x, ts+33754, 1)
		for i = 0; i < (*GeoPoly)(unsafe.Pointer(p)).FnVertex; i++ {
			Xsqlite3_str_appendf(tls, x, ts+33756, libc.VaList(bp, float64(*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(i*2)*4))), float64(*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(i*2+1)*4)))))
		}
		Xsqlite3_str_appendf(tls, x, ts+33767, libc.VaList(bp+16, float64(*(*GeoCoord)(unsafe.Pointer(p + 8))), float64(*(*GeoCoord)(unsafe.Pointer(p + 8 + 1*4)))))
		Xsqlite3_result_text(tls, context, Xsqlite3_str_finish(tls, x), -1, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
		Xsqlite3_free(tls, p)
	}
}

func geopolySvgFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var p uintptr
	if argc < 1 {
		return
	}
	p = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	if p != 0 {
		var db uintptr = Xsqlite3_context_db_handle(tls, context)
		var x uintptr = Xsqlite3_str_new(tls, db)
		var i int32
		var cSep uint8 = uint8('\'')
		Xsqlite3_str_appendf(tls, x, ts+33778, 0)
		for i = 0; i < (*GeoPoly)(unsafe.Pointer(p)).FnVertex; i++ {
			Xsqlite3_str_appendf(tls, x, ts+33796, libc.VaList(bp, int32(cSep), float64(*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(i*2)*4))), float64(*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(i*2+1)*4)))))
			cSep = uint8(' ')
		}
		Xsqlite3_str_appendf(tls, x, ts+33804, libc.VaList(bp+24, float64(*(*GeoCoord)(unsafe.Pointer(p + 8))), float64(*(*GeoCoord)(unsafe.Pointer(p + 8 + 1*4)))))
		for i = 1; i < argc; i++ {
			var z uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(i)*8)))
			if z != 0 && *(*uint8)(unsafe.Pointer(z)) != 0 {
				Xsqlite3_str_appendf(tls, x, ts+33812, libc.VaList(bp+40, z))
			}
		}
		Xsqlite3_str_appendf(tls, x, ts+33816, 0)
		Xsqlite3_result_text(tls, context, Xsqlite3_str_finish(tls, x), -1, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
		Xsqlite3_free(tls, p)
	}
}

func geopolyXformFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	var A float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	var B float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8)))
	var C float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8)))
	var D float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 4*8)))
	var E float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 5*8)))
	var F float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 6*8)))
	var x1 GeoCoord
	var y1 GeoCoord
	var x0 GeoCoord
	var y0 GeoCoord
	var ii int32
	_ = argc
	if p != 0 {
		for ii = 0; ii < (*GeoPoly)(unsafe.Pointer(p)).FnVertex; ii++ {
			x0 = *(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2)*4))
			y0 = *(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2+1)*4))
			x1 = GeoCoord(A*float64(x0) + B*float64(y0) + E)
			y1 = GeoCoord(C*float64(x0) + D*float64(y0) + F)
			*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2)*4)) = x1
			*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2+1)*4)) = y1
		}
		Xsqlite3_result_blob(tls, context, p+4,
			4+8*(*GeoPoly)(unsafe.Pointer(p)).FnVertex, libc.UintptrFromInt32(-1))
		Xsqlite3_free(tls, p)
	}
}

func geopolyArea(tls *libc.TLS, p uintptr) float64 {
	var rArea float64 = 0.0
	var ii int32
	for ii = 0; ii < (*GeoPoly)(unsafe.Pointer(p)).FnVertex-1; ii++ {
		rArea = rArea + float64((*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2)*4))-*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr((ii+1)*2)*4)))*
			(*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2+1)*4))+*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr((ii+1)*2+1)*4))))*
			0.5
	}
	rArea = rArea + float64((*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2)*4))-*(*GeoCoord)(unsafe.Pointer(p + 8)))*
		(*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2+1)*4))+*(*GeoCoord)(unsafe.Pointer(p + 8 + 1*4))))*
		0.5
	return rArea
}

func geopolyAreaFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr = 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)
	}
}

func geopolyCcwFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	_ = argc
	if p != 0 {
		if geopolyArea(tls, p) < 0.0 {
			var ii int32
			var jj int32
			ii = 1
			jj = (*GeoPoly)(unsafe.Pointer(p)).FnVertex - 1
		__1:
			if !(ii < jj) {
				goto __3
			}
			{
				var t GeoCoord = *(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2)*4))
				*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2)*4)) = *(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(jj*2)*4))
				*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(jj*2)*4)) = t
				t = *(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2+1)*4))
				*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(ii*2+1)*4)) = *(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(jj*2+1)*4))
				*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(jj*2+1)*4)) = t

			}
			goto __2
		__2:
			ii++
			jj--
			goto __1
			goto __3
		__3:
		}
		Xsqlite3_result_blob(tls, context, p+4,
			4+8*(*GeoPoly)(unsafe.Pointer(p)).FnVertex, libc.UintptrFromInt32(-1))
		Xsqlite3_free(tls, p)
	}
}

func geopolySine(tls *libc.TLS, r float64) float64 {
	if r >= float64(1.5)*3.1415926535897932385 {
		r = r - float64(2.0)*3.1415926535897932385
	}
	if r >= float64(0.5)*3.1415926535897932385 {
		return -geopolySine(tls, r-3.1415926535897932385)
	} else {
		var r2 float64 = r * r
		var r3 float64 = r2 * r
		var r5 float64 = r3 * r2
		return 0.9996949*r - 0.1656700*r3 + 0.0075134*r5
	}
	return float64(0)
}

func geopolyRegularFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var x float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv)))
	var y float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	var r float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8)))
	var n int32 = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8)))

	var p uintptr
	_ = argc

	if n < 3 || r <= 0.0 {
		return
	}
	if n > 1000 {
		n = 1000
	}
	p = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(GeoPoly{}))+uint64((n-1)*2)*uint64(unsafe.Sizeof(GeoCoord(0))))
	if p == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, context)
		return
	}
	*(*int32)(unsafe.Pointer(bp)) = 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 >> 8 & 0xff)
	*(*uint8)(unsafe.Pointer(p + 4 + 3)) = uint8(n & 0xff)
	for *(*int32)(unsafe.Pointer(bp)) = 0; *(*int32)(unsafe.Pointer(bp)) < n; *(*int32)(unsafe.Pointer(bp))++ {
		var rAngle float64 = float64(2.0) * 3.1415926535897932385 * float64(*(*int32)(unsafe.Pointer(bp))) / float64(n)
		*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(*(*int32)(unsafe.Pointer(bp))*2)*4)) = GeoCoord(x - r*geopolySine(tls, rAngle-float64(0.5)*3.1415926535897932385))
		*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(*(*int32)(unsafe.Pointer(bp))*2+1)*4)) = GeoCoord(y + r*geopolySine(tls, rAngle))
	}
	Xsqlite3_result_blob(tls, context, p+4, 4+8*n, libc.UintptrFromInt32(-1))
	Xsqlite3_free(tls, p)
}

func geopolyBBox(tls *libc.TLS, context uintptr, pPoly uintptr, aCoord uintptr, pRc uintptr) uintptr {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pOut uintptr
	var p uintptr
	var mnX float32
	var mxX float32
	var mnY float32
	var mxY float32
	var r float64

	pOut = uintptr(0)
	if !(pPoly == uintptr(0) && aCoord != uintptr(0)) {
		goto __1
	}
	p = uintptr(0)
	mnX = *(*RtreeValue)(unsafe.Pointer(aCoord))
	mxX = *(*RtreeValue)(unsafe.Pointer(aCoord + 1*4))
	mnY = *(*RtreeValue)(unsafe.Pointer(aCoord + 2*4))
	mxY = *(*RtreeValue)(unsafe.Pointer(aCoord + 3*4))
	goto geopolyBboxFill
	goto __2
__1:
	p = geopolyFuncParam(tls, context, pPoly, pRc)
__2:
	;
	if !(p != 0) {
		goto __3
	}
	mnX = libc.AssignFloat32(&mxX, *(*GeoCoord)(unsafe.Pointer(p + 8)))
	mnY = libc.AssignFloat32(&mxY, *(*GeoCoord)(unsafe.Pointer(p + 8 + 1*4)))
	*(*int32)(unsafe.Pointer(bp)) = 1
__5:
	if !(*(*int32)(unsafe.Pointer(bp)) < (*GeoPoly)(unsafe.Pointer(p)).FnVertex) {
		goto __7
	}
	r = float64(*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(*(*int32)(unsafe.Pointer(bp))*2)*4)))
	if !(r < float64(mnX)) {
		goto __8
	}
	mnX = float32(r)
	goto __9
__8:
	if !(r > float64(mxX)) {
		goto __10
	}
	mxX = float32(r)
__10:
	;
__9:
	;
	r = float64(*(*GeoCoord)(unsafe.Pointer(p + 8 + uintptr(*(*int32)(unsafe.Pointer(bp))*2+1)*4)))
	if !(r < float64(mnY)) {
		goto __11
	}
	mnY = float32(r)
	goto __12
__11:
	if !(r > float64(mxY)) {
		goto __13
	}
	mxY = float32(r)
__13:
	;
__12:
	;
	goto __6
__6:
	*(*int32)(unsafe.Pointer(bp))++
	goto __5
	goto __7
__7:
	;
	if !(pRc != 0) {
		goto __14
	}
	*(*int32)(unsafe.Pointer(pRc)) = SQLITE_OK
__14:
	;
	if !(aCoord == uintptr(0)) {
		goto __15
	}
geopolyBboxFill:
	pOut = Xsqlite3_realloc64(tls, p, uint64(unsafe.Sizeof(GeoPoly{}))+uint64(unsafe.Sizeof(GeoCoord(0)))*uint64(2)*uint64(4-4))
	if !(pOut == uintptr(0)) {
		goto __17
	}
	Xsqlite3_free(tls, p)
	if !(context != 0) {
		goto __18
	}
	Xsqlite3_result_error_nomem(tls, context)
__18:
	;
	if !(pRc != 0) {
		goto __19
	}
	*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
__19:
	;
	return uintptr(0)
__17:
	;
	(*GeoPoly)(unsafe.Pointer(pOut)).FnVertex = 4
	*(*int32)(unsafe.Pointer(bp)) = 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)
	*(*GeoCoord)(unsafe.Pointer(pOut + 8)) = mnX
	*(*GeoCoord)(unsafe.Pointer(pOut + 8 + 1*4)) = mnY
	*(*GeoCoord)(unsafe.Pointer(pOut + 8 + 2*4)) = mxX
	*(*GeoCoord)(unsafe.Pointer(pOut + 8 + 3*4)) = mnY
	*(*GeoCoord)(unsafe.Pointer(pOut + 8 + 4*4)) = mxX
	*(*GeoCoord)(unsafe.Pointer(pOut + 8 + 5*4)) = mxY
	*(*GeoCoord)(unsafe.Pointer(pOut + 8 + 6*4)) = mnX
	*(*GeoCoord)(unsafe.Pointer(pOut + 8 + 7*4)) = mxY
	goto __16
__15:
	Xsqlite3_free(tls, p)
	*(*RtreeValue)(unsafe.Pointer(aCoord)) = mnX
	*(*RtreeValue)(unsafe.Pointer(aCoord + 1*4)) = mxX
	*(*RtreeValue)(unsafe.Pointer(aCoord + 2*4)) = mnY
	*(*RtreeValue)(unsafe.Pointer(aCoord + 3*4)) = mxY
__16:
	;
	goto __4
__3:
	if !(aCoord != 0) {
		goto __20
	}
	libc.Xmemset(tls, aCoord, 0, uint64(unsafe.Sizeof(RtreeCoord{}))*uint64(4))
__20:
	;
__4:
	;
	return pOut
}

func geopolyBBoxFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr = geopolyBBox(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0), uintptr(0))
	_ = argc
	if p != 0 {
		Xsqlite3_result_blob(tls, context, p+4,
			4+8*(*GeoPoly)(unsafe.Pointer(p)).FnVertex, libc.UintptrFromInt32(-1))
		Xsqlite3_free(tls, p)
	}
}

type GeoBBox1 = struct {
	FisInit int32
	Fa      [4]RtreeCoord
}

type GeoBBox = GeoBBox1

func geopolyBBoxStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	*(*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 {
		var pBBox uintptr
		pBBox = Xsqlite3_aggregate_context(tls, context, int32(unsafe.Sizeof(GeoBBox{})))
		if pBBox == uintptr(0) {
			return
		}
		if (*GeoBBox)(unsafe.Pointer(pBBox)).FisInit == 0 {
			(*GeoBBox)(unsafe.Pointer(pBBox)).FisInit = 1
			libc.Xmemcpy(tls, pBBox+4, bp, uint64(unsafe.Sizeof(RtreeCoord{}))*uint64(4))
		} else {
			if *(*RtreeValue)(unsafe.Pointer(bp)) < *(*RtreeValue)(unsafe.Pointer(pBBox + 4)) {
				*(*RtreeCoord)(unsafe.Pointer(pBBox + 4)) = *(*RtreeCoord)(unsafe.Pointer(bp))
			}
			if *(*RtreeValue)(unsafe.Pointer(bp + 1*4)) > *(*RtreeValue)(unsafe.Pointer(pBBox + 4 + 1*4)) {
				*(*RtreeCoord)(unsafe.Pointer(pBBox + 4 + 1*4)) = *(*RtreeCoord)(unsafe.Pointer(bp + 1*4))
			}
			if *(*RtreeValue)(unsafe.Pointer(bp + 2*4)) < *(*RtreeValue)(unsafe.Pointer(pBBox + 4 + 2*4)) {
				*(*RtreeCoord)(unsafe.Pointer(pBBox + 4 + 2*4)) = *(*RtreeCoord)(unsafe.Pointer(bp + 2*4))
			}
			if *(*RtreeValue)(unsafe.Pointer(bp + 3*4)) > *(*RtreeValue)(unsafe.Pointer(pBBox + 4 + 3*4)) {
				*(*RtreeCoord)(unsafe.Pointer(pBBox + 4 + 3*4)) = *(*RtreeCoord)(unsafe.Pointer(bp + 3*4))
			}
		}
	}
}

func geopolyBBoxFinal(tls *libc.TLS, context uintptr) {
	var p uintptr
	var pBBox uintptr
	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,
			4+8*(*GeoPoly)(unsafe.Pointer(p)).FnVertex, libc.UintptrFromInt32(-1))
		Xsqlite3_free(tls, p)
	}
}

func pointBeneathLine(tls *libc.TLS, x0 float64, y0 float64, x1 float64, y1 float64, x2 float64, y2 float64) int32 {
	var y float64
	if x0 == x1 && y0 == y1 {
		return 2
	}
	if x1 < x2 {
		if x0 <= x1 || x0 > x2 {
			return 0
		}
	} else if x1 > x2 {
		if x0 <= x2 || x0 > x1 {
			return 0
		}
	} else {
		if x0 != x1 {
			return 0
		}
		if y0 < y1 && y0 < y2 {
			return 0
		}
		if y0 > y1 && y0 > y2 {
			return 0
		}
		return 2
	}
	y = y1 + (y2-y1)*(x0-x1)/(x2-x1)
	if y0 == y {
		return 2
	}
	if y0 < y {
		return 1
	}
	return 0
}

func geopolyContainsPointFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p1 uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	var x0 float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))
	var y0 float64 = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8)))
	var v int32 = 0
	var cnt int32 = 0
	var ii int32
	_ = argc

	if p1 == uintptr(0) {
		return
	}
	for ii = 0; ii < (*GeoPoly)(unsafe.Pointer(p1)).FnVertex-1; ii++ {
		v = pointBeneathLine(tls, x0, y0, float64(*(*GeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(ii*2)*4))), float64(*(*GeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(ii*2+1)*4))),
			float64(*(*GeoCoord)(unsafe.Pointer(p1 + 8 + uintptr((ii+1)*2)*4))), float64(*(*GeoCoord)(unsafe.Pointer(p1 + 8 + uintptr((ii+1)*2+1)*4))))
		if v == 2 {
			break
		}
		cnt = cnt + v
	}
	if v != 2 {
		v = pointBeneathLine(tls, x0, y0, float64(*(*GeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(ii*2)*4))), float64(*(*GeoCoord)(unsafe.Pointer(p1 + 8 + uintptr(ii*2+1)*4))),
			float64(*(*GeoCoord)(unsafe.Pointer(p1 + 8))), float64(*(*GeoCoord)(unsafe.Pointer(p1 + 8 + 1*4))))
	}
	if v == 2 {
		Xsqlite3_result_int(tls, context, 1)
	} else if (v+cnt)&1 == 0 {
		Xsqlite3_result_int(tls, context, 0)
	} else {
		Xsqlite3_result_int(tls, context, 2)
	}
	Xsqlite3_free(tls, p1)
}

func geopolyWithinFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p1 uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	var p2 uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv + 1*8)), uintptr(0))
	_ = argc
	if p1 != 0 && p2 != 0 {
		var x int32 = geopolyOverlap(tls, p1, p2)
		if x < 0 {
			Xsqlite3_result_error_nomem(tls, context)
		} else {
			Xsqlite3_result_int(tls, context, func() int32 {
				if x == 2 {
					return 1
				}
				return func() int32 {
					if x == 4 {
						return 2
					}
					return 0
				}()
			}())
		}
	}
	Xsqlite3_free(tls, p1)
	Xsqlite3_free(tls, p2)
}

type GeoEvent1 = struct {
	Fx           float64
	FeType       int32
	F__ccgo_pad1 [4]byte
	FpSeg        uintptr
	FpNext       uintptr
}

type GeoEvent = GeoEvent1
type GeoSegment1 = struct {
	FC           float64
	FB           float64
	Fy           float64
	Fy0          float32
	Fside        uint8
	F__ccgo_pad1 [3]byte
	Fidx         uint32
	F__ccgo_pad2 [4]byte
	FpNext       uintptr
}

type GeoSegment = GeoSegment1
type GeoOverlap1 = struct {
	FaEvent   uintptr
	FaSegment uintptr
	FnEvent   int32
	FnSegment int32
}

type GeoOverlap = GeoOverlap1

func geopolyAddOneSegment(tls *libc.TLS, p uintptr, x0 GeoCoord, y0 GeoCoord, x1 GeoCoord, y1 GeoCoord, side uint8, idx uint32) {
	var pSeg uintptr
	var pEvent uintptr
	if x0 == x1 {
		return
	}
	if x0 > x1 {
		var t GeoCoord = x0
		x0 = x1
		x1 = t
		t = y0
		y0 = y1
		y1 = t
	}
	pSeg = (*GeoOverlap)(unsafe.Pointer(p)).FaSegment + uintptr((*GeoOverlap)(unsafe.Pointer(p)).FnSegment)*48
	(*GeoOverlap)(unsafe.Pointer(p)).FnSegment++
	(*GeoSegment)(unsafe.Pointer(pSeg)).FC = float64((y1 - y0) / (x1 - x0))
	(*GeoSegment)(unsafe.Pointer(pSeg)).FB = float64(y1) - float64(x1)*(*GeoSegment)(unsafe.Pointer(pSeg)).FC
	(*GeoSegment)(unsafe.Pointer(pSeg)).Fy0 = y0
	(*GeoSegment)(unsafe.Pointer(pSeg)).Fside = side
	(*GeoSegment)(unsafe.Pointer(pSeg)).Fidx = idx
	pEvent = (*GeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr((*GeoOverlap)(unsafe.Pointer(p)).FnEvent)*32
	(*GeoOverlap)(unsafe.Pointer(p)).FnEvent++
	(*GeoEvent)(unsafe.Pointer(pEvent)).Fx = float64(x0)
	(*GeoEvent)(unsafe.Pointer(pEvent)).FeType = 0
	(*GeoEvent)(unsafe.Pointer(pEvent)).FpSeg = pSeg
	pEvent = (*GeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr((*GeoOverlap)(unsafe.Pointer(p)).FnEvent)*32
	(*GeoOverlap)(unsafe.Pointer(p)).FnEvent++
	(*GeoEvent)(unsafe.Pointer(pEvent)).Fx = float64(x1)
	(*GeoEvent)(unsafe.Pointer(pEvent)).FeType = 1
	(*GeoEvent)(unsafe.Pointer(pEvent)).FpSeg = pSeg
}

func geopolyAddSegments(tls *libc.TLS, p uintptr, pPoly uintptr, side uint8) {
	var i uint32
	var x uintptr
	for i = uint32(0); i < uint32((*GeoPoly)(unsafe.Pointer(pPoly)).FnVertex)-uint32(1); i++ {
		x = pPoly + 8 + uintptr(i*uint32(2))*4
		geopolyAddOneSegment(tls, p, *(*GeoCoord)(unsafe.Pointer(x)), *(*GeoCoord)(unsafe.Pointer(x + 1*4)), *(*GeoCoord)(unsafe.Pointer(x + 2*4)), *(*GeoCoord)(unsafe.Pointer(x + 3*4)), side, i)
	}
	x = pPoly + 8 + uintptr(i*uint32(2))*4
	geopolyAddOneSegment(tls, p, *(*GeoCoord)(unsafe.Pointer(x)), *(*GeoCoord)(unsafe.Pointer(x + 1*4)), *(*GeoCoord)(unsafe.Pointer(pPoly + 8)), *(*GeoCoord)(unsafe.Pointer(pPoly + 8 + 1*4)), side, i)
}

func geopolyEventMerge(tls *libc.TLS, pLeft uintptr, pRight uintptr) uintptr {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pLast uintptr
	(*GeoEvent)(unsafe.Pointer(bp)).FpNext = uintptr(0)
	pLast = bp
	for pRight != 0 && pLeft != 0 {
		if (*GeoEvent)(unsafe.Pointer(pRight)).Fx <= (*GeoEvent)(unsafe.Pointer(pLeft)).Fx {
			(*GeoEvent)(unsafe.Pointer(pLast)).FpNext = pRight
			pLast = pRight
			pRight = (*GeoEvent)(unsafe.Pointer(pRight)).FpNext
		} else {
			(*GeoEvent)(unsafe.Pointer(pLast)).FpNext = pLeft
			pLast = pLeft
			pLeft = (*GeoEvent)(unsafe.Pointer(pLeft)).FpNext
		}
	}
	(*GeoEvent)(unsafe.Pointer(pLast)).FpNext = func() uintptr {
		if pRight != 0 {
			return pRight
		}
		return pLeft
	}()
	return (*GeoEvent)(unsafe.Pointer(bp)).FpNext
}

func geopolySortEventsByX(tls *libc.TLS, aEvent uintptr, nEvent int32) uintptr {
	bp := tls.Alloc(400)
	defer tls.Free(400)

	var mx int32 = 0
	var i int32
	var j int32
	var p uintptr

	for i = 0; i < nEvent; i++ {
		p = aEvent + uintptr(i)*32
		(*GeoEvent)(unsafe.Pointer(p)).FpNext = uintptr(0)
		for j = 0; j < mx && *(*uintptr)(unsafe.Pointer(bp + uintptr(j)*8)) != 0; j++ {
			p = geopolyEventMerge(tls, *(*uintptr)(unsafe.Pointer(bp + uintptr(j)*8)), p)
			*(*uintptr)(unsafe.Pointer(bp + uintptr(j)*8)) = uintptr(0)
		}
		*(*uintptr)(unsafe.Pointer(bp + uintptr(j)*8)) = p
		if j >= mx {
			mx = j + 1
		}
	}
	p = uintptr(0)
	for i = 0; i < mx; i++ {
		p = geopolyEventMerge(tls, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)), p)
	}
	return p
}

func geopolySegmentMerge(tls *libc.TLS, pLeft uintptr, pRight uintptr) uintptr {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var pLast uintptr
	(*GeoSegment)(unsafe.Pointer(bp)).FpNext = uintptr(0)
	pLast = bp
	for pRight != 0 && pLeft != 0 {
		var r float64 = (*GeoSegment)(unsafe.Pointer(pRight)).Fy - (*GeoSegment)(unsafe.Pointer(pLeft)).Fy
		if r == 0.0 {
			r = (*GeoSegment)(unsafe.Pointer(pRight)).FC - (*GeoSegment)(unsafe.Pointer(pLeft)).FC
		}
		if r < 0.0 {
			(*GeoSegment)(unsafe.Pointer(pLast)).FpNext = pRight
			pLast = pRight
			pRight = (*GeoSegment)(unsafe.Pointer(pRight)).FpNext
		} else {
			(*GeoSegment)(unsafe.Pointer(pLast)).FpNext = pLeft
			pLast = pLeft
			pLeft = (*GeoSegment)(unsafe.Pointer(pLeft)).FpNext
		}
	}
	(*GeoSegment)(unsafe.Pointer(pLast)).FpNext = func() uintptr {
		if pRight != 0 {
			return pRight
		}
		return pLeft
	}()
	return (*GeoSegment)(unsafe.Pointer(bp)).FpNext
}

func geopolySortSegmentsByYAndC(tls *libc.TLS, pList uintptr) uintptr {
	bp := tls.Alloc(400)
	defer tls.Free(400)

	var mx int32 = 0
	var i int32
	var p uintptr

	for pList != 0 {
		p = pList
		pList = (*GeoSegment)(unsafe.Pointer(pList)).FpNext
		(*GeoSegment)(unsafe.Pointer(p)).FpNext = uintptr(0)
		for i = 0; i < mx && *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) != 0; i++ {
			p = geopolySegmentMerge(tls, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)), p)
			*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = uintptr(0)
		}
		*(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)) = p
		if i >= mx {
			mx = i + 1
		}
	}
	p = uintptr(0)
	for i = 0; i < mx; i++ {
		p = geopolySegmentMerge(tls, *(*uintptr)(unsafe.Pointer(bp + uintptr(i)*8)), p)
	}
	return p
}

func geopolyOverlap(tls *libc.TLS, p1 uintptr, p2 uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var nVertex Sqlite3_int64
	var p uintptr
	var nByte Sqlite3_int64
	var pThisEvent uintptr
	var rX float64
	var rc int32
	var needSort int32
	var pActive uintptr
	var pSeg uintptr

	var y float64
	var pPrev uintptr
	var iMask int32
	nVertex = Sqlite3_int64((*GeoPoly)(unsafe.Pointer(p1)).FnVertex + (*GeoPoly)(unsafe.Pointer(p2)).FnVertex + 2)
	rc = 0
	needSort = 0
	pActive = uintptr(0)

	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(GeoEvent{}))*uint64(nVertex)*uint64(2) +
		uint64(unsafe.Sizeof(GeoSegment{}))*uint64(nVertex) +
		uint64(unsafe.Sizeof(GeoOverlap{})))
	p = Xsqlite3_malloc64(tls, uint64(nByte))
	if !(p == uintptr(0)) {
		goto __1
	}
	return -1
__1:
	;
	(*GeoOverlap)(unsafe.Pointer(p)).FaEvent = p + 1*24
	(*GeoOverlap)(unsafe.Pointer(p)).FaSegment = (*GeoOverlap)(unsafe.Pointer(p)).FaEvent + uintptr(nVertex*int64(2))*32
	(*GeoOverlap)(unsafe.Pointer(p)).FnEvent = libc.AssignPtrInt32(p+20, 0)
	geopolyAddSegments(tls, p, p1, uint8(1))
	geopolyAddSegments(tls, p, p2, uint8(2))
	pThisEvent = geopolySortEventsByX(tls, (*GeoOverlap)(unsafe.Pointer(p)).FaEvent, (*GeoOverlap)(unsafe.Pointer(p)).FnEvent)
	if pThisEvent != 0 && (*GeoEvent)(unsafe.Pointer(pThisEvent)).Fx == 0.0 {
		rX = -1.0
	} else {
		rX = 0.0
	}
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([4]uint8{})))
__2:
	if !(pThisEvent != 0) {
		goto __3
	}
	if !((*GeoEvent)(unsafe.Pointer(pThisEvent)).Fx != rX) {
		goto __4
	}
	pPrev = uintptr(0)
	iMask = 0

	rX = (*GeoEvent)(unsafe.Pointer(pThisEvent)).Fx
	if !(needSort != 0) {
		goto __5
	}

	pActive = geopolySortSegmentsByYAndC(tls, pActive)
	needSort = 0
__5:
	;
	pSeg = pActive
__6:
	if !(pSeg != 0) {
		goto __8
	}
	if !(pPrev != 0) {
		goto __9
	}
	if !((*GeoSegment)(unsafe.Pointer(pPrev)).Fy != (*GeoSegment)(unsafe.Pointer(pSeg)).Fy) {
		goto __10
	}

	*(*uint8)(unsafe.Pointer(bp + uintptr(iMask))) = uint8(1)
__10:
	;
__9:
	;
	iMask = iMask ^ int32((*GeoSegment)(unsafe.Pointer(pSeg)).Fside)
	pPrev = pSeg
	goto __7
__7:
	pSeg = (*GeoSegment)(unsafe.Pointer(pSeg)).FpNext
	goto __6
	goto __8
__8:
	;
	pPrev = uintptr(0)
	pSeg = pActive
__11:
	if !(pSeg != 0) {
		goto __13
	}
	y = (*GeoSegment)(unsafe.Pointer(pSeg)).FC*rX + (*GeoSegment)(unsafe.Pointer(pSeg)).FB

	(*GeoSegment)(unsafe.Pointer(pSeg)).Fy = y
	if !(pPrev != 0) {
		goto __14
	}
	if !((*GeoSegment)(unsafe.Pointer(pPrev)).Fy > (*GeoSegment)(unsafe.Pointer(pSeg)).Fy && int32((*GeoSegment)(unsafe.Pointer(pPrev)).Fside) != int32((*GeoSegment)(unsafe.Pointer(pSeg)).Fside)) {
		goto __15
	}
	rc = 1

	goto geopolyOverlapDone
	goto __16
__15:
	if !((*GeoSegment)(unsafe.Pointer(pPrev)).Fy != (*GeoSegment)(unsafe.Pointer(pSeg)).Fy) {
		goto __17
	}

	*(*uint8)(unsafe.Pointer(bp + uintptr(iMask))) = uint8(1)
__17:
	;
__16:
	;
__14:
	;
	iMask = iMask ^ int32((*GeoSegment)(unsafe.Pointer(pSeg)).Fside)
	pPrev = pSeg
	goto __12
__12:
	pSeg = (*GeoSegment)(unsafe.Pointer(pSeg)).FpNext
	goto __11
	goto __13
__13:
	;
__4:
	;
	if !((*GeoEvent)(unsafe.Pointer(pThisEvent)).FeType == 0) {
		goto __18
	}

	pSeg = (*GeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg
	(*GeoSegment)(unsafe.Pointer(pSeg)).Fy = float64((*GeoSegment)(unsafe.Pointer(pSeg)).Fy0)
	(*GeoSegment)(unsafe.Pointer(pSeg)).FpNext = pActive
	pActive = pSeg
	needSort = 1
	goto __19
__18:
	if !(pActive == (*GeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg) {
		goto __20
	}
	if pActive != 0 {
		pActive = (*GeoSegment)(unsafe.Pointer(pActive)).FpNext
	} else {
		pActive = uintptr(0)
	}
	goto __21
__20:
	pSeg = pActive
__22:
	if !(pSeg != 0) {
		goto __24
	}
	if !((*GeoSegment)(unsafe.Pointer(pSeg)).FpNext == (*GeoEvent)(unsafe.Pointer(pThisEvent)).FpSeg) {
		goto __25
	}
	(*GeoSegment)(unsafe.Pointer(pSeg)).FpNext = func() uintptr {
		if (*GeoSegment)(unsafe.Pointer(pSeg)).FpNext != 0 {
			return (*GeoSegment)(unsafe.Pointer((*GeoSegment)(unsafe.Pointer(pSeg)).FpNext)).FpNext
		}
		return uintptr(0)
	}()
	goto __24
__25:
	;
	goto __23
__23:
	pSeg = (*GeoSegment)(unsafe.Pointer(pSeg)).FpNext
	goto __22
	goto __24
__24:
	;
__21:
	;
__19:
	;
	pThisEvent = (*GeoEvent)(unsafe.Pointer(pThisEvent)).FpNext
	goto __2
__3:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(bp + 3))) == 0) {
		goto __26
	}
	rc = 0
	goto __27
__26:
	if !(int32(*(*uint8)(unsafe.Pointer(bp + 1))) != 0 && int32(*(*uint8)(unsafe.Pointer(bp + 2))) == 0) {
		goto __28
	}
	rc = 3
	goto __29
__28:
	if !(int32(*(*uint8)(unsafe.Pointer(bp + 1))) == 0 && int32(*(*uint8)(unsafe.Pointer(bp + 2))) != 0) {
		goto __30
	}
	rc = 2
	goto __31
__30:
	if !(int32(*(*uint8)(unsafe.Pointer(bp + 1))) == 0 && int32(*(*uint8)(unsafe.Pointer(bp + 2))) == 0) {
		goto __32
	}
	rc = 4
	goto __33
__32:
	rc = 1
__33:
	;
__31:
	;
__29:
	;
__27:
	;
geopolyOverlapDone:
	Xsqlite3_free(tls, p)
	return rc
}

func geopolyOverlapFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p1 uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv)), uintptr(0))
	var p2 uintptr = geopolyFuncParam(tls, context, *(*uintptr)(unsafe.Pointer(argv + 1*8)), uintptr(0))
	_ = argc
	if p1 != 0 && p2 != 0 {
		var x int32 = 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)
}

func geopolyDebugFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	_ = context
	_ = argc
	_ = argv
}

func geopolyInit(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr, isCreate int32) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var rc int32
	var pRtree uintptr
	var nDb Sqlite3_int64
	var nName Sqlite3_int64
	var pSql uintptr
	var zSql uintptr
	var ii int32
	rc = SQLITE_OK
	_ = pAux

	Xsqlite3_vtab_config(tls, db, SQLITE_VTAB_CONSTRAINT_SUPPORT, libc.VaList(bp, 1))

	nDb = Sqlite3_int64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))))
	nName = Sqlite3_int64(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 2*8))))
	pRtree = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Rtree{}))+uint64(nDb)+uint64(nName)+uint64(2))
	if !!(pRtree != 0) {
		goto __1
	}
	return SQLITE_NOMEM
__1:
	;
	libc.Xmemset(tls, pRtree, 0, uint64(unsafe.Sizeof(Rtree{}))+uint64(nDb)+uint64(nName)+uint64(2))
	(*Rtree)(unsafe.Pointer(pRtree)).FnBusy = U32(1)
	(*Rtree)(unsafe.Pointer(pRtree)).Fbase.FpModule = uintptr(unsafe.Pointer(&rtreeModule))
	(*Rtree)(unsafe.Pointer(pRtree)).FzDb = pRtree + 1*968
	(*Rtree)(unsafe.Pointer(pRtree)).FzName = (*Rtree)(unsafe.Pointer(pRtree)).FzDb + uintptr(nDb+int64(1))
	(*Rtree)(unsafe.Pointer(pRtree)).FeCoordType = U8(RTREE_COORD_REAL32)
	(*Rtree)(unsafe.Pointer(pRtree)).FnDim = U8(2)
	(*Rtree)(unsafe.Pointer(pRtree)).FnDim2 = U8(4)
	libc.Xmemcpy(tls, (*Rtree)(unsafe.Pointer(pRtree)).FzDb, *(*uintptr)(unsafe.Pointer(argv + 1*8)), uint64(nDb))
	libc.Xmemcpy(tls, (*Rtree)(unsafe.Pointer(pRtree)).FzName, *(*uintptr)(unsafe.Pointer(argv + 2*8)), uint64(nName))

	pSql = Xsqlite3_str_new(tls, db)
	Xsqlite3_str_appendf(tls, pSql, ts+33829, 0)
	(*Rtree)(unsafe.Pointer(pRtree)).FnAux = U8(1)
	(*Rtree)(unsafe.Pointer(pRtree)).FnAuxNotNull = U8(1)
	ii = 3
__2:
	if !(ii < argc) {
		goto __4
	}
	(*Rtree)(unsafe.Pointer(pRtree)).FnAux++
	Xsqlite3_str_appendf(tls, pSql, ts+33851, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(argv + uintptr(ii)*8))))
	goto __3
__3:
	ii++
	goto __2
	goto __4
__4:
	;
	Xsqlite3_str_appendf(tls, pSql, ts+32918, 0)
	zSql = Xsqlite3_str_finish(tls, pSql)
	if !!(zSql != 0) {
		goto __5
	}
	rc = SQLITE_NOMEM
	goto __6
__5:
	if !(SQLITE_OK != libc.AssignInt32(&rc, Xsqlite3_declare_vtab(tls, db, zSql))) {
		goto __7
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+16, Xsqlite3_errmsg(tls, db)))
__7:
	;
__6:
	;
	Xsqlite3_free(tls, zSql)
	if !(rc != 0) {
		goto __8
	}
	goto geopolyInit_fail
__8:
	;
	(*Rtree)(unsafe.Pointer(pRtree)).FnBytesPerCell = U8(8 + int32((*Rtree)(unsafe.Pointer(pRtree)).FnDim2)*4)

	rc = getNodeSize(tls, db, pRtree, isCreate, pzErr)
	if !(rc != 0) {
		goto __9
	}
	goto geopolyInit_fail
__9:
	;
	rc = rtreeSqlInit(tls, pRtree, db, *(*uintptr)(unsafe.Pointer(argv + 1*8)), *(*uintptr)(unsafe.Pointer(argv + 2*8)), isCreate)
	if !(rc != 0) {
		goto __10
	}
	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+24, Xsqlite3_errmsg(tls, db)))
	goto geopolyInit_fail
__10:
	;
	*(*uintptr)(unsafe.Pointer(ppVtab)) = pRtree
	return SQLITE_OK

geopolyInit_fail:
	if !(rc == SQLITE_OK) {
		goto __11
	}
	rc = SQLITE_ERROR
__11:
	;
	rtreeRelease(tls, pRtree)
	return rc
}

func geopolyCreate(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	return geopolyInit(tls, db, pAux, argc, argv, ppVtab, pzErr, 1)
}

func geopolyConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	return geopolyInit(tls, db, pAux, argc, argv, ppVtab, pzErr, 0)
}

func geopolyFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) int32 {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var pRtree uintptr
	var pCsr uintptr

	var p uintptr
	var iRowid I64

	var p1 uintptr
	var pNew uintptr
	pRtree = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab
	pCsr = pVtabCursor
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 48)) = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 16)) = 0
	_ = idxStr

	rtreeReference(tls, pRtree)

	resetCursor(tls, pCsr)

	(*RtreeCursor)(unsafe.Pointer(pCsr)).FiStrategy = idxNum
	if !(idxNum == 1) {
		goto __1
	}
	iRowid = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))
	*(*I64)(unsafe.Pointer(bp + 8)) = int64(0)
	*(*int32)(unsafe.Pointer(bp + 48)) = findLeafNode(tls, pRtree, iRowid, bp, bp+8)
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK && *(*uintptr)(unsafe.Pointer(bp)) != uintptr(0)) {
		goto __3
	}
	p = rtreeSearchPointNew(tls, pCsr, 0.0, uint8(0))

	*(*uintptr)(unsafe.Pointer(pCsr + 88)) = *(*uintptr)(unsafe.Pointer(bp))
	(*RtreeSearchPoint)(unsafe.Pointer(p)).Fid = *(*I64)(unsafe.Pointer(bp + 8))
	(*RtreeSearchPoint)(unsafe.Pointer(p)).FeWithin = U8(PARTLY_WITHIN)
	*(*int32)(unsafe.Pointer(bp + 48)) = nodeRowidIndex(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp)), iRowid, bp+16)
	(*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell = U8(*(*int32)(unsafe.Pointer(bp + 16)))

	goto __4
__3:
	(*RtreeCursor)(unsafe.Pointer(pCsr)).FatEOF = U8(1)
__4:
	;
	goto __2
__1:
	*(*int32)(unsafe.Pointer(bp + 48)) = nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp+24)
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK && idxNum <= 3) {
		goto __5
	}

	geopolyBBox(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(argv)), bp+32, bp+48)
	if !(*(*int32)(unsafe.Pointer(bp + 48)) != 0) {
		goto __6
	}
	goto geopoly_filter_end
__6:
	;
	(*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint = libc.AssignUintptr(&p1, Xsqlite3_malloc(tls, int32(uint64(unsafe.Sizeof(RtreeConstraint{}))*uint64(4))))
	(*RtreeCursor)(unsafe.Pointer(pCsr)).FnConstraint = 4
	if !(p1 == uintptr(0)) {
		goto __7
	}
	*(*int32)(unsafe.Pointer(bp + 48)) = SQLITE_NOMEM
	goto __8
__7:
	libc.Xmemset(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FaConstraint, 0, uint64(unsafe.Sizeof(RtreeConstraint{}))*uint64(4))
	libc.Xmemset(tls, pCsr+128, 0, uint64(unsafe.Sizeof(U32(0)))*uint64((*Rtree)(unsafe.Pointer(pRtree)).FiDepth+1))
	if !(idxNum == 2) {
		goto __9
	}

	(*RtreeConstraint)(unsafe.Pointer(p1)).Fop = 'B'
	(*RtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 0
	*(*RtreeDValue)(unsafe.Pointer(p1 + 8)) = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(bp + 32 + 1*4)))
	p1 += 24
	(*RtreeConstraint)(unsafe.Pointer(p1)).Fop = 'D'
	(*RtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 1
	*(*RtreeDValue)(unsafe.Pointer(p1 + 8)) = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(bp + 32)))
	p1 += 24
	(*RtreeConstraint)(unsafe.Pointer(p1)).Fop = 'B'
	(*RtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 2
	*(*RtreeDValue)(unsafe.Pointer(p1 + 8)) = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(bp + 32 + 3*4)))
	p1 += 24
	(*RtreeConstraint)(unsafe.Pointer(p1)).Fop = 'D'
	(*RtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 3
	*(*RtreeDValue)(unsafe.Pointer(p1 + 8)) = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(bp + 32 + 2*4)))
	goto __10
__9:
	(*RtreeConstraint)(unsafe.Pointer(p1)).Fop = 'D'
	(*RtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 0
	*(*RtreeDValue)(unsafe.Pointer(p1 + 8)) = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(bp + 32)))
	p1 += 24
	(*RtreeConstraint)(unsafe.Pointer(p1)).Fop = 'B'
	(*RtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 1
	*(*RtreeDValue)(unsafe.Pointer(p1 + 8)) = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(bp + 32 + 1*4)))
	p1 += 24
	(*RtreeConstraint)(unsafe.Pointer(p1)).Fop = 'D'
	(*RtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 2
	*(*RtreeDValue)(unsafe.Pointer(p1 + 8)) = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(bp + 32 + 2*4)))
	p1 += 24
	(*RtreeConstraint)(unsafe.Pointer(p1)).Fop = 'B'
	(*RtreeConstraint)(unsafe.Pointer(p1)).FiCoord = 3
	*(*RtreeDValue)(unsafe.Pointer(p1 + 8)) = RtreeDValue(*(*RtreeValue)(unsafe.Pointer(bp + 32 + 3*4)))
__10:
	;
__8:
	;
__5:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK) {
		goto __11
	}
	pNew = rtreeSearchPointNew(tls, pCsr, 0.0, U8((*Rtree)(unsafe.Pointer(pRtree)).FiDepth+1))
	if !(pNew == uintptr(0)) {
		goto __12
	}
	*(*int32)(unsafe.Pointer(bp + 48)) = SQLITE_NOMEM
	goto geopoly_filter_end
__12:
	;
	(*RtreeSearchPoint)(unsafe.Pointer(pNew)).Fid = int64(1)
	(*RtreeSearchPoint)(unsafe.Pointer(pNew)).FiCell = U8(0)
	(*RtreeSearchPoint)(unsafe.Pointer(pNew)).FeWithin = U8(PARTLY_WITHIN)

	*(*uintptr)(unsafe.Pointer(pCsr + 88)) = *(*uintptr)(unsafe.Pointer(bp + 24))
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)

	*(*int32)(unsafe.Pointer(bp + 48)) = rtreeStepToLeaf(tls, pCsr)
__11:
	;
__2:
	;
geopoly_filter_end:
	nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 24)))
	rtreeRelease(tls, pRtree)
	return *(*int32)(unsafe.Pointer(bp + 48))
}

func geopolyBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) int32 {
	var ii int32
	var iRowidTerm int32 = -1
	var iFuncTerm int32 = -1
	var idxNum int32 = 0
	_ = tab

	for ii = 0; ii < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint; ii++ {
		var p uintptr = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(ii)*12
		if !(int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable) != 0) {
			continue
		}
		if (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn < 0 && int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_EQ {
			iRowidTerm = ii
			break
		}
		if (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn == 0 && int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) >= SQLITE_INDEX_CONSTRAINT_FUNCTION {
			iFuncTerm = ii
			idxNum = int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) - SQLITE_INDEX_CONSTRAINT_FUNCTION + 2
		}
	}

	if iRowidTerm >= 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 1
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = ts + 11466
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8)).FargvIndex = 1
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iRowidTerm)*8)).Fomit = uint8(1)
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 30.0
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = SQLITE_INDEX_SCAN_UNIQUE
		return SQLITE_OK
	}
	if iFuncTerm >= 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = idxNum
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = ts + 33855
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iFuncTerm)*8)).FargvIndex = 1
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iFuncTerm)*8)).Fomit = uint8(0)
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 300.0
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(10)
		return SQLITE_OK
	}
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = 4
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxStr = ts + 33861
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 3000000.0
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(100000)
	return SQLITE_OK
}

func geopolyColumn(tls *libc.TLS, cur uintptr, ctx uintptr, i int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pRtree uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	var pCsr uintptr = cur
	var p uintptr = rtreeSearchPointFirst(tls, pCsr)
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var pNode uintptr = 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((*Rtree)(unsafe.Pointer(pRtree)).FnAux) {
		if !(int32((*RtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid) != 0) {
			if (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_prepare_v3(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb, (*Rtree)(unsafe.Pointer(pRtree)).FzReadAuxSql, -1, uint32(0),
					pCsr+56, uintptr(0))
				if *(*int32)(unsafe.Pointer(bp)) != 0 {
					return *(*int32)(unsafe.Pointer(bp))
				}
			}
			Xsqlite3_bind_int64(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux, 1,
				nodeGetRowid(tls, pRtree, pNode, int32((*RtreeSearchPoint)(unsafe.Pointer(p)).FiCell)))
			*(*int32)(unsafe.Pointer(bp)) = Xsqlite3_step(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_ROW {
				(*RtreeCursor)(unsafe.Pointer(pCsr)).FbAuxValid = U8(1)
			} else {
				Xsqlite3_reset(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux)
				if *(*int32)(unsafe.Pointer(bp)) == SQLITE_DONE {
					*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
				}
				return *(*int32)(unsafe.Pointer(bp))
			}
		}
		Xsqlite3_result_value(tls, ctx, Xsqlite3_column_value(tls, (*RtreeCursor)(unsafe.Pointer(pCsr)).FpReadAux, i+2))
	}
	return SQLITE_OK
}

func geopolyUpdate(tls *libc.TLS, pVtab uintptr, nData int32, aData uintptr, pRowid uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var pRtree uintptr

	var oldRowid I64
	var oldRowidValid int32
	var newRowid I64
	var newRowidValid int32
	var coordChange int32
	var steprc int32
	var rc2 int32

	var p uintptr
	var pUp uintptr
	var jj int32
	var nChange int32
	pRtree = pVtab
	*(*int32)(unsafe.Pointer(bp + 48)) = SQLITE_OK
	coordChange = 0

	if !((*Rtree)(unsafe.Pointer(pRtree)).FnNodeRef != 0) {
		goto __1
	}

	return SQLITE_LOCKED | int32(2)<<8
__1:
	;
	rtreeReference(tls, pRtree)

	oldRowidValid = libc.Bool32(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData))) != SQLITE_NULL)

	if oldRowidValid != 0 {
		oldRowid = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData)))
	} else {
		oldRowid = int64(0)
	}
	newRowidValid = libc.Bool32(nData > 1 && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData + 1*8))) != SQLITE_NULL)
	if newRowidValid != 0 {
		newRowid = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(aData + 1*8)))
	} else {
		newRowid = int64(0)
	}
	(*RtreeCell)(unsafe.Pointer(bp)).FiRowid = newRowid

	if !(nData > 1 &&
		(!(oldRowidValid != 0) ||
			!(Xsqlite3_value_nochange(tls, *(*uintptr)(unsafe.Pointer(aData + 2*8))) != 0) ||
			oldRowid != newRowid)) {
		goto __2
	}

	geopolyBBox(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(aData + 2*8)), bp+8, bp+48)
	if !(*(*int32)(unsafe.Pointer(bp + 48)) != 0) {
		goto __3
	}
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_ERROR) {
		goto __4
	}
	(*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = Xsqlite3_mprintf(tls, ts+33870, 0)
__4:
	;
	goto geopoly_update_end
__3:
	;
	coordChange = 1

	if !(newRowidValid != 0 && (!(oldRowidValid != 0) || oldRowid != newRowid)) {
		goto __5
	}
	Xsqlite3_bind_int64(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid, 1, (*RtreeCell)(unsafe.Pointer(bp)).FiRowid)
	steprc = Xsqlite3_step(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid)
	*(*int32)(unsafe.Pointer(bp + 48)) = Xsqlite3_reset(tls, (*Rtree)(unsafe.Pointer(pRtree)).FpReadRowid)
	if !(SQLITE_ROW == steprc) {
		goto __6
	}
	if !(Xsqlite3_vtab_on_conflict(tls, (*Rtree)(unsafe.Pointer(pRtree)).Fdb) == SQLITE_REPLACE) {
		goto __7
	}
	*(*int32)(unsafe.Pointer(bp + 48)) = rtreeDeleteRowid(tls, pRtree, (*RtreeCell)(unsafe.Pointer(bp)).FiRowid)
	goto __8
__7:
	*(*int32)(unsafe.Pointer(bp + 48)) = rtreeConstraintError(tls, pRtree, 0)
__8:
	;
__6:
	;
__5:
	;
__2:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK && (nData == 1 || coordChange != 0 && oldRowidValid != 0)) {
		goto __9
	}
	*(*int32)(unsafe.Pointer(bp + 48)) = rtreeDeleteRowid(tls, pRtree, oldRowid)
__9:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK && nData > 1 && coordChange != 0) {
		goto __10
	}

	*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
	if !!(newRowidValid != 0) {
		goto __11
	}
	*(*int32)(unsafe.Pointer(bp + 48)) = rtreeNewRowid(tls, pRtree, bp)
__11:
	;
	*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = (*RtreeCell)(unsafe.Pointer(bp)).FiRowid
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK) {
		goto __12
	}
	*(*int32)(unsafe.Pointer(bp + 48)) = sChooseLeaf(tls, pRtree, bp, 0, bp+56)
__12:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK) {
		goto __13
	}
	(*Rtree)(unsafe.Pointer(pRtree)).FiReinsertHeight = -1
	*(*int32)(unsafe.Pointer(bp + 48)) = rtreeInsertCell(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 56)), bp, 0)
	rc2 = nodeRelease(tls, pRtree, *(*uintptr)(unsafe.Pointer(bp + 56)))
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK) {
		goto __14
	}
	*(*int32)(unsafe.Pointer(bp + 48)) = rc2
__14:
	;
__13:
	;
__10:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK && nData > 1) {
		goto __15
	}
	pUp = (*Rtree)(unsafe.Pointer(pRtree)).FpWriteAux
	nChange = 0
	Xsqlite3_bind_int64(tls, pUp, 1, (*RtreeCell)(unsafe.Pointer(bp)).FiRowid)

	if !(Xsqlite3_value_nochange(tls, *(*uintptr)(unsafe.Pointer(aData + 2*8))) != 0) {
		goto __16
	}
	Xsqlite3_bind_null(tls, pUp, 2)
	goto __17
__16:
	p = uintptr(0)
	if !(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(aData + 2*8))) == SQLITE_TEXT &&
		libc.AssignUintptr(&p, geopolyFuncParam(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(aData + 2*8)), bp+48)) != uintptr(0) &&
		*(*int32)(unsafe.Pointer(bp + 48)) == SQLITE_OK) {
		goto __18
	}
	Xsqlite3_bind_blob(tls, pUp, 2, p+4, 4+8*(*GeoPoly)(unsafe.Pointer(p)).FnVertex, libc.UintptrFromInt32(-1))
	goto __19
__18:
	Xsqlite3_bind_value(tls, pUp, 2, *(*uintptr)(unsafe.Pointer(aData + 2*8)))
__19:
	;
	Xsqlite3_free(tls, p)
	nChange = 1
__17:
	;
	jj = 1
__20:
	if !(jj < nData-2) {
		goto __22
	}
	nChange++
	Xsqlite3_bind_value(tls, pUp, jj+2, *(*uintptr)(unsafe.Pointer(aData + uintptr(jj+2)*8)))
	goto __21
__21:
	jj++
	goto __20
	goto __22
__22:
	;
	if !(nChange != 0) {
		goto __23
	}
	Xsqlite3_step(tls, pUp)
	*(*int32)(unsafe.Pointer(bp + 48)) = Xsqlite3_reset(tls, pUp)
__23:
	;
__15:
	;
geopoly_update_end:
	rtreeRelease(tls, pRtree)
	return *(*int32)(unsafe.Pointer(bp + 48))
}

func geopolyFindFunction(tls *libc.TLS, pVtab uintptr, nArg int32, zName uintptr, pxFunc uintptr, ppArg uintptr) int32 {
	_ = pVtab
	_ = nArg
	if Xsqlite3_stricmp(tls, zName, ts+33910) == 0 {
		*(*uintptr)(unsafe.Pointer(pxFunc)) = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{geopolyOverlapFunc}))
		*(*uintptr)(unsafe.Pointer(ppArg)) = uintptr(0)
		return SQLITE_INDEX_CONSTRAINT_FUNCTION
	}
	if Xsqlite3_stricmp(tls, zName, ts+33926) == 0 {
		*(*uintptr)(unsafe.Pointer(pxFunc)) = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{geopolyWithinFunc}))
		*(*uintptr)(unsafe.Pointer(ppArg)) = uintptr(0)
		return SQLITE_INDEX_CONSTRAINT_FUNCTION + 1
	}
	return 0
}

var geopolyModule = Sqlite3_module{
	FiVersion:      3,
	FxCreate:       0,
	FxConnect:      0,
	FxBestIndex:    0,
	FxDisconnect:   0,
	FxDestroy:      0,
	FxOpen:         0,
	FxClose:        0,
	FxFilter:       0,
	FxNext:         0,
	FxEof:          0,
	FxColumn:       0,
	FxRowid:        0,
	FxUpdate:       0,
	FxBegin:        0,
	FxSync:         0,
	FxCommit:       0,
	FxRollback:     0,
	FxFindFunction: 0,
	FxRename:       0,
	FxSavepoint:    0,
	FxShadowName:   0,
}

func sqlite3_geopoly_init(tls *libc.TLS, db uintptr) int32 {
	var rc int32 = SQLITE_OK
	var i uint32
	for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(aFunc))/uint64(unsafe.Sizeof(struct {
		FxFunc       uintptr
		FnArg        int8
		FbPure       uint8
		F__ccgo_pad1 [6]byte
		FzName       uintptr
	}{})) && rc == SQLITE_OK; i++ {
		var enc int32
		if aFunc[i].FbPure != 0 {
			enc = SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_INNOCUOUS
		} else {
			enc = SQLITE_UTF8 | 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))
	}
	for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(aAgg))/uint64(unsafe.Sizeof(struct {
		FxStep  uintptr
		FxFinal uintptr
		FzName  uintptr
	}{})) && rc == SQLITE_OK; i++ {
		rc = Xsqlite3_create_function(tls, db, aAgg[i].FzName, 1,
			SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS, uintptr(0),
			uintptr(0), aAgg[i].FxStep, aAgg[i].FxFinal)
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_module_v2(tls, db, ts+33941, uintptr(unsafe.Pointer(&geopolyModule)), uintptr(0), uintptr(0))
	}
	return rc
}

var aFunc = [12]struct {
	FxFunc       uintptr
	FnArg        int8
	FbPure       uint8
	F__ccgo_pad1 [6]byte
	FzName       uintptr
}{
	{FxFunc: 0, FnArg: int8(1), FbPure: uint8(1), FzName: ts + 33949},
	{FxFunc: 0, FnArg: int8(1), FbPure: uint8(1), FzName: ts + 33962},
	{FxFunc: 0, FnArg: int8(1), FbPure: uint8(1), FzName: ts + 33975},
	{FxFunc: 0, FnArg: int8(-1), FbPure: uint8(1), FzName: ts + 33988},
	{FxFunc: 0, FnArg: int8(2), FbPure: uint8(1), FzName: ts + 33926},
	{FxFunc: 0, FnArg: int8(3), FbPure: uint8(1), FzName: ts + 34000},
	{FxFunc: 0, FnArg: int8(2), FbPure: uint8(1), FzName: ts + 33910},
	{FxFunc: 0, FnArg: int8(1), FzName: ts + 34023},
	{FxFunc: 0, FnArg: int8(1), FbPure: uint8(1), FzName: ts + 34037},
	{FxFunc: 0, FnArg: int8(7), FbPure: uint8(1), FzName: ts + 34050},
	{FxFunc: 0, FnArg: int8(4), FbPure: uint8(1), FzName: ts + 34064},
	{FxFunc: 0, FnArg: int8(1), FbPure: uint8(1), FzName: ts + 34080},
}
var aAgg = [1]struct {
	FxStep  uintptr
	FxFinal uintptr
	FzName  uintptr
}{
	{FxStep: 0, FxFinal: 0, FzName: ts + 34092},
}

func Xsqlite3RtreeInit(tls *libc.TLS, db uintptr) int32 {
	var utf8 int32 = SQLITE_UTF8
	var rc int32

	rc = Xsqlite3_create_function(tls, db, ts+34111, 2, utf8, uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	}{rtreenode})), uintptr(0), uintptr(0))
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_function(tls, db, ts+34121, 1, utf8, uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{rtreedepth})), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_create_function(tls, db, ts+34132, -1, utf8, uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{rtreecheck})), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		var c uintptr = uintptr(RTREE_COORD_REAL32)
		rc = Xsqlite3_create_module_v2(tls, db, ts+33855, uintptr(unsafe.Pointer(&rtreeModule)), c, uintptr(0))
	}
	if rc == SQLITE_OK {
		var c uintptr = uintptr(RTREE_COORD_INT32)
		rc = Xsqlite3_create_module_v2(tls, db, ts+34143, uintptr(unsafe.Pointer(&rtreeModule)), c, uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = sqlite3_geopoly_init(tls, db)
	}

	return rc
}

func rtreeFreeCallback(tls *libc.TLS, p uintptr) {
	var pInfo uintptr = p
	if (*RtreeGeomCallback)(unsafe.Pointer(pInfo)).FxDestructor != 0 {
		(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*RtreeGeomCallback)(unsafe.Pointer(pInfo)).FxDestructor})).f(tls, (*RtreeGeomCallback)(unsafe.Pointer(pInfo)).FpContext)
	}
	Xsqlite3_free(tls, p)
}

func rtreeMatchArgFree(tls *libc.TLS, pArg uintptr) {
	var i int32
	var p uintptr = pArg
	for i = 0; i < (*RtreeMatchArg)(unsafe.Pointer(p)).FnParam; i++ {
		Xsqlite3_value_free(tls, *(*uintptr)(unsafe.Pointer((*RtreeMatchArg)(unsafe.Pointer(p)).FapSqlParam + uintptr(i)*8)))
	}
	Xsqlite3_free(tls, p)
}

func geomCallback(tls *libc.TLS, ctx uintptr, nArg int32, aArg uintptr) {
	var pGeomCtx uintptr = Xsqlite3_user_data(tls, ctx)
	var pBlob uintptr
	var nBlob Sqlite3_int64
	var memErr int32 = 0

	nBlob = Sqlite3_int64(uint64(unsafe.Sizeof(RtreeMatchArg{})) + uint64(nArg-1)*uint64(unsafe.Sizeof(RtreeDValue(0))) +
		uint64(nArg)*uint64(unsafe.Sizeof(uintptr(0))))
	pBlob = Xsqlite3_malloc64(tls, uint64(nBlob))
	if !(pBlob != 0) {
		Xsqlite3_result_error_nomem(tls, ctx)
	} else {
		var i int32
		(*RtreeMatchArg)(unsafe.Pointer(pBlob)).FiSize = U32(nBlob)
		(*RtreeMatchArg)(unsafe.Pointer(pBlob)).Fcb = *(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx))
		(*RtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam = pBlob + 56 + uintptr(nArg)*8
		(*RtreeMatchArg)(unsafe.Pointer(pBlob)).FnParam = nArg
		for i = 0; i < nArg; i++ {
			*(*uintptr)(unsafe.Pointer((*RtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*8)) = Xsqlite3_value_dup(tls, *(*uintptr)(unsafe.Pointer(aArg + uintptr(i)*8)))
			if *(*uintptr)(unsafe.Pointer((*RtreeMatchArg)(unsafe.Pointer(pBlob)).FapSqlParam + uintptr(i)*8)) == uintptr(0) {
				memErr = 1
			}
			*(*RtreeDValue)(unsafe.Pointer(pBlob + 56 + uintptr(i)*8)) = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(aArg + uintptr(i)*8)))
		}
		if memErr != 0 {
			Xsqlite3_result_error_nomem(tls, ctx)
			rtreeMatchArgFree(tls, pBlob)
		} else {
			Xsqlite3_result_pointer(tls, ctx, pBlob, ts+31431, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{rtreeMatchArgFree})))
		}
	}
}

func Xsqlite3_rtree_geometry_callback(tls *libc.TLS, db uintptr, zGeom uintptr, xGeom uintptr, pContext uintptr) int32 {
	var pGeomCtx uintptr

	pGeomCtx = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(RtreeGeomCallback{})))
	if !(pGeomCtx != 0) {
		return SQLITE_NOMEM
	}
	(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxGeom = xGeom
	(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxQueryFunc = uintptr(0)
	(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxDestructor = uintptr(0)
	(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FpContext = pContext
	return Xsqlite3_create_function_v2(tls, db, zGeom, -1, SQLITE_ANY,
		pGeomCtx, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{geomCallback})), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{rtreeFreeCallback})))
}

func Xsqlite3_rtree_query_callback(tls *libc.TLS, db uintptr, zQueryFunc uintptr, xQueryFunc uintptr, pContext uintptr, xDestructor uintptr) int32 {
	var pGeomCtx uintptr

	pGeomCtx = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(RtreeGeomCallback{})))
	if !(pGeomCtx != 0) {
		if xDestructor != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDestructor})).f(tls, pContext)
		}
		return SQLITE_NOMEM
	}
	(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxGeom = uintptr(0)
	(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxQueryFunc = xQueryFunc
	(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxDestructor = xDestructor
	(*RtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FpContext = pContext
	return Xsqlite3_create_function_v2(tls, db, zQueryFunc, -1, SQLITE_ANY,
		pGeomCtx, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{geomCallback})), uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{rtreeFreeCallback})))
}

type sqlite3rbu = struct {
	FeStage         int32
	F__ccgo_pad1    [4]byte
	FdbMain         uintptr
	FdbRbu          uintptr
	FzTarget        uintptr
	FzRbu           uintptr
	FzState         uintptr
	FzStateDb       [5]uint8
	F__ccgo_pad2    [3]byte
	Frc             int32
	F__ccgo_pad3    [4]byte
	FzErrmsg        uintptr
	FnStep          int32
	FnProgress      int32
	Fobjiter        RbuObjIter
	FzVfsName       uintptr
	FpTargetFd      uintptr
	FnPagePerSector int32
	F__ccgo_pad4    [4]byte
	FiOalSz         I64
	FnPhaseOneStep  I64
	FpRenameArg     uintptr
	FxRename        uintptr
	FiMaxFrame      U32
	FmLock          U32
	FnFrame         int32
	FnFrameAlloc    int32
	FaFrame         uintptr
	Fpgsz           int32
	F__ccgo_pad5    [4]byte
	FaBuf           uintptr
	FiWalCksum      I64
	FszTemp         I64
	FszTempLimit    I64
	FnRbu           int32
	F__ccgo_pad6    [4]byte
	FpRbuFd         uintptr
}

type Sqlite3rbu = sqlite3rbu

type RbuFrame1 = struct {
	FiDbPage   U32
	FiWalFrame U32
}

type RbuFrame = RbuFrame1
type RbuObjIter1 = struct {
	FpTblIter    uintptr
	FpIdxIter    uintptr
	FnTblCol     int32
	F__ccgo_pad1 [4]byte
	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
	F__ccgo_pad2 [4]byte
	FpSelect     uintptr
	FpInsert     uintptr
	FpDelete     uintptr
	FpTmpInsert  uintptr
	FnIdxCol     int32
	F__ccgo_pad3 [4]byte
	FaIdxCol     uintptr
	FzIdxSql     uintptr
	FpRbuUpdate  uintptr
}

type RbuObjIter = RbuObjIter1
type RbuState1 = struct {
	FeStage        int32
	F__ccgo_pad1   [4]byte
	FzTbl          uintptr
	FzDataTbl      uintptr
	FzIdx          uintptr
	FiWalCksum     I64
	FnRow          int32
	F__ccgo_pad2   [4]byte
	FnProgress     I64
	FiCookie       U32
	F__ccgo_pad3   [4]byte
	FiOalSz        I64
	FnPhaseOneStep I64
}

type RbuState = RbuState1
type RbuSpan1 = struct {
	FzSpan       uintptr
	FnSpan       int32
	F__ccgo_pad1 [4]byte
}

type RbuSpan = RbuSpan1
type rbu_vfs = struct {
	Fbase     Sqlite3_vfs
	FpRealVfs uintptr
	Fmutex    uintptr
	FpRbu     uintptr
	FpMain    uintptr
	FpMainRbu uintptr
}

type Rbu_vfs = rbu_vfs
type rbu_file = struct {
	Fbase         Sqlite3_file
	FpReal        uintptr
	FpRbuVfs      uintptr
	FpRbu         uintptr
	Fsz           I64
	FopenFlags    int32
	FiCookie      U32
	FiWriteVer    U8
	FbNolock      U8
	F__ccgo_pad1  [2]byte
	FnShm         int32
	FapShm        uintptr
	FzDel         uintptr
	FzWal         uintptr
	FpWalFd       uintptr
	FpMainNext    uintptr
	FpMainRbuNext uintptr
}

type Rbu_file = rbu_file
type RbuUpdateStmt1 = struct {
	FzMask   uintptr
	FpUpdate uintptr
	FpNext   uintptr
}

type RbuUpdateStmt = RbuUpdateStmt1

func rbuDeltaGetInt(tls *libc.TLS, pz uintptr, pLen uintptr) uint32 {
	var v uint32 = uint32(0)
	var c int32
	var z uintptr = *(*uintptr)(unsafe.Pointer(pz))
	var zStart uintptr = z
	for libc.AssignInt32(&c, int32(zValue[0x7f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&z, 1))))])) >= 0 {
		v = v<<6 + uint32(c)
	}
	z--
	*(*int32)(unsafe.Pointer(pLen)) -= int32((int64(z) - int64(zStart)) / 1)
	*(*uintptr)(unsafe.Pointer(pz)) = z
	return v
}

var zValue = [128]int8{
	int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1),
	int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1),
	int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1),
	int8(0), int8(1), int8(2), int8(3), int8(4), int8(5), int8(6), int8(7), int8(8), int8(9), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1), int8(-1),
	int8(-1), int8(10), int8(11), int8(12), int8(13), int8(14), int8(15), int8(16), int8(17), int8(18), int8(19), int8(20), int8(21), int8(22), int8(23), int8(24),
	int8(25), int8(26), int8(27), int8(28), int8(29), int8(30), int8(31), int8(32), int8(33), int8(34), int8(35), int8(-1), int8(-1), int8(-1), int8(-1), int8(36),
	int8(-1), int8(37), int8(38), int8(39), int8(40), int8(41), int8(42), int8(43), int8(44), int8(45), int8(46), int8(47), int8(48), int8(49), int8(50), int8(51),
	int8(52), int8(53), int8(54), int8(55), int8(56), int8(57), int8(58), int8(59), int8(60), int8(61), int8(62), int8(-1), int8(-1), int8(-1), int8(63), int8(-1),
}

func rbuDeltaApply(tls *libc.TLS, zSrc uintptr, lenSrc int32, zDelta uintptr, lenDelta int32, zOut uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)
	*(*uintptr)(unsafe.Pointer(bp)) = zDelta
	*(*int32)(unsafe.Pointer(bp + 8)) = lenDelta

	var limit uint32
	var total uint32 = uint32(0)

	limit = rbuDeltaGetInt(tls, bp, bp+8)
	if int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != '\n' {
		return -1
	}
	*(*uintptr)(unsafe.Pointer(bp))++
	*(*int32)(unsafe.Pointer(bp + 8))--
	for *(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))) != 0 && *(*int32)(unsafe.Pointer(bp + 8)) > 0 {
		var cnt uint32
		var ofst uint32
		cnt = rbuDeltaGetInt(tls, bp, bp+8)
		switch int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) {
		case '@':
			{
				*(*uintptr)(unsafe.Pointer(bp))++
				*(*int32)(unsafe.Pointer(bp + 8))--
				ofst = rbuDeltaGetInt(tls, bp, bp+8)
				if *(*int32)(unsafe.Pointer(bp + 8)) > 0 && int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != ',' {
					return -1
				}
				*(*uintptr)(unsafe.Pointer(bp))++
				*(*int32)(unsafe.Pointer(bp + 8))--
				total = total + cnt
				if total > limit {
					return -1
				}
				if int32(ofst+cnt) > lenSrc {
					return -1
				}
				libc.Xmemcpy(tls, zOut, zSrc+uintptr(ofst), uint64(cnt))
				zOut += uintptr(cnt)
				break

			}
		case ':':
			{
				*(*uintptr)(unsafe.Pointer(bp))++
				*(*int32)(unsafe.Pointer(bp + 8))--
				total = total + cnt
				if total > limit {
					return -1
				}
				if int32(cnt) > *(*int32)(unsafe.Pointer(bp + 8)) {
					return -1
				}
				libc.Xmemcpy(tls, zOut, *(*uintptr)(unsafe.Pointer(bp)), uint64(cnt))
				zOut += uintptr(cnt)
				*(*uintptr)(unsafe.Pointer(bp)) += uintptr(cnt)
				*(*int32)(unsafe.Pointer(bp + 8)) -= int32(cnt)
				break

			}
		case ';':
			{
				*(*uintptr)(unsafe.Pointer(bp))++
				*(*int32)(unsafe.Pointer(bp + 8))--
				*(*uint8)(unsafe.Pointer(zOut)) = uint8(0)
				if total != limit {
					return -1
				}
				return int32(total)

			}
		default:
			{
				return -1

			}
		}
	}

	return -1
}

func rbuDeltaOutputSize(tls *libc.TLS, zDelta uintptr, lenDelta int32) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)
	*(*uintptr)(unsafe.Pointer(bp)) = zDelta
	*(*int32)(unsafe.Pointer(bp + 8)) = lenDelta

	var size int32
	size = int32(rbuDeltaGetInt(tls, bp, bp+8))
	if int32(*(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))))) != '\n' {
		return -1
	}
	return size
}

func rbuFossilDeltaFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var aDelta uintptr
	var nDelta int32
	var aOrig uintptr
	var nOrig int32
	var nOut int32
	var nOut2 int32
	var aOut uintptr

	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*8)))
	aDelta = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))

	nOut = rbuDeltaOutputSize(tls, aDelta, nDelta)
	if nOut < 0 {
		Xsqlite3_result_error(tls, context, ts+34153, -1)
		return
	}

	aOut = Xsqlite3_malloc(tls, nOut+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, ts+34153, -1)
		} else {
			Xsqlite3_result_blob(tls, context, aOut, nOut, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
		}
	}
}

func prepareAndCollectError(tls *libc.TLS, db uintptr, ppStmt uintptr, pzErrmsg uintptr, zSql uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = Xsqlite3_prepare_v2(tls, db, zSql, -1, ppStmt, uintptr(0))
	if rc != SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(pzErrmsg)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, Xsqlite3_errmsg(tls, db)))
		*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	}
	return rc
}

func resetAndCollectError(tls *libc.TLS, pStmt uintptr, pzErrmsg uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = Xsqlite3_reset(tls, pStmt)
	if rc != SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(pzErrmsg)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, Xsqlite3_errmsg(tls, Xsqlite3_db_handle(tls, pStmt))))
	}
	return rc
}

func prepareFreeAndCollectError(tls *libc.TLS, db uintptr, ppStmt uintptr, pzErrmsg uintptr, zSql uintptr) int32 {
	var rc int32

	if zSql == uintptr(0) {
		rc = SQLITE_NOMEM
		*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	} else {
		rc = prepareAndCollectError(tls, db, ppStmt, pzErrmsg, zSql)
		Xsqlite3_free(tls, zSql)
	}
	return rc
}

func rbuObjIterFreeCols(tls *libc.TLS, pIter uintptr) {
	var i int32
	for i = 0; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; i++ {
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)))
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(i)*8)))
	}
	Xsqlite3_free(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FazTblType = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FabNotNull = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol = 0
	(*RbuObjIter)(unsafe.Pointer(pIter)).FeType = 0
}

func rbuObjIterClearStatements(tls *libc.TLS, pIter uintptr) {
	var pUp uintptr

	Xsqlite3_finalize(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
	Xsqlite3_finalize(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpInsert)
	Xsqlite3_finalize(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpDelete)
	Xsqlite3_finalize(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpTmpInsert)
	pUp = (*RbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
	for pUp != 0 {
		var pTmp uintptr = (*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext
		Xsqlite3_finalize(tls, (*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate)
		Xsqlite3_free(tls, pUp)
		pUp = pTmp
	}
	Xsqlite3_free(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol)
	Xsqlite3_free(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdxSql)

	(*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FpInsert = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FpDelete = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FpTmpInsert = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FnCol = 0
	(*RbuObjIter)(unsafe.Pointer(pIter)).FnIdxCol = 0
	(*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol = uintptr(0)
	(*RbuObjIter)(unsafe.Pointer(pIter)).FzIdxSql = uintptr(0)
}

func rbuObjIterFinalize(tls *libc.TLS, pIter uintptr) {
	rbuObjIterClearStatements(tls, pIter)
	Xsqlite3_finalize(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpTblIter)
	Xsqlite3_finalize(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter)
	rbuObjIterFreeCols(tls, pIter)
	libc.Xmemset(tls, pIter, 0, uint64(unsafe.Sizeof(RbuObjIter{})))
}

func rbuObjIterNext(tls *libc.TLS, p uintptr, pIter uintptr) int32 {
	var rc int32 = (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
	if rc == SQLITE_OK {
		rbuObjIterClearStatements(tls, pIter)
		if (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
			rc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain,
				ts+34174, uintptr(0), uintptr(0), p+64)
		}

		if rc == SQLITE_OK {
			if (*RbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 {
				rbuObjIterFreeCols(tls, pIter)
				(*RbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = 0
				rc = Xsqlite3_step(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpTblIter)
				if rc != SQLITE_ROW {
					rc = resetAndCollectError(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, p+64)
					(*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl = uintptr(0)
				} else {
					(*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl = Xsqlite3_column_text(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, 0)
					(*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl = Xsqlite3_column_text(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpTblIter, 1)
					if (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl != 0 && (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 {
						rc = SQLITE_OK
					} else {
						rc = SQLITE_NOMEM
					}
				}
			} else {
				if (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
					var pIdx uintptr = (*RbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter
					rc = Xsqlite3_bind_text(tls, pIdx, 1, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl, -1, uintptr(0))
				}
				if rc == SQLITE_OK {
					rc = Xsqlite3_step(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter)
					if rc != SQLITE_ROW {
						rc = resetAndCollectError(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, p+64)
						(*RbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = 1
						(*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx = uintptr(0)
					} else {
						(*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx = Xsqlite3_column_text(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, 0)
						(*RbuObjIter)(unsafe.Pointer(pIter)).FiTnum = Xsqlite3_column_int(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, 1)
						(*RbuObjIter)(unsafe.Pointer(pIter)).FbUnique = Xsqlite3_column_int(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter, 2)
						if (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx != 0 {
							rc = SQLITE_OK
						} else {
							rc = SQLITE_NOMEM
						}
					}
				}
			}
		}
	}

	if rc != SQLITE_OK {
		rbuObjIterFinalize(tls, pIter)
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	}
	return rc
}

func rbuTargetNameFunc(tls *libc.TLS, pCtx uintptr, argc int32, argv uintptr) {
	var p uintptr = Xsqlite3_user_data(tls, pCtx)
	var zIn uintptr

	zIn = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
	if zIn != 0 {
		if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			if argc == 1 || 0 == Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))) {
				Xsqlite3_result_text(tls, pCtx, zIn, -1, uintptr(0))
			}
		} else {
			if libc.Xstrlen(tls, zIn) > uint64(4) && libc.Xmemcmp(tls, ts+31344, zIn, uint64(4)) == 0 {
				var i int32
				for i = 4; int32(*(*uint8)(unsafe.Pointer(zIn + uintptr(i)))) >= '0' && int32(*(*uint8)(unsafe.Pointer(zIn + uintptr(i)))) <= '9'; i++ {
				}
				if int32(*(*uint8)(unsafe.Pointer(zIn + uintptr(i)))) == '_' && *(*uint8)(unsafe.Pointer(zIn + uintptr(i+1))) != 0 {
					Xsqlite3_result_text(tls, pCtx, zIn+uintptr(i+1), -1, uintptr(0))
				}
			}
		}
	}
}

func rbuObjIterFirst(tls *libc.TLS, p uintptr, pIter uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	libc.Xmemset(tls, pIter, 0, uint64(unsafe.Sizeof(RbuObjIter{})))

	rc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter, p+64,
		Xsqlite3_mprintf(tls,
			ts+34345, libc.VaList(bp, func() uintptr {
				if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					return ts + 34495
				}
				return ts + 1636
			}())))

	if rc == SQLITE_OK {
		rc = prepareAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+8, p+64,
			ts+34536)
	}

	(*RbuObjIter)(unsafe.Pointer(pIter)).FbCleanup = 1
	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	return rbuObjIterNext(tls, p, pIter)
}

func rbuMPrintf(tls *libc.TLS, p uintptr, zFmt uintptr, va uintptr) uintptr {
	var zSql uintptr = uintptr(0)
	var ap Va_list
	_ = ap
	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFmt, ap)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if zSql == uintptr(0) {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
		}
	} else {
		Xsqlite3_free(tls, zSql)
		zSql = uintptr(0)
	}
	_ = ap
	return zSql
}

func rbuMPrintfExec(tls *libc.TLS, p uintptr, db uintptr, zFmt uintptr, va uintptr) int32 {
	var ap Va_list
	_ = ap
	var zSql uintptr
	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFmt, ap)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if zSql == uintptr(0) {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
		} else {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, zSql, uintptr(0), uintptr(0), p+64)
		}
	}
	Xsqlite3_free(tls, zSql)
	_ = ap
	return (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
}

func rbuMalloc(tls *libc.TLS, p uintptr, nByte Sqlite3_int64) uintptr {
	var pRet uintptr = uintptr(0)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		pRet = Xsqlite3_malloc64(tls, uint64(nByte))
		if pRet == uintptr(0) {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
		} else {
			libc.Xmemset(tls, pRet, 0, uint64(nByte))
		}
	}
	return pRet
}

func rbuAllocateIterArrays(tls *libc.TLS, p uintptr, pIter uintptr, nCol int32) {
	var nByte Sqlite3_int64 = Sqlite3_int64((uint64(2)*uint64(unsafe.Sizeof(uintptr(0))) + uint64(unsafe.Sizeof(int32(0))) + uint64(3)*uint64(unsafe.Sizeof(U8(0)))) * uint64(nCol))
	var azNew uintptr

	azNew = rbuMalloc(tls, p, nByte)
	if azNew != 0 {
		(*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol = azNew
		(*RbuObjIter)(unsafe.Pointer(pIter)).FazTblType = azNew + uintptr(nCol)*8
		(*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder = (*RbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(nCol)*8
		(*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk = (*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(nCol)*4
		(*RbuObjIter)(unsafe.Pointer(pIter)).FabNotNull = (*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(nCol)
		(*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed = (*RbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(nCol)
	}
}

func rbuStrndup(tls *libc.TLS, zStr uintptr, pRc uintptr) uintptr {
	var zRet uintptr = uintptr(0)

	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		if zStr != 0 {
			var nCopy Size_t = libc.Xstrlen(tls, zStr) + uint64(1)
			zRet = Xsqlite3_malloc64(tls, nCopy)
			if zRet != 0 {
				libc.Xmemcpy(tls, zRet, zStr, nCopy)
			} else {
				*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
			}
		}
	}

	return zRet
}

func rbuFinalize(tls *libc.TLS, p uintptr, pStmt uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var db uintptr = Xsqlite3_db_handle(tls, pStmt)
	var rc int32 = Xsqlite3_finalize(tls, pStmt)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && rc != SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc
		(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, Xsqlite3_errmsg(tls, db)))
	}
}

func rbuTableType(tls *libc.TLS, p uintptr, zTab uintptr, peType uintptr, piTnum uintptr, piPk uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var zOrig uintptr
	var zIdx uintptr
	var i uint32
	*(*[4]uintptr)(unsafe.Pointer(bp + 32)) = [4]uintptr{uintptr(0), uintptr(0), uintptr(0), uintptr(0)}

	*(*int32)(unsafe.Pointer(peType)) = RBU_PK_NOTABLE
	*(*int32)(unsafe.Pointer(piPk)) = 0

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+32, p+64,
		Xsqlite3_mprintf(tls,
			ts+34661, libc.VaList(bp, zTab)))
	if !((*Sqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK || Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 32))) != SQLITE_ROW) {
		goto __1
	}

	goto rbuTableType_end
__1:
	;
	if !(Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 32)), 0) != 0) {
		goto __2
	}
	*(*int32)(unsafe.Pointer(peType)) = RBU_PK_VTAB
	goto rbuTableType_end
__2:
	;
	*(*int32)(unsafe.Pointer(piTnum)) = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 32)), 1)

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+32+1*8, p+64,
		Xsqlite3_mprintf(tls, ts+34780, libc.VaList(bp+8, zTab)))
	if !((*Sqlite3rbu)(unsafe.Pointer(p)).Frc != 0) {
		goto __3
	}
	goto rbuTableType_end
__3:
	;
__4:
	if !(Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 1*8))) == SQLITE_ROW) {
		goto __5
	}
	zOrig = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 1*8)), 3)
	zIdx = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 1*8)), 1)
	if !(zOrig != 0 && zIdx != 0 && int32(*(*U8)(unsafe.Pointer(zOrig))) == 'p') {
		goto __6
	}
	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+32+2*8, p+64,
		Xsqlite3_mprintf(tls,
			ts+34801, libc.VaList(bp+16, zIdx)))
	if !((*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
		goto __7
	}
	if !(Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 2*8))) == SQLITE_ROW) {
		goto __8
	}
	*(*int32)(unsafe.Pointer(piPk)) = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 2*8)), 0)
	*(*int32)(unsafe.Pointer(peType)) = RBU_PK_EXTERNAL
	goto __9
__8:
	*(*int32)(unsafe.Pointer(peType)) = RBU_PK_WITHOUT_ROWID
__9:
	;
__7:
	;
	goto rbuTableType_end
__6:
	;
	goto __4
__5:
	;
	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+32+3*8, p+64,
		Xsqlite3_mprintf(tls, ts+34852, libc.VaList(bp+24, zTab)))
	if !((*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
		goto __10
	}
__11:
	if !(Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 3*8))) == SQLITE_ROW) {
		goto __12
	}
	if !(Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 32 + 3*8)), 5) > 0) {
		goto __13
	}
	*(*int32)(unsafe.Pointer(peType)) = RBU_PK_IPK
	goto rbuTableType_end
__13:
	;
	goto __11
__12:
	;
	*(*int32)(unsafe.Pointer(peType)) = RBU_PK_NONE
__10:
	;
rbuTableType_end:
	i = uint32(0)
__14:
	if !(uint64(i) < uint64(unsafe.Sizeof([4]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0)))) {
		goto __16
	}
	rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 32 + uintptr(i)*8)))
	goto __15
__15:
	i++
	goto __14
	goto __16
__16:
}

func rbuObjIterCacheIndexedCols(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	var bIndex int32 = 0

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		libc.Xmemcpy(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, (*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk, uint64(unsafe.Sizeof(U8(0)))*uint64((*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+16, p+64,
			Xsqlite3_mprintf(tls, ts+34873, libc.VaList(bp, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
	}

	(*RbuObjIter)(unsafe.Pointer(pIter)).FnIndex = 0
	for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) {
		var zIdx uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 1)
		var bPartial int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 4)
		*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
		if zIdx == uintptr(0) {
			break
		}
		if bPartial != 0 {
			libc.Xmemset(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, 0x01, uint64(unsafe.Sizeof(U8(0)))*uint64((*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		}
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+24, p+64,
			Xsqlite3_mprintf(tls, ts+34901, libc.VaList(bp+8, zIdx)))
		for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 24))) {
			var iCid int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), 1)
			if iCid >= 0 {
				*(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed + uintptr(iCid))) = U8(1)
			}
			if iCid == -2 {
				libc.Xmemset(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed, 0x01, uint64(unsafe.Sizeof(U8(0)))*uint64((*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
			}
		}
		rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 24)))
		bIndex = 1
		(*RbuObjIter)(unsafe.Pointer(pIter)).FnIndex++
	}

	if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_WITHOUT_ROWID {
		(*RbuObjIter)(unsafe.Pointer(pIter)).FnIndex--
	}

	rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if bIndex == 0 {
		(*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed = uintptr(0)
	}
}

func rbuObjIterCacheTableInfo(tls *libc.TLS, p uintptr, pIter uintptr) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	if (*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)
		var nCol int32 = 0
		var i int32
		var bRbuRowid int32 = 0
		var iOrder int32 = 0
		*(*int32)(unsafe.Pointer(bp + 56)) = 0

		rbuTableType(tls, p, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl, pIter+72, bp+56, pIter+108)
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NOTABLE {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_ERROR
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+23376, libc.VaList(bp, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl))
		}
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			return (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
		}
		if (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
			(*RbuObjIter)(unsafe.Pointer(pIter)).FiTnum = *(*int32)(unsafe.Pointer(bp + 56))
		}

		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp+64, p+64,
			Xsqlite3_mprintf(tls, ts+34930, libc.VaList(bp+8, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl)))
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			nCol = Xsqlite3_column_count(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
			rbuAllocateIterArrays(tls, p, pIter, nCol)
		}
		for i = 0; (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && i < nCol; i++ {
			var zName uintptr = Xsqlite3_column_name(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), i)
			if Xsqlite3_strnicmp(tls, ts+34949, zName, 4) != 0 {
				var zCopy uintptr = rbuStrndup(tls, zName, p+56)
				*(*int32)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr((*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol)*4)) = (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol
				*(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(libc.PostIncInt32(&(*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol, 1))*8)) = zCopy
			} else if 0 == Xsqlite3_stricmp(tls, ts+34954, zName) {
				bRbuRowid = 1
			}
		}
		Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
		*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK &&
			libc.Bool32((*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 &&
			bRbuRowid != libc.Bool32((*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_VTAB || (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE) {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_ERROR
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls,
				ts+34964, libc.VaList(bp+16, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl,
					func() uintptr {
						if bRbuRowid != 0 {
							return ts + 34993
						}
						return ts + 35006
					}()))
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+64, p+64,
				Xsqlite3_mprintf(tls, ts+35015, libc.VaList(bp+32, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		}
		for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 64))) {
			var zName uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), 1)
			if zName == uintptr(0) {
				break
			}
			for i = iOrder; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; i++ {
				if 0 == libc.Xstrcmp(tls, zName, *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))) {
					break
				}
			}
			if i == (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_ERROR
				(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+35037,
					libc.VaList(bp+40, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zName))
			} else {
				var iPk int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), 5)
				var bNotNull int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), 3)
				var zType uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), 2)

				if i != iOrder {
					{
						var t int32 = *(*int32)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4))
						*(*int32)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)) = *(*int32)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(iOrder)*4))
						*(*int32)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(iOrder)*4)) = t
					}

					{
						var t uintptr = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
						*(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iOrder)*8))
						*(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iOrder)*8)) = t
					}

				}

				*(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iOrder)*8)) = rbuStrndup(tls, zType, p+56)

				*(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(iOrder))) = U8(iPk)
				*(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(iOrder))) = U8(libc.Bool32(U8(bNotNull) != 0 || iPk != 0))
				iOrder++
			}
		}

		rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 64)))
		rbuObjIterCacheIndexedCols(tls, p, pIter)

	}

	return (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
}

func rbuObjIterGetCollist(tls *libc.TLS, p uintptr, pIter uintptr) uintptr {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var zList uintptr = uintptr(0)
	var zSep uintptr = ts + 1636
	var i int32
	for i = 0; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; i++ {
		var z uintptr = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
		zList = rbuMPrintf(tls, p, ts+35064, libc.VaList(bp, zList, zSep, z))
		zSep = ts + 18036
	}
	return zList
}

func rbuObjIterGetPkList(tls *libc.TLS, p uintptr, pIter uintptr, zPre uintptr, zSeparator uintptr, zPost uintptr) uintptr {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var iPk int32 = 1
	var zRet uintptr = uintptr(0)
	var zSep uintptr = ts + 1636
	for 1 != 0 {
		var i int32
		for i = 0; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; i++ {
			if int32(*(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == iPk {
				var zCol uintptr = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
				zRet = rbuMPrintf(tls, p, ts+35073, libc.VaList(bp, zRet, zSep, zPre, zCol, zPost))
				zSep = zSeparator
				break
			}
		}
		if i == (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
			break
		}
		iPk++
	}
	return zRet
}

func rbuVacuumTableStart(tls *libc.TLS, p uintptr, pIter uintptr, bRowid int32, zWrite uintptr) uintptr {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	*(*uintptr)(unsafe.Pointer(bp + 72)) = uintptr(0)
	var zRet uintptr = uintptr(0)
	if bRowid != 0 {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+72, p+64,
			Xsqlite3_mprintf(tls,
				ts+35086, libc.VaList(bp, zWrite, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 72))) {
			var iMax Sqlite3_int64 = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 72)), 0)
			zRet = rbuMPrintf(tls, p, ts+35118, libc.VaList(bp+16, iMax))
		}
		rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 72)))
	} else {
		var zOrder uintptr = rbuObjIterGetPkList(tls, p, pIter, ts+1636, ts+18036, ts+35141)
		var zSelect uintptr = rbuObjIterGetPkList(tls, p, pIter, ts+35147, ts+35154, ts+7885)
		var zList uintptr = rbuObjIterGetPkList(tls, p, pIter, ts+1636, ts+18036, ts+1636)

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+72, p+64,
				Xsqlite3_mprintf(tls,
					ts+35162,
					libc.VaList(bp+24, zSelect, zWrite, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zOrder)))
			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 72))) {
				var zVal uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 72)), 0)
				zRet = rbuMPrintf(tls, p, ts+35204, libc.VaList(bp+56, zList, zVal))
			}
			rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 72)))
		}

		Xsqlite3_free(tls, zOrder)
		Xsqlite3_free(tls, zSelect)
		Xsqlite3_free(tls, zList)
	}
	return zRet
}

func rbuVacuumIndexStart(tls *libc.TLS, p uintptr, pIter uintptr) uintptr {
	bp := tls.Alloc(192)
	defer tls.Free(192)

	var zOrder uintptr
	var zLhs uintptr
	var zSelect uintptr
	var zVector uintptr
	var zRet uintptr
	var bFailed int32
	var zSep uintptr
	var iCol int32

	var i int32
	var iCid int32
	var zCollate uintptr
	var zCol uintptr
	var zQuoted uintptr

	zOrder = uintptr(0)
	zLhs = uintptr(0)
	zSelect = uintptr(0)
	zVector = uintptr(0)
	zRet = uintptr(0)
	bFailed = 0
	zSep = ts + 1636
	iCol = 0
	*(*uintptr)(unsafe.Pointer(bp + 176)) = uintptr(0)

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+176, p+64,
		Xsqlite3_mprintf(tls, ts+34901, libc.VaList(bp, (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx)))
__1:
	if !((*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 176)))) {
		goto __2
	}
	iCid = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 176)), 1)
	zCollate = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 176)), 4)
	if !(Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 176)), 3) != 0) {
		goto __3
	}
	bFailed = 1
	goto __2
__3:
	;
	if !(iCid < 0) {
		goto __4
	}
	if !((*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_IPK) {
		goto __6
	}
	i = 0
__8:
	if !(int32(*(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0) {
		goto __10
	}
	goto __9
__9:
	i++
	goto __8
	goto __10
__10:
	;
	zCol = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
	goto __7
__6:
	zCol = ts + 35224
__7:
	;
	goto __5
__4:
	zCol = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCid)*8))
__5:
	;
	zLhs = rbuMPrintf(tls, p, ts+35232,
		libc.VaList(bp+8, zLhs, zSep, zCol, zCollate))
	zOrder = rbuMPrintf(tls, p, ts+35253,
		libc.VaList(bp+40, zOrder, zSep, iCol, zCol, zCollate))
	zSelect = rbuMPrintf(tls, p, ts+35289,
		libc.VaList(bp+80, zSelect, zSep, iCol, zCol))
	zSep = ts + 18036
	iCol++
	goto __1
__2:
	;
	rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 176)))
	if !(bFailed != 0) {
		goto __11
	}
	goto index_start_out
__11:
	;
	if !((*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
		goto __12
	}
	*(*uintptr)(unsafe.Pointer(bp + 184)) = uintptr(0)

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+184, p+64,
		Xsqlite3_mprintf(tls, ts+35316,
			libc.VaList(bp+112, zSelect, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zOrder)))
	if !((*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 184)))) {
		goto __13
	}
	zSep = ts + 1636
	iCol = 0
__14:
	if !(iCol < (*RbuObjIter)(unsafe.Pointer(pIter)).FnCol) {
		goto __16
	}
	zQuoted = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 184)), iCol)
	if !(zQuoted == uintptr(0)) {
		goto __17
	}
	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
	goto __18
__17:
	if !(int32(*(*uint8)(unsafe.Pointer(zQuoted))) == 'N') {
		goto __19
	}
	bFailed = 1
	goto __16
__19:
	;
__18:
	;
	zVector = rbuMPrintf(tls, p, ts+35364, libc.VaList(bp+136, zVector, zSep, zQuoted))
	zSep = ts + 18036
	goto __15
__15:
	iCol++
	goto __14
	goto __16
__16:
	;
	if !!(bFailed != 0) {
		goto __20
	}
	zRet = rbuMPrintf(tls, p, ts+35371, libc.VaList(bp+160, zLhs, zVector))
__20:
	;
__13:
	;
	rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 184)))
__12:
	;
index_start_out:
	Xsqlite3_free(tls, zOrder)
	Xsqlite3_free(tls, zSelect)
	Xsqlite3_free(tls, zVector)
	Xsqlite3_free(tls, zLhs)
	return zRet
}

func rbuObjIterGetIndexCols(tls *libc.TLS, p uintptr, pIter uintptr, pzImposterCols uintptr, pzImposterPk uintptr, pzWhere uintptr, pnBind uintptr) uintptr {
	bp := tls.Alloc(208)
	defer tls.Free(208)

	var rc int32 = (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
	var rc2 int32
	var zRet uintptr = uintptr(0)
	var zImpCols uintptr = uintptr(0)
	var zImpPK uintptr = uintptr(0)
	var zWhere uintptr = uintptr(0)
	var nBind int32 = 0
	var zCom uintptr = ts + 1636
	var zAnd uintptr = ts + 1636
	*(*uintptr)(unsafe.Pointer(bp + 200)) = uintptr(0)

	if rc == SQLITE_OK {
		rc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+200, p+64,
			Xsqlite3_mprintf(tls, ts+34901, libc.VaList(bp, (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx)))
	}

	for rc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 200))) {
		var iCid int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 200)), 1)
		var bDesc int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 200)), 3)
		var zCollate uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 200)), 4)
		var zCol uintptr = uintptr(0)
		var zType uintptr

		if iCid == -2 {
			var iSeq int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 200)), 0)
			zRet = Xsqlite3_mprintf(tls, ts+35383, libc.VaList(bp+8, zRet, zCom,
				(*RbuSpan)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol+uintptr(iSeq)*16)).FnSpan, (*RbuSpan)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol+uintptr(iSeq)*16)).FzSpan, zCollate))
			zType = ts + 1636
		} else {
			if iCid < 0 {
				if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_IPK {
					var i int32
					for i = 0; int32(*(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0; i++ {
					}

					zCol = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
				} else if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					zCol = ts + 35224
				} else {
					zCol = ts + 34954
				}
				zType = ts + 1201
			} else {
				zCol = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCid)*8))
				zType = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCid)*8))
			}
			zRet = Xsqlite3_mprintf(tls, ts+35405, libc.VaList(bp+48, zRet, zCom, zCol, zCollate))
		}

		if (*RbuObjIter)(unsafe.Pointer(pIter)).FbUnique == 0 || Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 200)), 5) != 0 {
			var zOrder uintptr = func() uintptr {
				if bDesc != 0 {
					return ts + 35141
				}
				return ts + 1636
			}()
			zImpPK = Xsqlite3_mprintf(tls, ts+35425,
				libc.VaList(bp+80, zImpPK, zCom, nBind, zCol, zOrder))
		}
		zImpCols = Xsqlite3_mprintf(tls, ts+35446,
			libc.VaList(bp+120, zImpCols, zCom, nBind, zCol, zType, zCollate))
		zWhere = Xsqlite3_mprintf(tls,
			ts+35479, libc.VaList(bp+168, zWhere, zAnd, nBind, zCol))
		if zRet == uintptr(0) || zImpPK == uintptr(0) || zImpCols == uintptr(0) || zWhere == uintptr(0) {
			rc = SQLITE_NOMEM
		}
		zCom = ts + 18036
		zAnd = ts + 25874
		nBind++
	}

	rc2 = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 200)))
	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)
		(*Sqlite3rbu)(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
}

func rbuObjIterGetOldlist(tls *libc.TLS, p uintptr, pIter uintptr, zObj uintptr) uintptr {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var zList uintptr = uintptr(0)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
		var zS uintptr = ts + 1636
		var i int32
		for i = 0; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; i++ {
			if *(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed + uintptr(i))) != 0 {
				var zCol uintptr = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
				zList = Xsqlite3_mprintf(tls, ts+35503, libc.VaList(bp, zList, zS, zObj, zCol))
			} else {
				zList = Xsqlite3_mprintf(tls, ts+35515, libc.VaList(bp+32, zList, zS))
			}
			zS = ts + 18036
			if zList == uintptr(0) {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
				break
			}
		}

		if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL || (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE {
			zList = rbuMPrintf(tls, p, ts+35524, libc.VaList(bp+48, zList, zObj))
		}
	}
	return zList
}

func rbuObjIterGetWhere(tls *libc.TLS, p uintptr, pIter uintptr) uintptr {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var zList uintptr = uintptr(0)
	if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_VTAB || (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE {
		zList = rbuMPrintf(tls, p, ts+35539, libc.VaList(bp, (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+1))
	} else if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL {
		var zSep uintptr = ts + 1636
		var i int32
		for i = 0; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; i++ {
			if *(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 {
				zList = rbuMPrintf(tls, p, ts+35553, libc.VaList(bp+8, zList, zSep, i, i+1))
				zSep = ts + 25874
			}
		}
		zList = rbuMPrintf(tls, p,
			ts+35565, libc.VaList(bp+40, zList))

	} else {
		var zSep uintptr = ts + 1636
		var i int32
		for i = 0; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; i++ {
			if *(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 {
				var zCol uintptr = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8))
				zList = rbuMPrintf(tls, p, ts+35615, libc.VaList(bp+48, zList, zSep, zCol, i+1))
				zSep = ts + 25874
			}
		}
	}
	return zList
}

func rbuBadControlError(tls *libc.TLS, p uintptr) {
	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_ERROR
	(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+35628, 0)
}

func rbuObjIterGetSetlist(tls *libc.TLS, p uintptr, pIter uintptr, zMask uintptr) uintptr {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	var zList uintptr = uintptr(0)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var i int32

		if int32(libc.Xstrlen(tls, zMask)) != (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol {
			rbuBadControlError(tls, p)
		} else {
			var zSep uintptr = ts + 1636
			for i = 0; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; i++ {
				var c uint8 = *(*uint8)(unsafe.Pointer(zMask + uintptr(*(*int32)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)))))
				if int32(c) == 'x' {
					zList = rbuMPrintf(tls, p, ts+35615,
						libc.VaList(bp, zList, zSep, *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), i+1))
					zSep = ts + 18036
				} else if int32(c) == 'd' {
					zList = rbuMPrintf(tls, p, ts+35654,
						libc.VaList(bp+32, zList, zSep, *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), i+1))
					zSep = ts + 18036
				} else if int32(c) == 'f' {
					zList = rbuMPrintf(tls, p, ts+35684,
						libc.VaList(bp+72, zList, zSep, *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*8)), i+1))
					zSep = ts + 18036
				}
			}
		}
	}
	return zList
}

func rbuObjIterGetBindlist(tls *libc.TLS, p uintptr, nBind int32) uintptr {
	var zRet uintptr = uintptr(0)
	var nByte Sqlite3_int64 = int64(2)*Sqlite3_int64(nBind) + int64(1)

	zRet = rbuMalloc(tls, p, nByte)
	if zRet != 0 {
		var i int32
		for i = 0; i < nBind; i++ {
			*(*uint8)(unsafe.Pointer(zRet + uintptr(i*2))) = uint8('?')
			*(*uint8)(unsafe.Pointer(zRet + uintptr(i*2+1))) = func() uint8 {
				if i+1 == nBind {
					return uint8(0)
				}
				return uint8(',')
			}()
		}
	}
	return zRet
}

func rbuWithoutRowidPK(tls *libc.TLS, p uintptr, pIter uintptr) uintptr {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var z uintptr = uintptr(0)

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var zSep uintptr = ts + 35721
		*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)

		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+56, p+64,
			Xsqlite3_mprintf(tls, ts+34873, libc.VaList(bp, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl)))
		for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 56))) {
			var zOrig uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 56)), 3)
			if zOrig != 0 && libc.Xstrcmp(tls, zOrig, ts+19702) == 0 {
				var zIdx uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 56)), 1)
				if zIdx != 0 {
					(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+64, p+64,
						Xsqlite3_mprintf(tls, ts+34901, libc.VaList(bp+8, zIdx)))
				}
				break
			}
		}
		rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 56)))

		for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 64))) {
			if Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), 5) != 0 {
				var zCol uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), 2)
				var zDesc uintptr
				if Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 64)), 3) != 0 {
					zDesc = ts + 35141
				} else {
					zDesc = ts + 1636
				}
				z = rbuMPrintf(tls, p, ts+35734, libc.VaList(bp+16, z, zSep, zCol, zDesc))
				zSep = ts + 18036
			}
		}
		z = rbuMPrintf(tls, p, ts+35745, libc.VaList(bp+48, z))
		rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 64)))
	}
	return z
}

func rbuCreateImposterTable2(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(184)
	defer tls.Free(184)

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL {
		var tnum int32 = (*RbuObjIter)(unsafe.Pointer(pIter)).FiPkTnum
		*(*uintptr)(unsafe.Pointer(bp + 168)) = uintptr(0)
		var zIdx uintptr = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 176)) = uintptr(0)
		var zComma uintptr = ts + 1636
		var zCols uintptr = uintptr(0)
		var zPk uintptr = uintptr(0)

		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+168, p+64,
			ts+35749)
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			Xsqlite3_bind_int(tls, *(*uintptr)(unsafe.Pointer(bp + 168)), 1, tnum)
			if SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 168))) {
				zIdx = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 168)), 0)
			}
		}
		if zIdx != 0 {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+176, p+64,
				Xsqlite3_mprintf(tls, ts+34901, libc.VaList(bp, zIdx)))
		}
		rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 168)))

		for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 176))) {
			var bKey int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 176)), 5)
			if bKey != 0 {
				var iCid int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 176)), 1)
				var bDesc int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 176)), 3)
				var zCollate uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 176)), 4)
				zCols = rbuMPrintf(tls, p, ts+35799, libc.VaList(bp+8, zCols, zComma,
					iCid, *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCid)*8)), zCollate))
				zPk = rbuMPrintf(tls, p, ts+35821, libc.VaList(bp+48, zPk, zComma, iCid, func() uintptr {
					if bDesc != 0 {
						return ts + 35141
					}
					return ts + 1636
				}()))
				zComma = ts + 18036
			}
		}
		zCols = rbuMPrintf(tls, p, ts+35831, libc.VaList(bp+80, zCols))
		rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 176)))

		Xsqlite3_test_control(tls, SQLITE_TESTCTRL_IMPOSTER, libc.VaList(bp+88, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, 1, tnum))
		rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain,
			ts+35846,
			libc.VaList(bp+120, zCols, zPk))
		Xsqlite3_test_control(tls, SQLITE_TESTCTRL_IMPOSTER, libc.VaList(bp+136, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, 0, 0))
	}
}

func rbuCreateImposterTable(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(200)
	defer tls.Free(200)

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*RbuObjIter)(unsafe.Pointer(pIter)).FeType != RBU_PK_VTAB {
		var tnum int32 = (*RbuObjIter)(unsafe.Pointer(pIter)).FiTnum
		var zComma uintptr = ts + 1636
		var zSql uintptr = uintptr(0)
		var iCol int32
		Xsqlite3_test_control(tls, SQLITE_TESTCTRL_IMPOSTER, libc.VaList(bp, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, 0, 1))

		for iCol = 0; (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && iCol < (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol; iCol++ {
			var zPk uintptr = ts + 1636
			var zCol uintptr = *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(iCol)*8))
			*(*uintptr)(unsafe.Pointer(bp + 192)) = uintptr(0)

			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_table_column_metadata(tls,
				(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zCol, uintptr(0), bp+192, uintptr(0), uintptr(0), uintptr(0))

			if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_IPK && *(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(iCol))) != 0 {
				zPk = ts + 35908
			}
			zSql = rbuMPrintf(tls, p, ts+35921,
				libc.VaList(bp+32, zSql, zComma, zCol, *(*uintptr)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(iCol)*8)), zPk, *(*uintptr)(unsafe.Pointer(bp + 192)),
					func() uintptr {
						if *(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabNotNull + uintptr(iCol))) != 0 {
							return ts + 35948
						}
						return ts + 1636
					}()))
			zComma = ts + 18036
		}

		if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_WITHOUT_ROWID {
			var zPk uintptr = rbuWithoutRowidPK(tls, p, pIter)
			if zPk != 0 {
				zSql = rbuMPrintf(tls, p, ts+35958, libc.VaList(bp+88, zSql, zPk))
			}
		}

		Xsqlite3_test_control(tls, SQLITE_TESTCTRL_IMPOSTER, libc.VaList(bp+104, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, 1, tnum))
		rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+35965,
			libc.VaList(bp+136, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zSql,
				func() uintptr {
					if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_WITHOUT_ROWID {
						return ts + 35997
					}
					return ts + 1636
				}()))
		Xsqlite3_test_control(tls, SQLITE_TESTCTRL_IMPOSTER, libc.VaList(bp+160, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, 0, 0))
	}
}

func rbuObjIterPrepareTmpInsert(tls *libc.TLS, p uintptr, pIter uintptr, zCollist uintptr, zRbuRowid uintptr) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var bRbuRowid int32 = libc.Bool32((*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL || (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE)
	var zBind uintptr = rbuObjIterGetBindlist(tls, p, (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+1+bRbuRowid)
	if zBind != 0 {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls,
			(*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+152, p+64, Xsqlite3_mprintf(tls,
				ts+36012,
				libc.VaList(bp, p+48, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zCollist, zRbuRowid, zBind)))
	}
}

func rbuTmpInsertFunc(tls *libc.TLS, pCtx uintptr, nVal int32, apVal uintptr) {
	var p uintptr = Xsqlite3_user_data(tls, pCtx)
	var rc int32 = SQLITE_OK
	var i int32

	if Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal))) != 0 {
		*(*I64)(unsafe.Pointer(p + 304)) += I64((*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
	}

	for i = 0; rc == SQLITE_OK && i < nVal; i++ {
		rc = Xsqlite3_bind_value(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpTmpInsert, i+1, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8)))
	}
	if rc == SQLITE_OK {
		Xsqlite3_step(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpTmpInsert)
		rc = Xsqlite3_reset(tls, (*Sqlite3rbu)(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) uintptr {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 8)) = (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
	var zRet uintptr = uintptr(0)

	if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 8)) = prepareAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp, p+64,
			ts+36069)
	}
	if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
		var rc2 int32
		*(*int32)(unsafe.Pointer(bp + 8)) = Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 1, (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx, -1, uintptr(0))
		if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			var zSql uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			if zSql != 0 {
				(*RbuObjIter)(unsafe.Pointer(pIter)).FzIdxSql = libc.AssignUintptr(&zSql, rbuStrndup(tls, zSql, bp+8))
			}
			if zSql != 0 {
				var nParen int32 = 0
				var i int32
				var iIdxCol int32 = 0
				var nIdxAlloc int32 = 0
				for i = 0; *(*uint8)(unsafe.Pointer(zSql + uintptr(i))) != 0; i++ {
					var c uint8 = *(*uint8)(unsafe.Pointer(zSql + uintptr(i)))

					if iIdxCol == nIdxAlloc {
						var aIdxCol uintptr = Xsqlite3_realloc(tls,
							(*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol, int32(uint64(nIdxAlloc+16)*uint64(unsafe.Sizeof(RbuSpan{}))))
						if aIdxCol == uintptr(0) {
							*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_NOMEM
							break
						}
						(*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol = aIdxCol
						nIdxAlloc = nIdxAlloc + 16
					}

					if int32(c) == '(' {
						if nParen == 0 {
							(*RbuSpan)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol)).FzSpan = zSql + uintptr(i+1)
						}
						nParen++
					} else if int32(c) == ')' {
						nParen--
						if nParen == 0 {
							var nSpan int32 = int32((int64(zSql+uintptr(i)) - int64((*RbuSpan)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol+uintptr(iIdxCol)*16)).FzSpan)) / 1)
							(*RbuSpan)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(libc.PostIncInt32(&iIdxCol, 1))*16)).FnSpan = nSpan
							i++
							break
						}
					} else if int32(c) == ',' && nParen == 1 {
						var nSpan int32 = int32((int64(zSql+uintptr(i)) - int64((*RbuSpan)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol+uintptr(iIdxCol)*16)).FzSpan)) / 1)
						(*RbuSpan)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(libc.PostIncInt32(&iIdxCol, 1))*16)).FnSpan = nSpan
						(*RbuSpan)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaIdxCol + uintptr(iIdxCol)*16)).FzSpan = zSql + uintptr(i+1)
					} else if int32(c) == '"' || int32(c) == '\'' || int32(c) == '`' {
						for i++; 1 != 0; i++ {
							if int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i)))) == int32(c) {
								if int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i+1)))) != int32(c) {
									break
								}
								i++
							}
						}
					} else if int32(c) == '[' {
						for i++; 1 != 0; i++ {
							if int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i)))) == ']' {
								break
							}
						}
					} else if int32(c) == '-' && int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i+1)))) == '-' {
						for i = i + 2; *(*uint8)(unsafe.Pointer(zSql + uintptr(i))) != 0 && int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i)))) != '\n'; i++ {
						}
						if int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i)))) == 0 {
							break
						}
					} else if int32(c) == '/' && int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i+1)))) == '*' {
						for i = i + 2; *(*uint8)(unsafe.Pointer(zSql + uintptr(i))) != 0 && (int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i)))) != '*' || int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i+1)))) != '/'); i++ {
						}
						if int32(*(*uint8)(unsafe.Pointer(zSql + uintptr(i)))) == 0 {
							break
						}
						i++
					}
				}
				if *(*uint8)(unsafe.Pointer(zSql + uintptr(i))) != 0 {
					zRet = rbuStrndup(tls, zSql+uintptr(i), bp+8)
				}
				(*RbuObjIter)(unsafe.Pointer(pIter)).FnIdxCol = iIdxCol
			}
		}

		rc2 = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 8)) = rc2
		}
	}

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = *(*int32)(unsafe.Pointer(bp + 8))
	return zRet
}

func rbuObjIterPrepareAll(tls *libc.TLS, p uintptr, pIter uintptr, nOffset int32) int32 {
	bp := tls.Alloc(628)
	defer tls.Free(628)

	if (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect == uintptr(0) && rbuObjIterCacheTableInfo(tls, p, pIter) == SQLITE_OK {
		var tnum int32 = (*RbuObjIter)(unsafe.Pointer(pIter)).FiTnum
		var zCollist uintptr = uintptr(0)
		var pz uintptr = p + 64
		var zIdx uintptr = (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx
		var zLimit uintptr = uintptr(0)

		if nOffset != 0 {
			zLimit = Xsqlite3_mprintf(tls, ts+36135, libc.VaList(bp, nOffset))
			if !(zLimit != 0) {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
			}
		}

		if zIdx != 0 {
			var zTbl uintptr = (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl
			*(*uintptr)(unsafe.Pointer(bp + 600)) = uintptr(0)
			*(*uintptr)(unsafe.Pointer(bp + 608)) = uintptr(0)
			*(*uintptr)(unsafe.Pointer(bp + 616)) = uintptr(0)
			var zBind uintptr = uintptr(0)
			var zPart uintptr = uintptr(0)
			*(*int32)(unsafe.Pointer(bp + 624)) = 0

			zPart = rbuObjIterGetIndexWhere(tls, p, pIter)
			zCollist = rbuObjIterGetIndexCols(tls,
				p, pIter, bp+600, bp+608, bp+616, bp+624)
			zBind = rbuObjIterGetBindlist(tls, p, *(*int32)(unsafe.Pointer(bp + 624)))

			Xsqlite3_test_control(tls, SQLITE_TESTCTRL_IMPOSTER, libc.VaList(bp+8, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, 0, 1))
			Xsqlite3_test_control(tls, SQLITE_TESTCTRL_IMPOSTER, libc.VaList(bp+40, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, 1, tnum))
			rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain,
				ts+36155,
				libc.VaList(bp+72, zTbl, *(*uintptr)(unsafe.Pointer(bp + 600)), *(*uintptr)(unsafe.Pointer(bp + 608))))
			Xsqlite3_test_control(tls, SQLITE_TESTCTRL_IMPOSTER, libc.VaList(bp+96, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, 0, 0))

			(*RbuObjIter)(unsafe.Pointer(pIter)).FnCol = *(*int32)(unsafe.Pointer(bp + 624))
			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls,
					(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+136, p+64,
					Xsqlite3_mprintf(tls, ts+36220, libc.VaList(bp+128, zTbl, zBind)))
			}

			if libc.Bool32((*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls,
					(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+144, p+64,
					Xsqlite3_mprintf(tls, ts+36256, libc.VaList(bp+144, zTbl, *(*uintptr)(unsafe.Pointer(bp + 616)))))
			}

			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				var zSql uintptr
				if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					var zStart uintptr = uintptr(0)
					if nOffset != 0 {
						zStart = rbuVacuumIndexStart(tls, p, pIter)
						if zStart != 0 {
							Xsqlite3_free(tls, zLimit)
							zLimit = uintptr(0)
						}
					}

					zSql = Xsqlite3_mprintf(tls,
						ts+36290,
						libc.VaList(bp+160, zCollist,
							(*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl,
							zPart,
							func() uintptr {
								if zStart != 0 {
									return func() uintptr {
										if zPart != 0 {
											return ts + 36351
										}
										return ts + 36355
									}()
								}
								return ts + 1636
							}(), zStart,
							zCollist, zLimit))
					Xsqlite3_free(tls, zStart)
				} else if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL || (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE {
					zSql = Xsqlite3_mprintf(tls,
						ts+36361,
						libc.VaList(bp+216, zCollist, p+48, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl,
							zPart, zCollist, zLimit))
				} else {
					zSql = Xsqlite3_mprintf(tls,
						ts+36422,
						libc.VaList(bp+264, zCollist, p+48, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, zPart,
							zCollist, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl,
							zPart,
							func() uintptr {
								if zPart != 0 {
									return ts + 36351
								}
								return ts + 36355
							}(),
							zCollist, zLimit))
				}
				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+128, pz, zSql)
				} else {
					Xsqlite3_free(tls, zSql)
				}
			}

			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 600)))
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 608)))
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 616)))
			Xsqlite3_free(tls, zBind)
			Xsqlite3_free(tls, zPart)
		} else {
			var bRbuRowid int32 = libc.Bool32((*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_VTAB ||
				(*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE ||
				(*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL && (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0))
			var zTbl uintptr = (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl
			var zWrite uintptr

			var zBindings uintptr = rbuObjIterGetBindlist(tls, p, (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol+bRbuRowid)
			var zWhere uintptr = rbuObjIterGetWhere(tls, p, pIter)
			var zOldlist uintptr = rbuObjIterGetOldlist(tls, p, pIter, ts+9667)
			var zNewlist uintptr = rbuObjIterGetOldlist(tls, p, pIter, ts+9663)

			zCollist = rbuObjIterGetCollist(tls, p, pIter)
			(*RbuObjIter)(unsafe.Pointer(pIter)).FnCol = (*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol

			rbuCreateImposterTable(tls, p, pIter)
			rbuCreateImposterTable2(tls, p, pIter)
			zWrite = func() uintptr {
				if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_VTAB {
					return ts + 1636
				}
				return ts + 36581
			}()

			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+136, pz,
					Xsqlite3_mprintf(tls,
						ts+36590,
						libc.VaList(bp+344, zWrite, zTbl, zCollist, func() uintptr {
							if bRbuRowid != 0 {
								return ts + 36626
							}
							return ts + 1636
						}(), zBindings)))
			}

			if libc.Bool32((*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, pIter+144, pz,
					Xsqlite3_mprintf(tls,
						ts+36636, libc.VaList(bp+384, zWrite, zTbl, zWhere)))
			}

			if libc.Bool32((*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
				var zRbuRowid uintptr = ts + 1636
				if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL || (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE {
					zRbuRowid = ts + 36664
				}

				rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu,
					ts+36676, libc.VaList(bp+408, p+48, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, func() uintptr {
						if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL {
							return ts + 36752
						}
						return ts + 1636
					}(), (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl))

				rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain,
					ts+36769,
					libc.VaList(bp+440, zWrite, zTbl, zOldlist,
						zWrite, zTbl, zOldlist,
						zWrite, zTbl, zNewlist))

				if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL || (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE {
					rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain,
						ts+37068,
						libc.VaList(bp+512, zWrite, zTbl, zNewlist))
				}

				rbuObjIterPrepareTmpInsert(tls, p, pIter, zCollist, zRbuRowid)
			}

			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				var zRbuRowid uintptr = ts + 1636
				var zStart uintptr = uintptr(0)
				var zOrder uintptr = uintptr(0)
				if bRbuRowid != 0 {
					if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						zRbuRowid = ts + 37167
					} else {
						zRbuRowid = ts + 37177
					}
				}

				if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					if nOffset != 0 {
						zStart = rbuVacuumTableStart(tls, p, pIter, bRbuRowid, zWrite)
						if zStart != 0 {
							Xsqlite3_free(tls, zLimit)
							zLimit = uintptr(0)
						}
					}
					if bRbuRowid != 0 {
						zOrder = rbuMPrintf(tls, p, ts+35224, 0)
					} else {
						zOrder = rbuObjIterGetPkList(tls, p, pIter, ts+1636, ts+18036, ts+1636)
					}
				}

				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, pIter+128, pz,
						Xsqlite3_mprintf(tls,
							ts+37188,
							libc.VaList(bp+536, zCollist,
								func() uintptr {
									if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
										return ts + 37236
									}
									return ts + 1636
								}(),
								zRbuRowid,
								(*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, func() uintptr {
									if zStart != 0 {
										return zStart
									}
									return ts + 1636
								}(),
								func() uintptr {
									if zOrder != 0 {
										return ts + 27437
									}
									return ts + 1636
								}(), zOrder,
								zLimit)))
				}
				Xsqlite3_free(tls, zStart)
				Xsqlite3_free(tls, zOrder)
			}

			Xsqlite3_free(tls, zWhere)
			Xsqlite3_free(tls, zOldlist)
			Xsqlite3_free(tls, zNewlist)
			Xsqlite3_free(tls, zBindings)
		}
		Xsqlite3_free(tls, zCollist)
		Xsqlite3_free(tls, zLimit)
	}

	return (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
}

func rbuGetUpdateStmt(tls *libc.TLS, p uintptr, pIter uintptr, zMask uintptr, ppStmt uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pp uintptr
	var pUp uintptr = uintptr(0)
	var nUp int32 = 0

	*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)

	for pp = pIter + 184; *(*uintptr)(unsafe.Pointer(pp)) != 0; pp = *(*uintptr)(unsafe.Pointer(pp)) + 16 {
		pUp = *(*uintptr)(unsafe.Pointer(pp))
		if libc.Xstrcmp(tls, (*RbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask, zMask) == 0 {
			*(*uintptr)(unsafe.Pointer(pp)) = (*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext
			(*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext = (*RbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
			(*RbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = pUp
			*(*uintptr)(unsafe.Pointer(ppStmt)) = (*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate
			return SQLITE_OK
		}
		nUp++
	}

	if nUp >= SQLITE_RBU_UPDATE_CACHESIZE {
		for pp = pIter + 184; *(*uintptr)(unsafe.Pointer(pp)) != pUp; pp = *(*uintptr)(unsafe.Pointer(pp)) + 16 {
		}
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
		Xsqlite3_finalize(tls, (*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate)
		(*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate = uintptr(0)
	} else {
		pUp = rbuMalloc(tls, p, int64(uint64(unsafe.Sizeof(RbuUpdateStmt{}))+uint64((*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol)+uint64(1)))
	}

	if pUp != 0 {
		var zWhere uintptr = rbuObjIterGetWhere(tls, p, pIter)
		var zSet uintptr = rbuObjIterGetSetlist(tls, p, pIter, zMask)
		var zUpdate uintptr = uintptr(0)

		(*RbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask = pUp + 1*24
		libc.Xmemcpy(tls, (*RbuUpdateStmt)(unsafe.Pointer(pUp)).FzMask, zMask, uint64((*RbuObjIter)(unsafe.Pointer(pIter)).FnTblCol))
		(*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpNext = (*RbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate
		(*RbuObjIter)(unsafe.Pointer(pIter)).FpRbuUpdate = pUp

		if zSet != 0 {
			var zPrefix uintptr = ts + 1636

			if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType != RBU_PK_VTAB {
				zPrefix = ts + 36581
			}
			zUpdate = Xsqlite3_mprintf(tls, ts+37242,
				libc.VaList(bp, zPrefix, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl, zSet, zWhere))
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls,
				(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, pUp+8, p+64, zUpdate)
			*(*uintptr)(unsafe.Pointer(ppStmt)) = (*RbuUpdateStmt)(unsafe.Pointer(pUp)).FpUpdate
		}
		Xsqlite3_free(tls, zWhere)
		Xsqlite3_free(tls, zSet)
	}

	return (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
}

func rbuOpenDbhandle(tls *libc.TLS, p uintptr, zName uintptr, bUseVfs int32) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var flags int32 = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_open_v2(tls, zName, bp+8, flags, func() uintptr {
			if bUseVfs != 0 {
				return (*Sqlite3rbu)(unsafe.Pointer(p)).FzVfsName
			}
			return uintptr(0)
		}())
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, Xsqlite3_errmsg(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))))
			Xsqlite3_close(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		}
	}
	return *(*uintptr)(unsafe.Pointer(bp + 8))
}

func rbuFreeState(tls *libc.TLS, p uintptr) {
	if p != 0 {
		Xsqlite3_free(tls, (*RbuState)(unsafe.Pointer(p)).FzTbl)
		Xsqlite3_free(tls, (*RbuState)(unsafe.Pointer(p)).FzDataTbl)
		Xsqlite3_free(tls, (*RbuState)(unsafe.Pointer(p)).FzIdx)
		Xsqlite3_free(tls, p)
	}
}

func rbuLoadState(tls *libc.TLS, p uintptr) uintptr {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var pRet uintptr = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

	var rc2 int32

	pRet = rbuMalloc(tls, p, int64(unsafe.Sizeof(RbuState{})))
	if pRet == uintptr(0) {
		return uintptr(0)
	}

	*(*int32)(unsafe.Pointer(bp + 16)) = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp+8, p+64,
		Xsqlite3_mprintf(tls, ts+37272, libc.VaList(bp, p+48)))
	for *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 8))) {
		switch Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 0) {
		case RBU_STATE_STAGE:
			(*RbuState)(unsafe.Pointer(pRet)).FeStage = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1)
			if (*RbuState)(unsafe.Pointer(pRet)).FeStage != RBU_STAGE_OAL &&
				(*RbuState)(unsafe.Pointer(pRet)).FeStage != RBU_STAGE_MOVE &&
				(*RbuState)(unsafe.Pointer(pRet)).FeStage != RBU_STAGE_CKPT {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT
			}
			break

		case RBU_STATE_TBL:
			(*RbuState)(unsafe.Pointer(pRet)).FzTbl = rbuStrndup(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1), bp+16)
			break

		case RBU_STATE_IDX:
			(*RbuState)(unsafe.Pointer(pRet)).FzIdx = rbuStrndup(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1), bp+16)
			break

		case RBU_STATE_ROW:
			(*RbuState)(unsafe.Pointer(pRet)).FnRow = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1)
			break

		case RBU_STATE_PROGRESS:
			(*RbuState)(unsafe.Pointer(pRet)).FnProgress = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1)
			break

		case RBU_STATE_CKPT:
			(*RbuState)(unsafe.Pointer(pRet)).FiWalCksum = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1)
			break

		case RBU_STATE_COOKIE:
			(*RbuState)(unsafe.Pointer(pRet)).FiCookie = U32(Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1))
			break

		case RBU_STATE_OALSZ:
			(*RbuState)(unsafe.Pointer(pRet)).FiOalSz = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1)
			break

		case RBU_STATE_PHASEONESTEP:
			(*RbuState)(unsafe.Pointer(pRet)).FnPhaseOneStep = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1)
			break

		case RBU_STATE_DATATBL:
			(*RbuState)(unsafe.Pointer(pRet)).FzDataTbl = rbuStrndup(tls, Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 1), bp+16)
			break

		default:
			*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_CORRUPT
			break
		}
	}
	rc2 = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 16)) = rc2
	}

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = *(*int32)(unsafe.Pointer(bp + 16))
	return pRet
}

func rbuOpenDatabase(tls *libc.TLS, p uintptr, dbMain uintptr, pbRetry uintptr) {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	(*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu = rbuOpenDbhandle(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FzRbu, 1)
	(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain = dbMain

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		Xsqlite3_file_control(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+9656, SQLITE_FCNTL_RBUCNT, p)
		if (*Sqlite3rbu)(unsafe.Pointer(p)).FzState == uintptr(0) {
			var zFile uintptr = Xsqlite3_db_filename(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+9656)
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzState = rbuMPrintf(tls, p, ts+37302, libc.VaList(bp, zFile, zFile))
		}
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).FzState != 0 {
		rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+37330, libc.VaList(bp+16, (*Sqlite3rbu)(unsafe.Pointer(p)).FzState))
		libc.Xmemcpy(tls, p+48, ts+5648, uint64(4))
	} else {
		libc.Xmemcpy(tls, p+48, ts+9656, uint64(4))
	}

	rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+37348, libc.VaList(bp+24, p+48))

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		var bOpen int32 = 0
		var rc int32
		(*Sqlite3rbu)(unsafe.Pointer(p)).FnRbu = 0
		(*Sqlite3rbu)(unsafe.Pointer(p)).FpRbuFd = uintptr(0)
		rc = Xsqlite3_file_control(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+9656, SQLITE_FCNTL_RBUCNT, p)
		if rc != SQLITE_NOTFOUND {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc
		}
		if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage >= RBU_STAGE_MOVE {
			bOpen = 1
		} else {
			var pState uintptr = rbuLoadState(tls, p)
			if pState != 0 {
				bOpen = libc.Bool32((*RbuState)(unsafe.Pointer(pState)).FeStage >= RBU_STAGE_MOVE)
				rbuFreeState(tls, pState)
			}
		}
		if bOpen != 0 {
			(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain = rbuOpenDbhandle(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FzRbu, libc.Bool32((*Sqlite3rbu)(unsafe.Pointer(p)).FnRbu <= 1))
		}
	}

	(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = 0
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain == uintptr(0) {
		if !((*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) {
			(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain = rbuOpenDbhandle(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget, 1)
		} else if (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpRbuFd)).FpWalFd != 0 {
			if pbRetry != 0 {
				(*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpRbuFd)).FbNolock = U8(0)
				Xsqlite3_close(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
				Xsqlite3_close(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain)
				(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain = uintptr(0)
				(*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu = uintptr(0)
				*(*int32)(unsafe.Pointer(pbRetry)) = 1
				return
			}
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_ERROR
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+37414, 0)
		} else {
			var zTarget uintptr
			var zExtra uintptr = uintptr(0)
			if libc.Xstrlen(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzRbu) >= uint64(5) && 0 == libc.Xmemcmp(tls, ts+30501, (*Sqlite3rbu)(unsafe.Pointer(p)).FzRbu, uint64(5)) {
				zExtra = (*Sqlite3rbu)(unsafe.Pointer(p)).FzRbu + 5
				for *(*uint8)(unsafe.Pointer(zExtra)) != 0 {
					if int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zExtra, 1)))) == '?' {
						break
					}
				}
				if int32(*(*uint8)(unsafe.Pointer(zExtra))) == 0 {
					zExtra = uintptr(0)
				}
			}

			zTarget = Xsqlite3_mprintf(tls, ts+37446,
				libc.VaList(bp+32, Xsqlite3_db_filename(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+9656),
					func() uintptr {
						if zExtra == uintptr(0) {
							return ts + 1636
						}
						return ts + 37478
					}(), func() uintptr {
						if zExtra == uintptr(0) {
							return ts + 1636
						}
						return zExtra
					}()))

			if zTarget == uintptr(0) {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
				return
			}
			(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain = rbuOpenDbhandle(tls, p, zTarget, libc.Bool32((*Sqlite3rbu)(unsafe.Pointer(p)).FnRbu <= 1))
			Xsqlite3_free(tls, zTarget)
		}
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain,
			ts+37480, -1, SQLITE_UTF8, p, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr)
			}{rbuTmpInsertFunc})), uintptr(0), uintptr(0))
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain,
			ts+37495, 2, SQLITE_UTF8, uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr)
			}{rbuFossilDeltaFunc})), uintptr(0), uintptr(0))
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu,
			ts+37512, -1, SQLITE_UTF8, p, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr)
			}{rbuTargetNameFunc})), uintptr(0), uintptr(0))
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_file_control(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, SQLITE_FCNTL_RBU, p)
	}
	rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+37528, 0)

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_file_control(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, SQLITE_FCNTL_RBU, p)
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_NOTFOUND {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_ERROR
		(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+37556, 0)
	}
}

func rbuFileSuffix3(tls *libc.TLS, zBase uintptr, z uintptr) {
}

func rbuShmChecksum(tls *libc.TLS, p uintptr) I64 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var iRet I64 = int64(0)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var pDb uintptr = (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal

		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = (*struct {
			f func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxShmMap})).f(tls, pDb, 0, 32*1024, 0, bp)
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			iRet = I64(*(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 10*4)))<<32 + I64(*(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + 11*4)))
		}
	}
	return iRet
}

func rbuSetupCheckpoint(tls *libc.TLS, p uintptr, pState uintptr) {
	if pState == uintptr(0) {
		(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = 0
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+37528, uintptr(0), uintptr(0), uintptr(0))
		}
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var rc2 int32
		(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_CAPTURE
		rc2 = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+37574, uintptr(0), uintptr(0), uintptr(0))
		if rc2 != SQLITE_NOTICE {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc2
		}
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FnFrame > 0 {
		(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_CKPT
		(*Sqlite3rbu)(unsafe.Pointer(p)).FnStep = func() int32 {
			if pState != 0 {
				return (*RbuState)(unsafe.Pointer(pState)).FnRow
			}
			return 0
		}()
		(*Sqlite3rbu)(unsafe.Pointer(p)).FaBuf = rbuMalloc(tls, p, int64((*Sqlite3rbu)(unsafe.Pointer(p)).Fpgsz))
		(*Sqlite3rbu)(unsafe.Pointer(p)).FiWalCksum = rbuShmChecksum(tls, p)
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*Sqlite3rbu)(unsafe.Pointer(p)).FnFrame == 0 || pState != 0 && (*RbuState)(unsafe.Pointer(pState)).FiWalCksum != (*Sqlite3rbu)(unsafe.Pointer(p)).FiWalCksum {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_DONE
			(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_DONE
		} else {
			var nSectorSize int32
			var pDb uintptr = (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
			var pWal uintptr = (*Rbu_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd)).FpReal

			nSectorSize = (*struct {
				f func(*libc.TLS, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSectorSize})).f(tls, pDb)
			if nSectorSize > (*Sqlite3rbu)(unsafe.Pointer(p)).Fpgsz {
				(*Sqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector = nSectorSize / (*Sqlite3rbu)(unsafe.Pointer(p)).Fpgsz
			} else {
				(*Sqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector = 1
			}

			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = (*struct {
				f func(*libc.TLS, uintptr, int32) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pWal)).FpMethods)).FxSync})).f(tls, pWal, SQLITE_SYNC_NORMAL)
		}
	}
}

func rbuCaptureWalRead(tls *libc.TLS, pRbu uintptr, iOff I64, iAmt int32) int32 {
	var mReq U32 = U32(int32(1)<<WAL_LOCK_WRITE | int32(1)<<WAL_LOCK_CKPT | int32(1)<<WAL_LOCK_READ0)
	var iFrame U32

	if (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FmLock != mReq {
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).Frc = SQLITE_BUSY
		return SQLITE_NOTICE | int32(3)<<8
	}

	(*Sqlite3rbu)(unsafe.Pointer(pRbu)).Fpgsz = iAmt
	if (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame == (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrameAlloc {
		var nNew int32 = func() int32 {
			if (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrameAlloc != 0 {
				return (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrameAlloc
			}
			return 64
		}() * 2
		var aNew uintptr
		aNew = Xsqlite3_realloc64(tls, (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame, uint64(nNew)*uint64(unsafe.Sizeof(RbuFrame{})))
		if aNew == uintptr(0) {
			return SQLITE_NOMEM
		}
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame = aNew
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrameAlloc = nNew
	}

	iFrame = U32((iOff-int64(32))/I64(iAmt+24)) + U32(1)
	if (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FiMaxFrame < iFrame {
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FiMaxFrame = iFrame
	}
	(*RbuFrame)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame + uintptr((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame)*8)).FiWalFrame = iFrame
	(*RbuFrame)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame + uintptr((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame)*8)).FiDbPage = U32(0)
	(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame++
	return SQLITE_OK
}

func rbuCaptureDbWrite(tls *libc.TLS, pRbu uintptr, iOff I64) int32 {
	(*RbuFrame)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FaFrame + uintptr((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnFrame-1)*8)).FiDbPage = U32(iOff/I64((*Sqlite3rbu)(unsafe.Pointer(pRbu)).Fpgsz)) + U32(1)
	return SQLITE_OK
}

func rbuCheckpointFrame(tls *libc.TLS, p uintptr, pFrame uintptr) {
	var pWal uintptr = (*Rbu_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd)).FpReal
	var pDb uintptr = (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
	var iOff I64

	iOff = I64((*RbuFrame)(unsafe.Pointer(pFrame)).FiWalFrame-U32(1))*I64((*Sqlite3rbu)(unsafe.Pointer(p)).Fpgsz+24) + int64(32) + int64(24)
	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pWal)).FpMethods)).FxRead})).f(tls, pWal, (*Sqlite3rbu)(unsafe.Pointer(p)).FaBuf, (*Sqlite3rbu)(unsafe.Pointer(p)).Fpgsz, iOff)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
		return
	}

	iOff = I64((*RbuFrame)(unsafe.Pointer(pFrame)).FiDbPage-U32(1)) * I64((*Sqlite3rbu)(unsafe.Pointer(p)).Fpgsz)
	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxWrite})).f(tls, pDb, (*Sqlite3rbu)(unsafe.Pointer(p)).FaBuf, (*Sqlite3rbu)(unsafe.Pointer(p)).Fpgsz, iOff)
}

func rbuLockDatabase(tls *libc.TLS, db uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	Xsqlite3_file_control(tls, db, ts+9656, SQLITE_FCNTL_FILE_POINTER, bp)

	if (*Sqlite3_file)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpMethods != 0 {
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpMethods)).FxLock})).f(tls, *(*uintptr)(unsafe.Pointer(bp)), SQLITE_LOCK_SHARED)
		if rc == SQLITE_OK {
			rc = (*struct {
				f func(*libc.TLS, uintptr, int32) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FpMethods)).FxLock})).f(tls, *(*uintptr)(unsafe.Pointer(bp)), SQLITE_LOCK_EXCLUSIVE)
		}
	}
	return rc
}

func rbuExclusiveCheckpoint(tls *libc.TLS, db uintptr) int32 {
	var zUri uintptr = Xsqlite3_db_filename(tls, db, uintptr(0))
	return Xsqlite3_uri_boolean(tls, zUri, ts+37609, 0)
}

func rbuMoveOalFile(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var zBase uintptr = Xsqlite3_db_filename(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656)
	var zMove uintptr = zBase
	var zOal uintptr
	var zWal uintptr

	if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
		zMove = Xsqlite3_db_filename(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+9656)
	}
	zOal = Xsqlite3_mprintf(tls, ts+37634, libc.VaList(bp, zMove))
	zWal = Xsqlite3_mprintf(tls, ts+37641, libc.VaList(bp+8, zMove))

	if zWal == uintptr(0) || zOal == uintptr(0) {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
	} else {
		var dbMain uintptr = uintptr(0)
		rbuFileSuffix3(tls, zBase, zWal)
		rbuFileSuffix3(tls, zBase, zOal)

		rbuObjIterFinalize(tls, p+80)
		Xsqlite3_close(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
		Xsqlite3_close(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain)
		(*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain = uintptr(0)
		(*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu = uintptr(0)

		dbMain = rbuOpenDbhandle(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget, 1)
		if dbMain != 0 {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rbuLockDatabase(tls, dbMain)
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = (*struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3rbu)(unsafe.Pointer(p)).FxRename})).f(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FpRenameArg, zOal, zWal)
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK ||
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) ||
			rbuExclusiveCheckpoint(tls, dbMain) == 0 {
			Xsqlite3_close(tls, dbMain)
			dbMain = uintptr(0)
		}

		if (*Sqlite3rbu)(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)
}

func rbuStepType(tls *libc.TLS, p uintptr, pzMask uintptr) int32 {
	var iCol int32 = (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnCol
	var res int32 = 0

	switch Xsqlite3_column_type(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpSelect, iCol) {
	case SQLITE_INTEGER:
		{
			var iVal int32 = Xsqlite3_column_int(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpSelect, iCol)
			switch iVal {
			case 0:
				res = RBU_INSERT
				break
			case 1:
				res = RBU_DELETE
				break
			case 2:
				res = RBU_REPLACE
				break
			case 3:
				res = RBU_IDX_DELETE
				break
			case 4:
				res = RBU_IDX_INSERT
				break
			}
			break

		}

	case SQLITE_TEXT:
		{
			var z uintptr = Xsqlite3_column_text(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FpSelect, iCol)
			if z == uintptr(0) {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
			} else {
				*(*uintptr)(unsafe.Pointer(pzMask)) = z
			}
			res = RBU_UPDATE

			break

		}

	default:
		break
	}

	if res == 0 {
		rbuBadControlError(tls, p)
	}
	return res
}

func rbuStepOneOp(tls *libc.TLS, p uintptr, eType int32) {
	var pIter uintptr = p + 80
	var pVal uintptr
	var pWriter uintptr
	var i int32

	if eType == RBU_DELETE {
		*(*I64)(unsafe.Pointer(p + 304)) -= I64((*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
	}

	if eType == RBU_IDX_DELETE || eType == RBU_DELETE {
		pWriter = (*RbuObjIter)(unsafe.Pointer(pIter)).FpDelete
	} else {
		pWriter = (*RbuObjIter)(unsafe.Pointer(pIter)).FpInsert
	}

	for i = 0; i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnCol; i++ {
		if eType == RBU_INSERT &&
			(*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) && (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_IPK && *(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 &&
			Xsqlite3_column_type(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i) == SQLITE_NULL {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_MISMATCH
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+30139, 0)
			return
		}

		if eType == RBU_DELETE && int32(*(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i)))) == 0 {
			continue
		}

		pVal = Xsqlite3_column_value(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i)
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, pWriter, i+1, pVal)
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
	}
	if (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
		if (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_VTAB ||
			(*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE ||
			(*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_EXTERNAL && (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			pVal = Xsqlite3_column_value(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect, (*RbuObjIter)(unsafe.Pointer(pIter)).FnCol+1)
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, pWriter, (*RbuObjIter)(unsafe.Pointer(pIter)).FnCol+1, pVal)
		}
	}
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		Xsqlite3_step(tls, pWriter)
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = resetAndCollectError(tls, pWriter, p+64)
	}
}

func rbuStep(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pIter uintptr = p + 80
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var eType int32 = rbuStepType(tls, p, bp)

	if eType != 0 {
		if (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) && (eType == RBU_IDX_DELETE || eType == RBU_IDX_INSERT) {
			rbuBadControlError(tls, p)
		} else if eType == RBU_REPLACE {
			if (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx == uintptr(0) {
				*(*I64)(unsafe.Pointer(p + 304)) += I64((*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
				rbuStepOneOp(tls, p, RBU_DELETE)
			}
			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				rbuStepOneOp(tls, p, RBU_INSERT)
			}
		} else if eType != RBU_UPDATE {
			rbuStepOneOp(tls, p, eType)
		} else {
			var pVal uintptr
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

			*(*I64)(unsafe.Pointer(p + 304)) -= I64((*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FnIndex)
			rbuGetUpdateStmt(tls, p, pIter, *(*uintptr)(unsafe.Pointer(bp)), bp+8)
			if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
				var i int32
				for i = 0; (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && i < (*RbuObjIter)(unsafe.Pointer(pIter)).FnCol; i++ {
					var c uint8 = *(*uint8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(*(*int32)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder + uintptr(i)*4)))))
					pVal = Xsqlite3_column_value(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect, i)
					if *(*U8)(unsafe.Pointer((*RbuObjIter)(unsafe.Pointer(pIter)).FabTblPk + uintptr(i))) != 0 || int32(c) != '.' {
						(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), i+1, pVal)
					}
				}
				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK &&
					((*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_VTAB || (*RbuObjIter)(unsafe.Pointer(pIter)).FeType == RBU_PK_NONE) {
					pVal = Xsqlite3_column_value(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect, (*RbuObjIter)(unsafe.Pointer(pIter)).FnCol+1)
					(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), (*RbuObjIter)(unsafe.Pointer(pIter)).FnCol+1, pVal)
				}
				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
					(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = resetAndCollectError(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), p+64)
				}
			}
		}
	}
	return (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
}

func rbuIncrSchemaCookie(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var dbread uintptr = func() uintptr {
			if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
				return (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu
			}
			return (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain
		}()
		var iCookie int32 = 1000000

		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareAndCollectError(tls, dbread, bp+8, p+64,
			ts+37648)
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			if SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 8))) {
				iCookie = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 0)
			}
			rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 8)))
		}
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+37670, libc.VaList(bp, iCookie+1))
		}
	}
}

func rbuSaveState(tls *libc.TLS, p uintptr, eStage int32) {
	bp := tls.Alloc(176)
	defer tls.Free(176)

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK || (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_DONE {
		*(*uintptr)(unsafe.Pointer(bp + 168)) = uintptr(0)
		var pFd uintptr = func() uintptr {
			if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
				return (*Sqlite3rbu)(unsafe.Pointer(p)).FpRbuFd
			}
			return (*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd
		}()
		var rc int32

		rc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp+168, p+64,
			Xsqlite3_mprintf(tls,
				ts+37697,
				libc.VaList(bp, p+48,
					RBU_STATE_STAGE, eStage,
					RBU_STATE_TBL, (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzTbl,
					RBU_STATE_IDX, (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzIdx,
					RBU_STATE_ROW, (*Sqlite3rbu)(unsafe.Pointer(p)).FnStep,
					RBU_STATE_PROGRESS, (*Sqlite3rbu)(unsafe.Pointer(p)).FnProgress,
					RBU_STATE_CKPT, (*Sqlite3rbu)(unsafe.Pointer(p)).FiWalCksum,
					RBU_STATE_COOKIE, I64((*Rbu_file)(unsafe.Pointer(pFd)).FiCookie),
					RBU_STATE_OALSZ, (*Sqlite3rbu)(unsafe.Pointer(p)).FiOalSz,
					RBU_STATE_PHASEONESTEP, (*Sqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep,
					RBU_STATE_DATATBL, (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzDataTbl)))

		if rc == SQLITE_OK {
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 168)))
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 168)))
		}
		if rc != SQLITE_OK {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc
		}
	}
}

func rbuCopyPragma(tls *libc.TLS, p uintptr, zPragma uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareFreeAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp+24, p+64,
			Xsqlite3_mprintf(tls, ts+37855, libc.VaList(bp, zPragma)))
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 24))) {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+37870,
				libc.VaList(bp+8, zPragma, Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), 0)))
		}
		rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 24)))
	}
}

func rbuCreateTargetSchema(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+37890, uintptr(0), uintptr(0), p+64)
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64,
			ts+37915)
	}

	for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) == SQLITE_ROW {
		var zSql uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, zSql, uintptr(0), uintptr(0), p+64)
	}
	rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64,
			ts+38023)
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, bp+8, p+64,
			ts+38088)
	}

	for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) == SQLITE_ROW {
		var i int32
		for i = 0; i < 5; i++ {
			Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), i+1, Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp)), i))
		}
		Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+38132, uintptr(0), uintptr(0), p+64)
	}

	rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
	rbuFinalize(tls, p, *(*uintptr)(unsafe.Pointer(bp + 8)))
}

func Xsqlite3rbu_step(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	if p != 0 {
		switch (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage {
		case RBU_STAGE_OAL:
			{
				var pIter uintptr = p + 80

				if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) && (*Sqlite3rbu)(unsafe.Pointer(p)).FnProgress == 0 && (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					rbuCreateTargetSchema(tls, p)
					rbuCopyPragma(tls, p, ts+20793)
					rbuCopyPragma(tls, p, ts+19892)
				}

				for (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 {
					if (*RbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 {
						if libc.Bool32((*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) == 0 && (*RbuObjIter)(unsafe.Pointer(pIter)).FabIndexed != 0 {
							rbuMPrintfExec(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu,
								ts+38157, libc.VaList(bp, p+48, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl))
						}
					} else {
						rbuObjIterPrepareAll(tls, p, pIter, 0)

						if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
							var rc int32 = Xsqlite3_step(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
							if rc == SQLITE_ROW {
								(*Sqlite3rbu)(unsafe.Pointer(p)).FnProgress++
								(*Sqlite3rbu)(unsafe.Pointer(p)).FnStep++
								return rbuStep(tls, p)
							}
							(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FpSelect)
							(*Sqlite3rbu)(unsafe.Pointer(p)).FnStep = 0
						}
					}

					rbuObjIterNext(tls, p, pIter)
				}

				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					rbuSaveState(tls, p, RBU_STAGE_MOVE)
					rbuIncrSchemaCookie(tls, p)
					if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+17940, uintptr(0), uintptr(0), p+64)
					}
					if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+17940, uintptr(0), uintptr(0), p+64)
					}
					(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_MOVE
				}
				break

			}
			fallthrough

		case RBU_STAGE_MOVE:
			{
				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					rbuMoveOalFile(tls, p)
					(*Sqlite3rbu)(unsafe.Pointer(p)).FnProgress++
				}
				break

			}
			fallthrough

		case RBU_STAGE_CKPT:
			{
				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					if (*Sqlite3rbu)(unsafe.Pointer(p)).FnStep >= (*Sqlite3rbu)(unsafe.Pointer(p)).FnFrame {
						var pDb uintptr = (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal

						(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = (*struct {
							f func(*libc.TLS, uintptr, int32) int32
						})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})).f(tls, pDb, SQLITE_SYNC_NORMAL)

						if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
							(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = (*struct {
								f func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32
							})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxShmMap})).f(tls, pDb, 0, 32*1024, 0, bp+16)
							if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
								*(*U32)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)) + 24*4)) = (*Sqlite3rbu)(unsafe.Pointer(p)).FiMaxFrame
							}
						}

						if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
							(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_DONE
							(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_DONE
						}
					} else {
						var iSector U32
						for __ccgo := true; __ccgo; __ccgo = (*Sqlite3rbu)(unsafe.Pointer(p)).FnStep < (*Sqlite3rbu)(unsafe.Pointer(p)).FnFrame &&
							iSector == ((*RbuFrame)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FaFrame+uintptr((*Sqlite3rbu)(unsafe.Pointer(p)).FnStep)*8)).FiDbPage-U32(1))/U32((*Sqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector) &&
							(*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
							var pFrame uintptr = (*Sqlite3rbu)(unsafe.Pointer(p)).FaFrame + uintptr((*Sqlite3rbu)(unsafe.Pointer(p)).FnStep)*8
							iSector = ((*RbuFrame)(unsafe.Pointer(pFrame)).FiDbPage - U32(1)) / U32((*Sqlite3rbu)(unsafe.Pointer(p)).FnPagePerSector)
							rbuCheckpointFrame(tls, p, pFrame)
							(*Sqlite3rbu)(unsafe.Pointer(p)).FnStep++
						}
					}
					(*Sqlite3rbu)(unsafe.Pointer(p)).FnProgress++
				}
				break

			}
			fallthrough

		default:
			break
		}
		return (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
	} else {
		return SQLITE_NOMEM
	}
	return int32(0)
}

func rbuStrCompare(tls *libc.TLS, z1 uintptr, z2 uintptr) int32 {
	if z1 == uintptr(0) && z2 == uintptr(0) {
		return 0
	}
	if z1 == uintptr(0) || z2 == uintptr(0) {
		return 1
	}
	return libc.Bool32(Xsqlite3_stricmp(tls, z1, z2) != 0)
}

func rbuSetupOal(tls *libc.TLS, p uintptr, pState uintptr) {
	if (*RbuState)(unsafe.Pointer(pState)).FzTbl != 0 {
		var pIter uintptr = p + 80
		var rc int32 = SQLITE_OK

		for rc == SQLITE_OK && (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl != 0 && ((*RbuObjIter)(unsafe.Pointer(pIter)).FbCleanup != 0 ||
			rbuStrCompare(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FzIdx, (*RbuState)(unsafe.Pointer(pState)).FzIdx) != 0 ||
			(*RbuState)(unsafe.Pointer(pState)).FzDataTbl == uintptr(0) && rbuStrCompare(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl, (*RbuState)(unsafe.Pointer(pState)).FzTbl) != 0 ||
			(*RbuState)(unsafe.Pointer(pState)).FzDataTbl != 0 && rbuStrCompare(tls, (*RbuObjIter)(unsafe.Pointer(pIter)).FzDataTbl, (*RbuState)(unsafe.Pointer(pState)).FzDataTbl) != 0) {
			rc = rbuObjIterNext(tls, p, pIter)
		}

		if rc == SQLITE_OK && !(int32((*RbuObjIter)(unsafe.Pointer(pIter)).FzTbl) != 0) {
			rc = SQLITE_ERROR
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+38185, 0)
		}

		if rc == SQLITE_OK {
			(*Sqlite3rbu)(unsafe.Pointer(p)).FnStep = (*RbuState)(unsafe.Pointer(pState)).FnRow
			rc = rbuObjIterPrepareAll(tls, p, p+80, (*Sqlite3rbu)(unsafe.Pointer(p)).FnStep)
		}

		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	}
}

func rbuDeleteOalFile(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var zOal uintptr = rbuMPrintf(tls, p, ts+37634, libc.VaList(bp, (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget))
	if zOal != 0 {
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		Xsqlite3_file_control(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+9656, SQLITE_FCNTL_VFS_POINTER, bp+8)

		(*struct {
			f func(*libc.TLS, uintptr, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FxDelete})).f(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), zOal, 0)
		Xsqlite3_free(tls, zOal)
	}
}

func rbuCreateVfs(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(76)
	defer tls.Free(76)

	Xsqlite3_randomness(tls, int32(unsafe.Sizeof(int32(0))), bp+8)
	Xsqlite3_snprintf(tls, int32(unsafe.Sizeof([64]uint8{})), bp+12, ts+38210, libc.VaList(bp, *(*int32)(unsafe.Pointer(bp + 8))))
	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3rbu_create_vfs(tls, bp+12, uintptr(0))
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var pVfs uintptr = Xsqlite3_vfs_find(tls, bp+12)

		(*Sqlite3rbu)(unsafe.Pointer(p)).FzVfsName = (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FzName
		(*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRbu = p
	}
}

func rbuDeleteVfs(tls *libc.TLS, p uintptr) {
	if (*Sqlite3rbu)(unsafe.Pointer(p)).FzVfsName != 0 {
		Xsqlite3rbu_destroy_vfs(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzVfsName)
		(*Sqlite3rbu)(unsafe.Pointer(p)).FzVfsName = uintptr(0)
	}
}

func rbuIndexCntFunc(tls *libc.TLS, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var p uintptr = Xsqlite3_user_data(tls, pCtx)
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	var rc int32
	var db uintptr = func() uintptr {
		if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
			return (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu
		}
		return (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain
	}()

	rc = prepareFreeAndCollectError(tls, db, bp+8, bp+16,
		Xsqlite3_mprintf(tls,
			ts+38221, libc.VaList(bp, Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal))))))
	if rc != SQLITE_OK {
		Xsqlite3_result_error(tls, pCtx, *(*uintptr)(unsafe.Pointer(bp + 16)), -1)
	} else {
		var nIndex int32 = 0
		if SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 8))) {
			nIndex = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 0)
		}
		rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		if rc == SQLITE_OK {
			Xsqlite3_result_int(tls, pCtx, nIndex)
		} else {
			Xsqlite3_result_error(tls, pCtx, Xsqlite3_errmsg(tls, db), -1)
		}
	}

	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
}

func rbuInitPhaseOneSteps(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		var bExists int32 = 0

		(*Sqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = int64(-1)

		(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_create_function(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu,
			ts+38293, 1, SQLITE_UTF8, p, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr)
			}{rbuIndexCntFunc})), uintptr(0), uintptr(0))

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64,
				ts+38307)
		}
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			if SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				bExists = 1
			}
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && bExists != 0 {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = prepareAndCollectError(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, bp, p+64,
				ts+38364)
			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
					(*Sqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
				}
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
	}
}

func openRbuHandle(tls *libc.TLS, zTarget uintptr, zRbu uintptr, zState uintptr) uintptr {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var p uintptr
	var nTarget Size_t
	if zTarget != 0 {
		nTarget = libc.Xstrlen(tls, zTarget)
	} else {
		nTarget = uint64(0)
	}
	var nRbu Size_t = libc.Xstrlen(tls, zRbu)
	var nByte Size_t = uint64(unsafe.Sizeof(Sqlite3rbu{})) + nTarget + uint64(1) + nRbu + uint64(1)

	p = Xsqlite3_malloc64(tls, nByte)
	if p != 0 {
		var pState uintptr = uintptr(0)

		libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(Sqlite3rbu{})))
		Xsqlite3rbu_rename_handler(tls, p, uintptr(0), uintptr(0))
		rbuCreateVfs(tls, p)

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			var pCsr uintptr = p + 1*408
			*(*int32)(unsafe.Pointer(bp + 16)) = 0
			if zTarget != 0 {
				(*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget = pCsr
				libc.Xmemcpy(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget, zTarget, nTarget+uint64(1))
				pCsr += uintptr(nTarget + uint64(1))
			}
			(*Sqlite3rbu)(unsafe.Pointer(p)).FzRbu = pCsr
			libc.Xmemcpy(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzRbu, zRbu, nRbu+uint64(1))
			pCsr += uintptr(nRbu + uint64(1))
			if zState != 0 {
				(*Sqlite3rbu)(unsafe.Pointer(p)).FzState = rbuMPrintf(tls, p, ts+1684, libc.VaList(bp, zState))
			}

			rbuOpenDatabase(tls, p, uintptr(0), bp+16)
			if *(*int32)(unsafe.Pointer(bp + 16)) != 0 {
				rbuOpenDatabase(tls, p, uintptr(0), uintptr(0))
			}
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			pState = rbuLoadState(tls, p)

			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				if (*RbuState)(unsafe.Pointer(pState)).FeStage == 0 {
					rbuDeleteOalFile(tls, p)
					rbuInitPhaseOneSteps(tls, p)
					(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_OAL
				} else {
					(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = (*RbuState)(unsafe.Pointer(pState)).FeStage
					(*Sqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep = (*RbuState)(unsafe.Pointer(pState)).FnPhaseOneStep
				}
				(*Sqlite3rbu)(unsafe.Pointer(p)).FnProgress = int32((*RbuState)(unsafe.Pointer(pState)).FnProgress)
				(*Sqlite3rbu)(unsafe.Pointer(p)).FiOalSz = (*RbuState)(unsafe.Pointer(pState)).FiOalSz
			}
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpWalFd != 0 {
			if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_OAL {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_ERROR
				(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+38438, 0)
			} else if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_MOVE {
				(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_CKPT
				(*Sqlite3rbu)(unsafe.Pointer(p)).FnStep = 0
			}
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK &&
			((*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_OAL || (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_MOVE) &&
			(*RbuState)(unsafe.Pointer(pState)).FeStage != 0 {
			var pFd uintptr = func() uintptr {
				if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
					return (*Sqlite3rbu)(unsafe.Pointer(p)).FpRbuFd
				}
				return (*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd
			}()
			if (*Rbu_file)(unsafe.Pointer(pFd)).FiCookie != (*RbuState)(unsafe.Pointer(pState)).FiCookie {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_BUSY
				(*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg = Xsqlite3_mprintf(tls, ts+38470,
					libc.VaList(bp+8, func() uintptr {
						if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
							return ts + 38502
						}
						return ts + 38509
					}()))
			}
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_OAL {
				var db uintptr = (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+17925, uintptr(0), uintptr(0), p+64)

				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rbuObjIterFirst(tls, p, p+80)
				}

				if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).Fobjiter.FzTbl == uintptr(0) {
					(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_DONE
					(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_DONE
				} else {
					if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*RbuState)(unsafe.Pointer(pState)).FeStage == 0 && (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
						rbuCopyPragma(tls, p, ts+20507)
						rbuCopyPragma(tls, p, ts+19907)
					}

					if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, ts+38516, uintptr(0), uintptr(0), p+64)
					}

					if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						var frc int32 = Xsqlite3_file_control(tls, db, ts+9656, SQLITE_FCNTL_ZIPVFS, uintptr(0))
						if frc == SQLITE_OK {
							(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls,
								db, ts+38532, uintptr(0), uintptr(0), p+64)
						}
					}

					if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						rbuSetupOal(tls, p, pState)
					}
				}
			} else if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_MOVE {
			} else if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_CKPT {
				if !((*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0)) && rbuExclusiveCheckpoint(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain) != 0 {
					(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_DONE
					rbuLockDatabase(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain)
					(*Sqlite3rbu)(unsafe.Pointer(p)).FeStage = RBU_STAGE_CKPT
				}
				rbuSetupCheckpoint(tls, p, pState)
			} else if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_DONE {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_DONE
			} else {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT
			}
		}

		rbuFreeState(tls, pState)
	}

	return p
}

func rbuMisuseError(tls *libc.TLS) uintptr {
	var pRet uintptr
	pRet = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Sqlite3rbu{})))
	if pRet != 0 {
		libc.Xmemset(tls, pRet, 0, uint64(unsafe.Sizeof(Sqlite3rbu{})))
		(*Sqlite3rbu)(unsafe.Pointer(pRet)).Frc = SQLITE_MISUSE
	}
	return pRet
}

func Xsqlite3rbu_open(tls *libc.TLS, zTarget uintptr, zRbu uintptr, zState uintptr) uintptr {
	if zTarget == uintptr(0) || zRbu == uintptr(0) {
		return rbuMisuseError(tls)
	}
	return openRbuHandle(tls, zTarget, zRbu, zState)
}

func Xsqlite3rbu_vacuum(tls *libc.TLS, zTarget uintptr, zState uintptr) uintptr {
	if zTarget == uintptr(0) {
		return rbuMisuseError(tls)
	}
	if zState != 0 {
		var n int32 = int32(libc.Xstrlen(tls, zState))
		if n >= 7 && 0 == libc.Xmemcmp(tls, ts+38556, zState+uintptr(n-7), uint64(7)) {
			return rbuMisuseError(tls)
		}
	}

	return openRbuHandle(tls, uintptr(0), zTarget, zState)
}

func Xsqlite3rbu_db(tls *libc.TLS, pRbu uintptr, bRbu int32) uintptr {
	var db uintptr = uintptr(0)
	if pRbu != 0 {
		db = func() uintptr {
			if bRbu != 0 {
				return (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FdbRbu
			}
			return (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FdbMain
		}()
	}
	return db
}

func rbuEditErrmsg(tls *libc.TLS, p uintptr) {
	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_CONSTRAINT && (*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg != 0 {
		var i uint32
		var nErrmsg Size_t = libc.Xstrlen(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg)
		for i = uint32(0); Size_t(i) < nErrmsg-uint64(8); i++ {
			if libc.Xmemcmp(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i), ts+36581, uint64(8)) == 0 {
				var nDel int32 = 8
				for int32(*(*uint8)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg + uintptr(i+uint32(nDel))))) >= '0' && int32(*(*uint8)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg + uintptr(i+uint32(nDel))))) <= '9' {
					nDel++
				}
				libc.Xmemmove(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i), (*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg+uintptr(i+uint32(nDel)), nErrmsg+uint64(1)-Size_t(i)-Size_t(nDel))
				nErrmsg = nErrmsg - Size_t(nDel)
			}
		}
	}
}

func Xsqlite3rbu_close(tls *libc.TLS, p uintptr, pzErrmsg uintptr) int32 {
	var rc int32
	if p != 0 {
		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_OAL {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+17940, uintptr(0), uintptr(0), p+64)
		}

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_CKPT {
			var pDb uintptr = (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = (*struct {
				f func(*libc.TLS, uintptr, int32) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})).f(tls, pDb, SQLITE_SYNC_NORMAL)
		}

		rbuSaveState(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage)

		if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_OAL {
			(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+17940, uintptr(0), uintptr(0), p+64)
		}

		rbuObjIterFinalize(tls, p+80)

		if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) && (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu != 0 {
			var rc2 int32 = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+38564, uintptr(0), uintptr(0), uintptr(0))
			if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_DONE && rc2 != SQLITE_OK {
				(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc2
			}
		}

		Xsqlite3_close(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu)
		Xsqlite3_close(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain)

		rbuDeleteVfs(tls, p)
		Xsqlite3_free(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FaBuf)
		Xsqlite3_free(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FaFrame)

		rbuEditErrmsg(tls, p)
		rc = (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
		if pzErrmsg != 0 {
			*(*uintptr)(unsafe.Pointer(pzErrmsg)) = (*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg
		} else {
			Xsqlite3_free(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzErrmsg)
		}
		Xsqlite3_free(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FzState)
		Xsqlite3_free(tls, p)
	} else {
		rc = SQLITE_NOMEM
		*(*uintptr)(unsafe.Pointer(pzErrmsg)) = uintptr(0)
	}
	return rc
}

func Xsqlite3rbu_progress(tls *libc.TLS, pRbu uintptr) Sqlite3_int64 {
	return Sqlite3_int64((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnProgress)
}

func Xsqlite3rbu_bp_progress(tls *libc.TLS, p uintptr, pnOne uintptr, pnTwo uintptr) {
	var MAX_PROGRESS int32 = 10000
	switch (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage {
	case RBU_STAGE_OAL:
		if (*Sqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep > int64(0) {
			*(*int32)(unsafe.Pointer(pnOne)) = int32(I64(MAX_PROGRESS) * I64((*Sqlite3rbu)(unsafe.Pointer(p)).FnProgress) / (*Sqlite3rbu)(unsafe.Pointer(p)).FnPhaseOneStep)
		} else {
			*(*int32)(unsafe.Pointer(pnOne)) = -1
		}
		*(*int32)(unsafe.Pointer(pnTwo)) = 0
		break

	case RBU_STAGE_MOVE:
		*(*int32)(unsafe.Pointer(pnOne)) = MAX_PROGRESS
		*(*int32)(unsafe.Pointer(pnTwo)) = 0
		break

	case RBU_STAGE_CKPT:
		*(*int32)(unsafe.Pointer(pnOne)) = MAX_PROGRESS
		*(*int32)(unsafe.Pointer(pnTwo)) = int32(I64(MAX_PROGRESS) * I64((*Sqlite3rbu)(unsafe.Pointer(p)).FnStep) / I64((*Sqlite3rbu)(unsafe.Pointer(p)).FnFrame))
		break

	case RBU_STAGE_DONE:
		*(*int32)(unsafe.Pointer(pnOne)) = MAX_PROGRESS
		*(*int32)(unsafe.Pointer(pnTwo)) = MAX_PROGRESS
		break

	default:
	}
}

func Xsqlite3rbu_state(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	*(*[6]int32)(unsafe.Pointer(bp)) = [6]int32{
		0, SQLITE_RBU_STATE_OAL, SQLITE_RBU_STATE_MOVE,
		0, SQLITE_RBU_STATE_CHECKPOINT, SQLITE_RBU_STATE_DONE,
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).Frc != SQLITE_DONE {
		return SQLITE_RBU_STATE_ERROR
	} else {
		return *(*int32)(unsafe.Pointer(bp + uintptr((*Sqlite3rbu)(unsafe.Pointer(p)).FeStage)*4))
	}
	return int32(0)
}

func Xsqlite3rbu_savestate(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = (*Sqlite3rbu)(unsafe.Pointer(p)).Frc
	if rc == SQLITE_DONE {
		return SQLITE_OK
	}

	if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_OAL {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+17940, uintptr(0), uintptr(0), uintptr(0))
		}
	}

	if rc == SQLITE_OK && (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_CKPT {
		var pDb uintptr = (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(p)).FpTargetFd)).FpReal
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pDb)).FpMethods)).FxSync})).f(tls, pDb, SQLITE_SYNC_NORMAL)
	}

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	rbuSaveState(tls, p, (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage)
	rc = (*Sqlite3rbu)(unsafe.Pointer(p)).Frc

	if (*Sqlite3rbu)(unsafe.Pointer(p)).FeStage == RBU_STAGE_OAL {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, ts+17940, uintptr(0), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			var zBegin uintptr
			if (*Sqlite3rbu)(unsafe.Pointer(p)).FzTarget == uintptr(0) {
				zBegin = ts + 17925
			} else {
				zBegin = ts + 38516
			}
			rc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbRbu, zBegin, uintptr(0), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, (*Sqlite3rbu)(unsafe.Pointer(p)).FdbMain, ts+38516, uintptr(0), uintptr(0), uintptr(0))
		}
	}

	(*Sqlite3rbu)(unsafe.Pointer(p)).Frc = rc
	return rc
}

func xDefaultRename(tls *libc.TLS, pArg uintptr, zOld uintptr, zNew uintptr) int32 {
	var rc int32 = SQLITE_OK
	if libc.Xrename(tls, zOld, zNew) != 0 {
		rc = SQLITE_IOERR
	} else {
		rc = SQLITE_OK
	}
	return rc
}

func Xsqlite3rbu_rename_handler(tls *libc.TLS, pRbu uintptr, pArg uintptr, xRename uintptr) {
	if xRename != 0 {
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FxRename = xRename
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FpRenameArg = pArg
	} else {
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FxRename = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr) int32
		}{xDefaultRename}))
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FpRenameArg = uintptr(0)
	}
}

func rbuUnlockShm(tls *libc.TLS, p uintptr) {
	if (*Rbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
		var xShmLock uintptr = (*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmLock
		var i int32
		for i = 0; i < SQLITE_SHM_NLOCK; i++ {
			if U32(int32(1)<<i)&(*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpRbu)).FmLock != 0 {
				(*struct {
					f func(*libc.TLS, uintptr, int32, int32, int32) int32
				})(unsafe.Pointer(&struct{ uintptr }{xShmLock})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, i, 1, SQLITE_SHM_UNLOCK|SQLITE_SHM_EXCLUSIVE)
			}
		}
		(*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpRbu)).FmLock = U32(0)
	}
}

func rbuUpdateTempSize(tls *libc.TLS, pFd uintptr, nNew Sqlite3_int64) int32 {
	var pRbu uintptr = (*Rbu_file)(unsafe.Pointer(pFd)).FpRbu
	var nDiff I64 = nNew - (*Rbu_file)(unsafe.Pointer(pFd)).Fsz
	*(*I64)(unsafe.Pointer(pRbu + 376)) += nDiff
	(*Rbu_file)(unsafe.Pointer(pFd)).Fsz = nNew

	if (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FszTempLimit != 0 && (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FszTemp > (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FszTempLimit {
		return SQLITE_FULL
	}
	return SQLITE_OK
}

func rbuMainlistAdd(tls *libc.TLS, p uintptr) {
	var pRbuVfs uintptr = (*Rbu_file)(unsafe.Pointer(p)).FpRbuVfs
	var pIter uintptr

	Xsqlite3_mutex_enter(tls, (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).Fmutex)
	if (*Rbu_file)(unsafe.Pointer(p)).FpRbu == uintptr(0) {
		for pIter = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMain; pIter != 0; pIter = (*Rbu_file)(unsafe.Pointer(pIter)).FpMainNext {
		}
		(*Rbu_file)(unsafe.Pointer(p)).FpMainNext = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMain
		(*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMain = p
	} else {
		for pIter = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMainRbu; pIter != 0 && pIter != p; pIter = (*Rbu_file)(unsafe.Pointer(pIter)).FpMainRbuNext {
		}
		if pIter == uintptr(0) {
			(*Rbu_file)(unsafe.Pointer(p)).FpMainRbuNext = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMainRbu
			(*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMainRbu = p
		}
	}
	Xsqlite3_mutex_leave(tls, (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).Fmutex)
}

func rbuMainlistRemove(tls *libc.TLS, p uintptr) {
	var pp uintptr
	Xsqlite3_mutex_enter(tls, (*Rbu_vfs)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpRbuVfs)).Fmutex)
	for pp = (*Rbu_file)(unsafe.Pointer(p)).FpRbuVfs + 192; *(*uintptr)(unsafe.Pointer(pp)) != 0 && *(*uintptr)(unsafe.Pointer(pp)) != p; pp = *(*uintptr)(unsafe.Pointer(pp)) + 88 {
	}
	if *(*uintptr)(unsafe.Pointer(pp)) != 0 {
		*(*uintptr)(unsafe.Pointer(pp)) = (*Rbu_file)(unsafe.Pointer(p)).FpMainNext
	}
	(*Rbu_file)(unsafe.Pointer(p)).FpMainNext = uintptr(0)
	for pp = (*Rbu_file)(unsafe.Pointer(p)).FpRbuVfs + 200; *(*uintptr)(unsafe.Pointer(pp)) != 0 && *(*uintptr)(unsafe.Pointer(pp)) != p; pp = *(*uintptr)(unsafe.Pointer(pp)) + 96 {
	}
	if *(*uintptr)(unsafe.Pointer(pp)) != 0 {
		*(*uintptr)(unsafe.Pointer(pp)) = (*Rbu_file)(unsafe.Pointer(p)).FpMainRbuNext
	}
	(*Rbu_file)(unsafe.Pointer(p)).FpMainRbuNext = uintptr(0)
	Xsqlite3_mutex_leave(tls, (*Rbu_vfs)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpRbuVfs)).Fmutex)
}

func rbuFindMaindb(tls *libc.TLS, pRbuVfs uintptr, zWal uintptr, bRbu int32) uintptr {
	var pDb uintptr
	Xsqlite3_mutex_enter(tls, (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).Fmutex)
	if bRbu != 0 {
		for pDb = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMainRbu; pDb != 0 && (*Rbu_file)(unsafe.Pointer(pDb)).FzWal != zWal; pDb = (*Rbu_file)(unsafe.Pointer(pDb)).FpMainRbuNext {
		}
	} else {
		for pDb = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpMain; pDb != 0 && (*Rbu_file)(unsafe.Pointer(pDb)).FzWal != zWal; pDb = (*Rbu_file)(unsafe.Pointer(pDb)).FpMainNext {
		}
	}
	Xsqlite3_mutex_leave(tls, (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).Fmutex)
	return pDb
}

func rbuVfsClose(tls *libc.TLS, pFile uintptr) int32 {
	var p uintptr = pFile
	var rc int32
	var i int32

	for i = 0; i < (*Rbu_file)(unsafe.Pointer(p)).FnShm; i++ {
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FapShm + uintptr(i)*8)))
	}
	Xsqlite3_free(tls, (*Rbu_file)(unsafe.Pointer(p)).FapShm)
	(*Rbu_file)(unsafe.Pointer(p)).FapShm = uintptr(0)
	Xsqlite3_free(tls, (*Rbu_file)(unsafe.Pointer(p)).FzDel)

	if (*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_MAIN_DB != 0 {
		var pMeth uintptr = (*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods
		rbuMainlistRemove(tls, p)
		rbuUnlockShm(tls, p)
		if (*Sqlite3_io_methods)(unsafe.Pointer(pMeth)).FiVersion > 1 && (*Sqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmUnmap != 0 {
			(*struct {
				f func(*libc.TLS, uintptr, int32) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmUnmap})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, 0)
		}
	} else if (*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_DELETEONCLOSE != 0 && (*Rbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
		rbuUpdateTempSize(tls, p, int64(0))
	}

	rc = (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxClose})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal)
	return rc
}

func rbuGetU32(tls *libc.TLS, aBuf uintptr) U32 {
	return U32(*(*U8)(unsafe.Pointer(aBuf)))<<24 +
		U32(*(*U8)(unsafe.Pointer(aBuf + 1)))<<16 +
		U32(*(*U8)(unsafe.Pointer(aBuf + 2)))<<8 +
		U32(*(*U8)(unsafe.Pointer(aBuf + 3)))
}

func rbuPutU32(tls *libc.TLS, aBuf uintptr, iVal U32) {
	*(*U8)(unsafe.Pointer(aBuf)) = U8(iVal >> 24 & U32(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 1)) = U8(iVal >> 16 & U32(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 2)) = U8(iVal >> 8 & U32(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 3)) = U8(iVal >> 0 & U32(0xFF))
}

func rbuPutU16(tls *libc.TLS, aBuf uintptr, iVal U16) {
	*(*U8)(unsafe.Pointer(aBuf)) = U8(int32(iVal) >> 8 & 0xFF)
	*(*U8)(unsafe.Pointer(aBuf + 1)) = U8(int32(iVal) >> 0 & 0xFF)
}

func rbuVfsRead(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst Sqlite_int64) int32 {
	var p uintptr = pFile
	var pRbu uintptr = (*Rbu_file)(unsafe.Pointer(p)).FpRbu
	var rc int32

	if pRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == RBU_STAGE_CAPTURE {
		rc = rbuCaptureWalRead(tls, (*Rbu_file)(unsafe.Pointer(p)).FpRbu, iOfst, iAmt)
	} else {
		if pRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == RBU_STAGE_OAL &&
			(*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_WAL != 0 &&
			iOfst >= (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FiOalSz {
			rc = SQLITE_OK
			libc.Xmemset(tls, zBuf, 0, uint64(iAmt))
		} else {
			rc = (*struct {
				f func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxRead})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, zBuf, iAmt, iOfst)

			if pRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FzTarget == uintptr(0) &&
				rc == SQLITE_IOERR|int32(2)<<8 && iOfst == int64(0) &&
				(*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_MAIN_DB != 0 &&
				(*Sqlite3rbu)(unsafe.Pointer(pRbu)).Frc == SQLITE_OK {
				var pFd uintptr = (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FpRbuFd
				rc = (*struct {
					f func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer(pFd)).FpMethods)).FxRead})).f(tls, pFd, zBuf, iAmt, iOfst)
				if rc == SQLITE_OK {
					var aBuf uintptr = zBuf
					var iRoot U32
					if rbuGetU32(tls, aBuf+52) != 0 {
						iRoot = uint32(1)
					} else {
						iRoot = uint32(0)
					}
					rbuPutU32(tls, aBuf+52, iRoot)
					rbuPutU32(tls, aBuf+36, uint32(0))
					rbuPutU32(tls, aBuf+32, uint32(0))
					rbuPutU32(tls, aBuf+28, uint32(1))
					rbuPutU32(tls, aBuf+24, (*Rbu_file)(unsafe.Pointer((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FpRbuFd)).FiCookie+U32(1))

					if iAmt > 100 {
						libc.Xmemset(tls, aBuf+100, 0, uint64(iAmt-100))
						rbuPutU16(tls, aBuf+105, uint16(iAmt&0xFFFF))
						*(*U8)(unsafe.Pointer(aBuf + 100)) = U8(0x0D)
					}
				}
			}
		}
		if rc == SQLITE_OK && iOfst == int64(0) && (*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_MAIN_DB != 0 {
			var pBuf uintptr = zBuf
			(*Rbu_file)(unsafe.Pointer(p)).FiCookie = rbuGetU32(tls, pBuf+24)
			(*Rbu_file)(unsafe.Pointer(p)).FiWriteVer = *(*U8)(unsafe.Pointer(pBuf + 19))
		}
	}
	return rc
}

func rbuVfsWrite(tls *libc.TLS, pFile uintptr, zBuf uintptr, iAmt int32, iOfst Sqlite_int64) int32 {
	var p uintptr = pFile
	var pRbu uintptr = (*Rbu_file)(unsafe.Pointer(p)).FpRbu
	var rc int32

	if pRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == RBU_STAGE_CAPTURE {
		rc = rbuCaptureDbWrite(tls, (*Rbu_file)(unsafe.Pointer(p)).FpRbu, iOfst)
	} else {
		if pRbu != 0 {
			if (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == RBU_STAGE_OAL &&
				(*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_WAL != 0 &&
				iOfst >= (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FiOalSz {
				(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FiOalSz = Sqlite_int64(iAmt) + iOfst
			} else if (*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_DELETEONCLOSE != 0 {
				var szNew I64 = Sqlite_int64(iAmt) + iOfst
				if szNew > (*Rbu_file)(unsafe.Pointer(p)).Fsz {
					rc = rbuUpdateTempSize(tls, p, szNew)
					if rc != SQLITE_OK {
						return rc
					}
				}
			}
		}
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxWrite})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, zBuf, iAmt, iOfst)
		if rc == SQLITE_OK && iOfst == int64(0) && (*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_MAIN_DB != 0 {
			var pBuf uintptr = zBuf
			(*Rbu_file)(unsafe.Pointer(p)).FiCookie = rbuGetU32(tls, pBuf+24)
			(*Rbu_file)(unsafe.Pointer(p)).FiWriteVer = *(*U8)(unsafe.Pointer(pBuf + 19))
		}
	}
	return rc
}

func rbuVfsTruncate(tls *libc.TLS, pFile uintptr, size Sqlite_int64) int32 {
	var p uintptr = pFile
	if (*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_DELETEONCLOSE != 0 && (*Rbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
		var rc int32 = rbuUpdateTempSize(tls, p, size)
		if rc != SQLITE_OK {
			return rc
		}
	}
	return (*struct {
		f func(*libc.TLS, uintptr, Sqlite3_int64) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxTruncate})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, size)
}

func rbuVfsSync(tls *libc.TLS, pFile uintptr, flags int32) int32 {
	var p uintptr = pFile
	if (*Rbu_file)(unsafe.Pointer(p)).FpRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpRbu)).FeStage == RBU_STAGE_CAPTURE {
		if (*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_MAIN_DB != 0 {
			return SQLITE_NOTICE | int32(3)<<8
		}
		return SQLITE_OK
	}
	return (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxSync})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, flags)
}

func rbuVfsFileSize(tls *libc.TLS, pFile uintptr, pSize uintptr) int32 {
	var p uintptr = pFile
	var rc int32
	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxFileSize})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, pSize)

	if rc == SQLITE_OK && *(*Sqlite_int64)(unsafe.Pointer(pSize)) == int64(0) &&
		(*Rbu_file)(unsafe.Pointer(p)).FpRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpRbu)).FzTarget == uintptr(0) &&
		(*Rbu_file)(unsafe.Pointer(p)).FopenFlags&SQLITE_OPEN_MAIN_DB != 0 {
		*(*Sqlite_int64)(unsafe.Pointer(pSize)) = int64(1024)
	}
	return rc
}

func rbuVfsLock(tls *libc.TLS, pFile uintptr, eLock int32) int32 {
	var p uintptr = pFile
	var pRbu uintptr = (*Rbu_file)(unsafe.Pointer(p)).FpRbu
	var rc int32 = SQLITE_OK

	if eLock == SQLITE_LOCK_EXCLUSIVE &&
		((*Rbu_file)(unsafe.Pointer(p)).FbNolock != 0 || pRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage != RBU_STAGE_DONE) {
		rc = SQLITE_BUSY
	} else {
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxLock})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, eLock)
	}

	return rc
}

func rbuVfsUnlock(tls *libc.TLS, pFile uintptr, eLock int32) int32 {
	var p uintptr = pFile
	return (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxUnlock})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, eLock)
}

func rbuVfsCheckReservedLock(tls *libc.TLS, pFile uintptr, pResOut uintptr) int32 {
	var p uintptr = pFile
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxCheckReservedLock})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, pResOut)
}

func rbuVfsFileControl(tls *libc.TLS, pFile uintptr, op int32, pArg uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var p uintptr = pFile
	var xControl uintptr = (*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxFileControl
	var rc int32

	if op == SQLITE_FCNTL_RBU {
		var pRbu uintptr = pArg

		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{xControl})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, op, pArg)

		if rc == SQLITE_NOTFOUND {
			*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
			rc = (*struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{xControl})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, SQLITE_FCNTL_ZIPVFS, bp+16)
			if rc == SQLITE_OK {
				rc = SQLITE_ERROR
				(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FzErrmsg = Xsqlite3_mprintf(tls, ts+38591, 0)
			} else if rc == SQLITE_NOTFOUND {
				(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FpTargetFd = p
				(*Rbu_file)(unsafe.Pointer(p)).FpRbu = pRbu
				rbuMainlistAdd(tls, p)
				if (*Rbu_file)(unsafe.Pointer(p)).FpWalFd != 0 {
					(*Rbu_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpWalFd)).FpRbu = pRbu
				}
				rc = SQLITE_OK
			}
		}
		return rc
	} else if op == SQLITE_FCNTL_RBUCNT {
		var pRbu uintptr = pArg
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FnRbu++
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FpRbuFd = p
		(*Rbu_file)(unsafe.Pointer(p)).FbNolock = U8(1)
	}

	rc = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{xControl})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, op, pArg)
	if rc == SQLITE_OK && op == SQLITE_FCNTL_VFSNAME {
		var pRbuVfs uintptr = (*Rbu_file)(unsafe.Pointer(p)).FpRbuVfs
		var zIn uintptr = *(*uintptr)(unsafe.Pointer(pArg))
		var zOut uintptr = Xsqlite3_mprintf(tls, ts+38614, libc.VaList(bp, (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).Fbase.FzName, zIn))
		*(*uintptr)(unsafe.Pointer(pArg)) = zOut
		if zOut == uintptr(0) {
			rc = SQLITE_NOMEM
		}
	}

	return rc
}

func rbuVfsSectorSize(tls *libc.TLS, pFile uintptr) int32 {
	var p uintptr = pFile
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxSectorSize})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal)
}

func rbuVfsDeviceCharacteristics(tls *libc.TLS, pFile uintptr) int32 {
	var p uintptr = pFile
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxDeviceCharacteristics})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal)
}

func rbuVfsShmLock(tls *libc.TLS, pFile uintptr, ofst int32, n int32, flags int32) int32 {
	var p uintptr = pFile
	var pRbu uintptr = (*Rbu_file)(unsafe.Pointer(p)).FpRbu
	var rc int32 = SQLITE_OK

	if pRbu != 0 && ((*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == RBU_STAGE_OAL ||
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == RBU_STAGE_MOVE ||
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == RBU_STAGE_DONE) {
		if ofst == WAL_LOCK_CKPT && n == 1 {
			rc = SQLITE_BUSY
		}
	} else {
		var bCapture int32 = 0
		if pRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FeStage == RBU_STAGE_CAPTURE {
			bCapture = 1
		}
		if bCapture == 0 || 0 == flags&SQLITE_SHM_UNLOCK {
			rc = (*struct {
				f func(*libc.TLS, uintptr, int32, int32, int32) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmLock})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, ofst, n, flags)
			if bCapture != 0 && rc == SQLITE_OK {
				*(*U32)(unsafe.Pointer(pRbu + 332)) |= U32((int32(1)<<n - 1) << ofst)
			}
		}
	}

	return rc
}

func rbuVfsShmMap(tls *libc.TLS, pFile uintptr, iRegion int32, szRegion int32, isWrite int32, pp uintptr) int32 {
	var p uintptr = pFile
	var rc int32 = SQLITE_OK
	var eStage int32 = func() int32 {
		if (*Rbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
			return (*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpRbu)).FeStage
		}
		return 0
	}()

	if eStage == RBU_STAGE_OAL {
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(iRegion+1) * uint64(unsafe.Sizeof(uintptr(0))))
		var apNew uintptr = Xsqlite3_realloc64(tls, (*Rbu_file)(unsafe.Pointer(p)).FapShm, uint64(nByte))

		if apNew == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			libc.Xmemset(tls, apNew+uintptr((*Rbu_file)(unsafe.Pointer(p)).FnShm)*8, 0, uint64(unsafe.Sizeof(uintptr(0)))*uint64(1+iRegion-(*Rbu_file)(unsafe.Pointer(p)).FnShm))
			(*Rbu_file)(unsafe.Pointer(p)).FapShm = apNew
			(*Rbu_file)(unsafe.Pointer(p)).FnShm = iRegion + 1
		}

		if rc == SQLITE_OK {
			var pNew uintptr = Xsqlite3_malloc64(tls, uint64(szRegion))
			if pNew == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				libc.Xmemset(tls, pNew, 0, uint64(szRegion))
				*(*uintptr)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FapShm + uintptr(iRegion)*8)) = pNew
			}
		}

		if rc == SQLITE_OK {
			*(*uintptr)(unsafe.Pointer(pp)) = *(*uintptr)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FapShm + uintptr(iRegion)*8))
		} else {
			*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
		}
	} else {
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmMap})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, iRegion, szRegion, isWrite, pp)
	}

	return rc
}

func rbuVfsShmBarrier(tls *libc.TLS, pFile uintptr) {
	var p uintptr = pFile
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmBarrier})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal)
}

func rbuVfsShmUnmap(tls *libc.TLS, pFile uintptr, delFlag int32) int32 {
	var p uintptr = pFile
	var rc int32 = SQLITE_OK
	var eStage int32 = func() int32 {
		if (*Rbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
			return (*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpRbu)).FeStage
		}
		return 0
	}()

	if eStage == RBU_STAGE_OAL || eStage == RBU_STAGE_MOVE {
	} else {
		rbuUnlockShm(tls, p)
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*sqlite3_io_methods)(unsafe.Pointer((*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxShmUnmap})).f(tls, (*Rbu_file)(unsafe.Pointer(p)).FpReal, delFlag)
	}
	return rc
}

func rbuVfsOpen(tls *libc.TLS, pVfs uintptr, zName uintptr, pFile uintptr, flags int32, pOutFlags uintptr) int32 {
	var pRbuVfs uintptr = pVfs
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpRealVfs
	var pFd uintptr = pFile
	var rc int32 = SQLITE_OK
	var zOpen uintptr = zName
	var oflags int32 = flags

	libc.Xmemset(tls, pFd, 0, uint64(unsafe.Sizeof(Rbu_file{})))
	(*Rbu_file)(unsafe.Pointer(pFd)).FpReal = pFd + 1*104
	(*Rbu_file)(unsafe.Pointer(pFd)).FpRbuVfs = pRbuVfs
	(*Rbu_file)(unsafe.Pointer(pFd)).FopenFlags = flags
	if zName != 0 {
		if flags&SQLITE_OPEN_MAIN_DB != 0 {
			(*Rbu_file)(unsafe.Pointer(pFd)).FzWal = Xsqlite3_filename_wal(tls, zName)
		} else if flags&SQLITE_OPEN_WAL != 0 {
			var pDb uintptr = rbuFindMaindb(tls, pRbuVfs, zName, 0)
			if pDb != 0 {
				if (*Rbu_file)(unsafe.Pointer(pDb)).FpRbu != 0 && (*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(pDb)).FpRbu)).FeStage == RBU_STAGE_OAL {
					var nOpen Size_t
					if (*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(pDb)).FpRbu)).FzTarget == uintptr(0) {
						zOpen = Xsqlite3_db_filename(tls, (*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(pDb)).FpRbu)).FdbRbu, ts+9656)
						zOpen = Xsqlite3_filename_wal(tls, zOpen)
					}
					nOpen = libc.Xstrlen(tls, zOpen)
					*(*uint8)(unsafe.Pointer(zOpen + uintptr(nOpen-uint64(3)))) = uint8('o')
					(*Rbu_file)(unsafe.Pointer(pFd)).FpRbu = (*Rbu_file)(unsafe.Pointer(pDb)).FpRbu
				}
				(*Rbu_file)(unsafe.Pointer(pDb)).FpWalFd = pFd
			}
		}
	} else {
		(*Rbu_file)(unsafe.Pointer(pFd)).FpRbu = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpRbu
	}

	if oflags&SQLITE_OPEN_MAIN_DB != 0 &&
		Xsqlite3_uri_boolean(tls, zName, ts+38625, 0) != 0 {
		oflags = SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE
		zOpen = uintptr(0)
	}

	if rc == SQLITE_OK {
		rc = (*struct {
			f func(*libc.TLS, uintptr, Sqlite3_filename, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxOpen})).f(tls, pRealVfs, zOpen, (*Rbu_file)(unsafe.Pointer(pFd)).FpReal, oflags, pOutFlags)
	}
	if (*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(pFd)).FpReal)).FpMethods != 0 {
		var pMeth uintptr = (*Sqlite3_file)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(pFd)).FpReal)).FpMethods

		if (*Sqlite3_io_methods)(unsafe.Pointer(pMeth)).FiVersion < 2 || (*Sqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmLock == uintptr(0) {
			(*Sqlite3_file)(unsafe.Pointer(pFile)).FpMethods = uintptr(unsafe.Pointer(&rbuvfs_io_methods1))
		} else {
			(*Sqlite3_file)(unsafe.Pointer(pFile)).FpMethods = uintptr(unsafe.Pointer(&rbuvfs_io_methods))
		}
		if flags&SQLITE_OPEN_MAIN_DB != 0 {
			rbuMainlistAdd(tls, pFd)
		}
	} else {
		Xsqlite3_free(tls, (*Rbu_file)(unsafe.Pointer(pFd)).FzDel)
	}

	return rc
}

var rbuvfs_io_methods = Sqlite3_io_methods{
	FiVersion:               2,
	FxClose:                 0,
	FxRead:                  0,
	FxWrite:                 0,
	FxTruncate:              0,
	FxSync:                  0,
	FxFileSize:              0,
	FxLock:                  0,
	FxUnlock:                0,
	FxCheckReservedLock:     0,
	FxFileControl:           0,
	FxSectorSize:            0,
	FxDeviceCharacteristics: 0,
	FxShmMap:                0,
	FxShmLock:               0,
	FxShmBarrier:            0,
	FxShmUnmap:              0,
}
var rbuvfs_io_methods1 = Sqlite3_io_methods{
	FiVersion:               1,
	FxClose:                 0,
	FxRead:                  0,
	FxWrite:                 0,
	FxTruncate:              0,
	FxSync:                  0,
	FxFileSize:              0,
	FxLock:                  0,
	FxUnlock:                0,
	FxCheckReservedLock:     0,
	FxFileControl:           0,
	FxSectorSize:            0,
	FxDeviceCharacteristics: 0,
}

func rbuVfsDelete(tls *libc.TLS, pVfs uintptr, zPath uintptr, dirSync int32) int32 {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDelete})).f(tls, pRealVfs, zPath, dirSync)
}

func rbuVfsAccess(tls *libc.TLS, pVfs uintptr, zPath uintptr, flags int32, pResOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pRbuVfs uintptr = pVfs
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pRbuVfs)).FpRealVfs
	var rc int32

	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxAccess})).f(tls, pRealVfs, zPath, flags, pResOut)

	if rc == SQLITE_OK && flags == SQLITE_ACCESS_EXISTS {
		var pDb uintptr = rbuFindMaindb(tls, pRbuVfs, zPath, 1)
		if pDb != 0 && (*Sqlite3rbu)(unsafe.Pointer((*Rbu_file)(unsafe.Pointer(pDb)).FpRbu)).FeStage == RBU_STAGE_OAL {
			if *(*int32)(unsafe.Pointer(pResOut)) != 0 {
				rc = SQLITE_CANTOPEN
			} else {
				*(*Sqlite3_int64)(unsafe.Pointer(bp)) = int64(0)
				rc = rbuVfsFileSize(tls, pDb, bp)
				*(*int32)(unsafe.Pointer(pResOut)) = libc.Bool32(*(*Sqlite3_int64)(unsafe.Pointer(bp)) > int64(0))
			}
		}
	}

	return rc
}

func rbuVfsFullPathname(tls *libc.TLS, pVfs uintptr, zPath uintptr, nOut int32, zOut uintptr) int32 {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxFullPathname})).f(tls, pRealVfs, zPath, nOut, zOut)
}

func rbuVfsDlOpen(tls *libc.TLS, pVfs uintptr, zPath uintptr) uintptr {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDlOpen})).f(tls, pRealVfs, zPath)
}

func rbuVfsDlError(tls *libc.TLS, pVfs uintptr, nByte int32, zErrMsg uintptr) {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDlError})).f(tls, pRealVfs, nByte, zErrMsg)
}

func rbuVfsDlSym(tls *libc.TLS, pVfs uintptr, pArg uintptr, zSym uintptr) uintptr {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDlSym})).f(tls, pRealVfs, pArg, zSym)
}

func rbuVfsDlClose(tls *libc.TLS, pVfs uintptr, pHandle uintptr) {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	(*struct {
		f func(*libc.TLS, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxDlClose})).f(tls, pRealVfs, pHandle)
}

func rbuVfsRandomness(tls *libc.TLS, pVfs uintptr, nByte int32, zBufOut uintptr) int32 {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxRandomness})).f(tls, pRealVfs, nByte, zBufOut)
}

func rbuVfsSleep(tls *libc.TLS, pVfs uintptr, nMicro int32) int32 {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*struct {
		f func(*libc.TLS, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxSleep})).f(tls, pRealVfs, nMicro)
}

func rbuVfsCurrentTime(tls *libc.TLS, pVfs uintptr, pTimeOut uintptr) int32 {
	var pRealVfs uintptr = (*Rbu_vfs)(unsafe.Pointer(pVfs)).FpRealVfs
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_vfs)(unsafe.Pointer(pRealVfs)).FxCurrentTime})).f(tls, pRealVfs, pTimeOut)
}

func rbuVfsGetLastError(tls *libc.TLS, pVfs uintptr, a int32, b uintptr) int32 {
	return 0
}

func Xsqlite3rbu_destroy_vfs(tls *libc.TLS, zName uintptr) {
	var pVfs uintptr = Xsqlite3_vfs_find(tls, zName)
	if pVfs != 0 && (*Sqlite3_vfs)(unsafe.Pointer(pVfs)).FxOpen == *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32
	}{rbuVfsOpen})) {
		Xsqlite3_mutex_free(tls, (*Rbu_vfs)(unsafe.Pointer(pVfs)).Fmutex)
		Xsqlite3_vfs_unregister(tls, pVfs)
		Xsqlite3_free(tls, pVfs)
	}
}

func Xsqlite3rbu_create_vfs(tls *libc.TLS, zName uintptr, zParent uintptr) int32 {
	var pNew uintptr = uintptr(0)
	var rc int32 = SQLITE_OK
	var nName Size_t
	var nByte Size_t

	nName = libc.Xstrlen(tls, zName)
	nByte = uint64(unsafe.Sizeof(Rbu_vfs{})) + nName + uint64(1)
	pNew = Xsqlite3_malloc64(tls, nByte)
	if pNew == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		var pParent uintptr
		libc.Xmemset(tls, pNew, 0, nByte)
		pParent = Xsqlite3_vfs_find(tls, zParent)
		if pParent == uintptr(0) {
			rc = SQLITE_NOTFOUND
		} else {
			var zSpace uintptr
			libc.Xmemcpy(tls, pNew, uintptr(unsafe.Pointer(&vfs_template)), uint64(unsafe.Sizeof(Sqlite3_vfs{})))
			(*Rbu_vfs)(unsafe.Pointer(pNew)).Fbase.FmxPathname = (*Sqlite3_vfs)(unsafe.Pointer(pParent)).FmxPathname
			(*Rbu_vfs)(unsafe.Pointer(pNew)).Fbase.FszOsFile = int32(uint64(unsafe.Sizeof(Rbu_file{})) + uint64((*Sqlite3_vfs)(unsafe.Pointer(pParent)).FszOsFile))
			(*Rbu_vfs)(unsafe.Pointer(pNew)).FpRealVfs = pParent
			(*Rbu_vfs)(unsafe.Pointer(pNew)).Fbase.FzName = libc.AssignUintptr(&zSpace, pNew+1*208)
			libc.Xmemcpy(tls, zSpace, zName, nName)

			(*Rbu_vfs)(unsafe.Pointer(pNew)).Fmutex = Xsqlite3_mutex_alloc(tls, SQLITE_MUTEX_RECURSIVE)
			if (*Rbu_vfs)(unsafe.Pointer(pNew)).Fmutex == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				rc = Xsqlite3_vfs_register(tls, pNew, 0)
			}
		}

		if rc != SQLITE_OK {
			Xsqlite3_mutex_free(tls, (*Rbu_vfs)(unsafe.Pointer(pNew)).Fmutex)
			Xsqlite3_free(tls, pNew)
		}
	}

	return rc
}

var vfs_template = Sqlite3_vfs{
	FiVersion:      1,
	FxOpen:         0,
	FxDelete:       0,
	FxAccess:       0,
	FxFullPathname: 0,
	FxDlOpen:       0,
	FxDlError:      0,
	FxDlSym:        0,
	FxDlClose:      0,
	FxRandomness:   0,
	FxSleep:        0,
	FxCurrentTime:  0,
	FxGetLastError: 0,
}

func Xsqlite3rbu_temp_size_limit(tls *libc.TLS, pRbu uintptr, n Sqlite3_int64) Sqlite3_int64 {
	if n >= int64(0) {
		(*Sqlite3rbu)(unsafe.Pointer(pRbu)).FszTempLimit = n
	}
	return (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FszTempLimit
}

func Xsqlite3rbu_temp_size(tls *libc.TLS, pRbu uintptr) Sqlite3_int64 {
	return (*Sqlite3rbu)(unsafe.Pointer(pRbu)).FszTemp
}

var zDbstatSchema = *(*[258]uint8)(unsafe.Pointer(ts + 38636))

type StatTable1 = struct {
	Fbase        Sqlite3_vtab
	Fdb          uintptr
	FiDb         int32
	F__ccgo_pad1 [4]byte
}

type StatTable = StatTable1
type StatCursor1 = struct {
	Fbase        Sqlite3_vtab_cursor
	FpStmt       uintptr
	FisEof       U8
	FisAgg       U8
	F__ccgo_pad1 [2]byte
	FiDb         int32
	FaPage       [32]StatPage
	FiPage       int32
	FiPageno     U32
	FzName       uintptr
	FzPath       uintptr
	FzPagetype   uintptr
	FnPage       int32
	FnCell       int32
	FnMxPayload  int32
	F__ccgo_pad2 [4]byte
	FnUnused     I64
	FnPayload    I64
	FiOffset     I64
	FszPage      I64
}

type StatCursor = StatCursor1
type StatPage1 = struct {
	FiPgno         U32
	F__ccgo_pad1   [4]byte
	FaPg           uintptr
	FiCell         int32
	F__ccgo_pad2   [4]byte
	FzPath         uintptr
	Fflags         U8
	F__ccgo_pad3   [3]byte
	FnCell         int32
	FnUnused       int32
	F__ccgo_pad4   [4]byte
	FaCell         uintptr
	FiRightChildPg U32
	FnMxPayload    int32
}

type StatPage = StatPage1
type StatCell1 = struct {
	FnLocal      int32
	FiChildPg    U32
	FnOvfl       int32
	F__ccgo_pad1 [4]byte
	FaOvfl       uintptr
	FnLastOvfl   int32
	FiOvfl       int32
}

type StatCell = StatCell1

func statConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pTab uintptr = uintptr(0)
	var rc int32 = SQLITE_OK
	var iDb int32
	_ = pAux

	if argc >= 4 {
		Xsqlite3TokenInit(tls, bp+8, *(*uintptr)(unsafe.Pointer(argv + 3*8)))
		iDb = Xsqlite3FindDb(tls, db, bp+8)
		if iDb < 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+15286, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(argv + 3*8))))
			return SQLITE_ERROR
		}
	} else {
		iDb = 0
	}
	Xsqlite3_vtab_config(tls, db, SQLITE_VTAB_DIRECTONLY, 0)
	rc = Xsqlite3_declare_vtab(tls, db, uintptr(unsafe.Pointer(&zDbstatSchema)))
	if rc == SQLITE_OK {
		pTab = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(StatTable{})))
		if pTab == uintptr(0) {
			rc = SQLITE_NOMEM
		}
	}

	if rc == SQLITE_OK {
		libc.Xmemset(tls, pTab, 0, uint64(unsafe.Sizeof(StatTable{})))
		(*StatTable)(unsafe.Pointer(pTab)).Fdb = db
		(*StatTable)(unsafe.Pointer(pTab)).FiDb = iDb
	}

	*(*uintptr)(unsafe.Pointer(ppVtab)) = pTab
	return rc
}

func statDisconnect(tls *libc.TLS, pVtab uintptr) int32 {
	Xsqlite3_free(tls, pVtab)
	return SQLITE_OK
}

func statBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) int32 {
	var i int32
	var iSchema int32 = -1
	var iName int32 = -1
	var iAgg int32 = -1
	_ = tab

	for i = 0; i < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint; i++ {
		if int32((*sqlite3_index_constraint)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint+uintptr(i)*12)).Fop) != SQLITE_INDEX_CONSTRAINT_EQ {
			continue
		}
		if int32((*sqlite3_index_constraint)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint+uintptr(i)*12)).Fusable) == 0 {
			return SQLITE_CONSTRAINT
		}
		switch (*sqlite3_index_constraint)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12)).FiColumn {
		case 0:
			{
				iName = i
				break

			}
		case 10:
			{
				iSchema = i
				break

			}
		case 11:
			{
				iAgg = i
				break

			}
		}
	}
	i = 0
	if iSchema >= 0 {
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iSchema)*8)).FargvIndex = libc.PreIncInt32(&i, 1)
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iSchema)*8)).Fomit = uint8(1)
		*(*int32)(unsafe.Pointer(pIdxInfo + 40)) |= 0x01
	}
	if iName >= 0 {
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iName)*8)).FargvIndex = libc.PreIncInt32(&i, 1)
		*(*int32)(unsafe.Pointer(pIdxInfo + 40)) |= 0x02
	}
	if iAgg >= 0 {
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iAgg)*8)).FargvIndex = libc.PreIncInt32(&i, 1)
		*(*int32)(unsafe.Pointer(pIdxInfo + 40)) |= 0x04
	}
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 1.0

	if (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy == 1 &&
		(*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy)).FiColumn == 0 &&
		int32((*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy)).Fdesc) == 0 || (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy == 2 &&
		(*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy)).FiColumn == 0 &&
		int32((*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy)).Fdesc) == 0 &&
		(*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy+1*8)).FiColumn == 1 &&
		int32((*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy+1*8)).Fdesc) == 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 1
		*(*int32)(unsafe.Pointer(pIdxInfo + 40)) |= 0x08
	}

	return SQLITE_OK
}

func statOpen(tls *libc.TLS, pVTab uintptr, ppCursor uintptr) int32 {
	var pTab uintptr = pVTab
	var pCsr uintptr

	pCsr = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(StatCursor{})))
	if pCsr == uintptr(0) {
		return SQLITE_NOMEM
	} else {
		libc.Xmemset(tls, pCsr, 0, uint64(unsafe.Sizeof(StatCursor{})))
		(*StatCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVTab
		(*StatCursor)(unsafe.Pointer(pCsr)).FiDb = (*StatTable)(unsafe.Pointer(pTab)).FiDb
	}

	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCsr
	return SQLITE_OK
}

func statClearCells(tls *libc.TLS, p uintptr) {
	var i int32
	if (*StatPage)(unsafe.Pointer(p)).FaCell != 0 {
		for i = 0; i < (*StatPage)(unsafe.Pointer(p)).FnCell; i++ {
			Xsqlite3_free(tls, (*StatCell)(unsafe.Pointer((*StatPage)(unsafe.Pointer(p)).FaCell+uintptr(i)*32)).FaOvfl)
		}
		Xsqlite3_free(tls, (*StatPage)(unsafe.Pointer(p)).FaCell)
	}
	(*StatPage)(unsafe.Pointer(p)).FnCell = 0
	(*StatPage)(unsafe.Pointer(p)).FaCell = uintptr(0)
}

func statClearPage(tls *libc.TLS, p uintptr) {
	var aPg uintptr = (*StatPage)(unsafe.Pointer(p)).FaPg
	statClearCells(tls, p)
	Xsqlite3_free(tls, (*StatPage)(unsafe.Pointer(p)).FzPath)
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(StatPage{})))
	(*StatPage)(unsafe.Pointer(p)).FaPg = aPg
}

func statResetCsr(tls *libc.TLS, pCsr uintptr) {
	var i int32

	for i = 0; i < int32(uint64(unsafe.Sizeof([32]StatPage{}))/uint64(unsafe.Sizeof(StatPage{}))); i++ {
		statClearPage(tls, pCsr+24+uintptr(i)*64)
		Xsqlite3_free(tls, (*StatPage)(unsafe.Pointer(pCsr+24+uintptr(i)*64)).FaPg)
		(*StatPage)(unsafe.Pointer(pCsr + 24 + uintptr(i)*64)).FaPg = uintptr(0)
	}
	Xsqlite3_reset(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt)
	(*StatCursor)(unsafe.Pointer(pCsr)).FiPage = 0
	Xsqlite3_free(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FzPath)
	(*StatCursor)(unsafe.Pointer(pCsr)).FzPath = uintptr(0)
	(*StatCursor)(unsafe.Pointer(pCsr)).FisEof = U8(0)
}

func statResetCounts(tls *libc.TLS, pCsr uintptr) {
	(*StatCursor)(unsafe.Pointer(pCsr)).FnCell = 0
	(*StatCursor)(unsafe.Pointer(pCsr)).FnMxPayload = 0
	(*StatCursor)(unsafe.Pointer(pCsr)).FnUnused = int64(0)
	(*StatCursor)(unsafe.Pointer(pCsr)).FnPayload = int64(0)
	(*StatCursor)(unsafe.Pointer(pCsr)).FszPage = int64(0)
	(*StatCursor)(unsafe.Pointer(pCsr)).FnPage = 0
}

func statClose(tls *libc.TLS, pCursor uintptr) int32 {
	var pCsr uintptr = pCursor
	statResetCsr(tls, pCsr)
	Xsqlite3_finalize(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt)
	Xsqlite3_free(tls, pCsr)
	return SQLITE_OK
}

func getLocalPayload(tls *libc.TLS, nUsable int32, flags U8, nTotal int32) int32 {
	var nLocal int32
	var nMinLocal int32
	var nMaxLocal int32

	if int32(flags) == 0x0D {
		nMinLocal = (nUsable-12)*32/255 - 23
		nMaxLocal = nUsable - 35
	} else {
		nMinLocal = (nUsable-12)*32/255 - 23
		nMaxLocal = (nUsable-12)*64/255 - 23
	}

	nLocal = nMinLocal + (nTotal-nMinLocal)%(nUsable-4)
	if nLocal > nMaxLocal {
		nLocal = nMinLocal
	}
	return nLocal
}

func statDecodePage(tls *libc.TLS, pBt uintptr, p uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var nUnused int32
	var iOff int32
	var nHdr int32
	var isLeaf int32
	var szPage int32
	var aData uintptr
	var aHdr uintptr
	var iNext int32

	var rc int32
	var iPrev U32

	var j int32
	var nOvfl int32

	var nLocal int32
	var pCell uintptr
	var i int32
	var nUsable int32
	aData = (*StatPage)(unsafe.Pointer(p)).FaPg
	aHdr = aData + uintptr(func() int32 {
		if (*StatPage)(unsafe.Pointer(p)).FiPgno == U32(1) {
			return 100
		}
		return 0
	}())

	(*StatPage)(unsafe.Pointer(p)).Fflags = *(*U8)(unsafe.Pointer(aHdr))
	if !(int32((*StatPage)(unsafe.Pointer(p)).Fflags) == 0x0A || int32((*StatPage)(unsafe.Pointer(p)).Fflags) == 0x0D) {
		goto __1
	}
	isLeaf = 1
	nHdr = 8
	goto __2
__1:
	if !(int32((*StatPage)(unsafe.Pointer(p)).Fflags) == 0x05 || int32((*StatPage)(unsafe.Pointer(p)).Fflags) == 0x02) {
		goto __3
	}
	isLeaf = 0
	nHdr = 12
	goto __4
__3:
	goto statPageIsCorrupt
__4:
	;
__2:
	;
	if !((*StatPage)(unsafe.Pointer(p)).FiPgno == U32(1)) {
		goto __5
	}
	nHdr = nHdr + 100
__5:
	;
	(*StatPage)(unsafe.Pointer(p)).FnCell = int32(*(*U8)(unsafe.Pointer(aHdr + 3)))<<8 | int32(*(*U8)(unsafe.Pointer(aHdr + 3 + 1)))
	(*StatPage)(unsafe.Pointer(p)).FnMxPayload = 0
	szPage = Xsqlite3BtreeGetPageSize(tls, pBt)

	nUnused = int32(*(*U8)(unsafe.Pointer(aHdr + 5)))<<8 | int32(*(*U8)(unsafe.Pointer(aHdr + 5 + 1))) - nHdr - 2*(*StatPage)(unsafe.Pointer(p)).FnCell
	nUnused = nUnused + int32(*(*U8)(unsafe.Pointer(aHdr + 7)))
	iOff = int32(*(*U8)(unsafe.Pointer(aHdr + 1)))<<8 | int32(*(*U8)(unsafe.Pointer(aHdr + 1 + 1)))
__6:
	if !(iOff != 0) {
		goto __7
	}
	if !(iOff >= szPage) {
		goto __8
	}
	goto statPageIsCorrupt
__8:
	;
	nUnused = nUnused + (int32(*(*U8)(unsafe.Pointer(aData + uintptr(iOff+2))))<<8 | int32(*(*U8)(unsafe.Pointer(aData + uintptr(iOff+2) + 1))))
	iNext = int32(*(*U8)(unsafe.Pointer(aData + uintptr(iOff))))<<8 | int32(*(*U8)(unsafe.Pointer(aData + uintptr(iOff) + 1)))
	if !(iNext < iOff+4 && iNext > 0) {
		goto __9
	}
	goto statPageIsCorrupt
__9:
	;
	iOff = iNext
	goto __6
__7:
	;
	(*StatPage)(unsafe.Pointer(p)).FnUnused = nUnused
	(*StatPage)(unsafe.Pointer(p)).FiRightChildPg = func() uint32 {
		if isLeaf != 0 {
			return uint32(0)
		}
		return Xsqlite3Get4byte(tls, aHdr+8)
	}()

	if !((*StatPage)(unsafe.Pointer(p)).FnCell != 0) {
		goto __10
	}

	Xsqlite3BtreeEnter(tls, pBt)
	nUsable = szPage - Xsqlite3BtreeGetReserveNoMutex(tls, pBt)
	Xsqlite3BtreeLeave(tls, pBt)
	(*StatPage)(unsafe.Pointer(p)).FaCell = Xsqlite3_malloc64(tls, uint64((*StatPage)(unsafe.Pointer(p)).FnCell+1)*uint64(unsafe.Sizeof(StatCell{})))
	if !((*StatPage)(unsafe.Pointer(p)).FaCell == uintptr(0)) {
		goto __11
	}
	return SQLITE_NOMEM
__11:
	;
	libc.Xmemset(tls, (*StatPage)(unsafe.Pointer(p)).FaCell, 0, uint64((*StatPage)(unsafe.Pointer(p)).FnCell+1)*uint64(unsafe.Sizeof(StatCell{})))

	i = 0
__12:
	if !(i < (*StatPage)(unsafe.Pointer(p)).FnCell) {
		goto __14
	}
	pCell = (*StatPage)(unsafe.Pointer(p)).FaCell + uintptr(i)*32

	iOff = int32(*(*U8)(unsafe.Pointer(aData + uintptr(nHdr+i*2))))<<8 | int32(*(*U8)(unsafe.Pointer(aData + uintptr(nHdr+i*2) + 1)))
	if !(iOff < nHdr || iOff >= szPage) {
		goto __15
	}
	goto statPageIsCorrupt
__15:
	;
	if !!(isLeaf != 0) {
		goto __16
	}
	(*StatCell)(unsafe.Pointer(pCell)).FiChildPg = Xsqlite3Get4byte(tls, aData+uintptr(iOff))
	iOff = iOff + 4
__16:
	;
	if !(int32((*StatPage)(unsafe.Pointer(p)).Fflags) == 0x05) {
		goto __17
	}

	goto __18
__17:
	iOff = iOff + int32(func() uint8 {
		if int32(*(*U8)(unsafe.Pointer(aData + uintptr(iOff)))) < int32(U8(0x80)) {
			return uint8(func() int32 {
				*(*U32)(unsafe.Pointer(bp)) = U32(*(*U8)(unsafe.Pointer(aData + uintptr(iOff))))
				return 1
			}())
		}
		return Xsqlite3GetVarint32(tls, aData+uintptr(iOff), bp)
	}())
	if !(int32((*StatPage)(unsafe.Pointer(p)).Fflags) == 0x0D) {
		goto __19
	}
	iOff = iOff + int32(Xsqlite3GetVarint(tls, aData+uintptr(iOff), bp+8))
__19:
	;
	if !(*(*U32)(unsafe.Pointer(bp)) > U32((*StatPage)(unsafe.Pointer(p)).FnMxPayload)) {
		goto __20
	}
	(*StatPage)(unsafe.Pointer(p)).FnMxPayload = int32(*(*U32)(unsafe.Pointer(bp)))
__20:
	;
	nLocal = getLocalPayload(tls, nUsable, (*StatPage)(unsafe.Pointer(p)).Fflags, int32(*(*U32)(unsafe.Pointer(bp))))
	if !(nLocal < 0) {
		goto __21
	}
	goto statPageIsCorrupt
__21:
	;
	(*StatCell)(unsafe.Pointer(pCell)).FnLocal = nLocal

	if !(*(*U32)(unsafe.Pointer(bp)) > U32(nLocal)) {
		goto __22
	}
	nOvfl = int32((*(*U32)(unsafe.Pointer(bp)) - U32(nLocal) + U32(nUsable) - U32(4) - U32(1)) / U32(nUsable-4))
	if !(iOff+nLocal+4 > nUsable || *(*U32)(unsafe.Pointer(bp)) > U32(0x7fffffff)) {
		goto __23
	}
	goto statPageIsCorrupt
__23:
	;
	(*StatCell)(unsafe.Pointer(pCell)).FnLastOvfl = int32(*(*U32)(unsafe.Pointer(bp)) - U32(nLocal) - U32((nOvfl-1)*(nUsable-4)))
	(*StatCell)(unsafe.Pointer(pCell)).FnOvfl = nOvfl
	(*StatCell)(unsafe.Pointer(pCell)).FaOvfl = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(U32(0)))*uint64(nOvfl))
	if !((*StatCell)(unsafe.Pointer(pCell)).FaOvfl == uintptr(0)) {
		goto __24
	}
	return SQLITE_NOMEM
__24:
	;
	*(*U32)(unsafe.Pointer((*StatCell)(unsafe.Pointer(pCell)).FaOvfl)) = Xsqlite3Get4byte(tls, aData+uintptr(iOff+nLocal))
	j = 1
__25:
	if !(j < nOvfl) {
		goto __27
	}
	iPrev = *(*U32)(unsafe.Pointer((*StatCell)(unsafe.Pointer(pCell)).FaOvfl + uintptr(j-1)*4))
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	rc = Xsqlite3PagerGet(tls, Xsqlite3BtreePager(tls, pBt), iPrev, bp+16, 0)
	if !(rc != SQLITE_OK) {
		goto __28
	}

	return rc
__28:
	;
	*(*U32)(unsafe.Pointer((*StatCell)(unsafe.Pointer(pCell)).FaOvfl + uintptr(j)*4)) = Xsqlite3Get4byte(tls, Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 16))))
	Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	goto __26
__26:
	j++
	goto __25
	goto __27
__27:
	;
__22:
	;
__18:
	;
	goto __13
__13:
	i++
	goto __12
	goto __14
__14:
	;
__10:
	;
	return SQLITE_OK

statPageIsCorrupt:
	(*StatPage)(unsafe.Pointer(p)).Fflags = U8(0)
	statClearCells(tls, p)
	return SQLITE_OK
}

func statSizeAndOffset(tls *libc.TLS, pCsr uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCsr)).FpVtab
	var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*StatTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr((*StatTable)(unsafe.Pointer(pTab)).FiDb)*32)).FpBt
	var pPager uintptr = Xsqlite3BtreePager(tls, pBt)
	var fd uintptr

	fd = Xsqlite3PagerFile(tls, pPager)
	*(*Sqlite3_int64)(unsafe.Pointer(bp)) = Sqlite3_int64((*StatCursor)(unsafe.Pointer(pCsr)).FiPageno)
	if Xsqlite3OsFileControl(tls, fd, 230440, bp) == SQLITE_OK {
		(*StatCursor)(unsafe.Pointer(pCsr)).FiOffset = *(*Sqlite3_int64)(unsafe.Pointer(bp))
		*(*I64)(unsafe.Pointer(pCsr + 2144)) += *(*Sqlite3_int64)(unsafe.Pointer(bp + 1*8))
	} else {
		*(*I64)(unsafe.Pointer(pCsr + 2144)) += I64(Xsqlite3BtreeGetPageSize(tls, pBt))
		(*StatCursor)(unsafe.Pointer(pCsr)).FiOffset = (*StatCursor)(unsafe.Pointer(pCsr)).FszPage * I64((*StatCursor)(unsafe.Pointer(pCsr)).FiPageno-U32(1))
	}
}

func statGetPage(tls *libc.TLS, pBt uintptr, iPg U32, pPg uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pgsz int32 = Xsqlite3BtreeGetPageSize(tls, pBt)
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32

	if (*StatPage)(unsafe.Pointer(pPg)).FaPg == uintptr(0) {
		(*StatPage)(unsafe.Pointer(pPg)).FaPg = Xsqlite3_malloc(tls, pgsz+DBSTAT_PAGE_PADDING_BYTES)
		if (*StatPage)(unsafe.Pointer(pPg)).FaPg == uintptr(0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, (*StatPage)(unsafe.Pointer(pPg)).FaPg+uintptr(pgsz), 0, uint64(DBSTAT_PAGE_PADDING_BYTES))
	}

	rc = Xsqlite3PagerGet(tls, Xsqlite3BtreePager(tls, pBt), iPg, bp, 0)
	if rc == SQLITE_OK {
		var a uintptr = Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp)))
		libc.Xmemcpy(tls, (*StatPage)(unsafe.Pointer(pPg)).FaPg, a, uint64(pgsz))
		Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}

	return rc
}

func statNext(tls *libc.TLS, pCursor uintptr) int32 {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var rc int32
	var nPayload int32
	var z uintptr
	var pCsr uintptr
	var pTab uintptr
	var pBt uintptr
	var pPager uintptr

	var iRoot U32
	var nUsable int32
	var iOvfl int32
	var pCell uintptr

	var p uintptr
	var i int32
	var p1 uintptr
	pCsr = pCursor
	pTab = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pBt = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*StatTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr((*StatCursor)(unsafe.Pointer(pCsr)).FiDb)*32)).FpBt
	pPager = Xsqlite3BtreePager(tls, pBt)

	Xsqlite3_free(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FzPath)
	(*StatCursor)(unsafe.Pointer(pCsr)).FzPath = uintptr(0)

statNextRestart:
	if !((*StatCursor)(unsafe.Pointer(pCsr)).FiPage < 0) {
		goto __1
	}

	statResetCounts(tls, pCsr)
	rc = Xsqlite3_step(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt)
	if !(rc == SQLITE_ROW) {
		goto __3
	}
	iRoot = U32(Xsqlite3_column_int64(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt, 1))
	Xsqlite3PagerPagecount(tls, pPager, bp+48)
	if !(*(*int32)(unsafe.Pointer(bp + 48)) == 0) {
		goto __5
	}
	(*StatCursor)(unsafe.Pointer(pCsr)).FisEof = U8(1)
	return Xsqlite3_reset(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt)
__5:
	;
	rc = statGetPage(tls, pBt, iRoot, pCsr+24)
	(*StatPage)(unsafe.Pointer(pCsr + 24)).FiPgno = iRoot
	(*StatPage)(unsafe.Pointer(pCsr + 24)).FiCell = 0
	if !!(int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg) != 0) {
		goto __6
	}
	(*StatPage)(unsafe.Pointer(pCsr + 24)).FzPath = libc.AssignUintptr(&z, Xsqlite3_mprintf(tls, ts+38894, 0))
	if !(z == uintptr(0)) {
		goto __7
	}
	rc = SQLITE_NOMEM
__7:
	;
__6:
	;
	(*StatCursor)(unsafe.Pointer(pCsr)).FiPage = 0
	(*StatCursor)(unsafe.Pointer(pCsr)).FnPage = 1
	goto __4
__3:
	(*StatCursor)(unsafe.Pointer(pCsr)).FisEof = U8(1)
	return Xsqlite3_reset(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt)
__4:
	;
	goto __2
__1:
	p = pCsr + 24 + uintptr((*StatCursor)(unsafe.Pointer(pCsr)).FiPage)*64
	if !!(int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg) != 0) {
		goto __8
	}
	statResetCounts(tls, pCsr)
__8:
	;
__9:
	if !((*StatPage)(unsafe.Pointer(p)).FiCell < (*StatPage)(unsafe.Pointer(p)).FnCell) {
		goto __10
	}
	pCell = (*StatPage)(unsafe.Pointer(p)).FaCell + uintptr((*StatPage)(unsafe.Pointer(p)).FiCell)*32
__11:
	if !((*StatCell)(unsafe.Pointer(pCell)).FiOvfl < (*StatCell)(unsafe.Pointer(pCell)).FnOvfl) {
		goto __12
	}
	Xsqlite3BtreeEnter(tls, pBt)
	nUsable = Xsqlite3BtreeGetPageSize(tls, pBt) - Xsqlite3BtreeGetReserveNoMutex(tls, pBt)
	Xsqlite3BtreeLeave(tls, pBt)
	(*StatCursor)(unsafe.Pointer(pCsr)).FnPage++
	statSizeAndOffset(tls, pCsr)
	if !((*StatCell)(unsafe.Pointer(pCell)).FiOvfl < (*StatCell)(unsafe.Pointer(pCell)).FnOvfl-1) {
		goto __13
	}
	*(*I64)(unsafe.Pointer(pCsr + 2128)) += I64(nUsable - 4)
	goto __14
__13:
	*(*I64)(unsafe.Pointer(pCsr + 2128)) += I64((*StatCell)(unsafe.Pointer(pCell)).FnLastOvfl)
	*(*I64)(unsafe.Pointer(pCsr + 2120)) += I64(nUsable - 4 - (*StatCell)(unsafe.Pointer(pCell)).FnLastOvfl)
__14:
	;
	iOvfl = (*StatCell)(unsafe.Pointer(pCell)).FiOvfl
	(*StatCell)(unsafe.Pointer(pCell)).FiOvfl++
	if !!(int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg) != 0) {
		goto __15
	}
	(*StatCursor)(unsafe.Pointer(pCsr)).FzName = Xsqlite3_column_text(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt, 0)
	(*StatCursor)(unsafe.Pointer(pCsr)).FiPageno = *(*U32)(unsafe.Pointer((*StatCell)(unsafe.Pointer(pCell)).FaOvfl + uintptr(iOvfl)*4))
	(*StatCursor)(unsafe.Pointer(pCsr)).FzPagetype = ts + 38896
	(*StatCursor)(unsafe.Pointer(pCsr)).FzPath = libc.AssignUintptr(&z, Xsqlite3_mprintf(tls,
		ts+38905, libc.VaList(bp, (*StatPage)(unsafe.Pointer(p)).FzPath, (*StatPage)(unsafe.Pointer(p)).FiCell, iOvfl)))
	if z == uintptr(0) {
		return SQLITE_NOMEM
	}
	return SQLITE_OK
__15:
	;
	goto __11
__12:
	;
	if !((*StatPage)(unsafe.Pointer(p)).FiRightChildPg != 0) {
		goto __16
	}
	goto __10
__16:
	;
	(*StatPage)(unsafe.Pointer(p)).FiCell++
	goto __9
__10:
	;
	if !(!(int32((*StatPage)(unsafe.Pointer(p)).FiRightChildPg) != 0) || (*StatPage)(unsafe.Pointer(p)).FiCell > (*StatPage)(unsafe.Pointer(p)).FnCell) {
		goto __17
	}
	statClearPage(tls, p)
	(*StatCursor)(unsafe.Pointer(pCsr)).FiPage--
	if !((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0 && (*StatCursor)(unsafe.Pointer(pCsr)).FiPage < 0) {
		goto __18
	}

	return SQLITE_OK
__18:
	;
	goto statNextRestart
__17:
	;
	(*StatCursor)(unsafe.Pointer(pCsr)).FiPage++
	if !((*StatCursor)(unsafe.Pointer(pCsr)).FiPage >= int32(uint64(unsafe.Sizeof([32]StatPage{}))/uint64(unsafe.Sizeof(StatPage{})))) {
		goto __19
	}
	statResetCsr(tls, pCsr)
	return Xsqlite3CorruptError(tls, 215455)
__19:
	;
	if !((*StatPage)(unsafe.Pointer(p)).FiCell == (*StatPage)(unsafe.Pointer(p)).FnCell) {
		goto __20
	}
	(*StatPage)(unsafe.Pointer(p + 1*64)).FiPgno = (*StatPage)(unsafe.Pointer(p)).FiRightChildPg
	goto __21
__20:
	(*StatPage)(unsafe.Pointer(p + 1*64)).FiPgno = (*StatCell)(unsafe.Pointer((*StatPage)(unsafe.Pointer(p)).FaCell + uintptr((*StatPage)(unsafe.Pointer(p)).FiCell)*32)).FiChildPg
__21:
	;
	rc = statGetPage(tls, pBt, (*StatPage)(unsafe.Pointer(p+1*64)).FiPgno, p+1*64)
	(*StatCursor)(unsafe.Pointer(pCsr)).FnPage++
	(*StatPage)(unsafe.Pointer(p + 1*64)).FiCell = 0
	if !!(int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg) != 0) {
		goto __22
	}
	(*StatPage)(unsafe.Pointer(p + 1*64)).FzPath = libc.AssignUintptr(&z, Xsqlite3_mprintf(tls, ts+38917, libc.VaList(bp+24, (*StatPage)(unsafe.Pointer(p)).FzPath, (*StatPage)(unsafe.Pointer(p)).FiCell)))
	if !(z == uintptr(0)) {
		goto __23
	}
	rc = SQLITE_NOMEM
__23:
	;
__22:
	;
	(*StatPage)(unsafe.Pointer(p)).FiCell++
__2:
	;
	if !(rc == SQLITE_OK) {
		goto __24
	}
	p1 = pCsr + 24 + uintptr((*StatCursor)(unsafe.Pointer(pCsr)).FiPage)*64
	(*StatCursor)(unsafe.Pointer(pCsr)).FzName = Xsqlite3_column_text(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt, 0)
	(*StatCursor)(unsafe.Pointer(pCsr)).FiPageno = (*StatPage)(unsafe.Pointer(p1)).FiPgno

	rc = statDecodePage(tls, pBt, p1)
	if !(rc == SQLITE_OK) {
		goto __25
	}
	statSizeAndOffset(tls, pCsr)

	switch int32((*StatPage)(unsafe.Pointer(p1)).Fflags) {
	case 0x05:
		goto __27
	case 0x02:
		goto __28
	case 0x0D:
		goto __29
	case 0x0A:
		goto __30
	default:
		goto __31
	}
	goto __26
__27:
__28:
	(*StatCursor)(unsafe.Pointer(pCsr)).FzPagetype = ts + 38925
	goto __26
__29:
__30:
	(*StatCursor)(unsafe.Pointer(pCsr)).FzPagetype = ts + 38934
	goto __26
__31:
	(*StatCursor)(unsafe.Pointer(pCsr)).FzPagetype = ts + 38939
	goto __26
__26:
	;
	*(*int32)(unsafe.Pointer(pCsr + 2108)) += (*StatPage)(unsafe.Pointer(p1)).FnCell
	*(*I64)(unsafe.Pointer(pCsr + 2120)) += I64((*StatPage)(unsafe.Pointer(p1)).FnUnused)
	if !((*StatPage)(unsafe.Pointer(p1)).FnMxPayload > (*StatCursor)(unsafe.Pointer(pCsr)).FnMxPayload) {
		goto __32
	}
	(*StatCursor)(unsafe.Pointer(pCsr)).FnMxPayload = (*StatPage)(unsafe.Pointer(p1)).FnMxPayload
__32:
	;
	if !!(int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg) != 0) {
		goto __33
	}
	(*StatCursor)(unsafe.Pointer(pCsr)).FzPath = libc.AssignUintptr(&z, Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+40, (*StatPage)(unsafe.Pointer(p1)).FzPath)))
	if !(z == uintptr(0)) {
		goto __34
	}
	rc = SQLITE_NOMEM
__34:
	;
__33:
	;
	nPayload = 0
	i = 0
__35:
	if !(i < (*StatPage)(unsafe.Pointer(p1)).FnCell) {
		goto __37
	}
	nPayload = nPayload + (*StatCell)(unsafe.Pointer((*StatPage)(unsafe.Pointer(p1)).FaCell+uintptr(i)*32)).FnLocal
	goto __36
__36:
	i++
	goto __35
	goto __37
__37:
	;
	*(*I64)(unsafe.Pointer(pCsr + 2128)) += I64(nPayload)

	if !((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0) {
		goto __38
	}
	goto statNextRestart
__38:
	;
__25:
	;
__24:
	;
	return rc
}

func statEof(tls *libc.TLS, pCursor uintptr) int32 {
	var pCsr uintptr = pCursor
	return int32((*StatCursor)(unsafe.Pointer(pCsr)).FisEof)
}

func statFilter(tls *libc.TLS, pCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pCsr uintptr = pCursor
	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	var pSql uintptr
	var zSql uintptr
	var iArg int32 = 0
	var rc int32 = SQLITE_OK
	var zName uintptr = uintptr(0)
	_ = argc
	_ = idxStr

	statResetCsr(tls, pCsr)
	Xsqlite3_finalize(tls, (*StatCursor)(unsafe.Pointer(pCsr)).FpStmt)
	(*StatCursor)(unsafe.Pointer(pCsr)).FpStmt = uintptr(0)
	if idxNum&0x01 != 0 {
		var zDbase uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.PostIncInt32(&iArg, 1))*8)))
		(*StatCursor)(unsafe.Pointer(pCsr)).FiDb = Xsqlite3FindDbName(tls, (*StatTable)(unsafe.Pointer(pTab)).Fdb, zDbase)
		if (*StatCursor)(unsafe.Pointer(pCsr)).FiDb < 0 {
			(*StatCursor)(unsafe.Pointer(pCsr)).FiDb = 0
			(*StatCursor)(unsafe.Pointer(pCsr)).FisEof = U8(1)
			return SQLITE_OK
		}
	} else {
		(*StatCursor)(unsafe.Pointer(pCsr)).FiDb = (*StatTable)(unsafe.Pointer(pTab)).FiDb
	}
	if idxNum&0x02 != 0 {
		zName = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.PostIncInt32(&iArg, 1))*8)))
	}
	if idxNum&0x04 != 0 {
		(*StatCursor)(unsafe.Pointer(pCsr)).FisAgg = U8(libc.Bool32(Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(libc.PostIncInt32(&iArg, 1))*8))) != 0.0))
	} else {
		(*StatCursor)(unsafe.Pointer(pCsr)).FisAgg = U8(0)
	}
	pSql = Xsqlite3_str_new(tls, (*StatTable)(unsafe.Pointer(pTab)).Fdb)
	Xsqlite3_str_appendf(tls, pSql,
		ts+38949,
		libc.VaList(bp, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*StatTable)(unsafe.Pointer(pTab)).Fdb)).FaDb+uintptr((*StatCursor)(unsafe.Pointer(pCsr)).FiDb)*32)).FzDbSName))
	if zName != 0 {
		Xsqlite3_str_appendf(tls, pSql, ts+39104, libc.VaList(bp+8, zName))
	}
	if idxNum&0x08 != 0 {
		Xsqlite3_str_appendf(tls, pSql, ts+39118, 0)
	}
	zSql = Xsqlite3_str_finish(tls, pSql)
	if zSql == uintptr(0) {
		return SQLITE_NOMEM
	} else {
		rc = Xsqlite3_prepare_v2(tls, (*StatTable)(unsafe.Pointer(pTab)).Fdb, zSql, -1, pCsr+8, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}

	if rc == SQLITE_OK {
		(*StatCursor)(unsafe.Pointer(pCsr)).FiPage = -1
		rc = statNext(tls, pCursor)
	}
	return rc
}

func statColumn(tls *libc.TLS, pCursor uintptr, ctx uintptr, i int32) int32 {
	var pCsr uintptr = pCursor
	switch i {
	case 0:
		Xsqlite3_result_text(tls, ctx, (*StatCursor)(unsafe.Pointer(pCsr)).FzName, -1, libc.UintptrFromInt32(-1))
		break
	case 1:
		if !(int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg) != 0) {
			Xsqlite3_result_text(tls, ctx, (*StatCursor)(unsafe.Pointer(pCsr)).FzPath, -1, libc.UintptrFromInt32(-1))
		}
		break
	case 2:
		if (*StatCursor)(unsafe.Pointer(pCsr)).FisAgg != 0 {
			Xsqlite3_result_int64(tls, ctx, int64((*StatCursor)(unsafe.Pointer(pCsr)).FnPage))
		} else {
			Xsqlite3_result_int64(tls, ctx, int64((*StatCursor)(unsafe.Pointer(pCsr)).FiPageno))
		}
		break
	case 3:
		if !(int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg) != 0) {
			Xsqlite3_result_text(tls, ctx, (*StatCursor)(unsafe.Pointer(pCsr)).FzPagetype, -1, uintptr(0))
		}
		break
	case 4:
		Xsqlite3_result_int64(tls, ctx, int64((*StatCursor)(unsafe.Pointer(pCsr)).FnCell))
		break
	case 5:
		Xsqlite3_result_int64(tls, ctx, (*StatCursor)(unsafe.Pointer(pCsr)).FnPayload)
		break
	case 6:
		Xsqlite3_result_int64(tls, ctx, (*StatCursor)(unsafe.Pointer(pCsr)).FnUnused)
		break
	case 7:
		Xsqlite3_result_int64(tls, ctx, int64((*StatCursor)(unsafe.Pointer(pCsr)).FnMxPayload))
		break
	case 8:
		if !(int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg) != 0) {
			Xsqlite3_result_int64(tls, ctx, (*StatCursor)(unsafe.Pointer(pCsr)).FiOffset)
		}
		break
	case 9:
		Xsqlite3_result_int64(tls, ctx, (*StatCursor)(unsafe.Pointer(pCsr)).FszPage)
		break
	case 10:
		{
			var db uintptr = Xsqlite3_context_db_handle(tls, ctx)
			var iDb int32 = (*StatCursor)(unsafe.Pointer(pCsr)).FiDb
			Xsqlite3_result_text(tls, ctx, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr(iDb)*32)).FzDbSName, -1, uintptr(0))
			break

		}
	default:
		{
			Xsqlite3_result_int(tls, ctx, int32((*StatCursor)(unsafe.Pointer(pCsr)).FisAgg))
			break

		}
	}
	return SQLITE_OK
}

func statRowid(tls *libc.TLS, pCursor uintptr, pRowid uintptr) int32 {
	var pCsr uintptr = pCursor
	*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = Sqlite_int64((*StatCursor)(unsafe.Pointer(pCsr)).FiPageno)
	return SQLITE_OK
}

func Xsqlite3DbstatRegister(tls *libc.TLS, db uintptr) int32 {
	return Xsqlite3_create_module(tls, db, ts+39133, uintptr(unsafe.Pointer(&dbstat_module)), uintptr(0))
}

var dbstat_module = Sqlite3_module{
	FxCreate:     0,
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxDestroy:    0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
}

type DbpageTable1 = struct {
	Fbase Sqlite3_vtab
	Fdb   uintptr
}

type DbpageTable = DbpageTable1
type DbpageCursor1 = struct {
	Fbase   Sqlite3_vtab_cursor
	Fpgno   int32
	FmxPgno int32
	FpPager uintptr
	FpPage1 uintptr
	FiDb    int32
	FszPage int32
}

type DbpageCursor = DbpageCursor1

func dbpageConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	var pTab uintptr = uintptr(0)
	var rc int32 = SQLITE_OK
	_ = pAux
	_ = argc
	_ = argv
	_ = pzErr

	Xsqlite3_vtab_config(tls, db, SQLITE_VTAB_DIRECTONLY, 0)
	rc = Xsqlite3_declare_vtab(tls, db,
		ts+39140)
	if rc == SQLITE_OK {
		pTab = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(DbpageTable{})))
		if pTab == uintptr(0) {
			rc = SQLITE_NOMEM
		}
	}

	if rc == SQLITE_OK {
		libc.Xmemset(tls, pTab, 0, uint64(unsafe.Sizeof(DbpageTable{})))
		(*DbpageTable)(unsafe.Pointer(pTab)).Fdb = db
	}

	*(*uintptr)(unsafe.Pointer(ppVtab)) = pTab
	return rc
}

func dbpageDisconnect(tls *libc.TLS, pVtab uintptr) int32 {
	Xsqlite3_free(tls, pVtab)
	return SQLITE_OK
}

func dbpageBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) int32 {
	var i int32
	var iPlan int32 = 0
	_ = tab

	for i = 0; i < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint; i++ {
		var p uintptr = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12
		if (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn != DBPAGE_COLUMN_SCHEMA {
			continue
		}
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) != SQLITE_INDEX_CONSTRAINT_EQ {
			continue
		}
		if !(int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable) != 0) {
			return SQLITE_CONSTRAINT
		}
		iPlan = 2
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = 1
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).Fomit = uint8(1)
		break
	}

	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 1.0e6

	for i = 0; i < (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint; i++ {
		var p uintptr = (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12
		if (*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 && (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn <= 0 && int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_EQ {
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(1)
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxFlags = SQLITE_INDEX_SCAN_UNIQUE
			(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = 1.0
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = func() int32 {
				if iPlan != 0 {
					return 2
				}
				return 1
			}()
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(i)*8)).Fomit = uint8(1)
			iPlan = iPlan | 1
			break
		}
	}
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = iPlan

	if (*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy >= 1 &&
		(*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy)).FiColumn <= 0 &&
		int32((*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy)).Fdesc) == 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = 1
	}
	Xsqlite3VtabUsesAllSchemas(tls, pIdxInfo)
	return SQLITE_OK
}

func dbpageOpen(tls *libc.TLS, pVTab uintptr, ppCursor uintptr) int32 {
	var pCsr uintptr

	pCsr = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(DbpageCursor{})))
	if pCsr == uintptr(0) {
		return SQLITE_NOMEM
	} else {
		libc.Xmemset(tls, pCsr, 0, uint64(unsafe.Sizeof(DbpageCursor{})))
		(*DbpageCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVTab
		(*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno = -1
	}

	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCsr
	return SQLITE_OK
}

func dbpageClose(tls *libc.TLS, pCursor uintptr) int32 {
	var pCsr uintptr = pCursor
	if (*DbpageCursor)(unsafe.Pointer(pCsr)).FpPage1 != 0 {
		Xsqlite3PagerUnrefPageOne(tls, (*DbpageCursor)(unsafe.Pointer(pCsr)).FpPage1)
	}
	Xsqlite3_free(tls, pCsr)
	return SQLITE_OK
}

func dbpageNext(tls *libc.TLS, pCursor uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pCsr uintptr = pCursor
	(*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno++
	return rc
}

func dbpageEof(tls *libc.TLS, pCursor uintptr) int32 {
	var pCsr uintptr = pCursor
	return libc.Bool32((*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno > (*DbpageCursor)(unsafe.Pointer(pCsr)).FmxPgno)
}

func dbpageFilter(tls *libc.TLS, pCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) int32 {
	var pCsr uintptr = pCursor
	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	var rc int32
	var db uintptr = (*DbpageTable)(unsafe.Pointer(pTab)).Fdb
	var pBt uintptr

	_ = idxStr

	(*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno = 1
	(*DbpageCursor)(unsafe.Pointer(pCsr)).FmxPgno = 0

	if idxNum&2 != 0 {
		var zSchema uintptr

		zSchema = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv)))
		(*DbpageCursor)(unsafe.Pointer(pCsr)).FiDb = Xsqlite3FindDbName(tls, db, zSchema)
		if (*DbpageCursor)(unsafe.Pointer(pCsr)).FiDb < 0 {
			return SQLITE_OK
		}
	} else {
		(*DbpageCursor)(unsafe.Pointer(pCsr)).FiDb = 0
	}
	pBt = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr((*DbpageCursor)(unsafe.Pointer(pCsr)).FiDb)*32)).FpBt
	if pBt == uintptr(0) {
		return SQLITE_OK
	}
	(*DbpageCursor)(unsafe.Pointer(pCsr)).FpPager = Xsqlite3BtreePager(tls, pBt)
	(*DbpageCursor)(unsafe.Pointer(pCsr)).FszPage = Xsqlite3BtreeGetPageSize(tls, pBt)
	(*DbpageCursor)(unsafe.Pointer(pCsr)).FmxPgno = int32(Xsqlite3BtreeLastPage(tls, pBt))
	if idxNum&1 != 0 {
		(*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + uintptr(idxNum>>1)*8)))
		if (*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno < 1 || (*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno > (*DbpageCursor)(unsafe.Pointer(pCsr)).FmxPgno {
			(*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno = 1
			(*DbpageCursor)(unsafe.Pointer(pCsr)).FmxPgno = 0
		} else {
			(*DbpageCursor)(unsafe.Pointer(pCsr)).FmxPgno = (*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno
		}
	} else {
	}
	if (*DbpageCursor)(unsafe.Pointer(pCsr)).FpPage1 != 0 {
		Xsqlite3PagerUnrefPageOne(tls, (*DbpageCursor)(unsafe.Pointer(pCsr)).FpPage1)
	}
	rc = Xsqlite3PagerGet(tls, (*DbpageCursor)(unsafe.Pointer(pCsr)).FpPager, uint32(1), pCsr+24, 0)
	return rc
}

func dbpageColumn(tls *libc.TLS, pCursor uintptr, ctx uintptr, i int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pCsr uintptr = pCursor
	var rc int32 = SQLITE_OK
	switch i {
	case 0:
		{
			Xsqlite3_result_int(tls, ctx, (*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno)
			break

		}
	case 1:
		{
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			if (*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno == Xsqlite3PendingByte/(*DbpageCursor)(unsafe.Pointer(pCsr)).FszPage+1 {
				Xsqlite3_result_zeroblob(tls, ctx, (*DbpageCursor)(unsafe.Pointer(pCsr)).FszPage)
			} else {
				rc = Xsqlite3PagerGet(tls, (*DbpageCursor)(unsafe.Pointer(pCsr)).FpPager, uint32((*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno), bp, 0)
				if rc == SQLITE_OK {
					Xsqlite3_result_blob(tls, ctx, Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp))), (*DbpageCursor)(unsafe.Pointer(pCsr)).FszPage,
						libc.UintptrFromInt32(-1))
				}
				Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp)))
			}
			break

		}
	default:
		{
			var db uintptr = Xsqlite3_context_db_handle(tls, ctx)
			Xsqlite3_result_text(tls, ctx, (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb+uintptr((*DbpageCursor)(unsafe.Pointer(pCsr)).FiDb)*32)).FzDbSName, -1, uintptr(0))
			break

		}
	}
	return rc
}

func dbpageRowid(tls *libc.TLS, pCursor uintptr, pRowid uintptr) int32 {
	var pCsr uintptr = pCursor
	*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = Sqlite_int64((*DbpageCursor)(unsafe.Pointer(pCsr)).Fpgno)
	return SQLITE_OK
}

func dbpageUpdate(tls *libc.TLS, pVtab uintptr, argc int32, argv uintptr, pRowid uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTab uintptr
	var pgno Pgno

	var rc int32
	var zErr uintptr
	var zSchema uintptr
	var iDb int32
	var pBt uintptr
	var pPager uintptr
	var szPage int32
	var pData uintptr
	pTab = pVtab
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	rc = SQLITE_OK
	zErr = uintptr(0)

	_ = pRowid
	if !((*Sqlite3)(unsafe.Pointer((*DbpageTable)(unsafe.Pointer(pTab)).Fdb)).Fflags&uint64(SQLITE_Defensive) != 0) {
		goto __1
	}
	zErr = ts + 39207
	goto update_fail
__1:
	;
	if !(argc == 1) {
		goto __2
	}
	zErr = ts + 39217
	goto update_fail
__2:
	;
	pgno = Pgno(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv))))
	if !(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv))) == SQLITE_NULL ||
		Pgno(Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8)))) != pgno) {
		goto __3
	}
	zErr = ts + 39231
	goto update_fail
__3:
	;
	zSchema = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(argv + 4*8)))
	if zSchema != 0 {
		iDb = Xsqlite3FindDbName(tls, (*DbpageTable)(unsafe.Pointer(pTab)).Fdb, zSchema)
	} else {
		iDb = -1
	}
	if !(iDb < 0) {
		goto __4
	}
	zErr = ts + 39245
	goto update_fail
__4:
	;
	pBt = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer((*DbpageTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr(iDb)*32)).FpBt
	if !(pgno < Pgno(1) || pBt == uintptr(0) || pgno > Xsqlite3BtreeLastPage(tls, pBt)) {
		goto __5
	}
	zErr = ts + 39260
	goto update_fail
__5:
	;
	szPage = Xsqlite3BtreeGetPageSize(tls, pBt)
	if !(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8))) != SQLITE_BLOB ||
		Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8))) != szPage) {
		goto __6
	}
	zErr = ts + 39276
	goto update_fail
__6:
	;
	pPager = Xsqlite3BtreePager(tls, pBt)
	rc = Xsqlite3PagerGet(tls, pPager, pgno, bp+8, 0)
	if !(rc == SQLITE_OK) {
		goto __7
	}
	pData = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(argv + 3*8)))

	if !(pData != 0 &&
		libc.AssignInt32(&rc, Xsqlite3PagerWrite(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))) == SQLITE_OK) {
		goto __8
	}
	libc.Xmemcpy(tls, Xsqlite3PagerGetData(tls, *(*uintptr)(unsafe.Pointer(bp + 8))), pData, uint64(szPage))
__8:
	;
__7:
	;
	Xsqlite3PagerUnref(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	return rc

update_fail:
	Xsqlite3_free(tls, (*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg)
	(*Sqlite3_vtab)(unsafe.Pointer(pVtab)).FzErrMsg = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, zErr))
	return SQLITE_ERROR
}

func dbpageBegin(tls *libc.TLS, pVtab uintptr) int32 {
	var pTab uintptr = pVtab
	var db uintptr = (*DbpageTable)(unsafe.Pointer(pTab)).Fdb
	var i int32
	for i = 0; i < (*Sqlite3)(unsafe.Pointer(db)).FnDb; i++ {
		var pBt uintptr = (*Db)(unsafe.Pointer((*Sqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*32)).FpBt
		if pBt != 0 {
			Xsqlite3BtreeBeginTrans(tls, pBt, 1, uintptr(0))
		}
	}
	return SQLITE_OK
}

func Xsqlite3DbpageRegister(tls *libc.TLS, db uintptr) int32 {
	return Xsqlite3_create_module(tls, db, ts+39291, uintptr(unsafe.Pointer(&dbpage_module)), uintptr(0))
}

var dbpage_module = Sqlite3_module{
	FxCreate:     0,
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxDestroy:    0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
	FxUpdate:     0,
	FxBegin:      0,
}

type SessionTable1 = struct {
	FpNext    uintptr
	FzName    uintptr
	FnCol     int32
	FbStat1   int32
	FazCol    uintptr
	FabPK     uintptr
	FnEntry   int32
	FnChange  int32
	FapChange uintptr
}

type SessionTable = SessionTable1
type SessionChange1 = struct {
	Fop          U8
	FbIndirect   U8
	F__ccgo_pad1 [2]byte
	FnMaxSize    int32
	FnRecord     int32
	F__ccgo_pad2 [4]byte
	FaRecord     uintptr
	FpNext       uintptr
}

type SessionChange = SessionChange1
type SessionBuffer1 = struct {
	FaBuf   uintptr
	FnBuf   int32
	FnAlloc int32
}

type SessionBuffer = SessionBuffer1
type SessionInput1 = struct {
	FbNoDiscard  int32
	FiCurrent    int32
	FiNext       int32
	F__ccgo_pad1 [4]byte
	FaData       uintptr
	FnData       int32
	F__ccgo_pad2 [4]byte
	Fbuf         SessionBuffer
	FxInput      uintptr
	FpIn         uintptr
	FbEof        int32
	F__ccgo_pad3 [4]byte
}

type SessionInput = SessionInput1

var sessions_strm_chunk_size int32 = SESSIONS_STRM_CHUNK_SIZE

type SessionHook1 = struct {
	FpCtx   uintptr
	FxOld   uintptr
	FxNew   uintptr
	FxCount uintptr
	FxDepth uintptr
}

type SessionHook = SessionHook1

func sessionVarintPut(tls *libc.TLS, aBuf uintptr, iVal int32) int32 {
	return int32(func() uint8 {
		if U32(iVal) < U32(0x80) {
			return uint8(func() int32 { *(*U8)(unsafe.Pointer(aBuf)) = uint8(iVal); return 1 }())
		}
		return uint8(Xsqlite3PutVarint(tls, aBuf, uint64(iVal)))
	}())
}

func sessionVarintLen(tls *libc.TLS, iVal int32) int32 {
	return Xsqlite3VarintLen(tls, uint64(iVal))
}

func sessionVarintGet(tls *libc.TLS, aBuf uintptr, piVal uintptr) int32 {
	return int32(func() uint8 {
		if int32(*(*U8)(unsafe.Pointer(aBuf))) < int32(U8(0x80)) {
			return uint8(func() int32 { *(*int32)(unsafe.Pointer(piVal)) = int32(U32(*(*U8)(unsafe.Pointer(aBuf)))); return 1 }())
		}
		return Xsqlite3GetVarint32(tls, aBuf, piVal)
	}())
}

func sessionGetI64(tls *libc.TLS, aRec uintptr) Sqlite3_int64 {
	var x U64 = U64(U32(*(*U8)(unsafe.Pointer(aRec)))<<24 | U32(int32(*(*U8)(unsafe.Pointer(aRec + 1)))<<16) | U32(int32(*(*U8)(unsafe.Pointer(aRec + 2)))<<8) | U32(*(*U8)(unsafe.Pointer(aRec + 3))))
	var y U32 = U32(*(*U8)(unsafe.Pointer(aRec + uintptr(4))))<<24 | U32(int32(*(*U8)(unsafe.Pointer(aRec + uintptr(4) + 1)))<<16) | U32(int32(*(*U8)(unsafe.Pointer(aRec + uintptr(4) + 2)))<<8) | U32(*(*U8)(unsafe.Pointer(aRec + uintptr(4) + 3)))
	x = x<<32 + U64(y)
	return Sqlite3_int64(x)
}

func sessionPutI64(tls *libc.TLS, aBuf uintptr, i Sqlite3_int64) {
	*(*U8)(unsafe.Pointer(aBuf)) = U8(i >> 56 & int64(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 1)) = U8(i >> 48 & int64(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 2)) = U8(i >> 40 & int64(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 3)) = U8(i >> 32 & int64(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 4)) = U8(i >> 24 & int64(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 5)) = U8(i >> 16 & int64(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 6)) = U8(i >> 8 & int64(0xFF))
	*(*U8)(unsafe.Pointer(aBuf + 7)) = U8(i >> 0 & int64(0xFF))
}

func sessionSerializeValue(tls *libc.TLS, aBuf uintptr, pValue uintptr, pnWrite uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var nByte int32

	if pValue != 0 {
		var eType int32

		eType = Xsqlite3_value_type(tls, pValue)
		if aBuf != 0 {
			*(*U8)(unsafe.Pointer(aBuf)) = U8(eType)
		}

		switch eType {
		case SQLITE_NULL:
			nByte = 1
			break
			fallthrough

		case SQLITE_INTEGER:
			fallthrough
		case SQLITE_FLOAT:
			if aBuf != 0 {
				if eType == SQLITE_INTEGER {
					*(*U64)(unsafe.Pointer(bp)) = U64(Xsqlite3_value_int64(tls, pValue))
				} else {
					*(*float64)(unsafe.Pointer(bp + 8)) = Xsqlite3_value_double(tls, pValue)
					libc.Xmemcpy(tls, bp, bp+8, uint64(8))
				}
				sessionPutI64(tls, aBuf+1, int64(*(*U64)(unsafe.Pointer(bp))))
			}
			nByte = 9
			break
			fallthrough

		default:
			{
				var z uintptr
				var n int32
				var nVarint int32

				if eType == 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 != SQLITE_BLOB || n > 0) {
					return SQLITE_NOMEM
				}
				nVarint = sessionVarintLen(tls, n)

				if aBuf != 0 {
					sessionVarintPut(tls, aBuf+1, n)
					if n > 0 {
						libc.Xmemcpy(tls, aBuf+uintptr(nVarint+1), z, uint64(n))
					}
				}

				nByte = 1 + nVarint + n
				break

			}
		}
	} else {
		nByte = 1
		if aBuf != 0 {
			*(*U8)(unsafe.Pointer(aBuf)) = U8(0)
		}
	}

	if pnWrite != 0 {
		*(*Sqlite3_int64)(unsafe.Pointer(pnWrite)) += Sqlite3_int64(nByte)
	}
	return SQLITE_OK
}

func sessionMalloc64(tls *libc.TLS, pSession uintptr, nByte I64) uintptr {
	var pRet uintptr = Xsqlite3_malloc64(tls, uint64(nByte))
	if pSession != 0 {
		*(*I64)(unsafe.Pointer(pSession + 56)) += I64(Xsqlite3_msize(tls, pRet))
	}
	return pRet
}

func sessionFree(tls *libc.TLS, pSession uintptr, pFree uintptr) {
	if pSession != 0 {
		*(*I64)(unsafe.Pointer(pSession + 56)) -= I64(Xsqlite3_msize(tls, pFree))
	}
	Xsqlite3_free(tls, pFree)
}

func sessionHashAppendI64(tls *libc.TLS, h uint32, i I64) uint32 {
	h = h<<3 ^ h ^ uint32(i&int64(0xFFFFFFFF))
	return h<<3 ^ h ^ uint32(i>>32&int64(0xFFFFFFFF))
}

func sessionHashAppendBlob(tls *libc.TLS, h uint32, n int32, z uintptr) uint32 {
	var i int32
	for i = 0; i < n; i++ {
		h = h<<3 ^ h ^ uint32(*(*U8)(unsafe.Pointer(z + uintptr(i))))
	}
	return h
}

func sessionHashAppendType(tls *libc.TLS, h uint32, eType int32) uint32 {
	return h<<3 ^ h ^ uint32(eType)
}

func sessionPreupdateHash(tls *libc.TLS, pSession uintptr, pTab uintptr, bNew int32, piHash uintptr, pbNullPK uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var h uint32 = uint32(0)
	var i int32

	for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; i++ {
		if *(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 {
			var rc int32
			var eType int32

			if bNew != 0 {
				rc = (*struct {
					f func(*libc.TLS, uintptr, int32, uintptr) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp)
			} else {
				rc = (*struct {
					f func(*libc.TLS, uintptr, int32, uintptr) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})).f(tls, (*Sqlite3_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 == SQLITE_INTEGER || eType == SQLITE_FLOAT {
				if eType == SQLITE_INTEGER {
					*(*I64)(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, uint64(8))
				}
				h = sessionHashAppendI64(tls, h, *(*I64)(unsafe.Pointer(bp + 8)))
			} else if eType == SQLITE_TEXT || eType == SQLITE_BLOB {
				var z uintptr
				var n int32
				if eType == 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 != SQLITE_BLOB || n > 0) {
					return SQLITE_NOMEM
				}
				h = sessionHashAppendBlob(tls, h, n, z)
			} else {
				*(*int32)(unsafe.Pointer(pbNullPK)) = 1
			}
		}
	}

	*(*int32)(unsafe.Pointer(piHash)) = int32(h % uint32((*SessionTable)(unsafe.Pointer(pTab)).FnChange))
	return SQLITE_OK
}

func sessionSerialLen(tls *libc.TLS, a uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var e int32 = int32(*(*U8)(unsafe.Pointer(a)))

	if e == 0 || e == 0xFF {
		return 1
	}
	if e == SQLITE_NULL {
		return 1
	}
	if e == SQLITE_INTEGER || e == SQLITE_FLOAT {
		return 9
	}
	return sessionVarintGet(tls, a+1, bp) + 1 + *(*int32)(unsafe.Pointer(bp))
}

func sessionChangeHash(tls *libc.TLS, pTab uintptr, bPkOnly int32, aRecord uintptr, nBucket int32) uint32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var h uint32 = uint32(0)
	var i int32
	var a uintptr = aRecord

	for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; i++ {
		var eType int32 = int32(*(*U8)(unsafe.Pointer(a)))
		var isPK int32 = int32(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))))
		if bPkOnly != 0 && isPK == 0 {
			continue
		}

		if isPK != 0 {
			a++
			h = sessionHashAppendType(tls, h, eType)
			if eType == SQLITE_INTEGER || eType == 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))
		}
	}
	return h % uint32(nBucket)
}

func sessionChangeEqual(tls *libc.TLS, pTab uintptr, bLeftPkOnly int32, aLeft uintptr, bRightPkOnly int32, aRight uintptr) int32 {
	var a1 uintptr = aLeft
	var a2 uintptr = aRight
	var iCol int32

	for iCol = 0; iCol < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; iCol++ {
		if *(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(iCol))) != 0 {
			var n1 int32 = sessionSerialLen(tls, a1)
			var n2 int32 = sessionSerialLen(tls, a2)

			if n1 != n2 || libc.Xmemcmp(tls, a1, a2, uint64(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))
			}
		}
	}

	return 1
}

func sessionMergeRecord(tls *libc.TLS, paOut uintptr, nCol int32, aLeft uintptr, aRight uintptr) {
	var a1 uintptr = aLeft
	var a2 uintptr = aRight
	var aOut uintptr = *(*uintptr)(unsafe.Pointer(paOut))
	var iCol int32

	for iCol = 0; iCol < nCol; iCol++ {
		var n1 int32 = sessionSerialLen(tls, a1)
		var n2 int32 = sessionSerialLen(tls, a2)
		if *(*U8)(unsafe.Pointer(a2)) != 0 {
			libc.Xmemcpy(tls, aOut, a2, uint64(n2))
			aOut += uintptr(n2)
		} else {
			libc.Xmemcpy(tls, aOut, a1, uint64(n1))
			aOut += uintptr(n1)
		}
		a1 += uintptr(n1)
		a2 += uintptr(n2)
	}

	*(*uintptr)(unsafe.Pointer(paOut)) = aOut
}

func sessionMergeValue(tls *libc.TLS, paOne uintptr, paTwo uintptr, pnVal uintptr) uintptr {
	var a1 uintptr = *(*uintptr)(unsafe.Pointer(paOne))
	var a2 uintptr = *(*uintptr)(unsafe.Pointer(paTwo))
	var pRet uintptr = uintptr(0)
	var n1 int32

	if a2 != 0 {
		var n2 int32 = sessionSerialLen(tls, a2)
		if *(*U8)(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
}

func sessionMergeUpdate(tls *libc.TLS, paOut uintptr, pTab uintptr, bPatchset int32, aOldRecord1 uintptr, aOldRecord2 uintptr, aNewRecord1 uintptr, aNewRecord2 uintptr) int32 {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	*(*uintptr)(unsafe.Pointer(bp)) = aOldRecord1
	*(*uintptr)(unsafe.Pointer(bp + 8)) = aOldRecord2
	*(*uintptr)(unsafe.Pointer(bp + 24)) = aNewRecord1
	*(*uintptr)(unsafe.Pointer(bp + 32)) = aNewRecord2

	var aOut uintptr = *(*uintptr)(unsafe.Pointer(paOut))
	var i int32

	if bPatchset == 0 {
		var bRequired int32 = 0

		for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; i++ {
			var aOld uintptr

			var aNew uintptr

			aOld = sessionMergeValue(tls, bp, bp+8, bp+16)
			aNew = sessionMergeValue(tls, bp+24, bp+32, bp+40)
			if *(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 || *(*int32)(unsafe.Pointer(bp + 16)) != *(*int32)(unsafe.Pointer(bp + 40)) || libc.Xmemcmp(tls, aOld, aNew, uint64(*(*int32)(unsafe.Pointer(bp + 40)))) != 0 {
				if int32(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i)))) == 0 {
					bRequired = 1
				}
				libc.Xmemcpy(tls, aOut, aOld, uint64(*(*int32)(unsafe.Pointer(bp + 16))))
				aOut += uintptr(*(*int32)(unsafe.Pointer(bp + 16)))
			} else {
				*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&aOut, 1))) = U8(0)
			}
		}

		if !(bRequired != 0) {
			return 0
		}
	}

	*(*uintptr)(unsafe.Pointer(bp)) = aOldRecord1
	*(*uintptr)(unsafe.Pointer(bp + 8)) = aOldRecord2
	*(*uintptr)(unsafe.Pointer(bp + 24)) = aNewRecord1
	*(*uintptr)(unsafe.Pointer(bp + 32)) = aNewRecord2
	for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; i++ {
		var aOld uintptr

		var aNew uintptr

		aOld = sessionMergeValue(tls, bp, bp+8, bp+44)
		aNew = sessionMergeValue(tls, bp+24, bp+32, bp+48)
		if bPatchset == 0 &&
			(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0 || *(*int32)(unsafe.Pointer(bp + 44)) == *(*int32)(unsafe.Pointer(bp + 48)) && 0 == libc.Xmemcmp(tls, aOld, aNew, uint64(*(*int32)(unsafe.Pointer(bp + 48))))) {
			*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&aOut, 1))) = U8(0)
		} else {
			libc.Xmemcpy(tls, aOut, aNew, uint64(*(*int32)(unsafe.Pointer(bp + 48))))
			aOut += uintptr(*(*int32)(unsafe.Pointer(bp + 48)))
		}
	}

	*(*uintptr)(unsafe.Pointer(paOut)) = aOut
	return 1
}

func sessionPreupdateEqual(tls *libc.TLS, pSession uintptr, pTab uintptr, pChange uintptr, op int32) int32 {
	bp := tls.Alloc(28)
	defer tls.Free(28)

	var iCol int32
	var a uintptr = (*SessionChange)(unsafe.Pointer(pChange)).FaRecord

	for iCol = 0; iCol < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; iCol++ {
		if !(int32(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(iCol)))) != 0) {
			a += uintptr(sessionSerialLen(tls, a))
		} else {
			var rc int32
			_ = rc
			var eType int32 = int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&a, 1))))

			if op == SQLITE_INSERT {
				rc = (*struct {
					f func(*libc.TLS, uintptr, int32, uintptr) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iCol, bp)
			} else {
				rc = (*struct {
					f func(*libc.TLS, uintptr, int32, uintptr) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, iCol, bp)
			}

			if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp))) != eType {
				return 0
			}

			if eType == SQLITE_INTEGER || eType == SQLITE_FLOAT {
				*(*I64)(unsafe.Pointer(bp + 16)) = sessionGetI64(tls, a)
				a += uintptr(8)
				if eType == SQLITE_INTEGER {
					if Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(bp))) != *(*I64)(unsafe.Pointer(bp + 16)) {
						return 0
					}
				} else {
					libc.Xmemcpy(tls, bp+8, bp+16, uint64(8))
					if Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(bp))) != *(*float64)(unsafe.Pointer(bp + 8)) {
						return 0
					}
				}
			} else {
				var z uintptr
				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 == 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, uint64(*(*int32)(unsafe.Pointer(bp + 24)))) != 0 {
					return 0
				}
				a += uintptr(*(*int32)(unsafe.Pointer(bp + 24)))
			}
		}
	}

	return 1
}

func sessionGrowHash(tls *libc.TLS, pSession uintptr, bPatchset int32, pTab uintptr) int32 {
	if (*SessionTable)(unsafe.Pointer(pTab)).FnChange == 0 || (*SessionTable)(unsafe.Pointer(pTab)).FnEntry >= (*SessionTable)(unsafe.Pointer(pTab)).FnChange/2 {
		var i int32
		var apNew uintptr
		var nNew Sqlite3_int64 = int64(2) * func() int64 {
			if (*SessionTable)(unsafe.Pointer(pTab)).FnChange != 0 {
				return int64((*SessionTable)(unsafe.Pointer(pTab)).FnChange)
			}
			return int64(128)
		}()

		apNew = sessionMalloc64(tls,
			pSession, int64(uint64(unsafe.Sizeof(uintptr(0)))*uint64(nNew)))
		if apNew == uintptr(0) {
			if (*SessionTable)(unsafe.Pointer(pTab)).FnChange == 0 {
				return SQLITE_ERROR
			}
			return SQLITE_OK
		}
		libc.Xmemset(tls, apNew, 0, uint64(unsafe.Sizeof(uintptr(0)))*uint64(nNew))

		for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnChange; i++ {
			var p uintptr
			var pNext uintptr
			for p = *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*8)); p != 0; p = pNext {
				var bPkOnly int32 = libc.Bool32(int32((*SessionChange)(unsafe.Pointer(p)).Fop) == SQLITE_DELETE && bPatchset != 0)
				var iHash int32 = int32(sessionChangeHash(tls, pTab, bPkOnly, (*SessionChange)(unsafe.Pointer(p)).FaRecord, int32(nNew)))
				pNext = (*SessionChange)(unsafe.Pointer(p)).FpNext
				(*SessionChange)(unsafe.Pointer(p)).FpNext = *(*uintptr)(unsafe.Pointer(apNew + uintptr(iHash)*8))
				*(*uintptr)(unsafe.Pointer(apNew + uintptr(iHash)*8)) = p
			}
		}

		sessionFree(tls, pSession, (*SessionTable)(unsafe.Pointer(pTab)).FapChange)
		(*SessionTable)(unsafe.Pointer(pTab)).FnChange = int32(nNew)
		(*SessionTable)(unsafe.Pointer(pTab)).FapChange = apNew
	}

	return SQLITE_OK
}

func sessionTableInfo(tls *libc.TLS, pSession uintptr, db uintptr, zDb uintptr, zThis uintptr, pnCol uintptr, pzTab uintptr, pazCol uintptr, pabPK uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var zPragma uintptr

	var rc int32
	var nByte Sqlite3_int64
	var nDbCol int32 = 0
	var nThis int32
	var i int32
	var pAlloc uintptr = uintptr(0)
	var azCol uintptr = uintptr(0)
	var abPK uintptr = uintptr(0)

	nThis = Xsqlite3Strlen30(tls, zThis)
	if nThis == 12 && 0 == Xsqlite3_stricmp(tls, ts+14732, 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 {
			zPragma = Xsqlite3_mprintf(tls,
				ts+39305, 0)
		} else if rc == SQLITE_ERROR {
			zPragma = Xsqlite3_mprintf(tls, ts+1636, 0)
		} else {
			*(*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)
			}
			return rc
		}
	} else {
		zPragma = Xsqlite3_mprintf(tls, ts+39426, libc.VaList(bp, zDb, zThis))
	}
	if !(zPragma != 0) {
		*(*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)
		}
		return SQLITE_NOMEM
	}

	rc = Xsqlite3_prepare_v2(tls, db, zPragma, -1, bp+16, uintptr(0))
	Xsqlite3_free(tls, zPragma)
	if rc != SQLITE_OK {
		*(*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)
		}
		return rc
	}

	nByte = Sqlite3_int64(nThis + 1)
	for SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) {
		nByte = nByte + Sqlite3_int64(Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 1))
		nDbCol++
	}
	rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))

	if rc == SQLITE_OK {
		nByte = Sqlite3_int64(uint64(nByte) + uint64(nDbCol)*(uint64(unsafe.Sizeof(uintptr(0)))+uint64(unsafe.Sizeof(U8(0)))+uint64(1)))
		pAlloc = sessionMalloc64(tls, pSession, nByte)
		if pAlloc == uintptr(0) {
			rc = SQLITE_NOMEM
		}
	}
	if rc == SQLITE_OK {
		azCol = pAlloc
		pAlloc = azCol + uintptr(nDbCol)*8
		abPK = pAlloc
		pAlloc = abPK + uintptr(nDbCol)
		if pzTab != 0 {
			libc.Xmemcpy(tls, pAlloc, zThis, uint64(nThis+1))
			*(*uintptr)(unsafe.Pointer(pzTab)) = pAlloc
			pAlloc += uintptr(nThis + 1)
		}

		i = 0
		for SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) {
			var nName int32 = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 1)
			var zName uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 1)
			if zName == uintptr(0) {
				break
			}
			libc.Xmemcpy(tls, pAlloc, zName, uint64(nName+1))
			*(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*8)) = pAlloc
			pAlloc += uintptr(nName + 1)
			*(*U8)(unsafe.Pointer(abPK + uintptr(i))) = U8(Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 5))
			i++
		}
		rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))

	}

	if rc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(pazCol)) = azCol
		*(*uintptr)(unsafe.Pointer(pabPK)) = abPK
		*(*int32)(unsafe.Pointer(pnCol)) = nDbCol
	} else {
		*(*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)
		}
		sessionFree(tls, pSession, azCol)
	}
	Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	return rc
}

func sessionInitTable(tls *libc.TLS, pSession uintptr, pTab uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	if (*SessionTable)(unsafe.Pointer(pTab)).FnCol == 0 {
		(*Sqlite3_session)(unsafe.Pointer(pSession)).Frc = sessionTableInfo(tls, pSession, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb, (*Sqlite3_session)(unsafe.Pointer(pSession)).FzDb,
			(*SessionTable)(unsafe.Pointer(pTab)).FzName, pTab+16, uintptr(0), pTab+24, bp)
		if (*Sqlite3_session)(unsafe.Pointer(pSession)).Frc == SQLITE_OK {
			var i int32
			for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; i++ {
				if *(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)) + uintptr(i))) != 0 {
					(*SessionTable)(unsafe.Pointer(pTab)).FabPK = *(*uintptr)(unsafe.Pointer(bp))
					break
				}
			}
			if 0 == Xsqlite3_stricmp(tls, ts+14732, (*SessionTable)(unsafe.Pointer(pTab)).FzName) {
				(*SessionTable)(unsafe.Pointer(pTab)).FbStat1 = 1
			}

			if (*Sqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0 {
				*(*I64)(unsafe.Pointer(pSession + 64)) += I64(Size_t(1+sessionVarintLen(tls, (*SessionTable)(unsafe.Pointer(pTab)).FnCol)+(*SessionTable)(unsafe.Pointer(pTab)).FnCol) + libc.Xstrlen(tls, (*SessionTable)(unsafe.Pointer(pTab)).FzName) + uint64(1))
			}
		}
	}
	return libc.Bool32((*Sqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 || (*SessionTable)(unsafe.Pointer(pTab)).FabPK == uintptr(0))
}

type SessionStat1Ctx1 = struct {
	Fhook     SessionHook
	FpSession uintptr
}

type SessionStat1Ctx = SessionStat1Ctx1

func sessionStat1Old(tls *libc.TLS, pCtx uintptr, iCol int32, ppVal uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p uintptr = pCtx
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32 = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*SessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FxOld})).f(tls, (*SessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FpCtx, iCol, bp)
	if rc == SQLITE_OK && iCol == 1 && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp))) == SQLITE_NULL {
		*(*uintptr)(unsafe.Pointer(bp)) = (*Sqlite3_session)(unsafe.Pointer((*SessionStat1Ctx)(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) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p uintptr = pCtx
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32 = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*SessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FxNew})).f(tls, (*SessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FpCtx, iCol, bp)
	if rc == SQLITE_OK && iCol == 1 && Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp))) == SQLITE_NULL {
		*(*uintptr)(unsafe.Pointer(bp)) = (*Sqlite3_session)(unsafe.Pointer((*SessionStat1Ctx)(unsafe.Pointer(p)).FpSession)).FpZeroBlob
	}
	*(*uintptr)(unsafe.Pointer(ppVal)) = *(*uintptr)(unsafe.Pointer(bp))
	return rc
}

func sessionStat1Count(tls *libc.TLS, pCtx uintptr) int32 {
	var p uintptr = pCtx
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*SessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FxCount})).f(tls, (*SessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FpCtx)
}

func sessionStat1Depth(tls *libc.TLS, pCtx uintptr) int32 {
	var p uintptr = pCtx
	return (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*SessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FxDepth})).f(tls, (*SessionStat1Ctx)(unsafe.Pointer(p)).Fhook.FpCtx)
}

func sessionUpdateMaxSize(tls *libc.TLS, op int32, pSession uintptr, pTab uintptr, pC uintptr) int32 {
	bp := tls.Alloc(44)
	defer tls.Free(44)

	*(*I64)(unsafe.Pointer(bp + 8)) = int64(2)
	if int32((*SessionChange)(unsafe.Pointer(pC)).Fop) == SQLITE_INSERT {
		if op != SQLITE_DELETE {
			var ii int32
			for ii = 0; ii < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; ii++ {
				*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
				(*struct {
					f func(*libc.TLS, uintptr, int32, uintptr) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, ii, bp)
				sessionSerializeValue(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(bp)), bp+8)
			}
		}
	} else if op == SQLITE_DELETE {
		*(*I64)(unsafe.Pointer(bp + 8)) += I64((*SessionChange)(unsafe.Pointer(pC)).FnRecord)
		if Xsqlite3_preupdate_blobwrite(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb) >= 0 {
			*(*I64)(unsafe.Pointer(bp + 8)) += I64((*SessionChange)(unsafe.Pointer(pC)).FnRecord)
		}
	} else {
		var ii int32
		var pCsr uintptr = (*SessionChange)(unsafe.Pointer(pC)).FaRecord
		for ii = 0; ii < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; ii++ {
			var bChanged int32 = 1
			var nOld int32 = 0
			var eType int32
			*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
			(*struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, ii, bp+16)
			if *(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0) {
				return SQLITE_NOMEM
			}

			eType = int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pCsr, 1))))
			switch eType {
			case SQLITE_NULL:
				bChanged = libc.Bool32(Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) != SQLITE_NULL)
				break
				fallthrough

			case SQLITE_FLOAT:
				fallthrough
			case SQLITE_INTEGER:
				{
					if eType == Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) {
						*(*Sqlite3_int64)(unsafe.Pointer(bp + 32)) = sessionGetI64(tls, pCsr)
						if eType == SQLITE_INTEGER {
							bChanged = libc.Bool32(*(*Sqlite3_int64)(unsafe.Pointer(bp + 32)) != Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 16))))
						} else {
							libc.Xmemcpy(tls, bp+24, bp+32, uint64(8))
							bChanged = libc.Bool32(*(*float64)(unsafe.Pointer(bp + 24)) != Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(bp + 16))))
						}
					}
					nOld = 8
					pCsr += uintptr(8)
					break

				}
				fallthrough

			default:
				{
					nOld = sessionVarintGet(tls, pCsr, bp+40)
					pCsr += uintptr(nOld)
					nOld = nOld + *(*int32)(unsafe.Pointer(bp + 40))

					if eType == Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) &&
						*(*int32)(unsafe.Pointer(bp + 40)) == Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) &&
						(*(*int32)(unsafe.Pointer(bp + 40)) == 0 || 0 == libc.Xmemcmp(tls, pCsr, Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(bp + 16))), uint64(*(*int32)(unsafe.Pointer(bp + 40))))) {
						bChanged = 0
					}
					pCsr += uintptr(*(*int32)(unsafe.Pointer(bp + 40)))
					break

				}
			}

			if bChanged != 0 && *(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(ii))) != 0 {
				*(*I64)(unsafe.Pointer(bp + 8)) = I64((*SessionChange)(unsafe.Pointer(pC)).FnRecord + 2)
				break
			}

			if bChanged != 0 {
				*(*I64)(unsafe.Pointer(bp + 8)) += I64(1 + nOld)
				sessionSerializeValue(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(bp + 16)), bp+8)
			} else if *(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(ii))) != 0 {
				*(*I64)(unsafe.Pointer(bp + 8)) += I64(2 + nOld)
			} else {
				*(*I64)(unsafe.Pointer(bp + 8)) += int64(2)
			}
		}
	}

	if *(*I64)(unsafe.Pointer(bp + 8)) > I64((*SessionChange)(unsafe.Pointer(pC)).FnMaxSize) {
		var nIncr int32 = int32(*(*I64)(unsafe.Pointer(bp + 8)) - I64((*SessionChange)(unsafe.Pointer(pC)).FnMaxSize))
		(*SessionChange)(unsafe.Pointer(pC)).FnMaxSize = int32(*(*I64)(unsafe.Pointer(bp + 8)))
		*(*I64)(unsafe.Pointer(pSession + 64)) += I64(nIncr)
	}
	return SQLITE_OK
}

func sessionPreupdateOneChange(tls *libc.TLS, op int32, pSession uintptr, pTab uintptr) {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var rc int32

	var p uintptr

	var i int32

	var pC uintptr
	*(*int32)(unsafe.Pointer(bp + 52)) = 0
	rc = SQLITE_OK
	*(*SessionStat1Ctx)(unsafe.Pointer(bp)) = SessionStat1Ctx{}

	if !((*Sqlite3_session)(unsafe.Pointer(pSession)).Frc != 0) {
		goto __1
	}
	return
__1:
	;
	if !(sessionInitTable(tls, pSession, pTab) != 0) {
		goto __2
	}
	return
__2:
	;
	if !((*SessionTable)(unsafe.Pointer(pTab)).FnCol != (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx)) {
		goto __3
	}
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Frc = SQLITE_SCHEMA
	return
__3:
	;
	if !(sessionGrowHash(tls, pSession, 0, pTab) != 0) {
		goto __4
	}
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Frc = SQLITE_NOMEM
	return
__4:
	;
	if !((*SessionTable)(unsafe.Pointer(pTab)).FbStat1 != 0) {
		goto __5
	}
	(*SessionStat1Ctx)(unsafe.Pointer(bp)).Fhook = (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook
	(*SessionStat1Ctx)(unsafe.Pointer(bp)).FpSession = pSession
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx = bp
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	}{sessionStat1New}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	}{sessionStat1Old}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{sessionStat1Count}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{sessionStat1Depth}))
	if !((*Sqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob == uintptr(0)) {
		goto __6
	}
	p = Xsqlite3ValueNew(tls, uintptr(0))
	if !(p == uintptr(0)) {
		goto __7
	}
	rc = SQLITE_NOMEM
	goto error_out
__7:
	;
	Xsqlite3ValueSetStr(tls, p, 0, ts+1636, uint8(0), uintptr(0))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob = p
__6:
	;
__5:
	;
	rc = sessionPreupdateHash(tls, pSession, pTab, libc.Bool32(op == SQLITE_INSERT), bp+48, bp+52)
	if !(rc != SQLITE_OK) {
		goto __8
	}
	goto error_out
__8:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 52)) == 0) {
		goto __9
	}
	pC = *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(*(*int32)(unsafe.Pointer(bp + 48)))*8))
__10:
	if !(pC != 0) {
		goto __12
	}
	if !(sessionPreupdateEqual(tls, pSession, pTab, pC, op) != 0) {
		goto __13
	}
	goto __12
__13:
	;
	goto __11
__11:
	pC = (*SessionChange)(unsafe.Pointer(pC)).FpNext
	goto __10
	goto __12
__12:
	;
	if !(pC == uintptr(0)) {
		goto __14
	}

	(*SessionTable)(unsafe.Pointer(pTab)).FnEntry++

	*(*Sqlite3_int64)(unsafe.Pointer(bp + 64)) = Sqlite3_int64(unsafe.Sizeof(SessionChange{}))
	i = 0
__16:
	if !(i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol) {
		goto __18
	}
	*(*uintptr)(unsafe.Pointer(bp + 56)) = uintptr(0)
	if !(op != SQLITE_INSERT) {
		goto __19
	}
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp+56)

	goto __20
__19:
	if !(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0) {
		goto __21
	}
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp+56)

__21:
	;
__20:
	;
	rc = sessionSerializeValue(tls, uintptr(0), *(*uintptr)(unsafe.Pointer(bp + 56)), bp+64)
	if !(rc != SQLITE_OK) {
		goto __22
	}
	goto error_out
__22:
	;
	goto __17
__17:
	i++
	goto __16
	goto __18
__18:
	;
	pC = sessionMalloc64(tls, pSession, *(*Sqlite3_int64)(unsafe.Pointer(bp + 64)))
	if !!(pC != 0) {
		goto __23
	}
	rc = SQLITE_NOMEM
	goto error_out
	goto __24
__23:
	libc.Xmemset(tls, pC, 0, uint64(unsafe.Sizeof(SessionChange{})))
	(*SessionChange)(unsafe.Pointer(pC)).FaRecord = pC + 1*32
__24:
	;
	*(*Sqlite3_int64)(unsafe.Pointer(bp + 64)) = int64(0)
	i = 0
__25:
	if !(i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol) {
		goto __27
	}
	*(*uintptr)(unsafe.Pointer(bp + 72)) = uintptr(0)
	if !(op != SQLITE_INSERT) {
		goto __28
	}
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp+72)
	goto __29
__28:
	if !(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i))) != 0) {
		goto __30
	}
	(*struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx, i, bp+72)
__30:
	;
__29:
	;
	sessionSerializeValue(tls, (*SessionChange)(unsafe.Pointer(pC)).FaRecord+uintptr(*(*Sqlite3_int64)(unsafe.Pointer(bp + 64))), *(*uintptr)(unsafe.Pointer(bp + 72)), bp+64)
	goto __26
__26:
	i++
	goto __25
	goto __27
__27:
	;
	if !((*Sqlite3_session)(unsafe.Pointer(pSession)).FbIndirect != 0 || (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx) != 0) {
		goto __31
	}
	(*SessionChange)(unsafe.Pointer(pC)).FbIndirect = U8(1)
__31:
	;
	(*SessionChange)(unsafe.Pointer(pC)).FnRecord = int32(*(*Sqlite3_int64)(unsafe.Pointer(bp + 64)))
	(*SessionChange)(unsafe.Pointer(pC)).Fop = U8(op)
	(*SessionChange)(unsafe.Pointer(pC)).FpNext = *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(*(*int32)(unsafe.Pointer(bp + 48)))*8))
	*(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(*(*int32)(unsafe.Pointer(bp + 48)))*8)) = pC

	goto __15
__14:
	if !((*SessionChange)(unsafe.Pointer(pC)).FbIndirect != 0) {
		goto __32
	}

	if !((*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx) == 0 &&
		(*Sqlite3_session)(unsafe.Pointer(pSession)).FbIndirect == 0) {
		goto __33
	}
	(*SessionChange)(unsafe.Pointer(pC)).FbIndirect = U8(0)
__33:
	;
__32:
	;
__15:
	;
	if !((*Sqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize != 0) {
		goto __34
	}
	rc = sessionUpdateMaxSize(tls, op, pSession, pTab, pC)
__34:
	;
__9:
	;
error_out:
	if !((*SessionTable)(unsafe.Pointer(pTab)).FbStat1 != 0) {
		goto __35
	}
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook = (*SessionStat1Ctx)(unsafe.Pointer(bp)).Fhook
__35:
	;
	if !(rc != SQLITE_OK) {
		goto __36
	}
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Frc = rc
__36:
}

func sessionFindTable(tls *libc.TLS, pSession uintptr, zName uintptr, ppTab uintptr) int32 {
	var rc int32 = SQLITE_OK
	var nName int32 = Xsqlite3Strlen30(tls, zName)
	var pRet uintptr

	for pRet = (*Sqlite3_session)(unsafe.Pointer(pSession)).FpTable; pRet != 0; pRet = (*SessionTable)(unsafe.Pointer(pRet)).FpNext {
		if 0 == Xsqlite3_strnicmp(tls, (*SessionTable)(unsafe.Pointer(pRet)).FzName, zName, nName+1) {
			break
		}
	}

	if pRet == uintptr(0) && (*Sqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach != 0 {
		if (*Sqlite3_session)(unsafe.Pointer(pSession)).FxTableFilter == uintptr(0) ||
			(*struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Sqlite3_session)(unsafe.Pointer(pSession)).FxTableFilter})).f(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).FpFilterCtx, zName) != 0 {
			rc = Xsqlite3session_attach(tls, pSession, zName)
			if rc == SQLITE_OK {
				pRet = (*Sqlite3_session)(unsafe.Pointer(pSession)).FpTable
				for pRet != 0 && (*SessionTable)(unsafe.Pointer(pRet)).FpNext != 0 {
					pRet = (*SessionTable)(unsafe.Pointer(pRet)).FpNext
				}

			}
		}
	}

	*(*uintptr)(unsafe.Pointer(ppTab)) = pRet
	return rc
}

func xPreUpdate(tls *libc.TLS, pCtx uintptr, db uintptr, op int32, zDb uintptr, zName uintptr, iKey1 Sqlite3_int64, iKey2 Sqlite3_int64) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pSession uintptr
	var nDb int32 = Xsqlite3Strlen30(tls, zDb)

	_ = iKey1
	_ = iKey2

	for pSession = pCtx; pSession != 0; pSession = (*Sqlite3_session)(unsafe.Pointer(pSession)).FpNext {
		if (*Sqlite3_session)(unsafe.Pointer(pSession)).FbEnable == 0 {
			continue
		}
		if (*Sqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
			continue
		}
		if Xsqlite3_strnicmp(tls, zDb, (*Sqlite3_session)(unsafe.Pointer(pSession)).FzDb, nDb+1) != 0 {
			continue
		}

		(*Sqlite3_session)(unsafe.Pointer(pSession)).Frc = sessionFindTable(tls, pSession, zName, bp)
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
			sessionPreupdateOneChange(tls, op, pSession, *(*uintptr)(unsafe.Pointer(bp)))
			if op == SQLITE_UPDATE {
				sessionPreupdateOneChange(tls, SQLITE_INSERT, pSession, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
	}
}

func sessionPreupdateOld(tls *libc.TLS, pCtx uintptr, iVal int32, ppVal uintptr) int32 {
	return Xsqlite3_preupdate_old(tls, pCtx, iVal, ppVal)
}

func sessionPreupdateNew(tls *libc.TLS, pCtx uintptr, iVal int32, ppVal uintptr) int32 {
	return Xsqlite3_preupdate_new(tls, pCtx, iVal, ppVal)
}

func sessionPreupdateCount(tls *libc.TLS, pCtx uintptr) int32 {
	return Xsqlite3_preupdate_count(tls, pCtx)
}

func sessionPreupdateDepth(tls *libc.TLS, pCtx uintptr) int32 {
	return Xsqlite3_preupdate_depth(tls, pCtx)
}

func sessionPreupdateHooks(tls *libc.TLS, pSession uintptr) {
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx = (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	}{sessionPreupdateOld}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	}{sessionPreupdateNew}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{sessionPreupdateCount}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{sessionPreupdateDepth}))
}

type SessionDiffCtx1 = struct {
	FpStmt       uintptr
	FnOldOff     int32
	F__ccgo_pad1 [4]byte
}

type SessionDiffCtx = SessionDiffCtx1

func sessionDiffOld(tls *libc.TLS, pCtx uintptr, iVal int32, ppVal uintptr) int32 {
	var p uintptr = pCtx
	*(*uintptr)(unsafe.Pointer(ppVal)) = Xsqlite3_column_value(tls, (*SessionDiffCtx)(unsafe.Pointer(p)).FpStmt, iVal+(*SessionDiffCtx)(unsafe.Pointer(p)).FnOldOff)
	return SQLITE_OK
}

func sessionDiffNew(tls *libc.TLS, pCtx uintptr, iVal int32, ppVal uintptr) int32 {
	var p uintptr = pCtx
	*(*uintptr)(unsafe.Pointer(ppVal)) = Xsqlite3_column_value(tls, (*SessionDiffCtx)(unsafe.Pointer(p)).FpStmt, iVal)
	return SQLITE_OK
}

func sessionDiffCount(tls *libc.TLS, pCtx uintptr) int32 {
	var p uintptr = pCtx
	if (*SessionDiffCtx)(unsafe.Pointer(p)).FnOldOff != 0 {
		return (*SessionDiffCtx)(unsafe.Pointer(p)).FnOldOff
	}
	return Xsqlite3_column_count(tls, (*SessionDiffCtx)(unsafe.Pointer(p)).FpStmt)
}

func sessionDiffDepth(tls *libc.TLS, pCtx uintptr) int32 {
	_ = pCtx
	return 0
}

func sessionDiffHooks(tls *libc.TLS, pSession uintptr, pDiffCtx uintptr) {
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx = pDiffCtx
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxOld = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	}{sessionDiffOld}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxNew = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, uintptr) int32
	}{sessionDiffNew}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxCount = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{sessionDiffCount}))
	(*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FxDepth = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{sessionDiffDepth}))
}

func sessionExprComparePK(tls *libc.TLS, nCol int32, zDb1 uintptr, zDb2 uintptr, zTab uintptr, azCol uintptr, abPK uintptr) uintptr {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var i int32
	var zSep uintptr = ts + 1636
	var zRet uintptr = uintptr(0)

	for i = 0; i < nCol; i++ {
		if *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
			zRet = Xsqlite3_mprintf(tls, ts+39455,
				libc.VaList(bp, zRet, zSep, zDb1, zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*8)), zDb2, zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*8))))
			zSep = ts + 25874
			if zRet == uintptr(0) {
				break
			}
		}
	}

	return zRet
}

func sessionExprCompareOther(tls *libc.TLS, nCol int32, zDb1 uintptr, zDb2 uintptr, zTab uintptr, azCol uintptr, abPK uintptr) uintptr {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var i int32
	var zSep uintptr = ts + 1636
	var zRet uintptr = uintptr(0)
	var bHave int32 = 0

	for i = 0; i < nCol; i++ {
		if int32(*(*U8)(unsafe.Pointer(abPK + uintptr(i)))) == 0 {
			bHave = 1
			zRet = Xsqlite3_mprintf(tls,
				ts+39489,
				libc.VaList(bp, zRet, zSep, zDb1, zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*8)), zDb2, zTab, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*8))))
			zSep = ts + 39530
			if zRet == uintptr(0) {
				break
			}
		}
	}

	if bHave == 0 {
		zRet = Xsqlite3_mprintf(tls, ts+10734, 0)
	}

	return zRet
}

func sessionSelectFindNew(tls *libc.TLS, zDb1 uintptr, zDb2 uintptr, zTbl uintptr, zExpr uintptr) uintptr {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	var zRet uintptr = Xsqlite3_mprintf(tls,
		ts+39535,
		libc.VaList(bp, zDb1, zTbl, zDb2, zTbl, zExpr))
	return zRet
}

func sessionDiffFindNew(tls *libc.TLS, op int32, pSession uintptr, pTab uintptr, zDb1 uintptr, zDb2 uintptr, zExpr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var zStmt uintptr = sessionSelectFindNew(tls, zDb1, zDb2, (*SessionTable)(unsafe.Pointer(pTab)).FzName, zExpr)

	if zStmt == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		rc = Xsqlite3_prepare(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb, zStmt, -1, bp, uintptr(0))
		if rc == SQLITE_OK {
			var pDiffCtx uintptr = (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx
			(*SessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FpStmt = *(*uintptr)(unsafe.Pointer(bp))
			(*SessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FnOldOff = 0
			for SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				sessionPreupdateOneChange(tls, op, pSession, pTab)
			}
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		Xsqlite3_free(tls, zStmt)
	}

	return rc
}

func sessionDiffFindModified(tls *libc.TLS, pSession uintptr, pTab uintptr, zFrom uintptr, zExpr uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var rc int32 = SQLITE_OK

	var zExpr2 uintptr = sessionExprCompareOther(tls, (*SessionTable)(unsafe.Pointer(pTab)).FnCol,
		(*Sqlite3_session)(unsafe.Pointer(pSession)).FzDb, zFrom, (*SessionTable)(unsafe.Pointer(pTab)).FzName, (*SessionTable)(unsafe.Pointer(pTab)).FazCol, (*SessionTable)(unsafe.Pointer(pTab)).FabPK)
	if zExpr2 == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		var zStmt uintptr = Xsqlite3_mprintf(tls,
			ts+39613,
			libc.VaList(bp, (*Sqlite3_session)(unsafe.Pointer(pSession)).FzDb, (*SessionTable)(unsafe.Pointer(pTab)).FzName, zFrom, (*SessionTable)(unsafe.Pointer(pTab)).FzName, zExpr, zExpr2))
		if zStmt == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			rc = Xsqlite3_prepare(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb, zStmt, -1, bp+48, uintptr(0))

			if rc == SQLITE_OK {
				var pDiffCtx uintptr = (*Sqlite3_session)(unsafe.Pointer(pSession)).Fhook.FpCtx
				(*SessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FpStmt = *(*uintptr)(unsafe.Pointer(bp + 48))
				(*SessionDiffCtx)(unsafe.Pointer(pDiffCtx)).FnOldOff = (*SessionTable)(unsafe.Pointer(pTab)).FnCol
				for SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 48))) {
					sessionPreupdateOneChange(tls, SQLITE_UPDATE, pSession, pTab)
				}
				rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 48)))
			}
			Xsqlite3_free(tls, zStmt)
		}
	}

	return rc
}

func Xsqlite3session_diff(tls *libc.TLS, pSession uintptr, zFrom uintptr, zTbl uintptr, pzErrMsg uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var zDb uintptr
	var rc int32

	var i int32
	var bHasPk int32
	var bMismatch int32

	var zExpr uintptr
	var db uintptr

	zDb = (*Sqlite3_session)(unsafe.Pointer(pSession)).FzDb
	rc = (*Sqlite3_session)(unsafe.Pointer(pSession)).Frc

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(SessionDiffCtx{})))
	sessionDiffHooks(tls, pSession, bp)

	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	if !(pzErrMsg != 0) {
		goto __1
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = uintptr(0)
__1:
	;
	if !(rc == SQLITE_OK) {
		goto __2
	}
	zExpr = uintptr(0)
	db = (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb

	rc = sessionFindTable(tls, pSession, zTbl, bp+16)
	if !(*(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0)) {
		goto __3
	}
	goto diff_out
__3:
	;
	if !(sessionInitTable(tls, pSession, *(*uintptr)(unsafe.Pointer(bp + 16))) != 0) {
		goto __4
	}
	rc = (*Sqlite3_session)(unsafe.Pointer(pSession)).Frc
	goto diff_out
__4:
	;
	if !(rc == SQLITE_OK) {
		goto __5
	}
	bHasPk = 0
	bMismatch = 0
	*(*uintptr)(unsafe.Pointer(bp + 32)) = uintptr(0)
	rc = sessionTableInfo(tls, uintptr(0), db, zFrom, zTbl, bp+24, uintptr(0), bp+32, bp+40)
	if !(rc == SQLITE_OK) {
		goto __6
	}
	if !((*SessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FnCol != *(*int32)(unsafe.Pointer(bp + 24))) {
		goto __7
	}
	bMismatch = 1
	goto __8
__7:
	i = 0
__9:
	if !(i < *(*int32)(unsafe.Pointer(bp + 24))) {
		goto __11
	}
	if !(int32(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FabPK + uintptr(i)))) != int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 40)) + uintptr(i))))) {
		goto __12
	}
	bMismatch = 1
__12:
	;
	if !(Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 32)) + uintptr(i)*8)), *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FazCol + uintptr(i)*8))) != 0) {
		goto __13
	}
	bMismatch = 1
__13:
	;
	if !(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 40)) + uintptr(i))) != 0) {
		goto __14
	}
	bHasPk = 1
__14:
	;
	goto __10
__10:
	i++
	goto __9
	goto __11
__11:
	;
__8:
	;
__6:
	;
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 32)))
	if !(bMismatch != 0) {
		goto __15
	}
	if !(pzErrMsg != 0) {
		goto __16
	}
	*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+39666, 0)
__16:
	;
	rc = SQLITE_SCHEMA
__15:
	;
	if !(bHasPk == 0) {
		goto __17
	}

	goto diff_out
__17:
	;
__5:
	;
	if !(rc == SQLITE_OK) {
		goto __18
	}
	zExpr = sessionExprComparePK(tls, (*SessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FnCol,
		zDb, zFrom, (*SessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FzName, (*SessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FazCol, (*SessionTable)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FabPK)
__18:
	;
	if !(rc == SQLITE_OK) {
		goto __19
	}
	rc = sessionDiffFindNew(tls, SQLITE_INSERT, pSession, *(*uintptr)(unsafe.Pointer(bp + 16)), zDb, zFrom, zExpr)
__19:
	;
	if !(rc == SQLITE_OK) {
		goto __20
	}
	rc = sessionDiffFindNew(tls, SQLITE_DELETE, pSession, *(*uintptr)(unsafe.Pointer(bp + 16)), zFrom, zDb, zExpr)
__20:
	;
	if !(rc == SQLITE_OK) {
		goto __21
	}
	rc = sessionDiffFindModified(tls, pSession, *(*uintptr)(unsafe.Pointer(bp + 16)), zFrom, zExpr)
__21:
	;
	Xsqlite3_free(tls, zExpr)
__2:
	;
diff_out:
	sessionPreupdateHooks(tls, pSession)
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return rc
}

func Xsqlite3session_create(tls *libc.TLS, db uintptr, zDb uintptr, ppSession uintptr) int32 {
	var pNew uintptr
	var pOld uintptr
	var nDb int32 = Xsqlite3Strlen30(tls, zDb)

	*(*uintptr)(unsafe.Pointer(ppSession)) = uintptr(0)

	pNew = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Sqlite3_session{}))+uint64(nDb)+uint64(1))
	if !(pNew != 0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Sqlite3_session{})))
	(*Sqlite3_session)(unsafe.Pointer(pNew)).Fdb = db
	(*Sqlite3_session)(unsafe.Pointer(pNew)).FzDb = pNew + 1*136
	(*Sqlite3_session)(unsafe.Pointer(pNew)).FbEnable = 1
	libc.Xmemcpy(tls, (*Sqlite3_session)(unsafe.Pointer(pNew)).FzDb, zDb, uint64(nDb+1))
	sessionPreupdateHooks(tls, pNew)

	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	pOld = Xsqlite3_preupdate_hook(tls, db, *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, Sqlite3_int64, Sqlite3_int64)
	}{xPreUpdate})), pNew)
	(*Sqlite3_session)(unsafe.Pointer(pNew)).FpNext = pOld
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))

	*(*uintptr)(unsafe.Pointer(ppSession)) = pNew
	return SQLITE_OK
}

func sessionDeleteTable(tls *libc.TLS, pSession uintptr, pList uintptr) {
	var pNext uintptr
	var pTab uintptr

	for pTab = pList; pTab != 0; pTab = pNext {
		var i int32
		pNext = (*SessionTable)(unsafe.Pointer(pTab)).FpNext
		for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnChange; i++ {
			var p uintptr
			var pNextChange uintptr
			for p = *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*8)); p != 0; p = pNextChange {
				pNextChange = (*SessionChange)(unsafe.Pointer(p)).FpNext
				sessionFree(tls, pSession, p)
			}
		}
		sessionFree(tls, pSession, (*SessionTable)(unsafe.Pointer(pTab)).FazCol)
		sessionFree(tls, pSession, (*SessionTable)(unsafe.Pointer(pTab)).FapChange)
		sessionFree(tls, pSession, pTab)
	}
}

func Xsqlite3session_delete(tls *libc.TLS, pSession uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var db uintptr = (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb

	var pp uintptr

	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	*(*uintptr)(unsafe.Pointer(bp)) = Xsqlite3_preupdate_hook(tls, db, uintptr(0), uintptr(0))
	for pp = bp; *(*uintptr)(unsafe.Pointer(pp)) != uintptr(0); pp = *(*uintptr)(unsafe.Pointer(pp)) + 80 {
		if *(*uintptr)(unsafe.Pointer(pp)) == pSession {
			*(*uintptr)(unsafe.Pointer(pp)) = (*Sqlite3_session)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				Xsqlite3_preupdate_hook(tls, db, *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, Sqlite3_int64, Sqlite3_int64)
				}{xPreUpdate})), *(*uintptr)(unsafe.Pointer(bp)))
			}
			break
		}
	}
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	Xsqlite3ValueFree(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob)

	sessionDeleteTable(tls, pSession, (*Sqlite3_session)(unsafe.Pointer(pSession)).FpTable)

	Xsqlite3_free(tls, pSession)
}

func Xsqlite3session_table_filter(tls *libc.TLS, pSession uintptr, xFilter uintptr, pCtx uintptr) {
	(*Sqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = 1
	(*Sqlite3_session)(unsafe.Pointer(pSession)).FpFilterCtx = pCtx
	(*Sqlite3_session)(unsafe.Pointer(pSession)).FxTableFilter = xFilter
}

func Xsqlite3session_attach(tls *libc.TLS, pSession uintptr, zName uintptr) int32 {
	var rc int32 = SQLITE_OK
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))

	if !(zName != 0) {
		(*Sqlite3_session)(unsafe.Pointer(pSession)).FbAutoAttach = 1
	} else {
		var pTab uintptr
		var nName int32

		nName = Xsqlite3Strlen30(tls, zName)
		for pTab = (*Sqlite3_session)(unsafe.Pointer(pSession)).FpTable; pTab != 0; pTab = (*SessionTable)(unsafe.Pointer(pTab)).FpNext {
			if 0 == Xsqlite3_strnicmp(tls, (*SessionTable)(unsafe.Pointer(pTab)).FzName, zName, nName+1) {
				break
			}
		}

		if !(pTab != 0) {
			var nByte int32 = int32(uint64(unsafe.Sizeof(SessionTable{})) + uint64(nName) + uint64(1))
			pTab = sessionMalloc64(tls, pSession, int64(nByte))
			if !(pTab != 0) {
				rc = SQLITE_NOMEM
			} else {
				var ppTab uintptr
				libc.Xmemset(tls, pTab, 0, uint64(unsafe.Sizeof(SessionTable{})))
				(*SessionTable)(unsafe.Pointer(pTab)).FzName = pTab + 1*56
				libc.Xmemcpy(tls, (*SessionTable)(unsafe.Pointer(pTab)).FzName, zName, uint64(nName+1))
				for ppTab = pSession + 88; *(*uintptr)(unsafe.Pointer(ppTab)) != 0; ppTab = *(*uintptr)(unsafe.Pointer(ppTab)) {
				}
				*(*uintptr)(unsafe.Pointer(ppTab)) = pTab
			}
		}
	}

	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return rc
}

func sessionBufferGrow(tls *libc.TLS, p uintptr, nByte I64, pRc uintptr) int32 {
	var nReq I64 = I64((*SessionBuffer)(unsafe.Pointer(p)).FnBuf) + nByte
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK && nReq > I64((*SessionBuffer)(unsafe.Pointer(p)).FnAlloc) {
		var aNew uintptr
		var nNew I64
		if (*SessionBuffer)(unsafe.Pointer(p)).FnAlloc != 0 {
			nNew = int64((*SessionBuffer)(unsafe.Pointer(p)).FnAlloc)
		} else {
			nNew = int64(128)
		}

		for __ccgo := true; __ccgo; __ccgo = nNew < nReq {
			nNew = nNew * int64(2)
		}

		if nNew > int64(0x7FFFFF00-1) {
			nNew = int64(0x7FFFFF00 - 1)
			if nNew < nReq {
				*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
				return 1
			}
		}

		aNew = Xsqlite3_realloc64(tls, (*SessionBuffer)(unsafe.Pointer(p)).FaBuf, uint64(nNew))
		if uintptr(0) == aNew {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
		} else {
			(*SessionBuffer)(unsafe.Pointer(p)).FaBuf = aNew
			(*SessionBuffer)(unsafe.Pointer(p)).FnAlloc = int32(nNew)
		}
	}
	return libc.Bool32(*(*int32)(unsafe.Pointer(pRc)) != SQLITE_OK)
}

func sessionAppendValue(tls *libc.TLS, p uintptr, pVal uintptr, pRc uintptr) {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	*(*int32)(unsafe.Pointer(bp + 8)) = *(*int32)(unsafe.Pointer(pRc))
	if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
		*(*Sqlite3_int64)(unsafe.Pointer(bp)) = int64(0)
		*(*int32)(unsafe.Pointer(bp + 8)) = sessionSerializeValue(tls, uintptr(0), pVal, bp)
		sessionBufferGrow(tls, p, *(*Sqlite3_int64)(unsafe.Pointer(bp)), bp+8)
		if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 8)) = sessionSerializeValue(tls, (*SessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*SessionBuffer)(unsafe.Pointer(p)).FnBuf), pVal, uintptr(0))
			*(*int32)(unsafe.Pointer(p + 8)) += int32(*(*Sqlite3_int64)(unsafe.Pointer(bp)))
		} else {
			*(*int32)(unsafe.Pointer(pRc)) = *(*int32)(unsafe.Pointer(bp + 8))
		}
	}
}

func sessionAppendByte(tls *libc.TLS, p uintptr, v U8, pRc uintptr) {
	if 0 == sessionBufferGrow(tls, p, int64(1), pRc) {
		*(*U8)(unsafe.Pointer((*SessionBuffer)(unsafe.Pointer(p)).FaBuf + uintptr(libc.PostIncInt32(&(*SessionBuffer)(unsafe.Pointer(p)).FnBuf, 1)))) = v
	}
}

func sessionAppendVarint(tls *libc.TLS, p uintptr, v int32, pRc uintptr) {
	if 0 == sessionBufferGrow(tls, p, int64(9), pRc) {
		*(*int32)(unsafe.Pointer(p + 8)) += sessionVarintPut(tls, (*SessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*SessionBuffer)(unsafe.Pointer(p)).FnBuf), v)
	}
}

func sessionAppendBlob(tls *libc.TLS, p uintptr, aBlob uintptr, nBlob int32, pRc uintptr) {
	if nBlob > 0 && 0 == sessionBufferGrow(tls, p, int64(nBlob), pRc) {
		libc.Xmemcpy(tls, (*SessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*SessionBuffer)(unsafe.Pointer(p)).FnBuf), aBlob, uint64(nBlob))
		*(*int32)(unsafe.Pointer(p + 8)) += nBlob
	}
}

func sessionAppendStr(tls *libc.TLS, p uintptr, zStr uintptr, pRc uintptr) {
	var nStr int32 = Xsqlite3Strlen30(tls, zStr)
	if 0 == sessionBufferGrow(tls, p, int64(nStr), pRc) {
		libc.Xmemcpy(tls, (*SessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*SessionBuffer)(unsafe.Pointer(p)).FnBuf), zStr, uint64(nStr))
		*(*int32)(unsafe.Pointer(p + 8)) += nStr
	}
}

func sessionAppendInteger(tls *libc.TLS, p uintptr, iVal int32, pRc uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	Xsqlite3_snprintf(tls, int32(uint64(unsafe.Sizeof([24]uint8{}))-uint64(1)), bp+8, ts+7843, libc.VaList(bp, iVal))
	sessionAppendStr(tls, p, bp+8, pRc)
}

func sessionAppendIdent(tls *libc.TLS, p uintptr, zStr uintptr, pRc uintptr) {
	var nStr int32 = Xsqlite3Strlen30(tls, zStr)*2 + 2 + 1
	if 0 == sessionBufferGrow(tls, p, int64(nStr), pRc) {
		var zOut uintptr = (*SessionBuffer)(unsafe.Pointer(p)).FaBuf + uintptr((*SessionBuffer)(unsafe.Pointer(p)).FnBuf)
		var zIn uintptr = zStr
		*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8('"')
		for *(*uint8)(unsafe.Pointer(zIn)) != 0 {
			if int32(*(*uint8)(unsafe.Pointer(zIn))) == '"' {
				*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8('"')
			}
			*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = *(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))
		}
		*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8('"')
		(*SessionBuffer)(unsafe.Pointer(p)).FnBuf = int32((int64(zOut) - int64((*SessionBuffer)(unsafe.Pointer(p)).FaBuf)) / 1)
	}
}

func sessionAppendCol(tls *libc.TLS, p uintptr, pStmt uintptr, iCol int32, pRc uintptr) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var eType int32 = Xsqlite3_column_type(tls, pStmt, iCol)
		sessionAppendByte(tls, p, U8(eType), pRc)
		if eType == SQLITE_INTEGER || eType == SQLITE_FLOAT {
			if eType == SQLITE_INTEGER {
				*(*Sqlite3_int64)(unsafe.Pointer(bp)) = Xsqlite3_column_int64(tls, pStmt, iCol)
			} else {
				*(*float64)(unsafe.Pointer(bp + 8)) = Xsqlite3_column_double(tls, pStmt, iCol)
				libc.Xmemcpy(tls, bp, bp+8, uint64(8))
			}
			sessionPutI64(tls, bp+16, *(*Sqlite3_int64)(unsafe.Pointer(bp)))
			sessionAppendBlob(tls, p, bp+16, 8, pRc)
		}
		if eType == SQLITE_BLOB || eType == SQLITE_TEXT {
			var z uintptr
			var nByte int32
			if eType == 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 == SQLITE_BLOB && nByte == 0 {
				sessionAppendVarint(tls, p, nByte, pRc)
				sessionAppendBlob(tls, p, z, nByte, pRc)
			} else {
				*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
			}
		}
	}
}

func sessionAppendUpdate(tls *libc.TLS, pBuf uintptr, bPatchset int32, pStmt uintptr, p uintptr, abPK uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*SessionBuffer)(unsafe.Pointer(bp + 32)) = SessionBuffer{}
	var bNoop int32 = 1
	var nRewind int32 = (*SessionBuffer)(unsafe.Pointer(pBuf)).FnBuf
	var i int32
	var pCsr uintptr = (*SessionChange)(unsafe.Pointer(p)).FaRecord

	sessionAppendByte(tls, pBuf, uint8(SQLITE_UPDATE), bp)
	sessionAppendByte(tls, pBuf, (*SessionChange)(unsafe.Pointer(p)).FbIndirect, bp)
	for i = 0; i < Xsqlite3_column_count(tls, pStmt); i++ {
		var bChanged int32 = 0
		var nAdvance int32
		var eType int32 = int32(*(*U8)(unsafe.Pointer(pCsr)))
		switch eType {
		case SQLITE_NULL:
			nAdvance = 1
			if Xsqlite3_column_type(tls, pStmt, i) != SQLITE_NULL {
				bChanged = 1
			}
			break

		case SQLITE_FLOAT:
			fallthrough
		case SQLITE_INTEGER:
			{
				nAdvance = 9
				if eType == Xsqlite3_column_type(tls, pStmt, i) {
					*(*Sqlite3_int64)(unsafe.Pointer(bp + 16)) = sessionGetI64(tls, pCsr+1)
					if eType == SQLITE_INTEGER {
						if *(*Sqlite3_int64)(unsafe.Pointer(bp + 16)) == Xsqlite3_column_int64(tls, pStmt, i) {
							break
						}
					} else {
						libc.Xmemcpy(tls, bp+8, bp+16, uint64(8))
						if *(*float64)(unsafe.Pointer(bp + 8)) == Xsqlite3_column_double(tls, pStmt, i) {
							break
						}
					}
				}
				bChanged = 1
				break

			}

		default:
			{
				var nHdr int32 = 1 + sessionVarintGet(tls, pCsr+1, bp+24)

				nAdvance = nHdr + *(*int32)(unsafe.Pointer(bp + 24))
				if eType == Xsqlite3_column_type(tls, pStmt, i) &&
					*(*int32)(unsafe.Pointer(bp + 24)) == Xsqlite3_column_bytes(tls, pStmt, i) &&
					(*(*int32)(unsafe.Pointer(bp + 24)) == 0 || 0 == libc.Xmemcmp(tls, pCsr+uintptr(nHdr), Xsqlite3_column_blob(tls, pStmt, i), uint64(*(*int32)(unsafe.Pointer(bp + 24))))) {
					break
				}
				bChanged = 1

			}
		}

		if bChanged != 0 {
			bNoop = 0
		}

		if bPatchset == 0 {
			if bChanged != 0 || *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				sessionAppendBlob(tls, pBuf, pCsr, nAdvance, bp)
			} else {
				sessionAppendByte(tls, pBuf, uint8(0), bp)
			}
		}

		if bChanged != 0 || bPatchset != 0 && *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
			sessionAppendCol(tls, bp+32, pStmt, i, bp)
		} else {
			sessionAppendByte(tls, bp+32, uint8(0), bp)
		}

		pCsr += uintptr(nAdvance)
	}

	if bNoop != 0 {
		(*SessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = nRewind
	} else {
		sessionAppendBlob(tls, pBuf, (*SessionBuffer)(unsafe.Pointer(bp+32)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp+32)).FnBuf, bp)
	}
	Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp+32)).FaBuf)

	return *(*int32)(unsafe.Pointer(bp))
}

func sessionAppendDelete(tls *libc.TLS, pBuf uintptr, bPatchset int32, p uintptr, nCol int32, abPK uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK

	sessionAppendByte(tls, pBuf, uint8(SQLITE_DELETE), bp)
	sessionAppendByte(tls, pBuf, (*SessionChange)(unsafe.Pointer(p)).FbIndirect, bp)

	if bPatchset == 0 {
		sessionAppendBlob(tls, pBuf, (*SessionChange)(unsafe.Pointer(p)).FaRecord, (*SessionChange)(unsafe.Pointer(p)).FnRecord, bp)
	} else {
		var i int32
		var a uintptr = (*SessionChange)(unsafe.Pointer(p)).FaRecord
		for i = 0; i < nCol; i++ {
			var pStart uintptr = a
			var eType int32 = int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&a, 1))))

			switch eType {
			case 0:
				fallthrough
			case SQLITE_NULL:
				break
				fallthrough

			case SQLITE_FLOAT:
				fallthrough
			case SQLITE_INTEGER:
				a += uintptr(8)
				break
				fallthrough

			default:
				{
					a += uintptr(sessionVarintGet(tls, a, bp+4))
					a += uintptr(*(*int32)(unsafe.Pointer(bp + 4)))
					break

				}
			}
			if *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				sessionAppendBlob(tls, pBuf, pStart, int32((int64(a)-int64(pStart))/1), bp)
			}
		}

	}

	return *(*int32)(unsafe.Pointer(bp))
}

func sessionSelectStmt(tls *libc.TLS, db uintptr, zDb uintptr, zTab uintptr, nCol int32, azCol uintptr, abPK uintptr, ppStmt uintptr) int32 {
	bp := tls.Alloc(28)
	defer tls.Free(28)

	*(*int32)(unsafe.Pointer(bp + 24)) = SQLITE_OK
	var zSql uintptr = uintptr(0)
	var nSql int32 = -1

	if 0 == Xsqlite3_stricmp(tls, ts+14732, zTab) {
		zSql = Xsqlite3_mprintf(tls,
			ts+39693, libc.VaList(bp, zDb))
		if zSql == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp + 24)) = SQLITE_NOMEM
		}
	} else {
		var i int32
		var zSep uintptr = ts + 1636
		*(*SessionBuffer)(unsafe.Pointer(bp + 8)) = SessionBuffer{}

		sessionAppendStr(tls, bp+8, ts+39803, bp+24)
		sessionAppendIdent(tls, bp+8, zDb, bp+24)
		sessionAppendStr(tls, bp+8, ts+1649, bp+24)
		sessionAppendIdent(tls, bp+8, zTab, bp+24)
		sessionAppendStr(tls, bp+8, ts+39818, bp+24)
		for i = 0; i < nCol; i++ {
			if *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
				sessionAppendStr(tls, bp+8, zSep, bp+24)
				sessionAppendIdent(tls, bp+8, *(*uintptr)(unsafe.Pointer(azCol + uintptr(i)*8)), bp+24)
				sessionAppendStr(tls, bp+8, ts+39826, bp+24)
				sessionAppendInteger(tls, bp+8, i+1, bp+24)
				zSep = ts + 25874
			}
		}
		zSql = (*SessionBuffer)(unsafe.Pointer(bp + 8)).FaBuf
		nSql = (*SessionBuffer)(unsafe.Pointer(bp + 8)).FnBuf
	}

	if *(*int32)(unsafe.Pointer(bp + 24)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 24)) = Xsqlite3_prepare_v2(tls, db, zSql, nSql, ppStmt, uintptr(0))
	}
	Xsqlite3_free(tls, zSql)
	return *(*int32)(unsafe.Pointer(bp + 24))
}

func sessionSelectBind(tls *libc.TLS, pSelect uintptr, nCol int32, abPK uintptr, pChange uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var i int32
	var rc int32 = SQLITE_OK
	var a uintptr = (*SessionChange)(unsafe.Pointer(pChange)).FaRecord

	for i = 0; i < nCol && rc == SQLITE_OK; i++ {
		var eType int32 = int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&a, 1))))

		switch eType {
		case 0:
			fallthrough
		case SQLITE_NULL:
			break

		case SQLITE_INTEGER:
			{
				if *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
					var iVal I64 = sessionGetI64(tls, a)
					rc = Xsqlite3_bind_int64(tls, pSelect, i+1, iVal)
				}
				a += uintptr(8)
				break

			}

		case SQLITE_FLOAT:
			{
				if *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
					*(*I64)(unsafe.Pointer(bp + 8)) = sessionGetI64(tls, a)
					libc.Xmemcpy(tls, bp, bp+8, uint64(8))
					rc = Xsqlite3_bind_double(tls, pSelect, i+1, *(*float64)(unsafe.Pointer(bp)))
				}
				a += uintptr(8)
				break

			}

		case SQLITE_TEXT:
			{
				a += uintptr(sessionVarintGet(tls, a, bp+16))
				if *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
					rc = Xsqlite3_bind_text(tls, pSelect, i+1, a, *(*int32)(unsafe.Pointer(bp + 16)), libc.UintptrFromInt32(-1))
				}
				a += uintptr(*(*int32)(unsafe.Pointer(bp + 16)))
				break

			}

		default:
			{
				a += uintptr(sessionVarintGet(tls, a, bp+20))
				if *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
					rc = Xsqlite3_bind_blob(tls, pSelect, i+1, a, *(*int32)(unsafe.Pointer(bp + 20)), libc.UintptrFromInt32(-1))
				}
				a += uintptr(*(*int32)(unsafe.Pointer(bp + 20)))
				break

			}
		}
	}

	return rc
}

func sessionAppendTableHdr(tls *libc.TLS, pBuf uintptr, bPatchset int32, pTab uintptr, pRc uintptr) {
	sessionAppendByte(tls, pBuf, func() uint8 {
		if bPatchset != 0 {
			return uint8('P')
		}
		return uint8('T')
	}(), pRc)
	sessionAppendVarint(tls, pBuf, (*SessionTable)(unsafe.Pointer(pTab)).FnCol, pRc)
	sessionAppendBlob(tls, pBuf, (*SessionTable)(unsafe.Pointer(pTab)).FabPK, (*SessionTable)(unsafe.Pointer(pTab)).FnCol, pRc)
	sessionAppendBlob(tls, pBuf, (*SessionTable)(unsafe.Pointer(pTab)).FzName, int32(libc.Xstrlen(tls, (*SessionTable)(unsafe.Pointer(pTab)).FzName))+1, pRc)
}

func sessionGenerateChangeset(tls *libc.TLS, pSession uintptr, bPatchset int32, xOutput uintptr, pOut uintptr, pnChangeset uintptr, ppChangeset uintptr) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var db uintptr = (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb
	var pTab uintptr
	*(*SessionBuffer)(unsafe.Pointer(bp + 24)) = SessionBuffer{}

	if xOutput == uintptr(0) {
		*(*int32)(unsafe.Pointer(pnChangeset)) = 0
		*(*uintptr)(unsafe.Pointer(ppChangeset)) = uintptr(0)
	}

	if (*Sqlite3_session)(unsafe.Pointer(pSession)).Frc != 0 {
		return (*Sqlite3_session)(unsafe.Pointer(pSession)).Frc
	}
	*(*int32)(unsafe.Pointer(bp + 40)) = Xsqlite3_exec(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb, ts+39832, uintptr(0), uintptr(0), uintptr(0))
	if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
		return *(*int32)(unsafe.Pointer(bp + 40))
	}

	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))

	for pTab = (*Sqlite3_session)(unsafe.Pointer(pSession)).FpTable; *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && pTab != 0; pTab = (*SessionTable)(unsafe.Pointer(pTab)).FpNext {
		if (*SessionTable)(unsafe.Pointer(pTab)).FnEntry != 0 {
			var zName uintptr = (*SessionTable)(unsafe.Pointer(pTab)).FzName
			*(*int32)(unsafe.Pointer(bp)) = 0
			*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
			var i int32
			*(*uintptr)(unsafe.Pointer(bp + 48)) = uintptr(0)
			var nRewind int32 = (*SessionBuffer)(unsafe.Pointer(bp + 24)).FnBuf
			var nNoop int32

			*(*int32)(unsafe.Pointer(bp + 40)) = sessionTableInfo(tls, uintptr(0), db, (*Sqlite3_session)(unsafe.Pointer(pSession)).FzDb, zName, bp, uintptr(0), bp+8, bp+16)
			if !(*(*int32)(unsafe.Pointer(bp + 40)) != 0) && ((*SessionTable)(unsafe.Pointer(pTab)).FnCol != *(*int32)(unsafe.Pointer(bp)) || libc.Xmemcmp(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), (*SessionTable)(unsafe.Pointer(pTab)).FabPK, uint64(*(*int32)(unsafe.Pointer(bp)))) != 0) {
				*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_SCHEMA
			}

			sessionAppendTableHdr(tls, bp+24, bPatchset, pTab, bp+40)

			if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp + 40)) = sessionSelectStmt(tls,
					db, (*Sqlite3_session)(unsafe.Pointer(pSession)).FzDb, zName, *(*int32)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 8)), *(*uintptr)(unsafe.Pointer(bp + 16)), bp+48)
			}

			nNoop = (*SessionBuffer)(unsafe.Pointer(bp + 24)).FnBuf
			for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnChange && *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK; i++ {
				var p uintptr

				for p = *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*8)); *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && p != 0; p = (*SessionChange)(unsafe.Pointer(p)).FpNext {
					*(*int32)(unsafe.Pointer(bp + 40)) = sessionSelectBind(tls, *(*uintptr)(unsafe.Pointer(bp + 48)), *(*int32)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 16)), p)
					if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
						continue
					}
					if Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 48))) == SQLITE_ROW {
						if int32((*SessionChange)(unsafe.Pointer(p)).Fop) == SQLITE_INSERT {
							var iCol int32
							sessionAppendByte(tls, bp+24, uint8(SQLITE_INSERT), bp+40)
							sessionAppendByte(tls, bp+24, (*SessionChange)(unsafe.Pointer(p)).FbIndirect, bp+40)
							for iCol = 0; iCol < *(*int32)(unsafe.Pointer(bp)); iCol++ {
								sessionAppendCol(tls, bp+24, *(*uintptr)(unsafe.Pointer(bp + 48)), iCol, bp+40)
							}
						} else {
							*(*int32)(unsafe.Pointer(bp + 40)) = sessionAppendUpdate(tls, bp+24, bPatchset, *(*uintptr)(unsafe.Pointer(bp + 48)), p, *(*uintptr)(unsafe.Pointer(bp + 16)))
						}
					} else if int32((*SessionChange)(unsafe.Pointer(p)).Fop) != SQLITE_INSERT {
						*(*int32)(unsafe.Pointer(bp + 40)) = sessionAppendDelete(tls, bp+24, bPatchset, p, *(*int32)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(bp + 16)))
					}
					if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
						*(*int32)(unsafe.Pointer(bp + 40)) = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 48)))
					}

					if xOutput != 0 &&
						*(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK &&
						(*SessionBuffer)(unsafe.Pointer(bp+24)).FnBuf > nNoop &&
						(*SessionBuffer)(unsafe.Pointer(bp+24)).FnBuf > sessions_strm_chunk_size {
						*(*int32)(unsafe.Pointer(bp + 40)) = (*struct {
							f func(*libc.TLS, uintptr, uintptr, int32) int32
						})(unsafe.Pointer(&struct{ uintptr }{xOutput})).f(tls, pOut, (*SessionBuffer)(unsafe.Pointer(bp+24)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp+24)).FnBuf)
						nNoop = -1
						(*SessionBuffer)(unsafe.Pointer(bp + 24)).FnBuf = 0
					}

				}
			}

			Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 48)))
			if (*SessionBuffer)(unsafe.Pointer(bp+24)).FnBuf == nNoop {
				(*SessionBuffer)(unsafe.Pointer(bp + 24)).FnBuf = nRewind
			}
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
		if xOutput == uintptr(0) {
			*(*int32)(unsafe.Pointer(pnChangeset)) = (*SessionBuffer)(unsafe.Pointer(bp + 24)).FnBuf
			*(*uintptr)(unsafe.Pointer(ppChangeset)) = (*SessionBuffer)(unsafe.Pointer(bp + 24)).FaBuf
			(*SessionBuffer)(unsafe.Pointer(bp + 24)).FaBuf = uintptr(0)
		} else if (*SessionBuffer)(unsafe.Pointer(bp+24)).FnBuf > 0 {
			*(*int32)(unsafe.Pointer(bp + 40)) = (*struct {
				f func(*libc.TLS, uintptr, uintptr, int32) int32
			})(unsafe.Pointer(&struct{ uintptr }{xOutput})).f(tls, pOut, (*SessionBuffer)(unsafe.Pointer(bp+24)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp+24)).FnBuf)
		}
	}

	Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp+24)).FaBuf)
	Xsqlite3_exec(tls, db, ts+39852, uintptr(0), uintptr(0), uintptr(0))
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	return *(*int32)(unsafe.Pointer(bp + 40))
}

func Xsqlite3session_changeset(tls *libc.TLS, pSession uintptr, pnChangeset uintptr, ppChangeset uintptr) int32 {
	var rc int32

	if pnChangeset == uintptr(0) || ppChangeset == uintptr(0) {
		return SQLITE_MISUSE
	}
	rc = sessionGenerateChangeset(tls, pSession, 0, uintptr(0), uintptr(0), pnChangeset, ppChangeset)

	return rc
}

func Xsqlite3session_changeset_strm(tls *libc.TLS, pSession uintptr, xOutput uintptr, pOut uintptr) int32 {
	if xOutput == uintptr(0) {
		return SQLITE_MISUSE
	}
	return sessionGenerateChangeset(tls, pSession, 0, xOutput, pOut, uintptr(0), uintptr(0))
}

func Xsqlite3session_patchset_strm(tls *libc.TLS, pSession uintptr, xOutput uintptr, pOut uintptr) int32 {
	if xOutput == uintptr(0) {
		return SQLITE_MISUSE
	}
	return sessionGenerateChangeset(tls, pSession, 1, xOutput, pOut, uintptr(0), uintptr(0))
}

func Xsqlite3session_patchset(tls *libc.TLS, pSession uintptr, pnPatchset uintptr, ppPatchset uintptr) int32 {
	if pnPatchset == uintptr(0) || ppPatchset == uintptr(0) {
		return SQLITE_MISUSE
	}
	return sessionGenerateChangeset(tls, pSession, 1, uintptr(0), uintptr(0), pnPatchset, ppPatchset)
}

func Xsqlite3session_enable(tls *libc.TLS, pSession uintptr, bEnable int32) int32 {
	var ret int32
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	if bEnable >= 0 {
		(*Sqlite3_session)(unsafe.Pointer(pSession)).FbEnable = bEnable
	}
	ret = (*Sqlite3_session)(unsafe.Pointer(pSession)).FbEnable
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return ret
}

func Xsqlite3session_indirect(tls *libc.TLS, pSession uintptr, bIndirect int32) int32 {
	var ret int32
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	if bIndirect >= 0 {
		(*Sqlite3_session)(unsafe.Pointer(pSession)).FbIndirect = bIndirect
	}
	ret = (*Sqlite3_session)(unsafe.Pointer(pSession)).FbIndirect
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	return ret
}

func Xsqlite3session_isempty(tls *libc.TLS, pSession uintptr) int32 {
	var ret int32 = 0
	var pTab uintptr

	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))
	for pTab = (*Sqlite3_session)(unsafe.Pointer(pSession)).FpTable; pTab != 0 && ret == 0; pTab = (*SessionTable)(unsafe.Pointer(pTab)).FpNext {
		ret = libc.Bool32((*SessionTable)(unsafe.Pointer(pTab)).FnEntry > 0)
	}
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, (*Sqlite3_session)(unsafe.Pointer(pSession)).Fdb))

	return libc.Bool32(ret == 0)
}

func Xsqlite3session_memory_used(tls *libc.TLS, pSession uintptr) Sqlite3_int64 {
	return (*Sqlite3_session)(unsafe.Pointer(pSession)).FnMalloc
}

func Xsqlite3session_object_config(tls *libc.TLS, pSession uintptr, op int32, pArg uintptr) int32 {
	var rc int32 = SQLITE_OK
	switch op {
	case SQLITE_SESSION_OBJCONFIG_SIZE:
		{
			var iArg int32 = *(*int32)(unsafe.Pointer(pArg))
			if iArg >= 0 {
				if (*Sqlite3_session)(unsafe.Pointer(pSession)).FpTable != 0 {
					rc = SQLITE_MISUSE
				} else {
					(*Sqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize = libc.Bool32(iArg != 0)
				}
			}
			*(*int32)(unsafe.Pointer(pArg)) = (*Sqlite3_session)(unsafe.Pointer(pSession)).FbEnableSize
			break

		}

	default:
		rc = SQLITE_MISUSE
	}

	return rc
}

func Xsqlite3session_changeset_size(tls *libc.TLS, pSession uintptr) Sqlite3_int64 {
	return (*Sqlite3_session)(unsafe.Pointer(pSession)).FnMaxChangesetSize
}

func sessionChangesetStart(tls *libc.TLS, pp uintptr, xInput uintptr, pIn uintptr, nChangeset int32, pChangeset uintptr, bInvert int32, bSkipEmpty int32) int32 {
	var pRet uintptr
	var nByte int32

	*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)

	nByte = int32(unsafe.Sizeof(Sqlite3_changeset_iter{}))
	pRet = Xsqlite3_malloc(tls, nByte)
	if !(pRet != 0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pRet, 0, uint64(unsafe.Sizeof(Sqlite3_changeset_iter{})))
	(*Sqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FaData = pChangeset
	(*Sqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FnData = nChangeset
	(*Sqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FxInput = xInput
	(*Sqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FpIn = pIn
	(*Sqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FbEof = func() int32 {
		if xInput != 0 {
			return 0
		}
		return 1
	}()
	(*Sqlite3_changeset_iter)(unsafe.Pointer(pRet)).FbInvert = bInvert
	(*Sqlite3_changeset_iter)(unsafe.Pointer(pRet)).FbSkipEmpty = bSkipEmpty

	*(*uintptr)(unsafe.Pointer(pp)) = pRet
	return SQLITE_OK
}

func Xsqlite3changeset_start(tls *libc.TLS, pp uintptr, nChangeset int32, pChangeset uintptr) 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) int32 {
	var bInvert int32 = libc.BoolInt32(!!(flags&SQLITE_CHANGESETSTART_INVERT != 0))
	return sessionChangesetStart(tls, pp, uintptr(0), uintptr(0), nChangeset, pChangeset, bInvert, 0)
}

func Xsqlite3changeset_start_strm(tls *libc.TLS, pp uintptr, xInput uintptr, pIn uintptr) 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) int32 {
	var bInvert int32 = libc.BoolInt32(!!(flags&SQLITE_CHANGESETSTART_INVERT != 0))
	return sessionChangesetStart(tls, pp, xInput, pIn, 0, uintptr(0), bInvert, 0)
}

func sessionDiscardData(tls *libc.TLS, pIn uintptr) {
	if (*SessionInput)(unsafe.Pointer(pIn)).FxInput != 0 && (*SessionInput)(unsafe.Pointer(pIn)).FiNext >= sessions_strm_chunk_size {
		var nMove int32 = (*SessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf - (*SessionInput)(unsafe.Pointer(pIn)).FiNext

		if nMove > 0 {
			libc.Xmemmove(tls, (*SessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf, (*SessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf+uintptr((*SessionInput)(unsafe.Pointer(pIn)).FiNext), uint64(nMove))
		}
		*(*int32)(unsafe.Pointer(pIn + 32 + 8)) -= (*SessionInput)(unsafe.Pointer(pIn)).FiNext
		(*SessionInput)(unsafe.Pointer(pIn)).FiNext = 0
		(*SessionInput)(unsafe.Pointer(pIn)).FnData = (*SessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf
	}
}

func sessionInputBuffer(tls *libc.TLS, pIn uintptr, nByte int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	if (*SessionInput)(unsafe.Pointer(pIn)).FxInput != 0 {
		for !((*SessionInput)(unsafe.Pointer(pIn)).FbEof != 0) && (*SessionInput)(unsafe.Pointer(pIn)).FiNext+nByte >= (*SessionInput)(unsafe.Pointer(pIn)).FnData && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 4)) = sessions_strm_chunk_size

			if (*SessionInput)(unsafe.Pointer(pIn)).FbNoDiscard == 0 {
				sessionDiscardData(tls, pIn)
			}
			if SQLITE_OK == sessionBufferGrow(tls, pIn+32, int64(*(*int32)(unsafe.Pointer(bp + 4))), bp) {
				*(*int32)(unsafe.Pointer(bp)) = (*struct {
					f func(*libc.TLS, uintptr, uintptr, uintptr) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*SessionInput)(unsafe.Pointer(pIn)).FxInput})).f(tls, (*SessionInput)(unsafe.Pointer(pIn)).FpIn, (*SessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf+uintptr((*SessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf), bp+4)
				if *(*int32)(unsafe.Pointer(bp + 4)) == 0 {
					(*SessionInput)(unsafe.Pointer(pIn)).FbEof = 1
				} else {
					*(*int32)(unsafe.Pointer(pIn + 32 + 8)) += *(*int32)(unsafe.Pointer(bp + 4))
				}
			}

			(*SessionInput)(unsafe.Pointer(pIn)).FaData = (*SessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf
			(*SessionInput)(unsafe.Pointer(pIn)).FnData = (*SessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func sessionSkipRecord(tls *libc.TLS, ppRec uintptr, nCol int32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var aRec uintptr = *(*uintptr)(unsafe.Pointer(ppRec))
	var i int32
	for i = 0; i < nCol; i++ {
		var eType int32 = int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&aRec, 1))))
		if eType == SQLITE_TEXT || eType == SQLITE_BLOB {
			aRec += uintptr(sessionVarintGet(tls, aRec, bp))
			aRec += uintptr(*(*int32)(unsafe.Pointer(bp)))
		} else if eType == SQLITE_INTEGER || eType == SQLITE_FLOAT {
			aRec += uintptr(8)
		}
	}

	*(*uintptr)(unsafe.Pointer(ppRec)) = aRec
}

func sessionValueSetStr(tls *libc.TLS, pVal uintptr, aData uintptr, nData int32, enc U8) int32 {
	var aCopy uintptr = Xsqlite3_malloc64(tls, uint64(Sqlite3_int64(nData)+int64(1)))
	if aCopy == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemcpy(tls, aCopy, aData, uint64(nData))
	Xsqlite3ValueSetStr(tls, pVal, nData, aCopy, enc, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
	return SQLITE_OK
}

func sessionReadRecord(tls *libc.TLS, pIn uintptr, nCol int32, abPK uintptr, apOut uintptr, pbEmpty uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var i int32
	var rc int32 = SQLITE_OK

	if pbEmpty != 0 {
		*(*int32)(unsafe.Pointer(pbEmpty)) = 1
	}
	for i = 0; i < nCol && rc == SQLITE_OK; i++ {
		var eType int32 = 0
		if abPK != 0 && int32(*(*U8)(unsafe.Pointer(abPK + uintptr(i)))) == 0 {
			continue
		}
		rc = sessionInputBuffer(tls, pIn, 9)
		if rc == SQLITE_OK {
			if (*SessionInput)(unsafe.Pointer(pIn)).FiNext >= (*SessionInput)(unsafe.Pointer(pIn)).FnData {
				rc = Xsqlite3CorruptError(tls, 219169)
			} else {
				eType = int32(*(*U8)(unsafe.Pointer((*SessionInput)(unsafe.Pointer(pIn)).FaData + uintptr(libc.PostIncInt32(&(*SessionInput)(unsafe.Pointer(pIn)).FiNext, 1)))))

				if eType != 0 {
					if pbEmpty != 0 {
						*(*int32)(unsafe.Pointer(pbEmpty)) = 0
					}
					*(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*8)) = Xsqlite3ValueNew(tls, uintptr(0))
					if !(int32(*(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*8))) != 0) {
						rc = SQLITE_NOMEM
					}
				}
			}
		}

		if rc == SQLITE_OK {
			var aVal uintptr = (*SessionInput)(unsafe.Pointer(pIn)).FaData + uintptr((*SessionInput)(unsafe.Pointer(pIn)).FiNext)
			if eType == SQLITE_TEXT || eType == 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)) > (*SessionInput)(unsafe.Pointer(pIn)).FnData-(*SessionInput)(unsafe.Pointer(pIn)).FiNext {
						rc = Xsqlite3CorruptError(tls, 219189)
					} else {
						var enc U8 = func() uint8 {
							if eType == SQLITE_TEXT {
								return uint8(SQLITE_UTF8)
							}
							return uint8(0)
						}()
						rc = sessionValueSetStr(tls, *(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*8)), (*SessionInput)(unsafe.Pointer(pIn)).FaData+uintptr((*SessionInput)(unsafe.Pointer(pIn)).FiNext), *(*int32)(unsafe.Pointer(bp)), enc)
						*(*int32)(unsafe.Pointer(pIn + 8)) += *(*int32)(unsafe.Pointer(bp))
					}
				}
			}
			if eType == SQLITE_INTEGER || eType == SQLITE_FLOAT {
				*(*Sqlite3_int64)(unsafe.Pointer(bp + 16)) = sessionGetI64(tls, aVal)
				if eType == SQLITE_INTEGER {
					Xsqlite3VdbeMemSetInt64(tls, *(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*8)), *(*Sqlite3_int64)(unsafe.Pointer(bp + 16)))
				} else {
					libc.Xmemcpy(tls, bp+8, bp+16, uint64(8))
					Xsqlite3VdbeMemSetDouble(tls, *(*uintptr)(unsafe.Pointer(apOut + uintptr(i)*8)), *(*float64)(unsafe.Pointer(bp + 8)))
				}
				*(*int32)(unsafe.Pointer(pIn + 8)) += 8
			}
		}
	}

	return rc
}

func sessionChangesetBufferTblhdr(tls *libc.TLS, pIn uintptr, pnByte uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32 = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp)) = 0
	var nRead int32 = 0

	rc = sessionInputBuffer(tls, pIn, 9)
	if rc == SQLITE_OK {
		nRead = nRead + sessionVarintGet(tls, (*SessionInput)(unsafe.Pointer(pIn)).FaData+uintptr((*SessionInput)(unsafe.Pointer(pIn)).FiNext+nRead), bp)

		if *(*int32)(unsafe.Pointer(bp)) < 0 || *(*int32)(unsafe.Pointer(bp)) > 65536 {
			rc = Xsqlite3CorruptError(tls, 219243)
		} else {
			rc = sessionInputBuffer(tls, pIn, nRead+*(*int32)(unsafe.Pointer(bp))+100)
			nRead = nRead + *(*int32)(unsafe.Pointer(bp))
		}
	}

	for rc == SQLITE_OK {
		for (*SessionInput)(unsafe.Pointer(pIn)).FiNext+nRead < (*SessionInput)(unsafe.Pointer(pIn)).FnData && *(*U8)(unsafe.Pointer((*SessionInput)(unsafe.Pointer(pIn)).FaData + uintptr((*SessionInput)(unsafe.Pointer(pIn)).FiNext+nRead))) != 0 {
			nRead++
		}
		if (*SessionInput)(unsafe.Pointer(pIn)).FiNext+nRead < (*SessionInput)(unsafe.Pointer(pIn)).FnData {
			break
		}
		rc = sessionInputBuffer(tls, pIn, nRead+100)
	}
	*(*int32)(unsafe.Pointer(pnByte)) = nRead + 1
	return rc
}

func sessionChangesetBufferRecord(tls *libc.TLS, pIn uintptr, nCol int32, pnByte uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32 = SQLITE_OK
	var nByte int32 = 0
	var i int32
	for i = 0; rc == SQLITE_OK && i < nCol; i++ {
		var eType int32
		rc = sessionInputBuffer(tls, pIn, nByte+10)
		if rc == SQLITE_OK {
			eType = int32(*(*U8)(unsafe.Pointer((*SessionInput)(unsafe.Pointer(pIn)).FaData + uintptr((*SessionInput)(unsafe.Pointer(pIn)).FiNext+libc.PostIncInt32(&nByte, 1)))))
			if eType == SQLITE_TEXT || eType == SQLITE_BLOB {
				nByte = nByte + sessionVarintGet(tls, (*SessionInput)(unsafe.Pointer(pIn)).FaData+uintptr((*SessionInput)(unsafe.Pointer(pIn)).FiNext+nByte), bp)
				nByte = nByte + *(*int32)(unsafe.Pointer(bp))
				rc = sessionInputBuffer(tls, pIn, nByte)
			} else if eType == SQLITE_INTEGER || eType == SQLITE_FLOAT {
				nByte = nByte + 8
			}
		}
	}
	*(*int32)(unsafe.Pointer(pnByte)) = nByte
	return rc
}

func sessionChangesetReadTblhdr(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*int32)(unsafe.Pointer(bp + 4)) = sessionChangesetBufferTblhdr(tls, p, bp)
	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
		var nByte int32
		var nVarint int32
		nVarint = sessionVarintGet(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData+uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext), p+120)
		if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol > 0 {
			*(*int32)(unsafe.Pointer(bp)) -= nVarint
			*(*int32)(unsafe.Pointer(p + 8)) += nVarint
			nByte = int32(uint64((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*uint64(unsafe.Sizeof(uintptr(0)))*uint64(2) + uint64(*(*int32)(unsafe.Pointer(bp))))
			(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FnBuf = 0
			sessionBufferGrow(tls, p+72, int64(nByte), bp+4)
		} else {
			*(*int32)(unsafe.Pointer(bp + 4)) = Xsqlite3CorruptError(tls, 219331)
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
		var iPK Size_t = uint64(unsafe.Sizeof(uintptr(0))) * uint64((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol) * uint64(2)
		libc.Xmemset(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf, 0, iPK)
		libc.Xmemcpy(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf+uintptr(iPK), (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData+uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext), uint64(*(*int32)(unsafe.Pointer(bp))))
		*(*int32)(unsafe.Pointer(p + 8)) += *(*int32)(unsafe.Pointer(bp))
	}

	(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf
	if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue == uintptr(0) {
		(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK = uintptr(0)
		(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab = uintptr(0)
	} else {
		(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*2)*8
		(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab = func() uintptr {
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK != 0 {
				return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)
			}
			return uintptr(0)
		}()
	}
	return libc.AssignPtrInt32(p+100, *(*int32)(unsafe.Pointer(bp + 4)))
}

func sessionChangesetNextOne(tls *libc.TLS, p uintptr, paRec uintptr, pnRec uintptr, pbNew uintptr, pbEmpty uintptr) int32 {
	var i int32
	var op U8

	if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
	}

	if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue != 0 {
		for i = 0; i < (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*2; i++ {
			Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)))
		}
		libc.Xmemset(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue, 0, uint64(unsafe.Sizeof(uintptr(0)))*uint64((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*uint64(2))
	}

	(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = sessionInputBuffer(tls, p, 2)
	if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
	}

	if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext >= (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FnData {
		return SQLITE_DONE
	}

	sessionDiscardData(tls, p)
	(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiCurrent = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext

	op = *(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(libc.PostIncInt32(&(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext, 1))))
	for int32(op) == 'T' || int32(op) == 'P' {
		if pbNew != 0 {
			*(*int32)(unsafe.Pointer(pbNew)) = 1
		}
		(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset = libc.Bool32(int32(op) == 'P')
		if sessionChangesetReadTblhdr(tls, p) != 0 {
			return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		}
		if libc.AssignPtrInt32(p+100, sessionInputBuffer(tls, p, 2)) != 0 {
			return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		}
		(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiCurrent = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext
		if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext >= (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FnData {
			return SQLITE_DONE
		}
		op = *(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(libc.PostIncInt32(&(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext, 1))))
	}

	if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FzTab == uintptr(0) || (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 && (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
		return libc.AssignPtrInt32(p+100, Xsqlite3CorruptError(tls, 219417))
	}

	(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = int32(op)
	(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbIndirect = int32(*(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr(libc.PostIncInt32(&(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext, 1)))))
	if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != SQLITE_UPDATE && (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != SQLITE_DELETE && (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != SQLITE_INSERT {
		return libc.AssignPtrInt32(p+100, Xsqlite3CorruptError(tls, 219423))
	}

	if paRec != 0 {
		var nVal int32
		if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 && int32(op) == SQLITE_UPDATE {
			nVal = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol * 2
		} else if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 && int32(op) == SQLITE_DELETE {
			nVal = 0
			for i = 0; i < (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol; i++ {
				if *(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
					nVal++
				}
			}
		} else {
			nVal = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol
		}
		(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = sessionChangesetBufferRecord(tls, p, nVal, pnRec)
		if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
			return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		}
		*(*uintptr)(unsafe.Pointer(paRec)) = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FaData + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.FiNext)
		*(*int32)(unsafe.Pointer(p + 8)) += *(*int32)(unsafe.Pointer(pnRec))
	} else {
		var apOld uintptr = func() uintptr {
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
				return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8
			}
			return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue
		}()
		var apNew uintptr = func() uintptr {
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
				return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue
			}
			return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8
		}()

		if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != SQLITE_INSERT && ((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 || (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == SQLITE_DELETE) {
			var abPK uintptr
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 {
				abPK = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK
			} else {
				abPK = uintptr(0)
			}
			(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = sessionReadRecord(tls, p, (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol, abPK, apOld, uintptr(0))
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
			}
		}

		if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop != SQLITE_DELETE {
			(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc = sessionReadRecord(tls, p, (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol, uintptr(0), apNew, pbEmpty)
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				return (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
			}
		}

		if ((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset != 0 || (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0) && (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == SQLITE_UPDATE {
			for i = 0; i < (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol; i++ {
				if *(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
					*(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8))
					if *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)) == uintptr(0) {
						return libc.AssignPtrInt32(p+100, Xsqlite3CorruptError(tls, 219467))
					}
					*(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8)) = uintptr(0)
				}
			}
		} else if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbInvert != 0 {
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == SQLITE_INSERT {
				(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = SQLITE_DELETE
			} else if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == SQLITE_DELETE {
				(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop = SQLITE_INSERT
			}
		}

		if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FbPatchset == 0 && (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Fop == SQLITE_UPDATE {
			for i = 0; i < (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol; i++ {
				if int32(*(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FabPK + uintptr(i)))) == 0 && *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i+(*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol)*8)) == uintptr(0) {
					Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)))
					*(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)) = uintptr(0)
				}
			}
		}
	}

	return SQLITE_ROW
}

func sessionChangesetNext(tls *libc.TLS, p uintptr, paRec uintptr, pnRec uintptr, pbNew uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32
	for __ccgo := true; __ccgo; __ccgo = rc == SQLITE_ROW && (*Sqlite3_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
}

func Xsqlite3changeset_next(tls *libc.TLS, p uintptr) int32 {
	return sessionChangesetNext(tls, p, uintptr(0), uintptr(0), uintptr(0))
}

func Xsqlite3changeset_op(tls *libc.TLS, pIter uintptr, pzTab uintptr, pnCol uintptr, pOp uintptr, pbIndirect uintptr) int32 {
	*(*int32)(unsafe.Pointer(pOp)) = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop
	*(*int32)(unsafe.Pointer(pnCol)) = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	*(*uintptr)(unsafe.Pointer(pzTab)) = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab
	if pbIndirect != 0 {
		*(*int32)(unsafe.Pointer(pbIndirect)) = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect
	}
	return SQLITE_OK
}

func Xsqlite3changeset_pk(tls *libc.TLS, pIter uintptr, pabPK uintptr, pnCol uintptr) int32 {
	*(*uintptr)(unsafe.Pointer(pabPK)) = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK
	if pnCol != 0 {
		*(*int32)(unsafe.Pointer(pnCol)) = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	}
	return SQLITE_OK
}

func Xsqlite3changeset_old(tls *libc.TLS, pIter uintptr, iVal int32, ppValue uintptr) int32 {
	if (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != SQLITE_UPDATE && (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != SQLITE_DELETE {
		return SQLITE_MISUSE
	}
	if iVal < 0 || iVal >= (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol {
		return SQLITE_RANGE
	}
	*(*uintptr)(unsafe.Pointer(ppValue)) = *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(iVal)*8))
	return SQLITE_OK
}

func Xsqlite3changeset_new(tls *libc.TLS, pIter uintptr, iVal int32, ppValue uintptr) int32 {
	if (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != SQLITE_UPDATE && (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != SQLITE_INSERT {
		return SQLITE_MISUSE
	}
	if iVal < 0 || iVal >= (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol {
		return SQLITE_RANGE
	}
	*(*uintptr)(unsafe.Pointer(ppValue)) = *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+iVal)*8))
	return SQLITE_OK
}

func Xsqlite3changeset_conflict(tls *libc.TLS, pIter uintptr, iVal int32, ppValue uintptr) int32 {
	if !(int32((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict) != 0) {
		return SQLITE_MISUSE
	}
	if iVal < 0 || iVal >= (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol {
		return SQLITE_RANGE
	}
	*(*uintptr)(unsafe.Pointer(ppValue)) = Xsqlite3_column_value(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict, iVal)
	return SQLITE_OK
}

func Xsqlite3changeset_fk_conflicts(tls *libc.TLS, pIter uintptr, pnOut uintptr) int32 {
	if (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict != 0 || (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue != 0 {
		return SQLITE_MISUSE
	}
	*(*int32)(unsafe.Pointer(pnOut)) = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	return SQLITE_OK
}

func Xsqlite3changeset_finalize(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = SQLITE_OK
	if p != 0 {
		var i int32
		rc = (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		if (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue != 0 {
			for i = 0; i < (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*2; i++ {
				Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*8)))
			}
		}
		Xsqlite3_free(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf)
		Xsqlite3_free(tls, (*Sqlite3_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) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var abPK uintptr
	var apVal uintptr

	var nVar int32

	var bIndirect int32
	var eType2 int32
	var pVal uintptr
	var pVal1 uintptr
	var iCol int32
	var eType U8
	*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp + 20)) = 0
	abPK = uintptr(0)
	apVal = uintptr(0)
	*(*SessionBuffer)(unsafe.Pointer(bp + 24)) = SessionBuffer{}

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(SessionBuffer{})))

	if !(ppInverted != 0) {
		goto __1
	}
	*(*uintptr)(unsafe.Pointer(ppInverted)) = uintptr(0)
	*(*int32)(unsafe.Pointer(pnInverted)) = 0
__1:
	;
__2:
	if !(1 != 0) {
		goto __3
	}

	if !(libc.AssignPtrInt32(bp+40, sessionInputBuffer(tls, pInput, 2)) != 0) {
		goto __4
	}
	goto finished_invert
__4:
	;
	if !((*SessionInput)(unsafe.Pointer(pInput)).FiNext >= (*SessionInput)(unsafe.Pointer(pInput)).FnData) {
		goto __5
	}
	goto __3
__5:
	;
	eType = *(*U8)(unsafe.Pointer((*SessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*SessionInput)(unsafe.Pointer(pInput)).FiNext)))

	switch int32(eType) {
	case 'T':
		goto __7

	case SQLITE_INSERT:
		goto __8
	case SQLITE_DELETE:
		goto __9

	case SQLITE_UPDATE:
		goto __10

	default:
		goto __11
	}
	goto __6
__7:
	(*SessionInput)(unsafe.Pointer(pInput)).FiNext++
	if !(libc.AssignPtrInt32(bp+40, sessionChangesetBufferTblhdr(tls, pInput, bp+16)) != 0) {
		goto __12
	}
	goto finished_invert
__12:
	;
	nVar = sessionVarintGet(tls, (*SessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*SessionInput)(unsafe.Pointer(pInput)).FiNext), bp+20)
	(*SessionBuffer)(unsafe.Pointer(bp + 24)).FnBuf = 0
	sessionAppendBlob(tls, bp+24, (*SessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*SessionInput)(unsafe.Pointer(pInput)).FiNext+nVar), *(*int32)(unsafe.Pointer(bp + 20)), bp+40)
	sessionAppendByte(tls, bp, eType, bp+40)
	sessionAppendBlob(tls, bp, (*SessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*SessionInput)(unsafe.Pointer(pInput)).FiNext), *(*int32)(unsafe.Pointer(bp + 16)), bp+40)
	if !(*(*int32)(unsafe.Pointer(bp + 40)) != 0) {
		goto __13
	}
	goto finished_invert
__13:
	;
	*(*int32)(unsafe.Pointer(pInput + 8)) += *(*int32)(unsafe.Pointer(bp + 16))
	Xsqlite3_free(tls, apVal)
	apVal = uintptr(0)
	abPK = (*SessionBuffer)(unsafe.Pointer(bp + 24)).FaBuf
	goto __6

__8:
__9:
	bIndirect = int32(*(*U8)(unsafe.Pointer((*SessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*SessionInput)(unsafe.Pointer(pInput)).FiNext+1))))
	eType2 = func() int32 {
		if int32(eType) == SQLITE_DELETE {
			return SQLITE_INSERT
		}
		return SQLITE_DELETE
	}()
	*(*int32)(unsafe.Pointer(pInput + 8)) += 2

	*(*int32)(unsafe.Pointer(bp + 40)) = sessionChangesetBufferRecord(tls, pInput, *(*int32)(unsafe.Pointer(bp + 20)), bp+44)
	sessionAppendByte(tls, bp, uint8(eType2), bp+40)
	sessionAppendByte(tls, bp, uint8(bIndirect), bp+40)
	sessionAppendBlob(tls, bp, (*SessionInput)(unsafe.Pointer(pInput)).FaData+uintptr((*SessionInput)(unsafe.Pointer(pInput)).FiNext), *(*int32)(unsafe.Pointer(bp + 44)), bp+40)
	*(*int32)(unsafe.Pointer(pInput + 8)) += *(*int32)(unsafe.Pointer(bp + 44))
	if !(*(*int32)(unsafe.Pointer(bp + 40)) != 0) {
		goto __14
	}
	goto finished_invert
__14:
	;
	goto __6

__10:
	if !(uintptr(0) == apVal) {
		goto __15
	}
	apVal = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(uintptr(0)))*uint64(*(*int32)(unsafe.Pointer(bp + 20)))*uint64(2))
	if !(uintptr(0) == apVal) {
		goto __16
	}
	*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_NOMEM
	goto finished_invert
__16:
	;
	libc.Xmemset(tls, apVal, 0, uint64(unsafe.Sizeof(uintptr(0)))*uint64(*(*int32)(unsafe.Pointer(bp + 20)))*uint64(2))
__15:
	;
	sessionAppendByte(tls, bp, eType, bp+40)
	sessionAppendByte(tls, bp, *(*U8)(unsafe.Pointer((*SessionInput)(unsafe.Pointer(pInput)).FaData + uintptr((*SessionInput)(unsafe.Pointer(pInput)).FiNext+1))), bp+40)

	*(*int32)(unsafe.Pointer(pInput + 8)) += 2
	*(*int32)(unsafe.Pointer(bp + 40)) = sessionReadRecord(tls, pInput, *(*int32)(unsafe.Pointer(bp + 20)), uintptr(0), apVal, uintptr(0))
	if !(*(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK) {
		goto __17
	}
	*(*int32)(unsafe.Pointer(bp + 40)) = sessionReadRecord(tls, pInput, *(*int32)(unsafe.Pointer(bp + 20)), uintptr(0), apVal+uintptr(*(*int32)(unsafe.Pointer(bp + 20)))*8, uintptr(0))
__17:
	;
	iCol = 0
__18:
	if !(iCol < *(*int32)(unsafe.Pointer(bp + 20))) {
		goto __20
	}
	pVal = *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol+func() int32 {
		if *(*U8)(unsafe.Pointer(abPK + uintptr(iCol))) != 0 {
			return 0
		}
		return *(*int32)(unsafe.Pointer(bp + 20))
	}())*8))
	sessionAppendValue(tls, bp, pVal, bp+40)
	goto __19
__19:
	iCol++
	goto __18
	goto __20
__20:
	;
	iCol = 0
__21:
	if !(iCol < *(*int32)(unsafe.Pointer(bp + 20))) {
		goto __23
	}
	pVal1 = func() uintptr {
		if *(*U8)(unsafe.Pointer(abPK + uintptr(iCol))) != 0 {
			return uintptr(0)
		}
		return *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol)*8))
	}()
	sessionAppendValue(tls, bp, pVal1, bp+40)
	goto __22
__22:
	iCol++
	goto __21
	goto __23
__23:
	;
	iCol = 0
__24:
	if !(iCol < *(*int32)(unsafe.Pointer(bp + 20))*2) {
		goto __26
	}
	Xsqlite3ValueFree(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol)*8)))
	goto __25
__25:
	iCol++
	goto __24
	goto __26
__26:
	;
	libc.Xmemset(tls, apVal, 0, uint64(unsafe.Sizeof(uintptr(0)))*uint64(*(*int32)(unsafe.Pointer(bp + 20)))*uint64(2))
	if !(*(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK) {
		goto __27
	}
	goto finished_invert
__27:
	;
	goto __6

__11:
	*(*int32)(unsafe.Pointer(bp + 40)) = Xsqlite3CorruptError(tls, 219832)
	goto finished_invert
__6:
	;
	if !(xOutput != 0 && (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf >= sessions_strm_chunk_size) {
		goto __28
	}
	*(*int32)(unsafe.Pointer(bp + 40)) = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{xOutput})).f(tls, pOut, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf)
	(*SessionBuffer)(unsafe.Pointer(bp)).FnBuf = 0
	if !(*(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK) {
		goto __29
	}
	goto finished_invert
__29:
	;
__28:
	;
	goto __2
__3:
	;
	if !(pnInverted != 0 && ppInverted != 0) {
		goto __30
	}
	*(*int32)(unsafe.Pointer(pnInverted)) = (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf
	*(*uintptr)(unsafe.Pointer(ppInverted)) = (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf
	(*SessionBuffer)(unsafe.Pointer(bp)).FaBuf = uintptr(0)
	goto __31
__30:
	if !((*SessionBuffer)(unsafe.Pointer(bp)).FnBuf > 0 && xOutput != uintptr(0)) {
		goto __32
	}
	*(*int32)(unsafe.Pointer(bp + 40)) = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{xOutput})).f(tls, pOut, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf)
__32:
	;
__31:
	;
finished_invert:
	Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf)
	Xsqlite3_free(tls, apVal)
	Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp+24)).FaBuf)
	return *(*int32)(unsafe.Pointer(bp + 40))
}

func Xsqlite3changeset_invert(tls *libc.TLS, nChangeset int32, pChangeset uintptr, pnInverted uintptr, ppInverted uintptr) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(SessionInput{})))
	(*SessionInput)(unsafe.Pointer(bp)).FnData = nChangeset
	(*SessionInput)(unsafe.Pointer(bp)).FaData = pChangeset

	return sessionChangesetInvert(tls, bp, uintptr(0), uintptr(0), pnInverted, ppInverted)
}

func Xsqlite3changeset_invert_strm(tls *libc.TLS, xInput uintptr, pIn uintptr, xOutput uintptr, pOut uintptr) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var rc int32

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(SessionInput{})))
	(*SessionInput)(unsafe.Pointer(bp)).FxInput = xInput
	(*SessionInput)(unsafe.Pointer(bp)).FpIn = pIn

	rc = sessionChangesetInvert(tls, bp, xOutput, pOut, uintptr(0), uintptr(0))
	Xsqlite3_free(tls, (*SessionInput)(unsafe.Pointer(bp)).Fbuf.FaBuf)
	return rc
}

type SessionUpdate1 = struct {
	FpStmt uintptr
	FaMask uintptr
	FpNext uintptr
}

type SessionUpdate = SessionUpdate1

type SessionApplyCtx1 = struct {
	Fdb                 uintptr
	FpDelete            uintptr
	FpInsert            uintptr
	FpSelect            uintptr
	FnCol               int32
	F__ccgo_pad1        [4]byte
	FazCol              uintptr
	FabPK               uintptr
	FaUpdateMask        uintptr
	FpUp                uintptr
	FbStat1             int32
	FbDeferConstraints  int32
	FbInvertConstraints int32
	F__ccgo_pad2        [4]byte
	Fconstraints        SessionBuffer
	Frebase             SessionBuffer
	FbRebaseStarted     U8
	FbRebase            U8
	F__ccgo_pad3        [6]byte
}

type SessionApplyCtx = SessionApplyCtx1

func sessionUpdateFind(tls *libc.TLS, pIter uintptr, p uintptr, bPatchset int32, ppStmt uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
	var pUp uintptr = uintptr(0)
	var nCol int32 = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol
	var nU32 int32 = ((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol + 33) / 32
	var ii int32

	if (*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask == uintptr(0) {
		(*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask = Xsqlite3_malloc(tls, int32(uint64(nU32)*uint64(unsafe.Sizeof(U32(0)))))
		if (*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_NOMEM
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		libc.Xmemset(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, 0, uint64(nU32)*uint64(unsafe.Sizeof(U32(0))))
		*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_CORRUPT
		for ii = 0; ii < (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol; ii++ {
			if *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+ii)*8)) != 0 {
				*(*U32)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask + uintptr(ii/32)*4)) |= U32(int32(1) << (ii % 32))
				*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
			}
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		if bPatchset != 0 {
			*(*U32)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask + uintptr(nCol/32)*4)) |= U32(int32(1) << (nCol % 32))
		}

		if (*SessionApplyCtx)(unsafe.Pointer(p)).FpUp != 0 {
			var nUp int32 = 0
			var pp uintptr = p + 64
			for 1 != 0 {
				nUp++
				if 0 == libc.Xmemcmp(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, (*SessionUpdate)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FaMask, uint64(nU32)*uint64(unsafe.Sizeof(U32(0)))) {
					pUp = *(*uintptr)(unsafe.Pointer(pp))
					*(*uintptr)(unsafe.Pointer(pp)) = (*SessionUpdate)(unsafe.Pointer(pUp)).FpNext
					(*SessionUpdate)(unsafe.Pointer(pUp)).FpNext = (*SessionApplyCtx)(unsafe.Pointer(p)).FpUp
					(*SessionApplyCtx)(unsafe.Pointer(p)).FpUp = pUp
					break
				}

				if (*SessionUpdate)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext != 0 {
					pp = *(*uintptr)(unsafe.Pointer(pp)) + 16
				} else {
					if nUp >= SESSION_UPDATE_CACHE_SZ {
						Xsqlite3_finalize(tls, (*SessionUpdate)(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) {
			var nByte int32 = int32(uint64(unsafe.Sizeof(SessionUpdate{})) * uint64(nU32) * uint64(unsafe.Sizeof(U32(0))))
			var bStat1 int32 = libc.Bool32(Xsqlite3_stricmp(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, ts+14732) == 0)
			pUp = Xsqlite3_malloc(tls, nByte)
			if pUp == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_NOMEM
			} else {
				var zSep uintptr = ts + 1636

				libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(SessionBuffer{})))
				(*SessionUpdate)(unsafe.Pointer(pUp)).FaMask = pUp + 1*24
				libc.Xmemcpy(tls, (*SessionUpdate)(unsafe.Pointer(pUp)).FaMask, (*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask, uint64(nU32)*uint64(unsafe.Sizeof(U32(0))))

				sessionAppendStr(tls, bp, ts+39870, bp+16)
				sessionAppendIdent(tls, bp, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, bp+16)
				sessionAppendStr(tls, bp, ts+39883, bp+16)

				for ii = 0; ii < (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol; ii++ {
					if int32(*(*U8)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii)))) == 0 && *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+ii)*8)) != 0 {
						sessionAppendStr(tls, bp, zSep, bp+16)
						sessionAppendIdent(tls, bp, *(*uintptr)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(ii)*8)), bp+16)
						sessionAppendStr(tls, bp, ts+39889, bp+16)
						sessionAppendInteger(tls, bp, ii*2+1, bp+16)
						zSep = ts + 18036
					}
				}

				zSep = ts + 1636
				sessionAppendStr(tls, bp, ts+39818, bp+16)
				for ii = 0; ii < (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol; ii++ {
					if *(*U8)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(ii))) != 0 || bPatchset == 0 && *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(ii)*8)) != 0 {
						sessionAppendStr(tls, bp, zSep, bp+16)
						if bStat1 != 0 && ii == 1 {
							sessionAppendStr(tls, bp,
								ts+39894, bp+16)
						} else {
							sessionAppendIdent(tls, bp, *(*uintptr)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(ii)*8)), bp+16)
							sessionAppendStr(tls, bp, ts+39826, bp+16)
							sessionAppendInteger(tls, bp, ii*2+2, bp+16)
						}
						zSep = ts + 25874
					}
				}

				if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
					var zSql uintptr = (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf
					*(*int32)(unsafe.Pointer(bp + 16)) = Xsqlite3_prepare_v2(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).Fdb, zSql, (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf, pUp, uintptr(0))
				}

				if *(*int32)(unsafe.Pointer(bp + 16)) != SQLITE_OK {
					Xsqlite3_free(tls, pUp)
					pUp = uintptr(0)
				} else {
					(*SessionUpdate)(unsafe.Pointer(pUp)).FpNext = (*SessionApplyCtx)(unsafe.Pointer(p)).FpUp
					(*SessionApplyCtx)(unsafe.Pointer(p)).FpUp = pUp
				}
				Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf)
			}
		}
	}

	if pUp != 0 {
		*(*uintptr)(unsafe.Pointer(ppStmt)) = (*SessionUpdate)(unsafe.Pointer(pUp)).FpStmt
	} else {
		*(*uintptr)(unsafe.Pointer(ppStmt)) = uintptr(0)
	}
	return *(*int32)(unsafe.Pointer(bp + 16))
}

func sessionUpdateFree(tls *libc.TLS, p uintptr) {
	var pUp uintptr
	var pNext uintptr
	for pUp = (*SessionApplyCtx)(unsafe.Pointer(p)).FpUp; pUp != 0; pUp = pNext {
		pNext = (*SessionUpdate)(unsafe.Pointer(pUp)).FpNext
		Xsqlite3_finalize(tls, (*SessionUpdate)(unsafe.Pointer(pUp)).FpStmt)
		Xsqlite3_free(tls, pUp)
	}
	(*SessionApplyCtx)(unsafe.Pointer(p)).FpUp = uintptr(0)
	Xsqlite3_free(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask)
	(*SessionApplyCtx)(unsafe.Pointer(p)).FaUpdateMask = uintptr(0)
}

func sessionDeleteRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var i int32
	var zSep uintptr = ts + 1636
	*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
	*(*SessionBuffer)(unsafe.Pointer(bp)) = SessionBuffer{}
	var nPk int32 = 0

	sessionAppendStr(tls, bp, ts+39969, bp+16)
	sessionAppendIdent(tls, bp, zTab, bp+16)
	sessionAppendStr(tls, bp, ts+39818, bp+16)

	for i = 0; i < (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol; i++ {
		if *(*U8)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
			nPk++
			sessionAppendStr(tls, bp, zSep, bp+16)
			sessionAppendIdent(tls, bp, *(*uintptr)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp+16)
			sessionAppendStr(tls, bp, ts+39889, bp+16)
			sessionAppendInteger(tls, bp, i+1, bp+16)
			zSep = ts + 25874
		}
	}

	if nPk < (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol {
		sessionAppendStr(tls, bp, ts+39987, bp+16)
		sessionAppendInteger(tls, bp, (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol+1, bp+16)
		sessionAppendStr(tls, bp, ts+39530, bp+16)

		zSep = ts + 1636
		for i = 0; i < (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol; i++ {
			if !(int32(*(*U8)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i)))) != 0) {
				sessionAppendStr(tls, bp, zSep, bp+16)
				sessionAppendIdent(tls, bp, *(*uintptr)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp+16)
				sessionAppendStr(tls, bp, ts+39826, bp+16)
				sessionAppendInteger(tls, bp, i+1, bp+16)
				zSep = ts + 39995
			}
		}
		sessionAppendStr(tls, bp, ts+7885, bp+16)
	}

	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 16)) = Xsqlite3_prepare_v2(tls, db, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf, p+8, uintptr(0))
	}
	Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf)

	return *(*int32)(unsafe.Pointer(bp + 16))
}

func sessionSelectRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) int32 {
	return sessionSelectStmt(tls,
		db, ts+9656, zTab, (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol, (*SessionApplyCtx)(unsafe.Pointer(p)).FazCol, (*SessionApplyCtx)(unsafe.Pointer(p)).FabPK, p+24)
}

func sessionInsertRow(tls *libc.TLS, db uintptr, zTab uintptr, p uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
	var i int32
	*(*SessionBuffer)(unsafe.Pointer(bp)) = SessionBuffer{}

	sessionAppendStr(tls, bp, ts+40000, bp+16)
	sessionAppendIdent(tls, bp, zTab, bp+16)
	sessionAppendStr(tls, bp, ts+25880, bp+16)
	for i = 0; i < (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol; i++ {
		if i != 0 {
			sessionAppendStr(tls, bp, ts+18036, bp+16)
		}
		sessionAppendIdent(tls, bp, *(*uintptr)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FazCol + uintptr(i)*8)), bp+16)
	}

	sessionAppendStr(tls, bp, ts+40018, bp+16)
	for i = 1; i < (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol; i++ {
		sessionAppendStr(tls, bp, ts+40029, bp+16)
	}
	sessionAppendStr(tls, bp, ts+7885, bp+16)

	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 16)) = Xsqlite3_prepare_v2(tls, db, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf, p+16, uintptr(0))
	}
	Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf)
	return *(*int32)(unsafe.Pointer(bp + 16))
}

func sessionPrepare(tls *libc.TLS, db uintptr, pp uintptr, zSql uintptr) int32 {
	return Xsqlite3_prepare_v2(tls, db, zSql, -1, pp, uintptr(0))
}

func sessionStat1Sql(tls *libc.TLS, db uintptr, p uintptr) int32 {
	var rc int32 = sessionSelectRow(tls, db, ts+14732, p)
	if rc == SQLITE_OK {
		rc = sessionPrepare(tls, db, p+16,
			ts+40033)
	}
	if rc == SQLITE_OK {
		rc = sessionPrepare(tls, db, p+8,
			ts+40146)
	}
	return rc
}

func sessionBindValue(tls *libc.TLS, pStmt uintptr, i int32, pVal uintptr) int32 {
	var eType int32 = Xsqlite3_value_type(tls, pVal)

	if (eType == SQLITE_TEXT || eType == SQLITE_BLOB) && (*Sqlite3_value)(unsafe.Pointer(pVal)).Fz == uintptr(0) {
		return SQLITE_NOMEM
	}
	return Xsqlite3_bind_value(tls, pStmt, i, pVal)
}

func sessionBindRow(tls *libc.TLS, pIter uintptr, xValue uintptr, nCol int32, abPK uintptr, pStmt uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var i int32
	var rc int32 = SQLITE_OK

	for i = 0; rc == SQLITE_OK && i < nCol; i++ {
		if !(abPK != 0) || *(*U8)(unsafe.Pointer(abPK + uintptr(i))) != 0 {
			*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
			(*struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{xValue})).f(tls, pIter, i, bp)
			if *(*uintptr)(unsafe.Pointer(bp)) == uintptr(0) {
				rc = Xsqlite3CorruptError(tls, 220310)
			} else {
				rc = sessionBindValue(tls, pStmt, i+1, *(*uintptr)(unsafe.Pointer(bp)))
			}
		}
	}
	return rc
}

func sessionSeekToRow(tls *libc.TLS, pIter uintptr, abPK uintptr, pSelect uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32

	Xsqlite3changeset_op(tls, pIter, bp, bp+8, bp+12, uintptr(0))
	rc = sessionBindRow(tls, pIter,
		func() uintptr {
			if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_INSERT {
				return *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, int32, uintptr) int32
				}{Xsqlite3changeset_new}))
			}
			return *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			}{Xsqlite3changeset_old}))
		}(),
		*(*int32)(unsafe.Pointer(bp + 8)), abPK, pSelect)

	if rc == SQLITE_OK {
		rc = Xsqlite3_step(tls, pSelect)
		if rc != SQLITE_ROW {
			rc = Xsqlite3_reset(tls, pSelect)
		}
	}

	return rc
}

func sessionRebaseAdd(tls *libc.TLS, p uintptr, eType int32, pIter uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	if (*SessionApplyCtx)(unsafe.Pointer(p)).FbRebase != 0 {
		var i int32
		var eOp int32 = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop
		if int32((*SessionApplyCtx)(unsafe.Pointer(p)).FbRebaseStarted) == 0 {
			var zTab uintptr = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab
			sessionAppendByte(tls, p+104, uint8('T'), bp)
			sessionAppendVarint(tls, p+104, (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol, bp)
			sessionAppendBlob(tls, p+104, (*SessionApplyCtx)(unsafe.Pointer(p)).FabPK, (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol, bp)
			sessionAppendBlob(tls, p+104, zTab, int32(libc.Xstrlen(tls, zTab))+1, bp)
			(*SessionApplyCtx)(unsafe.Pointer(p)).FbRebaseStarted = U8(1)
		}

		sessionAppendByte(tls, p+104,
			func() uint8 {
				if eOp == SQLITE_DELETE {
					return uint8(SQLITE_DELETE)
				}
				return uint8(SQLITE_INSERT)
			}(), bp)
		sessionAppendByte(tls, p+104, uint8(libc.Bool32(eType == SQLITE_CHANGESET_REPLACE)), bp)
		for i = 0; i < (*SessionApplyCtx)(unsafe.Pointer(p)).FnCol; i++ {
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
			if eOp == SQLITE_DELETE || eOp == SQLITE_UPDATE && *(*U8)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 {
				Xsqlite3changeset_old(tls, pIter, i, bp+8)
			} else {
				Xsqlite3changeset_new(tls, pIter, i, bp+8)
			}
			sessionAppendValue(tls, p+104, *(*uintptr)(unsafe.Pointer(bp + 8)), bp)
		}
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func sessionConflictHandler(tls *libc.TLS, eType int32, p uintptr, pIter uintptr, xConflict uintptr, pCtx uintptr, pbReplace uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var res int32 = 0

	Xsqlite3changeset_op(tls, pIter, bp, bp+8, bp+12, uintptr(0))

	if pbReplace != 0 {
		*(*int32)(unsafe.Pointer(bp + 16)) = sessionSeekToRow(tls, pIter, (*SessionApplyCtx)(unsafe.Pointer(p)).FabPK, (*SessionApplyCtx)(unsafe.Pointer(p)).FpSelect)
	} else {
		*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
	}

	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_ROW {
		(*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict = (*SessionApplyCtx)(unsafe.Pointer(p)).FpSelect
		res = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{xConflict})).f(tls, pCtx, eType, pIter)
		(*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FpConflict = uintptr(0)
		*(*int32)(unsafe.Pointer(bp + 16)) = Xsqlite3_reset(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FpSelect)
	} else if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		if (*SessionApplyCtx)(unsafe.Pointer(p)).FbDeferConstraints != 0 && eType == SQLITE_CHANGESET_CONFLICT {
			var aBlob uintptr = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FaData + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent)
			var nBlob int32 = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiNext - (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent
			sessionAppendBlob(tls, p+88, aBlob, nBlob, bp+16)
			return SQLITE_OK
		} else {
			res = (*struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{xConflict})).f(tls, pCtx, eType+1, pIter)
			if res == SQLITE_CHANGESET_REPLACE {
				*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_MISUSE
			}
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		switch res {
		case SQLITE_CHANGESET_REPLACE:
			*(*int32)(unsafe.Pointer(pbReplace)) = 1
			break
			fallthrough

		case SQLITE_CHANGESET_OMIT:
			break
			fallthrough

		case SQLITE_CHANGESET_ABORT:
			*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_ABORT
			break
			fallthrough

		default:
			*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_MISUSE
			break
		}
		if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 16)) = sessionRebaseAdd(tls, p, res, pIter)
		}
	}

	return *(*int32)(unsafe.Pointer(bp + 16))
}

func sessionApplyOneOp(tls *libc.TLS, pIter uintptr, p uintptr, xConflict uintptr, pCtx uintptr, pbReplace uintptr, pbRetry uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32 = SQLITE_OK

	Xsqlite3changeset_op(tls, pIter, bp, bp+8, bp+12, uintptr(0))

	if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_DELETE {
		var abPK uintptr = func() uintptr {
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
				return (*SessionApplyCtx)(unsafe.Pointer(p)).FabPK
			}
			return uintptr(0)
		}()
		rc = sessionBindRow(tls, pIter, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr) int32
		}{Xsqlite3changeset_old})), *(*int32)(unsafe.Pointer(bp + 8)), abPK, (*SessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		if rc == SQLITE_OK && Xsqlite3_bind_parameter_count(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FpDelete) > *(*int32)(unsafe.Pointer(bp + 8)) {
			rc = Xsqlite3_bind_int(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FpDelete, *(*int32)(unsafe.Pointer(bp + 8))+1, libc.Bool32(pbRetry == uintptr(0) || abPK != 0))
		}
		if rc != SQLITE_OK {
			return rc
		}

		Xsqlite3_step(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		rc = Xsqlite3_reset(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		if rc == SQLITE_OK && Xsqlite3_changes(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).Fdb) == 0 {
			rc = sessionConflictHandler(tls,
				SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry)
		} else if rc&0xff == SQLITE_CONSTRAINT {
			rc = sessionConflictHandler(tls,
				SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, uintptr(0))
		}

	} else if *(*int32)(unsafe.Pointer(bp + 12)) == SQLITE_UPDATE {
		var i int32
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
		var bPatchset int32 = libc.Bool32(pbRetry == uintptr(0) || (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0)

		rc = sessionUpdateFind(tls, pIter, p, bPatchset, bp+16)

		for i = 0; rc == SQLITE_OK && i < *(*int32)(unsafe.Pointer(bp + 8)); i++ {
			var pOld uintptr = *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(i)*8))
			var pNew uintptr = *(*uintptr)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+i)*8))
			if *(*U8)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 || bPatchset == 0 && pOld != 0 {
				rc = sessionBindValue(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), i*2+2, pOld)
			}
			if rc == SQLITE_OK && pNew != 0 {
				rc = sessionBindValue(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), i*2+1, pNew)
			}
		}
		if rc != SQLITE_OK {
			return rc
		}

		Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
		rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))

		if rc == SQLITE_OK && Xsqlite3_changes(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).Fdb) == 0 {
			rc = sessionConflictHandler(tls,
				SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry)

		} else if rc&0xff == SQLITE_CONSTRAINT {
			rc = sessionConflictHandler(tls,
				SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, uintptr(0))
		}

	} else {
		if (*SessionApplyCtx)(unsafe.Pointer(p)).FbStat1 != 0 {
			rc = sessionSeekToRow(tls, pIter, (*SessionApplyCtx)(unsafe.Pointer(p)).FabPK, (*SessionApplyCtx)(unsafe.Pointer(p)).FpSelect)
			if rc == SQLITE_ROW {
				rc = SQLITE_CONSTRAINT
				Xsqlite3_reset(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FpSelect)
			}
		}

		if rc == SQLITE_OK {
			rc = sessionBindRow(tls, pIter, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			}{Xsqlite3changeset_new})), *(*int32)(unsafe.Pointer(bp + 8)), uintptr(0), (*SessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
			if rc != SQLITE_OK {
				return rc
			}

			Xsqlite3_step(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
			rc = Xsqlite3_reset(tls, (*SessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
		}

		if rc&0xff == SQLITE_CONSTRAINT {
			rc = sessionConflictHandler(tls,
				SQLITE_CHANGESET_CONFLICT, p, pIter, xConflict, pCtx, pbReplace)
		}
	}

	return rc
}

func sessionApplyOneWithRetry(tls *libc.TLS, db uintptr, pIter uintptr, pApply uintptr, xConflict uintptr, pCtx uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	var rc int32

	rc = sessionApplyOneOp(tls, pIter, pApply, xConflict, pCtx, bp, bp+4)
	if rc == SQLITE_OK {
		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, ts+40290, uintptr(0), uintptr(0), uintptr(0))
			if rc == SQLITE_OK {
				rc = sessionBindRow(tls, pIter,
					*(*uintptr)(unsafe.Pointer(&struct {
						f func(*libc.TLS, uintptr, int32, uintptr) int32
					}{Xsqlite3changeset_new})), (*SessionApplyCtx)(unsafe.Pointer(pApply)).FnCol, (*SessionApplyCtx)(unsafe.Pointer(pApply)).FabPK, (*SessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
				Xsqlite3_bind_int(tls, (*SessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete, (*SessionApplyCtx)(unsafe.Pointer(pApply)).FnCol+1, 1)
			}
			if rc == SQLITE_OK {
				Xsqlite3_step(tls, (*SessionApplyCtx)(unsafe.Pointer(pApply)).FpDelete)
				rc = Xsqlite3_reset(tls, (*SessionApplyCtx)(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, ts+40311, uintptr(0), uintptr(0), uintptr(0))
			}
		}
	}

	return rc
}

func sessionRetryConstraints(tls *libc.TLS, db uintptr, bPatchset int32, zTab uintptr, pApply uintptr, xConflict uintptr, pCtx uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_OK

	for (*SessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		var cons = (*SessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints
		libc.Xmemset(tls, pApply+88, 0, uint64(unsafe.Sizeof(SessionBuffer{})))

		*(*int32)(unsafe.Pointer(bp + 8)) = sessionChangesetStart(tls,
			bp, uintptr(0), uintptr(0), cons.FnBuf, cons.FaBuf, (*SessionApplyCtx)(unsafe.Pointer(pApply)).FbInvertConstraints, 1)
		if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
			var nByte Size_t = uint64(2*(*SessionApplyCtx)(unsafe.Pointer(pApply)).FnCol) * uint64(unsafe.Sizeof(uintptr(0)))
			var rc2 int32
			(*Sqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FbPatchset = bPatchset
			(*Sqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FzTab = zTab
			(*Sqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnCol = (*SessionApplyCtx)(unsafe.Pointer(pApply)).FnCol
			(*Sqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FabPK = (*SessionApplyCtx)(unsafe.Pointer(pApply)).FabPK
			sessionBufferGrow(tls, *(*uintptr)(unsafe.Pointer(bp))+72, int64(nByte), bp+8)
			(*Sqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FapValue = (*Sqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Ftblhdr.FaBuf
			if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
				libc.Xmemset(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FapValue, 0, nByte)
			}

			for *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK && SQLITE_ROW == Xsqlite3changeset_next(tls, *(*uintptr)(unsafe.Pointer(bp))) {
				*(*int32)(unsafe.Pointer(bp + 8)) = sessionApplyOneWithRetry(tls, db, *(*uintptr)(unsafe.Pointer(bp)), pApply, xConflict, pCtx)
			}

			rc2 = Xsqlite3changeset_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
			if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp + 8)) = rc2
			}
		}

		Xsqlite3_free(tls, cons.FaBuf)
		if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
			break
		}
		if (*SessionApplyCtx)(unsafe.Pointer(pApply)).Fconstraints.FnBuf >= cons.FnBuf {
			(*SessionApplyCtx)(unsafe.Pointer(pApply)).FbDeferConstraints = 0
		}
	}

	return *(*int32)(unsafe.Pointer(bp + 8))
}

func sessionChangesetApply(tls *libc.TLS, db uintptr, pIter uintptr, xFilter uintptr, xConflict uintptr, pCtx uintptr, ppRebase uintptr, pnRebase uintptr, flags int32) int32 {
	bp := tls.Alloc(368)
	defer tls.Free(368)

	var schemaMismatch int32 = 0
	var rc int32 = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp + 200)) = uintptr(0)
	var nTab int32 = 0

	var bPatchset int32

	(*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FbNoDiscard = 1
	libc.Xmemset(tls, bp+48, 0, uint64(unsafe.Sizeof(SessionApplyCtx{})))
	(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FbRebase = U8(libc.Bool32(ppRebase != 0 && pnRebase != 0))
	(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FbInvertConstraints = libc.BoolInt32(!!(flags&SQLITE_CHANGESETAPPLY_INVERT != 0))
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	if flags&SQLITE_CHANGESETAPPLY_NOSAVEPOINT == 0 {
		rc = Xsqlite3_exec(tls, db, ts+40330, uintptr(0), uintptr(0), uintptr(0))
	}
	if rc == SQLITE_OK {
		rc = Xsqlite3_exec(tls, db, ts+40356, uintptr(0), uintptr(0), uintptr(0))
	}
	for rc == SQLITE_OK && SQLITE_ROW == Xsqlite3changeset_next(tls, pIter) {
		Xsqlite3changeset_op(tls, pIter, bp+176, bp+184, bp+188, uintptr(0))

		if *(*uintptr)(unsafe.Pointer(bp + 200)) == uintptr(0) || Xsqlite3_strnicmp(tls, *(*uintptr)(unsafe.Pointer(bp + 176)), *(*uintptr)(unsafe.Pointer(bp + 200)), nTab+1) != 0 {
			rc = sessionRetryConstraints(tls,
				db, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, *(*uintptr)(unsafe.Pointer(bp + 200)), bp+48, xConflict, pCtx)
			if rc != SQLITE_OK {
				break
			}

			sessionUpdateFree(tls, bp+48)
			Xsqlite3_free(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FazCol)
			Xsqlite3_finalize(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FpDelete)
			Xsqlite3_finalize(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FpInsert)
			Xsqlite3_finalize(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FpSelect)
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).Fdb = db
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FpDelete = uintptr(0)
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FpInsert = uintptr(0)
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FpSelect = uintptr(0)
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FnCol = 0
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FazCol = uintptr(0)
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FabPK = uintptr(0)
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FbStat1 = 0
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FbDeferConstraints = 1
			(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FbRebaseStarted = U8(0)
			libc.Xmemset(tls, bp+48+88, 0, uint64(unsafe.Sizeof(SessionBuffer{})))

			schemaMismatch = libc.Bool32(xFilter != 0 && 0 == (*struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{xFilter})).f(tls, pCtx, *(*uintptr)(unsafe.Pointer(bp + 176))))
			if schemaMismatch != 0 {
				*(*uintptr)(unsafe.Pointer(bp + 200)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(bp + 176))))
				if *(*uintptr)(unsafe.Pointer(bp + 200)) == uintptr(0) {
					rc = SQLITE_NOMEM
					break
				}
				nTab = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp + 200))))
				(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FazCol = *(*uintptr)(unsafe.Pointer(bp + 200))
			} else {
				var nMinCol int32 = 0
				var i int32

				Xsqlite3changeset_pk(tls, pIter, bp+192, uintptr(0))
				rc = sessionTableInfo(tls, uintptr(0),
					db, ts+9656, *(*uintptr)(unsafe.Pointer(bp + 176)), bp+48+32, bp+200, bp+48+40, bp+48+48)
				if rc != SQLITE_OK {
					break
				}
				for i = 0; i < (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FnCol; i++ {
					if *(*U8)(unsafe.Pointer((*SessionApplyCtx)(unsafe.Pointer(bp+48)).FabPK + uintptr(i))) != 0 {
						nMinCol = i + 1
					}
				}

				if (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FnCol == 0 {
					schemaMismatch = 1
					Xsqlite3_log(tls, SQLITE_SCHEMA,
						ts+40386, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer(bp + 200))))
				} else if (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FnCol < *(*int32)(unsafe.Pointer(bp + 184)) {
					schemaMismatch = 1
					Xsqlite3_log(tls, SQLITE_SCHEMA,
						ts+40430,
						libc.VaList(bp+16, *(*uintptr)(unsafe.Pointer(bp + 200)), (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FnCol, *(*int32)(unsafe.Pointer(bp + 184))))
				} else if *(*int32)(unsafe.Pointer(bp + 184)) < nMinCol || libc.Xmemcmp(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FabPK, *(*uintptr)(unsafe.Pointer(bp + 192)), uint64(*(*int32)(unsafe.Pointer(bp + 184)))) != 0 {
					schemaMismatch = 1
					Xsqlite3_log(tls, SQLITE_SCHEMA,
						ts+40501, libc.VaList(bp+40, *(*uintptr)(unsafe.Pointer(bp + 200))))
				} else {
					(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FnCol = *(*int32)(unsafe.Pointer(bp + 184))
					if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(bp + 200)), ts+14732) {
						if libc.AssignInt32(&rc, sessionStat1Sql(tls, db, bp+48)) != 0 {
							break
						}
						(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FbStat1 = 1
					} else {
						if libc.AssignInt32(&rc, sessionSelectRow(tls, db, *(*uintptr)(unsafe.Pointer(bp + 200)), bp+48)) != 0 ||
							libc.AssignInt32(&rc, sessionDeleteRow(tls, db, *(*uintptr)(unsafe.Pointer(bp + 200)), bp+48)) != 0 ||
							libc.AssignInt32(&rc, sessionInsertRow(tls, db, *(*uintptr)(unsafe.Pointer(bp + 200)), bp+48)) != 0 {
							break
						}
						(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).FbStat1 = 0
					}
				}
				nTab = Xsqlite3Strlen30(tls, *(*uintptr)(unsafe.Pointer(bp + 200)))
			}
		}

		if schemaMismatch != 0 {
			continue
		}

		rc = sessionApplyOneWithRetry(tls, db, pIter, bp+48, xConflict, pCtx)
	}

	bPatchset = (*Sqlite3_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 + 200)), bp+48, xConflict, pCtx)
	}

	if rc == SQLITE_OK {
		Xsqlite3_db_status(tls, db, SQLITE_DBSTATUS_DEFERRED_FKS, bp+208, bp+212, 0)
		if *(*int32)(unsafe.Pointer(bp + 208)) != 0 {
			var res int32 = SQLITE_CHANGESET_ABORT

			libc.Xmemset(tls, bp+216, 0, uint64(unsafe.Sizeof(Sqlite3_changeset_iter{})))
			(*Sqlite3_changeset_iter)(unsafe.Pointer(bp + 216)).FnCol = *(*int32)(unsafe.Pointer(bp + 208))
			res = (*struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{xConflict})).f(tls, pCtx, SQLITE_CHANGESET_FOREIGN_KEY, bp+216)
			if res != SQLITE_CHANGESET_OMIT {
				rc = SQLITE_CONSTRAINT
			}
		}
	}
	Xsqlite3_exec(tls, db, ts+40561, uintptr(0), uintptr(0), uintptr(0))

	if flags&SQLITE_CHANGESETAPPLY_NOSAVEPOINT == 0 {
		if rc == SQLITE_OK {
			rc = Xsqlite3_exec(tls, db, ts+40591, uintptr(0), uintptr(0), uintptr(0))
		} else {
			Xsqlite3_exec(tls, db, ts+40615, uintptr(0), uintptr(0), uintptr(0))
			Xsqlite3_exec(tls, db, ts+40591, uintptr(0), uintptr(0), uintptr(0))
		}
	}

	if rc == SQLITE_OK && bPatchset == 0 && (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FbRebase != 0 {
		*(*uintptr)(unsafe.Pointer(ppRebase)) = (*SessionApplyCtx)(unsafe.Pointer(bp + 48)).Frebase.FaBuf
		*(*int32)(unsafe.Pointer(pnRebase)) = (*SessionApplyCtx)(unsafe.Pointer(bp + 48)).Frebase.FnBuf
		(*SessionApplyCtx)(unsafe.Pointer(bp + 48)).Frebase.FaBuf = uintptr(0)
	}
	sessionUpdateFree(tls, bp+48)
	Xsqlite3_finalize(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FpInsert)
	Xsqlite3_finalize(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FpDelete)
	Xsqlite3_finalize(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FpSelect)
	Xsqlite3_free(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).FazCol)
	Xsqlite3_free(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).Fconstraints.FaBuf)
	Xsqlite3_free(tls, (*SessionApplyCtx)(unsafe.Pointer(bp+48)).Frebase.FaBuf)
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	return rc
}

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) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var bInv int32 = libc.BoolInt32(!!(flags&SQLITE_CHANGESETAPPLY_INVERT != 0))
	var rc int32 = sessionChangesetStart(tls, bp, uintptr(0), uintptr(0), nChangeset, pChangeset, bInv, 1)
	if rc == SQLITE_OK {
		rc = sessionChangesetApply(tls,
			db, *(*uintptr)(unsafe.Pointer(bp)), xFilter, xConflict, pCtx, ppRebase, pnRebase, flags)
	}
	return rc
}

func Xsqlite3changeset_apply(tls *libc.TLS, db uintptr, nChangeset int32, pChangeset uintptr, xFilter uintptr, xConflict uintptr, pCtx uintptr) int32 {
	return Xsqlite3changeset_apply_v2(tls,
		db, nChangeset, pChangeset, xFilter, xConflict, pCtx, uintptr(0), uintptr(0), 0)
}

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) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var bInverse int32 = libc.BoolInt32(!!(flags&SQLITE_CHANGESETAPPLY_INVERT != 0))
	var rc int32 = sessionChangesetStart(tls, bp, xInput, pIn, 0, uintptr(0), bInverse, 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) int32 {
	return Xsqlite3changeset_apply_v2_strm(tls,
		db, xInput, pIn, xFilter, xConflict, pCtx, uintptr(0), uintptr(0), 0)
}

func sessionChangeMerge(tls *libc.TLS, pTab uintptr, bRebase int32, bPatchset int32, pExist uintptr, op2 int32, bIndirect int32, aRec uintptr, nRec int32, ppNew uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pNew uintptr = uintptr(0)
	var rc int32 = SQLITE_OK

	if !(pExist != 0) {
		pNew = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(SessionChange{}))+uint64(nRec))
		if !(pNew != 0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(SessionChange{})))
		(*SessionChange)(unsafe.Pointer(pNew)).Fop = U8(op2)
		(*SessionChange)(unsafe.Pointer(pNew)).FbIndirect = U8(bIndirect)
		(*SessionChange)(unsafe.Pointer(pNew)).FaRecord = pNew + 1*32
		if bIndirect == 0 || bRebase == 0 {
			(*SessionChange)(unsafe.Pointer(pNew)).FnRecord = nRec
			libc.Xmemcpy(tls, (*SessionChange)(unsafe.Pointer(pNew)).FaRecord, aRec, uint64(nRec))
		} else {
			var i int32
			var pIn uintptr = aRec
			var pOut uintptr = (*SessionChange)(unsafe.Pointer(pNew)).FaRecord
			for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; i++ {
				var nIn int32 = sessionSerialLen(tls, pIn)
				if int32(*(*U8)(unsafe.Pointer(pIn))) == 0 {
					*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pOut, 1))) = U8(0)
				} else if int32(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i)))) == 0 {
					*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pOut, 1))) = U8(0xFF)
				} else {
					libc.Xmemcpy(tls, pOut, pIn, uint64(nIn))
					pOut += uintptr(nIn)
				}
				pIn += uintptr(nIn)
			}
			(*SessionChange)(unsafe.Pointer(pNew)).FnRecord = int32((int64(pOut) - int64((*SessionChange)(unsafe.Pointer(pNew)).FaRecord)) / 1)
		}
	} else if bRebase != 0 {
		if int32((*SessionChange)(unsafe.Pointer(pExist)).Fop) == SQLITE_DELETE && (*SessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0 {
			*(*uintptr)(unsafe.Pointer(ppNew)) = pExist
		} else {
			var nByte Sqlite3_int64 = Sqlite3_int64(uint64(nRec+(*SessionChange)(unsafe.Pointer(pExist)).FnRecord) + uint64(unsafe.Sizeof(SessionChange{})))
			pNew = Xsqlite3_malloc64(tls, uint64(nByte))
			if pNew == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				var i int32
				var a1 uintptr = (*SessionChange)(unsafe.Pointer(pExist)).FaRecord
				var a2 uintptr = aRec
				var pOut uintptr

				libc.Xmemset(tls, pNew, 0, uint64(nByte))
				(*SessionChange)(unsafe.Pointer(pNew)).FbIndirect = U8(libc.Bool32(bIndirect != 0 || (*SessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0))
				(*SessionChange)(unsafe.Pointer(pNew)).Fop = U8(op2)
				pOut = libc.AssignPtrUintptr(pNew+16, pNew+1*32)

				for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnCol; i++ {
					var n1 int32 = sessionSerialLen(tls, a1)
					var n2 int32 = sessionSerialLen(tls, a2)
					if int32(*(*U8)(unsafe.Pointer(a1))) == 0xFF || int32(*(*U8)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(i)))) == 0 && bIndirect != 0 {
						*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pOut, 1))) = U8(0xFF)
					} else if int32(*(*U8)(unsafe.Pointer(a2))) == 0 {
						libc.Xmemcpy(tls, pOut, a1, uint64(n1))
						pOut += uintptr(n1)
					} else {
						libc.Xmemcpy(tls, pOut, a2, uint64(n2))
						pOut += uintptr(n2)
					}
					a1 += uintptr(n1)
					a2 += uintptr(n2)
				}
				(*SessionChange)(unsafe.Pointer(pNew)).FnRecord = int32((int64(pOut) - int64((*SessionChange)(unsafe.Pointer(pNew)).FaRecord)) / 1)
			}
			Xsqlite3_free(tls, pExist)
		}
	} else {
		var op1 int32 = int32((*SessionChange)(unsafe.Pointer(pExist)).Fop)

		if op1 == SQLITE_INSERT && op2 == SQLITE_INSERT ||
			op1 == SQLITE_UPDATE && op2 == SQLITE_INSERT ||
			op1 == SQLITE_DELETE && op2 == SQLITE_UPDATE ||
			op1 == SQLITE_DELETE && op2 == SQLITE_DELETE {
			pNew = pExist
		} else if op1 == SQLITE_INSERT && op2 == SQLITE_DELETE {
			Xsqlite3_free(tls, pExist)

		} else {
			var aExist uintptr = (*SessionChange)(unsafe.Pointer(pExist)).FaRecord
			var nByte Sqlite3_int64

			nByte = Sqlite3_int64(uint64(unsafe.Sizeof(SessionChange{})) + uint64((*SessionChange)(unsafe.Pointer(pExist)).FnRecord) + uint64(nRec))
			pNew = Xsqlite3_malloc64(tls, uint64(nByte))
			if !(pNew != 0) {
				Xsqlite3_free(tls, pExist)
				return SQLITE_NOMEM
			}
			libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(SessionChange{})))
			(*SessionChange)(unsafe.Pointer(pNew)).FbIndirect = U8(libc.Bool32(bIndirect != 0 && (*SessionChange)(unsafe.Pointer(pExist)).FbIndirect != 0))
			*(*uintptr)(unsafe.Pointer(bp + 8)) = libc.AssignPtrUintptr(pNew+16, pNew+1*32)

			if op1 == SQLITE_INSERT {
				*(*uintptr)(unsafe.Pointer(bp)) = aRec

				(*SessionChange)(unsafe.Pointer(pNew)).Fop = U8(SQLITE_INSERT)
				if bPatchset == 0 {
					sessionSkipRecord(tls, bp, (*SessionTable)(unsafe.Pointer(pTab)).FnCol)
				}
				sessionMergeRecord(tls, bp+8, (*SessionTable)(unsafe.Pointer(pTab)).FnCol, aExist, *(*uintptr)(unsafe.Pointer(bp)))
			} else if op1 == SQLITE_DELETE {
				(*SessionChange)(unsafe.Pointer(pNew)).Fop = U8(SQLITE_UPDATE)
				if bPatchset != 0 {
					libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), aRec, uint64(nRec))
					*(*uintptr)(unsafe.Pointer(bp + 8)) += uintptr(nRec)
				} else {
					if 0 == sessionMergeUpdate(tls, bp+8, pTab, bPatchset, aExist, uintptr(0), aRec, uintptr(0)) {
						Xsqlite3_free(tls, pNew)
						pNew = uintptr(0)
					}
				}
			} else if op2 == SQLITE_UPDATE {
				*(*uintptr)(unsafe.Pointer(bp + 16)) = aExist
				*(*uintptr)(unsafe.Pointer(bp + 24)) = aRec

				if bPatchset == 0 {
					sessionSkipRecord(tls, bp+16, (*SessionTable)(unsafe.Pointer(pTab)).FnCol)
					sessionSkipRecord(tls, bp+24, (*SessionTable)(unsafe.Pointer(pTab)).FnCol)
				}
				(*SessionChange)(unsafe.Pointer(pNew)).Fop = U8(SQLITE_UPDATE)
				if 0 == sessionMergeUpdate(tls, bp+8, pTab, bPatchset, aRec, aExist, *(*uintptr)(unsafe.Pointer(bp + 16)), *(*uintptr)(unsafe.Pointer(bp + 24))) {
					Xsqlite3_free(tls, pNew)
					pNew = uintptr(0)
				}
			} else {
				(*SessionChange)(unsafe.Pointer(pNew)).Fop = U8(SQLITE_DELETE)
				if bPatchset != 0 {
					libc.Xmemcpy(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), aRec, uint64(nRec))
					*(*uintptr)(unsafe.Pointer(bp + 8)) += uintptr(nRec)
				} else {
					sessionMergeRecord(tls, bp+8, (*SessionTable)(unsafe.Pointer(pTab)).FnCol, aRec, aExist)
				}
			}

			if pNew != 0 {
				(*SessionChange)(unsafe.Pointer(pNew)).FnRecord = int32((int64(*(*uintptr)(unsafe.Pointer(bp + 8))) - int64((*SessionChange)(unsafe.Pointer(pNew)).FaRecord)) / 1)
			}
			Xsqlite3_free(tls, pExist)
		}
	}

	*(*uintptr)(unsafe.Pointer(ppNew)) = pNew
	return rc
}

func sessionChangesetToHash(tls *libc.TLS, pIter uintptr, pGrp uintptr, bRebase int32) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var rc int32 = SQLITE_OK
	var pTab uintptr = uintptr(0)

	for SQLITE_ROW == sessionChangesetNext(tls, pIter, bp, bp+8, uintptr(0)) {
		var iHash int32

		var pExist uintptr = uintptr(0)
		var pp uintptr

		if (*Sqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList == uintptr(0) {
			(*Sqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset
		} else if (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != (*Sqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch {
			rc = SQLITE_ERROR
			break
		}

		Xsqlite3changeset_op(tls, pIter, bp+16, bp+24, bp+28, bp+32)
		if !(pTab != 0) || Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), (*SessionTable)(unsafe.Pointer(pTab)).FzName) != 0 {
			var nNew int32 = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp + 16))))

			Xsqlite3changeset_pk(tls, pIter, bp+40, uintptr(0))
			for pTab = (*Sqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList; pTab != 0; pTab = (*SessionTable)(unsafe.Pointer(pTab)).FpNext {
				if 0 == Xsqlite3_strnicmp(tls, (*SessionTable)(unsafe.Pointer(pTab)).FzName, *(*uintptr)(unsafe.Pointer(bp + 16)), nNew+1) {
					break
				}
			}
			if !(pTab != 0) {
				var ppTab uintptr

				pTab = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(SessionTable{}))+uint64(*(*int32)(unsafe.Pointer(bp + 24)))+uint64(nNew)+uint64(1))
				if !(pTab != 0) {
					rc = SQLITE_NOMEM
					break
				}
				libc.Xmemset(tls, pTab, 0, uint64(unsafe.Sizeof(SessionTable{})))
				(*SessionTable)(unsafe.Pointer(pTab)).FnCol = *(*int32)(unsafe.Pointer(bp + 24))
				(*SessionTable)(unsafe.Pointer(pTab)).FabPK = pTab + 1*56
				libc.Xmemcpy(tls, (*SessionTable)(unsafe.Pointer(pTab)).FabPK, *(*uintptr)(unsafe.Pointer(bp + 40)), uint64(*(*int32)(unsafe.Pointer(bp + 24))))
				(*SessionTable)(unsafe.Pointer(pTab)).FzName = (*SessionTable)(unsafe.Pointer(pTab)).FabPK + uintptr(*(*int32)(unsafe.Pointer(bp + 24)))
				libc.Xmemcpy(tls, (*SessionTable)(unsafe.Pointer(pTab)).FzName, *(*uintptr)(unsafe.Pointer(bp + 16)), uint64(nNew+1))

				for ppTab = pGrp + 8; *(*uintptr)(unsafe.Pointer(ppTab)) != 0; ppTab = *(*uintptr)(unsafe.Pointer(ppTab)) {
				}
				*(*uintptr)(unsafe.Pointer(ppTab)) = pTab
			} else if (*SessionTable)(unsafe.Pointer(pTab)).FnCol != *(*int32)(unsafe.Pointer(bp + 24)) || libc.Xmemcmp(tls, (*SessionTable)(unsafe.Pointer(pTab)).FabPK, *(*uintptr)(unsafe.Pointer(bp + 40)), uint64(*(*int32)(unsafe.Pointer(bp + 24)))) != 0 {
				rc = SQLITE_SCHEMA
				break
			}
		}

		if sessionGrowHash(tls, uintptr(0), (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, pTab) != 0 {
			rc = SQLITE_NOMEM
			break
		}
		iHash = int32(sessionChangeHash(tls,
			pTab, libc.Bool32((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 && *(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_DELETE), *(*uintptr)(unsafe.Pointer(bp)), (*SessionTable)(unsafe.Pointer(pTab)).FnChange))

		for pp = (*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(iHash)*8; *(*uintptr)(unsafe.Pointer(pp)) != 0; pp = *(*uintptr)(unsafe.Pointer(pp)) + 24 {
			var bPkOnly1 int32 = 0
			var bPkOnly2 int32 = 0
			if (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
				bPkOnly1 = libc.Bool32(int32((*SessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).Fop) == SQLITE_DELETE)
				bPkOnly2 = libc.Bool32(*(*int32)(unsafe.Pointer(bp + 28)) == SQLITE_DELETE)
			}
			if sessionChangeEqual(tls, pTab, bPkOnly1, (*SessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FaRecord, bPkOnly2, *(*uintptr)(unsafe.Pointer(bp))) != 0 {
				pExist = *(*uintptr)(unsafe.Pointer(pp))
				*(*uintptr)(unsafe.Pointer(pp)) = (*SessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FpNext
				(*SessionTable)(unsafe.Pointer(pTab)).FnEntry--
				break
			}
		}

		rc = sessionChangeMerge(tls, pTab, bRebase,
			(*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset, pExist, *(*int32)(unsafe.Pointer(bp + 28)), *(*int32)(unsafe.Pointer(bp + 32)), *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)), bp+48)
		if rc != 0 {
			break
		}
		if *(*uintptr)(unsafe.Pointer(bp + 48)) != 0 {
			(*SessionChange)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 48)))).FpNext = *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(iHash)*8))
			*(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(iHash)*8)) = *(*uintptr)(unsafe.Pointer(bp + 48))
			(*SessionTable)(unsafe.Pointer(pTab)).FnEntry++
		}
	}

	if rc == SQLITE_OK {
		rc = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Frc
	}
	return rc
}

func sessionChangegroupOutput(tls *libc.TLS, pGrp uintptr, xOutput uintptr, pOut uintptr, pnOut uintptr, ppOut uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
	*(*SessionBuffer)(unsafe.Pointer(bp)) = SessionBuffer{}
	var pTab uintptr

	for pTab = (*Sqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList; *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK && pTab != 0; pTab = (*SessionTable)(unsafe.Pointer(pTab)).FpNext {
		var i int32
		if (*SessionTable)(unsafe.Pointer(pTab)).FnEntry == 0 {
			continue
		}

		sessionAppendTableHdr(tls, bp, (*Sqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch, pTab, bp+16)
		for i = 0; i < (*SessionTable)(unsafe.Pointer(pTab)).FnChange; i++ {
			var p uintptr
			for p = *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*8)); p != 0; p = (*SessionChange)(unsafe.Pointer(p)).FpNext {
				sessionAppendByte(tls, bp, (*SessionChange)(unsafe.Pointer(p)).Fop, bp+16)
				sessionAppendByte(tls, bp, (*SessionChange)(unsafe.Pointer(p)).FbIndirect, bp+16)
				sessionAppendBlob(tls, bp, (*SessionChange)(unsafe.Pointer(p)).FaRecord, (*SessionChange)(unsafe.Pointer(p)).FnRecord, bp+16)
				if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK && xOutput != 0 && (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf >= sessions_strm_chunk_size {
					*(*int32)(unsafe.Pointer(bp + 16)) = (*struct {
						f func(*libc.TLS, uintptr, uintptr, int32) int32
					})(unsafe.Pointer(&struct{ uintptr }{xOutput})).f(tls, pOut, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf)
					(*SessionBuffer)(unsafe.Pointer(bp)).FnBuf = 0
				}
			}
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		if xOutput != 0 {
			if (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf > 0 {
				*(*int32)(unsafe.Pointer(bp + 16)) = (*struct {
					f func(*libc.TLS, uintptr, uintptr, int32) int32
				})(unsafe.Pointer(&struct{ uintptr }{xOutput})).f(tls, pOut, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf)
			}
		} else if ppOut != 0 {
			*(*uintptr)(unsafe.Pointer(ppOut)) = (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf
			if pnOut != 0 {
				*(*int32)(unsafe.Pointer(pnOut)) = (*SessionBuffer)(unsafe.Pointer(bp)).FnBuf
			}
			(*SessionBuffer)(unsafe.Pointer(bp)).FaBuf = uintptr(0)
		}
	}
	Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp)).FaBuf)

	return *(*int32)(unsafe.Pointer(bp + 16))
}

func Xsqlite3changegroup_new(tls *libc.TLS, pp uintptr) int32 {
	var rc int32 = SQLITE_OK
	var p uintptr
	p = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Sqlite3_changegroup{})))
	if p == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(Sqlite3_changegroup{})))
	}
	*(*uintptr)(unsafe.Pointer(pp)) = p
	return rc
}

func Xsqlite3changegroup_add(tls *libc.TLS, pGrp uintptr, nData int32, pData uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	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
}

func Xsqlite3changegroup_output(tls *libc.TLS, pGrp uintptr, pnData uintptr, ppData uintptr) int32 {
	return sessionChangegroupOutput(tls, pGrp, uintptr(0), uintptr(0), pnData, ppData)
}

func Xsqlite3changegroup_add_strm(tls *libc.TLS, pGrp uintptr, xInput uintptr, pIn uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	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
}

func Xsqlite3changegroup_output_strm(tls *libc.TLS, pGrp uintptr, xOutput uintptr, pOut uintptr) int32 {
	return sessionChangegroupOutput(tls, pGrp, xOutput, pOut, uintptr(0), uintptr(0))
}

func Xsqlite3changegroup_delete(tls *libc.TLS, pGrp uintptr) {
	if pGrp != 0 {
		sessionDeleteTable(tls, uintptr(0), (*Sqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList)
		Xsqlite3_free(tls, pGrp)
	}
}

func Xsqlite3changeset_concat(tls *libc.TLS, nLeft int32, pLeft uintptr, nRight int32, pRight uintptr, pnOut uintptr, ppOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	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
}

func Xsqlite3changeset_concat_strm(tls *libc.TLS, xInputA uintptr, pInA uintptr, xInputB uintptr, pInB uintptr, xOutput uintptr, pOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32

	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
}

func sessionAppendRecordMerge(tls *libc.TLS, pBuf uintptr, nCol int32, a1 uintptr, n1 int32, a2 uintptr, n2 int32, pRc uintptr) {
	sessionBufferGrow(tls, pBuf, int64(n1+n2), pRc)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var i int32
		var pOut uintptr = (*SessionBuffer)(unsafe.Pointer(pBuf)).FaBuf + uintptr((*SessionBuffer)(unsafe.Pointer(pBuf)).FnBuf)
		for i = 0; i < nCol; i++ {
			var nn1 int32 = sessionSerialLen(tls, a1)
			var nn2 int32 = sessionSerialLen(tls, a2)
			if int32(*(*U8)(unsafe.Pointer(a1))) == 0 || int32(*(*U8)(unsafe.Pointer(a1))) == 0xFF {
				libc.Xmemcpy(tls, pOut, a2, uint64(nn2))
				pOut += uintptr(nn2)
			} else {
				libc.Xmemcpy(tls, pOut, a1, uint64(nn1))
				pOut += uintptr(nn1)
			}
			a1 += uintptr(nn1)
			a2 += uintptr(nn2)
		}

		(*SessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = int32((int64(pOut) - int64((*SessionBuffer)(unsafe.Pointer(pBuf)).FaBuf)) / 1)

	}
}

func sessionAppendPartialUpdate(tls *libc.TLS, pBuf uintptr, pIter uintptr, aRec uintptr, nRec int32, aChange uintptr, nChange int32, pRc uintptr) {
	sessionBufferGrow(tls, pBuf, int64(2+nRec+nChange), pRc)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var bData int32 = 0
		var pOut uintptr = (*SessionBuffer)(unsafe.Pointer(pBuf)).FaBuf + uintptr((*SessionBuffer)(unsafe.Pointer(pBuf)).FnBuf)
		var i int32
		var a1 uintptr = aRec
		var a2 uintptr = aChange

		*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pOut, 1))) = U8(SQLITE_UPDATE)
		*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pOut, 1))) = U8((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect)
		for i = 0; i < (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol; i++ {
			var n1 int32 = sessionSerialLen(tls, a1)
			var n2 int32 = sessionSerialLen(tls, a2)
			if *(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i))) != 0 || int32(*(*U8)(unsafe.Pointer(a2))) == 0 {
				if !(int32(*(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i)))) != 0) && *(*U8)(unsafe.Pointer(a1)) != 0 {
					bData = 1
				}
				libc.Xmemcpy(tls, pOut, a1, uint64(n1))
				pOut += uintptr(n1)
			} else if int32(*(*U8)(unsafe.Pointer(a2))) != 0xFF && *(*U8)(unsafe.Pointer(a1)) != 0 {
				bData = 1
				libc.Xmemcpy(tls, pOut, a2, uint64(n2))
				pOut += uintptr(n2)
			} else {
				*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pOut, 1))) = U8(0)
			}
			a1 += uintptr(n1)
			a2 += uintptr(n2)
		}
		if bData != 0 {
			a2 = aChange
			for i = 0; i < (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol; i++ {
				var n1 int32 = sessionSerialLen(tls, a1)
				var n2 int32 = sessionSerialLen(tls, a2)
				if *(*U8)(unsafe.Pointer((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK + uintptr(i))) != 0 || int32(*(*U8)(unsafe.Pointer(a2))) != 0xFF {
					libc.Xmemcpy(tls, pOut, a1, uint64(n1))
					pOut += uintptr(n1)
				} else {
					*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&pOut, 1))) = U8(0)
				}
				a1 += uintptr(n1)
				a2 += uintptr(n2)
			}
			(*SessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = int32((int64(pOut) - int64((*SessionBuffer)(unsafe.Pointer(pBuf)).FaBuf)) / 1)
		}
	}
}

func sessionRebase(tls *libc.TLS, p uintptr, pIter uintptr, xOutput uintptr, pOut uintptr, pnOut uintptr, ppOut uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	*(*int32)(unsafe.Pointer(bp + 32)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	*(*int32)(unsafe.Pointer(bp + 12)) = 0
	var pTab uintptr = uintptr(0)
	*(*SessionBuffer)(unsafe.Pointer(bp + 16)) = SessionBuffer{}

	for SQLITE_ROW == sessionChangesetNext(tls, pIter, bp, bp+8, bp+12) {
		var pChange uintptr = uintptr(0)
		var bDone int32 = 0

		if *(*int32)(unsafe.Pointer(bp + 12)) != 0 {
			var zTab uintptr = (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab
			for pTab = (*Sqlite3_rebaser)(unsafe.Pointer(p)).Fgrp.FpList; pTab != 0; pTab = (*SessionTable)(unsafe.Pointer(pTab)).FpNext {
				if 0 == Xsqlite3_stricmp(tls, (*SessionTable)(unsafe.Pointer(pTab)).FzName, zTab) {
					break
				}
			}
			*(*int32)(unsafe.Pointer(bp + 12)) = 0

			if (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
				*(*int32)(unsafe.Pointer(bp + 32)) = SQLITE_ERROR
			}

			sessionAppendByte(tls, bp+16, func() uint8 {
				if (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
					return uint8('P')
				}
				return uint8('T')
			}(), bp+32)
			sessionAppendVarint(tls, bp+16, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, bp+32)
			sessionAppendBlob(tls, bp+16, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FabPK, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol, bp+32)
			sessionAppendBlob(tls, bp+16, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab, int32(libc.Xstrlen(tls, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FzTab))+1, bp+32)
		}

		if pTab != 0 && *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK {
			var iHash int32 = int32(sessionChangeHash(tls, pTab, 0, *(*uintptr)(unsafe.Pointer(bp)), (*SessionTable)(unsafe.Pointer(pTab)).FnChange))

			for pChange = *(*uintptr)(unsafe.Pointer((*SessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(iHash)*8)); pChange != 0; pChange = (*SessionChange)(unsafe.Pointer(pChange)).FpNext {
				if sessionChangeEqual(tls, pTab, 0, *(*uintptr)(unsafe.Pointer(bp)), 0, (*SessionChange)(unsafe.Pointer(pChange)).FaRecord) != 0 {
					break
				}
			}
		}

		if pChange != 0 {
			switch (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop {
			case SQLITE_INSERT:
				if int32((*SessionChange)(unsafe.Pointer(pChange)).Fop) == SQLITE_INSERT {
					bDone = 1
					if int32((*SessionChange)(unsafe.Pointer(pChange)).FbIndirect) == 0 {
						sessionAppendByte(tls, bp+16, uint8(SQLITE_UPDATE), bp+32)
						sessionAppendByte(tls, bp+16, uint8((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp+32)
						sessionAppendBlob(tls, bp+16, (*SessionChange)(unsafe.Pointer(pChange)).FaRecord, (*SessionChange)(unsafe.Pointer(pChange)).FnRecord, bp+32)
						sessionAppendBlob(tls, bp+16, *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)), bp+32)
					}
				}
				break
				fallthrough

			case SQLITE_UPDATE:
				bDone = 1
				if int32((*SessionChange)(unsafe.Pointer(pChange)).Fop) == SQLITE_DELETE {
					if int32((*SessionChange)(unsafe.Pointer(pChange)).FbIndirect) == 0 {
						*(*uintptr)(unsafe.Pointer(bp + 40)) = *(*uintptr)(unsafe.Pointer(bp))
						sessionSkipRecord(tls, bp+40, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol)
						sessionAppendByte(tls, bp+16, uint8(SQLITE_INSERT), bp+32)
						sessionAppendByte(tls, bp+16, uint8((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp+32)
						sessionAppendRecordMerge(tls, bp+16, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol,
							*(*uintptr)(unsafe.Pointer(bp + 40)), int32(int64(*(*int32)(unsafe.Pointer(bp + 8)))-(int64(*(*uintptr)(unsafe.Pointer(bp + 40)))-int64(*(*uintptr)(unsafe.Pointer(bp))))/1),
							(*SessionChange)(unsafe.Pointer(pChange)).FaRecord, (*SessionChange)(unsafe.Pointer(pChange)).FnRecord, bp+32)
					}
				} else {
					sessionAppendPartialUpdate(tls, bp+16, pIter,
						*(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)), (*SessionChange)(unsafe.Pointer(pChange)).FaRecord, (*SessionChange)(unsafe.Pointer(pChange)).FnRecord, bp+32)
				}
				break
				fallthrough

			default:
				bDone = 1
				if int32((*SessionChange)(unsafe.Pointer(pChange)).Fop) == SQLITE_INSERT {
					sessionAppendByte(tls, bp+16, uint8(SQLITE_DELETE), bp+32)
					sessionAppendByte(tls, bp+16, uint8((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp+32)
					sessionAppendRecordMerge(tls, bp+16, (*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol,
						(*SessionChange)(unsafe.Pointer(pChange)).FaRecord, (*SessionChange)(unsafe.Pointer(pChange)).FnRecord, *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)), bp+32)
				}
				break
			}
		}

		if bDone == 0 {
			sessionAppendByte(tls, bp+16, uint8((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop), bp+32)
			sessionAppendByte(tls, bp+16, uint8((*Sqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbIndirect), bp+32)
			sessionAppendBlob(tls, bp+16, *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)), bp+32)
		}
		if *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK && xOutput != 0 && (*SessionBuffer)(unsafe.Pointer(bp+16)).FnBuf > sessions_strm_chunk_size {
			*(*int32)(unsafe.Pointer(bp + 32)) = (*struct {
				f func(*libc.TLS, uintptr, uintptr, int32) int32
			})(unsafe.Pointer(&struct{ uintptr }{xOutput})).f(tls, pOut, (*SessionBuffer)(unsafe.Pointer(bp+16)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp+16)).FnBuf)
			(*SessionBuffer)(unsafe.Pointer(bp + 16)).FnBuf = 0
		}
		if *(*int32)(unsafe.Pointer(bp + 32)) != 0 {
			break
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 32)) != SQLITE_OK {
		Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp+16)).FaBuf)
		libc.Xmemset(tls, bp+16, 0, uint64(unsafe.Sizeof(SessionBuffer{})))
	}

	if *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK {
		if xOutput != 0 {
			if (*SessionBuffer)(unsafe.Pointer(bp+16)).FnBuf > 0 {
				*(*int32)(unsafe.Pointer(bp + 32)) = (*struct {
					f func(*libc.TLS, uintptr, uintptr, int32) int32
				})(unsafe.Pointer(&struct{ uintptr }{xOutput})).f(tls, pOut, (*SessionBuffer)(unsafe.Pointer(bp+16)).FaBuf, (*SessionBuffer)(unsafe.Pointer(bp+16)).FnBuf)
			}
		} else if ppOut != 0 {
			*(*uintptr)(unsafe.Pointer(ppOut)) = (*SessionBuffer)(unsafe.Pointer(bp + 16)).FaBuf
			*(*int32)(unsafe.Pointer(pnOut)) = (*SessionBuffer)(unsafe.Pointer(bp + 16)).FnBuf
			(*SessionBuffer)(unsafe.Pointer(bp + 16)).FaBuf = uintptr(0)
		}
	}
	Xsqlite3_free(tls, (*SessionBuffer)(unsafe.Pointer(bp+16)).FaBuf)
	return *(*int32)(unsafe.Pointer(bp + 32))
}

func Xsqlite3rebaser_create(tls *libc.TLS, ppNew uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pNew uintptr

	pNew = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Sqlite3_rebaser{})))
	if pNew == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Sqlite3_rebaser{})))
	}
	*(*uintptr)(unsafe.Pointer(ppNew)) = pNew
	return rc
}

func Xsqlite3rebaser_configure(tls *libc.TLS, p uintptr, nRebase int32, pRebase uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32
	rc = Xsqlite3changeset_start(tls, bp, nRebase, pRebase)
	if rc == SQLITE_OK {
		rc = sessionChangesetToHash(tls, *(*uintptr)(unsafe.Pointer(bp)), p, 1)
	}
	Xsqlite3changeset_finalize(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func Xsqlite3rebaser_rebase(tls *libc.TLS, p uintptr, nIn int32, pIn uintptr, pnOut uintptr, ppOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32 = 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
}

func Xsqlite3rebaser_rebase_strm(tls *libc.TLS, p uintptr, xInput uintptr, pIn uintptr, xOutput uintptr, pOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32 = 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
}

func Xsqlite3rebaser_delete(tls *libc.TLS, p uintptr) {
	if p != 0 {
		sessionDeleteTable(tls, uintptr(0), (*Sqlite3_rebaser)(unsafe.Pointer(p)).Fgrp.FpList)
		Xsqlite3_free(tls, p)
	}
}

func Xsqlite3session_config(tls *libc.TLS, op int32, pArg uintptr) int32 {
	var rc int32 = SQLITE_OK
	switch op {
	case SQLITE_SESSION_CONFIG_STRMSIZE:
		{
			var pInt uintptr = pArg
			if *(*int32)(unsafe.Pointer(pInt)) > 0 {
				sessions_strm_chunk_size = *(*int32)(unsafe.Pointer(pInt))
			}
			*(*int32)(unsafe.Pointer(pInt)) = sessions_strm_chunk_size
			break

		}
	default:
		rc = SQLITE_MISUSE
		break
	}
	return rc
}

type Fts5Global1 = struct {
	Fapi      Fts5_api
	Fdb       uintptr
	FiNextId  I64
	FpAux     uintptr
	FpTok     uintptr
	FpDfltTok uintptr
	FpCsr     uintptr
}

type Fts5Global = Fts5Global1
type Fts5Colset1 = struct {
	FnCol  int32
	FaiCol [1]int32
}

type Fts5Colset = Fts5Colset1

type Fts5Config1 = struct {
	Fdb               uintptr
	FzDb              uintptr
	FzName            uintptr
	FnCol             int32
	F__ccgo_pad1      [4]byte
	FazCol            uintptr
	FabUnindexed      uintptr
	FnPrefix          int32
	F__ccgo_pad2      [4]byte
	FaPrefix          uintptr
	FeContent         int32
	F__ccgo_pad3      [4]byte
	FzContent         uintptr
	FzContentRowid    uintptr
	FbColumnsize      int32
	FeDetail          int32
	FzContentExprlist uintptr
	FpTok             uintptr
	FpTokApi          uintptr
	FbLock            int32
	FePattern         int32
	FiCookie          int32
	Fpgsz             int32
	FnAutomerge       int32
	FnCrisisMerge     int32
	FnUsermerge       int32
	FnHashSize        int32
	FzRank            uintptr
	FzRankArgs        uintptr
	FpzErrmsg         uintptr
}

type Fts5Config = Fts5Config1

type Fts5Buffer1 = struct {
	Fp      uintptr
	Fn      int32
	FnSpace int32
}

type Fts5Buffer = Fts5Buffer1

type Fts5PoslistReader1 = struct {
	Fa           uintptr
	Fn           int32
	Fi           int32
	FbFlag       U8
	FbEof        U8
	F__ccgo_pad1 [6]byte
	FiPos        I64
}

type Fts5PoslistReader = Fts5PoslistReader1

type Fts5PoslistWriter1 = struct{ FiPrev I64 }

type Fts5PoslistWriter = Fts5PoslistWriter1

type Fts5Termset1 = struct{ FapHash [512]uintptr }

type Fts5Termset = Fts5Termset1

type Fts5Index1 = struct {
	FpConfig        uintptr
	FzDataTbl       uintptr
	FnWorkUnit      int32
	F__ccgo_pad1    [4]byte
	FpHash          uintptr
	FnPendingData   int32
	F__ccgo_pad2    [4]byte
	FiWriteRowid    I64
	FbDelete        int32
	Frc             int32
	FpReader        uintptr
	FpWriter        uintptr
	FpDeleter       uintptr
	FpIdxWriter     uintptr
	FpIdxDeleter    uintptr
	FpIdxSelect     uintptr
	FnRead          int32
	F__ccgo_pad3    [4]byte
	FpDataVersion   uintptr
	FiStructVersion I64
	FpStruct        uintptr
}

type Fts5Index = Fts5Index1
type Fts5IndexIter1 = struct {
	FiRowid      I64
	FpData       uintptr
	FnData       int32
	FbEof        U8
	F__ccgo_pad1 [3]byte
}

type Fts5IndexIter = Fts5IndexIter1

type Fts5Table1 = struct {
	Fbase    Sqlite3_vtab
	FpConfig uintptr
	FpIndex  uintptr
}

type Fts5Table = Fts5Table1

type Fts5Hash1 = struct {
	FeDetail     int32
	F__ccgo_pad1 [4]byte
	FpnByte      uintptr
	FnEntry      int32
	FnSlot       int32
	FpScan       uintptr
	FaSlot       uintptr
}

type Fts5Hash = Fts5Hash1

type Fts5Storage1 = struct {
	FpConfig      uintptr
	FpIndex       uintptr
	FbTotalsValid int32
	F__ccgo_pad1  [4]byte
	FnTotalRow    I64
	FaTotalSize   uintptr
	FaStmt        [11]uintptr
}

type Fts5Storage = Fts5Storage1

type Fts5Expr1 = struct {
	FpIndex       uintptr
	FpConfig      uintptr
	FpRoot        uintptr
	FbDesc        int32
	FnPhrase      int32
	FapExprPhrase uintptr
}

type Fts5Expr = Fts5Expr1
type Fts5ExprNode1 = struct {
	FeType       int32
	FbEof        int32
	FbNomatch    int32
	F__ccgo_pad1 [4]byte
	FxNext       uintptr
	FiRowid      I64
	FpNear       uintptr
	FnChild      int32
	F__ccgo_pad2 [4]byte
	FapChild     [1]uintptr
}

type Fts5ExprNode = Fts5ExprNode1
type Fts5Parse1 = struct {
	FpConfig      uintptr
	FzErr         uintptr
	Frc           int32
	FnPhrase      int32
	FapPhrase     uintptr
	FpExpr        uintptr
	FbPhraseToAnd int32
	F__ccgo_pad1  [4]byte
}

type Fts5Parse = Fts5Parse1
type Fts5Token1 = struct {
	Fp           uintptr
	Fn           int32
	F__ccgo_pad1 [4]byte
}

type Fts5Token = Fts5Token1
type Fts5ExprPhrase1 = struct {
	FpNode       uintptr
	Fposlist     Fts5Buffer
	FnTerm       int32
	F__ccgo_pad1 [4]byte
	FaTerm       [1]Fts5ExprTerm
}

type Fts5ExprPhrase = Fts5ExprPhrase1
type Fts5ExprNearset1 = struct {
	FnNear       int32
	F__ccgo_pad1 [4]byte
	FpColset     uintptr
	FnPhrase     int32
	F__ccgo_pad2 [4]byte
	FapPhrase    [1]uintptr
}

type Fts5ExprNearset = Fts5ExprNearset1

type Fts5PoslistPopulator1 = struct {
	Fwriter Fts5PoslistWriter
	FbOk    int32
	FbMiss  int32
}

type Fts5PoslistPopulator = Fts5PoslistPopulator1

type Fts5YYMINORTYPE = struct {
	F__ccgo_pad1 [0]uint64
	Ffts5yyinit  int32
	F__ccgo_pad2 [12]byte
}

var fts5yy_action = [105]uint8{
	uint8(81), uint8(20), uint8(96), uint8(6), uint8(28), uint8(99), uint8(98), uint8(26), uint8(26), uint8(18),
	uint8(96), uint8(6), uint8(28), uint8(17), uint8(98), uint8(56), uint8(26), uint8(19), uint8(96), uint8(6),
	uint8(28), uint8(14), uint8(98), uint8(14), uint8(26), uint8(31), uint8(92), uint8(96), uint8(6), uint8(28),
	uint8(108), uint8(98), uint8(25), uint8(26), uint8(21), uint8(96), uint8(6), uint8(28), uint8(78), uint8(98),
	uint8(58), uint8(26), uint8(29), uint8(96), uint8(6), uint8(28), uint8(107), uint8(98), uint8(22), uint8(26),
	uint8(24), uint8(16), uint8(12), uint8(11), uint8(1), uint8(13), uint8(13), uint8(24), uint8(16), uint8(23),
	uint8(11), uint8(33), uint8(34), uint8(13), uint8(97), uint8(8), uint8(27), uint8(32), uint8(98), uint8(7),
	uint8(26), uint8(3), uint8(4), uint8(5), uint8(3), uint8(4), uint8(5), uint8(3), uint8(83), uint8(4),
	uint8(5), uint8(3), uint8(63), uint8(5), uint8(3), uint8(62), uint8(12), uint8(2), uint8(86), uint8(13),
	uint8(9), uint8(30), uint8(10), uint8(10), uint8(54), uint8(57), uint8(75), uint8(78), uint8(78), uint8(53),
	uint8(57), uint8(15), uint8(82), uint8(82), uint8(71),
}
var fts5yy_lookahead = [121]uint8{
	uint8(16), uint8(17), uint8(18), uint8(19), uint8(20), uint8(22), uint8(22), uint8(24), uint8(24), uint8(17),
	uint8(18), uint8(19), uint8(20), uint8(7), uint8(22), uint8(9), uint8(24), uint8(17), uint8(18), uint8(19),
	uint8(20), uint8(9), uint8(22), uint8(9), uint8(24), uint8(13), uint8(17), uint8(18), uint8(19), uint8(20),
	uint8(26), uint8(22), uint8(24), uint8(24), uint8(17), uint8(18), uint8(19), uint8(20), uint8(15), uint8(22),
	uint8(9), uint8(24), uint8(17), uint8(18), uint8(19), uint8(20), uint8(26), uint8(22), uint8(21), uint8(24),
	uint8(6), uint8(7), uint8(9), uint8(9), uint8(10), uint8(12), uint8(12), uint8(6), uint8(7), uint8(21),
	uint8(9), uint8(24), uint8(25), uint8(12), uint8(18), uint8(5), uint8(20), uint8(14), uint8(22), uint8(5),
	uint8(24), uint8(3), uint8(1), uint8(2), uint8(3), uint8(1), uint8(2), uint8(3), uint8(0), uint8(1),
	uint8(2), uint8(3), uint8(11), uint8(2), uint8(3), uint8(11), uint8(9), uint8(10), uint8(5), uint8(12),
	uint8(23), uint8(24), uint8(10), uint8(10), uint8(8), uint8(9), uint8(9), uint8(15), uint8(15), uint8(8),
	uint8(9), uint8(9), uint8(27), uint8(27), uint8(11), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
	uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27), uint8(27),
	uint8(27),
}
var fts5yy_shift_ofst = [35]uint8{
	uint8(44), uint8(44), uint8(44), uint8(44), uint8(44), uint8(44), uint8(51), uint8(77), uint8(43), uint8(12),
	uint8(14), uint8(83), uint8(82), uint8(14), uint8(23), uint8(23), uint8(31), uint8(31), uint8(71), uint8(74),
	uint8(78), uint8(81), uint8(86), uint8(91), uint8(6), uint8(53), uint8(53), uint8(60), uint8(64), uint8(68),
	uint8(53), uint8(87), uint8(92), uint8(53), uint8(93),
}
var fts5yy_reduce_ofst = [18]int8{
	int8(-16), int8(-8), int8(0), int8(9), int8(17), int8(25), int8(46), int8(-17), int8(-17), int8(37),
	int8(67), int8(4), int8(4), int8(8), int8(4), int8(20), int8(27), int8(38),
}
var fts5yy_default = [35]uint8{
	uint8(80), uint8(80), uint8(80), uint8(80), uint8(80), uint8(80), uint8(95), uint8(80), uint8(80), uint8(105),
	uint8(80), uint8(110), uint8(110), uint8(80), uint8(110), uint8(110), uint8(80), uint8(80), uint8(80), uint8(80),
	uint8(80), uint8(91), uint8(80), uint8(80), uint8(80), uint8(101), uint8(100), uint8(80), uint8(80), uint8(90),
	uint8(103), uint8(80), uint8(80), uint8(104), uint8(80),
}

type fts5yyStackEntry = struct {
	Fstateno     uint8
	Fmajor       uint8
	F__ccgo_pad1 [6]byte
	Fminor       Fts5YYMINORTYPE
}

type Fts5yyStackEntry = fts5yyStackEntry

type fts5yyParser = struct {
	Ffts5yytos      uintptr
	FpParse         uintptr
	Ffts5yystack    [100]Fts5yyStackEntry
	Ffts5yystackEnd uintptr
}

type Fts5yyParser = fts5yyParser

func sqlite3Fts5ParserInit(tls *libc.TLS, fts5yypRawParser uintptr) {
	var fts5yypParser uintptr = fts5yypRawParser

	(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos = fts5yypParser + 16
	(*Fts5yyStackEntry)(unsafe.Pointer(fts5yypParser + 16)).Fstateno = uint8(0)
	(*Fts5yyStackEntry)(unsafe.Pointer(fts5yypParser + 16)).Fmajor = uint8(0)
	(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystackEnd = fts5yypParser + 16 + 99*24
}

func sqlite3Fts5ParserAlloc(tls *libc.TLS, mallocProc uintptr) uintptr {
	var fts5yypParser uintptr
	fts5yypParser = (*struct{ f func(*libc.TLS, U64) uintptr })(unsafe.Pointer(&struct{ uintptr }{mallocProc})).f(tls, U64(unsafe.Sizeof(Fts5yyParser{})))
	if fts5yypParser != 0 {
		sqlite3Fts5ParserInit(tls, fts5yypParser)
	}
	return fts5yypParser
}

func fts5yy_destructor(tls *libc.TLS, fts5yypParser uintptr, fts5yymajor uint8, fts5yypminor uintptr) {
	var pParse uintptr = (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	_ = pParse

	switch int32(fts5yymajor) {
	case 16:
		{
			_ = pParse
		}
		break
	case 17:
		fallthrough
	case 18:
		fallthrough
	case 19:
		{
			sqlite3Fts5ParseNodeFree(tls, *(*uintptr)(unsafe.Pointer(fts5yypminor)))
		}
		break
	case 20:
		fallthrough
	case 21:
		{
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(fts5yypminor)))
		}
		break
	case 22:
		fallthrough
	case 23:
		{
			sqlite3Fts5ParseNearsetFree(tls, *(*uintptr)(unsafe.Pointer(fts5yypminor)))
		}
		break
	case 24:
		{
			sqlite3Fts5ParsePhraseFree(tls, *(*uintptr)(unsafe.Pointer(fts5yypminor)))
		}
		break

	default:
		break
	}
}

func fts5yy_pop_parser_stack(tls *libc.TLS, pParser uintptr) {
	var fts5yytos uintptr

	fts5yytos = libc.PostDecUintptr(&(*Fts5yyParser)(unsafe.Pointer(pParser)).Ffts5yytos, 24)
	fts5yy_destructor(tls, pParser, (*Fts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fmajor, fts5yytos+8)
}

func sqlite3Fts5ParserFinalize(tls *libc.TLS, p uintptr) {
	var pParser uintptr = p
	for (*Fts5yyParser)(unsafe.Pointer(pParser)).Ffts5yytos > pParser+16 {
		fts5yy_pop_parser_stack(tls, pParser)
	}
}

func sqlite3Fts5ParserFree(tls *libc.TLS, p uintptr, freeProc uintptr) {
	if p == uintptr(0) {
		return
	}
	sqlite3Fts5ParserFinalize(tls, p)
	(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{freeProc})).f(tls, p)
}

func fts5yy_find_shift_action(tls *libc.TLS, iLookAhead uint8, stateno uint8) uint8 {
	var i int32

	if int32(stateno) > Fts5YY_MAX_SHIFT {
		return stateno
	}

	for __ccgo := true; __ccgo; __ccgo = 1 != 0 {
		i = int32(fts5yy_shift_ofst[stateno])

		i = i + int32(iLookAhead)

		if int32(fts5yy_lookahead[i]) != int32(iLookAhead) {
			return fts5yy_default[stateno]
		} else {
			return fts5yy_action[i]
		}
	}
	return uint8(0)
}

func fts5yy_find_reduce_action(tls *libc.TLS, stateno uint8, iLookAhead uint8) uint8 {
	var i int32

	i = int32(fts5yy_reduce_ofst[stateno])

	i = i + int32(iLookAhead)

	return fts5yy_action[i]
}

func fts5yyStackOverflow(tls *libc.TLS, fts5yypParser uintptr) {
	var pParse uintptr = (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse

	for (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos > fts5yypParser+16 {
		fts5yy_pop_parser_stack(tls, fts5yypParser)
	}

	sqlite3Fts5ParseError(tls, pParse, ts+40643, 0)

	(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse

}

func fts5yy_shift(tls *libc.TLS, fts5yypParser uintptr, fts5yyNewState uint8, fts5yyMajor uint8, fts5yyMinor Fts5Token) {
	var fts5yytos uintptr
	(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos += 24
	if (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos > (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystackEnd {
		(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos -= 24
		fts5yyStackOverflow(tls, fts5yypParser)
		return
	}
	if int32(fts5yyNewState) > Fts5YY_MAX_SHIFT {
		fts5yyNewState = uint8(int32(fts5yyNewState) + (Fts5YY_MIN_REDUCE - Fts5YY_MIN_SHIFTREDUCE))
	}
	fts5yytos = (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos
	(*Fts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fstateno = fts5yyNewState
	(*Fts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fmajor = fts5yyMajor
	*(*Fts5Token)(unsafe.Pointer(fts5yytos + 8)) = fts5yyMinor

}

var fts5yyRuleInfoLhs = [28]uint8{
	uint8(16),
	uint8(20),
	uint8(20),
	uint8(20),
	uint8(20),
	uint8(21),
	uint8(21),
	uint8(17),
	uint8(17),
	uint8(17),
	uint8(17),
	uint8(17),
	uint8(17),
	uint8(19),
	uint8(19),
	uint8(18),
	uint8(18),
	uint8(22),
	uint8(22),
	uint8(22),
	uint8(23),
	uint8(23),
	uint8(25),
	uint8(25),
	uint8(24),
	uint8(24),
	uint8(26),
	uint8(26),
}

var fts5yyRuleInfoNRhs = [28]int8{
	int8(-1),
	int8(-4),
	int8(-3),
	int8(-1),
	int8(-2),
	int8(-2),
	int8(-1),
	int8(-3),
	int8(-3),
	int8(-3),
	int8(-5),
	int8(-3),
	int8(-1),
	int8(-1),
	int8(-2),
	int8(-1),
	int8(-3),
	int8(-1),
	int8(-2),
	int8(-5),
	int8(-1),
	int8(-2),
	int8(0),
	int8(-2),
	int8(-4),
	int8(-2),
	int8(-1),
	int8(0),
}

func fts5yy_reduce(tls *libc.TLS, fts5yypParser uintptr, fts5yyruleno uint32, fts5yyLookahead int32, fts5yyLookaheadToken Fts5Token) uint8 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var fts5yygoto int32
	var fts5yyact uint8
	var fts5yymsp uintptr
	var fts5yysize int32
	var pParse uintptr = (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse
	_ = fts5yyLookahead
	_ = fts5yyLookaheadToken
	fts5yymsp = (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos

	{
		switch fts5yyruleno {
		case uint32(0):
			{
				sqlite3Fts5ParseFinished(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
			}
			break
		case uint32(1):
			{
				*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = sqlite3Fts5ParseColsetInvert(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(2):
			{
				*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		case uint32(3):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseColset(tls, pParse, uintptr(0), fts5yymsp+8)
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(4):
			{
				*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = sqlite3Fts5ParseColset(tls, pParse, uintptr(0), fts5yymsp+8)
				*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = sqlite3Fts5ParseColsetInvert(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)))
			}
			break
		case uint32(5):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseColset(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)), fts5yymsp+8)
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(6):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseColset(tls, pParse, uintptr(0), fts5yymsp+8)
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(7):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseNode(tls, pParse, FTS5_AND, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)), uintptr(0))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(8):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseNode(tls, pParse, FTS5_OR, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)), uintptr(0))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(9):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseNode(tls, pParse, FTS5_NOT, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)), uintptr(0))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(10):
			{
				sqlite3Fts5ParseSetColset(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-4)*24 + 8)))
				*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(11):
			{
				*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8))
			}
			break
		case uint32(12):
			fallthrough
		case uint32(13):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + 8))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(14):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseImplicitAnd(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(15):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseNode(tls, pParse, FTS5_STRING, uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(16):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseNode(tls, pParse, FTS5_STRING, uintptr(0), uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
				sqlite3Fts5ParseSetColset(tls, pParse, *(*uintptr)(unsafe.Pointer(bp)), *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(17):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseNearset(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(18):
			{
				sqlite3Fts5ParseSetCaret(tls, *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
				*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = sqlite3Fts5ParseNearset(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
			}
			break
		case uint32(19):
			{
				sqlite3Fts5ParseNear(tls, pParse, fts5yymsp+libc.UintptrFromInt32(-4)*24+8)
				sqlite3Fts5ParseSetDistance(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8)), fts5yymsp+libc.UintptrFromInt32(-1)*24+8)
				*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-2)*24 + 8))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-4)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(20):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseNearset(tls, pParse, uintptr(0), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(21):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseNearset(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)), *(*uintptr)(unsafe.Pointer(fts5yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(22):
			{
				(*Fts5Token)(unsafe.Pointer(fts5yymsp + 1*24 + 8)).Fp = uintptr(0)
				(*Fts5Token)(unsafe.Pointer(fts5yymsp + 1*24 + 8)).Fn = 0
			}
			break
		case uint32(23):
			{
				*(*Fts5Token)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*Fts5Token)(unsafe.Pointer(fts5yymsp + 8))
			}
			break
		case uint32(24):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseTerm(tls, pParse, *(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-3)*24 + 8)), fts5yymsp+libc.UintptrFromInt32(-1)*24+8, *(*int32)(unsafe.Pointer(fts5yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-3)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(25):
			{
				*(*uintptr)(unsafe.Pointer(bp)) = sqlite3Fts5ParseTerm(tls, pParse, uintptr(0), fts5yymsp+libc.UintptrFromInt32(-1)*24+8, *(*int32)(unsafe.Pointer(fts5yymsp + 8)))
			}
			*(*uintptr)(unsafe.Pointer(fts5yymsp + libc.UintptrFromInt32(-1)*24 + 8)) = *(*uintptr)(unsafe.Pointer(bp))
			break
		case uint32(26):
			{
				*(*int32)(unsafe.Pointer(fts5yymsp + 8)) = 1
			}
			break
		case uint32(27):
			{
				*(*int32)(unsafe.Pointer(fts5yymsp + 1*24 + 8)) = 0
			}
			break
		default:
			break

		}
	}

	fts5yygoto = int32(fts5yyRuleInfoLhs[fts5yyruleno])
	fts5yysize = int32(fts5yyRuleInfoNRhs[fts5yyruleno])
	fts5yyact = fts5yy_find_reduce_action(tls, (*Fts5yyStackEntry)(unsafe.Pointer(fts5yymsp+uintptr(fts5yysize)*24)).Fstateno, uint8(fts5yygoto))

	fts5yymsp += 24 * uintptr(fts5yysize+1)
	(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos = fts5yymsp
	(*Fts5yyStackEntry)(unsafe.Pointer(fts5yymsp)).Fstateno = fts5yyact
	(*Fts5yyStackEntry)(unsafe.Pointer(fts5yymsp)).Fmajor = uint8(fts5yygoto)

	return fts5yyact
}

func fts5yy_syntax_error(tls *libc.TLS, fts5yypParser uintptr, fts5yymajor int32, fts5yyminor Fts5Token) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pParse uintptr = (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse

	_ = fts5yymajor
	sqlite3Fts5ParseError(tls,
		pParse, ts+40671, libc.VaList(bp, fts5yyminor.Fn, fts5yyminor.Fp))

	(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse

}

func fts5yy_accept(tls *libc.TLS, fts5yypParser uintptr) {
	var pParse uintptr = (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse

	(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse

}

func sqlite3Fts5Parser(tls *libc.TLS, fts5yyp uintptr, fts5yymajor int32, fts5yyminor Fts5Token, pParse uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var fts5yyact uint8
	var fts5yypParser uintptr = fts5yyp

	(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).FpParse = pParse

	fts5yyact = (*Fts5yyStackEntry)(unsafe.Pointer((*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos)).Fstateno

	for 1 != 0 {
		fts5yyact = fts5yy_find_shift_action(tls, uint8(fts5yymajor), fts5yyact)
		if int32(fts5yyact) >= Fts5YY_MIN_REDUCE {
			var fts5yyruleno uint32 = uint32(int32(fts5yyact) - Fts5YY_MIN_REDUCE)

			if int32(fts5yyRuleInfoNRhs[fts5yyruleno]) == 0 {
				if (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos >= (*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystackEnd {
					fts5yyStackOverflow(tls, fts5yypParser)
					break
				}
			}
			fts5yyact = fts5yy_reduce(tls, fts5yypParser, fts5yyruleno, fts5yymajor, fts5yyminor)
		} else if int32(fts5yyact) <= Fts5YY_MAX_SHIFTREDUCE {
			fts5yy_shift(tls, fts5yypParser, fts5yyact, uint8(fts5yymajor), fts5yyminor)
			break
		} else if int32(fts5yyact) == Fts5YY_ACCEPT_ACTION {
			(*Fts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos -= 24
			fts5yy_accept(tls, fts5yypParser)
			return
		} else {
			*(*Fts5Token)(unsafe.Pointer(bp)) = fts5yyminor

			fts5yy_syntax_error(tls, fts5yypParser, fts5yymajor, fts5yyminor)
			fts5yy_destructor(tls, fts5yypParser, uint8(fts5yymajor), bp)
			break
		}
	}
	return
}

func sqlite3Fts5ParserFallback(tls *libc.TLS, iToken int32) int32 {
	_ = iToken
	return 0
}

type CInstIter1 = struct {
	FpApi        uintptr
	FpFts        uintptr
	FiCol        int32
	FiInst       int32
	FnInst       int32
	FiStart      int32
	FiEnd        int32
	F__ccgo_pad1 [4]byte
}

type CInstIter = CInstIter1

func fts5CInstIterNext(tls *libc.TLS, pIter uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var rc int32 = SQLITE_OK
	(*CInstIter)(unsafe.Pointer(pIter)).FiStart = -1
	(*CInstIter)(unsafe.Pointer(pIter)).FiEnd = -1

	for rc == SQLITE_OK && (*CInstIter)(unsafe.Pointer(pIter)).FiInst < (*CInstIter)(unsafe.Pointer(pIter)).FnInst {
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer((*CInstIter)(unsafe.Pointer(pIter)).FpApi)).FxInst})).f(tls, (*CInstIter)(unsafe.Pointer(pIter)).FpFts, (*CInstIter)(unsafe.Pointer(pIter)).FiInst, bp, bp+4, bp+8)
		if rc == SQLITE_OK {
			if *(*int32)(unsafe.Pointer(bp + 4)) == (*CInstIter)(unsafe.Pointer(pIter)).FiCol {
				var iEnd int32 = *(*int32)(unsafe.Pointer(bp + 8)) - 1 + (*struct {
					f func(*libc.TLS, uintptr, int32) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer((*CInstIter)(unsafe.Pointer(pIter)).FpApi)).FxPhraseSize})).f(tls, (*CInstIter)(unsafe.Pointer(pIter)).FpFts, *(*int32)(unsafe.Pointer(bp)))
				if (*CInstIter)(unsafe.Pointer(pIter)).FiStart < 0 {
					(*CInstIter)(unsafe.Pointer(pIter)).FiStart = *(*int32)(unsafe.Pointer(bp + 8))
					(*CInstIter)(unsafe.Pointer(pIter)).FiEnd = iEnd
				} else if *(*int32)(unsafe.Pointer(bp + 8)) <= (*CInstIter)(unsafe.Pointer(pIter)).FiEnd {
					if iEnd > (*CInstIter)(unsafe.Pointer(pIter)).FiEnd {
						(*CInstIter)(unsafe.Pointer(pIter)).FiEnd = iEnd
					}
				} else {
					break
				}
			}
			(*CInstIter)(unsafe.Pointer(pIter)).FiInst++
		}
	}

	return rc
}

func fts5CInstIterInit(tls *libc.TLS, pApi uintptr, pFts uintptr, iCol int32, pIter uintptr) int32 {
	var rc int32

	libc.Xmemset(tls, pIter, 0, uint64(unsafe.Sizeof(CInstIter{})))
	(*CInstIter)(unsafe.Pointer(pIter)).FpApi = pApi
	(*CInstIter)(unsafe.Pointer(pIter)).FpFts = pFts
	(*CInstIter)(unsafe.Pointer(pIter)).FiCol = iCol
	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})).f(tls, pFts, pIter+24)

	if rc == SQLITE_OK {
		rc = fts5CInstIterNext(tls, pIter)
	}

	return rc
}

type HighlightContext1 = struct {
	Fiter        CInstIter
	FiPos        int32
	FiRangeStart int32
	FiRangeEnd   int32
	F__ccgo_pad1 [4]byte
	FzOpen       uintptr
	FzClose      uintptr
	FzIn         uintptr
	FnIn         int32
	FiOff        int32
	FzOut        uintptr
}

type HighlightContext = HighlightContext1

func fts5HighlightAppend(tls *libc.TLS, pRc uintptr, p uintptr, z uintptr, n int32) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK && z != 0 {
		if n < 0 {
			n = int32(libc.Xstrlen(tls, z))
		}
		(*HighlightContext)(unsafe.Pointer(p)).FzOut = Xsqlite3_mprintf(tls, ts+40702, libc.VaList(bp, (*HighlightContext)(unsafe.Pointer(p)).FzOut, n, z))
		if (*HighlightContext)(unsafe.Pointer(p)).FzOut == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
		}
	}
}

func fts5HighlightCb(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iStartOff int32, iEndOff int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var p uintptr = pContext
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var iPos int32

	_ = pToken
	_ = nToken

	if tflags&FTS5_TOKEN_COLOCATED != 0 {
		return SQLITE_OK
	}
	iPos = libc.PostIncInt32(&(*HighlightContext)(unsafe.Pointer(p)).FiPos, 1)

	if (*HighlightContext)(unsafe.Pointer(p)).FiRangeEnd > 0 {
		if iPos < (*HighlightContext)(unsafe.Pointer(p)).FiRangeStart || iPos > (*HighlightContext)(unsafe.Pointer(p)).FiRangeEnd {
			return SQLITE_OK
		}
		if (*HighlightContext)(unsafe.Pointer(p)).FiRangeStart != 0 && iPos == (*HighlightContext)(unsafe.Pointer(p)).FiRangeStart {
			(*HighlightContext)(unsafe.Pointer(p)).FiOff = iStartOff
		}
	}

	if iPos == (*HighlightContext)(unsafe.Pointer(p)).Fiter.FiStart {
		fts5HighlightAppend(tls, bp, p, (*HighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*HighlightContext)(unsafe.Pointer(p)).FiOff), iStartOff-(*HighlightContext)(unsafe.Pointer(p)).FiOff)
		fts5HighlightAppend(tls, bp, p, (*HighlightContext)(unsafe.Pointer(p)).FzOpen, -1)
		(*HighlightContext)(unsafe.Pointer(p)).FiOff = iStartOff
	}

	if iPos == (*HighlightContext)(unsafe.Pointer(p)).Fiter.FiEnd {
		if (*HighlightContext)(unsafe.Pointer(p)).FiRangeEnd != 0 && (*HighlightContext)(unsafe.Pointer(p)).Fiter.FiStart < (*HighlightContext)(unsafe.Pointer(p)).FiRangeStart {
			fts5HighlightAppend(tls, bp, p, (*HighlightContext)(unsafe.Pointer(p)).FzOpen, -1)
		}
		fts5HighlightAppend(tls, bp, p, (*HighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*HighlightContext)(unsafe.Pointer(p)).FiOff), iEndOff-(*HighlightContext)(unsafe.Pointer(p)).FiOff)
		fts5HighlightAppend(tls, bp, p, (*HighlightContext)(unsafe.Pointer(p)).FzClose, -1)
		(*HighlightContext)(unsafe.Pointer(p)).FiOff = iEndOff
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp)) = fts5CInstIterNext(tls, p)
		}
	}

	if (*HighlightContext)(unsafe.Pointer(p)).FiRangeEnd > 0 && iPos == (*HighlightContext)(unsafe.Pointer(p)).FiRangeEnd {
		fts5HighlightAppend(tls, bp, p, (*HighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*HighlightContext)(unsafe.Pointer(p)).FiOff), iEndOff-(*HighlightContext)(unsafe.Pointer(p)).FiOff)
		(*HighlightContext)(unsafe.Pointer(p)).FiOff = iEndOff
		if iPos >= (*HighlightContext)(unsafe.Pointer(p)).Fiter.FiStart && iPos < (*HighlightContext)(unsafe.Pointer(p)).Fiter.FiEnd {
			fts5HighlightAppend(tls, bp, p, (*HighlightContext)(unsafe.Pointer(p)).FzClose, -1)
		}
	}

	return *(*int32)(unsafe.Pointer(bp))
}

func fts5HighlightFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(100)
	defer tls.Free(100)

	var iCol int32

	if nVal != 3 {
		var zErr uintptr = ts + 40709
		Xsqlite3_result_error(tls, pCtx, zErr, -1)
		return
	}

	iCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal)))
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(HighlightContext{})))
	(*HighlightContext)(unsafe.Pointer(bp)).FzOpen = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
	(*HighlightContext)(unsafe.Pointer(bp)).FzClose = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + 2*8)))
	*(*int32)(unsafe.Pointer(bp + 96)) = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})).f(tls, pFts, iCol, bp+72, bp+80)

	if (*HighlightContext)(unsafe.Pointer(bp)).FzIn != 0 {
		if *(*int32)(unsafe.Pointer(bp + 96)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 96)) = fts5CInstIterInit(tls, pApi, pFts, iCol, bp)
		}

		if *(*int32)(unsafe.Pointer(bp + 96)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 96)) = (*struct {
				f func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize})).f(tls, pFts, (*HighlightContext)(unsafe.Pointer(bp)).FzIn, (*HighlightContext)(unsafe.Pointer(bp)).FnIn, bp, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
			}{fts5HighlightCb})))
		}
		fts5HighlightAppend(tls, bp+96, bp, (*HighlightContext)(unsafe.Pointer(bp)).FzIn+uintptr((*HighlightContext)(unsafe.Pointer(bp)).FiOff), (*HighlightContext)(unsafe.Pointer(bp)).FnIn-(*HighlightContext)(unsafe.Pointer(bp)).FiOff)

		if *(*int32)(unsafe.Pointer(bp + 96)) == SQLITE_OK {
			Xsqlite3_result_text(tls, pCtx, (*HighlightContext)(unsafe.Pointer(bp)).FzOut, -1, libc.UintptrFromInt32(-1))
		}
		Xsqlite3_free(tls, (*HighlightContext)(unsafe.Pointer(bp)).FzOut)
	}
	if *(*int32)(unsafe.Pointer(bp + 96)) != SQLITE_OK {
		Xsqlite3_result_error_code(tls, pCtx, *(*int32)(unsafe.Pointer(bp + 96)))
	}
}

type Fts5SFinder1 = struct {
	FiPos        int32
	FnFirstAlloc int32
	FnFirst      int32
	F__ccgo_pad1 [4]byte
	FaFirst      uintptr
	FzDoc        uintptr
}

type Fts5SFinder = Fts5SFinder1

func fts5SentenceFinderAdd(tls *libc.TLS, p uintptr, iAdd int32) int32 {
	if (*Fts5SFinder)(unsafe.Pointer(p)).FnFirstAlloc == (*Fts5SFinder)(unsafe.Pointer(p)).FnFirst {
		var nNew int32
		if (*Fts5SFinder)(unsafe.Pointer(p)).FnFirstAlloc != 0 {
			nNew = (*Fts5SFinder)(unsafe.Pointer(p)).FnFirstAlloc * 2
		} else {
			nNew = 64
		}
		var aNew uintptr

		aNew = Xsqlite3_realloc64(tls, (*Fts5SFinder)(unsafe.Pointer(p)).FaFirst, uint64(nNew)*uint64(unsafe.Sizeof(int32(0))))
		if aNew == uintptr(0) {
			return SQLITE_NOMEM
		}
		(*Fts5SFinder)(unsafe.Pointer(p)).FaFirst = aNew
		(*Fts5SFinder)(unsafe.Pointer(p)).FnFirstAlloc = nNew
	}
	*(*int32)(unsafe.Pointer((*Fts5SFinder)(unsafe.Pointer(p)).FaFirst + uintptr(libc.PostIncInt32(&(*Fts5SFinder)(unsafe.Pointer(p)).FnFirst, 1))*4)) = iAdd
	return SQLITE_OK
}

func fts5SentenceFinderCb(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iStartOff int32, iEndOff int32) int32 {
	var rc int32 = SQLITE_OK

	_ = pToken
	_ = nToken
	_ = iEndOff

	if tflags&FTS5_TOKEN_COLOCATED == 0 {
		var p uintptr = pContext
		if (*Fts5SFinder)(unsafe.Pointer(p)).FiPos > 0 {
			var i int32
			var c uint8 = uint8(0)
			for i = iStartOff - 1; i >= 0; i-- {
				c = *(*uint8)(unsafe.Pointer((*Fts5SFinder)(unsafe.Pointer(p)).FzDoc + uintptr(i)))
				if int32(c) != ' ' && int32(c) != '\t' && int32(c) != '\n' && int32(c) != '\r' {
					break
				}
			}
			if i != iStartOff-1 && (int32(c) == '.' || int32(c) == ':') {
				rc = fts5SentenceFinderAdd(tls, p, (*Fts5SFinder)(unsafe.Pointer(p)).FiPos)
			}
		} else {
			rc = fts5SentenceFinderAdd(tls, p, 0)
		}
		(*Fts5SFinder)(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) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32
	var i int32
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	*(*int32)(unsafe.Pointer(bp + 12)) = 0
	var iFirst int32 = -1

	var nScore int32 = 0
	var iLast int32 = 0
	var iEnd Sqlite3_int64 = Sqlite3_int64(iPos) + Sqlite3_int64(nToken)

	rc = (*struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})).f(tls, pFts, bp)
	for i = 0; i < *(*int32)(unsafe.Pointer(bp)) && rc == SQLITE_OK; i++ {
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})).f(tls, pFts, i, bp+4, bp+8, bp+12)
		if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 8)) == iCol && *(*int32)(unsafe.Pointer(bp + 12)) >= iPos && Sqlite3_int64(*(*int32)(unsafe.Pointer(bp + 12))) < iEnd {
			nScore = nScore + func() int32 {
				if *(*uint8)(unsafe.Pointer(aSeen + uintptr(*(*int32)(unsafe.Pointer(bp + 4))))) != 0 {
					return 1
				}
				return 1000
			}()
			*(*uint8)(unsafe.Pointer(aSeen + uintptr(*(*int32)(unsafe.Pointer(bp + 4))))) = uint8(1)
			if iFirst < 0 {
				iFirst = *(*int32)(unsafe.Pointer(bp + 12))
			}
			iLast = *(*int32)(unsafe.Pointer(bp + 12)) + (*struct {
				f func(*libc.TLS, uintptr, int32) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseSize})).f(tls, pFts, *(*int32)(unsafe.Pointer(bp + 4)))
		}
	}

	*(*int32)(unsafe.Pointer(pnScore)) = nScore
	if piPos != 0 {
		var iAdj Sqlite3_int64 = Sqlite3_int64(iFirst - (nToken-(iLast-iFirst))/2)
		if iAdj+Sqlite3_int64(nToken) > Sqlite3_int64(nDocsize) {
			iAdj = Sqlite3_int64(nDocsize - nToken)
		}
		if iAdj < int64(0) {
			iAdj = int64(0)
		}
		*(*int32)(unsafe.Pointer(piPos)) = int32(iAdj)
	}

	return rc
}

func fts5ValueToText(tls *libc.TLS, pVal uintptr) uintptr {
	var zRet uintptr = Xsqlite3_value_text(tls, pVal)
	if zRet != 0 {
		return zRet
	}
	return ts + 1636
}

func fts5SnippetFunction(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(172)
	defer tls.Free(172)

	*(*int32)(unsafe.Pointer(bp + 168)) = SQLITE_OK
	var iCol int32
	var zEllips uintptr
	var nToken int32
	*(*int32)(unsafe.Pointer(bp + 96)) = 0
	var i int32
	var nPhrase int32
	var aSeen uintptr
	var iBestCol int32
	var iBestStart int32 = 0
	var nBestScore int32 = 0
	*(*int32)(unsafe.Pointer(bp + 164)) = 0

	var nCol int32

	if nVal != 5 {
		var zErr uintptr = ts + 40759
		Xsqlite3_result_error(tls, pCtx, zErr, -1)
		return
	}

	nCol = (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnCount})).f(tls, pFts)
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(HighlightContext{})))
	iCol = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal)))
	(*HighlightContext)(unsafe.Pointer(bp)).FzOpen = fts5ValueToText(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
	(*HighlightContext)(unsafe.Pointer(bp)).FzClose = fts5ValueToText(tls, *(*uintptr)(unsafe.Pointer(apVal + 2*8)))
	zEllips = fts5ValueToText(tls, *(*uintptr)(unsafe.Pointer(apVal + 3*8)))
	nToken = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal + 4*8)))

	iBestCol = func() int32 {
		if iCol >= 0 {
			return iCol
		}
		return 0
	}()
	nPhrase = (*struct {
		f func(*libc.TLS, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseCount})).f(tls, pFts)
	aSeen = Xsqlite3_malloc(tls, nPhrase)
	if aSeen == uintptr(0) {
		*(*int32)(unsafe.Pointer(bp + 168)) = SQLITE_NOMEM
	}
	if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 168)) = (*struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})).f(tls, pFts, bp+96)
	}

	libc.Xmemset(tls, bp+104, 0, uint64(unsafe.Sizeof(Fts5SFinder{})))
	for i = 0; i < nCol; i++ {
		if iCol < 0 || iCol == i {
			var ii int32
			(*Fts5SFinder)(unsafe.Pointer(bp + 104)).FiPos = 0
			(*Fts5SFinder)(unsafe.Pointer(bp + 104)).FnFirst = 0
			*(*int32)(unsafe.Pointer(bp + 168)) = (*struct {
				f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})).f(tls, pFts, i, bp+104+24, bp+136)
			if *(*int32)(unsafe.Pointer(bp + 168)) != SQLITE_OK {
				break
			}
			*(*int32)(unsafe.Pointer(bp + 168)) = (*struct {
				f func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize})).f(tls, pFts,
				(*Fts5SFinder)(unsafe.Pointer(bp+104)).FzDoc, *(*int32)(unsafe.Pointer(bp + 136)), bp+104, *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
				}{fts5SentenceFinderCb})))
			if *(*int32)(unsafe.Pointer(bp + 168)) != SQLITE_OK {
				break
			}
			*(*int32)(unsafe.Pointer(bp + 168)) = (*struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})).f(tls, pFts, i, bp+140)
			if *(*int32)(unsafe.Pointer(bp + 168)) != SQLITE_OK {
				break
			}

			for ii = 0; *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK && ii < *(*int32)(unsafe.Pointer(bp + 96)); ii++ {
				var jj int32

				*(*int32)(unsafe.Pointer(bp + 168)) = (*struct {
					f func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})).f(tls, pFts, ii, bp+144, bp+148, bp+152)
				if *(*int32)(unsafe.Pointer(bp + 148)) != i {
					continue
				}
				if *(*int32)(unsafe.Pointer(bp + 152)) > *(*int32)(unsafe.Pointer(bp + 140)) {
					*(*int32)(unsafe.Pointer(bp + 168)) = SQLITE_CORRUPT | int32(1)<<8
				}
				if *(*int32)(unsafe.Pointer(bp + 168)) != SQLITE_OK {
					continue
				}
				libc.Xmemset(tls, aSeen, 0, uint64(nPhrase))
				*(*int32)(unsafe.Pointer(bp + 168)) = fts5SnippetScore(tls, pApi, pFts, *(*int32)(unsafe.Pointer(bp + 140)), aSeen, i,
					*(*int32)(unsafe.Pointer(bp + 152)), nToken, bp+156, bp+160)
				if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 156)) > nBestScore {
					nBestScore = *(*int32)(unsafe.Pointer(bp + 156))
					iBestCol = i
					iBestStart = *(*int32)(unsafe.Pointer(bp + 160))
					*(*int32)(unsafe.Pointer(bp + 164)) = *(*int32)(unsafe.Pointer(bp + 140))
				}

				if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK && (*Fts5SFinder)(unsafe.Pointer(bp+104)).FnFirst != 0 && *(*int32)(unsafe.Pointer(bp + 140)) > nToken {
					for jj = 0; jj < (*Fts5SFinder)(unsafe.Pointer(bp+104)).FnFirst-1; jj++ {
						if *(*int32)(unsafe.Pointer((*Fts5SFinder)(unsafe.Pointer(bp+104)).FaFirst + uintptr(jj+1)*4)) > *(*int32)(unsafe.Pointer(bp + 152)) {
							break
						}
					}

					if *(*int32)(unsafe.Pointer((*Fts5SFinder)(unsafe.Pointer(bp+104)).FaFirst + uintptr(jj)*4)) < *(*int32)(unsafe.Pointer(bp + 152)) {
						libc.Xmemset(tls, aSeen, 0, uint64(nPhrase))
						*(*int32)(unsafe.Pointer(bp + 168)) = fts5SnippetScore(tls, pApi, pFts, *(*int32)(unsafe.Pointer(bp + 140)), aSeen, i,
							*(*int32)(unsafe.Pointer((*Fts5SFinder)(unsafe.Pointer(bp+104)).FaFirst + uintptr(jj)*4)), nToken, bp+156, uintptr(0))

						*(*int32)(unsafe.Pointer(bp + 156)) += func() int32 {
							if *(*int32)(unsafe.Pointer((*Fts5SFinder)(unsafe.Pointer(bp+104)).FaFirst + uintptr(jj)*4)) == 0 {
								return 120
							}
							return 100
						}()
						if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 156)) > nBestScore {
							nBestScore = *(*int32)(unsafe.Pointer(bp + 156))
							iBestCol = i
							iBestStart = *(*int32)(unsafe.Pointer((*Fts5SFinder)(unsafe.Pointer(bp+104)).FaFirst + uintptr(jj)*4))
							*(*int32)(unsafe.Pointer(bp + 164)) = *(*int32)(unsafe.Pointer(bp + 140))
						}
					}
				}
			}
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 168)) = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnText})).f(tls, pFts, iBestCol, bp+72, bp+80)
	}
	if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK && *(*int32)(unsafe.Pointer(bp + 164)) == 0 {
		*(*int32)(unsafe.Pointer(bp + 168)) = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})).f(tls, pFts, iBestCol, bp+164)
	}
	if (*HighlightContext)(unsafe.Pointer(bp)).FzIn != 0 {
		if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 168)) = fts5CInstIterInit(tls, pApi, pFts, iBestCol, bp)
		}

		(*HighlightContext)(unsafe.Pointer(bp)).FiRangeStart = iBestStart
		(*HighlightContext)(unsafe.Pointer(bp)).FiRangeEnd = iBestStart + nToken - 1

		if iBestStart > 0 {
			fts5HighlightAppend(tls, bp+168, bp, zEllips, -1)
		}

		for (*HighlightContext)(unsafe.Pointer(bp)).Fiter.FiStart >= 0 && (*HighlightContext)(unsafe.Pointer(bp)).Fiter.FiStart < iBestStart && *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 168)) = fts5CInstIterNext(tls, bp)
		}

		if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 168)) = (*struct {
				f func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxTokenize})).f(tls, pFts, (*HighlightContext)(unsafe.Pointer(bp)).FzIn, (*HighlightContext)(unsafe.Pointer(bp)).FnIn, bp, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
			}{fts5HighlightCb})))
		}
		if (*HighlightContext)(unsafe.Pointer(bp)).FiRangeEnd >= *(*int32)(unsafe.Pointer(bp + 164))-1 {
			fts5HighlightAppend(tls, bp+168, bp, (*HighlightContext)(unsafe.Pointer(bp)).FzIn+uintptr((*HighlightContext)(unsafe.Pointer(bp)).FiOff), (*HighlightContext)(unsafe.Pointer(bp)).FnIn-(*HighlightContext)(unsafe.Pointer(bp)).FiOff)
		} else {
			fts5HighlightAppend(tls, bp+168, bp, zEllips, -1)
		}
	}
	if *(*int32)(unsafe.Pointer(bp + 168)) == SQLITE_OK {
		Xsqlite3_result_text(tls, pCtx, (*HighlightContext)(unsafe.Pointer(bp)).FzOut, -1, libc.UintptrFromInt32(-1))
	} else {
		Xsqlite3_result_error_code(tls, pCtx, *(*int32)(unsafe.Pointer(bp + 168)))
	}
	Xsqlite3_free(tls, (*HighlightContext)(unsafe.Pointer(bp)).FzOut)
	Xsqlite3_free(tls, aSeen)
	Xsqlite3_free(tls, (*Fts5SFinder)(unsafe.Pointer(bp+104)).FaFirst)
}

type Fts5Bm25Data1 = struct {
	FnPhrase     int32
	F__ccgo_pad1 [4]byte
	Favgdl       float64
	FaIDF        uintptr
	FaFreq       uintptr
}

type Fts5Bm25Data = Fts5Bm25Data1

func fts5CountCb(tls *libc.TLS, pApi uintptr, pFts uintptr, pUserData uintptr) int32 {
	var pn uintptr = pUserData
	_ = pApi
	_ = pFts
	*(*Sqlite3_int64)(unsafe.Pointer(pn))++
	return SQLITE_OK
}

func fts5Bm25GetData(tls *libc.TLS, pApi uintptr, pFts uintptr, ppData uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32 = SQLITE_OK
	var p uintptr

	p = (*struct {
		f func(*libc.TLS, uintptr, int32) uintptr
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxGetAuxdata})).f(tls, pFts, 0)
	if p == uintptr(0) {
		var nPhrase int32
		*(*Sqlite3_int64)(unsafe.Pointer(bp)) = int64(0)
		*(*Sqlite3_int64)(unsafe.Pointer(bp + 8)) = int64(0)
		var nByte Sqlite3_int64
		var i int32

		nPhrase = (*struct {
			f func(*libc.TLS, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxPhraseCount})).f(tls, pFts)
		nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Bm25Data{})) + uint64(nPhrase*2)*uint64(unsafe.Sizeof(float64(0))))
		p = Xsqlite3_malloc64(tls, uint64(nByte))
		if p == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			libc.Xmemset(tls, p, 0, Size_t(nByte))
			(*Fts5Bm25Data)(unsafe.Pointer(p)).FnPhrase = nPhrase
			(*Fts5Bm25Data)(unsafe.Pointer(p)).FaIDF = p + 1*32
			(*Fts5Bm25Data)(unsafe.Pointer(p)).FaFreq = (*Fts5Bm25Data)(unsafe.Pointer(p)).FaIDF + uintptr(nPhrase)*8
		}

		if rc == SQLITE_OK {
			rc = (*struct {
				f func(*libc.TLS, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxRowCount})).f(tls, pFts, bp)
		}

		if rc == SQLITE_OK {
			rc = (*struct {
				f func(*libc.TLS, uintptr, int32, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnTotalSize})).f(tls, pFts, -1, bp+8)
		}
		if rc == SQLITE_OK {
			(*Fts5Bm25Data)(unsafe.Pointer(p)).Favgdl = float64(*(*Sqlite3_int64)(unsafe.Pointer(bp + 8))) / float64(*(*Sqlite3_int64)(unsafe.Pointer(bp)))
		}

		for i = 0; rc == SQLITE_OK && i < nPhrase; i++ {
			*(*Sqlite3_int64)(unsafe.Pointer(bp + 16)) = int64(0)
			rc = (*struct {
				f func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxQueryPhrase})).f(tls, pFts, i, bp+16, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr) int32
			}{fts5CountCb})))
			if rc == SQLITE_OK {
				var idf float64 = libc.Xlog(tls, (float64(*(*Sqlite3_int64)(unsafe.Pointer(bp))-*(*Sqlite3_int64)(unsafe.Pointer(bp + 16)))+0.5)/(float64(*(*Sqlite3_int64)(unsafe.Pointer(bp + 16)))+0.5))
				if idf <= 0.0 {
					idf = 1e-6
				}
				*(*float64)(unsafe.Pointer((*Fts5Bm25Data)(unsafe.Pointer(p)).FaIDF + uintptr(i)*8)) = idf
			}
		}

		if rc != SQLITE_OK {
			Xsqlite3_free(tls, p)
		} else {
			rc = (*struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxSetAuxdata})).f(tls, pFts, p, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
		}
		if rc != SQLITE_OK {
			p = uintptr(0)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppData)) = p
	return rc
}

func fts5Bm25Function(tls *libc.TLS, pApi uintptr, pFts uintptr, pCtx uintptr, nVal int32, apVal uintptr) {
	bp := tls.Alloc(28)
	defer tls.Free(28)

	var k1 float64 = 1.2
	var b float64 = 0.75
	var rc int32
	var score float64 = 0.0

	var i int32
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	var D float64 = 0.0
	var aFreq uintptr = uintptr(0)

	rc = fts5Bm25GetData(tls, pApi, pFts, bp)
	if rc == SQLITE_OK {
		aFreq = (*Fts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaFreq
		libc.Xmemset(tls, aFreq, 0, uint64(unsafe.Sizeof(float64(0)))*uint64((*Fts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnPhrase))
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})).f(tls, pFts, bp+8)
	}
	for i = 0; rc == SQLITE_OK && i < *(*int32)(unsafe.Pointer(bp + 8)); i++ {
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxInst})).f(tls, pFts, i, bp+12, bp+16, bp+20)
		if rc == SQLITE_OK {
			var w float64
			if nVal > *(*int32)(unsafe.Pointer(bp + 16)) {
				w = Xsqlite3_value_double(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(*(*int32)(unsafe.Pointer(bp + 16)))*8)))
			} else {
				w = 1.0
			}
			*(*float64)(unsafe.Pointer(aFreq + uintptr(*(*int32)(unsafe.Pointer(bp + 12)))*8)) += w
		}
	}

	if rc == SQLITE_OK {
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExtensionApi)(unsafe.Pointer(pApi)).FxColumnSize})).f(tls, pFts, -1, bp+24)
		D = float64(*(*int32)(unsafe.Pointer(bp + 24)))
	}

	if rc == SQLITE_OK {
		for i = 0; i < (*Fts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnPhrase; i++ {
			score = score + *(*float64)(unsafe.Pointer((*Fts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaIDF + uintptr(i)*8))*(*(*float64)(unsafe.Pointer(aFreq + uintptr(i)*8))*(k1+1.0)/(*(*float64)(unsafe.Pointer(aFreq + uintptr(i)*8))+k1*(float64(1)-b+b*D/(*Fts5Bm25Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Favgdl)))
		}
		Xsqlite3_result_double(tls, pCtx, -1.0*score)
	} else {
		Xsqlite3_result_error_code(tls, pCtx, rc)
	}
}

func sqlite3Fts5AuxInit(tls *libc.TLS, pApi uintptr) int32 {
	bp := tls.Alloc(96)
	defer tls.Free(96)

	*(*[3]Builtin)(unsafe.Pointer(bp)) = [3]Builtin{
		{FzFunc: ts + 40807, FxFunc: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr)
		}{fts5SnippetFunction}))},
		{FzFunc: ts + 40815, FxFunc: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr)
		}{fts5HighlightFunction}))},
		{FzFunc: ts + 40825, FxFunc: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr)
		}{fts5Bm25Function}))},
	}
	var rc int32 = SQLITE_OK
	var i int32

	for i = 0; rc == SQLITE_OK && i < int32(uint64(unsafe.Sizeof([3]Builtin{}))/uint64(unsafe.Sizeof(Builtin{}))); i++ {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, Fts5_extension_function, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5_api)(unsafe.Pointer(pApi)).FxCreateFunction})).f(tls, pApi,
			(*Builtin)(unsafe.Pointer(bp+uintptr(i)*32)).FzFunc,
			(*Builtin)(unsafe.Pointer(bp+uintptr(i)*32)).FpUserData,
			(*Builtin)(unsafe.Pointer(bp+uintptr(i)*32)).FxFunc,
			(*Builtin)(unsafe.Pointer(bp+uintptr(i)*32)).FxDestroy)
	}

	return rc
}

type Builtin = struct {
	FzFunc     uintptr
	FpUserData uintptr
	FxFunc     Fts5_extension_function
	FxDestroy  uintptr
}

func sqlite3Fts5BufferSize(tls *libc.TLS, pRc uintptr, pBuf uintptr, nByte U32) int32 {
	if U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) < nByte {
		var nNew U64
		if (*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace != 0 {
			nNew = uint64((*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace)
		} else {
			nNew = uint64(64)
		}
		var pNew uintptr
		for nNew < U64(nByte) {
			nNew = nNew * uint64(2)
		}
		pNew = Xsqlite3_realloc64(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp, nNew)
		if pNew == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
			return 1
		} else {
			(*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace = int32(nNew)
			(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp = pNew
		}
	}
	return 0
}

func sqlite3Fts5BufferAppendVarint(tls *libc.TLS, pRc uintptr, pBuf uintptr, iVal I64) {
	if func() int32 {
		if U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn)+U32(9) <= U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
			return 0
		}
		return sqlite3Fts5BufferSize(tls, pRc, pBuf, uint32(9+(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn))
	}() != 0 {
		return
	}
	*(*int32)(unsafe.Pointer(pBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(iVal))
}

func sqlite3Fts5Put32(tls *libc.TLS, aBuf uintptr, iVal int32) {
	*(*U8)(unsafe.Pointer(aBuf)) = U8(iVal >> 24 & 0x00FF)
	*(*U8)(unsafe.Pointer(aBuf + 1)) = U8(iVal >> 16 & 0x00FF)
	*(*U8)(unsafe.Pointer(aBuf + 2)) = U8(iVal >> 8 & 0x00FF)
	*(*U8)(unsafe.Pointer(aBuf + 3)) = U8(iVal >> 0 & 0x00FF)
}

func sqlite3Fts5Get32(tls *libc.TLS, aBuf uintptr) int32 {
	return int32(U32(*(*U8)(unsafe.Pointer(aBuf)))<<24 + U32(int32(*(*U8)(unsafe.Pointer(aBuf + 1)))<<16) + U32(int32(*(*U8)(unsafe.Pointer(aBuf + 2)))<<8) + U32(*(*U8)(unsafe.Pointer(aBuf + 3))))
}

func sqlite3Fts5BufferAppendBlob(tls *libc.TLS, pRc uintptr, pBuf uintptr, nData U32, pData uintptr) {
	if nData != 0 {
		if func() int32 {
			if U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn)+nData <= U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
				return 0
			}
			return sqlite3Fts5BufferSize(tls, pRc, pBuf, nData+U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn))
		}() != 0 {
			return
		}
		libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), pData, uint64(nData))
		*(*int32)(unsafe.Pointer(pBuf + 8)) += int32(nData)
	}
}

func sqlite3Fts5BufferAppendString(tls *libc.TLS, pRc uintptr, pBuf uintptr, zStr uintptr) {
	var nStr int32 = int32(libc.Xstrlen(tls, zStr))
	sqlite3Fts5BufferAppendBlob(tls, pRc, pBuf, uint32(nStr+1), zStr)
	(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn--
}

func sqlite3Fts5BufferAppendPrintf(tls *libc.TLS, pRc uintptr, pBuf uintptr, zFmt uintptr, va uintptr) {
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var zTmp uintptr
		var ap Va_list
		_ = ap
		ap = va
		zTmp = Xsqlite3_vmprintf(tls, zFmt, ap)
		_ = ap

		if zTmp == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
		} else {
			sqlite3Fts5BufferAppendString(tls, pRc, pBuf, zTmp)
			Xsqlite3_free(tls, zTmp)
		}
	}
}

func sqlite3Fts5Mprintf(tls *libc.TLS, pRc uintptr, zFmt uintptr, va uintptr) uintptr {
	var zRet uintptr = uintptr(0)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var ap Va_list
		_ = ap
		ap = va
		zRet = Xsqlite3_vmprintf(tls, zFmt, ap)
		_ = ap
		if zRet == uintptr(0) {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
		}
	}
	return zRet
}

func sqlite3Fts5BufferFree(tls *libc.TLS, pBuf uintptr) {
	Xsqlite3_free(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp)
	libc.Xmemset(tls, pBuf, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))
}

func sqlite3Fts5BufferZero(tls *libc.TLS, pBuf uintptr) {
	(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn = 0
}

func sqlite3Fts5BufferSet(tls *libc.TLS, pRc uintptr, pBuf uintptr, nData int32, pData uintptr) {
	(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn = 0
	sqlite3Fts5BufferAppendBlob(tls, pRc, pBuf, uint32(nData), pData)
}

func sqlite3Fts5PoslistNext64(tls *libc.TLS, a uintptr, n int32, pi uintptr, piOff uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var i int32 = *(*int32)(unsafe.Pointer(pi))
	if i >= n {
		*(*I64)(unsafe.Pointer(piOff)) = int64(-1)
		return 1
	} else {
		var iOff I64 = *(*I64)(unsafe.Pointer(piOff))

		{
			*(*U32)(unsafe.Pointer(bp)) = U32(*(*U8)(unsafe.Pointer(a + uintptr(libc.PostIncInt32(&i, 1)))))
			if *(*U32)(unsafe.Pointer(bp))&U32(0x80) != 0 {
				i--
				i = i + sqlite3Fts5GetVarint32(tls, a+uintptr(i), bp)
			}
		}

		if *(*U32)(unsafe.Pointer(bp)) <= U32(1) {
			if *(*U32)(unsafe.Pointer(bp)) == U32(0) {
				*(*int32)(unsafe.Pointer(pi)) = i
				return 0
			}
			{
				*(*U32)(unsafe.Pointer(bp)) = U32(*(*U8)(unsafe.Pointer(a + uintptr(libc.PostIncInt32(&i, 1)))))
				if *(*U32)(unsafe.Pointer(bp))&U32(0x80) != 0 {
					i--
					i = i + sqlite3Fts5GetVarint32(tls, a+uintptr(i), bp)
				}
			}

			iOff = I64(*(*U32)(unsafe.Pointer(bp))) << 32

			{
				*(*U32)(unsafe.Pointer(bp)) = U32(*(*U8)(unsafe.Pointer(a + uintptr(libc.PostIncInt32(&i, 1)))))
				if *(*U32)(unsafe.Pointer(bp))&U32(0x80) != 0 {
					i--
					i = i + sqlite3Fts5GetVarint32(tls, a+uintptr(i), bp)
				}
			}

			if *(*U32)(unsafe.Pointer(bp)) < U32(2) {
				*(*I64)(unsafe.Pointer(piOff)) = int64(-1)
				return 1
			}
			*(*I64)(unsafe.Pointer(piOff)) = iOff + I64((*(*U32)(unsafe.Pointer(bp))-U32(2))&U32(0x7FFFFFFF))
		} else {
			*(*I64)(unsafe.Pointer(piOff)) = iOff&(int64(0x7FFFFFFF)<<32) + (iOff+I64(*(*U32)(unsafe.Pointer(bp))-U32(2)))&int64(0x7FFFFFFF)
		}
		*(*int32)(unsafe.Pointer(pi)) = i

		return 0
	}
	return int32(0)
}

func sqlite3Fts5PoslistReaderNext(tls *libc.TLS, pIter uintptr) int32 {
	if sqlite3Fts5PoslistNext64(tls, (*Fts5PoslistReader)(unsafe.Pointer(pIter)).Fa, (*Fts5PoslistReader)(unsafe.Pointer(pIter)).Fn, pIter+12, pIter+24) != 0 {
		(*Fts5PoslistReader)(unsafe.Pointer(pIter)).FbEof = U8(1)
	}
	return int32((*Fts5PoslistReader)(unsafe.Pointer(pIter)).FbEof)
}

func sqlite3Fts5PoslistReaderInit(tls *libc.TLS, a uintptr, n int32, pIter uintptr) int32 {
	libc.Xmemset(tls, pIter, 0, uint64(unsafe.Sizeof(Fts5PoslistReader{})))
	(*Fts5PoslistReader)(unsafe.Pointer(pIter)).Fa = a
	(*Fts5PoslistReader)(unsafe.Pointer(pIter)).Fn = n
	sqlite3Fts5PoslistReaderNext(tls, pIter)
	return int32((*Fts5PoslistReader)(unsafe.Pointer(pIter)).FbEof)
}

func sqlite3Fts5PoslistSafeAppend(tls *libc.TLS, pBuf uintptr, piPrev uintptr, iPos I64) {
	if iPos >= *(*I64)(unsafe.Pointer(piPrev)) {
		if iPos&colmask != *(*I64)(unsafe.Pointer(piPrev))&colmask {
			*(*U8)(unsafe.Pointer((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(libc.PostIncInt32(&(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn, 1)))) = U8(1)
			*(*int32)(unsafe.Pointer(pBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(iPos>>32))
			*(*I64)(unsafe.Pointer(piPrev)) = iPos & colmask
		}
		*(*int32)(unsafe.Pointer(pBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(iPos-*(*I64)(unsafe.Pointer(piPrev))+int64(2)))
		*(*I64)(unsafe.Pointer(piPrev)) = iPos
	}
}

var colmask I64 = int64(0x7FFFFFFF) << 32

func sqlite3Fts5PoslistWriterAppend(tls *libc.TLS, pBuf uintptr, pWriter uintptr, iPos I64) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = 0
	if func() int32 {
		if U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn)+U32(5+5+5) <= U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
			return 0
		}
		return sqlite3Fts5BufferSize(tls, bp, pBuf, uint32(5+5+5+(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn))
	}() != 0 {
		return *(*int32)(unsafe.Pointer(bp))
	}
	sqlite3Fts5PoslistSafeAppend(tls, pBuf, pWriter, iPos)
	return SQLITE_OK
}

func sqlite3Fts5MallocZero(tls *libc.TLS, pRc uintptr, nByte Sqlite3_int64) uintptr {
	var pRet uintptr = uintptr(0)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		pRet = Xsqlite3_malloc64(tls, uint64(nByte))
		if pRet == uintptr(0) {
			if nByte > int64(0) {
				*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
			}
		} else {
			libc.Xmemset(tls, pRet, 0, Size_t(nByte))
		}
	}
	return pRet
}

func sqlite3Fts5Strndup(tls *libc.TLS, pRc uintptr, pIn uintptr, nIn int32) uintptr {
	var zRet uintptr = uintptr(0)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		if nIn < 0 {
			nIn = int32(libc.Xstrlen(tls, pIn))
		}
		zRet = Xsqlite3_malloc(tls, nIn+1)
		if zRet != 0 {
			libc.Xmemcpy(tls, zRet, pIn, uint64(nIn))
			*(*uint8)(unsafe.Pointer(zRet + uintptr(nIn))) = uint8(0)
		} else {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
		}
	}
	return zRet
}

func sqlite3Fts5IsBareword(tls *libc.TLS, t uint8) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	*(*[128]U8)(unsafe.Pointer(bp)) = [128]U8{
		U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0),
		U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(1), U8(0), U8(0), U8(0), U8(0), U8(0),
		U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0),
		U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0),
		U8(0), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1),
		U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(0), U8(0), U8(0), U8(0), U8(1),
		U8(0), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1),
		U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(1), U8(0), U8(0), U8(0), U8(0), U8(0),
	}

	return libc.Bool32(int32(t)&0x80 != 0 || *(*U8)(unsafe.Pointer(bp + uintptr(int32(t)))) != 0)
}

type Fts5TermsetEntry1 = struct {
	FpTerm uintptr
	FnTerm int32
	FiIdx  int32
	FpNext uintptr
}

type Fts5TermsetEntry = Fts5TermsetEntry1

func sqlite3Fts5TermsetNew(tls *libc.TLS, pp uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(pp)) = sqlite3Fts5MallocZero(tls, bp, int64(unsafe.Sizeof(Fts5Termset{})))
	return *(*int32)(unsafe.Pointer(bp))
}

func sqlite3Fts5TermsetAdd(tls *libc.TLS, p uintptr, iIdx int32, pTerm uintptr, nTerm int32, pbPresent uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*int32)(unsafe.Pointer(pbPresent)) = 0
	if p != 0 {
		var i int32
		var hash U32 = U32(13)
		var pEntry uintptr

		for i = nTerm - 1; i >= 0; i-- {
			hash = hash<<3 ^ hash ^ U32(*(*uint8)(unsafe.Pointer(pTerm + uintptr(i))))
		}
		hash = hash<<3 ^ hash ^ U32(iIdx)
		hash = hash % U32(int32(uint64(unsafe.Sizeof([512]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0)))))

		for pEntry = *(*uintptr)(unsafe.Pointer(p + uintptr(hash)*8)); pEntry != 0; pEntry = (*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FpNext {
			if (*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FiIdx == iIdx &&
				(*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FnTerm == nTerm &&
				libc.Xmemcmp(tls, (*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FpTerm, pTerm, uint64(nTerm)) == 0 {
				*(*int32)(unsafe.Pointer(pbPresent)) = 1
				break
			}
		}

		if pEntry == uintptr(0) {
			pEntry = sqlite3Fts5MallocZero(tls, bp, int64(uint64(unsafe.Sizeof(Fts5TermsetEntry{}))+uint64(nTerm)))
			if pEntry != 0 {
				(*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FpTerm = pEntry + 1*24
				(*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FnTerm = nTerm
				(*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FiIdx = iIdx
				libc.Xmemcpy(tls, (*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FpTerm, pTerm, uint64(nTerm))
				(*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FpNext = *(*uintptr)(unsafe.Pointer(p + uintptr(hash)*8))
				*(*uintptr)(unsafe.Pointer(p + uintptr(hash)*8)) = pEntry
			}
		}
	}

	return *(*int32)(unsafe.Pointer(bp))
}

func sqlite3Fts5TermsetFree(tls *libc.TLS, p uintptr) {
	if p != 0 {
		var i U32
		for i = U32(0); i < U32(int32(uint64(unsafe.Sizeof([512]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0))))); i++ {
			var pEntry uintptr = *(*uintptr)(unsafe.Pointer(p + uintptr(i)*8))
			for pEntry != 0 {
				var pDel uintptr = pEntry
				pEntry = (*Fts5TermsetEntry)(unsafe.Pointer(pEntry)).FpNext
				Xsqlite3_free(tls, pDel)
			}
		}
		Xsqlite3_free(tls, p)
	}
}

func fts5_iswhitespace(tls *libc.TLS, x uint8) int32 {
	return libc.Bool32(int32(x) == ' ')
}

func fts5_isopenquote(tls *libc.TLS, x uint8) int32 {
	return libc.Bool32(int32(x) == '"' || int32(x) == '\'' || int32(x) == '[' || int32(x) == '`')
}

func fts5ConfigSkipWhitespace(tls *libc.TLS, pIn uintptr) uintptr {
	var p uintptr = pIn
	if p != 0 {
		for fts5_iswhitespace(tls, *(*uint8)(unsafe.Pointer(p))) != 0 {
			p++
		}
	}
	return p
}

func fts5ConfigSkipBareword(tls *libc.TLS, pIn uintptr) uintptr {
	var p uintptr = pIn
	for sqlite3Fts5IsBareword(tls, *(*uint8)(unsafe.Pointer(p))) != 0 {
		p++
	}
	if p == pIn {
		p = uintptr(0)
	}
	return p
}

func fts5_isdigit(tls *libc.TLS, a uint8) int32 {
	return libc.Bool32(int32(a) >= '0' && int32(a) <= '9')
}

func fts5ConfigSkipLiteral(tls *libc.TLS, pIn uintptr) uintptr {
	var p uintptr = pIn
	switch int32(*(*uint8)(unsafe.Pointer(p))) {
	case 'n':
		fallthrough
	case 'N':
		if Xsqlite3_strnicmp(tls, ts+9106, p, 4) == 0 {
			p = p + 4
		} else {
			p = uintptr(0)
		}
		break

	case 'x':
		fallthrough
	case 'X':
		p++
		if int32(*(*uint8)(unsafe.Pointer(p))) == '\'' {
			p++
			for int32(*(*uint8)(unsafe.Pointer(p))) >= 'a' && int32(*(*uint8)(unsafe.Pointer(p))) <= 'f' ||
				int32(*(*uint8)(unsafe.Pointer(p))) >= 'A' && int32(*(*uint8)(unsafe.Pointer(p))) <= 'F' ||
				int32(*(*uint8)(unsafe.Pointer(p))) >= '0' && int32(*(*uint8)(unsafe.Pointer(p))) <= '9' {
				p++
			}
			if int32(*(*uint8)(unsafe.Pointer(p))) == '\'' && int64(0) == (int64(p)-int64(pIn))/1%int64(2) {
				p++
			} else {
				p = uintptr(0)
			}
		} else {
			p = uintptr(0)
		}
		break

	case '\'':
		p++
		for p != 0 {
			if int32(*(*uint8)(unsafe.Pointer(p))) == '\'' {
				p++
				if int32(*(*uint8)(unsafe.Pointer(p))) != '\'' {
					break
				}
			}
			p++
			if int32(*(*uint8)(unsafe.Pointer(p))) == 0 {
				p = uintptr(0)
			}
		}
		break

	default:
		if int32(*(*uint8)(unsafe.Pointer(p))) == '+' || int32(*(*uint8)(unsafe.Pointer(p))) == '-' {
			p++
		}
		for fts5_isdigit(tls, *(*uint8)(unsafe.Pointer(p))) != 0 {
			p++
		}

		if int32(*(*uint8)(unsafe.Pointer(p))) == '.' && fts5_isdigit(tls, *(*uint8)(unsafe.Pointer(p + 1))) != 0 {
			p += uintptr(2)
			for fts5_isdigit(tls, *(*uint8)(unsafe.Pointer(p))) != 0 {
				p++
			}
		}
		if p == pIn {
			p = uintptr(0)
		}

		break
	}

	return p
}

func fts5Dequote(tls *libc.TLS, z uintptr) int32 {
	var q uint8
	var iIn int32 = 1
	var iOut int32 = 0
	q = *(*uint8)(unsafe.Pointer(z))

	if int32(q) == '[' {
		q = uint8(']')
	}

	for *(*uint8)(unsafe.Pointer(z + uintptr(iIn))) != 0 {
		if int32(*(*uint8)(unsafe.Pointer(z + uintptr(iIn)))) == int32(q) {
			if int32(*(*uint8)(unsafe.Pointer(z + uintptr(iIn+1)))) != int32(q) {
				iIn++
				break
			} else {
				iIn = iIn + 2
				*(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&iOut, 1)))) = q
			}
		} else {
			*(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&iOut, 1)))) = *(*uint8)(unsafe.Pointer(z + uintptr(libc.PostIncInt32(&iIn, 1))))
		}
	}

	*(*uint8)(unsafe.Pointer(z + uintptr(iOut))) = uint8(0)
	return iIn
}

func sqlite3Fts5Dequote(tls *libc.TLS, z uintptr) {
	var quote uint8

	quote = *(*uint8)(unsafe.Pointer(z))
	if int32(quote) == '[' || int32(quote) == '\'' || int32(quote) == '"' || int32(quote) == '`' {
		fts5Dequote(tls, z)
	}
}

type Fts5Enum1 = struct {
	FzName       uintptr
	FeVal        int32
	F__ccgo_pad1 [4]byte
}

type Fts5Enum = Fts5Enum1

func fts5ConfigSetEnum(tls *libc.TLS, aEnum uintptr, zEnum uintptr, peVal uintptr) int32 {
	var nEnum int32 = int32(libc.Xstrlen(tls, zEnum))
	var i int32
	var iVal int32 = -1

	for i = 0; (*Fts5Enum)(unsafe.Pointer(aEnum+uintptr(i)*16)).FzName != 0; i++ {
		if Xsqlite3_strnicmp(tls, (*Fts5Enum)(unsafe.Pointer(aEnum+uintptr(i)*16)).FzName, zEnum, nEnum) == 0 {
			if iVal >= 0 {
				return SQLITE_ERROR
			}
			iVal = (*Fts5Enum)(unsafe.Pointer(aEnum + uintptr(i)*16)).FeVal
		}
	}

	*(*int32)(unsafe.Pointer(peVal)) = iVal
	if iVal < 0 {
		return SQLITE_ERROR
	}
	return SQLITE_OK
}

func fts5ConfigParseSpecial(tls *libc.TLS, pGlobal uintptr, pConfig uintptr, zCmd uintptr, zArg uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(112)
	defer tls.Free(112)

	*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_OK
	var nCmd int32 = int32(libc.Xstrlen(tls, zCmd))
	if Xsqlite3_strnicmp(tls, ts+40830, zCmd, nCmd) == 0 {
		var nByte int32 = int32(uint64(unsafe.Sizeof(int32(0))) * uint64(FTS5_MAX_PREFIX_INDEXES))
		var p uintptr
		var bFirst int32 = 1
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FaPrefix == uintptr(0) {
			(*Fts5Config)(unsafe.Pointer(pConfig)).FaPrefix = sqlite3Fts5MallocZero(tls, bp+40, int64(nByte))
			if *(*int32)(unsafe.Pointer(bp + 40)) != 0 {
				return *(*int32)(unsafe.Pointer(bp + 40))
			}
		}

		p = zArg
		for 1 != 0 {
			var nPre int32 = 0

			for int32(*(*uint8)(unsafe.Pointer(p))) == ' ' {
				p++
			}
			if bFirst == 0 && int32(*(*uint8)(unsafe.Pointer(p))) == ',' {
				p++
				for int32(*(*uint8)(unsafe.Pointer(p))) == ' ' {
					p++
				}
			} else if int32(*(*uint8)(unsafe.Pointer(p))) == 0 {
				break
			}
			if int32(*(*uint8)(unsafe.Pointer(p))) < '0' || int32(*(*uint8)(unsafe.Pointer(p))) > '9' {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+40837, 0)
				*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
				break
			}

			if (*Fts5Config)(unsafe.Pointer(pConfig)).FnPrefix == FTS5_MAX_PREFIX_INDEXES {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls,
					ts+40868, libc.VaList(bp, FTS5_MAX_PREFIX_INDEXES))
				*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
				break
			}

			for int32(*(*uint8)(unsafe.Pointer(p))) >= '0' && int32(*(*uint8)(unsafe.Pointer(p))) <= '9' && nPre < 1000 {
				nPre = nPre*10 + (int32(*(*uint8)(unsafe.Pointer(p))) - '0')
				p++
			}

			if nPre <= 0 || nPre >= 1000 {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+40901, 0)
				*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
				break
			}

			*(*int32)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FaPrefix + uintptr((*Fts5Config)(unsafe.Pointer(pConfig)).FnPrefix)*4)) = nPre
			(*Fts5Config)(unsafe.Pointer(pConfig)).FnPrefix++
			bFirst = 0
		}

		return *(*int32)(unsafe.Pointer(bp + 40))
	}

	if Xsqlite3_strnicmp(tls, ts+40938, zCmd, nCmd) == 0 {
		var p uintptr = zArg
		var nArg Sqlite3_int64 = Sqlite3_int64(libc.Xstrlen(tls, zArg) + uint64(1))
		var azArg uintptr = sqlite3Fts5MallocZero(tls, bp+40, int64(uint64(unsafe.Sizeof(uintptr(0)))*uint64(nArg)))
		var pDel uintptr = sqlite3Fts5MallocZero(tls, bp+40, nArg*int64(2))
		var pSpace uintptr = pDel

		if azArg != 0 && pSpace != 0 {
			if (*Fts5Config)(unsafe.Pointer(pConfig)).FpTok != 0 {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+40947, 0)
				*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
			} else {
				for nArg = int64(0); p != 0 && *(*uint8)(unsafe.Pointer(p)) != 0; nArg++ {
					var p2 uintptr = fts5ConfigSkipWhitespace(tls, p)
					if int32(*(*uint8)(unsafe.Pointer(p2))) == '\'' {
						p = fts5ConfigSkipLiteral(tls, p2)
					} else {
						p = fts5ConfigSkipBareword(tls, p2)
					}
					if p != 0 {
						libc.Xmemcpy(tls, pSpace, p2, uint64((int64(p)-int64(p2))/1))
						*(*uintptr)(unsafe.Pointer(azArg + uintptr(nArg)*8)) = pSpace
						sqlite3Fts5Dequote(tls, pSpace)
						pSpace += uintptr((int64(p)-int64(p2))/1 + int64(1))
						p = fts5ConfigSkipWhitespace(tls, p)
					}
				}
				if p == uintptr(0) {
					*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+40980, 0)
					*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
				} else {
					*(*int32)(unsafe.Pointer(bp + 40)) = sqlite3Fts5GetTokenizer(tls, pGlobal,
						azArg, int32(nArg), pConfig,
						pzErr)
				}
			}
		}

		Xsqlite3_free(tls, azArg)
		Xsqlite3_free(tls, pDel)
		return *(*int32)(unsafe.Pointer(bp + 40))
	}

	if Xsqlite3_strnicmp(tls, ts+41014, zCmd, nCmd) == 0 {
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41022, 0)
			*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
		} else {
			if *(*uint8)(unsafe.Pointer(zArg)) != 0 {
				(*Fts5Config)(unsafe.Pointer(pConfig)).FeContent = FTS5_CONTENT_EXTERNAL
				(*Fts5Config)(unsafe.Pointer(pConfig)).FzContent = sqlite3Fts5Mprintf(tls, bp+40, ts+41054, libc.VaList(bp+8, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, zArg))
			} else {
				(*Fts5Config)(unsafe.Pointer(pConfig)).FeContent = FTS5_CONTENT_NONE
			}
		}
		return *(*int32)(unsafe.Pointer(bp + 40))
	}

	if Xsqlite3_strnicmp(tls, ts+41060, zCmd, nCmd) == 0 {
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FzContentRowid != 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41074, 0)
			*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
		} else {
			(*Fts5Config)(unsafe.Pointer(pConfig)).FzContentRowid = sqlite3Fts5Strndup(tls, bp+40, zArg, -1)
		}
		return *(*int32)(unsafe.Pointer(bp + 40))
	}

	if Xsqlite3_strnicmp(tls, ts+41112, zCmd, nCmd) == 0 {
		if int32(*(*uint8)(unsafe.Pointer(zArg))) != '0' && int32(*(*uint8)(unsafe.Pointer(zArg))) != '1' || int32(*(*uint8)(unsafe.Pointer(zArg + 1))) != 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41123, 0)
			*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
		} else {
			(*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize = libc.Bool32(int32(*(*uint8)(unsafe.Pointer(zArg))) == '1')
		}
		return *(*int32)(unsafe.Pointer(bp + 40))
	}

	if Xsqlite3_strnicmp(tls, ts+8000, zCmd, nCmd) == 0 {
		*(*[4]Fts5Enum)(unsafe.Pointer(bp + 48)) = [4]Fts5Enum{
			{FzName: ts + 11374, FeVal: FTS5_DETAIL_NONE},
			{FzName: ts + 20898},
			{FzName: ts + 41158, FeVal: FTS5_DETAIL_COLUMNS},
			{},
		}

		if libc.AssignPtrInt32(bp+40, fts5ConfigSetEnum(tls, bp+48, zArg, pConfig+92)) != 0 {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41166, 0)
		}
		return *(*int32)(unsafe.Pointer(bp + 40))
	}

	*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41197, libc.VaList(bp+24, nCmd, zCmd))
	return SQLITE_ERROR
}

func fts5ConfigDefaultTokenizer(tls *libc.TLS, pGlobal uintptr, pConfig uintptr) int32 {
	return sqlite3Fts5GetTokenizer(tls, pGlobal, uintptr(0), 0, pConfig, uintptr(0))
}

func fts5ConfigGobbleWord(tls *libc.TLS, pRc uintptr, zIn uintptr, pzOut uintptr, pbQuoted uintptr) uintptr {
	var zRet uintptr = uintptr(0)

	var nIn Sqlite3_int64 = Sqlite3_int64(libc.Xstrlen(tls, zIn))
	var zOut uintptr = 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)) = SQLITE_NOMEM
	} else {
		libc.Xmemcpy(tls, zOut, zIn, Size_t(nIn+int64(1)))
		if fts5_isopenquote(tls, *(*uint8)(unsafe.Pointer(zOut))) != 0 {
			var ii int32 = fts5Dequote(tls, zOut)
			zRet = zIn + uintptr(ii)
			*(*int32)(unsafe.Pointer(pbQuoted)) = 1
		} else {
			zRet = fts5ConfigSkipBareword(tls, zIn)
			if zRet != 0 {
				*(*uint8)(unsafe.Pointer(zOut + uintptr((int64(zRet)-int64(zIn))/1))) = uint8(0)
			}
		}
	}

	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) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32 = SQLITE_OK
	if 0 == Xsqlite3_stricmp(tls, zCol, ts+26748) ||
		0 == Xsqlite3_stricmp(tls, zCol, ts+11466) {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41225, libc.VaList(bp, zCol))
		rc = SQLITE_ERROR
	} else if zArg != 0 {
		if 0 == Xsqlite3_stricmp(tls, zArg, ts+41255) {
			*(*U8)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(p)).FabUnindexed + uintptr((*Fts5Config)(unsafe.Pointer(p)).FnCol))) = U8(1)
		} else {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41265, libc.VaList(bp+8, zArg))
			rc = SQLITE_ERROR
		}
	}

	*(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(p)).FazCol + uintptr(libc.PostIncInt32(&(*Fts5Config)(unsafe.Pointer(p)).FnCol, 1))*8)) = zCol
	return rc
}

func fts5ConfigMakeExprlist(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var i int32
	*(*int32)(unsafe.Pointer(bp + 24)) = SQLITE_OK
	*(*Fts5Buffer)(unsafe.Pointer(bp + 32)) = Fts5Buffer{}

	sqlite3Fts5BufferAppendPrintf(tls, bp+24, bp+32, ts+41296, libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(p)).FzContentRowid))
	if (*Fts5Config)(unsafe.Pointer(p)).FeContent != FTS5_CONTENT_NONE {
		for i = 0; i < (*Fts5Config)(unsafe.Pointer(p)).FnCol; i++ {
			if (*Fts5Config)(unsafe.Pointer(p)).FeContent == FTS5_CONTENT_EXTERNAL {
				sqlite3Fts5BufferAppendPrintf(tls, bp+24, bp+32, ts+41301, libc.VaList(bp+8, *(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(p)).FazCol + uintptr(i)*8))))
			} else {
				sqlite3Fts5BufferAppendPrintf(tls, bp+24, bp+32, ts+41308, libc.VaList(bp+16, i))
			}
		}
	}

	(*Fts5Config)(unsafe.Pointer(p)).FzContentExprlist = (*Fts5Buffer)(unsafe.Pointer(bp + 32)).Fp
	return *(*int32)(unsafe.Pointer(bp + 24))
}

func sqlite3Fts5ConfigParse(tls *libc.TLS, pGlobal uintptr, db uintptr, nArg int32, azArg uintptr, ppOut uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(76)
	defer tls.Free(76)

	*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_OK
	var pRet uintptr
	var i int32
	var nByte Sqlite3_int64

	*(*uintptr)(unsafe.Pointer(ppOut)) = libc.AssignUintptr(&pRet, Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Fts5Config{}))))
	if pRet == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pRet, 0, uint64(unsafe.Sizeof(Fts5Config{})))
	(*Fts5Config)(unsafe.Pointer(pRet)).Fdb = db
	(*Fts5Config)(unsafe.Pointer(pRet)).FiCookie = -1

	nByte = Sqlite3_int64(uint64(nArg) * (uint64(unsafe.Sizeof(uintptr(0))) + uint64(unsafe.Sizeof(U8(0)))))
	(*Fts5Config)(unsafe.Pointer(pRet)).FazCol = sqlite3Fts5MallocZero(tls, bp+40, nByte)
	(*Fts5Config)(unsafe.Pointer(pRet)).FabUnindexed = func() uintptr {
		if (*Fts5Config)(unsafe.Pointer(pRet)).FazCol != 0 {
			return (*Fts5Config)(unsafe.Pointer(pRet)).FazCol + uintptr(nArg)*8
		}
		return uintptr(0)
	}()
	(*Fts5Config)(unsafe.Pointer(pRet)).FzDb = sqlite3Fts5Strndup(tls, bp+40, *(*uintptr)(unsafe.Pointer(azArg + 1*8)), -1)
	(*Fts5Config)(unsafe.Pointer(pRet)).FzName = sqlite3Fts5Strndup(tls, bp+40, *(*uintptr)(unsafe.Pointer(azArg + 2*8)), -1)
	(*Fts5Config)(unsafe.Pointer(pRet)).FbColumnsize = 1
	(*Fts5Config)(unsafe.Pointer(pRet)).FeDetail = FTS5_DETAIL_FULL
	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && Xsqlite3_stricmp(tls, (*Fts5Config)(unsafe.Pointer(pRet)).FzName, ts+26748) == 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41316, libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pRet)).FzName))
		*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
	}

	for i = 3; *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && i < nArg; i++ {
		var zOrig uintptr = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8))
		var z uintptr
		*(*uintptr)(unsafe.Pointer(bp + 48)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)
		var bOption int32 = 0
		*(*int32)(unsafe.Pointer(bp + 56)) = 0

		z = fts5ConfigGobbleWord(tls, bp+40, zOrig, bp+48, bp+56)
		z = fts5ConfigSkipWhitespace(tls, z)
		if z != 0 && int32(*(*uint8)(unsafe.Pointer(z))) == '=' {
			bOption = 1

			z++
			if *(*int32)(unsafe.Pointer(bp + 56)) != 0 {
				z = uintptr(0)
			}
		}
		z = fts5ConfigSkipWhitespace(tls, z)
		if z != 0 && *(*uint8)(unsafe.Pointer(z)) != 0 {
			z = fts5ConfigGobbleWord(tls, bp+40, z, bp+64, bp+72)
			if z != 0 && *(*uint8)(unsafe.Pointer(z)) != 0 {
				z = uintptr(0)
			}
		}

		if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
			if z == uintptr(0) {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+41345, libc.VaList(bp+8, zOrig))
				*(*int32)(unsafe.Pointer(bp + 40)) = SQLITE_ERROR
			} else {
				if bOption != 0 {
					*(*int32)(unsafe.Pointer(bp + 40)) = fts5ConfigParseSpecial(tls, pGlobal, pRet,
						func() uintptr {
							if *(*uintptr)(unsafe.Pointer(bp + 48)) != 0 {
								return *(*uintptr)(unsafe.Pointer(bp + 48))
							}
							return ts + 1636
						}(),
						func() uintptr {
							if *(*uintptr)(unsafe.Pointer(bp + 64)) != 0 {
								return *(*uintptr)(unsafe.Pointer(bp + 64))
							}
							return ts + 1636
						}(),
						pzErr)
				} else {
					*(*int32)(unsafe.Pointer(bp + 40)) = fts5ConfigParseColumn(tls, pRet, *(*uintptr)(unsafe.Pointer(bp + 48)), *(*uintptr)(unsafe.Pointer(bp + 64)), pzErr)
					*(*uintptr)(unsafe.Pointer(bp + 48)) = uintptr(0)
				}
			}
		}

		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 48)))
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
	}

	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pRet)).FpTok == uintptr(0) {
		*(*int32)(unsafe.Pointer(bp + 40)) = fts5ConfigDefaultTokenizer(tls, pGlobal, pRet)
	}

	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pRet)).FzContent == uintptr(0) {
		var zTail uintptr = uintptr(0)

		if (*Fts5Config)(unsafe.Pointer(pRet)).FeContent == FTS5_CONTENT_NORMAL {
			zTail = ts + 41014
		} else if (*Fts5Config)(unsafe.Pointer(pRet)).FbColumnsize != 0 {
			zTail = ts + 41365
		}

		if zTail != 0 {
			(*Fts5Config)(unsafe.Pointer(pRet)).FzContent = sqlite3Fts5Mprintf(tls,
				bp+40, ts+41373, libc.VaList(bp+16, (*Fts5Config)(unsafe.Pointer(pRet)).FzDb, (*Fts5Config)(unsafe.Pointer(pRet)).FzName, zTail))
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pRet)).FzContentRowid == uintptr(0) {
		(*Fts5Config)(unsafe.Pointer(pRet)).FzContentRowid = sqlite3Fts5Strndup(tls, bp+40, ts+11466, -1)
	}

	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 40)) = fts5ConfigMakeExprlist(tls, pRet)
	}

	if *(*int32)(unsafe.Pointer(bp + 40)) != SQLITE_OK {
		sqlite3Fts5ConfigFree(tls, pRet)
		*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
	}
	return *(*int32)(unsafe.Pointer(bp + 40))
}

func sqlite3Fts5ConfigFree(tls *libc.TLS, pConfig uintptr) {
	if pConfig != 0 {
		var i int32
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FpTok != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Fts5_tokenizer)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FpTokApi)).FxDelete})).f(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FpTok)
		}
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb)
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName)
		for i = 0; i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; i++ {
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(i)*8)))
		}
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FazCol)
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FaPrefix)
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzRank)
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzRankArgs)
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzContent)
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzContentRowid)
		Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzContentExprlist)
		Xsqlite3_free(tls, pConfig)
	}
}

func sqlite3Fts5ConfigDeclareVtab(tls *libc.TLS, pConfig uintptr) int32 {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var i int32
	*(*int32)(unsafe.Pointer(bp + 48)) = SQLITE_OK
	var zSql uintptr

	zSql = sqlite3Fts5Mprintf(tls, bp+48, ts+41384, 0)
	for i = 0; zSql != 0 && i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; i++ {
		var zSep uintptr = func() uintptr {
			if i == 0 {
				return ts + 1636
			}
			return ts + 18036
		}()
		zSql = sqlite3Fts5Mprintf(tls, bp+48, ts+41400, libc.VaList(bp, zSql, zSep, *(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(i)*8))))
	}
	zSql = sqlite3Fts5Mprintf(tls, bp+48, ts+41407,
		libc.VaList(bp+24, zSql, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName, ts+26748))

	if zSql != 0 {
		*(*int32)(unsafe.Pointer(bp + 48)) = Xsqlite3_declare_vtab(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql)
		Xsqlite3_free(tls, zSql)
	}

	return *(*int32)(unsafe.Pointer(bp + 48))
}

func sqlite3Fts5Tokenize(tls *libc.TLS, pConfig uintptr, flags int32, pText uintptr, nText int32, pCtx uintptr, xToken uintptr) int32 {
	if pText == uintptr(0) {
		return SQLITE_OK
	}
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5_tokenizer)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FpTokApi)).FxTokenize})).f(tls,
		(*Fts5Config)(unsafe.Pointer(pConfig)).FpTok, pCtx, flags, pText, nText, xToken)
}

func fts5ConfigSkipArgs(tls *libc.TLS, pIn uintptr) uintptr {
	var p uintptr = pIn

	for 1 != 0 {
		p = fts5ConfigSkipWhitespace(tls, p)
		p = fts5ConfigSkipLiteral(tls, p)
		p = fts5ConfigSkipWhitespace(tls, p)
		if p == uintptr(0) || int32(*(*uint8)(unsafe.Pointer(p))) == ')' {
			break
		}
		if int32(*(*uint8)(unsafe.Pointer(p))) != ',' {
			p = uintptr(0)
			break
		}
		p++
	}

	return p
}

func sqlite3Fts5ConfigParseRank(tls *libc.TLS, zIn uintptr, pzRank uintptr, pzRankArgs uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var p uintptr = zIn
	var pRank uintptr
	var zRank uintptr = uintptr(0)
	var zRankArgs uintptr = 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)) = SQLITE_ERROR
	} else {
		p = fts5ConfigSkipWhitespace(tls, p)
		pRank = p
		p = fts5ConfigSkipBareword(tls, p)

		if p != 0 {
			zRank = sqlite3Fts5MallocZero(tls, bp, (int64(uintptr(1)+p)-int64(pRank))/1)
			if zRank != 0 {
				libc.Xmemcpy(tls, zRank, pRank, uint64((int64(p)-int64(pRank))/1))
			}
		} else {
			*(*int32)(unsafe.Pointer(bp)) = SQLITE_ERROR
		}

		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			p = fts5ConfigSkipWhitespace(tls, p)
			if int32(*(*uint8)(unsafe.Pointer(p))) != '(' {
				*(*int32)(unsafe.Pointer(bp)) = SQLITE_ERROR
			}
			p++
		}
		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			var pArgs uintptr
			p = fts5ConfigSkipWhitespace(tls, p)
			pArgs = p
			if int32(*(*uint8)(unsafe.Pointer(p))) != ')' {
				p = fts5ConfigSkipArgs(tls, p)
				if p == uintptr(0) {
					*(*int32)(unsafe.Pointer(bp)) = SQLITE_ERROR
				} else {
					zRankArgs = sqlite3Fts5MallocZero(tls, bp, (int64(uintptr(1)+p)-int64(pArgs))/1)
					if zRankArgs != 0 {
						libc.Xmemcpy(tls, zRankArgs, pArgs, uint64((int64(p)-int64(pArgs))/1))
					}
				}
			}
		}
	}

	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) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32 = SQLITE_OK

	if 0 == Xsqlite3_stricmp(tls, zKey, ts+41433) {
		var pgsz int32 = 0
		if SQLITE_INTEGER == Xsqlite3_value_numeric_type(tls, pVal) {
			pgsz = Xsqlite3_value_int(tls, pVal)
		}
		if pgsz < 32 || pgsz > 64*1024 {
			*(*int32)(unsafe.Pointer(pbBadkey)) = 1
		} else {
			(*Fts5Config)(unsafe.Pointer(pConfig)).Fpgsz = pgsz
		}
	} else if 0 == Xsqlite3_stricmp(tls, zKey, ts+41438) {
		var nHashSize int32 = -1
		if SQLITE_INTEGER == Xsqlite3_value_numeric_type(tls, pVal) {
			nHashSize = Xsqlite3_value_int(tls, pVal)
		}
		if nHashSize <= 0 {
			*(*int32)(unsafe.Pointer(pbBadkey)) = 1
		} else {
			(*Fts5Config)(unsafe.Pointer(pConfig)).FnHashSize = nHashSize
		}
	} else if 0 == Xsqlite3_stricmp(tls, zKey, ts+41447) {
		var nAutomerge int32 = -1
		if SQLITE_INTEGER == Xsqlite3_value_numeric_type(tls, pVal) {
			nAutomerge = Xsqlite3_value_int(tls, pVal)
		}
		if nAutomerge < 0 || nAutomerge > 64 {
			*(*int32)(unsafe.Pointer(pbBadkey)) = 1
		} else {
			if nAutomerge == 1 {
				nAutomerge = FTS5_DEFAULT_AUTOMERGE
			}
			(*Fts5Config)(unsafe.Pointer(pConfig)).FnAutomerge = nAutomerge
		}
	} else if 0 == Xsqlite3_stricmp(tls, zKey, ts+41457) {
		var nUsermerge int32 = -1
		if SQLITE_INTEGER == Xsqlite3_value_numeric_type(tls, pVal) {
			nUsermerge = Xsqlite3_value_int(tls, pVal)
		}
		if nUsermerge < 2 || nUsermerge > 16 {
			*(*int32)(unsafe.Pointer(pbBadkey)) = 1
		} else {
			(*Fts5Config)(unsafe.Pointer(pConfig)).FnUsermerge = nUsermerge
		}
	} else if 0 == Xsqlite3_stricmp(tls, zKey, ts+41467) {
		var nCrisisMerge int32 = -1
		if SQLITE_INTEGER == Xsqlite3_value_numeric_type(tls, pVal) {
			nCrisisMerge = Xsqlite3_value_int(tls, pVal)
		}
		if nCrisisMerge < 0 {
			*(*int32)(unsafe.Pointer(pbBadkey)) = 1
		} else {
			if nCrisisMerge <= 1 {
				nCrisisMerge = FTS5_DEFAULT_CRISISMERGE
			}
			if nCrisisMerge >= FTS5_MAX_SEGMENT {
				nCrisisMerge = FTS5_MAX_SEGMENT - 1
			}
			(*Fts5Config)(unsafe.Pointer(pConfig)).FnCrisisMerge = nCrisisMerge
		}
	} else if 0 == Xsqlite3_stricmp(tls, zKey, ts+26748) {
		var zIn uintptr = Xsqlite3_value_text(tls, pVal)

		rc = sqlite3Fts5ConfigParseRank(tls, zIn, bp, bp+8)
		if rc == SQLITE_OK {
			Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzRank)
			Xsqlite3_free(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).FzRankArgs)
			(*Fts5Config)(unsafe.Pointer(pConfig)).FzRank = *(*uintptr)(unsafe.Pointer(bp))
			(*Fts5Config)(unsafe.Pointer(pConfig)).FzRankArgs = *(*uintptr)(unsafe.Pointer(bp + 8))
		} else if rc == SQLITE_ERROR {
			rc = SQLITE_OK
			*(*int32)(unsafe.Pointer(pbBadkey)) = 1
		}
	} else {
		*(*int32)(unsafe.Pointer(pbBadkey)) = 1
	}
	return rc
}

func sqlite3Fts5ConfigLoad(tls *libc.TLS, pConfig uintptr, iCookie int32) int32 {
	bp := tls.Alloc(52)
	defer tls.Free(52)

	var zSelect uintptr = ts + 41479
	var zSql uintptr
	*(*uintptr)(unsafe.Pointer(bp + 40)) = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 32)) = SQLITE_OK
	var iVersion int32 = 0

	(*Fts5Config)(unsafe.Pointer(pConfig)).Fpgsz = FTS5_DEFAULT_PAGE_SIZE
	(*Fts5Config)(unsafe.Pointer(pConfig)).FnAutomerge = FTS5_DEFAULT_AUTOMERGE
	(*Fts5Config)(unsafe.Pointer(pConfig)).FnUsermerge = FTS5_DEFAULT_USERMERGE
	(*Fts5Config)(unsafe.Pointer(pConfig)).FnCrisisMerge = FTS5_DEFAULT_CRISISMERGE
	(*Fts5Config)(unsafe.Pointer(pConfig)).FnHashSize = 1024 * 1024

	zSql = sqlite3Fts5Mprintf(tls, bp+32, zSelect, libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
	if zSql != 0 {
		*(*int32)(unsafe.Pointer(bp + 32)) = Xsqlite3_prepare_v2(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -1, bp+40, uintptr(0))
		Xsqlite3_free(tls, zSql)
	}

	if *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK {
		for SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 40))) {
			var zK uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 40)), 0)
			var pVal uintptr = Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp + 40)), 1)
			if 0 == Xsqlite3_stricmp(tls, zK, ts+41511) {
				iVersion = Xsqlite3_value_int(tls, pVal)
			} else {
				*(*int32)(unsafe.Pointer(bp + 48)) = 0
				sqlite3Fts5ConfigSetValue(tls, pConfig, zK, pVal, bp+48)
			}
		}
		*(*int32)(unsafe.Pointer(bp + 32)) = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
	}

	if *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK && iVersion != FTS5_CURRENT_VERSION {
		*(*int32)(unsafe.Pointer(bp + 32)) = SQLITE_ERROR
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg != 0 {
			*(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)) = Xsqlite3_mprintf(tls,
				ts+41519,
				libc.VaList(bp+16, iVersion, FTS5_CURRENT_VERSION))
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK {
		(*Fts5Config)(unsafe.Pointer(pConfig)).FiCookie = iCookie
	}
	return *(*int32)(unsafe.Pointer(bp + 32))
}

type Fts5ExprTerm1 = struct {
	FbPrefix     U8
	FbFirst      U8
	F__ccgo_pad1 [6]byte
	FzTerm       uintptr
	FpIter       uintptr
	FpSynonym    uintptr
}

type Fts5ExprTerm = Fts5ExprTerm1

func sqlite3Fts5ParseError(tls *libc.TLS, pParse uintptr, zFmt uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	ap = va
	if (*Fts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		(*Fts5Parse)(unsafe.Pointer(pParse)).FzErr = Xsqlite3_vmprintf(tls, zFmt, ap)
		(*Fts5Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_ERROR
	}
	_ = ap
}

func fts5ExprIsspace(tls *libc.TLS, t uint8) int32 {
	return libc.Bool32(int32(t) == ' ' || int32(t) == '\t' || int32(t) == '\n' || int32(t) == '\r')
}

func fts5ExprGetToken(tls *libc.TLS, pParse uintptr, pz uintptr, pToken uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var z uintptr = *(*uintptr)(unsafe.Pointer(pz))
	var tok int32

	for fts5ExprIsspace(tls, *(*uint8)(unsafe.Pointer(z))) != 0 {
		z++
	}

	(*Fts5Token)(unsafe.Pointer(pToken)).Fp = z
	(*Fts5Token)(unsafe.Pointer(pToken)).Fn = 1
	switch int32(*(*uint8)(unsafe.Pointer(z))) {
	case '(':
		tok = FTS5_LP
		break
	case ')':
		tok = FTS5_RP
		break
	case '{':
		tok = FTS5_LCP
		break
	case '}':
		tok = FTS5_RCP
		break
	case ':':
		tok = FTS5_COLON
		break
	case ',':
		tok = FTS5_COMMA
		break
	case '+':
		tok = FTS5_PLUS
		break
	case '*':
		tok = FTS5_STAR
		break
	case '-':
		tok = FTS5_MINUS
		break
	case '^':
		tok = FTS5_CARET
		break
	case 0:
		tok = FTS5_EOF
		break

	case '"':
		{
			var z2 uintptr
			tok = FTS5_STRING

			for z2 = z + 1; 1 != 0; z2++ {
				if int32(*(*uint8)(unsafe.Pointer(z2))) == '"' {
					z2++
					if int32(*(*uint8)(unsafe.Pointer(z2))) != '"' {
						break
					}
				}
				if int32(*(*uint8)(unsafe.Pointer(z2))) == 0 {
					sqlite3Fts5ParseError(tls, pParse, ts+41584, 0)
					return FTS5_EOF
				}
			}
			(*Fts5Token)(unsafe.Pointer(pToken)).Fn = int32((int64(z2) - int64(z)) / 1)
			break

		}

	default:
		{
			var z2 uintptr
			if sqlite3Fts5IsBareword(tls, *(*uint8)(unsafe.Pointer(z))) == 0 {
				sqlite3Fts5ParseError(tls, pParse, ts+41604, libc.VaList(bp, z))
				return FTS5_EOF
			}
			tok = FTS5_STRING
			for z2 = z + 1; sqlite3Fts5IsBareword(tls, *(*uint8)(unsafe.Pointer(z2))) != 0; z2++ {
			}
			(*Fts5Token)(unsafe.Pointer(pToken)).Fn = int32((int64(z2) - int64(z)) / 1)
			if (*Fts5Token)(unsafe.Pointer(pToken)).Fn == 2 && libc.Xmemcmp(tls, (*Fts5Token)(unsafe.Pointer(pToken)).Fp, ts+41635, uint64(2)) == 0 {
				tok = FTS5_OR
			}
			if (*Fts5Token)(unsafe.Pointer(pToken)).Fn == 3 && libc.Xmemcmp(tls, (*Fts5Token)(unsafe.Pointer(pToken)).Fp, ts+41638, uint64(3)) == 0 {
				tok = FTS5_NOT
			}
			if (*Fts5Token)(unsafe.Pointer(pToken)).Fn == 3 && libc.Xmemcmp(tls, (*Fts5Token)(unsafe.Pointer(pToken)).Fp, ts+36351, uint64(3)) == 0 {
				tok = FTS5_AND
			}
			break

		}
	}

	*(*uintptr)(unsafe.Pointer(pz)) = (*Fts5Token)(unsafe.Pointer(pToken)).Fp + uintptr((*Fts5Token)(unsafe.Pointer(pToken)).Fn)
	return tok
}

func fts5ParseAlloc(tls *libc.TLS, t U64) uintptr {
	return Xsqlite3_malloc64(tls, uint64(Sqlite3_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) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	*(*uintptr)(unsafe.Pointer(bp + 48)) = zExpr
	var t int32
	var pEngine uintptr
	var pNew uintptr

	*(*uintptr)(unsafe.Pointer(ppNew)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(pzErr)) = uintptr(0)
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Parse{})))
	(*Fts5Parse)(unsafe.Pointer(bp)).FbPhraseToAnd = bPhraseToAnd
	pEngine = sqlite3Fts5ParserAlloc(tls, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, U64) uintptr }{fts5ParseAlloc})))
	if pEngine == uintptr(0) {
		return SQLITE_NOMEM
	}
	(*Fts5Parse)(unsafe.Pointer(bp)).FpConfig = pConfig

	for __ccgo := true; __ccgo; __ccgo = (*Fts5Parse)(unsafe.Pointer(bp)).Frc == SQLITE_OK && t != FTS5_EOF {
		t = fts5ExprGetToken(tls, bp, bp+48, bp+56)
		sqlite3Fts5Parser(tls, pEngine, t, *(*Fts5Token)(unsafe.Pointer(bp + 56)), bp)
	}
	sqlite3Fts5ParserFree(tls, pEngine, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{fts5ParseFree})))

	if iCol < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol && (*Fts5Parse)(unsafe.Pointer(bp)).FpExpr != 0 && (*Fts5Parse)(unsafe.Pointer(bp)).Frc == SQLITE_OK {
		var n int32 = int32(unsafe.Sizeof(Fts5Colset{}))
		var pColset uintptr = sqlite3Fts5MallocZero(tls, bp+16, int64(n))
		if pColset != 0 {
			(*Fts5Colset)(unsafe.Pointer(pColset)).FnCol = 1
			*(*int32)(unsafe.Pointer(pColset + 4)) = iCol
			sqlite3Fts5ParseSetColset(tls, bp, (*Fts5Parse)(unsafe.Pointer(bp)).FpExpr, pColset)
		}
	}

	if (*Fts5Parse)(unsafe.Pointer(bp)).Frc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(ppNew)) = libc.AssignUintptr(&pNew, Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Fts5Expr{}))))
		if pNew == uintptr(0) {
			(*Fts5Parse)(unsafe.Pointer(bp)).Frc = SQLITE_NOMEM
			sqlite3Fts5ParseNodeFree(tls, (*Fts5Parse)(unsafe.Pointer(bp)).FpExpr)
		} else {
			if !(int32((*Fts5Parse)(unsafe.Pointer(bp)).FpExpr) != 0) {
				var nByte int32 = int32(unsafe.Sizeof(Fts5ExprNode{}))
				(*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot = sqlite3Fts5MallocZero(tls, bp+16, int64(nByte))
				if (*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot != 0 {
					(*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FbEof = 1
				}
			} else {
				(*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot = (*Fts5Parse)(unsafe.Pointer(bp)).FpExpr
			}
			(*Fts5Expr)(unsafe.Pointer(pNew)).FpIndex = uintptr(0)
			(*Fts5Expr)(unsafe.Pointer(pNew)).FpConfig = pConfig
			(*Fts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase = (*Fts5Parse)(unsafe.Pointer(bp)).FapPhrase
			(*Fts5Expr)(unsafe.Pointer(pNew)).FnPhrase = (*Fts5Parse)(unsafe.Pointer(bp)).FnPhrase
			(*Fts5Expr)(unsafe.Pointer(pNew)).FbDesc = 0
			(*Fts5Parse)(unsafe.Pointer(bp)).FapPhrase = uintptr(0)
		}
	} else {
		sqlite3Fts5ParseNodeFree(tls, (*Fts5Parse)(unsafe.Pointer(bp)).FpExpr)
	}

	Xsqlite3_free(tls, (*Fts5Parse)(unsafe.Pointer(bp)).FapPhrase)
	*(*uintptr)(unsafe.Pointer(pzErr)) = (*Fts5Parse)(unsafe.Pointer(bp)).FzErr
	return (*Fts5Parse)(unsafe.Pointer(bp)).Frc
}

func fts5ExprCountChar(tls *libc.TLS, z uintptr, nByte int32) int32 {
	var nRet int32 = 0
	var ii int32
	for ii = 0; ii < nByte; ii++ {
		if int32(*(*uint8)(unsafe.Pointer(z + uintptr(ii))))&0xC0 != 0x80 {
			nRet++
		}
	}
	return nRet
}

func sqlite3Fts5ExprPattern(tls *libc.TLS, pConfig uintptr, bGlob int32, iCol int32, zText uintptr, pp uintptr) int32 {
	bp := tls.Alloc(3)
	defer tls.Free(3)

	var nText I64 = I64(libc.Xstrlen(tls, zText))
	var zExpr uintptr = Xsqlite3_malloc64(tls, uint64(nText*int64(4)+int64(1)))
	var rc int32 = SQLITE_OK

	if zExpr == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		var iOut int32 = 0
		var i int32 = 0
		var iFirst int32 = 0

		if bGlob == 0 {
			*(*uint8)(unsafe.Pointer(bp)) = uint8('_')
			*(*uint8)(unsafe.Pointer(bp + 1)) = uint8('%')
			*(*uint8)(unsafe.Pointer(bp + 2)) = uint8(0)
		} else {
			*(*uint8)(unsafe.Pointer(bp)) = uint8('*')
			*(*uint8)(unsafe.Pointer(bp + 1)) = uint8('?')
			*(*uint8)(unsafe.Pointer(bp + 2)) = uint8('[')
		}

		for I64(i) <= nText {
			if I64(i) == nText ||
				int32(*(*uint8)(unsafe.Pointer(zText + uintptr(i)))) == int32(*(*uint8)(unsafe.Pointer(bp))) || int32(*(*uint8)(unsafe.Pointer(zText + uintptr(i)))) == int32(*(*uint8)(unsafe.Pointer(bp + 1))) || int32(*(*uint8)(unsafe.Pointer(zText + uintptr(i)))) == int32(*(*uint8)(unsafe.Pointer(bp + 2))) {
				if fts5ExprCountChar(tls, zText+uintptr(iFirst), i-iFirst) >= 3 {
					var jj int32
					*(*uint8)(unsafe.Pointer(zExpr + uintptr(libc.PostIncInt32(&iOut, 1)))) = uint8('"')
					for jj = iFirst; jj < i; jj++ {
						*(*uint8)(unsafe.Pointer(zExpr + uintptr(libc.PostIncInt32(&iOut, 1)))) = *(*uint8)(unsafe.Pointer(zText + uintptr(jj)))
						if int32(*(*uint8)(unsafe.Pointer(zText + uintptr(jj)))) == '"' {
							*(*uint8)(unsafe.Pointer(zExpr + uintptr(libc.PostIncInt32(&iOut, 1)))) = uint8('"')
						}
					}
					*(*uint8)(unsafe.Pointer(zExpr + uintptr(libc.PostIncInt32(&iOut, 1)))) = uint8('"')
					*(*uint8)(unsafe.Pointer(zExpr + uintptr(libc.PostIncInt32(&iOut, 1)))) = uint8(' ')
				}
				if int32(*(*uint8)(unsafe.Pointer(zText + uintptr(i)))) == int32(*(*uint8)(unsafe.Pointer(bp + 2))) {
					i = i + 2
					if int32(*(*uint8)(unsafe.Pointer(zText + uintptr(i-1)))) == '^' {
						i++
					}
					for I64(i) < nText && int32(*(*uint8)(unsafe.Pointer(zText + uintptr(i)))) != ']' {
						i++
					}
				}
				iFirst = i + 1
			}
			i++
		}
		if iOut > 0 {
			var bAnd int32 = 0
			if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail != FTS5_DETAIL_FULL {
				bAnd = 1
				if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_NONE {
					iCol = (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol
				}
			}
			*(*uint8)(unsafe.Pointer(zExpr + uintptr(iOut))) = uint8(0)
			rc = sqlite3Fts5ExprNew(tls, pConfig, bAnd, iCol, zExpr, pp, (*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)
		} else {
			*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
		}
		Xsqlite3_free(tls, zExpr)
	}

	return rc
}

func sqlite3Fts5ParseNodeFree(tls *libc.TLS, p uintptr) {
	if p != 0 {
		var i int32
		for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(p)).FnChild; i++ {
			sqlite3Fts5ParseNodeFree(tls, *(*uintptr)(unsafe.Pointer(p + 48 + uintptr(i)*8)))
		}
		sqlite3Fts5ParseNearsetFree(tls, (*Fts5ExprNode)(unsafe.Pointer(p)).FpNear)
		Xsqlite3_free(tls, p)
	}
}

func sqlite3Fts5ExprFree(tls *libc.TLS, p uintptr) {
	if p != 0 {
		sqlite3Fts5ParseNodeFree(tls, (*Fts5Expr)(unsafe.Pointer(p)).FpRoot)
		Xsqlite3_free(tls, (*Fts5Expr)(unsafe.Pointer(p)).FapExprPhrase)
		Xsqlite3_free(tls, p)
	}
}

func sqlite3Fts5ExprAnd(tls *libc.TLS, pp1 uintptr, p2 uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Parse{})))

	if *(*uintptr)(unsafe.Pointer(pp1)) != 0 {
		var p1 uintptr = *(*uintptr)(unsafe.Pointer(pp1))
		var nPhrase int32 = (*Fts5Expr)(unsafe.Pointer(p1)).FnPhrase + (*Fts5Expr)(unsafe.Pointer(p2)).FnPhrase

		(*Fts5Expr)(unsafe.Pointer(p1)).FpRoot = sqlite3Fts5ParseNode(tls, bp, FTS5_AND, (*Fts5Expr)(unsafe.Pointer(p1)).FpRoot, (*Fts5Expr)(unsafe.Pointer(p2)).FpRoot, uintptr(0))
		(*Fts5Expr)(unsafe.Pointer(p2)).FpRoot = uintptr(0)

		if (*Fts5Parse)(unsafe.Pointer(bp)).Frc == SQLITE_OK {
			var ap uintptr = Xsqlite3_realloc(tls,
				(*Fts5Expr)(unsafe.Pointer(p1)).FapExprPhrase, int32(uint64(nPhrase)*uint64(unsafe.Sizeof(uintptr(0)))))
			if ap == uintptr(0) {
				(*Fts5Parse)(unsafe.Pointer(bp)).Frc = SQLITE_NOMEM
			} else {
				var i int32
				libc.Xmemmove(tls, ap+uintptr((*Fts5Expr)(unsafe.Pointer(p2)).FnPhrase)*8, ap, uint64((*Fts5Expr)(unsafe.Pointer(p1)).FnPhrase)*uint64(unsafe.Sizeof(uintptr(0))))
				for i = 0; i < (*Fts5Expr)(unsafe.Pointer(p2)).FnPhrase; i++ {
					*(*uintptr)(unsafe.Pointer(ap + uintptr(i)*8)) = *(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(p2)).FapExprPhrase + uintptr(i)*8))
				}
				(*Fts5Expr)(unsafe.Pointer(p1)).FnPhrase = nPhrase
				(*Fts5Expr)(unsafe.Pointer(p1)).FapExprPhrase = ap
			}
		}
		Xsqlite3_free(tls, (*Fts5Expr)(unsafe.Pointer(p2)).FapExprPhrase)
		Xsqlite3_free(tls, p2)
	} else {
		*(*uintptr)(unsafe.Pointer(pp1)) = p2
	}

	return (*Fts5Parse)(unsafe.Pointer(bp)).Frc
}

func fts5ExprSynonymRowid(tls *libc.TLS, pTerm uintptr, bDesc int32, pbEof uintptr) I64 {
	var iRet I64 = int64(0)
	var bRetValid int32 = 0
	var p uintptr

	for p = pTerm; p != 0; p = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym {
		if 0 == int32((*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) {
			var iRowid I64 = (*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FiRowid
			if bRetValid == 0 || bDesc != libc.Bool32(iRowid < iRet) {
				iRet = iRowid
				bRetValid = 1
			}
		}
	}

	if pbEof != 0 && bRetValid == 0 {
		*(*int32)(unsafe.Pointer(pbEof)) = 1
	}
	return iRet
}

func fts5ExprSynonymList(tls *libc.TLS, pTerm uintptr, iRowid I64, pBuf uintptr, pa uintptr, pn uintptr) int32 {
	bp := tls.Alloc(136)
	defer tls.Free(136)

	var aIter uintptr
	var nIter int32
	var nAlloc int32
	var rc int32
	var p uintptr
	var nByte Sqlite3_int64
	var aNew uintptr
	var pIter uintptr
	var i int32
	var iMin I64

	var iPrev I64
	aIter = bp
	nIter = 0
	nAlloc = 4
	rc = SQLITE_OK

	p = pTerm
__1:
	if !(p != 0) {
		goto __3
	}
	pIter = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter
	if !(int32((*Fts5IndexIter)(unsafe.Pointer(pIter)).FbEof) == 0 && (*Fts5IndexIter)(unsafe.Pointer(pIter)).FiRowid == iRowid) {
		goto __4
	}
	if !((*Fts5IndexIter)(unsafe.Pointer(pIter)).FnData == 0) {
		goto __5
	}
	goto __2
__5:
	;
	if !(nIter == nAlloc) {
		goto __6
	}
	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5PoslistReader{})) * uint64(nAlloc) * uint64(2))
	aNew = Xsqlite3_malloc64(tls, uint64(nByte))
	if !(aNew == uintptr(0)) {
		goto __7
	}
	rc = SQLITE_NOMEM
	goto synonym_poslist_out
__7:
	;
	libc.Xmemcpy(tls, aNew, aIter, uint64(unsafe.Sizeof(Fts5PoslistReader{}))*uint64(nIter))
	nAlloc = nAlloc * 2
	if !(aIter != bp) {
		goto __8
	}
	Xsqlite3_free(tls, aIter)
__8:
	;
	aIter = aNew
__6:
	;
	sqlite3Fts5PoslistReaderInit(tls, (*Fts5IndexIter)(unsafe.Pointer(pIter)).FpData, (*Fts5IndexIter)(unsafe.Pointer(pIter)).FnData, aIter+uintptr(nIter)*32)

	nIter++
__4:
	;
	goto __2
__2:
	p = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym
	goto __1
	goto __3
__3:
	;
	if !(nIter == 1) {
		goto __9
	}
	*(*uintptr)(unsafe.Pointer(pa)) = (*Fts5PoslistReader)(unsafe.Pointer(aIter)).Fa
	*(*int32)(unsafe.Pointer(pn)) = (*Fts5PoslistReader)(unsafe.Pointer(aIter)).Fn
	goto __10
__9:
	*(*Fts5PoslistWriter)(unsafe.Pointer(bp + 128)) = Fts5PoslistWriter{}
	iPrev = int64(-1)
	sqlite3Fts5BufferZero(tls, pBuf)
__11:
	if !(1 != 0) {
		goto __12
	}
	iMin = int64(0xffffffff) | int64(0x7fffffff)<<32
	i = 0
__13:
	if !(i < nIter) {
		goto __15
	}
	if !(int32((*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(i)*32)).FbEof) == 0) {
		goto __16
	}
	if !((*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(i)*32)).FiPos == iPrev) {
		goto __17
	}
	if !(sqlite3Fts5PoslistReaderNext(tls, aIter+uintptr(i)*32) != 0) {
		goto __18
	}
	goto __14
__18:
	;
__17:
	;
	if !((*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(i)*32)).FiPos < iMin) {
		goto __19
	}
	iMin = (*Fts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*32)).FiPos
__19:
	;
__16:
	;
	goto __14
__14:
	i++
	goto __13
	goto __15
__15:
	;
	if !(iMin == int64(0xffffffff)|int64(0x7fffffff)<<32 || rc != SQLITE_OK) {
		goto __20
	}
	goto __12
__20:
	;
	rc = sqlite3Fts5PoslistWriterAppend(tls, pBuf, bp+128, iMin)
	iPrev = iMin
	goto __11
__12:
	;
	if !(rc == SQLITE_OK) {
		goto __21
	}
	*(*uintptr)(unsafe.Pointer(pa)) = (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp
	*(*int32)(unsafe.Pointer(pn)) = (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn
__21:
	;
__10:
	;
synonym_poslist_out:
	if !(aIter != bp) {
		goto __22
	}
	Xsqlite3_free(tls, aIter)
__22:
	;
	return rc
}

func fts5ExprPhraseIsMatch(tls *libc.TLS, pNode uintptr, pPhrase uintptr, pbMatch uintptr) int32 {
	bp := tls.Alloc(168)
	defer tls.Free(168)

	var aIter uintptr
	var i int32
	var rc int32
	var bFirst int32
	var nByte Sqlite3_int64

	var pTerm uintptr

	var bFlag int32

	var pPos uintptr
	var iAdj I64
	var bMatch int32
	var iPos I64
	*(*Fts5PoslistWriter)(unsafe.Pointer(bp + 160)) = Fts5PoslistWriter{}
	aIter = bp
	rc = SQLITE_OK
	bFirst = int32((*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32)).FbFirst)

	sqlite3Fts5BufferZero(tls, pPhrase+8)

	if !((*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > int32(uint64(unsafe.Sizeof([4]Fts5PoslistReader{}))/uint64(unsafe.Sizeof(Fts5PoslistReader{})))) {
		goto __1
	}
	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5PoslistReader{})) * uint64((*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm))
	aIter = Xsqlite3_malloc64(tls, uint64(nByte))
	if !!(aIter != 0) {
		goto __2
	}
	return SQLITE_NOMEM
__2:
	;
__1:
	;
	libc.Xmemset(tls, aIter, 0, uint64(unsafe.Sizeof(Fts5PoslistReader{}))*uint64((*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm))

	i = 0
__3:
	if !(i < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
		goto __5
	}
	pTerm = pPhrase + 32 + uintptr(i)*32
	*(*int32)(unsafe.Pointer(bp + 152)) = 0
	bFlag = 0
	*(*uintptr)(unsafe.Pointer(bp + 144)) = uintptr(0)
	if !((*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0) {
		goto __6
	}
	*(*Fts5Buffer)(unsafe.Pointer(bp + 128)) = Fts5Buffer{}
	rc = fts5ExprSynonymList(tls, pTerm, (*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid, bp+128, bp+144, bp+152)
	if !(rc != 0) {
		goto __8
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 144)))
	goto ismatch_out
__8:
	;
	if !(*(*uintptr)(unsafe.Pointer(bp + 144)) == (*Fts5Buffer)(unsafe.Pointer(bp+128)).Fp) {
		goto __9
	}
	bFlag = 1
__9:
	;
	goto __7
__6:
	*(*uintptr)(unsafe.Pointer(bp + 144)) = (*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)).FpData
	*(*int32)(unsafe.Pointer(bp + 152)) = (*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)).FnData
__7:
	;
	sqlite3Fts5PoslistReaderInit(tls, *(*uintptr)(unsafe.Pointer(bp + 144)), *(*int32)(unsafe.Pointer(bp + 152)), aIter+uintptr(i)*32)
	(*Fts5PoslistReader)(unsafe.Pointer(aIter + uintptr(i)*32)).FbFlag = U8(bFlag)
	if !((*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(i)*32)).FbEof != 0) {
		goto __10
	}
	goto ismatch_out
__10:
	;
	goto __4
__4:
	i++
	goto __3
	goto __5
__5:
	;
__11:
	if !(1 != 0) {
		goto __12
	}
	iPos = (*Fts5PoslistReader)(unsafe.Pointer(aIter)).FiPos
__13:
	bMatch = 1
	i = 0
__16:
	if !(i < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
		goto __18
	}
	pPos = aIter + uintptr(i)*32
	iAdj = iPos + I64(i)
	if !((*Fts5PoslistReader)(unsafe.Pointer(pPos)).FiPos != iAdj) {
		goto __19
	}
	bMatch = 0
__20:
	if !((*Fts5PoslistReader)(unsafe.Pointer(pPos)).FiPos < iAdj) {
		goto __21
	}
	if !(sqlite3Fts5PoslistReaderNext(tls, pPos) != 0) {
		goto __22
	}
	goto ismatch_out
__22:
	;
	goto __20
__21:
	;
	if !((*Fts5PoslistReader)(unsafe.Pointer(pPos)).FiPos > iAdj) {
		goto __23
	}
	iPos = (*Fts5PoslistReader)(unsafe.Pointer(pPos)).FiPos - I64(i)
__23:
	;
__19:
	;
	goto __17
__17:
	i++
	goto __16
	goto __18
__18:
	;
	goto __14
__14:
	if bMatch == 0 {
		goto __13
	}
	goto __15
__15:
	;
	if !(bFirst == 0 || int32(iPos&int64(0x7FFFFFFF)) == 0) {
		goto __24
	}
	rc = sqlite3Fts5PoslistWriterAppend(tls, pPhrase+8, bp+160, iPos)
	if !(rc != SQLITE_OK) {
		goto __25
	}
	goto ismatch_out
__25:
	;
__24:
	;
	i = 0
__26:
	if !(i < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
		goto __28
	}
	if !(sqlite3Fts5PoslistReaderNext(tls, aIter+uintptr(i)*32) != 0) {
		goto __29
	}
	goto ismatch_out
__29:
	;
	goto __27
__27:
	i++
	goto __26
	goto __28
__28:
	;
	goto __11
__12:
	;
ismatch_out:
	*(*int32)(unsafe.Pointer(pbMatch)) = libc.Bool32((*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn > 0)
	i = 0
__30:
	if !(i < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
		goto __32
	}
	if !((*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(i)*32)).FbFlag != 0) {
		goto __33
	}
	Xsqlite3_free(tls, (*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(i)*32)).Fa)
__33:
	;
	goto __31
__31:
	i++
	goto __30
	goto __32
__32:
	;
	if !(aIter != bp) {
		goto __34
	}
	Xsqlite3_free(tls, aIter)
__34:
	;
	return rc
}

type Fts5LookaheadReader1 = struct {
	Fa          uintptr
	Fn          int32
	Fi          int32
	FiPos       I64
	FiLookahead I64
}

type Fts5LookaheadReader = Fts5LookaheadReader1

func fts5LookaheadReaderNext(tls *libc.TLS, p uintptr) int32 {
	(*Fts5LookaheadReader)(unsafe.Pointer(p)).FiPos = (*Fts5LookaheadReader)(unsafe.Pointer(p)).FiLookahead
	if sqlite3Fts5PoslistNext64(tls, (*Fts5LookaheadReader)(unsafe.Pointer(p)).Fa, (*Fts5LookaheadReader)(unsafe.Pointer(p)).Fn, p+12, p+24) != 0 {
		(*Fts5LookaheadReader)(unsafe.Pointer(p)).FiLookahead = int64(1) << 62
	}
	return libc.Bool32((*Fts5LookaheadReader)(unsafe.Pointer(p)).FiPos == int64(1)<<62)
}

func fts5LookaheadReaderInit(tls *libc.TLS, a uintptr, n int32, p uintptr) int32 {
	libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(Fts5LookaheadReader{})))
	(*Fts5LookaheadReader)(unsafe.Pointer(p)).Fa = a
	(*Fts5LookaheadReader)(unsafe.Pointer(p)).Fn = n
	fts5LookaheadReaderNext(tls, p)
	return fts5LookaheadReaderNext(tls, p)
}

type Fts5NearTrimmer1 = struct {
	Freader Fts5LookaheadReader
	Fwriter Fts5PoslistWriter
	FpOut   uintptr
}

type Fts5NearTrimmer = Fts5NearTrimmer1

func fts5ExprNearIsMatch(tls *libc.TLS, pRc uintptr, pNear uintptr) int32 {
	bp := tls.Alloc(196)
	defer tls.Free(196)

	var a uintptr
	var apPhrase uintptr
	var i int32

	var bMatch int32
	var nByte Sqlite3_int64
	var pPoslist uintptr
	var pPos uintptr
	var iPos I64
	var pWriter uintptr
	var iAdv int32
	var iMin I64
	var iMax I64
	var bRet int32
	a = bp
	apPhrase = pNear + 24
	*(*int32)(unsafe.Pointer(bp + 192)) = *(*int32)(unsafe.Pointer(pRc))

	if !((*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase > int32(uint64(unsafe.Sizeof([4]Fts5NearTrimmer{}))/uint64(unsafe.Sizeof(Fts5NearTrimmer{})))) {
		goto __1
	}
	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5NearTrimmer{})) * uint64((*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase))
	a = sqlite3Fts5MallocZero(tls, bp+192, nByte)
	goto __2
__1:
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([4]Fts5NearTrimmer{})))
__2:
	;
	if !(*(*int32)(unsafe.Pointer(bp + 192)) != SQLITE_OK) {
		goto __3
	}
	*(*int32)(unsafe.Pointer(pRc)) = *(*int32)(unsafe.Pointer(bp + 192))
	return 0
__3:
	;
	i = 0
__4:
	if !(i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
		goto __6
	}
	pPoslist = *(*uintptr)(unsafe.Pointer(apPhrase + uintptr(i)*8)) + 8
	fts5LookaheadReaderInit(tls, (*Fts5Buffer)(unsafe.Pointer(pPoslist)).Fp, (*Fts5Buffer)(unsafe.Pointer(pPoslist)).Fn, a+uintptr(i)*48)
	(*Fts5Buffer)(unsafe.Pointer(pPoslist)).Fn = 0
	(*Fts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48)).FpOut = pPoslist
	goto __5
__5:
	i++
	goto __4
	goto __6
__6:
	;
__7:
	if !(1 != 0) {
		goto __8
	}

	iMax = (*Fts5NearTrimmer)(unsafe.Pointer(a)).Freader.FiPos
__9:
	bMatch = 1
	i = 0
__12:
	if !(i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
		goto __14
	}
	pPos = a + uintptr(i)*48
	iMin = iMax - I64((*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8)))).FnTerm) - I64((*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnNear)
	if !((*Fts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos < iMin || (*Fts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos > iMax) {
		goto __15
	}
	bMatch = 0
__16:
	if !((*Fts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos < iMin) {
		goto __17
	}
	if !(fts5LookaheadReaderNext(tls, pPos) != 0) {
		goto __18
	}
	goto ismatch_out
__18:
	;
	goto __16
__17:
	;
	if !((*Fts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos > iMax) {
		goto __19
	}
	iMax = (*Fts5LookaheadReader)(unsafe.Pointer(pPos)).FiPos
__19:
	;
__15:
	;
	goto __13
__13:
	i++
	goto __12
	goto __14
__14:
	;
	goto __10
__10:
	if bMatch == 0 {
		goto __9
	}
	goto __11
__11:
	;
	i = 0
__20:
	if !(i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
		goto __22
	}
	iPos = (*Fts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48)).Freader.FiPos
	pWriter = a + uintptr(i)*48 + 32
	if !((*Fts5Buffer)(unsafe.Pointer((*Fts5NearTrimmer)(unsafe.Pointer(a+uintptr(i)*48)).FpOut)).Fn == 0 || iPos != (*Fts5PoslistWriter)(unsafe.Pointer(pWriter)).FiPrev) {
		goto __23
	}
	sqlite3Fts5PoslistWriterAppend(tls, (*Fts5NearTrimmer)(unsafe.Pointer(a+uintptr(i)*48)).FpOut, pWriter, iPos)
__23:
	;
	goto __21
__21:
	i++
	goto __20
	goto __22
__22:
	;
	iAdv = 0
	iMin = (*Fts5NearTrimmer)(unsafe.Pointer(a)).Freader.FiLookahead
	i = 0
__24:
	if !(i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
		goto __26
	}
	if !((*Fts5NearTrimmer)(unsafe.Pointer(a+uintptr(i)*48)).Freader.FiLookahead < iMin) {
		goto __27
	}
	iMin = (*Fts5NearTrimmer)(unsafe.Pointer(a + uintptr(i)*48)).Freader.FiLookahead
	iAdv = i
__27:
	;
	goto __25
__25:
	i++
	goto __24
	goto __26
__26:
	;
	if !(fts5LookaheadReaderNext(tls, a+uintptr(iAdv)*48) != 0) {
		goto __28
	}
	goto ismatch_out
__28:
	;
	goto __7
__8:
	;
ismatch_out:
	bRet = libc.Bool32((*Fts5Buffer)(unsafe.Pointer((*Fts5NearTrimmer)(unsafe.Pointer(a)).FpOut)).Fn > 0)
	*(*int32)(unsafe.Pointer(pRc)) = *(*int32)(unsafe.Pointer(bp + 192))
	if !(a != bp) {
		goto __29
	}
	Xsqlite3_free(tls, a)
__29:
	;
	return bRet

	return int32(0)
}

func fts5ExprAdvanceto(tls *libc.TLS, pIter uintptr, bDesc int32, piLast uintptr, pRc uintptr, pbEof uintptr) int32 {
	var iLast I64 = *(*I64)(unsafe.Pointer(piLast))
	var iRowid I64

	iRowid = (*Fts5IndexIter)(unsafe.Pointer(pIter)).FiRowid
	if bDesc == 0 && iLast > iRowid || bDesc != 0 && iLast < iRowid {
		var rc int32 = sqlite3Fts5IterNextFrom(tls, pIter, iLast)
		if rc != 0 || (*Fts5IndexIter)(unsafe.Pointer(pIter)).FbEof != 0 {
			*(*int32)(unsafe.Pointer(pRc)) = rc
			*(*int32)(unsafe.Pointer(pbEof)) = 1
			return 1
		}
		iRowid = (*Fts5IndexIter)(unsafe.Pointer(pIter)).FiRowid

	}
	*(*I64)(unsafe.Pointer(piLast)) = iRowid

	return 0
}

func fts5ExprSynonymAdvanceto(tls *libc.TLS, pTerm uintptr, bDesc int32, piLast uintptr, pRc uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var rc int32 = SQLITE_OK
	var iLast I64 = *(*I64)(unsafe.Pointer(piLast))
	var p uintptr
	*(*int32)(unsafe.Pointer(bp)) = 0

	for p = pTerm; rc == SQLITE_OK && p != 0; p = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym {
		if int32((*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) == 0 {
			var iRowid I64 = (*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FiRowid
			if bDesc == 0 && iLast > iRowid || bDesc != 0 && iLast < iRowid {
				rc = sqlite3Fts5IterNextFrom(tls, (*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter, iLast)
			}
		}
	}

	if rc != SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRc)) = rc
		*(*int32)(unsafe.Pointer(bp)) = 1
	} else {
		*(*I64)(unsafe.Pointer(piLast)) = fts5ExprSynonymRowid(tls, pTerm, bDesc, bp)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func fts5ExprNearTest(tls *libc.TLS, pRc uintptr, pExpr uintptr, pNode uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pNear uintptr = (*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear
	*(*int32)(unsafe.Pointer(bp + 4)) = *(*int32)(unsafe.Pointer(pRc))

	if (*Fts5Config)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FeDetail != FTS5_DETAIL_FULL {
		var pTerm uintptr
		var pPhrase uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24))
		(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = 0
		for pTerm = pPhrase + 32; pTerm != 0; pTerm = (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym {
			var pIter uintptr = (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter
			if int32((*Fts5IndexIter)(unsafe.Pointer(pIter)).FbEof) == 0 {
				if (*Fts5IndexIter)(unsafe.Pointer(pIter)).FiRowid == (*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid && (*Fts5IndexIter)(unsafe.Pointer(pIter)).FnData > 0 {
					(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = 1
				}
			}
		}
		return (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn
	} else {
		var i int32

		for i = 0; *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK && i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase; i++ {
			var pPhrase uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8))
			if (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 1 || (*Fts5ExprTerm)(unsafe.Pointer(pPhrase+32)).FpSynonym != 0 ||
				(*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset != 0 || (*Fts5ExprTerm)(unsafe.Pointer(pPhrase+32)).FbFirst != 0 {
				*(*int32)(unsafe.Pointer(bp)) = 0
				*(*int32)(unsafe.Pointer(bp + 4)) = fts5ExprPhraseIsMatch(tls, pNode, pPhrase, bp)
				if *(*int32)(unsafe.Pointer(bp)) == 0 {
					break
				}
			} else {
				var pIter uintptr = (*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32)).FpIter
				sqlite3Fts5BufferSet(tls, bp+4, pPhrase+8, (*Fts5IndexIter)(unsafe.Pointer(pIter)).FnData, (*Fts5IndexIter)(unsafe.Pointer(pIter)).FpData)
			}
		}

		*(*int32)(unsafe.Pointer(pRc)) = *(*int32)(unsafe.Pointer(bp + 4))
		if i == (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase && (i == 1 || fts5ExprNearIsMatch(tls, pRc, pNear) != 0) {
			return 1
		}
		return 0
	}
	return int32(0)
}

func fts5ExprNearInitAll(tls *libc.TLS, pExpr uintptr, pNode uintptr) int32 {
	var pNear uintptr = (*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear
	var i int32

	for i = 0; i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase; i++ {
		var pPhrase uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8))
		if (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm == 0 {
			(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 1
			return SQLITE_OK
		} else {
			var j int32
			for j = 0; j < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm; j++ {
				var pTerm uintptr = pPhrase + 32 + uintptr(j)*32
				var p uintptr
				var bHit int32 = 0

				for p = pTerm; p != 0; p = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym {
					var rc int32
					if (*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter != 0 {
						sqlite3Fts5IterClose(tls, (*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)
						(*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter = uintptr(0)
					}
					rc = sqlite3Fts5IndexQuery(tls,
						(*Fts5Expr)(unsafe.Pointer(pExpr)).FpIndex, (*Fts5ExprTerm)(unsafe.Pointer(p)).FzTerm, int32(libc.Xstrlen(tls, (*Fts5ExprTerm)(unsafe.Pointer(p)).FzTerm)),
						func() int32 {
							if (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FbPrefix != 0 {
								return FTS5INDEX_QUERY_PREFIX
							}
							return 0
						}()|func() int32 {
							if (*Fts5Expr)(unsafe.Pointer(pExpr)).FbDesc != 0 {
								return FTS5INDEX_QUERY_DESC
							}
							return 0
						}(),
						(*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset,
						p+16)

					if rc != SQLITE_OK {
						return rc
					}
					if 0 == int32((*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) {
						bHit = 1
					}
				}

				if bHit == 0 {
					(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 1
					return SQLITE_OK
				}
			}
		}
	}

	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 0
	return SQLITE_OK
}

func fts5RowidCmp(tls *libc.TLS, pExpr uintptr, iLhs I64, iRhs I64) int32 {
	if (*Fts5Expr)(unsafe.Pointer(pExpr)).FbDesc == 0 {
		if iLhs < iRhs {
			return -1
		}
		return libc.Bool32(iLhs > iRhs)
	} else {
		if iLhs > iRhs {
			return -1
		}
		return libc.Bool32(iLhs < iRhs)
	}
	return int32(0)
}

func fts5ExprSetEof(tls *libc.TLS, pNode uintptr) {
	var i int32
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 1
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild; i++ {
		fts5ExprSetEof(tls, *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8)))
	}
}

func fts5ExprNodeZeroPoslist(tls *libc.TLS, pNode uintptr) {
	if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType == FTS5_STRING || (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType == FTS5_TERM {
		var pNear uintptr = (*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear
		var i int32
		for i = 0; i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase; i++ {
			var pPhrase uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8))
			(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = 0
		}
	} else {
		var i int32
		for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild; i++ {
			fts5ExprNodeZeroPoslist(tls, *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8)))
		}
	}
}

func fts5NodeCompare(tls *libc.TLS, pExpr uintptr, p1 uintptr, p2 uintptr) int32 {
	if (*Fts5ExprNode)(unsafe.Pointer(p2)).FbEof != 0 {
		return -1
	}
	if (*Fts5ExprNode)(unsafe.Pointer(p1)).FbEof != 0 {
		return +1
	}
	return fts5RowidCmp(tls, pExpr, (*Fts5ExprNode)(unsafe.Pointer(p1)).FiRowid, (*Fts5ExprNode)(unsafe.Pointer(p2)).FiRowid)
}

func fts5ExprNodeTest_STRING(tls *libc.TLS, pExpr uintptr, pNode uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var pNear uintptr = (*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear
	var pLeft uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24))
	*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_OK

	var i int32
	var j int32
	var bMatch int32
	var bDesc int32 = (*Fts5Expr)(unsafe.Pointer(pExpr)).FbDesc

	if (*Fts5ExprTerm)(unsafe.Pointer(pLeft+32)).FpSynonym != 0 {
		*(*I64)(unsafe.Pointer(bp)) = fts5ExprSynonymRowid(tls, pLeft+32, bDesc, uintptr(0))
	} else {
		*(*I64)(unsafe.Pointer(bp)) = (*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(pLeft + 32)).FpIter)).FiRowid
	}

	for __ccgo := true; __ccgo; __ccgo = bMatch == 0 {
		bMatch = 1
		for i = 0; i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase; i++ {
			var pPhrase uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8))
			for j = 0; j < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm; j++ {
				var pTerm uintptr = pPhrase + 32 + uintptr(j)*32
				if (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
					var iRowid I64 = fts5ExprSynonymRowid(tls, pTerm, bDesc, uintptr(0))
					if iRowid == *(*I64)(unsafe.Pointer(bp)) {
						continue
					}
					bMatch = 0
					if fts5ExprSynonymAdvanceto(tls, pTerm, bDesc, bp, bp+8) != 0 {
						(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
						(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 1
						return *(*int32)(unsafe.Pointer(bp + 8))
					}
				} else {
					var pIter uintptr = (*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32 + uintptr(j)*32)).FpIter
					if (*Fts5IndexIter)(unsafe.Pointer(pIter)).FiRowid == *(*I64)(unsafe.Pointer(bp)) || (*Fts5IndexIter)(unsafe.Pointer(pIter)).FbEof != 0 {
						continue
					}
					bMatch = 0
					if fts5ExprAdvanceto(tls, pIter, bDesc, bp, bp+8, pNode+4) != 0 {
						return *(*int32)(unsafe.Pointer(bp + 8))
					}
				}
			}
		}
	}

	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = *(*I64)(unsafe.Pointer(bp))
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = libc.Bool32(0 == fts5ExprNearTest(tls, bp+8, pExpr, pNode) && *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK)

	return *(*int32)(unsafe.Pointer(bp + 8))
}

func fts5ExprNodeNext_STRING(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom I64) int32 {
	var pTerm uintptr = *(*uintptr)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 24)) + 32
	var rc int32 = SQLITE_OK

	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	if (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
		var bEof int32 = 1
		var p uintptr

		var iRowid I64 = fts5ExprSynonymRowid(tls, pTerm, (*Fts5Expr)(unsafe.Pointer(pExpr)).FbDesc, uintptr(0))

		for p = pTerm; p != 0; p = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym {
			if int32((*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) == 0 {
				var ii I64 = (*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FiRowid
				if ii == iRowid ||
					bFromValid != 0 && ii != iFrom && libc.Bool32(ii > iFrom) == (*Fts5Expr)(unsafe.Pointer(pExpr)).FbDesc {
					if bFromValid != 0 {
						rc = sqlite3Fts5IterNextFrom(tls, (*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter, iFrom)
					} else {
						rc = sqlite3Fts5IterNext(tls, (*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)
					}
					if rc != SQLITE_OK {
						break
					}
					if int32((*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(p)).FpIter)).FbEof) == 0 {
						bEof = 0
					}
				} else {
					bEof = 0
				}
			}
		}

		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = libc.Bool32(rc != 0 || bEof != 0)
	} else {
		var pIter uintptr = (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter

		if bFromValid != 0 {
			rc = sqlite3Fts5IterNextFrom(tls, pIter, iFrom)
		} else {
			rc = sqlite3Fts5IterNext(tls, pIter)
		}

		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = libc.Bool32(rc != 0 || (*Fts5IndexIter)(unsafe.Pointer(pIter)).FbEof != 0)
	}

	if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 {
		rc = fts5ExprNodeTest_STRING(tls, pExpr, pNode)
	}

	return rc
}

func fts5ExprNodeTest_TERM(tls *libc.TLS, pExpr uintptr, pNode uintptr) int32 {
	var pPhrase uintptr = *(*uintptr)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 24))
	var pIter uintptr = (*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32)).FpIter

	(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = (*Fts5IndexIter)(unsafe.Pointer(pIter)).FnData
	if (*Fts5Config)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FeDetail == FTS5_DETAIL_FULL {
		(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fp = (*Fts5IndexIter)(unsafe.Pointer(pIter)).FpData
	}
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*Fts5IndexIter)(unsafe.Pointer(pIter)).FiRowid
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = libc.Bool32((*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn == 0)
	return SQLITE_OK
}

func fts5ExprNodeNext_TERM(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom I64) int32 {
	var rc int32
	var pIter uintptr = (*Fts5ExprTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 24)) + 32)).FpIter

	if bFromValid != 0 {
		rc = sqlite3Fts5IterNextFrom(tls, pIter, iFrom)
	} else {
		rc = sqlite3Fts5IterNext(tls, pIter)
	}
	if rc == SQLITE_OK && int32((*Fts5IndexIter)(unsafe.Pointer(pIter)).FbEof) == 0 {
		rc = fts5ExprNodeTest_TERM(tls, pExpr, pNode)
	} else {
		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 1
		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	}
	return rc
}

func fts5ExprNodeTest_OR(tls *libc.TLS, pExpr uintptr, pNode uintptr) {
	var pNext uintptr = *(*uintptr)(unsafe.Pointer(pNode + 48))
	var i int32

	for i = 1; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild; i++ {
		var pChild uintptr = *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8))
		var cmp int32 = fts5NodeCompare(tls, pExpr, pNext, pChild)
		if cmp > 0 || cmp == 0 && (*Fts5ExprNode)(unsafe.Pointer(pChild)).FbNomatch == 0 {
			pNext = pChild
		}
	}
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*Fts5ExprNode)(unsafe.Pointer(pNext)).FiRowid
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = (*Fts5ExprNode)(unsafe.Pointer(pNext)).FbEof
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = (*Fts5ExprNode)(unsafe.Pointer(pNext)).FbNomatch
}

func fts5ExprNodeNext_OR(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom I64) int32 {
	var i int32
	var iLast I64 = (*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid

	for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild; i++ {
		var p1 uintptr = *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8))

		if (*Fts5ExprNode)(unsafe.Pointer(p1)).FbEof == 0 {
			if (*Fts5ExprNode)(unsafe.Pointer(p1)).FiRowid == iLast ||
				bFromValid != 0 && fts5RowidCmp(tls, pExpr, (*Fts5ExprNode)(unsafe.Pointer(p1)).FiRowid, iFrom) < 0 {
				var rc int32 = (*struct {
					f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(p1)).FxNext})).f(tls, pExpr, p1, bFromValid, iFrom)
				if rc != SQLITE_OK {
					(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
					return rc
				}
			}
		}
	}

	fts5ExprNodeTest_OR(tls, pExpr, pNode)
	return SQLITE_OK
}

func fts5ExprNodeTest_AND(tls *libc.TLS, pExpr uintptr, pAnd uintptr) int32 {
	var iChild int32
	var iLast I64 = (*Fts5ExprNode)(unsafe.Pointer(pAnd)).FiRowid
	var rc int32 = SQLITE_OK
	var bMatch int32

	for __ccgo := true; __ccgo; __ccgo = bMatch == 0 {
		(*Fts5ExprNode)(unsafe.Pointer(pAnd)).FbNomatch = 0
		bMatch = 1
		for iChild = 0; iChild < (*Fts5ExprNode)(unsafe.Pointer(pAnd)).FnChild; iChild++ {
			var pChild uintptr = *(*uintptr)(unsafe.Pointer(pAnd + 48 + uintptr(iChild)*8))
			var cmp int32 = fts5RowidCmp(tls, pExpr, iLast, (*Fts5ExprNode)(unsafe.Pointer(pChild)).FiRowid)
			if cmp > 0 {
				rc = (*struct {
					f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
				})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(pChild)).FxNext})).f(tls, pExpr, pChild, 1, iLast)
				if rc != SQLITE_OK {
					(*Fts5ExprNode)(unsafe.Pointer(pAnd)).FbNomatch = 0
					return rc
				}
			}

			if (*Fts5ExprNode)(unsafe.Pointer(pChild)).FbEof != 0 {
				fts5ExprSetEof(tls, pAnd)
				bMatch = 1
				break
			} else if iLast != (*Fts5ExprNode)(unsafe.Pointer(pChild)).FiRowid {
				bMatch = 0
				iLast = (*Fts5ExprNode)(unsafe.Pointer(pChild)).FiRowid
			}

			if (*Fts5ExprNode)(unsafe.Pointer(pChild)).FbNomatch != 0 {
				(*Fts5ExprNode)(unsafe.Pointer(pAnd)).FbNomatch = 1
			}
		}
	}

	if (*Fts5ExprNode)(unsafe.Pointer(pAnd)).FbNomatch != 0 && pAnd != (*Fts5Expr)(unsafe.Pointer(pExpr)).FpRoot {
		fts5ExprNodeZeroPoslist(tls, pAnd)
	}
	(*Fts5ExprNode)(unsafe.Pointer(pAnd)).FiRowid = iLast
	return SQLITE_OK
}

func fts5ExprNodeNext_AND(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom I64) int32 {
	var rc int32 = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 48)))).FxNext})).f(tls, pExpr, *(*uintptr)(unsafe.Pointer(pNode + 48)), bFromValid, iFrom)
	if rc == SQLITE_OK {
		rc = fts5ExprNodeTest_AND(tls, pExpr, pNode)
	} else {
		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	}
	return rc
}

func fts5ExprNodeTest_NOT(tls *libc.TLS, pExpr uintptr, pNode uintptr) int32 {
	var rc int32 = SQLITE_OK
	var p1 uintptr = *(*uintptr)(unsafe.Pointer(pNode + 48))
	var p2 uintptr = *(*uintptr)(unsafe.Pointer(pNode + 48 + 1*8))

	for rc == SQLITE_OK && (*Fts5ExprNode)(unsafe.Pointer(p1)).FbEof == 0 {
		var cmp int32 = fts5NodeCompare(tls, pExpr, p1, p2)
		if cmp > 0 {
			rc = (*struct {
				f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(p2)).FxNext})).f(tls, pExpr, p2, 1, (*Fts5ExprNode)(unsafe.Pointer(p1)).FiRowid)
			cmp = fts5NodeCompare(tls, pExpr, p1, p2)
		}

		if cmp != 0 || (*Fts5ExprNode)(unsafe.Pointer(p2)).FbNomatch != 0 {
			break
		}
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(p1)).FxNext})).f(tls, pExpr, p1, 0, int64(0))
	}
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = (*Fts5ExprNode)(unsafe.Pointer(p1)).FbEof
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = (*Fts5ExprNode)(unsafe.Pointer(p1)).FbNomatch
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*Fts5ExprNode)(unsafe.Pointer(p1)).FiRowid
	if (*Fts5ExprNode)(unsafe.Pointer(p1)).FbEof != 0 {
		fts5ExprNodeZeroPoslist(tls, p2)
	}
	return rc
}

func fts5ExprNodeNext_NOT(tls *libc.TLS, pExpr uintptr, pNode uintptr, bFromValid int32, iFrom I64) int32 {
	var rc int32 = (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 48)))).FxNext})).f(tls, pExpr, *(*uintptr)(unsafe.Pointer(pNode + 48)), bFromValid, iFrom)
	if rc == SQLITE_OK {
		rc = fts5ExprNodeTest_NOT(tls, pExpr, pNode)
	}
	if rc != SQLITE_OK {
		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
	}
	return rc
}

func fts5ExprNodeTest(tls *libc.TLS, pExpr uintptr, pNode uintptr) int32 {
	var rc int32 = SQLITE_OK
	if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 {
		switch (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType {
		case FTS5_STRING:
			{
				rc = fts5ExprNodeTest_STRING(tls, pExpr, pNode)
				break

			}
			fallthrough

		case FTS5_TERM:
			{
				rc = fts5ExprNodeTest_TERM(tls, pExpr, pNode)
				break

			}
			fallthrough

		case FTS5_AND:
			{
				rc = fts5ExprNodeTest_AND(tls, pExpr, pNode)
				break

			}
			fallthrough

		case FTS5_OR:
			{
				fts5ExprNodeTest_OR(tls, pExpr, pNode)
				break

			}
			fallthrough

		default:
			{
				rc = fts5ExprNodeTest_NOT(tls, pExpr, pNode)
				break

			}
		}
	}
	return rc
}

func fts5ExprNodeFirst(tls *libc.TLS, pExpr uintptr, pNode uintptr) int32 {
	var rc int32 = SQLITE_OK
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 0
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0

	if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType == FTS5_TERM || (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType == FTS5_STRING {
		rc = fts5ExprNearInitAll(tls, pExpr, pNode)
	} else if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FxNext == uintptr(0) {
		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 1
	} else {
		var i int32
		var nEof int32 = 0
		for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild && rc == SQLITE_OK; i++ {
			var pChild uintptr = *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8))
			rc = fts5ExprNodeFirst(tls, pExpr, *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8)))

			nEof = nEof + (*Fts5ExprNode)(unsafe.Pointer(pChild)).FbEof
		}
		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*Fts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 48)))).FiRowid

		switch (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType {
		case FTS5_AND:
			if nEof > 0 {
				fts5ExprSetEof(tls, pNode)
			}
			break
			fallthrough

		case FTS5_OR:
			if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild == nEof {
				fts5ExprSetEof(tls, pNode)
			}
			break
			fallthrough

		default:
			(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = (*Fts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNode + 48)))).FbEof
			break
		}
	}

	if rc == SQLITE_OK {
		rc = fts5ExprNodeTest(tls, pExpr, pNode)
	}
	return rc
}

func sqlite3Fts5ExprFirst(tls *libc.TLS, p uintptr, pIdx uintptr, iFirst I64, bDesc int32) int32 {
	var pRoot uintptr = (*Fts5Expr)(unsafe.Pointer(p)).FpRoot
	var rc int32

	(*Fts5Expr)(unsafe.Pointer(p)).FpIndex = pIdx
	(*Fts5Expr)(unsafe.Pointer(p)).FbDesc = bDesc
	rc = fts5ExprNodeFirst(tls, p, pRoot)

	if rc == SQLITE_OK &&
		0 == (*Fts5ExprNode)(unsafe.Pointer(pRoot)).FbEof &&
		fts5RowidCmp(tls, p, (*Fts5ExprNode)(unsafe.Pointer(pRoot)).FiRowid, iFirst) < 0 {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(pRoot)).FxNext})).f(tls, p, pRoot, 1, iFirst)
	}

	for (*Fts5ExprNode)(unsafe.Pointer(pRoot)).FbNomatch != 0 && rc == SQLITE_OK {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(pRoot)).FxNext})).f(tls, p, pRoot, 0, int64(0))
	}
	return rc
}

func sqlite3Fts5ExprNext(tls *libc.TLS, p uintptr, iLast I64) int32 {
	var rc int32
	var pRoot uintptr = (*Fts5Expr)(unsafe.Pointer(p)).FpRoot

	for __ccgo := true; __ccgo; __ccgo = (*Fts5ExprNode)(unsafe.Pointer(pRoot)).FbNomatch != 0 {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5ExprNode)(unsafe.Pointer(pRoot)).FxNext})).f(tls, p, pRoot, 0, int64(0))

	}
	if fts5RowidCmp(tls, p, (*Fts5ExprNode)(unsafe.Pointer(pRoot)).FiRowid, iLast) > 0 {
		(*Fts5ExprNode)(unsafe.Pointer(pRoot)).FbEof = 1
	}
	return rc
}

func sqlite3Fts5ExprEof(tls *libc.TLS, p uintptr) int32 {
	return (*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(p)).FpRoot)).FbEof
}

func sqlite3Fts5ExprRowid(tls *libc.TLS, p uintptr) I64 {
	return (*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(p)).FpRoot)).FiRowid
}

func fts5ParseStringFromToken(tls *libc.TLS, pToken uintptr, pz uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(pz)) = sqlite3Fts5Strndup(tls, bp, (*Fts5Token)(unsafe.Pointer(pToken)).Fp, (*Fts5Token)(unsafe.Pointer(pToken)).Fn)
	return *(*int32)(unsafe.Pointer(bp))
}

func fts5ExprPhraseFree(tls *libc.TLS, pPhrase uintptr) {
	if pPhrase != 0 {
		var i int32
		for i = 0; i < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm; i++ {
			var pSyn uintptr
			var pNext uintptr
			var pTerm uintptr = pPhrase + 32 + uintptr(i)*32
			Xsqlite3_free(tls, (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FzTerm)
			sqlite3Fts5IterClose(tls, (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)
			for pSyn = (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym; pSyn != 0; pSyn = pNext {
				pNext = (*Fts5ExprTerm)(unsafe.Pointer(pSyn)).FpSynonym
				sqlite3Fts5IterClose(tls, (*Fts5ExprTerm)(unsafe.Pointer(pSyn)).FpIter)
				sqlite3Fts5BufferFree(tls, pSyn+1*32)
				Xsqlite3_free(tls, pSyn)
			}
		}
		if (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.FnSpace > 0 {
			sqlite3Fts5BufferFree(tls, pPhrase+8)
		}
		Xsqlite3_free(tls, pPhrase)
	}
}

func sqlite3Fts5ParseSetCaret(tls *libc.TLS, pPhrase uintptr) {
	if pPhrase != 0 && (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm != 0 {
		(*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32)).FbFirst = U8(1)
	}
}

func sqlite3Fts5ParseNearset(tls *libc.TLS, pParse uintptr, pNear uintptr, pPhrase uintptr) uintptr {
	var SZALLOC int32 = 8
	var pRet uintptr = uintptr(0)

	if (*Fts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		if pPhrase == uintptr(0) {
			return pNear
		}
		if pNear == uintptr(0) {
			var nByte Sqlite3_int64
			nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5ExprNearset{})) + uint64(SZALLOC)*uint64(unsafe.Sizeof(uintptr(0))))
			pRet = Xsqlite3_malloc64(tls, uint64(nByte))
			if pRet == uintptr(0) {
				(*Fts5Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
			} else {
				libc.Xmemset(tls, pRet, 0, Size_t(nByte))
			}
		} else if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase%SZALLOC == 0 {
			var nNew int32 = (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase + SZALLOC
			var nByte Sqlite3_int64

			nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5ExprNearset{})) + uint64(nNew)*uint64(unsafe.Sizeof(uintptr(0))))
			pRet = Xsqlite3_realloc64(tls, pNear, uint64(nByte))
			if pRet == uintptr(0) {
				(*Fts5Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
			}
		} else {
			pRet = pNear
		}
	}

	if pRet == uintptr(0) {
		sqlite3Fts5ParseNearsetFree(tls, pNear)
		sqlite3Fts5ParsePhraseFree(tls, pPhrase)
	} else {
		if (*Fts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase > 0 {
			var pLast uintptr = *(*uintptr)(unsafe.Pointer(pRet + 24 + uintptr((*Fts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase-1)*8))

			if (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm == 0 {
				fts5ExprPhraseFree(tls, pPhrase)
				(*Fts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase--
				(*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
				pPhrase = pLast
			} else if (*Fts5ExprPhrase)(unsafe.Pointer(pLast)).FnTerm == 0 {
				fts5ExprPhraseFree(tls, pLast)
				*(*uintptr)(unsafe.Pointer((*Fts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase-2)*8)) = pPhrase
				(*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
				(*Fts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase--
			}
		}
		*(*uintptr)(unsafe.Pointer(pRet + 24 + uintptr(libc.PostIncInt32(&(*Fts5ExprNearset)(unsafe.Pointer(pRet)).FnPhrase, 1))*8)) = pPhrase
	}
	return pRet
}

type TokenCtx1 = struct {
	FpPhrase     uintptr
	Frc          int32
	F__ccgo_pad1 [4]byte
}

type TokenCtx = TokenCtx1

func fts5ParseTokenize(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var SZALLOC int32 = 8
	var pCtx uintptr = pContext
	var pPhrase uintptr = (*TokenCtx)(unsafe.Pointer(pCtx)).FpPhrase

	_ = iUnused1
	_ = iUnused2

	if (*TokenCtx)(unsafe.Pointer(pCtx)).Frc != SQLITE_OK {
		return (*TokenCtx)(unsafe.Pointer(pCtx)).Frc
	}
	if nToken > FTS5_MAX_TOKEN_SIZE {
		nToken = FTS5_MAX_TOKEN_SIZE
	}

	if pPhrase != 0 && (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 0 && tflags&FTS5_TOKEN_COLOCATED != 0 {
		var pSyn uintptr
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5ExprTerm{})) + uint64(unsafe.Sizeof(Fts5Buffer{})) + uint64(nToken) + uint64(1))
		pSyn = Xsqlite3_malloc64(tls, uint64(nByte))
		if pSyn == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp)) = SQLITE_NOMEM
		} else {
			libc.Xmemset(tls, pSyn, 0, Size_t(nByte))
			(*Fts5ExprTerm)(unsafe.Pointer(pSyn)).FzTerm = pSyn + uintptr(uint64(unsafe.Sizeof(Fts5ExprTerm{}))) + uintptr(uint64(unsafe.Sizeof(Fts5Buffer{})))
			libc.Xmemcpy(tls, (*Fts5ExprTerm)(unsafe.Pointer(pSyn)).FzTerm, pToken, uint64(nToken))
			(*Fts5ExprTerm)(unsafe.Pointer(pSyn)).FpSynonym = (*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32 + uintptr((*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm-1)*32)).FpSynonym
			(*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32 + uintptr((*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm-1)*32)).FpSynonym = pSyn
		}
	} else {
		var pTerm uintptr
		if pPhrase == uintptr(0) || (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm%SZALLOC == 0 {
			var pNew uintptr
			var nNew int32 = SZALLOC + func() int32 {
				if pPhrase != 0 {
					return (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm
				}
				return 0
			}()

			pNew = Xsqlite3_realloc64(tls, pPhrase,
				uint64(unsafe.Sizeof(Fts5ExprPhrase{}))+uint64(unsafe.Sizeof(Fts5ExprTerm{}))*uint64(nNew))
			if pNew == uintptr(0) {
				*(*int32)(unsafe.Pointer(bp)) = SQLITE_NOMEM
			} else {
				if pPhrase == uintptr(0) {
					libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Fts5ExprPhrase{})))
				}
				(*TokenCtx)(unsafe.Pointer(pCtx)).FpPhrase = libc.AssignUintptr(&pPhrase, pNew)
				(*Fts5ExprPhrase)(unsafe.Pointer(pNew)).FnTerm = nNew - SZALLOC
			}
		}

		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			pTerm = pPhrase + 32 + uintptr(libc.PostIncInt32(&(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm, 1))*32
			libc.Xmemset(tls, pTerm, 0, uint64(unsafe.Sizeof(Fts5ExprTerm{})))
			(*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FzTerm = sqlite3Fts5Strndup(tls, bp, pToken, nToken)
		}
	}

	(*TokenCtx)(unsafe.Pointer(pCtx)).Frc = *(*int32)(unsafe.Pointer(bp))
	return *(*int32)(unsafe.Pointer(bp))
}

func sqlite3Fts5ParsePhraseFree(tls *libc.TLS, pPhrase uintptr) {
	fts5ExprPhraseFree(tls, pPhrase)
}

func sqlite3Fts5ParseNearsetFree(tls *libc.TLS, pNear uintptr) {
	if pNear != 0 {
		var i int32
		for i = 0; i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase; i++ {
			fts5ExprPhraseFree(tls, *(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8)))
		}
		Xsqlite3_free(tls, (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset)
		Xsqlite3_free(tls, pNear)
	}
}

func sqlite3Fts5ParseFinished(tls *libc.TLS, pParse uintptr, p uintptr) {
	(*Fts5Parse)(unsafe.Pointer(pParse)).FpExpr = p
}

func parseGrowPhraseArray(tls *libc.TLS, pParse uintptr) int32 {
	if (*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase%8 == 0 {
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(uintptr(0))) * uint64((*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase+8))
		var apNew uintptr
		apNew = Xsqlite3_realloc64(tls, (*Fts5Parse)(unsafe.Pointer(pParse)).FapPhrase, uint64(nByte))
		if apNew == uintptr(0) {
			(*Fts5Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
			return SQLITE_NOMEM
		}
		(*Fts5Parse)(unsafe.Pointer(pParse)).FapPhrase = apNew
	}
	return SQLITE_OK
}

func sqlite3Fts5ParseTerm(tls *libc.TLS, pParse uintptr, pAppend uintptr, pToken uintptr, bPrefix int32) uintptr {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pConfig uintptr = (*Fts5Parse)(unsafe.Pointer(pParse)).FpConfig

	var rc int32
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(TokenCtx{})))
	(*TokenCtx)(unsafe.Pointer(bp)).FpPhrase = pAppend

	rc = fts5ParseStringFromToken(tls, pToken, bp+16)
	if rc == SQLITE_OK {
		var flags int32 = FTS5_TOKENIZE_QUERY | func() int32 {
			if bPrefix != 0 {
				return FTS5_TOKENIZE_PREFIX
			}
			return 0
		}()
		var n int32
		sqlite3Fts5Dequote(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
		n = int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp + 16))))
		rc = sqlite3Fts5Tokenize(tls, pConfig, flags, *(*uintptr)(unsafe.Pointer(bp + 16)), n, bp, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
		}{fts5ParseTokenize})))
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if rc != 0 || libc.AssignInt32(&rc, (*TokenCtx)(unsafe.Pointer(bp)).Frc) != 0 {
		(*Fts5Parse)(unsafe.Pointer(pParse)).Frc = rc
		fts5ExprPhraseFree(tls, (*TokenCtx)(unsafe.Pointer(bp)).FpPhrase)
		(*TokenCtx)(unsafe.Pointer(bp)).FpPhrase = uintptr(0)
	} else {
		if pAppend == uintptr(0) {
			if parseGrowPhraseArray(tls, pParse) != 0 {
				fts5ExprPhraseFree(tls, (*TokenCtx)(unsafe.Pointer(bp)).FpPhrase)
				return uintptr(0)
			}
			(*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase++
		}

		if (*TokenCtx)(unsafe.Pointer(bp)).FpPhrase == uintptr(0) {
			(*TokenCtx)(unsafe.Pointer(bp)).FpPhrase = sqlite3Fts5MallocZero(tls, pParse+16, int64(unsafe.Sizeof(Fts5ExprPhrase{})))
		} else if (*Fts5ExprPhrase)(unsafe.Pointer((*TokenCtx)(unsafe.Pointer(bp)).FpPhrase)).FnTerm != 0 {
			(*Fts5ExprTerm)(unsafe.Pointer((*TokenCtx)(unsafe.Pointer(bp)).FpPhrase + 32 + uintptr((*Fts5ExprPhrase)(unsafe.Pointer((*TokenCtx)(unsafe.Pointer(bp)).FpPhrase)).FnTerm-1)*32)).FbPrefix = U8(bPrefix)
		}
		*(*uintptr)(unsafe.Pointer((*Fts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase-1)*8)) = (*TokenCtx)(unsafe.Pointer(bp)).FpPhrase
	}

	return (*TokenCtx)(unsafe.Pointer(bp)).FpPhrase
}

func sqlite3Fts5ExprClonePhrase(tls *libc.TLS, pExpr uintptr, iPhrase int32, ppNew uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var pOrig uintptr
	var pNew uintptr = uintptr(0)
	*(*TokenCtx)(unsafe.Pointer(bp + 8)) = TokenCtx{}

	pOrig = *(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*8))
	pNew = sqlite3Fts5MallocZero(tls, bp, int64(unsafe.Sizeof(Fts5Expr{})))
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*Fts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase = sqlite3Fts5MallocZero(tls, bp,
			int64(unsafe.Sizeof(uintptr(0))))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot = sqlite3Fts5MallocZero(tls, bp,
			int64(unsafe.Sizeof(Fts5ExprNode{})))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear = sqlite3Fts5MallocZero(tls, bp,
			int64(uint64(unsafe.Sizeof(Fts5ExprNearset{}))+uint64(unsafe.Sizeof(uintptr(0)))))
	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		var pColsetOrig uintptr = (*Fts5ExprNearset)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer((*Fts5ExprPhrase)(unsafe.Pointer(pOrig)).FpNode)).FpNear)).FpColset
		if pColsetOrig != 0 {
			var nByte Sqlite3_int64
			var pColset uintptr
			nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Colset{})) + uint64((*Fts5Colset)(unsafe.Pointer(pColsetOrig)).FnCol-1)*uint64(unsafe.Sizeof(int32(0))))
			pColset = sqlite3Fts5MallocZero(tls, bp, nByte)
			if pColset != 0 {
				libc.Xmemcpy(tls, pColset, pColsetOrig, Size_t(nByte))
			}
			(*Fts5ExprNearset)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear)).FpColset = pColset
		}
	}

	if (*Fts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm != 0 {
		var i int32
		for i = 0; *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && i < (*Fts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm; i++ {
			var tflags int32 = 0
			var p uintptr
			for p = pOrig + 32 + uintptr(i)*32; p != 0 && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK; p = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym {
				var zTerm uintptr = (*Fts5ExprTerm)(unsafe.Pointer(p)).FzTerm
				*(*int32)(unsafe.Pointer(bp)) = fts5ParseTokenize(tls, bp+8, tflags, zTerm, int32(libc.Xstrlen(tls, zTerm)),
					0, 0)
				tflags = FTS5_TOKEN_COLOCATED
			}
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				(*Fts5ExprTerm)(unsafe.Pointer((*TokenCtx)(unsafe.Pointer(bp+8)).FpPhrase + 32 + uintptr(i)*32)).FbPrefix = (*Fts5ExprTerm)(unsafe.Pointer(pOrig + 32 + uintptr(i)*32)).FbPrefix
				(*Fts5ExprTerm)(unsafe.Pointer((*TokenCtx)(unsafe.Pointer(bp+8)).FpPhrase + 32 + uintptr(i)*32)).FbFirst = (*Fts5ExprTerm)(unsafe.Pointer(pOrig + 32 + uintptr(i)*32)).FbFirst
			}
		}
	} else {
		(*TokenCtx)(unsafe.Pointer(bp + 8)).FpPhrase = sqlite3Fts5MallocZero(tls, bp, int64(unsafe.Sizeof(Fts5ExprPhrase{})))
	}

	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK && (*TokenCtx)(unsafe.Pointer(bp+8)).FpPhrase != 0 {
		(*Fts5Expr)(unsafe.Pointer(pNew)).FpIndex = (*Fts5Expr)(unsafe.Pointer(pExpr)).FpIndex
		(*Fts5Expr)(unsafe.Pointer(pNew)).FpConfig = (*Fts5Expr)(unsafe.Pointer(pExpr)).FpConfig
		(*Fts5Expr)(unsafe.Pointer(pNew)).FnPhrase = 1
		*(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FapExprPhrase)) = (*TokenCtx)(unsafe.Pointer(bp + 8)).FpPhrase
		*(*uintptr)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear + 24)) = (*TokenCtx)(unsafe.Pointer(bp + 8)).FpPhrase
		(*Fts5ExprNearset)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FpNear)).FnPhrase = 1
		(*Fts5ExprPhrase)(unsafe.Pointer((*TokenCtx)(unsafe.Pointer(bp + 8)).FpPhrase)).FpNode = (*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot

		if (*Fts5ExprPhrase)(unsafe.Pointer(pOrig)).FnTerm == 1 &&
			(*Fts5ExprTerm)(unsafe.Pointer(pOrig+32)).FpSynonym == uintptr(0) &&
			int32((*Fts5ExprTerm)(unsafe.Pointer(pOrig+32)).FbFirst) == 0 {
			(*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FeType = FTS5_TERM
			(*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
			}{fts5ExprNodeNext_TERM}))
		} else {
			(*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FeType = FTS5_STRING
			(*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pNew)).FpRoot)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
			}{fts5ExprNodeNext_STRING}))
		}
	} else {
		sqlite3Fts5ExprFree(tls, pNew)
		fts5ExprPhraseFree(tls, (*TokenCtx)(unsafe.Pointer(bp+8)).FpPhrase)
		pNew = uintptr(0)
	}

	*(*uintptr)(unsafe.Pointer(ppNew)) = pNew
	return *(*int32)(unsafe.Pointer(bp))
}

func sqlite3Fts5ParseNear(tls *libc.TLS, pParse uintptr, pTok uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Fts5Token)(unsafe.Pointer(pTok)).Fn != 4 || libc.Xmemcmp(tls, ts+41642, (*Fts5Token)(unsafe.Pointer(pTok)).Fp, uint64(4)) != 0 {
		sqlite3Fts5ParseError(tls,
			pParse, ts+40671, libc.VaList(bp, (*Fts5Token)(unsafe.Pointer(pTok)).Fn, (*Fts5Token)(unsafe.Pointer(pTok)).Fp))
	}
}

func sqlite3Fts5ParseSetDistance(tls *libc.TLS, pParse uintptr, pNear uintptr, p uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if pNear != 0 {
		var nNear int32 = 0
		var i int32
		if (*Fts5Token)(unsafe.Pointer(p)).Fn != 0 {
			for i = 0; i < (*Fts5Token)(unsafe.Pointer(p)).Fn; i++ {
				var c uint8 = *(*uint8)(unsafe.Pointer((*Fts5Token)(unsafe.Pointer(p)).Fp + uintptr(i)))
				if int32(c) < '0' || int32(c) > '9' {
					sqlite3Fts5ParseError(tls,
						pParse, ts+41647, libc.VaList(bp, (*Fts5Token)(unsafe.Pointer(p)).Fn, (*Fts5Token)(unsafe.Pointer(p)).Fp))
					return
				}
				nNear = nNear*10 + (int32(*(*uint8)(unsafe.Pointer((*Fts5Token)(unsafe.Pointer(p)).Fp + uintptr(i)))) - '0')
			}
		} else {
			nNear = FTS5_DEFAULT_NEARDIST
		}
		(*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnNear = nNear
	}
}

func fts5ParseColset(tls *libc.TLS, pParse uintptr, p uintptr, iCol int32) uintptr {
	var nCol int32
	if p != 0 {
		nCol = (*Fts5Colset)(unsafe.Pointer(p)).FnCol
	} else {
		nCol = 0
	}
	var pNew uintptr

	pNew = Xsqlite3_realloc64(tls, p, uint64(unsafe.Sizeof(Fts5Colset{}))+uint64(unsafe.Sizeof(int32(0)))*uint64(nCol))
	if pNew == uintptr(0) {
		(*Fts5Parse)(unsafe.Pointer(pParse)).Frc = SQLITE_NOMEM
	} else {
		var aiCol uintptr = pNew + 4
		var i int32
		var j int32
		for i = 0; i < nCol; i++ {
			if *(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) == iCol {
				return pNew
			}
			if *(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) > iCol {
				break
			}
		}
		for j = nCol; j > i; j-- {
			*(*int32)(unsafe.Pointer(aiCol + uintptr(j)*4)) = *(*int32)(unsafe.Pointer(aiCol + uintptr(j-1)*4))
		}
		*(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4)) = iCol
		(*Fts5Colset)(unsafe.Pointer(pNew)).FnCol = nCol + 1

	}

	return pNew
}

func sqlite3Fts5ParseColsetInvert(tls *libc.TLS, pParse uintptr, p uintptr) uintptr {
	var pRet uintptr
	var nCol int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FnCol

	pRet = sqlite3Fts5MallocZero(tls, pParse+16,
		int64(uint64(unsafe.Sizeof(Fts5Colset{}))+uint64(unsafe.Sizeof(int32(0)))*uint64(nCol)))
	if pRet != 0 {
		var i int32
		var iOld int32 = 0
		for i = 0; i < nCol; i++ {
			if iOld >= (*Fts5Colset)(unsafe.Pointer(p)).FnCol || *(*int32)(unsafe.Pointer(p + 4 + uintptr(iOld)*4)) != i {
				*(*int32)(unsafe.Pointer(pRet + 4 + uintptr(libc.PostIncInt32(&(*Fts5Colset)(unsafe.Pointer(pRet)).FnCol, 1))*4)) = i
			} else {
				iOld++
			}
		}
	}

	Xsqlite3_free(tls, p)
	return pRet
}

func sqlite3Fts5ParseColset(tls *libc.TLS, pParse uintptr, pColset uintptr, p uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pRet uintptr = uintptr(0)
	var iCol int32
	var z uintptr

	z = sqlite3Fts5Strndup(tls, pParse+16, (*Fts5Token)(unsafe.Pointer(p)).Fp, (*Fts5Token)(unsafe.Pointer(p)).Fn)
	if (*Fts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		var pConfig uintptr = (*Fts5Parse)(unsafe.Pointer(pParse)).FpConfig
		sqlite3Fts5Dequote(tls, z)
		for iCol = 0; iCol < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; iCol++ {
			if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(iCol)*8)), z) {
				break
			}
		}
		if iCol == (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol {
			sqlite3Fts5ParseError(tls, pParse, ts+24827, libc.VaList(bp, z))
		} else {
			pRet = fts5ParseColset(tls, pParse, pColset, iCol)
		}
		Xsqlite3_free(tls, z)
	}

	if pRet == uintptr(0) {
		Xsqlite3_free(tls, pColset)
	}

	return pRet
}

func fts5CloneColset(tls *libc.TLS, pRc uintptr, pOrig uintptr) uintptr {
	var pRet uintptr
	if pOrig != 0 {
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Colset{})) + uint64((*Fts5Colset)(unsafe.Pointer(pOrig)).FnCol-1)*uint64(unsafe.Sizeof(int32(0))))
		pRet = sqlite3Fts5MallocZero(tls, pRc, nByte)
		if pRet != 0 {
			libc.Xmemcpy(tls, pRet, pOrig, Size_t(nByte))
		}
	} else {
		pRet = uintptr(0)
	}
	return pRet
}

func fts5MergeColset(tls *libc.TLS, pColset uintptr, pMerge uintptr) {
	var iIn int32 = 0
	var iMerge int32 = 0
	var iOut int32 = 0

	for iIn < (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol && iMerge < (*Fts5Colset)(unsafe.Pointer(pMerge)).FnCol {
		var iDiff int32 = *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(iIn)*4)) - *(*int32)(unsafe.Pointer(pMerge + 4 + uintptr(iMerge)*4))
		if iDiff == 0 {
			*(*int32)(unsafe.Pointer(pColset + 4 + uintptr(libc.PostIncInt32(&iOut, 1))*4)) = *(*int32)(unsafe.Pointer(pMerge + 4 + uintptr(iMerge)*4))
			iMerge++
			iIn++
		} else if iDiff > 0 {
			iMerge++
		} else {
			iIn++
		}
	}
	(*Fts5Colset)(unsafe.Pointer(pColset)).FnCol = iOut
}

func fts5ParseSetColset(tls *libc.TLS, pParse uintptr, pNode uintptr, pColset uintptr, ppFree uintptr) {
	if (*Fts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType == FTS5_STRING || (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType == FTS5_TERM {
			var pNear uintptr = (*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear
			if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset != 0 {
				fts5MergeColset(tls, (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset, pColset)
				if (*Fts5Colset)(unsafe.Pointer((*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset)).FnCol == 0 {
					(*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType = FTS5_EOF
					(*Fts5ExprNode)(unsafe.Pointer(pNode)).FxNext = uintptr(0)
				}
			} else if *(*uintptr)(unsafe.Pointer(ppFree)) != 0 {
				(*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset = pColset
				*(*uintptr)(unsafe.Pointer(ppFree)) = uintptr(0)
			} else {
				(*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset = fts5CloneColset(tls, pParse+16, pColset)
			}
		} else {
			var i int32

			for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild; i++ {
				fts5ParseSetColset(tls, pParse, *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8)), pColset, ppFree)
			}
		}
	}
}

func sqlite3Fts5ParseSetColset(tls *libc.TLS, pParse uintptr, pExpr uintptr, pColset uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*uintptr)(unsafe.Pointer(bp)) = pColset
	if (*Fts5Config)(unsafe.Pointer((*Fts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FeDetail == FTS5_DETAIL_NONE {
		sqlite3Fts5ParseError(tls, pParse,
			ts+41676, 0)
	} else {
		fts5ParseSetColset(tls, pParse, pExpr, pColset, bp)
	}
	Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func fts5ExprAssignXNext(tls *libc.TLS, pNode uintptr) {
	switch (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType {
	case FTS5_STRING:
		{
			var pNear uintptr = (*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear
			if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase == 1 && (*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24)))).FnTerm == 1 &&
				(*Fts5ExprTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24))+32)).FpSynonym == uintptr(0) &&
				int32((*Fts5ExprTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24))+32)).FbFirst) == 0 {
				(*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType = FTS5_TERM
				(*Fts5ExprNode)(unsafe.Pointer(pNode)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
				}{fts5ExprNodeNext_TERM}))
			} else {
				(*Fts5ExprNode)(unsafe.Pointer(pNode)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
				}{fts5ExprNodeNext_STRING}))
			}
			break

		}

	case FTS5_OR:
		{
			(*Fts5ExprNode)(unsafe.Pointer(pNode)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
			}{fts5ExprNodeNext_OR}))
			break

		}

	case FTS5_AND:
		{
			(*Fts5ExprNode)(unsafe.Pointer(pNode)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
			}{fts5ExprNodeNext_AND}))
			break

		}

	default:
		{
			(*Fts5ExprNode)(unsafe.Pointer(pNode)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, int32, I64) int32
			}{fts5ExprNodeNext_NOT}))
			break

		}

	}
}

func fts5ExprAddChildren(tls *libc.TLS, p uintptr, pSub uintptr) {
	if (*Fts5ExprNode)(unsafe.Pointer(p)).FeType != FTS5_NOT && (*Fts5ExprNode)(unsafe.Pointer(pSub)).FeType == (*Fts5ExprNode)(unsafe.Pointer(p)).FeType {
		var nByte int32 = int32(uint64(unsafe.Sizeof(uintptr(0))) * uint64((*Fts5ExprNode)(unsafe.Pointer(pSub)).FnChild))
		libc.Xmemcpy(tls, p+48+uintptr((*Fts5ExprNode)(unsafe.Pointer(p)).FnChild)*8, pSub+48, uint64(nByte))
		*(*int32)(unsafe.Pointer(p + 40)) += (*Fts5ExprNode)(unsafe.Pointer(pSub)).FnChild
		Xsqlite3_free(tls, pSub)
	} else {
		*(*uintptr)(unsafe.Pointer(p + 48 + uintptr(libc.PostIncInt32(&(*Fts5ExprNode)(unsafe.Pointer(p)).FnChild, 1))*8)) = pSub
	}
}

func fts5ParsePhraseToAnd(tls *libc.TLS, pParse uintptr, pNear uintptr) uintptr {
	var nTerm int32 = (*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24)))).FnTerm
	var ii int32
	var nByte int32
	var pRet uintptr

	nByte = int32(uint64(unsafe.Sizeof(Fts5ExprNode{})) + uint64(nTerm)*uint64(unsafe.Sizeof(uintptr(0))))
	pRet = sqlite3Fts5MallocZero(tls, pParse+16, int64(nByte))
	if pRet != 0 {
		(*Fts5ExprNode)(unsafe.Pointer(pRet)).FeType = FTS5_AND
		(*Fts5ExprNode)(unsafe.Pointer(pRet)).FnChild = nTerm
		fts5ExprAssignXNext(tls, pRet)
		(*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
		for ii = 0; ii < nTerm; ii++ {
			var pPhrase uintptr = sqlite3Fts5MallocZero(tls,
				pParse+16, int64(unsafe.Sizeof(Fts5ExprPhrase{})))
			if pPhrase != 0 {
				if parseGrowPhraseArray(tls, pParse) != 0 {
					fts5ExprPhraseFree(tls, pPhrase)
				} else {
					*(*uintptr)(unsafe.Pointer((*Fts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr(libc.PostIncInt32(&(*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase, 1))*8)) = pPhrase
					(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm = 1
					(*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32)).FzTerm = sqlite3Fts5Strndup(tls,
						pParse+16, (*Fts5ExprTerm)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24))+32+uintptr(ii)*32)).FzTerm, -1)
					*(*uintptr)(unsafe.Pointer(pRet + 48 + uintptr(ii)*8)) = sqlite3Fts5ParseNode(tls, pParse, FTS5_STRING,
						uintptr(0), uintptr(0), sqlite3Fts5ParseNearset(tls, pParse, uintptr(0), pPhrase))
				}
			}
		}

		if (*Fts5Parse)(unsafe.Pointer(pParse)).Frc != 0 {
			sqlite3Fts5ParseNodeFree(tls, pRet)
			pRet = uintptr(0)
		} else {
			sqlite3Fts5ParseNearsetFree(tls, pNear)
		}
	}

	return pRet
}

func sqlite3Fts5ParseNode(tls *libc.TLS, pParse uintptr, eType int32, pLeft uintptr, pRight uintptr, pNear uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pRet uintptr = uintptr(0)

	if (*Fts5Parse)(unsafe.Pointer(pParse)).Frc == SQLITE_OK {
		var nChild int32 = 0
		var nByte Sqlite3_int64

		if eType == FTS5_STRING && pNear == uintptr(0) {
			return uintptr(0)
		}
		if eType != FTS5_STRING && pLeft == uintptr(0) {
			return pRight
		}
		if eType != FTS5_STRING && pRight == uintptr(0) {
			return pLeft
		}

		if eType == FTS5_STRING &&
			(*Fts5Parse)(unsafe.Pointer(pParse)).FbPhraseToAnd != 0 &&
			(*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24)))).FnTerm > 1 {
			pRet = fts5ParsePhraseToAnd(tls, pParse, pNear)
		} else {
			if eType == FTS5_NOT {
				nChild = 2
			} else if eType == FTS5_AND || eType == FTS5_OR {
				nChild = 2
				if (*Fts5ExprNode)(unsafe.Pointer(pLeft)).FeType == eType {
					nChild = nChild + ((*Fts5ExprNode)(unsafe.Pointer(pLeft)).FnChild - 1)
				}
				if (*Fts5ExprNode)(unsafe.Pointer(pRight)).FeType == eType {
					nChild = nChild + ((*Fts5ExprNode)(unsafe.Pointer(pRight)).FnChild - 1)
				}
			}

			nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5ExprNode{})) + uint64(unsafe.Sizeof(uintptr(0)))*uint64(nChild-1))
			pRet = sqlite3Fts5MallocZero(tls, pParse+16, nByte)

			if pRet != 0 {
				(*Fts5ExprNode)(unsafe.Pointer(pRet)).FeType = eType
				(*Fts5ExprNode)(unsafe.Pointer(pRet)).FpNear = pNear
				fts5ExprAssignXNext(tls, pRet)
				if eType == FTS5_STRING {
					var iPhrase int32
					for iPhrase = 0; iPhrase < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase; iPhrase++ {
						(*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(iPhrase)*8)))).FpNode = pRet
						if (*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(iPhrase)*8)))).FnTerm == 0 {
							(*Fts5ExprNode)(unsafe.Pointer(pRet)).FxNext = uintptr(0)
							(*Fts5ExprNode)(unsafe.Pointer(pRet)).FeType = FTS5_EOF
						}
					}

					if (*Fts5Config)(unsafe.Pointer((*Fts5Parse)(unsafe.Pointer(pParse)).FpConfig)).FeDetail != FTS5_DETAIL_FULL {
						var pPhrase uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24))
						if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase != 1 ||
							(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 1 ||
							(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm > 0 && (*Fts5ExprTerm)(unsafe.Pointer(pPhrase+32)).FbFirst != 0 {
							sqlite3Fts5ParseError(tls, pParse,
								ts+41729,
								libc.VaList(bp, func() uintptr {
									if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase == 1 {
										return ts + 41779
									}
									return ts + 41642
								}()))
							Xsqlite3_free(tls, pRet)
							pRet = uintptr(0)
						}
					}
				} else {
					fts5ExprAddChildren(tls, pRet, pLeft)
					fts5ExprAddChildren(tls, pRet, pRight)
				}
			}
		}
	}

	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) uintptr {
	var pRet uintptr = uintptr(0)
	var pPrev uintptr

	if (*Fts5Parse)(unsafe.Pointer(pParse)).Frc != 0 {
		sqlite3Fts5ParseNodeFree(tls, pLeft)
		sqlite3Fts5ParseNodeFree(tls, pRight)
	} else {
		if (*Fts5ExprNode)(unsafe.Pointer(pLeft)).FeType == FTS5_AND {
			pPrev = *(*uintptr)(unsafe.Pointer(pLeft + 48 + uintptr((*Fts5ExprNode)(unsafe.Pointer(pLeft)).FnChild-1)*8))
		} else {
			pPrev = pLeft
		}

		if (*Fts5ExprNode)(unsafe.Pointer(pRight)).FeType == FTS5_EOF {
			sqlite3Fts5ParseNodeFree(tls, pRight)
			pRet = pLeft
			(*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase--
		} else if (*Fts5ExprNode)(unsafe.Pointer(pPrev)).FeType == FTS5_EOF {
			var ap uintptr

			if pPrev == pLeft {
				pRet = pRight
			} else {
				*(*uintptr)(unsafe.Pointer(pLeft + 48 + uintptr((*Fts5ExprNode)(unsafe.Pointer(pLeft)).FnChild-1)*8)) = pRight
				pRet = pLeft
			}

			ap = (*Fts5Parse)(unsafe.Pointer(pParse)).FapPhrase + uintptr((*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase-1-(*Fts5ExprNearset)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer(pRight)).FpNear)).FnPhrase)*8

			libc.Xmemmove(tls, ap, ap+1*8, uint64(unsafe.Sizeof(uintptr(0)))*uint64((*Fts5ExprNearset)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer(pRight)).FpNear)).FnPhrase))
			(*Fts5Parse)(unsafe.Pointer(pParse)).FnPhrase--

			sqlite3Fts5ParseNodeFree(tls, pPrev)
		} else {
			pRet = sqlite3Fts5ParseNode(tls, pParse, FTS5_AND, pLeft, pRight, uintptr(0))
		}
	}

	return pRet
}

func fts5ExprTermPrint(tls *libc.TLS, pTerm uintptr) uintptr {
	var nByte Sqlite3_int64 = int64(0)
	var p uintptr
	var zQuoted uintptr

	for p = pTerm; p != 0; p = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym {
		nByte = nByte + Sqlite3_int64(int32(libc.Xstrlen(tls, (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FzTerm))*2+3+2)
	}
	zQuoted = Xsqlite3_malloc64(tls, uint64(nByte))

	if zQuoted != 0 {
		var i int32 = 0
		for p = pTerm; p != 0; p = (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym {
			var zIn uintptr = (*Fts5ExprTerm)(unsafe.Pointer(p)).FzTerm
			*(*uint8)(unsafe.Pointer(zQuoted + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('"')
			for *(*uint8)(unsafe.Pointer(zIn)) != 0 {
				if int32(*(*uint8)(unsafe.Pointer(zIn))) == '"' {
					*(*uint8)(unsafe.Pointer(zQuoted + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('"')
				}
				*(*uint8)(unsafe.Pointer(zQuoted + uintptr(libc.PostIncInt32(&i, 1)))) = *(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))
			}
			*(*uint8)(unsafe.Pointer(zQuoted + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('"')
			if (*Fts5ExprTerm)(unsafe.Pointer(p)).FpSynonym != 0 {
				*(*uint8)(unsafe.Pointer(zQuoted + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('|')
			}
		}
		if (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FbPrefix != 0 {
			*(*uint8)(unsafe.Pointer(zQuoted + uintptr(libc.PostIncInt32(&i, 1)))) = uint8(' ')
			*(*uint8)(unsafe.Pointer(zQuoted + uintptr(libc.PostIncInt32(&i, 1)))) = uint8('*')
		}
		*(*uint8)(unsafe.Pointer(zQuoted + uintptr(libc.PostIncInt32(&i, 1)))) = uint8(0)
	}
	return zQuoted
}

func fts5PrintfAppend(tls *libc.TLS, zApp uintptr, zFmt uintptr, va uintptr) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var zNew uintptr
	var ap Va_list
	_ = ap
	ap = va
	zNew = Xsqlite3_vmprintf(tls, zFmt, ap)
	_ = ap
	if zApp != 0 && zNew != 0 {
		var zNew2 uintptr = Xsqlite3_mprintf(tls, ts+7814, libc.VaList(bp, zApp, zNew))
		Xsqlite3_free(tls, zNew)
		zNew = zNew2
	}
	Xsqlite3_free(tls, zApp)
	return zNew
}

func fts5ExprPrintTcl(tls *libc.TLS, pConfig uintptr, zNearsetCmd uintptr, pExpr uintptr) uintptr {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var zRet uintptr = uintptr(0)
	if (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FeType == FTS5_STRING || (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FeType == FTS5_TERM {
		var pNear uintptr = (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FpNear
		var i int32
		var iTerm int32

		zRet = fts5PrintfAppend(tls, zRet, ts+41786, libc.VaList(bp, zNearsetCmd))
		if zRet == uintptr(0) {
			return uintptr(0)
		}
		if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset != 0 {
			var aiCol uintptr = (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset + 4
			var nCol int32 = (*Fts5Colset)(unsafe.Pointer((*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset)).FnCol
			if nCol == 1 {
				zRet = fts5PrintfAppend(tls, zRet, ts+41790, libc.VaList(bp+8, *(*int32)(unsafe.Pointer(aiCol))))
			} else {
				zRet = fts5PrintfAppend(tls, zRet, ts+41799, libc.VaList(bp+16, *(*int32)(unsafe.Pointer(aiCol))))
				for i = 1; i < (*Fts5Colset)(unsafe.Pointer((*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset)).FnCol; i++ {
					zRet = fts5PrintfAppend(tls, zRet, ts+41808, libc.VaList(bp+24, *(*int32)(unsafe.Pointer(aiCol + uintptr(i)*4))))
				}
				zRet = fts5PrintfAppend(tls, zRet, ts+41812, 0)
			}
			if zRet == uintptr(0) {
				return uintptr(0)
			}
		}

		if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase > 1 {
			zRet = fts5PrintfAppend(tls, zRet, ts+41815, libc.VaList(bp+32, (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnNear))
			if zRet == uintptr(0) {
				return uintptr(0)
			}
		}

		zRet = fts5PrintfAppend(tls, zRet, ts+41825, 0)
		if zRet == uintptr(0) {
			return uintptr(0)
		}

		for i = 0; i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase; i++ {
			var pPhrase uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8))

			zRet = fts5PrintfAppend(tls, zRet, ts+41828, 0)
			for iTerm = 0; zRet != 0 && iTerm < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm; iTerm++ {
				var zTerm uintptr = (*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32 + uintptr(iTerm)*32)).FzTerm
				zRet = fts5PrintfAppend(tls, zRet, ts+7814, libc.VaList(bp+40, func() uintptr {
					if iTerm == 0 {
						return ts + 1636
					}
					return ts + 14304
				}(), zTerm))
				if (*Fts5ExprTerm)(unsafe.Pointer(pPhrase+32+uintptr(iTerm)*32)).FbPrefix != 0 {
					zRet = fts5PrintfAppend(tls, zRet, ts+9661, 0)
				}
			}

			if zRet != 0 {
				zRet = fts5PrintfAppend(tls, zRet, ts+32952, 0)
			}
			if zRet == uintptr(0) {
				return uintptr(0)
			}
		}

	} else {
		var zOp uintptr = uintptr(0)
		var i int32
		switch (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FeType {
		case FTS5_AND:
			zOp = ts + 36351
			break
			fallthrough
		case FTS5_NOT:
			zOp = ts + 41638
			break
			fallthrough
		default:
			zOp = ts + 41635
			break
		}

		zRet = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+56, zOp))
		for i = 0; zRet != 0 && i < (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FnChild; i++ {
			var z uintptr = fts5ExprPrintTcl(tls, pConfig, zNearsetCmd, *(*uintptr)(unsafe.Pointer(pExpr + 48 + uintptr(i)*8)))
			if !(z != 0) {
				Xsqlite3_free(tls, zRet)
				zRet = uintptr(0)
			} else {
				zRet = fts5PrintfAppend(tls, zRet, ts+41831, libc.VaList(bp+64, z))
			}
		}
	}

	return zRet
}

func fts5ExprPrint(tls *libc.TLS, pConfig uintptr, pExpr uintptr) uintptr {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var zRet uintptr = uintptr(0)
	if (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FeType == 0 {
		return Xsqlite3_mprintf(tls, ts+41837, 0)
	} else if (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FeType == FTS5_STRING || (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FeType == FTS5_TERM {
		var pNear uintptr = (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FpNear
		var i int32
		var iTerm int32

		if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset != 0 {
			var ii int32
			var pColset uintptr = (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FpColset
			if (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol > 1 {
				zRet = fts5PrintfAppend(tls, zRet, ts+41840, 0)
			}
			for ii = 0; ii < (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol; ii++ {
				zRet = fts5PrintfAppend(tls, zRet, ts+7814,
					libc.VaList(bp, *(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(*(*int32)(unsafe.Pointer(pColset + 4 + uintptr(ii)*4)))*8)), func() uintptr {
						if ii == (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol-1 {
							return ts + 1636
						}
						return ts + 14304
					}()))
			}
			if zRet != 0 {
				zRet = fts5PrintfAppend(tls, zRet, ts+41842, libc.VaList(bp+16, func() uintptr {
					if (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol > 1 {
						return ts + 32952
					}
					return ts + 1636
				}()))
			}
			if zRet == uintptr(0) {
				return uintptr(0)
			}
		}

		if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase > 1 {
			zRet = fts5PrintfAppend(tls, zRet, ts+41848, 0)
			if zRet == uintptr(0) {
				return uintptr(0)
			}
		}

		for i = 0; i < (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase; i++ {
			var pPhrase uintptr = *(*uintptr)(unsafe.Pointer(pNear + 24 + uintptr(i)*8))
			if i != 0 {
				zRet = fts5PrintfAppend(tls, zRet, ts+14304, 0)
				if zRet == uintptr(0) {
					return uintptr(0)
				}
			}
			for iTerm = 0; iTerm < (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm; iTerm++ {
				var zTerm uintptr = fts5ExprTermPrint(tls, pPhrase+32+uintptr(iTerm)*32)
				if zTerm != 0 {
					zRet = fts5PrintfAppend(tls, zRet, ts+7814, libc.VaList(bp+24, func() uintptr {
						if iTerm == 0 {
							return ts + 1636
						}
						return ts + 41854
					}(), zTerm))
					Xsqlite3_free(tls, zTerm)
				}
				if zTerm == uintptr(0) || zRet == uintptr(0) {
					Xsqlite3_free(tls, zRet)
					return uintptr(0)
				}
			}
		}

		if (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase > 1 {
			zRet = fts5PrintfAppend(tls, zRet, ts+41858, libc.VaList(bp+40, (*Fts5ExprNearset)(unsafe.Pointer(pNear)).FnNear))
			if zRet == uintptr(0) {
				return uintptr(0)
			}
		}

	} else {
		var zOp uintptr = uintptr(0)
		var i int32

		switch (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FeType {
		case FTS5_AND:
			zOp = ts + 25874
			break
			fallthrough
		case FTS5_NOT:
			zOp = ts + 41864
			break
			fallthrough
		default:
			zOp = ts + 39530
			break
		}

		for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pExpr)).FnChild; i++ {
			var z uintptr = fts5ExprPrint(tls, pConfig, *(*uintptr)(unsafe.Pointer(pExpr + 48 + uintptr(i)*8)))
			if z == uintptr(0) {
				Xsqlite3_free(tls, zRet)
				zRet = uintptr(0)
			} else {
				var e int32 = (*Fts5ExprNode)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pExpr + 48 + uintptr(i)*8)))).FeType
				var b int32 = libc.Bool32(e != FTS5_STRING && e != FTS5_TERM && e != FTS5_EOF)
				zRet = fts5PrintfAppend(tls, zRet, ts+41870,
					libc.VaList(bp+48, func() uintptr {
						if i == 0 {
							return ts + 1636
						}
						return zOp
					}(),
						func() uintptr {
							if b != 0 {
								return ts + 25880
							}
							return ts + 1636
						}(), z, func() uintptr {
							if b != 0 {
								return ts + 7885
							}
							return ts + 1636
						}()))
			}
			if zRet == uintptr(0) {
				break
			}
		}
	}

	return zRet
}

func fts5ExprFunction(tls *libc.TLS, pCtx uintptr, nArg int32, apVal uintptr, bTcl int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pGlobal uintptr = Xsqlite3_user_data(tls, pCtx)
	var db uintptr = Xsqlite3_context_db_handle(tls, pCtx)
	var zExpr uintptr = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
	var rc int32
	var i int32
	var azConfig uintptr
	var zNearsetCmd uintptr = ts + 41879
	var nConfig int32
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	var iArg int32 = 1

	if nArg < 1 {
		*(*uintptr)(unsafe.Pointer(bp + 16)) = Xsqlite3_mprintf(tls, ts+41887,
			libc.VaList(bp, func() uintptr {
				if bTcl != 0 {
					return ts + 41928
				}
				return ts + 41942
			}()))
		Xsqlite3_result_error(tls, pCtx, *(*uintptr)(unsafe.Pointer(bp + 16)), -1)
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
		return
	}

	if bTcl != 0 && nArg > 1 {
		zNearsetCmd = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
		iArg = 2
	}

	nConfig = 3 + (nArg - iArg)
	azConfig = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(uintptr(0)))*uint64(nConfig))
	if azConfig == uintptr(0) {
		Xsqlite3_result_error_nomem(tls, pCtx)
		return
	}
	*(*uintptr)(unsafe.Pointer(azConfig)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(azConfig + 1*8)) = ts + 9656
	*(*uintptr)(unsafe.Pointer(azConfig + 2*8)) = ts + 14907
	for i = 3; iArg < nArg; iArg++ {
		var z uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(iArg)*8)))
		*(*uintptr)(unsafe.Pointer(azConfig + uintptr(libc.PostIncInt32(&i, 1))*8)) = func() uintptr {
			if z != 0 {
				return z
			}
			return ts + 1636
		}()
	}

	zExpr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal)))
	if zExpr == uintptr(0) {
		zExpr = ts + 1636
	}

	rc = sqlite3Fts5ConfigParse(tls, pGlobal, db, nConfig, azConfig, bp+8, bp+16)
	if rc == SQLITE_OK {
		rc = sqlite3Fts5ExprNew(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), 0, (*Fts5Config)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FnCol, zExpr, bp+24, bp+16)
	}
	if rc == SQLITE_OK {
		var zText uintptr
		if (*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).FpRoot)).FxNext == uintptr(0) {
			zText = Xsqlite3_mprintf(tls, ts+1636, 0)
		} else if bTcl != 0 {
			zText = fts5ExprPrintTcl(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), zNearsetCmd, (*Fts5Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).FpRoot)
		} else {
			zText = fts5ExprPrint(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), (*Fts5Expr)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).FpRoot)
		}
		if zText == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			Xsqlite3_result_text(tls, pCtx, zText, -1, libc.UintptrFromInt32(-1))
			Xsqlite3_free(tls, zText)
		}
	}

	if rc != SQLITE_OK {
		if *(*uintptr)(unsafe.Pointer(bp + 16)) != 0 {
			Xsqlite3_result_error(tls, pCtx, *(*uintptr)(unsafe.Pointer(bp + 16)), -1)
			Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
		} else {
			Xsqlite3_result_error_code(tls, pCtx, rc)
		}
	}
	Xsqlite3_free(tls, azConfig)
	sqlite3Fts5ConfigFree(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	sqlite3Fts5ExprFree(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
}

func fts5ExprFunctionHr(tls *libc.TLS, pCtx uintptr, nArg int32, apVal uintptr) {
	fts5ExprFunction(tls, pCtx, nArg, apVal, 0)
}

func fts5ExprFunctionTcl(tls *libc.TLS, pCtx uintptr, nArg int32, apVal uintptr) {
	fts5ExprFunction(tls, pCtx, nArg, apVal, 1)
}

func fts5ExprIsAlnum(tls *libc.TLS, pCtx uintptr, nArg int32, apVal uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var iCode int32

	if nArg != 1 {
		Xsqlite3_result_error(tls, pCtx,
			ts+41952, -1)
		return
	}
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([32]U8{})))
	sqlite3Fts5UnicodeCatParse(tls, ts+42003, bp)
	sqlite3Fts5UnicodeCatParse(tls, ts+42006, bp)
	sqlite3Fts5UnicodeCatParse(tls, ts+42009, bp)
	iCode = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal)))
	Xsqlite3_result_int(tls, pCtx, int32(*(*U8)(unsafe.Pointer(bp + uintptr(sqlite3Fts5UnicodeCategory(tls, U32(iCode)))))))
}

func fts5ExprFold(tls *libc.TLS, pCtx uintptr, nArg int32, apVal uintptr) {
	if nArg != 1 && nArg != 2 {
		Xsqlite3_result_error(tls, pCtx,
			ts+42012, -1)
	} else {
		var iCode int32
		var bRemoveDiacritics int32 = 0
		iCode = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal)))
		if nArg == 2 {
			bRemoveDiacritics = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
		}
		Xsqlite3_result_int(tls, pCtx, sqlite3Fts5UnicodeFold(tls, iCode, bRemoveDiacritics))
	}
}

func sqlite3Fts5ExprInit(tls *libc.TLS, pGlobal uintptr, db uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	*(*[4]Fts5ExprFunc)(unsafe.Pointer(bp)) = [4]Fts5ExprFunc{
		{Fz: ts + 41942, Fx: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{fts5ExprFunctionHr}))},
		{Fz: ts + 41928, Fx: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{fts5ExprFunctionTcl}))},
		{Fz: ts + 42060, Fx: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{fts5ExprIsAlnum}))},
		{Fz: ts + 42073, Fx: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{fts5ExprFold}))},
	}
	var i int32
	var rc int32 = SQLITE_OK
	var pCtx uintptr = pGlobal

	for i = 0; rc == SQLITE_OK && i < int32(uint64(unsafe.Sizeof([4]Fts5ExprFunc{}))/uint64(unsafe.Sizeof(Fts5ExprFunc{}))); i++ {
		var p uintptr = bp + uintptr(i)*16
		rc = Xsqlite3_create_function(tls, db, (*Fts5ExprFunc)(unsafe.Pointer(p)).Fz, -1, SQLITE_UTF8, pCtx, (*Fts5ExprFunc)(unsafe.Pointer(p)).Fx, uintptr(0), uintptr(0))
	}

	_ = *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, int32) int32 }{sqlite3Fts5ParserFallback}))

	return rc
}

type Fts5ExprFunc = struct {
	Fz uintptr
	Fx uintptr
}

func sqlite3Fts5ExprPhraseCount(tls *libc.TLS, pExpr uintptr) int32 {
	return func() int32 {
		if pExpr != 0 {
			return (*Fts5Expr)(unsafe.Pointer(pExpr)).FnPhrase
		}
		return 0
	}()
}

func sqlite3Fts5ExprPhraseSize(tls *libc.TLS, pExpr uintptr, iPhrase int32) int32 {
	if iPhrase < 0 || iPhrase >= (*Fts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
		return 0
	}
	return (*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*8)))).FnTerm
}

func sqlite3Fts5ExprPoslist(tls *libc.TLS, pExpr uintptr, iPhrase int32, pa uintptr) int32 {
	var nRet int32
	var pPhrase uintptr = *(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*8))
	var pNode uintptr = (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FpNode
	if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 && (*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid == (*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid {
		*(*uintptr)(unsafe.Pointer(pa)) = (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fp
		nRet = (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn
	} else {
		*(*uintptr)(unsafe.Pointer(pa)) = uintptr(0)
		nRet = 0
	}
	return nRet
}

func sqlite3Fts5ExprClearPoslists(tls *libc.TLS, pExpr uintptr, bLive int32) uintptr {
	var pRet uintptr
	pRet = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Fts5PoslistPopulator{}))*uint64((*Fts5Expr)(unsafe.Pointer(pExpr)).FnPhrase))
	if pRet != 0 {
		var i int32
		libc.Xmemset(tls, pRet, 0, uint64(unsafe.Sizeof(Fts5PoslistPopulator{}))*uint64((*Fts5Expr)(unsafe.Pointer(pExpr)).FnPhrase))
		for i = 0; i < (*Fts5Expr)(unsafe.Pointer(pExpr)).FnPhrase; i++ {
			var pBuf uintptr = *(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*8)) + 8
			var pNode uintptr = (*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*8)))).FpNode

			if bLive != 0 && ((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn == 0 || (*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid != (*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid || (*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof != 0) {
				(*Fts5PoslistPopulator)(unsafe.Pointer(pRet + uintptr(i)*16)).FbMiss = 1
			} else {
				(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn = 0
			}
		}
	}
	return pRet
}

type Fts5ExprCtx1 = struct {
	FpExpr      uintptr
	FaPopulator uintptr
	FiOff       I64
}

type Fts5ExprCtx = Fts5ExprCtx1

func fts5ExprColsetTest(tls *libc.TLS, pColset uintptr, iCol int32) int32 {
	var i int32
	for i = 0; i < (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol; i++ {
		if *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) == iCol {
			return 1
		}
	}
	return 0
}

func fts5ExprPopulatePoslistsCb(tls *libc.TLS, pCtx uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) int32 {
	var p uintptr = pCtx
	var pExpr uintptr = (*Fts5ExprCtx)(unsafe.Pointer(p)).FpExpr
	var i int32

	_ = iUnused1
	_ = iUnused2

	if nToken > FTS5_MAX_TOKEN_SIZE {
		nToken = FTS5_MAX_TOKEN_SIZE
	}
	if tflags&FTS5_TOKEN_COLOCATED == 0 {
		(*Fts5ExprCtx)(unsafe.Pointer(p)).FiOff++
	}
	for i = 0; i < (*Fts5Expr)(unsafe.Pointer(pExpr)).FnPhrase; i++ {
		var pTerm uintptr
		if (*Fts5PoslistPopulator)(unsafe.Pointer((*Fts5ExprCtx)(unsafe.Pointer(p)).FaPopulator+uintptr(i)*16)).FbOk == 0 {
			continue
		}
		for pTerm = *(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*8)) + 32; pTerm != 0; pTerm = (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym {
			var nTerm int32 = int32(libc.Xstrlen(tls, (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FzTerm))
			if (nTerm == nToken || nTerm < nToken && (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FbPrefix != 0) &&
				libc.Xmemcmp(tls, (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FzTerm, pToken, uint64(nTerm)) == 0 {
				var rc int32 = sqlite3Fts5PoslistWriterAppend(tls,
					*(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*8))+8, (*Fts5ExprCtx)(unsafe.Pointer(p)).FaPopulator+uintptr(i)*16, (*Fts5ExprCtx)(unsafe.Pointer(p)).FiOff)
				if rc != 0 {
					return rc
				}
				break
			}
		}
	}
	return SQLITE_OK
}

func sqlite3Fts5ExprPopulatePoslists(tls *libc.TLS, pConfig uintptr, pExpr uintptr, aPopulator uintptr, iCol int32, z uintptr, n int32) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var i int32

	(*Fts5ExprCtx)(unsafe.Pointer(bp)).FpExpr = pExpr
	(*Fts5ExprCtx)(unsafe.Pointer(bp)).FaPopulator = aPopulator
	(*Fts5ExprCtx)(unsafe.Pointer(bp)).FiOff = I64(iCol)<<32 - int64(1)

	for i = 0; i < (*Fts5Expr)(unsafe.Pointer(pExpr)).FnPhrase; i++ {
		var pNode uintptr = (*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*8)))).FpNode
		var pColset uintptr = (*Fts5ExprNearset)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear)).FpColset
		if pColset != 0 && 0 == fts5ExprColsetTest(tls, pColset, iCol) ||
			(*Fts5PoslistPopulator)(unsafe.Pointer(aPopulator+uintptr(i)*16)).FbMiss != 0 {
			(*Fts5PoslistPopulator)(unsafe.Pointer(aPopulator + uintptr(i)*16)).FbOk = 0
		} else {
			(*Fts5PoslistPopulator)(unsafe.Pointer(aPopulator + uintptr(i)*16)).FbOk = 1
		}
	}

	return sqlite3Fts5Tokenize(tls, pConfig,
		FTS5_TOKENIZE_DOCUMENT, z, n, bp, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
		}{fts5ExprPopulatePoslistsCb})))
}

func fts5ExprClearPoslists(tls *libc.TLS, pNode uintptr) {
	if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType == FTS5_TERM || (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType == FTS5_STRING {
		(*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 24)))).Fposlist.Fn = 0
	} else {
		var i int32
		for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild; i++ {
			fts5ExprClearPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8)))
		}
	}
}

func fts5ExprCheckPoslists(tls *libc.TLS, pNode uintptr, iRowid I64) int32 {
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = iRowid
	(*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof = 0
	switch (*Fts5ExprNode)(unsafe.Pointer(pNode)).FeType {
	case FTS5_TERM:
		fallthrough
	case FTS5_STRING:
		return libc.Bool32((*Fts5ExprPhrase)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*Fts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 24)))).Fposlist.Fn > 0)

	case FTS5_AND:
		{
			var i int32
			for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild; i++ {
				if fts5ExprCheckPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8)), iRowid) == 0 {
					fts5ExprClearPoslists(tls, pNode)
					return 0
				}
			}
			break

		}

	case FTS5_OR:
		{
			var i int32
			var bRet int32 = 0
			for i = 0; i < (*Fts5ExprNode)(unsafe.Pointer(pNode)).FnChild; i++ {
				if fts5ExprCheckPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 48 + uintptr(i)*8)), iRowid) != 0 {
					bRet = 1
				}
			}
			return bRet

		}

	default:
		{
			if 0 == fts5ExprCheckPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 48)), iRowid) ||
				0 != fts5ExprCheckPoslists(tls, *(*uintptr)(unsafe.Pointer(pNode + 48 + 1*8)), iRowid) {
				fts5ExprClearPoslists(tls, pNode)
				return 0
			}
			break

		}
	}
	return 1
}

func sqlite3Fts5ExprCheckPoslists(tls *libc.TLS, pExpr uintptr, iRowid I64) {
	fts5ExprCheckPoslists(tls, (*Fts5Expr)(unsafe.Pointer(pExpr)).FpRoot, iRowid)
}

func sqlite3Fts5ExprPhraseCollist(tls *libc.TLS, pExpr uintptr, iPhrase int32, ppCollist uintptr, pnCollist uintptr) int32 {
	var pPhrase uintptr = *(*uintptr)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*8))
	var pNode uintptr = (*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).FpNode
	var rc int32 = SQLITE_OK

	if (*Fts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 &&
		(*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid == (*Fts5ExprNode)(unsafe.Pointer((*Fts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid &&
		(*Fts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn > 0 {
		var pTerm uintptr = pPhrase + 32
		if (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
			var pBuf uintptr = (*Fts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym + 1*32
			rc = fts5ExprSynonymList(tls,
				pTerm, (*Fts5ExprNode)(unsafe.Pointer(pNode)).FiRowid, pBuf, ppCollist, pnCollist)
		} else {
			*(*uintptr)(unsafe.Pointer(ppCollist)) = (*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32)).FpIter)).FpData
			*(*int32)(unsafe.Pointer(pnCollist)) = (*Fts5IndexIter)(unsafe.Pointer((*Fts5ExprTerm)(unsafe.Pointer(pPhrase + 32)).FpIter)).FnData
		}
	} else {
		*(*uintptr)(unsafe.Pointer(ppCollist)) = uintptr(0)
		*(*int32)(unsafe.Pointer(pnCollist)) = 0
	}

	return rc
}

type Fts5HashEntry1 = struct {
	FpHashNext  uintptr
	FpScanNext  uintptr
	FnAlloc     int32
	FiSzPoslist int32
	FnData      int32
	FnKey       int32
	FbDel       U8
	FbContent   U8
	FiCol       I16
	FiPos       int32
	FiRowid     I64
}

type Fts5HashEntry = Fts5HashEntry1

func sqlite3Fts5HashNew(tls *libc.TLS, pConfig uintptr, ppNew uintptr, pnByte uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pNew uintptr

	*(*uintptr)(unsafe.Pointer(ppNew)) = libc.AssignUintptr(&pNew, Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Fts5Hash{}))))
	if pNew == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		var nByte Sqlite3_int64
		libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Fts5Hash{})))
		(*Fts5Hash)(unsafe.Pointer(pNew)).FpnByte = pnByte
		(*Fts5Hash)(unsafe.Pointer(pNew)).FeDetail = (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail

		(*Fts5Hash)(unsafe.Pointer(pNew)).FnSlot = 1024
		nByte = Sqlite3_int64(uint64(unsafe.Sizeof(uintptr(0))) * uint64((*Fts5Hash)(unsafe.Pointer(pNew)).FnSlot))
		(*Fts5Hash)(unsafe.Pointer(pNew)).FaSlot = Xsqlite3_malloc64(tls, uint64(nByte))
		if (*Fts5Hash)(unsafe.Pointer(pNew)).FaSlot == uintptr(0) {
			Xsqlite3_free(tls, pNew)
			*(*uintptr)(unsafe.Pointer(ppNew)) = uintptr(0)
			rc = SQLITE_NOMEM
		} else {
			libc.Xmemset(tls, (*Fts5Hash)(unsafe.Pointer(pNew)).FaSlot, 0, Size_t(nByte))
		}
	}
	return rc
}

func sqlite3Fts5HashFree(tls *libc.TLS, pHash uintptr) {
	if pHash != 0 {
		sqlite3Fts5HashClear(tls, pHash)
		Xsqlite3_free(tls, (*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot)
		Xsqlite3_free(tls, pHash)
	}
}

func sqlite3Fts5HashClear(tls *libc.TLS, pHash uintptr) {
	var i int32
	for i = 0; i < (*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot; i++ {
		var pNext uintptr
		var pSlot uintptr
		for pSlot = *(*uintptr)(unsafe.Pointer((*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(i)*8)); pSlot != 0; pSlot = pNext {
			pNext = (*Fts5HashEntry)(unsafe.Pointer(pSlot)).FpHashNext
			Xsqlite3_free(tls, pSlot)
		}
	}
	libc.Xmemset(tls, (*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot, 0, uint64((*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot)*uint64(unsafe.Sizeof(uintptr(0))))
	(*Fts5Hash)(unsafe.Pointer(pHash)).FnEntry = 0
}

func fts5HashKey(tls *libc.TLS, nSlot int32, p uintptr, n int32) uint32 {
	var i int32
	var h uint32 = uint32(13)
	for i = n - 1; i >= 0; i-- {
		h = h<<3 ^ h ^ uint32(*(*U8)(unsafe.Pointer(p + uintptr(i))))
	}
	return h % uint32(nSlot)
}

func fts5HashKey2(tls *libc.TLS, nSlot int32, b U8, p uintptr, n int32) uint32 {
	var i int32
	var h uint32 = uint32(13)
	for i = n - 1; i >= 0; i-- {
		h = h<<3 ^ h ^ uint32(*(*U8)(unsafe.Pointer(p + uintptr(i))))
	}
	h = h<<3 ^ h ^ uint32(b)
	return h % uint32(nSlot)
}

func fts5HashResize(tls *libc.TLS, pHash uintptr) int32 {
	var nNew int32 = (*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot * 2
	var i int32
	var apNew uintptr
	var apOld uintptr = (*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot

	apNew = Xsqlite3_malloc64(tls, uint64(nNew)*uint64(unsafe.Sizeof(uintptr(0))))
	if !(apNew != 0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, apNew, 0, uint64(nNew)*uint64(unsafe.Sizeof(uintptr(0))))

	for i = 0; i < (*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot; i++ {
		for *(*uintptr)(unsafe.Pointer(apOld + uintptr(i)*8)) != 0 {
			var iHash uint32
			var p uintptr = *(*uintptr)(unsafe.Pointer(apOld + uintptr(i)*8))
			*(*uintptr)(unsafe.Pointer(apOld + uintptr(i)*8)) = (*Fts5HashEntry)(unsafe.Pointer(p)).FpHashNext
			iHash = fts5HashKey(tls, nNew, p+1*48,
				int32(libc.Xstrlen(tls, p+1*48)))
			(*Fts5HashEntry)(unsafe.Pointer(p)).FpHashNext = *(*uintptr)(unsafe.Pointer(apNew + uintptr(iHash)*8))
			*(*uintptr)(unsafe.Pointer(apNew + uintptr(iHash)*8)) = p
		}
	}

	Xsqlite3_free(tls, apOld)
	(*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot = nNew
	(*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot = apNew
	return SQLITE_OK
}

func fts5HashAddPoslistSize(tls *libc.TLS, pHash uintptr, p uintptr, p2 uintptr) int32 {
	var nRet int32 = 0
	if (*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist != 0 {
		var pPtr uintptr
		if p2 != 0 {
			pPtr = p2
		} else {
			pPtr = p
		}
		var nData int32 = (*Fts5HashEntry)(unsafe.Pointer(p)).FnData
		if (*Fts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_NONE {
			if (*Fts5HashEntry)(unsafe.Pointer(p)).FbDel != 0 {
				*(*U8)(unsafe.Pointer(pPtr + uintptr(libc.PostIncInt32(&nData, 1)))) = U8(0x00)
				if (*Fts5HashEntry)(unsafe.Pointer(p)).FbContent != 0 {
					*(*U8)(unsafe.Pointer(pPtr + uintptr(libc.PostIncInt32(&nData, 1)))) = U8(0x00)
				}
			}
		} else {
			var nSz int32 = nData - (*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist - 1
			var nPos int32 = nSz*2 + int32((*Fts5HashEntry)(unsafe.Pointer(p)).FbDel)

			if nPos <= 127 {
				*(*U8)(unsafe.Pointer(pPtr + uintptr((*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist))) = U8(nPos)
			} else {
				var nByte int32 = sqlite3Fts5GetVarintLen(tls, U32(nPos))
				libc.Xmemmove(tls, pPtr+uintptr((*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist+nByte), pPtr+uintptr((*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist+1), uint64(nSz))
				sqlite3Fts5PutVarint(tls, pPtr+uintptr((*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist), uint64(nPos))
				nData = nData + (nByte - 1)
			}
		}

		nRet = nData - (*Fts5HashEntry)(unsafe.Pointer(p)).FnData
		if p2 == uintptr(0) {
			(*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = 0
			(*Fts5HashEntry)(unsafe.Pointer(p)).FbDel = U8(0)
			(*Fts5HashEntry)(unsafe.Pointer(p)).FbContent = U8(0)
			(*Fts5HashEntry)(unsafe.Pointer(p)).FnData = nData
		}
	}
	return nRet
}

func sqlite3Fts5HashWrite(tls *libc.TLS, pHash uintptr, iRowid I64, iCol int32, iPos int32, bByte uint8, pToken uintptr, nToken int32) int32 {
	var iHash uint32
	var p uintptr
	var pPtr uintptr
	var nIncr int32 = 0
	var bNew int32

	bNew = libc.Bool32((*Fts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL)

	iHash = fts5HashKey2(tls, (*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot, bByte, pToken, nToken)
	for p = *(*uintptr)(unsafe.Pointer((*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8)); p != 0; p = (*Fts5HashEntry)(unsafe.Pointer(p)).FpHashNext {
		var zKey uintptr = p + 1*48
		if int32(*(*uint8)(unsafe.Pointer(zKey))) == int32(bByte) &&
			(*Fts5HashEntry)(unsafe.Pointer(p)).FnKey == nToken &&
			libc.Xmemcmp(tls, zKey+1, pToken, uint64(nToken)) == 0 {
			break
		}
	}

	if p == uintptr(0) {
		var zKey uintptr
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5HashEntry{})) + uint64(nToken+1) + uint64(1) + uint64(64))
		if nByte < int64(128) {
			nByte = int64(128)
		}

		if (*Fts5Hash)(unsafe.Pointer(pHash)).FnEntry*2 >= (*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot {
			var rc int32 = fts5HashResize(tls, pHash)
			if rc != SQLITE_OK {
				return rc
			}
			iHash = fts5HashKey2(tls, (*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot, bByte, pToken, nToken)
		}

		p = Xsqlite3_malloc64(tls, uint64(nByte))
		if !(p != 0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(Fts5HashEntry{})))
		(*Fts5HashEntry)(unsafe.Pointer(p)).FnAlloc = int32(nByte)
		zKey = p + 1*48
		*(*uint8)(unsafe.Pointer(zKey)) = bByte
		libc.Xmemcpy(tls, zKey+1, pToken, uint64(nToken))

		(*Fts5HashEntry)(unsafe.Pointer(p)).FnKey = nToken
		*(*uint8)(unsafe.Pointer(zKey + uintptr(nToken+1))) = uint8(0)
		(*Fts5HashEntry)(unsafe.Pointer(p)).FnData = int32(uint64(nToken+1+1) + uint64(unsafe.Sizeof(Fts5HashEntry{})))
		(*Fts5HashEntry)(unsafe.Pointer(p)).FpHashNext = *(*uintptr)(unsafe.Pointer((*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8))
		*(*uintptr)(unsafe.Pointer((*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8)) = p
		(*Fts5Hash)(unsafe.Pointer(pHash)).FnEntry++

		*(*int32)(unsafe.Pointer(p + 24)) += sqlite3Fts5PutVarint(tls, p+uintptr((*Fts5HashEntry)(unsafe.Pointer(p)).FnData), uint64(iRowid))
		(*Fts5HashEntry)(unsafe.Pointer(p)).FiRowid = iRowid

		(*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = (*Fts5HashEntry)(unsafe.Pointer(p)).FnData
		if (*Fts5Hash)(unsafe.Pointer(pHash)).FeDetail != FTS5_DETAIL_NONE {
			*(*int32)(unsafe.Pointer(p + 24)) += 1
			(*Fts5HashEntry)(unsafe.Pointer(p)).FiCol = func() int16 {
				if (*Fts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
					return int16(0)
				}
				return int16(-1)
			}()
		}

	} else {
		if (*Fts5HashEntry)(unsafe.Pointer(p)).FnAlloc-(*Fts5HashEntry)(unsafe.Pointer(p)).FnData < 9+4+1+3+5 {
			var nNew Sqlite3_int64 = Sqlite3_int64((*Fts5HashEntry)(unsafe.Pointer(p)).FnAlloc * 2)
			var pNew uintptr
			var pp uintptr
			pNew = Xsqlite3_realloc64(tls, p, uint64(nNew))
			if pNew == uintptr(0) {
				return SQLITE_NOMEM
			}
			(*Fts5HashEntry)(unsafe.Pointer(pNew)).FnAlloc = int32(nNew)
			for pp = (*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8; *(*uintptr)(unsafe.Pointer(pp)) != p; pp = *(*uintptr)(unsafe.Pointer(pp)) {
			}
			*(*uintptr)(unsafe.Pointer(pp)) = pNew
			p = pNew
		}
		nIncr = nIncr - (*Fts5HashEntry)(unsafe.Pointer(p)).FnData
	}

	pPtr = p

	if iRowid != (*Fts5HashEntry)(unsafe.Pointer(p)).FiRowid {
		var iDiff U64 = U64(iRowid) - U64((*Fts5HashEntry)(unsafe.Pointer(p)).FiRowid)
		fts5HashAddPoslistSize(tls, pHash, p, uintptr(0))
		*(*int32)(unsafe.Pointer(p + 24)) += sqlite3Fts5PutVarint(tls, pPtr+uintptr((*Fts5HashEntry)(unsafe.Pointer(p)).FnData), iDiff)
		(*Fts5HashEntry)(unsafe.Pointer(p)).FiRowid = iRowid
		bNew = 1
		(*Fts5HashEntry)(unsafe.Pointer(p)).FiSzPoslist = (*Fts5HashEntry)(unsafe.Pointer(p)).FnData
		if (*Fts5Hash)(unsafe.Pointer(pHash)).FeDetail != FTS5_DETAIL_NONE {
			*(*int32)(unsafe.Pointer(p + 24)) += 1
			(*Fts5HashEntry)(unsafe.Pointer(p)).FiCol = func() int16 {
				if (*Fts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
					return int16(0)
				}
				return int16(-1)
			}()
			(*Fts5HashEntry)(unsafe.Pointer(p)).FiPos = 0
		}
	}

	if iCol >= 0 {
		if (*Fts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_NONE {
			(*Fts5HashEntry)(unsafe.Pointer(p)).FbContent = U8(1)
		} else {
			if iCol != int32((*Fts5HashEntry)(unsafe.Pointer(p)).FiCol) {
				if (*Fts5Hash)(unsafe.Pointer(pHash)).FeDetail == FTS5_DETAIL_FULL {
					*(*U8)(unsafe.Pointer(pPtr + uintptr(libc.PostIncInt32(&(*Fts5HashEntry)(unsafe.Pointer(p)).FnData, 1)))) = U8(0x01)
					*(*int32)(unsafe.Pointer(p + 24)) += sqlite3Fts5PutVarint(tls, pPtr+uintptr((*Fts5HashEntry)(unsafe.Pointer(p)).FnData), uint64(iCol))
					(*Fts5HashEntry)(unsafe.Pointer(p)).FiCol = I16(iCol)
					(*Fts5HashEntry)(unsafe.Pointer(p)).FiPos = 0
				} else {
					bNew = 1
					(*Fts5HashEntry)(unsafe.Pointer(p)).FiCol = I16(libc.AssignInt32(&iPos, iCol))
				}
			}

			if bNew != 0 {
				*(*int32)(unsafe.Pointer(p + 24)) += sqlite3Fts5PutVarint(tls, pPtr+uintptr((*Fts5HashEntry)(unsafe.Pointer(p)).FnData), uint64(iPos-(*Fts5HashEntry)(unsafe.Pointer(p)).FiPos+2))
				(*Fts5HashEntry)(unsafe.Pointer(p)).FiPos = iPos
			}
		}
	} else {
		(*Fts5HashEntry)(unsafe.Pointer(p)).FbDel = U8(1)
	}

	nIncr = nIncr + (*Fts5HashEntry)(unsafe.Pointer(p)).FnData
	*(*int32)(unsafe.Pointer((*Fts5Hash)(unsafe.Pointer(pHash)).FpnByte)) += nIncr
	return SQLITE_OK
}

func fts5HashEntryMerge(tls *libc.TLS, pLeft uintptr, pRight uintptr) uintptr {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var p1 uintptr = pLeft
	var p2 uintptr = pRight
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var ppOut uintptr = 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 {
			var i int32 = 0
			var zKey1 uintptr = p1 + 1*48
			var zKey2 uintptr = p2 + 1*48
			for int32(*(*uint8)(unsafe.Pointer(zKey1 + uintptr(i)))) == int32(*(*uint8)(unsafe.Pointer(zKey2 + uintptr(i)))) {
				i++
			}

			if int32(*(*uint8)(unsafe.Pointer(zKey1 + uintptr(i)))) > int32(*(*uint8)(unsafe.Pointer(zKey2 + uintptr(i)))) {
				*(*uintptr)(unsafe.Pointer(ppOut)) = p2
				ppOut = p2 + 8
				p2 = (*Fts5HashEntry)(unsafe.Pointer(p2)).FpScanNext
			} else {
				*(*uintptr)(unsafe.Pointer(ppOut)) = p1
				ppOut = p1 + 8
				p1 = (*Fts5HashEntry)(unsafe.Pointer(p1)).FpScanNext
			}
			*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
		}
	}

	return *(*uintptr)(unsafe.Pointer(bp))
}

func fts5HashEntrySort(tls *libc.TLS, pHash uintptr, pTerm uintptr, nTerm int32, ppSorted uintptr) int32 {
	var nMergeSlot int32 = 32
	var ap uintptr
	var pList uintptr
	var iSlot int32
	var i int32

	*(*uintptr)(unsafe.Pointer(ppSorted)) = uintptr(0)
	ap = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(uintptr(0)))*uint64(nMergeSlot))
	if !(ap != 0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, ap, 0, uint64(unsafe.Sizeof(uintptr(0)))*uint64(nMergeSlot))

	for iSlot = 0; iSlot < (*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot; iSlot++ {
		var pIter uintptr
		for pIter = *(*uintptr)(unsafe.Pointer((*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iSlot)*8)); pIter != 0; pIter = (*Fts5HashEntry)(unsafe.Pointer(pIter)).FpHashNext {
			if pTerm == uintptr(0) ||
				(*Fts5HashEntry)(unsafe.Pointer(pIter)).FnKey+1 >= nTerm && 0 == libc.Xmemcmp(tls, pIter+1*48, pTerm, uint64(nTerm)) {
				var pEntry uintptr = pIter
				(*Fts5HashEntry)(unsafe.Pointer(pEntry)).FpScanNext = uintptr(0)
				for i = 0; *(*uintptr)(unsafe.Pointer(ap + uintptr(i)*8)) != 0; i++ {
					pEntry = fts5HashEntryMerge(tls, pEntry, *(*uintptr)(unsafe.Pointer(ap + uintptr(i)*8)))
					*(*uintptr)(unsafe.Pointer(ap + uintptr(i)*8)) = uintptr(0)
				}
				*(*uintptr)(unsafe.Pointer(ap + uintptr(i)*8)) = pEntry
			}
		}
	}

	pList = uintptr(0)
	for i = 0; i < nMergeSlot; i++ {
		pList = fts5HashEntryMerge(tls, pList, *(*uintptr)(unsafe.Pointer(ap + uintptr(i)*8)))
	}

	(*Fts5Hash)(unsafe.Pointer(pHash)).FnEntry = 0
	Xsqlite3_free(tls, ap)
	*(*uintptr)(unsafe.Pointer(ppSorted)) = pList
	return SQLITE_OK
}

func sqlite3Fts5HashQuery(tls *libc.TLS, pHash uintptr, nPre int32, pTerm uintptr, nTerm int32, ppOut uintptr, pnDoclist uintptr) int32 {
	var iHash uint32 = fts5HashKey(tls, (*Fts5Hash)(unsafe.Pointer(pHash)).FnSlot, pTerm, nTerm)
	var zKey uintptr = uintptr(0)
	var p uintptr

	for p = *(*uintptr)(unsafe.Pointer((*Fts5Hash)(unsafe.Pointer(pHash)).FaSlot + uintptr(iHash)*8)); p != 0; p = (*Fts5HashEntry)(unsafe.Pointer(p)).FpHashNext {
		zKey = p + 1*48

		if nTerm == (*Fts5HashEntry)(unsafe.Pointer(p)).FnKey+1 && libc.Xmemcmp(tls, zKey, pTerm, uint64(nTerm)) == 0 {
			break
		}
	}

	if p != 0 {
		var nHashPre int32 = int32(uint64(unsafe.Sizeof(Fts5HashEntry{})) + uint64(nTerm) + uint64(1))
		var nList int32 = (*Fts5HashEntry)(unsafe.Pointer(p)).FnData - nHashPre
		var pRet uintptr = libc.AssignPtrUintptr(ppOut, Xsqlite3_malloc64(tls, uint64(nPre+nList+10)))
		if pRet != 0 {
			var pFaux uintptr = pRet + uintptr(nPre-nHashPre)
			libc.Xmemcpy(tls, pRet+uintptr(nPre), p+uintptr(nHashPre), uint64(nList))
			nList = nList + fts5HashAddPoslistSize(tls, pHash, p, pFaux)
			*(*int32)(unsafe.Pointer(pnDoclist)) = nList
		} else {
			*(*int32)(unsafe.Pointer(pnDoclist)) = 0
			return 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) int32 {
	return fts5HashEntrySort(tls, p, pTerm, nTerm, p+24)
}

func sqlite3Fts5HashScanNext(tls *libc.TLS, p uintptr) {
	(*Fts5Hash)(unsafe.Pointer(p)).FpScan = (*Fts5HashEntry)(unsafe.Pointer((*Fts5Hash)(unsafe.Pointer(p)).FpScan)).FpScanNext
}

func sqlite3Fts5HashScanEof(tls *libc.TLS, p uintptr) int32 {
	return libc.Bool32((*Fts5Hash)(unsafe.Pointer(p)).FpScan == uintptr(0))
}

func sqlite3Fts5HashScanEntry(tls *libc.TLS, pHash uintptr, pzTerm uintptr, ppDoclist uintptr, pnDoclist uintptr) {
	var p uintptr
	if libc.AssignUintptr(&p, (*Fts5Hash)(unsafe.Pointer(pHash)).FpScan) != 0 {
		var zKey uintptr = p + 1*48
		var nTerm int32 = int32(libc.Xstrlen(tls, zKey))
		fts5HashAddPoslistSize(tls, pHash, p, uintptr(0))
		*(*uintptr)(unsafe.Pointer(pzTerm)) = zKey
		*(*uintptr)(unsafe.Pointer(ppDoclist)) = zKey + uintptr(nTerm+1)
		*(*int32)(unsafe.Pointer(pnDoclist)) = int32(uint64((*Fts5HashEntry)(unsafe.Pointer(p)).FnData) - (uint64(unsafe.Sizeof(Fts5HashEntry{})) + uint64(nTerm) + uint64(1)))
	} else {
		*(*uintptr)(unsafe.Pointer(pzTerm)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(ppDoclist)) = uintptr(0)
		*(*int32)(unsafe.Pointer(pnDoclist)) = 0
	}
}

type Fts5Data1 = struct {
	Fp      uintptr
	Fnn     int32
	FszLeaf int32
}

type Fts5Data = Fts5Data1
type Fts5DlidxIter1 = struct {
	FnLvl   int32
	FiSegid int32
	FaLvl   [1]Fts5DlidxLvl
}

type Fts5DlidxIter = Fts5DlidxIter1
type Fts5DlidxLvl1 = struct {
	FpData     uintptr
	FiOff      int32
	FbEof      int32
	FiFirstOff int32
	FiLeafPgno int32
	FiRowid    I64
}

type Fts5DlidxLvl = Fts5DlidxLvl1
type Fts5DlidxWriter1 = struct {
	Fpgno       int32
	FbPrevValid int32
	FiPrev      I64
	Fbuf        Fts5Buffer
}

type Fts5DlidxWriter = Fts5DlidxWriter1
type Fts5Iter1 = struct {
	Fbase         Fts5IndexIter
	FpIndex       uintptr
	Fposlist      Fts5Buffer
	FpColset      uintptr
	FxSetOutputs  uintptr
	FnSeg         int32
	FbRev         int32
	FbSkipEmpty   U8
	F__ccgo_pad1  [7]byte
	FiSwitchRowid I64
	FaFirst       uintptr
	FaSeg         [1]Fts5SegIter
}

type Fts5Iter = Fts5Iter1
type Fts5PageWriter1 = struct {
	Fpgno       int32
	FiPrevPgidx int32
	Fbuf        Fts5Buffer
	Fpgidx      Fts5Buffer
	Fterm       Fts5Buffer
}

type Fts5PageWriter = Fts5PageWriter1
type Fts5SegIter1 = struct {
	FpSeg            uintptr
	Fflags           int32
	FiLeafPgno       int32
	FpLeaf           uintptr
	FpNextLeaf       uintptr
	FiLeafOffset     I64
	FxNext           uintptr
	FiTermLeafPgno   int32
	FiTermLeafOffset int32
	FiPgidxOff       int32
	FiEndofDoclist   int32
	FiRowidOffset    int32
	FnRowidOffset    int32
	FaRowidOffset    uintptr
	FpDlidx          uintptr
	Fterm            Fts5Buffer
	FiRowid          I64
	FnPos            int32
	FbDel            U8
	F__ccgo_pad1     [3]byte
}

type Fts5SegIter = Fts5SegIter1
type Fts5DoclistIter1 = struct {
	FaEof     uintptr
	FiRowid   I64
	FaPoslist uintptr
	FnPoslist int32
	FnSize    int32
}

type Fts5DoclistIter = Fts5DoclistIter1
type Fts5SegWriter1 = struct {
	FiSegid               int32
	F__ccgo_pad1          [4]byte
	Fwriter               Fts5PageWriter
	FiPrevRowid           I64
	FbFirstRowidInDoclist U8
	FbFirstRowidInPage    U8
	FbFirstTermInPage     U8
	F__ccgo_pad2          [1]byte
	FnLeafWritten         int32
	FnEmpty               int32
	FnDlidx               int32
	FaDlidx               uintptr
	Fbtterm               Fts5Buffer
	FiBtPage              int32
	F__ccgo_pad3          [4]byte
}

type Fts5SegWriter = Fts5SegWriter1
type Fts5Structure1 = struct {
	FnRef          int32
	F__ccgo_pad1   [4]byte
	FnWriteCounter U64
	FnSegment      int32
	FnLevel        int32
	FaLevel        [1]Fts5StructureLevel
}

type Fts5Structure = Fts5Structure1
type Fts5StructureLevel1 = struct {
	FnMerge int32
	FnSeg   int32
	FaSeg   uintptr
}

type Fts5StructureLevel = Fts5StructureLevel1
type Fts5StructureSegment1 = struct {
	FiSegid    int32
	FpgnoFirst int32
	FpgnoLast  int32
}

type Fts5StructureSegment = Fts5StructureSegment1

type Fts5CResult1 = struct {
	FiFirst      U16
	FbTermEq     U8
	F__ccgo_pad1 [1]byte
}

type Fts5CResult = Fts5CResult1

func fts5PutU16(tls *libc.TLS, aOut uintptr, iVal U16) {
	*(*U8)(unsafe.Pointer(aOut)) = U8(int32(iVal) >> 8)
	*(*U8)(unsafe.Pointer(aOut + 1)) = U8(int32(iVal) & 0xFF)
}

func fts5GetU16(tls *libc.TLS, aIn uintptr) U16 {
	return U16(int32(U16(*(*U8)(unsafe.Pointer(aIn))))<<8 + int32(*(*U8)(unsafe.Pointer(aIn + 1))))
}

func fts5IdxMalloc(tls *libc.TLS, p uintptr, nByte Sqlite3_int64) uintptr {
	return sqlite3Fts5MallocZero(tls, p+52, nByte)
}

func fts5BufferCompare(tls *libc.TLS, pLeft uintptr, pRight uintptr) int32 {
	var nCmp int32
	var res int32
	nCmp = func() int32 {
		if (*Fts5Buffer)(unsafe.Pointer(pLeft)).Fn < (*Fts5Buffer)(unsafe.Pointer(pRight)).Fn {
			return (*Fts5Buffer)(unsafe.Pointer(pLeft)).Fn
		}
		return (*Fts5Buffer)(unsafe.Pointer(pRight)).Fn
	}()

	res = func() int32 {
		if nCmp <= 0 {
			return 0
		}
		return libc.Xmemcmp(tls, (*Fts5Buffer)(unsafe.Pointer(pLeft)).Fp, (*Fts5Buffer)(unsafe.Pointer(pRight)).Fp, uint64(nCmp))
	}()
	return func() int32 {
		if res == 0 {
			return (*Fts5Buffer)(unsafe.Pointer(pLeft)).Fn - (*Fts5Buffer)(unsafe.Pointer(pRight)).Fn
		}
		return res
	}()
}

func fts5LeafFirstTermOff(tls *libc.TLS, pLeaf uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr((*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf), bp)
	return *(*int32)(unsafe.Pointer(bp))
}

func sqlite3Fts5IndexCloseReader(tls *libc.TLS, p uintptr) {
	if (*Fts5Index)(unsafe.Pointer(p)).FpReader != 0 {
		var pReader uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpReader
		(*Fts5Index)(unsafe.Pointer(p)).FpReader = uintptr(0)
		Xsqlite3_blob_close(tls, pReader)
	}
}

func fts5DataRead(tls *libc.TLS, p uintptr, iRowid I64) uintptr {
	var pRet uintptr = uintptr(0)
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var rc int32 = SQLITE_OK

		if (*Fts5Index)(unsafe.Pointer(p)).FpReader != 0 {
			var pBlob uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpReader
			(*Fts5Index)(unsafe.Pointer(p)).FpReader = uintptr(0)
			rc = Xsqlite3_blob_reopen(tls, pBlob, iRowid)

			(*Fts5Index)(unsafe.Pointer(p)).FpReader = pBlob
			if rc != SQLITE_OK {
				sqlite3Fts5IndexCloseReader(tls, p)
			}
			if rc == SQLITE_ABORT {
				rc = SQLITE_OK
			}
		}

		if (*Fts5Index)(unsafe.Pointer(p)).FpReader == uintptr(0) && rc == SQLITE_OK {
			var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig
			rc = Xsqlite3_blob_open(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb,
				(*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Index)(unsafe.Pointer(p)).FzDataTbl, ts+42083, iRowid, 0, p+56)
		}

		if rc == SQLITE_ERROR {
			rc = SQLITE_CORRUPT | int32(1)<<8
		}

		if rc == SQLITE_OK {
			var aOut uintptr = uintptr(0)
			var nByte int32 = Xsqlite3_blob_bytes(tls, (*Fts5Index)(unsafe.Pointer(p)).FpReader)
			var nAlloc Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Data{})) + uint64(nByte) + uint64(FTS5_DATA_PADDING))
			pRet = Xsqlite3_malloc64(tls, uint64(nAlloc))
			if pRet != 0 {
				(*Fts5Data)(unsafe.Pointer(pRet)).Fnn = nByte
				aOut = libc.AssignPtrUintptr(pRet, pRet+1*16)
			} else {
				rc = SQLITE_NOMEM
			}

			if rc == SQLITE_OK {
				rc = Xsqlite3_blob_read(tls, (*Fts5Index)(unsafe.Pointer(p)).FpReader, aOut, nByte, 0)
			}
			if rc != SQLITE_OK {
				Xsqlite3_free(tls, pRet)
				pRet = uintptr(0)
			} else {
				*(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer(pRet)).Fp + uintptr(nByte))) = U8(0x00)
				*(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer(pRet)).Fp + uintptr(nByte+1))) = U8(0x00)
				(*Fts5Data)(unsafe.Pointer(pRet)).FszLeaf = int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pRet)).Fp+2))
			}
		}
		(*Fts5Index)(unsafe.Pointer(p)).Frc = rc
		(*Fts5Index)(unsafe.Pointer(p)).FnRead++
	}

	return pRet
}

func fts5DataRelease(tls *libc.TLS, pData uintptr) {
	Xsqlite3_free(tls, pData)
}

func fts5LeafRead(tls *libc.TLS, p uintptr, iRowid I64) uintptr {
	var pRet uintptr = fts5DataRead(tls, p, iRowid)
	if pRet != 0 {
		if (*Fts5Data)(unsafe.Pointer(pRet)).Fnn < 4 || (*Fts5Data)(unsafe.Pointer(pRet)).FszLeaf > (*Fts5Data)(unsafe.Pointer(pRet)).Fnn {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			fts5DataRelease(tls, pRet)
			pRet = uintptr(0)
		}
	}
	return pRet
}

func fts5IndexPrepareStmt(tls *libc.TLS, p uintptr, ppStmt uintptr, zSql uintptr) int32 {
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if zSql != 0 {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_prepare_v3(tls, (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).Fdb, zSql, -1,
				uint32(SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB),
				ppStmt, uintptr(0))
		} else {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
		}
	}
	Xsqlite3_free(tls, zSql)
	return (*Fts5Index)(unsafe.Pointer(p)).Frc
}

func fts5DataWrite(tls *libc.TLS, p uintptr, iRowid I64, pData uintptr, nData int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}

	if (*Fts5Index)(unsafe.Pointer(p)).FpWriter == uintptr(0) {
		var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig
		fts5IndexPrepareStmt(tls, p, p+64, Xsqlite3_mprintf(tls,
			ts+42089,
			libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName)))
		if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
	}

	Xsqlite3_bind_int64(tls, (*Fts5Index)(unsafe.Pointer(p)).FpWriter, 1, iRowid)
	Xsqlite3_bind_blob(tls, (*Fts5Index)(unsafe.Pointer(p)).FpWriter, 2, pData, nData, uintptr(0))
	Xsqlite3_step(tls, (*Fts5Index)(unsafe.Pointer(p)).FpWriter)
	(*Fts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*Fts5Index)(unsafe.Pointer(p)).FpWriter)
	Xsqlite3_bind_null(tls, (*Fts5Index)(unsafe.Pointer(p)).FpWriter, 2)
}

func fts5DataDelete(tls *libc.TLS, p uintptr, iFirst I64, iLast I64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return
	}

	if (*Fts5Index)(unsafe.Pointer(p)).FpDeleter == uintptr(0) {
		var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig
		var zSql uintptr = Xsqlite3_mprintf(tls,
			ts+42140,
			libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
		if fts5IndexPrepareStmt(tls, p, p+72, zSql) != 0 {
			return
		}
	}

	Xsqlite3_bind_int64(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDeleter, 1, iFirst)
	Xsqlite3_bind_int64(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDeleter, 2, iLast)
	Xsqlite3_step(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDeleter)
	(*Fts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDeleter)
}

func fts5DataRemoveSegment(tls *libc.TLS, p uintptr, iSegid int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var iFirst I64 = I64(iSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + int64(0)
	var iLast I64 = I64(iSegid+1)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + int64(0) - int64(1)
	fts5DataDelete(tls, p, iFirst, iLast)
	if (*Fts5Index)(unsafe.Pointer(p)).FpIdxDeleter == uintptr(0) {
		var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig
		fts5IndexPrepareStmt(tls, p, p+88, Xsqlite3_mprintf(tls,
			ts+42189,
			libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		Xsqlite3_bind_int(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxDeleter, 1, iSegid)
		Xsqlite3_step(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxDeleter)
		(*Fts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxDeleter)
	}
}

func fts5StructureRelease(tls *libc.TLS, pStruct uintptr) {
	if pStruct != 0 && 0 >= libc.PreDecInt32(&(*Fts5Structure)(unsafe.Pointer(pStruct)).FnRef, 1) {
		var i int32

		for i = 0; i < (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel; i++ {
			Xsqlite3_free(tls, (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(i)*16)).FaSeg)
		}
		Xsqlite3_free(tls, pStruct)
	}
}

func fts5StructureRef(tls *libc.TLS, pStruct uintptr) {
	(*Fts5Structure)(unsafe.Pointer(pStruct)).FnRef++
}

func sqlite3Fts5StructureRef(tls *libc.TLS, p uintptr) uintptr {
	fts5StructureRef(tls, (*Fts5Index)(unsafe.Pointer(p)).FpStruct)
	return (*Fts5Index)(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) int32 {
	if (*Fts5Index)(unsafe.Pointer(p)).FpStruct != pStruct {
		return SQLITE_ABORT
	}
	return SQLITE_OK
}

func fts5StructureMakeWritable(tls *libc.TLS, pRc uintptr, pp uintptr) {
	var p uintptr = *(*uintptr)(unsafe.Pointer(pp))
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK && (*Fts5Structure)(unsafe.Pointer(p)).FnRef > 1 {
		var nByte I64 = I64(uint64(unsafe.Sizeof(Fts5Structure{})) + uint64((*Fts5Structure)(unsafe.Pointer(p)).FnLevel-1)*uint64(unsafe.Sizeof(Fts5StructureLevel{})))
		var pNew uintptr
		pNew = sqlite3Fts5MallocZero(tls, pRc, nByte)
		if pNew != 0 {
			var i int32
			libc.Xmemcpy(tls, pNew, p, uint64(nByte))
			for i = 0; i < (*Fts5Structure)(unsafe.Pointer(p)).FnLevel; i++ {
				(*Fts5StructureLevel)(unsafe.Pointer(pNew + 24 + uintptr(i)*16)).FaSeg = uintptr(0)
			}
			for i = 0; i < (*Fts5Structure)(unsafe.Pointer(p)).FnLevel; i++ {
				var pLvl uintptr = pNew + 24 + uintptr(i)*16
				nByte = I64(uint64(unsafe.Sizeof(Fts5StructureSegment{})) * uint64((*Fts5StructureLevel)(unsafe.Pointer(pNew+24+uintptr(i)*16)).FnSeg))
				(*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = sqlite3Fts5MallocZero(tls, pRc, nByte)
				if (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg == uintptr(0) {
					for i = 0; i < (*Fts5Structure)(unsafe.Pointer(p)).FnLevel; i++ {
						Xsqlite3_free(tls, (*Fts5StructureLevel)(unsafe.Pointer(pNew+24+uintptr(i)*16)).FaSeg)
					}
					Xsqlite3_free(tls, pNew)
					return
				}
				libc.Xmemcpy(tls, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg, (*Fts5StructureLevel)(unsafe.Pointer(p+24+uintptr(i)*16)).FaSeg, uint64(nByte))
			}
			(*Fts5Structure)(unsafe.Pointer(p)).FnRef--
			(*Fts5Structure)(unsafe.Pointer(pNew)).FnRef = 1
		}
		*(*uintptr)(unsafe.Pointer(pp)) = pNew
	}
}

func fts5StructureDecode(tls *libc.TLS, pData uintptr, nData int32, piCookie uintptr, ppOut uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_OK
	var i int32 = 0
	var iLvl int32
	*(*int32)(unsafe.Pointer(bp)) = 0
	*(*int32)(unsafe.Pointer(bp + 4)) = 0
	var nByte Sqlite3_int64
	var pRet uintptr = uintptr(0)

	if piCookie != 0 {
		*(*int32)(unsafe.Pointer(piCookie)) = sqlite3Fts5Get32(tls, pData)
	}
	i = 4

	i = i + sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp)
	i = i + sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+4)
	if *(*int32)(unsafe.Pointer(bp)) > FTS5_MAX_SEGMENT || *(*int32)(unsafe.Pointer(bp)) < 0 ||
		*(*int32)(unsafe.Pointer(bp + 4)) > FTS5_MAX_SEGMENT || *(*int32)(unsafe.Pointer(bp + 4)) < 0 {
		return SQLITE_CORRUPT | int32(1)<<8
	}
	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Structure{})) + uint64(unsafe.Sizeof(Fts5StructureLevel{}))*uint64(*(*int32)(unsafe.Pointer(bp))-1))
	pRet = sqlite3Fts5MallocZero(tls, bp+8, nByte)

	if pRet != 0 {
		(*Fts5Structure)(unsafe.Pointer(pRet)).FnRef = 1
		(*Fts5Structure)(unsafe.Pointer(pRet)).FnLevel = *(*int32)(unsafe.Pointer(bp))
		(*Fts5Structure)(unsafe.Pointer(pRet)).FnSegment = *(*int32)(unsafe.Pointer(bp + 4))
		i = i + int32(sqlite3Fts5GetVarint(tls, pData+uintptr(i), pRet+8))

		for iLvl = 0; *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK && iLvl < *(*int32)(unsafe.Pointer(bp)); iLvl++ {
			var pLvl uintptr = pRet + 24 + uintptr(iLvl)*16
			*(*int32)(unsafe.Pointer(bp + 12)) = 0
			var iSeg int32

			if i >= nData {
				*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_CORRUPT | int32(1)<<8
			} else {
				i = i + sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pLvl)
				i = i + sqlite3Fts5GetVarint32(tls, pData+uintptr(i), bp+12)
				if *(*int32)(unsafe.Pointer(bp + 12)) < (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge {
					*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_CORRUPT | int32(1)<<8
				}
				(*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = sqlite3Fts5MallocZero(tls, bp+8,
					int64(uint64(*(*int32)(unsafe.Pointer(bp + 12)))*uint64(unsafe.Sizeof(Fts5StructureSegment{}))))
				*(*int32)(unsafe.Pointer(bp + 4)) -= *(*int32)(unsafe.Pointer(bp + 12))
			}

			if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
				(*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg = *(*int32)(unsafe.Pointer(bp + 12))
				for iSeg = 0; iSeg < *(*int32)(unsafe.Pointer(bp + 12)); iSeg++ {
					var pSeg uintptr = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*12
					if i >= nData {
						*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_CORRUPT | int32(1)<<8
						break
					}
					i = i + sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg)
					i = i + sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+4)
					i = i + sqlite3Fts5GetVarint32(tls, pData+uintptr(i), pSeg+8)
					if (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast < (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
						*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_CORRUPT | int32(1)<<8
						break
					}
				}
				if iLvl > 0 && (*Fts5StructureLevel)(unsafe.Pointer(pLvl+libc.UintptrFromInt32(-1)*16)).FnMerge != 0 && *(*int32)(unsafe.Pointer(bp + 12)) == 0 {
					*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_CORRUPT | int32(1)<<8
				}
				if iLvl == *(*int32)(unsafe.Pointer(bp))-1 && (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
					*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_CORRUPT | int32(1)<<8
				}
			}
		}
		if *(*int32)(unsafe.Pointer(bp + 4)) != 0 && *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_CORRUPT | int32(1)<<8
		}

		if *(*int32)(unsafe.Pointer(bp + 8)) != SQLITE_OK {
			fts5StructureRelease(tls, pRet)
			pRet = uintptr(0)
		}
	}

	*(*uintptr)(unsafe.Pointer(ppOut)) = pRet
	return *(*int32)(unsafe.Pointer(bp + 8))
}

func fts5StructureAddLevel(tls *libc.TLS, pRc uintptr, ppStruct uintptr) {
	fts5StructureMakeWritable(tls, pRc, ppStruct)
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var pStruct uintptr = *(*uintptr)(unsafe.Pointer(ppStruct))
		var nLevel int32 = (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Structure{})) + uint64(unsafe.Sizeof(Fts5StructureLevel{}))*uint64(nLevel+1))

		pStruct = Xsqlite3_realloc64(tls, pStruct, uint64(nByte))
		if pStruct != 0 {
			libc.Xmemset(tls, pStruct+24+uintptr(nLevel)*16, 0, uint64(unsafe.Sizeof(Fts5StructureLevel{})))
			(*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel++
			*(*uintptr)(unsafe.Pointer(ppStruct)) = pStruct
		} else {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
		}
	}
}

func fts5StructureExtendLevel(tls *libc.TLS, pRc uintptr, pStruct uintptr, iLvl int32, nExtra int32, bInsert int32) {
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var pLvl uintptr = pStruct + 24 + uintptr(iLvl)*16
		var aNew uintptr
		var nByte Sqlite3_int64

		nByte = Sqlite3_int64(uint64((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg+nExtra) * uint64(unsafe.Sizeof(Fts5StructureSegment{})))
		aNew = Xsqlite3_realloc64(tls, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg, uint64(nByte))
		if aNew != 0 {
			if bInsert == 0 {
				libc.Xmemset(tls, aNew+uintptr((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg)*12, 0, uint64(unsafe.Sizeof(Fts5StructureSegment{}))*uint64(nExtra))
			} else {
				var nMove int32 = int32(uint64((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg) * uint64(unsafe.Sizeof(Fts5StructureSegment{})))
				libc.Xmemmove(tls, aNew+uintptr(nExtra)*12, aNew, uint64(nMove))
				libc.Xmemset(tls, aNew, 0, uint64(unsafe.Sizeof(Fts5StructureSegment{}))*uint64(nExtra))
			}
			(*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = aNew
		} else {
			*(*int32)(unsafe.Pointer(pRc)) = SQLITE_NOMEM
		}
	}
}

func fts5StructureReadUncached(tls *libc.TLS, p uintptr) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig

	var pData uintptr

	pData = fts5DataRead(tls, p, int64(FTS5_STRUCTURE_ROWID))
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		libc.Xmemset(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*Fts5Data)(unsafe.Pointer(pData)).Fnn), 0, uint64(FTS5_DATA_PADDING))
		(*Fts5Index)(unsafe.Pointer(p)).Frc = fts5StructureDecode(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp, (*Fts5Data)(unsafe.Pointer(pData)).Fnn, bp, bp+8)
		if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && ((*Fts5Config)(unsafe.Pointer(pConfig)).Fpgsz == 0 || (*Fts5Config)(unsafe.Pointer(pConfig)).FiCookie != *(*int32)(unsafe.Pointer(bp))) {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = sqlite3Fts5ConfigLoad(tls, pConfig, *(*int32)(unsafe.Pointer(bp)))
		}
		fts5DataRelease(tls, pData)
		if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
			fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
			*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		}
	}

	return *(*uintptr)(unsafe.Pointer(bp + 8))
}

func fts5IndexDataVersion(tls *libc.TLS, p uintptr) I64 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var iVersion I64 = int64(0)

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*Fts5Index)(unsafe.Pointer(p)).FpDataVersion == uintptr(0) {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = fts5IndexPrepareStmt(tls, p, p+112,
				Xsqlite3_mprintf(tls, ts+42229, libc.VaList(bp, (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FzDb)))
			if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
				return int64(0)
			}
		}

		if SQLITE_ROW == Xsqlite3_step(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDataVersion) {
			iVersion = Xsqlite3_column_int64(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDataVersion, 0)
		}
		(*Fts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDataVersion)
	}

	return iVersion
}

func fts5StructureRead(tls *libc.TLS, p uintptr) uintptr {
	if (*Fts5Index)(unsafe.Pointer(p)).FpStruct == uintptr(0) {
		(*Fts5Index)(unsafe.Pointer(p)).FiStructVersion = fts5IndexDataVersion(tls, p)
		if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Fts5Index)(unsafe.Pointer(p)).FpStruct = fts5StructureReadUncached(tls, p)
		}
	}

	if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		return uintptr(0)
	}

	fts5StructureRef(tls, (*Fts5Index)(unsafe.Pointer(p)).FpStruct)
	return (*Fts5Index)(unsafe.Pointer(p)).FpStruct
}

func fts5StructureInvalidate(tls *libc.TLS, p uintptr) {
	if (*Fts5Index)(unsafe.Pointer(p)).FpStruct != 0 {
		fts5StructureRelease(tls, (*Fts5Index)(unsafe.Pointer(p)).FpStruct)
		(*Fts5Index)(unsafe.Pointer(p)).FpStruct = uintptr(0)
	}
}

func fts5StructureWrite(tls *libc.TLS, p uintptr, pStruct uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var iLvl int32
		var iCookie int32

		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))

		iCookie = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FiCookie
		if iCookie < 0 {
			iCookie = 0
		}

		if 0 == sqlite3Fts5BufferSize(tls, p+52, bp, uint32(4+9+9+9)) {
			sqlite3Fts5Put32(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp, iCookie)
			(*Fts5Buffer)(unsafe.Pointer(bp)).Fn = 4
			{
				*(*int32)(unsafe.Pointer(bp + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp)).Fn), uint64((*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel))
			}

			{
				*(*int32)(unsafe.Pointer(bp + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp)).Fn), uint64((*Fts5Structure)(unsafe.Pointer(pStruct)).FnSegment))
			}

			{
				*(*int32)(unsafe.Pointer(bp + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp)).Fn), uint64(I64((*Fts5Structure)(unsafe.Pointer(pStruct)).FnWriteCounter)))
			}

		}

		for iLvl = 0; iLvl < (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel; iLvl++ {
			var iSeg int32
			var pLvl uintptr = pStruct + 24 + uintptr(iLvl)*16
			sqlite3Fts5BufferAppendVarint(tls, p+52, bp, I64((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge))
			sqlite3Fts5BufferAppendVarint(tls, p+52, bp, I64((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg))

			for iSeg = 0; iSeg < (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg; iSeg++ {
				sqlite3Fts5BufferAppendVarint(tls, p+52, bp, I64((*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(iSeg)*12)).FiSegid))
				sqlite3Fts5BufferAppendVarint(tls, p+52, bp, I64((*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(iSeg)*12)).FpgnoFirst))
				sqlite3Fts5BufferAppendVarint(tls, p+52, bp, I64((*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(iSeg)*12)).FpgnoLast))
			}
		}

		fts5DataWrite(tls, p, int64(FTS5_STRUCTURE_ROWID), (*Fts5Buffer)(unsafe.Pointer(bp)).Fp, (*Fts5Buffer)(unsafe.Pointer(bp)).Fn)
		sqlite3Fts5BufferFree(tls, bp)
	}
}

func fts5SegmentSize(tls *libc.TLS, pSeg uintptr) int32 {
	return 1 + (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast - (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst
}

func fts5StructurePromoteTo(tls *libc.TLS, p uintptr, iPromote int32, szPromote int32, pStruct uintptr) {
	var il int32
	var is int32
	var pOut uintptr = pStruct + 24 + uintptr(iPromote)*16

	if (*Fts5StructureLevel)(unsafe.Pointer(pOut)).FnMerge == 0 {
		for il = iPromote + 1; il < (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel; il++ {
			var pLvl uintptr = pStruct + 24 + uintptr(il)*16
			if (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
				return
			}
			for is = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg - 1; is >= 0; is-- {
				var sz int32 = fts5SegmentSize(tls, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(is)*12)
				if sz > szPromote {
					return
				}
				fts5StructureExtendLevel(tls, p+52, pStruct, iPromote, 1, 1)
				if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
					return
				}
				libc.Xmemcpy(tls, (*Fts5StructureLevel)(unsafe.Pointer(pOut)).FaSeg, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(is)*12, uint64(unsafe.Sizeof(Fts5StructureSegment{})))
				(*Fts5StructureLevel)(unsafe.Pointer(pOut)).FnSeg++
				(*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg--
			}
		}
	}
}

func fts5StructurePromote(tls *libc.TLS, p uintptr, iLvl int32, pStruct uintptr) {
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var iTst int32
		var iPromote int32 = -1
		var szPromote int32 = 0
		var pSeg uintptr
		var szSeg int32
		var nSeg int32 = (*Fts5StructureLevel)(unsafe.Pointer(pStruct + 24 + uintptr(iLvl)*16)).FnSeg

		if nSeg == 0 {
			return
		}
		pSeg = (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLvl)*16)).FaSeg + uintptr((*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLvl)*16)).FnSeg-1)*12
		szSeg = 1 + (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast - (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst

		for iTst = iLvl - 1; iTst >= 0 && (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iTst)*16)).FnSeg == 0; iTst-- {
		}
		if iTst >= 0 {
			var i int32
			var szMax int32 = 0
			var pTst uintptr = pStruct + 24 + uintptr(iTst)*16

			for i = 0; i < (*Fts5StructureLevel)(unsafe.Pointer(pTst)).FnSeg; i++ {
				var sz int32 = (*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pTst)).FaSeg+uintptr(i)*12)).FpgnoLast - (*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pTst)).FaSeg+uintptr(i)*12)).FpgnoFirst + 1
				if sz > szMax {
					szMax = sz
				}
			}
			if szMax >= szSeg {
				iPromote = iTst
				szPromote = szMax
			}
		}

		if iPromote < 0 {
			iPromote = iLvl
			szPromote = szSeg
		}
		fts5StructurePromoteTo(tls, p, iPromote, szPromote, pStruct)
	}
}

func fts5DlidxLvlNext(tls *libc.TLS, pLvl uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pData uintptr = (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData

	if (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff == 0 {
		(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff = 1
		*(*int32)(unsafe.Pointer(pLvl + 8)) += sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp+1, pLvl+20)
		*(*int32)(unsafe.Pointer(pLvl + 8)) += int32(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff), pLvl+24))
		(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiFirstOff = (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff
	} else {
		var iOff int32
		for iOff = (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff; iOff < (*Fts5Data)(unsafe.Pointer(pData)).Fnn; iOff++ {
			if *(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer(pData)).Fp + uintptr(iOff))) != 0 {
				break
			}
		}

		if iOff < (*Fts5Data)(unsafe.Pointer(pData)).Fnn {
			*(*int32)(unsafe.Pointer(pLvl + 20)) += iOff - (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff + 1
			iOff = iOff + int32(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp+uintptr(iOff), bp))
			*(*I64)(unsafe.Pointer(pLvl + 24)) += *(*I64)(unsafe.Pointer(bp))
			(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff = iOff
		} else {
			(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = 1
		}
	}

	return (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof
}

func fts5DlidxIterNextR(tls *libc.TLS, p uintptr, pIter uintptr, iLvl int32) int32 {
	var pLvl uintptr = pIter + 8 + uintptr(iLvl)*32

	if fts5DlidxLvlNext(tls, pLvl) != 0 {
		if iLvl+1 < (*Fts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl {
			fts5DlidxIterNextR(tls, p, pIter, iLvl+1)
			if (*Fts5DlidxLvl)(unsafe.Pointer(pLvl+1*32)).FbEof == 0 {
				fts5DataRelease(tls, (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData)
				libc.Xmemset(tls, pLvl, 0, uint64(unsafe.Sizeof(Fts5DlidxLvl{})))
				(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData = fts5DataRead(tls, p,
					I64((*Fts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(1)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+I64(iLvl)<<FTS5_DATA_PAGE_B+I64((*Fts5DlidxLvl)(unsafe.Pointer(pLvl+1*32)).FiLeafPgno))
				if (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData != 0 {
					fts5DlidxLvlNext(tls, pLvl)
				}
			}
		}
	}

	return (*Fts5DlidxLvl)(unsafe.Pointer(pIter + 8)).FbEof
}

func fts5DlidxIterNext(tls *libc.TLS, p uintptr, pIter uintptr) int32 {
	return fts5DlidxIterNextR(tls, p, pIter, 0)
}

func fts5DlidxIterFirst(tls *libc.TLS, pIter uintptr) int32 {
	var i int32
	for i = 0; i < (*Fts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl; i++ {
		fts5DlidxLvlNext(tls, pIter+8+uintptr(i)*32)
	}
	return (*Fts5DlidxLvl)(unsafe.Pointer(pIter + 8)).FbEof
}

func fts5DlidxIterEof(tls *libc.TLS, p uintptr, pIter uintptr) int32 {
	return libc.Bool32((*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK || (*Fts5DlidxLvl)(unsafe.Pointer(pIter+8)).FbEof != 0)
}

func fts5DlidxIterLast(tls *libc.TLS, p uintptr, pIter uintptr) {
	var i int32

	for i = (*Fts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl - 1; (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && i >= 0; i-- {
		var pLvl uintptr = pIter + 8 + uintptr(i)*32
		for fts5DlidxLvlNext(tls, pLvl) == 0 {
		}
		(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = 0

		if i > 0 {
			var pChild uintptr = pLvl + libc.UintptrFromInt32(-1)*32
			fts5DataRelease(tls, (*Fts5DlidxLvl)(unsafe.Pointer(pChild)).FpData)
			libc.Xmemset(tls, pChild, 0, uint64(unsafe.Sizeof(Fts5DlidxLvl{})))
			(*Fts5DlidxLvl)(unsafe.Pointer(pChild)).FpData = fts5DataRead(tls, p,
				I64((*Fts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(1)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+I64(i-1)<<FTS5_DATA_PAGE_B+I64((*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiLeafPgno))
		}
	}
}

func fts5DlidxLvlPrev(tls *libc.TLS, pLvl uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var iOff int32 = (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff

	if iOff <= (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiFirstOff {
		(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = 1
	} else {
		var a uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData)).Fp

		var iLimit int32
		var ii int32
		var nZero int32 = 0

		iLimit = func() int32 {
			if iOff > 9 {
				return iOff - 9
			}
			return 0
		}()
		for iOff--; iOff > iLimit; iOff-- {
			if int32(*(*U8)(unsafe.Pointer(a + uintptr(iOff-1))))&0x80 == 0 {
				break
			}
		}

		sqlite3Fts5GetVarint(tls, a+uintptr(iOff), bp)
		*(*I64)(unsafe.Pointer(pLvl + 24)) -= *(*I64)(unsafe.Pointer(bp))
		(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiLeafPgno--

		for ii = iOff - 1; ii >= (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiFirstOff && int32(*(*U8)(unsafe.Pointer(a + uintptr(ii)))) == 0x00; ii-- {
			nZero++
		}
		if ii >= (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiFirstOff && int32(*(*U8)(unsafe.Pointer(a + uintptr(ii))))&0x80 != 0 {
			var bZero int32 = 0
			if ii-8 >= (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiFirstOff {
				var j int32
				for j = 1; j <= 8 && int32(*(*U8)(unsafe.Pointer(a + uintptr(ii-j))))&0x80 != 0; j++ {
				}
				bZero = libc.Bool32(j > 8)
			}
			if bZero == 0 {
				nZero--
			}
		}
		*(*int32)(unsafe.Pointer(pLvl + 20)) -= nZero
		(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FiOff = iOff - nZero
	}

	return (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof
}

func fts5DlidxIterPrevR(tls *libc.TLS, p uintptr, pIter uintptr, iLvl int32) int32 {
	var pLvl uintptr = pIter + 8 + uintptr(iLvl)*32

	if fts5DlidxLvlPrev(tls, pLvl) != 0 {
		if iLvl+1 < (*Fts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl {
			fts5DlidxIterPrevR(tls, p, pIter, iLvl+1)
			if (*Fts5DlidxLvl)(unsafe.Pointer(pLvl+1*32)).FbEof == 0 {
				fts5DataRelease(tls, (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData)
				libc.Xmemset(tls, pLvl, 0, uint64(unsafe.Sizeof(Fts5DlidxLvl{})))
				(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData = fts5DataRead(tls, p,
					I64((*Fts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(1)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+I64(iLvl)<<FTS5_DATA_PAGE_B+I64((*Fts5DlidxLvl)(unsafe.Pointer(pLvl+1*32)).FiLeafPgno))
				if (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData != 0 {
					for fts5DlidxLvlNext(tls, pLvl) == 0 {
					}
					(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FbEof = 0
				}
			}
		}
	}

	return (*Fts5DlidxLvl)(unsafe.Pointer(pIter + 8)).FbEof
}

func fts5DlidxIterPrev(tls *libc.TLS, p uintptr, pIter uintptr) int32 {
	return fts5DlidxIterPrevR(tls, p, pIter, 0)
}

func fts5DlidxIterFree(tls *libc.TLS, pIter uintptr) {
	if pIter != 0 {
		var i int32
		for i = 0; i < (*Fts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl; i++ {
			fts5DataRelease(tls, (*Fts5DlidxLvl)(unsafe.Pointer(pIter+8+uintptr(i)*32)).FpData)
		}
		Xsqlite3_free(tls, pIter)
	}
}

func fts5DlidxIterInit(tls *libc.TLS, p uintptr, bRev int32, iSegid int32, iLeafPg int32) uintptr {
	var pIter uintptr = uintptr(0)
	var i int32
	var bDone int32 = 0

	for i = 0; (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bDone == 0; i++ {
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5DlidxIter{})) + uint64(i)*uint64(unsafe.Sizeof(Fts5DlidxLvl{})))
		var pNew uintptr

		pNew = Xsqlite3_realloc64(tls, pIter, uint64(nByte))
		if pNew == uintptr(0) {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
		} else {
			var iRowid I64 = I64(iSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(1)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + I64(i)<<FTS5_DATA_PAGE_B + I64(iLeafPg)
			var pLvl uintptr = pNew + 8 + uintptr(i)*32
			pIter = pNew
			libc.Xmemset(tls, pLvl, 0, uint64(unsafe.Sizeof(Fts5DlidxLvl{})))
			(*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData = fts5DataRead(tls, p, iRowid)
			if (*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData != 0 && int32(*(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer((*Fts5DlidxLvl)(unsafe.Pointer(pLvl)).FpData)).Fp)))&0x0001 == 0 {
				bDone = 1
			}
			(*Fts5DlidxIter)(unsafe.Pointer(pIter)).FnLvl = i + 1
		}
	}

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Fts5DlidxIter)(unsafe.Pointer(pIter)).FiSegid = iSegid
		if bRev == 0 {
			fts5DlidxIterFirst(tls, pIter)
		} else {
			fts5DlidxIterLast(tls, p, pIter)
		}
	}

	if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
		fts5DlidxIterFree(tls, pIter)
		pIter = uintptr(0)
	}

	return pIter
}

func fts5DlidxIterRowid(tls *libc.TLS, pIter uintptr) I64 {
	return (*Fts5DlidxLvl)(unsafe.Pointer(pIter + 8)).FiRowid
}

func fts5DlidxIterPgno(tls *libc.TLS, pIter uintptr) int32 {
	return (*Fts5DlidxLvl)(unsafe.Pointer(pIter + 8)).FiLeafPgno
}

func fts5SegIterNextPage(tls *libc.TLS, p uintptr, pIter uintptr) {
	var pLeaf uintptr
	var pSeg uintptr = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg
	fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno++
	if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf != 0 {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf = uintptr(0)
	} else if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno <= (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = fts5LeafRead(tls, p,
			I64((*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+int64(0)<<FTS5_DATA_PAGE_B+I64((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno))
	} else {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
	}
	pLeaf = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf

	if pLeaf != 0 {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf
		if (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf >= (*Fts5Data)(unsafe.Pointer(pLeaf)).Fnn {
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*Fts5Data)(unsafe.Pointer(pLeaf)).Fnn + 1
		} else {
			*(*int32)(unsafe.Pointer(pIter + 56)) += sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr((*Fts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff), pIter+60)
		}
	}
}

func fts5GetPoslistSize(tls *libc.TLS, p uintptr, pnSz uintptr, pbDel uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var n int32 = 0
	{
		*(*int32)(unsafe.Pointer(bp)) = int32(*(*U8)(unsafe.Pointer(p + uintptr(libc.PostIncInt32(&n, 1)))))
		if *(*int32)(unsafe.Pointer(bp))&0x80 != 0 {
			n--
			n = n + sqlite3Fts5GetVarint32(tls, p+uintptr(n), bp)
		}
	}

	*(*int32)(unsafe.Pointer(pnSz)) = *(*int32)(unsafe.Pointer(bp)) / 2
	*(*int32)(unsafe.Pointer(pbDel)) = *(*int32)(unsafe.Pointer(bp)) & 0x0001
	return n
}

func fts5SegIterLoadNPos(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var iOff int32 = int32((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)

		if (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == FTS5_DETAIL_NONE {
			var iEod int32 = func() int32 {
				if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist < (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf {
					return (*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist
				}
				return (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf
			}()
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FbDel = U8(0)
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FnPos = 1
			if iOff < iEod && int32(*(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr(iOff)))) == 0 {
				(*Fts5SegIter)(unsafe.Pointer(pIter)).FbDel = U8(1)
				iOff++
				if iOff < iEod && int32(*(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr(iOff)))) == 0 {
					(*Fts5SegIter)(unsafe.Pointer(pIter)).FnPos = 1
					iOff++
				} else {
					(*Fts5SegIter)(unsafe.Pointer(pIter)).FnPos = 0
				}
			}
		} else {
			{
				*(*int32)(unsafe.Pointer(bp)) = int32(*(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr(libc.PostIncInt32(&iOff, 1)))))
				if *(*int32)(unsafe.Pointer(bp))&0x80 != 0 {
					iOff--
					iOff = iOff + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr(iOff), bp)
				}
			}

			(*Fts5SegIter)(unsafe.Pointer(pIter)).FbDel = U8(*(*int32)(unsafe.Pointer(bp)) & 0x0001)
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FnPos = *(*int32)(unsafe.Pointer(bp)) >> 1

		}
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(iOff)
	}
}

func fts5SegIterLoadRowid(tls *libc.TLS, p uintptr, pIter uintptr) {
	var a uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	var iOff I64 = (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset

	if iOff >= I64((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf) {
		fts5SegIterNextPage(tls, p, pIter)
		if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0) {
			if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			}
			return
		}
		iOff = int64(4)
		a = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	}
	iOff = iOff + I64(sqlite3Fts5GetVarint(tls, a+uintptr(iOff), pIter+104))
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = iOff
}

func fts5SegIterLoadTerm(tls *libc.TLS, p uintptr, pIter uintptr, nKeep int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var a uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	var iOff I64 = (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset

	iOff = iOff + I64(sqlite3Fts5GetVarint32(tls, a+uintptr(iOff), bp))
	if iOff+I64(*(*int32)(unsafe.Pointer(bp))) > I64((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf) || nKeep > (*Fts5SegIter)(unsafe.Pointer(pIter)).Fterm.Fn || *(*int32)(unsafe.Pointer(bp)) == 0 {
		(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
		return
	}
	(*Fts5SegIter)(unsafe.Pointer(pIter)).Fterm.Fn = nKeep
	sqlite3Fts5BufferAppendBlob(tls, p+52, pIter+88, uint32(*(*int32)(unsafe.Pointer(bp))), a+uintptr(iOff))

	iOff = iOff + I64(*(*int32)(unsafe.Pointer(bp)))
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset = int32(iOff)
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno = (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = iOff

	if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff >= (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn + 1
	} else {
		*(*int32)(unsafe.Pointer(pIter + 56)) += sqlite3Fts5GetVarint32(tls, a+uintptr((*Fts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff), bp+4)
		*(*int32)(unsafe.Pointer(pIter + 60)) += *(*int32)(unsafe.Pointer(bp + 4))
	}

	fts5SegIterLoadRowid(tls, p, pIter)
}

func fts5SegIterSetNext(tls *libc.TLS, p uintptr, pIter uintptr) {
	if (*Fts5SegIter)(unsafe.Pointer(pIter)).Fflags&FTS5_SEGITER_REVERSE != 0 {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr)
		}{fts5SegIterNext_Reverse}))
	} else if (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == FTS5_DETAIL_NONE {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr)
		}{fts5SegIterNext_None}))
	} else {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FxNext = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr)
		}{fts5SegIterNext}))
	}
}

func fts5SegIterInit(tls *libc.TLS, p uintptr, pSeg uintptr, pIter uintptr) {
	if (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst == 0 {
		return
	}

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		libc.Xmemset(tls, pIter, 0, uint64(unsafe.Sizeof(Fts5SegIter{})))
		fts5SegIterSetNext(tls, p, pIter)
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg = pSeg
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst - 1
		fts5SegIterNextPage(tls, p, pIter)
	}

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = int64(4)

		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf + 1
		fts5SegIterLoadTerm(tls, p, pIter, 0)
		fts5SegIterLoadNPos(tls, p, pIter)
	}
}

func fts5SegIterReverseInitPage(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var eDetail int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
	var n int32 = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf
	var i int32 = int32((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
	var a uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	var iRowidOffset int32 = 0

	if n > (*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist {
		n = (*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist
	}

	for 1 != 0 {
		*(*U64)(unsafe.Pointer(bp + 8)) = uint64(0)

		if eDetail == FTS5_DETAIL_NONE {
			if i < n && int32(*(*U8)(unsafe.Pointer(a + uintptr(i)))) == 0 {
				i++
				if i < n && int32(*(*U8)(unsafe.Pointer(a + uintptr(i)))) == 0 {
					i++
				}
			}
		} else {
			i = i + fts5GetPoslistSize(tls, a+uintptr(i), bp, bp+4)
			i = i + *(*int32)(unsafe.Pointer(bp))
		}
		if i >= n {
			break
		}
		i = i + int32(sqlite3Fts5GetVarint(tls, a+uintptr(i), bp+8))
		*(*I64)(unsafe.Pointer(pIter + 104)) += I64(*(*U64)(unsafe.Pointer(bp + 8)))

		if iRowidOffset >= (*Fts5SegIter)(unsafe.Pointer(pIter)).FnRowidOffset {
			var nNew int32 = (*Fts5SegIter)(unsafe.Pointer(pIter)).FnRowidOffset + 8
			var aNew uintptr = Xsqlite3_realloc64(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset, uint64(nNew)*uint64(unsafe.Sizeof(int32(0))))
			if aNew == uintptr(0) {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
				break
			}
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset = aNew
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FnRowidOffset = nNew
		}

		*(*int32)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset + uintptr(libc.PostIncInt32(&iRowidOffset, 1))*4)) = int32((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(i)
	}
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiRowidOffset = iRowidOffset
	fts5SegIterLoadNPos(tls, p, pIter)
}

func fts5SegIterReverseNewPage(tls *libc.TLS, p uintptr, pIter uintptr) {
	fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
	for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno > (*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno {
		var pNew uintptr
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno--
		pNew = fts5DataRead(tls, p, I64((*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+int64(0)<<FTS5_DATA_PAGE_B+I64((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno))
		if pNew != 0 {
			if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno == (*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno {
				if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset < (*Fts5Data)(unsafe.Pointer(pNew)).FszLeaf {
					(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = pNew
					(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64((*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset)
				}
			} else {
				var iRowidOff int32
				iRowidOff = int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pNew)).Fp))
				if iRowidOff != 0 {
					if iRowidOff >= (*Fts5Data)(unsafe.Pointer(pNew)).FszLeaf {
						(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
					} else {
						(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = pNew
						(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(iRowidOff)
					}
				}
			}

			if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
				var a uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
				*(*I64)(unsafe.Pointer(pIter + 32)) += I64(sqlite3Fts5GetVarint(tls, a, pIter+104))
				break
			} else {
				fts5DataRelease(tls, pNew)
			}
		}
	}

	if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn + 1
		fts5SegIterReverseInitPage(tls, p, pIter)
	}
}

func fts5MultiIterIsEmpty(tls *libc.TLS, p uintptr, pIter uintptr) int32 {
	var pSeg uintptr = pIter + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst+1*4)).FiFirst)*120
	return libc.Bool32((*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf != 0 && (*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos == 0)
}

func fts5SegIterNext_Reverse(tls *libc.TLS, p uintptr, pIter uintptr, pbUnused uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	_ = pbUnused

	if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiRowidOffset > 0 {
		var a uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
		var iOff int32

		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiRowidOffset--
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(*(*int32)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset + uintptr((*Fts5SegIter)(unsafe.Pointer(pIter)).FiRowidOffset)*4)))
		fts5SegIterLoadNPos(tls, p, pIter)
		iOff = int32((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
		if (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail != FTS5_DETAIL_NONE {
			iOff = iOff + (*Fts5SegIter)(unsafe.Pointer(pIter)).FnPos
		}
		sqlite3Fts5GetVarint(tls, a+uintptr(iOff), bp)
		*(*I64)(unsafe.Pointer(pIter + 104)) -= I64(*(*U64)(unsafe.Pointer(bp)))
	} else {
		fts5SegIterReverseNewPage(tls, p, pIter)
	}
}

func fts5SegIterNext_None(tls *libc.TLS, p uintptr, pIter uintptr, pbNewTerm uintptr) {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var iOff int32

	iOff = int32((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)

	if !((*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg != 0 && iOff >= (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf) {
		goto __1
	}
	fts5SegIterNextPage(tls, p, pIter)
	if !((*Fts5Index)(unsafe.Pointer(p)).Frc != 0 || (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0)) {
		goto __2
	}
	return
__2:
	;
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiRowid = int64(0)
	iOff = 4
__1:
	;
	if !(iOff < (*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist) {
		goto __3
	}
	iOff = iOff + int32(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr(iOff), bp))
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(iOff)
	*(*I64)(unsafe.Pointer(pIter + 104)) += *(*I64)(unsafe.Pointer(bp))
	goto __4
__3:
	if !((*Fts5SegIter)(unsafe.Pointer(pIter)).Fflags&FTS5_SEGITER_ONETERM == 0) {
		goto __5
	}
	if !((*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg != 0) {
		goto __7
	}
	*(*int32)(unsafe.Pointer(bp + 8)) = 0
	if !(iOff != fts5LeafFirstTermOff(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)) {
		goto __9
	}
	iOff = iOff + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr(iOff), bp+8)
__9:
	;
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(iOff)
	fts5SegIterLoadTerm(tls, p, pIter, *(*int32)(unsafe.Pointer(bp + 8)))
	goto __8
__7:
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	sqlite3Fts5HashScanNext(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash)
	sqlite3Fts5HashScanEntry(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash, bp+16, bp+24, bp+32)
	if !(*(*uintptr)(unsafe.Pointer(bp + 24)) == uintptr(0)) {
		goto __10
	}
	goto next_none_eof
__10:
	;
	(*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp = *(*uintptr)(unsafe.Pointer(bp + 24))
	(*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn = *(*int32)(unsafe.Pointer(bp + 32))
	(*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf = *(*int32)(unsafe.Pointer(bp + 32))
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = *(*int32)(unsafe.Pointer(bp + 32))
	sqlite3Fts5BufferSet(tls, p+52, pIter+88, int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))), *(*uintptr)(unsafe.Pointer(bp + 16)))
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(sqlite3Fts5GetVarint(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), pIter+104))
__8:
	;
	if !(pbNewTerm != 0) {
		goto __11
	}
	*(*int32)(unsafe.Pointer(pbNewTerm)) = 1
__11:
	;
	goto __6
__5:
	goto next_none_eof
__6:
	;
__4:
	;
	fts5SegIterLoadNPos(tls, p, pIter)

	return
next_none_eof:
	fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
}

func fts5SegIterNext(tls *libc.TLS, p uintptr, pIter uintptr, pbNewTerm uintptr) {
	bp := tls.Alloc(44)
	defer tls.Free(44)

	var pLeaf uintptr = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf

	var bNewTerm int32 = 0
	*(*int32)(unsafe.Pointer(bp)) = 0
	var a uintptr
	var n int32

	a = (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp
	n = (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf

	*(*int32)(unsafe.Pointer(bp + 36)) = int32((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset + I64((*Fts5SegIter)(unsafe.Pointer(pIter)).FnPos))

	if *(*int32)(unsafe.Pointer(bp + 36)) < n {
		if *(*int32)(unsafe.Pointer(bp + 36)) >= (*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist {
			bNewTerm = 1
			if *(*int32)(unsafe.Pointer(bp + 36)) != fts5LeafFirstTermOff(tls, pLeaf) {
				*(*int32)(unsafe.Pointer(bp + 36)) += sqlite3Fts5GetVarint32(tls, a+uintptr(*(*int32)(unsafe.Pointer(bp + 36))), bp)
			}
		} else {
			*(*int32)(unsafe.Pointer(bp + 36)) += int32(sqlite3Fts5GetVarint(tls, a+uintptr(*(*int32)(unsafe.Pointer(bp + 36))), bp+8))
			*(*I64)(unsafe.Pointer(pIter + 104)) += I64(*(*U64)(unsafe.Pointer(bp + 8)))

		}
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(*(*int32)(unsafe.Pointer(bp + 36)))

	} else if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg == uintptr(0) {
		*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
		*(*int32)(unsafe.Pointer(bp + 32)) = 0

		if 0 == (*Fts5SegIter)(unsafe.Pointer(pIter)).Fflags&FTS5_SEGITER_ONETERM {
			sqlite3Fts5HashScanNext(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash)
			sqlite3Fts5HashScanEntry(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash, bp+16, bp+24, bp+32)
		}
		if *(*uintptr)(unsafe.Pointer(bp + 24)) == uintptr(0) {
			fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
		} else {
			(*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp = *(*uintptr)(unsafe.Pointer(bp + 24))
			(*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn = *(*int32)(unsafe.Pointer(bp + 32))
			(*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf = *(*int32)(unsafe.Pointer(bp + 32))
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = *(*int32)(unsafe.Pointer(bp + 32)) + 1
			sqlite3Fts5BufferSet(tls, p+52, pIter+88, int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))),
				*(*uintptr)(unsafe.Pointer(bp + 16)))
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(sqlite3Fts5GetVarint(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), pIter+104))
			*(*int32)(unsafe.Pointer(pbNewTerm)) = 1
		}
	} else {
		*(*int32)(unsafe.Pointer(bp + 36)) = 0

		for *(*int32)(unsafe.Pointer(bp + 36)) == 0 {
			fts5SegIterNextPage(tls, p, pIter)
			pLeaf = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf
			if pLeaf == uintptr(0) {
				break
			}

			if libc.AssignPtrInt32(bp+36, int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp))) != 0 && *(*int32)(unsafe.Pointer(bp + 36)) < (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
				*(*int32)(unsafe.Pointer(bp + 36)) += int32(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(*(*int32)(unsafe.Pointer(bp + 36))), pIter+104))
				(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(*(*int32)(unsafe.Pointer(bp + 36)))

				if (*Fts5Data)(unsafe.Pointer(pLeaf)).Fnn > (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
					(*Fts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr((*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf), pIter+60)
				}
			} else if (*Fts5Data)(unsafe.Pointer(pLeaf)).Fnn > (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
				(*Fts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr((*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf), bp+36)
				(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(*(*int32)(unsafe.Pointer(bp + 36)))
				(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = *(*int32)(unsafe.Pointer(bp + 36))
				bNewTerm = 1
			}

			if *(*int32)(unsafe.Pointer(bp + 36)) > (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
				return
			}
		}
	}

	if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
		if bNewTerm != 0 {
			if (*Fts5SegIter)(unsafe.Pointer(pIter)).Fflags&FTS5_SEGITER_ONETERM != 0 {
				fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
				(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
			} else {
				fts5SegIterLoadTerm(tls, p, pIter, *(*int32)(unsafe.Pointer(bp)))
				fts5SegIterLoadNPos(tls, p, pIter)
				if pbNewTerm != 0 {
					*(*int32)(unsafe.Pointer(pbNewTerm)) = 1
				}
			}
		} else {
			{
				*(*int32)(unsafe.Pointer(bp + 40)) = int32(*(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp + uintptr(libc.PostIncInt64(&(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset, 1)))))
				if *(*int32)(unsafe.Pointer(bp + 40))&0x80 != 0 {
					(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset--
					*(*I64)(unsafe.Pointer(pIter + 32)) += I64(sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset), bp+40))
				}
			}

			(*Fts5SegIter)(unsafe.Pointer(pIter)).FbDel = U8(*(*int32)(unsafe.Pointer(bp + 40)) & 0x0001)
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FnPos = *(*int32)(unsafe.Pointer(bp + 40)) >> 1

		}
	}
}

func fts5SegIterReverse(tls *libc.TLS, p uintptr, pIter uintptr) {
	var pDlidx uintptr = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpDlidx
	var pLast uintptr = uintptr(0)
	var pgnoLast int32 = 0

	if pDlidx != 0 {
		var iSegid int32 = (*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FiSegid
		pgnoLast = fts5DlidxIterPgno(tls, pDlidx)
		pLast = fts5LeafRead(tls, p, I64(iSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+int64(0)<<FTS5_DATA_PAGE_B+I64(pgnoLast))
	} else {
		var pLeaf uintptr = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf

		var iPoslist int32
		if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno == (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno {
			iPoslist = (*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset
		} else {
			iPoslist = 4
		}
		{
			var iEnd int32 = iPoslist + 9
			for int32(*(*U8)(unsafe.Pointer((*Fts5Data)(unsafe.Pointer(pLeaf)).Fp + uintptr(libc.PostIncInt32(&iPoslist, 1)))))&0x80 != 0 && iPoslist < iEnd {
			}
		}

		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(iPoslist)

		if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist >= (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
			var pgno int32
			var pSeg uintptr = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg

			for pgno = (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno + 1; !((*Fts5Index)(unsafe.Pointer(p)).Frc != 0) && pgno <= (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast; pgno++ {
				var iAbs I64 = I64((*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + I64(pgno)
				var pNew uintptr = fts5LeafRead(tls, p, iAbs)
				if pNew != 0 {
					var iRowid int32
					var bTermless int32
					iRowid = int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pNew)).Fp))
					bTermless = libc.Bool32((*Fts5Data)(unsafe.Pointer(pNew)).FszLeaf >= (*Fts5Data)(unsafe.Pointer(pNew)).Fnn)
					if iRowid != 0 {
						{
							var tmp uintptr
							tmp = pNew
							pNew = pLast
							pLast = tmp
						}

						pgnoLast = pgno
					}
					fts5DataRelease(tls, pNew)
					if bTermless == 0 {
						break
					}
				}
			}
		}
	}

	if pLast != 0 {
		var iOff int32
		fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = pLast
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = pgnoLast
		iOff = int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pLast)).Fp))
		if iOff > (*Fts5Data)(unsafe.Pointer(pLast)).FszLeaf {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			return
		}
		iOff = iOff + int32(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(pLast)).Fp+uintptr(iOff), pIter+104))
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(iOff)

		if (*Fts5Data)(unsafe.Pointer(pLast)).FszLeaf >= (*Fts5Data)(unsafe.Pointer(pLast)).Fnn {
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*Fts5Data)(unsafe.Pointer(pLast)).Fnn + 1
		} else {
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = fts5LeafFirstTermOff(tls, pLast)
		}
	}

	fts5SegIterReverseInitPage(tls, p, pIter)
}

func fts5SegIterLoadDlidx(tls *libc.TLS, p uintptr, pIter uintptr) {
	var iSeg int32 = (*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FiSegid
	var bRev int32 = (*Fts5SegIter)(unsafe.Pointer(pIter)).Fflags & FTS5_SEGITER_REVERSE
	var pLeaf uintptr = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf

	if (*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno == (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno &&
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist < (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
		return
	}

	(*Fts5SegIter)(unsafe.Pointer(pIter)).FpDlidx = fts5DlidxIterInit(tls, p, bRev, iSeg, (*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno)
}

func fts5LeafSeek(tls *libc.TLS, p uintptr, bGe int32, pIter uintptr, pTerm uintptr, nTerm int32) {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var a uintptr
	var n U32
	var nMatch U32

	var iPgidx U32
	var bEndOfPage int32
	var nCmp U32
	var i U32

	a = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	n = U32((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn)
	nMatch = U32(0)
	*(*U32)(unsafe.Pointer(bp + 8)) = U32(0)
	*(*U32)(unsafe.Pointer(bp + 4)) = U32(0)
	bEndOfPage = 0

	iPgidx = U32((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf)
	iPgidx = iPgidx + U32(sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidx), bp))
	*(*U32)(unsafe.Pointer(bp + 12)) = *(*U32)(unsafe.Pointer(bp))
	if !(*(*U32)(unsafe.Pointer(bp + 12)) > n) {
		goto __1
	}
	(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
	return
__1:
	;
__2:
	if !(1 != 0) {
		goto __3
	}

	*(*U32)(unsafe.Pointer(bp + 4)) = U32(*(*U8)(unsafe.Pointer(a + uintptr(libc.PostIncUint32(&*(*U32)(unsafe.Pointer(bp + 12)), 1)))))
	if !(*(*U32)(unsafe.Pointer(bp + 4))&U32(0x80) != 0) {
		goto __4
	}
	*(*U32)(unsafe.Pointer(bp + 12))--
	*(*U32)(unsafe.Pointer(bp + 12)) += U32(sqlite3Fts5GetVarint32(tls, a+uintptr(*(*U32)(unsafe.Pointer(bp + 12))), bp+4))
__4:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 8)) < nMatch) {
		goto __5
	}
	goto search_failed
__5:
	;
	if !(*(*U32)(unsafe.Pointer(bp + 8)) == nMatch) {
		goto __6
	}
	nCmp = func() uint32 {
		if *(*U32)(unsafe.Pointer(bp + 4)) < U32(nTerm)-nMatch {
			return *(*U32)(unsafe.Pointer(bp + 4))
		}
		return U32(nTerm) - nMatch
	}()
	i = U32(0)
__7:
	if !(i < nCmp) {
		goto __9
	}
	if !(int32(*(*U8)(unsafe.Pointer(a + uintptr(*(*U32)(unsafe.Pointer(bp + 12))+i)))) != int32(*(*U8)(unsafe.Pointer(pTerm + uintptr(nMatch+i))))) {
		goto __10
	}
	goto __9
__10:
	;
	goto __8
__8:
	i++
	goto __7
	goto __9
__9:
	;
	nMatch = nMatch + i

	if !(U32(nTerm) == nMatch) {
		goto __11
	}
	if !(i == *(*U32)(unsafe.Pointer(bp + 4))) {
		goto __13
	}
	goto search_success
	goto __14
__13:
	goto search_failed
__14:
	;
	goto __12
__11:
	if !(i < *(*U32)(unsafe.Pointer(bp + 4)) && int32(*(*U8)(unsafe.Pointer(a + uintptr(*(*U32)(unsafe.Pointer(bp + 12))+i)))) > int32(*(*U8)(unsafe.Pointer(pTerm + uintptr(nMatch))))) {
		goto __15
	}
	goto search_failed
__15:
	;
__12:
	;
__6:
	;
	if !(iPgidx >= n) {
		goto __16
	}
	bEndOfPage = 1
	goto __3
__16:
	;
	iPgidx = iPgidx + U32(sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidx), bp+8))
	*(*U32)(unsafe.Pointer(bp)) += *(*U32)(unsafe.Pointer(bp + 8))
	*(*U32)(unsafe.Pointer(bp + 12)) = *(*U32)(unsafe.Pointer(bp))

	if !(*(*U32)(unsafe.Pointer(bp + 12)) >= n) {
		goto __17
	}
	(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
	return
__17:
	;
	*(*U32)(unsafe.Pointer(bp + 8)) = U32(*(*U8)(unsafe.Pointer(a + uintptr(libc.PostIncUint32(&*(*U32)(unsafe.Pointer(bp + 12)), 1)))))
	if !(*(*U32)(unsafe.Pointer(bp + 8))&U32(0x80) != 0) {
		goto __18
	}
	*(*U32)(unsafe.Pointer(bp + 12))--
	*(*U32)(unsafe.Pointer(bp + 12)) += U32(sqlite3Fts5GetVarint32(tls, a+uintptr(*(*U32)(unsafe.Pointer(bp + 12))), bp+8))
__18:
	;
	goto __2
__3:
	;
search_failed:
	if !(bGe == 0) {
		goto __19
	}
	fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = uintptr(0)
	return
	goto __20
__19:
	if !(bEndOfPage != 0) {
		goto __21
	}
__22:
	fts5SegIterNextPage(tls, p, pIter)
	if !((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0)) {
		goto __25
	}
	return
__25:
	;
	a = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
	if !(libc.Bool32((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf >= (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn) == 0) {
		goto __26
	}
	iPgidx = U32((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf)
	iPgidx = iPgidx + U32(sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp+uintptr(iPgidx), bp+12))
	if !(*(*U32)(unsafe.Pointer(bp + 12)) < U32(4) || I64(*(*U32)(unsafe.Pointer(bp + 12))) >= I64((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf)) {
		goto __27
	}
	(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
	return
	goto __28
__27:
	*(*U32)(unsafe.Pointer(bp + 8)) = U32(0)
	*(*U32)(unsafe.Pointer(bp)) = *(*U32)(unsafe.Pointer(bp + 12))
	n = U32((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn)
	*(*U32)(unsafe.Pointer(bp + 12)) += U32(sqlite3Fts5GetVarint32(tls, a+uintptr(*(*U32)(unsafe.Pointer(bp + 12))), bp+4))
	goto __24
__28:
	;
__26:
	;
	goto __23
__23:
	if 1 != 0 {
		goto __22
	}
	goto __24
__24:
	;
__21:
	;
__20:
	;
search_success:
	if !(I64(*(*U32)(unsafe.Pointer(bp + 12)))+I64(*(*U32)(unsafe.Pointer(bp + 4))) > I64(n) || *(*U32)(unsafe.Pointer(bp + 4)) < U32(1)) {
		goto __29
	}
	(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
	return
__29:
	;
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(*(*U32)(unsafe.Pointer(bp + 12)) + *(*U32)(unsafe.Pointer(bp + 4)))
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafOffset = int32((*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset)
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiTermLeafPgno = (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno

	sqlite3Fts5BufferSet(tls, p+52, pIter+88, int32(*(*U32)(unsafe.Pointer(bp + 8))), pTerm)
	sqlite3Fts5BufferAppendBlob(tls, p+52, pIter+88, *(*U32)(unsafe.Pointer(bp + 4)), a+uintptr(*(*U32)(unsafe.Pointer(bp + 12))))

	if !(iPgidx >= n) {
		goto __30
	}
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fnn + 1
	goto __31
__30:
	iPgidx = iPgidx + U32(sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidx), bp+16))
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = int32(*(*U32)(unsafe.Pointer(bp)) + U32(*(*int32)(unsafe.Pointer(bp + 16))))
__31:
	;
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiPgidxOff = int32(iPgidx)

	fts5SegIterLoadRowid(tls, p, pIter)
	fts5SegIterLoadNPos(tls, p, pIter)
}

func fts5IdxSelectStmt(tls *libc.TLS, p uintptr) uintptr {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Fts5Index)(unsafe.Pointer(p)).FpIdxSelect == uintptr(0) {
		var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig
		fts5IndexPrepareStmt(tls, p, p+96, Xsqlite3_mprintf(tls,
			ts+42252,
			libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}
	return (*Fts5Index)(unsafe.Pointer(p)).FpIdxSelect
}

func fts5SegIterSeekInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32, flags int32, pSeg uintptr, pIter uintptr) {
	var iPg int32 = 1
	var bGe int32 = flags & FTS5INDEX_QUERY_SCAN
	var bDlidx int32 = 0
	var pIdxSelect uintptr = uintptr(0)

	libc.Xmemset(tls, pIter, 0, uint64(unsafe.Sizeof(Fts5SegIter{})))
	(*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg = pSeg

	pIdxSelect = fts5IdxSelectStmt(tls, p)
	if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
		return
	}
	Xsqlite3_bind_int(tls, pIdxSelect, 1, (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)
	Xsqlite3_bind_blob(tls, pIdxSelect, 2, pTerm, nTerm, uintptr(0))
	if SQLITE_ROW == Xsqlite3_step(tls, pIdxSelect) {
		var val I64 = I64(Xsqlite3_column_int(tls, pIdxSelect, 0))
		iPg = int32(val >> 1)
		bDlidx = int32(val & int64(0x0001))
	}
	(*Fts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, pIdxSelect)
	Xsqlite3_bind_null(tls, pIdxSelect, 2)

	if iPg < (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
		iPg = (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst
		bDlidx = 0
	}

	(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iPg - 1
	fts5SegIterNextPage(tls, p, pIter)

	if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
		fts5LeafSeek(tls, p, bGe, pIter, pTerm, nTerm)
	}

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bGe == 0 {
		*(*int32)(unsafe.Pointer(pIter + 8)) |= FTS5_SEGITER_ONETERM
		if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != 0 {
			if flags&FTS5INDEX_QUERY_DESC != 0 {
				*(*int32)(unsafe.Pointer(pIter + 8)) |= FTS5_SEGITER_REVERSE
			}
			if bDlidx != 0 {
				fts5SegIterLoadDlidx(tls, p, pIter)
			}
			if flags&FTS5INDEX_QUERY_DESC != 0 {
				fts5SegIterReverse(tls, p, pIter)
			}
		}
	}

	fts5SegIterSetNext(tls, p, pIter)

}

func fts5SegIterHashInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32, flags int32, pIter uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	*(*int32)(unsafe.Pointer(bp + 16)) = 0
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var n int32 = 0
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)

	if pTerm == uintptr(0) || flags&FTS5INDEX_QUERY_SCAN != 0 {
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

		(*Fts5Index)(unsafe.Pointer(p)).Frc = sqlite3Fts5HashScanInit(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash, pTerm, nTerm)
		sqlite3Fts5HashScanEntry(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash, bp, bp+8, bp+16)
		n = func() int32 {
			if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
				return int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp))))
			}
			return 0
		}()
		if *(*uintptr)(unsafe.Pointer(bp + 8)) != 0 {
			*(*uintptr)(unsafe.Pointer(bp + 24)) = fts5IdxMalloc(tls, p, int64(unsafe.Sizeof(Fts5Data{})))
			if *(*uintptr)(unsafe.Pointer(bp + 24)) != 0 {
				(*Fts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).Fp = *(*uintptr)(unsafe.Pointer(bp + 8))
			}
		}
	} else {
		(*Fts5Index)(unsafe.Pointer(p)).Frc = sqlite3Fts5HashQuery(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash, int32(unsafe.Sizeof(Fts5Data{})),
			pTerm, nTerm, bp+24, bp+16)
		if *(*uintptr)(unsafe.Pointer(bp + 24)) != 0 {
			(*Fts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).Fp = *(*uintptr)(unsafe.Pointer(bp + 24)) + 1*16
		}
		*(*uintptr)(unsafe.Pointer(bp)) = pTerm
		n = nTerm
		*(*int32)(unsafe.Pointer(pIter + 8)) |= FTS5_SEGITER_ONETERM
	}

	if *(*uintptr)(unsafe.Pointer(bp + 24)) != 0 {
		sqlite3Fts5BufferSet(tls, p+52, pIter+88, n, *(*uintptr)(unsafe.Pointer(bp)))
		(*Fts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).Fnn = libc.AssignPtrInt32(*(*uintptr)(unsafe.Pointer(bp + 24))+12, *(*int32)(unsafe.Pointer(bp + 16)))
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = *(*uintptr)(unsafe.Pointer(bp + 24))
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).Fp, pIter+104))
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*Fts5Data)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 24)))).Fnn

		if flags&FTS5INDEX_QUERY_DESC != 0 {
			*(*int32)(unsafe.Pointer(pIter + 8)) |= FTS5_SEGITER_REVERSE
			fts5SegIterReverseInitPage(tls, p, pIter)
		} else {
			fts5SegIterLoadNPos(tls, p, pIter)
		}
	}

	fts5SegIterSetNext(tls, p, pIter)
}

func fts5SegIterClear(tls *libc.TLS, pIter uintptr) {
	sqlite3Fts5BufferFree(tls, pIter+88)
	fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)
	fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf)
	fts5DlidxIterFree(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpDlidx)
	Xsqlite3_free(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FaRowidOffset)
	libc.Xmemset(tls, pIter, 0, uint64(unsafe.Sizeof(Fts5SegIter{})))
}

func fts5MultiIterDoCompare(tls *libc.TLS, pIter uintptr, iOut int32) int32 {
	var i1 int32
	var i2 int32
	var iRes int32
	var p1 uintptr
	var p2 uintptr
	var pRes uintptr = (*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(iOut)*4

	if iOut >= (*Fts5Iter)(unsafe.Pointer(pIter)).FnSeg/2 {
		i1 = (iOut - (*Fts5Iter)(unsafe.Pointer(pIter)).FnSeg/2) * 2
		i2 = i1 + 1
	} else {
		i1 = int32((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(iOut*2)*4)).FiFirst)
		i2 = int32((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(iOut*2+1)*4)).FiFirst)
	}
	p1 = pIter + 96 + uintptr(i1)*120
	p2 = pIter + 96 + uintptr(i2)*120

	(*Fts5CResult)(unsafe.Pointer(pRes)).FbTermEq = U8(0)
	if (*Fts5SegIter)(unsafe.Pointer(p1)).FpLeaf == uintptr(0) {
		iRes = i2
	} else if (*Fts5SegIter)(unsafe.Pointer(p2)).FpLeaf == uintptr(0) {
		iRes = i1
	} else {
		var res int32 = fts5BufferCompare(tls, p1+88, p2+88)
		if res == 0 {
			(*Fts5CResult)(unsafe.Pointer(pRes)).FbTermEq = U8(1)
			if (*Fts5SegIter)(unsafe.Pointer(p1)).FiRowid == (*Fts5SegIter)(unsafe.Pointer(p2)).FiRowid {
				(*Fts5SegIter)(unsafe.Pointer(p1)).FbDel = (*Fts5SegIter)(unsafe.Pointer(p2)).FbDel
				return i2
			}
			if libc.Bool32((*Fts5SegIter)(unsafe.Pointer(p1)).FiRowid > (*Fts5SegIter)(unsafe.Pointer(p2)).FiRowid) == (*Fts5Iter)(unsafe.Pointer(pIter)).FbRev {
				res = -1
			} else {
				res = +1
			}
		}

		if res < 0 {
			iRes = i1
		} else {
			iRes = i2
		}
	}

	(*Fts5CResult)(unsafe.Pointer(pRes)).FiFirst = U16(iRes)
	return 0
}

func fts5SegIterGotoPage(tls *libc.TLS, p uintptr, pIter uintptr, iLeafPgno int32) {
	if iLeafPgno > (*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpSeg)).FpgnoLast {
		(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
	} else {
		fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf)
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FpNextLeaf = uintptr(0)
		(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iLeafPgno - 1
		fts5SegIterNextPage(tls, p, pIter)

		if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf != uintptr(0) {
			var iOff int32
			var a uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp
			var n int32 = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).FszLeaf

			iOff = int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf)).Fp))
			if iOff < 4 || iOff >= n {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			} else {
				iOff = iOff + int32(sqlite3Fts5GetVarint(tls, a+uintptr(iOff), pIter+104))
				(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(iOff)
				fts5SegIterLoadNPos(tls, p, pIter)
			}
		}
	}
}

func fts5SegIterNextFrom(tls *libc.TLS, p uintptr, pIter uintptr, iMatch I64) {
	var bRev int32 = (*Fts5SegIter)(unsafe.Pointer(pIter)).Fflags & FTS5_SEGITER_REVERSE
	var pDlidx uintptr = (*Fts5SegIter)(unsafe.Pointer(pIter)).FpDlidx
	var iLeafPgno int32 = (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno
	var 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 > (*Fts5SegIter)(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 < (*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno {
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafPgno = iLeafPgno + 1
			fts5SegIterReverseNewPage(tls, p, pIter)
			bMove = 0
		}
	}

	for __ccgo := true; __ccgo; __ccgo = (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if bMove != 0 && (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5SegIter)(unsafe.Pointer(pIter)).FxNext})).f(tls, p, pIter, uintptr(0))
		}
		if (*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf == uintptr(0) {
			break
		}
		if bRev == 0 && (*Fts5SegIter)(unsafe.Pointer(pIter)).FiRowid >= iMatch {
			break
		}
		if bRev != 0 && (*Fts5SegIter)(unsafe.Pointer(pIter)).FiRowid <= iMatch {
			break
		}
		bMove = 1
	}
}

func fts5MultiIterFree(tls *libc.TLS, pIter uintptr) {
	if pIter != 0 {
		var i int32
		for i = 0; i < (*Fts5Iter)(unsafe.Pointer(pIter)).FnSeg; i++ {
			fts5SegIterClear(tls, pIter+96+uintptr(i)*120)
		}
		sqlite3Fts5BufferFree(tls, pIter+32)
		Xsqlite3_free(tls, pIter)
	}
}

func fts5MultiIterAdvanced(tls *libc.TLS, p uintptr, pIter uintptr, iChanged int32, iMinset int32) {
	var i int32
	for i = ((*Fts5Iter)(unsafe.Pointer(pIter)).FnSeg + iChanged) / 2; i >= iMinset && (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK; i = i / 2 {
		var iEq int32
		if libc.AssignInt32(&iEq, fts5MultiIterDoCompare(tls, pIter, i)) != 0 {
			var pSeg uintptr = pIter + 96 + uintptr(iEq)*120

			(*struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5SegIter)(unsafe.Pointer(pSeg)).FxNext})).f(tls, p, pSeg, uintptr(0))
			i = (*Fts5Iter)(unsafe.Pointer(pIter)).FnSeg + iEq
		}
	}
}

func fts5MultiIterAdvanceRowid(tls *libc.TLS, pIter uintptr, iChanged int32, ppFirst uintptr) int32 {
	var pNew uintptr = pIter + 96 + uintptr(iChanged)*120

	if (*Fts5SegIter)(unsafe.Pointer(pNew)).FiRowid == (*Fts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid ||
		libc.Bool32((*Fts5SegIter)(unsafe.Pointer(pNew)).FiRowid < (*Fts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid) == (*Fts5Iter)(unsafe.Pointer(pIter)).FbRev {
		var i int32
		var pOther uintptr = pIter + 96 + uintptr(iChanged^0x0001)*120
		(*Fts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid = func() int64 {
			if (*Fts5Iter)(unsafe.Pointer(pIter)).FbRev != 0 {
				return int64(-1) - (int64(0xffffffff) | int64(0x7fffffff)<<32)
			}
			return int64(0xffffffff) | int64(0x7fffffff)<<32
		}()
		for i = ((*Fts5Iter)(unsafe.Pointer(pIter)).FnSeg + iChanged) / 2; 1 != 0; i = i / 2 {
			var pRes uintptr = (*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst + uintptr(i)*4

			if (*Fts5CResult)(unsafe.Pointer(pRes)).FbTermEq != 0 {
				if (*Fts5SegIter)(unsafe.Pointer(pNew)).FiRowid == (*Fts5SegIter)(unsafe.Pointer(pOther)).FiRowid {
					return 1
				} else if libc.Bool32((*Fts5SegIter)(unsafe.Pointer(pOther)).FiRowid > (*Fts5SegIter)(unsafe.Pointer(pNew)).FiRowid) == (*Fts5Iter)(unsafe.Pointer(pIter)).FbRev {
					(*Fts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid = (*Fts5SegIter)(unsafe.Pointer(pOther)).FiRowid
					pNew = pOther
				} else if libc.Bool32((*Fts5SegIter)(unsafe.Pointer(pOther)).FiRowid > (*Fts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid) == (*Fts5Iter)(unsafe.Pointer(pIter)).FbRev {
					(*Fts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid = (*Fts5SegIter)(unsafe.Pointer(pOther)).FiRowid
				}
			}
			(*Fts5CResult)(unsafe.Pointer(pRes)).FiFirst = U16(int64((pNew - (pIter + 96)) / 120))
			if i == 1 {
				break
			}

			pOther = pIter + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst+uintptr(i^0x0001)*4)).FiFirst)*120
		}
	}

	*(*uintptr)(unsafe.Pointer(ppFirst)) = pNew
	return 0
}

func fts5MultiIterSetEof(tls *libc.TLS, pIter uintptr) {
	var pSeg uintptr = pIter + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst+1*4)).FiFirst)*120
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof = U8(libc.Bool32((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf == uintptr(0)))
	(*Fts5Iter)(unsafe.Pointer(pIter)).FiSwitchRowid = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
}

func fts5MultiIterNext(tls *libc.TLS, p uintptr, pIter uintptr, bFrom int32, iFrom I64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var bUseFrom int32 = bFrom

	for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var iFirst int32 = int32((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4)).FiFirst)
		*(*int32)(unsafe.Pointer(bp)) = 0
		*(*uintptr)(unsafe.Pointer(bp + 8)) = pIter + 96 + uintptr(iFirst)*120

		if bUseFrom != 0 && (*Fts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpDlidx != 0 {
			fts5SegIterNextFrom(tls, p, *(*uintptr)(unsafe.Pointer(bp + 8)), iFrom)
		} else {
			(*struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FxNext})).f(tls, p, *(*uintptr)(unsafe.Pointer(bp + 8)), bp)
		}

		if (*Fts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpLeaf == uintptr(0) || *(*int32)(unsafe.Pointer(bp)) != 0 ||
			fts5MultiIterAdvanceRowid(tls, pIter, iFirst, bp+8) != 0 {
			fts5MultiIterAdvanced(tls, p, pIter, iFirst, 1)
			fts5MultiIterSetEof(tls, pIter)
			*(*uintptr)(unsafe.Pointer(bp + 8)) = pIter + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst+1*4)).FiFirst)*120
			if (*Fts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpLeaf == uintptr(0) {
				return
			}
		}

		if int32((*Fts5Iter)(unsafe.Pointer(pIter)).FbSkipEmpty) == 0 || (*Fts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FnPos != 0 {
			(*struct {
				f func(*libc.TLS, uintptr, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs})).f(tls, pIter, *(*uintptr)(unsafe.Pointer(bp + 8)))
			return
		}
		bUseFrom = 0
	}
}

func fts5MultiIterNext2(tls *libc.TLS, p uintptr, pIter uintptr, pbNewTerm uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pbNewTerm)) = 0
		for __ccgo := true; __ccgo; __ccgo = fts5MultiIterIsEmpty(tls, p, pIter) != 0 {
			var iFirst int32 = int32((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst + 1*4)).FiFirst)
			*(*uintptr)(unsafe.Pointer(bp + 8)) = pIter + 96 + uintptr(iFirst)*120
			*(*int32)(unsafe.Pointer(bp)) = 0

			(*struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FxNext})).f(tls, p, *(*uintptr)(unsafe.Pointer(bp + 8)), bp)
			if (*Fts5SegIter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpLeaf == uintptr(0) || *(*int32)(unsafe.Pointer(bp)) != 0 ||
				fts5MultiIterAdvanceRowid(tls, pIter, iFirst, bp+8) != 0 {
				fts5MultiIterAdvanced(tls, p, pIter, iFirst, 1)
				fts5MultiIterSetEof(tls, pIter)
				*(*int32)(unsafe.Pointer(pbNewTerm)) = 1
			}

		}
	}
}

func fts5IterSetOutputs_Noop(tls *libc.TLS, pUnused1 uintptr, pUnused2 uintptr) {
	_ = pUnused1
	_ = pUnused2
}

func fts5MultiIterAlloc(tls *libc.TLS, p uintptr, nSeg int32) uintptr {
	var pNew uintptr
	var nSlot int32

	for nSlot = 2; nSlot < nSeg; nSlot = nSlot * 2 {
	}
	pNew = fts5IdxMalloc(tls, p,
		int64(uint64(unsafe.Sizeof(Fts5Iter{}))+uint64(unsafe.Sizeof(Fts5SegIter{}))*uint64(nSlot-1)+uint64(unsafe.Sizeof(Fts5CResult{}))*uint64(nSlot)))
	if pNew != 0 {
		(*Fts5Iter)(unsafe.Pointer(pNew)).FnSeg = nSlot
		(*Fts5Iter)(unsafe.Pointer(pNew)).FaFirst = pNew + 96 + uintptr(nSlot)*120
		(*Fts5Iter)(unsafe.Pointer(pNew)).FpIndex = p
		(*Fts5Iter)(unsafe.Pointer(pNew)).FxSetOutputs = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr)
		}{fts5IterSetOutputs_Noop}))
	}
	return pNew
}

func fts5PoslistCallback(tls *libc.TLS, pUnused uintptr, pContext uintptr, pChunk uintptr, nChunk int32) {
	_ = pUnused

	if nChunk > 0 {
		{
			libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(pContext)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pContext)).Fn), pChunk, uint64(nChunk))
			*(*int32)(unsafe.Pointer(pContext + 8)) += nChunk
		}

	}
}

type PoslistCallbackCtx1 = struct {
	FpBuf        uintptr
	FpColset     uintptr
	FeState      int32
	F__ccgo_pad1 [4]byte
}

type PoslistCallbackCtx = PoslistCallbackCtx1

type PoslistOffsetsCtx1 = struct {
	FpBuf    uintptr
	FpColset uintptr
	FiRead   int32
	FiWrite  int32
}

type PoslistOffsetsCtx = PoslistOffsetsCtx1

func fts5IndexColsetTest(tls *libc.TLS, pColset uintptr, iCol int32) int32 {
	var i int32
	for i = 0; i < (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol; i++ {
		if *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) == iCol {
			return 1
		}
	}
	return 0
}

func fts5PoslistOffsetsCallback(tls *libc.TLS, pUnused uintptr, pContext uintptr, pChunk uintptr, nChunk int32) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pCtx uintptr = pContext
	_ = pUnused

	if nChunk > 0 {
		var i int32 = 0
		for i < nChunk {
			i = i + sqlite3Fts5GetVarint32(tls, pChunk+uintptr(i), bp)
			*(*int32)(unsafe.Pointer(bp)) += (*PoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FiRead - 2
			(*PoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FiRead = *(*int32)(unsafe.Pointer(bp))
			if fts5IndexColsetTest(tls, (*PoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FpColset, *(*int32)(unsafe.Pointer(bp))) != 0 {
				{
					*(*int32)(unsafe.Pointer((*PoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FpBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer((*PoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer((*PoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), uint64(*(*int32)(unsafe.Pointer(bp))+2-(*PoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FiWrite))
				}

				(*PoslistOffsetsCtx)(unsafe.Pointer(pCtx)).FiWrite = *(*int32)(unsafe.Pointer(bp))
			}
		}
	}
}

func fts5PoslistFilterCallback(tls *libc.TLS, pUnused uintptr, pContext uintptr, pChunk uintptr, nChunk int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pCtx uintptr = pContext
	_ = pUnused

	if nChunk > 0 {
		var i int32 = 0
		var iStart int32 = 0

		if (*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState == 2 {
			{
				*(*int32)(unsafe.Pointer(bp)) = int32(*(*U8)(unsafe.Pointer(pChunk + uintptr(libc.PostIncInt32(&i, 1)))))
				if *(*int32)(unsafe.Pointer(bp))&0x80 != 0 {
					i--
					i = i + sqlite3Fts5GetVarint32(tls, pChunk+uintptr(i), bp)
				}
			}

			if fts5IndexColsetTest(tls, (*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpColset, *(*int32)(unsafe.Pointer(bp))) != 0 {
				(*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = 1
				{
					*(*int32)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), uint64(1))
				}

			} else {
				(*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = 0
			}
		}

		for __ccgo := true; __ccgo; __ccgo = i < nChunk {
			for i < nChunk && int32(*(*U8)(unsafe.Pointer(pChunk + uintptr(i)))) != 0x01 {
				for int32(*(*U8)(unsafe.Pointer(pChunk + uintptr(i))))&0x80 != 0 {
					i++
				}
				i++
			}
			if (*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState != 0 {
				{
					libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), pChunk+uintptr(iStart), uint64(i-iStart))
					*(*int32)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 8)) += i - iStart
				}

			}
			if i < nChunk {
				iStart = i
				i++
				if i >= nChunk {
					(*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = 2
				} else {
					{
						*(*int32)(unsafe.Pointer(bp + 4)) = int32(*(*U8)(unsafe.Pointer(pChunk + uintptr(libc.PostIncInt32(&i, 1)))))
						if *(*int32)(unsafe.Pointer(bp + 4))&0x80 != 0 {
							i--
							i = i + sqlite3Fts5GetVarint32(tls, pChunk+uintptr(i), bp+4)
						}
					}

					(*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState = fts5IndexColsetTest(tls, (*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpColset, *(*int32)(unsafe.Pointer(bp + 4)))
					if (*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FeState != 0 {
						{
							libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf)).Fn), pChunk+uintptr(iStart), uint64(i-iStart))
							*(*int32)(unsafe.Pointer((*PoslistCallbackCtx)(unsafe.Pointer(pCtx)).FpBuf + 8)) += i - iStart
						}

						iStart = i
					}
				}
			}
		}
	}
}

func fts5ChunkIterate(tls *libc.TLS, p uintptr, pSeg uintptr, pCtx uintptr, xChunk uintptr) {
	var nRem int32 = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos
	var pData uintptr = uintptr(0)
	var pChunk uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp + uintptr((*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
	var nChunk int32 = func() int32 {
		if I64(nRem) < I64((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf)-(*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset {
			return nRem
		}
		return int32(I64((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf) - (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
	}()
	var pgno int32 = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno
	var pgnoSave int32 = 0

	if (*Fts5SegIter)(unsafe.Pointer(pSeg)).Fflags&FTS5_SEGITER_REVERSE == 0 {
		pgnoSave = pgno + 1
	}

	for 1 != 0 {
		(*struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, int32)
		})(unsafe.Pointer(&struct{ uintptr }{xChunk})).f(tls, p, pCtx, pChunk, nChunk)
		nRem = nRem - nChunk
		fts5DataRelease(tls, pData)
		if nRem <= 0 {
			break
		} else if (*Fts5SegIter)(unsafe.Pointer(pSeg)).FpSeg == uintptr(0) {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			return
		} else {
			pgno++
			pData = fts5LeafRead(tls, p, I64((*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+int64(0)<<FTS5_DATA_PAGE_B+I64(pgno))
			if pData == uintptr(0) {
				break
			}
			pChunk = (*Fts5Data)(unsafe.Pointer(pData)).Fp + 4
			nChunk = func() int32 {
				if nRem < (*Fts5Data)(unsafe.Pointer(pData)).FszLeaf-4 {
					return nRem
				}
				return (*Fts5Data)(unsafe.Pointer(pData)).FszLeaf - 4
			}()
			if pgno == pgnoSave {
				(*Fts5SegIter)(unsafe.Pointer(pSeg)).FpNextLeaf = pData
				pData = uintptr(0)
			}
		}
	}
}

func fts5SegiterPoslist(tls *libc.TLS, p uintptr, pSeg uintptr, pColset uintptr, pBuf uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	if 0 == func() int32 {
		if U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn)+U32((*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos+FTS5_DATA_ZERO_PADDING) <= U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
			return 0
		}
		return sqlite3Fts5BufferSize(tls, p+52, pBuf, uint32((*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos+FTS5_DATA_ZERO_PADDING+(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn))
	}() {
		libc.Xmemset(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos), 0, uint64(FTS5_DATA_ZERO_PADDING))
		if pColset == uintptr(0) {
			fts5ChunkIterate(tls, p, pSeg, pBuf, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr, int32)
			}{fts5PoslistCallback})))
		} else {
			if (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == FTS5_DETAIL_FULL {
				(*PoslistCallbackCtx)(unsafe.Pointer(bp)).FpBuf = pBuf
				(*PoslistCallbackCtx)(unsafe.Pointer(bp)).FpColset = pColset
				(*PoslistCallbackCtx)(unsafe.Pointer(bp)).FeState = fts5IndexColsetTest(tls, pColset, 0)

				fts5ChunkIterate(tls, p, pSeg, bp, *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr, uintptr, int32)
				}{fts5PoslistFilterCallback})))
			} else {
				libc.Xmemset(tls, bp+24, 0, uint64(unsafe.Sizeof(PoslistOffsetsCtx{})))
				(*PoslistOffsetsCtx)(unsafe.Pointer(bp + 24)).FpBuf = pBuf
				(*PoslistOffsetsCtx)(unsafe.Pointer(bp + 24)).FpColset = pColset
				fts5ChunkIterate(tls, p, pSeg, bp+24, *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr, uintptr, int32)
				}{fts5PoslistOffsetsCallback})))
			}
		}
	}
}

func fts5IndexExtractColset(tls *libc.TLS, pRc uintptr, pColset uintptr, pPos uintptr, nPos int32, pIter uintptr) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var p uintptr = pPos
		var aCopy uintptr = p
		var pEnd uintptr = p + uintptr(nPos)
		var i int32 = 0
		*(*int32)(unsafe.Pointer(bp)) = 0

		if (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol > 1 && sqlite3Fts5BufferSize(tls, pRc, pIter+32, uint32(nPos)) != 0 {
			return
		}

		for 1 != 0 {
			for *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) < *(*int32)(unsafe.Pointer(bp)) {
				i++
				if i == (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol {
					(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
					(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
					return
				}
			}

			for p < pEnd && int32(*(*U8)(unsafe.Pointer(p))) != 0x01 {
				for int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&p, 1))))&0x80 != 0 {
				}
			}

			if *(*int32)(unsafe.Pointer(pColset + 4 + uintptr(i)*4)) == *(*int32)(unsafe.Pointer(bp)) {
				if (*Fts5Colset)(unsafe.Pointer(pColset)).FnCol == 1 {
					(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = aCopy
					(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = int32((int64(p) - int64(aCopy)) / 1)
					return
				}
				{
					libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(pIter+32)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pIter+32)).Fn), aCopy, uint64((int64(p)-int64(aCopy))/1))
					*(*int32)(unsafe.Pointer(pIter + 32 + 8)) += int32((int64(p) - int64(aCopy)) / 1)
				}

			}
			if p >= pEnd {
				(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
				(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
				return
			}
			aCopy = libc.PostIncUintptr(&p, 1)
			*(*int32)(unsafe.Pointer(bp)) = int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&p, 1))))
			if *(*int32)(unsafe.Pointer(bp))&0x80 != 0 {
				p--
				p += uintptr(sqlite3Fts5GetVarint32(tls, p, bp))
			}
		}
	}

}

func fts5IterSetOutputs_None(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos
}

func fts5IterSetOutputs_Nocolset(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos

	if (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset+I64((*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos) <= I64((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf) {
		(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp + uintptr((*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
	} else {
		sqlite3Fts5BufferZero(tls, pIter+32)
		fts5SegiterPoslist(tls, (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex, pSeg, uintptr(0), pIter+32)
		(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
	}
}

func fts5IterSetOutputs_ZeroColset(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	_ = pSeg
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = 0
}

func fts5IterSetOutputs_Col(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	sqlite3Fts5BufferZero(tls, pIter+32)
	fts5SegiterPoslist(tls, (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex, pSeg, (*Fts5Iter)(unsafe.Pointer(pIter)).FpColset, pIter+32)
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiRowid
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
}

func fts5IterSetOutputs_Col100(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	var a uintptr
	var pEnd uintptr
	var iPrev int32
	var aiCol uintptr
	var aiColEnd uintptr
	var aOut uintptr
	var iPrevOut int32

	if !((*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset+I64((*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos) > I64((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf)) {
		goto __1
	}
	fts5IterSetOutputs_Col(tls, pIter, pSeg)
	goto __2
__1:
	a = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp + uintptr((*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
	pEnd = a + uintptr((*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos)
	iPrev = 0
	aiCol = (*Fts5Iter)(unsafe.Pointer(pIter)).FpColset + 4
	aiColEnd = aiCol + uintptr((*Fts5Colset)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FpColset)).FnCol)*4
	aOut = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
	iPrevOut = 0

	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiRowid

__3:
	if !(a < pEnd) {
		goto __4
	}
	iPrev = iPrev + (int32(*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&a, 1)))) - 2)
__5:
	if !(*(*int32)(unsafe.Pointer(aiCol)) < iPrev) {
		goto __6
	}
	aiCol += 4
	if !(aiCol == aiColEnd) {
		goto __7
	}
	goto setoutputs_col_out
__7:
	;
	goto __5
__6:
	;
	if !(*(*int32)(unsafe.Pointer(aiCol)) == iPrev) {
		goto __8
	}
	*(*U8)(unsafe.Pointer(libc.PostIncUintptr(&aOut, 1))) = U8(iPrev - iPrevOut + 2)
	iPrevOut = iPrev
__8:
	;
	goto __3
__4:
	;
setoutputs_col_out:
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = int32((int64(aOut) - int64((*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp)) / 1)
__2:
}

func fts5IterSetOutputs_Full(tls *libc.TLS, pIter uintptr, pSeg uintptr) {
	var pColset uintptr = (*Fts5Iter)(unsafe.Pointer(pIter)).FpColset
	(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FiRowid = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiRowid

	if (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset+I64((*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos) <= I64((*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).FszLeaf) {
		var a uintptr = (*Fts5Data)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)).Fp + uintptr((*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafOffset)
		var pRc uintptr = (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex + 52
		sqlite3Fts5BufferZero(tls, pIter+32)
		fts5IndexExtractColset(tls, pRc, pColset, a, (*Fts5SegIter)(unsafe.Pointer(pSeg)).FnPos, pIter)
	} else {
		sqlite3Fts5BufferZero(tls, pIter+32)
		fts5SegiterPoslist(tls, (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex, pSeg, pColset, pIter+32)
		(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FpData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fp
		(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FnData = (*Fts5Iter)(unsafe.Pointer(pIter)).Fposlist.Fn
	}
}

func fts5IterSetOutputCb(tls *libc.TLS, pRc uintptr, pIter uintptr) {
	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		var pConfig uintptr = (*Fts5Index)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex)).FpConfig
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_NONE {
			(*Fts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr)
			}{fts5IterSetOutputs_None}))
		} else if (*Fts5Iter)(unsafe.Pointer(pIter)).FpColset == uintptr(0) {
			(*Fts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr)
			}{fts5IterSetOutputs_Nocolset}))
		} else if (*Fts5Colset)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FpColset)).FnCol == 0 {
			(*Fts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr)
			}{fts5IterSetOutputs_ZeroColset}))
		} else if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_FULL {
			(*Fts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr)
			}{fts5IterSetOutputs_Full}))
		} else {
			if (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol <= 100 {
				(*Fts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr)
				}{fts5IterSetOutputs_Col100}))
				sqlite3Fts5BufferSize(tls, pRc, pIter+32, uint32((*Fts5Config)(unsafe.Pointer(pConfig)).FnCol))
			} else {
				(*Fts5Iter)(unsafe.Pointer(pIter)).FxSetOutputs = *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, uintptr)
				}{fts5IterSetOutputs_Col}))
			}
		}
	}
}

func fts5MultiIterNew(tls *libc.TLS, p uintptr, pStruct uintptr, flags int32, pColset uintptr, pTerm uintptr, nTerm int32, iLevel int32, nSegment int32, ppOut uintptr) {
	var nSeg int32
	var iIter int32
	var iSeg int32
	var pLvl uintptr
	var pNew uintptr

	var pIter uintptr
	var pSeg uintptr
	var pIter1 uintptr
	var pEnd uintptr
	var pSeg1 uintptr
	var iEq int32
	var pSeg2 uintptr
	nSeg = 0
	iIter = 0

	if !((*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
		goto __1
	}
	if !(iLevel < 0) {
		goto __2
	}

	nSeg = (*Fts5Structure)(unsafe.Pointer(pStruct)).FnSegment
	nSeg = nSeg + func() int32 {
		if (*Fts5Index)(unsafe.Pointer(p)).FpHash != 0 {
			return 1
		}
		return 0
	}()
	goto __3
__2:
	nSeg = func() int32 {
		if (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLevel)*16)).FnSeg < nSegment {
			return (*Fts5StructureLevel)(unsafe.Pointer(pStruct + 24 + uintptr(iLevel)*16)).FnSeg
		}
		return nSegment
	}()
__3:
	;
__1:
	;
	*(*uintptr)(unsafe.Pointer(ppOut)) = libc.AssignUintptr(&pNew, fts5MultiIterAlloc(tls, p, nSeg))
	if !(pNew == uintptr(0)) {
		goto __4
	}

	goto fts5MultiIterNew_post_check
__4:
	;
	(*Fts5Iter)(unsafe.Pointer(pNew)).FbRev = libc.Bool32(0 != flags&FTS5INDEX_QUERY_DESC)
	(*Fts5Iter)(unsafe.Pointer(pNew)).FbSkipEmpty = U8(libc.Bool32(0 != flags&FTS5INDEX_QUERY_SKIPEMPTY))
	(*Fts5Iter)(unsafe.Pointer(pNew)).FpColset = pColset
	if !(flags&FTS5INDEX_QUERY_NOOUTPUT == 0) {
		goto __5
	}
	fts5IterSetOutputCb(tls, p+52, pNew)
__5:
	;
	if !((*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
		goto __6
	}
	if !(iLevel < 0) {
		goto __7
	}
	pEnd = pStruct + 24 + uintptr((*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel)*16
	if !((*Fts5Index)(unsafe.Pointer(p)).FpHash != 0) {
		goto __9
	}

	pIter = pNew + 96 + uintptr(libc.PostIncInt32(&iIter, 1))*120
	fts5SegIterHashInit(tls, p, pTerm, nTerm, flags, pIter)
__9:
	;
	pLvl = pStruct + 24
__10:
	if !(pLvl < pEnd) {
		goto __12
	}
	iSeg = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg - 1
__13:
	if !(iSeg >= 0) {
		goto __15
	}
	pSeg = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*12
	pIter1 = pNew + 96 + uintptr(libc.PostIncInt32(&iIter, 1))*120
	if !(pTerm == uintptr(0)) {
		goto __16
	}
	fts5SegIterInit(tls, p, pSeg, pIter1)
	goto __17
__16:
	fts5SegIterSeekInit(tls, p, pTerm, nTerm, flags, pSeg, pIter1)
__17:
	;
	goto __14
__14:
	iSeg--
	goto __13
	goto __15
__15:
	;
	goto __11
__11:
	pLvl += 16
	goto __10
	goto __12
__12:
	;
	goto __8
__7:
	pLvl = pStruct + 24 + uintptr(iLevel)*16
	iSeg = nSeg - 1
__18:
	if !(iSeg >= 0) {
		goto __20
	}
	fts5SegIterInit(tls, p, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(iSeg)*12, pNew+96+uintptr(libc.PostIncInt32(&iIter, 1))*120)
	goto __19
__19:
	iSeg--
	goto __18
	goto __20
__20:
	;
__8:
	;
__6:
	;
	if !((*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
		goto __21
	}
	iIter = (*Fts5Iter)(unsafe.Pointer(pNew)).FnSeg - 1
__23:
	if !(iIter > 0) {
		goto __25
	}
	if !(libc.AssignInt32(&iEq, fts5MultiIterDoCompare(tls, pNew, iIter)) != 0) {
		goto __26
	}
	pSeg1 = pNew + 96 + uintptr(iEq)*120
	if !((*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK) {
		goto __27
	}
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5SegIter)(unsafe.Pointer(pSeg1)).FxNext})).f(tls, p, pSeg1, uintptr(0))
__27:
	;
	fts5MultiIterAdvanced(tls, p, pNew, iEq, iIter)
__26:
	;
	goto __24
__24:
	iIter--
	goto __23
	goto __25
__25:
	;
	fts5MultiIterSetEof(tls, pNew)

	if !((*Fts5Iter)(unsafe.Pointer(pNew)).FbSkipEmpty != 0 && fts5MultiIterIsEmpty(tls, p, pNew) != 0) {
		goto __28
	}
	fts5MultiIterNext(tls, p, pNew, 0, int64(0))
	goto __29
__28:
	if !(int32((*Fts5Iter)(unsafe.Pointer(pNew)).Fbase.FbEof) == 0) {
		goto __30
	}
	pSeg2 = pNew + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pNew)).FaFirst+1*4)).FiFirst)*120
	(*struct {
		f func(*libc.TLS, uintptr, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5Iter)(unsafe.Pointer(pNew)).FxSetOutputs})).f(tls, pNew, pSeg2)
__30:
	;
__29:
	;
	goto __22
__21:
	fts5MultiIterFree(tls, pNew)
	*(*uintptr)(unsafe.Pointer(ppOut)) = uintptr(0)
__22:
	;
fts5MultiIterNew_post_check:
	;
	return
}

func fts5MultiIterNew2(tls *libc.TLS, p uintptr, pData uintptr, bDesc int32, ppOut uintptr) {
	var pNew uintptr
	pNew = fts5MultiIterAlloc(tls, p, 2)
	if pNew != 0 {
		var pIter uintptr = pNew + 96 + 1*120

		(*Fts5SegIter)(unsafe.Pointer(pIter)).Fflags = FTS5_SEGITER_ONETERM
		if (*Fts5Data)(unsafe.Pointer(pData)).FszLeaf > 0 {
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FpLeaf = pData
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FiLeafOffset = I64(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp, pIter+104))
			(*Fts5SegIter)(unsafe.Pointer(pIter)).FiEndofDoclist = (*Fts5Data)(unsafe.Pointer(pData)).Fnn
			(*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pNew)).FaFirst + 1*4)).FiFirst = U16(1)
			if bDesc != 0 {
				(*Fts5Iter)(unsafe.Pointer(pNew)).FbRev = 1
				*(*int32)(unsafe.Pointer(pIter + 8)) |= FTS5_SEGITER_REVERSE
				fts5SegIterReverseInitPage(tls, p, pIter)
			} else {
				fts5SegIterLoadNPos(tls, p, pIter)
			}
			pData = uintptr(0)
		} else {
			(*Fts5Iter)(unsafe.Pointer(pNew)).Fbase.FbEof = U8(1)
		}
		fts5SegIterSetNext(tls, p, pIter)

		*(*uintptr)(unsafe.Pointer(ppOut)) = pNew
	}

	fts5DataRelease(tls, pData)
}

func fts5MultiIterEof(tls *libc.TLS, p uintptr, pIter uintptr) int32 {
	return libc.Bool32((*Fts5Index)(unsafe.Pointer(p)).Frc != 0 || (*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof != 0)
}

func fts5MultiIterRowid(tls *libc.TLS, pIter uintptr) I64 {
	return (*Fts5SegIter)(unsafe.Pointer(pIter + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst+1*4)).FiFirst)*120)).FiRowid
}

func fts5MultiIterNextFrom(tls *libc.TLS, p uintptr, pIter uintptr, iMatch I64) {
	for 1 != 0 {
		var iRowid I64
		fts5MultiIterNext(tls, p, pIter, 1, iMatch)
		if fts5MultiIterEof(tls, p, pIter) != 0 {
			break
		}
		iRowid = fts5MultiIterRowid(tls, pIter)
		if (*Fts5Iter)(unsafe.Pointer(pIter)).FbRev == 0 && iRowid >= iMatch {
			break
		}
		if (*Fts5Iter)(unsafe.Pointer(pIter)).FbRev != 0 && iRowid <= iMatch {
			break
		}
	}
}

func fts5MultiIterTerm(tls *libc.TLS, pIter uintptr, pn uintptr) uintptr {
	var p uintptr = pIter + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst+1*4)).FiFirst)*120
	*(*int32)(unsafe.Pointer(pn)) = (*Fts5SegIter)(unsafe.Pointer(p)).Fterm.Fn
	return (*Fts5SegIter)(unsafe.Pointer(p)).Fterm.Fp
}

func fts5AllocateSegid(tls *libc.TLS, p uintptr, pStruct uintptr) int32 {
	bp := tls.Alloc(252)
	defer tls.Free(252)

	var iSegid int32 = 0

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*Fts5Structure)(unsafe.Pointer(pStruct)).FnSegment >= FTS5_MAX_SEGMENT {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_FULL
		} else {
			var iLvl int32
			var iSeg int32
			var i int32
			var mask U32
			libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof([63]U32{})))
			for iLvl = 0; iLvl < (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel; iLvl++ {
				for iSeg = 0; iSeg < (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLvl)*16)).FnSeg; iSeg++ {
					var iId int32 = (*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLvl)*16)).FaSeg + uintptr(iSeg)*12)).FiSegid
					if iId <= FTS5_MAX_SEGMENT && iId > 0 {
						*(*U32)(unsafe.Pointer(bp + uintptr((iId-1)/32)*4)) |= U32(1) << ((iId - 1) % 32)
					}
				}
			}

			for i = 0; *(*U32)(unsafe.Pointer(bp + uintptr(i)*4)) == 0xFFFFFFFF; i++ {
			}
			mask = *(*U32)(unsafe.Pointer(bp + uintptr(i)*4))
			for iSegid = 0; mask&(U32(1)<<iSegid) != 0; iSegid++ {
			}
			iSegid = iSegid + (1 + i*32)

		}
	}

	return iSegid
}

func fts5IndexDiscardData(tls *libc.TLS, p uintptr) {
	if (*Fts5Index)(unsafe.Pointer(p)).FpHash != 0 {
		sqlite3Fts5HashClear(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash)
		(*Fts5Index)(unsafe.Pointer(p)).FnPendingData = 0
	}
}

func fts5PrefixCompress(tls *libc.TLS, nOld int32, pOld uintptr, pNew uintptr) int32 {
	var i int32
	for i = 0; i < nOld; i++ {
		if int32(*(*U8)(unsafe.Pointer(pOld + uintptr(i)))) != int32(*(*U8)(unsafe.Pointer(pNew + uintptr(i)))) {
			break
		}
	}
	return i
}

func fts5WriteDlidxClear(tls *libc.TLS, p uintptr, pWriter uintptr, bFlush int32) {
	var i int32

	for i = 0; i < (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx; i++ {
		var pDlidx uintptr = (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx + uintptr(i)*32
		if (*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fn == 0 {
			break
		}
		if bFlush != 0 {
			fts5DataWrite(tls, p,
				I64((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(1)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+I64(i)<<FTS5_DATA_PAGE_B+I64((*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno),
				(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fp, (*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fn)
		}
		sqlite3Fts5BufferZero(tls, pDlidx+16)
		(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).FbPrevValid = 0
	}
}

func fts5WriteDlidxGrow(tls *libc.TLS, p uintptr, pWriter uintptr, nLvl int32) int32 {
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && nLvl >= (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx {
		var aDlidx uintptr = Xsqlite3_realloc64(tls,
			(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx, uint64(unsafe.Sizeof(Fts5DlidxWriter{}))*uint64(nLvl))
		if aDlidx == uintptr(0) {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_NOMEM
		} else {
			var nByte Size_t = uint64(unsafe.Sizeof(Fts5DlidxWriter{})) * uint64(nLvl-(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx)
			libc.Xmemset(tls, aDlidx+uintptr((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx)*32, 0, nByte)
			(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx = aDlidx
			(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx = nLvl
		}
	}
	return (*Fts5Index)(unsafe.Pointer(p)).Frc
}

func fts5WriteFlushDlidx(tls *libc.TLS, p uintptr, pWriter uintptr) int32 {
	var bFlag int32 = 0

	if (*Fts5DlidxWriter)(unsafe.Pointer((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx)).Fbuf.Fn > 0 && (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnEmpty >= FTS5_MIN_DLIDX_SIZE {
		bFlag = 1
	}
	fts5WriteDlidxClear(tls, p, pWriter, bFlag)
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnEmpty = 0
	return bFlag
}

func fts5WriteFlushBtree(tls *libc.TLS, p uintptr, pWriter uintptr) {
	var bFlag int32

	if (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage == 0 {
		return
	}
	bFlag = fts5WriteFlushDlidx(tls, p, pWriter)

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var z uintptr = func() uintptr {
			if (*Fts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fn > 0 {
				return (*Fts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fp
			}
			return ts + 1636
		}()

		Xsqlite3_bind_blob(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxWriter, 2, z, (*Fts5SegWriter)(unsafe.Pointer(pWriter)).Fbtterm.Fn, uintptr(0))
		Xsqlite3_bind_int64(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxWriter, 3, I64(bFlag)+I64((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage)<<1)
		Xsqlite3_step(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		(*Fts5Index)(unsafe.Pointer(p)).Frc = Xsqlite3_reset(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		Xsqlite3_bind_null(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxWriter, 2)
	}
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = 0
}

func fts5WriteBtreeTerm(tls *libc.TLS, p uintptr, pWriter uintptr, nTerm int32, pTerm uintptr) {
	fts5WriteFlushBtree(tls, p, pWriter)
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		sqlite3Fts5BufferSet(tls, p+52, pWriter+96, nTerm, pTerm)
		(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = (*Fts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fpgno
	}
}

func fts5WriteBtreeNoTerm(tls *libc.TLS, p uintptr, pWriter uintptr) {
	if (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage != 0 && (*Fts5DlidxWriter)(unsafe.Pointer((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx)).Fbuf.Fn > 0 {
		var pDlidx uintptr = (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx

		sqlite3Fts5BufferAppendVarint(tls, p+52, pDlidx+16, int64(0))
	}

	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnEmpty++
}

func fts5DlidxExtractFirstRowid(tls *libc.TLS, pBuf uintptr) I64 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var iOff int32

	iOff = 1 + int32(sqlite3Fts5GetVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+1, bp))
	sqlite3Fts5GetVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr(iOff), bp)
	return *(*I64)(unsafe.Pointer(bp))
}

func fts5WriteDlidxAppend(tls *libc.TLS, p uintptr, pWriter uintptr, iRowid I64) {
	var i int32
	var bDone int32 = 0

	for i = 0; (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bDone == 0; i++ {
		var iVal I64
		var pDlidx uintptr = (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx + uintptr(i)*32

		if (*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fn >= (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz {
			*(*U8)(unsafe.Pointer((*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fp)) = U8(0x01)
			fts5DataWrite(tls, p,
				I64((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(1)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+I64(i)<<FTS5_DATA_PAGE_B+I64((*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno),
				(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fp, (*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fbuf.Fn)
			fts5WriteDlidxGrow(tls, p, pWriter, i+2)
			pDlidx = (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx + uintptr(i)*32
			if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5DlidxWriter)(unsafe.Pointer(pDlidx+1*32)).Fbuf.Fn == 0 {
				var iFirst I64 = fts5DlidxExtractFirstRowid(tls, pDlidx+16)

				(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx + 1*32)).Fpgno = (*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno
				sqlite3Fts5BufferAppendVarint(tls, p+52, pDlidx+1*32+16, int64(0))
				sqlite3Fts5BufferAppendVarint(tls, p+52, pDlidx+1*32+16, int64((*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno))
				sqlite3Fts5BufferAppendVarint(tls, p+52, pDlidx+1*32+16, iFirst)
				(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx + 1*32)).FbPrevValid = 1
				(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx + 1*32)).FiPrev = iFirst
			}

			sqlite3Fts5BufferZero(tls, pDlidx+16)
			(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).FbPrevValid = 0
			(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).Fpgno++
		} else {
			bDone = 1
		}

		if (*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).FbPrevValid != 0 {
			iVal = iRowid - (*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).FiPrev
		} else {
			var iPgno I64 = func() int64 {
				if i == 0 {
					return int64((*Fts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fpgno)
				}
				return int64((*Fts5DlidxWriter)(unsafe.Pointer(pDlidx + libc.UintptrFromInt32(-1)*32)).Fpgno)
			}()

			sqlite3Fts5BufferAppendVarint(tls, p+52, pDlidx+16, libc.BoolInt64(!(bDone != 0)))
			sqlite3Fts5BufferAppendVarint(tls, p+52, pDlidx+16, iPgno)
			iVal = iRowid
		}

		sqlite3Fts5BufferAppendVarint(tls, p+52, pDlidx+16, iVal)
		(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).FbPrevValid = 1
		(*Fts5DlidxWriter)(unsafe.Pointer(pDlidx)).FiPrev = iRowid
	}
}

func fts5WriteFlushLeaf(tls *libc.TLS, p uintptr, pWriter uintptr) {
	var pPage uintptr = pWriter + 8
	var iRowid I64

	fts5PutU16(tls, (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fp+2, U16((*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn))

	if (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage != 0 {
		fts5WriteBtreeNoTerm(tls, p, pWriter)
	} else {
		sqlite3Fts5BufferAppendBlob(tls, p+52, pPage+8, uint32((*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fn), (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fp)
	}

	iRowid = I64((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + I64((*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgno)
	fts5DataWrite(tls, p, iRowid, (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fp, (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn)

	sqlite3Fts5BufferZero(tls, pPage+8)
	sqlite3Fts5BufferZero(tls, pPage+24)
	sqlite3Fts5BufferAppendBlob(tls, p+52, pPage+8, uint32(4), uintptr(unsafe.Pointer(&zero)))
	(*Fts5PageWriter)(unsafe.Pointer(pPage)).FiPrevPgidx = 0
	(*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgno++

	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnLeafWritten++

	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage = U8(1)
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage = U8(1)
}

var zero = [4]U8{U8(0x00), U8(0x00), U8(0x00), U8(0x00)}

func fts5WriteAppendTerm(tls *libc.TLS, p uintptr, pWriter uintptr, nTerm int32, pTerm uintptr) {
	var nPrefix int32
	var pPage uintptr = pWriter + 8
	var pPgidx uintptr = pWriter + 8 + 24
	var nMin int32 = func() int32 {
		if (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fn < nTerm {
			return (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fn
		}
		return nTerm
	}()

	if (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn+(*Fts5Buffer)(unsafe.Pointer(pPgidx)).Fn+nTerm+2 >= (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz {
		if (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn > 4 {
			fts5WriteFlushLeaf(tls, p, pWriter)
			if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				return
			}
		}
		if !(U32((*Fts5Buffer)(unsafe.Pointer(pPage+8)).Fn)+U32(nTerm+FTS5_DATA_PADDING) <= U32((*Fts5Buffer)(unsafe.Pointer(pPage+8)).FnSpace)) {
			sqlite3Fts5BufferSize(tls, p+52, pPage+8, uint32(nTerm+FTS5_DATA_PADDING+(*Fts5Buffer)(unsafe.Pointer(pPage+8)).Fn))
		}
	}

	*(*int32)(unsafe.Pointer(pPgidx + 8)) += sqlite3Fts5PutVarint(tls,
		(*Fts5Buffer)(unsafe.Pointer(pPgidx)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pPgidx)).Fn), uint64((*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn-(*Fts5PageWriter)(unsafe.Pointer(pPage)).FiPrevPgidx))
	(*Fts5PageWriter)(unsafe.Pointer(pPage)).FiPrevPgidx = (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn

	if (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage != 0 {
		nPrefix = 0
		if (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgno != 1 {
			var n int32 = nTerm
			if (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fn != 0 {
				n = 1 + fts5PrefixCompress(tls, nMin, (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fp, pTerm)
			}
			fts5WriteBtreeTerm(tls, p, pWriter, n, pTerm)
			if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				return
			}
			pPage = pWriter + 8
		}
	} else {
		nPrefix = fts5PrefixCompress(tls, nMin, (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fterm.Fp, pTerm)
		sqlite3Fts5BufferAppendVarint(tls, p+52, pPage+8, I64(nPrefix))
	}

	sqlite3Fts5BufferAppendVarint(tls, p+52, pPage+8, I64(nTerm)-I64(nPrefix))
	sqlite3Fts5BufferAppendBlob(tls, p+52, pPage+8, uint32(nTerm-nPrefix), pTerm+uintptr(nPrefix))

	sqlite3Fts5BufferSet(tls, p+52, pPage+40, nTerm, pTerm)
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage = U8(0)

	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage = U8(0)
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInDoclist = U8(1)

	(*Fts5DlidxWriter)(unsafe.Pointer((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx)).Fpgno = (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgno
}

func fts5WriteAppendRowid(tls *libc.TLS, p uintptr, pWriter uintptr, iRowid I64) {
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var pPage uintptr = pWriter + 8

		if (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn+(*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fn >= (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz {
			fts5WriteFlushLeaf(tls, p, pWriter)
		}

		if (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage != 0 {
			fts5PutU16(tls, (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fp, U16((*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn))
			fts5WriteDlidxAppend(tls, p, pWriter, iRowid)
		}

		if (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInDoclist != 0 || (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage != 0 {
			sqlite3Fts5BufferAppendVarint(tls, p+52, pPage+8, iRowid)
		} else {
			sqlite3Fts5BufferAppendVarint(tls, p+52, pPage+8, int64(U64(I64(U64(iRowid)))-U64((*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiPrevRowid)))
		}
		(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiPrevRowid = iRowid
		(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInDoclist = U8(0)
		(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstRowidInPage = U8(0)
	}
}

func fts5WriteAppendPoslistData(tls *libc.TLS, p uintptr, pWriter uintptr, aData uintptr, nData int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pPage uintptr = pWriter + 8
	var a uintptr = aData
	var n int32 = nData

	for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK &&
		(*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn+(*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fn+n >= (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz {
		var nReq int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz - (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fbuf.Fn - (*Fts5PageWriter)(unsafe.Pointer(pPage)).Fpgidx.Fn
		var nCopy int32 = 0
		for nCopy < nReq {
			nCopy = nCopy + int32(sqlite3Fts5GetVarint(tls, a+uintptr(nCopy), bp))
		}
		sqlite3Fts5BufferAppendBlob(tls, p+52, pPage+8, uint32(nCopy), a)
		a += uintptr(nCopy)
		n = n - nCopy
		fts5WriteFlushLeaf(tls, p, pWriter)
	}
	if n > 0 {
		sqlite3Fts5BufferAppendBlob(tls, p+52, pPage+8, uint32(n), a)
	}
}

func fts5WriteFinish(tls *libc.TLS, p uintptr, pWriter uintptr, pnLeaf uintptr) {
	var i int32
	var pLeaf uintptr = pWriter + 8
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if (*Fts5PageWriter)(unsafe.Pointer(pLeaf)).Fbuf.Fn > 4 {
			fts5WriteFlushLeaf(tls, p, pWriter)
		}
		*(*int32)(unsafe.Pointer(pnLeaf)) = (*Fts5PageWriter)(unsafe.Pointer(pLeaf)).Fpgno - 1
		if (*Fts5PageWriter)(unsafe.Pointer(pLeaf)).Fpgno > 1 {
			fts5WriteFlushBtree(tls, p, pWriter)
		}
	}
	sqlite3Fts5BufferFree(tls, pLeaf+40)
	sqlite3Fts5BufferFree(tls, pLeaf+8)
	sqlite3Fts5BufferFree(tls, pLeaf+24)
	sqlite3Fts5BufferFree(tls, pWriter+96)

	for i = 0; i < (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FnDlidx; i++ {
		sqlite3Fts5BufferFree(tls, (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx+uintptr(i)*32+16)
	}
	Xsqlite3_free(tls, (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FaDlidx)
}

func fts5WriteInit(tls *libc.TLS, p uintptr, pWriter uintptr, iSegid int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var nBuffer int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz + FTS5_DATA_PADDING

	libc.Xmemset(tls, pWriter, 0, uint64(unsafe.Sizeof(Fts5SegWriter{})))
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid = iSegid

	fts5WriteDlidxGrow(tls, p, pWriter, 1)
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fpgno = 1
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FbFirstTermInPage = U8(1)
	(*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiBtPage = 1

	sqlite3Fts5BufferSize(tls, p+52, pWriter+8+24, uint32(nBuffer))
	sqlite3Fts5BufferSize(tls, p+52, pWriter+8+8, uint32(nBuffer))

	if (*Fts5Index)(unsafe.Pointer(p)).FpIdxWriter == uintptr(0) {
		var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig
		fts5IndexPrepareStmt(tls, p, p+80, Xsqlite3_mprintf(tls,
			ts+42336,
			libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName)))
	}

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		libc.Xmemset(tls, (*Fts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fbuf.Fp, 0, uint64(4))
		(*Fts5SegWriter)(unsafe.Pointer(pWriter)).Fwriter.Fbuf.Fn = 4

		Xsqlite3_bind_int(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxWriter, 1, (*Fts5SegWriter)(unsafe.Pointer(pWriter)).FiSegid)
	}
}

func fts5TrimSegments(tls *libc.TLS, p uintptr, pIter uintptr) {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var i int32

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))
	for i = 0; i < (*Fts5Iter)(unsafe.Pointer(pIter)).FnSeg && (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK; i++ {
		var pSeg uintptr = pIter + 96 + uintptr(i)*120
		if (*Fts5SegIter)(unsafe.Pointer(pSeg)).FpSeg == uintptr(0) {
		} else if (*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf == uintptr(0) {
			(*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoLast = 0
			(*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoFirst = 0
		} else {
			var iOff int32 = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafOffset
			var iLeafRowid I64
			var pData uintptr
			var iId int32 = (*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FiSegid
			*(*[4]U8)(unsafe.Pointer(bp + 16)) = [4]U8{U8(0x00), U8(0x00), U8(0x00), U8(0x00)}

			iLeafRowid = I64(iId)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + I64((*Fts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno)
			pData = fts5LeafRead(tls, p, iLeafRowid)
			if pData != 0 {
				if iOff > (*Fts5Data)(unsafe.Pointer(pData)).FszLeaf {
					(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
				} else {
					sqlite3Fts5BufferZero(tls, bp)
					if !(U32((*Fts5Buffer)(unsafe.Pointer(bp)).Fn)+U32((*Fts5Data)(unsafe.Pointer(pData)).Fnn) <= U32((*Fts5Buffer)(unsafe.Pointer(bp)).FnSpace)) {
						sqlite3Fts5BufferSize(tls, p+52, bp, uint32((*Fts5Data)(unsafe.Pointer(pData)).Fnn+(*Fts5Buffer)(unsafe.Pointer(bp)).Fn))
					}
					sqlite3Fts5BufferAppendBlob(tls, p+52, bp, uint32(unsafe.Sizeof([4]U8{})), bp+16)
					sqlite3Fts5BufferAppendVarint(tls, p+52, bp, I64((*Fts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn))
					sqlite3Fts5BufferAppendBlob(tls, p+52, bp, uint32((*Fts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn), (*Fts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fp)
					sqlite3Fts5BufferAppendBlob(tls, p+52, bp, uint32((*Fts5Data)(unsafe.Pointer(pData)).FszLeaf-iOff), (*Fts5Data)(unsafe.Pointer(pData)).Fp+uintptr(iOff))
					if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
						fts5PutU16(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp+2, U16((*Fts5Buffer)(unsafe.Pointer(bp)).Fn))
					}

					sqlite3Fts5BufferAppendVarint(tls, p+52, bp, int64(4))
					if (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiLeafPgno == (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno &&
						(*Fts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist < (*Fts5Data)(unsafe.Pointer(pData)).FszLeaf &&
						(*Fts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff <= (*Fts5Data)(unsafe.Pointer(pData)).Fnn {
						var nDiff int32 = (*Fts5Data)(unsafe.Pointer(pData)).FszLeaf - (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiEndofDoclist
						sqlite3Fts5BufferAppendVarint(tls, p+52, bp, I64((*Fts5Buffer)(unsafe.Pointer(bp)).Fn)-int64(1)-I64(nDiff)-int64(4))
						sqlite3Fts5BufferAppendBlob(tls, p+52, bp, uint32((*Fts5Data)(unsafe.Pointer(pData)).Fnn-(*Fts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff), (*Fts5Data)(unsafe.Pointer(pData)).Fp+uintptr((*Fts5SegIter)(unsafe.Pointer(pSeg)).FiPgidxOff))
					}

					(*Fts5StructureSegment)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).FpSeg)).FpgnoFirst = (*Fts5SegIter)(unsafe.Pointer(pSeg)).FiTermLeafPgno
					fts5DataDelete(tls, p, I64(iId)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+int64(0)<<FTS5_DATA_PAGE_B+int64(1), iLeafRowid)
					fts5DataWrite(tls, p, iLeafRowid, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp, (*Fts5Buffer)(unsafe.Pointer(bp)).Fn)
				}
				fts5DataRelease(tls, pData)
			}
		}
	}
	sqlite3Fts5BufferFree(tls, bp)
}

func fts5MergeChunkCallback(tls *libc.TLS, p uintptr, pCtx uintptr, pChunk uintptr, nChunk int32) {
	var pWriter uintptr = pCtx
	fts5WriteAppendPoslistData(tls, p, pWriter, pChunk, nChunk)
}

func fts5IndexMergeLevel(tls *libc.TLS, p uintptr, ppStruct uintptr, iLvl int32, pnRem uintptr) {
	bp := tls.Alloc(148)
	defer tls.Free(148)

	var pStruct uintptr = *(*uintptr)(unsafe.Pointer(ppStruct))
	var pLvl uintptr = pStruct + 24 + uintptr(iLvl)*16
	var pLvlOut uintptr
	*(*uintptr)(unsafe.Pointer(bp + 136)) = uintptr(0)
	var nRem int32
	if pnRem != 0 {
		nRem = *(*int32)(unsafe.Pointer(pnRem))
	} else {
		nRem = 0
	}
	var nInput int32

	var pSeg uintptr

	var bOldest int32
	var eDetail int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
	var flags int32 = FTS5INDEX_QUERY_NOOUTPUT
	var bTermWritten int32 = 0

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5SegWriter{})))
	libc.Xmemset(tls, bp+120, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))
	if (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
		pLvlOut = pStruct + 24 + uintptr(iLvl+1)*16

		nInput = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge
		pSeg = (*Fts5StructureLevel)(unsafe.Pointer(pLvlOut)).FaSeg + uintptr((*Fts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg-1)*12

		fts5WriteInit(tls, p, bp, (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)
		(*Fts5SegWriter)(unsafe.Pointer(bp)).Fwriter.Fpgno = (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast + 1
		(*Fts5SegWriter)(unsafe.Pointer(bp)).FiBtPage = 0
	} else {
		var iSegid int32 = fts5AllocateSegid(tls, p, pStruct)

		if iLvl == (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel-1 {
			fts5StructureAddLevel(tls, p+52, ppStruct)
			pStruct = *(*uintptr)(unsafe.Pointer(ppStruct))
		}
		fts5StructureExtendLevel(tls, p+52, pStruct, iLvl+1, 1, 0)
		if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
			return
		}
		pLvl = pStruct + 24 + uintptr(iLvl)*16
		pLvlOut = pStruct + 24 + uintptr(iLvl+1)*16

		fts5WriteInit(tls, p, bp, iSegid)

		pSeg = (*Fts5StructureLevel)(unsafe.Pointer(pLvlOut)).FaSeg + uintptr((*Fts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg)*12
		(*Fts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg++
		(*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst = 1
		(*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid = iSegid
		(*Fts5Structure)(unsafe.Pointer(pStruct)).FnSegment++

		nInput = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg
	}
	bOldest = libc.Bool32((*Fts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg == 1 && (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel == iLvl+2)

	for fts5MultiIterNew(tls, p, pStruct, flags, uintptr(0), uintptr(0), 0, iLvl, nInput, bp+136); fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp + 136))) == 0; fts5MultiIterNext(tls, p, *(*uintptr)(unsafe.Pointer(bp + 136)), 0, int64(0)) {
		var pSegIter uintptr = *(*uintptr)(unsafe.Pointer(bp + 136)) + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 136)))).FaFirst+1*4)).FiFirst)*120
		var nPos int32

		var pTerm uintptr

		pTerm = fts5MultiIterTerm(tls, *(*uintptr)(unsafe.Pointer(bp + 136)), bp+144)
		if *(*int32)(unsafe.Pointer(bp + 144)) != (*Fts5Buffer)(unsafe.Pointer(bp+120)).Fn || func() int32 {
			if *(*int32)(unsafe.Pointer(bp + 144)) <= 0 {
				return 0
			}
			return libc.Xmemcmp(tls, pTerm, (*Fts5Buffer)(unsafe.Pointer(bp+120)).Fp, uint64(*(*int32)(unsafe.Pointer(bp + 144))))
		}() != 0 {
			if pnRem != 0 && (*Fts5SegWriter)(unsafe.Pointer(bp)).FnLeafWritten > nRem {
				break
			}
			sqlite3Fts5BufferSet(tls, p+52, bp+120, *(*int32)(unsafe.Pointer(bp + 144)), pTerm)
			bTermWritten = 0
		}

		if (*Fts5SegIter)(unsafe.Pointer(pSegIter)).FnPos == 0 && (bOldest != 0 || int32((*Fts5SegIter)(unsafe.Pointer(pSegIter)).FbDel) == 0) {
			continue
		}

		if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bTermWritten == 0 {
			fts5WriteAppendTerm(tls, p, bp, *(*int32)(unsafe.Pointer(bp + 144)), pTerm)
			bTermWritten = 1
		}

		fts5WriteAppendRowid(tls, p, bp, fts5MultiIterRowid(tls, *(*uintptr)(unsafe.Pointer(bp + 136))))

		if eDetail == FTS5_DETAIL_NONE {
			if (*Fts5SegIter)(unsafe.Pointer(pSegIter)).FbDel != 0 {
				sqlite3Fts5BufferAppendVarint(tls, p+52, bp+8+8, int64(0))
				if (*Fts5SegIter)(unsafe.Pointer(pSegIter)).FnPos > 0 {
					sqlite3Fts5BufferAppendVarint(tls, p+52, bp+8+8, int64(0))
				}
			}
		} else {
			nPos = (*Fts5SegIter)(unsafe.Pointer(pSegIter)).FnPos*2 + int32((*Fts5SegIter)(unsafe.Pointer(pSegIter)).FbDel)
			sqlite3Fts5BufferAppendVarint(tls, p+52, bp+8+8, I64(nPos))
			fts5ChunkIterate(tls, p, pSegIter, bp, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr, int32)
			}{fts5MergeChunkCallback})))
		}
	}

	fts5WriteFinish(tls, p, bp, pSeg+8)

	if fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp + 136))) != 0 {
		var i int32

		for i = 0; i < nInput; i++ {
			fts5DataRemoveSegment(tls, p, (*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(i)*12)).FiSegid)
		}

		if (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg != nInput {
			var nMove int32 = int32(uint64((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg-nInput) * uint64(unsafe.Sizeof(Fts5StructureSegment{})))
			libc.Xmemmove(tls, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg+uintptr(nInput)*12, uint64(nMove))
		}
		*(*int32)(unsafe.Pointer(pStruct + 16)) -= nInput
		*(*int32)(unsafe.Pointer(pLvl + 4)) -= nInput
		(*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge = 0
		if (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast == 0 {
			(*Fts5StructureLevel)(unsafe.Pointer(pLvlOut)).FnSeg--
			(*Fts5Structure)(unsafe.Pointer(pStruct)).FnSegment--
		}
	} else {
		fts5TrimSegments(tls, p, *(*uintptr)(unsafe.Pointer(bp + 136)))
		(*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge = nInput
	}

	fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp + 136)))
	sqlite3Fts5BufferFree(tls, bp+120)
	if pnRem != 0 {
		*(*int32)(unsafe.Pointer(pnRem)) -= (*Fts5SegWriter)(unsafe.Pointer(bp)).FnLeafWritten
	}
}

func fts5IndexMerge(tls *libc.TLS, p uintptr, ppStruct uintptr, nPg int32, nMin int32) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	*(*int32)(unsafe.Pointer(bp + 8)) = nPg
	var bRet int32 = 0
	*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(ppStruct))
	for *(*int32)(unsafe.Pointer(bp + 8)) > 0 && (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var iLvl int32
		var iBestLvl int32 = 0
		var nBest int32 = 0

		for iLvl = 0; iLvl < (*Fts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FnLevel; iLvl++ {
			var pLvl uintptr = *(*uintptr)(unsafe.Pointer(bp)) + 24 + uintptr(iLvl)*16
			if (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge != 0 {
				if (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge > nBest {
					iBestLvl = iLvl
					nBest = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge
				}
				break
			}
			if (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg > nBest {
				nBest = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg
				iBestLvl = iLvl
			}
		}

		if nBest < nMin && (*Fts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))+24+uintptr(iBestLvl)*16)).FnMerge == 0 {
			break
		}
		bRet = 1
		fts5IndexMergeLevel(tls, p, bp, iBestLvl, bp+8)
		if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))+24+uintptr(iBestLvl)*16)).FnMerge == 0 {
			fts5StructurePromote(tls, p, iBestLvl+1, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}
	*(*uintptr)(unsafe.Pointer(ppStruct)) = *(*uintptr)(unsafe.Pointer(bp))
	return bRet
}

func fts5IndexAutomerge(tls *libc.TLS, p uintptr, ppStruct uintptr, nLeaf int32) {
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FnAutomerge > 0 && *(*uintptr)(unsafe.Pointer(ppStruct)) != uintptr(0) {
		var pStruct uintptr = *(*uintptr)(unsafe.Pointer(ppStruct))
		var nWrite U64
		var nWork int32
		var nRem int32

		nWrite = (*Fts5Structure)(unsafe.Pointer(pStruct)).FnWriteCounter
		nWork = int32((nWrite+U64(nLeaf))/U64((*Fts5Index)(unsafe.Pointer(p)).FnWorkUnit) - nWrite/U64((*Fts5Index)(unsafe.Pointer(p)).FnWorkUnit))
		*(*U64)(unsafe.Pointer(pStruct + 8)) += U64(nLeaf)
		nRem = (*Fts5Index)(unsafe.Pointer(p)).FnWorkUnit * nWork * (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel

		fts5IndexMerge(tls, p, ppStruct, nRem, (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FnAutomerge)
	}
}

func fts5IndexCrisismerge(tls *libc.TLS, p uintptr, ppStruct uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var nCrisis int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FnCrisisMerge
	*(*uintptr)(unsafe.Pointer(bp)) = *(*uintptr)(unsafe.Pointer(ppStruct))
	var iLvl int32 = 0

	for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))+24+uintptr(iLvl)*16)).FnSeg >= nCrisis {
		fts5IndexMergeLevel(tls, p, bp, iLvl, uintptr(0))

		fts5StructurePromote(tls, p, iLvl+1, *(*uintptr)(unsafe.Pointer(bp)))
		iLvl++
	}
	*(*uintptr)(unsafe.Pointer(ppStruct)) = *(*uintptr)(unsafe.Pointer(bp))
}

func fts5IndexReturn(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = (*Fts5Index)(unsafe.Pointer(p)).Frc
	(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_OK
	return rc
}

type Fts5FlushCtx1 = struct {
	FpIdx   uintptr
	Fwriter Fts5SegWriter
}

type Fts5FlushCtx = Fts5FlushCtx1

func fts5PoslistPrefix(tls *libc.TLS, aBuf uintptr, nMax int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var ret int32

	ret = sqlite3Fts5GetVarint32(tls, aBuf, bp)
	if ret < nMax {
		for 1 != 0 {
			var i int32 = sqlite3Fts5GetVarint32(tls, aBuf+uintptr(ret), bp)
			if ret+i > nMax {
				break
			}
			ret = ret + i
		}
	}
	return ret
}

func fts5FlushOneHash(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(176)
	defer tls.Free(176)

	var pHash uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpHash

	var iSegid int32
	*(*int32)(unsafe.Pointer(bp + 160)) = 0

	*(*uintptr)(unsafe.Pointer(bp + 168)) = fts5StructureRead(tls, p)
	iSegid = fts5AllocateSegid(tls, p, *(*uintptr)(unsafe.Pointer(bp + 168)))
	fts5StructureInvalidate(tls, p)

	if iSegid != 0 {
		var pgsz int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).Fpgsz
		var eDetail int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
		var pSeg uintptr
		var pBuf uintptr
		var pPgidx uintptr

		fts5WriteInit(tls, p, bp, iSegid)

		pBuf = bp + 8 + 8
		pPgidx = bp + 8 + 24

		if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = sqlite3Fts5HashScanInit(tls, pHash, uintptr(0), 0)
		}
		for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && 0 == sqlite3Fts5HashScanEof(tls, pHash) {
			sqlite3Fts5HashScanEntry(tls, pHash, bp+120, bp+128, bp+136)
			fts5WriteAppendTerm(tls, p, bp, int32(libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(bp + 120)))), *(*uintptr)(unsafe.Pointer(bp + 120)))
			if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
				break
			}

			if pgsz >= (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*Fts5Buffer)(unsafe.Pointer(pPgidx)).Fn+*(*int32)(unsafe.Pointer(bp + 136))+1 {
				{
					libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), *(*uintptr)(unsafe.Pointer(bp + 128)), uint64(*(*int32)(unsafe.Pointer(bp + 136))))
					*(*int32)(unsafe.Pointer(pBuf + 8)) += *(*int32)(unsafe.Pointer(bp + 136))
				}

			} else {
				var iRowid I64 = int64(0)
				*(*U64)(unsafe.Pointer(bp + 144)) = uint64(0)
				var iOff int32 = 0

				for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && iOff < *(*int32)(unsafe.Pointer(bp + 136)) {
					iOff = iOff + int32(sqlite3Fts5GetVarint(tls, *(*uintptr)(unsafe.Pointer(bp + 128))+uintptr(iOff), bp+144))
					iRowid = I64(U64(iRowid) + *(*U64)(unsafe.Pointer(bp + 144)))

					if (*Fts5SegWriter)(unsafe.Pointer(bp)).FbFirstRowidInPage != 0 {
						fts5PutU16(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp, U16((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn))
						*(*int32)(unsafe.Pointer(pBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(iRowid))
						(*Fts5SegWriter)(unsafe.Pointer(bp)).FbFirstRowidInPage = U8(0)
						fts5WriteDlidxAppend(tls, p, bp, iRowid)
						if (*Fts5Index)(unsafe.Pointer(p)).Frc != SQLITE_OK {
							break
						}
					} else {
						*(*int32)(unsafe.Pointer(pBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), *(*U64)(unsafe.Pointer(bp + 144)))
					}

					if eDetail == FTS5_DETAIL_NONE {
						if iOff < *(*int32)(unsafe.Pointer(bp + 136)) && int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 128)) + uintptr(iOff)))) == 0 {
							*(*U8)(unsafe.Pointer((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(libc.PostIncInt32(&(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn, 1)))) = U8(0)
							iOff++
							if iOff < *(*int32)(unsafe.Pointer(bp + 136)) && int32(*(*U8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 128)) + uintptr(iOff)))) == 0 {
								*(*U8)(unsafe.Pointer((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr(libc.PostIncInt32(&(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn, 1)))) = U8(0)
								iOff++
							}
						}
						if (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*Fts5Buffer)(unsafe.Pointer(pPgidx)).Fn >= pgsz {
							fts5WriteFlushLeaf(tls, p, bp)
						}
					} else {
						var nCopy int32 = fts5GetPoslistSize(tls, *(*uintptr)(unsafe.Pointer(bp + 128))+uintptr(iOff), bp+152, bp+156)
						nCopy = nCopy + *(*int32)(unsafe.Pointer(bp + 152))
						if (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*Fts5Buffer)(unsafe.Pointer(pPgidx)).Fn+nCopy <= pgsz {
							{
								libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), *(*uintptr)(unsafe.Pointer(bp + 128))+uintptr(iOff), uint64(nCopy))
								*(*int32)(unsafe.Pointer(pBuf + 8)) += nCopy
							}

						} else {
							var pPoslist uintptr = *(*uintptr)(unsafe.Pointer(bp + 128)) + uintptr(iOff)
							var iPos int32 = 0
							for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
								var nSpace int32 = pgsz - (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn - (*Fts5Buffer)(unsafe.Pointer(pPgidx)).Fn
								var n int32 = 0
								if nCopy-iPos <= nSpace {
									n = nCopy - iPos
								} else {
									n = fts5PoslistPrefix(tls, pPoslist+uintptr(iPos), nSpace)
								}

								{
									libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), pPoslist+uintptr(iPos), uint64(n))
									*(*int32)(unsafe.Pointer(pBuf + 8)) += n
								}

								iPos = iPos + n
								if (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn+(*Fts5Buffer)(unsafe.Pointer(pPgidx)).Fn >= pgsz {
									fts5WriteFlushLeaf(tls, p, bp)
								}
								if iPos >= nCopy {
									break
								}
							}
						}
						iOff = iOff + nCopy
					}
				}
			}

			if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				sqlite3Fts5HashScanNext(tls, pHash)
			}
		}
		sqlite3Fts5HashClear(tls, pHash)
		fts5WriteFinish(tls, p, bp, bp+160)

		if (*Fts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 168)))).FnLevel == 0 {
			fts5StructureAddLevel(tls, p+52, bp+168)
		}
		fts5StructureExtendLevel(tls, p+52, *(*uintptr)(unsafe.Pointer(bp + 168)), 0, 1, 0)
		if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
			pSeg = (*Fts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 168))+24)).FaSeg + uintptr(libc.PostIncInt32(&(*Fts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 168))+24)).FnSeg, 1))*12
			(*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid = iSegid
			(*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst = 1
			(*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast = *(*int32)(unsafe.Pointer(bp + 160))
			(*Fts5Structure)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 168)))).FnSegment++
		}
		fts5StructurePromote(tls, p, 0, *(*uintptr)(unsafe.Pointer(bp + 168)))
	}

	fts5IndexAutomerge(tls, p, bp+168, *(*int32)(unsafe.Pointer(bp + 160)))
	fts5IndexCrisismerge(tls, p, bp+168)
	fts5StructureWrite(tls, p, *(*uintptr)(unsafe.Pointer(bp + 168)))
	fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp + 168)))
}

func fts5IndexFlush(tls *libc.TLS, p uintptr) {
	if (*Fts5Index)(unsafe.Pointer(p)).FnPendingData != 0 {
		(*Fts5Index)(unsafe.Pointer(p)).FnPendingData = 0
		fts5FlushOneHash(tls, p)
	}
}

func fts5IndexOptimizeStruct(tls *libc.TLS, p uintptr, pStruct uintptr) uintptr {
	var pNew uintptr = uintptr(0)
	var nByte Sqlite3_int64 = Sqlite3_int64(unsafe.Sizeof(Fts5Structure{}))
	var nSeg int32 = (*Fts5Structure)(unsafe.Pointer(pStruct)).FnSegment
	var i int32

	if nSeg < 2 {
		return uintptr(0)
	}
	for i = 0; i < (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel; i++ {
		var nThis int32 = (*Fts5StructureLevel)(unsafe.Pointer(pStruct + 24 + uintptr(i)*16)).FnSeg
		if nThis == nSeg || nThis == nSeg-1 && (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(i)*16)).FnMerge == nThis {
			fts5StructureRef(tls, pStruct)
			return pStruct
		}

	}

	nByte = Sqlite3_int64(uint64(nByte) + uint64((*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel+1)*uint64(unsafe.Sizeof(Fts5StructureLevel{})))
	pNew = sqlite3Fts5MallocZero(tls, p+52, nByte)

	if pNew != 0 {
		var pLvl uintptr
		nByte = Sqlite3_int64(uint64(nSeg) * uint64(unsafe.Sizeof(Fts5StructureSegment{})))
		(*Fts5Structure)(unsafe.Pointer(pNew)).FnLevel = func() int32 {
			if (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel+1 < FTS5_MAX_LEVEL {
				return (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel + 1
			}
			return FTS5_MAX_LEVEL
		}()
		(*Fts5Structure)(unsafe.Pointer(pNew)).FnRef = 1
		(*Fts5Structure)(unsafe.Pointer(pNew)).FnWriteCounter = (*Fts5Structure)(unsafe.Pointer(pStruct)).FnWriteCounter
		pLvl = pNew + 24 + uintptr((*Fts5Structure)(unsafe.Pointer(pNew)).FnLevel-1)*16
		(*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg = sqlite3Fts5MallocZero(tls, p+52, nByte)
		if (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg != 0 {
			var iLvl int32
			var iSeg int32
			var iSegOut int32 = 0

			for iLvl = (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel - 1; iLvl >= 0; iLvl-- {
				for iSeg = 0; iSeg < (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLvl)*16)).FnSeg; iSeg++ {
					*(*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSegOut)*12)) = *(*Fts5StructureSegment)(unsafe.Pointer((*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLvl)*16)).FaSeg + uintptr(iSeg)*12))
					iSegOut++
				}
			}
			(*Fts5Structure)(unsafe.Pointer(pNew)).FnSegment = libc.AssignPtrInt32(pLvl+4, nSeg)
		} else {
			Xsqlite3_free(tls, pNew)
			pNew = uintptr(0)
		}
	}

	return pNew
}

func sqlite3Fts5IndexOptimize(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var pStruct uintptr
	*(*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 {
		var iLvl int32
		for iLvl = 0; (*Fts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))+24+uintptr(iLvl)*16)).FnSeg == 0; iLvl++ {
		}
		for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5StructureLevel)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp))+24+uintptr(iLvl)*16)).FnSeg > 0 {
			*(*int32)(unsafe.Pointer(bp + 8)) = FTS5_OPT_WORK_UNIT
			fts5IndexMergeLevel(tls, p, bp, iLvl, bp+8)
		}

		fts5StructureWrite(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
		fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
	}

	return fts5IndexReturn(tls, p)
}

func sqlite3Fts5IndexMerge(tls *libc.TLS, p uintptr, nMerge int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*uintptr)(unsafe.Pointer(bp)) = fts5StructureRead(tls, p)
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		var nMin int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FnUsermerge
		fts5StructureInvalidate(tls, p)
		if nMerge < 0 {
			var pNew uintptr = fts5IndexOptimizeStruct(tls, p, *(*uintptr)(unsafe.Pointer(bp)))
			fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
			*(*uintptr)(unsafe.Pointer(bp)) = pNew
			nMin = 2
			nMerge = nMerge * -1
		}
		if *(*uintptr)(unsafe.Pointer(bp)) != 0 && (*Fts5Structure)(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 U64, pUnused uintptr, pBuf uintptr) {
	_ = pUnused
	sqlite3Fts5BufferAppendVarint(tls, p+52, pBuf, I64(iDelta))
}

func fts5AppendPoslist(tls *libc.TLS, p uintptr, iDelta U64, pMulti uintptr, pBuf uintptr) {
	var nData int32 = (*Fts5Iter)(unsafe.Pointer(pMulti)).Fbase.FnData
	var nByte int32 = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING

	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && 0 == func() int32 {
		if U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn)+U32(nByte) <= U32((*Fts5Buffer)(unsafe.Pointer(pBuf)).FnSpace) {
			return 0
		}
		return sqlite3Fts5BufferSize(tls, p+52, pBuf, uint32(nByte+(*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn))
	}() {
		{
			*(*int32)(unsafe.Pointer(pBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), iDelta)
		}

		{
			*(*int32)(unsafe.Pointer(pBuf + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), uint64(nData*2))
		}

		{
			libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), (*Fts5Iter)(unsafe.Pointer(pMulti)).Fbase.FpData, uint64(nData))
			*(*int32)(unsafe.Pointer(pBuf + 8)) += nData
		}

		libc.Xmemset(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn), 0, uint64(FTS5_DATA_ZERO_PADDING))
	}
}

func fts5DoclistIterNext(tls *libc.TLS, pIter uintptr) {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var p uintptr = (*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist + uintptr((*Fts5DoclistIter)(unsafe.Pointer(pIter)).FnSize) + uintptr((*Fts5DoclistIter)(unsafe.Pointer(pIter)).FnPoslist)

	if p >= (*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaEof {
		(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = uintptr(0)
	} else {
		p += uintptr(sqlite3Fts5GetVarint(tls, p, bp))
		*(*I64)(unsafe.Pointer(pIter + 8)) += *(*I64)(unsafe.Pointer(bp))

		if int32(*(*U8)(unsafe.Pointer(p)))&0x80 != 0 {
			(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FnSize = sqlite3Fts5GetVarint32(tls, p, bp+8)
			(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FnPoslist = *(*int32)(unsafe.Pointer(bp + 8)) >> 1
		} else {
			(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FnPoslist = int32(*(*U8)(unsafe.Pointer(p))) >> 1
			(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FnSize = 1
		}

		(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = p
		if (*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist+uintptr((*Fts5DoclistIter)(unsafe.Pointer(pIter)).FnPoslist) > (*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaEof {
			(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = uintptr(0)
		}
	}
}

func fts5DoclistIterInit(tls *libc.TLS, pBuf uintptr, pIter uintptr) {
	libc.Xmemset(tls, pIter, 0, uint64(unsafe.Sizeof(Fts5DoclistIter{})))
	if (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn > 0 {
		(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaPoslist = (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp
		(*Fts5DoclistIter)(unsafe.Pointer(pIter)).FaEof = (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp + uintptr((*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn)
		fts5DoclistIterNext(tls, pIter)
	}
}

func fts5BufferSwap(tls *libc.TLS, p1 uintptr, p2 uintptr) {
	var tmp = *(*Fts5Buffer)(unsafe.Pointer(p1))
	*(*Fts5Buffer)(unsafe.Pointer(p1)) = *(*Fts5Buffer)(unsafe.Pointer(p2))
	*(*Fts5Buffer)(unsafe.Pointer(p2)) = tmp
}

func fts5NextRowid(tls *libc.TLS, pBuf uintptr, piOff uintptr, piRowid uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var i int32 = *(*int32)(unsafe.Pointer(piOff))
	if i >= (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn {
		*(*int32)(unsafe.Pointer(piOff)) = -1
	} else {
		*(*int32)(unsafe.Pointer(piOff)) = i + int32(sqlite3Fts5GetVarint(tls, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp+uintptr(i), bp))
		*(*I64)(unsafe.Pointer(piRowid)) += I64(*(*U64)(unsafe.Pointer(bp)))
	}
}

func fts5MergeRowidLists(tls *libc.TLS, p uintptr, p1 uintptr, nBuf int32, aBuf uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	*(*int32)(unsafe.Pointer(bp + 16)) = 0
	*(*int32)(unsafe.Pointer(bp + 32)) = 0
	*(*I64)(unsafe.Pointer(bp + 24)) = int64(0)
	*(*I64)(unsafe.Pointer(bp + 40)) = int64(0)
	var iOut I64 = int64(0)
	var p2 uintptr = aBuf

	_ = nBuf
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))

	sqlite3Fts5BufferSize(tls, p+52, bp, uint32((*Fts5Buffer)(unsafe.Pointer(p1)).Fn+(*Fts5Buffer)(unsafe.Pointer(p2)).Fn))
	if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
		return
	}

	fts5NextRowid(tls, p1, bp+16, bp+24)
	fts5NextRowid(tls, p2, bp+32, bp+40)
	for *(*int32)(unsafe.Pointer(bp + 16)) >= 0 || *(*int32)(unsafe.Pointer(bp + 32)) >= 0 {
		if *(*int32)(unsafe.Pointer(bp + 16)) >= 0 && (*(*int32)(unsafe.Pointer(bp + 32)) < 0 || *(*I64)(unsafe.Pointer(bp + 24)) < *(*I64)(unsafe.Pointer(bp + 40))) {
			{
				*(*int32)(unsafe.Pointer(bp + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp)).Fn), uint64(*(*I64)(unsafe.Pointer(bp + 24))-iOut))
			}

			iOut = *(*I64)(unsafe.Pointer(bp + 24))
			fts5NextRowid(tls, p1, bp+16, bp+24)
		} else {
			{
				*(*int32)(unsafe.Pointer(bp + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp)).Fn), uint64(*(*I64)(unsafe.Pointer(bp + 40))-iOut))
			}

			iOut = *(*I64)(unsafe.Pointer(bp + 40))
			if *(*int32)(unsafe.Pointer(bp + 16)) >= 0 && *(*I64)(unsafe.Pointer(bp + 24)) == *(*I64)(unsafe.Pointer(bp + 40)) {
				fts5NextRowid(tls, p1, bp+16, bp+24)
			}
			fts5NextRowid(tls, p2, bp+32, bp+40)
		}
	}

	fts5BufferSwap(tls, bp, p1)
	sqlite3Fts5BufferFree(tls, bp)
}

type PrefixMerger1 = struct {
	Fiter        Fts5DoclistIter
	FiPos        I64
	FiOff        int32
	F__ccgo_pad1 [4]byte
	FaPos        uintptr
	FpNext       uintptr
}

type PrefixMerger = PrefixMerger1

func fts5PrefixMergerInsertByRowid(tls *libc.TLS, ppHead uintptr, p uintptr) {
	if (*PrefixMerger)(unsafe.Pointer(p)).Fiter.FaPoslist != 0 {
		var pp uintptr = ppHead
		for *(*uintptr)(unsafe.Pointer(pp)) != 0 && (*PrefixMerger)(unsafe.Pointer(p)).Fiter.FiRowid > (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).Fiter.FiRowid {
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 56
		}
		(*PrefixMerger)(unsafe.Pointer(p)).FpNext = *(*uintptr)(unsafe.Pointer(pp))
		*(*uintptr)(unsafe.Pointer(pp)) = p
	}
}

func fts5PrefixMergerInsertByPosition(tls *libc.TLS, ppHead uintptr, p uintptr) {
	if (*PrefixMerger)(unsafe.Pointer(p)).FiPos >= int64(0) {
		var pp uintptr = ppHead
		for *(*uintptr)(unsafe.Pointer(pp)) != 0 && (*PrefixMerger)(unsafe.Pointer(p)).FiPos > (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pp)))).FiPos {
			pp = *(*uintptr)(unsafe.Pointer(pp)) + 56
		}
		(*PrefixMerger)(unsafe.Pointer(p)).FpNext = *(*uintptr)(unsafe.Pointer(pp))
		*(*uintptr)(unsafe.Pointer(pp)) = p
	}
}

func fts5MergePrefixLists(tls *libc.TLS, p uintptr, p1 uintptr, nBuf int32, aBuf uintptr) {
	bp := tls.Alloc(1072)
	defer tls.Free(1072)

	*(*uintptr)(unsafe.Pointer(bp + 1024)) = uintptr(0)
	var i int32
	var nOut int32 = 0
	*(*Fts5Buffer)(unsafe.Pointer(bp + 1032)) = Fts5Buffer{}
	*(*Fts5Buffer)(unsafe.Pointer(bp + 1048)) = Fts5Buffer{}
	var iLastRowid I64 = int64(0)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(PrefixMerger{}))*uint64(nBuf+1))
	*(*uintptr)(unsafe.Pointer(bp + 1024)) = bp + uintptr(nBuf)*64
	fts5DoclistIterInit(tls, p1, *(*uintptr)(unsafe.Pointer(bp + 1024)))
	for i = 0; i < nBuf; i++ {
		fts5DoclistIterInit(tls, aBuf+uintptr(i)*16, bp+uintptr(i)*64)
		fts5PrefixMergerInsertByRowid(tls, bp+1024, bp+uintptr(i)*64)
		nOut = nOut + (*Fts5Buffer)(unsafe.Pointer(aBuf+uintptr(i)*16)).Fn
	}
	if nOut == 0 {
		return
	}
	nOut = nOut + ((*Fts5Buffer)(unsafe.Pointer(p1)).Fn + 9 + 10*nBuf)

	if sqlite3Fts5BufferSize(tls, p+52, bp+1032, uint32(nOut)) != 0 {
		return
	}

	for *(*uintptr)(unsafe.Pointer(bp + 1024)) != 0 {
		{
			{
				*(*int32)(unsafe.Pointer(bp + 1032 + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fn), U64((*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).Fiter.FiRowid)-U64(iLastRowid))
			}
			iLastRowid = (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).Fiter.FiRowid
		}

		if (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FpNext != 0 && iLastRowid == (*PrefixMerger)(unsafe.Pointer((*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FpNext)).Fiter.FiRowid {
			*(*I64)(unsafe.Pointer(bp + 1064)) = int64(0)
			var nTmp int32 = FTS5_DATA_ZERO_PADDING
			var nMerge int32 = 0
			var pSave uintptr = *(*uintptr)(unsafe.Pointer(bp + 1024))
			var pThis uintptr = uintptr(0)
			var nTail int32 = 0

			*(*uintptr)(unsafe.Pointer(bp + 1024)) = uintptr(0)
			for pSave != 0 && (*PrefixMerger)(unsafe.Pointer(pSave)).Fiter.FiRowid == iLastRowid {
				var pNext uintptr = (*PrefixMerger)(unsafe.Pointer(pSave)).FpNext
				(*PrefixMerger)(unsafe.Pointer(pSave)).FiOff = 0
				(*PrefixMerger)(unsafe.Pointer(pSave)).FiPos = int64(0)
				(*PrefixMerger)(unsafe.Pointer(pSave)).FaPos = (*PrefixMerger)(unsafe.Pointer(pSave)).Fiter.FaPoslist + uintptr((*PrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnSize)
				sqlite3Fts5PoslistNext64(tls, (*PrefixMerger)(unsafe.Pointer(pSave)).FaPos, (*PrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnPoslist, pSave+40, pSave+32)
				nTmp = nTmp + ((*PrefixMerger)(unsafe.Pointer(pSave)).Fiter.FnPoslist + 10)
				nMerge++
				fts5PrefixMergerInsertByPosition(tls, bp+1024, pSave)
				pSave = pNext
			}

			if *(*uintptr)(unsafe.Pointer(bp + 1024)) == uintptr(0) || (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FpNext == uintptr(0) {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
				break
			}

			if sqlite3Fts5BufferSize(tls, p+52, bp+1048, uint32(nTmp+nMerge*10)) != 0 {
				break
			}
			sqlite3Fts5BufferZero(tls, bp+1048)

			pThis = *(*uintptr)(unsafe.Pointer(bp + 1024))
			*(*uintptr)(unsafe.Pointer(bp + 1024)) = (*PrefixMerger)(unsafe.Pointer(pThis)).FpNext
			sqlite3Fts5PoslistSafeAppend(tls, bp+1048, bp+1064, (*PrefixMerger)(unsafe.Pointer(pThis)).FiPos)
			sqlite3Fts5PoslistNext64(tls, (*PrefixMerger)(unsafe.Pointer(pThis)).FaPos, (*PrefixMerger)(unsafe.Pointer(pThis)).Fiter.FnPoslist, pThis+40, pThis+32)
			fts5PrefixMergerInsertByPosition(tls, bp+1024, pThis)

			for (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FpNext != 0 {
				pThis = *(*uintptr)(unsafe.Pointer(bp + 1024))
				if (*PrefixMerger)(unsafe.Pointer(pThis)).FiPos != *(*I64)(unsafe.Pointer(bp + 1064)) {
					sqlite3Fts5PoslistSafeAppend(tls, bp+1048, bp+1064, (*PrefixMerger)(unsafe.Pointer(pThis)).FiPos)
				}
				sqlite3Fts5PoslistNext64(tls, (*PrefixMerger)(unsafe.Pointer(pThis)).FaPos, (*PrefixMerger)(unsafe.Pointer(pThis)).Fiter.FnPoslist, pThis+40, pThis+32)
				*(*uintptr)(unsafe.Pointer(bp + 1024)) = (*PrefixMerger)(unsafe.Pointer(pThis)).FpNext
				fts5PrefixMergerInsertByPosition(tls, bp+1024, pThis)
			}

			if (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FiPos != *(*I64)(unsafe.Pointer(bp + 1064)) {
				sqlite3Fts5PoslistSafeAppend(tls, bp+1048, bp+1064, (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FiPos)
			}
			nTail = (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).Fiter.FnPoslist - (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FiOff

			if (*Fts5Buffer)(unsafe.Pointer(bp+1048)).Fn+nTail > nTmp-FTS5_DATA_ZERO_PADDING {
				if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
				}
				break
			}
			{
				*(*int32)(unsafe.Pointer(bp + 1032 + 8)) += sqlite3Fts5PutVarint(tls, (*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fn), uint64(((*Fts5Buffer)(unsafe.Pointer(bp+1048)).Fn+nTail)*2))
			}

			{
				libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fn), (*Fts5Buffer)(unsafe.Pointer(bp+1048)).Fp, uint64((*Fts5Buffer)(unsafe.Pointer(bp+1048)).Fn))
				*(*int32)(unsafe.Pointer(bp + 1032 + 8)) += (*Fts5Buffer)(unsafe.Pointer(bp + 1048)).Fn
			}

			if nTail > 0 {
				{
					libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fn), (*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FaPos+uintptr((*PrefixMerger)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 1024)))).FiOff), uint64(nTail))
					*(*int32)(unsafe.Pointer(bp + 1032 + 8)) += nTail
				}

			}

			*(*uintptr)(unsafe.Pointer(bp + 1024)) = pSave
			for i = 0; i < nBuf+1; i++ {
				var pX uintptr = bp + uintptr(i)*64
				if (*PrefixMerger)(unsafe.Pointer(pX)).Fiter.FaPoslist != 0 && (*PrefixMerger)(unsafe.Pointer(pX)).Fiter.FiRowid == iLastRowid {
					fts5DoclistIterNext(tls, pX)
					fts5PrefixMergerInsertByRowid(tls, bp+1024, pX)
				}
			}

		} else {
			var pThis uintptr = *(*uintptr)(unsafe.Pointer(bp + 1024))
			var pI uintptr = pThis
			{
				libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fn), (*Fts5DoclistIter)(unsafe.Pointer(pI)).FaPoslist, uint64((*Fts5DoclistIter)(unsafe.Pointer(pI)).FnPoslist+(*Fts5DoclistIter)(unsafe.Pointer(pI)).FnSize))
				*(*int32)(unsafe.Pointer(bp + 1032 + 8)) += (*Fts5DoclistIter)(unsafe.Pointer(pI)).FnPoslist + (*Fts5DoclistIter)(unsafe.Pointer(pI)).FnSize
			}

			fts5DoclistIterNext(tls, pI)
			*(*uintptr)(unsafe.Pointer(bp + 1024)) = (*PrefixMerger)(unsafe.Pointer(pThis)).FpNext
			fts5PrefixMergerInsertByRowid(tls, bp+1024, pThis)
		}
	}

	sqlite3Fts5BufferFree(tls, p1)
	sqlite3Fts5BufferFree(tls, bp+1048)
	libc.Xmemset(tls, (*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fp+uintptr((*Fts5Buffer)(unsafe.Pointer(bp+1032)).Fn), 0, uint64(FTS5_DATA_ZERO_PADDING))
	*(*Fts5Buffer)(unsafe.Pointer(p1)) = *(*Fts5Buffer)(unsafe.Pointer(bp + 1032))
}

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 pStruct uintptr
	var aBuf uintptr
	var nBuf int32 = 32
	var nMerge int32 = 1
	var xMerge uintptr
	var xAppend uintptr
	if (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail == FTS5_DETAIL_NONE {
		xMerge = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr)
		}{fts5MergeRowidLists}))
		xAppend = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, U64, uintptr, uintptr)
		}{fts5AppendRowid}))
	} else {
		nMerge = FTS5_MERGE_NLIST - 1
		nBuf = nMerge * 8
		xMerge = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr)
		}{fts5MergePrefixLists}))
		xAppend = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, U64, uintptr, uintptr)
		}{fts5AppendPoslist}))
	}

	aBuf = fts5IdxMalloc(tls, p, int64(uint64(unsafe.Sizeof(Fts5Buffer{}))*uint64(nBuf)))
	pStruct = fts5StructureRead(tls, p)

	if aBuf != 0 && pStruct != 0 {
		var flags int32 = FTS5INDEX_QUERY_SCAN |
			FTS5INDEX_QUERY_SKIPEMPTY |
			FTS5INDEX_QUERY_NOOUTPUT
		var i int32
		var iLastRowid I64 = int64(0)
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
		var pData uintptr

		*(*int32)(unsafe.Pointer(bp + 28)) = 1

		libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))
		if iIdx != 0 {
			*(*int32)(unsafe.Pointer(bp + 24)) = 0
			var f2 int32 = FTS5INDEX_QUERY_SKIPEMPTY | FTS5INDEX_QUERY_NOOUTPUT
			*(*U8)(unsafe.Pointer(pToken)) = U8('0')
			fts5MultiIterNew(tls, p, pStruct, f2, pColset, pToken, nToken, -1, 0, bp+16)
			fts5IterSetOutputCb(tls, p+52, *(*uintptr)(unsafe.Pointer(bp + 16)))
			for ; fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp + 16))) == 0; fts5MultiIterNext2(tls, p, *(*uintptr)(unsafe.Pointer(bp + 16)), bp+24) {
				var pSeg uintptr = *(*uintptr)(unsafe.Pointer(bp + 16)) + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaFirst+1*4)).FiFirst)*120
				(*struct {
					f func(*libc.TLS, uintptr, uintptr)
				})(unsafe.Pointer(&struct{ uintptr }{(*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FxSetOutputs})).f(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), pSeg)
				if (*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fbase.FnData != 0 {
					(*struct {
						f func(*libc.TLS, uintptr, U64, uintptr, uintptr)
					})(unsafe.Pointer(&struct{ uintptr }{xAppend})).f(tls, p, U64((*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fbase.FiRowid)-U64(iLastRowid), *(*uintptr)(unsafe.Pointer(bp + 16)), bp)
					iLastRowid = (*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fbase.FiRowid
				}
			}
			fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
		}

		*(*U8)(unsafe.Pointer(pToken)) = U8('0' + iIdx)
		fts5MultiIterNew(tls, p, pStruct, flags, pColset, pToken, nToken, -1, 0, bp+16)
		fts5IterSetOutputCb(tls, p+52, *(*uintptr)(unsafe.Pointer(bp + 16)))
		for ; fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp + 16))) == 0; fts5MultiIterNext2(tls, p, *(*uintptr)(unsafe.Pointer(bp + 16)), bp+28) {
			var pSeg uintptr = *(*uintptr)(unsafe.Pointer(bp + 16)) + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaFirst+1*4)).FiFirst)*120
			var nTerm int32 = (*Fts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fn
			var pTerm uintptr = (*Fts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fp
			(*struct {
				f func(*libc.TLS, uintptr, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{(*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FxSetOutputs})).f(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), pSeg)

			if *(*int32)(unsafe.Pointer(bp + 28)) != 0 {
				if nTerm < nToken || libc.Xmemcmp(tls, pToken, pTerm, uint64(nToken)) != 0 {
					break
				}
			}

			if (*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fbase.FnData == 0 {
				continue
			}

			if (*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fbase.FiRowid <= iLastRowid && (*Fts5Buffer)(unsafe.Pointer(bp)).Fn > 0 {
				for i = 0; (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5Buffer)(unsafe.Pointer(bp)).Fn != 0; i++ {
					var i1 int32 = i * nMerge
					var iStore int32

					for iStore = i1; iStore < i1+nMerge; iStore++ {
						if (*Fts5Buffer)(unsafe.Pointer(aBuf+uintptr(iStore)*16)).Fn == 0 {
							fts5BufferSwap(tls, bp, aBuf+uintptr(iStore)*16)
							sqlite3Fts5BufferZero(tls, bp)
							break
						}
					}
					if iStore == i1+nMerge {
						(*struct {
							f func(*libc.TLS, uintptr, uintptr, int32, uintptr)
						})(unsafe.Pointer(&struct{ uintptr }{xMerge})).f(tls, p, bp, nMerge, aBuf+uintptr(i1)*16)
						for iStore = i1; iStore < i1+nMerge; iStore++ {
							sqlite3Fts5BufferZero(tls, aBuf+uintptr(iStore)*16)
						}
					}
				}
				iLastRowid = int64(0)
			}

			(*struct {
				f func(*libc.TLS, uintptr, U64, uintptr, uintptr)
			})(unsafe.Pointer(&struct{ uintptr }{xAppend})).f(tls, p, U64((*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fbase.FiRowid)-U64(iLastRowid), *(*uintptr)(unsafe.Pointer(bp + 16)), bp)
			iLastRowid = (*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).Fbase.FiRowid
		}

		for i = 0; i < nBuf; i = i + nMerge {
			var iFree int32
			if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				(*struct {
					f func(*libc.TLS, uintptr, uintptr, int32, uintptr)
				})(unsafe.Pointer(&struct{ uintptr }{xMerge})).f(tls, p, bp, nMerge, aBuf+uintptr(i)*16)
			}
			for iFree = i; iFree < i+nMerge; iFree++ {
				sqlite3Fts5BufferFree(tls, aBuf+uintptr(iFree)*16)
			}
		}
		fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))

		pData = fts5IdxMalloc(tls, p, int64(uint64(unsafe.Sizeof(Fts5Data{}))+uint64((*Fts5Buffer)(unsafe.Pointer(bp)).Fn)+uint64(FTS5_DATA_ZERO_PADDING)))
		if pData != 0 {
			(*Fts5Data)(unsafe.Pointer(pData)).Fp = pData + 1*16
			(*Fts5Data)(unsafe.Pointer(pData)).Fnn = libc.AssignPtrInt32(pData+12, (*Fts5Buffer)(unsafe.Pointer(bp)).Fn)
			if (*Fts5Buffer)(unsafe.Pointer(bp)).Fn != 0 {
				libc.Xmemcpy(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp, uint64((*Fts5Buffer)(unsafe.Pointer(bp)).Fn))
			}
			fts5MultiIterNew2(tls, p, pData, bDesc, ppIter)
		}
		sqlite3Fts5BufferFree(tls, bp)
	}

	fts5StructureRelease(tls, pStruct)
	Xsqlite3_free(tls, aBuf)
}

func sqlite3Fts5IndexBeginWrite(tls *libc.TLS, p uintptr, bDelete int32, iRowid I64) int32 {
	if (*Fts5Index)(unsafe.Pointer(p)).FpHash == uintptr(0) {
		(*Fts5Index)(unsafe.Pointer(p)).Frc = sqlite3Fts5HashNew(tls, (*Fts5Index)(unsafe.Pointer(p)).FpConfig, p+24, p+32)
	}

	if iRowid < (*Fts5Index)(unsafe.Pointer(p)).FiWriteRowid ||
		iRowid == (*Fts5Index)(unsafe.Pointer(p)).FiWriteRowid && (*Fts5Index)(unsafe.Pointer(p)).FbDelete == 0 ||
		(*Fts5Index)(unsafe.Pointer(p)).FnPendingData > (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FnHashSize {
		fts5IndexFlush(tls, p)
	}

	(*Fts5Index)(unsafe.Pointer(p)).FiWriteRowid = iRowid
	(*Fts5Index)(unsafe.Pointer(p)).FbDelete = bDelete
	return fts5IndexReturn(tls, p)
}

func sqlite3Fts5IndexSync(tls *libc.TLS, p uintptr) int32 {
	fts5IndexFlush(tls, p)
	sqlite3Fts5IndexCloseReader(tls, p)
	return fts5IndexReturn(tls, p)
}

func sqlite3Fts5IndexRollback(tls *libc.TLS, p uintptr) int32 {
	sqlite3Fts5IndexCloseReader(tls, p)
	fts5IndexDiscardData(tls, p)
	fts5StructureInvalidate(tls, p)

	return SQLITE_OK
}

func sqlite3Fts5IndexReinit(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	fts5StructureInvalidate(tls, p)
	fts5IndexDiscardData(tls, p)
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Structure{})))
	fts5DataWrite(tls, p, int64(FTS5_AVERAGES_ROWID), ts+1636, 0)
	fts5StructureWrite(tls, p, bp)
	return fts5IndexReturn(tls, p)
}

func sqlite3Fts5IndexOpen(tls *libc.TLS, pConfig uintptr, bCreate int32, pp uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_OK
	var p uintptr

	*(*uintptr)(unsafe.Pointer(pp)) = libc.AssignUintptr(&p, sqlite3Fts5MallocZero(tls, bp+8, int64(unsafe.Sizeof(Fts5Index{}))))
	if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
		(*Fts5Index)(unsafe.Pointer(p)).FpConfig = pConfig
		(*Fts5Index)(unsafe.Pointer(p)).FnWorkUnit = FTS5_WORK_UNIT
		(*Fts5Index)(unsafe.Pointer(p)).FzDataTbl = sqlite3Fts5Mprintf(tls, bp+8, ts+42393, libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
		if (*Fts5Index)(unsafe.Pointer(p)).FzDataTbl != 0 && bCreate != 0 {
			*(*int32)(unsafe.Pointer(bp + 8)) = sqlite3Fts5CreateTable(tls,
				pConfig, ts+31344, ts+42401, 0, pzErr)
			if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp + 8)) = sqlite3Fts5CreateTable(tls, pConfig, ts+14903,
					ts+42436,
					1, pzErr)
			}
			if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
				*(*int32)(unsafe.Pointer(bp + 8)) = sqlite3Fts5IndexReinit(tls, p)
			}
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
		sqlite3Fts5IndexClose(tls, p)
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	}
	return *(*int32)(unsafe.Pointer(bp + 8))
}

func sqlite3Fts5IndexClose(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = SQLITE_OK
	if p != 0 {
		fts5StructureInvalidate(tls, p)
		Xsqlite3_finalize(tls, (*Fts5Index)(unsafe.Pointer(p)).FpWriter)
		Xsqlite3_finalize(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDeleter)
		Xsqlite3_finalize(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxWriter)
		Xsqlite3_finalize(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxDeleter)
		Xsqlite3_finalize(tls, (*Fts5Index)(unsafe.Pointer(p)).FpIdxSelect)
		Xsqlite3_finalize(tls, (*Fts5Index)(unsafe.Pointer(p)).FpDataVersion)
		sqlite3Fts5HashFree(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash)
		Xsqlite3_free(tls, (*Fts5Index)(unsafe.Pointer(p)).FzDataTbl)
		Xsqlite3_free(tls, p)
	}
	return rc
}

func sqlite3Fts5IndexCharlenToBytelen(tls *libc.TLS, p uintptr, nByte int32, nChar int32) int32 {
	var n int32 = 0
	var i int32
	for i = 0; i < nChar; i++ {
		if n >= nByte {
			return 0
		}
		if int32(*(*uint8)(unsafe.Pointer(p + uintptr(libc.PostIncInt32(&n, 1))))) >= 0xc0 {
			if n >= nByte {
				return 0
			}
			for int32(*(*uint8)(unsafe.Pointer(p + uintptr(n))))&0xc0 == 0x80 {
				n++
				if n >= nByte {
					if i+1 == nChar {
						break
					}
					return 0
				}
			}
		}
	}
	return n
}

func fts5IndexCharlen(tls *libc.TLS, pIn uintptr, nIn int32) int32 {
	var nChar int32 = 0
	var i int32 = 0
	for i < nIn {
		if int32(*(*uint8)(unsafe.Pointer(pIn + uintptr(libc.PostIncInt32(&i, 1))))) >= 0xc0 {
			for i < nIn && int32(*(*uint8)(unsafe.Pointer(pIn + uintptr(i))))&0xc0 == 0x80 {
				i++
			}
		}
		nChar++
	}
	return nChar
}

func sqlite3Fts5IndexWrite(tls *libc.TLS, p uintptr, iCol int32, iPos int32, pToken uintptr, nToken int32) int32 {
	var i int32
	var rc int32 = SQLITE_OK
	var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig

	rc = sqlite3Fts5HashWrite(tls,
		(*Fts5Index)(unsafe.Pointer(p)).FpHash, (*Fts5Index)(unsafe.Pointer(p)).FiWriteRowid, iCol, iPos, uint8('0'), pToken, nToken)

	for i = 0; i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnPrefix && rc == SQLITE_OK; i++ {
		var nChar int32 = *(*int32)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FaPrefix + uintptr(i)*4))
		var nByte int32 = sqlite3Fts5IndexCharlenToBytelen(tls, pToken, nToken, nChar)
		if nByte != 0 {
			rc = sqlite3Fts5HashWrite(tls, (*Fts5Index)(unsafe.Pointer(p)).FpHash,
				(*Fts5Index)(unsafe.Pointer(p)).FiWriteRowid, iCol, iPos, uint8('0'+i+1), pToken,
				nByte)
		}
	}

	return rc
}

func sqlite3Fts5IndexQuery(tls *libc.TLS, p uintptr, pToken uintptr, nToken int32, flags int32, pColset uintptr, ppIter uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
	*(*Fts5Buffer)(unsafe.Pointer(bp)) = Fts5Buffer{}

	if sqlite3Fts5BufferSize(tls, p+52, bp, uint32(nToken+1)) == 0 {
		var iIdx int32 = 0
		var iPrefixIdx int32 = 0
		if nToken > 0 {
			libc.Xmemcpy(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp+1, pToken, uint64(nToken))
		}

		if flags&FTS5INDEX_QUERY_PREFIX != 0 {
			var nChar int32 = fts5IndexCharlen(tls, pToken, nToken)
			for iIdx = 1; iIdx <= (*Fts5Config)(unsafe.Pointer(pConfig)).FnPrefix; iIdx++ {
				var nIdxChar int32 = *(*int32)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FaPrefix + uintptr(iIdx-1)*4))
				if nIdxChar == nChar {
					break
				}
				if nIdxChar == nChar+1 {
					iPrefixIdx = iIdx
				}
			}
		}

		if iIdx <= (*Fts5Config)(unsafe.Pointer(pConfig)).FnPrefix {
			var pStruct uintptr = fts5StructureRead(tls, p)
			*(*U8)(unsafe.Pointer((*Fts5Buffer)(unsafe.Pointer(bp)).Fp)) = U8('0' + iIdx)
			if pStruct != 0 {
				fts5MultiIterNew(tls, p, pStruct, flags|FTS5INDEX_QUERY_SKIPEMPTY,
					pColset, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp, nToken+1, -1, 0, bp+16)
				fts5StructureRelease(tls, pStruct)
			}
		} else {
			var bDesc int32 = libc.Bool32(flags&FTS5INDEX_QUERY_DESC != 0)
			fts5SetupPrefixIter(tls, p, bDesc, iPrefixIdx, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp, nToken+1, pColset, bp+16)
			if *(*uintptr)(unsafe.Pointer(bp + 16)) == uintptr(0) {
			} else {
				fts5IterSetOutputCb(tls, p+52, *(*uintptr)(unsafe.Pointer(bp + 16)))
				if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
					var pSeg uintptr = *(*uintptr)(unsafe.Pointer(bp + 16)) + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FaFirst+1*4)).FiFirst)*120
					if (*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf != 0 {
						(*struct {
							f func(*libc.TLS, uintptr, uintptr)
						})(unsafe.Pointer(&struct{ uintptr }{(*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16)))).FxSetOutputs})).f(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), pSeg)
					}
				}
			}
		}

		if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
			sqlite3Fts5IterClose(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
			*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)
			sqlite3Fts5IndexCloseReader(tls, p)
		}

		*(*uintptr)(unsafe.Pointer(ppIter)) = *(*uintptr)(unsafe.Pointer(bp + 16))
		sqlite3Fts5BufferFree(tls, bp)
	}
	return fts5IndexReturn(tls, p)
}

func sqlite3Fts5IterNext(tls *libc.TLS, pIndexIter uintptr) int32 {
	var pIter uintptr = pIndexIter

	fts5MultiIterNext(tls, (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex, pIter, 0, int64(0))
	return fts5IndexReturn(tls, (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex)
}

func sqlite3Fts5IterNextScan(tls *libc.TLS, pIndexIter uintptr) int32 {
	var pIter uintptr = pIndexIter
	var p uintptr = (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex

	fts5MultiIterNext(tls, p, pIter, 0, int64(0))
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var pSeg uintptr = pIter + 96 + uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(pIter)).FaFirst+1*4)).FiFirst)*120
		if (*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf != 0 && int32(*(*U8)(unsafe.Pointer((*Fts5SegIter)(unsafe.Pointer(pSeg)).Fterm.Fp))) != '0' {
			fts5DataRelease(tls, (*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf)
			(*Fts5SegIter)(unsafe.Pointer(pSeg)).FpLeaf = uintptr(0)
			(*Fts5Iter)(unsafe.Pointer(pIter)).Fbase.FbEof = U8(1)
		}
	}

	return fts5IndexReturn(tls, (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex)
}

func sqlite3Fts5IterNextFrom(tls *libc.TLS, pIndexIter uintptr, iMatch I64) int32 {
	var pIter uintptr = pIndexIter
	fts5MultiIterNextFrom(tls, (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex, pIter, iMatch)
	return fts5IndexReturn(tls, (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex)
}

func sqlite3Fts5IterTerm(tls *libc.TLS, pIndexIter uintptr, pn uintptr) uintptr {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var z uintptr = fts5MultiIterTerm(tls, pIndexIter, bp)

	*(*int32)(unsafe.Pointer(pn)) = *(*int32)(unsafe.Pointer(bp)) - 1
	return func() uintptr {
		if z != 0 {
			return z + 1
		}
		return uintptr(0)
	}()
}

func sqlite3Fts5IterClose(tls *libc.TLS, pIndexIter uintptr) {
	if pIndexIter != 0 {
		var pIter uintptr = pIndexIter
		var pIndex uintptr = (*Fts5Iter)(unsafe.Pointer(pIter)).FpIndex
		fts5MultiIterFree(tls, pIter)
		sqlite3Fts5IndexCloseReader(tls, pIndex)
	}
}

func sqlite3Fts5IndexGetAverages(tls *libc.TLS, p uintptr, pnRow uintptr, anSize uintptr) int32 {
	var nCol int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FnCol
	var pData uintptr

	*(*I64)(unsafe.Pointer(pnRow)) = int64(0)
	libc.Xmemset(tls, anSize, 0, uint64(unsafe.Sizeof(I64(0)))*uint64(nCol))
	pData = fts5DataRead(tls, p, int64(FTS5_AVERAGES_ROWID))
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && (*Fts5Data)(unsafe.Pointer(pData)).Fnn != 0 {
		var i int32 = 0
		var iCol int32
		i = i + int32(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp+uintptr(i), pnRow))
		for iCol = 0; i < (*Fts5Data)(unsafe.Pointer(pData)).Fnn && iCol < nCol; iCol++ {
			i = i + int32(sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(pData)).Fp+uintptr(i), anSize+uintptr(iCol)*8))
		}
	}

	fts5DataRelease(tls, pData)
	return fts5IndexReturn(tls, p)
}

func sqlite3Fts5IndexSetAverages(tls *libc.TLS, p uintptr, pData uintptr, nData int32) int32 {
	fts5DataWrite(tls, p, int64(FTS5_AVERAGES_ROWID), pData, nData)
	return fts5IndexReturn(tls, p)
}

func sqlite3Fts5IndexReads(tls *libc.TLS, p uintptr) int32 {
	return (*Fts5Index)(unsafe.Pointer(p)).FnRead
}

func sqlite3Fts5IndexSetCookie(tls *libc.TLS, p uintptr, iNew int32) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32
	var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig

	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

	sqlite3Fts5Put32(tls, bp, iNew)

	rc = Xsqlite3_blob_open(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Index)(unsafe.Pointer(p)).FzDataTbl,
		ts+42083, int64(FTS5_STRUCTURE_ROWID), 1, bp+8)
	if rc == SQLITE_OK {
		Xsqlite3_blob_write(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), bp, 4, 0)
		rc = Xsqlite3_blob_close(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}

	return rc
}

func sqlite3Fts5IndexLoadConfig(tls *libc.TLS, p uintptr) int32 {
	var pStruct uintptr
	pStruct = fts5StructureRead(tls, p)
	fts5StructureRelease(tls, pStruct)
	return fts5IndexReturn(tls, p)
}

func sqlite3Fts5IndexEntryCksum(tls *libc.TLS, iRowid I64, iCol int32, iPos int32, iIdx int32, pTerm uintptr, nTerm int32) U64 {
	var i int32
	var ret U64 = U64(iRowid)
	ret = ret + (ret<<3 + U64(iCol))
	ret = ret + (ret<<3 + U64(iPos))
	if iIdx >= 0 {
		ret = ret + (ret<<3 + U64('0'+iIdx))
	}
	for i = 0; i < nTerm; i++ {
		ret = ret + (ret<<3 + U64(*(*uint8)(unsafe.Pointer(pTerm + uintptr(i)))))
	}
	return ret
}

func fts5IndexIntegrityCheckEmpty(tls *libc.TLS, p uintptr, pSeg uintptr, iFirst int32, iNoRowid int32, iLast int32) {
	var i int32

	for i = iFirst; (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && i <= iLast; i++ {
		var pLeaf uintptr = fts5DataRead(tls, p, I64((*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B)+int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B)+int64(0)<<FTS5_DATA_PAGE_B+I64(i))
		if pLeaf != 0 {
			if !((*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf >= (*Fts5Data)(unsafe.Pointer(pLeaf)).Fnn) {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			}
			if i >= iNoRowid && 0 != int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp)) {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			}
		}
		fts5DataRelease(tls, pLeaf)
	}
}

func fts5IntegrityCheckPgidx(tls *libc.TLS, p uintptr, pLeaf uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var iTermOff int32 = 0
	var ii int32

	*(*Fts5Buffer)(unsafe.Pointer(bp + 8)) = Fts5Buffer{}
	*(*Fts5Buffer)(unsafe.Pointer(bp + 32)) = Fts5Buffer{}

	ii = (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf
	for ii < (*Fts5Data)(unsafe.Pointer(pLeaf)).Fnn && (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		var res int32
		var iOff int32

		ii = ii + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(ii), bp)
		iTermOff = iTermOff + *(*int32)(unsafe.Pointer(bp))
		iOff = iTermOff

		if iOff >= (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
		} else if iTermOff == *(*int32)(unsafe.Pointer(bp)) {
			iOff = iOff + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+4)
			if iOff+*(*int32)(unsafe.Pointer(bp + 4)) > (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			} else {
				sqlite3Fts5BufferSet(tls, p+52, bp+8, *(*int32)(unsafe.Pointer(bp + 4)), (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff))
			}
		} else {
			iOff = iOff + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+24)
			iOff = iOff + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+28)
			if *(*int32)(unsafe.Pointer(bp + 24)) > (*Fts5Buffer)(unsafe.Pointer(bp+8)).Fn || iOff+*(*int32)(unsafe.Pointer(bp + 28)) > (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			} else {
				(*Fts5Buffer)(unsafe.Pointer(bp + 8)).Fn = *(*int32)(unsafe.Pointer(bp + 24))
				sqlite3Fts5BufferAppendBlob(tls, p+52, bp+8, uint32(*(*int32)(unsafe.Pointer(bp + 28))), (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff))
			}

			if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
				res = fts5BufferCompare(tls, bp+8, bp+32)
				if res <= 0 {
					(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
				}
			}
		}
		sqlite3Fts5BufferSet(tls, p+52, bp+32, (*Fts5Buffer)(unsafe.Pointer(bp+8)).Fn, (*Fts5Buffer)(unsafe.Pointer(bp+8)).Fp)
	}

	sqlite3Fts5BufferFree(tls, bp+8)
	sqlite3Fts5BufferFree(tls, bp+32)
}

func fts5IndexIntegrityCheckSegment(tls *libc.TLS, p uintptr, pSeg uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var pConfig uintptr = (*Fts5Index)(unsafe.Pointer(p)).FpConfig
	*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
	var rc2 int32
	var iIdxPrevLeaf int32 = (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst - 1
	var iDlidxPrevLeaf int32 = (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast

	if (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst == 0 {
		return
	}

	fts5IndexPrepareStmt(tls, p, bp+24, Xsqlite3_mprintf(tls,
		ts+42480,
		libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName, (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)))

	for (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 24))) {
		var iRow I64
		var pLeaf uintptr

		var zIdxTerm uintptr = Xsqlite3_column_blob(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), 1)
		var nIdxTerm int32 = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), 1)
		var iIdxLeaf int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), 2)
		var bIdxDlidx int32 = Xsqlite3_column_int(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), 3)

		if iIdxLeaf < (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst {
			continue
		}
		iRow = I64((*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + I64(iIdxLeaf)
		pLeaf = fts5LeafRead(tls, p, iRow)
		if pLeaf == uintptr(0) {
			break
		}

		if (*Fts5Data)(unsafe.Pointer(pLeaf)).Fnn <= (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
			(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
		} else {
			var iOff int32
			var iRowidOff int32

			var res int32

			iOff = fts5LeafFirstTermOff(tls, pLeaf)
			iRowidOff = int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp))
			if iRowidOff >= iOff || iOff >= (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
				(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
			} else {
				iOff = iOff + sqlite3Fts5GetVarint32(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), bp+32)
				res = func() int32 {
					if func() int32 {
						if *(*int32)(unsafe.Pointer(bp + 32)) < nIdxTerm {
							return *(*int32)(unsafe.Pointer(bp + 32))
						}
						return nIdxTerm
					}() <= 0 {
						return 0
					}
					return libc.Xmemcmp(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iOff), zIdxTerm, func() uint64 {
						if *(*int32)(unsafe.Pointer(bp + 32)) < nIdxTerm {
							return uint64(*(*int32)(unsafe.Pointer(bp + 32)))
						}
						return uint64(nIdxTerm)
					}())
				}()
				if res == 0 {
					res = *(*int32)(unsafe.Pointer(bp + 32)) - nIdxTerm
				}
				if res < 0 {
					(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
				}
			}

			fts5IntegrityCheckPgidx(tls, p, pLeaf)
		}
		fts5DataRelease(tls, pLeaf)
		if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}

		fts5IndexIntegrityCheckEmpty(tls,
			p, pSeg, iIdxPrevLeaf+1, iDlidxPrevLeaf+1, iIdxLeaf-1)
		if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}

		if bIdxDlidx != 0 {
			var pDlidx uintptr = uintptr(0)
			var iPrevLeaf int32 = iIdxLeaf
			var iSegid int32 = (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid
			var iPg int32 = 0
			var iKey I64

			for pDlidx = fts5DlidxIterInit(tls, p, 0, iSegid, iIdxLeaf); fts5DlidxIterEof(tls, p, pDlidx) == 0; fts5DlidxIterNext(tls, p, pDlidx) {
				for iPg = iPrevLeaf + 1; iPg < fts5DlidxIterPgno(tls, pDlidx); iPg++ {
					iKey = I64(iSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + I64(iPg)
					pLeaf = fts5DataRead(tls, p, iKey)
					if pLeaf != 0 {
						if int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp)) != 0 {
							(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
						}
						fts5DataRelease(tls, pLeaf)
					}
				}
				iPrevLeaf = fts5DlidxIterPgno(tls, pDlidx)

				iKey = I64(iSegid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + I64(iPrevLeaf)
				pLeaf = fts5DataRead(tls, p, iKey)
				if pLeaf != 0 {
					var iRowidOff int32 = int32(fts5GetU16(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp))

					if iRowidOff >= (*Fts5Data)(unsafe.Pointer(pLeaf)).FszLeaf {
						(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
					} else {
						sqlite3Fts5GetVarint(tls, (*Fts5Data)(unsafe.Pointer(pLeaf)).Fp+uintptr(iRowidOff), bp+40)
						if *(*I64)(unsafe.Pointer(bp + 40)) != fts5DlidxIterRowid(tls, pDlidx) {
							(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
						}
					}
					fts5DataRelease(tls, pLeaf)
				}
			}

			iDlidxPrevLeaf = iPg
			fts5DlidxIterFree(tls, pDlidx)

		} else {
			iDlidxPrevLeaf = (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast

		}

		iIdxPrevLeaf = iIdxLeaf
	}

	rc2 = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		(*Fts5Index)(unsafe.Pointer(p)).Frc = rc2
	}

}

func sqlite3Fts5IndexIntegrityCheck(tls *libc.TLS, p uintptr, cksum U64, bUseCksum int32) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var eDetail int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Index)(unsafe.Pointer(p)).FpConfig)).FeDetail
	var cksum2 U64 = uint64(0)
	*(*Fts5Buffer)(unsafe.Pointer(bp + 16)) = Fts5Buffer{}

	var pStruct uintptr
	var iLvl int32
	var iSeg int32

	var flags int32 = FTS5INDEX_QUERY_NOOUTPUT

	pStruct = fts5StructureRead(tls, p)
	if pStruct == uintptr(0) {
		return fts5IndexReturn(tls, p)
	}

	for iLvl = 0; iLvl < (*Fts5Structure)(unsafe.Pointer(pStruct)).FnLevel; iLvl++ {
		for iSeg = 0; iSeg < (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLvl)*16)).FnSeg; iSeg++ {
			var pSeg uintptr = (*Fts5StructureLevel)(unsafe.Pointer(pStruct+24+uintptr(iLvl)*16)).FaSeg + uintptr(iSeg)*12
			fts5IndexIntegrityCheckSegment(tls, p, pSeg)
		}
	}

	for fts5MultiIterNew(tls, p, pStruct, flags, uintptr(0), uintptr(0), 0, -1, 0, bp); fts5MultiIterEof(tls, p, *(*uintptr)(unsafe.Pointer(bp))) == 0; fts5MultiIterNext(tls, p, *(*uintptr)(unsafe.Pointer(bp)), 0, int64(0)) {
		*(*I64)(unsafe.Pointer(bp + 40)) = int64(0)
		*(*int32)(unsafe.Pointer(bp + 32)) = 0
		var iRowid I64 = fts5MultiIterRowid(tls, *(*uintptr)(unsafe.Pointer(bp)))
		var z uintptr = fts5MultiIterTerm(tls, *(*uintptr)(unsafe.Pointer(bp)), bp+8)

		if (*Fts5Index)(unsafe.Pointer(p)).Frc != 0 {
			break
		}

		if eDetail == FTS5_DETAIL_NONE {
			if 0 == fts5MultiIterIsEmpty(tls, p, *(*uintptr)(unsafe.Pointer(bp))) {
				cksum2 = cksum2 ^ sqlite3Fts5IndexEntryCksum(tls, iRowid, 0, 0, -1, z, *(*int32)(unsafe.Pointer(bp + 8)))
			}
		} else {
			(*Fts5Buffer)(unsafe.Pointer(bp + 16)).Fn = 0
			fts5SegiterPoslist(tls, p, *(*uintptr)(unsafe.Pointer(bp))+96+uintptr((*Fts5CResult)(unsafe.Pointer((*Fts5Iter)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FaFirst+1*4)).FiFirst)*120, uintptr(0), bp+16)
			sqlite3Fts5BufferAppendBlob(tls, p+52, bp+16, uint32(4), ts+42566)
			for 0 == sqlite3Fts5PoslistNext64(tls, (*Fts5Buffer)(unsafe.Pointer(bp+16)).Fp, (*Fts5Buffer)(unsafe.Pointer(bp+16)).Fn, bp+32, bp+40) {
				var iCol int32 = int32(*(*I64)(unsafe.Pointer(bp + 40)) >> 32)
				var iTokOff int32 = int32(*(*I64)(unsafe.Pointer(bp + 40)) & int64(0x7FFFFFFF))
				cksum2 = cksum2 ^ sqlite3Fts5IndexEntryCksum(tls, iRowid, iCol, iTokOff, -1, z, *(*int32)(unsafe.Pointer(bp + 8)))
			}
		}
	}

	fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if (*Fts5Index)(unsafe.Pointer(p)).Frc == SQLITE_OK && bUseCksum != 0 && cksum != cksum2 {
		(*Fts5Index)(unsafe.Pointer(p)).Frc = SQLITE_CORRUPT | int32(1)<<8
	}

	fts5StructureRelease(tls, pStruct)
	sqlite3Fts5BufferFree(tls, bp+16)
	return fts5IndexReturn(tls, p)
}

func fts5DecodeRowid(tls *libc.TLS, iRowid I64, piSegid uintptr, pbDlidx uintptr, piHeight uintptr, piPgno uintptr) {
	*(*int32)(unsafe.Pointer(piPgno)) = int32(iRowid & (int64(1)<<FTS5_DATA_PAGE_B - int64(1)))
	iRowid >>= FTS5_DATA_PAGE_B

	*(*int32)(unsafe.Pointer(piHeight)) = int32(iRowid & (int64(1)<<FTS5_DATA_HEIGHT_B - int64(1)))
	iRowid >>= FTS5_DATA_HEIGHT_B

	*(*int32)(unsafe.Pointer(pbDlidx)) = int32(iRowid & int64(0x0001))
	iRowid >>= FTS5_DATA_DLI_B

	*(*int32)(unsafe.Pointer(piSegid)) = int32(iRowid & (int64(1)<<FTS5_DATA_ID_B - int64(1)))
}

func fts5DebugRowid(tls *libc.TLS, pRc uintptr, pBuf uintptr, iKey I64) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	fts5DecodeRowid(tls, iKey, bp+32, bp+36, bp+40, bp+44)

	if *(*int32)(unsafe.Pointer(bp + 32)) == 0 {
		if iKey == int64(FTS5_AVERAGES_ROWID) {
			sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42571, 0)
		} else {
			sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42583, 0)
		}
	} else {
		sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42595,
			libc.VaList(bp, func() uintptr {
				if *(*int32)(unsafe.Pointer(bp + 36)) != 0 {
					return ts + 42621
				}
				return ts + 1636
			}(), *(*int32)(unsafe.Pointer(bp + 32)), *(*int32)(unsafe.Pointer(bp + 40)), *(*int32)(unsafe.Pointer(bp + 44))))
	}
}

func fts5DebugStructure(tls *libc.TLS, pRc uintptr, pBuf uintptr, p uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var iLvl int32
	var iSeg int32

	for iLvl = 0; iLvl < (*Fts5Structure)(unsafe.Pointer(p)).FnLevel; iLvl++ {
		var pLvl uintptr = p + 24 + uintptr(iLvl)*16
		sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf,
			ts+42628, libc.VaList(bp, iLvl, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnMerge, (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg))
		for iSeg = 0; iSeg < (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FnSeg; iSeg++ {
			var pSeg uintptr = (*Fts5StructureLevel)(unsafe.Pointer(pLvl)).FaSeg + uintptr(iSeg)*12
			sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42655,
				libc.VaList(bp+24, (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FiSegid, (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoFirst, (*Fts5StructureSegment)(unsafe.Pointer(pSeg)).FpgnoLast))
		}
		sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+32952, 0)
	}
}

func fts5DecodeStructure(tls *libc.TLS, pRc uintptr, pBuf uintptr, pBlob uintptr, nBlob int32) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)

	rc = fts5StructureDecode(tls, pBlob, nBlob, uintptr(0), bp)
	if rc != SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRc)) = rc
		return
	}

	fts5DebugStructure(tls, pRc, pBuf, *(*uintptr)(unsafe.Pointer(bp)))
	fts5StructureRelease(tls, *(*uintptr)(unsafe.Pointer(bp)))
}

func fts5DecodeAverages(tls *libc.TLS, pRc uintptr, pBuf uintptr, pBlob uintptr, nBlob int32) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var i int32 = 0
	var zSpace uintptr = ts + 1636

	for i < nBlob {
		i = i + int32(sqlite3Fts5GetVarint(tls, pBlob+uintptr(i), bp+16))
		sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42678, libc.VaList(bp, zSpace, int32(*(*U64)(unsafe.Pointer(bp + 16)))))
		zSpace = ts + 14304
	}
}

func fts5DecodePoslist(tls *libc.TLS, pRc uintptr, pBuf uintptr, a uintptr, n int32) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var iOff int32 = 0
	for iOff < n {
		iOff = iOff + sqlite3Fts5GetVarint32(tls, a+uintptr(iOff), bp+8)
		sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+41808, libc.VaList(bp, *(*int32)(unsafe.Pointer(bp + 8))))
	}
	return iOff
}

func fts5DecodeDoclist(tls *libc.TLS, pRc uintptr, pBuf uintptr, a uintptr, n int32) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	*(*I64)(unsafe.Pointer(bp + 32)) = int64(0)
	var iOff int32 = 0

	if n > 0 {
		iOff = int32(sqlite3Fts5GetVarint(tls, a, bp+32))
		sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42683, libc.VaList(bp, *(*I64)(unsafe.Pointer(bp + 32))))
	}
	for iOff < n {
		iOff = iOff + fts5GetPoslistSize(tls, a+uintptr(iOff), bp+40, bp+44)
		sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42692, libc.VaList(bp+8, *(*int32)(unsafe.Pointer(bp + 40)), func() uintptr {
			if *(*int32)(unsafe.Pointer(bp + 44)) != 0 {
				return ts + 9661
			}
			return ts + 1636
		}()))
		iOff = iOff + fts5DecodePoslist(tls, pRc, pBuf, a+uintptr(iOff), func() int32 {
			if n-iOff < *(*int32)(unsafe.Pointer(bp + 40)) {
				return n - iOff
			}
			return *(*int32)(unsafe.Pointer(bp + 40))
		}())
		if iOff < n {
			iOff = iOff + int32(sqlite3Fts5GetVarint(tls, a+uintptr(iOff), bp+48))
			*(*I64)(unsafe.Pointer(bp + 32)) += *(*I64)(unsafe.Pointer(bp + 48))
			sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42683, libc.VaList(bp+24, *(*I64)(unsafe.Pointer(bp + 32))))
		}
	}

	return iOff
}

func fts5DecodeRowidList(tls *libc.TLS, pRc uintptr, pBuf uintptr, pData uintptr, nData int32) {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var i int32 = 0
	var iRowid I64 = int64(0)

	for i < nData {
		var zApp uintptr = ts + 1636

		i = i + int32(sqlite3Fts5GetVarint(tls, pData+uintptr(i), bp+16))
		iRowid = I64(U64(iRowid) + *(*U64)(unsafe.Pointer(bp + 16)))

		if i < nData && int32(*(*U8)(unsafe.Pointer(pData + uintptr(i)))) == 0x00 {
			i++
			if i < nData && int32(*(*U8)(unsafe.Pointer(pData + uintptr(i)))) == 0x00 {
				i++
				zApp = ts + 42703
			} else {
				zApp = ts + 9661
			}
		}

		sqlite3Fts5BufferAppendPrintf(tls, pRc, pBuf, ts+42705, libc.VaList(bp, iRowid, zApp))
	}
}

func fts5DecodeFunction(tls *libc.TLS, pCtx uintptr, nArg int32, apVal uintptr) {
	bp := tls.Alloc(192)
	defer tls.Free(192)

	var iRowid I64

	var aBlob uintptr
	var n int32
	var a uintptr

	var nSpace Sqlite3_int64
	var eDetailNone int32

	var szLeaf int32
	var iPgidxOff int32

	var iOff int32
	var bFirst int32

	var iEnd int32

	var szLeaf1 int32
	var iPgidxOff1 int32
	var iPgidxPrev int32

	var iRowidOff int32
	var iOff1 int32
	var nDoclist int32
	a = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_OK
	nSpace = int64(0)
	eDetailNone = libc.Bool32(Xsqlite3_user_data(tls, pCtx) != uintptr(0))

	_ = nArg
	libc.Xmemset(tls, bp+48, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))
	iRowid = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal)))

	n = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
	aBlob = Xsqlite3_value_blob(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
	nSpace = Sqlite3_int64(n + FTS5_DATA_ZERO_PADDING)
	a = sqlite3Fts5MallocZero(tls, bp+64, nSpace)
	if !(a == uintptr(0)) {
		goto __1
	}
	goto decode_out
__1:
	;
	if !(n > 0) {
		goto __2
	}
	libc.Xmemcpy(tls, a, aBlob, uint64(n))
__2:
	;
	fts5DecodeRowid(tls, iRowid, bp+68, bp+72, bp+76, bp+80)

	fts5DebugRowid(tls, bp+64, bp+48, iRowid)
	if !(*(*int32)(unsafe.Pointer(bp + 72)) != 0) {
		goto __3
	}

	(*Fts5Data)(unsafe.Pointer(bp + 120)).Fp = a
	(*Fts5Data)(unsafe.Pointer(bp + 120)).Fnn = n

	libc.Xmemset(tls, bp+88, 0, uint64(unsafe.Sizeof(Fts5DlidxLvl{})))
	(*Fts5DlidxLvl)(unsafe.Pointer(bp + 88)).FpData = bp + 120
	(*Fts5DlidxLvl)(unsafe.Pointer(bp + 88)).FiLeafPgno = *(*int32)(unsafe.Pointer(bp + 80))

	fts5DlidxLvlNext(tls, bp+88)
__5:
	if !((*Fts5DlidxLvl)(unsafe.Pointer(bp+88)).FbEof == 0) {
		goto __7
	}
	sqlite3Fts5BufferAppendPrintf(tls, bp+64, bp+48,
		ts+42713, libc.VaList(bp, (*Fts5DlidxLvl)(unsafe.Pointer(bp+88)).FiLeafPgno, (*Fts5DlidxLvl)(unsafe.Pointer(bp+88)).FiRowid))
	goto __6
__6:
	fts5DlidxLvlNext(tls, bp+88)
	goto __5
	goto __7
__7:
	;
	goto __4
__3:
	if !(*(*int32)(unsafe.Pointer(bp + 68)) == 0) {
		goto __8
	}
	if !(iRowid == int64(FTS5_AVERAGES_ROWID)) {
		goto __10
	}
	fts5DecodeAverages(tls, bp+64, bp+48, a, n)
	goto __11
__10:
	fts5DecodeStructure(tls, bp+64, bp+48, a, n)
__11:
	;
	goto __9
__8:
	if !(eDetailNone != 0) {
		goto __12
	}
	iPgidxOff = libc.AssignInt32(&szLeaf, int32(fts5GetU16(tls, a+2)))
	*(*int32)(unsafe.Pointer(bp + 164)) = 0

	libc.Xmemset(tls, bp+136, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))

	if !(szLeaf < n) {
		goto __14
	}
	iPgidxOff = iPgidxOff + sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidxOff), bp+152)
	goto __15
__14:
	*(*int32)(unsafe.Pointer(bp + 152)) = szLeaf
__15:
	;
	fts5DecodeRowidList(tls, bp+64, bp+48, a+4, *(*int32)(unsafe.Pointer(bp + 152))-4)

	iOff = *(*int32)(unsafe.Pointer(bp + 152))
__16:
	if !(iOff < szLeaf) {
		goto __17
	}

	iOff = iOff + sqlite3Fts5GetVarint32(tls, a+uintptr(iOff), bp+156)
	(*Fts5Buffer)(unsafe.Pointer(bp + 136)).Fn = *(*int32)(unsafe.Pointer(bp + 164))
	sqlite3Fts5BufferAppendBlob(tls, bp+64, bp+136, uint32(*(*int32)(unsafe.Pointer(bp + 156))), a+uintptr(iOff))
	sqlite3Fts5BufferAppendPrintf(tls,
		bp+64, bp+48, ts+42723, libc.VaList(bp+16, (*Fts5Buffer)(unsafe.Pointer(bp+136)).Fn, (*Fts5Buffer)(unsafe.Pointer(bp+136)).Fp))
	iOff = iOff + *(*int32)(unsafe.Pointer(bp + 156))

	if !(iPgidxOff < n) {
		goto __18
	}
	iPgidxOff = iPgidxOff + sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidxOff), bp+160)
	*(*int32)(unsafe.Pointer(bp + 152)) += *(*int32)(unsafe.Pointer(bp + 160))
	goto __19
__18:
	*(*int32)(unsafe.Pointer(bp + 152)) = szLeaf
__19:
	;
	fts5DecodeRowidList(tls, bp+64, bp+48, a+uintptr(iOff), *(*int32)(unsafe.Pointer(bp + 152))-iOff)
	iOff = *(*int32)(unsafe.Pointer(bp + 152))
	if !(iOff < szLeaf) {
		goto __20
	}
	iOff = iOff + sqlite3Fts5GetVarint32(tls, a+uintptr(iOff), bp+164)
__20:
	;
	goto __16
__17:
	;
	sqlite3Fts5BufferFree(tls, bp+136)
	goto __13
__12:
	iPgidxPrev = 0
	*(*int32)(unsafe.Pointer(bp + 184)) = 0
	iRowidOff = 0

	libc.Xmemset(tls, bp+168, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))

	if !(n < 4) {
		goto __21
	}
	sqlite3Fts5BufferSet(tls, bp+64, bp+48, 7, ts+42734)
	goto decode_out
	goto __22
__21:
	iRowidOff = int32(fts5GetU16(tls, a))
	iPgidxOff1 = libc.AssignInt32(&szLeaf1, int32(fts5GetU16(tls, a+2)))
	if !(iPgidxOff1 < n) {
		goto __23
	}
	sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidxOff1), bp+184)
	goto __24
__23:
	if !(iPgidxOff1 > n) {
		goto __25
	}
	*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_CORRUPT | int32(1)<<8
	goto decode_out
__25:
	;
__24:
	;
__22:
	;
	if !(iRowidOff != 0) {
		goto __26
	}
	iOff1 = iRowidOff
	goto __27
__26:
	if !(*(*int32)(unsafe.Pointer(bp + 184)) != 0) {
		goto __28
	}
	iOff1 = *(*int32)(unsafe.Pointer(bp + 184))
	goto __29
__28:
	iOff1 = szLeaf1
__29:
	;
__27:
	;
	if !(iOff1 > n) {
		goto __30
	}
	*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_CORRUPT | int32(1)<<8
	goto decode_out
__30:
	;
	fts5DecodePoslist(tls, bp+64, bp+48, a+4, iOff1-4)

	nDoclist = func() int32 {
		if *(*int32)(unsafe.Pointer(bp + 184)) != 0 {
			return *(*int32)(unsafe.Pointer(bp + 184))
		}
		return szLeaf1
	}() - iOff1
	if !(nDoclist+iOff1 > n) {
		goto __31
	}
	*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_CORRUPT | int32(1)<<8
	goto decode_out
__31:
	;
	fts5DecodeDoclist(tls, bp+64, bp+48, a+uintptr(iOff1), nDoclist)

__32:
	if !(iPgidxOff1 < n && *(*int32)(unsafe.Pointer(bp + 64)) == SQLITE_OK) {
		goto __33
	}
	bFirst = libc.Bool32(iPgidxOff1 == szLeaf1)

	iPgidxOff1 = iPgidxOff1 + sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidxOff1), bp+188)
	iPgidxPrev = iPgidxPrev + *(*int32)(unsafe.Pointer(bp + 188))
	iOff1 = iPgidxPrev

	if !(iPgidxOff1 < n) {
		goto __34
	}
	sqlite3Fts5GetVarint32(tls, a+uintptr(iPgidxOff1), bp+188)
	iEnd = iPgidxPrev + *(*int32)(unsafe.Pointer(bp + 188))
	goto __35
__34:
	iEnd = szLeaf1
__35:
	;
	if !(iEnd > szLeaf1) {
		goto __36
	}
	*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_CORRUPT | int32(1)<<8
	goto __33
__36:
	;
	if !(bFirst == 0) {
		goto __37
	}
	iOff1 = iOff1 + sqlite3Fts5GetVarint32(tls, a+uintptr(iOff1), bp+188)
	if !(*(*int32)(unsafe.Pointer(bp + 188)) > (*Fts5Buffer)(unsafe.Pointer(bp+168)).Fn) {
		goto __38
	}
	*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_CORRUPT | int32(1)<<8
	goto __33
__38:
	;
	(*Fts5Buffer)(unsafe.Pointer(bp + 168)).Fn = *(*int32)(unsafe.Pointer(bp + 188))
__37:
	;
	iOff1 = iOff1 + sqlite3Fts5GetVarint32(tls, a+uintptr(iOff1), bp+188)
	if !(iOff1+*(*int32)(unsafe.Pointer(bp + 188)) > n) {
		goto __39
	}
	*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_CORRUPT | int32(1)<<8
	goto __33
__39:
	;
	sqlite3Fts5BufferAppendBlob(tls, bp+64, bp+168, uint32(*(*int32)(unsafe.Pointer(bp + 188))), a+uintptr(iOff1))
	iOff1 = iOff1 + *(*int32)(unsafe.Pointer(bp + 188))

	sqlite3Fts5BufferAppendPrintf(tls,
		bp+64, bp+48, ts+42723, libc.VaList(bp+32, (*Fts5Buffer)(unsafe.Pointer(bp+168)).Fn, (*Fts5Buffer)(unsafe.Pointer(bp+168)).Fp))
	iOff1 = iOff1 + fts5DecodeDoclist(tls, bp+64, bp+48, a+uintptr(iOff1), iEnd-iOff1)
	goto __32
__33:
	;
	sqlite3Fts5BufferFree(tls, bp+168)
__13:
	;
__9:
	;
__4:
	;
decode_out:
	Xsqlite3_free(tls, a)
	if !(*(*int32)(unsafe.Pointer(bp + 64)) == SQLITE_OK) {
		goto __40
	}
	Xsqlite3_result_text(tls, pCtx, (*Fts5Buffer)(unsafe.Pointer(bp+48)).Fp, (*Fts5Buffer)(unsafe.Pointer(bp+48)).Fn, libc.UintptrFromInt32(-1))
	goto __41
__40:
	Xsqlite3_result_error_code(tls, pCtx, *(*int32)(unsafe.Pointer(bp + 64)))
__41:
	;
	sqlite3Fts5BufferFree(tls, bp+48)
}

func fts5RowidFunction(tls *libc.TLS, pCtx uintptr, nArg int32, apVal uintptr) {
	var zArg uintptr
	if nArg == 0 {
		Xsqlite3_result_error(tls, pCtx, ts+42742, -1)
	} else {
		zArg = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal)))
		if 0 == Xsqlite3_stricmp(tls, zArg, ts+42779) {
			var iRowid I64
			var segid int32
			var pgno int32
			if nArg != 3 {
				Xsqlite3_result_error(tls, pCtx,
					ts+42787, -1)
			} else {
				segid = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
				pgno = Xsqlite3_value_int(tls, *(*uintptr)(unsafe.Pointer(apVal + 2*8)))
				iRowid = I64(segid)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B+FTS5_DATA_DLI_B) + int64(0)<<(FTS5_DATA_PAGE_B+FTS5_DATA_HEIGHT_B) + int64(0)<<FTS5_DATA_PAGE_B + I64(pgno)
				Xsqlite3_result_int64(tls, pCtx, iRowid)
			}
		} else {
			Xsqlite3_result_error(tls, pCtx,
				ts+42834, -1)
		}
	}
}

func sqlite3Fts5IndexInit(tls *libc.TLS, db uintptr) int32 {
	var rc int32 = Xsqlite3_create_function(tls,
		db, ts+42878, 2, SQLITE_UTF8, uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{fts5DecodeFunction})), uintptr(0), uintptr(0))

	if rc == SQLITE_OK {
		rc = Xsqlite3_create_function(tls,
			db, ts+42890, 2,
			SQLITE_UTF8, db, *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr)
			}{fts5DecodeFunction})), uintptr(0), uintptr(0))
	}

	if rc == SQLITE_OK {
		rc = Xsqlite3_create_function(tls,
			db, ts+42907, -1, SQLITE_UTF8, uintptr(0), *(*uintptr)(unsafe.Pointer(&struct {
				f func(*libc.TLS, uintptr, int32, uintptr)
			}{fts5RowidFunction})), uintptr(0), uintptr(0))
	}
	return rc
}

func sqlite3Fts5IndexReset(tls *libc.TLS, p uintptr) int32 {
	if fts5IndexDataVersion(tls, p) != (*Fts5Index)(unsafe.Pointer(p)).FiStructVersion {
		fts5StructureInvalidate(tls, p)
	}
	return fts5IndexReturn(tls, p)
}

type Fts5Auxdata1 = struct {
	FpAux    uintptr
	FpPtr    uintptr
	FxDelete uintptr
	FpNext   uintptr
}

type Fts5Auxdata = Fts5Auxdata1
type Fts5Auxiliary1 = struct {
	FpGlobal   uintptr
	FzFunc     uintptr
	FpUserData uintptr
	FxFunc     Fts5_extension_function
	FxDestroy  uintptr
	FpNext     uintptr
}

type Fts5Auxiliary = Fts5Auxiliary1
type Fts5Cursor1 = struct {
	Fbase         Sqlite3_vtab_cursor
	FpNext        uintptr
	FaColumnSize  uintptr
	FiCsrId       I64
	FePlan        int32
	FbDesc        int32
	FiFirstRowid  I64
	FiLastRowid   I64
	FpStmt        uintptr
	FpExpr        uintptr
	FpSorter      uintptr
	Fcsrflags     int32
	F__ccgo_pad1  [4]byte
	FiSpecial     I64
	FzRank        uintptr
	FzRankArgs    uintptr
	FpRank        uintptr
	FnRankArg     int32
	F__ccgo_pad2  [4]byte
	FapRankArg    uintptr
	FpRankArgStmt uintptr
	FpAux         uintptr
	FpAuxdata     uintptr
	FaInstIter    uintptr
	FnInstAlloc   int32
	FnInstCount   int32
	FaInst        uintptr
}

type Fts5Cursor = Fts5Cursor1
type Fts5FullTable1 = struct {
	Fp        Fts5Table
	FpStorage uintptr
	FpGlobal  uintptr
	FpSortCsr uintptr
}

type Fts5FullTable = Fts5FullTable1
type Fts5Sorter1 = struct {
	FpStmt    uintptr
	FiRowid   I64
	FaPoslist uintptr
	FnIdx     int32
	FaIdx     [1]int32
}

type Fts5Sorter = Fts5Sorter1
type Fts5TokenizerModule1 = struct {
	FzName     uintptr
	FpUserData uintptr
	Fx         Fts5_tokenizer
	FxDestroy  uintptr
	FpNext     uintptr
}

type Fts5TokenizerModule = Fts5TokenizerModule1

type Fts5TransactionState = struct {
	FeState     int32
	FiSavepoint int32
}

type Fts5MatchPhrase = struct {
	FpPoslist    uintptr
	FnTerm       int32
	F__ccgo_pad1 [4]byte
}

func fts5IsContentless(tls *libc.TLS, pTab uintptr) int32 {
	return libc.Bool32((*Fts5Config)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FeContent == FTS5_CONTENT_NONE)
}

func fts5FreeVtab(tls *libc.TLS, pTab uintptr) {
	if pTab != 0 {
		sqlite3Fts5IndexClose(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
		sqlite3Fts5StorageClose(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
		sqlite3Fts5ConfigFree(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)
		Xsqlite3_free(tls, pTab)
	}
}

func fts5DisconnectMethod(tls *libc.TLS, pVtab uintptr) int32 {
	fts5FreeVtab(tls, pVtab)
	return SQLITE_OK
}

func fts5DestroyMethod(tls *libc.TLS, pVtab uintptr) int32 {
	var pTab uintptr = pVtab
	var rc int32 = sqlite3Fts5DropAll(tls, (*Fts5Table)(unsafe.Pointer(pTab)).FpConfig)
	if rc == SQLITE_OK {
		fts5FreeVtab(tls, pVtab)
	}
	return rc
}

func fts5InitVtab(tls *libc.TLS, bCreate int32, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVTab uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pGlobal uintptr = pAux
	var azConfig uintptr = argv
	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	var pTab uintptr = uintptr(0)

	pTab = sqlite3Fts5MallocZero(tls, bp, int64(unsafe.Sizeof(Fts5FullTable{})))
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = sqlite3Fts5ConfigParse(tls, pGlobal, db, argc, azConfig, bp+8, pzErr)

	}
	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig = *(*uintptr)(unsafe.Pointer(bp + 8))
		(*Fts5FullTable)(unsafe.Pointer(pTab)).FpGlobal = pGlobal
	}

	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = sqlite3Fts5IndexOpen(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), bCreate, pTab+32, pzErr)
	}

	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = sqlite3Fts5StorageOpen(tls,
			*(*uintptr)(unsafe.Pointer(bp + 8)), (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex, bCreate, pTab+40, pzErr)
	}

	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp)) = sqlite3Fts5ConfigDeclareVtab(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	}

	if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
		(*Fts5Config)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpzErrmsg = pzErr
		*(*int32)(unsafe.Pointer(bp)) = sqlite3Fts5IndexLoadConfig(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
		sqlite3Fts5IndexRollback(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
		(*Fts5Config)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 8)))).FpzErrmsg = uintptr(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))
}

func fts5ConnectMethod(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) 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) int32 {
	return fts5InitVtab(tls, 1, db, pAux, argc, argv, ppVtab, pzErr)
}

func fts5SetUniqueFlag(tls *libc.TLS, pIdxInfo uintptr) {
	{
		*(*int32)(unsafe.Pointer(pIdxInfo + 80)) |= SQLITE_INDEX_SCAN_UNIQUE

	}
}

func fts5UsePatternMatch(tls *libc.TLS, pConfig uintptr, p uintptr) int32 {
	if (*Fts5Config)(unsafe.Pointer(pConfig)).FePattern == FTS5_PATTERN_GLOB && int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == FTS5_PATTERN_GLOB {
		return 1
	}
	if (*Fts5Config)(unsafe.Pointer(pConfig)).FePattern == FTS5_PATTERN_LIKE &&
		(int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == FTS5_PATTERN_LIKE || int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == FTS5_PATTERN_GLOB) {
		return 1
	}
	return 0
}

func fts5BestIndexMethod(tls *libc.TLS, pVTab uintptr, pInfo uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTab uintptr = pVTab
	var pConfig uintptr = (*Fts5Table)(unsafe.Pointer(pTab)).FpConfig
	var nCol int32 = (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol
	var idxFlags int32 = 0
	var i int32
	var idxStr uintptr
	var iIdxStr int32 = 0
	var iCons int32 = 0

	var bSeenEq int32 = 0
	var bSeenGt int32 = 0
	var bSeenLt int32 = 0
	var bSeenMatch int32 = 0
	var bSeenRank int32 = 0

	if (*Fts5Config)(unsafe.Pointer(pConfig)).FbLock != 0 {
		(*Fts5Table)(unsafe.Pointer(pTab)).Fbase.FzErrMsg = Xsqlite3_mprintf(tls,
			ts+42918, 0)
		return SQLITE_ERROR
	}

	idxStr = Xsqlite3_malloc(tls, (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint*8+1)
	if idxStr == uintptr(0) {
		return SQLITE_NOMEM
	}
	(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FidxStr = idxStr
	(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FneedToFreeIdxStr = 1

	for i = 0; i < (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint; i++ {
		var p uintptr = (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraint + uintptr(i)*12
		var iCol int32 = (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_MATCH ||
			int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_EQ && iCol >= nCol {
			if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable) == 0 || iCol < 0 {
				(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = 1e50

				*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr))) = uint8(0)
				return SQLITE_OK
			} else {
				if iCol == nCol+1 {
					if bSeenRank != 0 {
						continue
					}
					*(*uint8)(unsafe.Pointer(idxStr + uintptr(libc.PostIncInt32(&iIdxStr, 1)))) = uint8('r')
					bSeenRank = 1
				} else if iCol >= 0 {
					bSeenMatch = 1
					*(*uint8)(unsafe.Pointer(idxStr + uintptr(libc.PostIncInt32(&iIdxStr, 1)))) = uint8('M')
					Xsqlite3_snprintf(tls, 6, idxStr+uintptr(iIdxStr), ts+7843, libc.VaList(bp, iCol))
					idxStr += uintptr(libc.Xstrlen(tls, idxStr+uintptr(iIdxStr)))

				}
				(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = libc.PreIncInt32(&iCons, 1)
				(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8)).Fomit = uint8(1)
			}
		} else if (*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 {
			if iCol >= 0 && iCol < nCol && fts5UsePatternMatch(tls, pConfig, p) != 0 {
				*(*uint8)(unsafe.Pointer(idxStr + uintptr(libc.PostIncInt32(&iIdxStr, 1)))) = func() uint8 {
					if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == FTS5_PATTERN_LIKE {
						return uint8('L')
					}
					return uint8('G')
				}()
				Xsqlite3_snprintf(tls, 6, idxStr+uintptr(iIdxStr), ts+7843, libc.VaList(bp+8, iCol))
				idxStr += uintptr(libc.Xstrlen(tls, idxStr+uintptr(iIdxStr)))
				(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = libc.PreIncInt32(&iCons, 1)

			} else if bSeenEq == 0 && int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_EQ && iCol < 0 {
				*(*uint8)(unsafe.Pointer(idxStr + uintptr(libc.PostIncInt32(&iIdxStr, 1)))) = uint8('=')
				bSeenEq = 1
				(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = libc.PreIncInt32(&iCons, 1)
			}
		}
	}

	if bSeenEq == 0 {
		for i = 0; i < (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint; i++ {
			var p uintptr = (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraint + uintptr(i)*12
			if (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn < 0 && (*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable != 0 {
				var op int32 = int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop)
				if op == SQLITE_INDEX_CONSTRAINT_LT || op == SQLITE_INDEX_CONSTRAINT_LE {
					if bSeenLt != 0 {
						continue
					}
					*(*uint8)(unsafe.Pointer(idxStr + uintptr(libc.PostIncInt32(&iIdxStr, 1)))) = uint8('<')
					(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = libc.PreIncInt32(&iCons, 1)
					bSeenLt = 1
				} else if op == SQLITE_INDEX_CONSTRAINT_GT || op == SQLITE_INDEX_CONSTRAINT_GE {
					if bSeenGt != 0 {
						continue
					}
					*(*uint8)(unsafe.Pointer(idxStr + uintptr(libc.PostIncInt32(&iIdxStr, 1)))) = uint8('>')
					(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(i)*8)).FargvIndex = libc.PreIncInt32(&iCons, 1)
					bSeenGt = 1
				}
			}
		}
	}
	*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr))) = uint8(0)

	if (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FnOrderBy == 1 {
		var iSort int32 = (*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy)).FiColumn
		if iSort == (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol+1 && bSeenMatch != 0 {
			idxFlags = idxFlags | FTS5_BI_ORDER_RANK
		} else if iSort == -1 {
			idxFlags = idxFlags | FTS5_BI_ORDER_ROWID
		}
		if idxFlags&(FTS5_BI_ORDER_RANK|FTS5_BI_ORDER_ROWID) != 0 {
			(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).ForderByConsumed = 1
			if (*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy)).Fdesc != 0 {
				idxFlags = idxFlags | FTS5_BI_ORDER_DESC
			}
		}
	}

	if bSeenEq != 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = func() float64 {
			if bSeenMatch != 0 {
				return 100.0
			}
			return 10.0
		}()
		if bSeenMatch == 0 {
			fts5SetUniqueFlag(tls, pInfo)
		}
	} else if bSeenLt != 0 && bSeenGt != 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = func() float64 {
			if bSeenMatch != 0 {
				return 500.0
			}
			return 250000.0
		}()
	} else if bSeenLt != 0 || bSeenGt != 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = func() float64 {
			if bSeenMatch != 0 {
				return 750.0
			}
			return 750000.0
		}()
	} else {
		(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = func() float64 {
			if bSeenMatch != 0 {
				return 1000.0
			}
			return 1000000.0
		}()
	}

	(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FidxNum = idxFlags
	return SQLITE_OK
}

func fts5NewTransaction(tls *libc.TLS, pTab uintptr) int32 {
	var pCsr uintptr
	for pCsr = (*Fts5Global)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpGlobal)).FpCsr; pCsr != 0; pCsr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpNext {
		if (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab == pTab {
			return SQLITE_OK
		}
	}
	return sqlite3Fts5StorageReset(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
}

func fts5OpenMethod(tls *libc.TLS, pVTab uintptr, ppCsr uintptr) int32 {
	var pTab uintptr = pVTab
	var pConfig uintptr = (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	var pCsr uintptr = uintptr(0)
	var nByte Sqlite3_int64
	var rc int32

	rc = fts5NewTransaction(tls, pTab)
	if rc == SQLITE_OK {
		nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Cursor{})) + uint64((*Fts5Config)(unsafe.Pointer(pConfig)).FnCol)*uint64(unsafe.Sizeof(int32(0))))
		pCsr = Xsqlite3_malloc64(tls, uint64(nByte))
		if pCsr != 0 {
			var pGlobal uintptr = (*Fts5FullTable)(unsafe.Pointer(pTab)).FpGlobal
			libc.Xmemset(tls, pCsr, 0, Size_t(nByte))
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize = pCsr + 1*184
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpNext = (*Fts5Global)(unsafe.Pointer(pGlobal)).FpCsr
			(*Fts5Global)(unsafe.Pointer(pGlobal)).FpCsr = pCsr
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId = libc.PreIncInt64(&(*Fts5Global)(unsafe.Pointer(pGlobal)).FiNextId, 1)
		} else {
			rc = SQLITE_NOMEM
		}
	}
	*(*uintptr)(unsafe.Pointer(ppCsr)) = pCsr
	return rc
}

func fts5StmtType(tls *libc.TLS, pCsr uintptr) int32 {
	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan == FTS5_PLAN_SCAN {
		if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FbDesc != 0 {
			return FTS5_STMT_SCAN_DESC
		}
		return FTS5_STMT_SCAN_ASC
	}
	return FTS5_STMT_LOOKUP
}

func fts5CsrNewrow(tls *libc.TLS, pCsr uintptr) {
	*(*int32)(unsafe.Pointer(pCsr + 80)) |= FTS5CSR_REQUIRE_CONTENT | FTS5CSR_REQUIRE_DOCSIZE | FTS5CSR_REQUIRE_INST | FTS5CSR_REQUIRE_POSLIST
}

func fts5FreeCursorComponents(tls *libc.TLS, pCsr uintptr) {
	var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	var pData uintptr
	var pNext uintptr

	Xsqlite3_free(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter)
	Xsqlite3_free(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInst)
	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt != 0 {
		var eStmt int32 = fts5StmtType(tls, pCsr)
		sqlite3Fts5StorageStmtRelease(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, eStmt, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
	}
	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 {
		var pSorter uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter
		Xsqlite3_finalize(tls, (*Fts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
		Xsqlite3_free(tls, pSorter)
	}

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan != FTS5_PLAN_SOURCE {
		sqlite3Fts5ExprFree(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	}

	for pData = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata; pData != 0; pData = pNext {
		pNext = (*Fts5Auxdata)(unsafe.Pointer(pData)).FpNext
		if (*Fts5Auxdata)(unsafe.Pointer(pData)).FxDelete != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Fts5Auxdata)(unsafe.Pointer(pData)).FxDelete})).f(tls, (*Fts5Auxdata)(unsafe.Pointer(pData)).FpPtr)
		}
		Xsqlite3_free(tls, pData)
	}

	Xsqlite3_finalize(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpRankArgStmt)
	Xsqlite3_free(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg)

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&FTS5CSR_FREE_ZRANK != 0 {
		Xsqlite3_free(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRank)
		Xsqlite3_free(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs)
	}

	sqlite3Fts5IndexCloseReader(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
	libc.Xmemset(tls, pCsr+32, 0, uint64(unsafe.Sizeof(Fts5Cursor{}))-uint64((int64(pCsr+32)-int64(pCsr))/1))
}

func fts5CloseMethod(tls *libc.TLS, pCursor uintptr) int32 {
	if pCursor != 0 {
		var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
		var pCsr uintptr = pCursor
		var pp uintptr

		fts5FreeCursorComponents(tls, pCsr)

		for pp = (*Fts5FullTable)(unsafe.Pointer(pTab)).FpGlobal + 72; *(*uintptr)(unsafe.Pointer(pp)) != pCsr; pp = *(*uintptr)(unsafe.Pointer(pp)) + 8 {
		}
		*(*uintptr)(unsafe.Pointer(pp)) = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpNext

		Xsqlite3_free(tls, pCsr)
	}
	return SQLITE_OK
}

func fts5SorterNext(tls *libc.TLS, pCsr uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pSorter uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter
	var rc int32

	rc = Xsqlite3_step(tls, (*Fts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
	if rc == SQLITE_DONE {
		rc = SQLITE_OK
		*(*int32)(unsafe.Pointer(pCsr + 80)) |= FTS5CSR_EOF | FTS5CSR_REQUIRE_CONTENT
	} else if rc == SQLITE_ROW {
		var a uintptr
		var aBlob uintptr
		var nBlob int32
		var i int32
		var iOff int32 = 0
		rc = SQLITE_OK

		(*Fts5Sorter)(unsafe.Pointer(pSorter)).FiRowid = Xsqlite3_column_int64(tls, (*Fts5Sorter)(unsafe.Pointer(pSorter)).FpStmt, 0)
		nBlob = Xsqlite3_column_bytes(tls, (*Fts5Sorter)(unsafe.Pointer(pSorter)).FpStmt, 1)
		aBlob = libc.AssignUintptr(&a, Xsqlite3_column_blob(tls, (*Fts5Sorter)(unsafe.Pointer(pSorter)).FpStmt, 1))

		if nBlob > 0 {
			for i = 0; i < (*Fts5Sorter)(unsafe.Pointer(pSorter)).FnIdx-1; i++ {
				a += uintptr(sqlite3Fts5GetVarint32(tls, a, bp))
				iOff = iOff + *(*int32)(unsafe.Pointer(bp))
				*(*int32)(unsafe.Pointer(pSorter + 28 + uintptr(i)*4)) = iOff
			}
			*(*int32)(unsafe.Pointer(pSorter + 28 + uintptr(i)*4)) = int32((int64(aBlob+uintptr(nBlob)) - int64(a)) / 1)
			(*Fts5Sorter)(unsafe.Pointer(pSorter)).FaPoslist = a
		}

		fts5CsrNewrow(tls, pCsr)
	}

	return rc
}

func fts5TripCursors(tls *libc.TLS, pTab uintptr) {
	var pCsr uintptr
	for pCsr = (*Fts5Global)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpGlobal)).FpCsr; pCsr != 0; pCsr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpNext {
		if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan == FTS5_PLAN_MATCH &&
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab == pTab {
			*(*int32)(unsafe.Pointer(pCsr + 80)) |= FTS5CSR_REQUIRE_RESEEK
		}
	}
}

func fts5CursorReseek(tls *libc.TLS, pCsr uintptr, pbSkip uintptr) int32 {
	var rc int32 = SQLITE_OK

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&FTS5CSR_REQUIRE_RESEEK != 0 {
		var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
		var bDesc int32 = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FbDesc
		var iRowid I64 = sqlite3Fts5ExprRowid(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)

		rc = sqlite3Fts5ExprFirst(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex, iRowid, bDesc)
		if rc == SQLITE_OK && iRowid != sqlite3Fts5ExprRowid(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr) {
			*(*int32)(unsafe.Pointer(pbSkip)) = 1
		}

		*(*int32)(unsafe.Pointer(pCsr + 80)) &= libc.CplInt32(FTS5CSR_REQUIRE_RESEEK)
		fts5CsrNewrow(tls, pCsr)
		if sqlite3Fts5ExprEof(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr) != 0 {
			*(*int32)(unsafe.Pointer(pCsr + 80)) |= FTS5CSR_EOF
			*(*int32)(unsafe.Pointer(pbSkip)) = 1
		}
	}
	return rc
}

func fts5NextMethod(tls *libc.TLS, pCursor uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var pCsr uintptr = pCursor
	var rc int32

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan < 3 {
		*(*int32)(unsafe.Pointer(bp + 8)) = 0
		if libc.AssignInt32(&rc, fts5CursorReseek(tls, pCsr, bp+8)) != 0 || *(*int32)(unsafe.Pointer(bp + 8)) != 0 {
			return rc
		}
		rc = sqlite3Fts5ExprNext(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid)
		*(*int32)(unsafe.Pointer(pCsr + 80)) |= sqlite3Fts5ExprEof(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
		fts5CsrNewrow(tls, pCsr)
	} else {
		switch (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan {
		case FTS5_PLAN_SPECIAL:
			{
				*(*int32)(unsafe.Pointer(pCsr + 80)) |= FTS5CSR_EOF
				rc = SQLITE_OK
				break

			}
			fallthrough

		case FTS5_PLAN_SORTED_MATCH:
			{
				rc = fts5SorterNext(tls, pCsr)
				break

			}
			fallthrough

		default:
			{
				var pConfig uintptr = (*Fts5Table)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FpConfig
				(*Fts5Config)(unsafe.Pointer(pConfig)).FbLock++
				rc = Xsqlite3_step(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
				(*Fts5Config)(unsafe.Pointer(pConfig)).FbLock--
				if rc != SQLITE_ROW {
					*(*int32)(unsafe.Pointer(pCsr + 80)) |= FTS5CSR_EOF
					rc = Xsqlite3_reset(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
					if rc != SQLITE_OK {
						(*Sqlite3_vtab)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls,
							ts+1684, libc.VaList(bp, Xsqlite3_errmsg(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb)))
					}
				} else {
					rc = SQLITE_OK
				}
				break

			}
		}
	}

	return rc
}

func fts5PrepareStatement(tls *libc.TLS, ppStmt uintptr, pConfig uintptr, zFmt uintptr, va uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
	var rc int32
	var zSql uintptr
	var ap Va_list
	_ = ap

	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFmt, ap)
	if zSql == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		rc = Xsqlite3_prepare_v3(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -1,
			uint32(SQLITE_PREPARE_PERSISTENT), bp+8, uintptr(0))
		if rc != SQLITE_OK {
			*(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp, Xsqlite3_errmsg(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb)))
		}
		Xsqlite3_free(tls, zSql)
	}

	_ = ap
	*(*uintptr)(unsafe.Pointer(ppStmt)) = *(*uintptr)(unsafe.Pointer(bp + 8))
	return rc
}

func fts5CursorFirstSorted(tls *libc.TLS, pTab uintptr, pCsr uintptr, bDesc int32) int32 {
	bp := tls.Alloc(56)
	defer tls.Free(56)

	var pConfig uintptr = (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	var pSorter uintptr
	var nPhrase int32
	var nByte Sqlite3_int64
	var rc int32
	var zRank uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRank
	var zRankArgs uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs

	nPhrase = sqlite3Fts5ExprPhraseCount(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Sorter{})) + uint64(unsafe.Sizeof(int32(0)))*uint64(nPhrase-1))
	pSorter = Xsqlite3_malloc64(tls, uint64(nByte))
	if pSorter == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pSorter, 0, Size_t(nByte))
	(*Fts5Sorter)(unsafe.Pointer(pSorter)).FnIdx = nPhrase

	rc = fts5PrepareStatement(tls, pSorter, pConfig,
		ts+42957,
		libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName, zRank, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName,
			func() uintptr {
				if zRankArgs != 0 {
					return ts + 18036
				}
				return ts + 1636
			}(),
			func() uintptr {
				if zRankArgs != 0 {
					return zRankArgs
				}
				return ts + 1636
			}(),
			func() uintptr {
				if bDesc != 0 {
					return ts + 43012
				}
				return ts + 43017
			}()))

	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter = pSorter
	if rc == SQLITE_OK {
		(*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr = pCsr
		rc = fts5SorterNext(tls, pCsr)
		(*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr = uintptr(0)
	}

	if rc != SQLITE_OK {
		Xsqlite3_finalize(tls, (*Fts5Sorter)(unsafe.Pointer(pSorter)).FpStmt)
		Xsqlite3_free(tls, pSorter)
		(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter = uintptr(0)
	}

	return rc
}

func fts5CursorFirst(tls *libc.TLS, pTab uintptr, pCsr uintptr, bDesc int32) int32 {
	var rc int32
	var pExpr uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr
	rc = sqlite3Fts5ExprFirst(tls, pExpr, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid, bDesc)
	if sqlite3Fts5ExprEof(tls, pExpr) != 0 {
		*(*int32)(unsafe.Pointer(pCsr + 80)) |= FTS5CSR_EOF
	}
	fts5CsrNewrow(tls, pCsr)
	return rc
}

func fts5SpecialMatch(tls *libc.TLS, pTab uintptr, pCsr uintptr, zQuery uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var rc int32 = SQLITE_OK
	var z uintptr = zQuery
	var n int32

	for int32(*(*uint8)(unsafe.Pointer(z))) == ' ' {
		z++
	}
	for n = 0; *(*uint8)(unsafe.Pointer(z + uintptr(n))) != 0 && int32(*(*uint8)(unsafe.Pointer(z + uintptr(n)))) != ' '; n++ {
	}

	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan = FTS5_PLAN_SPECIAL

	if n == 5 && 0 == Xsqlite3_strnicmp(tls, ts+43021, z, n) {
		(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial = I64(sqlite3Fts5IndexReads(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex))
	} else if n == 2 && 0 == Xsqlite3_strnicmp(tls, ts+7982, z, n) {
		(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId
	} else {
		(*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, ts+43027, libc.VaList(bp, n, z))
		rc = SQLITE_ERROR
	}

	return rc
}

func fts5FindAuxiliary(tls *libc.TLS, pTab uintptr, zName uintptr) uintptr {
	var pAux uintptr

	for pAux = (*Fts5Global)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpGlobal)).FpAux; pAux != 0; pAux = (*Fts5Auxiliary)(unsafe.Pointer(pAux)).FpNext {
		if Xsqlite3_stricmp(tls, zName, (*Fts5Auxiliary)(unsafe.Pointer(pAux)).FzFunc) == 0 {
			return pAux
		}
	}

	return uintptr(0)
}

func fts5FindRankFunction(tls *libc.TLS, pCsr uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	var pConfig uintptr = (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
	var pAux uintptr = uintptr(0)
	var zRank uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRank
	var zRankArgs uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs

	if zRankArgs != 0 {
		var zSql uintptr = sqlite3Fts5Mprintf(tls, bp+16, ts+43055, libc.VaList(bp, zRankArgs))
		if zSql != 0 {
			*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
			*(*int32)(unsafe.Pointer(bp + 16)) = Xsqlite3_prepare_v3(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -1,
				uint32(SQLITE_PREPARE_PERSISTENT), bp+24, uintptr(0))
			Xsqlite3_free(tls, zSql)

			if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
				if SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 24))) {
					var nByte Sqlite3_int64
					(*Fts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg = Xsqlite3_column_count(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
					nByte = Sqlite3_int64(uint64(unsafe.Sizeof(uintptr(0))) * uint64((*Fts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg))
					(*Fts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg = sqlite3Fts5MallocZero(tls, bp+16, nByte)
					if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
						var i int32
						for i = 0; i < (*Fts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg; i++ {
							*(*uintptr)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg + uintptr(i)*8)) = Xsqlite3_column_value(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), i)
						}
					}
					(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpRankArgStmt = *(*uintptr)(unsafe.Pointer(bp + 24))
				} else {
					*(*int32)(unsafe.Pointer(bp + 16)) = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))

				}
			}
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		pAux = fts5FindAuxiliary(tls, pTab, zRank)
		if pAux == uintptr(0) {
			(*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls, ts+43065, libc.VaList(bp+8, zRank))
			*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_ERROR
		}
	}

	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpRank = pAux
	return *(*int32)(unsafe.Pointer(bp + 16))
}

func fts5CursorParseRank(tls *libc.TLS, pConfig uintptr, pCsr uintptr, pRank uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var rc int32 = SQLITE_OK
	if pRank != 0 {
		var z uintptr = Xsqlite3_value_text(tls, pRank)
		*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
		*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)

		if z == uintptr(0) {
			if Xsqlite3_value_type(tls, pRank) == SQLITE_NULL {
				rc = SQLITE_ERROR
			}
		} else {
			rc = sqlite3Fts5ConfigParseRank(tls, z, bp+8, bp+16)
		}
		if rc == SQLITE_OK {
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRank = *(*uintptr)(unsafe.Pointer(bp + 8))
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = *(*uintptr)(unsafe.Pointer(bp + 16))
			*(*int32)(unsafe.Pointer(pCsr + 80)) |= FTS5CSR_FREE_ZRANK
		} else if rc == SQLITE_ERROR {
			(*Sqlite3_vtab)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FzErrMsg = Xsqlite3_mprintf(tls,
				ts+43086, libc.VaList(bp, z))
		}
	} else {
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FzRank != 0 {
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRank = (*Fts5Config)(unsafe.Pointer(pConfig)).FzRank
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = (*Fts5Config)(unsafe.Pointer(pConfig)).FzRankArgs
		} else {
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRank = ts + 40825
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FzRankArgs = uintptr(0)
		}
	}
	return rc
}

func fts5GetRowidLimit(tls *libc.TLS, pVal uintptr, iDefault I64) I64 {
	if pVal != 0 {
		var eType int32 = Xsqlite3_value_numeric_type(tls, pVal)
		if eType == SQLITE_INTEGER {
			return Xsqlite3_value_int64(tls, pVal)
		}
	}
	return iDefault
}

func fts5FilterMethod(tls *libc.TLS, pCursor uintptr, idxNum int32, idxStr uintptr, nVal int32, apVal uintptr) int32 {
	bp := tls.Alloc(16)
	defer tls.Free(16)

	var pTab uintptr
	var pConfig uintptr
	var pCsr uintptr
	var rc int32
	var bDesc int32
	var bOrderByRank int32
	var pRank uintptr
	var pRowidEq uintptr
	var pRowidLe uintptr
	var pRowidGe uintptr
	var iCol int32
	var pzErrmsg uintptr
	var i int32
	var iIdxStr int32

	var pzErr uintptr
	var zText uintptr
	var bGlob int32
	var zText1 uintptr
	pTab = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pConfig = (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	pCsr = pCursor
	rc = SQLITE_OK
	pRank = uintptr(0)
	pRowidEq = uintptr(0)
	pRowidLe = uintptr(0)
	pRowidGe = uintptr(0)
	pzErrmsg = (*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg
	iIdxStr = 0
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)

	if !((*Fts5Config)(unsafe.Pointer(pConfig)).FbLock != 0) {
		goto __1
	}
	(*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls,
		ts+42918, 0)
	return SQLITE_ERROR
__1:
	;
	if !((*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan != 0) {
		goto __2
	}
	fts5FreeCursorComponents(tls, pCsr)
	libc.Xmemset(tls, pCsr+32, 0, uint64(unsafe.Sizeof(Fts5Cursor{}))-uint64((int64(pCsr+32)-int64(pCsr))/1))
__2:
	;
	(*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pTab + 16

	i = 0
__3:
	if !(i < nVal) {
		goto __5
	}
	switch int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(libc.PostIncInt32(&iIdxStr, 1))))) {
	case 'r':
		goto __7
	case 'M':
		goto __8
	case 'L':
		goto __9
	case 'G':
		goto __10
	case '=':
		goto __11
	case '<':
		goto __12
	default:
		goto __13
	}
	goto __6
__7:
	pRank = *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8))
	goto __6
__8:
	zText = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8)))
	if !(zText == uintptr(0)) {
		goto __14
	}
	zText = ts + 1636
__14:
	;
	iCol = 0
__15:
	iCol = iCol*10 + (int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) - '0')
	iIdxStr++
	goto __16
__16:
	if int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) >= '0' && int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) <= '9' {
		goto __15
	}
	goto __17
__17:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(zText))) == '*') {
		goto __18
	}

	rc = fts5SpecialMatch(tls, pTab, pCsr, zText+1)
	goto filter_out
	goto __19
__18:
	pzErr = pTab + 16
	rc = sqlite3Fts5ExprNew(tls, pConfig, 0, iCol, zText, bp+8, pzErr)
	if !(rc == SQLITE_OK) {
		goto __20
	}
	rc = sqlite3Fts5ExprAnd(tls, pCsr+64, *(*uintptr)(unsafe.Pointer(bp + 8)))
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
__20:
	;
	if !(rc != SQLITE_OK) {
		goto __21
	}
	goto filter_out
__21:
	;
__19:
	;
	goto __6

__9:
__10:
	bGlob = libc.Bool32(int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr-1)))) == 'G')
	zText1 = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8)))
	iCol = 0
__22:
	iCol = iCol*10 + (int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) - '0')
	iIdxStr++
	goto __23
__23:
	if int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) >= '0' && int32(*(*uint8)(unsafe.Pointer(idxStr + uintptr(iIdxStr)))) <= '9' {
		goto __22
	}
	goto __24
__24:
	;
	if !(zText1 != 0) {
		goto __25
	}
	rc = sqlite3Fts5ExprPattern(tls, pConfig, bGlob, iCol, zText1, bp+8)
__25:
	;
	if !(rc == SQLITE_OK) {
		goto __26
	}
	rc = sqlite3Fts5ExprAnd(tls, pCsr+64, *(*uintptr)(unsafe.Pointer(bp + 8)))
	*(*uintptr)(unsafe.Pointer(bp + 8)) = uintptr(0)
__26:
	;
	if !(rc != SQLITE_OK) {
		goto __27
	}
	goto filter_out
__27:
	;
	goto __6

__11:
	pRowidEq = *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8))
	goto __6
__12:
	pRowidLe = *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8))
	goto __6
__13:
	;
	pRowidGe = *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8))
	goto __6
__6:
	;
	goto __4
__4:
	i++
	goto __3
	goto __5
__5:
	;
	bOrderByRank = func() int32 {
		if idxNum&FTS5_BI_ORDER_RANK != 0 {
			return 1
		}
		return 0
	}()
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FbDesc = libc.AssignInt32(&bDesc, func() int32 {
		if idxNum&FTS5_BI_ORDER_DESC != 0 {
			return 1
		}
		return 0
	}())

	if !(pRowidEq != 0) {
		goto __28
	}
	pRowidLe = libc.AssignUintptr(&pRowidGe, pRowidEq)
__28:
	;
	if !(bDesc != 0) {
		goto __29
	}
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = fts5GetRowidLimit(tls, pRowidLe, int64(0xffffffff)|int64(0x7fffffff)<<32)
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = fts5GetRowidLimit(tls, pRowidGe, int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32))
	goto __30
__29:
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = fts5GetRowidLimit(tls, pRowidLe, int64(0xffffffff)|int64(0x7fffffff)<<32)
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = fts5GetRowidLimit(tls, pRowidGe, int64(-1)-(int64(0xffffffff)|int64(0x7fffffff)<<32))
__30:
	;
	if !((*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr != 0) {
		goto __31
	}

	if !((*Fts5Cursor)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FbDesc != 0) {
		goto __33
	}
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = (*Fts5Cursor)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiFirstRowid
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = (*Fts5Cursor)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiLastRowid
	goto __34
__33:
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid = (*Fts5Cursor)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiLastRowid
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid = (*Fts5Cursor)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FiFirstRowid
__34:
	;
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan = FTS5_PLAN_SOURCE
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr = (*Fts5Cursor)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).FpSortCsr)).FpExpr
	rc = fts5CursorFirst(tls, pTab, pCsr, bDesc)
	goto __32
__31:
	if !((*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr != 0) {
		goto __35
	}
	rc = fts5CursorParseRank(tls, pConfig, pCsr, pRank)
	if !(rc == SQLITE_OK) {
		goto __37
	}
	if !(bOrderByRank != 0) {
		goto __38
	}
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan = FTS5_PLAN_SORTED_MATCH
	rc = fts5CursorFirstSorted(tls, pTab, pCsr, bDesc)
	goto __39
__38:
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan = FTS5_PLAN_MATCH
	rc = fts5CursorFirst(tls, pTab, pCsr, bDesc)
__39:
	;
__37:
	;
	goto __36
__35:
	if !((*Fts5Config)(unsafe.Pointer(pConfig)).FzContent == uintptr(0)) {
		goto __40
	}
	*(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg)) = Xsqlite3_mprintf(tls,
		ts+43119, libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
	rc = SQLITE_ERROR
	goto __41
__40:
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan = func() int32 {
		if pRowidEq != 0 {
			return FTS5_PLAN_ROWID
		}
		return FTS5_PLAN_SCAN
	}()
	rc = sqlite3Fts5StorageStmt(tls,
		(*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, fts5StmtType(tls, pCsr), pCsr+56, pTab+16)
	if !(rc == SQLITE_OK) {
		goto __42
	}
	if !(pRowidEq != uintptr(0)) {
		goto __43
	}

	Xsqlite3_bind_value(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, 1, pRowidEq)
	goto __44
__43:
	Xsqlite3_bind_int64(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, 1, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FiFirstRowid)
	Xsqlite3_bind_int64(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, 2, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FiLastRowid)
__44:
	;
	rc = fts5NextMethod(tls, pCursor)
__42:
	;
__41:
	;
__36:
	;
__32:
	;
filter_out:
	sqlite3Fts5ExprFree(tls, *(*uintptr)(unsafe.Pointer(bp + 8)))
	(*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pzErrmsg
	return rc
}

func fts5EofMethod(tls *libc.TLS, pCursor uintptr) int32 {
	var pCsr uintptr = pCursor
	return func() int32 {
		if (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&FTS5CSR_EOF != 0 {
			return 1
		}
		return 0
	}()
}

func fts5CursorRowid(tls *libc.TLS, pCsr uintptr) I64 {
	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 {
		return (*Fts5Sorter)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter)).FiRowid
	} else {
		return sqlite3Fts5ExprRowid(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	}
	return I64(0)
}

func fts5RowidMethod(tls *libc.TLS, pCursor uintptr, pRowid uintptr) int32 {
	var pCsr uintptr = pCursor
	var ePlan int32 = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan

	switch ePlan {
	case FTS5_PLAN_SPECIAL:
		*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = int64(0)
		break

	case FTS5_PLAN_SOURCE:
		fallthrough
	case FTS5_PLAN_MATCH:
		fallthrough
	case FTS5_PLAN_SORTED_MATCH:
		*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = fts5CursorRowid(tls, pCsr)
		break

	default:
		*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = Xsqlite3_column_int64(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, 0)
		break
	}

	return SQLITE_OK
}

func fts5SeekCursor(tls *libc.TLS, pCsr uintptr, bErrormsg int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt == uintptr(0) {
		var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
		var eStmt int32 = fts5StmtType(tls, pCsr)
		rc = sqlite3Fts5StorageStmt(tls,
			(*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, eStmt, pCsr+56, func() uintptr {
				if bErrormsg != 0 {
					return pTab + 16
				}
				return uintptr(0)
			}())

	}

	if rc == SQLITE_OK && (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&FTS5CSR_REQUIRE_CONTENT != 0 {
		var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab

		Xsqlite3_reset(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
		Xsqlite3_bind_int64(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, 1, fts5CursorRowid(tls, pCsr))
		(*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer(pTab)).FpConfig)).FbLock++
		rc = Xsqlite3_step(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
		(*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer(pTab)).FpConfig)).FbLock--
		if rc == SQLITE_ROW {
			rc = SQLITE_OK
			*(*int32)(unsafe.Pointer(pCsr + 80)) &= libc.CplInt32(FTS5CSR_REQUIRE_CONTENT)
		} else {
			rc = Xsqlite3_reset(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt)
			if rc == SQLITE_OK {
				rc = SQLITE_CORRUPT | int32(1)<<8
			} else if (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer(pTab)).FpConfig)).FpzErrmsg != 0 {
				*(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer(pTab)).FpConfig)).FpzErrmsg)) = Xsqlite3_mprintf(tls,
					ts+1684, libc.VaList(bp, Xsqlite3_errmsg(tls, (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer(pTab)).FpConfig)).Fdb)))
			}
		}
	}
	return rc
}

func fts5SetVtabError(tls *libc.TLS, p uintptr, zFormat uintptr, va uintptr) {
	var ap Va_list
	_ = ap
	ap = va

	(*Fts5FullTable)(unsafe.Pointer(p)).Fp.Fbase.FzErrMsg = Xsqlite3_vmprintf(tls, zFormat, ap)
	_ = ap
}

func fts5SpecialInsert(tls *libc.TLS, pTab uintptr, zCmd uintptr, pVal uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pConfig uintptr = (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	var rc int32 = SQLITE_OK
	*(*int32)(unsafe.Pointer(bp)) = 0

	if 0 == Xsqlite3_stricmp(tls, ts+43155, zCmd) {
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			fts5SetVtabError(tls, pTab,
				ts+43166, 0)
			rc = SQLITE_ERROR
		} else {
			rc = sqlite3Fts5StorageDeleteAll(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
		}
	} else if 0 == Xsqlite3_stricmp(tls, ts+43246, zCmd) {
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NONE {
			fts5SetVtabError(tls, pTab,
				ts+43254, 0)
			rc = SQLITE_ERROR
		} else {
			rc = sqlite3Fts5StorageRebuild(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
		}
	} else if 0 == Xsqlite3_stricmp(tls, ts+20487, zCmd) {
		rc = sqlite3Fts5StorageOptimize(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
	} else if 0 == Xsqlite3_stricmp(tls, ts+43310, zCmd) {
		var nMerge int32 = Xsqlite3_value_int(tls, pVal)
		rc = sqlite3Fts5StorageMerge(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, nMerge)
	} else if 0 == Xsqlite3_stricmp(tls, ts+43316, zCmd) {
		var iArg int32 = Xsqlite3_value_int(tls, pVal)
		rc = sqlite3Fts5StorageIntegrity(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iArg)
	} else {
		rc = sqlite3Fts5IndexLoadConfig(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex)
		if rc == SQLITE_OK {
			rc = sqlite3Fts5ConfigSetValue(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig, zCmd, pVal, bp)
		}
		if rc == SQLITE_OK {
			if *(*int32)(unsafe.Pointer(bp)) != 0 {
				rc = SQLITE_ERROR
			} else {
				rc = sqlite3Fts5StorageConfigValue(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, zCmd, pVal, 0)
			}
		}
	}
	return rc
}

func fts5SpecialDelete(tls *libc.TLS, pTab uintptr, apVal uintptr) int32 {
	var rc int32 = SQLITE_OK
	var eType1 int32 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
	if eType1 == SQLITE_INTEGER {
		var iDel Sqlite3_int64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
		rc = sqlite3Fts5StorageDelete(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iDel, apVal+2*8)
	}
	return rc
}

func fts5StorageInsert(tls *libc.TLS, pRc uintptr, pTab uintptr, apVal uintptr, piRowid uintptr) {
	var rc int32 = *(*int32)(unsafe.Pointer(pRc))
	if rc == SQLITE_OK {
		rc = sqlite3Fts5StorageContentInsert(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, apVal, piRowid)
	}
	if rc == SQLITE_OK {
		rc = sqlite3Fts5StorageIndexInsert(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, apVal, *(*I64)(unsafe.Pointer(piRowid)))
	}
	*(*int32)(unsafe.Pointer(pRc)) = rc
}

func fts5UpdateMethod(tls *libc.TLS, pVtab uintptr, nArg int32, apVal uintptr, pRowid uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var pTab uintptr = pVtab
	var pConfig uintptr = (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	var eType0 int32
	*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK

	(*Fts5Config)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pTab + 16

	fts5TripCursors(tls, pTab)

	eType0 = Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apVal)))
	if eType0 == SQLITE_NULL &&
		Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(2+(*Fts5Config)(unsafe.Pointer(pConfig)).FnCol)*8))) != SQLITE_NULL {
		var z uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(2+(*Fts5Config)(unsafe.Pointer(pConfig)).FnCol)*8)))
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL &&
			0 == Xsqlite3_stricmp(tls, ts+21032, z) {
			*(*int32)(unsafe.Pointer(bp + 16)) = fts5SpecialDelete(tls, pTab, apVal)
		} else {
			*(*int32)(unsafe.Pointer(bp + 16)) = fts5SpecialInsert(tls, pTab, z, *(*uintptr)(unsafe.Pointer(apVal + uintptr(2+(*Fts5Config)(unsafe.Pointer(pConfig)).FnCol+1)*8)))
		}
	} else {
		var eConflict int32 = SQLITE_ABORT
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			eConflict = Xsqlite3_vtab_on_conflict(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb)
		}

		if eType0 == SQLITE_INTEGER && fts5IsContentless(tls, pTab) != 0 {
			(*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.Fbase.FzErrMsg = Xsqlite3_mprintf(tls,
				ts+43332,
				libc.VaList(bp, func() uintptr {
					if nArg > 1 {
						return ts + 24623
					}
					return ts + 43369
				}(), (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
			*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_ERROR
		} else if nArg == 1 {
			var iDel I64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal)))
			*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5StorageDelete(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iDel, uintptr(0))
		} else {
			var eType1 int32 = Xsqlite3_value_numeric_type(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))

			if eType1 != SQLITE_INTEGER && eType1 != SQLITE_NULL {
				*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_MISMATCH
			} else if eType0 != SQLITE_INTEGER {
				if eConflict == SQLITE_REPLACE && eType1 == SQLITE_INTEGER {
					var iNew I64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
					*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5StorageDelete(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iNew, uintptr(0))
				}
				fts5StorageInsert(tls, bp+16, pTab, apVal, pRowid)
			} else {
				var iOld I64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal)))
				var iNew I64 = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
				if eType1 == SQLITE_INTEGER && iOld != iNew {
					if eConflict == SQLITE_REPLACE {
						*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5StorageDelete(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iOld, uintptr(0))
						if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
							*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5StorageDelete(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iNew, uintptr(0))
						}
						fts5StorageInsert(tls, bp+16, pTab, apVal, pRowid)
					} else {
						*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5StorageContentInsert(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, apVal, pRowid)
						if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
							*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5StorageDelete(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iOld, uintptr(0))
						}
						if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
							*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5StorageIndexInsert(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, apVal, *(*Sqlite_int64)(unsafe.Pointer(pRowid)))
						}
					}
				} else {
					*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5StorageDelete(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iOld, uintptr(0))
					fts5StorageInsert(tls, bp+16, pTab, apVal, pRowid)
				}
			}
		}
	}

	(*Fts5Config)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
	return *(*int32)(unsafe.Pointer(bp + 16))
}

func fts5SyncMethod(tls *libc.TLS, pVtab uintptr) int32 {
	var rc int32
	var pTab uintptr = pVtab

	(*Fts5Config)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pTab + 16
	fts5TripCursors(tls, pTab)
	rc = sqlite3Fts5StorageSync(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
	(*Fts5Config)(unsafe.Pointer((*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
	return rc
}

func fts5BeginMethod(tls *libc.TLS, pVtab uintptr) int32 {
	fts5NewTransaction(tls, pVtab)
	return SQLITE_OK
}

func fts5CommitMethod(tls *libc.TLS, pVtab uintptr) int32 {
	_ = pVtab

	return SQLITE_OK
}

func fts5RollbackMethod(tls *libc.TLS, pVtab uintptr) int32 {
	var rc int32
	var pTab uintptr = pVtab

	rc = sqlite3Fts5StorageRollback(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
	return rc
}

func fts5ApiUserData(tls *libc.TLS, pCtx uintptr) uintptr {
	var pCsr uintptr = pCtx
	return (*Fts5Auxiliary)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAux)).FpUserData
}

func fts5ApiColumnCount(tls *libc.TLS, pCtx uintptr) int32 {
	var pCsr uintptr = pCtx
	return (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig)).FnCol
}

func fts5ApiColumnTotalSize(tls *libc.TLS, pCtx uintptr, iCol int32, pnToken uintptr) int32 {
	var pCsr uintptr = pCtx
	var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	return sqlite3Fts5StorageSize(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iCol, pnToken)
}

func fts5ApiRowCount(tls *libc.TLS, pCtx uintptr, pnRow uintptr) int32 {
	var pCsr uintptr = pCtx
	var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	return sqlite3Fts5StorageRowCount(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, pnRow)
}

func fts5ApiTokenize(tls *libc.TLS, pCtx uintptr, pText uintptr, nText int32, pUserData uintptr, xToken uintptr) int32 {
	var pCsr uintptr = pCtx
	var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	return sqlite3Fts5Tokenize(tls,
		(*Fts5Table)(unsafe.Pointer(pTab)).FpConfig, FTS5_TOKENIZE_AUX, pText, nText, pUserData, xToken)
}

func fts5ApiPhraseCount(tls *libc.TLS, pCtx uintptr) int32 {
	var pCsr uintptr = pCtx
	return sqlite3Fts5ExprPhraseCount(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
}

func fts5ApiPhraseSize(tls *libc.TLS, pCtx uintptr, iPhrase int32) int32 {
	var pCsr uintptr = pCtx
	return sqlite3Fts5ExprPhraseSize(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase)
}

func fts5ApiColumnText(tls *libc.TLS, pCtx uintptr, iCol int32, pz uintptr, pn uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pCsr uintptr = pCtx
	if fts5IsContentless(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab) != 0 ||
		(*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan == 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, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, iCol+1)
			*(*int32)(unsafe.Pointer(pn)) = Xsqlite3_column_bytes(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, iCol+1)
		}
	}
	return rc
}

func fts5CsrPoslist(tls *libc.TLS, pCsr uintptr, iPhrase int32, pa uintptr, pn uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var pConfig uintptr = (*Fts5Table)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig
	var rc int32 = SQLITE_OK
	var bLive int32 = libc.Bool32((*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter == uintptr(0))

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&FTS5CSR_REQUIRE_POSLIST != 0 {
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail != FTS5_DETAIL_FULL {
			var aPopulator uintptr
			var i int32
			aPopulator = sqlite3Fts5ExprClearPoslists(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, bLive)
			if aPopulator == uintptr(0) {
				rc = SQLITE_NOMEM
			}
			for i = 0; i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol && rc == SQLITE_OK; i++ {
				rc = fts5ApiColumnText(tls, pCsr, i, bp, bp+8)
				if rc == SQLITE_OK {
					rc = sqlite3Fts5ExprPopulatePoslists(tls,
						pConfig, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, aPopulator, i, *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)))
				}
			}
			Xsqlite3_free(tls, aPopulator)

			if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 {
				sqlite3Fts5ExprCheckPoslists(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, (*Fts5Sorter)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter)).FiRowid)
			}
		}
		*(*int32)(unsafe.Pointer(pCsr + 80)) &= libc.CplInt32(FTS5CSR_REQUIRE_POSLIST)
	}

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter != 0 && (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_FULL {
		var pSorter uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter
		var i1 int32 = func() int32 {
			if iPhrase == 0 {
				return 0
			}
			return *(*int32)(unsafe.Pointer(pSorter + 28 + uintptr(iPhrase-1)*4))
		}()
		*(*int32)(unsafe.Pointer(pn)) = *(*int32)(unsafe.Pointer(pSorter + 28 + uintptr(iPhrase)*4)) - i1
		*(*uintptr)(unsafe.Pointer(pa)) = (*Fts5Sorter)(unsafe.Pointer(pSorter)).FaPoslist + uintptr(i1)
	} else {
		*(*int32)(unsafe.Pointer(pn)) = sqlite3Fts5ExprPoslist(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase, pa)
	}

	return rc
}

func fts5CacheInstArray(tls *libc.TLS, pCsr uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
	var aIter uintptr
	var nIter int32
	var nCol int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig)).FnCol

	nIter = sqlite3Fts5ExprPhraseCount(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)
	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter == uintptr(0) {
		var nByte Sqlite3_int64 = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5PoslistReader{})) * uint64(nIter))
		(*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter = sqlite3Fts5MallocZero(tls, bp, nByte)
	}
	aIter = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInstIter

	if aIter != 0 {
		var nInst int32 = 0
		var i int32

		for i = 0; i < nIter && *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK; i++ {
			*(*int32)(unsafe.Pointer(bp)) = fts5CsrPoslist(tls, pCsr, i, bp+8, bp+16)
			if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
				sqlite3Fts5PoslistReaderInit(tls, *(*uintptr)(unsafe.Pointer(bp + 8)), *(*int32)(unsafe.Pointer(bp + 16)), aIter+uintptr(i)*32)
			}
		}

		if *(*int32)(unsafe.Pointer(bp)) == SQLITE_OK {
			for 1 != 0 {
				var aInst uintptr
				var iBest int32 = -1
				for i = 0; i < nIter; i++ {
					if int32((*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(i)*32)).FbEof) == 0 &&
						(iBest < 0 || (*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(i)*32)).FiPos < (*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(iBest)*32)).FiPos) {
						iBest = i
					}
				}
				if iBest < 0 {
					break
				}

				nInst++
				if nInst >= (*Fts5Cursor)(unsafe.Pointer(pCsr)).FnInstAlloc {
					var nNewSize int32
					if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FnInstAlloc != 0 {
						nNewSize = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FnInstAlloc * 2
					} else {
						nNewSize = 32
					}
					aInst = Xsqlite3_realloc64(tls,
						(*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInst, uint64(nNewSize)*uint64(unsafe.Sizeof(int32(0)))*uint64(3))
					if aInst != 0 {
						(*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInst = aInst
						(*Fts5Cursor)(unsafe.Pointer(pCsr)).FnInstAlloc = nNewSize
					} else {
						nInst--
						*(*int32)(unsafe.Pointer(bp)) = SQLITE_NOMEM
						break
					}
				}

				aInst = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(3*(nInst-1))*4
				*(*int32)(unsafe.Pointer(aInst)) = iBest
				*(*int32)(unsafe.Pointer(aInst + 1*4)) = int32((*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(iBest)*32)).FiPos >> 32)
				*(*int32)(unsafe.Pointer(aInst + 2*4)) = int32((*Fts5PoslistReader)(unsafe.Pointer(aIter+uintptr(iBest)*32)).FiPos & int64(0x7FFFFFFF))
				if *(*int32)(unsafe.Pointer(aInst + 1*4)) < 0 || *(*int32)(unsafe.Pointer(aInst + 1*4)) >= nCol {
					*(*int32)(unsafe.Pointer(bp)) = SQLITE_CORRUPT | int32(1)<<8
					break
				}
				sqlite3Fts5PoslistReaderNext(tls, aIter+uintptr(iBest)*32)
			}
		}

		(*Fts5Cursor)(unsafe.Pointer(pCsr)).FnInstCount = nInst
		*(*int32)(unsafe.Pointer(pCsr + 80)) &= libc.CplInt32(FTS5CSR_REQUIRE_INST)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func fts5ApiInstCount(tls *libc.TLS, pCtx uintptr, pnInst uintptr) int32 {
	var pCsr uintptr = pCtx
	var rc int32 = SQLITE_OK
	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&FTS5CSR_REQUIRE_INST == 0 ||
		SQLITE_OK == libc.AssignInt32(&rc, fts5CacheInstArray(tls, pCsr)) {
		*(*int32)(unsafe.Pointer(pnInst)) = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FnInstCount
	}
	return rc
}

func fts5ApiInst(tls *libc.TLS, pCtx uintptr, iIdx int32, piPhrase uintptr, piCol uintptr, piOff uintptr) int32 {
	var pCsr uintptr = pCtx
	var rc int32 = SQLITE_OK
	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&FTS5CSR_REQUIRE_INST == 0 ||
		SQLITE_OK == libc.AssignInt32(&rc, fts5CacheInstArray(tls, pCsr)) {
		if iIdx < 0 || iIdx >= (*Fts5Cursor)(unsafe.Pointer(pCsr)).FnInstCount {
			rc = SQLITE_RANGE
		} else {
			*(*int32)(unsafe.Pointer(piPhrase)) = *(*int32)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*3)*4))
			*(*int32)(unsafe.Pointer(piCol)) = *(*int32)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*3+1)*4))
			*(*int32)(unsafe.Pointer(piOff)) = *(*int32)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FaInst + uintptr(iIdx*3+2)*4))
		}
	}
	return rc
}

func fts5ApiRowid(tls *libc.TLS, pCtx uintptr) Sqlite3_int64 {
	return fts5CursorRowid(tls, pCtx)
}

func fts5ColumnSizeCb(tls *libc.TLS, pContext uintptr, tflags int32, pUnused uintptr, nUnused int32, iUnused1 int32, iUnused2 int32) int32 {
	var pCnt uintptr = pContext
	_ = pUnused
	_ = nUnused
	_ = iUnused1
	_ = iUnused2
	if tflags&FTS5_TOKEN_COLOCATED == 0 {
		*(*int32)(unsafe.Pointer(pCnt))++
	}
	return SQLITE_OK
}

func fts5ApiColumnSize(tls *libc.TLS, pCtx uintptr, iCol int32, pnToken uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	var pCsr uintptr = pCtx
	var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	var pConfig uintptr = (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	var rc int32 = SQLITE_OK

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fcsrflags&FTS5CSR_REQUIRE_DOCSIZE != 0 {
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
			var iRowid I64 = fts5CursorRowid(tls, pCsr)
			rc = sqlite3Fts5StorageDocsize(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iRowid, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize)
		} else if (*Fts5Config)(unsafe.Pointer(pConfig)).FzContent == uintptr(0) {
			var i int32
			for i = 0; i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; i++ {
				if int32(*(*U8)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i)))) == 0 {
					*(*int32)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(i)*4)) = -1
				}
			}
		} else {
			var i int32
			for i = 0; rc == SQLITE_OK && i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; i++ {
				if int32(*(*U8)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i)))) == 0 {
					var p uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(i)*4
					*(*int32)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(i)*4)) = 0
					rc = fts5ApiColumnText(tls, pCtx, i, bp, bp+8)
					if rc == SQLITE_OK {
						rc = sqlite3Fts5Tokenize(tls,
							pConfig, FTS5_TOKENIZE_AUX, *(*uintptr)(unsafe.Pointer(bp)), *(*int32)(unsafe.Pointer(bp + 8)), p, *(*uintptr)(unsafe.Pointer(&struct {
								f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
							}{fts5ColumnSizeCb})))
					}
				}
			}
		}
		*(*int32)(unsafe.Pointer(pCsr + 80)) &= libc.CplInt32(FTS5CSR_REQUIRE_DOCSIZE)
	}
	if iCol < 0 {
		var i int32
		*(*int32)(unsafe.Pointer(pnToken)) = 0
		for i = 0; i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; i++ {
			*(*int32)(unsafe.Pointer(pnToken)) += *(*int32)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(i)*4))
		}
	} else if iCol < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol {
		*(*int32)(unsafe.Pointer(pnToken)) = *(*int32)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).FaColumnSize + uintptr(iCol)*4))
	} else {
		*(*int32)(unsafe.Pointer(pnToken)) = 0
		rc = SQLITE_RANGE
	}
	return rc
}

func fts5ApiSetAuxdata(tls *libc.TLS, pCtx uintptr, pPtr uintptr, xDelete uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pCsr uintptr = pCtx
	var pData uintptr

	for pData = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata; pData != 0; pData = (*Fts5Auxdata)(unsafe.Pointer(pData)).FpNext {
		if (*Fts5Auxdata)(unsafe.Pointer(pData)).FpAux == (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAux {
			break
		}
	}

	if pData != 0 {
		if (*Fts5Auxdata)(unsafe.Pointer(pData)).FxDelete != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Fts5Auxdata)(unsafe.Pointer(pData)).FxDelete})).f(tls, (*Fts5Auxdata)(unsafe.Pointer(pData)).FpPtr)
		}
	} else {
		*(*int32)(unsafe.Pointer(bp)) = SQLITE_OK
		pData = sqlite3Fts5MallocZero(tls, bp, int64(unsafe.Sizeof(Fts5Auxdata{})))
		if pData == uintptr(0) {
			if xDelete != 0 {
				(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{xDelete})).f(tls, pPtr)
			}
			return *(*int32)(unsafe.Pointer(bp))
		}
		(*Fts5Auxdata)(unsafe.Pointer(pData)).FpAux = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAux
		(*Fts5Auxdata)(unsafe.Pointer(pData)).FpNext = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata
		(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata = pData
	}

	(*Fts5Auxdata)(unsafe.Pointer(pData)).FxDelete = xDelete
	(*Fts5Auxdata)(unsafe.Pointer(pData)).FpPtr = pPtr
	return SQLITE_OK
}

func fts5ApiGetAuxdata(tls *libc.TLS, pCtx uintptr, bClear int32) uintptr {
	var pCsr uintptr = pCtx
	var pData uintptr
	var pRet uintptr = uintptr(0)

	for pData = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata; pData != 0; pData = (*Fts5Auxdata)(unsafe.Pointer(pData)).FpNext {
		if (*Fts5Auxdata)(unsafe.Pointer(pData)).FpAux == (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAux {
			break
		}
	}

	if pData != 0 {
		pRet = (*Fts5Auxdata)(unsafe.Pointer(pData)).FpPtr
		if bClear != 0 {
			(*Fts5Auxdata)(unsafe.Pointer(pData)).FpPtr = uintptr(0)
			(*Fts5Auxdata)(unsafe.Pointer(pData)).FxDelete = uintptr(0)
		}
	}

	return pRet
}

func fts5ApiPhraseNext(tls *libc.TLS, pUnused uintptr, pIter uintptr, piCol uintptr, piOff uintptr) {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	_ = pUnused
	if (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa >= (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fb {
		*(*int32)(unsafe.Pointer(piCol)) = -1
		*(*int32)(unsafe.Pointer(piOff)) = -1
	} else {
		*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(sqlite3Fts5GetVarint32(tls, (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp))
		if *(*int32)(unsafe.Pointer(bp)) == 1 {
			*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(sqlite3Fts5GetVarint32(tls, (*Fts5PhraseIter)(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, (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp))
		}
		*(*int32)(unsafe.Pointer(piOff)) += *(*int32)(unsafe.Pointer(bp)) - 2
	}
}

func fts5ApiPhraseFirst(tls *libc.TLS, pCtx uintptr, iPhrase int32, pIter uintptr, piCol uintptr, piOff uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pCsr uintptr = pCtx

	var rc int32 = fts5CsrPoslist(tls, pCsr, iPhrase, pIter, bp)
	if rc == SQLITE_OK {
		(*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fb = func() uintptr {
			if (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa != 0 {
				return (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa + uintptr(*(*int32)(unsafe.Pointer(bp)))
			}
			return uintptr(0)
		}()
		*(*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(8)
	defer tls.Free(8)

	var pCsr uintptr = pCtx
	var pConfig uintptr = (*Fts5Table)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig

	if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_COLUMNS {
		if (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa >= (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fb {
			*(*int32)(unsafe.Pointer(piCol)) = -1
		} else {
			*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(sqlite3Fts5GetVarint32(tls, (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp))
			*(*int32)(unsafe.Pointer(piCol)) += *(*int32)(unsafe.Pointer(bp)) - 2
		}
	} else {
		for 1 != 0 {
			if (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa >= (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fb {
				*(*int32)(unsafe.Pointer(piCol)) = -1
				return
			}
			if int32(*(*uint8)(unsafe.Pointer((*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa))) == 0x01 {
				break
			}
			*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(sqlite3Fts5GetVarint32(tls, (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa, bp+4))
		}
		*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(1 + sqlite3Fts5GetVarint32(tls, (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa+1, piCol))
	}
}

func fts5ApiPhraseFirstColumn(tls *libc.TLS, pCtx uintptr, iPhrase int32, pIter uintptr, piCol uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var pCsr uintptr = pCtx
	var pConfig uintptr = (*Fts5Table)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig

	if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_COLUMNS {
		var pSorter uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpSorter

		if pSorter != 0 {
			var i1 int32 = func() int32 {
				if iPhrase == 0 {
					return 0
				}
				return *(*int32)(unsafe.Pointer(pSorter + 28 + uintptr(iPhrase-1)*4))
			}()
			*(*int32)(unsafe.Pointer(bp)) = *(*int32)(unsafe.Pointer(pSorter + 28 + uintptr(iPhrase)*4)) - i1
			(*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa = (*Fts5Sorter)(unsafe.Pointer(pSorter)).FaPoslist + uintptr(i1)
		} else {
			rc = sqlite3Fts5ExprPhraseCollist(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase, pIter, bp)
		}
		if rc == SQLITE_OK {
			(*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fb = func() uintptr {
				if (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa != 0 {
					return (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa + uintptr(*(*int32)(unsafe.Pointer(bp)))
				}
				return uintptr(0)
			}()
			*(*int32)(unsafe.Pointer(piCol)) = 0
			fts5ApiPhraseNextColumn(tls, pCtx, pIter, piCol)
		}
	} else {
		rc = fts5CsrPoslist(tls, pCsr, iPhrase, pIter, bp+4)
		if rc == SQLITE_OK {
			(*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fb = func() uintptr {
				if (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa != 0 {
					return (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa + uintptr(*(*int32)(unsafe.Pointer(bp + 4)))
				}
				return uintptr(0)
			}()
			if *(*int32)(unsafe.Pointer(bp + 4)) <= 0 {
				*(*int32)(unsafe.Pointer(piCol)) = -1
			} else if int32(*(*uint8)(unsafe.Pointer((*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa))) == 0x01 {
				*(*uintptr)(unsafe.Pointer(pIter)) += uintptr(1 + sqlite3Fts5GetVarint32(tls, (*Fts5PhraseIter)(unsafe.Pointer(pIter)).Fa+1, piCol))
			} else {
				*(*int32)(unsafe.Pointer(piCol)) = 0
			}
		}
	}

	return rc
}

var sFts5Api = Fts5ExtensionApi{
	FiVersion:           2,
	FxUserData:          0,
	FxColumnCount:       0,
	FxRowCount:          0,
	FxColumnTotalSize:   0,
	FxTokenize:          0,
	FxPhraseCount:       0,
	FxPhraseSize:        0,
	FxInstCount:         0,
	FxInst:              0,
	FxRowid:             0,
	FxColumnText:        0,
	FxColumnSize:        0,
	FxQueryPhrase:       0,
	FxSetAuxdata:        0,
	FxGetAuxdata:        0,
	FxPhraseFirst:       0,
	FxPhraseNext:        0,
	FxPhraseFirstColumn: 0,
	FxPhraseNextColumn:  0,
}

func fts5ApiQueryPhrase(tls *libc.TLS, pCtx uintptr, iPhrase int32, pUserData uintptr, xCallback uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pCsr uintptr = pCtx
	var pTab uintptr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	var rc int32
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)

	rc = fts5OpenMethod(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab, bp)
	if rc == SQLITE_OK {
		(*Fts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FePlan = FTS5_PLAN_MATCH
		(*Fts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FiFirstRowid = int64(-1) - (int64(0xffffffff) | int64(0x7fffffff)<<32)
		(*Fts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).FiLastRowid = int64(0xffffffff) | int64(0x7fffffff)<<32
		(*Fts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fbase.FpVtab = pTab
		rc = sqlite3Fts5ExprClonePhrase(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, iPhrase, *(*uintptr)(unsafe.Pointer(bp))+64)
	}

	if rc == SQLITE_OK {
		for rc = fts5CursorFirst(tls, pTab, *(*uintptr)(unsafe.Pointer(bp)), 0); rc == SQLITE_OK && (*Fts5Cursor)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp)))).Fcsrflags&FTS5CSR_EOF == 0; rc = fts5NextMethod(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			rc = (*struct {
				f func(*libc.TLS, uintptr, uintptr, uintptr) int32
			})(unsafe.Pointer(&struct{ uintptr }{xCallback})).f(tls, uintptr(unsafe.Pointer(&sFts5Api)), *(*uintptr)(unsafe.Pointer(bp)), pUserData)
			if rc != SQLITE_OK {
				if rc == SQLITE_DONE {
					rc = SQLITE_OK
				}
				break
			}
		}
	}

	fts5CloseMethod(tls, *(*uintptr)(unsafe.Pointer(bp)))
	return rc
}

func fts5ApiInvoke(tls *libc.TLS, pAux uintptr, pCsr uintptr, context uintptr, argc int32, argv uintptr) {
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAux = pAux
	(*struct {
		f func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr)
	})(unsafe.Pointer(&struct{ uintptr }{(*Fts5Auxiliary)(unsafe.Pointer(pAux)).FxFunc})).f(tls, uintptr(unsafe.Pointer(&sFts5Api)), pCsr, context, argc, argv)
	(*Fts5Cursor)(unsafe.Pointer(pCsr)).FpAux = uintptr(0)
}

func fts5CursorFromCsrid(tls *libc.TLS, pGlobal uintptr, iCsrId I64) uintptr {
	var pCsr uintptr
	for pCsr = (*Fts5Global)(unsafe.Pointer(pGlobal)).FpCsr; pCsr != 0; pCsr = (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpNext {
		if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId == iCsrId {
			break
		}
	}
	return pCsr
}

func fts5ApiCallback(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pAux uintptr
	var pCsr uintptr
	var iCsrId I64

	pAux = Xsqlite3_user_data(tls, context)
	iCsrId = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(argv)))

	pCsr = fts5CursorFromCsrid(tls, (*Fts5Auxiliary)(unsafe.Pointer(pAux)).FpGlobal, iCsrId)
	if pCsr == uintptr(0) || (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan == 0 {
		var zErr uintptr = Xsqlite3_mprintf(tls, ts+43381, libc.VaList(bp, iCsrId))
		Xsqlite3_result_error(tls, context, zErr, -1)
		Xsqlite3_free(tls, zErr)
	} else {
		fts5ApiInvoke(tls, pAux, pCsr, context, argc-1, argv+1*8)
	}
}

func sqlite3Fts5TableFromCsrid(tls *libc.TLS, pGlobal uintptr, iCsrId I64) uintptr {
	var pCsr uintptr
	pCsr = fts5CursorFromCsrid(tls, pGlobal, iCsrId)
	if pCsr != 0 {
		return (*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab
	}
	return uintptr(0)
}

func fts5PoslistBlob(tls *libc.TLS, pCtx uintptr, pCsr uintptr) int32 {
	bp := tls.Alloc(68)
	defer tls.Free(68)

	var i int32
	*(*int32)(unsafe.Pointer(bp + 24)) = SQLITE_OK
	var nPhrase int32 = sqlite3Fts5ExprPhraseCount(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr)

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))
	switch (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5Cursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab)).FpConfig)).FeDetail {
	case FTS5_DETAIL_FULL:
		for i = 0; i < nPhrase-1; i++ {
			var nByte int32 = sqlite3Fts5ExprPoslist(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+16)
			sqlite3Fts5BufferAppendVarint(tls, bp+24, bp, int64(nByte))
		}

		for i = 0; i < nPhrase; i++ {
			var nPoslist int32
			nPoslist = sqlite3Fts5ExprPoslist(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+32)
			sqlite3Fts5BufferAppendBlob(tls, bp+24, bp, uint32(nPoslist), *(*uintptr)(unsafe.Pointer(bp + 32)))
		}
		break

	case FTS5_DETAIL_COLUMNS:
		for i = 0; *(*int32)(unsafe.Pointer(bp + 24)) == SQLITE_OK && i < nPhrase-1; i++ {
			*(*int32)(unsafe.Pointer(bp + 24)) = sqlite3Fts5ExprPhraseCollist(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+40, bp+48)
			sqlite3Fts5BufferAppendVarint(tls, bp+24, bp, int64(*(*int32)(unsafe.Pointer(bp + 48))))
		}

		for i = 0; *(*int32)(unsafe.Pointer(bp + 24)) == SQLITE_OK && i < nPhrase; i++ {
			*(*int32)(unsafe.Pointer(bp + 24)) = sqlite3Fts5ExprPhraseCollist(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpExpr, i, bp+56, bp+64)
			sqlite3Fts5BufferAppendBlob(tls, bp+24, bp, uint32(*(*int32)(unsafe.Pointer(bp + 64))), *(*uintptr)(unsafe.Pointer(bp + 56)))
		}
		break

	default:
		break
	}

	Xsqlite3_result_blob(tls, pCtx, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp, (*Fts5Buffer)(unsafe.Pointer(bp)).Fn, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{Xsqlite3_free})))
	return *(*int32)(unsafe.Pointer(bp + 24))
}

func fts5ColumnMethod(tls *libc.TLS, pCursor uintptr, pCtx uintptr, iCol int32) int32 {
	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	var pConfig uintptr = (*Fts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	var pCsr uintptr = pCursor
	var rc int32 = SQLITE_OK

	if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan == FTS5_PLAN_SPECIAL {
		if iCol == (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol {
			Xsqlite3_result_int64(tls, pCtx, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial)
		}
	} else if iCol == (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol {
		Xsqlite3_result_int64(tls, pCtx, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId)
	} else if iCol == (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol+1 {
		if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan == FTS5_PLAN_SOURCE {
			fts5PoslistBlob(tls, pCtx, pCsr)
		} else if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan == FTS5_PLAN_MATCH ||
			(*Fts5Cursor)(unsafe.Pointer(pCsr)).FePlan == FTS5_PLAN_SORTED_MATCH {
			if (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpRank != 0 || SQLITE_OK == libc.AssignInt32(&rc, fts5FindRankFunction(tls, pCsr)) {
				fts5ApiInvoke(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpRank, pCsr, pCtx, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg)
			}
		}
	} else if !(fts5IsContentless(tls, pTab) != 0) {
		(*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pTab + 16
		rc = fts5SeekCursor(tls, pCsr, 1)
		if rc == SQLITE_OK {
			Xsqlite3_result_value(tls, pCtx, Xsqlite3_column_value(tls, (*Fts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, iCol+1))
		}
		(*Fts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = uintptr(0)
	}
	return rc
}

func fts5FindFunctionMethod(tls *libc.TLS, pVtab uintptr, nUnused int32, zName uintptr, pxFunc uintptr, ppArg uintptr) int32 {
	var pTab uintptr = pVtab
	var pAux uintptr

	_ = nUnused
	pAux = fts5FindAuxiliary(tls, pTab, zName)
	if pAux != 0 {
		*(*uintptr)(unsafe.Pointer(pxFunc)) = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr)
		}{fts5ApiCallback}))
		*(*uintptr)(unsafe.Pointer(ppArg)) = pAux
		return 1
	}

	return 0
}

func fts5RenameMethod(tls *libc.TLS, pVtab uintptr, zName uintptr) int32 {
	var pTab uintptr = pVtab
	return sqlite3Fts5StorageRename(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage, zName)
}

func sqlite3Fts5FlushToDisk(tls *libc.TLS, pTab uintptr) int32 {
	fts5TripCursors(tls, pTab)
	return sqlite3Fts5StorageSync(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
}

func fts5SavepointMethod(tls *libc.TLS, pVtab uintptr, iSavepoint int32) int32 {
	_ = iSavepoint

	return sqlite3Fts5FlushToDisk(tls, pVtab)
}

func fts5ReleaseMethod(tls *libc.TLS, pVtab uintptr, iSavepoint int32) int32 {
	_ = iSavepoint

	return sqlite3Fts5FlushToDisk(tls, pVtab)
}

func fts5RollbackToMethod(tls *libc.TLS, pVtab uintptr, iSavepoint int32) int32 {
	var pTab uintptr = pVtab
	_ = iSavepoint

	fts5TripCursors(tls, pTab)
	return sqlite3Fts5StorageRollback(tls, (*Fts5FullTable)(unsafe.Pointer(pTab)).FpStorage)
}

func fts5CreateAux(tls *libc.TLS, pApi uintptr, zName uintptr, pUserData uintptr, xFunc Fts5_extension_function, xDestroy uintptr) int32 {
	var pGlobal uintptr = pApi
	var rc int32 = Xsqlite3_overload_function(tls, (*Fts5Global)(unsafe.Pointer(pGlobal)).Fdb, zName, -1)
	if rc == SQLITE_OK {
		var pAux uintptr
		var nName Sqlite3_int64
		var nByte Sqlite3_int64

		nName = Sqlite3_int64(libc.Xstrlen(tls, zName) + uint64(1))
		nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Auxiliary{})) + uint64(nName))
		pAux = Xsqlite3_malloc64(tls, uint64(nByte))
		if pAux != 0 {
			libc.Xmemset(tls, pAux, 0, Size_t(nByte))
			(*Fts5Auxiliary)(unsafe.Pointer(pAux)).FzFunc = pAux + 1*48
			libc.Xmemcpy(tls, (*Fts5Auxiliary)(unsafe.Pointer(pAux)).FzFunc, zName, uint64(nName))
			(*Fts5Auxiliary)(unsafe.Pointer(pAux)).FpGlobal = pGlobal
			(*Fts5Auxiliary)(unsafe.Pointer(pAux)).FpUserData = pUserData
			(*Fts5Auxiliary)(unsafe.Pointer(pAux)).FxFunc = xFunc
			(*Fts5Auxiliary)(unsafe.Pointer(pAux)).FxDestroy = xDestroy
			(*Fts5Auxiliary)(unsafe.Pointer(pAux)).FpNext = (*Fts5Global)(unsafe.Pointer(pGlobal)).FpAux
			(*Fts5Global)(unsafe.Pointer(pGlobal)).FpAux = pAux
		} else {
			rc = SQLITE_NOMEM
		}
	}

	return rc
}

func fts5CreateTokenizer(tls *libc.TLS, pApi uintptr, zName uintptr, pUserData uintptr, pTokenizer uintptr, xDestroy uintptr) int32 {
	var pGlobal uintptr = pApi
	var pNew uintptr
	var nName Sqlite3_int64
	var nByte Sqlite3_int64
	var rc int32 = SQLITE_OK

	nName = Sqlite3_int64(libc.Xstrlen(tls, zName) + uint64(1))
	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5TokenizerModule{})) + uint64(nName))
	pNew = Xsqlite3_malloc64(tls, uint64(nByte))
	if pNew != 0 {
		libc.Xmemset(tls, pNew, 0, Size_t(nByte))
		(*Fts5TokenizerModule)(unsafe.Pointer(pNew)).FzName = pNew + 1*56
		libc.Xmemcpy(tls, (*Fts5TokenizerModule)(unsafe.Pointer(pNew)).FzName, zName, uint64(nName))
		(*Fts5TokenizerModule)(unsafe.Pointer(pNew)).FpUserData = pUserData
		(*Fts5TokenizerModule)(unsafe.Pointer(pNew)).Fx = *(*Fts5_tokenizer)(unsafe.Pointer(pTokenizer))
		(*Fts5TokenizerModule)(unsafe.Pointer(pNew)).FxDestroy = xDestroy
		(*Fts5TokenizerModule)(unsafe.Pointer(pNew)).FpNext = (*Fts5Global)(unsafe.Pointer(pGlobal)).FpTok
		(*Fts5Global)(unsafe.Pointer(pGlobal)).FpTok = pNew
		if (*Fts5TokenizerModule)(unsafe.Pointer(pNew)).FpNext == uintptr(0) {
			(*Fts5Global)(unsafe.Pointer(pGlobal)).FpDfltTok = pNew
		}
	} else {
		rc = SQLITE_NOMEM
	}

	return rc
}

func fts5LocateTokenizer(tls *libc.TLS, pGlobal uintptr, zName uintptr) uintptr {
	var pMod uintptr = uintptr(0)

	if zName == uintptr(0) {
		pMod = (*Fts5Global)(unsafe.Pointer(pGlobal)).FpDfltTok
	} else {
		for pMod = (*Fts5Global)(unsafe.Pointer(pGlobal)).FpTok; pMod != 0; pMod = (*Fts5TokenizerModule)(unsafe.Pointer(pMod)).FpNext {
			if Xsqlite3_stricmp(tls, zName, (*Fts5TokenizerModule)(unsafe.Pointer(pMod)).FzName) == 0 {
				break
			}
		}
	}

	return pMod
}

func fts5FindTokenizer(tls *libc.TLS, pApi uintptr, zName uintptr, ppUserData uintptr, pTokenizer uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pMod uintptr

	pMod = fts5LocateTokenizer(tls, pApi, zName)
	if pMod != 0 {
		*(*Fts5_tokenizer)(unsafe.Pointer(pTokenizer)) = (*Fts5TokenizerModule)(unsafe.Pointer(pMod)).Fx
		*(*uintptr)(unsafe.Pointer(ppUserData)) = (*Fts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData
	} else {
		libc.Xmemset(tls, pTokenizer, 0, uint64(unsafe.Sizeof(Fts5_tokenizer{})))
		rc = SQLITE_ERROR
	}

	return rc
}

func sqlite3Fts5GetTokenizer(tls *libc.TLS, pGlobal uintptr, azArg uintptr, nArg int32, pConfig uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pMod uintptr
	var rc int32 = SQLITE_OK

	pMod = fts5LocateTokenizer(tls, pGlobal, func() uintptr {
		if nArg == 0 {
			return uintptr(0)
		}
		return *(*uintptr)(unsafe.Pointer(azArg))
	}())
	if pMod == uintptr(0) {
		rc = SQLITE_ERROR
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+43402, libc.VaList(bp, *(*uintptr)(unsafe.Pointer(azArg))))
	} else {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5TokenizerModule)(unsafe.Pointer(pMod)).Fx.FxCreate})).f(tls,
			(*Fts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData, func() uintptr {
				if azArg != 0 {
					return azArg + 1*8
				}
				return uintptr(0)
			}(), func() int32 {
				if nArg != 0 {
					return nArg - 1
				}
				return 0
			}(), pConfig+104)
		(*Fts5Config)(unsafe.Pointer(pConfig)).FpTokApi = pMod + 16
		if rc != SQLITE_OK {
			if pzErr != 0 {
				*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+43424, 0)
			}
		} else {
			(*Fts5Config)(unsafe.Pointer(pConfig)).FePattern = sqlite3Fts5TokenizerPattern(tls,
				(*Fts5TokenizerModule)(unsafe.Pointer(pMod)).Fx.FxCreate, (*Fts5Config)(unsafe.Pointer(pConfig)).FpTok)
		}
	}

	if rc != SQLITE_OK {
		(*Fts5Config)(unsafe.Pointer(pConfig)).FpTokApi = uintptr(0)
		(*Fts5Config)(unsafe.Pointer(pConfig)).FpTok = uintptr(0)
	}

	return rc
}

func fts5ModuleDestroy(tls *libc.TLS, pCtx uintptr) {
	var pTok uintptr
	var pNextTok uintptr
	var pAux uintptr
	var pNextAux uintptr
	var pGlobal uintptr = pCtx

	for pAux = (*Fts5Global)(unsafe.Pointer(pGlobal)).FpAux; pAux != 0; pAux = pNextAux {
		pNextAux = (*Fts5Auxiliary)(unsafe.Pointer(pAux)).FpNext
		if (*Fts5Auxiliary)(unsafe.Pointer(pAux)).FxDestroy != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Fts5Auxiliary)(unsafe.Pointer(pAux)).FxDestroy})).f(tls, (*Fts5Auxiliary)(unsafe.Pointer(pAux)).FpUserData)
		}
		Xsqlite3_free(tls, pAux)
	}

	for pTok = (*Fts5Global)(unsafe.Pointer(pGlobal)).FpTok; pTok != 0; pTok = pNextTok {
		pNextTok = (*Fts5TokenizerModule)(unsafe.Pointer(pTok)).FpNext
		if (*Fts5TokenizerModule)(unsafe.Pointer(pTok)).FxDestroy != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*Fts5TokenizerModule)(unsafe.Pointer(pTok)).FxDestroy})).f(tls, (*Fts5TokenizerModule)(unsafe.Pointer(pTok)).FpUserData)
		}
		Xsqlite3_free(tls, pTok)
	}

	Xsqlite3_free(tls, pGlobal)
}

func fts5Fts5Func(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var pGlobal uintptr = Xsqlite3_user_data(tls, pCtx)
	var ppApi uintptr
	_ = nArg

	ppApi = Xsqlite3_value_pointer(tls, *(*uintptr)(unsafe.Pointer(apArg)), ts+43455)
	if ppApi != 0 {
		*(*uintptr)(unsafe.Pointer(ppApi)) = pGlobal
	}
}

func fts5SourceIdFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apUnused uintptr) {
	_ = nArg
	_ = apUnused
	Xsqlite3_result_text(tls, pCtx, ts+43468, -1, libc.UintptrFromInt32(-1))
}

func fts5ShadowName(tls *libc.TLS, zName uintptr) int32 {
	var i uint32
	for i = uint32(0); uint64(i) < uint64(unsafe.Sizeof(azName2))/uint64(unsafe.Sizeof(uintptr(0))); i++ {
		if Xsqlite3_stricmp(tls, zName, azName2[i]) == 0 {
			return 1
		}
	}
	return 0
}

var azName2 = [5]uintptr{
	ts + 43559, ts + 41014, ts + 31344, ts + 41365, ts + 14903,
}

func fts5Init(tls *libc.TLS, db uintptr) int32 {
	var rc int32
	var pGlobal uintptr = uintptr(0)

	pGlobal = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Fts5Global{})))
	if pGlobal == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		var p uintptr = pGlobal
		libc.Xmemset(tls, pGlobal, 0, uint64(unsafe.Sizeof(Fts5Global{})))
		(*Fts5Global)(unsafe.Pointer(pGlobal)).Fdb = db
		(*Fts5Global)(unsafe.Pointer(pGlobal)).Fapi.FiVersion = 2
		(*Fts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateFunction = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, Fts5_extension_function, uintptr) int32
		}{fts5CreateAux}))
		(*Fts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxCreateTokenizer = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr) int32
		}{fts5CreateTokenizer}))
		(*Fts5Global)(unsafe.Pointer(pGlobal)).Fapi.FxFindTokenizer = *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) int32
		}{fts5FindTokenizer}))
		rc = Xsqlite3_create_module_v2(tls, db, ts+43566, uintptr(unsafe.Pointer(&fts5Mod)), p, *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{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, ts+43566, 1, SQLITE_UTF8, p, *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, int32, uintptr)
				}{fts5Fts5Func})), uintptr(0), uintptr(0))
		}
		if rc == SQLITE_OK {
			rc = Xsqlite3_create_function(tls,
				db, ts+43571, 0,
				SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS,
				p, *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, int32, uintptr)
				}{fts5SourceIdFunc})), uintptr(0), uintptr(0))
		}
	}

	return rc
}

var fts5Mod = Sqlite3_module{
	FiVersion:      3,
	FxCreate:       0,
	FxConnect:      0,
	FxBestIndex:    0,
	FxDisconnect:   0,
	FxDestroy:      0,
	FxOpen:         0,
	FxClose:        0,
	FxFilter:       0,
	FxNext:         0,
	FxEof:          0,
	FxColumn:       0,
	FxRowid:        0,
	FxUpdate:       0,
	FxBegin:        0,
	FxSync:         0,
	FxCommit:       0,
	FxRollback:     0,
	FxFindFunction: 0,
	FxRename:       0,
	FxSavepoint:    0,
	FxRelease:      0,
	FxRollbackTo:   0,
	FxShadowName:   0,
}

func Xsqlite3Fts5Init(tls *libc.TLS, db uintptr) int32 {
	return fts5Init(tls, db)
}

func fts5StorageGetStmt(tls *libc.TLS, p uintptr, eStmt int32, ppStmt uintptr, pzErrMsg uintptr) int32 {
	bp := tls.Alloc(216)
	defer tls.Free(216)

	var rc int32 = SQLITE_OK

	if *(*uintptr)(unsafe.Pointer(p + 40 + uintptr(eStmt)*8)) == uintptr(0) {
		*(*[11]uintptr)(unsafe.Pointer(bp + 128)) = [11]uintptr{
			ts + 43586,
			ts + 43654,
			ts + 43723,
			ts + 43756,
			ts + 43795,
			ts + 43835,
			ts + 43874,
			ts + 43915,
			ts + 43954,
			ts + 43996,
			ts + 44036,
		}
		var pC uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
		var zSql uintptr = uintptr(0)

		switch eStmt {
		case FTS5_STMT_SCAN:
			zSql = Xsqlite3_mprintf(tls, *(*uintptr)(unsafe.Pointer(bp + 128 + uintptr(eStmt)*8)),
				libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pC)).FzContentExprlist, (*Fts5Config)(unsafe.Pointer(pC)).FzContent))
			break
			fallthrough

		case FTS5_STMT_SCAN_ASC:
			fallthrough
		case FTS5_STMT_SCAN_DESC:
			zSql = Xsqlite3_mprintf(tls, *(*uintptr)(unsafe.Pointer(bp + 128 + uintptr(eStmt)*8)), libc.VaList(bp+16, (*Fts5Config)(unsafe.Pointer(pC)).FzContentExprlist,
				(*Fts5Config)(unsafe.Pointer(pC)).FzContent, (*Fts5Config)(unsafe.Pointer(pC)).FzContentRowid, (*Fts5Config)(unsafe.Pointer(pC)).FzContentRowid,
				(*Fts5Config)(unsafe.Pointer(pC)).FzContentRowid))
			break
			fallthrough

		case FTS5_STMT_LOOKUP:
			zSql = Xsqlite3_mprintf(tls, *(*uintptr)(unsafe.Pointer(bp + 128 + uintptr(eStmt)*8)),
				libc.VaList(bp+56, (*Fts5Config)(unsafe.Pointer(pC)).FzContentExprlist, (*Fts5Config)(unsafe.Pointer(pC)).FzContent, (*Fts5Config)(unsafe.Pointer(pC)).FzContentRowid))
			break
			fallthrough

		case FTS5_STMT_INSERT_CONTENT:
			fallthrough
		case FTS5_STMT_REPLACE_CONTENT:
			{
				var nCol int32 = (*Fts5Config)(unsafe.Pointer(pC)).FnCol + 1
				var zBind uintptr
				var i int32

				zBind = Xsqlite3_malloc64(tls, uint64(1+nCol*2))
				if zBind != 0 {
					for i = 0; i < nCol; i++ {
						*(*uint8)(unsafe.Pointer(zBind + uintptr(i*2))) = uint8('?')
						*(*uint8)(unsafe.Pointer(zBind + uintptr(i*2+1))) = uint8(',')
					}
					*(*uint8)(unsafe.Pointer(zBind + uintptr(i*2-1))) = uint8(0)
					zSql = Xsqlite3_mprintf(tls, *(*uintptr)(unsafe.Pointer(bp + 128 + uintptr(eStmt)*8)), libc.VaList(bp+80, (*Fts5Config)(unsafe.Pointer(pC)).FzDb, (*Fts5Config)(unsafe.Pointer(pC)).FzName, zBind))
					Xsqlite3_free(tls, zBind)
				}
				break

			}
			fallthrough

		default:
			zSql = Xsqlite3_mprintf(tls, *(*uintptr)(unsafe.Pointer(bp + 128 + uintptr(eStmt)*8)), libc.VaList(bp+104, (*Fts5Config)(unsafe.Pointer(pC)).FzDb, (*Fts5Config)(unsafe.Pointer(pC)).FzName))
			break
		}

		if zSql == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			var f int32 = SQLITE_PREPARE_PERSISTENT
			if eStmt > FTS5_STMT_LOOKUP {
				f = f | SQLITE_PREPARE_NO_VTAB
			}
			(*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock++
			rc = Xsqlite3_prepare_v3(tls, (*Fts5Config)(unsafe.Pointer(pC)).Fdb, zSql, -1, uint32(f), p+40+uintptr(eStmt)*8, uintptr(0))
			(*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FbLock--
			Xsqlite3_free(tls, zSql)
			if rc != SQLITE_OK && pzErrMsg != 0 {
				*(*uintptr)(unsafe.Pointer(pzErrMsg)) = Xsqlite3_mprintf(tls, ts+1684, libc.VaList(bp+120, Xsqlite3_errmsg(tls, (*Fts5Config)(unsafe.Pointer(pC)).Fdb)))
			}
		}
	}

	*(*uintptr)(unsafe.Pointer(ppStmt)) = *(*uintptr)(unsafe.Pointer(p + 40 + uintptr(eStmt)*8))
	Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(ppStmt)))
	return rc
}

func fts5ExecPrintf(tls *libc.TLS, db uintptr, pzErr uintptr, zFormat uintptr, va uintptr) int32 {
	var rc int32
	var ap Va_list
	_ = ap
	var zSql uintptr

	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFormat, ap)

	if zSql == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		rc = Xsqlite3_exec(tls, db, zSql, uintptr(0), uintptr(0), pzErr)
		Xsqlite3_free(tls, zSql)
	}

	_ = ap
	return rc
}

func sqlite3Fts5DropAll(tls *libc.TLS, pConfig uintptr) int32 {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var rc int32 = fts5ExecPrintf(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0),
		ts+44059,
		libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName,
			(*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName,
			(*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
	if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		rc = fts5ExecPrintf(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0),
			ts+44163,
			libc.VaList(bp+48, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
		rc = fts5ExecPrintf(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0),
			ts+44201,
			libc.VaList(bp+64, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
	}
	return rc
}

func fts5StorageRenameOne(tls *libc.TLS, pConfig uintptr, pRc uintptr, zTail uintptr, zName uintptr) {
	bp := tls.Alloc(40)
	defer tls.Free(40)

	if *(*int32)(unsafe.Pointer(pRc)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(pRc)) = fts5ExecPrintf(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0),
			ts+44239,
			libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName, zTail, zName, zTail))
	}
}

func sqlite3Fts5StorageRename(tls *libc.TLS, pStorage uintptr, zName uintptr) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(pStorage)).FpConfig
	*(*int32)(unsafe.Pointer(bp)) = sqlite3Fts5StorageSync(tls, pStorage)

	fts5StorageRenameOne(tls, pConfig, bp, ts+31344, zName)
	fts5StorageRenameOne(tls, pConfig, bp, ts+14903, zName)
	fts5StorageRenameOne(tls, pConfig, bp, ts+43559, zName)
	if (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		fts5StorageRenameOne(tls, pConfig, bp, ts+41365, zName)
	}
	if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
		fts5StorageRenameOne(tls, pConfig, bp, ts+41014, zName)
	}
	return *(*int32)(unsafe.Pointer(bp))
}

func sqlite3Fts5CreateTable(tls *libc.TLS, pConfig uintptr, zPost uintptr, zDefn uintptr, bWithout int32, pzErr uintptr) int32 {
	bp := tls.Alloc(72)
	defer tls.Free(72)

	var rc int32
	*(*uintptr)(unsafe.Pointer(bp + 64)) = uintptr(0)

	rc = fts5ExecPrintf(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, bp+64, ts+44281,
		libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName, zPost, zDefn,
			func() uintptr {
				if bWithout != 0 {
					return ts + 35997
				}
				return ts + 1636
			}()))
	if *(*uintptr)(unsafe.Pointer(bp + 64)) != 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls,
			ts+44311,
			libc.VaList(bp+40, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName, zPost, *(*uintptr)(unsafe.Pointer(bp + 64))))
		Xsqlite3_free(tls, *(*uintptr)(unsafe.Pointer(bp + 64)))
	}

	return rc
}

func sqlite3Fts5StorageOpen(tls *libc.TLS, pConfig uintptr, pIndex uintptr, bCreate int32, pp uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	var p uintptr
	var nByte Sqlite3_int64

	nByte = Sqlite3_int64(uint64(unsafe.Sizeof(Fts5Storage{})) +
		uint64((*Fts5Config)(unsafe.Pointer(pConfig)).FnCol)*uint64(unsafe.Sizeof(I64(0))))
	*(*uintptr)(unsafe.Pointer(pp)) = libc.AssignUintptr(&p, Xsqlite3_malloc64(tls, uint64(nByte)))
	if !(p != 0) {
		return SQLITE_NOMEM
	}

	libc.Xmemset(tls, p, 0, Size_t(nByte))
	(*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize = p + 1*128
	(*Fts5Storage)(unsafe.Pointer(p)).FpConfig = pConfig
	(*Fts5Storage)(unsafe.Pointer(p)).FpIndex = pIndex

	if bCreate != 0 {
		if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			var nDefn int32 = 32 + (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol*10
			var zDefn uintptr = Xsqlite3_malloc64(tls, uint64(int64(32)+Sqlite3_int64((*Fts5Config)(unsafe.Pointer(pConfig)).FnCol)*int64(10)))
			if zDefn == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				var i int32
				var iOff int32
				Xsqlite3_snprintf(tls, nDefn, zDefn, ts+44355, 0)
				iOff = int32(libc.Xstrlen(tls, zDefn))
				for i = 0; i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; i++ {
					Xsqlite3_snprintf(tls, nDefn-iOff, zDefn+uintptr(iOff), ts+44378, libc.VaList(bp, i))
					iOff = iOff + int32(libc.Xstrlen(tls, zDefn+uintptr(iOff)))
				}
				rc = sqlite3Fts5CreateTable(tls, pConfig, ts+41014, zDefn, 0, pzErr)
			}
			Xsqlite3_free(tls, zDefn)
		}

		if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
			rc = sqlite3Fts5CreateTable(tls,
				pConfig, ts+41365, ts+44384, 0, pzErr)
		}
		if rc == SQLITE_OK {
			rc = sqlite3Fts5CreateTable(tls,
				pConfig, ts+43559, ts+44416, 1, pzErr)
		}
		if rc == SQLITE_OK {
			rc = sqlite3Fts5StorageConfigValue(tls, p, ts+41511, uintptr(0), FTS5_CURRENT_VERSION)
		}
	}

	if rc != 0 {
		sqlite3Fts5StorageClose(tls, p)
		*(*uintptr)(unsafe.Pointer(pp)) = uintptr(0)
	}
	return rc
}

func sqlite3Fts5StorageClose(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = SQLITE_OK
	if p != 0 {
		var i int32

		for i = 0; i < int32(uint64(unsafe.Sizeof([11]uintptr{}))/uint64(unsafe.Sizeof(uintptr(0)))); i++ {
			Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(p + 40 + uintptr(i)*8)))
		}

		Xsqlite3_free(tls, p)
	}
	return rc
}

type Fts5InsertCtx1 = struct {
	FpStorage uintptr
	FiCol     int32
	FszCol    int32
}

type Fts5InsertCtx = Fts5InsertCtx1

func fts5StorageInsertCallback(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) int32 {
	var pCtx uintptr = pContext
	var pIdx uintptr = (*Fts5Storage)(unsafe.Pointer((*Fts5InsertCtx)(unsafe.Pointer(pCtx)).FpStorage)).FpIndex
	_ = iUnused1
	_ = iUnused2
	if nToken > FTS5_MAX_TOKEN_SIZE {
		nToken = FTS5_MAX_TOKEN_SIZE
	}
	if tflags&FTS5_TOKEN_COLOCATED == 0 || (*Fts5InsertCtx)(unsafe.Pointer(pCtx)).FszCol == 0 {
		(*Fts5InsertCtx)(unsafe.Pointer(pCtx)).FszCol++
	}
	return sqlite3Fts5IndexWrite(tls, pIdx, (*Fts5InsertCtx)(unsafe.Pointer(pCtx)).FiCol, (*Fts5InsertCtx)(unsafe.Pointer(pCtx)).FszCol-1, pToken, nToken)
}

func fts5StorageDeleteFromIndex(tls *libc.TLS, p uintptr, iDel I64, apVal uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32
	var rc2 int32
	var iCol int32

	if apVal == uintptr(0) {
		rc = fts5StorageGetStmt(tls, p, FTS5_STMT_LOOKUP, bp, uintptr(0))
		if rc != SQLITE_OK {
			return rc
		}
		Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 1, iDel)
		if Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) != SQLITE_ROW {
			return Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}

	(*Fts5InsertCtx)(unsafe.Pointer(bp + 8)).FpStorage = p
	(*Fts5InsertCtx)(unsafe.Pointer(bp + 8)).FiCol = -1
	rc = sqlite3Fts5IndexBeginWrite(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex, 1, iDel)
	for iCol = 1; rc == SQLITE_OK && iCol <= (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; iCol++ {
		if int32(*(*U8)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(iCol-1)))) == 0 {
			var zText uintptr
			var nText int32

			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-1)*8)))
				nText = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr(iCol-1)*8)))
			} else {
				continue
			}
			(*Fts5InsertCtx)(unsafe.Pointer(bp + 8)).FszCol = 0
			rc = sqlite3Fts5Tokenize(tls, pConfig, FTS5_TOKENIZE_DOCUMENT,
				zText, nText, bp+8, *(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
				}{fts5StorageInsertCallback})))
			*(*I64)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(iCol-1)*8)) -= I64((*Fts5InsertCtx)(unsafe.Pointer(bp + 8)).FszCol)
			if *(*I64)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(iCol-1)*8)) < int64(0) {
				rc = SQLITE_CORRUPT | int32(1)<<8
			}
		}
	}
	if rc == SQLITE_OK && (*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow < int64(1) {
		rc = SQLITE_CORRUPT | int32(1)<<8
	} else {
		(*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow--
	}

	rc2 = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
	if rc == SQLITE_OK {
		rc = rc2
	}
	return rc
}

func fts5StorageInsertDocsize(tls *libc.TLS, p uintptr, iRowid I64, pBuf uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_OK
	if (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FbColumnsize != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		rc = fts5StorageGetStmt(tls, p, FTS5_STMT_REPLACE_DOCSIZE, bp, uintptr(0))
		if rc == SQLITE_OK {
			Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 1, iRowid)
			Xsqlite3_bind_blob(tls, *(*uintptr)(unsafe.Pointer(bp)), 2, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fp, (*Fts5Buffer)(unsafe.Pointer(pBuf)).Fn, uintptr(0))
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
			Xsqlite3_bind_null(tls, *(*uintptr)(unsafe.Pointer(bp)), 2)
		}
	}
	return rc
}

func fts5StorageLoadTotals(tls *libc.TLS, p uintptr, bCache int32) int32 {
	var rc int32 = SQLITE_OK
	if (*Fts5Storage)(unsafe.Pointer(p)).FbTotalsValid == 0 {
		rc = sqlite3Fts5IndexGetAverages(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex, p+24, (*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize)
		(*Fts5Storage)(unsafe.Pointer(p)).FbTotalsValid = bCache
	}
	return rc
}

func fts5StorageSaveTotals(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(20)
	defer tls.Free(20)

	var nCol int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol
	var i int32

	*(*int32)(unsafe.Pointer(bp + 16)) = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))

	sqlite3Fts5BufferAppendVarint(tls, bp+16, bp, (*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow)
	for i = 0; i < nCol; i++ {
		sqlite3Fts5BufferAppendVarint(tls, bp+16, bp, *(*I64)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i)*8)))
	}
	if *(*int32)(unsafe.Pointer(bp + 16)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 16)) = sqlite3Fts5IndexSetAverages(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp, (*Fts5Buffer)(unsafe.Pointer(bp)).Fn)
	}
	Xsqlite3_free(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp)

	return *(*int32)(unsafe.Pointer(bp + 16))
}

func sqlite3Fts5StorageDelete(tls *libc.TLS, p uintptr, iDel I64, apVal uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	var rc int32
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)

	rc = fts5StorageLoadTotals(tls, p, 1)

	if rc == SQLITE_OK {
		rc = fts5StorageDeleteFromIndex(tls, p, iDel, apVal)
	}

	if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		rc = fts5StorageGetStmt(tls, p, FTS5_STMT_DELETE_DOCSIZE, bp, uintptr(0))
		if rc == SQLITE_OK {
			Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 1, iDel)
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}

	if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
		if rc == SQLITE_OK {
			rc = fts5StorageGetStmt(tls, p, FTS5_STMT_DELETE_CONTENT, bp, uintptr(0))
		}
		if rc == SQLITE_OK {
			Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 1, iDel)
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
	}

	return rc
}

func sqlite3Fts5StorageDeleteAll(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(48)
	defer tls.Free(48)

	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	var rc int32

	(*Fts5Storage)(unsafe.Pointer(p)).FbTotalsValid = 0

	rc = fts5ExecPrintf(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0),
		ts+44433,
		libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName,
			(*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
	if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
		rc = fts5ExecPrintf(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, uintptr(0),
			ts+44483,
			libc.VaList(bp+32, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName))
	}

	if rc == SQLITE_OK {
		rc = sqlite3Fts5IndexReinit(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex)
	}
	if rc == SQLITE_OK {
		rc = sqlite3Fts5StorageConfigValue(tls, p, ts+41511, uintptr(0), FTS5_CURRENT_VERSION)
	}
	return rc
}

func sqlite3Fts5StorageRebuild(tls *libc.TLS, p uintptr) int32 {
	bp := tls.Alloc(44)
	defer tls.Free(44)

	*(*Fts5Buffer)(unsafe.Pointer(bp + 24)) = Fts5Buffer{}
	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	*(*uintptr)(unsafe.Pointer(bp + 16)) = uintptr(0)

	var rc2 int32

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5InsertCtx{})))
	(*Fts5InsertCtx)(unsafe.Pointer(bp)).FpStorage = p
	*(*int32)(unsafe.Pointer(bp + 40)) = sqlite3Fts5StorageDeleteAll(tls, p)
	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 40)) = fts5StorageLoadTotals(tls, p, 1)
	}

	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 40)) = fts5StorageGetStmt(tls, p, FTS5_STMT_SCAN, bp+16, uintptr(0))
	}

	for *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 16))) {
		var iRowid I64 = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), 0)

		sqlite3Fts5BufferZero(tls, bp+24)
		*(*int32)(unsafe.Pointer(bp + 40)) = sqlite3Fts5IndexBeginWrite(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex, 0, iRowid)
		for (*Fts5InsertCtx)(unsafe.Pointer(bp)).FiCol = 0; *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK && (*Fts5InsertCtx)(unsafe.Pointer(bp)).FiCol < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; (*Fts5InsertCtx)(unsafe.Pointer(bp)).FiCol++ {
			(*Fts5InsertCtx)(unsafe.Pointer(bp)).FszCol = 0
			if int32(*(*U8)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr((*Fts5InsertCtx)(unsafe.Pointer(bp)).FiCol)))) == 0 {
				var zText uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), (*Fts5InsertCtx)(unsafe.Pointer(bp)).FiCol+1)
				var nText int32 = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 16)), (*Fts5InsertCtx)(unsafe.Pointer(bp)).FiCol+1)
				*(*int32)(unsafe.Pointer(bp + 40)) = sqlite3Fts5Tokenize(tls, pConfig,
					FTS5_TOKENIZE_DOCUMENT,
					zText, nText,
					bp,
					*(*uintptr)(unsafe.Pointer(&struct {
						f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
					}{fts5StorageInsertCallback})))
			}
			sqlite3Fts5BufferAppendVarint(tls, bp+40, bp+24, int64((*Fts5InsertCtx)(unsafe.Pointer(bp)).FszCol))
			*(*I64)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr((*Fts5InsertCtx)(unsafe.Pointer(bp)).FiCol)*8)) += I64((*Fts5InsertCtx)(unsafe.Pointer(bp)).FszCol)
		}
		(*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow++

		if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 40)) = fts5StorageInsertDocsize(tls, p, iRowid, bp+24)
		}
	}
	Xsqlite3_free(tls, (*Fts5Buffer)(unsafe.Pointer(bp+24)).Fp)
	rc2 = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 16)))
	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 40)) = rc2
	}

	if *(*int32)(unsafe.Pointer(bp + 40)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 40)) = fts5StorageSaveTotals(tls, p)
	}
	return *(*int32)(unsafe.Pointer(bp + 40))
}

func sqlite3Fts5StorageOptimize(tls *libc.TLS, p uintptr) int32 {
	return sqlite3Fts5IndexOptimize(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex)
}

func sqlite3Fts5StorageMerge(tls *libc.TLS, p uintptr, nMerge int32) int32 {
	return sqlite3Fts5IndexMerge(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex, nMerge)
}

func sqlite3Fts5StorageReset(tls *libc.TLS, p uintptr) int32 {
	return sqlite3Fts5IndexReset(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex)
}

func fts5StorageNewRowid(tls *libc.TLS, p uintptr, piRowid uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var rc int32 = SQLITE_MISMATCH
	if (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FbColumnsize != 0 {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		rc = fts5StorageGetStmt(tls, p, FTS5_STMT_REPLACE_DOCSIZE, bp, uintptr(0))
		if rc == SQLITE_OK {
			Xsqlite3_bind_null(tls, *(*uintptr)(unsafe.Pointer(bp)), 1)
			Xsqlite3_bind_null(tls, *(*uintptr)(unsafe.Pointer(bp)), 2)
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		if rc == SQLITE_OK {
			*(*I64)(unsafe.Pointer(piRowid)) = Xsqlite3_last_insert_rowid(tls, (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).Fdb)
		}
	}
	return rc
}

func sqlite3Fts5StorageContentInsert(tls *libc.TLS, p uintptr, apVal uintptr, piRowid uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	var rc int32 = SQLITE_OK

	if (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent != FTS5_CONTENT_NORMAL {
		if Xsqlite3_value_type(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8))) == SQLITE_INTEGER {
			*(*I64)(unsafe.Pointer(piRowid)) = Xsqlite3_value_int64(tls, *(*uintptr)(unsafe.Pointer(apVal + 1*8)))
		} else {
			rc = fts5StorageNewRowid(tls, p, piRowid)
		}
	} else {
		*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
		var i int32
		rc = fts5StorageGetStmt(tls, p, FTS5_STMT_INSERT_CONTENT, bp, uintptr(0))
		for i = 1; rc == SQLITE_OK && i <= (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol+1; i++ {
			rc = Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp)), i, *(*uintptr)(unsafe.Pointer(apVal + uintptr(i)*8)))
		}
		if rc == SQLITE_OK {
			Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp)))
			rc = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp)))
		}
		*(*I64)(unsafe.Pointer(piRowid)) = Xsqlite3_last_insert_rowid(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb)
	}

	return rc
}

func sqlite3Fts5StorageIndexInsert(tls *libc.TLS, p uintptr, apVal uintptr, iRowid I64) int32 {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	*(*int32)(unsafe.Pointer(bp + 32)) = SQLITE_OK

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5Buffer{})))
	(*Fts5InsertCtx)(unsafe.Pointer(bp + 16)).FpStorage = p
	*(*int32)(unsafe.Pointer(bp + 32)) = fts5StorageLoadTotals(tls, p, 1)

	if *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 32)) = sqlite3Fts5IndexBeginWrite(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex, 0, iRowid)
	}
	for (*Fts5InsertCtx)(unsafe.Pointer(bp + 16)).FiCol = 0; *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK && (*Fts5InsertCtx)(unsafe.Pointer(bp+16)).FiCol < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; (*Fts5InsertCtx)(unsafe.Pointer(bp+16)).FiCol++ {
		(*Fts5InsertCtx)(unsafe.Pointer(bp + 16)).FszCol = 0
		if int32(*(*U8)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr((*Fts5InsertCtx)(unsafe.Pointer(bp+16)).FiCol)))) == 0 {
			var zText uintptr = Xsqlite3_value_text(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr((*Fts5InsertCtx)(unsafe.Pointer(bp+16)).FiCol+2)*8)))
			var nText int32 = Xsqlite3_value_bytes(tls, *(*uintptr)(unsafe.Pointer(apVal + uintptr((*Fts5InsertCtx)(unsafe.Pointer(bp+16)).FiCol+2)*8)))
			*(*int32)(unsafe.Pointer(bp + 32)) = sqlite3Fts5Tokenize(tls, pConfig,
				FTS5_TOKENIZE_DOCUMENT,
				zText, nText,
				bp+16,
				*(*uintptr)(unsafe.Pointer(&struct {
					f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
				}{fts5StorageInsertCallback})))
		}
		sqlite3Fts5BufferAppendVarint(tls, bp+32, bp, int64((*Fts5InsertCtx)(unsafe.Pointer(bp+16)).FszCol))
		*(*I64)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr((*Fts5InsertCtx)(unsafe.Pointer(bp+16)).FiCol)*8)) += I64((*Fts5InsertCtx)(unsafe.Pointer(bp + 16)).FszCol)
	}
	(*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow++

	if *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK {
		*(*int32)(unsafe.Pointer(bp + 32)) = fts5StorageInsertDocsize(tls, p, iRowid, bp)
	}
	Xsqlite3_free(tls, (*Fts5Buffer)(unsafe.Pointer(bp)).Fp)

	return *(*int32)(unsafe.Pointer(bp + 32))
}

func fts5StorageCount(tls *libc.TLS, p uintptr, zSuffix uintptr, pnRow uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	var zSql uintptr
	var rc int32

	zSql = Xsqlite3_mprintf(tls, ts+44512,
		libc.VaList(bp, (*Fts5Config)(unsafe.Pointer(pConfig)).FzDb, (*Fts5Config)(unsafe.Pointer(pConfig)).FzName, zSuffix))
	if zSql == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		*(*uintptr)(unsafe.Pointer(bp + 24)) = uintptr(0)
		rc = Xsqlite3_prepare_v2(tls, (*Fts5Config)(unsafe.Pointer(pConfig)).Fdb, zSql, -1, bp+24, uintptr(0))
		if rc == SQLITE_OK {
			if SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 24))) {
				*(*I64)(unsafe.Pointer(pnRow)) = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 24)), 0)
			}
			rc = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 24)))
		}
	}

	Xsqlite3_free(tls, zSql)
	return rc
}

type Fts5IntegrityCtx1 = struct {
	FiRowid   I64
	FiCol     int32
	FszCol    int32
	Fcksum    U64
	FpTermset uintptr
	FpConfig  uintptr
}

type Fts5IntegrityCtx = Fts5IntegrityCtx1

func fts5StorageIntegrityCallback(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iUnused1 int32, iUnused2 int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var pCtx uintptr = pContext
	var pTermset uintptr = (*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FpTermset

	var ii int32
	var rc int32 = SQLITE_OK
	var iPos int32
	var iCol int32

	_ = iUnused1
	_ = iUnused2
	if nToken > FTS5_MAX_TOKEN_SIZE {
		nToken = FTS5_MAX_TOKEN_SIZE
	}

	if tflags&FTS5_TOKEN_COLOCATED == 0 || (*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FszCol == 0 {
		(*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FszCol++
	}

	switch (*Fts5Config)(unsafe.Pointer((*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FpConfig)).FeDetail {
	case FTS5_DETAIL_FULL:
		iPos = (*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FszCol - 1
		iCol = (*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FiCol
		break

	case FTS5_DETAIL_COLUMNS:
		iPos = (*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FiCol
		iCol = 0
		break

	default:
		iPos = 0
		iCol = 0
		break
	}

	rc = sqlite3Fts5TermsetAdd(tls, pTermset, 0, pToken, nToken, bp)
	if rc == SQLITE_OK && *(*int32)(unsafe.Pointer(bp)) == 0 {
		*(*U64)(unsafe.Pointer(pCtx + 16)) ^= sqlite3Fts5IndexEntryCksum(tls,
			(*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FiRowid, iCol, iPos, 0, pToken, nToken)
	}

	for ii = 0; rc == SQLITE_OK && ii < (*Fts5Config)(unsafe.Pointer((*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FpConfig)).FnPrefix; ii++ {
		var nChar int32 = *(*int32)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer((*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FpConfig)).FaPrefix + uintptr(ii)*4))
		var nByte int32 = sqlite3Fts5IndexCharlenToBytelen(tls, pToken, nToken, nChar)
		if nByte != 0 {
			rc = sqlite3Fts5TermsetAdd(tls, pTermset, ii+1, pToken, nByte, bp)
			if *(*int32)(unsafe.Pointer(bp)) == 0 {
				*(*U64)(unsafe.Pointer(pCtx + 16)) ^= sqlite3Fts5IndexEntryCksum(tls,
					(*Fts5IntegrityCtx)(unsafe.Pointer(pCtx)).FiRowid, iCol, iPos, ii+1, pToken, nByte)
			}
		}
	}

	return rc
}

func sqlite3Fts5StorageIntegrity(tls *libc.TLS, p uintptr, iArg int32) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var pConfig uintptr = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	var rc int32 = SQLITE_OK
	var aColSize uintptr
	var aTotalSize uintptr

	var bUseCksum int32

	libc.Xmemset(tls, bp, 0, uint64(unsafe.Sizeof(Fts5IntegrityCtx{})))
	(*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FpConfig = (*Fts5Storage)(unsafe.Pointer(p)).FpConfig
	aTotalSize = Xsqlite3_malloc64(tls, uint64((*Fts5Config)(unsafe.Pointer(pConfig)).FnCol)*(uint64(unsafe.Sizeof(int32(0)))+uint64(unsafe.Sizeof(I64(0)))))
	if !(aTotalSize != 0) {
		return SQLITE_NOMEM
	}
	aColSize = aTotalSize + uintptr((*Fts5Config)(unsafe.Pointer(pConfig)).FnCol)*8
	libc.Xmemset(tls, aTotalSize, 0, uint64(unsafe.Sizeof(I64(0)))*uint64((*Fts5Config)(unsafe.Pointer(pConfig)).FnCol))

	bUseCksum = libc.Bool32((*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL ||
		(*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_EXTERNAL && iArg != 0)
	if bUseCksum != 0 {
		rc = fts5StorageGetStmt(tls, p, FTS5_STMT_SCAN, bp+40, uintptr(0))
		if rc == SQLITE_OK {
			var rc2 int32
			for SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 40))) {
				var i int32
				(*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FiRowid = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 40)), 0)
				(*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FszCol = 0
				if (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
					rc = sqlite3Fts5StorageDocsize(tls, p, (*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FiRowid, aColSize)
				}
				if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_NONE {
					rc = sqlite3Fts5TermsetNew(tls, bp+24)
				}
				for i = 0; rc == SQLITE_OK && i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; i++ {
					if *(*U8)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer(pConfig)).FabUnindexed + uintptr(i))) != 0 {
						continue
					}
					(*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FiCol = i
					(*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FszCol = 0
					if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_COLUMNS {
						rc = sqlite3Fts5TermsetNew(tls, bp+24)
					}
					if rc == SQLITE_OK {
						var zText uintptr = Xsqlite3_column_text(tls, *(*uintptr)(unsafe.Pointer(bp + 40)), i+1)
						var nText int32 = Xsqlite3_column_bytes(tls, *(*uintptr)(unsafe.Pointer(bp + 40)), i+1)
						rc = sqlite3Fts5Tokenize(tls, pConfig,
							FTS5_TOKENIZE_DOCUMENT,
							zText, nText,
							bp,
							*(*uintptr)(unsafe.Pointer(&struct {
								f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
							}{fts5StorageIntegrityCallback})))
					}
					if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 && (*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FszCol != *(*int32)(unsafe.Pointer(aColSize + uintptr(i)*4)) {
						rc = SQLITE_CORRUPT | int32(1)<<8
					}
					*(*I64)(unsafe.Pointer(aTotalSize + uintptr(i)*8)) += I64((*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FszCol)
					if (*Fts5Config)(unsafe.Pointer(pConfig)).FeDetail == FTS5_DETAIL_COLUMNS {
						sqlite3Fts5TermsetFree(tls, (*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FpTermset)
						(*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FpTermset = uintptr(0)
					}
				}
				sqlite3Fts5TermsetFree(tls, (*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FpTermset)
				(*Fts5IntegrityCtx)(unsafe.Pointer(bp)).FpTermset = uintptr(0)

				if rc != SQLITE_OK {
					break
				}
			}
			rc2 = Xsqlite3_reset(tls, *(*uintptr)(unsafe.Pointer(bp + 40)))
			if rc == SQLITE_OK {
				rc = rc2
			}
		}

		if rc == SQLITE_OK {
			var i int32
			rc = fts5StorageLoadTotals(tls, p, 0)
			for i = 0; rc == SQLITE_OK && i < (*Fts5Config)(unsafe.Pointer(pConfig)).FnCol; i++ {
				if *(*I64)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i)*8)) != *(*I64)(unsafe.Pointer(aTotalSize + uintptr(i)*8)) {
					rc = SQLITE_CORRUPT | int32(1)<<8
				}
			}
		}

		if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			*(*I64)(unsafe.Pointer(bp + 48)) = int64(0)
			rc = fts5StorageCount(tls, p, ts+41014, bp+48)
			if rc == SQLITE_OK && *(*I64)(unsafe.Pointer(bp + 48)) != (*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow {
				rc = SQLITE_CORRUPT | int32(1)<<8
			}
		}
		if rc == SQLITE_OK && (*Fts5Config)(unsafe.Pointer(pConfig)).FbColumnsize != 0 {
			*(*I64)(unsafe.Pointer(bp + 56)) = int64(0)
			rc = fts5StorageCount(tls, p, ts+41365, bp+56)
			if rc == SQLITE_OK && *(*I64)(unsafe.Pointer(bp + 56)) != (*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow {
				rc = SQLITE_CORRUPT | int32(1)<<8
			}
		}
	}

	if rc == SQLITE_OK {
		rc = sqlite3Fts5IndexIntegrityCheck(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex, (*Fts5IntegrityCtx)(unsafe.Pointer(bp)).Fcksum, bUseCksum)
	}

	Xsqlite3_free(tls, aTotalSize)
	return rc
}

func sqlite3Fts5StorageStmt(tls *libc.TLS, p uintptr, eStmt int32, pp uintptr, pzErrMsg uintptr) int32 {
	var rc int32

	rc = fts5StorageGetStmt(tls, p, eStmt, pp, pzErrMsg)
	if rc == SQLITE_OK {
		*(*uintptr)(unsafe.Pointer(p + 40 + uintptr(eStmt)*8)) = uintptr(0)
	}
	return rc
}

func sqlite3Fts5StorageStmtRelease(tls *libc.TLS, p uintptr, eStmt int32, pStmt uintptr) {
	if *(*uintptr)(unsafe.Pointer(p + 40 + uintptr(eStmt)*8)) == uintptr(0) {
		Xsqlite3_reset(tls, pStmt)
		*(*uintptr)(unsafe.Pointer(p + 40 + uintptr(eStmt)*8)) = pStmt
	} else {
		Xsqlite3_finalize(tls, pStmt)
	}
}

func fts5StorageDecodeSizeArray(tls *libc.TLS, aCol uintptr, nCol int32, aBlob uintptr, nBlob int32) int32 {
	var i int32
	var iOff int32 = 0
	for i = 0; i < nCol; i++ {
		if iOff >= nBlob {
			return 1
		}
		iOff = iOff + sqlite3Fts5GetVarint32(tls, aBlob+uintptr(iOff), aCol+uintptr(i)*4)
	}
	return libc.Bool32(iOff != nBlob)
}

func sqlite3Fts5StorageDocsize(tls *libc.TLS, p uintptr, iRowid I64, aCol uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var nCol int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32

	rc = fts5StorageGetStmt(tls, p, FTS5_STMT_LOOKUP_DOCSIZE, bp, uintptr(0))
	if *(*uintptr)(unsafe.Pointer(bp)) != 0 {
		var bCorrupt int32 = 1

		Xsqlite3_bind_int64(tls, *(*uintptr)(unsafe.Pointer(bp)), 1, iRowid)
		if SQLITE_ROW == Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp))) {
			var aBlob uintptr = Xsqlite3_column_blob(tls, *(*uintptr)(unsafe.Pointer(bp)), 0)
			var nBlob int32 = 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 = SQLITE_CORRUPT | int32(1)<<8
		}
	} else {
	}

	return rc
}

func sqlite3Fts5StorageSize(tls *libc.TLS, p uintptr, iCol int32, pnToken uintptr) int32 {
	var rc int32 = fts5StorageLoadTotals(tls, p, 0)
	if rc == SQLITE_OK {
		*(*I64)(unsafe.Pointer(pnToken)) = int64(0)
		if iCol < 0 {
			var i int32
			for i = 0; i < (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol; i++ {
				*(*I64)(unsafe.Pointer(pnToken)) += *(*I64)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i)*8))
			}
		} else if iCol < (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol {
			*(*I64)(unsafe.Pointer(pnToken)) = *(*I64)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(iCol)*8))
		} else {
			rc = SQLITE_RANGE
		}
	}
	return rc
}

func sqlite3Fts5StorageRowCount(tls *libc.TLS, p uintptr, pnRow uintptr) int32 {
	var rc int32 = fts5StorageLoadTotals(tls, p, 0)
	if rc == SQLITE_OK {
		*(*I64)(unsafe.Pointer(pnRow)) = (*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow
		if (*Fts5Storage)(unsafe.Pointer(p)).FnTotalRow <= int64(0) {
			rc = SQLITE_CORRUPT | int32(1)<<8
		}
	}
	return rc
}

func sqlite3Fts5StorageSync(tls *libc.TLS, p uintptr) int32 {
	var rc int32 = SQLITE_OK
	var iLastRowid I64 = Xsqlite3_last_insert_rowid(tls, (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).Fdb)
	if (*Fts5Storage)(unsafe.Pointer(p)).FbTotalsValid != 0 {
		rc = fts5StorageSaveTotals(tls, p)
		(*Fts5Storage)(unsafe.Pointer(p)).FbTotalsValid = 0
	}
	if rc == SQLITE_OK {
		rc = sqlite3Fts5IndexSync(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex)
	}
	Xsqlite3_set_last_insert_rowid(tls, (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).Fdb, iLastRowid)
	return rc
}

func sqlite3Fts5StorageRollback(tls *libc.TLS, p uintptr) int32 {
	(*Fts5Storage)(unsafe.Pointer(p)).FbTotalsValid = 0
	return sqlite3Fts5IndexRollback(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex)
}

func sqlite3Fts5StorageConfigValue(tls *libc.TLS, p uintptr, z uintptr, pVal uintptr, iVal int32) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var rc int32 = fts5StorageGetStmt(tls, p, FTS5_STMT_REPLACE_CONFIG, bp, uintptr(0))
	if rc == SQLITE_OK {
		Xsqlite3_bind_text(tls, *(*uintptr)(unsafe.Pointer(bp)), 1, z, -1, uintptr(0))
		if pVal != 0 {
			Xsqlite3_bind_value(tls, *(*uintptr)(unsafe.Pointer(bp)), 2, pVal)
		} else {
			Xsqlite3_bind_int(tls, *(*uintptr)(unsafe.Pointer(bp)), 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)), 1)
	}
	if rc == SQLITE_OK && pVal != 0 {
		var iNew int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FiCookie + 1
		rc = sqlite3Fts5IndexSetCookie(tls, (*Fts5Storage)(unsafe.Pointer(p)).FpIndex, iNew)
		if rc == SQLITE_OK {
			(*Fts5Config)(unsafe.Pointer((*Fts5Storage)(unsafe.Pointer(p)).FpConfig)).FiCookie = iNew
		}
	}
	return rc
}

var aAsciiTokenChar = [128]uint8{
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1),
	uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
	uint8(0), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1),
	uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(1), uint8(0), uint8(0), uint8(0), uint8(0), uint8(0),
}

type AsciiTokenizer1 = struct{ FaTokenChar [128]uint8 }

type AsciiTokenizer = AsciiTokenizer1

func fts5AsciiAddExceptions(tls *libc.TLS, p uintptr, zArg uintptr, bTokenChars int32) {
	var i int32
	for i = 0; *(*uint8)(unsafe.Pointer(zArg + uintptr(i))) != 0; i++ {
		if int32(*(*uint8)(unsafe.Pointer(zArg + uintptr(i))))&0x80 == 0 {
			*(*uint8)(unsafe.Pointer(p + uintptr(int32(*(*uint8)(unsafe.Pointer(zArg + uintptr(i))))))) = uint8(bTokenChars)
		}
	}
}

func fts5AsciiDelete(tls *libc.TLS, p uintptr) {
	Xsqlite3_free(tls, p)
}

func fts5AsciiCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) int32 {
	var rc int32 = SQLITE_OK
	var p uintptr = uintptr(0)
	_ = pUnused
	if nArg%2 != 0 {
		rc = SQLITE_ERROR
	} else {
		p = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(AsciiTokenizer{})))
		if p == uintptr(0) {
			rc = SQLITE_NOMEM
		} else {
			var i int32
			libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(AsciiTokenizer{})))
			libc.Xmemcpy(tls, p, uintptr(unsafe.Pointer(&aAsciiTokenChar)), uint64(unsafe.Sizeof(aAsciiTokenChar)))
			for i = 0; rc == SQLITE_OK && i < nArg; i = i + 2 {
				var zArg uintptr = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i+1)*8))
				if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8)), ts+44544) {
					fts5AsciiAddExceptions(tls, p, zArg, 1)
				} else if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8)), ts+44555) {
					fts5AsciiAddExceptions(tls, p, zArg, 0)
				} else {
					rc = SQLITE_ERROR
				}
			}
			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 i int32
	for i = 0; i < nByte; i++ {
		var c uint8 = *(*uint8)(unsafe.Pointer(aIn + uintptr(i)))
		if int32(c) >= 'A' && int32(c) <= 'Z' {
			c = uint8(int32(c) + 32)
		}
		*(*uint8)(unsafe.Pointer(aOut + uintptr(i))) = c
	}
}

func fts5AsciiTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, iUnused int32, pText uintptr, nText int32, xToken uintptr) int32 {
	bp := tls.Alloc(64)
	defer tls.Free(64)

	var p uintptr = pTokenizer
	var rc int32 = SQLITE_OK
	var ie int32
	var is int32 = 0

	var nFold int32 = int32(unsafe.Sizeof([64]uint8{}))
	var pFold uintptr = bp
	var a uintptr = p

	_ = iUnused

	for is < nText && rc == SQLITE_OK {
		var nByte int32

		for is < nText && (int32(*(*uint8)(unsafe.Pointer(pText + uintptr(is))))&0x80 == 0 && int32(*(*uint8)(unsafe.Pointer(a + uintptr(int32(*(*uint8)(unsafe.Pointer(pText + uintptr(is)))))))) == 0) {
			is++
		}
		if is == nText {
			break
		}

		ie = is + 1
		for ie < nText && (int32(*(*uint8)(unsafe.Pointer(pText + uintptr(ie))))&0x80 != 0 || *(*uint8)(unsafe.Pointer(a + uintptr(int32(*(*uint8)(unsafe.Pointer(pText + uintptr(ie))))))) != 0) {
			ie++
		}

		nByte = ie - is
		if nByte > nFold {
			if pFold != bp {
				Xsqlite3_free(tls, pFold)
			}
			pFold = Xsqlite3_malloc64(tls, uint64(Sqlite3_int64(nByte)*int64(2)))
			if pFold == uintptr(0) {
				rc = SQLITE_NOMEM
				break
			}
			nFold = nByte * 2
		}
		asciiFold(tls, pFold, pText+uintptr(is), nByte)

		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{xToken})).f(tls, pCtx, 0, pFold, nByte, is, ie)
		is = ie + 1
	}

	if pFold != bp {
		Xsqlite3_free(tls, pFold)
	}
	if rc == SQLITE_DONE {
		rc = SQLITE_OK
	}
	return rc
}

type Unicode61Tokenizer1 = struct {
	FaTokenChar       [128]uint8
	FaFold            uintptr
	FnFold            int32
	FeRemoveDiacritic int32
	FnException       int32
	F__ccgo_pad1      [4]byte
	FaiException      uintptr
	FaCategory        [32]uint8
}

type Unicode61Tokenizer = Unicode61Tokenizer1

func fts5UnicodeAddExceptions(tls *libc.TLS, p uintptr, z uintptr, bTokenChars int32) int32 {
	var rc int32 = SQLITE_OK
	var n int32 = int32(libc.Xstrlen(tls, z))
	var aNew uintptr

	if n > 0 {
		aNew = Xsqlite3_realloc64(tls, (*Unicode61Tokenizer)(unsafe.Pointer(p)).FaiException,
			uint64(n+(*Unicode61Tokenizer)(unsafe.Pointer(p)).FnException)*uint64(unsafe.Sizeof(int32(0))))
		if aNew != 0 {
			var nNew int32 = (*Unicode61Tokenizer)(unsafe.Pointer(p)).FnException
			var zCsr uintptr = z
			var zTerm uintptr = z + uintptr(n)
			for zCsr < zTerm {
				var iCode U32
				var bToken int32
				iCode = U32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zCsr, 1))))
				if iCode >= U32(0xc0) {
					iCode = U32(sqlite3Utf8Trans1[iCode-U32(0xc0)])
					for zCsr != zTerm && int32(*(*uint8)(unsafe.Pointer(zCsr)))&0xc0 == 0x80 {
						iCode = iCode<<6 + U32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zCsr, 1)))))
					}
					if iCode < U32(0x80) || iCode&0xFFFFF800 == U32(0xD800) || iCode&0xFFFFFFFE == U32(0xFFFE) {
						iCode = U32(0xFFFD)
					}
				}

				if iCode < U32(128) {
					*(*uint8)(unsafe.Pointer(p + uintptr(iCode))) = uint8(bTokenChars)
				} else {
					bToken = int32(*(*uint8)(unsafe.Pointer(p + 160 + uintptr(sqlite3Fts5UnicodeCategory(tls, iCode)))))

					if bToken != bTokenChars && sqlite3Fts5UnicodeIsdiacritic(tls, int32(iCode)) == 0 {
						var i int32
						for i = 0; i < nNew; i++ {
							if U32(*(*int32)(unsafe.Pointer(aNew + uintptr(i)*4))) > iCode {
								break
							}
						}
						libc.Xmemmove(tls, aNew+uintptr(i+1)*4, aNew+uintptr(i)*4, uint64(nNew-i)*uint64(unsafe.Sizeof(int32(0))))
						*(*int32)(unsafe.Pointer(aNew + uintptr(i)*4)) = int32(iCode)
						nNew++
					}
				}
			}
			(*Unicode61Tokenizer)(unsafe.Pointer(p)).FaiException = aNew
			(*Unicode61Tokenizer)(unsafe.Pointer(p)).FnException = nNew
		} else {
			rc = SQLITE_NOMEM
		}
	}

	return rc
}

func fts5UnicodeIsException(tls *libc.TLS, p uintptr, iCode int32) int32 {
	if (*Unicode61Tokenizer)(unsafe.Pointer(p)).FnException > 0 {
		var a uintptr = (*Unicode61Tokenizer)(unsafe.Pointer(p)).FaiException
		var iLo int32 = 0
		var iHi int32 = (*Unicode61Tokenizer)(unsafe.Pointer(p)).FnException - 1

		for iHi >= iLo {
			var iTest int32 = (iHi + iLo) / 2
			if iCode == *(*int32)(unsafe.Pointer(a + uintptr(iTest)*4)) {
				return 1
			} else if iCode > *(*int32)(unsafe.Pointer(a + uintptr(iTest)*4)) {
				iLo = iTest + 1
			} else {
				iHi = iTest - 1
			}
		}
	}

	return 0
}

func fts5UnicodeDelete(tls *libc.TLS, pTok uintptr) {
	if pTok != 0 {
		var p uintptr = pTok
		Xsqlite3_free(tls, (*Unicode61Tokenizer)(unsafe.Pointer(p)).FaiException)
		Xsqlite3_free(tls, (*Unicode61Tokenizer)(unsafe.Pointer(p)).FaFold)
		Xsqlite3_free(tls, p)
	}
	return
}

func unicodeSetCategories(tls *libc.TLS, p uintptr, zCat uintptr) int32 {
	var z uintptr = zCat

	for *(*uint8)(unsafe.Pointer(z)) != 0 {
		for int32(*(*uint8)(unsafe.Pointer(z))) == ' ' || int32(*(*uint8)(unsafe.Pointer(z))) == '\t' {
			z++
		}
		if *(*uint8)(unsafe.Pointer(z)) != 0 && sqlite3Fts5UnicodeCatParse(tls, z, p+160) != 0 {
			return SQLITE_ERROR
		}
		for int32(*(*uint8)(unsafe.Pointer(z))) != ' ' && int32(*(*uint8)(unsafe.Pointer(z))) != '\t' && int32(*(*uint8)(unsafe.Pointer(z))) != 0 {
			z++
		}
	}

	sqlite3Fts5UnicodeAscii(tls, p+160, p)
	return SQLITE_OK
}

func fts5UnicodeCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) int32 {
	var rc int32 = SQLITE_OK
	var p uintptr = uintptr(0)

	_ = pUnused

	if nArg%2 != 0 {
		rc = SQLITE_ERROR
	} else {
		p = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(Unicode61Tokenizer{})))
		if p != 0 {
			var zCat uintptr = ts + 44566
			var i int32
			libc.Xmemset(tls, p, 0, uint64(unsafe.Sizeof(Unicode61Tokenizer{})))

			(*Unicode61Tokenizer)(unsafe.Pointer(p)).FeRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE
			(*Unicode61Tokenizer)(unsafe.Pointer(p)).FnFold = 64
			(*Unicode61Tokenizer)(unsafe.Pointer(p)).FaFold = Xsqlite3_malloc64(tls, uint64((*Unicode61Tokenizer)(unsafe.Pointer(p)).FnFold)*uint64(unsafe.Sizeof(uint8(0))))
			if (*Unicode61Tokenizer)(unsafe.Pointer(p)).FaFold == uintptr(0) {
				rc = SQLITE_NOMEM
			}

			for i = 0; rc == SQLITE_OK && i < nArg; i = i + 2 {
				if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8)), ts+44575) {
					zCat = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i+1)*8))
				}
			}

			if rc == SQLITE_OK {
				rc = unicodeSetCategories(tls, p, zCat)
			}

			for i = 0; rc == SQLITE_OK && i < nArg; i = i + 2 {
				var zArg uintptr = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i+1)*8))
				if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8)), ts+44586) {
					if int32(*(*uint8)(unsafe.Pointer(zArg))) != '0' && int32(*(*uint8)(unsafe.Pointer(zArg))) != '1' && int32(*(*uint8)(unsafe.Pointer(zArg))) != '2' || *(*uint8)(unsafe.Pointer(zArg + 1)) != 0 {
						rc = SQLITE_ERROR
					} else {
						(*Unicode61Tokenizer)(unsafe.Pointer(p)).FeRemoveDiacritic = int32(*(*uint8)(unsafe.Pointer(zArg))) - '0'

					}
				} else if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8)), ts+44544) {
					rc = fts5UnicodeAddExceptions(tls, p, zArg, 1)
				} else if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8)), ts+44555) {
					rc = fts5UnicodeAddExceptions(tls, p, zArg, 0)
				} else if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8)), ts+44575) {
				} else {
					rc = SQLITE_ERROR
				}
			}

		} else {
			rc = SQLITE_NOMEM
		}
		if rc != SQLITE_OK {
			fts5UnicodeDelete(tls, p)
			p = uintptr(0)
		}
		*(*uintptr)(unsafe.Pointer(ppOut)) = p
	}
	return rc
}

func fts5UnicodeIsAlnum(tls *libc.TLS, p uintptr, iCode int32) int32 {
	return int32(*(*uint8)(unsafe.Pointer(p + 160 + uintptr(sqlite3Fts5UnicodeCategory(tls, U32(iCode)))))) ^
		fts5UnicodeIsException(tls, p, iCode)
}

func fts5UnicodeTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, iUnused int32, pText uintptr, nText int32, xToken uintptr) int32 {
	var p uintptr
	var rc int32
	var a uintptr
	var zTerm uintptr
	var zCsr uintptr

	var aFold uintptr
	var nFold int32
	var pEnd uintptr
	var iCode U32
	var zOut uintptr
	var is int32
	var ie int32
	p = pTokenizer
	rc = SQLITE_OK
	a = p
	zTerm = pText + uintptr(nText)
	zCsr = pText
	aFold = (*Unicode61Tokenizer)(unsafe.Pointer(p)).FaFold
	nFold = (*Unicode61Tokenizer)(unsafe.Pointer(p)).FnFold
	pEnd = aFold + uintptr(nFold-6)

	_ = iUnused

__1:
	if !(rc == SQLITE_OK) {
		goto __2
	}
	zOut = aFold

__3:
	if !(1 != 0) {
		goto __4
	}
	if !(zCsr >= zTerm) {
		goto __5
	}
	goto tokenize_done
__5:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(zCsr)))&0x80 != 0) {
		goto __6
	}

	is = int32((int64(zCsr) - int64(pText)) / 1)
	iCode = U32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zCsr, 1))))
	if !(iCode >= U32(0xc0)) {
		goto __8
	}
	iCode = U32(sqlite3Utf8Trans1[iCode-U32(0xc0)])
__9:
	if !(zCsr != zTerm && int32(*(*uint8)(unsafe.Pointer(zCsr)))&0xc0 == 0x80) {
		goto __10
	}
	iCode = iCode<<6 + U32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zCsr, 1)))))
	goto __9
__10:
	;
	if !(iCode < U32(0x80) || iCode&0xFFFFF800 == U32(0xD800) || iCode&0xFFFFFFFE == U32(0xFFFE)) {
		goto __11
	}
	iCode = U32(0xFFFD)
__11:
	;
__8:
	;
	if !(fts5UnicodeIsAlnum(tls, p, int32(iCode)) != 0) {
		goto __12
	}
	goto non_ascii_tokenchar
__12:
	;
	goto __7
__6:
	if !(*(*uint8)(unsafe.Pointer(a + uintptr(*(*uint8)(unsafe.Pointer(zCsr))))) != 0) {
		goto __13
	}
	is = int32((int64(zCsr) - int64(pText)) / 1)
	goto ascii_tokenchar
__13:
	;
	zCsr++
__7:
	;
	goto __3
__4:
	;
__14:
	if !(zCsr < zTerm) {
		goto __15
	}

	if !(zOut > pEnd) {
		goto __16
	}
	aFold = Xsqlite3_malloc64(tls, uint64(Sqlite3_int64(nFold)*int64(2)))
	if !(aFold == uintptr(0)) {
		goto __17
	}
	rc = SQLITE_NOMEM
	goto tokenize_done
__17:
	;
	zOut = aFold + uintptr((int64(zOut)-int64((*Unicode61Tokenizer)(unsafe.Pointer(p)).FaFold))/1)
	libc.Xmemcpy(tls, aFold, (*Unicode61Tokenizer)(unsafe.Pointer(p)).FaFold, uint64(nFold))
	Xsqlite3_free(tls, (*Unicode61Tokenizer)(unsafe.Pointer(p)).FaFold)
	(*Unicode61Tokenizer)(unsafe.Pointer(p)).FaFold = aFold
	(*Unicode61Tokenizer)(unsafe.Pointer(p)).FnFold = libc.AssignInt32(&nFold, nFold*2)
	pEnd = aFold + uintptr(nFold-6)
__16:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(zCsr)))&0x80 != 0) {
		goto __18
	}

	iCode = U32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zCsr, 1))))
	if !(iCode >= U32(0xc0)) {
		goto __20
	}
	iCode = U32(sqlite3Utf8Trans1[iCode-U32(0xc0)])
__21:
	if !(zCsr != zTerm && int32(*(*uint8)(unsafe.Pointer(zCsr)))&0xc0 == 0x80) {
		goto __22
	}
	iCode = iCode<<6 + U32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zCsr, 1)))))
	goto __21
__22:
	;
	if !(iCode < U32(0x80) || iCode&0xFFFFF800 == U32(0xD800) || iCode&0xFFFFFFFE == U32(0xFFFE)) {
		goto __23
	}
	iCode = U32(0xFFFD)
__23:
	;
__20:
	;
	if !(fts5UnicodeIsAlnum(tls, p, int32(iCode)) != 0 || sqlite3Fts5UnicodeIsdiacritic(tls, int32(iCode)) != 0) {
		goto __24
	}
non_ascii_tokenchar:
	iCode = U32(sqlite3Fts5UnicodeFold(tls, int32(iCode), (*Unicode61Tokenizer)(unsafe.Pointer(p)).FeRemoveDiacritic))
	if !(iCode != 0) {
		goto __26
	}
	if !(iCode < U32(0x00080)) {
		goto __27
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = U8(iCode & U32(0xFF))
	goto __28
__27:
	if !(iCode < U32(0x00800)) {
		goto __29
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xC0 + int32(U8(iCode>>6&U32(0x1F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
	goto __30
__29:
	if !(iCode < U32(0x10000)) {
		goto __31
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xE0 + int32(U8(iCode>>12&U32(0x0F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>6&U32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
	goto __32
__31:
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xF0 + int32(U8(iCode>>18&U32(0x07))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>12&U32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>6&U32(0x3F))))
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
__32:
	;
__30:
	;
__28:
	;
__26:
	;
	goto __25
__24:
	goto __15
__25:
	;
	goto __19
__18:
	if !(int32(*(*uint8)(unsafe.Pointer(a + uintptr(*(*uint8)(unsafe.Pointer(zCsr)))))) == 0) {
		goto __33
	}

	goto __15
	goto __34
__33:
ascii_tokenchar:
	if !(int32(*(*uint8)(unsafe.Pointer(zCsr))) >= 'A' && int32(*(*uint8)(unsafe.Pointer(zCsr))) <= 'Z') {
		goto __35
	}
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(int32(*(*uint8)(unsafe.Pointer(zCsr))) + 32)
	goto __36
__35:
	*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = *(*uint8)(unsafe.Pointer(zCsr))
__36:
	;
	zCsr++
__34:
	;
__19:
	;
	ie = int32((int64(zCsr) - int64(pText)) / 1)
	goto __14
__15:
	;
	rc = (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{xToken})).f(tls, pCtx, 0, aFold, int32((int64(zOut)-int64(aFold))/1), is, ie)
	goto __1
__2:
	;
tokenize_done:
	if !(rc == SQLITE_DONE) {
		goto __37
	}
	rc = SQLITE_OK
__37:
	;
	return rc
}

type PorterTokenizer1 = struct {
	Ftokenizer  Fts5_tokenizer
	FpTokenizer uintptr
	FaBuf       [128]uint8
}

type PorterTokenizer = PorterTokenizer1

func fts5PorterDelete(tls *libc.TLS, pTok uintptr) {
	if pTok != 0 {
		var p uintptr = pTok
		if (*PorterTokenizer)(unsafe.Pointer(p)).FpTokenizer != 0 {
			(*struct{ f func(*libc.TLS, uintptr) })(unsafe.Pointer(&struct{ uintptr }{(*PorterTokenizer)(unsafe.Pointer(p)).Ftokenizer.FxDelete})).f(tls, (*PorterTokenizer)(unsafe.Pointer(p)).FpTokenizer)
		}
		Xsqlite3_free(tls, p)
	}
}

func fts5PorterCreate(tls *libc.TLS, pCtx uintptr, azArg uintptr, nArg int32, ppOut uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var pApi uintptr = pCtx
	var rc int32 = SQLITE_OK
	var pRet uintptr
	*(*uintptr)(unsafe.Pointer(bp)) = uintptr(0)
	var zBase uintptr = ts + 44604

	if nArg > 0 {
		zBase = *(*uintptr)(unsafe.Pointer(azArg))
	}

	pRet = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(PorterTokenizer{})))
	if pRet != 0 {
		libc.Xmemset(tls, pRet, 0, uint64(unsafe.Sizeof(PorterTokenizer{})))
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5_api)(unsafe.Pointer(pApi)).FxFindTokenizer})).f(tls, pApi, zBase, bp, pRet)
	} else {
		rc = SQLITE_NOMEM
	}
	if rc == SQLITE_OK {
		var nArg2 int32 = func() int32 {
			if nArg > 0 {
				return nArg - 1
			}
			return 0
		}()
		var azArg2 uintptr = func() uintptr {
			if nArg2 != 0 {
				return azArg + 1*8
			}
			return uintptr(0)
		}()
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*PorterTokenizer)(unsafe.Pointer(pRet)).Ftokenizer.FxCreate})).f(tls, *(*uintptr)(unsafe.Pointer(bp)), azArg2, nArg2, pRet+24)
	}

	if rc != SQLITE_OK {
		fts5PorterDelete(tls, pRet)
		pRet = uintptr(0)
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = pRet
	return rc
}

type PorterContext1 = struct {
	FpCtx   uintptr
	FxToken uintptr
	FaBuf   uintptr
}

type PorterContext = PorterContext1

type PorterRule1 = struct {
	FzSuffix     uintptr
	FnSuffix     int32
	F__ccgo_pad1 [4]byte
	FxCond       uintptr
	FzOutput     uintptr
	FnOutput     int32
	F__ccgo_pad2 [4]byte
}

type PorterRule = PorterRule1

func fts5PorterIsVowel(tls *libc.TLS, c uint8, bYIsVowel int32) int32 {
	return libc.Bool32(int32(c) == 'a' || int32(c) == 'e' || int32(c) == 'i' || int32(c) == 'o' || int32(c) == 'u' || bYIsVowel != 0 && int32(c) == 'y')
}

func fts5PorterGobbleVC(tls *libc.TLS, zStem uintptr, nStem int32, bPrevCons int32) int32 {
	var i int32
	var bCons int32 = bPrevCons

	for i = 0; i < nStem; i++ {
		if 0 == libc.AssignInt32(&bCons, libc.BoolInt32(!(fts5PorterIsVowel(tls, *(*uint8)(unsafe.Pointer(zStem + uintptr(i))), bCons) != 0))) {
			break
		}
	}

	for i++; i < nStem; i++ {
		if libc.AssignInt32(&bCons, libc.BoolInt32(!(fts5PorterIsVowel(tls, *(*uint8)(unsafe.Pointer(zStem + uintptr(i))), bCons) != 0))) != 0 {
			return i + 1
		}
	}
	return 0
}

func fts5Porter_MGt0(tls *libc.TLS, zStem uintptr, nStem int32) int32 {
	return libc.BoolInt32(!!(fts5PorterGobbleVC(tls, zStem, nStem, 0) != 0))
}

func fts5Porter_MGt1(tls *libc.TLS, zStem uintptr, nStem int32) int32 {
	var n int32
	n = fts5PorterGobbleVC(tls, zStem, nStem, 0)
	if n != 0 && fts5PorterGobbleVC(tls, zStem+uintptr(n), nStem-n, 1) != 0 {
		return 1
	}
	return 0
}

func fts5Porter_MEq1(tls *libc.TLS, zStem uintptr, nStem int32) int32 {
	var n int32
	n = fts5PorterGobbleVC(tls, zStem, nStem, 0)
	if n != 0 && 0 == fts5PorterGobbleVC(tls, zStem+uintptr(n), nStem-n, 1) {
		return 1
	}
	return 0
}

func fts5Porter_Ostar(tls *libc.TLS, zStem uintptr, nStem int32) int32 {
	if int32(*(*uint8)(unsafe.Pointer(zStem + uintptr(nStem-1)))) == 'w' || int32(*(*uint8)(unsafe.Pointer(zStem + uintptr(nStem-1)))) == 'x' || int32(*(*uint8)(unsafe.Pointer(zStem + uintptr(nStem-1)))) == 'y' {
		return 0
	} else {
		var i int32
		var mask int32 = 0
		var bCons int32 = 0
		for i = 0; i < nStem; i++ {
			bCons = libc.BoolInt32(!(fts5PorterIsVowel(tls, *(*uint8)(unsafe.Pointer(zStem + uintptr(i))), bCons) != 0))

			mask = mask<<1 + bCons
		}
		return libc.Bool32(mask&0x0007 == 0x0005)
	}
	return int32(0)
}

func fts5Porter_MGt1_and_S_or_T(tls *libc.TLS, zStem uintptr, nStem int32) int32 {
	return libc.Bool32((int32(*(*uint8)(unsafe.Pointer(zStem + uintptr(nStem-1)))) == 's' || int32(*(*uint8)(unsafe.Pointer(zStem + uintptr(nStem-1)))) == 't') &&
		fts5Porter_MGt1(tls, zStem, nStem) != 0)
}

func fts5Porter_Vowel(tls *libc.TLS, zStem uintptr, nStem int32) int32 {
	var i int32
	for i = 0; i < nStem; i++ {
		if fts5PorterIsVowel(tls, *(*uint8)(unsafe.Pointer(zStem + uintptr(i))), libc.Bool32(i > 0)) != 0 {
			return 1
		}
	}
	return 0
}

func fts5PorterStep4(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) int32 {
	var ret int32 = 0
	var nBuf int32 = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-2)))) {
	case 'a':
		if nBuf > 2 && 0 == libc.Xmemcmp(tls, ts+44614, aBuf+uintptr(nBuf-2), uint64(2)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-2) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2
			}
		}
		break

	case 'c':
		if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44617, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-4) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4
			}
		} else if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44622, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-4) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4
			}
		}
		break

	case 'e':
		if nBuf > 2 && 0 == libc.Xmemcmp(tls, ts+44627, aBuf+uintptr(nBuf-2), uint64(2)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-2) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2
			}
		}
		break

	case 'i':
		if nBuf > 2 && 0 == libc.Xmemcmp(tls, ts+44630, aBuf+uintptr(nBuf-2), uint64(2)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-2) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2
			}
		}
		break

	case 'l':
		if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44633, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-4) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4
			}
		} else if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44638, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-4) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4
			}
		}
		break

	case 'n':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44643, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		} else if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44647, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-5) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5
			}
		} else if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44653, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-4) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4
			}
		} else if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44658, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		}
		break

	case 'o':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44662, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1_and_S_or_T(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		} else if nBuf > 2 && 0 == libc.Xmemcmp(tls, ts+44666, aBuf+uintptr(nBuf-2), uint64(2)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-2) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2
			}
		}
		break

	case 's':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44669, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		}
		break

	case 't':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44673, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		} else if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44677, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		}
		break

	case 'u':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44681, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		}
		break

	case 'v':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44685, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		}
		break

	case 'z':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44689, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt1(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		}
		break

	}
	return ret
}

func fts5PorterStep1B2(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) int32 {
	var ret int32 = 0
	var nBuf int32 = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-2)))) {
	case 'a':
		if nBuf > 2 && 0 == libc.Xmemcmp(tls, ts+44693, aBuf+uintptr(nBuf-2), uint64(2)) {
			libc.Xmemcpy(tls, aBuf+uintptr(nBuf-2), ts+44673, uint64(3))
			*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2 + 3
			ret = 1
		}
		break

	case 'b':
		if nBuf > 2 && 0 == libc.Xmemcmp(tls, ts+44696, aBuf+uintptr(nBuf-2), uint64(2)) {
			libc.Xmemcpy(tls, aBuf+uintptr(nBuf-2), ts+44699, uint64(3))
			*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2 + 3
			ret = 1
		}
		break

	case 'i':
		if nBuf > 2 && 0 == libc.Xmemcmp(tls, ts+44703, aBuf+uintptr(nBuf-2), uint64(2)) {
			libc.Xmemcpy(tls, aBuf+uintptr(nBuf-2), ts+44689, uint64(3))
			*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2 + 3
			ret = 1
		}
		break

	}
	return ret
}

func fts5PorterStep2(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) int32 {
	var ret int32 = 0
	var nBuf int32 = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-2)))) {
	case 'a':
		if nBuf > 7 && 0 == libc.Xmemcmp(tls, ts+44706, aBuf+uintptr(nBuf-7), uint64(7)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-7) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-7), ts+44673, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 7 + 3
			}
		} else if nBuf > 6 && 0 == libc.Xmemcmp(tls, ts+44714, aBuf+uintptr(nBuf-6), uint64(6)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-6) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-6), ts+44721, uint64(4))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 6 + 4
			}
		}
		break

	case 'c':
		if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44726, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-4) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-4), ts+44622, uint64(4))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4 + 4
			}
		} else if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44731, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-4) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-4), ts+44617, uint64(4))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4 + 4
			}
		}
		break

	case 'e':
		if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44736, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-4) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-4), ts+44689, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4 + 3
			}
		}
		break

	case 'g':
		if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44741, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-4) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-4), ts+18893, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4 + 3
			}
		}
		break

	case 'l':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44746, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-3) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-3), ts+44699, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3 + 3
			}
		} else if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44750, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-4) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-4), ts+44614, uint64(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4 + 2
			}
		} else if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44755, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44658, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 3
			}
		} else if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44761, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-3) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-3), ts+44765, uint64(1))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3 + 1
			}
		} else if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44767, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44681, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 3
			}
		}
		break

	case 'o':
		if nBuf > 7 && 0 == libc.Xmemcmp(tls, ts+44773, aBuf+uintptr(nBuf-7), uint64(7)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-7) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-7), ts+44689, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 7 + 3
			}
		} else if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44781, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44673, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 3
			}
		} else if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44787, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-4) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-4), ts+44673, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4 + 3
			}
		}
		break

	case 's':
		if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44792, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44614, uint64(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 2
			}
		} else if nBuf > 7 && 0 == libc.Xmemcmp(tls, ts+44798, aBuf+uintptr(nBuf-7), uint64(7)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-7) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-7), ts+44685, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 7 + 3
			}
		} else if nBuf > 7 && 0 == libc.Xmemcmp(tls, ts+44806, aBuf+uintptr(nBuf-7), uint64(7)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-7) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-7), ts+44814, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 7 + 3
			}
		} else if nBuf > 7 && 0 == libc.Xmemcmp(tls, ts+44818, aBuf+uintptr(nBuf-7), uint64(7)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-7) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-7), ts+44681, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 7 + 3
			}
		}
		break

	case 't':
		if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44826, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44614, uint64(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 2
			}
		} else if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44832, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44685, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 3
			}
		} else if nBuf > 6 && 0 == libc.Xmemcmp(tls, ts+44838, aBuf+uintptr(nBuf-6), uint64(6)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-6) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-6), ts+44699, uint64(3))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 6 + 3
			}
		}
		break

	}
	return ret
}

func fts5PorterStep3(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) int32 {
	var ret int32 = 0
	var nBuf int32 = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-2)))) {
	case 'a':
		if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44845, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-4) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-4), ts+44630, uint64(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4 + 2
			}
		}
		break

	case 's':
		if nBuf > 4 && 0 == libc.Xmemcmp(tls, ts+44850, aBuf+uintptr(nBuf-4), uint64(4)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-4) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 4
			}
		}
		break

	case 't':
		if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44855, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44630, uint64(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 2
			}
		} else if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44861, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44630, uint64(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 2
			}
		}
		break

	case 'u':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44814, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
			}
		}
		break

	case 'v':
		if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44867, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5
			}
		}
		break

	case 'z':
		if nBuf > 5 && 0 == libc.Xmemcmp(tls, ts+44873, aBuf+uintptr(nBuf-5), uint64(5)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-5) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-5), ts+44614, uint64(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 5 + 2
			}
		}
		break

	}
	return ret
}

func fts5PorterStep1B(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) int32 {
	var ret int32 = 0
	var nBuf int32 = *(*int32)(unsafe.Pointer(pnBuf))
	switch int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-2)))) {
	case 'e':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44879, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_MGt0(tls, aBuf, nBuf-3) != 0 {
				libc.Xmemcpy(tls, aBuf+uintptr(nBuf-3), ts+44883, uint64(2))
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3 + 2
			}
		} else if nBuf > 2 && 0 == libc.Xmemcmp(tls, ts+44886, aBuf+uintptr(nBuf-2), uint64(2)) {
			if fts5Porter_Vowel(tls, aBuf, nBuf-2) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2
				ret = 1
			}
		}
		break

	case 'n':
		if nBuf > 3 && 0 == libc.Xmemcmp(tls, ts+44889, aBuf+uintptr(nBuf-3), uint64(3)) {
			if fts5Porter_Vowel(tls, aBuf, nBuf-3) != 0 {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 3
				ret = 1
			}
		}
		break

	}
	return ret
}

func fts5PorterStep1A(tls *libc.TLS, aBuf uintptr, pnBuf uintptr) {
	var nBuf int32 = *(*int32)(unsafe.Pointer(pnBuf))
	if int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-1)))) == 's' {
		if int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-2)))) == 'e' {
			if nBuf > 4 && int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-4)))) == 's' && int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-3)))) == 's' ||
				nBuf > 3 && int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-3)))) == 'i' {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 2
			} else {
				*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 1
			}
		} else if int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(nBuf-2)))) != 's' {
			*(*int32)(unsafe.Pointer(pnBuf)) = nBuf - 1
		}
	}
}

func fts5PorterCb(tls *libc.TLS, pCtx uintptr, tflags int32, pToken uintptr, nToken int32, iStart int32, iEnd int32) int32 {
	bp := tls.Alloc(4)
	defer tls.Free(4)

	var p uintptr
	var aBuf uintptr

	var c uint8
	p = pCtx

	if !(nToken > FTS5_PORTER_MAX_TOKEN || nToken < 3) {
		goto __1
	}
	goto pass_through
__1:
	;
	aBuf = (*PorterContext)(unsafe.Pointer(p)).FaBuf
	*(*int32)(unsafe.Pointer(bp)) = nToken
	libc.Xmemcpy(tls, aBuf, pToken, uint64(*(*int32)(unsafe.Pointer(bp))))

	fts5PorterStep1A(tls, aBuf, bp)
	if !(fts5PorterStep1B(tls, aBuf, bp) != 0) {
		goto __2
	}
	if !(fts5PorterStep1B2(tls, aBuf, bp) == 0) {
		goto __3
	}
	c = *(*uint8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-1)))
	if !(fts5PorterIsVowel(tls, c, 0) == 0 &&
		int32(c) != 'l' && int32(c) != 's' && int32(c) != 'z' && int32(c) == int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-2))))) {
		goto __4
	}
	*(*int32)(unsafe.Pointer(bp))--
	goto __5
__4:
	if !(fts5Porter_MEq1(tls, aBuf, *(*int32)(unsafe.Pointer(bp))) != 0 && fts5Porter_Ostar(tls, aBuf, *(*int32)(unsafe.Pointer(bp))) != 0) {
		goto __6
	}
	*(*uint8)(unsafe.Pointer(aBuf + uintptr(libc.PostIncInt32(&*(*int32)(unsafe.Pointer(bp)), 1)))) = uint8('e')
__6:
	;
__5:
	;
__3:
	;
__2:
	;
	if !(int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-1)))) == 'y' && fts5Porter_Vowel(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-1) != 0) {
		goto __7
	}
	*(*uint8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-1))) = uint8('i')
__7:
	;
	fts5PorterStep2(tls, aBuf, bp)
	fts5PorterStep3(tls, aBuf, bp)
	fts5PorterStep4(tls, aBuf, bp)

	if !(int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-1)))) == 'e') {
		goto __8
	}
	if !(fts5Porter_MGt1(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-1) != 0 ||
		fts5Porter_MEq1(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-1) != 0 && !(fts5Porter_Ostar(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-1) != 0)) {
		goto __9
	}
	*(*int32)(unsafe.Pointer(bp))--
__9:
	;
__8:
	;
	if !(*(*int32)(unsafe.Pointer(bp)) > 1 && int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-1)))) == 'l' &&
		int32(*(*uint8)(unsafe.Pointer(aBuf + uintptr(*(*int32)(unsafe.Pointer(bp))-2)))) == 'l' && fts5Porter_MGt1(tls, aBuf, *(*int32)(unsafe.Pointer(bp))-1) != 0) {
		goto __10
	}
	*(*int32)(unsafe.Pointer(bp))--
__10:
	;
	return (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*PorterContext)(unsafe.Pointer(p)).FxToken})).f(tls, (*PorterContext)(unsafe.Pointer(p)).FpCtx, tflags, aBuf, *(*int32)(unsafe.Pointer(bp)), iStart, iEnd)

pass_through:
	return (*struct {
		f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*PorterContext)(unsafe.Pointer(p)).FxToken})).f(tls, (*PorterContext)(unsafe.Pointer(p)).FpCtx, tflags, pToken, nToken, iStart, iEnd)
}

func fts5PorterTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, flags int32, pText uintptr, nText int32, xToken uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var p uintptr = pTokenizer

	(*PorterContext)(unsafe.Pointer(bp)).FxToken = xToken
	(*PorterContext)(unsafe.Pointer(bp)).FpCtx = pCtx
	(*PorterContext)(unsafe.Pointer(bp)).FaBuf = p + 32
	return (*struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32
	})(unsafe.Pointer(&struct{ uintptr }{(*PorterTokenizer)(unsafe.Pointer(p)).Ftokenizer.FxTokenize})).f(tls,
		(*PorterTokenizer)(unsafe.Pointer(p)).FpTokenizer, bp, flags, pText, nText, *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
		}{fts5PorterCb})))
}

type TrigramTokenizer1 = struct{ FbFold int32 }

type TrigramTokenizer = TrigramTokenizer1

func fts5TriDelete(tls *libc.TLS, p uintptr) {
	Xsqlite3_free(tls, p)
}

func fts5TriCreate(tls *libc.TLS, pUnused uintptr, azArg uintptr, nArg int32, ppOut uintptr) int32 {
	var rc int32 = SQLITE_OK
	var pNew uintptr = Xsqlite3_malloc(tls, int32(unsafe.Sizeof(TrigramTokenizer{})))
	_ = pUnused
	if pNew == uintptr(0) {
		rc = SQLITE_NOMEM
	} else {
		var i int32
		(*TrigramTokenizer)(unsafe.Pointer(pNew)).FbFold = 1
		for i = 0; rc == SQLITE_OK && i < nArg; i = i + 2 {
			var zArg uintptr = *(*uintptr)(unsafe.Pointer(azArg + uintptr(i+1)*8))
			if 0 == Xsqlite3_stricmp(tls, *(*uintptr)(unsafe.Pointer(azArg + uintptr(i)*8)), ts+44893) {
				if int32(*(*uint8)(unsafe.Pointer(zArg))) != '0' && int32(*(*uint8)(unsafe.Pointer(zArg))) != '1' || *(*uint8)(unsafe.Pointer(zArg + 1)) != 0 {
					rc = SQLITE_ERROR
				} else {
					(*TrigramTokenizer)(unsafe.Pointer(pNew)).FbFold = libc.Bool32(int32(*(*uint8)(unsafe.Pointer(zArg))) == '0')
				}
			} else {
				rc = SQLITE_ERROR
			}
		}
		if rc != SQLITE_OK {
			fts5TriDelete(tls, pNew)
			pNew = uintptr(0)
		}
	}
	*(*uintptr)(unsafe.Pointer(ppOut)) = pNew
	return rc
}

func fts5TriTokenize(tls *libc.TLS, pTok uintptr, pCtx uintptr, unusedFlags int32, pText uintptr, nText int32, xToken uintptr) int32 {
	bp := tls.Alloc(32)
	defer tls.Free(32)

	var p uintptr = pTok
	var rc int32 = SQLITE_OK

	var zIn uintptr = pText
	var zEof uintptr = zIn + uintptr(nText)
	var iCode U32

	_ = unusedFlags
	for 1 != 0 {
		var zOut uintptr = bp
		var iStart int32 = int32((int64(zIn) - int64(pText)) / 1)
		var zNext uintptr

		iCode = U32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
		if iCode >= U32(0xc0) {
			iCode = U32(sqlite3Utf8Trans1[iCode-U32(0xc0)])
			for zIn != zEof && int32(*(*uint8)(unsafe.Pointer(zIn)))&0xc0 == 0x80 {
				iCode = iCode<<6 + U32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))))
			}
			if iCode < U32(0x80) || iCode&0xFFFFF800 == U32(0xD800) || iCode&0xFFFFFFFE == U32(0xFFFE) {
				iCode = U32(0xFFFD)
			}
		}

		if iCode == U32(0) {
			break
		}
		zNext = zIn
		if zIn < zEof {
			if (*TrigramTokenizer)(unsafe.Pointer(p)).FbFold != 0 {
				iCode = U32(sqlite3Fts5UnicodeFold(tls, int32(iCode), 0))
			}
			{
				if iCode < U32(0x00080) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = U8(iCode & U32(0xFF))
				} else if iCode < U32(0x00800) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xC0 + int32(U8(iCode>>6&U32(0x1F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				} else if iCode < U32(0x10000) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xE0 + int32(U8(iCode>>12&U32(0x0F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>6&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				} else {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xF0 + int32(U8(iCode>>18&U32(0x07))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>12&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>6&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				}
			}

			iCode = U32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
			if iCode >= U32(0xc0) {
				iCode = U32(sqlite3Utf8Trans1[iCode-U32(0xc0)])
				for zIn != zEof && int32(*(*uint8)(unsafe.Pointer(zIn)))&0xc0 == 0x80 {
					iCode = iCode<<6 + U32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))))
				}
				if iCode < U32(0x80) || iCode&0xFFFFF800 == U32(0xD800) || iCode&0xFFFFFFFE == U32(0xFFFE) {
					iCode = U32(0xFFFD)
				}
			}

			if iCode == U32(0) {
				break
			}
		} else {
			break
		}
		if zIn < zEof {
			if (*TrigramTokenizer)(unsafe.Pointer(p)).FbFold != 0 {
				iCode = U32(sqlite3Fts5UnicodeFold(tls, int32(iCode), 0))
			}
			{
				if iCode < U32(0x00080) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = U8(iCode & U32(0xFF))
				} else if iCode < U32(0x00800) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xC0 + int32(U8(iCode>>6&U32(0x1F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				} else if iCode < U32(0x10000) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xE0 + int32(U8(iCode>>12&U32(0x0F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>6&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				} else {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xF0 + int32(U8(iCode>>18&U32(0x07))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>12&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>6&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				}
			}

			iCode = U32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1))))
			if iCode >= U32(0xc0) {
				iCode = U32(sqlite3Utf8Trans1[iCode-U32(0xc0)])
				for zIn != zEof && int32(*(*uint8)(unsafe.Pointer(zIn)))&0xc0 == 0x80 {
					iCode = iCode<<6 + U32(0x3f&int32(*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zIn, 1)))))
				}
				if iCode < U32(0x80) || iCode&0xFFFFF800 == U32(0xD800) || iCode&0xFFFFFFFE == U32(0xFFFE) {
					iCode = U32(0xFFFD)
				}
			}

			if iCode == U32(0) {
				break
			}
			if (*TrigramTokenizer)(unsafe.Pointer(p)).FbFold != 0 {
				iCode = U32(sqlite3Fts5UnicodeFold(tls, int32(iCode), 0))
			}
			{
				if iCode < U32(0x00080) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = U8(iCode & U32(0xFF))
				} else if iCode < U32(0x00800) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xC0 + int32(U8(iCode>>6&U32(0x1F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				} else if iCode < U32(0x10000) {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xE0 + int32(U8(iCode>>12&U32(0x0F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>6&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				} else {
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0xF0 + int32(U8(iCode>>18&U32(0x07))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>12&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode>>6&U32(0x3F))))
					*(*uint8)(unsafe.Pointer(libc.PostIncUintptr(&zOut, 1))) = uint8(0x80 + int32(U8(iCode&U32(0x3F))))
				}
			}

		} else {
			break
		}
		rc = (*struct {
			f func(*libc.TLS, uintptr, int32, uintptr, int32, int32, int32) int32
		})(unsafe.Pointer(&struct{ uintptr }{xToken})).f(tls, pCtx, 0, bp, int32(int64((zOut-bp)/1)), iStart, int32(int64((uintptr(iStart)+zOut-bp)/1)))
		if rc != SQLITE_OK {
			break
		}
		zIn = zNext
	}

	return rc
}

func sqlite3Fts5TokenizerPattern(tls *libc.TLS, xCreate uintptr, pTok uintptr) int32 {
	if xCreate == *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
	}{fts5TriCreate})) {
		var p uintptr = pTok
		if (*TrigramTokenizer)(unsafe.Pointer(p)).FbFold != 0 {
			return FTS5_PATTERN_LIKE
		}
		return FTS5_PATTERN_GLOB
	}
	return FTS5_PATTERN_NONE
}

func sqlite3Fts5TokenizerInit(tls *libc.TLS, pApi uintptr) int32 {
	bp := tls.Alloc(128)
	defer tls.Free(128)

	*(*[4]BuiltinTokenizer)(unsafe.Pointer(bp)) = [4]BuiltinTokenizer{
		{FzName: ts + 44604, Fx: Fts5_tokenizer{FxCreate: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
		}{fts5UnicodeCreate})), FxDelete: *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{fts5UnicodeDelete})), FxTokenize: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32
		}{fts5UnicodeTokenize}))}},
		{FzName: ts + 44908, Fx: Fts5_tokenizer{FxCreate: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
		}{fts5AsciiCreate})), FxDelete: *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{fts5AsciiDelete})), FxTokenize: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32
		}{fts5AsciiTokenize}))}},
		{FzName: ts + 44914, Fx: Fts5_tokenizer{FxCreate: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
		}{fts5PorterCreate})), FxDelete: *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{fts5PorterDelete})), FxTokenize: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32
		}{fts5PorterTokenize}))}},
		{FzName: ts + 44921, Fx: Fts5_tokenizer{FxCreate: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32
		}{fts5TriCreate})), FxDelete: *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, uintptr) }{fts5TriDelete})), FxTokenize: *(*uintptr)(unsafe.Pointer(&struct {
			f func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr) int32
		}{fts5TriTokenize}))}},
	}

	var rc int32 = SQLITE_OK
	var i int32

	for i = 0; rc == SQLITE_OK && i < int32(uint64(unsafe.Sizeof([4]BuiltinTokenizer{}))/uint64(unsafe.Sizeof(BuiltinTokenizer{}))); i++ {
		rc = (*struct {
			f func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr) int32
		})(unsafe.Pointer(&struct{ uintptr }{(*Fts5_api)(unsafe.Pointer(pApi)).FxCreateTokenizer})).f(tls, pApi,
			(*BuiltinTokenizer)(unsafe.Pointer(bp+uintptr(i)*32)).FzName,
			pApi,
			bp+uintptr(i)*32+8,
			uintptr(0))
	}

	return rc
}

type BuiltinTokenizer = struct {
	FzName uintptr
	Fx     Fts5_tokenizer
}

func fts5_remove_diacritic(tls *libc.TLS, c int32, bComplex int32) int32 {
	bp := tls.Alloc(378)
	defer tls.Free(378)

	*(*[126]uint16)(unsafe.Pointer(bp)) = [126]uint16{
		uint16(0), uint16(1797), uint16(1848), uint16(1859), uint16(1891), uint16(1928), uint16(1940), uint16(1995),
		uint16(2024), uint16(2040), uint16(2060), uint16(2110), uint16(2168), uint16(2206), uint16(2264), uint16(2286),
		uint16(2344), uint16(2383), uint16(2472), uint16(2488), uint16(2516), uint16(2596), uint16(2668), uint16(2732),
		uint16(2782), uint16(2842), uint16(2894), uint16(2954), uint16(2984), uint16(3000), uint16(3028), uint16(3336),
		uint16(3456), uint16(3696), uint16(3712), uint16(3728), uint16(3744), uint16(3766), uint16(3832), uint16(3896),
		uint16(3912), uint16(3928), uint16(3944), uint16(3968), uint16(4008), uint16(4040), uint16(4056), uint16(4106),
		uint16(4138), uint16(4170), uint16(4202), uint16(4234), uint16(4266), uint16(4296), uint16(4312), uint16(4344),
		uint16(4408), uint16(4424), uint16(4442), uint16(4472), uint16(4488), uint16(4504), uint16(6148), uint16(6198),
		uint16(6264), uint16(6280), uint16(6360), uint16(6429), uint16(6505), uint16(6529), uint16(61448), uint16(61468),
		uint16(61512), uint16(61534), uint16(61592), uint16(61610), uint16(61642), uint16(61672), uint16(61688), uint16(61704),
		uint16(61726), uint16(61784), uint16(61800), uint16(61816), uint16(61836), uint16(61880), uint16(61896), uint16(61914),
		uint16(61948), uint16(61998), uint16(62062), uint16(62122), uint16(62154), uint16(62184), uint16(62200), uint16(62218),
		uint16(62252), uint16(62302), uint16(62364), uint16(62410), uint16(62442), uint16(62478), uint16(62536), uint16(62554),
		uint16(62584), uint16(62604), uint16(62640), uint16(62648), uint16(62656), uint16(62664), uint16(62730), uint16(62766),
		uint16(62830), uint16(62890), uint16(62924), uint16(62974), uint16(63032), uint16(63050), uint16(63082), uint16(63118),
		uint16(63182), uint16(63242), uint16(63274), uint16(63310), uint16(63368), uint16(63390),
	}
	*(*[126]uint8)(unsafe.Pointer(bp + 252)) = [126]uint8{
		uint8(0), uint8('a'), uint8('c'), uint8('e'), uint8('i'), uint8('n'),
		uint8('o'), uint8('u'), uint8('y'), uint8('y'), uint8('a'), uint8('c'),
		uint8('d'), uint8('e'), uint8('e'), uint8('g'), uint8('h'), uint8('i'),
		uint8('j'), uint8('k'), uint8('l'), uint8('n'), uint8('o'), uint8('r'),
		uint8('s'), uint8('t'), uint8('u'), uint8('u'), uint8('w'), uint8('y'),
		uint8('z'), uint8('o'), uint8('u'), uint8('a'), uint8('i'), uint8('o'),
		uint8('u'), uint8('u' | int32(uint8(0x80))), uint8('a' | int32(uint8(0x80))), uint8('g'), uint8('k'), uint8('o'),
		uint8('o' | int32(uint8(0x80))), uint8('j'), uint8('g'), uint8('n'), uint8('a' | int32(uint8(0x80))), uint8('a'),
		uint8('e'), uint8('i'), uint8('o'), uint8('r'), uint8('u'), uint8('s'),
		uint8('t'), uint8('h'), uint8('a'), uint8('e'), uint8('o' | int32(uint8(0x80))), uint8('o'),
		uint8('o' | int32(uint8(0x80))), uint8('y'), uint8(0), uint8(0), uint8(0), uint8(0),
		uint8(0), uint8(0), uint8(0), uint8(0), uint8('a'), uint8('b'),
		uint8('c' | int32(uint8(0x80))), uint8('d'), uint8('d'), uint8('e' | int32(uint8(0x80))), uint8('e'), uint8('e' | int32(uint8(0x80))),
		uint8('f'), uint8('g'), uint8('h'), uint8('h'), uint8('i'), uint8('i' | int32(uint8(0x80))),
		uint8('k'), uint8('l'), uint8('l' | int32(uint8(0x80))), uint8('l'), uint8('m'), uint8('n'),
		uint8('o' | int32(uint8(0x80))), uint8('p'), uint8('r'), uint8('r' | int32(uint8(0x80))), uint8('r'), uint8('s'),
		uint8('s' | int32(uint8(0x80))), uint8('t'), uint8('u'), uint8('u' | int32(uint8(0x80))), uint8('v'), uint8('w'),
		uint8('w'), uint8('x'), uint8('y'), uint8('z'), uint8('h'), uint8('t'),
		uint8('w'), uint8('y'), uint8('a'), uint8('a' | int32(uint8(0x80))), uint8('a' | int32(uint8(0x80))), uint8('a' | int32(uint8(0x80))),
		uint8('e'), uint8('e' | int32(uint8(0x80))), uint8('e' | int32(uint8(0x80))), uint8('i'), uint8('o'), uint8('o' | int32(uint8(0x80))),
		uint8('o' | int32(uint8(0x80))), uint8('o' | int32(uint8(0x80))), uint8('u'), uint8('u' | int32(uint8(0x80))), uint8('u' | int32(uint8(0x80))), uint8('y'),
	}

	var key uint32 = uint32(c)<<3 | uint32(0x00000007)
	var iRes int32 = 0
	var iHi int32 = int32(uint64(unsafe.Sizeof([126]uint16{}))/uint64(unsafe.Sizeof(uint16(0))) - uint64(1))
	var iLo int32 = 0
	for iHi >= iLo {
		var iTest int32 = (iHi + iLo) / 2
		if key >= uint32(*(*uint16)(unsafe.Pointer(bp + uintptr(iTest)*2))) {
			iRes = iTest
			iLo = iTest + 1
		} else {
			iHi = iTest - 1
		}
	}

	if bComplex == 0 && int32(*(*uint8)(unsafe.Pointer(bp + 252 + uintptr(iRes))))&0x80 != 0 {
		return c
	}
	if c > int32(*(*uint16)(unsafe.Pointer(bp + uintptr(iRes)*2)))>>3+int32(*(*uint16)(unsafe.Pointer(bp + uintptr(iRes)*2)))&0x07 {
		return c
	}
	return int32(*(*uint8)(unsafe.Pointer(bp + 252 + uintptr(iRes)))) & 0x7F
}

func sqlite3Fts5UnicodeIsdiacritic(tls *libc.TLS, c int32) int32 {
	var mask0 uint32 = uint32(0x08029FDF)
	var mask1 uint32 = uint32(0x000361F8)
	if c < 768 || c > 817 {
		return 0
	}
	if c < 768+32 {
		return int32(mask0 & (uint32(1) << (c - 768)))
	}
	return int32(mask1 & (uint32(1) << (c - 768 - 32)))
}

func sqlite3Fts5UnicodeFold(tls *libc.TLS, c int32, eRemoveDiacritic int32) int32 {
	var ret int32 = c

	if c < 128 {
		if c >= 'A' && c <= 'Z' {
			ret = c + ('a' - 'A')
		}
	} else if c < 65536 {
		var p uintptr
		var iHi int32 = int32(uint64(unsafe.Sizeof(aEntry))/uint64(unsafe.Sizeof(TableEntry{})) - uint64(1))
		var iLo int32 = 0
		var iRes int32 = -1

		for iHi >= iLo {
			var iTest int32 = (iHi + iLo) / 2
			var cmp int32 = c - int32(aEntry[iTest].FiCode)
			if cmp >= 0 {
				iRes = iTest
				iLo = iTest + 1
			} else {
				iHi = iTest - 1
			}
		}

		p = uintptr(unsafe.Pointer(&aEntry)) + uintptr(iRes)*4
		if c < int32((*TableEntry)(unsafe.Pointer(p)).FiCode)+int32((*TableEntry)(unsafe.Pointer(p)).FnRange) && 0 == 0x01&int32((*TableEntry)(unsafe.Pointer(p)).Fflags)&(int32((*TableEntry)(unsafe.Pointer(p)).FiCode)^c) {
			ret = (c + int32(aiOff[int32((*TableEntry)(unsafe.Pointer(p)).Fflags)>>1])) & 0x0000FFFF

		}

		if eRemoveDiacritic != 0 {
			ret = fts5_remove_diacritic(tls, ret, libc.Bool32(eRemoveDiacritic == 2))
		}
	} else if c >= 66560 && c < 66600 {
		ret = c + 40
	}

	return ret
}

type TableEntry = struct {
	FiCode  uint16
	Fflags  uint8
	FnRange uint8
}

var aEntry = [163]TableEntry{
	{FiCode: uint16(65), Fflags: uint8(14), FnRange: uint8(26)}, {FiCode: uint16(181), Fflags: uint8(64), FnRange: uint8(1)}, {FiCode: uint16(192), Fflags: uint8(14), FnRange: uint8(23)},
	{FiCode: uint16(216), Fflags: uint8(14), FnRange: uint8(7)}, {FiCode: uint16(256), Fflags: uint8(1), FnRange: uint8(48)}, {FiCode: uint16(306), Fflags: uint8(1), FnRange: uint8(6)},
	{FiCode: uint16(313), Fflags: uint8(1), FnRange: uint8(16)}, {FiCode: uint16(330), Fflags: uint8(1), FnRange: uint8(46)}, {FiCode: uint16(376), Fflags: uint8(116), FnRange: uint8(1)},
	{FiCode: uint16(377), Fflags: uint8(1), FnRange: uint8(6)}, {FiCode: uint16(383), Fflags: uint8(104), FnRange: uint8(1)}, {FiCode: uint16(385), Fflags: uint8(50), FnRange: uint8(1)},
	{FiCode: uint16(386), Fflags: uint8(1), FnRange: uint8(4)}, {FiCode: uint16(390), Fflags: uint8(44), FnRange: uint8(1)}, {FiCode: uint16(391), FnRange: uint8(1)},
	{FiCode: uint16(393), Fflags: uint8(42), FnRange: uint8(2)}, {FiCode: uint16(395), FnRange: uint8(1)}, {FiCode: uint16(398), Fflags: uint8(32), FnRange: uint8(1)},
	{FiCode: uint16(399), Fflags: uint8(38), FnRange: uint8(1)}, {FiCode: uint16(400), Fflags: uint8(40), FnRange: uint8(1)}, {FiCode: uint16(401), FnRange: uint8(1)},
	{FiCode: uint16(403), Fflags: uint8(42), FnRange: uint8(1)}, {FiCode: uint16(404), Fflags: uint8(46), FnRange: uint8(1)}, {FiCode: uint16(406), Fflags: uint8(52), FnRange: uint8(1)},
	{FiCode: uint16(407), Fflags: uint8(48), FnRange: uint8(1)}, {FiCode: uint16(408), FnRange: uint8(1)}, {FiCode: uint16(412), Fflags: uint8(52), FnRange: uint8(1)},
	{FiCode: uint16(413), Fflags: uint8(54), FnRange: uint8(1)}, {FiCode: uint16(415), Fflags: uint8(56), FnRange: uint8(1)}, {FiCode: uint16(416), Fflags: uint8(1), FnRange: uint8(6)},
	{FiCode: uint16(422), Fflags: uint8(60), FnRange: uint8(1)}, {FiCode: uint16(423), FnRange: uint8(1)}, {FiCode: uint16(425), Fflags: uint8(60), FnRange: uint8(1)},
	{FiCode: uint16(428), FnRange: uint8(1)}, {FiCode: uint16(430), Fflags: uint8(60), FnRange: uint8(1)}, {FiCode: uint16(431), FnRange: uint8(1)},
	{FiCode: uint16(433), Fflags: uint8(58), FnRange: uint8(2)}, {FiCode: uint16(435), Fflags: uint8(1), FnRange: uint8(4)}, {FiCode: uint16(439), Fflags: uint8(62), FnRange: uint8(1)},
	{FiCode: uint16(440), FnRange: uint8(1)}, {FiCode: uint16(444), FnRange: uint8(1)}, {FiCode: uint16(452), Fflags: uint8(2), FnRange: uint8(1)},
	{FiCode: uint16(453), FnRange: uint8(1)}, {FiCode: uint16(455), Fflags: uint8(2), FnRange: uint8(1)}, {FiCode: uint16(456), FnRange: uint8(1)},
	{FiCode: uint16(458), Fflags: uint8(2), FnRange: uint8(1)}, {FiCode: uint16(459), Fflags: uint8(1), FnRange: uint8(18)}, {FiCode: uint16(478), Fflags: uint8(1), FnRange: uint8(18)},
	{FiCode: uint16(497), Fflags: uint8(2), FnRange: uint8(1)}, {FiCode: uint16(498), Fflags: uint8(1), FnRange: uint8(4)}, {FiCode: uint16(502), Fflags: uint8(122), FnRange: uint8(1)},
	{FiCode: uint16(503), Fflags: uint8(134), FnRange: uint8(1)}, {FiCode: uint16(504), Fflags: uint8(1), FnRange: uint8(40)}, {FiCode: uint16(544), Fflags: uint8(110), FnRange: uint8(1)},
	{FiCode: uint16(546), Fflags: uint8(1), FnRange: uint8(18)}, {FiCode: uint16(570), Fflags: uint8(70), FnRange: uint8(1)}, {FiCode: uint16(571), FnRange: uint8(1)},
	{FiCode: uint16(573), Fflags: uint8(108), FnRange: uint8(1)}, {FiCode: uint16(574), Fflags: uint8(68), FnRange: uint8(1)}, {FiCode: uint16(577), FnRange: uint8(1)},
	{FiCode: uint16(579), Fflags: uint8(106), FnRange: uint8(1)}, {FiCode: uint16(580), Fflags: uint8(28), FnRange: uint8(1)}, {FiCode: uint16(581), Fflags: uint8(30), FnRange: uint8(1)},
	{FiCode: uint16(582), Fflags: uint8(1), FnRange: uint8(10)}, {FiCode: uint16(837), Fflags: uint8(36), FnRange: uint8(1)}, {FiCode: uint16(880), Fflags: uint8(1), FnRange: uint8(4)},
	{FiCode: uint16(886), FnRange: uint8(1)}, {FiCode: uint16(902), Fflags: uint8(18), FnRange: uint8(1)}, {FiCode: uint16(904), Fflags: uint8(16), FnRange: uint8(3)},
	{FiCode: uint16(908), Fflags: uint8(26), FnRange: uint8(1)}, {FiCode: uint16(910), Fflags: uint8(24), FnRange: uint8(2)}, {FiCode: uint16(913), Fflags: uint8(14), FnRange: uint8(17)},
	{FiCode: uint16(931), Fflags: uint8(14), FnRange: uint8(9)}, {FiCode: uint16(962), FnRange: uint8(1)}, {FiCode: uint16(975), Fflags: uint8(4), FnRange: uint8(1)},
	{FiCode: uint16(976), Fflags: uint8(140), FnRange: uint8(1)}, {FiCode: uint16(977), Fflags: uint8(142), FnRange: uint8(1)}, {FiCode: uint16(981), Fflags: uint8(146), FnRange: uint8(1)},
	{FiCode: uint16(982), Fflags: uint8(144), FnRange: uint8(1)}, {FiCode: uint16(984), Fflags: uint8(1), FnRange: uint8(24)}, {FiCode: uint16(1008), Fflags: uint8(136), FnRange: uint8(1)},
	{FiCode: uint16(1009), Fflags: uint8(138), FnRange: uint8(1)}, {FiCode: uint16(1012), Fflags: uint8(130), FnRange: uint8(1)}, {FiCode: uint16(1013), Fflags: uint8(128), FnRange: uint8(1)},
	{FiCode: uint16(1015), FnRange: uint8(1)}, {FiCode: uint16(1017), Fflags: uint8(152), FnRange: uint8(1)}, {FiCode: uint16(1018), FnRange: uint8(1)},
	{FiCode: uint16(1021), Fflags: uint8(110), FnRange: uint8(3)}, {FiCode: uint16(1024), Fflags: uint8(34), FnRange: uint8(16)}, {FiCode: uint16(1040), Fflags: uint8(14), FnRange: uint8(32)},
	{FiCode: uint16(1120), Fflags: uint8(1), FnRange: uint8(34)}, {FiCode: uint16(1162), Fflags: uint8(1), FnRange: uint8(54)}, {FiCode: uint16(1216), Fflags: uint8(6), FnRange: uint8(1)},
	{FiCode: uint16(1217), Fflags: uint8(1), FnRange: uint8(14)}, {FiCode: uint16(1232), Fflags: uint8(1), FnRange: uint8(88)}, {FiCode: uint16(1329), Fflags: uint8(22), FnRange: uint8(38)},
	{FiCode: uint16(4256), Fflags: uint8(66), FnRange: uint8(38)}, {FiCode: uint16(4295), Fflags: uint8(66), FnRange: uint8(1)}, {FiCode: uint16(4301), Fflags: uint8(66), FnRange: uint8(1)},
	{FiCode: uint16(7680), Fflags: uint8(1), FnRange: uint8(150)}, {FiCode: uint16(7835), Fflags: uint8(132), FnRange: uint8(1)}, {FiCode: uint16(7838), Fflags: uint8(96), FnRange: uint8(1)},
	{FiCode: uint16(7840), Fflags: uint8(1), FnRange: uint8(96)}, {FiCode: uint16(7944), Fflags: uint8(150), FnRange: uint8(8)}, {FiCode: uint16(7960), Fflags: uint8(150), FnRange: uint8(6)},
	{FiCode: uint16(7976), Fflags: uint8(150), FnRange: uint8(8)}, {FiCode: uint16(7992), Fflags: uint8(150), FnRange: uint8(8)}, {FiCode: uint16(8008), Fflags: uint8(150), FnRange: uint8(6)},
	{FiCode: uint16(8025), Fflags: uint8(151), FnRange: uint8(8)}, {FiCode: uint16(8040), Fflags: uint8(150), FnRange: uint8(8)}, {FiCode: uint16(8072), Fflags: uint8(150), FnRange: uint8(8)},
	{FiCode: uint16(8088), Fflags: uint8(150), FnRange: uint8(8)}, {FiCode: uint16(8104), Fflags: uint8(150), FnRange: uint8(8)}, {FiCode: uint16(8120), Fflags: uint8(150), FnRange: uint8(2)},
	{FiCode: uint16(8122), Fflags: uint8(126), FnRange: uint8(2)}, {FiCode: uint16(8124), Fflags: uint8(148), FnRange: uint8(1)}, {FiCode: uint16(8126), Fflags: uint8(100), FnRange: uint8(1)},
	{FiCode: uint16(8136), Fflags: uint8(124), FnRange: uint8(4)}, {FiCode: uint16(8140), Fflags: uint8(148), FnRange: uint8(1)}, {FiCode: uint16(8152), Fflags: uint8(150), FnRange: uint8(2)},
	{FiCode: uint16(8154), Fflags: uint8(120), FnRange: uint8(2)}, {FiCode: uint16(8168), Fflags: uint8(150), FnRange: uint8(2)}, {FiCode: uint16(8170), Fflags: uint8(118), FnRange: uint8(2)},
	{FiCode: uint16(8172), Fflags: uint8(152), FnRange: uint8(1)}, {FiCode: uint16(8184), Fflags: uint8(112), FnRange: uint8(2)}, {FiCode: uint16(8186), Fflags: uint8(114), FnRange: uint8(2)},
	{FiCode: uint16(8188), Fflags: uint8(148), FnRange: uint8(1)}, {FiCode: uint16(8486), Fflags: uint8(98), FnRange: uint8(1)}, {FiCode: uint16(8490), Fflags: uint8(92), FnRange: uint8(1)},
	{FiCode: uint16(8491), Fflags: uint8(94), FnRange: uint8(1)}, {FiCode: uint16(8498), Fflags: uint8(12), FnRange: uint8(1)}, {FiCode: uint16(8544), Fflags: uint8(8), FnRange: uint8(16)},
	{FiCode: uint16(8579), FnRange: uint8(1)}, {FiCode: uint16(9398), Fflags: uint8(10), FnRange: uint8(26)}, {FiCode: uint16(11264), Fflags: uint8(22), FnRange: uint8(47)},
	{FiCode: uint16(11360), FnRange: uint8(1)}, {FiCode: uint16(11362), Fflags: uint8(88), FnRange: uint8(1)}, {FiCode: uint16(11363), Fflags: uint8(102), FnRange: uint8(1)},
	{FiCode: uint16(11364), Fflags: uint8(90), FnRange: uint8(1)}, {FiCode: uint16(11367), Fflags: uint8(1), FnRange: uint8(6)}, {FiCode: uint16(11373), Fflags: uint8(84), FnRange: uint8(1)},
	{FiCode: uint16(11374), Fflags: uint8(86), FnRange: uint8(1)}, {FiCode: uint16(11375), Fflags: uint8(80), FnRange: uint8(1)}, {FiCode: uint16(11376), Fflags: uint8(82), FnRange: uint8(1)},
	{FiCode: uint16(11378), FnRange: uint8(1)}, {FiCode: uint16(11381), FnRange: uint8(1)}, {FiCode: uint16(11390), Fflags: uint8(78), FnRange: uint8(2)},
	{FiCode: uint16(11392), Fflags: uint8(1), FnRange: uint8(100)}, {FiCode: uint16(11499), Fflags: uint8(1), FnRange: uint8(4)}, {FiCode: uint16(11506), FnRange: uint8(1)},
	{FiCode: uint16(42560), Fflags: uint8(1), FnRange: uint8(46)}, {FiCode: uint16(42624), Fflags: uint8(1), FnRange: uint8(24)}, {FiCode: uint16(42786), Fflags: uint8(1), FnRange: uint8(14)},
	{FiCode: uint16(42802), Fflags: uint8(1), FnRange: uint8(62)}, {FiCode: uint16(42873), Fflags: uint8(1), FnRange: uint8(4)}, {FiCode: uint16(42877), Fflags: uint8(76), FnRange: uint8(1)},
	{FiCode: uint16(42878), Fflags: uint8(1), FnRange: uint8(10)}, {FiCode: uint16(42891), FnRange: uint8(1)}, {FiCode: uint16(42893), Fflags: uint8(74), FnRange: uint8(1)},
	{FiCode: uint16(42896), Fflags: uint8(1), FnRange: uint8(4)}, {FiCode: uint16(42912), Fflags: uint8(1), FnRange: uint8(10)}, {FiCode: uint16(42922), Fflags: uint8(72), FnRange: uint8(1)},
	{FiCode: uint16(65313), Fflags: uint8(14), FnRange: uint8(26)},
}
var aiOff = [77]uint16{
	uint16(1), uint16(2), uint16(8), uint16(15), uint16(16), uint16(26), uint16(28), uint16(32),
	uint16(37), uint16(38), uint16(40), uint16(48), uint16(63), uint16(64), uint16(69), uint16(71),
	uint16(79), uint16(80), uint16(116), uint16(202), uint16(203), uint16(205), uint16(206), uint16(207),
	uint16(209), uint16(210), uint16(211), uint16(213), uint16(214), uint16(217), uint16(218), uint16(219),
	uint16(775), uint16(7264), uint16(10792), uint16(10795), uint16(23228), uint16(23256), uint16(30204), uint16(54721),
	uint16(54753), uint16(54754), uint16(54756), uint16(54787), uint16(54793), uint16(54809), uint16(57153), uint16(57274),
	uint16(57921), uint16(58019), uint16(58363), uint16(61722), uint16(65268), uint16(65341), uint16(65373), uint16(65406),
	uint16(65408), uint16(65410), uint16(65415), uint16(65424), uint16(65436), uint16(65439), uint16(65450), uint16(65462),
	uint16(65472), uint16(65476), uint16(65478), uint16(65480), uint16(65482), uint16(65488), uint16(65506), uint16(65511),
	uint16(65514), uint16(65521), uint16(65527), uint16(65528), uint16(65529),
}

func sqlite3Fts5UnicodeCatParse(tls *libc.TLS, zCat uintptr, aArray uintptr) int32 {
	*(*U8)(unsafe.Pointer(aArray)) = U8(1)
	switch int32(*(*uint8)(unsafe.Pointer(zCat))) {
	case 'C':
		switch int32(*(*uint8)(unsafe.Pointer(zCat + 1))) {
		case 'c':
			*(*U8)(unsafe.Pointer(aArray + 1)) = U8(1)
			break
		case 'f':
			*(*U8)(unsafe.Pointer(aArray + 2)) = U8(1)
			break
		case 'n':
			*(*U8)(unsafe.Pointer(aArray + 3)) = U8(1)
			break
		case 's':
			*(*U8)(unsafe.Pointer(aArray + 4)) = U8(1)
			break
		case 'o':
			*(*U8)(unsafe.Pointer(aArray + 31)) = U8(1)
			break
		case '*':
			*(*U8)(unsafe.Pointer(aArray + 1)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 2)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 3)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 4)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 31)) = U8(1)
			break
		default:
			return 1
		}
		break

	case 'L':
		switch int32(*(*uint8)(unsafe.Pointer(zCat + 1))) {
		case 'l':
			*(*U8)(unsafe.Pointer(aArray + 5)) = U8(1)
			break
		case 'm':
			*(*U8)(unsafe.Pointer(aArray + 6)) = U8(1)
			break
		case 'o':
			*(*U8)(unsafe.Pointer(aArray + 7)) = U8(1)
			break
		case 't':
			*(*U8)(unsafe.Pointer(aArray + 8)) = U8(1)
			break
		case 'u':
			*(*U8)(unsafe.Pointer(aArray + 9)) = U8(1)
			break
		case 'C':
			*(*U8)(unsafe.Pointer(aArray + 30)) = U8(1)
			break
		case '*':
			*(*U8)(unsafe.Pointer(aArray + 5)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 6)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 7)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 8)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 9)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 30)) = U8(1)
			break
		default:
			return 1
		}
		break

	case 'M':
		switch int32(*(*uint8)(unsafe.Pointer(zCat + 1))) {
		case 'c':
			*(*U8)(unsafe.Pointer(aArray + 10)) = U8(1)
			break
		case 'e':
			*(*U8)(unsafe.Pointer(aArray + 11)) = U8(1)
			break
		case 'n':
			*(*U8)(unsafe.Pointer(aArray + 12)) = U8(1)
			break
		case '*':
			*(*U8)(unsafe.Pointer(aArray + 10)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 11)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 12)) = U8(1)
			break
		default:
			return 1
		}
		break

	case 'N':
		switch int32(*(*uint8)(unsafe.Pointer(zCat + 1))) {
		case 'd':
			*(*U8)(unsafe.Pointer(aArray + 13)) = U8(1)
			break
		case 'l':
			*(*U8)(unsafe.Pointer(aArray + 14)) = U8(1)
			break
		case 'o':
			*(*U8)(unsafe.Pointer(aArray + 15)) = U8(1)
			break
		case '*':
			*(*U8)(unsafe.Pointer(aArray + 13)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 14)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 15)) = U8(1)
			break
		default:
			return 1
		}
		break

	case 'P':
		switch int32(*(*uint8)(unsafe.Pointer(zCat + 1))) {
		case 'c':
			*(*U8)(unsafe.Pointer(aArray + 16)) = U8(1)
			break
		case 'd':
			*(*U8)(unsafe.Pointer(aArray + 17)) = U8(1)
			break
		case 'e':
			*(*U8)(unsafe.Pointer(aArray + 18)) = U8(1)
			break
		case 'f':
			*(*U8)(unsafe.Pointer(aArray + 19)) = U8(1)
			break
		case 'i':
			*(*U8)(unsafe.Pointer(aArray + 20)) = U8(1)
			break
		case 'o':
			*(*U8)(unsafe.Pointer(aArray + 21)) = U8(1)
			break
		case 's':
			*(*U8)(unsafe.Pointer(aArray + 22)) = U8(1)
			break
		case '*':
			*(*U8)(unsafe.Pointer(aArray + 16)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 17)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 18)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 19)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 20)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 21)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 22)) = U8(1)
			break
		default:
			return 1
		}
		break

	case 'S':
		switch int32(*(*uint8)(unsafe.Pointer(zCat + 1))) {
		case 'c':
			*(*U8)(unsafe.Pointer(aArray + 23)) = U8(1)
			break
		case 'k':
			*(*U8)(unsafe.Pointer(aArray + 24)) = U8(1)
			break
		case 'm':
			*(*U8)(unsafe.Pointer(aArray + 25)) = U8(1)
			break
		case 'o':
			*(*U8)(unsafe.Pointer(aArray + 26)) = U8(1)
			break
		case '*':
			*(*U8)(unsafe.Pointer(aArray + 23)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 24)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 25)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 26)) = U8(1)
			break
		default:
			return 1
		}
		break

	case 'Z':
		switch int32(*(*uint8)(unsafe.Pointer(zCat + 1))) {
		case 'l':
			*(*U8)(unsafe.Pointer(aArray + 27)) = U8(1)
			break
		case 'p':
			*(*U8)(unsafe.Pointer(aArray + 28)) = U8(1)
			break
		case 's':
			*(*U8)(unsafe.Pointer(aArray + 29)) = U8(1)
			break
		case '*':
			*(*U8)(unsafe.Pointer(aArray + 27)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 28)) = U8(1)
			*(*U8)(unsafe.Pointer(aArray + 29)) = U8(1)
			break
		default:
			return 1
		}
		break

	}
	return 0
}

var aFts5UnicodeBlock = [17]U16{
	U16(0), U16(1471), U16(1753), U16(1760), U16(1760), U16(1760), U16(1760), U16(1760), U16(1760), U16(1760),
	U16(1760), U16(1760), U16(1760), U16(1760), U16(1760), U16(1763), U16(1765),
}
var aFts5UnicodeMap = [1765]U16{
	U16(0), U16(32), U16(33), U16(36), U16(37), U16(40), U16(41), U16(42), U16(43), U16(44),
	U16(45), U16(46), U16(48), U16(58), U16(60), U16(63), U16(65), U16(91), U16(92), U16(93),
	U16(94), U16(95), U16(96), U16(97), U16(123), U16(124), U16(125), U16(126), U16(127), U16(160),
	U16(161), U16(162), U16(166), U16(167), U16(168), U16(169), U16(170), U16(171), U16(172), U16(173),
	U16(174), U16(175), U16(176), U16(177), U16(178), U16(180), U16(181), U16(182), U16(184), U16(185),
	U16(186), U16(187), U16(188), U16(191), U16(192), U16(215), U16(216), U16(223), U16(247), U16(248),
	U16(256), U16(312), U16(313), U16(329), U16(330), U16(377), U16(383), U16(385), U16(387), U16(388),
	U16(391), U16(394), U16(396), U16(398), U16(402), U16(403), U16(405), U16(406), U16(409), U16(412),
	U16(414), U16(415), U16(417), U16(418), U16(423), U16(427), U16(428), U16(431), U16(434), U16(436),
	U16(437), U16(440), U16(442), U16(443), U16(444), U16(446), U16(448), U16(452), U16(453), U16(454),
	U16(455), U16(456), U16(457), U16(458), U16(459), U16(460), U16(461), U16(477), U16(478), U16(496),
	U16(497), U16(498), U16(499), U16(500), U16(503), U16(505), U16(506), U16(564), U16(570), U16(572),
	U16(573), U16(575), U16(577), U16(580), U16(583), U16(584), U16(592), U16(660), U16(661), U16(688),
	U16(706), U16(710), U16(722), U16(736), U16(741), U16(748), U16(749), U16(750), U16(751), U16(768),
	U16(880), U16(884), U16(885), U16(886), U16(890), U16(891), U16(894), U16(900), U16(902), U16(903),
	U16(904), U16(908), U16(910), U16(912), U16(913), U16(931), U16(940), U16(975), U16(977), U16(978),
	U16(981), U16(984), U16(1008), U16(1012), U16(1014), U16(1015), U16(1018), U16(1020), U16(1021), U16(1072),
	U16(1120), U16(1154), U16(1155), U16(1160), U16(1162), U16(1217), U16(1231), U16(1232), U16(1329), U16(1369),
	U16(1370), U16(1377), U16(1417), U16(1418), U16(1423), U16(1425), U16(1470), U16(1471), U16(1472), U16(1473),
	U16(1475), U16(1476), U16(1478), U16(1479), U16(1488), U16(1520), U16(1523), U16(1536), U16(1542), U16(1545),
	U16(1547), U16(1548), U16(1550), U16(1552), U16(1563), U16(1566), U16(1568), U16(1600), U16(1601), U16(1611),
	U16(1632), U16(1642), U16(1646), U16(1648), U16(1649), U16(1748), U16(1749), U16(1750), U16(1757), U16(1758),
	U16(1759), U16(1765), U16(1767), U16(1769), U16(1770), U16(1774), U16(1776), U16(1786), U16(1789), U16(1791),
	U16(1792), U16(1807), U16(1808), U16(1809), U16(1810), U16(1840), U16(1869), U16(1958), U16(1969), U16(1984),
	U16(1994), U16(2027), U16(2036), U16(2038), U16(2039), U16(2042), U16(2048), U16(2070), U16(2074), U16(2075),
	U16(2084), U16(2085), U16(2088), U16(2089), U16(2096), U16(2112), U16(2137), U16(2142), U16(2208), U16(2210),
	U16(2276), U16(2304), U16(2307), U16(2308), U16(2362), U16(2363), U16(2364), U16(2365), U16(2366), U16(2369),
	U16(2377), U16(2381), U16(2382), U16(2384), U16(2385), U16(2392), U16(2402), U16(2404), U16(2406), U16(2416),
	U16(2417), U16(2418), U16(2425), U16(2433), U16(2434), U16(2437), U16(2447), U16(2451), U16(2474), U16(2482),
	U16(2486), U16(2492), U16(2493), U16(2494), U16(2497), U16(2503), U16(2507), U16(2509), U16(2510), U16(2519),
	U16(2524), U16(2527), U16(2530), U16(2534), U16(2544), U16(2546), U16(2548), U16(2554), U16(2555), U16(2561),
	U16(2563), U16(2565), U16(2575), U16(2579), U16(2602), U16(2610), U16(2613), U16(2616), U16(2620), U16(2622),
	U16(2625), U16(2631), U16(2635), U16(2641), U16(2649), U16(2654), U16(2662), U16(2672), U16(2674), U16(2677),
	U16(2689), U16(2691), U16(2693), U16(2703), U16(2707), U16(2730), U16(2738), U16(2741), U16(2748), U16(2749),
	U16(2750), U16(2753), U16(2759), U16(2761), U16(2763), U16(2765), U16(2768), U16(2784), U16(2786), U16(2790),
	U16(2800), U16(2801), U16(2817), U16(2818), U16(2821), U16(2831), U16(2835), U16(2858), U16(2866), U16(2869),
	U16(2876), U16(2877), U16(2878), U16(2879), U16(2880), U16(2881), U16(2887), U16(2891), U16(2893), U16(2902),
	U16(2903), U16(2908), U16(2911), U16(2914), U16(2918), U16(2928), U16(2929), U16(2930), U16(2946), U16(2947),
	U16(2949), U16(2958), U16(2962), U16(2969), U16(2972), U16(2974), U16(2979), U16(2984), U16(2990), U16(3006),
	U16(3008), U16(3009), U16(3014), U16(3018), U16(3021), U16(3024), U16(3031), U16(3046), U16(3056), U16(3059),
	U16(3065), U16(3066), U16(3073), U16(3077), U16(3086), U16(3090), U16(3114), U16(3125), U16(3133), U16(3134),
	U16(3137), U16(3142), U16(3146), U16(3157), U16(3160), U16(3168), U16(3170), U16(3174), U16(3192), U16(3199),
	U16(3202), U16(3205), U16(3214), U16(3218), U16(3242), U16(3253), U16(3260), U16(3261), U16(3262), U16(3263),
	U16(3264), U16(3270), U16(3271), U16(3274), U16(3276), U16(3285), U16(3294), U16(3296), U16(3298), U16(3302),
	U16(3313), U16(3330), U16(3333), U16(3342), U16(3346), U16(3389), U16(3390), U16(3393), U16(3398), U16(3402),
	U16(3405), U16(3406), U16(3415), U16(3424), U16(3426), U16(3430), U16(3440), U16(3449), U16(3450), U16(3458),
	U16(3461), U16(3482), U16(3507), U16(3517), U16(3520), U16(3530), U16(3535), U16(3538), U16(3542), U16(3544),
	U16(3570), U16(3572), U16(3585), U16(3633), U16(3634), U16(3636), U16(3647), U16(3648), U16(3654), U16(3655),
	U16(3663), U16(3664), U16(3674), U16(3713), U16(3716), U16(3719), U16(3722), U16(3725), U16(3732), U16(3737),
	U16(3745), U16(3749), U16(3751), U16(3754), U16(3757), U16(3761), U16(3762), U16(3764), U16(3771), U16(3773),
	U16(3776), U16(3782), U16(3784), U16(3792), U16(3804), U16(3840), U16(3841), U16(3844), U16(3859), U16(3860),
	U16(3861), U16(3864), U16(3866), U16(3872), U16(3882), U16(3892), U16(3893), U16(3894), U16(3895), U16(3896),
	U16(3897), U16(3898), U16(3899), U16(3900), U16(3901), U16(3902), U16(3904), U16(3913), U16(3953), U16(3967),
	U16(3968), U16(3973), U16(3974), U16(3976), U16(3981), U16(3993), U16(4030), U16(4038), U16(4039), U16(4046),
	U16(4048), U16(4053), U16(4057), U16(4096), U16(4139), U16(4141), U16(4145), U16(4146), U16(4152), U16(4153),
	U16(4155), U16(4157), U16(4159), U16(4160), U16(4170), U16(4176), U16(4182), U16(4184), U16(4186), U16(4190),
	U16(4193), U16(4194), U16(4197), U16(4199), U16(4206), U16(4209), U16(4213), U16(4226), U16(4227), U16(4229),
	U16(4231), U16(4237), U16(4238), U16(4239), U16(4240), U16(4250), U16(4253), U16(4254), U16(4256), U16(4295),
	U16(4301), U16(4304), U16(4347), U16(4348), U16(4349), U16(4682), U16(4688), U16(4696), U16(4698), U16(4704),
	U16(4746), U16(4752), U16(4786), U16(4792), U16(4800), U16(4802), U16(4808), U16(4824), U16(4882), U16(4888),
	U16(4957), U16(4960), U16(4969), U16(4992), U16(5008), U16(5024), U16(5120), U16(5121), U16(5741), U16(5743),
	U16(5760), U16(5761), U16(5787), U16(5788), U16(5792), U16(5867), U16(5870), U16(5888), U16(5902), U16(5906),
	U16(5920), U16(5938), U16(5941), U16(5952), U16(5970), U16(5984), U16(5998), U16(6002), U16(6016), U16(6068),
	U16(6070), U16(6071), U16(6078), U16(6086), U16(6087), U16(6089), U16(6100), U16(6103), U16(6104), U16(6107),
	U16(6108), U16(6109), U16(6112), U16(6128), U16(6144), U16(6150), U16(6151), U16(6155), U16(6158), U16(6160),
	U16(6176), U16(6211), U16(6212), U16(6272), U16(6313), U16(6314), U16(6320), U16(6400), U16(6432), U16(6435),
	U16(6439), U16(6441), U16(6448), U16(6450), U16(6451), U16(6457), U16(6464), U16(6468), U16(6470), U16(6480),
	U16(6512), U16(6528), U16(6576), U16(6593), U16(6600), U16(6608), U16(6618), U16(6622), U16(6656), U16(6679),
	U16(6681), U16(6686), U16(6688), U16(6741), U16(6742), U16(6743), U16(6744), U16(6752), U16(6753), U16(6754),
	U16(6755), U16(6757), U16(6765), U16(6771), U16(6783), U16(6784), U16(6800), U16(6816), U16(6823), U16(6824),
	U16(6912), U16(6916), U16(6917), U16(6964), U16(6965), U16(6966), U16(6971), U16(6972), U16(6973), U16(6978),
	U16(6979), U16(6981), U16(6992), U16(7002), U16(7009), U16(7019), U16(7028), U16(7040), U16(7042), U16(7043),
	U16(7073), U16(7074), U16(7078), U16(7080), U16(7082), U16(7083), U16(7084), U16(7086), U16(7088), U16(7098),
	U16(7142), U16(7143), U16(7144), U16(7146), U16(7149), U16(7150), U16(7151), U16(7154), U16(7164), U16(7168),
	U16(7204), U16(7212), U16(7220), U16(7222), U16(7227), U16(7232), U16(7245), U16(7248), U16(7258), U16(7288),
	U16(7294), U16(7360), U16(7376), U16(7379), U16(7380), U16(7393), U16(7394), U16(7401), U16(7405), U16(7406),
	U16(7410), U16(7412), U16(7413), U16(7424), U16(7468), U16(7531), U16(7544), U16(7545), U16(7579), U16(7616),
	U16(7676), U16(7680), U16(7830), U16(7838), U16(7936), U16(7944), U16(7952), U16(7960), U16(7968), U16(7976),
	U16(7984), U16(7992), U16(8000), U16(8008), U16(8016), U16(8025), U16(8027), U16(8029), U16(8031), U16(8033),
	U16(8040), U16(8048), U16(8064), U16(8072), U16(8080), U16(8088), U16(8096), U16(8104), U16(8112), U16(8118),
	U16(8120), U16(8124), U16(8125), U16(8126), U16(8127), U16(8130), U16(8134), U16(8136), U16(8140), U16(8141),
	U16(8144), U16(8150), U16(8152), U16(8157), U16(8160), U16(8168), U16(8173), U16(8178), U16(8182), U16(8184),
	U16(8188), U16(8189), U16(8192), U16(8203), U16(8208), U16(8214), U16(8216), U16(8217), U16(8218), U16(8219),
	U16(8221), U16(8222), U16(8223), U16(8224), U16(8232), U16(8233), U16(8234), U16(8239), U16(8240), U16(8249),
	U16(8250), U16(8251), U16(8255), U16(8257), U16(8260), U16(8261), U16(8262), U16(8263), U16(8274), U16(8275),
	U16(8276), U16(8277), U16(8287), U16(8288), U16(8298), U16(8304), U16(8305), U16(8308), U16(8314), U16(8317),
	U16(8318), U16(8319), U16(8320), U16(8330), U16(8333), U16(8334), U16(8336), U16(8352), U16(8400), U16(8413),
	U16(8417), U16(8418), U16(8421), U16(8448), U16(8450), U16(8451), U16(8455), U16(8456), U16(8458), U16(8459),
	U16(8462), U16(8464), U16(8467), U16(8468), U16(8469), U16(8470), U16(8472), U16(8473), U16(8478), U16(8484),
	U16(8485), U16(8486), U16(8487), U16(8488), U16(8489), U16(8490), U16(8494), U16(8495), U16(8496), U16(8500),
	U16(8501), U16(8505), U16(8506), U16(8508), U16(8510), U16(8512), U16(8517), U16(8519), U16(8522), U16(8523),
	U16(8524), U16(8526), U16(8527), U16(8528), U16(8544), U16(8579), U16(8581), U16(8585), U16(8592), U16(8597),
	U16(8602), U16(8604), U16(8608), U16(8609), U16(8611), U16(8612), U16(8614), U16(8615), U16(8622), U16(8623),
	U16(8654), U16(8656), U16(8658), U16(8659), U16(8660), U16(8661), U16(8692), U16(8960), U16(8968), U16(8972),
	U16(8992), U16(8994), U16(9001), U16(9002), U16(9003), U16(9084), U16(9085), U16(9115), U16(9140), U16(9180),
	U16(9186), U16(9216), U16(9280), U16(9312), U16(9372), U16(9450), U16(9472), U16(9655), U16(9656), U16(9665),
	U16(9666), U16(9720), U16(9728), U16(9839), U16(9840), U16(9985), U16(10088), U16(10089), U16(10090), U16(10091),
	U16(10092), U16(10093), U16(10094), U16(10095), U16(10096), U16(10097), U16(10098), U16(10099), U16(10100), U16(10101),
	U16(10102), U16(10132), U16(10176), U16(10181), U16(10182), U16(10183), U16(10214), U16(10215), U16(10216), U16(10217),
	U16(10218), U16(10219), U16(10220), U16(10221), U16(10222), U16(10223), U16(10224), U16(10240), U16(10496), U16(10627),
	U16(10628), U16(10629), U16(10630), U16(10631), U16(10632), U16(10633), U16(10634), U16(10635), U16(10636), U16(10637),
	U16(10638), U16(10639), U16(10640), U16(10641), U16(10642), U16(10643), U16(10644), U16(10645), U16(10646), U16(10647),
	U16(10648), U16(10649), U16(10712), U16(10713), U16(10714), U16(10715), U16(10716), U16(10748), U16(10749), U16(10750),
	U16(11008), U16(11056), U16(11077), U16(11079), U16(11088), U16(11264), U16(11312), U16(11360), U16(11363), U16(11365),
	U16(11367), U16(11374), U16(11377), U16(11378), U16(11380), U16(11381), U16(11383), U16(11388), U16(11390), U16(11393),
	U16(11394), U16(11492), U16(11493), U16(11499), U16(11503), U16(11506), U16(11513), U16(11517), U16(11518), U16(11520),
	U16(11559), U16(11565), U16(11568), U16(11631), U16(11632), U16(11647), U16(11648), U16(11680), U16(11688), U16(11696),
	U16(11704), U16(11712), U16(11720), U16(11728), U16(11736), U16(11744), U16(11776), U16(11778), U16(11779), U16(11780),
	U16(11781), U16(11782), U16(11785), U16(11786), U16(11787), U16(11788), U16(11789), U16(11790), U16(11799), U16(11800),
	U16(11802), U16(11803), U16(11804), U16(11805), U16(11806), U16(11808), U16(11809), U16(11810), U16(11811), U16(11812),
	U16(11813), U16(11814), U16(11815), U16(11816), U16(11817), U16(11818), U16(11823), U16(11824), U16(11834), U16(11904),
	U16(11931), U16(12032), U16(12272), U16(12288), U16(12289), U16(12292), U16(12293), U16(12294), U16(12295), U16(12296),
	U16(12297), U16(12298), U16(12299), U16(12300), U16(12301), U16(12302), U16(12303), U16(12304), U16(12305), U16(12306),
	U16(12308), U16(12309), U16(12310), U16(12311), U16(12312), U16(12313), U16(12314), U16(12315), U16(12316), U16(12317),
	U16(12318), U16(12320), U16(12321), U16(12330), U16(12334), U16(12336), U16(12337), U16(12342), U16(12344), U16(12347),
	U16(12348), U16(12349), U16(12350), U16(12353), U16(12441), U16(12443), U16(12445), U16(12447), U16(12448), U16(12449),
	U16(12539), U16(12540), U16(12543), U16(12549), U16(12593), U16(12688), U16(12690), U16(12694), U16(12704), U16(12736),
	U16(12784), U16(12800), U16(12832), U16(12842), U16(12872), U16(12880), U16(12881), U16(12896), U16(12928), U16(12938),
	U16(12977), U16(12992), U16(13056), U16(13312), U16(19893), U16(19904), U16(19968), U16(40908), U16(40960), U16(40981),
	U16(40982), U16(42128), U16(42192), U16(42232), U16(42238), U16(42240), U16(42508), U16(42509), U16(42512), U16(42528),
	U16(42538), U16(42560), U16(42606), U16(42607), U16(42608), U16(42611), U16(42612), U16(42622), U16(42623), U16(42624),
	U16(42655), U16(42656), U16(42726), U16(42736), U16(42738), U16(42752), U16(42775), U16(42784), U16(42786), U16(42800),
	U16(42802), U16(42864), U16(42865), U16(42873), U16(42878), U16(42888), U16(42889), U16(42891), U16(42896), U16(42912),
	U16(43000), U16(43002), U16(43003), U16(43010), U16(43011), U16(43014), U16(43015), U16(43019), U16(43020), U16(43043),
	U16(43045), U16(43047), U16(43048), U16(43056), U16(43062), U16(43064), U16(43065), U16(43072), U16(43124), U16(43136),
	U16(43138), U16(43188), U16(43204), U16(43214), U16(43216), U16(43232), U16(43250), U16(43256), U16(43259), U16(43264),
	U16(43274), U16(43302), U16(43310), U16(43312), U16(43335), U16(43346), U16(43359), U16(43360), U16(43392), U16(43395),
	U16(43396), U16(43443), U16(43444), U16(43446), U16(43450), U16(43452), U16(43453), U16(43457), U16(43471), U16(43472),
	U16(43486), U16(43520), U16(43561), U16(43567), U16(43569), U16(43571), U16(43573), U16(43584), U16(43587), U16(43588),
	U16(43596), U16(43597), U16(43600), U16(43612), U16(43616), U16(43632), U16(43633), U16(43639), U16(43642), U16(43643),
	U16(43648), U16(43696), U16(43697), U16(43698), U16(43701), U16(43703), U16(43705), U16(43710), U16(43712), U16(43713),
	U16(43714), U16(43739), U16(43741), U16(43742), U16(43744), U16(43755), U16(43756), U16(43758), U16(43760), U16(43762),
	U16(43763), U16(43765), U16(43766), U16(43777), U16(43785), U16(43793), U16(43808), U16(43816), U16(43968), U16(44003),
	U16(44005), U16(44006), U16(44008), U16(44009), U16(44011), U16(44012), U16(44013), U16(44016), U16(44032), U16(55203),
	U16(55216), U16(55243), U16(55296), U16(56191), U16(56319), U16(57343), U16(57344), U16(63743), U16(63744), U16(64112),
	U16(64256), U16(64275), U16(64285), U16(64286), U16(64287), U16(64297), U16(64298), U16(64312), U16(64318), U16(64320),
	U16(64323), U16(64326), U16(64434), U16(64467), U16(64830), U16(64831), U16(64848), U16(64914), U16(65008), U16(65020),
	U16(65021), U16(65024), U16(65040), U16(65047), U16(65048), U16(65049), U16(65056), U16(65072), U16(65073), U16(65075),
	U16(65077), U16(65078), U16(65079), U16(65080), U16(65081), U16(65082), U16(65083), U16(65084), U16(65085), U16(65086),
	U16(65087), U16(65088), U16(65089), U16(65090), U16(65091), U16(65092), U16(65093), U16(65095), U16(65096), U16(65097),
	U16(65101), U16(65104), U16(65108), U16(65112), U16(65113), U16(65114), U16(65115), U16(65116), U16(65117), U16(65118),
	U16(65119), U16(65122), U16(65123), U16(65124), U16(65128), U16(65129), U16(65130), U16(65136), U16(65142), U16(65279),
	U16(65281), U16(65284), U16(65285), U16(65288), U16(65289), U16(65290), U16(65291), U16(65292), U16(65293), U16(65294),
	U16(65296), U16(65306), U16(65308), U16(65311), U16(65313), U16(65339), U16(65340), U16(65341), U16(65342), U16(65343),
	U16(65344), U16(65345), U16(65371), U16(65372), U16(65373), U16(65374), U16(65375), U16(65376), U16(65377), U16(65378),
	U16(65379), U16(65380), U16(65382), U16(65392), U16(65393), U16(65438), U16(65440), U16(65474), U16(65482), U16(65490),
	U16(65498), U16(65504), U16(65506), U16(65507), U16(65508), U16(65509), U16(65512), U16(65513), U16(65517), U16(65529),
	U16(65532), U16(0), U16(13), U16(40), U16(60), U16(63), U16(80), U16(128), U16(256), U16(263),
	U16(311), U16(320), U16(373), U16(377), U16(394), U16(400), U16(464), U16(509), U16(640), U16(672),
	U16(768), U16(800), U16(816), U16(833), U16(834), U16(842), U16(896), U16(927), U16(928), U16(968),
	U16(976), U16(977), U16(1024), U16(1064), U16(1104), U16(1184), U16(2048), U16(2056), U16(2058), U16(2103),
	U16(2108), U16(2111), U16(2135), U16(2136), U16(2304), U16(2326), U16(2335), U16(2336), U16(2367), U16(2432),
	U16(2494), U16(2560), U16(2561), U16(2565), U16(2572), U16(2576), U16(2581), U16(2585), U16(2616), U16(2623),
	U16(2624), U16(2640), U16(2656), U16(2685), U16(2687), U16(2816), U16(2873), U16(2880), U16(2904), U16(2912),
	U16(2936), U16(3072), U16(3680), U16(4096), U16(4097), U16(4098), U16(4099), U16(4152), U16(4167), U16(4178),
	U16(4198), U16(4224), U16(4226), U16(4227), U16(4272), U16(4275), U16(4279), U16(4281), U16(4283), U16(4285),
	U16(4286), U16(4304), U16(4336), U16(4352), U16(4355), U16(4391), U16(4396), U16(4397), U16(4406), U16(4416),
	U16(4480), U16(4482), U16(4483), U16(4531), U16(4534), U16(4543), U16(4545), U16(4549), U16(4560), U16(5760),
	U16(5803), U16(5804), U16(5805), U16(5806), U16(5808), U16(5814), U16(5815), U16(5824), U16(8192), U16(9216),
	U16(9328), U16(12288), U16(26624), U16(28416), U16(28496), U16(28497), U16(28559), U16(28563), U16(45056), U16(53248),
	U16(53504), U16(53545), U16(53605), U16(53607), U16(53610), U16(53613), U16(53619), U16(53627), U16(53635), U16(53637),
	U16(53644), U16(53674), U16(53678), U16(53760), U16(53826), U16(53829), U16(54016), U16(54112), U16(54272), U16(54298),
	U16(54324), U16(54350), U16(54358), U16(54376), U16(54402), U16(54428), U16(54430), U16(54434), U16(54437), U16(54441),
	U16(54446), U16(54454), U16(54459), U16(54461), U16(54469), U16(54480), U16(54506), U16(54532), U16(54535), U16(54541),
	U16(54550), U16(54558), U16(54584), U16(54587), U16(54592), U16(54598), U16(54602), U16(54610), U16(54636), U16(54662),
	U16(54688), U16(54714), U16(54740), U16(54766), U16(54792), U16(54818), U16(54844), U16(54870), U16(54896), U16(54922),
	U16(54952), U16(54977), U16(54978), U16(55003), U16(55004), U16(55010), U16(55035), U16(55036), U16(55061), U16(55062),
	U16(55068), U16(55093), U16(55094), U16(55119), U16(55120), U16(55126), U16(55151), U16(55152), U16(55177), U16(55178),
	U16(55184), U16(55209), U16(55210), U16(55235), U16(55236), U16(55242), U16(55246), U16(60928), U16(60933), U16(60961),
	U16(60964), U16(60967), U16(60969), U16(60980), U16(60985), U16(60987), U16(60994), U16(60999), U16(61001), U16(61003),
	U16(61005), U16(61009), U16(61012), U16(61015), U16(61017), U16(61019), U16(61021), U16(61023), U16(61025), U16(61028),
	U16(61031), U16(61036), U16(61044), U16(61049), U16(61054), U16(61056), U16(61067), U16(61089), U16(61093), U16(61099),
	U16(61168), U16(61440), U16(61488), U16(61600), U16(61617), U16(61633), U16(61649), U16(61696), U16(61712), U16(61744),
	U16(61808), U16(61926), U16(61968), U16(62016), U16(62032), U16(62208), U16(62256), U16(62263), U16(62336), U16(62368),
	U16(62406), U16(62432), U16(62464), U16(62528), U16(62530), U16(62713), U16(62720), U16(62784), U16(62800), U16(62971),
	U16(63045), U16(63104), U16(63232), U16(0), U16(42710), U16(42752), U16(46900), U16(46912), U16(47133), U16(63488),
	U16(1), U16(32), U16(256), U16(0), U16(65533),
}
var aFts5UnicodeData = [1765]U16{
	U16(1025), U16(61), U16(117), U16(55), U16(117), U16(54), U16(50), U16(53), U16(57), U16(53),
	U16(49), U16(85), U16(333), U16(85), U16(121), U16(85), U16(841), U16(54), U16(53), U16(50),
	U16(56), U16(48), U16(56), U16(837), U16(54), U16(57), U16(50), U16(57), U16(1057), U16(61),
	U16(53), U16(151), U16(58), U16(53), U16(56), U16(58), U16(39), U16(52), U16(57), U16(34),
	U16(58), U16(56), U16(58), U16(57), U16(79), U16(56), U16(37), U16(85), U16(56), U16(47),
	U16(39), U16(51), U16(111), U16(53), U16(745), U16(57), U16(233), U16(773), U16(57), U16(261),
	U16(1822), U16(37), U16(542), U16(37), U16(1534), U16(222), U16(69), U16(73), U16(37), U16(126),
	U16(126), U16(73), U16(69), U16(137), U16(37), U16(73), U16(37), U16(105), U16(101), U16(73),
	U16(37), U16(73), U16(37), U16(190), U16(158), U16(37), U16(126), U16(126), U16(73), U16(37),
	U16(126), U16(94), U16(37), U16(39), U16(94), U16(69), U16(135), U16(41), U16(40), U16(37),
	U16(41), U16(40), U16(37), U16(41), U16(40), U16(37), U16(542), U16(37), U16(606), U16(37),
	U16(41), U16(40), U16(37), U16(126), U16(73), U16(37), U16(1886), U16(197), U16(73), U16(37),
	U16(73), U16(69), U16(126), U16(105), U16(37), U16(286), U16(2181), U16(39), U16(869), U16(582),
	U16(152), U16(390), U16(472), U16(166), U16(248), U16(38), U16(56), U16(38), U16(568), U16(3596),
	U16(158), U16(38), U16(56), U16(94), U16(38), U16(101), U16(53), U16(88), U16(41), U16(53),
	U16(105), U16(41), U16(73), U16(37), U16(553), U16(297), U16(1125), U16(94), U16(37), U16(105),
	U16(101), U16(798), U16(133), U16(94), U16(57), U16(126), U16(94), U16(37), U16(1641), U16(1541),
	U16(1118), U16(58), U16(172), U16(75), U16(1790), U16(478), U16(37), U16(2846), U16(1225), U16(38),
	U16(213), U16(1253), U16(53), U16(49), U16(55), U16(1452), U16(49), U16(44), U16(53), U16(76),
	U16(53), U16(76), U16(53), U16(44), U16(871), U16(103), U16(85), U16(162), U16(121), U16(85),
	U16(55), U16(85), U16(90), U16(364), U16(53), U16(85), U16(1031), U16(38), U16(327), U16(684),
	U16(333), U16(149), U16(71), U16(44), U16(3175), U16(53), U16(39), U16(236), U16(34), U16(58),
	U16(204), U16(70), U16(76), U16(58), U16(140), U16(71), U16(333), U16(103), U16(90), U16(39),
	U16(469), U16(34), U16(39), U16(44), U16(967), U16(876), U16(2855), U16(364), U16(39), U16(333),
	U16(1063), U16(300), U16(70), U16(58), U16(117), U16(38), U16(711), U16(140), U16(38), U16(300),
	U16(38), U16(108), U16(38), U16(172), U16(501), U16(807), U16(108), U16(53), U16(39), U16(359),
	U16(876), U16(108), U16(42), U16(1735), U16(44), U16(42), U16(44), U16(39), U16(106), U16(268),
	U16(138), U16(44), U16(74), U16(39), U16(236), U16(327), U16(76), U16(85), U16(333), U16(53),
	U16(38), U16(199), U16(231), U16(44), U16(74), U16(263), U16(71), U16(711), U16(231), U16(39),
	U16(135), U16(44), U16(39), U16(106), U16(140), U16(74), U16(74), U16(44), U16(39), U16(42),
	U16(71), U16(103), U16(76), U16(333), U16(71), U16(87), U16(207), U16(58), U16(55), U16(76),
	U16(42), U16(199), U16(71), U16(711), U16(231), U16(71), U16(71), U16(71), U16(44), U16(106),
	U16(76), U16(76), U16(108), U16(44), U16(135), U16(39), U16(333), U16(76), U16(103), U16(44),
	U16(76), U16(42), U16(295), U16(103), U16(711), U16(231), U16(71), U16(167), U16(44), U16(39),
	U16(106), U16(172), U16(76), U16(42), U16(74), U16(44), U16(39), U16(71), U16(76), U16(333),
	U16(53), U16(55), U16(44), U16(74), U16(263), U16(71), U16(711), U16(231), U16(71), U16(167),
	U16(44), U16(39), U16(42), U16(44), U16(42), U16(140), U16(74), U16(74), U16(44), U16(44),
	U16(42), U16(71), U16(103), U16(76), U16(333), U16(58), U16(39), U16(207), U16(44), U16(39),
	U16(199), U16(103), U16(135), U16(71), U16(39), U16(71), U16(71), U16(103), U16(391), U16(74),
	U16(44), U16(74), U16(106), U16(106), U16(44), U16(39), U16(42), U16(333), U16(111), U16(218),
	U16(55), U16(58), U16(106), U16(263), U16(103), U16(743), U16(327), U16(167), U16(39), U16(108),
	U16(138), U16(108), U16(140), U16(76), U16(71), U16(71), U16(76), U16(333), U16(239), U16(58),
	U16(74), U16(263), U16(103), U16(743), U16(327), U16(167), U16(44), U16(39), U16(42), U16(44),
	U16(170), U16(44), U16(74), U16(74), U16(76), U16(74), U16(39), U16(71), U16(76), U16(333),
	U16(71), U16(74), U16(263), U16(103), U16(1319), U16(39), U16(106), U16(140), U16(106), U16(106),
	U16(44), U16(39), U16(42), U16(71), U16(76), U16(333), U16(207), U16(58), U16(199), U16(74),
	U16(583), U16(775), U16(295), U16(39), U16(231), U16(44), U16(106), U16(108), U16(44), U16(266),
	U16(74), U16(53), U16(1543), U16(44), U16(71), U16(236), U16(55), U16(199), U16(38), U16(268),
	U16(53), U16(333), U16(85), U16(71), U16(39), U16(71), U16(39), U16(39), U16(135), U16(231),
	U16(103), U16(39), U16(39), U16(71), U16(135), U16(44), U16(71), U16(204), U16(76), U16(39),
	U16(167), U16(38), U16(204), U16(333), U16(135), U16(39), U16(122), U16(501), U16(58), U16(53),
	U16(122), U16(76), U16(218), U16(333), U16(335), U16(58), U16(44), U16(58), U16(44), U16(58),
	U16(44), U16(54), U16(50), U16(54), U16(50), U16(74), U16(263), U16(1159), U16(460), U16(42),
	U16(172), U16(53), U16(76), U16(167), U16(364), U16(1164), U16(282), U16(44), U16(218), U16(90),
	U16(181), U16(154), U16(85), U16(1383), U16(74), U16(140), U16(42), U16(204), U16(42), U16(76),
	U16(74), U16(76), U16(39), U16(333), U16(213), U16(199), U16(74), U16(76), U16(135), U16(108),
	U16(39), U16(106), U16(71), U16(234), U16(103), U16(140), U16(423), U16(44), U16(74), U16(76),
	U16(202), U16(44), U16(39), U16(42), U16(333), U16(106), U16(44), U16(90), U16(1225), U16(41),
	U16(41), U16(1383), U16(53), U16(38), U16(10631), U16(135), U16(231), U16(39), U16(135), U16(1319),
	U16(135), U16(1063), U16(135), U16(231), U16(39), U16(135), U16(487), U16(1831), U16(135), U16(2151),
	U16(108), U16(309), U16(655), U16(519), U16(346), U16(2727), U16(49), U16(19847), U16(85), U16(551),
	U16(61), U16(839), U16(54), U16(50), U16(2407), U16(117), U16(110), U16(423), U16(135), U16(108),
	U16(583), U16(108), U16(85), U16(583), U16(76), U16(423), U16(103), U16(76), U16(1671), U16(76),
	U16(42), U16(236), U16(266), U16(44), U16(74), U16(364), U16(117), U16(38), U16(117), U16(55),
	U16(39), U16(44), U16(333), U16(335), U16(213), U16(49), U16(149), U16(108), U16(61), U16(333),
	U16(1127), U16(38), U16(1671), U16(1319), U16(44), U16(39), U16(2247), U16(935), U16(108), U16(138),
	U16(76), U16(106), U16(74), U16(44), U16(202), U16(108), U16(58), U16(85), U16(333), U16(967),
	U16(167), U16(1415), U16(554), U16(231), U16(74), U16(333), U16(47), U16(1114), U16(743), U16(76),
	U16(106), U16(85), U16(1703), U16(42), U16(44), U16(42), U16(236), U16(44), U16(42), U16(44),
	U16(74), U16(268), U16(202), U16(332), U16(44), U16(333), U16(333), U16(245), U16(38), U16(213),
	U16(140), U16(42), U16(1511), U16(44), U16(42), U16(172), U16(42), U16(44), U16(170), U16(44),
	U16(74), U16(231), U16(333), U16(245), U16(346), U16(300), U16(314), U16(76), U16(42), U16(967),
	U16(42), U16(140), U16(74), U16(76), U16(42), U16(44), U16(74), U16(71), U16(333), U16(1415),
	U16(44), U16(42), U16(76), U16(106), U16(44), U16(42), U16(108), U16(74), U16(149), U16(1159),
	U16(266), U16(268), U16(74), U16(76), U16(181), U16(333), U16(103), U16(333), U16(967), U16(198),
	U16(85), U16(277), U16(108), U16(53), U16(428), U16(42), U16(236), U16(135), U16(44), U16(135),
	U16(74), U16(44), U16(71), U16(1413), U16(2022), U16(421), U16(38), U16(1093), U16(1190), U16(1260),
	U16(140), U16(4830), U16(261), U16(3166), U16(261), U16(265), U16(197), U16(201), U16(261), U16(265),
	U16(261), U16(265), U16(197), U16(201), U16(261), U16(41), U16(41), U16(41), U16(94), U16(229),
	U16(265), U16(453), U16(261), U16(264), U16(261), U16(264), U16(261), U16(264), U16(165), U16(69),
	U16(137), U16(40), U16(56), U16(37), U16(120), U16(101), U16(69), U16(137), U16(40), U16(120),
	U16(133), U16(69), U16(137), U16(120), U16(261), U16(169), U16(120), U16(101), U16(69), U16(137),
	U16(40), U16(88), U16(381), U16(162), U16(209), U16(85), U16(52), U16(51), U16(54), U16(84),
	U16(51), U16(54), U16(52), U16(277), U16(59), U16(60), U16(162), U16(61), U16(309), U16(52),
	U16(51), U16(149), U16(80), U16(117), U16(57), U16(54), U16(50), U16(373), U16(57), U16(53),
	U16(48), U16(341), U16(61), U16(162), U16(194), U16(47), U16(38), U16(207), U16(121), U16(54),
	U16(50), U16(38), U16(335), U16(121), U16(54), U16(50), U16(422), U16(855), U16(428), U16(139),
	U16(44), U16(107), U16(396), U16(90), U16(41), U16(154), U16(41), U16(90), U16(37), U16(105),
	U16(69), U16(105), U16(37), U16(58), U16(41), U16(90), U16(57), U16(169), U16(218), U16(41),
	U16(58), U16(41), U16(58), U16(41), U16(58), U16(137), U16(58), U16(37), U16(137), U16(37),
	U16(135), U16(37), U16(90), U16(69), U16(73), U16(185), U16(94), U16(101), U16(58), U16(57),
	U16(90), U16(37), U16(58), U16(527), U16(1134), U16(94), U16(142), U16(47), U16(185), U16(186),
	U16(89), U16(154), U16(57), U16(90), U16(57), U16(90), U16(57), U16(250), U16(57), U16(1018),
	U16(89), U16(90), U16(57), U16(58), U16(57), U16(1018), U16(8601), U16(282), U16(153), U16(666),
	U16(89), U16(250), U16(54), U16(50), U16(2618), U16(57), U16(986), U16(825), U16(1306), U16(217),
	U16(602), U16(1274), U16(378), U16(1935), U16(2522), U16(719), U16(5882), U16(57), U16(314), U16(57),
	U16(1754), U16(281), U16(3578), U16(57), U16(4634), U16(3322), U16(54), U16(50), U16(54), U16(50),
	U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50),
	U16(975), U16(1434), U16(185), U16(54), U16(50), U16(1017), U16(54), U16(50), U16(54), U16(50),
	U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(537), U16(8218), U16(4217), U16(54),
	U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54),
	U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54),
	U16(50), U16(2041), U16(54), U16(50), U16(54), U16(50), U16(1049), U16(54), U16(50), U16(8281),
	U16(1562), U16(697), U16(90), U16(217), U16(346), U16(1513), U16(1509), U16(126), U16(73), U16(69),
	U16(254), U16(105), U16(37), U16(94), U16(37), U16(94), U16(165), U16(70), U16(105), U16(37),
	U16(3166), U16(37), U16(218), U16(158), U16(108), U16(94), U16(149), U16(47), U16(85), U16(1221),
	U16(37), U16(37), U16(1799), U16(38), U16(53), U16(44), U16(743), U16(231), U16(231), U16(231),
	U16(231), U16(231), U16(231), U16(231), U16(231), U16(1036), U16(85), U16(52), U16(51), U16(52),
	U16(51), U16(117), U16(52), U16(51), U16(53), U16(52), U16(51), U16(309), U16(49), U16(85),
	U16(49), U16(53), U16(52), U16(51), U16(85), U16(52), U16(51), U16(54), U16(50), U16(54),
	U16(50), U16(54), U16(50), U16(54), U16(50), U16(181), U16(38), U16(341), U16(81), U16(858),
	U16(2874), U16(6874), U16(410), U16(61), U16(117), U16(58), U16(38), U16(39), U16(46), U16(54),
	U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(90),
	U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(49), U16(54),
	U16(82), U16(58), U16(302), U16(140), U16(74), U16(49), U16(166), U16(90), U16(110), U16(38),
	U16(39), U16(53), U16(90), U16(2759), U16(76), U16(88), U16(70), U16(39), U16(49), U16(2887),
	U16(53), U16(102), U16(39), U16(1319), U16(3015), U16(90), U16(143), U16(346), U16(871), U16(1178),
	U16(519), U16(1018), U16(335), U16(986), U16(271), U16(58), U16(495), U16(1050), U16(335), U16(1274),
	U16(495), U16(2042), U16(8218), U16(39), U16(39), U16(2074), U16(39), U16(39), U16(679), U16(38),
	U16(36583), U16(1786), U16(1287), U16(198), U16(85), U16(8583), U16(38), U16(117), U16(519), U16(333),
	U16(71), U16(1502), U16(39), U16(44), U16(107), U16(53), U16(332), U16(53), U16(38), U16(798),
	U16(44), U16(2247), U16(334), U16(76), U16(213), U16(760), U16(294), U16(88), U16(478), U16(69),
	U16(2014), U16(38), U16(261), U16(190), U16(350), U16(38), U16(88), U16(158), U16(158), U16(382),
	U16(70), U16(37), U16(231), U16(44), U16(103), U16(44), U16(135), U16(44), U16(743), U16(74),
	U16(76), U16(42), U16(154), U16(207), U16(90), U16(55), U16(58), U16(1671), U16(149), U16(74),
	U16(1607), U16(522), U16(44), U16(85), U16(333), U16(588), U16(199), U16(117), U16(39), U16(333),
	U16(903), U16(268), U16(85), U16(743), U16(364), U16(74), U16(53), U16(935), U16(108), U16(42),
	U16(1511), U16(44), U16(74), U16(140), U16(74), U16(44), U16(138), U16(437), U16(38), U16(333),
	U16(85), U16(1319), U16(204), U16(74), U16(76), U16(74), U16(76), U16(103), U16(44), U16(263),
	U16(44), U16(42), U16(333), U16(149), U16(519), U16(38), U16(199), U16(122), U16(39), U16(42),
	U16(1543), U16(44), U16(39), U16(108), U16(71), U16(76), U16(167), U16(76), U16(39), U16(44),
	U16(39), U16(71), U16(38), U16(85), U16(359), U16(42), U16(76), U16(74), U16(85), U16(39),
	U16(70), U16(42), U16(44), U16(199), U16(199), U16(199), U16(231), U16(231), U16(1127), U16(74),
	U16(44), U16(74), U16(44), U16(74), U16(53), U16(42), U16(44), U16(333), U16(39), U16(39),
	U16(743), U16(1575), U16(36), U16(68), U16(68), U16(36), U16(63), U16(63), U16(11719), U16(3399),
	U16(229), U16(165), U16(39), U16(44), U16(327), U16(57), U16(423), U16(167), U16(39), U16(71),
	U16(71), U16(3463), U16(536), U16(11623), U16(54), U16(50), U16(2055), U16(1735), U16(391), U16(55),
	U16(58), U16(524), U16(245), U16(54), U16(50), U16(53), U16(236), U16(53), U16(81), U16(80),
	U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50),
	U16(54), U16(50), U16(54), U16(50), U16(54), U16(50), U16(85), U16(54), U16(50), U16(149),
	U16(112), U16(117), U16(149), U16(49), U16(54), U16(50), U16(54), U16(50), U16(54), U16(50),
	U16(117), U16(57), U16(49), U16(121), U16(53), U16(55), U16(85), U16(167), U16(4327), U16(34),
	U16(117), U16(55), U16(117), U16(54), U16(50), U16(53), U16(57), U16(53), U16(49), U16(85),
	U16(333), U16(85), U16(121), U16(85), U16(841), U16(54), U16(53), U16(50), U16(56), U16(48),
	U16(56), U16(837), U16(54), U16(57), U16(50), U16(57), U16(54), U16(50), U16(53), U16(54),
	U16(50), U16(85), U16(327), U16(38), U16(1447), U16(70), U16(999), U16(199), U16(199), U16(199),
	U16(103), U16(87), U16(57), U16(56), U16(58), U16(87), U16(58), U16(153), U16(90), U16(98),
	U16(90), U16(391), U16(839), U16(615), U16(71), U16(487), U16(455), U16(3943), U16(117), U16(1455),
	U16(314), U16(1710), U16(143), U16(570), U16(47), U16(410), U16(1466), U16(44), U16(935), U16(1575),
	U16(999), U16(143), U16(551), U16(46), U16(263), U16(46), U16(967), U16(53), U16(1159), U16(263),
	U16(53), U16(174), U16(1289), U16(1285), U16(2503), U16(333), U16(199), U16(39), U16(1415), U16(71),
	U16(39), U16(743), U16(53), U16(271), U16(711), U16(207), U16(53), U16(839), U16(53), U16(1799),
	U16(71), U16(39), U16(108), U16(76), U16(140), U16(135), U16(103), U16(871), U16(108), U16(44),
	U16(271), U16(309), U16(935), U16(79), U16(53), U16(1735), U16(245), U16(711), U16(271), U16(615),
	U16(271), U16(2343), U16(1007), U16(42), U16(44), U16(42), U16(1703), U16(492), U16(245), U16(655),
	U16(333), U16(76), U16(42), U16(1447), U16(106), U16(140), U16(74), U16(76), U16(85), U16(34),
	U16(149), U16(807), U16(333), U16(108), U16(1159), U16(172), U16(42), U16(268), U16(333), U16(149),
	U16(76), U16(42), U16(1543), U16(106), U16(300), U16(74), U16(135), U16(149), U16(333), U16(1383),
	U16(44), U16(42), U16(44), U16(74), U16(204), U16(42), U16(44), U16(333), U16(28135), U16(3182),
	U16(149), U16(34279), U16(18215), U16(2215), U16(39), U16(1482), U16(140), U16(422), U16(71), U16(7898),
	U16(1274), U16(1946), U16(74), U16(108), U16(122), U16(202), U16(258), U16(268), U16(90), U16(236),
	U16(986), U16(140), U16(1562), U16(2138), U16(108), U16(58), U16(2810), U16(591), U16(841), U16(837),
	U16(841), U16(229), U16(581), U16(841), U16(837), U16(41), U16(73), U16(41), U16(73), U16(137),
	U16(265), U16(133), U16(37), U16(229), U16(357), U16(841), U16(837), U16(73), U16(137), U16(265),
	U16(233), U16(837), U16(73), U16(137), U16(169), U16(41), U16(233), U16(837), U16(841), U16(837),
	U16(841), U16(837), U16(841), U16(837), U16(841), U16(837), U16(841), U16(837), U16(841), U16(901),
	U16(809), U16(57), U16(805), U16(57), U16(197), U16(809), U16(57), U16(805), U16(57), U16(197),
	U16(809), U16(57), U16(805), U16(57), U16(197), U16(809), U16(57), U16(805), U16(57), U16(197),
	U16(809), U16(57), U16(805), U16(57), U16(197), U16(94), U16(1613), U16(135), U16(871), U16(71),
	U16(39), U16(39), U16(327), U16(135), U16(39), U16(39), U16(39), U16(39), U16(39), U16(39),
	U16(103), U16(71), U16(39), U16(39), U16(39), U16(39), U16(39), U16(39), U16(71), U16(39),
	U16(135), U16(231), U16(135), U16(135), U16(39), U16(327), U16(551), U16(103), U16(167), U16(551),
	U16(89), U16(1434), U16(3226), U16(506), U16(474), U16(506), U16(506), U16(367), U16(1018), U16(1946),
	U16(1402), U16(954), U16(1402), U16(314), U16(90), U16(1082), U16(218), U16(2266), U16(666), U16(1210),
	U16(186), U16(570), U16(2042), U16(58), U16(5850), U16(154), U16(2010), U16(154), U16(794), U16(2266),
	U16(378), U16(2266), U16(3738), U16(39), U16(39), U16(39), U16(39), U16(39), U16(39), U16(17351),
	U16(34), U16(3074), U16(7692), U16(63), U16(63),
}

func sqlite3Fts5UnicodeCategory(tls *libc.TLS, iCode U32) int32 {
	var iRes int32 = -1
	var iHi int32
	var iLo int32
	var ret int32
	var iKey U16

	if iCode >= U32(int32(1)<<20) {
		return 0
	}
	iLo = int32(aFts5UnicodeBlock[iCode>>16])
	iHi = int32(aFts5UnicodeBlock[U32(1)+iCode>>16])
	iKey = U16(iCode & U32(0xFFFF))
	for iHi > iLo {
		var iTest int32 = (iHi + iLo) / 2

		if int32(iKey) >= int32(aFts5UnicodeMap[iTest]) {
			iRes = iTest
			iLo = iTest + 1
		} else {
			iHi = iTest
		}
	}

	if iRes < 0 {
		return 0
	}
	if int32(iKey) >= int32(aFts5UnicodeMap[iRes])+int32(aFts5UnicodeData[iRes])>>5 {
		return 0
	}
	ret = int32(aFts5UnicodeData[iRes]) & 0x1F
	if ret != 30 {
		return ret
	}
	if (int32(iKey)-int32(aFts5UnicodeMap[iRes]))&0x01 != 0 {
		return 5
	}
	return 9
}

func sqlite3Fts5UnicodeAscii(tls *libc.TLS, aArray uintptr, aAscii uintptr) {
	var i int32 = 0
	var iTbl int32 = 0
	for i < 128 {
		var bToken int32 = int32(*(*U8)(unsafe.Pointer(aArray + uintptr(int32(aFts5UnicodeData[iTbl])&0x1F))))
		var n int32 = int32(aFts5UnicodeData[iTbl])>>5 + i
		for ; i < 128 && i < n; i++ {
			*(*U8)(unsafe.Pointer(aAscii + uintptr(i))) = U8(bToken)
		}
		iTbl++
	}
	*(*U8)(unsafe.Pointer(aAscii)) = U8(0)
}

func sqlite3Fts5GetVarint32(tls *libc.TLS, p uintptr, v uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	var a U32
	var b U32

	a = U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		*(*U32)(unsafe.Pointer(v)) = a
		return 1
	}

	p++
	b = U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		a = a & U32(0x7f)
		a = a << 7
		*(*U32)(unsafe.Pointer(v)) = a | b
		return 2
	}

	p++
	a = a << 14
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		a = a & U32(int32(0x7f)<<14|0x7f)
		b = b & U32(0x7f)
		b = b << 7
		*(*U32)(unsafe.Pointer(v)) = a | b
		return 3
	}

	{
		var n U8
		p -= uintptr(2)
		n = sqlite3Fts5GetVarint(tls, p, bp)
		*(*U32)(unsafe.Pointer(v)) = U32(*(*U64)(unsafe.Pointer(bp))) & U32(0x7FFFFFFF)

		return int32(n)

	}
	return int32(0)
}

func sqlite3Fts5GetVarint(tls *libc.TLS, p uintptr, v uintptr) U8 {
	var a U32
	var b U32
	var s U32

	a = U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		*(*U64)(unsafe.Pointer(v)) = U64(a)
		return U8(1)
	}

	p++
	b = U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		a = a & U32(0x7f)
		a = a << 7
		a = a | b
		*(*U64)(unsafe.Pointer(v)) = U64(a)
		return U8(2)
	}

	p++
	a = a << 14
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		a = a & U32(SLOT_2_0)
		b = b & U32(0x7f)
		b = b << 7
		a = a | b
		*(*U64)(unsafe.Pointer(v)) = U64(a)
		return U8(3)
	}

	a = a & U32(SLOT_2_0)
	p++
	b = b << 14
	b = b | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		b = b & U32(SLOT_2_0)

		a = a << 7
		a = a | b
		*(*U64)(unsafe.Pointer(v)) = U64(a)
		return U8(4)
	}

	b = b & U32(SLOT_2_0)
	s = a

	p++
	a = a << 14
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		b = b << 7
		a = a | b
		s = s >> 18
		*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)
		return U8(5)
	}

	s = s << 7
	s = s | b

	p++
	b = b << 14
	b = b | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		a = a & U32(SLOT_2_0)
		a = a << 7
		a = a | b
		s = s >> 18
		*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)
		return U8(6)
	}

	p++
	a = a << 14
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(a&U32(0x80) != 0) {
		a = a & SLOT_4_2_0
		b = b & U32(SLOT_2_0)
		b = b << 7
		a = a | b
		s = s >> 11
		*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)
		return U8(7)
	}

	a = a & U32(SLOT_2_0)
	p++
	b = b << 14
	b = b | U32(*(*uint8)(unsafe.Pointer(p)))

	if !(b&U32(0x80) != 0) {
		b = b & SLOT_4_2_0

		a = a << 7
		a = a | b
		s = s >> 4
		*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)
		return U8(8)
	}

	p++
	a = a << 15
	a = a | U32(*(*uint8)(unsafe.Pointer(p)))

	b = b & U32(SLOT_2_0)
	b = b << 8
	a = a | b

	s = s << 4
	b = U32(*(*uint8)(unsafe.Pointer(p + libc.UintptrFromInt32(-4))))
	b = b & U32(0x7f)
	b = b >> 3
	s = s | b

	*(*U64)(unsafe.Pointer(v)) = U64(s)<<32 | U64(a)

	return U8(9)
}

func fts5PutVarint64(tls *libc.TLS, p uintptr, v U64) int32 {
	bp := tls.Alloc(10)
	defer tls.Free(10)

	var i int32
	var j int32
	var n int32

	if v&(uint64(0xff000000)<<32) != 0 {
		*(*uint8)(unsafe.Pointer(p + 8)) = U8(v)
		v >>= 8
		for i = 7; i >= 0; i-- {
			*(*uint8)(unsafe.Pointer(p + uintptr(i))) = U8(v&uint64(0x7f) | uint64(0x80))
			v >>= 7
		}
		return 9
	}
	n = 0
	for __ccgo := true; __ccgo; __ccgo = v != uint64(0) {
		*(*U8)(unsafe.Pointer(bp + uintptr(libc.PostIncInt32(&n, 1)))) = U8(v&uint64(0x7f) | uint64(0x80))
		v >>= 7
	}
	*(*U8)(unsafe.Pointer(bp)) &= U8(0x7f)

	i = 0
	j = n - 1
__1:
	if !(j >= 0) {
		goto __3
	}
	{
		*(*uint8)(unsafe.Pointer(p + uintptr(i))) = *(*U8)(unsafe.Pointer(bp + uintptr(j)))

	}
	goto __2
__2:
	j--
	i++
	goto __1
	goto __3
__3:
	;
	return n
}

func sqlite3Fts5PutVarint(tls *libc.TLS, p uintptr, v U64) int32 {
	if v <= uint64(0x7f) {
		*(*uint8)(unsafe.Pointer(p)) = uint8(v & uint64(0x7f))
		return 1
	}
	if v <= uint64(0x3fff) {
		*(*uint8)(unsafe.Pointer(p)) = uint8(v>>7&uint64(0x7f) | uint64(0x80))
		*(*uint8)(unsafe.Pointer(p + 1)) = uint8(v & uint64(0x7f))
		return 2
	}
	return fts5PutVarint64(tls, p, v)
}

func sqlite3Fts5GetVarintLen(tls *libc.TLS, iVal U32) int32 {
	if iVal < U32(int32(1)<<14) {
		return 2
	}
	if iVal < U32(int32(1)<<21) {
		return 3
	}
	if iVal < U32(int32(1)<<28) {
		return 4
	}
	return 5
}

type Fts5VocabTable1 = struct {
	Fbase     Sqlite3_vtab
	FzFts5Tbl uintptr
	FzFts5Db  uintptr
	Fdb       uintptr
	FpGlobal  uintptr
	FeType    int32
	FbBusy    uint32
}

type Fts5VocabTable = Fts5VocabTable1
type Fts5VocabCursor1 = struct {
	Fbase        Sqlite3_vtab_cursor
	FpStmt       uintptr
	FpFts5       uintptr
	FbEof        int32
	F__ccgo_pad1 [4]byte
	FpIter       uintptr
	FpStruct     uintptr
	FnLeTerm     int32
	F__ccgo_pad2 [4]byte
	FzLeTerm     uintptr
	FiCol        int32
	F__ccgo_pad3 [4]byte
	FaCnt        uintptr
	FaDoc        uintptr
	Frowid       I64
	Fterm        Fts5Buffer
	FiInstPos    I64
	FiInstOff    int32
	F__ccgo_pad4 [4]byte
}

type Fts5VocabCursor = Fts5VocabCursor1

func fts5VocabTableType(tls *libc.TLS, zType uintptr, pzErr uintptr, peType uintptr) int32 {
	bp := tls.Alloc(12)
	defer tls.Free(12)

	*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_OK
	var zCopy uintptr = sqlite3Fts5Strndup(tls, bp+8, zType, -1)
	if *(*int32)(unsafe.Pointer(bp + 8)) == SQLITE_OK {
		sqlite3Fts5Dequote(tls, zCopy)
		if Xsqlite3_stricmp(tls, zCopy, ts+44929) == 0 {
			*(*int32)(unsafe.Pointer(peType)) = FTS5_VOCAB_COL
		} else if Xsqlite3_stricmp(tls, zCopy, ts+44933) == 0 {
			*(*int32)(unsafe.Pointer(peType)) = FTS5_VOCAB_ROW
		} else if Xsqlite3_stricmp(tls, zCopy, ts+44937) == 0 {
			*(*int32)(unsafe.Pointer(peType)) = FTS5_VOCAB_INSTANCE
		} else {
			*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+44946, libc.VaList(bp, zCopy))
			*(*int32)(unsafe.Pointer(bp + 8)) = SQLITE_ERROR
		}
		Xsqlite3_free(tls, zCopy)
	}

	return *(*int32)(unsafe.Pointer(bp + 8))
}

func fts5VocabDisconnectMethod(tls *libc.TLS, pVtab uintptr) int32 {
	var pTab uintptr = pVtab
	Xsqlite3_free(tls, pTab)
	return SQLITE_OK
}

func fts5VocabDestroyMethod(tls *libc.TLS, pVtab uintptr) int32 {
	var pTab uintptr = pVtab
	Xsqlite3_free(tls, pTab)
	return SQLITE_OK
}

func fts5VocabInitVtab(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVTab uintptr, pzErr uintptr) int32 {
	bp := tls.Alloc(36)
	defer tls.Free(36)

	*(*[3]uintptr)(unsafe.Pointer(bp + 8)) = [3]uintptr{
		ts + 44980,
		ts + 45020,
		ts + 45055,
	}

	var pRet uintptr = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 32)) = SQLITE_OK
	var bDb int32

	bDb = libc.Bool32(argc == 6 && libc.Xstrlen(tls, *(*uintptr)(unsafe.Pointer(argv + 1*8))) == uint64(4) && libc.Xmemcmp(tls, ts+27930, *(*uintptr)(unsafe.Pointer(argv + 1*8)), uint64(4)) == 0)

	if argc != 5 && bDb == 0 {
		*(*uintptr)(unsafe.Pointer(pzErr)) = Xsqlite3_mprintf(tls, ts+45098, 0)
		*(*int32)(unsafe.Pointer(bp + 32)) = SQLITE_ERROR
	} else {
		var nByte int32
		var zDb uintptr
		if bDb != 0 {
			zDb = *(*uintptr)(unsafe.Pointer(argv + 3*8))
		} else {
			zDb = *(*uintptr)(unsafe.Pointer(argv + 1*8))
		}
		var zTab uintptr
		if bDb != 0 {
			zTab = *(*uintptr)(unsafe.Pointer(argv + 4*8))
		} else {
			zTab = *(*uintptr)(unsafe.Pointer(argv + 3*8))
		}
		var zType uintptr
		if bDb != 0 {
			zType = *(*uintptr)(unsafe.Pointer(argv + 5*8))
		} else {
			zType = *(*uintptr)(unsafe.Pointer(argv + 4*8))
		}
		var nDb int32 = int32(libc.Xstrlen(tls, zDb)) + 1
		var nTab int32 = int32(libc.Xstrlen(tls, zTab)) + 1
		*(*int32)(unsafe.Pointer(bp)) = 0

		*(*int32)(unsafe.Pointer(bp + 32)) = fts5VocabTableType(tls, zType, pzErr, bp)
		if *(*int32)(unsafe.Pointer(bp + 32)) == SQLITE_OK {
			*(*int32)(unsafe.Pointer(bp + 32)) = Xsqlite3_declare_vtab(tls, db, *(*uintptr)(unsafe.Pointer(bp + 8 + uintptr(*(*int32)(unsafe.Pointer(bp)))*8)))
		}

		nByte = int32(uint64(unsafe.Sizeof(Fts5VocabTable{})) + uint64(nDb) + uint64(nTab))
		pRet = sqlite3Fts5MallocZero(tls, bp+32, int64(nByte))
		if pRet != 0 {
			(*Fts5VocabTable)(unsafe.Pointer(pRet)).FpGlobal = pAux
			(*Fts5VocabTable)(unsafe.Pointer(pRet)).FeType = *(*int32)(unsafe.Pointer(bp))
			(*Fts5VocabTable)(unsafe.Pointer(pRet)).Fdb = db
			(*Fts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl = pRet + 1*64
			(*Fts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db = (*Fts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl + uintptr(nTab)
			libc.Xmemcpy(tls, (*Fts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl, zTab, uint64(nTab))
			libc.Xmemcpy(tls, (*Fts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db, zDb, uint64(nDb))
			sqlite3Fts5Dequote(tls, (*Fts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Tbl)
			sqlite3Fts5Dequote(tls, (*Fts5VocabTable)(unsafe.Pointer(pRet)).FzFts5Db)
		}
	}

	*(*uintptr)(unsafe.Pointer(ppVTab)) = pRet
	return *(*int32)(unsafe.Pointer(bp + 32))
}

func fts5VocabConnectMethod(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) 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) int32 {
	return fts5VocabInitVtab(tls, db, pAux, argc, argv, ppVtab, pzErr)
}

func fts5VocabBestIndexMethod(tls *libc.TLS, pUnused uintptr, pInfo uintptr) int32 {
	var i int32
	var iTermEq int32 = -1
	var iTermGe int32 = -1
	var iTermLe int32 = -1
	var idxNum int32 = 0
	var nArg int32 = 0

	_ = pUnused

	for i = 0; i < (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FnConstraint; i++ {
		var p uintptr = (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraint + uintptr(i)*12
		if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fusable) == 0 {
			continue
		}
		if (*sqlite3_index_constraint)(unsafe.Pointer(p)).FiColumn == 0 {
			if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_EQ {
				iTermEq = i
			}
			if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_LE {
				iTermLe = i
			}
			if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_LT {
				iTermLe = i
			}
			if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_GE {
				iTermGe = i
			}
			if int32((*sqlite3_index_constraint)(unsafe.Pointer(p)).Fop) == SQLITE_INDEX_CONSTRAINT_GT {
				iTermGe = i
			}
		}
	}

	if iTermEq >= 0 {
		idxNum = idxNum | FTS5_VOCAB_TERM_EQ
		(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(iTermEq)*8)).FargvIndex = libc.PreIncInt32(&nArg, 1)
		(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(100)
	} else {
		(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = float64(1000000)
		if iTermGe >= 0 {
			idxNum = idxNum | FTS5_VOCAB_TERM_GE
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(iTermGe)*8)).FargvIndex = libc.PreIncInt32(&nArg, 1)
			(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost / float64(2)
		}
		if iTermLe >= 0 {
			idxNum = idxNum | FTS5_VOCAB_TERM_LE
			(*sqlite3_index_constraint_usage)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaConstraintUsage + uintptr(iTermLe)*8)).FargvIndex = libc.PreIncInt32(&nArg, 1)
			(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost = (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FestimatedCost / float64(2)
		}
	}

	if (*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FnOrderBy == 1 &&
		(*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy)).FiColumn == 0 &&
		int32((*sqlite3_index_orderby)(unsafe.Pointer((*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FaOrderBy)).Fdesc) == 0 {
		(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).ForderByConsumed = 1
	}

	(*Sqlite3_index_info)(unsafe.Pointer(pInfo)).FidxNum = idxNum
	return SQLITE_OK
}

func fts5VocabOpenMethod(tls *libc.TLS, pVTab uintptr, ppCsr uintptr) int32 {
	bp := tls.Alloc(80)
	defer tls.Free(80)

	var pTab uintptr = pVTab
	var pFts5 uintptr = uintptr(0)
	var pCsr uintptr = uintptr(0)
	*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_OK
	*(*uintptr)(unsafe.Pointer(bp + 72)) = uintptr(0)
	var zSql uintptr = uintptr(0)

	if (*Fts5VocabTable)(unsafe.Pointer(pTab)).FbBusy != 0 {
		(*Sqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = Xsqlite3_mprintf(tls,
			ts+45131, libc.VaList(bp, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
		return SQLITE_ERROR
	}
	zSql = sqlite3Fts5Mprintf(tls, bp+64,
		ts+45162,
		libc.VaList(bp+16, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
	if zSql != 0 {
		*(*int32)(unsafe.Pointer(bp + 64)) = Xsqlite3_prepare_v2(tls, (*Fts5VocabTable)(unsafe.Pointer(pTab)).Fdb, zSql, -1, bp+72, uintptr(0))
	}
	Xsqlite3_free(tls, zSql)

	if *(*int32)(unsafe.Pointer(bp + 64)) == SQLITE_ERROR {
		*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_OK
	}

	(*Fts5VocabTable)(unsafe.Pointer(pTab)).FbBusy = uint32(1)
	if *(*uintptr)(unsafe.Pointer(bp + 72)) != 0 && Xsqlite3_step(tls, *(*uintptr)(unsafe.Pointer(bp + 72))) == SQLITE_ROW {
		var iId I64 = Xsqlite3_column_int64(tls, *(*uintptr)(unsafe.Pointer(bp + 72)), 0)
		pFts5 = sqlite3Fts5TableFromCsrid(tls, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FpGlobal, iId)
	}
	(*Fts5VocabTable)(unsafe.Pointer(pTab)).FbBusy = uint32(0)

	if *(*int32)(unsafe.Pointer(bp + 64)) == SQLITE_OK {
		if pFts5 == uintptr(0) {
			*(*int32)(unsafe.Pointer(bp + 64)) = Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 72)))
			*(*uintptr)(unsafe.Pointer(bp + 72)) = uintptr(0)
			if *(*int32)(unsafe.Pointer(bp + 64)) == SQLITE_OK {
				(*Sqlite3_vtab)(unsafe.Pointer(pVTab)).FzErrMsg = Xsqlite3_mprintf(tls,
					ts+45213, libc.VaList(bp+48, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Db, (*Fts5VocabTable)(unsafe.Pointer(pTab)).FzFts5Tbl))
				*(*int32)(unsafe.Pointer(bp + 64)) = SQLITE_ERROR
			}
		} else {
			*(*int32)(unsafe.Pointer(bp + 64)) = sqlite3Fts5FlushToDisk(tls, pFts5)
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 64)) == SQLITE_OK {
		var nByte I64 = I64(uint64((*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer(pFts5)).FpConfig)).FnCol)*uint64(unsafe.Sizeof(I64(0)))*uint64(2) + uint64(unsafe.Sizeof(Fts5VocabCursor{})))
		pCsr = sqlite3Fts5MallocZero(tls, bp+64, nByte)
	}

	if pCsr != 0 {
		(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5 = pFts5
		(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpStmt = *(*uintptr)(unsafe.Pointer(bp + 72))
		(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt = pCsr + 1*128
		(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc = (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt + uintptr((*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer(pFts5)).FpConfig)).FnCol)*8
	} else {
		Xsqlite3_finalize(tls, *(*uintptr)(unsafe.Pointer(bp + 72)))
	}

	*(*uintptr)(unsafe.Pointer(ppCsr)) = pCsr
	return *(*int32)(unsafe.Pointer(bp + 64))
}

func fts5VocabResetCursor(tls *libc.TLS, pCsr uintptr) {
	(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).Frowid = int64(0)
	sqlite3Fts5IterClose(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)
	sqlite3Fts5StructureRelease(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct)
	(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct = uintptr(0)
	(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter = uintptr(0)
	Xsqlite3_free(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm)
	(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm = -1
	(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm = uintptr(0)
	(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = 0
}

func fts5VocabCloseMethod(tls *libc.TLS, pCursor uintptr) int32 {
	var pCsr uintptr = pCursor
	fts5VocabResetCursor(tls, pCsr)
	sqlite3Fts5BufferFree(tls, pCsr+96)
	Xsqlite3_finalize(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpStmt)
	Xsqlite3_free(tls, pCsr)
	return SQLITE_OK
}

func fts5VocabInstanceNewTerm(tls *libc.TLS, pCsr uintptr) int32 {
	bp := tls.Alloc(8)
	defer tls.Free(8)

	*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_OK

	if (*Fts5IndexIter)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FbEof != 0 {
		(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = 1
	} else {
		var zTerm uintptr

		zTerm = sqlite3Fts5IterTerm(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter, bp)
		if (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm >= 0 {
			var nCmp int32 = func() int32 {
				if *(*int32)(unsafe.Pointer(bp)) < (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm {
					return *(*int32)(unsafe.Pointer(bp))
				}
				return (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm
			}()
			var bCmp int32 = libc.Xmemcmp(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zTerm, uint64(nCmp))
			if bCmp < 0 || bCmp == 0 && (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm < *(*int32)(unsafe.Pointer(bp)) {
				(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = 1
			}
		}

		sqlite3Fts5BufferSet(tls, bp+4, pCsr+96, *(*int32)(unsafe.Pointer(bp)), zTerm)
	}
	return *(*int32)(unsafe.Pointer(bp + 4))
}

func fts5VocabInstanceNext(tls *libc.TLS, pCsr uintptr) int32 {
	var eDetail int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail
	var rc int32 = SQLITE_OK
	var pIter uintptr = (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter
	var pp uintptr = pCsr + 112
	var po uintptr = pCsr + 120

	for eDetail == FTS5_DETAIL_NONE ||
		sqlite3Fts5PoslistNext64(tls, (*Fts5IndexIter)(unsafe.Pointer(pIter)).FpData, (*Fts5IndexIter)(unsafe.Pointer(pIter)).FnData, po, pp) != 0 {
		(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos = int64(0)
		(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstOff = 0

		rc = sqlite3Fts5IterNextScan(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)
		if rc == SQLITE_OK {
			rc = fts5VocabInstanceNewTerm(tls, pCsr)
			if (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof != 0 || eDetail == FTS5_DETAIL_NONE {
				break
			}
		}
		if rc != 0 {
			(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = 1
			break
		}
	}

	return rc
}

func fts5VocabNextMethod(tls *libc.TLS, pCursor uintptr) int32 {
	bp := tls.Alloc(24)
	defer tls.Free(24)

	var pCsr uintptr = pCursor
	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	var nCol int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FnCol

	*(*int32)(unsafe.Pointer(bp + 4)) = sqlite3Fts5StructureTest(tls, (*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpIndex, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct)
	if *(*int32)(unsafe.Pointer(bp + 4)) != SQLITE_OK {
		return *(*int32)(unsafe.Pointer(bp + 4))
	}
	(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).Frowid++

	if (*Fts5VocabTable)(unsafe.Pointer(pTab)).FeType == FTS5_VOCAB_INSTANCE {
		return fts5VocabInstanceNext(tls, pCsr)
	}

	if (*Fts5VocabTable)(unsafe.Pointer(pTab)).FeType == FTS5_VOCAB_COL {
		for (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol++; (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol < nCol; (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol++ {
			if *(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8)) != 0 {
				break
			}
		}
	}

	if (*Fts5VocabTable)(unsafe.Pointer(pTab)).FeType != FTS5_VOCAB_COL || (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol >= nCol {
		if (*Fts5IndexIter)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FbEof != 0 {
			(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = 1
		} else {
			var zTerm uintptr

			zTerm = sqlite3Fts5IterTerm(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter, bp)

			if (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm >= 0 {
				var nCmp int32 = func() int32 {
					if *(*int32)(unsafe.Pointer(bp)) < (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm {
						return *(*int32)(unsafe.Pointer(bp))
					}
					return (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm
				}()
				var bCmp int32 = libc.Xmemcmp(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zTerm, uint64(nCmp))
				if bCmp < 0 || bCmp == 0 && (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm < *(*int32)(unsafe.Pointer(bp)) {
					(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof = 1
					return SQLITE_OK
				}
			}

			sqlite3Fts5BufferSet(tls, bp+4, pCsr+96, *(*int32)(unsafe.Pointer(bp)), zTerm)
			libc.Xmemset(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt, 0, uint64(nCol)*uint64(unsafe.Sizeof(I64(0))))
			libc.Xmemset(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc, 0, uint64(nCol)*uint64(unsafe.Sizeof(I64(0))))
			(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol = 0

			for *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
				var eDetail int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail
				var pPos uintptr
				var nPos int32
				*(*I64)(unsafe.Pointer(bp + 16)) = int64(0)
				*(*int32)(unsafe.Pointer(bp + 8)) = 0

				pPos = (*Fts5IndexIter)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FpData
				nPos = (*Fts5IndexIter)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FnData

				switch (*Fts5VocabTable)(unsafe.Pointer(pTab)).FeType {
				case FTS5_VOCAB_ROW:
					if eDetail == FTS5_DETAIL_FULL {
						for 0 == sqlite3Fts5PoslistNext64(tls, pPos, nPos, bp+8, bp+16) {
							*(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt))++
						}
					}
					*(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc))++
					break
					fallthrough

				case FTS5_VOCAB_COL:
					if eDetail == FTS5_DETAIL_FULL {
						var iCol int32 = -1
						for 0 == sqlite3Fts5PoslistNext64(tls, pPos, nPos, bp+8, bp+16) {
							var ii int32 = int32(*(*I64)(unsafe.Pointer(bp + 16)) >> 32)
							if iCol != ii {
								if ii >= nCol {
									*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_CORRUPT | int32(1)<<8
									break
								}
								*(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr(ii)*8))++
								iCol = ii
							}
							*(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt + uintptr(ii)*8))++
						}
					} else if eDetail == FTS5_DETAIL_COLUMNS {
						for 0 == sqlite3Fts5PoslistNext64(tls, pPos, nPos, bp+8, bp+16) {
							if *(*I64)(unsafe.Pointer(bp + 16)) >= I64(nCol) {
								*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_CORRUPT | int32(1)<<8
								break
							}
							*(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr(*(*I64)(unsafe.Pointer(bp + 16)))*8))++
						}
					} else {
						*(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc))++
					}
					break
					fallthrough

				default:
					break
				}

				if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
					*(*int32)(unsafe.Pointer(bp + 4)) = sqlite3Fts5IterNextScan(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)
				}
				if (*Fts5VocabTable)(unsafe.Pointer(pTab)).FeType == FTS5_VOCAB_INSTANCE {
					break
				}

				if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK {
					zTerm = sqlite3Fts5IterTerm(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter, bp)
					if *(*int32)(unsafe.Pointer(bp)) != (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fn ||
						*(*int32)(unsafe.Pointer(bp)) > 0 && libc.Xmemcmp(tls, zTerm, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fp, uint64(*(*int32)(unsafe.Pointer(bp)))) != 0 {
						break
					}
					if (*Fts5IndexIter)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FbEof != 0 {
						break
					}
				}
			}
		}
	}

	if *(*int32)(unsafe.Pointer(bp + 4)) == SQLITE_OK && (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof == 0 && (*Fts5VocabTable)(unsafe.Pointer(pTab)).FeType == FTS5_VOCAB_COL {
		for ; (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol < nCol && *(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8)) == int64(0); (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol++ {
		}
		if (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol == nCol {
			*(*int32)(unsafe.Pointer(bp + 4)) = SQLITE_CORRUPT | int32(1)<<8
		}
	}
	return *(*int32)(unsafe.Pointer(bp + 4))
}

func fts5VocabFilterMethod(tls *libc.TLS, pCursor uintptr, idxNum int32, zUnused uintptr, nUnused int32, apVal uintptr) int32 {
	var pTab uintptr = (*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	var pCsr uintptr = pCursor
	var eType int32 = (*Fts5VocabTable)(unsafe.Pointer(pTab)).FeType
	var rc int32 = SQLITE_OK

	var iVal int32 = 0
	var f int32 = FTS5INDEX_QUERY_SCAN
	var zTerm uintptr = uintptr(0)
	var nTerm int32 = 0

	var pEq uintptr = uintptr(0)
	var pGe uintptr = uintptr(0)
	var pLe uintptr = uintptr(0)

	_ = zUnused
	_ = nUnused

	fts5VocabResetCursor(tls, pCsr)
	if idxNum&FTS5_VOCAB_TERM_EQ != 0 {
		pEq = *(*uintptr)(unsafe.Pointer(apVal + uintptr(libc.PostIncInt32(&iVal, 1))*8))
	}
	if idxNum&FTS5_VOCAB_TERM_GE != 0 {
		pGe = *(*uintptr)(unsafe.Pointer(apVal + uintptr(libc.PostIncInt32(&iVal, 1))*8))
	}
	if idxNum&FTS5_VOCAB_TERM_LE != 0 {
		pLe = *(*uintptr)(unsafe.Pointer(apVal + uintptr(libc.PostIncInt32(&iVal, 1))*8))
	}

	if pEq != 0 {
		zTerm = Xsqlite3_value_text(tls, pEq)
		nTerm = Xsqlite3_value_bytes(tls, pEq)
		f = 0
	} else {
		if pGe != 0 {
			zTerm = Xsqlite3_value_text(tls, pGe)
			nTerm = Xsqlite3_value_bytes(tls, pGe)
		}
		if pLe != 0 {
			var zCopy uintptr = Xsqlite3_value_text(tls, pLe)
			if zCopy == uintptr(0) {
				zCopy = ts + 1636
			}
			(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm = Xsqlite3_value_bytes(tls, pLe)
			(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm = Xsqlite3_malloc(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm+1)
			if (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm == uintptr(0) {
				rc = SQLITE_NOMEM
			} else {
				libc.Xmemcpy(tls, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FzLeTerm, zCopy, uint64((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FnLeTerm+1))
			}
		}
	}

	if rc == SQLITE_OK {
		var pIndex uintptr = (*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpIndex
		rc = sqlite3Fts5IndexQuery(tls, pIndex, zTerm, nTerm, f, uintptr(0), pCsr+32)
		if rc == SQLITE_OK {
			(*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpStruct = sqlite3Fts5StructureRef(tls, pIndex)
		}
	}
	if rc == SQLITE_OK && eType == FTS5_VOCAB_INSTANCE {
		rc = fts5VocabInstanceNewTerm(tls, pCsr)
	}
	if rc == SQLITE_OK && !((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof != 0) &&
		(eType != FTS5_VOCAB_INSTANCE ||
			(*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail != FTS5_DETAIL_NONE) {
		rc = fts5VocabNextMethod(tls, pCursor)
	}

	return rc
}

func fts5VocabEofMethod(tls *libc.TLS, pCursor uintptr) int32 {
	var pCsr uintptr = pCursor
	return (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FbEof
}

func fts5VocabColumnMethod(tls *libc.TLS, pCursor uintptr, pCtx uintptr, iCol int32) int32 {
	var pCsr uintptr = pCursor
	var eDetail int32 = (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail
	var eType int32 = (*Fts5VocabTable)(unsafe.Pointer((*Sqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FeType
	var iVal I64 = int64(0)

	if iCol == 0 {
		Xsqlite3_result_text(tls,
			pCtx, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fp, (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fn, libc.UintptrFromInt32(-1))
	} else if eType == FTS5_VOCAB_COL {
		if iCol == 1 {
			if eDetail != FTS5_DETAIL_NONE {
				var z uintptr = *(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FazCol + uintptr((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8))
				Xsqlite3_result_text(tls, pCtx, z, -1, uintptr(0))
			}
		} else if iCol == 2 {
			iVal = *(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8))
		} else {
			iVal = *(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt + uintptr((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8))
		}
	} else if eType == FTS5_VOCAB_ROW {
		if iCol == 1 {
			iVal = *(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc))
		} else {
			iVal = *(*I64)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt))
		}
	} else {
		switch iCol {
		case 1:
			Xsqlite3_result_int64(tls, pCtx, (*Fts5IndexIter)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FiRowid)
			break
			fallthrough
		case 2:
			{
				var ii int32 = -1
				if eDetail == FTS5_DETAIL_FULL {
					ii = int32((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos >> 32)
				} else if eDetail == FTS5_DETAIL_COLUMNS {
					ii = int32((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos)
				}
				if ii >= 0 && ii < (*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FnCol {
					var z uintptr = *(*uintptr)(unsafe.Pointer((*Fts5Config)(unsafe.Pointer((*Fts5Table)(unsafe.Pointer((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FazCol + uintptr(ii)*8))
					Xsqlite3_result_text(tls, pCtx, z, -1, uintptr(0))
				}
				break

			}
			fallthrough
		default:
			{
				if eDetail == FTS5_DETAIL_FULL {
					var ii int32 = int32((*Fts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos & int64(0x7FFFFFFF))
					Xsqlite3_result_int(tls, pCtx, ii)
				}
				break

			}
		}
	}

	if iVal > int64(0) {
		Xsqlite3_result_int64(tls, pCtx, iVal)
	}
	return SQLITE_OK
}

func fts5VocabRowidMethod(tls *libc.TLS, pCursor uintptr, pRowid uintptr) int32 {
	var pCsr uintptr = pCursor
	*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = (*Fts5VocabCursor)(unsafe.Pointer(pCsr)).Frowid
	return SQLITE_OK
}

func sqlite3Fts5VocabInit(tls *libc.TLS, pGlobal uintptr, db uintptr) int32 {
	var p uintptr = pGlobal

	return Xsqlite3_create_module_v2(tls, db, ts+45239, uintptr(unsafe.Pointer(&fts5Vocab)), p, uintptr(0))
}

var fts5Vocab = Sqlite3_module{
	FiVersion:    2,
	FxCreate:     0,
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxDestroy:    0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
}

type StmtRow1 = struct {
	FiRowid      Sqlite3_int64
	FzSql        uintptr
	FaCol        [11]int32
	F__ccgo_pad1 [4]byte
	FpNext       uintptr
}

type StmtRow = StmtRow1

type stmt_vtab = struct {
	Fbase Sqlite3_vtab
	Fdb   uintptr
}

type Stmt_vtab = stmt_vtab

type stmt_cursor = struct {
	Fbase Sqlite3_vtab_cursor
	Fdb   uintptr
	FpRow uintptr
}

type Stmt_cursor = stmt_cursor

func stmtConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) int32 {
	var pNew uintptr
	var rc int32

	_ = pAux
	_ = argc
	_ = argv
	_ = pzErr
	rc = Xsqlite3_declare_vtab(tls, db,
		ts+45249)
	if rc == SQLITE_OK {
		pNew = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Stmt_vtab{})))
		*(*uintptr)(unsafe.Pointer(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(Stmt_vtab{})))
		(*Stmt_vtab)(unsafe.Pointer(pNew)).Fdb = db
	}
	return rc
}

func stmtDisconnect(tls *libc.TLS, pVtab uintptr) int32 {
	Xsqlite3_free(tls, pVtab)
	return SQLITE_OK
}

func stmtOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) int32 {
	var pCur uintptr
	pCur = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(Stmt_cursor{})))
	if pCur == uintptr(0) {
		return SQLITE_NOMEM
	}
	libc.Xmemset(tls, pCur, 0, uint64(unsafe.Sizeof(Stmt_cursor{})))
	(*Stmt_cursor)(unsafe.Pointer(pCur)).Fdb = (*Stmt_vtab)(unsafe.Pointer(p)).Fdb
	*(*uintptr)(unsafe.Pointer(ppCursor)) = pCur
	return SQLITE_OK
}

func stmtCsrReset(tls *libc.TLS, pCur uintptr) {
	var pRow uintptr = uintptr(0)
	var pNext uintptr = uintptr(0)
	for pRow = (*Stmt_cursor)(unsafe.Pointer(pCur)).FpRow; pRow != 0; pRow = pNext {
		pNext = (*StmtRow)(unsafe.Pointer(pRow)).FpNext
		Xsqlite3_free(tls, pRow)
	}
	(*Stmt_cursor)(unsafe.Pointer(pCur)).FpRow = uintptr(0)
}

func stmtClose(tls *libc.TLS, cur uintptr) int32 {
	stmtCsrReset(tls, cur)
	Xsqlite3_free(tls, cur)
	return SQLITE_OK
}

func stmtNext(tls *libc.TLS, cur uintptr) int32 {
	var pCur uintptr = cur
	var pNext uintptr = (*StmtRow)(unsafe.Pointer((*Stmt_cursor)(unsafe.Pointer(pCur)).FpRow)).FpNext
	Xsqlite3_free(tls, (*Stmt_cursor)(unsafe.Pointer(pCur)).FpRow)
	(*Stmt_cursor)(unsafe.Pointer(pCur)).FpRow = pNext
	return SQLITE_OK
}

func stmtColumn(tls *libc.TLS, cur uintptr, ctx uintptr, i int32) int32 {
	var pCur uintptr = cur
	var pRow uintptr = (*Stmt_cursor)(unsafe.Pointer(pCur)).FpRow
	if i == STMT_COLUMN_SQL {
		Xsqlite3_result_text(tls, ctx, (*StmtRow)(unsafe.Pointer(pRow)).FzSql, -1, libc.UintptrFromInt32(-1))
	} else {
		Xsqlite3_result_int(tls, ctx, *(*int32)(unsafe.Pointer(pRow + 16 + uintptr(i)*4)))
	}
	return SQLITE_OK
}

func stmtRowid(tls *libc.TLS, cur uintptr, pRowid uintptr) int32 {
	var pCur uintptr = cur
	*(*Sqlite_int64)(unsafe.Pointer(pRowid)) = (*StmtRow)(unsafe.Pointer((*Stmt_cursor)(unsafe.Pointer(pCur)).FpRow)).FiRowid
	return SQLITE_OK
}

func stmtEof(tls *libc.TLS, cur uintptr) int32 {
	var pCur uintptr = cur
	return libc.Bool32((*Stmt_cursor)(unsafe.Pointer(pCur)).FpRow == uintptr(0))
}

func stmtFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) int32 {
	var pCur uintptr = pVtabCursor
	var p uintptr = uintptr(0)
	var iRowid Sqlite3_int64 = int64(1)
	var ppRow uintptr = uintptr(0)

	_ = idxNum
	_ = idxStr
	_ = argc
	_ = argv
	stmtCsrReset(tls, pCur)
	ppRow = pCur + 16
	for p = Xsqlite3_next_stmt(tls, (*Stmt_cursor)(unsafe.Pointer(pCur)).Fdb, uintptr(0)); p != 0; p = Xsqlite3_next_stmt(tls, (*Stmt_cursor)(unsafe.Pointer(pCur)).Fdb, p) {
		var zSql uintptr = Xsqlite3_sql(tls, p)
		var nSql Sqlite3_int64
		if zSql != 0 {
			nSql = int64(libc.Xstrlen(tls, zSql) + uint64(1))
		} else {
			nSql = int64(0)
		}
		var pNew uintptr = Xsqlite3_malloc64(tls, uint64(unsafe.Sizeof(StmtRow{}))+uint64(nSql))

		if pNew == uintptr(0) {
			return SQLITE_NOMEM
		}
		libc.Xmemset(tls, pNew, 0, uint64(unsafe.Sizeof(StmtRow{})))
		if zSql != 0 {
			(*StmtRow)(unsafe.Pointer(pNew)).FzSql = pNew + 1*72
			libc.Xmemcpy(tls, (*StmtRow)(unsafe.Pointer(pNew)).FzSql, zSql, uint64(nSql))
		}
		*(*int32)(unsafe.Pointer(pNew + 16 + 1*4)) = Xsqlite3_column_count(tls, p)
		*(*int32)(unsafe.Pointer(pNew + 16 + 2*4)) = Xsqlite3_stmt_readonly(tls, p)
		*(*int32)(unsafe.Pointer(pNew + 16 + 3*4)) = Xsqlite3_stmt_busy(tls, p)
		*(*int32)(unsafe.Pointer(pNew + 16 + 4*4)) = Xsqlite3_stmt_status(tls,
			p, SQLITE_STMTSTATUS_FULLSCAN_STEP, 0)
		*(*int32)(unsafe.Pointer(pNew + 16 + 5*4)) = Xsqlite3_stmt_status(tls,
			p, SQLITE_STMTSTATUS_SORT, 0)
		*(*int32)(unsafe.Pointer(pNew + 16 + 6*4)) = Xsqlite3_stmt_status(tls,
			p, SQLITE_STMTSTATUS_AUTOINDEX, 0)
		*(*int32)(unsafe.Pointer(pNew + 16 + 7*4)) = Xsqlite3_stmt_status(tls,
			p, SQLITE_STMTSTATUS_VM_STEP, 0)
		*(*int32)(unsafe.Pointer(pNew + 16 + 8*4)) = Xsqlite3_stmt_status(tls,
			p, SQLITE_STMTSTATUS_REPREPARE, 0)
		*(*int32)(unsafe.Pointer(pNew + 16 + 9*4)) = Xsqlite3_stmt_status(tls,
			p, SQLITE_STMTSTATUS_RUN, 0)
		*(*int32)(unsafe.Pointer(pNew + 16 + 10*4)) = Xsqlite3_stmt_status(tls,
			p, SQLITE_STMTSTATUS_MEMUSED, 0)
		(*StmtRow)(unsafe.Pointer(pNew)).FiRowid = libc.PostIncInt64(&iRowid, 1)
		*(*uintptr)(unsafe.Pointer(ppRow)) = pNew
		ppRow = pNew + 64
	}

	return SQLITE_OK
}

func stmtBestIndex(tls *libc.TLS, tab uintptr, pIdxInfo uintptr) int32 {
	_ = tab
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64(500)
	(*Sqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(500)
	return SQLITE_OK
}

var stmtModule = Sqlite3_module{
	FxConnect:    0,
	FxBestIndex:  0,
	FxDisconnect: 0,
	FxOpen:       0,
	FxClose:      0,
	FxFilter:     0,
	FxNext:       0,
	FxEof:        0,
	FxColumn:     0,
	FxRowid:      0,
}

func Xsqlite3StmtVtabInit(tls *libc.TLS, db uintptr) int32 {
	var rc int32 = SQLITE_OK
	rc = Xsqlite3_create_module(tls, db, ts+45321, uintptr(unsafe.Pointer(&stmtModule)), uintptr(0))
	return rc
}

func Xsqlite3_sourceid(tls *libc.TLS) uintptr {
	return ts + 45333
}

func init() {
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&Xsqlite3aEQb)) + 0)) = uintptr(unsafe.Pointer(&Xsqlite3UpperToLower)) + 210
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&Xsqlite3aGTb)) + 0)) = uintptr(unsafe.Pointer(&Xsqlite3UpperToLower)) + 216
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&Xsqlite3aLTb)) + 0)) = uintptr(unsafe.Pointer(&Xsqlite3UpperToLower)) + 204
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aAgg)) + 0)) = geopolyBBoxStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aAgg)) + 8)) = geopolyBBoxFinal
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aAlterTableFuncs)) + 24)) = renameColumnFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aAlterTableFuncs)) + 96)) = renameTableFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aAlterTableFuncs)) + 168)) = renameTableTest
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aAlterTableFuncs)) + 240)) = dropColumnFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aAlterTableFuncs)) + 312)) = renameQuotefixFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 24)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 96)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 168)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 240)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 312)) = soundexFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 384)) = loadExt
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 456)) = loadExt
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 528)) = compileoptionusedFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 600)) = compileoptiongetFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 672)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 744)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 816)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 888)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 960)) = trimFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1032)) = trimFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1104)) = trimFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1176)) = trimFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1248)) = trimFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1320)) = trimFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1392)) = minmaxFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1536)) = minmaxStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1544)) = minMaxFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1552)) = minMaxValue
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1608)) = minmaxFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1752)) = minmaxStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1760)) = minMaxFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1768)) = minMaxValue
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1824)) = typeofFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1896)) = subtypeFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 1968)) = lengthFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2040)) = instrFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2112)) = printfFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2184)) = printfFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2256)) = unicodeFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2328)) = charFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2400)) = absFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2472)) = roundFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2544)) = roundFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2616)) = upperFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2688)) = lowerFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2760)) = hexFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2832)) = unhexFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2904)) = unhexFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 2976)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3048)) = randomFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3120)) = randomBlob
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3192)) = nullifFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3264)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3336)) = sourceidFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3408)) = errlogFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3480)) = quoteFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3552)) = last_insert_rowid
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3624)) = changes
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3696)) = total_changes
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3768)) = replaceFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3840)) = zeroblobFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3912)) = substrFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 3984)) = substrFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4056)) = substrFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4128)) = substrFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4200)) = sumStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4208)) = sumFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4216)) = sumFinalize
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4224)) = sumInverse
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4272)) = sumStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4280)) = totalFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4288)) = totalFinalize
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4296)) = sumInverse
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4344)) = sumStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4352)) = avgFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4360)) = avgFinalize
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4368)) = sumInverse
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4416)) = countStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4424)) = countFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4432)) = countFinalize
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4440)) = countInverse
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4488)) = countStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4496)) = countFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4504)) = countFinalize
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4512)) = countInverse
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4560)) = groupConcatStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4568)) = groupConcatFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4576)) = groupConcatValue
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4584)) = groupConcatInverse
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4632)) = groupConcatStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4640)) = groupConcatFinalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4648)) = groupConcatValue
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4656)) = groupConcatInverse
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4688)) = uintptr(unsafe.Pointer(&globInfo))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4704)) = likeFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4760)) = uintptr(unsafe.Pointer(&likeInfoNorm))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4776)) = likeFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4832)) = uintptr(unsafe.Pointer(&likeInfoNorm))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 4848)) = likeFunc
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5048)) = xCeil
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5064)) = ceilingFunc
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5120)) = xCeil
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5136)) = ceilingFunc
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5192)) = xFloor
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5208)) = ceilingFunc
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5264)) = libc.Xtrunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5280)) = ceilingFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5352)) = logFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5424)) = logFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5496)) = logFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5568)) = logFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5640)) = logFunc
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5696)) = libc.Xexp
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5712)) = math1Func
	*(*func(*libc.TLS, float64, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5768)) = libc.Xpow
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5784)) = math2Func
	*(*func(*libc.TLS, float64, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5840)) = libc.Xpow
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5856)) = math2Func
	*(*func(*libc.TLS, float64, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5912)) = libc.Xfmod
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5928)) = math2Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 5984)) = libc.Xacos
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6000)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6056)) = libc.Xasin
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6072)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6128)) = libc.Xatan
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6144)) = math1Func
	*(*func(*libc.TLS, float64, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6200)) = libc.Xatan2
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6216)) = math2Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6272)) = libc.Xcos
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6288)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6344)) = libc.Xsin
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6360)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6416)) = libc.Xtan
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6432)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6488)) = libc.Xcosh
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6504)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6560)) = libc.Xsinh
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6576)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6632)) = libc.Xtanh
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6648)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6704)) = libc.Xacosh
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6720)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6776)) = libc.Xasinh
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6792)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6848)) = libc.Xatanh
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6864)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6920)) = libc.Xsqrt
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6936)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 6992)) = degToRad
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 7008)) = math1Func
	*(*func(*libc.TLS, float64) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 7064)) = radToDeg
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 7080)) = math1Func
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 7152)) = piFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 7224)) = signFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 7296)) = versionFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aBuiltinFunc)) + 7368)) = versionFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 8)) = uintptr(unsafe.Pointer(&Xsqlite3Config))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 24)) = juliandayFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 80)) = uintptr(unsafe.Pointer(&Xsqlite3Config))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 96)) = unixepochFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 152)) = uintptr(unsafe.Pointer(&Xsqlite3Config))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 168)) = dateFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 224)) = uintptr(unsafe.Pointer(&Xsqlite3Config))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 240)) = timeFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 296)) = uintptr(unsafe.Pointer(&Xsqlite3Config))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 312)) = datetimeFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 368)) = uintptr(unsafe.Pointer(&Xsqlite3Config))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 384)) = strftimeFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 456)) = ctimeFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 528)) = ctimestampFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aDateTimeFuncs)) + 600)) = cdateFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 0)) = geopolyAreaFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 24)) = geopolyBlobFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 48)) = geopolyJsonFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 72)) = geopolySvgFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 96)) = geopolyWithinFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 120)) = geopolyContainsPointFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 144)) = geopolyOverlapFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 168)) = geopolyDebugFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 192)) = geopolyBBoxFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 216)) = geopolyXformFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 240)) = geopolyRegularFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aFunc)) + 264)) = geopolyCcwFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 24)) = jsonRemoveFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 96)) = jsonArrayFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 168)) = jsonArrayLengthFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 240)) = jsonArrayLengthFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 312)) = jsonExtractFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 384)) = jsonExtractFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 456)) = jsonExtractFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 528)) = jsonSetFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 600)) = jsonObjectFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 672)) = jsonPatchFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 744)) = jsonQuoteFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 816)) = jsonRemoveFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 888)) = jsonReplaceFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 960)) = jsonSetFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1032)) = jsonTypeFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1104)) = jsonTypeFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1176)) = jsonValidFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1248)) = jsonArrayStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1256)) = jsonArrayFinal
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1264)) = jsonArrayValue
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1272)) = jsonGroupInverse
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1320)) = jsonObjectStep
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1328)) = jsonObjectFinal
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1336)) = jsonObjectValue
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aJsonFunc)) + 1344)) = jsonGroupInverse
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aMod)) + 8)) = uintptr(unsafe.Pointer(&jsonEachModule))
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aMod)) + 24)) = uintptr(unsafe.Pointer(&jsonTreeModule))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 8)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32, int32) int32
	}{posixOpen}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 32)) = *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS, int32) int32 }{libc.Xclose}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 56)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, int32) int32
	}{libc.Xaccess}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 80)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, Size_t) uintptr
	}{libc.Xgetcwd}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 104)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{libc.Xstat}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 128)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, int32, uintptr) int32
	}{libc.Xfstat}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 152)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, int32, X__off64_t) int32
	}{libc.Xftruncate}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 176)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, int32, int32, uintptr) int32
	}{libc.Xfcntl}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 200)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, int32, uintptr, Size_t) Ssize_t
	}{libc.Xread}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 272)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, int32, uintptr, Size_t) Ssize_t
	}{libc.Xwrite}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 344)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, int32, X__mode_t) int32
	}{libc.Xfchmod}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 392)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{libc.Xunlink}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 416)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{openDirectory}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 440)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, X__mode_t) int32
	}{libc.Xmkdir}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 464)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) int32
	}{libc.Xrmdir}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 488)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, int32, X__uid_t, X__gid_t) int32
	}{libc.Xfchown}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 512)) = *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS) X__uid_t }{libc.Xgeteuid}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 536)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, Size_t, int32, int32, int32, X__off64_t) uintptr
	}{libc.Xmmap}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 560)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, Size_t) int32
	}{libc.Xmunmap}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 584)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, Size_t, Size_t, int32, uintptr) uintptr
	}{libc.Xmremap}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 608)) = *(*uintptr)(unsafe.Pointer(&struct{ f func(*libc.TLS) int32 }{unixGetpagesize}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 632)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr, Size_t) Ssize_t
	}{libc.Xreadlink}))
	*(*Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aSyscall)) + 656)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr, uintptr) int32
	}{libc.Xlstat}))
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 32)) = uintptr(unsafe.Pointer(&posixIoFinder))
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 40)) = unixOpen
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 48)) = unixDelete
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 56)) = unixAccess
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 64)) = unixFullPathname
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 72)) = unixDlOpen
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 80)) = unixDlError
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 88)) = unixDlSym
	*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 96)) = unixDlClose
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 104)) = unixRandomness
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 112)) = unixSleep
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 120)) = unixCurrentTime
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 128)) = unixGetLastError
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 136)) = unixCurrentTimeInt64
	*(*func(*libc.TLS, uintptr, uintptr, Sqlite3_syscall_ptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 144)) = unixSetSystemCall
	*(*func(*libc.TLS, uintptr, uintptr) Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 152)) = unixGetSystemCall
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 160)) = unixNextSystemCall
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 200)) = uintptr(unsafe.Pointer(&nolockIoFinder))
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 208)) = unixOpen
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 216)) = unixDelete
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 224)) = unixAccess
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 232)) = unixFullPathname
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 240)) = unixDlOpen
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 248)) = unixDlError
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 256)) = unixDlSym
	*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 264)) = unixDlClose
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 272)) = unixRandomness
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 280)) = unixSleep
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 288)) = unixCurrentTime
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 296)) = unixGetLastError
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 304)) = unixCurrentTimeInt64
	*(*func(*libc.TLS, uintptr, uintptr, Sqlite3_syscall_ptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 312)) = unixSetSystemCall
	*(*func(*libc.TLS, uintptr, uintptr) Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 320)) = unixGetSystemCall
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 328)) = unixNextSystemCall
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 368)) = uintptr(unsafe.Pointer(&dotlockIoFinder))
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 376)) = unixOpen
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 384)) = unixDelete
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 392)) = unixAccess
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 400)) = unixFullPathname
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 408)) = unixDlOpen
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 416)) = unixDlError
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 424)) = unixDlSym
	*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 432)) = unixDlClose
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 440)) = unixRandomness
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 448)) = unixSleep
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 456)) = unixCurrentTime
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 464)) = unixGetLastError
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 472)) = unixCurrentTimeInt64
	*(*func(*libc.TLS, uintptr, uintptr, Sqlite3_syscall_ptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 480)) = unixSetSystemCall
	*(*func(*libc.TLS, uintptr, uintptr) Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 488)) = unixGetSystemCall
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 496)) = unixNextSystemCall
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 536)) = uintptr(unsafe.Pointer(&posixIoFinder))
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 544)) = unixOpen
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 552)) = unixDelete
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 560)) = unixAccess
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 568)) = unixFullPathname
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 576)) = unixDlOpen
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 584)) = unixDlError
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 592)) = unixDlSym
	*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 600)) = unixDlClose
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 608)) = unixRandomness
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 616)) = unixSleep
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 624)) = unixCurrentTime
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 632)) = unixGetLastError
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 640)) = unixCurrentTimeInt64
	*(*func(*libc.TLS, uintptr, uintptr, Sqlite3_syscall_ptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 648)) = unixSetSystemCall
	*(*func(*libc.TLS, uintptr, uintptr) Sqlite3_syscall_ptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 656)) = unixGetSystemCall
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aVfs)) + 664)) = unixNextSystemCall
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 24)) = row_numberStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 32)) = row_numberValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 40)) = row_numberValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 48)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 56)) = uintptr(unsafe.Pointer(&row_numberName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 96)) = dense_rankStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 104)) = dense_rankValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 112)) = dense_rankValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 120)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 128)) = uintptr(unsafe.Pointer(&dense_rankName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 168)) = rankStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 176)) = rankValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 184)) = rankValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 192)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 200)) = uintptr(unsafe.Pointer(&rankName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 240)) = percent_rankStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 248)) = percent_rankValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 256)) = percent_rankValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 264)) = percent_rankInvFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 272)) = uintptr(unsafe.Pointer(&percent_rankName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 312)) = cume_distStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 320)) = cume_distValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 328)) = cume_distValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 336)) = cume_distInvFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 344)) = uintptr(unsafe.Pointer(&cume_distName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 384)) = ntileStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 392)) = ntileValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 400)) = ntileValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 408)) = ntileInvFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 416)) = uintptr(unsafe.Pointer(&ntileName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 456)) = last_valueStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 464)) = last_valueFinalizeFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 472)) = last_valueValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 480)) = last_valueInvFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 488)) = uintptr(unsafe.Pointer(&last_valueName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 528)) = nth_valueStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 536)) = nth_valueFinalizeFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 544)) = noopValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 552)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 560)) = uintptr(unsafe.Pointer(&nth_valueName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 600)) = first_valueStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 608)) = first_valueFinalizeFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 616)) = noopValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 624)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 632)) = uintptr(unsafe.Pointer(&first_valueName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 672)) = noopStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 680)) = noopValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 688)) = noopValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 696)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 704)) = uintptr(unsafe.Pointer(&leadName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 744)) = noopStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 752)) = noopValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 760)) = noopValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 768)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 776)) = uintptr(unsafe.Pointer(&leadName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 816)) = noopStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 824)) = noopValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 832)) = noopValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 840)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 848)) = uintptr(unsafe.Pointer(&leadName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 888)) = noopStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 896)) = noopValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 904)) = noopValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 912)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 920)) = uintptr(unsafe.Pointer(&lagName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 960)) = noopStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 968)) = noopValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 976)) = noopValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 984)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 992)) = uintptr(unsafe.Pointer(&lagName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 1032)) = noopStepFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 1040)) = noopValueFunc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 1048)) = noopValueFunc
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 1056)) = noopStepFunc
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&aWindowFuncs)) + 1064)) = uintptr(unsafe.Pointer(&lagName))
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&attach_func)) + 24)) = attachFunc
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 16)) = bytecodevtabConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 24)) = bytecodevtabBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 32)) = bytecodevtabDisconnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 48)) = bytecodevtabOpen
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 56)) = bytecodevtabClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 64)) = bytecodevtabFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 72)) = bytecodevtabNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 80)) = bytecodevtabEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 88)) = bytecodevtabColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&bytecodevtabModule)) + 96)) = bytecodevtabRowid
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 8)) = dbpageConnect
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 16)) = dbpageConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 24)) = dbpageBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 32)) = dbpageDisconnect
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 40)) = dbpageDisconnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 48)) = dbpageOpen
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 56)) = dbpageClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 64)) = dbpageFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 72)) = dbpageNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 80)) = dbpageEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 88)) = dbpageColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 96)) = dbpageRowid
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 104)) = dbpageUpdate
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbpage_module)) + 112)) = dbpageBegin
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 8)) = statConnect
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 16)) = statConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 24)) = statBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 32)) = statDisconnect
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 40)) = statDisconnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 48)) = statOpen
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 56)) = statClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 64)) = statFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 72)) = statNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 80)) = statEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 88)) = statColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dbstat_module)) + 96)) = statRowid
	*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods)) + 0)) = sqlite3MemMalloc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods)) + 8)) = sqlite3MemFree
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods)) + 16)) = sqlite3MemRealloc
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods)) + 24)) = sqlite3MemSize
	*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods)) + 32)) = sqlite3MemRoundup
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods)) + 40)) = sqlite3MemInit
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods)) + 48)) = sqlite3MemShutdown
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 16)) = pcache1Init
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 24)) = pcache1Shutdown
	*(*func(*libc.TLS, int32, int32, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 32)) = pcache1Create
	*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 40)) = pcache1Cachesize
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 48)) = pcache1Pagecount
	*(*func(*libc.TLS, uintptr, uint32, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 56)) = pcache1Fetch
	*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 64)) = pcache1Unpin
	*(*func(*libc.TLS, uintptr, uintptr, uint32, uint32))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 72)) = pcache1Rekey
	*(*func(*libc.TLS, uintptr, uint32))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 80)) = pcache1Truncate
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 88)) = pcache1Destroy
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&defaultMethods1)) + 96)) = pcache1Shrink
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&detach_func)) + 24)) = detachFunc
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoFinder)) + 0)) = dotlockIoFinderImpl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 8)) = dotlockClose
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 16)) = unixRead
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 24)) = unixWrite
	*(*func(*libc.TLS, uintptr, I64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 32)) = unixTruncate
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 40)) = unixSync
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 48)) = unixFileSize
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 56)) = dotlockLock
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 64)) = dotlockUnlock
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 72)) = dotlockCheckReservedLock
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 80)) = unixFileControl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 88)) = unixSectorSize
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 96)) = unixDeviceCharacteristics
	*(*func(*libc.TLS, uintptr, int32, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 112)) = unixShmLock
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 120)) = unixShmBarrier
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 128)) = unixShmUnmap
	*(*func(*libc.TLS, uintptr, I64, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 136)) = unixFetch
	*(*func(*libc.TLS, uintptr, I64, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&dotlockIoMethods)) + 144)) = unixUnfetch
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 8)) = fts5CreateMethod
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 16)) = fts5ConnectMethod
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 24)) = fts5BestIndexMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 32)) = fts5DisconnectMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 40)) = fts5DestroyMethod
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 48)) = fts5OpenMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 56)) = fts5CloseMethod
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 64)) = fts5FilterMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 72)) = fts5NextMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 80)) = fts5EofMethod
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 88)) = fts5ColumnMethod
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 96)) = fts5RowidMethod
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 104)) = fts5UpdateMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 112)) = fts5BeginMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 120)) = fts5SyncMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 128)) = fts5CommitMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 136)) = fts5RollbackMethod
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 144)) = fts5FindFunctionMethod
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 152)) = fts5RenameMethod
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 160)) = fts5SavepointMethod
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 168)) = fts5ReleaseMethod
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 176)) = fts5RollbackToMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Mod)) + 184)) = fts5ShadowName
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 8)) = fts5VocabCreateMethod
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 16)) = fts5VocabConnectMethod
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 24)) = fts5VocabBestIndexMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 32)) = fts5VocabDisconnectMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 40)) = fts5VocabDestroyMethod
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 48)) = fts5VocabOpenMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 56)) = fts5VocabCloseMethod
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 64)) = fts5VocabFilterMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 72)) = fts5VocabNextMethod
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 80)) = fts5VocabEofMethod
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 88)) = fts5VocabColumnMethod
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&fts5Vocab)) + 96)) = fts5VocabRowidMethod
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 8)) = geopolyCreate
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 16)) = geopolyConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 24)) = geopolyBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 32)) = rtreeDisconnect
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 40)) = rtreeDestroy
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 48)) = rtreeOpen
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 56)) = rtreeClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 64)) = geopolyFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 72)) = rtreeNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 80)) = rtreeEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 88)) = geopolyColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 96)) = rtreeRowid
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 104)) = geopolyUpdate
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 112)) = rtreeBeginTransaction
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 120)) = rtreeEndTransaction
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 128)) = rtreeEndTransaction
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 136)) = rtreeEndTransaction
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 144)) = geopolyFindFunction
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 152)) = rtreeRename
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 160)) = rtreeSavepoint
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&geopolyModule)) + 184)) = rtreeShadowName
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 16)) = jsonEachConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 24)) = jsonEachBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 32)) = jsonEachDisconnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 48)) = jsonEachOpenEach
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 56)) = jsonEachClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 64)) = jsonEachFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 72)) = jsonEachNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 80)) = jsonEachEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 88)) = jsonEachColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonEachModule)) + 96)) = jsonEachRowid
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 16)) = jsonEachConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 24)) = jsonEachBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 32)) = jsonEachDisconnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 48)) = jsonEachOpenTree
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 56)) = jsonEachClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 64)) = jsonEachFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 72)) = jsonEachNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 80)) = jsonEachEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 88)) = jsonEachColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&jsonTreeModule)) + 96)) = jsonEachRowid
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 8)) = memdbClose
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 16)) = memdbRead
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 24)) = memdbWrite
	*(*func(*libc.TLS, uintptr, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 32)) = memdbTruncate
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 40)) = memdbSync
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 48)) = memdbFileSize
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 56)) = memdbLock
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 64)) = memdbUnlock
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 80)) = memdbFileControl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 96)) = memdbDeviceCharacteristics
	*(*func(*libc.TLS, uintptr, Sqlite3_int64, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 136)) = memdbFetch
	*(*func(*libc.TLS, uintptr, Sqlite3_int64, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_io_methods)) + 144)) = memdbUnfetch
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 40)) = memdbOpen
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 56)) = memdbAccess
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 64)) = memdbFullPathname
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 72)) = memdbDlOpen
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 80)) = memdbDlError
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 88)) = memdbDlSym
	*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 96)) = memdbDlClose
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 104)) = memdbRandomness
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 112)) = memdbSleep
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 128)) = memdbGetLastError
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&memdb_vfs)) + 136)) = memdbCurrentTimeInt64
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoFinder)) + 0)) = nolockIoFinderImpl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 8)) = nolockClose
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 16)) = unixRead
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 24)) = unixWrite
	*(*func(*libc.TLS, uintptr, I64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 32)) = unixTruncate
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 40)) = unixSync
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 48)) = unixFileSize
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 56)) = nolockLock
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 64)) = nolockUnlock
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 72)) = nolockCheckReservedLock
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 80)) = unixFileControl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 88)) = unixSectorSize
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 96)) = unixDeviceCharacteristics
	*(*func(*libc.TLS, uintptr, int32, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 112)) = unixShmLock
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 120)) = unixShmBarrier
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 128)) = unixShmUnmap
	*(*func(*libc.TLS, uintptr, I64, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 136)) = unixFetch
	*(*func(*libc.TLS, uintptr, I64, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&nolockIoMethods)) + 144)) = unixUnfetch
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoFinder)) + 0)) = posixIoFinderImpl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 8)) = unixClose
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 16)) = unixRead
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 24)) = unixWrite
	*(*func(*libc.TLS, uintptr, I64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 32)) = unixTruncate
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 40)) = unixSync
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 48)) = unixFileSize
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 56)) = unixLock
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 64)) = unixUnlock
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 72)) = unixCheckReservedLock
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 80)) = unixFileControl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 88)) = unixSectorSize
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 96)) = unixDeviceCharacteristics
	*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 104)) = unixShmMap
	*(*func(*libc.TLS, uintptr, int32, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 112)) = unixShmLock
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 120)) = unixShmBarrier
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 128)) = unixShmUnmap
	*(*func(*libc.TLS, uintptr, I64, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 136)) = unixFetch
	*(*func(*libc.TLS, uintptr, I64, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&posixIoMethods)) + 144)) = unixUnfetch
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 16)) = pragmaVtabConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 24)) = pragmaVtabBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 32)) = pragmaVtabDisconnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 48)) = pragmaVtabOpen
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 56)) = pragmaVtabClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 64)) = pragmaVtabFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 72)) = pragmaVtabNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 80)) = pragmaVtabEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 88)) = pragmaVtabColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&pragmaVtabModule)) + 96)) = pragmaVtabRowid
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 8)) = rbuVfsClose
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 16)) = rbuVfsRead
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 24)) = rbuVfsWrite
	*(*func(*libc.TLS, uintptr, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 32)) = rbuVfsTruncate
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 40)) = rbuVfsSync
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 48)) = rbuVfsFileSize
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 56)) = rbuVfsLock
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 64)) = rbuVfsUnlock
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 72)) = rbuVfsCheckReservedLock
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 80)) = rbuVfsFileControl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 88)) = rbuVfsSectorSize
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 96)) = rbuVfsDeviceCharacteristics
	*(*func(*libc.TLS, uintptr, int32, int32, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 104)) = rbuVfsShmMap
	*(*func(*libc.TLS, uintptr, int32, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 112)) = rbuVfsShmLock
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 120)) = rbuVfsShmBarrier
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods)) + 128)) = rbuVfsShmUnmap
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 8)) = rbuVfsClose
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 16)) = rbuVfsRead
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 24)) = rbuVfsWrite
	*(*func(*libc.TLS, uintptr, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 32)) = rbuVfsTruncate
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 40)) = rbuVfsSync
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 48)) = rbuVfsFileSize
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 56)) = rbuVfsLock
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 64)) = rbuVfsUnlock
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 72)) = rbuVfsCheckReservedLock
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 80)) = rbuVfsFileControl
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 88)) = rbuVfsSectorSize
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rbuvfs_io_methods1)) + 96)) = rbuVfsDeviceCharacteristics
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 8)) = rtreeCreate
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 16)) = rtreeConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 24)) = rtreeBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 32)) = rtreeDisconnect
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 40)) = rtreeDestroy
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 48)) = rtreeOpen
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 56)) = rtreeClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 64)) = rtreeFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 72)) = rtreeNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 80)) = rtreeEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 88)) = rtreeColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 96)) = rtreeRowid
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 104)) = rtreeUpdate
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 112)) = rtreeBeginTransaction
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 120)) = rtreeEndTransaction
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 128)) = rtreeEndTransaction
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 136)) = rtreeEndTransaction
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 152)) = rtreeRename
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 160)) = rtreeSavepoint
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&rtreeModule)) + 184)) = rtreeShadowName
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 8)) = fts5ApiUserData
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 16)) = fts5ApiColumnCount
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 24)) = fts5ApiRowCount
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 32)) = fts5ApiColumnTotalSize
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 40)) = fts5ApiTokenize
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 48)) = fts5ApiPhraseCount
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 56)) = fts5ApiPhraseSize
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 64)) = fts5ApiInstCount
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 72)) = fts5ApiInst
	*(*func(*libc.TLS, uintptr) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 80)) = fts5ApiRowid
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 88)) = fts5ApiColumnText
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 96)) = fts5ApiColumnSize
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 104)) = fts5ApiQueryPhrase
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 112)) = fts5ApiSetAuxdata
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 120)) = fts5ApiGetAuxdata
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 128)) = fts5ApiPhraseFirst
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 136)) = fts5ApiPhraseNext
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 144)) = fts5ApiPhraseFirstColumn
	*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sFts5Api)) + 152)) = fts5ApiPhraseNextColumn
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMemJournalMethods)) + 8)) = memjrnlClose
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMemJournalMethods)) + 16)) = memjrnlRead
	*(*func(*libc.TLS, uintptr, uintptr, int32, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMemJournalMethods)) + 24)) = memjrnlWrite
	*(*func(*libc.TLS, uintptr, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMemJournalMethods)) + 32)) = memjrnlTruncate
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMemJournalMethods)) + 40)) = memjrnlSync
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMemJournalMethods)) + 48)) = memjrnlFileSize
	*(*func(*libc.TLS) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMutex)) + 0)) = noopMutexInit
	*(*func(*libc.TLS) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMutex)) + 8)) = noopMutexEnd
	*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMutex)) + 16)) = noopMutexAlloc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sMutex)) + 24)) = noopMutexFree
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sMutex)) + 32)) = noopMutexEnter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sMutex)) + 40)) = noopMutexTry
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sMutex)) + 48)) = noopMutexLeave
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 0)) = Xsqlite3_aggregate_context
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 8)) = Xsqlite3_aggregate_count
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 16)) = Xsqlite3_bind_blob
	*(*func(*libc.TLS, uintptr, int32, float64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 24)) = Xsqlite3_bind_double
	*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 32)) = Xsqlite3_bind_int
	*(*func(*libc.TLS, uintptr, int32, Sqlite_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 40)) = Xsqlite3_bind_int64
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 48)) = Xsqlite3_bind_null
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 56)) = Xsqlite3_bind_parameter_count
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 64)) = Xsqlite3_bind_parameter_index
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 72)) = Xsqlite3_bind_parameter_name
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 80)) = Xsqlite3_bind_text
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 88)) = Xsqlite3_bind_text16
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 96)) = Xsqlite3_bind_value
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 104)) = Xsqlite3_busy_handler
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 112)) = Xsqlite3_busy_timeout
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 120)) = Xsqlite3_changes
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 128)) = Xsqlite3_close
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 136)) = Xsqlite3_collation_needed
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 144)) = Xsqlite3_collation_needed16
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 152)) = Xsqlite3_column_blob
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 160)) = Xsqlite3_column_bytes
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 168)) = Xsqlite3_column_bytes16
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 176)) = Xsqlite3_column_count
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 184)) = Xsqlite3_column_database_name
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 192)) = Xsqlite3_column_database_name16
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 200)) = Xsqlite3_column_decltype
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 208)) = Xsqlite3_column_decltype16
	*(*func(*libc.TLS, uintptr, int32) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 216)) = Xsqlite3_column_double
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 224)) = Xsqlite3_column_int
	*(*func(*libc.TLS, uintptr, int32) Sqlite_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 232)) = Xsqlite3_column_int64
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 240)) = Xsqlite3_column_name
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 248)) = Xsqlite3_column_name16
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 256)) = Xsqlite3_column_origin_name
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 264)) = Xsqlite3_column_origin_name16
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 272)) = Xsqlite3_column_table_name
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 280)) = Xsqlite3_column_table_name16
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 288)) = Xsqlite3_column_text
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 296)) = Xsqlite3_column_text16
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 304)) = Xsqlite3_column_type
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 312)) = Xsqlite3_column_value
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 320)) = Xsqlite3_commit_hook
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 328)) = Xsqlite3_complete
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 336)) = Xsqlite3_complete16
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 344)) = Xsqlite3_create_collation
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 352)) = Xsqlite3_create_collation16
	*(*func(*libc.TLS, uintptr, uintptr, int32, int32, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 360)) = Xsqlite3_create_function
	*(*func(*libc.TLS, uintptr, uintptr, int32, int32, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 368)) = Xsqlite3_create_function16
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 376)) = Xsqlite3_create_module
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 384)) = Xsqlite3_data_count
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 392)) = Xsqlite3_db_handle
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 400)) = Xsqlite3_declare_vtab
	*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 408)) = Xsqlite3_enable_shared_cache
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 416)) = Xsqlite3_errcode
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 424)) = Xsqlite3_errmsg
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 432)) = Xsqlite3_errmsg16
	*(*func(*libc.TLS, uintptr, uintptr, Sqlite3_callback, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 440)) = Xsqlite3_exec
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 448)) = Xsqlite3_expired
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 456)) = Xsqlite3_finalize
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 464)) = Xsqlite3_free
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 472)) = Xsqlite3_free_table
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 480)) = Xsqlite3_get_autocommit
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 488)) = Xsqlite3_get_auxdata
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 496)) = Xsqlite3_get_table
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 512)) = Xsqlite3_interrupt
	*(*func(*libc.TLS, uintptr) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 520)) = Xsqlite3_last_insert_rowid
	*(*func(*libc.TLS) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 528)) = Xsqlite3_libversion
	*(*func(*libc.TLS) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 536)) = Xsqlite3_libversion_number
	*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 544)) = Xsqlite3_malloc
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 552)) = Xsqlite3_mprintf
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 560)) = Xsqlite3_open
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 568)) = Xsqlite3_open16
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 576)) = Xsqlite3_prepare
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 584)) = Xsqlite3_prepare16
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 592)) = Xsqlite3_profile
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 600)) = Xsqlite3_progress_handler
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 608)) = Xsqlite3_realloc
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 616)) = Xsqlite3_reset
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 624)) = Xsqlite3_result_blob
	*(*func(*libc.TLS, uintptr, float64))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 632)) = Xsqlite3_result_double
	*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 640)) = Xsqlite3_result_error
	*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 648)) = Xsqlite3_result_error16
	*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 656)) = Xsqlite3_result_int
	*(*func(*libc.TLS, uintptr, I64))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 664)) = Xsqlite3_result_int64
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 672)) = Xsqlite3_result_null
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 680)) = Xsqlite3_result_text
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 688)) = Xsqlite3_result_text16
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 696)) = Xsqlite3_result_text16be
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 704)) = Xsqlite3_result_text16le
	*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 712)) = Xsqlite3_result_value
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 720)) = Xsqlite3_rollback_hook
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 728)) = Xsqlite3_set_authorizer
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 736)) = Xsqlite3_set_auxdata
	*(*func(*libc.TLS, int32, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 744)) = Xsqlite3_snprintf
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 752)) = Xsqlite3_step
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 760)) = Xsqlite3_table_column_metadata
	*(*func(*libc.TLS))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 768)) = Xsqlite3_thread_cleanup
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 776)) = Xsqlite3_total_changes
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 784)) = Xsqlite3_trace
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 792)) = Xsqlite3_transfer_bindings
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 800)) = Xsqlite3_update_hook
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 808)) = Xsqlite3_user_data
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 816)) = Xsqlite3_value_blob
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 824)) = Xsqlite3_value_bytes
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 832)) = Xsqlite3_value_bytes16
	*(*func(*libc.TLS, uintptr) float64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 840)) = Xsqlite3_value_double
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 848)) = Xsqlite3_value_int
	*(*func(*libc.TLS, uintptr) Sqlite_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 856)) = Xsqlite3_value_int64
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 864)) = Xsqlite3_value_numeric_type
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 872)) = Xsqlite3_value_text
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 880)) = Xsqlite3_value_text16
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 888)) = Xsqlite3_value_text16be
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 896)) = Xsqlite3_value_text16le
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 904)) = Xsqlite3_value_type
	*(*func(*libc.TLS, uintptr, Va_list) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 912)) = Xsqlite3_vmprintf
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 920)) = Xsqlite3_overload_function
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 928)) = Xsqlite3_prepare_v2
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 936)) = Xsqlite3_prepare16_v2
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 944)) = Xsqlite3_clear_bindings
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 952)) = Xsqlite3_create_module_v2
	*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 960)) = Xsqlite3_bind_zeroblob
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 968)) = Xsqlite3_blob_bytes
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 976)) = Xsqlite3_blob_close
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr, Sqlite_int64, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 984)) = Xsqlite3_blob_open
	*(*func(*libc.TLS, uintptr, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 992)) = Xsqlite3_blob_read
	*(*func(*libc.TLS, uintptr, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1000)) = Xsqlite3_blob_write
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1008)) = Xsqlite3_create_collation_v2
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1016)) = Xsqlite3_file_control
	*(*func(*libc.TLS, int32) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1024)) = Xsqlite3_memory_highwater
	*(*func(*libc.TLS) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1032)) = Xsqlite3_memory_used
	*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1040)) = Xsqlite3_mutex_alloc
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1048)) = Xsqlite3_mutex_enter
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1056)) = Xsqlite3_mutex_free
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1064)) = Xsqlite3_mutex_leave
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1072)) = Xsqlite3_mutex_try
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1080)) = Xsqlite3_open_v2
	*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1088)) = Xsqlite3_release_memory
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1096)) = Xsqlite3_result_error_nomem
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1104)) = Xsqlite3_result_error_toobig
	*(*func(*libc.TLS, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1112)) = Xsqlite3_sleep
	*(*func(*libc.TLS, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1120)) = Xsqlite3_soft_heap_limit
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1128)) = Xsqlite3_vfs_find
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1136)) = Xsqlite3_vfs_register
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1144)) = Xsqlite3_vfs_unregister
	*(*func(*libc.TLS) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1152)) = Xsqlite3_threadsafe
	*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1160)) = Xsqlite3_result_zeroblob
	*(*func(*libc.TLS, uintptr, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1168)) = Xsqlite3_result_error_code
	*(*func(*libc.TLS, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1176)) = Xsqlite3_test_control
	*(*func(*libc.TLS, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1184)) = Xsqlite3_randomness
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1192)) = Xsqlite3_context_db_handle
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1200)) = Xsqlite3_extended_result_codes
	*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1208)) = Xsqlite3_limit
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1216)) = Xsqlite3_next_stmt
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1224)) = Xsqlite3_sql
	*(*func(*libc.TLS, int32, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1232)) = Xsqlite3_status
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1240)) = Xsqlite3_backup_finish
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1248)) = Xsqlite3_backup_init
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1256)) = Xsqlite3_backup_pagecount
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1264)) = Xsqlite3_backup_remaining
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1272)) = Xsqlite3_backup_step
	*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1280)) = Xsqlite3_compileoption_get
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1288)) = Xsqlite3_compileoption_used
	*(*func(*libc.TLS, uintptr, uintptr, int32, int32, uintptr, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1296)) = Xsqlite3_create_function_v2
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1304)) = Xsqlite3_db_config
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1312)) = Xsqlite3_db_mutex
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1320)) = Xsqlite3_db_status
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1328)) = Xsqlite3_extended_errcode
	*(*func(*libc.TLS, int32, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1336)) = Xsqlite3_log
	*(*func(*libc.TLS, Sqlite3_int64) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1344)) = Xsqlite3_soft_heap_limit64
	*(*func(*libc.TLS) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1352)) = Xsqlite3_sourceid
	*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1360)) = Xsqlite3_stmt_status
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1368)) = Xsqlite3_strnicmp
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1376)) = Xsqlite3_unlock_notify
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1384)) = Xsqlite3_wal_autocheckpoint
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1392)) = Xsqlite3_wal_checkpoint
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1400)) = Xsqlite3_wal_hook
	*(*func(*libc.TLS, uintptr, Sqlite3_int64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1408)) = Xsqlite3_blob_reopen
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1416)) = Xsqlite3_vtab_config
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1424)) = Xsqlite3_vtab_on_conflict
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1432)) = Xsqlite3_close_v2
	*(*func(*libc.TLS, uintptr, uintptr) Sqlite3_filename)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1440)) = Xsqlite3_db_filename
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1448)) = Xsqlite3_db_readonly
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1456)) = Xsqlite3_db_release_memory
	*(*func(*libc.TLS, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1464)) = Xsqlite3_errstr
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1472)) = Xsqlite3_stmt_busy
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1480)) = Xsqlite3_stmt_readonly
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1488)) = Xsqlite3_stricmp
	*(*func(*libc.TLS, Sqlite3_filename, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1496)) = Xsqlite3_uri_boolean
	*(*func(*libc.TLS, Sqlite3_filename, uintptr, Sqlite3_int64) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1504)) = Xsqlite3_uri_int64
	*(*func(*libc.TLS, Sqlite3_filename, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1512)) = Xsqlite3_uri_parameter
	*(*func(*libc.TLS, int32, uintptr, uintptr, Va_list) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1520)) = Xsqlite3_vsnprintf
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1528)) = Xsqlite3_wal_checkpoint_v2
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1536)) = Xsqlite3_auto_extension
	*(*func(*libc.TLS, uintptr, int32, uintptr, Sqlite3_uint64, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1544)) = Xsqlite3_bind_blob64
	*(*func(*libc.TLS, uintptr, int32, uintptr, Sqlite3_uint64, uintptr, uint8) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1552)) = Xsqlite3_bind_text64
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1560)) = Xsqlite3_cancel_auto_extension
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1568)) = Xsqlite3_load_extension
	*(*func(*libc.TLS, Sqlite3_uint64) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1576)) = Xsqlite3_malloc64
	*(*func(*libc.TLS, uintptr) Sqlite3_uint64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1584)) = Xsqlite3_msize
	*(*func(*libc.TLS, uintptr, Sqlite3_uint64) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1592)) = Xsqlite3_realloc64
	*(*func(*libc.TLS))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1600)) = Xsqlite3_reset_auto_extension
	*(*func(*libc.TLS, uintptr, uintptr, Sqlite3_uint64, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1608)) = Xsqlite3_result_blob64
	*(*func(*libc.TLS, uintptr, uintptr, Sqlite3_uint64, uintptr, uint8))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1616)) = Xsqlite3_result_text64
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1624)) = Xsqlite3_strglob
	*(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1632)) = *(*uintptr)(unsafe.Pointer(&struct {
		f func(*libc.TLS, uintptr) uintptr
	}{Xsqlite3_value_dup}))
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1640)) = Xsqlite3_value_free
	*(*func(*libc.TLS, uintptr, U64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1648)) = Xsqlite3_result_zeroblob64
	*(*func(*libc.TLS, uintptr, int32, Sqlite3_uint64) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1656)) = Xsqlite3_bind_zeroblob64
	*(*func(*libc.TLS, uintptr) uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1664)) = Xsqlite3_value_subtype
	*(*func(*libc.TLS, uintptr, uint32))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1672)) = Xsqlite3_result_subtype
	*(*func(*libc.TLS, int32, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1680)) = Xsqlite3_status64
	*(*func(*libc.TLS, uintptr, uintptr, uint32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1688)) = Xsqlite3_strlike
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1696)) = Xsqlite3_db_cacheflush
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1704)) = Xsqlite3_system_errno
	*(*func(*libc.TLS, uintptr, uint32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1712)) = Xsqlite3_trace_v2
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1720)) = Xsqlite3_expanded_sql
	*(*func(*libc.TLS, uintptr, Sqlite3_int64))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1728)) = Xsqlite3_set_last_insert_rowid
	*(*func(*libc.TLS, uintptr, uintptr, int32, uint32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1736)) = Xsqlite3_prepare_v3
	*(*func(*libc.TLS, uintptr, uintptr, int32, uint32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1744)) = Xsqlite3_prepare16_v3
	*(*func(*libc.TLS, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1752)) = Xsqlite3_bind_pointer
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1760)) = Xsqlite3_result_pointer
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1768)) = Xsqlite3_value_pointer
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1776)) = Xsqlite3_vtab_nochange
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1784)) = Xsqlite3_value_nochange
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1792)) = Xsqlite3_vtab_collation
	*(*func(*libc.TLS) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1800)) = Xsqlite3_keyword_count
	*(*func(*libc.TLS, int32, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1808)) = Xsqlite3_keyword_name
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1816)) = Xsqlite3_keyword_check
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1824)) = Xsqlite3_str_new
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1832)) = Xsqlite3_str_finish
	*(*func(*libc.TLS, uintptr, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1840)) = Xsqlite3_str_appendf
	*(*func(*libc.TLS, uintptr, uintptr, Va_list))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1848)) = Xsqlite3_str_vappendf
	*(*func(*libc.TLS, uintptr, uintptr, int32))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1856)) = Xsqlite3_str_append
	*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1864)) = Xsqlite3_str_appendall
	*(*func(*libc.TLS, uintptr, int32, uint8))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1872)) = Xsqlite3_str_appendchar
	*(*func(*libc.TLS, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1880)) = Xsqlite3_str_reset
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1888)) = Xsqlite3_str_errcode
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1896)) = Xsqlite3_str_length
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1904)) = Xsqlite3_str_value
	*(*func(*libc.TLS, uintptr, uintptr, int32, int32, uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1912)) = Xsqlite3_create_window_function
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1928)) = Xsqlite3_stmt_isexplain
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1936)) = Xsqlite3_value_frombind
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1944)) = Xsqlite3_drop_modules
	*(*func(*libc.TLS, Sqlite3_int64) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1952)) = Xsqlite3_hard_heap_limit64
	*(*func(*libc.TLS, Sqlite3_filename, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1960)) = Xsqlite3_uri_key
	*(*func(*libc.TLS, Sqlite3_filename) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1968)) = Xsqlite3_filename_database
	*(*func(*libc.TLS, Sqlite3_filename) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1976)) = Xsqlite3_filename_journal
	*(*func(*libc.TLS, Sqlite3_filename) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1984)) = Xsqlite3_filename_wal
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) Sqlite3_filename)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 1992)) = Xsqlite3_create_filename
	*(*func(*libc.TLS, Sqlite3_filename))(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2000)) = Xsqlite3_free_filename
	*(*func(*libc.TLS, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2008)) = Xsqlite3_database_file_object
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2016)) = Xsqlite3_txn_state
	*(*func(*libc.TLS, uintptr) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2024)) = Xsqlite3_changes64
	*(*func(*libc.TLS, uintptr) Sqlite3_int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2032)) = Xsqlite3_total_changes64
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2040)) = Xsqlite3_autovacuum_pages
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2048)) = Xsqlite3_error_offset
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2056)) = Xsqlite3_vtab_rhs_value
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2064)) = Xsqlite3_vtab_distinct
	*(*func(*libc.TLS, uintptr, int32, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2072)) = Xsqlite3_vtab_in
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2080)) = Xsqlite3_vtab_in_first
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2088)) = Xsqlite3_vtab_in_next
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, Sqlite3_int64, Sqlite3_int64, uint32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2096)) = Xsqlite3_deserialize
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, uint32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2104)) = Xsqlite3_serialize
	*(*func(*libc.TLS, uintptr, int32) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2112)) = Xsqlite3_db_name
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2120)) = Xsqlite3_value_encoding
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3Apis)) + 2128)) = Xsqlite3_is_interrupted
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3BuiltinExtensions)) + 0)) = Xsqlite3Fts5Init
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3BuiltinExtensions)) + 8)) = Xsqlite3RtreeInit
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3BuiltinExtensions)) + 16)) = Xsqlite3DbpageRegister
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3BuiltinExtensions)) + 24)) = Xsqlite3DbstatRegister
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3BuiltinExtensions)) + 32)) = sqlite3TestExtInit
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3BuiltinExtensions)) + 40)) = Xsqlite3JsonTableFunctions
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3BuiltinExtensions)) + 48)) = Xsqlite3StmtVtabInit
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&sqlite3BuiltinExtensions)) + 56)) = Xsqlite3VdbeBytecodeVtabInit
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&statGetFuncdef)) + 24)) = statGet
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&statInitFuncdef)) + 24)) = statInit
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&statPushFuncdef)) + 24)) = statPush
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 16)) = stmtConnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 24)) = stmtBestIndex
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 32)) = stmtDisconnect
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 48)) = stmtOpen
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 56)) = stmtClose
	*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 64)) = stmtFilter
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 72)) = stmtNext
	*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 80)) = stmtEof
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 88)) = stmtColumn
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&stmtModule)) + 96)) = stmtRowid
	*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 40)) = rbuVfsOpen
	*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 48)) = rbuVfsDelete
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 56)) = rbuVfsAccess
	*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 64)) = rbuVfsFullPathname
	*(*func(*libc.TLS, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 72)) = rbuVfsDlOpen
	*(*func(*libc.TLS, uintptr, int32, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 80)) = rbuVfsDlError
	*(*func(*libc.TLS, uintptr, uintptr, uintptr) uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 88)) = rbuVfsDlSym
	*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 96)) = rbuVfsDlClose
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 104)) = rbuVfsRandomness
	*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 112)) = rbuVfsSleep
	*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 120)) = rbuVfsCurrentTime
	*(*func(*libc.TLS, uintptr, int32, uintptr) int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&vfs_template)) + 128)) = rbuVfsGetLastError
}

var ts1 = "3.41.2\x00ATOMIC_INTRINSICS=1\x00COMPILER=gcc-10.2.1 20210110\x00DEFAULT_AUTOVACUUM\x00DEFAULT_CACHE_SIZE=-2000\x00DEFAULT_FILE_FORMAT=4\x00DEFAULT_JOURNAL_SIZE_LIMIT=-1\x00DEFAULT_MMAP_SIZE=0\x00DEFAULT_PAGE_SIZE=1024\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\x00ENABLE_BYTECODE_VTAB\x00ENABLE_COLUMN_METADATA\x00ENABLE_DBPAGE_VTAB\x00ENABLE_DBSTAT_VTAB\x00ENABLE_EXPLAIN_COMMENTS\x00ENABLE_FTS5\x00ENABLE_GEOPOLY\x00ENABLE_MATH_FUNCTIONS\x00ENABLE_MEMORY_MANAGEMENT\x00ENABLE_OFFSET_SQL_FUNC\x00ENABLE_PREUPDATE_HOOK\x00ENABLE_RBU\x00ENABLE_RTREE\x00ENABLE_SESSION\x00ENABLE_STAT4\x00ENABLE_STMTVTAB\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=1073741823\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_NOOP\x00NEED_ERR_NAME\x00SOUNDEX\x00SYSTEM_MALLOC\x00TEMP_STORE=1\x00TEST\x00THREADSAFE=1\x00BINARY\x00ANY\x00BLOB\x00INT\x00INTEGER\x00REAL\x00TEXT\x0020b:20e\x0020c:20e\x0020e\x0040f-21a-21d\x00now\x00local time unavailable\x00second\x00minute\x00hour\x00\x00\x00day\x00\x00\x00\x00month\x00\x00year\x00\x00\x00auto\x00julianday\x00localtime\x00unixepoch\x00utc\x00weekday \x00start of \x00month\x00year\x00day\x00%02d\x00%06.3f\x00%03d\x00%.16g\x00%lld\x00%04d\x00date\x00time\x00datetime\x00strftime\x00current_time\x00current_timestamp\x00current_date\x00failed to allocate %u bytes of memory\x00failed memory resize %u to %u bytes\x00out of memory\x000123456789ABCDEF0123456789abcdef\x00-x0\x00X0\x00%\x00NaN\x00Inf\x00\x00NULL\x00(NULL)\x00.\x00(join-%u)\x00(subquery-%u)\x00thstndrd\x00%s\x00922337203685477580\x00API call with %s database connection pointer\x00unopened\x00invalid\x00Savepoint\x00\x00AutoCommit\x00\x00Transaction\x00\x00Checkpoint\x00\x00JournalMode\x00\x00Vacuum\x00\x00VFilter\x00iplan=r[P3] zplan='P4'\x00VUpdate\x00data=r[P3@P2]\x00Init\x00Start at P2\x00Goto\x00\x00Gosub\x00\x00InitCoroutine\x00\x00Yield\x00\x00MustBeInt\x00\x00Jump\x00\x00Once\x00\x00If\x00\x00IfNot\x00\x00IsType\x00if typeof(P1.P3) in P5 goto P2\x00Not\x00r[P2]= !r[P1]\x00IfNullRow\x00if P1.nullRow then r[P3]=NULL, goto P2\x00SeekLT\x00key=r[P3@P4]\x00SeekLE\x00key=r[P3@P4]\x00SeekGE\x00key=r[P3@P4]\x00SeekGT\x00key=r[P3@P4]\x00IfNotOpen\x00if( !csr[P1] ) goto P2\x00IfNoHope\x00key=r[P3@P4]\x00NoConflict\x00key=r[P3@P4]\x00NotFound\x00key=r[P3@P4]\x00Found\x00key=r[P3@P4]\x00SeekRowid\x00intkey=r[P3]\x00NotExists\x00intkey=r[P3]\x00Last\x00\x00IfSmaller\x00\x00SorterSort\x00\x00Sort\x00\x00Rewind\x00\x00SorterNext\x00\x00Prev\x00\x00Next\x00\x00IdxLE\x00key=r[P3@P4]\x00IdxGT\x00key=r[P3@P4]\x00IdxLT\x00key=r[P3@P4]\x00Or\x00r[P3]=(r[P1] || r[P2])\x00And\x00r[P3]=(r[P1] && r[P2])\x00IdxGE\x00key=r[P3@P4]\x00RowSetRead\x00r[P3]=rowset(P1)\x00RowSetTest\x00if r[P3] in rowset(P1) goto P2\x00Program\x00\x00FkIfZero\x00if fkctr[P1]==0 goto P2\x00IsNull\x00if r[P1]==NULL goto P2\x00NotNull\x00if r[P1]!=NULL goto P2\x00Ne\x00IF r[P3]!=r[P1]\x00Eq\x00IF r[P3]==r[P1]\x00Gt\x00IF r[P3]>r[P1]\x00Le\x00IF r[P3]<=r[P1]\x00Lt\x00IF r[P3]<r[P1]\x00Ge\x00IF r[P3]>=r[P1]\x00ElseEq\x00\x00IfPos\x00if r[P1]>0 then r[P1]-=P3, goto P2\x00IfNotZero\x00if r[P1]!=0 then r[P1]--, goto P2\x00DecrJumpZero\x00if (--r[P1])==0 goto P2\x00IncrVacuum\x00\x00VNext\x00\x00Filter\x00if key(P3@P4) not in filter(P1) goto P2\x00PureFunc\x00r[P3]=func(r[P2@NP])\x00Function\x00r[P3]=func(r[P2@NP])\x00Return\x00\x00EndCoroutine\x00\x00HaltIfNull\x00if r[P3]=null halt\x00Halt\x00\x00Integer\x00r[P2]=P1\x00Int64\x00r[P2]=P4\x00String\x00r[P2]='P4' (len=P1)\x00BeginSubrtn\x00r[P2]=NULL\x00Null\x00r[P2..P3]=NULL\x00SoftNull\x00r[P1]=NULL\x00Blob\x00r[P2]=P4 (len=P1)\x00Variable\x00r[P2]=parameter(P1,P4)\x00Move\x00r[P2@P3]=r[P1@P3]\x00Copy\x00r[P2@P3+1]=r[P1@P3+1]\x00SCopy\x00r[P2]=r[P1]\x00IntCopy\x00r[P2]=r[P1]\x00FkCheck\x00\x00ResultRow\x00output=r[P1@P2]\x00CollSeq\x00\x00AddImm\x00r[P1]=r[P1]+P2\x00RealAffinity\x00\x00Cast\x00affinity(r[P1])\x00Permutation\x00\x00Compare\x00r[P1@P3] <-> r[P2@P3]\x00IsTrue\x00r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4\x00ZeroOrNull\x00r[P2] = 0 OR NULL\x00Offset\x00r[P3] = sqlite_offset(P1)\x00Column\x00r[P3]=PX cursor P1 column P2\x00TypeCheck\x00typecheck(r[P1@P2])\x00Affinity\x00affinity(r[P1@P2])\x00MakeRecord\x00r[P3]=mkrec(r[P1@P2])\x00Count\x00r[P2]=count()\x00ReadCookie\x00\x00SetCookie\x00\x00ReopenIdx\x00root=P2 iDb=P3\x00BitAnd\x00r[P3]=r[P1]&r[P2]\x00BitOr\x00r[P3]=r[P1]|r[P2]\x00ShiftLeft\x00r[P3]=r[P2]<<r[P1]\x00ShiftRight\x00r[P3]=r[P2]>>r[P1]\x00Add\x00r[P3]=r[P1]+r[P2]\x00Subtract\x00r[P3]=r[P2]-r[P1]\x00Multiply\x00r[P3]=r[P1]*r[P2]\x00Divide\x00r[P3]=r[P2]/r[P1]\x00Remainder\x00r[P3]=r[P2]%r[P1]\x00Concat\x00r[P3]=r[P2]+r[P1]\x00OpenRead\x00root=P2 iDb=P3\x00OpenWrite\x00root=P2 iDb=P3\x00BitNot\x00r[P2]= ~r[P1]\x00OpenDup\x00\x00OpenAutoindex\x00nColumn=P2\x00String8\x00r[P2]='P4'\x00OpenEphemeral\x00nColumn=P2\x00SorterOpen\x00\x00SequenceTest\x00if( cursor[P1].ctr++ ) pc = P2\x00OpenPseudo\x00P3 columns in r[P2]\x00Close\x00\x00ColumnsUsed\x00\x00SeekScan\x00Scan-ahead up to P1 rows\x00SeekHit\x00set P2<=seekHit<=P3\x00Sequence\x00r[P2]=cursor[P1].ctr++\x00NewRowid\x00r[P2]=rowid\x00Insert\x00intkey=r[P3] data=r[P2]\x00RowCell\x00\x00Delete\x00\x00ResetCount\x00\x00SorterCompare\x00if key(P1)!=trim(r[P3],P4) goto P2\x00SorterData\x00r[P2]=data\x00RowData\x00r[P2]=data\x00Rowid\x00r[P2]=PX rowid of P1\x00NullRow\x00\x00SeekEnd\x00\x00IdxInsert\x00key=r[P2]\x00SorterInsert\x00key=r[P2]\x00IdxDelete\x00key=r[P2@P3]\x00DeferredSeek\x00Move P3 to P1.rowid if needed\x00IdxRowid\x00r[P2]=rowid\x00FinishSeek\x00\x00Destroy\x00\x00Clear\x00\x00ResetSorter\x00\x00CreateBtree\x00r[P2]=root iDb=P1 flags=P3\x00SqlExec\x00\x00ParseSchema\x00\x00LoadAnalysis\x00\x00DropTable\x00\x00DropIndex\x00\x00Real\x00r[P2]=P4\x00DropTrigger\x00\x00IntegrityCk\x00\x00RowSetAdd\x00rowset(P1)=r[P2]\x00Param\x00\x00FkCounter\x00fkctr[P1]+=P2\x00MemMax\x00r[P1]=max(r[P1],r[P2])\x00OffsetLimit\x00if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)\x00AggInverse\x00accum=r[P3] inverse(r[P2@P5])\x00AggStep\x00accum=r[P3] step(r[P2@P5])\x00AggStep1\x00accum=r[P3] step(r[P2@P5])\x00AggValue\x00r[P3]=value N=P2\x00AggFinal\x00accum=r[P1] N=P2\x00Expire\x00\x00CursorLock\x00\x00CursorUnlock\x00\x00TableLock\x00iDb=P1 root=P2 write=P3\x00VBegin\x00\x00VCreate\x00\x00VDestroy\x00\x00VOpen\x00\x00VInitIn\x00r[P2]=ValueList(P1,P3)\x00VColumn\x00r[P3]=vcolumn(P2)\x00VRename\x00\x00Pagecount\x00\x00MaxPgcnt\x00\x00ClrSubtype\x00r[P1].subtype = 0\x00FilterAdd\x00filter(P1) += key(P3@P4)\x00Trace\x00\x00CursorHint\x00\x00ReleaseReg\x00release r[P1@P2] mask P3\x00Noop\x00\x00Explain\x00\x00Abortable\x00\x00open\x00close\x00access\x00getcwd\x00stat\x00fstat\x00ftruncate\x00fcntl\x00read\x00pread\x00pread64\x00write\x00pwrite\x00pwrite64\x00fchmod\x00fallocate\x00unlink\x00openDirectory\x00mkdir\x00rmdir\x00fchown\x00geteuid\x00mmap\x00munmap\x00mremap\x00getpagesize\x00readlink\x00lstat\x00ioctl\x00attempt to open \"%s\" as file descriptor %d\x00/dev/null\x00NONE\x00SHARED\x00RESERVED\x00PENDING\x00EXCLUSIVE\x00ERROR\x00os_unix.c:%d: (%d) %s(%s) - %s\x00cannot fstat db file %s\x00file unlinked while open: %s\x00multiple links to file: %s\x00file renamed while open: %s\x00TEST WR-LOCK %d %d %d (unix)\n\x00LOCK    %d %s was %s(%s,%d) pid=%d (unix)\n\x00LOCK    %d %s ok (already held) (unix)\n\x00LOCK    %d %s %s (unix)\n\x00ok\x00failed\x00UNLOCK  %d %d was %d(%d,%d) pid=%d (unix)\n\x00CLOSE   %-3d\n\x00TEST WR-LOCK %d %d %d (dotlock)\n\x00UNLOCK  %d %d was %d pid=%d (dotlock)\n\x00READ    %-3d %5d %7lld %llu\n\x00WRITE   %-3d %5d %7lld %llu\n\x00OPENDIR %-3d %s\n\x00SYNC    %-3d\n\x00full_fsync\x00DIRSYNC %s (have_fullfsync=%d fullsync=%d)\n\x00%s-shm\x00readonly_shm\x00SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n\x00OPEN    %-3d %s\n\x00psow\x00unix-excl\x00%s.lock\x00/var/tmp\x00/usr/tmp\x00/tmp\x00SQLITE_TMPDIR\x00TMPDIR\x00%s/etilqs_%llx%c\x00modeof\x00OPENX   %-3d %s 0%o\n\x00fsync\x00unix\x00unix-none\x00unix-dotfile\x00memdb\x00memdb(%p,%lld)\x00PRAGMA \"%w\".page_count\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\x00SQLite format 3\x00:memory:\x00@  \x00\n\x00invalid page number %d\x002nd reference to page %d\x00Failed to read ptrmap key=%d\x00Bad ptr map entry key=%d expected=(%d,%d) got=(%d,%d)\x00failed to get page %d\x00freelist leaf count too big on page %d\x00%s is %d but should be %d\x00size\x00overflow list length\x00Page %u: \x00unable to get the page. error code=%d\x00btreeInitPage() returns error code %d\x00free space corruption\x00On tree page %u cell %d: \x00On page %u at right child: \x00Offset %d out of range %d..%d\x00Extends off end of page\x00Rowid %lld out of order\x00Child page depth differs\x00Multiple uses for byte %u of page %u\x00Fragmentation of %d bytes reported as %d on page %u\x00Main freelist: \x00max rootpage (%d) disagrees with header (%d)\x00incremental_vacuum enabled with a max rootpage of zero\x00Page %d is never used\x00Pointer map page %d is referenced\x00unknown database %s\x00destination database is in use\x00source and destination must be distinct\x00%!.15g\x00-\x00%s%s\x00IF \x00if %s goto P2\x00@P\x00+1\x00%d\x00%d..%d\x00@NP\x00..P3\x00; %s\x00k(%d\x00B\x00,%s%s%s\x00N.\x00)\x00%.18s-%s\x00%s(%d)\x00(blob)\x00vtab:%p\x00%c%u\x00]\x00program\x00?\x008\x0016LE\x0016BE\x00addr\x00opcode\x00p1\x00p2\x00p3\x00p4\x00p5\x00comment\x00id\x00parent\x00notused\x00detail\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\x00bind on a busy prepared statement: [%s]\x00-- \x00'%.*q'\x00zeroblob(%d)\x00x'\x00%02x\x00'\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\x00cannot change %s wal mode from within a transaction\x00into\x00out of\x00database table is locked: %s\x00ValueList\x00-- %s\x00statement aborts at %d: [%s] %s\x00NOT NULL\x00UNIQUE\x00CHECK\x00FOREIGN KEY\x00cannot open value of type %s\x00null\x00real\x00integer\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\x00CREATE TABLE x(addr INT,opcode TEXT,p1 INT,p2 INT,p3 INT,p4 TEXT,p5 INT,comment TEXT,subprog TEXT,stmt HIDDEN);\x00CREATE TABLE x(type TEXT,schema TEXT,name TEXT,wr INT,subprog TEXT,stmt HIDDEN);\x00table\x00index\x00(FK)\x00stmt-pointer\x00argument to %s() is not a valid SQL statement\x00tables_used\x00bytecode\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\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)\x00IN(...) element has %d term%s - expected %d\x00s\x000\x00too many arguments on function %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\x00first_entry_in(%d)\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\x00Result of SELECT %u\x00RHS of IN operator\x00%sLIST SUBQUERY %d\x00CORRELATED \x00REUSE SUBQUERY %d\x00%sSCALAR SUBQUERY %d\x00Init subquery result\x00Init EXISTS result\x001\x00begin IN expr\x00end IN expr\x000x\x00hex literal too big: %s%#T\x00%s.rowid\x00generated column loop on \"%s\"\x00blob\x00text\x00numeric\x00flexnum\x00none\x00%s expr-column %d\x00%s.%s\x00misuse of aggregate: %#T()\x00unknown function: %#T()\x00r[%d]=%s.%s\x00rowid\x00RAISE() may only be used within a trigger-program\x00B\x00C\x00D\x00E\x00F\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\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') ELSE raise(ABORT,'NOT NULL constraint failed') END  FROM pragma_quick_check(%Q,%Q) WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'\x00virtual tables may not be altered\x00Cannot add a column to a view\x00sqlite_altertab_%s\x00view\x00virtual table\x00cannot %s %s \"%s\"\x00drop column from\x00rename columns of\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')\x00error in %s %s%s%s: %s\x00 \x00CREATE \x00\"%w\" \x00%Q%s\x00%.*s%s\x00cannot drop %s column: \"%s\"\x00PRIMARY KEY\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\x00CREATE TABLE %Q.%s(%s)\x00DELETE FROM %Q.%s WHERE %s=%Q\x00DELETE FROM %Q.%s\x00sqlite_stat1\x00tbl,idx,stat\x00sqlite_stat4\x00tbl,idx,neq,nlt,ndlt,sample\x00sqlite_stat3\x00stat_init\x00stat_push\x00%llu\x00 %llu\x00%llu \x00stat_get\x00%s.expr(%d)\x00sqlite\\_%\x00Analysis for %s.%s\x00BBB\x00idx\x00tbl\x00unordered*\x00sz=[0-9]*\x00noskipscan*\x00SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx\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.%z\x00access to %z is prohibited\x00not authorized\x00usesStmtJournal=%d\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\x00sqlite_returning\x00cannot use RETURNING in a trigger\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'\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'\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\x00unsupported use of NULLS %s\x00FIRST\x00LAST\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\x00CREATE%s INDEX %.*s\x00 UNIQUE\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\x00a JOIN clause is required before %s\x00ON\x00USING\x00BEGIN\x00ROLLBACK\x00COMMIT\x00RELEASE\x00unable to open a temporary database file for storing temporary tables\x00index '%q'\x00, \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%!.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\x00instr\x00printf\x00format\x00unicode\x00char\x00abs\x00round\x00upper\x00lower\x00hex\x00unhex\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\x00glob\x00ceil\x00ceiling\x00floor\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\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\x00trigger count\x00defer IPK REPLACE until last\x00uniqueness check for ROWID\x00prep index %s\x00%s column %d\x00for %s\x00bypass recheck\x00Do IPK REPLACE\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]\x00so\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\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_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\x00lock_status\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\x00onoffalseyestruextrafull\x00exclusive\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\x00w\x00a\x00sissii\x00utf8\x00utf16le\x00utf16be\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\x00siX\x00*** in database %s ***\n\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 \x00wrong # of entries in index \x00unsupported encoding: %s\x00restart\x00ANALYZE \"%w\".\"%w\"\x00unknown\x00closed\x00ss\x00UTF8\x00UTF-8\x00UTF-16le\x00UTF-16be\x00UTF16le\x00UTF16be\x00UTF-16\x00UTF16\x00unlocked\x00shared\x00reserved\x00pending\x00CREATE TABLE x\x00%c\"%s\"\x00(\"%s\"\x00,arg HIDDEN\x00,schema HIDDEN\x00PRAGMA \x00%Q.\x00=%Q\x00error in %s %s after %s: %s\x00malformed database schema (%s)\x00%z - %s\x00rename\x00drop column\x00add column\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\x00naturaleftouterightfullinnercross\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()\x00OFFSET\x00UNION ALL\x00INTERSECT\x00EXCEPT\x00UNION\x00USE TEMP B-TREE FOR %s\x00USE TEMP B-TREE FOR %sORDER BY\x00RIGHT PART OF \x00column%d\x00%.*z:%u\x00NUM\x00LIMIT counter\x00OFFSET counter\x00LIMIT+OFFSET\x00cannot use window functions in recursive queries\x00Queue table\x00recursive aggregate queries not supported\x00SETUP\x00RECURSIVE STEP\x00SCAN %d CONSTANT ROW%s\x00S\x00COMPOUND QUERY\x00LEFT-MOST SUBQUERY\x00Jump ahead if LIMIT reached\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 SELECT\x00LEFT\x00right SELECT\x00RIGHT\x00Output routine for A\x00Output routine for B\x00eof-A subroutine\x00eof-B subroutine\x00A-lt-B subroutine\x00A-eq-B subroutine\x00A-gt-B subroutine\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)\x00SCAN %s%s%s\x00 USING COVERING INDEX \x00target object/alias may not appear in FROM clause: %s\x00expected %d columns for '%s' but got %d\x00CO-ROUTINE %!S\x00materialize %!S\x00MATERIALIZE %!S\x00end %!S\x00inner-loop subroutine\x00end inner-loop subroutine\x00clear abort flag\x00DISTINCT\x00GROUP BY\x00GROUP BY sort\x00output one row\x00check abort flag\x00reset accumulator\x00indicate data in accumulator\x00output final row\x00set abort flag\x00Groupby result generator entry point\x00end groupby result generator\x00indicate accumulator empty\x00sqlite3_get_table() called with two or more incompatible queries\x00temporary trigger may not have qualified name\x00trigger\x00cannot create triggers on virtual tables\x00trigger %T already exists\x00cannot create trigger on system table\x00cannot create %s trigger on view: %S\x00BEFORE\x00AFTER\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'\x00%s RETURNING is not available on virtual tables\x00DELETE\x00UPDATE\x00RETURNING may not use \"TABLE.*\" wildcards\x00abort\x00rollback\x00fail\x00ignore\x00default\x00n/a\x00Start: %s.%s (%s %s%s%s ON %s)\x00INSERT\x00-- TRIGGER %s\x00End: %s.%s\x00Call: %s.%s\x00fkey\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\x00Begin DO UPDATE of UPSERT\x00End DO UPDATE of UPSERT\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\x00<expr>\x00 AND \x00(\x00 (\x00%s=?\x00ANY(%s)\x00>\x00<\x00%s %S\x00SEARCH\x00SCAN\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=?\x00begin skip-scan on %s\x00init LEFT JOIN no-match flag\x00next row of %s\x00Zero OFFSET counter\x00NULL-scan pass ctr\x00If NULL-scan 2nd pass\x00If NULL-scan 1st pass\x00MULTI-INDEX OR\x00INDEX %d\x00match against %s\x00record LEFT JOIN hit\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\x00next skip-scan on %s\x00second argument to nth_value must be a positive integer\x00argument of ntile must be a positive integer\x00row_number\x00dense_rank\x00rank\x00percent_rank\x00cume_dist\x00ntile\x00last_value\x00nth_value\x00first_value\x00lead\x00lag\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\x00call flush_partition\x00%s clause should come after %s not before\x00ORDER BY\x00LIMIT\x00too many terms in compound SELECT\x00syntax error after column name \"%.*s\"\x00parser stack overflow\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\x00SQLITE_OK\x00SQLITE_ERROR\x00SQLITE_ERROR_SNAPSHOT\x00SQLITE_INTERNAL\x00SQLITE_PERM\x00SQLITE_ABORT\x00SQLITE_ABORT_ROLLBACK\x00SQLITE_BUSY\x00SQLITE_BUSY_RECOVERY\x00SQLITE_BUSY_SNAPSHOT\x00SQLITE_LOCKED\x00SQLITE_LOCKED_SHAREDCACHE\x00SQLITE_NOMEM\x00SQLITE_READONLY\x00SQLITE_READONLY_RECOVERY\x00SQLITE_READONLY_CANTINIT\x00SQLITE_READONLY_ROLLBACK\x00SQLITE_READONLY_DBMOVED\x00SQLITE_READONLY_DIRECTORY\x00SQLITE_INTERRUPT\x00SQLITE_IOERR\x00SQLITE_IOERR_READ\x00SQLITE_IOERR_SHORT_READ\x00SQLITE_IOERR_WRITE\x00SQLITE_IOERR_FSYNC\x00SQLITE_IOERR_DIR_FSYNC\x00SQLITE_IOERR_TRUNCATE\x00SQLITE_IOERR_FSTAT\x00SQLITE_IOERR_UNLOCK\x00SQLITE_IOERR_RDLOCK\x00SQLITE_IOERR_DELETE\x00SQLITE_IOERR_NOMEM\x00SQLITE_IOERR_ACCESS\x00SQLITE_IOERR_CHECKRESERVEDLOCK\x00SQLITE_IOERR_LOCK\x00SQLITE_IOERR_CLOSE\x00SQLITE_IOERR_DIR_CLOSE\x00SQLITE_IOERR_SHMOPEN\x00SQLITE_IOERR_SHMSIZE\x00SQLITE_IOERR_SHMLOCK\x00SQLITE_IOERR_SHMMAP\x00SQLITE_IOERR_SEEK\x00SQLITE_IOERR_DELETE_NOENT\x00SQLITE_IOERR_MMAP\x00SQLITE_IOERR_GETTEMPPATH\x00SQLITE_IOERR_CONVPATH\x00SQLITE_CORRUPT\x00SQLITE_CORRUPT_VTAB\x00SQLITE_NOTFOUND\x00SQLITE_FULL\x00SQLITE_CANTOPEN\x00SQLITE_CANTOPEN_NOTEMPDIR\x00SQLITE_CANTOPEN_ISDIR\x00SQLITE_CANTOPEN_FULLPATH\x00SQLITE_CANTOPEN_CONVPATH\x00SQLITE_CANTOPEN_SYMLINK\x00SQLITE_PROTOCOL\x00SQLITE_EMPTY\x00SQLITE_SCHEMA\x00SQLITE_TOOBIG\x00SQLITE_CONSTRAINT\x00SQLITE_CONSTRAINT_UNIQUE\x00SQLITE_CONSTRAINT_TRIGGER\x00SQLITE_CONSTRAINT_FOREIGNKEY\x00SQLITE_CONSTRAINT_CHECK\x00SQLITE_CONSTRAINT_PRIMARYKEY\x00SQLITE_CONSTRAINT_NOTNULL\x00SQLITE_CONSTRAINT_COMMITHOOK\x00SQLITE_CONSTRAINT_VTAB\x00SQLITE_CONSTRAINT_FUNCTION\x00SQLITE_CONSTRAINT_ROWID\x00SQLITE_MISMATCH\x00SQLITE_MISUSE\x00SQLITE_NOLFS\x00SQLITE_AUTH\x00SQLITE_FORMAT\x00SQLITE_RANGE\x00SQLITE_NOTADB\x00SQLITE_ROW\x00SQLITE_NOTICE\x00SQLITE_NOTICE_RECOVER_WAL\x00SQLITE_NOTICE_RECOVER_ROLLBACK\x00SQLITE_NOTICE_RBU\x00SQLITE_WARNING\x00SQLITE_WARNING_AUTOINDEX\x00SQLITE_DONE\x00SQLITE_UNKNOWN(%d)\x00unknown error\x00abort due to ROLLBACK\x00another row available\x00no more rows available\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\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\x00mode\x00no such %s mode: %s\x00%s mode not allowed: %s\x00no such vfs: %s\x00private\x00ro\x00rw\x00rwc\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\x00[0]\x00JSON path error near '%q'\x00json_%s() needs an odd number of arguments\x00$[\x00$.\x00json_object() requires an even number of arguments\x00json_object() labels must be TEXT\x00set\x00insert\x00[]\x00{}\x00CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path,json HIDDEN,root HIDDEN)\x00.%.*s\x00[%d]\x00$\x00json\x00json_array\x00json_array_length\x00json_extract\x00->\x00->>\x00json_insert\x00json_object\x00json_patch\x00json_quote\x00json_remove\x00json_replace\x00json_set\x00json_type\x00json_valid\x00json_group_array\x00json_group_object\x00json_each\x00json_tree\x00%s_node\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\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\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\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\x00CREATE TABLE x(%.*s INT\x00,%.*s\x00);\x00,%.*s REAL\x00,%.*s INT\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\x00Mapping (%lld -> %lld) missing from %s table\x00%_rowid\x00%_parent\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\x00END\x00wrong number of arguments to function rtreecheck()\x00[\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\x00geopoly_area\x00geopoly_blob\x00geopoly_json\x00geopoly_svg\x00geopoly_contains_point\x00geopoly_debug\x00geopoly_bbox\x00geopoly_xform\x00geopoly_regular\x00geopoly_ccw\x00geopoly_group_bbox\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;\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\x00AND rootpage!=0 AND rootpage IS NOT NULL\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\x00table %q %s rbu_rowid column\x00may not have\x00requires\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%z%s\"%w\" %s %sCOLLATE %Q%s\x00 NOT NULL\x00%z, %z\x00CREATE TABLE \"rbu_imp_%w\"(%z)%s\x00 WITHOUT ROWID\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\x00SELECT %s, 0 AS rbu_control FROM '%q' %s %s %s ORDER BY %s%s\x00AND\x00WHERE\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_\x00INSERT INTO \"%s%w\"(%s%s) VALUES(%s)\x00, _rowid_\x00DELETE FROM \"%s%w\" WHERE %s\x00, rbu_rowid\x00CREATE TABLE IF NOT EXISTS %s.'rbu_tmp_%q' AS SELECT *%s FROM '%q' WHERE 0;\x00, 0 AS rbu_rowid\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\x00SELECT %s,%s rbu_control%s FROM '%q'%s %s %s %s\x000 AS \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\x00file:%s-vactmp?rbu_memory=1%s%s\x00&\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\x00database modified during rbu %s\x00vacuum\x00update\x00BEGIN IMMEDIATE\x00PRAGMA journal_mode=off\x00-vactmp\x00DELETE FROM stat.rbu_state\x00rbu/zipvfs setup error\x00rbu(%s)/%z\x00rbu_memory\x00CREATE TABLE x( name       TEXT, path       TEXT, pageno     INTEGER, pagetype   TEXT, ncell      INTEGER, payload    INTEGER, unused     INTEGER, mx_payload INTEGER, pgoffset   INTEGER, pgsize     INTEGER, schema     TEXT HIDDEN, aggregate  BOOLEAN HIDDEN)\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\x00CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)\x00read-only\x00cannot delete\x00cannot insert\x00no such schema\x00bad page number\x00bad page value\x00sqlite_dbpage\x00SELECT 0, 'tbl',  '', 0, '', 1     UNION ALL SELECT 1, 'idx',  '', 0, '', 2     UNION ALL SELECT 2, 'stat', '', 0, '', 0\x00PRAGMA '%q'.table_info('%q')\x00%z%s\"%w\".\"%w\".\"%w\"=\"%w\".\"%w\".\"%w\"\x00%z%s\"%w\".\"%w\".\"%w\" IS NOT \"%w\".\"%w\".\"%w\"\x00 OR \x00SELECT * FROM \"%w\".\"%w\" WHERE NOT EXISTS (  SELECT 1 FROM \"%w\".\"%w\" WHERE %s)\x00SELECT * FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)\x00table schemas do not match\x00SELECT tbl, ?2, stat FROM %Q.sqlite_stat1 WHERE tbl IS ?1 AND idx IS (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)\x00SELECT * FROM \x00 WHERE \x00 IS ?\x00SAVEPOINT changeset\x00RELEASE changeset\x00UPDATE main.\x00 SET \x00 = ?\x00idx IS CASE WHEN length(?4)=0 AND typeof(?4)='blob' THEN NULL ELSE ?4 END \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\x00content_rowid\x00multiple content_rowid=... directives\x00columnsize\x00malformed columnsize=... directive\x00columns\x00malformed detail=... directive\x00unrecognized option: \"%.*s\"\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\"\x00docsize\x00%Q.'%q_%s'\x00CREATE TABLE x(\x00%z%s%Q\x00%z, %Q HIDDEN, %s HIDDEN)\x00pgsz\x00hashsize\x00automerge\x00usermerge\x00crisismerge\x00SELECT k, v FROM %Q.'%q_config'\x00version\x00invalid fts5 file format (found %d, expected %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)\x00fts5: %s queries are not supported (detail!=full)\x00phrase\x00%s \x00-col %d \x00-col {%d\x00 %d\x00} \x00-near %d \x00--\x00 {\x00 [%z]\x00\"\"\x00{\x00%s : \x00NEAR(\x00 + \x00, %d)\x00 NOT \x00%s%s%z%s\x00nearset\x00wrong number of arguments to function %s\x00fts5_expr_tcl\x00fts5_expr\x00wrong number of arguments to function fts5_isalnum\x00L*\x00N*\x00Co\x00wrong number of arguments to function fts5_fold\x00fts5_isalnum\x00fts5_fold\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=?\x00PRAGMA %Q.data_version\x00SELECT pgno FROM '%q'.'%q_idx' WHERE segid=? AND term<=? ORDER BY term DESC LIMIT 1\x00INSERT INTO '%q'.'%q_idx'(segid,term,pgno) VALUES(?,?,?)\x00%s_data\x00id INTEGER PRIMARY KEY, block BLOB\x00segid, term, pgno, PRIMARY KEY(segid, term)\x00SELECT segid, term, (pgno>>1), (pgno&1) FROM %Q.'%q_idx' WHERE segid=%d ORDER BY 1, 2\x00\x00\x00\x00\x00\x00{averages} \x00{structure}\x00{%ssegid=%d h=%d pgno=%d}\x00dlidx \x00 {lvl=%d nMerge=%d nSeg=%d\x00 {id=%d leaves=%d..%d}\x00%s%d\x00 id=%lld\x00 nPos=%d%s\x00+\x00 %lld%s\x00 %d(%lld)\x00 term=%.*s\x00corrupt\x00should be: fts5_rowid(subject, ....)\x00segment\x00should be: fts5_rowid('segment', segid, pgno))\x00first arg to fts5_rowid() must be 'segment'\x00fts5_decode\x00fts5_decode_none\x00fts5_rowid\x00recursively defined fts5 content table\x00SELECT rowid, rank FROM %Q.%Q ORDER BY %s(\"%w\"%s%s) %s\x00DESC\x00ASC\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\x00cannot %s contentless fts5 table: %s\x00DELETE from\x00no such cursor: %lld\x00no such tokenizer: %s\x00error in tokenizer constructor\x00fts5_api_ptr\x00fts5: 2023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69cffde2924203304e8ffc4155597af0c191da\x00config\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(?,?)\x00DELETE FROM %Q.'%q_docsize' WHERE id=?\x00SELECT sz FROM %Q.'%q_docsize' WHERE id=?\x00REPLACE INTO %Q.'%q_config' VALUES(?,?)\x00SELECT %s FROM %s AS T\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\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\x00CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep,reprep,run,mem)\x00sqlite_stmt\x002023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69cffde2924203304e8ffc4155597af0c191da\x00"
var ts = (*reflect.StringHeader)(unsafe.Pointer(&ts1)).Data
