program main
    implicit none
    integer K, ans, a, b, c
    ans = 0
    read (*, *) K
    do a = 1, K
        do b = 1, K
            do c = 1, K
                ans = ans + gcd(a, gcd(b, c))
            end do
        end do
    end do
    write(*, '(I0)') ans
    stop
contains
    recursive integer function gcd(x, y) result(ret)
        implicit none
        integer x, y
        if (y == 0) then
            ret = x
        else
            ret = gcd(y, mod(x, y))
        end if
        return
    end function
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.9cf10b332344dafb412b8fde39712047 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1802/source.f\00"
@_QQcl.28493029 = linkonce constant [4 x i8] c"(I0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9cf10b332344dafb412b8fde39712047, i32 5)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %5, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %9 = load i32, ptr %5, align 4, !tbaa !3
  %10 = sext i32 %9 to i64
  %11 = icmp sgt i32 %9, 0
  br i1 %11, label %.lr.ph11.us.us, label %._crit_edge

.lr.ph11.us.us:                                   ; preds = %0, %._crit_edge12.split.us.us.us
  %12 = phi i64 [ %29, %._crit_edge12.split.us.us.us ], [ %10, %0 ]
  %13 = phi i32 [ %28, %._crit_edge12.split.us.us.us ], [ 1, %0 ]
  %.016.us.us = phi i32 [ %21, %._crit_edge12.split.us.us.us ], [ 0, %0 ]
  store i32 %13, ptr %2, align 4, !tbaa !3
  br label %.lr.ph.us.us.us

.lr.ph.us.us.us:                                  ; preds = %._crit_edge.us.us.us, %.lr.ph11.us.us
  %14 = phi i64 [ %10, %.lr.ph11.us.us ], [ %26, %._crit_edge.us.us.us ]
  %15 = phi i32 [ 1, %.lr.ph11.us.us ], [ %25, %._crit_edge.us.us.us ]
  %.19.us.us.us = phi i32 [ %.016.us.us, %.lr.ph11.us.us ], [ %21, %._crit_edge.us.us.us ]
  store i32 %15, ptr %3, align 4, !tbaa !3
  br label %16

16:                                               ; preds = %16, %.lr.ph.us.us.us
  %17 = phi i64 [ %10, %.lr.ph.us.us.us ], [ %23, %16 ]
  %18 = phi i32 [ 1, %.lr.ph.us.us.us ], [ %22, %16 ]
  %.27.us.us.us = phi i32 [ %.19.us.us.us, %.lr.ph.us.us.us ], [ %21, %16 ]
  store i32 %18, ptr %4, align 4, !tbaa !3
  %19 = call i32 @_QFPgcd(ptr nonnull %3, ptr nonnull %4)
  store i32 %19, ptr %1, align 4, !tbaa !3
  %20 = call i32 @_QFPgcd(ptr nonnull %2, ptr nonnull %1)
  %21 = add i32 %20, %.27.us.us.us
  %22 = add nuw i32 %18, 1
  %23 = add nsw i64 %17, -1
  %24 = icmp sgt i64 %17, 1
  br i1 %24, label %16, label %._crit_edge.us.us.us

._crit_edge.us.us.us:                             ; preds = %16
  store i32 %22, ptr %4, align 4, !tbaa !3
  %25 = add nuw i32 %15, 1
  %26 = add nsw i64 %14, -1
  %27 = icmp sgt i64 %14, 1
  br i1 %27, label %.lr.ph.us.us.us, label %._crit_edge12.split.us.us.us

._crit_edge12.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  store i32 %25, ptr %3, align 4, !tbaa !3
  %28 = add nuw i32 %13, 1
  %29 = add nsw i64 %12, -1
  %30 = icmp sgt i64 %12, 1
  br i1 %30, label %.lr.ph11.us.us, label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge12.split.us.us.us, %0
  %.0.lcssa = phi i32 [ 0, %0 ], [ %21, %._crit_edge12.split.us.us.us ]
  %31 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28493029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.9cf10b332344dafb412b8fde39712047, i32 13)
  %32 = call i1 @_FortranAioOutputInteger32(ptr %31, i32 %.0.lcssa)
  %33 = call i32 @_FortranAioEndIoStatement(ptr %31)
  %34 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

; Function Attrs: nofree nosync nounwind memory(argmem: read)
define i32 @_QFPgcd(ptr nocapture readonly %0, ptr nocapture readonly %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = load i32, ptr %1, align 4, !tbaa !3
  %5 = icmp eq i32 %4, 0
  %6 = load i32, ptr %0, align 4, !tbaa !3
  br i1 %5, label %10, label %7

7:                                                ; preds = %2
  %8 = srem i32 %6, %4
  store i32 %8, ptr %3, align 4, !tbaa !3
  %9 = call i32 @_QFPgcd(ptr nonnull %1, ptr nonnull %3)
  br label %10

10:                                               ; preds = %2, %7
  %.0 = phi i32 [ %9, %7 ], [ %6, %2 ]
  ret i32 %.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 @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

attributes #0 = { noreturn }
attributes #1 = { nofree 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"}
