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

//go:build (freebsd && 386) || (freebsd && arm) || (linux && 386) || (linux && arm)

package vec

import (
	"unsafe"

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

// C documentation
//
//	/**
//	 * @brief Initial an array with the given element size and capacity.
//	 *
//	 * @param array
//	 * @param element_size
//	 * @param init_capacity
//	 * @return SQLITE_OK on success, error code on failure. Only error is
//	 * SQLITE_NOMEM
//	 */
func Xarray_init(tls *libc.TLS, array uintptr, element_size Tsize_t, init_capacity Tsize_t) (r int32) {
	var sz int32
	var z uintptr
	_, _ = sz, z
	sz = libc.Int32FromUint32(element_size * init_capacity)
	z = libsqlite3.Xsqlite3_malloc(tls, sz)
	if !(z != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, z, 0, libc.Uint32FromInt32(sz))
	(*TArray)(unsafe.Pointer(array)).Felement_size = element_size
	(*TArray)(unsafe.Pointer(array)).Flength = uint32(0)
	(*TArray)(unsafe.Pointer(array)).Fcapacity = init_capacity
	(*TArray)(unsafe.Pointer(array)).Fz = z
	return m_SQLITE_OK
}

func Xparse_npy_buffer(tls *libc.TLS, pVTab uintptr, buffer uintptr, bufferLength int32, data uintptr, numElements uintptr, numDimensions uintptr, element_type uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var dataSize, expectedDataSize, totalHeaderLength Ti32
	var header uintptr
	var major, minor Tu8
	var rc int32
	var _ /* fortran_order at bp+4 */ int32
	var _ /* headerLength at bp+0 */ Tuint16_t
	_, _, _, _, _, _, _ = dataSize, expectedDataSize, header, major, minor, rc, totalHeaderLength
	if bufferLength < int32(10) {
		// IMP: V03312_20150
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3171, 0)
		return int32(m_SQLITE_ERROR)
	}
	if libc.Xmemcmp(tls, uintptr(unsafe.Pointer(&_NPY_MAGIC)), buffer, uint32(6)) != 0 {
		// V11954_28792
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3193, 0)
		return int32(m_SQLITE_ERROR)
	}
	major = **(**uint8)(__ccgo_up(buffer + 6))
	minor = **(**uint8)(__ccgo_up(buffer + 7))
	**(**Tuint16_t)(__ccgo_up(bp)) = uint16(0)
	libc.Xmemcpy(tls, bp, buffer+8, uint32(2))
	totalHeaderLength = libc.Int32FromUint32(libc.Uint32FromInt64(6) + libc.Uint32FromInt64(1) + libc.Uint32FromInt64(1) + libc.Uint32FromInt64(2) + uint32(**(**Tuint16_t)(__ccgo_up(bp))))
	dataSize = bufferLength - totalHeaderLength
	if dataSize < 0 {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3241, 0)
		return int32(m_SQLITE_ERROR)
	}
	header = buffer + 10
	rc = Xparse_npy_header(tls, pVTab, header, uint32(**(**Tuint16_t)(__ccgo_up(bp))), element_type, bp+4, numElements, numDimensions)
	if rc != m_SQLITE_OK {
		return rc
	}
	expectedDataSize = libc.Int32FromUint32(**(**Tsize_t)(__ccgo_up(numElements)) * Xvector_byte_size(tls, **(**_VectorElementType)(__ccgo_up(element_type)), **(**Tsize_t)(__ccgo_up(numDimensions))))
	if expectedDataSize != dataSize {
		Xvtab_set_error(tls, pVTab, __ccgo_ts+3278, libc.VaList(bp+16, expectedDataSize, dataSize))
		return int32(m_SQLITE_ERROR)
	}
	**(**uintptr)(__ccgo_up(data)) = buffer + uintptr(totalHeaderLength)
	return m_SQLITE_OK
}

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(32)
	defer tls.Free(32)
	var first Tsize_t
	var key uintptr
	var rc, v1 int32
	var _ /* scanner at bp+0 */ TNpyScanner
	var _ /* token at bp+12 */ TNpyToken
	_, _, _, _ = first, key, rc, v1
	Xnpy_scanner_init(tls, bp, header, libc.Int32FromUint32(headerLength))
	if Xnpy_scanner_next(tls, bp, bp+12) != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TNpyToken)(__ccgo_up(bp + 12))).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+12)
		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 + 12))).Ftoken_type == int32(_NPY_TOKEN_TYPE_RBRACE) {
			break
		}
		if (**(**TNpyToken)(__ccgo_up(bp + 12))).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 + 12))).Fstart
		rc = Xnpy_scanner_next(tls, bp, bp+12)
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 12))).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+12)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 12))).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 + 12))).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+12)
				if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 12))).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+12)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 12))).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+12)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 12))).Ftoken_type != int32(_NPY_TOKEN_TYPE_NUMBER) {
						Xvtab_set_error(tls, pVTab, __ccgo_ts+2543, 0)
						return int32(m_SQLITE_ERROR)
					}
					first = libc.Uint32FromInt32(libc.Xstrtol(tls, (**(**TNpyToken)(__ccgo_up(bp + 12))).Fstart, libc.UintptrFromInt32(0), int32(10)))
					rc = Xnpy_scanner_next(tls, bp, bp+12)
					if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 12))).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+12)
					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 + 12))).Ftoken_type == int32(_NPY_TOKEN_TYPE_NUMBER) {
						**(**Tsize_t)(__ccgo_up(numElements)) = first
						**(**Tsize_t)(__ccgo_up(numDimensions)) = libc.Uint32FromInt32(libc.Xstrtol(tls, (**(**TNpyToken)(__ccgo_up(bp + 12))).Fstart, libc.UintptrFromInt32(0), int32(10)))
						rc = Xnpy_scanner_next(tls, bp, bp+12)
						if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 12))).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 + 12))).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.Uint32FromInt32(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+12)
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TNpyToken)(__ccgo_up(bp + 12))).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_ClearVectors(tls *libc.TLS, p uintptr, chunk_id Ti64, chunk_offset Tu64) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var brc, i, rc int32
	var n Tsize_t
	var zeroBuf uintptr
	var _ /* blobVectors at bp+0 */ uintptr
	_, _, _, _, _ = brc, i, n, rc, zeroBuf
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
		n = Xvector_column_byte_size(tls, **(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20)))
		rc = libsqlite3.Xsqlite3_blob_open(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)), __ccgo_ts+3712, chunk_id, int32(1), bp)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+14213, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)), chunk_id, i))
			return int32(m_SQLITE_ERROR)
		}
		zeroBuf = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint32(n))
		if !(zeroBuf != 0) {
			libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp)))
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, zeroBuf, 0, n)
		rc = libsqlite3.Xsqlite3_blob_write(tls, **(**uintptr)(__ccgo_up(bp)), zeroBuf, libc.Int32FromUint32(n), libc.Int32FromUint64(chunk_offset*uint64(n)))
		libsqlite3.Xsqlite3_free(tls, zeroBuf)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+14265, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)), chunk_id, chunk_offset, i))
		}
		brc = libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp)))
		if rc != m_SQLITE_OK {
			return rc
		}
		if brc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+14329, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)), chunk_id, i))
			return brc
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	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+4 */ 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+16, 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+16, (*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+4, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		return rc
	}
	libsqlite3.Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp + 4)), int32(1), chunk_id)
	rc = libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 4)))
	libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 4)))
	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+16, (*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+4, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			return rc
		}
		libsqlite3.Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp + 4)), int32(1), chunk_id)
		rc = libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 4)))
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 4)))
		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+16, (*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+4, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			return rc
		}
		libsqlite3.Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp + 4)), int32(1), chunk_id)
		rc = libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 4)))
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 4)))
		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(240)
	defer tls.Free(240)
	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+168 */ uintptr
	var _ /* bufferChunksValidity at bp+172 */ uintptr
	var _ /* chunk_offset at bp+160 */ Ti64
	var _ /* chunk_rowid at bp+152 */ Ti64
	var _ /* cleanups at bp+72 */ [16]Tvector_cleanup
	var _ /* dimensions at bp+176 */ Tsize_t
	var _ /* elementType at bp+184 */ _VectorElementType
	var _ /* partitionKeyValues at bp+136 */ [4]uintptr
	var _ /* pzError at bp+180 */ uintptr
	var _ /* rowid at bp+0 */ Ti64
	var _ /* stmt at bp+188 */ 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 + 168)) = libc.UintptrFromInt32(0)
	// buffer for the valididty column for the given chunk. Maybe not needed here?
	**(**uintptr)(__ccgo_up(bp + 172)) = 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 + 52 + uintptr(i)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION) {
			goto _1
		}
		partition_key_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 260 + uintptr(i))))
		(**(**[4]uintptr)(__ccgo_up(bp + 136)))[partition_key_idx] = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i)*4))
		new_value_type = libsqlite3.Xsqlite3_value_type(tls, (**(**[4]uintptr)(__ccgo_up(bp + 136)))[partition_key_idx])
		if new_value_type != int32(m_SQLITE_NULL) && new_value_type != (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 760 + uintptr(partition_key_idx)*12))).Ftype1 {
			// IMP: V11454_28292
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13042, libc.VaList(bp+200, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 760 + uintptr(partition_key_idx)*12))).Fname_length, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 760 + uintptr(partition_key_idx)*12))).Fname, Xtype_name(tls, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 760 + uintptr(partition_key_idx)*12))).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 + 52 + uintptr(i1)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
			goto _2
		}
		vector_column_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 260 + uintptr(i1))))
		valueVector = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i1)*4))
		rc = Xvector_from_value(tls, valueVector, bp+8+uintptr(vector_column_idx)*4, bp+176, bp+184, bp+72+uintptr(vector_column_idx)*4, bp+180)
		if rc != m_SQLITE_OK {
			// IMP: V06519_23358
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13134, libc.VaList(bp+200, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(vector_column_idx)*20))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(vector_column_idx)*20))).Fname, **(**uintptr)(__ccgo_up(bp + 180))))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		numReadVectors = numReadVectors + 1
		if **(**_VectorElementType)(__ccgo_up(bp + 184)) != (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(vector_column_idx)*20))).Felement_type {
			// IMP: V08221_25059
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13187, libc.VaList(bp+200, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i1)*20))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i1)*20))).Fname, Xvector_subtype_name(tls, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i1)*20))).Felement_type), Xvector_subtype_name(tls, **(**_VectorElementType)(__ccgo_up(bp + 184)))))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		if **(**Tsize_t)(__ccgo_up(bp + 176)) != (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(vector_column_idx)*20))).Fdimensions {
			// IMP: V01145_17984
			Xvtab_set_error(tls, pVTab, __ccgo_ts+13285, libc.VaList(bp+200, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(vector_column_idx)*20))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(vector_column_idx)*20))).Fname, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(vector_column_idx)*20))).Fdimensions, **(**Tsize_t)(__ccgo_up(bp + 176))))
			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))*4))) != 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))*4))) != 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))*4)), 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+136, bp+152, bp+160, bp+168, bp+172)
	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 + 152)), **(**Ti64)(__ccgo_up(bp + 160)), **(**Ti64)(__ccgo_up(bp)), bp+8, **(**uintptr)(__ccgo_up(bp + 168)), **(**uintptr)(__ccgo_up(bp + 172)))
	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+200, (*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+200, 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+188, libc.UintptrFromInt32(0))
		if rc != m_SQLITE_OK {
			goto cleanup
		}
		libsqlite3.Xsqlite3_bind_int64(tls, **(**uintptr)(__ccgo_up(bp + 188)), 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 + 52 + uintptr(i4)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY) {
				goto _5
			}
			auxiliary_key_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 260 + uintptr(i4))))
			v = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i4)*4))
			v_type = libsqlite3.Xsqlite3_value_type(tls, v)
			if v_type != int32(m_SQLITE_NULL) && v_type != (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 808 + uintptr(auxiliary_key_idx)*12))).Ftype1 {
				libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 188)))
				rc = int32(m_SQLITE_CONSTRAINT)
				Xvtab_set_error(tls, pVTab, __ccgo_ts+13542, libc.VaList(bp+200, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 808 + uintptr(auxiliary_key_idx)*12))).Fname_length, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 808 + uintptr(auxiliary_key_idx)*12))).Fname, Xtype_name(tls, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 808 + uintptr(auxiliary_key_idx)*12))).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 + 188)), 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 + 188)))
		if rc != int32(m_SQLITE_DONE) {
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 188)))
			rc = int32(m_SQLITE_ERROR)
			goto cleanup
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 188)))
	}
	i5 = 0
	for {
		if !(i5 < Xvec0_num_defined_user_columns(tls, p)) {
			break
		}
		if **(**Tvec0_user_column_kind)(__ccgo_up(p + 52 + uintptr(i5)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA) {
			goto _6
		}
		metadata_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 260 + uintptr(i5))))
		v1 = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i5)*4))
		rc = Xvec0_write_metadata_value(tls, p, metadata_idx, **(**Ti64)(__ccgo_up(bp)), **(**Ti64)(__ccgo_up(bp + 152)), **(**Ti64)(__ccgo_up(bp + 160)), 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 + 72)))[i6]})))(tls, (**(**[16]uintptr)(__ccgo_up(bp + 8)))[i6])
		goto _7
	_7:
		;
		i6 = i6 + 1
	}
	libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 172)))
	brc = libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 168)))
	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*4)))
		// IMP: V08886_25725
		if libsqlite3.Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv))) != libsqlite3.Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 1*4))) || libc.Xstrncmp(tls, a, b, libc.Uint32FromInt32(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 + 52 + 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)*4))
		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 + 52 + uintptr(i1)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY) {
			goto _2
		}
		auxiliary_column_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 260 + uintptr(i1))))
		value1 = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i1)*4))
		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 + 52 + uintptr(i2)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA) {
			goto _3
		}
		metadata_column_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 260 + uintptr(i2))))
		value2 = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i2)*4))
		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 + 52 + uintptr(i3)*4)) != int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR) {
			goto _4
		}
		vector_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(p + 260 + uintptr(i3))))
		valueVector = **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC0_COLUMN_USERN_START)+i3)*4))
		// 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 + 260 + 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 + 260 + 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 + 260 + 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 + 260 + 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 + 312 + uintptr(vector_column_idx)*4)), __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 + 440 + uintptr(vector_column_idx)*20)))
	blobOffset = int32(**(**Ti64)(__ccgo_up(bp + 8)) * libc.Int64FromUint32(size))
	buf = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint32(size))
	if !(buf != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto cleanup
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, **(**uintptr)(__ccgo_up(bp + 16)), buf, libc.Int32FromUint32(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.Int32FromUint32(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.Int32FromUint32(libc.Uint32FromInt32(chunk_size) * uint32(8))
	case int32(_VEC0_METADATA_COLUMN_KIND_FLOAT):
		return libc.Int32FromUint32(libc.Uint32FromInt32(chunk_size) * uint32(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(32)
	defer tls.Free(32)
	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+12 */ int32
	var _ /* nFull at bp+20 */ int32
	var _ /* rowidsBlob at bp+4 */ uintptr
	var _ /* sFull at bp+16 */ uintptr
	var _ /* sFull at bp+8 */ 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+4)
	if rc != m_SQLITE_OK {
		return rc
	}
	rowids = libsqlite3.Xsqlite3_malloc(tls, libsqlite3.Xsqlite3_blob_bytes(tls, **(**uintptr)(__ccgo_up(bp + 4))))
	if !(rowids != 0) {
		libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 4)))
		return int32(m_SQLITE_NOMEM)
	}
	rc = libsqlite3.Xsqlite3_blob_read(tls, **(**uintptr)(__ccgo_up(bp + 4)), rowids, libsqlite3.Xsqlite3_blob_bytes(tls, **(**uintptr)(__ccgo_up(bp + 4))), 0)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 4)))
		return rc
	}
	libsqlite3.Xsqlite3_blob_close(tls, **(**uintptr)(__ccgo_up(bp + 4)))
	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.Uint32FromInt32(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+12, bp+8)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 12)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 8)), sTarget, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 12)))) == 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.Uint32FromInt32(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+12, bp+8)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 12)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i1, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 8)), sTarget, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 12)))) != 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.Uint32FromInt32(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+12, bp+8)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 12)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i2, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 8)), sTarget, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 12)))) > 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.Uint32FromInt32(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+12, bp+8)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 12)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i3, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 8)), sTarget, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 12)))) >= 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.Uint32FromInt32(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+12, bp+8)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 12)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i4, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 8)), sTarget, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 12)))) <= 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.Uint32FromInt32(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+12, bp+8)
		if rc != m_SQLITE_OK {
			goto done
		}
		if nPrefix != **(**int32)(__ccgo_up(bp + 12)) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		Xbitmap_set(tls, b, i5, libc.BoolInt32(libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 8)), sTarget, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 12)))) < 0))
		goto _25
	_25:
		;
		i5 = i5 + 1
	}
	goto _8
