// 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) || (windows && 386)

package vec

import (
	"unsafe"

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

type Tintptr_t = int32

type Tsize_t = uint32

type Tssize_t = int32

type Tuintptr_t = uint32

type Tusize = uint32

func Xarray_append(tls *libc.TLS, array uintptr, element uintptr) (r int32) {
	var new_capacity Tsize_t
	var z uintptr
	_, _ = new_capacity, z
	if (*TArray)(unsafe.Pointer(array)).Flength == (*TArray)(unsafe.Pointer(array)).Fcapacity {
		new_capacity = (*TArray)(unsafe.Pointer(array)).Fcapacity*uint32(2) + uint32(100)
		z = libsqlite3.Xsqlite3_realloc64(tls, (*TArray)(unsafe.Pointer(array)).Fz, uint64((*TArray)(unsafe.Pointer(array)).Felement_size*new_capacity))
		if z != 0 {
			(*TArray)(unsafe.Pointer(array)).Fcapacity = new_capacity
			(*TArray)(unsafe.Pointer(array)).Fz = z
		} else {
			return int32(m_SQLITE_NOMEM)
		}
	}
	libc.Xmemcpy(tls, (*TArray)(unsafe.Pointer(array)).Fz+uintptr((*TArray)(unsafe.Pointer(array)).Flength*(*TArray)(unsafe.Pointer(array)).Felement_size), element, (*TArray)(unsafe.Pointer(array)).Felement_size)
	(*TArray)(unsafe.Pointer(array)).Flength = (*TArray)(unsafe.Pointer(array)).Flength + 1
	return m_SQLITE_OK
}

func Xarray_cleanup(tls *libc.TLS, array uintptr) {
	if !(array != 0) {
		return
	}
	(*TArray)(unsafe.Pointer(array)).Felement_size = uint32(0)
	(*TArray)(unsafe.Pointer(array)).Flength = uint32(0)
	(*TArray)(unsafe.Pointer(array)).Fcapacity = uint32(0)
	libsqlite3.Xsqlite3_free(tls, (*TArray)(unsafe.Pointer(array)).Fz)
	(*TArray)(unsafe.Pointer(array)).Fz = libc.UintptrFromInt32(0)
}

func Xensure_vector_match(tls *libc.TLS, aValue uintptr, bValue uintptr, a uintptr, b uintptr, element_type uintptr, dimensions uintptr, __ccgo_fp_outACleanup uintptr, __ccgo_fp_outBCleanup uintptr, outError uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var rc int32
	var _ /* aCleanup at bp+20 */ Tvector_cleanup
	var _ /* aDims at bp+8 */ Tsize_t
	var _ /* aType at bp+0 */ _VectorElementType
	var _ /* bCleanup at bp+24 */ Tvector_cleanup
	var _ /* bDims at bp+12 */ Tsize_t
	var _ /* bType at bp+4 */ _VectorElementType
	var _ /* error at bp+16 */ uintptr
	_ = rc
	**(**uintptr)(__ccgo_up(bp + 16)) = libc.UintptrFromInt32(0)
	rc = Xvector_from_value(tls, aValue, a, bp+8, bp, bp+20, bp+16)
	if rc != m_SQLITE_OK {
		**(**uintptr)(__ccgo_up(outError)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+439, libc.VaList(bp+40, **(**uintptr)(__ccgo_up(bp + 16))))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 16)))
		return int32(m_SQLITE_ERROR)
	}
	rc = Xvector_from_value(tls, bValue, b, bp+12, bp+4, bp+24, bp+16)
	if rc != m_SQLITE_OK {
		**(**uintptr)(__ccgo_up(outError)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+468, libc.VaList(bp+40, **(**uintptr)(__ccgo_up(bp + 16))))
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp + 16)))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 20)))(tls, **(**uintptr)(__ccgo_up(a)))
		return int32(m_SQLITE_ERROR)
	}
	if **(**_VectorElementType)(__ccgo_up(bp)) != **(**_VectorElementType)(__ccgo_up(bp + 4)) {
		**(**uintptr)(__ccgo_up(outError)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+497, libc.VaList(bp+40, Xvector_subtype_name(tls, **(**_VectorElementType)(__ccgo_up(bp))), Xvector_subtype_name(tls, **(**_VectorElementType)(__ccgo_up(bp + 4)))))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 20)))(tls, **(**uintptr)(__ccgo_up(a)))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, **(**uintptr)(__ccgo_up(b)))
		return int32(m_SQLITE_ERROR)
	}
	if **(**Tsize_t)(__ccgo_up(bp + 8)) != **(**Tsize_t)(__ccgo_up(bp + 12)) {
		**(**uintptr)(__ccgo_up(outError)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+576, libc.VaList(bp+40, **(**Tsize_t)(__ccgo_up(bp + 8)), **(**Tsize_t)(__ccgo_up(bp + 12))))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 20)))(tls, **(**uintptr)(__ccgo_up(a)))
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 24)))(tls, **(**uintptr)(__ccgo_up(b)))
		return int32(m_SQLITE_ERROR)
	}
	**(**_VectorElementType)(__ccgo_up(element_type)) = **(**_VectorElementType)(__ccgo_up(bp))
	**(**Tsize_t)(__ccgo_up(dimensions)) = **(**Tsize_t)(__ccgo_up(bp + 8))
	**(**Tvector_cleanup)(__ccgo_up(__ccgo_fp_outACleanup)) = **(**Tvector_cleanup)(__ccgo_up(bp + 20))
	**(**Tvector_cleanup)(__ccgo_up(__ccgo_fp_outBCleanup)) = **(**Tvector_cleanup)(__ccgo_up(bp + 24))
	return m_SQLITE_OK
}

