// Code generated by modernc.org/undup from the per-target vec_*.go files; DO NOT EDIT.

//go:build (darwin && amd64) || (darwin && arm64) || (freebsd && amd64) || (freebsd && arm64) || (linux && amd64) || (linux && arm64) || (linux && loong64) || (linux && ppc64le) || (linux && riscv64) || (linux && s390x) || (netbsd && amd64) || (openbsd && amd64) || (openbsd && arm64)

package vec

import (
	"unsafe"

	"modernc.org/libc"
	libsqlite3 "modernc.org/sqlite/lib"
)

type Tldiv_t = struct {
	Fquot int64
	Frem  int64
}

func Xparse_npy_header(tls *libc.TLS, pVTab uintptr, header uintptr, headerLength Tsize_t, out_element_type uintptr, fortran_order uintptr, numElements uintptr, numDimensions uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var first Tsize_t
	var key uintptr
	var rc, v1 int32
	var _ /* scanner at bp+0 */ TNpyScanner
	var _ /* token at bp+24 */ TNpyToken
	_, _, _, _ = first, key, rc, v1
	Xnpy_scanner_init(tls, bp, header, libc.Int32FromUint64(headerLength))
	if Xnpy_scanner_next(tls, bp, bp+24) != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_LBRACE) {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+1922, 0)
		return int32(m_SQLITE_ERROR)
	}
	for int32(1) != 0 {
		rc = Xnpy_scanner_next(tls, bp, bp+24)
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+1985, 0)
			return int32(m_SQLITE_ERROR)
		}
		if (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type == int32(_NPY_TOKEN_TYPE_RBRACE) {
			break
		}
		if (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_STRING) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+2041, 0)
			return int32(m_SQLITE_ERROR)
		}
		key = (**(**TNpyToken)(__ccgo_up(bp + 24))).Fstart
		rc = Xnpy_scanner_next(tls, bp, bp+24)
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_COLON) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+2109, 0)
			return int32(m_SQLITE_ERROR)
		}
		if libc.Xstrncmp(tls, key, __ccgo_ts+2177, libc.Xstrlen(tls, __ccgo_ts+2177)) == 0 {
			rc = Xnpy_scanner_next(tls, bp, bp+24)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_STRING) {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+2185, 0)
				return int32(m_SQLITE_ERROR)
			}
			if libc.Xstrncmp(tls, (**(**TNpyToken)(__ccgo_up(bp + 24))).Fstart, __ccgo_ts+2254, libc.Xstrlen(tls, __ccgo_ts+2254)) != 0 {
				Xvtab_set_error(tls, pVTab, __ccgo_ts+2260, 0)
				return int32(m_SQLITE_ERROR)
			}
			**(**_VectorElementType)(__ccgo_up(out_element_type)) = int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32)
		} else {
			if libc.Xstrncmp(tls, key, __ccgo_ts+2349, libc.Xstrlen(tls, __ccgo_ts+2349)) == 0 {
				rc = Xnpy_scanner_next(tls, bp, bp+24)
				if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_FALSE) {
					Xvtab_set_error(tls, pVTab, __ccgo_ts+2365, 0)
					return int32(m_SQLITE_ERROR)
				}
				**(**int32)(__ccgo_up(fortran_order)) = 0
			} else {
				if libc.Xstrncmp(tls, key, __ccgo_ts+2462, libc.Xstrlen(tls, __ccgo_ts+2462)) == 0 {
					rc = Xnpy_scanner_next(tls, bp, bp+24)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_LPAREN) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2470, 0)
						return int32(m_SQLITE_ERROR)
					}
					rc = Xnpy_scanner_next(tls, bp, bp+24)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_NUMBER) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2543, 0)
						return int32(m_SQLITE_ERROR)
					}
					first = libc.Uint64FromInt64(libc.Xstrtol(tls, (**(**TNpyToken)(__ccgo_up(bp + 24))).Fstart, libc.UintptrFromInt32(0), int32(10)))
					rc = Xnpy_scanner_next(tls, bp, bp+24)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_COMMA) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2612, 0)
						return int32(m_SQLITE_ERROR)
					}
					rc = Xnpy_scanner_next(tls, bp, bp+24)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2678, 0)
						return int32(m_SQLITE_ERROR)
					}
					if (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type == int32(_NPY_TOKEN_TYPE_NUMBER) {
						**(**Tsize_t)(__ccgo_up(numElements)) = first
						**(**Tsize_t)(__ccgo_up(numDimensions)) = libc.Uint64FromInt64(libc.Xstrtol(tls, (**(**TNpyToken)(__ccgo_up(bp + 24))).Fstart, libc.UintptrFromInt32(0), int32(10)))
						rc = Xnpy_scanner_next(tls, bp, bp+24)
						if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_RPAREN) {
							Xvtab_set_error(tls, pVTab, __ccgo_ts+2747, 0)
							return int32(m_SQLITE_ERROR)
						}
					} else {
						if (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type == int32(_NPY_TOKEN_TYPE_RPAREN) {
							// '(0,)' means an empty array!
							if first != 0 {
								v1 = int32(1)
							} else {
								v1 = 0
							}
							**(**Tsize_t)(__ccgo_up(numElements)) = libc.Uint64FromInt32(v1)
							**(**Tsize_t)(__ccgo_up(numDimensions)) = first
						} else {
							Xvtab_set_error(tls, pVTab, __ccgo_ts+2819, 0)
							return int32(m_SQLITE_ERROR)
						}
					}
				} else {
					Xvtab_set_error(tls, pVTab, __ccgo_ts+2874, 0)
					return int32(m_SQLITE_ERROR)
				}
			}
		}
		rc = Xnpy_scanner_next(tls, bp, bp+24)
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 24))).Ftoken_type != int32(_NPY_TOKEN_TYPE_COMMA) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+2929, 0)
			return int32(m_SQLITE_ERROR)
		}
	}
	return m_SQLITE_OK
}

