program sample
    implicit none
  
    integer(8) :: i,j,k,m,n,x,y
    real(8)::b
    integer(8),allocatable :: a(:)
  
    read(*,*) n
    allocate(a(n))
    read(*,*)a
    k=sum(a)/n
    m=k+1
    x=0
    y=0
    do i=1,n
        x=x+(a(i)-k)**2
        y=y+(a(i)-m)**2
        
    end do
    if (x<=y)then
        write(*,*) x
    
    else
        write(*,*) y
    end if
  

    deallocate(a)
    stop
end program sample
  


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

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QQcl.b5e40fd695a394ff8e319740483dfdea = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2348/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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #2 {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i64, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.b5e40fd695a394ff8e319740483dfdea, i32 8)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 8)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i64, ptr %2, align 8, !tbaa !3
  %7 = call i64 @llvm.smax.i64(i64 %6, i64 0)
  %8 = shl i64 %7, 3
  %9 = call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %7, ptr @_QFEa.8, align 8, !tbaa !7
  %10 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.b5e40fd695a394ff8e319740483dfdea, i32 10)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack245.unpack.unpack247 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack245.unpack.unpack247, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %11 = call i1 @_FortranAioInputDescriptor(ptr %10, ptr nonnull %1)
  %12 = call i32 @_FortranAioEndIoStatement(ptr %10)
  %.unpack250 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack257.unpack.unpack259 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %13 = icmp sgt i64 %.unpack257.unpack.unpack259, 0
  br i1 %13, label %.lr.ph.i.preheader, label %_FortranASumInteger8x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %0
  %min.iters.check = icmp ult i64 %.unpack257.unpack.unpack259, 4
  br i1 %min.iters.check, label %.lr.ph.i.preheader304, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack257.unpack.unpack259, -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %17, %vector.body ]
  %vec.phi301 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %18, %vector.body ]
  %14 = shl i64 %index, 3
  %15 = getelementptr i8, ptr %.unpack250, i64 %14
  %wide.load = load <2 x i64>, ptr %15, align 8, !tbaa !3
  %16 = getelementptr i64, ptr %15, i64 2
  %wide.load302 = load <2 x i64>, ptr %16, align 8, !tbaa !3
  %17 = add <2 x i64> %wide.load, %vec.phi
  %18 = add <2 x i64> %wide.load302, %vec.phi301
  %index.next = add nuw i64 %index, 4
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %18, %17
  %20 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %.unpack257.unpack.unpack259, %n.vec
  br i1 %cmp.n, label %_FortranASumInteger8x1_contract_simplified.exit, label %.lr.ph.i.preheader304

.lr.ph.i.preheader304:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i64 [ 0, %.lr.ph.i.preheader ], [ %20, %middle.block ]
  %.ph305 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader304, %.lr.ph.i
  %21 = phi i64 [ %26, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader304 ]
  %22 = phi i64 [ %27, %.lr.ph.i ], [ %.ph305, %.lr.ph.i.preheader304 ]
  %23 = shl i64 %22, 3
  %24 = getelementptr i8, ptr %.unpack250, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !3
  %26 = add i64 %25, %21
  %27 = add nuw nsw i64 %22, 1
  %exitcond.not.i = icmp eq i64 %27, %.unpack257.unpack.unpack259
  br i1 %exitcond.not.i, label %_FortranASumInteger8x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranASumInteger8x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block, %0
  %.lcssa.i = phi i64 [ 0, %0 ], [ %20, %middle.block ], [ %26, %.lr.ph.i ]
  %28 = load i64, ptr %2, align 8, !tbaa !3
  %29 = sdiv i64 %.lcssa.i, %28
  %.neg = xor i64 %29, -1
  %30 = icmp sgt i64 %28, 0
  br i1 %30, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %_FortranASumInteger8x1_contract_simplified.exit
  %xtraiter = and i64 %28, 1
  %31 = icmp eq i64 %28, 1
  br i1 %31, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %28, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %32 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %50, %.lr.ph ]
  %.0287 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %49, %.lr.ph ]
  %.0228286 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %46, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %33 = add nsw i64 %32, -1
  %34 = getelementptr i64, ptr %.unpack250, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !3
  %36 = sub i64 %35, %29
  %37 = mul i64 %36, %36
  %38 = add i64 %37, %.0228286
  %39 = add i64 %35, %.neg
  %40 = mul i64 %39, %39
  %41 = add i64 %40, %.0287
  %42 = getelementptr i64, ptr %.unpack250, i64 %32
  %43 = load i64, ptr %42, align 8, !tbaa !3
  %44 = sub i64 %43, %29
  %45 = mul i64 %44, %44
  %46 = add i64 %45, %38
  %47 = add i64 %43, %.neg
  %48 = mul i64 %47, %47
  %49 = add i64 %48, %41
  %50 = add nuw i64 %32, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa.loopexit, label %.lr.ph

._crit_edge.unr-lcssa.loopexit:                   ; preds = %.lr.ph
  %51 = add i64 %32, 1
  br label %._crit_edge.unr-lcssa

._crit_edge.unr-lcssa:                            ; preds = %._crit_edge.unr-lcssa.loopexit, %.lr.ph.preheader
  %.lcssa303.ph = phi i64 [ undef, %.lr.ph.preheader ], [ %46, %._crit_edge.unr-lcssa.loopexit ]
  %.lcssa.ph = phi i64 [ undef, %.lr.ph.preheader ], [ %49, %._crit_edge.unr-lcssa.loopexit ]
  %.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %51, %._crit_edge.unr-lcssa.loopexit ]
  %.0287.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %49, %._crit_edge.unr-lcssa.loopexit ]
  %.0228286.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %46, %._crit_edge.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %52 = getelementptr i64, ptr %.unpack250, i64 %.unr
  %53 = load i64, ptr %52, align 8, !tbaa !3
  %54 = sub i64 %53, %29
  %55 = mul i64 %54, %54
  %56 = add i64 %55, %.0228286.unr
  %57 = add i64 %53, %.neg
  %58 = mul i64 %57, %57
  %59 = add i64 %58, %.0287.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.lcssa303 = phi i64 [ %.lcssa303.ph, %._crit_edge.unr-lcssa ], [ %56, %.lr.ph.epil ]
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %59, %.lr.ph.epil ]
  %.not = icmp sgt i64 %.lcssa303, %.lcssa
  %spec.select = select i1 %.not, i32 24, i32 21
  %spec.select298 = call i64 @llvm.smin.i64(i64 %.lcssa303, i64 %.lcssa)
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %._crit_edge, %_FortranASumInteger8x1_contract_simplified.exit
  %.sink = phi i32 [ 21, %_FortranASumInteger8x1_contract_simplified.exit ], [ %spec.select, %._crit_edge ]
  %.0228.lcssa294.sink = phi i64 [ 0, %_FortranASumInteger8x1_contract_simplified.exit ], [ %spec.select298, %._crit_edge ]
  %60 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.b5e40fd695a394ff8e319740483dfdea, i32 %.sink)
  %61 = call i1 @_FortranAioOutputInteger64(ptr %60, i64 %.0228.lcssa294.sink)
  %62 = call i32 @_FortranAioEndIoStatement(ptr %60)
  %.unpack262 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  call void @free(ptr %.unpack262)
  store ptr null, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 0, ptr @_QFEa.8, align 8, !tbaa !7
  %63 = 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

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

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

; 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 i64 @llvm.smin.i64(i64, i64) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #4

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

!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}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
