Index: common/include/adt/gcdlcm.h
===================================================================
--- common/include/adt/gcdlcm.h	(revision f9c4c43357bfb943298ed524857f234914ca8409)
+++ common/include/adt/gcdlcm.h	(revision 283bb9f64f2d4e4e355cbc07e6be918c77e2aead)
@@ -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; \
 	}
 