func Xvec0Update_Delete_DeleteChunkIfEmpty(tls *libc.TLS, p uintptr, chunk_id Ti64, deleted uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var allZero, brc, i, i1, i2, rc, validitySize int32
	var validityBuf, zSql uintptr
	var _ /* blobValidity at bp+0 */ uintptr
	var _ /* stmt at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _ = allZero, brc, i, i1, i2, rc, validityBuf, validitySize, zSql
	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
	**(**int32)(__ccgo_up(deleted)) = 0
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, __ccgo_ts+11207, chunk_id, 0, bp)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+14414, libc.VaList(bp+24, chunk_id))
		return int32(m_SQLITE_ERROR)
	}
	validitySize = libsqlite3.Xsqlite3_blob_bytes(tls, **(**uintptr)(__ccgo_up(bp)))
	validityBuf = libsqlite3.Xsqlite3_malloc(tls, validitySize)
	if !(validityBuf != 0) {
		libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp)))
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, **(**uintptr)(__ccgo_up(bp)), validityBuf, validitySize, 0)
	brc = libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp)))
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_free(tls, validityBuf)
		return rc
	}
	if brc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_free(tls, validityBuf)
		return brc
	}
	allZero = int32(1)
	i = 0
	for {
		if !(i < validitySize) {
			break
		}
		if libc.Int32FromUint8(**(**uint8)(__ccgo_up(validityBuf + uintptr(i)))) != 0 {
			allZero = 0
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	libsqlite3.Xsqlite3_free(tls, validityBuf)
	if !(allZero != 0) {
		return m_SQLITE_OK
	}
	// Delete from _chunks
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+14458, libc.VaList(bp+24, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	if !(zSql != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp+8, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		return rc
	}
	libsqlite3.Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(1), chunk_id)
	rc = libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	if rc != int32(m_SQLITE_DONE) {
		return int32(m_SQLITE_ERROR)
	}
	// Delete from each _vector_chunksNN
	i1 = 0
	for {
		if !(i1 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+14503, libc.VaList(bp+24, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, i1))
		if !(zSql != 0) {
			return int32(m_SQLITE_NOMEM)
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp+8, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			return rc
		}
		libsqlite3.Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(1), chunk_id)
		rc = libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8)))
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
		if rc != int32(m_SQLITE_DONE) {
			return int32(m_SQLITE_ERROR)
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	// Delete from each _metadatachunksNN
	i2 = 0
	for {
		if !(i2 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumMetadataColumns) {
			break
		}
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+14559, libc.VaList(bp+24, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, i2))
		if !(zSql != 0) {
			return int32(m_SQLITE_NOMEM)
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp+8, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			return rc
		}
		libsqlite3.Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp + 8)), int32(1), chunk_id)
		rc = libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 8)))
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 8)))
		if rc != int32(m_SQLITE_DONE) {
			return int32(m_SQLITE_ERROR)
		}
		goto _3
	_3:
		;
		i2 = i2 + 1
	}
	// Invalidate cached stmtLatestChunk so it gets re-prepared on next insert
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk != 0 {
		libsqlite3.Xsqlite3_finalize(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
		(*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk = libc.UintptrFromInt32(0)
	}
	**(**int32)(__ccgo_up(deleted)) = int32(1)
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * @brief Handles INSERT INTO operations on a vec0 table.
//	 *
//	 * @return int SQLITE_OK on success, otherwise error code on failure
//	 */
func Xvec0Update_Insert(tls *libc.TLS, pVTab uintptr, argc int32, argv uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(400)
	defer tls.Free(400)
	var auxiliary_key_idx, brc, i, i1, i2, i3, i4, i5, i6, metadata_idx, new_value_type, numReadVectors, partition_key_idx, rc, v_type, vector_column_idx int32
	var p, s, v, v1, valueVector, zSql uintptr
	var _ /* blobChunksValidity at bp+312 */ uintptr
	var _ /* bufferChunksValidity at bp+320 */ uintptr
	var _ /* chunk_offset at bp+304 */ Ti64
	var _ /* chunk_rowid at bp+296 */ Ti64
	var _ /* cleanups at bp+136 */ [16]Tvector_cleanup
	var _ /* dimensions at bp+328 */ Tsize_t
	var _ /* elementType at bp+344 */ _VectorElementType
	var _ /* partitionKeyValues at bp+264 */ [4]uintptr
	var _ /* pzError at bp+336 */ uintptr
	var _ /* rowid at bp+0 */ Ti64
	var _ /* stmt at bp+352 */ uintptr
	var _ /* vectorDatas at bp+8 */ [16]uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = auxiliary_key_idx, brc, i, i1, i2, i3, i4, i5, i6, metadata_idx, new_value_type, numReadVectors, p, partition_key_idx, rc, s, v, v1, v_type, valueVector, vector_column_idx, zSql
	_ = argc
	p = pVTab
	// a write-able blob of the validity column for the given chunk. Used to mark
	// validity bit
	**(**uintptr)(__ccgo_up(bp + 312)) = libc.UintptrFromInt32(0)
	// buffer for the valididty column for the given chunk. Maybe not needed here?
	**(**uintptr)(__ccgo_up(bp + 320)) = libc.UintptrFromInt32(0)
	numReadVectors = 0
	// Read all provided partition key values into partitionKeyValues
	i = 0
	for {
		if !(i < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if **(**Tvec0_user_column_kind)(__ccgo_up(p + 88 + uintptr(i)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION) {
			goto _1
		}
		partition_key_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 296 + uintptr(i))))
		(**(**[4]uintptr)(__ccgo_up(bp + 264)))[partition_key_idx] = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i)*8))
		new_value_type = libsqlite3.Xsqlite3_value_type(tls, (**(**[4]uintptr)(__ccgo_up(bp + 264)))[partition_key_idx])
		if new_value_type != int32(m_SQLITE_NULL) && new_value_type != (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 1120 + uintptr(partition_key_idx)*24))).Ftype1 {
			// IMP: V11454_28292
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13042, libc.VaList(bp+368, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 1120 + uintptr(partition_key_idx)*24))).Fname_length, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 1120 + uintptr(partition_key_idx)*24))).Fname, Xtype_name(tls, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 1120 + uintptr(partition_key_idx)*24))).Ftype1), Xtype_name(tls, new_value_type)))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	// read all the inserted vectors  into vectorDatas, validate their lengths.
	i1 = 0
	for {
		if !(i1 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if **(**Tvec0_user_column_kind)(__ccgo_up(p + 88 + uintptr(i1)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
			goto _2
		}
		vector_column_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 296 + uintptr(i1))))
		valueVector = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i1)*8))
		rc = Xvector_from_value(tls, valueVector, bp+8+uintptr(vector_column_idx)*8, bp+328, bp+344, bp+136+uintptr(vector_column_idx)*8, bp+336)
		if rc != m_SQLITE_OK {
			// IMP: V06519_23358
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13134, libc.VaList(bp+368, (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(vector_column_idx)*32))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(vector_column_idx)*32))).Fname, **(**uintptr)(__ccgo_up(bp + 336))))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		numReadVectors = numReadVectors + 1
		if **(**_VectorElementType)(__ccgo_up(bp + 344)) != (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(vector_column_idx)*32))).Felement_type {
			// IMP: V08221_25059
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13187, libc.VaList(bp+368, (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(i1)*32))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(i1)*32))).Fname, Xvector_subtype_name(tls, (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(i1)*32))).Felement_type), Xvector_subtype_name(tls, **(**_VectorElementType)(__ccgo_up(bp + 344)))))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		if **(**Tsize_t)(__ccgo_up(bp + 328)) != (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(vector_column_idx)*32))).Fdimensions {
			// IMP: V01145_17984
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13285, libc.VaList(bp+368, (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(vector_column_idx)*32))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(vector_column_idx)*32))).Fname, (**(**TVectorColumnDefinition)(__ccgo_up(p + 608 + uintptr(vector_column_idx)*32))).Fdimensions, **(**Tsize_t)(__ccgo_up(bp + 328))))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	// Cannot insert a value in the hidden "distance" column
	if libsqlite3.Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + uintptr(int32(2)+Xvec0_column_distance_idx(tls, p))*8))) != int32(m_SQLITE_NULL) {
		// IMP: V24228_08298
		Xvtab_set_error(tls, pVTab, __ccgo_ts+13387, 0)
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	// Cannot insert a value in the hidden "k" column
	if libsqlite3.Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + uintptr(int32(2)+Xvec0_column_k_idx(tls, p))*8))) != int32(m_SQLITE_NULL) {
		// IMP: V11875_28713
		Xvtab_set_error(tls, pVTab, __ccgo_ts+13442, 0)
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	// Step #1: Insert/get a rowid for this row, from the _rowids table.
	rc = Xvec0Update_InsertRowidStep(tls, p, **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_ID))*8)), bp)
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	// Step #2: Find the next "available" position in the _chunks table for this
	// row.
	rc = Xvec0Update_InsertNextAvailableStep(tls, p, bp+264, bp+296, bp+304, bp+312, bp+320)
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	// Step #3: With the next available chunk position, write out all the vectors
	//          to their specified location.
	rc = Xvec0Update_InsertWriteFinalStep(tls, p, **(**Ti64)(__ccgo_up(bp + 296)), **(**Ti64)(__ccgo_up(bp + 304)), **(**Ti64)(__ccgo_up(bp)), bp+8, **(**uintptr)(__ccgo_up(bp + 312)), **(**uintptr)(__ccgo_up(bp + 320)))
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns > 0 {
		s = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+13490, libc.VaList(bp+368, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		i2 = 0
		for {
			if !(i2 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns) {
				break
			}
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+8098, libc.VaList(bp+368, i2))
			goto _3
		_3:
			;
			i2 = i2 + 1
		}
		libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+13529)
		i3 = 0
		for {
			if !(i3 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns) {
				break
			}
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+5252)
			goto _4
		_4:
			;
			i3 = i3 + 1
		}
		libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+5256)
		zSql = libsqlite3.Xsqlite3_str_finish(tls, s)
		// TODO double check error handling ehre
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp+352, libc.UintptrFromInt32(0))
		if rc != m_SQLITE_OK {
			goto cleanup
		}
		libsqlite3.Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp + 352)), int32(1), **(**Ti64)(__ccgo_up(bp)))
		i4 = 0
		for {
			if !(i4 < Xvec0_num_defined_user_columns(tls, p)) {
				break
			}
			if **(**Tvec0_user_column_kind)(__ccgo_up(p + 88 + uintptr(i4)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY) {
				goto _5
			}
			auxiliary_key_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 296 + uintptr(i4))))
			v = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i4)*8))
			v_type = libsqlite3.Xsqlite3_value_type(tls, v)
			if v_type != int32(m_SQLITE_NULL) && v_type != (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 1216 + uintptr(auxiliary_key_idx)*24))).Ftype1 {
				libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 352)))
				rc = int32(m_SQLITE_CONSTRAINT)
				Xvtab_set_error(tls, pVTab, __ccgo_ts+13542, libc.VaList(bp+368, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 1216 + uintptr(auxiliary_key_idx)*24))).Fname_length, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 1216 + uintptr(auxiliary_key_idx)*24))).Fname, Xtype_name(tls, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 1216 + uintptr(auxiliary_key_idx)*24))).Ftype1), Xtype_name(tls, v_type)))
				goto cleanup
			}
			// first 1 is for 1-based indexing on sqlite3_bind_*, second 1 is to account for initial rowid parameter
			libsqlite3.Xsqlite3_bind_value(tls, **(**uintptr)(__ccgo_up(bp + 352)), libc.Int32FromInt32(1)+libc.Int32FromInt32(1)+auxiliary_key_idx, v)
			goto _5
		_5:
			;
			i4 = i4 + 1
		}
		rc = libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 352)))
		if rc != int32(m_SQLITE_DONE) {
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 352)))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 352)))
	}
	i5 = 0
	for {
		if !(i5 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if **(**Tvec0_user_column_kind)(__ccgo_up(p + 88 + uintptr(i5)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA) {
			goto _6
		}
		metadata_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 296 + uintptr(i5))))
		v1 = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i5)*8))
		rc = Xvec0_write_metadata_value(tls, p, metadata_idx, **(**Ti64)(__ccgo_up(bp)), **(**Ti64)(__ccgo_up(bp + 296)), **(**Ti64)(__ccgo_up(bp + 304)), v1, 0)
		if rc != m_SQLITE_OK {
			goto cleanup
		}
		goto _6
	_6:
		;
		i5 = i5 + 1
	}
	**(**Tsqlite_int64)(__ccgo_up(pRowid)) = **(**Ti64)(__ccgo_up(bp))
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	i6 = 0
	for {
		if !(i6 < numReadVectors) {
			break
		}
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(**(**[16]Tvector_cleanup)(__ccgo_up(bp + 136)))[i6]})))(tls, (**(**[16]uintptr)(__ccgo_up(bp + 8)))[i6])
		goto _7
	_7:
		;
		i6 = i6 + 1
	}
	libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 320)))
	brc = libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 312)))
	if rc == m_SQLITE_OK && brc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+13634, 0)
		return brc
	}
	return rc
}