_7:
	;
	metadataInIdx = libc.Uint32FromInt32(-libc.Int32FromInt32(1))
	i6 = uint32(0)
	for {
		if !(i6 < (*TArray)(unsafe.Pointer(aMetadataIn)).Flength) {
			break
		}
		metadataIn = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(i6)*24
		if (*TVec0MetadataIn)(unsafe.Pointer(metadataIn)).Fargv_idx == argv_idx {
			metadataInIdx = i6
			break
		}
		goto _29
	_29:
		;
		i6 = i6 + 1
	}
	if metadataInIdx < uint32(0) {
		rc = int32(m_SQLITE_ERROR)
		goto done
	}
	metadataIn1 = (*TArray)(unsafe.Pointer(aMetadataIn)).Fz + uintptr(metadataInIdx)*24
	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 = uint32(0)
		for {
			if !(target_idx < (*TArray)(unsafe.Pointer(aTarget)).Flength) {
				break
			}
			entry = (*TArray)(unsafe.Pointer(aTarget)).Fz + uintptr(target_idx)*8
			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.Uint32FromInt32(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+20, bp+16)
			if rc != m_SQLITE_OK {
				goto done
			}
			if nPrefix1 != **(**int32)(__ccgo_up(bp + 20)) {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			if libc.Xstrncmp(tls, **(**uintptr)(__ccgo_up(bp + 16)), (*TVec0MetadataInTextEntry)(unsafe.Pointer(entry)).FzString, libc.Uint32FromInt32(**(**int32)(__ccgo_up(bp + 20)))) == 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(48)
	defer tls.Free(48)
	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+12 */ 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+12)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 12))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	name = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
	nameLength = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)
	// vector column type comes next: float, int, or bit
	rc = Xvec0_scanner_next(tls, bp, bp+12)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) || (**(**TVec0Token)(__ccgo_up(bp + 12))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1771, int32(5)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1838, int32(3)) == 0 {
		elementType = int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+8, int32(4)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1842, int32(2)) == 0 {
			elementType = int32(_SQLITE_VEC_ELEMENT_TYPE_INT8)
		} else {
			if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).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+12)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 12))).Ftoken_type != int32(_TOKEN_TYPE_LBRACKET) {
		return int32(m_SQLITE_EMPTY)
	}
	// digit, for vector dimension length
	rc = Xvec0_scanner_next(tls, bp, bp+12)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 12))).Ftoken_type != int32(_TOKEN_TYPE_DIGIT) {
		return int32(m_SQLITE_ERROR)
	}
	dimensions = libc.Xatoi(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)
	if dimensions <= 0 {
		return int32(m_SQLITE_ERROR)
	}
	// // right ']' bracket
	rc = Xvec0_scanner_next(tls, bp, bp+12)
	if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 12))).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+12)
		if rc == int32(m_VEC0_TOKEN_RESULT_EOF) {
			break
		}
		if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 12))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
			return int32(m_SQLITE_ERROR)
		}
		key = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
		keyLength = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).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+12)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 12))).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+12)
			if rc != int32(m_VEC0_TOKEN_RESULT_SOME) && (**(**TVec0Token)(__ccgo_up(bp + 12))).Ftoken_type != int32(_TOKEN_TYPE_IDENTIFIER) {
				return int32(m_SQLITE_ERROR)
			}
			value = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
			valueLength = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).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+32, 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.Uint32FromInt32(dimensions)
	return m_SQLITE_OK
}