func Xsqlite3_vec_init(tls *libc.TLS, db uintptr, pzErrMsg uintptr, pApi uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, i1 uint32
	var rc int32
	_, _, _ = i, i1, rc
	rc = m_SQLITE_OK
	rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, __ccgo_ts+16107, 0, libc.Int32FromInt32(m_SQLITE_UTF8)|libc.Int32FromInt32(m_SQLITE_INNOCUOUS)|libc.Int32FromInt32(m_SQLITE_DETERMINISTIC), __ccgo_ts+6911, __ccgo_fp(__static_text_func), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, __ccgo_ts+16119, 0, libc.Int32FromInt32(m_SQLITE_UTF8)|libc.Int32FromInt32(m_SQLITE_INNOCUOUS)|libc.Int32FromInt32(m_SQLITE_DETERMINISTIC), __ccgo_ts+16129, __ccgo_fp(__static_text_func), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	i = uint32(0)
	for {
		if !(i < uint32(libc.Uint32FromInt64(256)/libc.Uint32FromInt64(16)) && rc == m_SQLITE_OK) {
			break
		}
		rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, _aFunc[i].FzFName, _aFunc[i].FnArg, _aFunc[i].Fflags, libc.UintptrFromInt32(0), _aFunc[i].FxFunc, libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
		if rc != m_SQLITE_OK {
			**(**uintptr)(__ccgo_up(pzErrMsg)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+16423, libc.VaList(bp+8, _aFunc[i].FzFName, libsqlite3.Xsqlite3_errmsg(tls, db)))
			return rc
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	i1 = uint32(0)
	for {
		if !(i1 < uint32(libc.Uint32FromInt64(32)/libc.Uint32FromInt64(16)) && rc == m_SQLITE_OK) {
			break
		}
		rc = libsqlite3.Xsqlite3_create_module_v2(tls, db, _aMod[i1].Fname, _aMod[i1].Fmodule, libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
		if rc != m_SQLITE_OK {
			**(**uintptr)(__ccgo_up(pzErrMsg)) = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+16454, libc.VaList(bp+8, _aMod[i1].Fname, libsqlite3.Xsqlite3_errmsg(tls, db)))
			return rc
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	return m_SQLITE_OK
}

func Xsqlite3_vec_static_blobs_init(tls *libc.TLS, db uintptr, pzErrMsg uintptr, pApi uintptr) (r int32) {
	var rc int32
	var static_blob_data uintptr
	_, _ = rc, static_blob_data
	_ = pzErrMsg
	rc = m_SQLITE_OK
	static_blob_data = libsqlite3.Xsqlite3_malloc(tls, int32(320))
	if !(static_blob_data != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, static_blob_data, 0, uint32(320))
	rc = libsqlite3.Xsqlite3_create_function_v2(tls, db, __ccgo_ts+16509, int32(4), libc.Int32FromInt32(m_SQLITE_UTF8)|libc.Int32FromInt32(m_SQLITE_INNOCUOUS)|libc.Int32FromInt32(m_SQLITE_DETERMINISTIC)|libc.Int32FromInt32(m_SQLITE_SUBTYPE)|libc.Int32FromInt32(m_SQLITE_RESULT_SUBTYPE), libc.UintptrFromInt32(0), __ccgo_fp(_vec_static_blob_from_raw), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0), libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = libsqlite3.Xsqlite3_create_module_v2(tls, db, __ccgo_ts+16534, uintptr(unsafe.Pointer(&_vec_static_blobsModule)), static_blob_data, __ccgo_fp(libsqlite3.Xsqlite3_free))
	if rc != m_SQLITE_OK {
		return rc
	}
	rc = libsqlite3.Xsqlite3_create_module_v2(tls, db, __ccgo_ts+16551, uintptr(unsafe.Pointer(&_vec_static_blob_entriesModule)), static_blob_data, libc.UintptrFromInt32(0))
	if rc != m_SQLITE_OK {
		return rc
	}
	return rc
}

func Xvec0Filter_fullscan(tls *libc.TLS, p uintptr, pCur uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var fullscan_data, zSql uintptr
	var rc int32
	_, _, _ = fullscan_data, rc, zSql
	fullscan_data = libsqlite3.Xsqlite3_malloc(tls, int32(8))
	if !(fullscan_data != 0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, fullscan_data, 0, uint32(8))
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+10644, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	if !(zSql != 0) {
		rc = int32(m_SQLITE_NOMEM)
		goto error
	}
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), fullscan_data, libc.UintptrFromInt32(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK {
		// IMP: V09901_26739
		Xvtab_set_error(tls, p, __ccgo_ts+10714, libc.VaList(bp+8, libsqlite3.Xsqlite3_errmsg(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb)))
		goto error
	}
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_query_fullscan_data)(unsafe.Pointer(fullscan_data)).Frowids_stmt)
	// DONE when there's no rowids, ROW when there are, both "success"
	if !(rc == int32(m_SQLITE_ROW) || rc == int32(m_SQLITE_DONE)) {
		goto error
	}
	(*Tvec0_query_fullscan_data)(unsafe.Pointer(fullscan_data)).Fdone = libc.BoolInt8(rc == int32(m_SQLITE_DONE))
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Fquery_plan = int32(_VEC0_QUERY_PLAN_FULLSCAN)
	(*Tvec0_cursor)(unsafe.Pointer(pCur)).Ffullscan_data = fullscan_data
	return m_SQLITE_OK
	goto error
error:
	;
	Xvec0_query_fullscan_data_clear(tls, fullscan_data)
	libsqlite3.Xsqlite3_free(tls, fullscan_data)
	return rc
}

func Xvec0Update_UpdateVectorColumn(tls *libc.TLS, p uintptr, chunk_id Ti64, chunk_offset Ti64, i int32, valueVector uintptr) (r int32) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var brc, rc int32
	var _ /* blobVectors at bp+0 */ uintptr
	var _ /* cleanup at bp+20 */ Tvector_cleanup
	var _ /* dimensions at bp+8 */ Tsize_t
	var _ /* elementType at bp+12 */ _VectorElementType
	var _ /* pzError at bp+4 */ uintptr
	var _ /* vector at bp+16 */ uintptr
	_, _ = brc, rc
	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
	**(**Tvector_cleanup)(__ccgo_up(bp + 20)) = __ccgo_fp(Xvector_cleanup_noop)
	// https://github.com/asg017/sqlite-vec/issues/53
	rc = Xvector_from_value(tls, valueVector, bp+16, bp+8, bp+12, bp+20, bp+4)
	if rc != m_SQLITE_OK {
		// IMP: V15203_32042
		Xvtab_set_error(tls, p, __ccgo_ts+14770, libc.VaList(bp+32, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fname, **(**uintptr)(__ccgo_up(bp + 4))))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if **(**_VectorElementType)(__ccgo_up(bp + 12)) != (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Felement_type {
		// IMP: V03643_20481
		Xvtab_set_error(tls, p, __ccgo_ts+14822, libc.VaList(bp+32, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fname, Xvector_subtype_name(tls, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Felement_type), Xvector_subtype_name(tls, **(**_VectorElementType)(__ccgo_up(bp + 12)))))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if **(**Tsize_t)(__ccgo_up(bp + 8)) != (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fdimensions {
		// IMP: V25739_09810
		Xvtab_set_error(tls, p, __ccgo_ts+14919, libc.VaList(bp+32, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fname_length, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fname, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fdimensions, **(**Tsize_t)(__ccgo_up(bp + 8))))
		rc = int32(m_SQLITE_ERROR)
		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(i)*4)), __ccgo_ts+3712, chunk_id, int32(1), bp)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+15024, libc.VaList(bp+32, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)), chunk_id))
		goto cleanup
	}
	rc = _vec0_write_vector_to_vector_blob(tls, **(**uintptr)(__ccgo_up(bp)), chunk_offset, **(**uintptr)(__ccgo_up(bp + 16)), (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fdimensions, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Felement_type)
	if rc != m_SQLITE_OK {
		Xvtab_set_error(tls, p, __ccgo_ts+15067, libc.VaList(bp+32, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)), chunk_id))
		goto cleanup
	}
	goto cleanup
cleanup:
	;
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 20)))(tls, **(**uintptr)(__ccgo_up(bp + 16)))
	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+15114, libc.VaList(bp+32, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)), chunk_id))
		return brc
	}
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * Returns 1 if the given column-based index is a auxiliary column,
//	 * 0 otherwise.
//	 */
func Xvec0_column_idx_is_auxiliary(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	return libc.BoolInt32(column_idx >= int32(m_VEC0_COLUMN_USERN_START) && column_idx <= int32(m_VEC0_COLUMN_USERN_START)+Xvec0_num_defined_user_columns(tls, pVtab)-int32(1) && **(**Tvec0_user_column_kind)(__ccgo_up(pVtab + 52 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START))*4)) == int32(_SQLITE_VEC0_USER_COLUMN_KIND_AUXILIARY))
}

// C documentation
//
//	/**
//	 * Returns 1 if the given column-based index is a metadata column,
//	 * 0 otherwise.
//	 */
func Xvec0_column_idx_is_metadata(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	return libc.BoolInt32(column_idx >= int32(m_VEC0_COLUMN_USERN_START) && column_idx <= int32(m_VEC0_COLUMN_USERN_START)+Xvec0_num_defined_user_columns(tls, pVtab)-int32(1) && **(**Tvec0_user_column_kind)(__ccgo_up(pVtab + 52 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START))*4)) == int32(_SQLITE_VEC0_USER_COLUMN_KIND_METADATA))
}

// C documentation
//
//	/**
//	 * Returns 1 if the given column-based index is a "partition key" column,
//	 * 0 otherwise.
//	 */
func Xvec0_column_idx_is_partition(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	return libc.BoolInt32(column_idx >= int32(m_VEC0_COLUMN_USERN_START) && column_idx <= int32(m_VEC0_COLUMN_USERN_START)+Xvec0_num_defined_user_columns(tls, pVtab)-int32(1) && **(**Tvec0_user_column_kind)(__ccgo_up(pVtab + 52 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START))*4)) == int32(_SQLITE_VEC0_USER_COLUMN_KIND_PARTITION))
}

