Index: common/include/adt/gcdlcm.h
===================================================================
--- common/include/adt/gcdlcm.h	(revision 1db4e2ae125c1e44cf798e9a321ba480b184b645)
+++ common/include/adt/gcdlcm.h	(revision c111da2e5d8d220f8936c4d80df74d461f2e0866)
@@ -42,12 +42,8 @@
 	static inline type name(type a, type b) \
 	{ \
-		if (a == 0) \
-			return b; \
-		 \
 		while (b != 0) { \
-			if (a > b) \
-				a -= b; \
-			else \
-				b -= a; \
+			type remainder = a % b; \
+			a = b; \
+			b = remainder; \
 		} \
 		 \
@@ -58,5 +54,5 @@
 	static inline type name(type a, type b) \
 	{ \
-		return (a * b) / gcd(a, b); \
+		return (a / gcd(a, b)) * b; \
 	}
 