func _distance_hamming_u64(tls *libc.TLS, a uintptr, b uintptr, n Tsize_t) (r Tf32) {
	var i uint32
	var same int32
	_, _ = i, same
	same = 0
	i = uint32(0)
	for {
		if !(i < n) {
			break
		}
		same = same + libc.X__builtin_popcountll(tls, **(**Tu64)(__ccgo_up(a + uintptr(i)*8))^**(**Tu64)(__ccgo_up(b + uintptr(i)*8)))
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(same)
}

func _distance_hamming_u8(tls *libc.TLS, a uintptr, b uintptr, n Tsize_t) (r Tf32) {
	var i uint32
	var same int32
	_, _ = i, same
	same = 0
	i = uint32(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(48)
	defer tls.Free(48)
	var auxiliary_idx, metadata_idx, partition_idx, rc, rc1, rc2, rc3, vector_idx int32
	var rowid Ti64
	var zErr uintptr
	var _ /* sz at bp+4 */ int32
	var _ /* v at bp+0 */ uintptr
	var _ /* v at bp+12 */ uintptr
	var _ /* v at bp+8 */ 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+4)
			if rc != m_SQLITE_OK {
				return rc
			}
			libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), __ccgo_fp(libsqlite3.Xsqlite3_free))
			libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((**(**TVectorColumnDefinition)(__ccgo_up(pVtab + 440 + uintptr(vector_idx)*20))).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+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_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+12)
						if rc2 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp + 12)))
							libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp + 12)))
						} 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+24, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1000 + uintptr(metadata_idx)*12))).Fname_length, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1000 + uintptr(metadata_idx)*12))).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(48)
	defer tls.Free(48)
	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+4 */ int32
	var _ /* v at bp+12 */ uintptr
	var _ /* v at bp+8 */ 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+4)
				if rc != m_SQLITE_OK {
					return rc
				}
				libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), __ccgo_fp(libsqlite3.Xsqlite3_free))
				libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((**(**TVectorColumnDefinition)(__ccgo_up(pVtab + 440 + uintptr(vector_idx)*20))).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+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_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+12)
						if rc2 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp + 12)))
							libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp + 12)))
						} 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+24, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1000 + uintptr(metadata_idx)*12))).Fname_length, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1000 + uintptr(metadata_idx)*12))).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+4 */ 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)*4)), libc.Int32FromUint32(Xvector_column_byte_size(tls, **(**TVectorColumnDefinition)(__ccgo_up(pVtab + 440 + uintptr(vector_idx)*20)))), uintptr(-libc.Int32FromInt32(1)))
				libsqlite3.Xsqlite3_result_subtype(tls, context, libc.Uint32FromInt32((**(**TVectorColumnDefinition)(__ccgo_up(pVtab + 440 + uintptr(vector_idx)*20))).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+4)
						if rc1 == m_SQLITE_OK {
							libsqlite3.Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(bp + 4)))
							libsqlite3.Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up(bp + 4)))
						} 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+16, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1000 + uintptr(metadata_idx)*12))).Fname_length, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pVtab + 1000 + uintptr(metadata_idx)*12))).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 _vec0_init(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr, isCreate uint8) (r int32) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var auxiliary_idx, chunk_size, i, i1, i2, i3, i4, i5, i6, i7, metadata_idx, numAuxiliaryColumns, numMetadataColumns, numPartitionColumns, numVectorColumns, partition_idx, pkColumnNameLength, pkColumnType, rc, rc1, user_column_idx, vector_idx int32
	var createStr, pNew, pkColumnName, s, s1, schemaName, tableName, zCreateInfo, zCreateShadowChunks, zCreateShadowRowids, zSeedInfo, zSql, zSql1, zSql2, zSql3, zSql4 uintptr
	var _ /* auxColumn at bp+32 */ TVec0AuxiliaryColumnDefinition
	var _ /* cName at bp+56 */ uintptr
	var _ /* cNameLength at bp+60 */ int32
	var _ /* cType at bp+64 */ int32
	var _ /* key at bp+72 */ uintptr
	var _ /* keyLength at bp+80 */ int32
	var _ /* kind at bp+68 */ Tvec0_metadata_column_kind
	var _ /* metadataColumn at bp+44 */ TVec0MetadataColumnDefinition
	var _ /* partitionColumn at bp+20 */ TVec0PartitionColumnDefinition
	var _ /* stmt at bp+88 */ uintptr
	var _ /* stmt at bp+92 */ uintptr
	var _ /* value at bp+76 */ uintptr
	var _ /* valueLength at bp+84 */ int32
	var _ /* vecColumn at bp+0 */ TVectorColumnDefinition
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = auxiliary_idx, chunk_size, createStr, i, i1, i2, i3, i4, i5, i6, i7, metadata_idx, numAuxiliaryColumns, numMetadataColumns, numPartitionColumns, numVectorColumns, pNew, partition_idx, pkColumnName, pkColumnNameLength, pkColumnType, rc, rc1, s, s1, schemaName, tableName, user_column_idx, vector_idx, zCreateInfo, zCreateShadowChunks, zCreateShadowRowids, zSeedInfo, zSql, zSql1, zSql2, zSql3, zSql4
	_ = pAux
	pNew = libsqlite3.Xsqlite3_malloc(tls, int32(1216))
	if pNew == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pNew, 0, uint32(1216))
	// Declared chunk_size=N for entire table.
	// -1 to use the defualt, otherwise will get re-assigned on `chunk_size=N`
	// option
	chunk_size = -int32(1)
	numVectorColumns = 0
	numPartitionColumns = 0
	numAuxiliaryColumns = 0
	numMetadataColumns = 0
	user_column_idx = 0
	// track if a "primary key" column is defined
	pkColumnName = libc.UintptrFromInt32(0)
	pkColumnType = int32(m_SQLITE_INTEGER)
	i = int32(3)
	for {
		if !(i < argc) {
			break
		}
		**(**uintptr)(__ccgo_up(bp + 56)) = libc.UintptrFromInt32(0)
		// Scenario #1: Constructor argument is a vector column definition, ie `foo float[1024]`
		rc = Xvec0_parse_vector_column(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)), libc.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))), bp)
		if rc == int32(m_SQLITE_ERROR) {
			**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5489, libc.VaList(bp+104, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4))))
			goto error
		}
		if rc == m_SQLITE_OK {
			if numVectorColumns >= int32(m_VEC0_MAX_VECTOR_COLUMNS) {
				libsqlite3.Xsqlite3_free(tls, (**(**TVectorColumnDefinition)(__ccgo_up(bp))).Fname)
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5548, libc.VaList(bp+104, int32(m_VEC0_MAX_VECTOR_COLUMNS)))
				goto error
			}
			if (**(**TVectorColumnDefinition)(__ccgo_up(bp))).Fdimensions > uint32(m_SQLITE_VEC_VEC0_MAX_DIMENSIONS) {
				libsqlite3.Xsqlite3_free(tls, (**(**TVectorColumnDefinition)(__ccgo_up(bp))).Fname)
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5617, libc.VaList(bp+104, libc.Int64FromUint32((**(**TVectorColumnDefinition)(__ccgo_up(bp))).Fdimensions), int32(m_SQLITE_VEC_VEC0_MAX_DIMENSIONS)))
				goto error
			}
			**(**Tvec0_user_column_kind)(__ccgo_up(pNew + 52 + uintptr(user_column_idx)*4)) = int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR)
			**(**Tuint8_t)(__ccgo_up(pNew + 260 + uintptr(user_column_idx))) = libc.Uint8FromInt32(numVectorColumns)
			libc.Xmemcpy(tls, pNew+440+uintptr(numVectorColumns)*20, bp, uint32(20))
			numVectorColumns = numVectorColumns + 1
			(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumVectorColumns = numVectorColumns
			user_column_idx = user_column_idx + 1
			goto _1
		}
		// Scenario #2: Constructor argument is a partition key column definition, ie `user_id text partition key`
		rc = Xvec0_parse_partition_key_definition(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)), libc.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))), bp+56, bp+60, bp+64)
		if rc == m_SQLITE_OK {
			if numPartitionColumns >= int32(m_VEC0_MAX_PARTITION_COLUMNS) {
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5707, libc.VaList(bp+104, int32(m_VEC0_MAX_PARTITION_COLUMNS)))
				goto error
			}
			(**(**TVec0PartitionColumnDefinition)(__ccgo_up(bp + 20))).Ftype1 = **(**int32)(__ccgo_up(bp + 64))
			(**(**TVec0PartitionColumnDefinition)(__ccgo_up(bp + 20))).Fname_length = **(**int32)(__ccgo_up(bp + 60))
			(**(**TVec0PartitionColumnDefinition)(__ccgo_up(bp + 20))).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1874, libc.VaList(bp+104, **(**int32)(__ccgo_up(bp + 60)), **(**uintptr)(__ccgo_up(bp + 56))))
			if !((**(**TVec0PartitionColumnDefinition)(__ccgo_up(bp + 20))).Fname != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto error
			}
			**(**Tvec0_user_column_kind)(__ccgo_up(pNew + 52 + uintptr(user_column_idx)*4)) = int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION)
			**(**Tuint8_t)(__ccgo_up(pNew + 260 + uintptr(user_column_idx))) = libc.Uint8FromInt32(numPartitionColumns)
			libc.Xmemcpy(tls, pNew+760+uintptr(numPartitionColumns)*12, bp+20, uint32(12))
			numPartitionColumns = numPartitionColumns + 1
			(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumPartitionColumns = numPartitionColumns
			user_column_idx = user_column_idx + 1
			goto _1
		}
		// Scenario #3: Constructor argument is a primary key column definition, ie `article_id text primary key`
		rc = Xvec0_parse_primary_key_definition(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)), libc.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))), bp+56, bp+60, bp+64)
		if rc == m_SQLITE_OK {
			if pkColumnName != 0 {
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5780, libc.VaList(bp+104, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4))))
				goto error
			}
			pkColumnName = **(**uintptr)(__ccgo_up(bp + 56))
			pkColumnNameLength = **(**int32)(__ccgo_up(bp + 60))
			pkColumnType = **(**int32)(__ccgo_up(bp + 64))
			goto _1
		}
		// Scenario #4: Constructor argument is a auxiliary column definition, ie `+contents text`
		rc = Xvec0_parse_auxiliary_column_definition(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)), libc.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))), bp+56, bp+60, bp+64)
		if rc == m_SQLITE_OK {
			if numAuxiliaryColumns >= int32(m_VEC0_MAX_AUXILIARY_COLUMNS) {
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5901, libc.VaList(bp+104, int32(m_VEC0_MAX_AUXILIARY_COLUMNS)))
				goto error
			}
			(**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(bp + 32))).Ftype1 = **(**int32)(__ccgo_up(bp + 64))
			(**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(bp + 32))).Fname_length = **(**int32)(__ccgo_up(bp + 60))
			(**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(bp + 32))).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1874, libc.VaList(bp+104, **(**int32)(__ccgo_up(bp + 60)), **(**uintptr)(__ccgo_up(bp + 56))))
			if !((**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(bp + 32))).Fname != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto error
			}
			**(**Tvec0_user_column_kind)(__ccgo_up(pNew + 52 + uintptr(user_column_idx)*4)) = int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY)
			**(**Tuint8_t)(__ccgo_up(pNew + 260 + uintptr(user_column_idx))) = libc.Uint8FromInt32(numAuxiliaryColumns)
			libc.Xmemcpy(tls, pNew+808+uintptr(numAuxiliaryColumns)*12, bp+32, uint32(12))
			numAuxiliaryColumns = numAuxiliaryColumns + 1
			(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumAuxiliaryColumns = numAuxiliaryColumns
			user_column_idx = user_column_idx + 1
			goto _1
		}
		rc = Xvec0_parse_metadata_column_definition(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)), libc.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))), bp+56, bp+60, bp+68)
		if rc == m_SQLITE_OK {
			if numMetadataColumns >= int32(m_VEC0_MAX_METADATA_COLUMNS) {
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+5970, libc.VaList(bp+104, int32(m_VEC0_MAX_METADATA_COLUMNS)))
				goto error
			}
			(**(**TVec0MetadataColumnDefinition)(__ccgo_up(bp + 44))).Fkind = **(**Tvec0_metadata_column_kind)(__ccgo_up(bp + 68))
			(**(**TVec0MetadataColumnDefinition)(__ccgo_up(bp + 44))).Fname_length = **(**int32)(__ccgo_up(bp + 60))
			(**(**TVec0MetadataColumnDefinition)(__ccgo_up(bp + 44))).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+1874, libc.VaList(bp+104, **(**int32)(__ccgo_up(bp + 60)), **(**uintptr)(__ccgo_up(bp + 56))))
			if !((**(**TVec0MetadataColumnDefinition)(__ccgo_up(bp + 44))).Fname != 0) {
				rc = int32(m_SQLITE_NOMEM)
				goto error
			}
			**(**Tvec0_user_column_kind)(__ccgo_up(pNew + 52 + uintptr(user_column_idx)*4)) = int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA)
			**(**Tuint8_t)(__ccgo_up(pNew + 260 + uintptr(user_column_idx))) = libc.Uint8FromInt32(numMetadataColumns)
			libc.Xmemcpy(tls, pNew+1000+uintptr(numMetadataColumns)*12, bp+44, uint32(12))
			numMetadataColumns = numMetadataColumns + 1
			(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumMetadataColumns = numMetadataColumns
			user_column_idx = user_column_idx + 1
			goto _1
		}
		rc = Xvec0_parse_table_option(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)), libc.Int32FromUint32(libc.Xstrlen(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)))), bp+72, bp+80, bp+76, bp+84)
		if rc == int32(m_SQLITE_ERROR) {
			**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6038, libc.VaList(bp+104, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4))))
			goto error
		}
		if rc == m_SQLITE_OK {
			if libsqlite3.Xsqlite3_strnicmp(tls, **(**uintptr)(__ccgo_up(bp + 72)), __ccgo_ts+6096, **(**int32)(__ccgo_up(bp + 80))) == 0 {
				chunk_size = libc.Xatoi(tls, **(**uintptr)(__ccgo_up(bp + 76)))
				if chunk_size <= 0 {
					// IMP: V01931_18769
					**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6107, 0)
					goto error
				}
				if chunk_size%int32(8) != 0 {
					// IMP: V14110_30948
					**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6178, 0)
					goto error
				}
				if chunk_size > int32(m_SQLITE_VEC_CHUNK_SIZE_MAX) {
					**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6236, 0)
					goto error
				}
			} else {
				// IMP: V27642_11712
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6281, libc.VaList(bp+104, **(**int32)(__ccgo_up(bp + 80)), **(**uintptr)(__ccgo_up(bp + 72))))
				goto error
			}
			goto _1
		}
		// Scenario #5: Unknown constructor argument
		**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6332, libc.VaList(bp+104, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4))))
		goto error
		goto _1
	_1:
		;
		i = i + 1
	}
	if chunk_size < 0 {
		chunk_size = int32(1024)
	}
	if numVectorColumns <= 0 {
		**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6377, 0)
		goto error
	}
	createStr = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_str_appendall(tls, createStr, __ccgo_ts+6440)
	if pkColumnName != 0 {
		libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6456, libc.VaList(bp+104, pkColumnNameLength, pkColumnName))
	} else {
		libsqlite3.Xsqlite3_str_appendall(tls, createStr, __ccgo_ts+6477)
	}
	i1 = 0
	for {
		if !(i1 < numVectorColumns+numPartitionColumns+numAuxiliaryColumns+numMetadataColumns) {
			break
		}
		switch **(**Tvec0_user_column_kind)(__ccgo_up(pNew + 52 + uintptr(i1)*4)) {
		case int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR):
			vector_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(pNew + 260 + uintptr(i1))))
			libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6485, libc.VaList(bp+104, (**(**TVectorColumnDefinition)(__ccgo_up(pNew + 440 + uintptr(vector_idx)*20))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(pNew + 440 + uintptr(vector_idx)*20))).Fname))
		case int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION):
			partition_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(pNew + 260 + uintptr(i1))))
			libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6485, libc.VaList(bp+104, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(pNew + 760 + uintptr(partition_idx)*12))).Fname_length, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(pNew + 760 + uintptr(partition_idx)*12))).Fname))
		case int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY):
			auxiliary_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(pNew + 260 + uintptr(i1))))
			libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6485, libc.VaList(bp+104, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(pNew + 808 + uintptr(auxiliary_idx)*12))).Fname_length, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(pNew + 808 + uintptr(auxiliary_idx)*12))).Fname))
		case int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA):
			metadata_idx = libc.Int32FromUint8(**(**Tuint8_t)(__ccgo_up(pNew + 260 + uintptr(i1))))
			libsqlite3.Xsqlite3_str_appendf(tls, createStr, __ccgo_ts+6485, libc.VaList(bp+104, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pNew + 1000 + uintptr(metadata_idx)*12))).Fname_length, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pNew + 1000 + uintptr(metadata_idx)*12))).Fname))
			break
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	libsqlite3.Xsqlite3_str_appendall(tls, createStr, __ccgo_ts+6494)
	if pkColumnName != 0 {
		libsqlite3.Xsqlite3_str_appendall(tls, createStr, __ccgo_ts+6523)
	}
	zSql = libsqlite3.Xsqlite3_str_finish(tls, createStr)
	if !(zSql != 0) {
		goto error
	}
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, zSql)
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6538, libc.VaList(bp+104, libsqlite3.Xsqlite3_errmsg(tls, db)))
		goto error
	}
	schemaName = **(**uintptr)(__ccgo_up(argv + 1*4))
	tableName = **(**uintptr)(__ccgo_up(argv + 2*4))
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).Fdb = db
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FpkIsText = libc.BoolInt32(pkColumnType == int32(m_SQLITE_TEXT))
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6600, libc.VaList(bp+104, schemaName))
	if !((*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName != 0) {
		goto error
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6600, libc.VaList(bp+104, tableName))
	if !((*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName != 0) {
		goto error
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FshadowRowidsName = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6603, libc.VaList(bp+104, tableName))
	if !((*Tvec0_vtab)(unsafe.Pointer(pNew)).FshadowRowidsName != 0) {
		goto error
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FshadowChunksName = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6613, libc.VaList(bp+104, tableName))
	if !((*Tvec0_vtab)(unsafe.Pointer(pNew)).FshadowChunksName != 0) {
		goto error
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumVectorColumns = numVectorColumns
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumPartitionColumns = numPartitionColumns
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumAuxiliaryColumns = numAuxiliaryColumns
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumMetadataColumns = numMetadataColumns
	i2 = 0
	for {
		if !(i2 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumVectorColumns) {
			break
		}
		**(**uintptr)(__ccgo_up(pNew + 312 + uintptr(i2)*4)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6623, libc.VaList(bp+104, tableName, i2))
		if !(**(**uintptr)(__ccgo_up(pNew + 312 + uintptr(i2)*4)) != 0) {
			goto error
		}
		goto _3
	_3:
		;
		i2 = i2 + 1
	}
	i3 = 0
	for {
		if !(i3 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumMetadataColumns) {
			break
		}
		**(**uintptr)(__ccgo_up(pNew + 376 + uintptr(i3)*4)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6644, libc.VaList(bp+104, tableName, i3))
		if !(**(**uintptr)(__ccgo_up(pNew + 376 + uintptr(i3)*4)) != 0) {
			goto error
		}
		goto _4
	_4:
		;
		i3 = i3 + 1
	}
	(*Tvec0_vtab)(unsafe.Pointer(pNew)).Fchunk_size = chunk_size
	// if xCreate, then create the necessary shadow tables
	if isCreate != 0 {
		zCreateInfo = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6666, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		if !(zCreateInfo != 0) {
			goto error
		}
		rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zCreateInfo, -int32(1), bp+88, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zCreateInfo)
		if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 88))) != int32(m_SQLITE_DONE) {
			// TODO(IMP)
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
			**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6728, libc.VaList(bp+104, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
		zSeedInfo = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6770, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		if !(zSeedInfo != 0) {
			goto error
		}
		rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSeedInfo, -int32(1), bp+88, libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_free(tls, zSeedInfo)
		if rc1 != m_SQLITE_OK {
			// TODO(IMP)
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
			**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6856, libc.VaList(bp+104, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_bind_text(tls, **(**uintptr)(__ccgo_up(bp + 88)), int32(1), __ccgo_ts+6896, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_text(tls, **(**uintptr)(__ccgo_up(bp + 88)), int32(2), __ccgo_ts+6911, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_text(tls, **(**uintptr)(__ccgo_up(bp + 88)), int32(3), __ccgo_ts+6918, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_int(tls, **(**uintptr)(__ccgo_up(bp + 88)), int32(4), m_SQLITE_VEC_VERSION_MAJOR)
		libsqlite3.Xsqlite3_bind_text(tls, **(**uintptr)(__ccgo_up(bp + 88)), int32(5), __ccgo_ts+6939, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_int(tls, **(**uintptr)(__ccgo_up(bp + 88)), int32(6), int32(m_SQLITE_VEC_VERSION_MINOR))
		libsqlite3.Xsqlite3_bind_text(tls, **(**uintptr)(__ccgo_up(bp + 88)), int32(7), __ccgo_ts+6960, -int32(1), libc.UintptrFromInt32(0))
		libsqlite3.Xsqlite3_bind_int(tls, **(**uintptr)(__ccgo_up(bp + 88)), int32(8), int32(m_SQLITE_VEC_VERSION_PATCH))
		if libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 88))) != int32(m_SQLITE_DONE) {
			// TODO(IMP)
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
			**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6856, libc.VaList(bp+104, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
		// create the _chunks shadow table
		zCreateShadowChunks = libc.UintptrFromInt32(0)
		if (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumPartitionColumns != 0 {
			s = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+6981, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+7012)
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+7078)
			i4 = 0
			for {
				if !(i4 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumPartitionColumns) {
					break
				}
				libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+7099, libc.VaList(bp+104, i4))
				goto _5
			_5:
				;
				i4 = i4 + 1
			}
			libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+7114)
			zCreateShadowChunks = libsqlite3.Xsqlite3_str_finish(tls, s)
		} else {
			zCreateShadowChunks = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7161, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		}
		if !(zCreateShadowChunks != 0) {
			goto error
		}
		rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zCreateShadowChunks, -int32(1), bp+88, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zCreateShadowChunks)
		if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 88))) != int32(m_SQLITE_DONE) {
			// IMP: V17740_01811
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
			**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7302, libc.VaList(bp+104, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
		if (*Tvec0_vtab)(unsafe.Pointer(pNew)).FpkIsText != 0 {
			// adds a "text unique not null" constraint to the id column
			zCreateShadowRowids = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7346, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		} else {
			zCreateShadowRowids = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7480, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
		}
		if !(zCreateShadowRowids != 0) {
			goto error
		}
		rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zCreateShadowRowids, -int32(1), bp+88, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zCreateShadowRowids)
		if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 88))) != int32(m_SQLITE_DONE) {
			// IMP: V11631_28470
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
			**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7593, libc.VaList(bp+104, libsqlite3.Xsqlite3_errmsg(tls, db)))
			goto error
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
		i5 = 0
		for {
			if !(i5 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumVectorColumns) {
				break
			}
			zSql1 = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7637, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName, i5))
			if !(zSql1 != 0) {
				goto error
			}
			rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSql1, -int32(1), bp+88, uintptr(0))
			libsqlite3.Xsqlite3_free(tls, zSql1)
			if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 88))) != int32(m_SQLITE_DONE) {
				// IMP: V25919_09989
				libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7720, libc.VaList(bp+104, i5, libsqlite3.Xsqlite3_errmsg(tls, db)))
				goto error
			}
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
			goto _6
		_6:
			;
			i5 = i5 + 1
		}
		// See SHADOW_TABLE_ROWID_QUIRK in vec0_new_chunk() — same "rowid PRIMARY KEY"
		// without INTEGER type issue applies here.
		i6 = 0
		for {
			if !(i6 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumMetadataColumns) {
				break
			}
			zSql2 = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7775, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName, i6))
			if !(zSql2 != 0) {
				goto error
			}
			rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSql2, -int32(1), bp+88, uintptr(0))
			libsqlite3.Xsqlite3_free(tls, zSql2)
			if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 88))) != int32(m_SQLITE_DONE) {
				libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7857, libc.VaList(bp+104, i6, libsqlite3.Xsqlite3_errmsg(tls, db)))
				goto error
			}
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
			if (**(**TVec0MetadataColumnDefinition)(__ccgo_up(pNew + 1000 + uintptr(i6)*12))).Fkind == int32(_VEC0_METADATA_COLUMN_KIND_TEXT) {
				zSql3 = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7912, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName, i6))
				if !(zSql3 != 0) {
					goto error
				}
				rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSql3, -int32(1), bp+88, uintptr(0))
				libsqlite3.Xsqlite3_free(tls, zSql3)
				if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 88))) != int32(m_SQLITE_DONE) {
					libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
					**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+7983, libc.VaList(bp+104, i6, libsqlite3.Xsqlite3_errmsg(tls, db)))
					goto error
				}
				libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 88)))
			}
			goto _7
		_7:
			;
			i6 = i6 + 1
		}
		if (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumAuxiliaryColumns > 0 {
			s1 = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
			libsqlite3.Xsqlite3_str_appendf(tls, s1, __ccgo_ts+8037, libc.VaList(bp+104, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(pNew)).FtableName))
			i7 = 0
			for {
				if !(i7 < (*Tvec0_vtab)(unsafe.Pointer(pNew)).FnumAuxiliaryColumns) {
					break
				}
				libsqlite3.Xsqlite3_str_appendf(tls, s1, __ccgo_ts+8098, libc.VaList(bp+104, i7))
				goto _8
			_8:
				;
				i7 = i7 + 1
			}
			libsqlite3.Xsqlite3_str_appendall(tls, s1, __ccgo_ts+5256)
			zSql4 = libsqlite3.Xsqlite3_str_finish(tls, s1)
			if !(zSql4 != 0) {
				goto error
			}
			rc1 = libsqlite3.Xsqlite3_prepare_v2(tls, db, zSql4, -int32(1), bp+92, libc.UintptrFromInt32(0))
			if rc1 != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 92))) != int32(m_SQLITE_DONE) {
				libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 92)))
				**(**uintptr)(__ccgo_up(pzErr)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8110, libc.VaList(bp+104, libsqlite3.Xsqlite3_errmsg(tls, db)))
				goto error
			}
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp + 92)))
		}
	}
	**(**uintptr)(__ccgo_up(ppVtab)) = pNew
	return m_SQLITE_OK
	goto error
