Index: src/AST/Decl.cpp
===================================================================
--- src/AST/Decl.cpp	(revision a1da039d49b92f720bc279fc8e82273197880e11)
+++ src/AST/Decl.cpp	(revision bef4f1a7c08805c9e325222c0cbf3d9df27ef61e)
@@ -20,4 +20,5 @@
 #include <unordered_map>
 
+#include "CodeGen/FixMain.h"   // for FixMain
 #include "Common/Eval.h"       // for eval
 
@@ -75,4 +76,10 @@
 	}
 	this->type = ftype;
+	// Hack forcing the function "main" to have Cforall linkage to replace
+	// main even if it is inside an extern "C", and also makes sure the
+	// replacing function is always a C function.
+	if ( name == "main" ) {
+		this->linkage = CodeGen::FixMain::getMainLinkage();
+	}
 }
 
@@ -101,4 +108,8 @@
 	}
 	this->type = type;
+	// See note above about this hack.
+	if ( name == "main" ) {
+		this->linkage = CodeGen::FixMain::getMainLinkage();
+	}
 }
 