// C documentation
//
//	/**
//	 * Returns 1 if the given column-based index is a valid vector column,
//	 * 0 otherwise.
//	 */
func Xvec0_column_idx_is_vector(tls *libc.TLS, pVtab uintptr, column_idx int32) (r int32) {
	return libc.BoolInt32(column_idx >= int32(m_VEC0_COLUMN_USERN_START) && column_idx <= int32(m_VEC0_COLUMN_USERN_START)+Xvec0_num_defined_user_columns(tls, pVtab)-int32(1) && **(**Tvec0_user_column_kind)(__ccgo_up(pVtab + 52 + uintptr(column_idx-int32(m_VEC0_COLUMN_USERN_START))*4)) == int32(_SQLITE_VEC0_USER_COLUMN_KIND_VECTOR))
}

// C documentation
//
//	/**
//	 * @brief Free all memory and sqlite3_stmt members of a vec0_vtab
//	 *
//	 * @param p vec0_vtab pointer
//	 */
func Xvec0_free(tls *libc.TLS, p uintptr) {
	var i, i1, i2, i3 int32
	_, _, _, _ = i, i1, i2, i3
	Xvec0_free_resources(tls, p)
	libsqlite3.Xsqlite3_free(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_free(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FtableName = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_free(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName = libc.UintptrFromInt32(0)
	libsqlite3.Xsqlite3_free(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowRowidsName)
	(*Tvec0_vtab)(unsafe.Pointer(p)).FshadowRowidsName = libc.UintptrFromInt32(0)
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)))
		**(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4)) = libc.UintptrFromInt32(0)
		libsqlite3.Xsqlite3_free(tls, (**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fname)
		(**(**TVectorColumnDefinition)(__ccgo_up(p + 440 + uintptr(i)*20))).Fname = libc.UintptrFromInt32(0)
		goto _1
	_1:
		;
		i = i + 1
	}
	i1 = 0
	for {
		if !(i1 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns) {
			break
		}
		libsqlite3.Xsqlite3_free(tls, (**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 760 + uintptr(i1)*12))).Fname)
		(**(**TVec0PartitionColumnDefinition)(__ccgo_up(p + 760 + uintptr(i1)*12))).Fname = libc.UintptrFromInt32(0)
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	i2 = 0
	for {
		if !(i2 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns) {
			break
		}
		libsqlite3.Xsqlite3_free(tls, (**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 808 + uintptr(i2)*12))).Fname)
		(**(**TVec0AuxiliaryColumnDefinition)(__ccgo_up(p + 808 + uintptr(i2)*12))).Fname = libc.UintptrFromInt32(0)
		goto _3
	_3:
		;
		i2 = i2 + 1
	}
	i3 = 0
	for {
		if !(i3 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumMetadataColumns) {
			break
		}
		libsqlite3.Xsqlite3_free(tls, (**(**TVec0MetadataColumnDefinition)(__ccgo_up(p + 1000 + uintptr(i3)*12))).Fname)
		(**(**TVec0MetadataColumnDefinition)(__ccgo_up(p + 1000 + uintptr(i3)*12))).Fname = libc.UintptrFromInt32(0)
		goto _4
	_4:
		;
		i3 = i3 + 1
	}
}

// C documentation
//
//	/**
//	 * @brief Retrieve the chunk_id, chunk_offset, and possible "id" value
//	 * of a vec0_vtab row with the provided rowid
//	 *
//	 * @param p vec0_vtab
//	 * @param rowid the rowid of the row to query
//	 * @param id output, optional sqlite3_value to provide the id.
//	 *            Useful for text PK rows. Must be freed with sqlite3_value_free()
//	 * @param chunk_id output, the chunk_id the row belongs to
//	 * @param chunk_offset  output, the offset within the chunk the row belongs to
//	 * @return SQLITE_ROW on success, error code otherwise. SQLITE_EMPTY if row DNE
//	 */
func Xvec0_get_chunk_position(tls *libc.TLS, p uintptr, rowid Ti64, id uintptr, chunk_id uintptr, chunk_offset uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var value, zSql uintptr
	_, _, _ = rc, value, zSql
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+3469, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		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), p+1212, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+3541, 0)
			goto cleanup
		}
	}
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition, int32(1), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition)
	// special case: when no results, return SQLITE_EMPTY to convey "that chunk
	// position doesnt exist"
	if rc == int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_EMPTY)
		goto cleanup
	}
	if rc != int32(m_SQLITE_ROW) {
		goto cleanup
	}
	if id != 0 {
		value = libsqlite3.Xsqlite3_column_value(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition, 0)
		**(**uintptr)(__ccgo_up(id)) = libsqlite3.Xsqlite3_value_dup(tls, value)
		if !(**(**uintptr)(__ccgo_up(id)) != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto cleanup
		}
	}
	if chunk_id != 0 {
		**(**Ti64)(__ccgo_up(chunk_id)) = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition, int32(1))
	}
	if chunk_offset != 0 {
		**(**Ti64)(__ccgo_up(chunk_offset)) = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition, int32(2))
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition)
	libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsGetChunkPosition)
	return rc
}

func Xvec0_get_latest_chunk_rowid(tls *libc.TLS, p uintptr, chunk_rowid uintptr, partitionKeyValues uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i, i1, rc int32
	var s, zSql uintptr
	_, _, _, _, _ = i, i1, rc, s, zSql
	// lazy initialize stmtLatestChunk when needed. May be cleared during xSync()
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk != 0) {
		if (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns > 0 {
			s = libsqlite3.Xsqlite3_str_new(tls, libc.UintptrFromInt32(0))
			libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+4118, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
			i = 0
			for {
				if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns) {
					break
				}
				if i != 0 {
					libsqlite3.Xsqlite3_str_appendall(tls, s, __ccgo_ts+4165)
				}
				libsqlite3.Xsqlite3_str_appendf(tls, s, __ccgo_ts+4171, libc.VaList(bp+8, i))
				goto _1
			_1:
				;
				i = i + 1
			}
			zSql = libsqlite3.Xsqlite3_str_finish(tls, s)
		} else {
			zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4191, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		}
		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), p+1196, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			// IMP: V21406_05476
			Xvtab_set_error(tls, p, __ccgo_ts+4231, 0)
			goto cleanup
		}
	}
	i1 = 0
	for {
		if !(i1 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumPartitionColumns) {
			break
		}
		libsqlite3.Xsqlite3_bind_value(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk, i1+int32(1), **(**uintptr)(__ccgo_up(partitionKeyValues + uintptr(i1)*4)))
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
	if rc != int32(m_SQLITE_ROW) {
		// IMP: V31559_15629
		Xvtab_set_error(tls, p, __ccgo_ts+4304, 0)
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	if libsqlite3.Xsqlite3_column_type(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk, 0) == int32(m_SQLITE_NULL) {
		rc = int32(m_SQLITE_EMPTY)
		goto cleanup
	}
	**(**Ti64)(__ccgo_up(chunk_rowid)) = libsqlite3.Xsqlite3_column_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk, 0)
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
	if rc != int32(m_SQLITE_DONE) {
		Xvtab_set_error(tls, p, __ccgo_ts+4359, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FshadowChunksName))
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk != 0 {
		libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
		libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtLatestChunk)
	}
	return rc
}