func Xvec0Update_Update(tls *libc.TLS, pVTab uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var a, b, p, value, value1, value2, valueVector uintptr
	var auxiliary_column_idx, i, i1, i2, i3, metadata_column_idx, rc, vector_idx int32
	var _ /* chunk_id at bp+0 */ Ti64
	var _ /* chunk_offset at bp+8 */ Ti64
	var _ /* rowid at bp+16 */ Ti64
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = a, auxiliary_column_idx, b, i, i1, i2, i3, metadata_column_idx, p, rc, value, value1, value2, valueVector, vector_idx
	_ = argc
	p = pVTab
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FpkIsText != 0 {
		a = libsqlite3.Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
		b = libsqlite3.Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*8)))
		// IMP: V08886_25725
		if libsqlite3.Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv))) != libsqlite3.Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 1*8))) || libc.Xstrncmp(tls, a, b, libc.Uint64FromInt32(libsqlite3.Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv))))) != 0 {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+15180, 0)
			return int32(m_SQLITE_ERROR)
		}
		rc = Xvec0_rowid_from_id(tls, p, **(**uintptr)(__ccgo_up(argv)), bp+16)
		if rc != m_SQLITE_OK {
			return rc
		}
	} else {
		**(**Ti64)(__ccgo_up(bp + 16)) = libsqlite3.Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv)))
	}
	// 1) get chunk_id and chunk_offset from _rowids
	rc = Xvec0_get_chunk_position(tls, p, **(**Ti64)(__ccgo_up(bp + 16)), libc.UintptrFromInt32(0), bp, bp+8)
	if rc != m_SQLITE_OK {
		return rc
	}
	// 2) update any partition key values
	i = 0
	for {
		if !(i < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if **(**Tvec0_user_column_kind)(__ccgo_up(p + 88 + uintptr(i)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION) {
			goto _1
		}
		value = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i)*8))
		if libsqlite3.Xsqlite3_value_nochange(tls, value) != 0 {
			goto _1
		}
		Xvtab_set_error(tls, pVTab, __ccgo_ts+15232, 0)
		return int32(m_SQLITE_ERROR)
		goto _1
	_1:
		;
		i = i + 1
	}
	// 3) handle auxiliary column updates
	i1 = 0
	for {
		if !(i1 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if **(**Tvec0_user_column_kind)(__ccgo_up(p + 88 + uintptr(i1)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY) {
			goto _2
		}
		auxiliary_column_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 296 + uintptr(i1))))
		value1 = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i1)*8))
		if libsqlite3.Xsqlite3_value_nochange(tls, value1) != 0 {
			goto _2
		}
		rc = Xvec0Update_UpdateAuxColumn(tls, p, auxiliary_column_idx, value1, **(**Ti64)(__ccgo_up(bp + 16)))
		if rc != m_SQLITE_OK {
			return int32(m_SQLITE_ERROR)
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	// 4) handle metadata column updates
	i2 = 0
	for {
		if !(i2 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if **(**Tvec0_user_column_kind)(__ccgo_up(p + 88 + uintptr(i2)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA) {
			goto _3
		}
		metadata_column_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 296 + uintptr(i2))))
		value2 = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i2)*8))
		if libsqlite3.Xsqlite3_value_nochange(tls, value2) != 0 {
			goto _3
		}
		rc = Xvec0_write_metadata_value(tls, p, metadata_column_idx, **(**Ti64)(__ccgo_up(bp + 16)), **(**Ti64)(__ccgo_up(bp)), **(**Ti64)(__ccgo_up(bp + 8)), value2, int32(1))
		if rc != m_SQLITE_OK {
			return rc
		}
		goto _3
	_3:
		;
		i2 = i2 + 1
	}
	// 5) iterate over all new vectors, update the vectors
	i3 = 0
	for {
		if !(i3 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if **(**Tvec0_user_column_kind)(__ccgo_up(p + 88 + uintptr(i3)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
			goto _4
		}
		vector_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 296 + uintptr(i3))))
		valueVector = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i3)*8))
		// in vec0Column, we check sqlite3_vtab_nochange() on vector columns.
		// If the vector column isn't being changed, we return NULL;
		// That's not great, that means vector columns can never be NULLABLE
		// (bc we cant distinguish if an updated vector is truly NULL or nochange).
		// Also it means that if someone tries to run `UPDATE v SET X = NULL`,
		// we can't effectively detect and raise an error.
		// A better solution would be to use a custom result_type for "empty",
		// but subtypes don't appear to survive xColumn -> xUpdate, it's always 0.
		// So for now, we'll just use NULL and warn people to not SET X = NULL
		// in the docs.
		if libsqlite3.Xsqlite3_value_type(tls, valueVector) == int32(m_SQLITE_NULL) {
			goto _4
		}
		rc = Xvec0Update_UpdateVectorColumn(tls, p, **(**Ti64)(__ccgo_up(bp)), **(**Ti64)(__ccgo_up(bp + 8)), vector_idx, valueVector)
		if rc != m_SQLITE_OK {
			return int32(m_SQLITE_ERROR)
		}
		goto _4
	_4:
		;
		i3 = i3 + 1
	}
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * Returns the auxiliary column index of the given user column index.
//	 * ONLY call if validated with vec0_column_idx_to_partition_idx before
//	 */
func Xvec0_column_idx_to_auxiliary_idx(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	_ = pVtab
	return libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(pVtab + 296 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START)))))
}

// C documentation
//
//	/**
//	 * Returns the metadata column index of the given user column index.
//	 * ONLY call if validated with vec0_column_idx_is_metadata before
//	 */
func Xvec0_column_idx_to_metadata_idx(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	_ = pVtab
	return libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(pVtab + 296 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START)))))
}

// C documentation
//
//	/**
//	 * Returns the partition column index of the given user column index.
//	 * ONLY call if validated with vec0_column_idx_is_vector before
//	 */
func Xvec0_column_idx_to_partition_idx(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	_ = pVtab
	return libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(pVtab + 296 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START)))))
}

// C documentation
//
//	/**
//	 * Returns the vector index of the given user column index.
//	 * ONLY call if validated with vec0_column_idx_is_vector before
//	 */
func Xvec0_column_idx_to_vector_idx(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	_ = pVtab
	return libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(pVtab + 296 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START)))))
}

