#include "gc.h"

#include "tree.h"
#include "dict.h"
#include "match.h"
#include "optimize.h"

/*
 * We recursively iterate through all
 * rules on all the children of the tree
 * until the expression is irreducible,
 * i.e. stops changing.
 *
 * Also, we (try to) apply the optimization
 * routine.
 */

int apply_rules_and_optimize(exp_tree_t** rules, int rc, exp_tree_t *tree)
{
	int success = 0;
	while (1) {
		if (matchloop(rules, rc, tree)) {
			/*
			 * Reduction algorithm
			 * suceeded, print reduced tree
			 */
			#ifdef DEBUG_2
				printout_tree(*tree);
				printf("\n");
			#endif
			#ifdef DEBUG
				printout_tree_infix(*tree);
				printf("\n");
			#endif
			success = 1;
		}

		/*
		 * If optimization succeeds in
		 * modifying the tree, try
		 * reducing the new optimized
		 * tree.
		 */
		if (optimize(tree)) {
			#ifdef DEBUG
				printf("[optimize] \n");
				#ifdef DEBUG_2
					printout_tree(*tree);
					printf("\n");
				#endif
				printout_tree_infix(*tree);
				printf("\n");
			#endif
			success = 1;
			continue;
		}
		break;
	}
	return success;
}

#include "gc.h"

#include "tree.h"
#include "dict.h"
#include "match.h"
#include "optimize.h"

/* We recursively iterate through all 
 * rules on all the children of the tree
 * until the expression is irreducible, 
 * i.e. stops changing.
 * 
 * Also, we (try to) apply the optimization
 * routine.
 */

int apply_rules_and_optimize(exp_tree_t** rules, int rc, exp_tree_t *tree)
{
	int success = 0;
	while (1) {
		if (matchloop(rules, rc, tree)) {
			/*
			 * Reduction algorithm
			 * suceeded, print reduced tree
			 */
#ifdef DEBUG_2
			printout_tree(*tree);
			printf("\n");
#endif
#ifdef DEBUG
			printout_tree_infix(*tree);
			printf("\n");
#endif
			success = 1;
		}

		/*
		 * If optimization succeeds in
		 * modifying the tree, try
		 * reducing the new optimized
		 * tree.
		 */
		if (optimize(tree)) {
#ifdef DEBUG
			printf("[optimize] \n");
#ifdef DEBUG_2
			printout_tree(*tree);
			printf("\n");
#endif
			printout_tree_infix(*tree);
			printf("\n");
#endif
			success = 1;
			continue;
		}
		break;
	}
	return success;
}

--- 
+++ 
@@ -5,11 +5,12 @@
 #include "match.h"
 #include "optimize.h"
 
-/* We recursively iterate through all 
+/*
+ * We recursively iterate through all
  * rules on all the children of the tree
- * until the expression is irreducible, 
+ * until the expression is irreducible,
  * i.e. stops changing.
- * 
+ *
  * Also, we (try to) apply the optimization
  * routine.
  */
@@ -23,14 +24,14 @@
 			 * Reduction algorithm
 			 * suceeded, print reduced tree
 			 */
-#ifdef DEBUG_2
-			printout_tree(*tree);
-			printf("\n");
-#endif
-#ifdef DEBUG
-			printout_tree_infix(*tree);
-			printf("\n");
-#endif
+			#ifdef DEBUG_2
+				printout_tree(*tree);
+				printf("\n");
+			#endif
+			#ifdef DEBUG
+				printout_tree_infix(*tree);
+				printf("\n");
+			#endif
 			success = 1;
 		}
 
@@ -41,15 +42,15 @@
 		 * tree.
 		 */
 		if (optimize(tree)) {
-#ifdef DEBUG
-			printf("[optimize] \n");
-#ifdef DEBUG_2
-			printout_tree(*tree);
-			printf("\n");
-#endif
-			printout_tree_infix(*tree);
-			printf("\n");
-#endif
+			#ifdef DEBUG
+				printf("[optimize] \n");
+				#ifdef DEBUG_2
+					printout_tree(*tree);
+					printf("\n");
+				#endif
+				printout_tree_infix(*tree);
+				printf("\n");
+			#endif
 			success = 1;
 			continue;
 		}
Change indent and comments to a more readable style