error:
	;
	Xvec0_free(tls, pNew)
	libsqlite3.Xsqlite3_free(tls, pNew)
	return int32(m_SQLITE_ERROR)
}

func _vec_add(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, i1, outSize, outSize1 Tsize_t
	var out, out1 uintptr
	var rc int32
	var _ /* a at bp+0 */ uintptr
	var _ /* aCleanup at bp+12 */ Tvector_cleanup
	var _ /* b at bp+4 */ uintptr
	var _ /* bCleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+24 */ _VectorElementType
	var _ /* error at bp+20 */ uintptr
	_, _, _, _, _, _, _ = i, i1, out, out1, outSize, outSize1, rc
	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
	**(**uintptr)(__ccgo_up(bp + 4)) = libc.UintptrFromInt32(0)
	rc = Xensure_vector_match(tls, **(**uintptr)(__ccgo_up(argv)), **(**uintptr)(__ccgo_up(argv + 1*4)), bp, bp+4, bp+24, bp+8, bp+12, bp+16, bp+20)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 20)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 20)))
		return
	}
	switch **(**_VectorElementType)(__ccgo_up(bp + 24)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1183, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		outSize = **(**Tsize_t)(__ccgo_up(bp + 8)) * uint32(4)
		out = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint32(outSize))
		if !(out != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto finish
		}
		libc.Xmemset(tls, out, 0, outSize)
		i = uint32(0)
		for {
			if !(i < **(**Tsize_t)(__ccgo_up(bp + 8))) {
				break
			}
			**(**Tf32)(__ccgo_up(out + uintptr(i)*4)) = **(**Tf32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) + **(**Tf32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 4)) + uintptr(i)*4))
			goto _1
		_1:
			;
			i = i + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out, libc.Int32FromUint32(outSize), __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		outSize1 = **(**Tsize_t)(__ccgo_up(bp + 8)) * uint32(1)
		out1 = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint32(outSize1))
		if !(out1 != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto finish
		}
		libc.Xmemset(tls, out1, 0, outSize1)
		i1 = uint32(0)
		for {
			if !(i1 < **(**Tsize_t)(__ccgo_up(bp + 8))) {
				break
			}
			**(**Ti8)(__ccgo_up(out1 + uintptr(i1))) = int8(int32(**(**Ti8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i1)))) + int32(**(**Ti8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 4)) + uintptr(i1)))))
			goto _2
		_2:
			;
			i1 = i1 + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out1, libc.Int32FromUint32(outSize1), __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
		goto finish
	}
	goto finish