// C documentation
//
//	/**
//	 * @brief Parse an argv[i] entry of a vec0 virtual table definition, and see if
//	 * it's an auxiliar column definition, ie `+[name] [type]` like `+contents text`
//	 *
//	 * @param source: argv[i] source string
//	 * @param source_length: length of the source string
//	 * @param out_column_name: If it is a partition key, the output column name. Same lifetime
//	 * as source, points to specific char *
//	 * @param out_column_name_length: Length of out_column_name in bytes
//	 * @param out_column_type: SQLITE_TEXT, SQLITE_INTEGER, SQLITE_FLOAT, or SQLITE_BLOB.
//	 * @return int: SQLITE_EMPTY if not an aux column, SQLITE_OK if it is.
//	 */
func Xvec0_parse_auxiliary_column_definition(tls *libc.TLS, source uintptr, source_length int32, out_column_name uintptr, out_column_name_length uintptr, out_column_type uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var column_name uintptr
	var column_name_length, column_type, rc int32
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+12 */ TVec0Token
	_, _, _, _ = column_name, column_name_length, column_type, rc
	Xvec0_scanner_init(tls, bp, source, source_length)
	// Check first token is '+', which denotes aux columns
	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_PLUS) {
		return int32(m_SQLITE_EMPTY)
	}
	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)
	}
	column_name = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
	column_name_length = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)
	// Check the next token matches "text" or "integer", as column type
	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+1740, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 {
		column_type = int32(m_SQLITE_TEXT)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1745, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1749, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 {
			column_type = int32(m_SQLITE_INTEGER)
		} else {
			if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1771, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1777, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 {
				column_type = int32(m_SQLITE_FLOAT)
			} else {
				if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1784, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 {
					column_type = int32(m_SQLITE_BLOB)
				} else {
					return int32(m_SQLITE_EMPTY)
				}
			}
		}
	}
	**(**uintptr)(__ccgo_up(out_column_name)) = column_name
	**(**int32)(__ccgo_up(out_column_name_length)) = column_name_length
	**(**int32)(__ccgo_up(out_column_type)) = column_type
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * @brief Parse an argv[i] entry of a vec0 virtual table definition, and see if
//	 * it's an metadata column definition, ie `[name] [type]` like `is_released boolean`
//	 *
//	 * @param source: argv[i] source string
//	 * @param source_length: length of the source string
//	 * @param out_column_name: If it is a metadata column, the output column name. Same lifetime
//	 * as source, points to specific char *
//	 * @param out_column_name_length: Length of out_column_name in bytes
//	 * @param out_column_type: one of vec0_metadata_column_kind
//	 * @return int: SQLITE_EMPTY if not an metadata column, SQLITE_OK if it is.
//	 */
func Xvec0_parse_metadata_column_definition(tls *libc.TLS, source uintptr, source_length int32, out_column_name uintptr, out_column_name_length uintptr, out_column_type uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var column_name, t uintptr
	var column_name_length, n, rc int32
	var column_type Tvec0_metadata_column_kind
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+12 */ TVec0Token
	_, _, _, _, _, _ = column_name, column_name_length, column_type, n, rc, t
	Xvec0_scanner_init(tls, bp, source, source_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_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	column_name = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
	column_name_length = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)
	// Check the next token matches a valid metadata type
	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)
	}
	t = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
	n = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)
	if libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1789, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1797, n) == 0 {
		column_type = int32(_VEC0_METADATA_COLUMN_KIND_BOOLEAN)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1802, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1808, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1749, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1745, n) == 0 {
			column_type = int32(_VEC0_METADATA_COLUMN_KIND_INTEGER)
		} else {
			if libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1771, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1777, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1818, n) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1826, n) == 0 {
				column_type = int32(_VEC0_METADATA_COLUMN_KIND_FLOAT)
			} else {
				if libsqlite3.Xsqlite3_strnicmp(tls, t, __ccgo_ts+1740, n) == 0 {
					column_type = int32(_VEC0_METADATA_COLUMN_KIND_TEXT)
				} else {
					return int32(m_SQLITE_EMPTY)
				}
			}
		}
	}
	**(**uintptr)(__ccgo_up(out_column_name)) = column_name
	**(**int32)(__ccgo_up(out_column_name_length)) = column_name_length
	**(**Tvec0_metadata_column_kind)(__ccgo_up(out_column_type)) = column_type
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * @brief Parse an argv[i] entry of a vec0 virtual table definition, and see if
//	 * it's a PARTITION KEY definition.
//	 *
//	 * @param source: argv[i] source string
//	 * @param source_length: length of the source string
//	 * @param out_column_name: If it is a partition key, the output column name. Same lifetime
//	 * as source, points to specific char *
//	 * @param out_column_name_length: Length of out_column_name in bytes
//	 * @param out_column_type: SQLITE_TEXT or SQLITE_INTEGER.
//	 * @return int: SQLITE_EMPTY if not a PK, SQLITE_OK if it is.
//	 */
func Xvec0_parse_partition_key_definition(tls *libc.TLS, source uintptr, source_length int32, out_column_name uintptr, out_column_name_length uintptr, out_column_type uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var column_name uintptr
	var column_name_length, column_type, rc int32
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+12 */ TVec0Token
	_, _, _, _ = column_name, column_name_length, column_type, rc
	Xvec0_scanner_init(tls, bp, source, source_length)
	// Check first token is identifier, will be the column name
	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)
	}
	column_name = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
	column_name_length = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)
	// Check the next token matches "text" or "integer", as column type
	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+1740, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 {
		column_type = int32(m_SQLITE_TEXT)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1745, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1749, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 {
			column_type = int32(m_SQLITE_INTEGER)
		} else {
			return int32(m_SQLITE_EMPTY)
		}
	}
	// Check the next token is identifier and matches "partition"
	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+1757, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) != 0 {
		return int32(m_SQLITE_EMPTY)
	}
	// Check the next token is identifier and matches "key"
	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+1767, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) != 0 {
		return int32(m_SQLITE_EMPTY)
	}
	**(**uintptr)(__ccgo_up(out_column_name)) = column_name
	**(**int32)(__ccgo_up(out_column_name_length)) = column_name_length
	**(**int32)(__ccgo_up(out_column_type)) = column_type
	return m_SQLITE_OK
}

// C documentation
//
//	/**
//	 * @brief Parse an argv[i] entry of a vec0 virtual table definition, and see if
//	 * it's a PRIMARY KEY definition.
//	 *
//	 * @param source: argv[i] source string
//	 * @param source_length: length of the source string
//	 * @param out_column_name: If it is a PK, the output column name. Same lifetime
//	 * as source, points to specific char *
//	 * @param out_column_name_length: Length of out_column_name in bytes
//	 * @param out_column_type: SQLITE_TEXT or SQLITE_INTEGER.
//	 * @return int: SQLITE_EMPTY if not a PK, SQLITE_OK if it is.
//	 */
func Xvec0_parse_primary_key_definition(tls *libc.TLS, source uintptr, source_length int32, out_column_name uintptr, out_column_name_length uintptr, out_column_type uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var column_name uintptr
	var column_name_length, column_type, rc int32
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+12 */ TVec0Token
	_, _, _, _ = column_name, column_name_length, column_type, rc
	Xvec0_scanner_init(tls, bp, source, source_length)
	// Check first token is identifier, will be the column name
	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)
	}
	column_name = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
	column_name_length = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)
	// Check the next token matches "text" or "integer", as column type
	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+1740, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 {
		column_type = int32(m_SQLITE_TEXT)
	} else {
		if libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1745, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 || libsqlite3.Xsqlite3_strnicmp(tls, (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart, __ccgo_ts+1749, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) == 0 {
			column_type = int32(m_SQLITE_INTEGER)
		} else {
			return int32(m_SQLITE_EMPTY)
		}
	}
	// Check the next token is identifier and matches "primary"
	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+1830, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) != 0 {
		return int32(m_SQLITE_EMPTY)
	}
	// Check the next token is identifier and matches "key"
	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+1767, int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend)-int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)) != 0 {
		return int32(m_SQLITE_EMPTY)
	}
	**(**uintptr)(__ccgo_up(out_column_name)) = column_name
	**(**int32)(__ccgo_up(out_column_name_length)) = column_name_length
	**(**int32)(__ccgo_up(out_column_type)) = column_type
	return m_SQLITE_OK
}

