program XYZTriplets
    implicit none
    
    integer(4) :: n
    integer(4), allocatable :: cnt(:)

    integer(4) :: m, l
    integer(4) :: i, j, k
    read(*, *) n

    m = nint(sqrt(float(n-4)))
    allocate(cnt(1:n))

    cnt(1:n) = 0

    do i = 1, m+1
        do j = 1, m+1
            do k = 1, m+1
                l = i**2 + j**2 + k**2 + i*j + j*k + k*i
                if (l > n) then
                    exit
                end if
                cnt(l) = cnt(l) + 1
            end do
        end do
    end do

    do i = 1, n
        write(*, *) cnt(i)
    end do

    stop

end program XYZTriplets

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

@_QFEcnt.0 = internal unnamed_addr global ptr null
@_QQcl.da86c1cabd4f564469b85bbad41a64bb = linkonce constant [72 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_953/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.da86c1cabd4f564469b85bbad41a64bb, i32 9)
  %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 = add i32 %5, -4
  %7 = sitofp i32 %6 to float
  %8 = call contract float @llvm.sqrt.f32(float %7)
  %9 = call i32 @llvm.lround.i32.f32(float %8)
  %10 = call i32 @llvm.smax.i32(i32 %5, i32 0)
  %11 = zext i32 %10 to i64
  %12 = shl nuw nsw i64 %11, 2
  %13 = call ptr @malloc(i64 %12)
  store ptr %13, ptr @_QFEcnt.0, align 8, !tbaa !7
  %.not = icmp slt i32 %5, 1
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %14 = call i64 @llvm.smax.i64(i64 %11, i64 1)
  %15 = shl nuw nsw i64 %14, 2
  call void @llvm.memset.p0.i64(ptr align 4 %13, i8 0, i64 %15, i1 false), !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %0
  %16 = add i32 %9, 1
  %17 = icmp ult i32 %9, 2147483647
  br i1 %17, label %.preheader129.lr.ph, label %._crit_edge141

.preheader129.lr.ph:                              ; preds = %._crit_edge
  %18 = add nuw i32 %9, 2
  %smin151 = call i32 @llvm.smin.i32(i32 %9, i32 0)
  %19 = sub nuw nsw i32 %18, %smin151
  br label %.preheader129.us.us

.preheader129.us.us:                              ; preds = %.preheader129.lr.ph, %._crit_edge137.split.us.us.us
  %.089139.us.us = phi i32 [ %35, %._crit_edge137.split.us.us.us ], [ 1, %.preheader129.lr.ph ]
  %20 = mul i32 %.089139.us.us, %.089139.us.us
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge133.us.us.us, %.preheader129.us.us
  %.088135.us.us.us = phi i32 [ 1, %.preheader129.us.us ], [ %34, %._crit_edge133.us.us.us ]
  %reass.add.us.us.us = add i32 %.088135.us.us.us, %.089139.us.us
  %reass.mul128.us.us.us = mul i32 %reass.add.us.us.us, %.088135.us.us.us
  %21 = add i32 %reass.mul128.us.us.us, %20
  br label %22

22:                                               ; preds = %26, %.preheader.us.us.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %26 ], [ 1, %.preheader.us.us.us ]
  %.0131.us.us.us = phi i32 [ %32, %26 ], [ %16, %.preheader.us.us.us ]
  %23 = trunc i64 %indvars.iv to i32
  %reass.add126.us.us.us = add i32 %reass.add.us.us.us, %23
  %reass.mul.us.us.us = mul i32 %reass.add126.us.us.us, %23
  %24 = add i32 %21, %reass.mul.us.us.us
  %25 = icmp sgt i32 %24, %5
  br i1 %25, label %._crit_edge133.us.us.us, label %26

26:                                               ; preds = %22
  %27 = sext i32 %24 to i64
  %28 = add nsw i64 %27, -1
  %29 = getelementptr i32, ptr %13, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !3
  %31 = add i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !3
  %32 = add nsw i32 %.0131.us.us.us, -1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = icmp sgt i32 %.0131.us.us.us, 1
  br i1 %33, label %22, label %._crit_edge133.us.us.us

._crit_edge133.us.us.us:                          ; preds = %26, %22
  %34 = add nuw i32 %.088135.us.us.us, 1
  %exitcond.not = icmp eq i32 %34, %19
  br i1 %exitcond.not, label %._crit_edge137.split.us.us.us, label %.preheader.us.us.us

._crit_edge137.split.us.us.us:                    ; preds = %._crit_edge133.us.us.us
  %35 = add nuw i32 %.089139.us.us, 1
  %exitcond152.not = icmp eq i32 %35, %19
  br i1 %exitcond152.not, label %._crit_edge141, label %.preheader129.us.us

._crit_edge141:                                   ; preds = %._crit_edge137.split.us.us.us, %._crit_edge
  %36 = icmp sgt i32 %5, 0
  br i1 %36, label %.lr.ph148.preheader, label %._crit_edge149

.lr.ph148.preheader:                              ; preds = %._crit_edge141
  %37 = zext i32 %5 to i64
  br label %.lr.ph148

.lr.ph148:                                        ; preds = %.lr.ph148.preheader, %.lr.ph148
  %indvars.iv153 = phi i64 [ 1, %.lr.ph148.preheader ], [ %indvars.iv.next154, %.lr.ph148 ]
  %38 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.da86c1cabd4f564469b85bbad41a64bb, i32 29)
  %.unpack = load ptr, ptr @_QFEcnt.0, align 8, !tbaa !7
  %39 = add nsw i64 %indvars.iv153, -1
  %40 = getelementptr i32, ptr %.unpack, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !3
  %42 = call i1 @_FortranAioOutputInteger32(ptr %38, i32 %41)
  %43 = call i32 @_FortranAioEndIoStatement(ptr %38)
  %indvars.iv.next154 = add nuw nsw i64 %indvars.iv153, 1
  %exitcond156.not = icmp eq i64 %indvars.iv153, %37
  br i1 %exitcond156.not, label %._crit_edge149, label %.lr.ph148

._crit_edge149:                                   ; preds = %.lr.ph148, %._crit_edge141
  %44 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.lround.i32.f32(float) #2

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

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.sqrt.f32(float) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { noreturn }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