// C documentation
//
//	/**
//	 * @brief
//	 *
//	 * @param pVtab: virtual table to query
//	 * @param rowid: row to lookup
//	 * @param vector_column_idx: which vector column to query
//	 * @param outVector: Output pointer to the vector buffer.
//	 *                    Must be sqlite3_free()'ed.
//	 * @param outVectorSize: Pointer to a int where the size of outVector
//	 *                       will be stored.
//	 * @return int SQLITE_OK on success.
//	 */
func Xvec0_get_vector_data(tls *libc.TLS, pVtab uintptr, rowid Ti64, vector_column_idx int32, outVector uintptr, outVectorSize uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var blobOffset, brc, rc int32
	var buf, p uintptr
	var size Tsize_t
	var _ /* chunk_id at bp+0 */ Ti64
	var _ /* chunk_offset at bp+8 */ Ti64
	var _ /* vectorBlob at bp+16 */ uintptr
	_, _, _, _, _, _ = blobOffset, brc, buf, p, rc, size
	p = pVtab
	buf = libc.UintptrFromInt32(0)
	**(**uintptr)(__ccgo_up(bp + 16)) = libc.UintptrFromInt32(0)
	rc = Xvec0_get_chunk_position(tls, pVtab, rowid, libc.UintptrFromInt32(0), bp, bp+8)
	if rc == int32(m_SQLITE_EMPTY) {
		Xvtab_set_error(tls, pVtab, __ccgo_ts+3675, libc.VaList(bp+32, rowid))
		goto cleanup
	}
	if rc != m_SQLITE_OK {
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 352 + uintptr(vector_column_idx)*8)), __ccgo_ts+3712, **(**Ti64)(__ccgo_up(bp)), 0, bp+16)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, pVtab, __ccgo_ts+3720, libc.VaList(bp+32, rowid))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	size = Xvector_column_byte_size(tls, **(**TVectorColumnDefinition)(__ccgo_up(pVtab + 608 + uintptr(vector_column_idx)*32)))
	blobOffset = libc.Int32FromUint64(libc.Uint64FromInt64(**(**Ti64)(__ccgo_up(bp + 8))) * size)
	buf = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint64(size))
	if !(buf != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, **(**uintptr)(__ccgo_up(bp + 16)), buf, libc.Int32FromUint64(size), blobOffset)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_free(tls, buf)
		buf = libc.UintptrFromInt32(0)
		Xvtab_set_error(tls, pVtab, __ccgo_ts+3778, libc.VaList(bp+32, rowid))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	**(**uintptr)(__ccgo_up(outVector)) = buf
	if outVectorSize != 0 {
		**(**int32)(__ccgo_up(outVectorSize)) = libc.Int32FromUint64(size)
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	brc = libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 16)))
	if rc == m_SQLITE_OK && brc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+3841, 0)
		return brc
	}
	return rc
}

func Xvec0_metadata_chunk_size(tls *libc.TLS, kind Tvec0_metadata_column_kind, chunk_size int32) (r int32) {
	switch kind {
	case int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN):
		return chunk_size / int32(8)
	case int32(_VEC0_METADATA_COLUMN_KIND_INTEGER):
		return libc.Int32FromUint64(libc.Uint64FromInt32(chunk_size) * uint64(8))
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		return libc.Int32FromUint64(libc.Uint64FromInt32(chunk_size) * uint64(8))
	case int32(_VEC0_METADATA_COLUMN_KIND_TEXT):
		return chunk_size * int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH)
	}
	return 0
}

func Xvec0_metadata_filter_text(tls *libc.TLS, p uintptr, value uintptr, buffer uintptr, size int32, op Tvec0_metadata_operator, b uintptr, metadata_idx int32, chunk_rowid int32, aMetadataIn uintptr, argv_idx int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var aTarget, entry, metadataIn, metadataIn1, rowids, sPrefix, sPrefix1, sTarget, view, view1 uintptr
	var cmpPrefix, cmpPrefix1, cmpPrefix2, cmpPrefix3, cmpPrefix4, cmpPrefix5, cmpPrefix6, i, i1, i2, i3, i4, i5, i7, nPrefix, nPrefix1, nTarget, rc, v10, v12, v14 int32
	var i6, metadataInIdx, target_idx Tsize_t
	var _ /* nFull at bp+24 */ int32
	var _ /* nFull at bp+40 */ int32
	var _ /* rowidsBlob at bp+8 */ uintptr
	var _ /* sFull at bp+16 */ uintptr
	var _ /* sFull at bp+32 */ uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = aTarget, cmpPrefix, cmpPrefix1, cmpPrefix2, cmpPrefix3, cmpPrefix4, cmpPrefix5, cmpPrefix6, entry, i, i1, i2, i3, i4, i5, i6, i7, metadataIn, metadataIn1, metadataInIdx, nPrefix, nPrefix1, nTarget, rc, rowids, sPrefix, sPrefix1, sTarget, target_idx, view, view1, v10, v12, v14
	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
	rowids = libc.UintptrFromInt32(0)
	sTarget = libsqlite3.Xsqlite3_value_text(tls, value)
	nTarget = libsqlite3.Xsqlite3_value_bytes(tls, value)
	// TODO(perf): only text metadata news the rowids BLOB. Make it so that
	// rowids BLOB is re-used when multiple fitlers on text columns,
	// ex "name BETWEEN 'a' and 'b'""
	rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName, __ccgo_ts+9690, int64(chunk_rowid), 0, bp+8)
	if rc != m_SQLITE_OK {
		return rc
	}
	rowids = libsqlite3.Xsqlite3_malloc(tls, libsqlite3.Xsqlite3_blob_bytes(tls, **(**uintptr)(__ccgo_up(bp + 8))))
	if !(rowids != 0) {
		libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 8)))
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, **(**uintptr)(__ccgo_up(bp + 8)), rowids, libsqlite3.Xsqlite3_blob_bytes(tls, **(**uintptr)(__ccgo_up(bp + 8))), 0)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 8)))
		return rc
	}
	libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 8)))
	switch op {
	case int32(_VEC0_METADATA_OPERATOR_EQ):
		goto _1
	case int32(_VEC0_METADATA_OPERATOR_NE):
		goto _2
	case int32(_VEC0_METADATA_OPERATOR_GT):
		goto _3
	case int32(_VEC0_METADATA_OPERATOR_GE):
		goto _4
	case int32(_VEC0_METADATA_OPERATOR_LE):
		goto _5
	case int32(_VEC0_METADATA_OPERATOR_LT):
		goto _6
	case int32(_VEC0_METADATA_OPERATOR_IN):
		goto _7
	}
	goto _8
_1:
	;
	i = 0
	for {
		if !(i < size) {
			break
		}
		view = buffer + uintptr(i*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = **(**int32)(__ccgo_up(view))
		sPrefix = view + 4
		// for EQ the text lengths must match
		if nPrefix != nTarget {
			Xbitmap_set(tls, b, i, 0)
			goto _9
		}
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v10 = nPrefix
		} else {
			v10 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		cmpPrefix = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		// for short strings, use the prefix comparison direclty
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			Xbitmap_set(tls, b, i, libc.BoolInt32(cmpPrefix == 0))
			goto _9
		}
		// for EQ on longs strings, the prefix must match
		if cmpPrefix != 0 {
			Xbitmap_set(tls, b, i, 0)
			goto _9
		}
		// consult the full string
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, **(**Ti64)(__ccgo_up(rowids + uintptr(i)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 16)), sTarget, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))) == 0))
		goto _9
	_9:
		;
		i = i + 1
	}
	goto _8
_2:
	;
	i1 = 0
	for {
		if !(i1 < size) {
			break
		}
		view = buffer + uintptr(i1*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = **(**int32)(__ccgo_up(view))
		sPrefix = view + 4
		// for NE if text lengths dont match, it never will
		if nPrefix != nTarget {
			Xbitmap_set(tls, b, i1, int32(1))
			goto _11
		}
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v10 = nPrefix
		} else {
			v10 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		cmpPrefix1 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		// for short strings, use the prefix comparison direclty
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			Xbitmap_set(tls, b, i1, libc.BoolInt32(cmpPrefix1 != 0))
			goto _11
		}
		// for NE on longs strings, if prefixes dont match, then long string wont
		if cmpPrefix1 != 0 {
			Xbitmap_set(tls, b, i1, int32(1))
			goto _11
		}
		// consult the full string
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, **(**Ti64)(__ccgo_up(rowids + uintptr(i1)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i1, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 16)), sTarget, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))) != 0))
		goto _11
	_11:
		;
		i1 = i1 + 1
	}
	goto _8