func Xvec0_parse_table_option(tls *libc.TLS, source uintptr, source_length int32, out_key uintptr, out_key_length uintptr, out_value uintptr, out_value_length uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var key, value uintptr
	var keyLength, rc, valueLength int32
	var _ /* scanner at bp+0 */ TVec0Scanner
	var _ /* token at bp+12 */ TVec0Token
	_, _, _, _, _ = key, keyLength, rc, value, valueLength
	Xvec0_scanner_init(tls, bp, source, source_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_IDENTIFIER) {
		return int32(m_SQLITE_EMPTY)
	}
	key = (**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart
	keyLength = int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fend) - int32((**(**TVec0Token)(__ccgo_up(bp + 12))).Fstart)
	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_EMPTY)
	}
	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) || (**(**TVec0Token)(__ccgo_up(bp + 12))).Ftoken_type == int32(_TOKEN_TYPE_DIGIT)) {
		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)
	rc = Xvec0_scanner_next(tls, bp, bp+12)
	if rc == int32(m_VEC0_TOKEN_RESULT_EOF) {
		**(**uintptr)(__ccgo_up(out_key)) = key
		**(**int32)(__ccgo_up(out_key_length)) = keyLength
		**(**uintptr)(__ccgo_up(out_value)) = value
		**(**int32)(__ccgo_up(out_value_length)) = valueLength
		return m_SQLITE_OK
	}
	return int32(m_SQLITE_ERROR)
}

func Xvec0_query_point_data_clear(tls *libc.TLS, point_data uintptr) {
	var i int32
	_ = i
	if !(point_data != 0) {
		return
	}
	i = 0
	for {
		if !(i < int32(m_VEC0_MAX_VECTOR_COLUMNS)) {
			break
		}
		libsqlite3.Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(point_data + 8 + uintptr(i)*4)))
		**(**uintptr)(__ccgo_up(point_data + 8 + uintptr(i)*4)) = libc.UintptrFromInt32(0)
		goto _1
	_1:
		;
		i = i + 1
	}
}

func Xvec0_rowids_insert_id(tls *libc.TLS, p uintptr, idValue uintptr, rowid uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var entered, rc int32
	var zSql uintptr
	_, _, _ = entered, rc, zSql
	rc = m_SQLITE_OK
	entered = 0
	_ = entered // temporary
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4725, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		if !(zSql != 0) {
			rc = int32(m_SQLITE_NOMEM)
			goto complete
		}
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), p+1204, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+4769, 0)
			goto complete
		}
	}
	if idValue != 0 {
		libsqlite3.Xsqlite3_bind_value(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId, int32(1), idValue)
	}
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId)
	if rc != int32(m_SQLITE_DONE) {
		if libsqlite3.Xsqlite3_extended_errcode(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb) == libc.Int32FromInt32(m_SQLITE_CONSTRAINT)|libc.Int32FromInt32(8)<<libc.Int32FromInt32(8) {
			// IMP: V20497_04568
			Xvtab_set_error(tls, p, __ccgo_ts+4631, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		} else {
			// IMP: V24016_08086
			// IMP: V15177_32015
			Xvtab_set_error(tls, p, __ccgo_ts+4846, libc.VaList(bp+8, libsqlite3.Xsqlite3_errmsg(tls, libsqlite3.Xsqlite3_db_handle(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId))))
		}
		rc = int32(m_SQLITE_ERROR)
		goto complete
	}
	**(**Ti64)(__ccgo_up(rowid)) = libsqlite3.Xsqlite3_last_insert_rowid(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb)
	rc = m_SQLITE_OK
	goto complete
complete:
	;
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId != 0 {
		libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId)
		libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId)
	}
	return rc
}

func Xvec0_rowids_insert_rowid(tls *libc.TLS, p uintptr, rowid Ti64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var entered, rc int32
	var zSql uintptr
	_, _, _ = entered, rc, zSql
	rc = m_SQLITE_OK
	entered = 0
	_ = entered // temporary
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4510, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		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), p+1200, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+4557, 0)
			goto cleanup
		}
	}
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid, int32(1), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid)
	if rc != int32(m_SQLITE_DONE) {
		if libsqlite3.Xsqlite3_extended_errcode(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb) == libc.Int32FromInt32(m_SQLITE_CONSTRAINT)|libc.Int32FromInt32(6)<<libc.Int32FromInt32(8) {
			// IMP: V17090_01160
			Xvtab_set_error(tls, p, __ccgo_ts+4631, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		} else {
			// IMP: V04679_21517
			Xvtab_set_error(tls, p, __ccgo_ts+4674, libc.VaList(bp+8, libsqlite3.Xsqlite3_errmsg(tls, libsqlite3.Xsqlite3_db_handle(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertId))))
		}
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid != 0 {
		libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid)
		libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsInsertRowid)
	}
	return rc
}

func Xvec0_rowids_update_position(tls *libc.TLS, p uintptr, rowid Ti64, chunk_rowid Ti64, chunk_offset Ti64) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var zSql uintptr
	_, _ = rc, zSql
	rc = m_SQLITE_OK
	if !((*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition != 0) {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+4894, libc.VaList(bp+8, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		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), p+1208, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK {
			Xvtab_set_error(tls, p, __ccgo_ts+4970, 0)
			goto cleanup
		}
	}
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition, int32(1), chunk_rowid)
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition, int32(2), chunk_offset)
	libsqlite3.Xsqlite3_bind_int64(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition, int32(3), rowid)
	rc = libsqlite3.Xsqlite3_step(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition)
	if rc != int32(m_SQLITE_DONE) {
		// IMP: V21925_05995
		Xvtab_set_error(tls, p, __ccgo_ts+5053, libc.VaList(bp+8, rowid, chunk_rowid, chunk_offset))
		rc = int32(m_SQLITE_ERROR)
		goto cleanup
	}
	rc = m_SQLITE_OK
	goto cleanup
cleanup:
	;
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition != 0 {
		libsqlite3.Xsqlite3_reset(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition)
		libsqlite3.Xsqlite3_clear_bindings(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).FstmtRowidsUpdatePosition)
	}
	return rc
}

func _distance_cosine_float(tls *libc.TLS, pVect1v uintptr, pVect2v uintptr, qty_ptr uintptr) (r Tf32) {
	var aMag, bMag, dot Tf32
	var i, qty Tsize_t
	var pVect1, pVect2 uintptr
	_, _, _, _, _, _, _ = aMag, bMag, dot, i, pVect1, pVect2, qty
	pVect1 = pVect1v
	pVect2 = pVect2v
	qty = **(**Tsize_t)(__ccgo_up(qty_ptr))
	dot = libc.Float32FromInt32(0)
	aMag = libc.Float32FromInt32(0)
	bMag = libc.Float32FromInt32(0)
	i = uint32(0)
	for {
		if !(i < qty) {
			break
		}
		dot = dot + Tf32(**(**Tf32)(__ccgo_up(pVect1))***(**Tf32)(__ccgo_up(pVect2)))
		aMag = aMag + Tf32(**(**Tf32)(__ccgo_up(pVect1))***(**Tf32)(__ccgo_up(pVect1)))
		bMag = bMag + Tf32(**(**Tf32)(__ccgo_up(pVect2))***(**Tf32)(__ccgo_up(pVect2)))
		pVect1 += 4
		pVect2 += 4
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Float64FromInt32(1) - float64(dot)/float64(libc.Xsqrt(tls, float64(aMag))*libc.Xsqrt(tls, float64(bMag))))
}