finish:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 12)))(tls, **(**uintptr)(__ccgo_up(bp)))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, **(**uintptr)(__ccgo_up(bp + 4)))
	return
}

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.Int64FromUint32((*Tvec_each_cursor)(unsafe.Pointer(pCur)).Fdimensions))
}

func _vec_f32(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* cleanup at bp+8 */ Tfvec_cleanup
	var _ /* dimensions at bp+4 */ Tsize_t
	var _ /* errmsg at bp+12 */ 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+4, bp+8, bp+12)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 12)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 12)))
		return
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up(bp)), libc.Int32FromUint32(**(**Tsize_t)(__ccgo_up(bp + 4))*uint32(4)), **(**Tfvec_cleanup)(__ccgo_up(bp + 8)))
	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(16)
	defer tls.Free(16)
	var rc int32
	var _ /* cleanup at bp+8 */ Tvector_cleanup
	var _ /* dimensions at bp+4 */ Tsize_t
	var _ /* errmsg at bp+12 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_ = rc
	rc = _int8_vec_from_value(tls, **(**uintptr)(__ccgo_up(argv)), bp, bp+4, bp+8, bp+12)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 12)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 12)))
		return
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, **(**uintptr)(__ccgo_up(bp)), libc.Int32FromUint32(**(**Tsize_t)(__ccgo_up(bp + 4))), uintptr(-libc.Int32FromInt32(1)))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 8)))(tls, **(**uintptr)(__ccgo_up(bp)))
}

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

func _vec_normalize(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, i1 Tsize_t
	var norm Tf32
	var out, v uintptr
	var outSize, rc int32
	var _ /* cleanup at bp+8 */ Tvector_cleanup
	var _ /* dimensions at bp+4 */ Tsize_t
	var _ /* elementType at bp+16 */ _VectorElementType
	var _ /* err at bp+12 */ uintptr
	var _ /* vector at bp+0 */ uintptr
	_, _, _, _, _, _, _ = i, i1, norm, out, outSize, rc, v
	rc = Xvector_from_value(tls, **(**uintptr)(__ccgo_up(argv)), bp, bp+4, bp+16, bp+8, bp+12)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 12)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 12)))
		return
	}
	if **(**_VectorElementType)(__ccgo_up(bp + 16)) != int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32) {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1688, -int32(1))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 8)))(tls, **(**uintptr)(__ccgo_up(bp)))
		return
	}
	outSize = libc.Int32FromUint32(**(**Tsize_t)(__ccgo_up(bp + 4)) * uint32(4))
	out = libsqlite3.Xsqlite3_malloc(tls, outSize)
	if !(out != 0) {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 8)))(tls, **(**uintptr)(__ccgo_up(bp)))
		libsqlite3.Xsqlite3_result_error_code(tls, context, int32(m_SQLITE_NOMEM))
		return
	}
	libc.Xmemset(tls, out, 0, libc.Uint32FromInt32(outSize))
	v = **(**uintptr)(__ccgo_up(bp))
	norm = libc.Float32FromInt32(0)
	i = uint32(0)
	for {
		if !(i < **(**Tsize_t)(__ccgo_up(bp + 4))) {
			break
		}
		norm = norm + Tf32(**(**Tf32)(__ccgo_up(v + uintptr(i)*4))***(**Tf32)(__ccgo_up(v + uintptr(i)*4)))
		goto _1
	_1:
		;
		i = i + 1
	}
	norm = float32(libc.Xsqrt(tls, float64(norm)))
	i1 = uint32(0)
	for {
		if !(i1 < **(**Tsize_t)(__ccgo_up(bp + 4))) {
			break
		}
		**(**Tf32)(__ccgo_up(out + uintptr(i1)*4)) = **(**Tf32)(__ccgo_up(v + uintptr(i1)*4)) / norm
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, out, libc.Int32FromUint32(**(**Tsize_t)(__ccgo_up(bp + 4))*uint32(4)), __ccgo_fp(libsqlite3.Xsqlite3_free))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 8)))(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((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid*libc.Int64FromUint32((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions)*int64(4)), libc.Int32FromUint32((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint32(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*uint32(4)), libc.Int32FromUint32((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions*uint32(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.Uint32FromInt64((*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_npy_file(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var f, path uintptr
	var pathLength Tsize_t
	_, _, _ = f, path, pathLength
	path = libsqlite3.Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	pathLength = libc.Uint32FromInt32(libsqlite3.Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv))))
	f = libsqlite3.Xsqlite3_malloc(tls, int32(8))
	if !(f != 0) {
		libsqlite3.Xsqlite3_result_error_nomem(tls, context)
		return
	}
	libc.Xmemset(tls, f, 0, uint32(8))
	(*TVecNpyFile)(unsafe.Pointer(f)).Fpath = path
	(*TVecNpyFile)(unsafe.Pointer(f)).FpathLength = pathLength
	libsqlite3.Xsqlite3_result_pointer(tls, context, f, __ccgo_ts+674, __ccgo_fp(libsqlite3.Xsqlite3_free))
}

func _vec_quantize_int8(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i Tsize_t
	var out uintptr
	var rc, sz int32
	var step Tf32
	var val float64
	var _ /* dimensions at bp+4 */ Tsize_t
	var _ /* err at bp+12 */ uintptr
	var _ /* srcCleanup at bp+8 */ Tfvec_cleanup
	var _ /* srcVector at bp+0 */ uintptr
	_, _, _, _, _, _ = i, out, rc, step, sz, val
	out = libc.UintptrFromInt32(0)
	rc = _fvec_from_value(tls, **(**uintptr)(__ccgo_up(argv)), bp, bp+4, bp+8, bp+12)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 12)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 12)))
		return
	}
	sz = libc.Int32FromUint32(**(**Tsize_t)(__ccgo_up(bp + 4)) * uint32(1))
	out = libsqlite3.Xsqlite3_malloc(tls, sz)
	if !(out != 0) {
		libsqlite3.Xsqlite3_result_error_nomem(tls, context)
		goto cleanup
	}
	libc.Xmemset(tls, out, 0, libc.Uint32FromInt32(sz))
	if libsqlite3.Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + 1*4))) != int32(m_SQLITE_TEXT) || libc.Uint32FromInt32(libsqlite3.Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))) != libc.Xstrlen(tls, __ccgo_ts+1126) || libsqlite3.Xsqlite3_stricmp(tls, libsqlite3.Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*4))), __ccgo_ts+1126) != 0 {
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1131, -int32(1))
		libsqlite3.Xsqlite3_free(tls, out)
		goto cleanup
	}
	step = float32((float64(1) - -libc.Float64FromFloat64(1)) / libc.Float64FromInt32(255))
	i = uint32(0)
	for {
		if !(i < **(**Tsize_t)(__ccgo_up(bp + 4))) {
			break
		}
		val = (float64(**(**Tf32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4))) - -libc.Float64FromFloat64(1))/float64(step) - libc.Float64FromInt32(128)
		if !(val <= libc.Float64FromFloat64(127)) {
			val = float64(127)
		} /* also clamps NaN */
		if !(val >= -libc.Float64FromFloat64(128)) {
			val = -libc.Float64FromFloat64(128)
		}
		**(**Ti8)(__ccgo_up(out + uintptr(i))) = int8(val)
		goto _1
	_1:
		;
		i = i + 1
	}
	libsqlite3.Xsqlite3_result_blob(tls, context, out, libc.Int32FromUint32(**(**Tsize_t)(__ccgo_up(bp + 4))*uint32(1)), __ccgo_fp(libsqlite3.Xsqlite3_free))
	libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
	goto cleanup