_3:
	;
	i2 = 0
	for {
		if !(i2 < size) {
			break
		}
		view = buffer + uintptr(i2*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = **(**int32)(__ccgo_up(view))
		sPrefix = view + 4
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v12 = nPrefix
		} else {
			v12 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		if v12 <= nTarget {
			if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v14 = nPrefix
			} else {
				v14 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			v10 = v14
		} else {
			v10 = nTarget
		}
		cmpPrefix2 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		if nPrefix < int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			// if prefix match, check which is longer
			if cmpPrefix2 == 0 {
				Xbitmap_set(tls, b, i2, libc.BoolInt32(nPrefix > nTarget))
			} else {
				Xbitmap_set(tls, b, i2, libc.BoolInt32(cmpPrefix2 > 0))
			}
			goto _13
		}
		// TODO(perf): may not need to compare full text in some cases
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, **(**Ti64)(__ccgo_up(rowids + uintptr(i2)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i2, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 16)), sTarget, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))) > 0))
		goto _13
	_13:
		;
		i2 = i2 + 1
	}
	goto _8
_4:
	;
	i3 = 0
	for {
		if !(i3 < size) {
			break
		}
		view = buffer + uintptr(i3*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = **(**int32)(__ccgo_up(view))
		sPrefix = view + 4
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v12 = nPrefix
		} else {
			v12 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		if v12 <= nTarget {
			if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v14 = nPrefix
			} else {
				v14 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			v10 = v14
		} else {
			v10 = nTarget
		}
		cmpPrefix3 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		if nPrefix < int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			// if prefix match, check which is longer
			if cmpPrefix3 == 0 {
				Xbitmap_set(tls, b, i3, libc.BoolInt32(nPrefix >= nTarget))
			} else {
				Xbitmap_set(tls, b, i3, libc.BoolInt32(cmpPrefix3 >= 0))
			}
			goto _17
		}
		// TODO(perf): may not need to compare full text in some cases
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, **(**Ti64)(__ccgo_up(rowids + uintptr(i3)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i3, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 16)), sTarget, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))) >= 0))
		goto _17
	_17:
		;
		i3 = i3 + 1
	}
	goto _8
_5:
	;
	i4 = 0
	for {
		if !(i4 < size) {
			break
		}
		view = buffer + uintptr(i4*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = **(**int32)(__ccgo_up(view))
		sPrefix = view + 4
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v12 = nPrefix
		} else {
			v12 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		if v12 <= nTarget {
			if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v14 = nPrefix
			} else {
				v14 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			v10 = v14
		} else {
			v10 = nTarget
		}
		cmpPrefix4 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		if nPrefix < int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			// if prefix match, check which is longer
			if cmpPrefix4 == 0 {
				Xbitmap_set(tls, b, i4, libc.BoolInt32(nPrefix <= nTarget))
			} else {
				Xbitmap_set(tls, b, i4, libc.BoolInt32(cmpPrefix4 <= 0))
			}
			goto _21
		}
		// TODO(perf): may not need to compare full text in some cases
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, **(**Ti64)(__ccgo_up(rowids + uintptr(i4)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i4, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 16)), sTarget, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))) <= 0))
		goto _21
	_21:
		;
		i4 = i4 + 1
	}
	goto _8
_6:
	;
	i5 = 0
	for {
		if !(i5 < size) {
			break
		}
		view = buffer + uintptr(i5*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix = **(**int32)(__ccgo_up(view))
		sPrefix = view + 4
		if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			v12 = nPrefix
		} else {
			v12 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
		}
		if v12 <= nTarget {
			if nPrefix <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v14 = nPrefix
			} else {
				v14 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			v10 = v14
		} else {
			v10 = nTarget
		}
		cmpPrefix5 = libc.Xstrncmp(tls, sPrefix, sTarget, libc.Uint64FromInt32(v10))
		if nPrefix < int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
			// if prefix match, check which is longer
			if cmpPrefix5 == 0 {
				Xbitmap_set(tls, b, i5, libc.BoolInt32(nPrefix < nTarget))
			} else {
				Xbitmap_set(tls, b, i5, libc.BoolInt32(cmpPrefix5 < 0))
			}
			goto _25
		}
		// TODO(perf): may not need to compare full text in some cases
		rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, **(**Ti64)(__ccgo_up(rowids + uintptr(i5)*8)), bp+24, bp+16)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 24)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i5, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 16)), sTarget, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 24)))) < 0))
		goto _25
	_25:
		;
		i5 = i5 + 1
	}
	goto _8
_7:
	;
	metadataInIdx = libc.Uint64FromInt32(-libc.Int32FromInt32(1))
	i6 = uint64(0)
	for {
		if !(i6 < (*TArray)(unsafe.Pointer(aMetadataIn)).Flength) {
			break
		}
		metadataIn = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(i6)*40
		if (*TVec0MetadataIn)(unsafe.Pointer(metadataIn)).Fargv_idx == argv_idx {
			metadataInIdx = i6
			break
		}
		goto _29
	_29:
		;
		i6 = i6 + 1
	}
	if metadataInIdx < uint64(0) {
		rc = int32(m_SQLITE_ERROR)
		goto done
	}
	metadataIn1 = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(metadataInIdx)*40
	aTarget = metadataIn1 + 8
	i7 = 0
	for {
		if !(i7 < size) {
			break
		}
		view1 = buffer + uintptr(i7*int32(m_VEC0_METADATA_TEXT_VIEW_BUFFER_LENGTH))
		nPrefix1 = **(**int32)(__ccgo_up(view1))
		sPrefix1 = view1 + 4
		target_idx = uint64(0)
		for {
			if !(target_idx < (*TArray)(unsafe.Pointer(aTarget)).Flength) {
				break
			}
			entry = (*TArray)(unsafe.Pointer(aTarget)).Fz + uintptr(target_idx)*16
			if (*TVec0MetadataInTextEntry)(unsafe.Pointer(entry)).Fn != nPrefix1 {
				goto _31
			}
			if nPrefix1 <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				v10 = nPrefix1
			} else {
				v10 = int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH)
			}
			cmpPrefix6 = libc.Xstrncmp(tls, sPrefix1, (*TVec0MetadataInTextEntry)(unsafe.Pointer(entry)).FzString, libc.Uint64FromInt32(v10))
			if nPrefix1 <= int32(m_VEC0_METADATA_TEXT_VIEW_DATA_LENGTH) {
				if cmpPrefix6 == 0 {
					Xbitmap_set(tls, b, i7, int32(1))
					break
				}
				goto _31
			}
			if cmpPrefix6 != 0 {
				goto _31
			}
			rc = Xvec0_get_metadata_text_long_value(tls, p, bp, metadata_idx, **(**Ti64)(__ccgo_up(rowids + uintptr(i7)*8)), bp+40, bp+32)
			if rc != m_SQLITE_OK {
				goto done
			}
			if nPrefix1 != **(**int32)(__ccgo_up(bp + 40)) {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			if libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 32)), (*TVec0MetadataInTextEntry)(unsafe.Pointer(entry)).FzString, libc.Uint64FromInt32(**(**int32)(__ccgo_up(bp + 40)))) == 0 {
				Xbitmap_set(tls, b, i7, int32(1))
				break
			}
			goto _31
		_31:
			;
			target_idx = target_idx + 1
		}
		goto _30
	_30:
		;
		i7 = i7 + 1
	}
	goto _8
_8:
	;
	rc = m_SQLITE_OK
	goto done
done:
	;
	libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	libsqlite3.Xsqlite3_free(tls, rowids)
	return rc
}