func _distance_cosine_int8(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r Tf32) {
	var a, b uintptr
	var aMag, bMag, dot Tf32
	var d, i Tsize_t
	_, _, _, _, _, _, _ = a, aMag, b, bMag, d, dot, i
	a = pA
	b = pB
	d = **(**Tsize_t)(__ccgo_up(pD))
	dot = libc.Float32FromInt32(0)
	aMag = libc.Float32FromInt32(0)
	bMag = libc.Float32FromInt32(0)
	i = uint32(0)
	for {
		if !(i < d) {
			break
		}
		dot = dot + Tf32(int32(**(**Ti8)(__ccgo_up(a)))*int32(**(**Ti8)(__ccgo_up(b))))
		aMag = aMag + Tf32(int32(**(**Ti8)(__ccgo_up(a)))*int32(**(**Ti8)(__ccgo_up(a))))
		bMag = bMag + Tf32(int32(**(**Ti8)(__ccgo_up(b)))*int32(**(**Ti8)(__ccgo_up(b))))
		a = a + 1
		b = b + 1
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Float64FromInt32(1) - float64(dot)/float64(libc.Xsqrt(tls, float64(aMag))*libc.Xsqrt(tls, float64(bMag))))
}

func _l1_f32(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r float64) {
	var a, b uintptr
	var d, i Tsize_t
	var res float64
	_, _, _, _, _ = a, b, d, i, res
	a = pA
	b = pB
	d = **(**Tsize_t)(__ccgo_up(pD))
	res = libc.Float64FromInt32(0)
	i = uint32(0)
	for {
		if !(i < d) {
			break
		}
		res = res + libc.Xfabs(tls, float64(**(**Tf32)(__ccgo_up(a)))-float64(**(**Tf32)(__ccgo_up(b))))
		a += 4
		b += 4
		goto _1
	_1:
		;
		i = i + 1
	}
	return res
}

func _l1_int8(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r Ti32) {
	var a, b uintptr
	var d, i Tsize_t
	var res Ti32
	_, _, _, _, _ = a, b, d, i, res
	a = pA
	b = pB
	d = **(**Tsize_t)(__ccgo_up(pD))
	res = 0
	i = uint32(0)
	for {
		if !(i < d) {
			break
		}
		res = res + libc.Xabs(tls, int32(**(**Ti8)(__ccgo_up(a)))-int32(**(**Ti8)(__ccgo_up(b))))
		a = a + 1
		b = b + 1
		goto _1
	_1:
		;
		i = i + 1
	}
	return res
}

func _l2_sqr_float(tls *libc.TLS, pVect1v uintptr, pVect2v uintptr, qty_ptr uintptr) (r Tf32) {
	var i, qty Tsize_t
	var pVect1, pVect2 uintptr
	var res, t Tf32
	_, _, _, _, _, _ = i, pVect1, pVect2, qty, res, t
	pVect1 = pVect1v
	pVect2 = pVect2v
	qty = **(**Tsize_t)(__ccgo_up(qty_ptr))
	res = libc.Float32FromInt32(0)
	i = uint32(0)
	for {
		if !(i < qty) {
			break
		}
		t = **(**Tf32)(__ccgo_up(pVect1)) - **(**Tf32)(__ccgo_up(pVect2))
		pVect1 += 4
		pVect2 += 4
		res = res + Tf32(t*t)
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Xsqrt(tls, float64(res)))
}

func _l2_sqr_int8(tls *libc.TLS, pA uintptr, pB uintptr, pD uintptr) (r Tf32) {
	var a, b uintptr
	var d, i Tsize_t
	var res, t Tf32
	_, _, _, _, _, _ = a, b, d, i, res, t
	a = pA
	b = pB
	d = **(**Tsize_t)(__ccgo_up(pD))
	res = libc.Float32FromInt32(0)
	i = uint32(0)
	for {
		if !(i < d) {
			break
		}
		t = float32(int32(**(**Ti8)(__ccgo_up(a))) - int32(**(**Ti8)(__ccgo_up(b))))
		a = a + 1
		b = b + 1
		res = res + Tf32(t*t)
		goto _1
	_1:
		;
		i = i + 1
	}
	return float32(libc.Xsqrt(tls, float64(res)))
}

func _vec0Destroy(tls *libc.TLS, pVtab uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i, i1, rc int32
	var p, zSql uintptr
	var _ /* stmt at bp+0 */ uintptr
	_, _, _, _, _ = i, i1, p, rc, zSql
	p = pVtab
	// Free up any sqlite3_stmt, otherwise DROPs on those tables will fail
	Xvec0_free_resources(tls, p)
	// TODO(test) later: can't evidence-of here, bc always gives "SQL logic error" instead of
	// provided error
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8154, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) != int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_ERROR)
		Xvtab_set_error(tls, pVtab, __ccgo_ts+8182, 0)
		goto done
	}
	libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8217, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) != int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_ERROR)
		Xvtab_set_error(tls, pVtab, __ccgo_ts+8243, 0)
		goto done
	}
	libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8276, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
	rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
	libsqlite3.Xsqlite3_free(tls, zSql)
	if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) != int32(m_SQLITE_DONE) {
		rc = int32(m_SQLITE_ERROR)
		goto done
	}
	libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	i = 0
	for {
		if !(i < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumVectorColumns) {
			break
		}
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8304, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, **(**uintptr)(__ccgo_up(p + 312 + uintptr(i)*4))))
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) != int32(m_SQLITE_DONE) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		goto _1
	_1:
		;
		i = i + 1
	}
	if (*Tvec0_vtab)(unsafe.Pointer(p)).FnumAuxiliaryColumns > 0 {
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8325, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName))
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) != int32(m_SQLITE_DONE) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	}
	i1 = 0
	for {
		if !(i1 < (*Tvec0_vtab)(unsafe.Pointer(p)).FnumMetadataColumns) {
			break
		}
		zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8356, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, i1))
		rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
		libsqlite3.Xsqlite3_free(tls, zSql)
		if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) != int32(m_SQLITE_DONE) {
			rc = int32(m_SQLITE_ERROR)
			goto done
		}
		libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		if (**(**TVec0MetadataColumnDefinition)(__ccgo_up(p + 1000 + uintptr(i1)*12))).Fkind == int32(_VEC0_METADATA_COLUMN_KIND_TEXT) {
			zSql = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+8396, libc.VaList(bp+16, (*Tvec0_vtab)(unsafe.Pointer(p)).FschemaName, (*Tvec0_vtab)(unsafe.Pointer(p)).FtableName, i1))
			rc = libsqlite3.Xsqlite3_prepare_v2(tls, (*Tvec0_vtab)(unsafe.Pointer(p)).Fdb, zSql, -int32(1), bp, uintptr(0))
			libsqlite3.Xsqlite3_free(tls, zSql)
			if rc != m_SQLITE_OK || libsqlite3.Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp))) != int32(m_SQLITE_DONE) {
				rc = int32(m_SQLITE_ERROR)
				goto done
			}
			libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
		}
		goto _2
	_2:
		;
		i1 = i1 + 1
	}
	**(**uintptr)(__ccgo_up(bp)) = libc.UintptrFromInt32(0)
	rc = m_SQLITE_OK
	goto done
done:
	;
	libsqlite3.Xsqlite3_finalize(tls, **(**uintptr)(__ccgo_up(bp)))
	Xvec0_free(tls, p)
	// If there was an error
	if rc == m_SQLITE_OK {
		libsqlite3.Xsqlite3_free(tls, p)
	}
	return rc
}

func _vec0Open(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	_ = p
	pCur = libsqlite3.Xsqlite3_malloc(tls, int32(20))
	if pCur == uintptr(0) {
		return int32(m_SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCur, 0, uint32(20))
	**(**uintptr)(__ccgo_up(ppCursor)) = pCur
	return m_SQLITE_OK
}

func _vec0ShadowName(tls *libc.TLS, zName uintptr) (r int32) {
	var i Tsize_t
	_ = i
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(144)/libc.Uint32FromInt64(4)) {
			break
		}
		if libsqlite3.Xsqlite3_stricmp(tls, zName, _azName[i]) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	//for(size_t i = 0; i < )"vector_chunks", "metadatachunks"
	return 0
}

