Index: src/AST/Expr.cpp
===================================================================
--- src/AST/Expr.cpp	(revision 20737104831e8e78cbe01e2e63a3969afaec6c88)
+++ src/AST/Expr.cpp	(revision e01eb4aa19bfce233e01f84a77d45064842e6ebf)
@@ -22,4 +22,5 @@
 #include "Copy.hpp"                // for shallowCopy
 #include "GenericSubstitution.hpp"
+#include "Inspect.hpp"
 #include "LinkageSpec.hpp"
 #include "Stmt.hpp"
@@ -29,5 +30,4 @@
 #include "Common/SemanticError.h"
 #include "GenPoly/Lvalue.h"        // for referencesPermissable
-#include "InitTweak/InitTweak.h"   // for getFunction, getPointerBase
 #include "ResolvExpr/typeops.h"    // for extractResultType
 #include "Tuples/Tuples.h"         // for makeTupleType
@@ -58,5 +58,5 @@
 
 bool ApplicationExpr::get_lvalue() const {
-	if ( const DeclWithType * func = InitTweak::getFunction( this ) ) {
+	if ( const DeclWithType * func = getFunction( this ) ) {
 		return func->linkage == Linkage::Intrinsic && lvalueFunctionNames.count( func->name );
 	}
@@ -67,5 +67,5 @@
 
 bool UntypedExpr::get_lvalue() const {
-	std::string fname = InitTweak::getFunctionName( this );
+	std::string fname = getFunctionName( this );
 	return lvalueFunctionNames.count( fname );
 }
@@ -76,5 +76,5 @@
 	UntypedExpr * ret = createCall( loc, "*?", { arg } );
 	if ( const Type * ty = arg->result ) {
-		const Type * base = InitTweak::getPointerBase( ty );
+		const Type * base = getPointerBase( ty );
 		assertf( base, "expected pointer type in dereference (type was %s)", toString( ty ).c_str() );
 
@@ -335,5 +335,5 @@
 	// first argument
 	assert( callExpr );
-	const Expr * arg = InitTweak::getCallArg( callExpr, 0 );
+	const Expr * arg = getCallArg( callExpr, 0 );
 	assert( arg );
 	result = arg->result;
Index: src/AST/Inspect.cpp
===================================================================
--- src/AST/Inspect.cpp	(revision 20737104831e8e78cbe01e2e63a3969afaec6c88)
+++ src/AST/Inspect.cpp	(revision e01eb4aa19bfce233e01f84a77d45064842e6ebf)
@@ -10,15 +10,142 @@
 // Created On       : Fri Jun 24 13:16:31 2022
 // Last Modified By : Andrew Beach
-// Last Modified On : Mon Jun 27 15:35:00 2022
-// Update Count     : 1
+// Last Modified On : Wed Sep 22 13:50:00 2022
+// Update Count     : 2
 //
 
-#include "AST/Decl.hpp"
-#include "AST/Type.hpp"
+#include "Inspect.hpp"
 
 #include <iostream>
-#include <AST/Print.hpp>
+
+#include "AST/Decl.hpp"
+#include "AST/Expr.hpp"
+#include "AST/Print.hpp"
+#include "AST/Stmt.hpp"
+#include "AST/Type.hpp"
+#include "CodeGen/OperatorTable.h"
 
 namespace ast {
+
+const Type * getPointerBase( const Type * t ) {
+	if ( const auto * p = dynamic_cast< const PointerType * >( t ) ) {
+		return p->base;
+	} else if ( const auto * a = dynamic_cast< const ArrayType * >( t ) ) {
+		return a->base;
+	} else if ( const auto * r = dynamic_cast< const ReferenceType * >( t ) ) {
+		return r->base;
+	} else {
+		return nullptr;
+	}
+}
+
+template<typename CallExpr>
+static const Expr * callArg( const CallExpr * call, unsigned int pos ) {
+	assertf( pos < call->args.size(),
+		"getCallArg for argument that doesn't exist: (%u); %s.",
+		pos, toString( call ).c_str() );
+	for ( const Expr * arg : call->args ) {
+		if ( 0 == pos ) return arg;
+		--pos;
+	}
+	assert( false );
+}
+
+template<typename CallExpr, typename Ret>
+static Ret throughDeref( const CallExpr * expr, Ret(*func)( const Expr * ) ) {
+	// In `(*f)(x)` the function we want is `f`.
+	std::string name = getFunctionName( expr );
+	assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() );
+	assertf( !expr->args.empty(), "Cannot get function name from dereference with no arguments" );
+	return func( expr->args.front() );
+}
+
+static const DeclWithType * getCalledFunction( const Expr * expr ) {
+	assert( expr );
+	if ( const ast::VariableExpr * varExpr = dynamic_cast< const ast::VariableExpr * >( expr ) ) {
+		return varExpr->var;
+	} else if ( const ast::MemberExpr * memberExpr = dynamic_cast< const ast::MemberExpr * >( expr ) ) {
+		return memberExpr->member;
+	} else if ( const ast::CastExpr * castExpr = dynamic_cast< const ast::CastExpr * >( expr ) ) {
+		return getCalledFunction( castExpr->arg );
+	} else if ( const ast::UntypedExpr * untypedExpr = dynamic_cast< const ast::UntypedExpr * >( expr ) ) {
+		return throughDeref( untypedExpr, getCalledFunction );
+	} else if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * > ( expr ) ) {
+		return throughDeref( appExpr, getCalledFunction );
+	} else if ( const ast::AddressExpr * addrExpr = dynamic_cast< const ast::AddressExpr * >( expr ) ) {
+		return getCalledFunction( addrExpr->arg );
+	} else if ( const ast::CommaExpr * commaExpr = dynamic_cast< const ast::CommaExpr * >( expr ) ) {
+		return getCalledFunction( commaExpr->arg2 );
+	}
+	return nullptr;
+}
+
+const DeclWithType * getFunction( const Expr * expr ) {
+	if ( auto app = dynamic_cast< const ApplicationExpr * >( expr ) ) {
+		return getCalledFunction( app->func );
+	} else if ( auto untyped = dynamic_cast< const UntypedExpr * >( expr ) ) {
+		return getCalledFunction( untyped->func );
+	}
+	assertf( false, "getFunction received unknown expression: %s", toString( expr ).c_str() );
+}
+
+// There is a lot of overlap with getCalledFunction. Ideally it would use
+// it as a helper function and return the name of the DeclWithType. But the
+// NameExpr and UntypedMemberExpr only work on this version.
+static std::string funcName( const Expr * func ) {
+	assert( func );
+	if ( const ast::NameExpr * nameExpr = dynamic_cast< const ast::NameExpr * >( func ) ) {
+		return nameExpr->name;
+	} else if ( const ast::VariableExpr * varExpr = dynamic_cast< const ast::VariableExpr * >( func ) ) {
+		return varExpr->var->name;
+	} else if ( const ast::CastExpr * castExpr = dynamic_cast< const ast::CastExpr * >( func ) ) {
+		return funcName( castExpr->arg );
+	} else if ( const ast::MemberExpr * memberExpr = dynamic_cast< const ast::MemberExpr * >( func ) ) {
+		return memberExpr->member->name;
+	} else if ( const ast::UntypedMemberExpr * memberExpr = dynamic_cast< const ast::UntypedMemberExpr * > ( func ) ) {
+		return funcName( memberExpr->member );
+	} else if ( const ast::UntypedExpr * untypedExpr = dynamic_cast< const ast::UntypedExpr * >( func ) ) {
+		return throughDeref( untypedExpr, funcName );
+	} else if ( const ast::ApplicationExpr * appExpr = dynamic_cast< const ast::ApplicationExpr * >( func ) ) {
+		return throughDeref( appExpr, funcName );
+	} else if ( const ast::ConstructorExpr * ctorExpr = dynamic_cast< const ast::ConstructorExpr * >( func ) ) {
+		return funcName( getCallArg( ctorExpr->callExpr, 0 ) );
+	} else {
+		assertf( false, "Unexpected expression type being called as a function in call expression: %s", toString( func ).c_str() );
+	}
+}
+
+std::string getFunctionName( const Expr * expr ) {
+	// There's some unforunate overlap here with getCalledFunction. Ideally
+	// this would be able to use getCalledFunction and return the name of the
+	// DeclWithType, but this needs to work for NameExpr and UntypedMemberExpr,
+	// where getCalledFunction can't possibly do anything reasonable.
+	if ( auto app = dynamic_cast< const ApplicationExpr * >( expr ) ) {
+		return funcName( app->func );
+	} else if ( auto untyped = dynamic_cast< const UntypedExpr * >( expr ) ) {
+		return funcName( untyped->func );
+	} else {
+		assertf( false, "Unexpected expression type passed to getFunctionName: %s", toString( expr ).c_str() );
+	}
+}
+
+const Expr * getCallArg( const Expr * call, unsigned int pos ) {
+	if ( auto app = dynamic_cast< const ApplicationExpr * >( call ) ) {
+		return callArg( app, pos );
+	} else if ( auto untyped = dynamic_cast< const UntypedExpr * >( call ) ) {
+		return callArg( untyped, pos );
+	} else if ( auto tupleAssn = dynamic_cast< const TupleAssignExpr * >( call ) ) {
+		const std::list<ptr<Stmt>>& stmts = tupleAssn->stmtExpr->stmts->kids;
+		assertf( !stmts.empty(), "TupleAssignExpr missing statements." );
+		auto stmt  = strict_dynamic_cast< const ExprStmt * >( stmts.back().get() );
+		auto tuple = strict_dynamic_cast< const TupleExpr * >( stmt->expr.get() );
+		assertf( !tuple->exprs.empty(), "TupleAssignExpr has empty tuple expr." );
+		return getCallArg( tuple->exprs.front(), pos );
+	} else if ( auto ctor = dynamic_cast< const ImplicitCopyCtorExpr * >( call ) ) {
+		return getCallArg( ctor->callExpr, pos );
+	} else {
+		assertf( false, "Unexpected expression type passed to getCallArg: %s",
+			toString( call ).c_str() );
+	}
+}
 
 bool structHasFlexibleArray( const ast::StructDecl * decl ) {
@@ -33,3 +160,14 @@
 }
 
+const ApplicationExpr * isIntrinsicCallExpr( const Expr * expr ) {
+	auto appExpr = dynamic_cast< const ApplicationExpr * >( expr );
+	if ( !appExpr ) return nullptr;
+
+	const DeclWithType * func = getCalledFunction( appExpr->func );
+	assertf( func,
+		"getCalledFunction returned nullptr: %s", toString( appExpr->func ).c_str() );
+
+	return func->linkage == ast::Linkage::Intrinsic ? appExpr : nullptr;
+}
+
 } // namespace ast
Index: src/AST/Inspect.hpp
===================================================================
--- src/AST/Inspect.hpp	(revision 20737104831e8e78cbe01e2e63a3969afaec6c88)
+++ src/AST/Inspect.hpp	(revision e01eb4aa19bfce233e01f84a77d45064842e6ebf)
@@ -10,6 +10,6 @@
 // Created On       : Fri Jun 24 13:16:31 2022
 // Last Modified By : Andrew Beach
-// Last Modified On : Mon Jun 27 15:35:00 2022
-// Update Count     : 1
+// Last Modified On : Thr Sep 22 13:44:00 2022
+// Update Count     : 2
 //
 
@@ -18,6 +18,23 @@
 namespace ast {
 
-// Does the structure end in a flexable array declaration?
-bool structHasFlexibleArray( const ast::StructDecl * );
+/// Returns the base type of an pointer/array/reference type,
+/// if the argument is not one of those types, return null.
+const Type * getPointerBase( const Type * );
+
+/// Get the declaration of the function called (ApplicationExpr or UntypedExpr).
+const DeclWithType * getFunction( const Expr * expr );
+
+/// Get the name of the function being called.
+std::string getFunctionName( const Expr * expr );
+
+/// Returns the argument to a call expression in position N, indexed from 0.
+const Expr * getCallArg( const Expr * call, unsigned pos );
+
+/// Does the structure end in a flexable array declaration?
+bool structHasFlexibleArray( const StructDecl * );
+
+/// If the expression is an application whose target function is an
+/// intrinsic, then returns a pointer to that application.
+const ApplicationExpr * isIntrinsicCallExpr( const Expr * expr );
 
 }
Index: src/AST/SymbolTable.cpp
===================================================================
--- src/AST/SymbolTable.cpp	(revision 20737104831e8e78cbe01e2e63a3969afaec6c88)
+++ src/AST/SymbolTable.cpp	(revision e01eb4aa19bfce233e01f84a77d45064842e6ebf)
@@ -20,4 +20,5 @@
 #include "Decl.hpp"
 #include "Expr.hpp"
+#include "Inspect.hpp"
 #include "Type.hpp"
 #include "CodeGen/OperatorTable.h"  // for isCtorDtorAssign
@@ -466,5 +467,5 @@
 		assert( ! params.empty() );
 		// use base type of pointer, so that qualifiers on the pointer type aren't considered.
-		const Type * base = InitTweak::getPointerBase( params.front() );
+		const Type * base = ast::getPointerBase( params.front() );
 		assert( base );
 		if (stripParams) {
Index: src/AST/Type.cpp
===================================================================
--- src/AST/Type.cpp	(revision 20737104831e8e78cbe01e2e63a3969afaec6c88)
+++ src/AST/Type.cpp	(revision e01eb4aa19bfce233e01f84a77d45064842e6ebf)
@@ -22,6 +22,6 @@
 #include "Decl.hpp"
 #include "Init.hpp"
+#include "Inspect.hpp"
 #include "Common/utility.h"      // for copy, move
-#include "InitTweak/InitTweak.h" // for getPointerBase
 #include "Tuples/Tuples.h"       // for isTtype
 
@@ -36,5 +36,5 @@
 	const Type * t;
 	const Type * a;
-	for ( t = this; (a = InitTweak::getPointerBase( t )); t = a );
+	for ( t = this; (a = ast::getPointerBase( t )); t = a );
 	return t;
 }