cleanup:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 8)))(tls, **(**uintptr)(__ccgo_up(bp)))
}

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.Int64FromUint32((*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((*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid*libc.Int64FromUint32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions)*libc.Int64FromInt64(4)), libc.Int32FromUint32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*uint32(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.Uint32FromInt32(rowid)*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*libc.Uint32FromInt64(4)), libc.Int32FromUint32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions*uint32(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.Uint32FromInt64((*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_blob_entriesFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var bsize, i, i1 Tsize_t
	var candidates, distances, knn_data, p, pCur, taken, topk_rowids, v uintptr
	var k Ti64
	var rc int32
	var v1 int64
	var _ /* cleanup at bp+12 */ Tvector_cleanup
	var _ /* dimensions at bp+4 */ Tsize_t
	var _ /* elementType at bp+8 */ _VectorElementType
	var _ /* err at bp+16 */ uintptr
	var _ /* k_used at bp+20 */ Ti32
	var _ /* queryVector at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _ = bsize, candidates, distances, i, i1, k, knn_data, p, pCur, rc, taken, topk_rowids, v, v1
	_ = idxStr
	pCur = pVtabCursor
	p = (*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fbase.FpVtab
	if idxNum == int32(_VEC_SBE__QUERYPLAN_KNN) {
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC_SBE__QUERYPLAN_KNN)
		knn_data = libsqlite3.Xsqlite3_malloc(tls, int32(32))
		if !(knn_data != 0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, knn_data, 0, uint32(32))
		rc = Xvector_from_value(tls, **(**uintptr)(__ccgo_up(argv)), bp, bp+4, bp+8, bp+12, bp+16)
		if rc != m_SQLITE_OK {
			return int32(m_SQLITE_ERROR)
		}
		if **(**_VectorElementType)(__ccgo_up(bp + 8)) != (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Felement_type {
			return int32(m_SQLITE_ERROR)
		}
		if **(**Tsize_t)(__ccgo_up(bp + 4)) != (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions {
			return int32(m_SQLITE_ERROR)
		}
		if libsqlite3.Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 1*4))) <= libc.Int64FromUint32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors) {
			v1 = libsqlite3.Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
		} else {
			v1 = libc.Int64FromUint32((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors)
		}
		k = v1
		if k < 0 {
			// HANDLE https://github.com/asg017/sqlite-vec/issues/55
			return int32(m_SQLITE_ERROR)
		}
		if k == 0 {
			(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fk = 0
			(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data = knn_data
			return m_SQLITE_OK
		}
		bsize = ((*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors + uint32(7)) & libc.Uint32FromInt32(^libc.Int32FromInt32(7))
		topk_rowids = libsqlite3.Xsqlite3_malloc(tls, int32(k*int64(4)))
		if !(topk_rowids != 0) {
			// HANDLE https://github.com/asg017/sqlite-vec/issues/55
			return int32(m_SQLITE_ERROR)
		}
		distances = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint32(bsize*uint32(4)))
		if !(distances != 0) {
			// HANDLE https://github.com/asg017/sqlite-vec/issues/55
			return int32(m_SQLITE_ERROR)
		}
		i = uint32(0)
		for {
			if !(i < (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors) {
				break
			}
			// https://github.com/asg017/sqlite-vec/issues/52
			v = (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fp + uintptr(i*(*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fdimensions)*4
			**(**Tf32)(__ccgo_up(distances + uintptr(i)*4)) = _distance_l2_sqr_float(tls, v, **(**uintptr)(__ccgo_up(bp)), (*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob+8)
			goto _2
		_2:
			;
			i = i + 1
		}
		candidates = Xbitmap_new(tls, libc.Int32FromUint32(bsize))
		taken = Xbitmap_new(tls, libc.Int32FromUint32(bsize))
		Xbitmap_fill(tls, candidates, libc.Int32FromUint32(bsize))
		i1 = bsize
		for {
			if !(i1 >= (*Tstatic_blob)(unsafe.Pointer((*Tvec_static_blob_entries_vtab)(unsafe.Pointer(p)).Fblob)).Fnvectors) {
				break
			}
			Xbitmap_set(tls, candidates, libc.Int32FromUint32(i1), 0)
			goto _3
		_3:
			;
			i1 = i1 - 1
		}
		**(**Ti32)(__ccgo_up(bp + 20)) = 0
		Xmin_idx(tls, distances, libc.Int32FromUint32(bsize), candidates, topk_rowids, int32(k), taken, bp+20)
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fcurrent_idx = 0
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fdistances = distances
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Fk = k
		(*Tsbe_query_knn_data)(unsafe.Pointer(knn_data)).Frowids = topk_rowids
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fknn_data = knn_data
	} else {
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC_SBE__QUERYPLAN_FULLSCAN)
		(*Tvec_static_blob_entries_cursor)(unsafe.Pointer(pCur)).FiRowid = 0
	}
	return m_SQLITE_OK
}

func _vec_static_blob_from_raw(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p uintptr
	_ = p
	p = libsqlite3.Xsqlite3_malloc(tls, int32(16))
	if !(p != 0) {
		libsqlite3.Xsqlite3_result_error_nomem(tls, context)
		return
	}
	libc.Xmemset(tls, p, 0, uint32(16))
	(*Tstatic_blob_definition)(unsafe.Pointer(p)).Fp = uintptr(libsqlite3.Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv))))
	(*Tstatic_blob_definition)(unsafe.Pointer(p)).Felement_type = int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32)
	(*Tstatic_blob_definition)(unsafe.Pointer(p)).Fdimensions = libc.Uint32FromInt64(libsqlite3.Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 2*4))))
	(*Tstatic_blob_definition)(unsafe.Pointer(p)).Fnvectors = libc.Uint32FromInt64(libsqlite3.Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(argv + 3*4))))
	libsqlite3.Xsqlite3_result_pointer(tls, context, p, _POINTER_NAME_STATIC_BLOB_DEF, __ccgo_fp(libsqlite3.Xsqlite3_free))
}

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)*20))).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.Int64FromUint32((**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*20))).Fdimensions))
	case int32(m_VEC_STATIC_BLOBS_COUNT):
		libsqlite3.Xsqlite3_result_int64(tls, context, libc.Int64FromUint32((**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*20))).Fnvectors))
		break
	}
	return m_SQLITE_OK
}

func _vec_sub(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, i1, outSize, outSize1 Tsize_t
	var out, out1 uintptr
	var rc int32
	var _ /* a at bp+0 */ uintptr
	var _ /* aCleanup at bp+12 */ Tvector_cleanup
	var _ /* b at bp+4 */ uintptr
	var _ /* bCleanup at bp+16 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+24 */ _VectorElementType
	var _ /* error at bp+20 */ uintptr
	_, _, _, _, _, _, _ = i, i1, out, out1, outSize, outSize1, rc
	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
	**(**uintptr)(__ccgo_up(bp + 4)) = libc.UintptrFromInt32(0)
	rc = Xensure_vector_match(tls, **(**uintptr)(__ccgo_up(argv)), **(**uintptr)(__ccgo_up(argv + 1*4)), bp, bp+4, bp+24, bp+8, bp+12, bp+16, bp+20)
	if rc != m_SQLITE_OK {
		libsqlite3.Xsqlite3_result_error(tls, context, **(**uintptr)(__ccgo_up(bp + 20)), -int32(1))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 20)))
		return
	}
	switch **(**_VectorElementType)(__ccgo_up(bp + 24)) {
	case int32(_SQLITE_VEC_ELEMENT_TYPE_BIT):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+1219, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		outSize = **(**Tsize_t)(__ccgo_up(bp + 8)) * uint32(4)
		out = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint32(outSize))
		if !(out != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto finish
		}
		libc.Xmemset(tls, out, 0, outSize)
		i = uint32(0)
		for {
			if !(i < **(**Tsize_t)(__ccgo_up(bp + 8))) {
				break
			}
			**(**Tf32)(__ccgo_up(out + uintptr(i)*4)) = **(**Tf32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i)*4)) - **(**Tf32)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 4)) + uintptr(i)*4))
			goto _1
		_1:
			;
			i = i + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out, libc.Int32FromUint32(outSize), __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		outSize1 = **(**Tsize_t)(__ccgo_up(bp + 8)) * uint32(1)
		out1 = libsqlite3.Xsqlite3_malloc(tls, libc.Int32FromUint32(outSize1))
		if !(out1 != 0) {
			libsqlite3.Xsqlite3_result_error_nomem(tls, context)
			goto finish
		}
		libc.Xmemset(tls, out1, 0, outSize1)
		i1 = uint32(0)
		for {
			if !(i1 < **(**Tsize_t)(__ccgo_up(bp + 8))) {
				break
			}
			**(**Ti8)(__ccgo_up(out1 + uintptr(i1))) = int8(int32(**(**Ti8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp)) + uintptr(i1)))) - int32(**(**Ti8)(__ccgo_up(**(**uintptr)(__ccgo_up(bp + 4)) + uintptr(i1)))))
			goto _2
		_2:
			;
			i1 = i1 + 1
		}
		libsqlite3.Xsqlite3_result_blob(tls, context, out1, libc.Int32FromUint32(outSize1), __ccgo_fp(libsqlite3.Xsqlite3_free))
		libsqlite3.Xsqlite3_result_subtype(tls, context, uint32(_SQLITE_VEC_ELEMENT_TYPE_INT8))
		goto finish
	}
	goto finish
finish:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 12)))(tls, **(**uintptr)(__ccgo_up(bp)))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 16)))(tls, **(**uintptr)(__ccgo_up(bp + 4)))
	return
}

const m___LONG_MAX = 2147483647

const m___builtin_popcountl = "__builtin_popcountll"