func _vec_distance_cosine(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var result, result1 Tf32
	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
	_, _, _ = rc, result, result1
	**(**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+688, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		result = _distance_cosine_float(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 4)), bp+8)
		libsqlite3.Xsqlite3_result_double(tls, context, float64(result))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		result1 = _distance_cosine_int8(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 4)), bp+8)
		libsqlite3.Xsqlite3_result_double(tls, context, float64(result1))
		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_distance_hamming(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	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
	_ = 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_double(tls, context, float64(_distance_hamming(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 4)), bp+8)))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+851, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		libsqlite3.Xsqlite3_result_error(tls, context, __ccgo_ts+914, -int32(1))
		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_distance_l1(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var result float64
	var result1 Ti64
	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
	_, _, _ = rc, result, result1
	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+798, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		result = _distance_l1_f32(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 4)), bp+8)
		libsqlite3.Xsqlite3_result_double(tls, context, result)
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		result1 = int64(_distance_l1_int8(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 4)), bp+8))
		libsqlite3.Xsqlite3_result_int(tls, context, int32(result1))
		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_distance_l2(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var rc int32
	var result, result1 Tf32
	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
	_, _, _ = rc, result, result1
	**(**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+745, -int32(1))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_FLOAT32):
		result = _distance_l2_sqr_float(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 4)), bp+8)
		libsqlite3.Xsqlite3_result_double(tls, context, float64(result))
		goto finish
	case int32(_SQLITE_VEC_ELEMENT_TYPE_INT8):
		result1 = _distance_l2_sqr_int8(tls, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp + 4)), bp+8)
		libsqlite3.Xsqlite3_result_double(tls, context, float64(result1))
		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_eachConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	_ = pAux
	_ = argc
	_ = argv
	_ = pzErr
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, __ccgo_ts+1879)
	if rc == m_SQLITE_OK {
		pNew = libsqlite3.Xsqlite3_malloc(tls, int32(12))
		**(**uintptr)(__ccgo_up(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint32(12))
	}
	return rc
}

func _vec_npy_eachConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	_ = pAux
	_ = argc
	_ = argv
	_ = pzErr
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, __ccgo_ts+3334)
	if rc == m_SQLITE_OK {
		pNew = libsqlite3.Xsqlite3_malloc(tls, int32(12))
		**(**uintptr)(__ccgo_up(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint32(12))
	}
	return rc
}

func _vec_npy_eachFilter(tls *libc.TLS, pVtabCursor uintptr, idxNum int32, idxStr uintptr, argc int32, argv uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var f, file, input, pCur, v1 uintptr
	var inputLength, rc int32
	var _ /* data at bp+0 */ uintptr
	var _ /* element_type at bp+12 */ _VectorElementType
	var _ /* numDimensions at bp+8 */ Tsize_t
	var _ /* numElements at bp+4 */ Tsize_t
	_, _, _, _, _, _, _ = f, file, input, inputLength, pCur, rc, v1
	_ = idxNum
	_ = idxStr
	pCur = pVtabCursor
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile != 0 {
		libc.Xfclose(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile)
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile = libc.UintptrFromInt32(0)
	}
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer != 0 {
		libsqlite3.Xsqlite3_free(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer)
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer = libc.UintptrFromInt32(0)
	}
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector != 0 {
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector = libc.UintptrFromInt32(0)
	}
	f = libc.UintptrFromInt32(0)
	v1 = libsqlite3.Xsqlite3_value_pointer(tls, **(**uintptr)(__ccgo_up(argv)), __ccgo_ts+674)
	f = v1
	if v1 != 0 {
		file = libc.Xfopen(tls, (*TVecNpyFile)(unsafe.Pointer(f)).Fpath, __ccgo_ts+3398)
		if !(file != 0) {
			Xvtab_set_error(tls, (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab, __ccgo_ts+3400, 0)
			return int32(m_SQLITE_ERROR)
		}
		rc = Xparse_npy_file(tls, (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab, file, pCur)
		if rc != m_SQLITE_OK {
			libc.Xfclose(tls, file)
			return rc
		}
	} else {
		input = libsqlite3.Xsqlite3_value_blob(tls, **(**uintptr)(__ccgo_up(argv)))
		inputLength = libsqlite3.Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
		rc = Xparse_npy_buffer(tls, (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pVtabCursor)).FpVtab, input, inputLength, bp, bp+4, bp+8, bp+12)
		if rc != m_SQLITE_OK {
			return rc
		}
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Fvector = **(**uintptr)(__ccgo_up(bp))
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType = **(**_VectorElementType)(__ccgo_up(bp + 12))
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnElements = **(**Tsize_t)(__ccgo_up(bp + 4))
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions = **(**Tsize_t)(__ccgo_up(bp + 8))
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Finput_type = int32(_VEC_NPY_EACH_INPUT_BUFFER)
	}
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid = 0
	return m_SQLITE_OK
}

func _vec_npy_eachNext(tls *libc.TLS, cur uintptr) (r int32) {
	var pCur uintptr
	_ = pCur
	pCur = cur
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid = (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FiRowid + 1
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Finput_type == int32(_VEC_NPY_EACH_INPUT_BUFFER) {
		return m_SQLITE_OK
	}
	// else: input is a file
	(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex = (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex + 1
	if (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex >= (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkSize {
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkSize = libc.Xfread(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FchunksBuffer, Xvector_byte_size(tls, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FelementType, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FnDimensions), (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FmaxChunks, (*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Ffile)
		if !((*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkSize != 0) {
			(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).Feof = int32(1)
		}
		(*Tvec_npy_each_cursor)(unsafe.Pointer(pCur)).FcurrentChunkIndex = uint32(0)
	}
	return m_SQLITE_OK
}

func _vec_static_blob_entriesConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var blob_data, pNew uintptr
	var i, idx, rc int32
	_, _, _, _, _ = blob_data, i, idx, pNew, rc
	_ = argc
	_ = argv
	_ = pzErr
	blob_data = pAux
	idx = -int32(1)
	i = 0
	for {
		if !(i < int32(m_MAX_STATIC_BLOBS)) {
			break
		}
		if !((**(**Tstatic_blob)(__ccgo_up(blob_data + uintptr(i)*20))).Fname != 0) {
			goto _1
		}
		if libc.Xstrncmp(tls, (**(**Tstatic_blob)(__ccgo_up(blob_data + uintptr(i)*20))).Fname, **(**uintptr)(__ccgo_up(argv + 3*4)), libc.Xstrlen(tls, (**(**Tstatic_blob)(__ccgo_up(blob_data + uintptr(i)*20))).Fname)) == 0 {
			idx = i
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if idx < 0 {
		libc.Xabort(tls)
	}
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, __ccgo_ts+15953)
	if rc == m_SQLITE_OK {
		pNew = libsqlite3.Xsqlite3_malloc(tls, int32(16))
		**(**uintptr)(__ccgo_up(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint32(16))
		(*Tvec_static_blob_entries_vtab)(unsafe.Pointer(pNew)).Fblob = blob_data + uintptr(idx)*20
	}
	return rc
}

func _vec_static_blobsConnect(tls *libc.TLS, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVtab uintptr, pzErr uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	_ = argc
	_ = argv
	_ = pzErr
	rc = libsqlite3.Xsqlite3_declare_vtab(tls, db, __ccgo_ts+15893)
	if rc == m_SQLITE_OK {
		pNew = libsqlite3.Xsqlite3_malloc(tls, int32(16))
		**(**uintptr)(__ccgo_up(ppVtab)) = pNew
		if pNew == uintptr(0) {
			return int32(m_SQLITE_NOMEM)
		}
		libc.Xmemset(tls, pNew, 0, uint32(16))
		(*Tvec_static_blobs_vtab)(unsafe.Pointer(pNew)).Fdata = pAux
	}
	return rc
}

func _vec_static_blobsNext(tls *libc.TLS, cur uintptr) (r int32) {
	var p, pCur uintptr
	_, _ = p, pCur
	pCur = cur
	p = (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).Fbase.FpVtab
	(*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid = (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid + 1
	for (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid < int64(m_MAX_STATIC_BLOBS) {
		if (**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr((*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid)*20))).Fname != 0 {
			return m_SQLITE_OK
		}
		(*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid = (*Tvec_static_blobs_cursor)(unsafe.Pointer(pCur)).FiRowid + 1
	}
	return m_SQLITE_OK
}

func _vec_static_blobsUpdate(tls *libc.TLS, pVTab uintptr, argc int32, argv uintptr, pRowid uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var def, key, p uintptr
	var i, idx int32
	_, _, _, _, _ = def, i, idx, key, p
	_ = pRowid
	p = pVTab
	// DELETE operation
	if argc == int32(1) && libsqlite3.Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) != int32(m_SQLITE_NULL) {
		return int32(m_SQLITE_ERROR)
	} else {
		if argc > int32(1) && libsqlite3.Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(m_SQLITE_NULL) {
			key = libsqlite3.Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC_STATIC_BLOBS_NAME))*4)))
			idx = -int32(1)
			i = 0
			for {
				if !(i < int32(m_MAX_STATIC_BLOBS)) {
					break
				}
				if !((**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(i)*20))).Fname != 0) {
					(**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(i)*20))).Fname = libsqlite3.Xsqlite3_mprintf(tls, __ccgo_ts+6600, libc.VaList(bp+8, key))
					idx = i
					break
				}
				goto _1
			_1:
				;
				i = i + 1
			}
			if idx < 0 {
				libc.Xabort(tls)
			}
			def = libsqlite3.Xsqlite3_value_pointer(tls, **(**uintptr)(__ccgo_up(argv + uintptr(libc.Int32FromInt32(2)+libc.Int32FromInt32(m_VEC_STATIC_BLOBS_DATA))*4)), _POINTER_NAME_STATIC_BLOB_DEF)
			(**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(idx)*20))).Fp = (*Tstatic_blob_definition)(unsafe.Pointer(def)).Fp
			(**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(idx)*20))).Fdimensions = (*Tstatic_blob_definition)(unsafe.Pointer(def)).Fdimensions
			(**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(idx)*20))).Fnvectors = (*Tstatic_blob_definition)(unsafe.Pointer(def)).Fnvectors
			(**(**Tstatic_blob)(__ccgo_up((*Tvec_static_blobs_vtab)(unsafe.Pointer(p)).Fdata + uintptr(idx)*20))).Felement_type = (*Tstatic_blob_definition)(unsafe.Pointer(def)).Felement_type
			return m_SQLITE_OK
		} else {
			if argc > int32(1) && libsqlite3.Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) != int32(m_SQLITE_NULL) {
				return int32(m_SQLITE_ERROR)
			}
		}
	}
	return int32(m_SQLITE_ERROR)
}

