program rally
implicit none
integer n
integer, allocatable :: listx(:)
integer i, j
integer power, powerold
!
! input
read *, n
allocate(listx(n))
read *, listx
!
! calculation
powerold=1000000
do i = 1, 100
  power = 0
  do j = 1, n
    power = power + (listx(j) - i)**2
  end do
  if(power<powerold) then
    powerold = power
  end if
end do
!
! output
print '(i0)', powerold
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"

@_QFElistx.0 = internal unnamed_addr global ptr null
@_QFElistx.8 = internal unnamed_addr global i64 0
@_QQcl.56519e5faec662c52880d815d7f51b39 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2344/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.56519e5faec662c52880d815d7f51b39, i32 9)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFElistx.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFElistx.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.56519e5faec662c52880d815d7f51b39, i32 11)
  %.unpack = load ptr, ptr @_QFElistx.0, align 8, !tbaa !7
  %.unpack94.unpack.unpack96 = load i64, ptr @_QFElistx.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 4, 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 9, 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 %.unpack94.unpack.unpack96, 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 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %12 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %13 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %14 = load i32, ptr %2, align 4, !tbaa !3
  %15 = icmp sgt i32 %14, 0
  %.unpack99 = load ptr, ptr @_QFElistx.0, align 8
  br i1 %15, label %.lr.ph.us.preheader, label %.split114.us

.lr.ph.us.preheader:                              ; preds = %0
  %16 = zext i32 %14 to i64
  %min.iters.check = icmp ult i32 %14, 8
  %n.vec = and i64 %16, 4294967288
  %ind.end = or i64 %n.vec, 1
  %cmp.n = icmp eq i64 %n.vec, %16
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %17 = phi i64 [ %36, %._crit_edge.us ], [ 100, %.lr.ph.us.preheader ]
  %18 = phi i32 [ %35, %._crit_edge.us ], [ 1, %.lr.ph.us.preheader ]
  %.0112.us = phi i32 [ %spec.select.us, %._crit_edge.us ], [ 1000000, %.lr.ph.us.preheader ]
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %18, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert119 = insertelement <4 x i32> poison, i32 %18, i64 0
  %broadcast.splat120 = shufflevector <4 x i32> %broadcast.splatinsert119, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %25, %vector.body ]
  %vec.phi117 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %26, %vector.body ]
  %19 = getelementptr i32, ptr %.unpack99, i64 %index
  %wide.load = load <4 x i32>, ptr %19, align 4, !tbaa !3
  %20 = getelementptr i32, ptr %19, i64 4
  %wide.load118 = load <4 x i32>, ptr %20, align 4, !tbaa !3
  %21 = sub <4 x i32> %wide.load, %broadcast.splat
  %22 = sub <4 x i32> %wide.load118, %broadcast.splat120
  %23 = mul <4 x i32> %21, %21
  %24 = mul <4 x i32> %22, %22
  %25 = add <4 x i32> %23, %vec.phi
  %26 = add <4 x i32> %24, %vec.phi117
  %index.next = add nuw i64 %index, 8
  %27 = icmp eq i64 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %26, %25
  %28 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph.us, %middle.block
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph.us ], [ %ind.end, %middle.block ]
  %.076111.us.ph = phi i32 [ 0, %.lr.ph.us ], [ %28, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.076111.us = phi i32 [ %34, %scalar.ph ], [ %.076111.us.ph, %scalar.ph.preheader ]
  %29 = add i64 %indvars.iv, -1
  %30 = getelementptr i32, ptr %.unpack99, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !3
  %32 = sub i32 %31, %18
  %33 = mul i32 %32, %32
  %34 = add i32 %33, %.076111.us
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %16
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !12

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %.lcssa = phi i32 [ %28, %middle.block ], [ %34, %scalar.ph ]
  %spec.select.us = call i32 @llvm.smin.i32(i32 %.lcssa, i32 %.0112.us)
  %35 = add nuw nsw i32 %18, 1
  %36 = add nsw i64 %17, -1
  %.not = icmp eq i64 %36, 0
  br i1 %.not, label %.split114.us, label %.lr.ph.us

.split114.us:                                     ; preds = %._crit_edge.us, %0
  %.us-phi = phi i32 [ 0, %0 ], [ %spec.select.us, %._crit_edge.us ]
  %37 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.56519e5faec662c52880d815d7f51b39, i32 26)
  %38 = call i1 @_FortranAioOutputInteger32(ptr %37, i32 %.us-phi)
  %39 = call i32 @_FortranAioEndIoStatement(ptr %37)
  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 i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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}
