program main
      implicit none
      integer(4) :: k, a, b, mab, c, mabc
      integer(8) :: cnt

      read *, k
      cnt = 0
      do a = 1, k
        do b = 1, k
          do c = 1, k
            call gcd(a,b,mab)
            call gcd(mab, c, mabc)
            cnt = cnt + mabc
          end do
        end do
      end do
      print *, cnt

      contains

      subroutine gcd(m,n,j)
        implicit none
        integer, intent(in) :: m, n
        integer, intent(out) :: j
        integer :: i, l, x, y

        x = m
        y = n
        do 
          l = mod(x,y)
          if ( l == 0 ) exit
          x = y
          y = l
        end do
        j = y

      end subroutine gcd

end program main

; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QQcl.6eefffe81ea04613198f93ae37220a3c = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1805/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.6eefffe81ea04613198f93ae37220a3c, i32 6)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 4)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i32, ptr %1, align 4, !tbaa !3
  %6 = sext i32 %5 to i64
  %7 = icmp sgt i32 %5, 0
  br i1 %7, label %.preheader16.us.us, label %._crit_edge

.preheader16.us.us:                               ; preds = %0, %._crit_edge19.split.us.us.us
  %8 = phi i64 [ %28, %._crit_edge19.split.us.us.us ], [ %6, %0 ]
  %9 = phi i32 [ %27, %._crit_edge19.split.us.us.us ], [ 1, %0 ]
  %.021.us.us = phi i64 [ %18, %._crit_edge19.split.us.us.us ], [ 0, %0 ]
  br label %.preheader15.us.us.us

.preheader15.us.us.us:                            ; preds = %._crit_edge.us.us.us, %.preheader16.us.us
  %10 = phi i64 [ %6, %.preheader16.us.us ], [ %25, %._crit_edge.us.us.us ]
  %11 = phi i32 [ 1, %.preheader16.us.us ], [ %24, %._crit_edge.us.us.us ]
  %.118.us.us.us = phi i64 [ %.021.us.us, %.preheader16.us.us ], [ %18, %._crit_edge.us.us.us ]
  br label %.preheader.us.us.us

12:                                               ; preds = %.preheader.us.us.us, %12
  %.06.i.us.us.us = phi i32 [ %.0.i.us.us.us, %12 ], [ %9, %.preheader.us.us.us ]
  %.0.i.us.us.us = phi i32 [ %13, %12 ], [ %11, %.preheader.us.us.us ]
  %13 = srem i32 %.06.i.us.us.us, %.0.i.us.us.us
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %_QFPgcd.exit.us.us.us, label %12

_QFPgcd.exit.us.us.us:                            ; preds = %12, %_QFPgcd.exit.us.us.us
  %.06.i5.us.us.us = phi i32 [ %.0.i6.us.us.us, %_QFPgcd.exit.us.us.us ], [ %.0.i.us.us.us, %12 ]
  %.0.i6.us.us.us = phi i32 [ %15, %_QFPgcd.exit.us.us.us ], [ %23, %12 ]
  %15 = srem i32 %.06.i5.us.us.us, %.0.i6.us.us.us
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %_QFPgcd.exit7.us.us.us, label %_QFPgcd.exit.us.us.us

_QFPgcd.exit7.us.us.us:                           ; preds = %_QFPgcd.exit.us.us.us
  %17 = sext i32 %.0.i6.us.us.us to i64
  %18 = add i64 %.217.us.us.us, %17
  %19 = add nuw i32 %23, 1
  %20 = add nsw i64 %22, -1
  %21 = icmp sgt i64 %22, 1
  br i1 %21, label %.preheader.us.us.us, label %._crit_edge.us.us.us

.preheader.us.us.us:                              ; preds = %_QFPgcd.exit7.us.us.us, %.preheader15.us.us.us
  %22 = phi i64 [ %6, %.preheader15.us.us.us ], [ %20, %_QFPgcd.exit7.us.us.us ]
  %23 = phi i32 [ 1, %.preheader15.us.us.us ], [ %19, %_QFPgcd.exit7.us.us.us ]
  %.217.us.us.us = phi i64 [ %.118.us.us.us, %.preheader15.us.us.us ], [ %18, %_QFPgcd.exit7.us.us.us ]
  br label %12

._crit_edge.us.us.us:                             ; preds = %_QFPgcd.exit7.us.us.us
  %24 = add nuw i32 %11, 1
  %25 = add nsw i64 %10, -1
  %26 = icmp sgt i64 %10, 1
  br i1 %26, label %.preheader15.us.us.us, label %._crit_edge19.split.us.us.us

._crit_edge19.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %27 = add nuw i32 %9, 1
  %28 = add nsw i64 %8, -1
  %29 = icmp sgt i64 %8, 1
  br i1 %29, label %.preheader16.us.us, label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge19.split.us.us.us, %0
  %.0.lcssa = phi i64 [ 0, %0 ], [ %18, %._crit_edge19.split.us.us.us ]
  %30 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.6eefffe81ea04613198f93ae37220a3c, i32 17)
  %31 = call i1 @_FortranAioOutputInteger64(ptr %30, i64 %.0.lcssa)
  %32 = call i32 @_FortranAioEndIoStatement(ptr %30)
  ret void
}

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite)
define void @_QFPgcd(ptr nocapture readonly %0, ptr nocapture readonly %1, ptr nocapture writeonly %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %0, align 4, !tbaa !3
  %5 = load i32, ptr %1, align 4, !tbaa !3
  br label %6

6:                                                ; preds = %6, %3
  %.06 = phi i32 [ %4, %3 ], [ %.0, %6 ]
  %.0 = phi i32 [ %5, %3 ], [ %7, %6 ]
  %7 = srem i32 %.06, %.0
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %6

9:                                                ; preds = %6
  store i32 %.0, ptr %2, align 4, !tbaa !3
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
