program test
implicit none
integer(8) :: i,j,k,a,b,c,ans=0

read(*,*) k

do a=1,k
  do b=1,k
    do c=1,k
      ans = ans + gcd(gcd(a,b),c)
    enddo
  enddo
enddo

write(*,*) ans

contains
integer(8) function gcd(a,b)
  implicit none
  integer(8), intent(in) :: a,b
  integer(8) :: l,m,n

  m = a
  n = b

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

  gcd = n

  return
end function gcd

end program
; 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"

@_QFEans = internal unnamed_addr global i64 0
@_QQcl.cf88feee9cb411fcc8011b0fb6b17124 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1797/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

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

.preheader12.us.us.preheader:                     ; preds = %0
  %_QFEans.promoted = load i64, ptr @_QFEans, align 8, !tbaa !3
  br label %.preheader12.us.us

.preheader12.us.us:                               ; preds = %.preheader12.us.us.preheader, %._crit_edge17.split.us.us.us
  %7 = phi i64 [ %20, %._crit_edge17.split.us.us.us ], [ 1, %.preheader12.us.us.preheader ]
  %.lcssa.us.lcssa2021.us.us = phi i64 [ %17, %._crit_edge17.split.us.us.us ], [ %_QFEans.promoted, %.preheader12.us.us.preheader ]
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader12.us.us
  %8 = phi i64 [ 1, %.preheader12.us.us ], [ %19, %._crit_edge.us.us.us ]
  %.lcssa1516.us.us.us = phi i64 [ %.lcssa.us.lcssa2021.us.us, %.preheader12.us.us ], [ %17, %._crit_edge.us.us.us ]
  br label %9

9:                                                ; preds = %_QFPgcd.exit5.us.us.us, %.preheader.us.us.us
  %10 = phi i64 [ 1, %.preheader.us.us.us ], [ %18, %_QFPgcd.exit5.us.us.us ]
  %11 = phi i64 [ %.lcssa1516.us.us.us, %.preheader.us.us.us ], [ %17, %_QFPgcd.exit5.us.us.us ]
  br label %12

12:                                               ; preds = %12, %9
  %.07.i.us.us.us = phi i64 [ %7, %9 ], [ %.0.i.us.us.us, %12 ]
  %.0.i.us.us.us = phi i64 [ %8, %9 ], [ %13, %12 ]
  %13 = srem i64 %.07.i.us.us.us, %.0.i.us.us.us
  %14 = icmp eq i64 %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
  %.07.i3.us.us.us = phi i64 [ %.0.i4.us.us.us, %_QFPgcd.exit.us.us.us ], [ %.0.i.us.us.us, %12 ]
  %.0.i4.us.us.us = phi i64 [ %15, %_QFPgcd.exit.us.us.us ], [ %10, %12 ]
  %15 = srem i64 %.07.i3.us.us.us, %.0.i4.us.us.us
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %_QFPgcd.exit5.us.us.us, label %_QFPgcd.exit.us.us.us

_QFPgcd.exit5.us.us.us:                           ; preds = %_QFPgcd.exit.us.us.us
  %17 = add i64 %.0.i4.us.us.us, %11
  %18 = add nuw i64 %10, 1
  %exitcond.not = icmp eq i64 %10, %5
  br i1 %exitcond.not, label %._crit_edge.us.us.us, label %9

._crit_edge.us.us.us:                             ; preds = %_QFPgcd.exit5.us.us.us
  %19 = add nuw i64 %8, 1
  %exitcond25.not = icmp eq i64 %8, %5
  br i1 %exitcond25.not, label %._crit_edge17.split.us.us.us, label %.preheader.us.us.us

._crit_edge17.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %20 = add nuw i64 %7, 1
  %exitcond26.not = icmp eq i64 %7, %5
  br i1 %exitcond26.not, label %._crit_edge.split.us.split.us, label %.preheader12.us.us

._crit_edge.split.us.split.us:                    ; preds = %._crit_edge17.split.us.us.us
  store i64 %17, ptr @_QFEans, align 8, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.split.us.split.us, %0
  %21 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.cf88feee9cb411fcc8011b0fb6b17124, i32 15)
  %22 = load i64, ptr @_QFEans, align 8, !tbaa !3
  %23 = call i1 @_FortranAioOutputInteger64(ptr %21, i64 %22)
  %24 = call i32 @_FortranAioEndIoStatement(ptr %21)
  ret void
}

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read)
define i64 @_QFPgcd(ptr nocapture readonly %0, ptr nocapture readonly %1) local_unnamed_addr #0 {
  %3 = load i64, ptr %0, align 8, !tbaa !3
  %4 = load i64, ptr %1, align 8, !tbaa !3
  br label %5

5:                                                ; preds = %5, %2
  %.07 = phi i64 [ %3, %2 ], [ %.0, %5 ]
  %.0 = phi i64 [ %4, %2 ], [ %6, %5 ]
  %6 = srem i64 %.07, %.0
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %8, label %5

8:                                                ; preds = %5
  ret i64 %.0
}

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: read) }

!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"}