// C documentation
//
//	/**
//	 * @brief Parse an vec0 vtab argv[i] column definition and see if
//	 * it's a vector column defintion, ex `contents_embedding float[768]`.
//	 *
//	 * @param source vec0 argv[i] item
//	 * @param source_length length of source in bytes
//	 * @param outColumn Output the parse vector column to this struct, if success
//	 * @return int SQLITE_OK on success, SQLITE_EMPTY is it's not a vector column
//	 * definition, SQLITE_ERROR on error.
//	 */
func Xvec0_parse_vector_column(tls *libc.TLS, source uintptr, source_length int32, outColumn uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var dimensions, keyLength, nameLength, rc, valueLength int32
	var distanceMetric _Vec0DistanceMetrics
	var elementType _VectorElementType
	var key, name, value uintptr
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+24 */ TVec0Token
	_, _, _, _, _, _, _, _, _, _ = dimensions, distanceMetric, elementType, key, keyLength, name, nameLength, rc, value, valueLength
	distanceMetric = int32(_VEC0_DISTANCE_METRIC_L2)
	Xvec0_scanner_init(tls, bp, source, source_length)
	// starts with an identifier
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	name = (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart
	nameLength = int32(int64((**(**TVec0Token)(__ccgo_up(bp + 24))).Fend) - int64((**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart))
	// vector column type comes next: float, int, or bit
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TVec0Token)(__ccgo_up(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart, __ccgo_ts+1771, int32(5)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart, __ccgo_ts+1838, int32(3)) == 0 {
		elementType = int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart, __ccgo_ts+8, int32(4)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart, __ccgo_ts+1842, int32(2)) == 0 {
			elementType = int32(_SQLITE_VEC_ELEMENT_TYPE_INT8)
		} else {
			if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart, __ccgo_ts+13, int32(3)) == 0 {
				elementType = int32(_SQLITE_VEC_ELEMENT_TYPE_BIT)
			} else {
				return int32(m_SQLITE_EMPTY)
			}
		}
	}
	// left '[' bracket
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_LBRACKET) {
		return int32(m_SQLITE_EMPTY)
	}
	// digit, for vector dimension length
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_DIGIT) {
		return int32(m_SQLITE_ERROR)
	}
	dimensions = libc.Xatoi(tls, (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart)
	if dimensions <= 0 {
		return int32(m_SQLITE_ERROR)
	}
	// // right ']' bracket
	rc = Xvec0_scanner_next(tls, bp, bp+24)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_RBRACKET) {
		return int32(m_SQLITE_ERROR)
	}
	// any other tokens left should be column-level options , ex `key=value`
	// ex `distance_metric=L2 distance_metric=cosine` should error
	for int32(1) != 0 {
		// should be EOF or identifier (option key)
		rc = Xvec0_scanner_next(tls, bp, bp+24)
		if rc == int32(m_VEC0_TOKEN_RESULT_EOF) {
			break
		}
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
			return int32(m_SQLITE_ERROR)
		}
		key = (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart
		keyLength = int32(int64((**(**TVec0Token)(__ccgo_up(bp + 24))).Fend) - int64((**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart))
		if libsqlite3.Xsqlite3_strnicmp(tls, key, __ccgo_ts+1845, keyLength) == 0 {
			if elementType == int32(_SQLITE_VEC_ELEMENT_TYPE_BIT) {
				return int32(m_SQLITE_ERROR)
			}
			// ensure equal sign after distance_metric
			rc = Xvec0_scanner_next(tls, bp, bp+24)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_EQ) {
				return int32(m_SQLITE_ERROR)
			}
			// distance_metric value, an identifier (L2, cosine, etc)
			rc = Xvec0_scanner_next(tls, bp, bp+24)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 24))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
				return int32(m_SQLITE_ERROR)
			}
			value = (**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart
			valueLength = int32(int64((**(**TVec0Token)(__ccgo_up(bp + 24))).Fend) - int64((**(**TVec0Token)(__ccgo_up(bp + 24))).Fstart))
			if libsqlite3.Xsqlite3_strnicmp(tls, value, __ccgo_ts+1861, valueLength) == 0 {
				distanceMetric = int32(_VEC0_DISTANCE_METRIC_L2)
			} else {
				if libsqlite3.Xsqlite3_strnicmp(tls, value, __ccgo_ts+1864, valueLength) == 0 {
					distanceMetric = int32(_VEC0_DISTANCE_METRIC_L1)
				} else {
					if libsqlite3.Xsqlite3_strnicmp(tls, value, __ccgo_ts+1867, valueLength) == 0 {
						distanceMetric = int32(_VEC0_DISTANCE_METRIC_COSINE)
					} else {
						return int32(m_SQLITE_ERROR)
					}
				}
			}
		} else {
			return int32(m_SQLITE_ERROR)
		}
	}
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1874, libc.VaList(bp+56, nameLength, name))
	if !((*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fname != 0) {
		return int32(m_SQLITE_ERROR)
	}
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fname_length = nameLength
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fdistance_metric = distanceMetric
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Felement_type = elementType
	(*TVectorColumnDefinition)(unsafe.Pointer(outColumn)).Fdimensions = libc.Uint64FromInt32(dimensions)
	return m_SQLITE_OK
}

func _distance_hamming_u8(tls *libc.TLS, a uintptr, b uintptr, n Tsize_t) (r Tf32) {
	var i uint64
	var same int32
	_, _ = i, same
	same = 0
	i = uint64(0)
	for {
		if !(i < n) {
			break
		}
		same = same + libc.Int32FromUint8(_hamdist_table[libc.Int32FromUint8(**(**Tu8)(__ccgo_up(a + uintptr(i))))^libc.Int32FromUint8(**(**Tu8)(__ccgo_up(b + uintptr(i))))])
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(same)
}

func _vec0Column_fullscan(tls *libc.TLS, pVtab uintptr, pCur uintptr, context uintptr, i int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, vector_idx int32
	var rowid Ti64
	var zErr uintptr
	var _ /* sz at bp+8 */ int32
	var _ /* v at bp+0 */ uintptr
	var _ /* v at bp+16 */ uintptr
	var _ /* v at bp+24 */ uintptr
	_, _, _, _, _, _, _, _, _, _ = auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, rowid, vector_idx, zErr
	if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data != 0) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+10841, -int32(1))
		return int32(m_SQLITE_ERROR)
	}
	rowid = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_query_fullscan_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data)).Frowids_stmt, 0)
	if i == m_VEC0_COLUMN_ID {
		return Xvec0_result_id(tls, pVtab, context, rowid)
	} else {
		if Xvec0_column_idx_is_vector(tls, pVtab, i) != 0 {
			vector_idx = Xvec0_column_idx_to_vector_idx(tls, pVtab, i)
			rc = Xvec0_get_vector_data(tls, pVtab, rowid, vector_idx, bp, bp+8)
			if rc != m_SQLITE_OK {
				return rc
			}
			libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), __ccgo_fp(libsqlite3.Xsqlite3_free))
			libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((**(**TVectorColumnDefinition)(__ccgo_up(pVtab + 608 + uintptr(vector_idx)*32))).Felement_type))
		} else {
			if i == Xvec0_column_distance_idx(tls, pVtab) {
				libsqlite3.Xsqlite3_result_null(tls, context)
			} else {
				if Xvec0_column_idx_is_partition(tls, pVtab, i) != 0 {
					partition_idx = Xvec0_column_idx_to_partition_idx(tls, pVtab, i)
					rc1 = Xvec0_get_partition_value_for_rowid(tls, pVtab, rowid, partition_idx, bp+16)
					if rc1 == m_SQLITE_OK {
						libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp + 16)))
						libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp + 16)))
					} else {
						libsqlite3.Xsqlite3_result_error_code(tls, context, rc1)
					}
				} else {
					if Xvec0_column_idx_is_auxiliary(tls, pVtab, i) != 0 {
						auxiliary_idx = Xvec0_column_idx_to_auxiliary_idx(tls, pVtab, i)
						rc2 = Xvec0_get_auxiliary_value_for_rowid(tls, pVtab, rowid, auxiliary_idx, bp+24)
						if rc2 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp + 24)))
							libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp + 24)))
						} else {
							libsqlite3.Xsqlite3_result_error_code(tls, context, rc2)
						}
					} else {
						if Xvec0_column_idx_is_metadata(tls, pVtab, i) != 0 {
							if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
								return m_SQLITE_OK
							}
							metadata_idx = Xvec0_column_idx_to_metadata_idx(tls, pVtab, i)
							rc3 = Xvec0_result_metadata_value_for_rowid(tls, pVtab, rowid, metadata_idx, context)
							if rc3 != m_SQLITE_OK {
								// IMP: V15466_32305
								zErr = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+10891, libc.VaList(bp+40, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname_length, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname, rowid))
								if zErr != 0 {
									libsqlite3.Xsqlite3_result_error(tls, context, zErr, -int32(1))
									libsqlite3.Xsqlite3_free(tls, zErr)
								} else {
									libsqlite3.Xsqlite3_result_error_nomem(tls, context)
								}
							}
						}
					}
				}
			}
		}
	}
	return m_SQLITE_OK
}