func _vec_type(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 _ /* pzError 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_text(tls, context, Xvec_type_name(tls, **(**_VectorElementType)(__ccgo_up(bp + 16))), -int32(1), libc.UintptrFromInt32(0))
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(bp + 8)))(tls, **(**uintptr)(__ccgo_up(bp)))
}

func init() {
	p := unsafe.Pointer(&_vec0Module)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_vec0Create)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_vec0Connect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_vec0BestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec0Disconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_vec0Destroy)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec0Open)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_vec0Close)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec0Filter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_vec0Next)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_vec0Eof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_vec0Column)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec0Rowid)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_vec0Update)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_vec0Begin)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_vec0Sync)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_vec0Commit)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_vec0Rollback)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(_vec0ShadowName)
}

func init() {
	p := unsafe.Pointer(&_vec_static_blob_entriesModule)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_vec_static_blob_entriesCreate)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_vec_static_blob_entriesConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_vec_static_blob_entriesBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec_static_blob_entriesDisconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_vec_static_blob_entriesDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec_static_blob_entriesOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_vec_static_blob_entriesClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_static_blob_entriesFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_vec_static_blob_entriesNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_vec_static_blob_entriesEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_vec_static_blob_entriesColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec_static_blob_entriesRowid)
}

func init() {
	p := unsafe.Pointer(&_vec_npy_eachModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_vec_npy_eachConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_vec_npy_eachBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec_npy_eachDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec_npy_eachOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_vec_npy_eachClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_npy_eachFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_vec_npy_eachNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_vec_npy_eachEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_vec_npy_eachColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec_npy_eachRowid)
}

/// 1) schema, 2) original vtab table name

/// 1) schema, 2) original vtab table name

// vec0 tables with a text primary keys are still backed by int64 primary keys,
// since a fixed-length rowid is required for vec0 chunks. But we add a new 'id
// text unique' column to emulate a text primary key interface.

/// 1) schema, 2) original vtab table name

/// 1) schema, 2) original vtab table name
//
// IMPORTANT: "rowid" is declared as PRIMARY KEY but WITHOUT the INTEGER type.
// This means it is NOT a true SQLite rowid alias — the user-defined "rowid"
// column and the internal SQLite rowid (_rowid_) are two separate values.
// When inserting, both must be set explicitly to keep them in sync. See the
// _rowid_ bindings in vec0_new_chunk() and the explanation in
// SHADOW_TABLE_ROWID_QUIRK below.

func init() {
	p := unsafe.Pointer(&_vec_static_blobsModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_vec_static_blobsConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_vec_static_blobsBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec_static_blobsDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec_static_blobsOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_vec_static_blobsClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_static_blobsFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_vec_static_blobsNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_vec_static_blobsEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_vec_static_blobsColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec_static_blobsRowid)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_vec_static_blobsUpdate)
}

func init() {
	p := unsafe.Pointer(&_vec_eachModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_vec_eachConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_vec_eachBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_vec_eachDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_vec_eachOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_vec_eachClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_vec_eachFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_vec_eachNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_vec_eachEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_vec_eachColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_vec_eachRowid)
}

func init() {
	p := unsafe.Pointer(&_aFunc)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_vec_distance_l2)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_vec_distance_l1)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_vec_distance_hamming)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_vec_distance_cosine)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_vec_length)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_vec_type)
	*(*uintptr)(unsafe.Add(p, 100)) = __ccgo_fp(_vec_to_json)
	*(*uintptr)(unsafe.Add(p, 116)) = __ccgo_fp(_vec_add)
	*(*uintptr)(unsafe.Add(p, 132)) = __ccgo_fp(_vec_sub)
	*(*uintptr)(unsafe.Add(p, 148)) = __ccgo_fp(_vec_slice)
	*(*uintptr)(unsafe.Add(p, 164)) = __ccgo_fp(_vec_normalize)
	*(*uintptr)(unsafe.Add(p, 180)) = __ccgo_fp(_vec_f32)
	*(*uintptr)(unsafe.Add(p, 196)) = __ccgo_fp(_vec_bit)
	*(*uintptr)(unsafe.Add(p, 212)) = __ccgo_fp(_vec_int8)
	*(*uintptr)(unsafe.Add(p, 228)) = __ccgo_fp(_vec_quantize_int8)
	*(*uintptr)(unsafe.Add(p, 244)) = __ccgo_fp(_vec_quantize_binary)
}

const m_INTPTR_MAX = "INT32_MAX"

const m_INTPTR_MIN = "INT32_MIN"

const m_PTRDIFF_MAX = "INT32_MAX"

const m_PTRDIFF_MIN = "INT32_MIN"

const m_SIZE_MAX = "UINT32_MAX"

const m_UINTPTR_MAX = "UINT32_MAX"

const m__FILE_OFFSET_BITS = 64

const m___INTPTR_TYPE__ = "int"

const m___INTPTR_WIDTH__ = 32

const m___PTRDIFF_TYPE__ = "int"

const m___PTRDIFF_WIDTH__ = 32

const m___SIZEOF_POINTER__ = 4

const m___SIZEOF_PTRDIFF_T__ = 4

const m___SIZEOF_SIZE_T__ = 4

const m___SIZE_WIDTH__ = 32

type t__predefined_ptrdiff_t = int32

type t__predefined_size_t = uint32