func _vec0Column_knn(tls *libc.TLS, pVtab uintptr, pCur uintptr, context uintptr, i int32) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, vector_idx int32
	var rowid, rowid1, rowid2, rowid3 Ti64
	var zErr uintptr
	var _ /* out at bp+0 */ uintptr
	var _ /* sz at bp+8 */ int32
	var _ /* v at bp+16 */ uintptr
	var _ /* v at bp+24 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _ = auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, rowid, rowid1, rowid2, rowid3, vector_idx, zErr
	if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data != 0) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+11001, -int32(1))
		return int32(m_SQLITE_ERROR)
	}
	if i == m_VEC0_COLUMN_ID {
		rowid = **(**Ti64)(__ccgo_up((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8))
		return Xvec0_result_id(tls, pVtab, context, rowid)
	} else {
		if i == Xvec0_column_distance_idx(tls, pVtab) {
			libsqlite3.Xsqlite3_result_double(tls, context, float64(**(**Tf32)(__ccgo_up((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fdistances + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*4))))
			return m_SQLITE_OK
		} else {
			if Xvec0_column_idx_is_vector(tls, pVtab, i) != 0 {
				vector_idx = Xvec0_column_idx_to_vector_idx(tls, pVtab, i)
				rc = Xvec0_get_vector_data(tls, pVtab, **(**Ti64)(__ccgo_up((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8)), vector_idx, bp, bp+8)
				if rc != m_SQLITE_OK {
					return rc
				}
				libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 8)), __ccgo_fp(libsqlite3.Xsqlite3_free))
				libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((**(**TVectorColumnDefinition)(__ccgo_up(pVtab + 608 + uintptr(vector_idx)*32))).Felement_type))
				return m_SQLITE_OK
			} else {
				if Xvec0_column_idx_is_partition(tls, pVtab, i) != 0 {
					partition_idx = Xvec0_column_idx_to_partition_idx(tls, pVtab, i)
					rowid1 = **(**Ti64)(__ccgo_up((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8))
					rc1 = Xvec0_get_partition_value_for_rowid(tls, pVtab, rowid1, partition_idx, bp+16)
					if rc1 == m_SQLITE_OK {
						libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp + 16)))
						libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp + 16)))
					} else {
						libsqlite3.Xsqlite3_result_error_code(tls, context, rc1)
					}
				} else {
					if Xvec0_column_idx_is_auxiliary(tls, pVtab, i) != 0 {
						auxiliary_idx = Xvec0_column_idx_to_auxiliary_idx(tls, pVtab, i)
						rowid2 = **(**Ti64)(__ccgo_up((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8))
						rc2 = Xvec0_get_auxiliary_value_for_rowid(tls, pVtab, rowid2, auxiliary_idx, bp+24)
						if rc2 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp + 24)))
							libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp + 24)))
						} else {
							libsqlite3.Xsqlite3_result_error_code(tls, context, rc2)
						}
					} else {
						if Xvec0_column_idx_is_metadata(tls, pVtab, i) != 0 {
							metadata_idx = Xvec0_column_idx_to_metadata_idx(tls, pVtab, i)
							rowid3 = **(**Ti64)(__ccgo_up((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tvec0_query_knn_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*8))
							rc3 = Xvec0_result_metadata_value_for_rowid(tls, pVtab, rowid3, metadata_idx, context)
							if rc3 != m_SQLITE_OK {
								zErr = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+10891, libc.VaList(bp+40, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname_length, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname, rowid3))
								if zErr != 0 {
									libsqlite3.Xsqlite3_result_error(tls, context, zErr, -int32(1))
									libsqlite3.Xsqlite3_free(tls, zErr)
								} else {
									libsqlite3.Xsqlite3_result_error_nomem(tls, context)
								}
							}
						}
					}
				}
			}
		}
	}
	return m_SQLITE_OK
}

func _vec0Column_point(tls *libc.TLS, pVtab uintptr, pCur uintptr, context uintptr, i int32) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, vector_idx int32
	var rowid, rowid1, rowid2 Ti64
	var zErr uintptr
	var _ /* v at bp+0 */ uintptr
	var _ /* v at bp+8 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rowid, rowid1, rowid2, vector_idx, zErr
	if !((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data != 0) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+10954, -int32(1))
		return int32(m_SQLITE_ERROR)
	}
	if i == m_VEC0_COLUMN_ID {
		return Xvec0_result_id(tls, pVtab, context, (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid)
	} else {
		if i == Xvec0_column_distance_idx(tls, pVtab) {
			libsqlite3.Xsqlite3_result_null(tls, context)
			return m_SQLITE_OK
		} else {
			if Xvec0_column_idx_is_vector(tls, pVtab, i) != 0 {
				if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
					libsqlite3.Xsqlite3_result_null(tls, context)
					return m_SQLITE_OK
				}
				vector_idx = Xvec0_column_idx_to_vector_idx(tls, pVtab, i)
				libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data + 8 + uintptr(vector_idx)*8)), libc.Int32FromUint64(Xvector_column_byte_size(tls, **(**TVectorColumnDefinition)(__ccgo_up(pVtab + 608 + uintptr(vector_idx)*32)))), uintptr(-libc.Int32FromInt32(1)))
				libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((**(**TVectorColumnDefinition)(__ccgo_up(pVtab + 608 + uintptr(vector_idx)*32))).Felement_type))
				return m_SQLITE_OK
			} else {
				if Xvec0_column_idx_is_partition(tls, pVtab, i) != 0 {
					if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
						return m_SQLITE_OK
					}
					partition_idx = Xvec0_column_idx_to_partition_idx(tls, pVtab, i)
					rowid = (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid
					rc = Xvec0_get_partition_value_for_rowid(tls, pVtab, rowid, partition_idx, bp)
					if rc == m_SQLITE_OK {
						libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp)))
						libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp)))
					} else {
						libsqlite3.Xsqlite3_result_error_code(tls, context, rc)
					}
				} else {
					if Xvec0_column_idx_is_auxiliary(tls, pVtab, i) != 0 {
						if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
							return m_SQLITE_OK
						}
						rowid1 = (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid
						auxiliary_idx = Xvec0_column_idx_to_auxiliary_idx(tls, pVtab, i)
						rc1 = Xvec0_get_auxiliary_value_for_rowid(tls, pVtab, rowid1, auxiliary_idx, bp+8)
						if rc1 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp + 8)))
							libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp + 8)))
						} else {
							libsqlite3.Xsqlite3_result_error_code(tls, context, rc1)
						}
					} else {
						if Xvec0_column_idx_is_metadata(tls, pVtab, i) != 0 {
							if libsqlite3.Xsqlite3_vtab_nochange(tls, context) != 0 {
								return m_SQLITE_OK
							}
							rowid2 = (*Tvec0_query_point_data)(unsafe.Pointer((*Tvec0_cursor)(unsafe.Pointer(pCur)).Fpoint_data)).Frowid
							metadata_idx = Xvec0_column_idx_to_metadata_idx(tls, pVtab, i)
							rc2 = Xvec0_result_metadata_value_for_rowid(tls, pVtab, rowid2, metadata_idx, context)
							if rc2 != m_SQLITE_OK {
								zErr = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+10891, libc.VaList(bp+24, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname_length, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1600 + uintptr(metadata_idx)*24))).Fname, rowid2))
								if zErr != 0 {
									libsqlite3.Xsqlite3_result_error(tls, context, zErr, -int32(1))
									libsqlite3.Xsqlite3_free(tls, zErr)
								} else {
									libsqlite3.Xsqlite3_result_error_nomem(tls, context)
								}
							}
						}
					}
				}
			}
		}
	}
	return m_SQLITE_OK
}

func _vec_eachEof(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	return libc.BoolInt32((*Tvec_each_cursor)(unsafe.Pointer(pCur)).FiRowid >= libc.Int64FromUint64((*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fdimensions))
}

func _vec_f32(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var _ /* cleanup at bp+16 */ Tfvec_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* errmsg at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
	rc = _fvec_from_value(tls, **(**uintptr)(__ccgo_up(argv)), bp, bp+8, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 24)))
		return
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up(bp)), libc.Int32FromUint64(**(**Tsize_t)(__ccgo_up(bp + 8))*uint64(4)), **(**Tfvec_cleanup)(__ccgo_up(bp + 16)))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
}

func _vec_int8(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var _ /* cleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* errmsg at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	rc = _int8_vec_from_value(tls, **(**uintptr)(__ccgo_up(argv)), bp, bp+8, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 24)))
		return
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up(bp)), libc.Int32FromUint64(**(**Tsize_t)(__ccgo_up(bp + 8))), uintptr(-libc.Int32FromInt32(1)))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, **(**uintptr)(__ccgo_up(bp)))
}

func _vec_length(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc int32
	var _ /* cleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+32 */ _VectorElementType
	var _ /* errmsg at bp+24 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	rc = Xvector_from_value(tls, **(**uintptr)(__ccgo_up(argv)), bp, bp+8, bp+32, bp+16, bp+24)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 24)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 24)))
		return
	}
	libsqlite3.Xsqlite3_result_int64(tls, context, libc.Int64FromUint64(**(**Tsize_t)(__ccgo_up(bp + 8))))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, **(**uintptr)(__ccgo_up(bp)))
}

func _vec_npy_eachColumnBuffer(tls *libc.TLS, pCur uintptr, context uintptr, i int32) (r int32) {
	switch i {
	case m_VEC_NPY_EACH_COLUMN_VECTOR:
		libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType))
		switch (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType {
		case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
			libsqlite3.Xsqlite3_result_blob(tls, context, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector+uintptr(libc.Uint64FromInt64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid)*(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint64(4)), libc.Int32FromUint64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint64(4)), uintptr(-libc.Int32FromInt32(1)))
		case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
			fallthrough
		case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
			// https://github.com/asg017/sqlite-vec/issues/42
			libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+3426, -int32(1))
			break
		}
		break
	}
	return m_SQLITE_OK
}

func _vec_npy_eachColumnFile(tls *libc.TLS, pCur uintptr, context uintptr, i int32) (r int32) {
	switch i {
	case m_VEC_NPY_EACH_COLUMN_VECTOR:
		switch (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType {
		case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
			libsqlite3.Xsqlite3_result_blob(tls, context, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer+uintptr((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex*(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint64(4)), libc.Int32FromUint64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint64(4)), uintptr(-libc.Int32FromInt32(1)))
		case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
			fallthrough
		case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
			// https://github.com/asg017/sqlite-vec/issues/42
			libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+3426, -int32(1))
			break
		}
		break
	}
	return m_SQLITE_OK
}

func _vec_npy_eachEof(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Finput_type == int32(_VEC_NPY_EACH_INPUT_BUFFER) {
		return libc.BoolInt32(!((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnElements != 0) || libc.Uint64FromInt64((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid) >= (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnElements)
	}
	return (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Feof
}

func _vec_static_blob_entriesBestIndex(tls *libc.TLS, pVTab uintptr, pIdxInfo uintptr) (r int32) {
	var i, iColumn, iKTerm, iLimitTerm, iMatchTerm, op int32
	var p uintptr
	_, _, _, _, _, _, _ = i, iColumn, iKTerm, iLimitTerm, iMatchTerm, op, p
	p = pVTab
	iMatchTerm = -int32(1)
	iLimitTerm = -int32(1)
	// int iRowidTerm = -1; // https://github.com/asg017/sqlite-vec/issues/47
	iKTerm = -int32(1)
	i = 0
	for {
		if !(i < (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnConstraint) {
			break
		}
		if !((**(**Tsqlite3_index_constraint)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).Fusable != 0) {
			goto _1
		}
		iColumn = (**(**Tsqlite3_index_constraint)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).FiColumn
		op = libc.Int32FromUint8((**(**Tsqlite3_index_constraint)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraint + uintptr(i)*12))).Fop)
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_MATCH) && iColumn == m_VEC_STATIC_BLOB_ENTRIES_VECTOR {
			if iMatchTerm > -int32(1) {
				// https://github.com/asg017/sqlite-vec/issues/51
				return int32(m_SQLITE_ERROR)
			}
			iMatchTerm = i
		}
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_LIMIT) {
			iLimitTerm = i
		}
		if op == int32(m_SQLITE_INDEX_CONSTRAINT_EQ) && iColumn == int32(m_VEC_STATIC_BLOB_ENTRIES_K) {
			iKTerm = i
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if iMatchTerm >= 0 {
		if iLimitTerm < 0 && iKTerm < 0 {
			// https://github.com/asg017/sqlite-vec/issues/51
			return int32(m_SQLITE_ERROR)
		}
		if iLimitTerm >= 0 && iKTerm >= 0 {
			return int32(m_SQLITE_ERROR) // limit or k, not both
		}
		if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy < int32(1) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+16003, 0)
			return int32(m_SQLITE_CONSTRAINT)
		}
		if (*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FnOrderBy > int32(1) {
			// https://github.com/asg017/sqlite-vec/issues/51
			Xvtab_set_error(tls, pVTab, __ccgo_ts+16030, 0)
			return int32(m_SQLITE_CONSTRAINT)
		}
		if (**(**Tsqlite3_index_orderby)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).FiColumn != int32(m_VEC_STATIC_BLOB_ENTRIES_DISTANCE) {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+16067, 0)
			return int32(m_SQLITE_CONSTRAINT)
		}
		if (**(**Tsqlite3_index_orderby)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaOrderBy))).Fdesc != 0 {
			Xvtab_set_error(tls, pVTab, __ccgo_ts+8832, 0)
			return int32(m_SQLITE_CONSTRAINT)
		}
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(_VEC_SBE__QUERYPLAN_KNN)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = libc.Float64FromInt32(10)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = int64(10)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).ForderByConsumed = int32(1)
		(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iMatchTerm)*8))).FargvIndex = int32(1)
		(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iMatchTerm)*8))).Fomit = uint8(1)
		if iLimitTerm >= 0 {
			(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iLimitTerm)*8))).FargvIndex = int32(2)
			(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iLimitTerm)*8))).Fomit = uint8(1)
		} else {
			(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iKTerm)*8))).FargvIndex = int32(2)
			(**(**Tsqlite3_index_constraint_usage)(__ccgo_up((*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FaConstraintUsage + uintptr(iKTerm)*8))).Fomit = uint8(1)
		}
	} else {
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FidxNum = int32(_VEC_SBE__QUERYPLAN_FULLSCAN)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedCost = float64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors)
		(*Tsqlite3_index_info)(unsafe.Pointer(pIdxInfo)).FestimatedRows = libc.Int64FromUint64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors)
	}
	return m_SQLITE_OK
}

func _vec_static_blob_entriesColumn(tls *libc.TLS, cur uintptr, context uintptr, i int32) (r int32) {
	var p, pCur uintptr
	var rowid Ti32
	_, _, _ = p, pCur, rowid
	pCur = cur
	p = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	switch (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC_SBE__QUERYPLAN_FULLSCAN):
		switch i {
		case m_VEC_STATIC_BLOB_ENTRIES_VECTOR:
			libsqlite3.Xsqlite3_result_blob(tls, context, (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fp+uintptr(libc.Uint64FromInt64((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid)*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*libc.Uint64FromInt64(4)), libc.Int32FromUint64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*uint64(4)), uintptr(-libc.Int32FromInt32(1)))
			libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Felement_type))
			break
		}
		return m_SQLITE_OK
	case int32(_VEC_SBE__QUERYPLAN_KNN):
		switch i {
		case m_VEC_STATIC_BLOB_ENTRIES_VECTOR:
			rowid = **(**Ti32)(__ccgo_up((*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Frowids + uintptr((*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx)*4))
			libsqlite3.Xsqlite3_result_blob(tls, context, (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fp+uintptr(libc.Uint64FromInt32(rowid)*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*libc.Uint64FromInt64(4)), libc.Int32FromUint64((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*uint64(4)), uintptr(-libc.Int32FromInt32(1)))
			libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Felement_type))
			break
		}
		return m_SQLITE_OK
	}
	return int32(m_SQLITE_ERROR)
}

func _vec_static_blob_entriesEof(tls *libc.TLS, cur uintptr) (r int32) {
	var p, pCur uintptr
	_, _ = p, pCur
	pCur = cur
	p = (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fbase.FpVtab
	switch (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan {
	case int32(_VEC_SBE__QUERYPLAN_FULLSCAN):
		return libc.BoolInt32(libc.Uint64FromInt64((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid) >= (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors)
	case int32(_VEC_SBE__QUERYPLAN_KNN):
		return libc.BoolInt32((*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fcurrent_idx >= (*Tsbe_query_knn_data)(unsafe.Pointer((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data)).Fk)
	}
	return int32(m_SQLITE_ERROR)
}

func _vec_static_blobsColumn(tls *libc.TLS, cur uintptr, context uintptr, i int32) (r int32) {
	var p, pCur uintptr
	_, _ = p, pCur
	pCur = cur
	p = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(cur)).FpVtab
	switch i {
	case m_VEC_STATIC_BLOBS_NAME:
		libsqlite3.Xsqlite3_result_text(tls, context, (**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*40))).Fname, -int32(1), uintptr(-libc.Int32FromInt32(1)))
	case int32(m_VEC_STATIC_BLOBS_DATA):
		libsqlite3.Xsqlite3_result_null(tls, context)
	case int32(m_VEC_STATIC_BLOBS_DIMENSIONS):
		libsqlite3.Xsqlite3_result_int64(tls, context, libc.Int64FromUint64((**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*40))).Fdimensions))
	case int32(m_VEC_STATIC_BLOBS_COUNT):
		libsqlite3.Xsqlite3_result_int64(tls, context, libc.Int64FromUint64((**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*40))).Fnvectors))
		break
	}
	return m_SQLITE_OK
}

const m__LP64 = 1

const m___LONG_WIDTH__ = 64

const m___LP64__ = 1

const m___SIZEOF_LONG__ = 8
