program ABC043C
    implicit none
    integer(8)::N,cost,result,i,j
    integer(8),allocatable,dimension(:)::A

    read(5,*)N
    allocate(A(N))
    read(5,*)(A(i),i=1,N)

    do i=minval(A),maxval(A)
        cost=0
        do j=1,N
            cost=cost+(i-A(j))**2
        end do

        if(i==minval(A))then
            result=cost
        else if(cost<result)then
            result=cost
        end if
    end do

    print'(i0)',result
end program ABC043C
; 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.beaf9ffa7711bbc1092148255498a4a7 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7982/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 { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca i64, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.beaf9ffa7711bbc1092148255498a4a7, i32 6)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i64, ptr %3, align 8, !tbaa !3
  %8 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %9 = shl i64 %8, 3
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEa.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.beaf9ffa7711bbc1092148255498a4a7, i32 8)
  %12 = load i64, ptr %3, align 8, !tbaa !3
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %14 = phi i64 [ %18, %.lr.ph ], [ 1, %0 ]
  %.unpack269 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %15 = add i64 %14, -1
  %16 = getelementptr i64, ptr %.unpack269, i64 %15
  %17 = call i1 @_FortranAioInputInteger(ptr %11, ptr %16, i32 8)
  %18 = add nuw i64 %14, 1
  %exitcond.not = icmp eq i64 %14, %12
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %19 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack228.unpack.unpack230 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %2, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack228.unpack.unpack230, 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 %2, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %20 = call i64 @_FortranAMinvalInteger8(ptr nonnull %2, ptr nonnull @_QQcl.beaf9ffa7711bbc1092148255498a4a7, i32 10, i32 0, ptr null)
  %.unpack233 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack240.unpack.unpack242 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %21 = icmp sgt i64 %.unpack240.unpack.unpack242, 0
  br i1 %21, label %.lr.ph.i.preheader, label %_FortranAMaxvalInteger8x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge
  %min.iters.check = icmp ult i64 %.unpack240.unpack.unpack242, 4
  br i1 %min.iters.check, label %.lr.ph.i.preheader318, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack240.unpack.unpack242, -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> [ <i64 -9223372036854775808, i64 -9223372036854775808>, %vector.ph ], [ %25, %vector.body ]
  %vec.phi295 = phi <2 x i64> [ <i64 -9223372036854775808, i64 -9223372036854775808>, %vector.ph ], [ %26, %vector.body ]
  %22 = shl i64 %index, 3
  %23 = getelementptr i8, ptr %.unpack233, i64 %22
  %wide.load = load <2 x i64>, ptr %23, align 8, !tbaa !3
  %24 = getelementptr i64, ptr %23, i64 2
  %wide.load296 = load <2 x i64>, ptr %24, align 8, !tbaa !3
  %25 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %wide.load, <2 x i64> %vec.phi)
  %26 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %wide.load296, <2 x i64> %vec.phi295)
  %index.next = add nuw i64 %index, 4
  %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
  %rdx.minmax.select = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %25, <2 x i64> %26)
  %28 = call i64 @llvm.vector.reduce.smax.v2i64(<2 x i64> %rdx.minmax.select)
  %cmp.n = icmp eq i64 %.unpack240.unpack.unpack242, %n.vec
  br i1 %cmp.n, label %_FortranAMaxvalInteger8x1_contract_simplified.exit, label %.lr.ph.i.preheader318

.lr.ph.i.preheader318:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph319 = phi i64 [ -9223372036854775808, %.lr.ph.i.preheader ], [ %28, %middle.block ]
  %.ph320 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader318, %.lr.ph.i
  %29 = phi i64 [ %34, %.lr.ph.i ], [ %.ph319, %.lr.ph.i.preheader318 ]
  %30 = phi i64 [ %35, %.lr.ph.i ], [ %.ph320, %.lr.ph.i.preheader318 ]
  %31 = shl i64 %30, 3
  %32 = getelementptr i8, ptr %.unpack233, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !3
  %34 = call i64 @llvm.smax.i64(i64 %33, i64 %29)
  %35 = add nuw nsw i64 %30, 1
  %exitcond.not.i = icmp eq i64 %35, %.unpack240.unpack.unpack242
  br i1 %exitcond.not.i, label %_FortranAMaxvalInteger8x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranAMaxvalInteger8x1_contract_simplified.exit: ; preds = %.lr.ph.i, %middle.block, %._crit_edge
  %.lcssa.i = phi i64 [ -9223372036854775808, %._crit_edge ], [ %28, %middle.block ], [ %34, %.lr.ph.i ]
  %36 = sub i64 1, %20
  %37 = add i64 %36, %.lcssa.i
  %38 = icmp sgt i64 %37, 0
  br i1 %38, label %.lr.ph286, label %._crit_edge287

.lr.ph286:                                        ; preds = %_FortranAMaxvalInteger8x1_contract_simplified.exit
  %.fca.1.gep132 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  %.fca.2.gep134 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  %.fca.3.gep136 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  %.fca.4.gep138 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  %.fca.5.gep140 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  %.fca.6.gep142 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  %.fca.7.0.0.gep144 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  %.fca.7.0.1.gep146 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  %.fca.7.0.2.gep148 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  br label %39

39:                                               ; preds = %.lr.ph286, %._crit_edge284
  %40 = phi i64 [ %37, %.lr.ph286 ], [ %65, %._crit_edge284 ]
  %41 = phi i64 [ %20, %.lr.ph286 ], [ %64, %._crit_edge284 ]
  %.0285 = phi i64 [ undef, %.lr.ph286 ], [ %.1, %._crit_edge284 ]
  %42 = load i64, ptr %3, align 8, !tbaa !3
  %43 = icmp sgt i64 %42, 0
  %.unpack257 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br i1 %43, label %.lr.ph283.preheader, label %._crit_edge284

.lr.ph283.preheader:                              ; preds = %39
  %min.iters.check299 = icmp ult i64 %42, 4
  br i1 %min.iters.check299, label %.lr.ph283.preheader315, label %vector.ph300

vector.ph300:                                     ; preds = %.lr.ph283.preheader
  %n.vec302 = and i64 %42, -4
  %ind.end = or i64 %n.vec302, 1
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %41, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert311 = insertelement <2 x i64> poison, i64 %41, i64 0
  %broadcast.splat312 = shufflevector <2 x i64> %broadcast.splatinsert311, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body305

vector.body305:                                   ; preds = %vector.body305, %vector.ph300
  %index306 = phi i64 [ 0, %vector.ph300 ], [ %index.next313, %vector.body305 ]
  %vec.phi307 = phi <2 x i64> [ zeroinitializer, %vector.ph300 ], [ %50, %vector.body305 ]
  %vec.phi308 = phi <2 x i64> [ zeroinitializer, %vector.ph300 ], [ %51, %vector.body305 ]
  %44 = getelementptr i64, ptr %.unpack257, i64 %index306
  %wide.load309 = load <2 x i64>, ptr %44, align 8, !tbaa !3
  %45 = getelementptr i64, ptr %44, i64 2
  %wide.load310 = load <2 x i64>, ptr %45, align 8, !tbaa !3
  %46 = sub <2 x i64> %broadcast.splat, %wide.load309
  %47 = sub <2 x i64> %broadcast.splat312, %wide.load310
  %48 = mul <2 x i64> %46, %46
  %49 = mul <2 x i64> %47, %47
  %50 = add <2 x i64> %48, %vec.phi307
  %51 = add <2 x i64> %49, %vec.phi308
  %index.next313 = add nuw i64 %index306, 4
  %52 = icmp eq i64 %index.next313, %n.vec302
  br i1 %52, label %middle.block297, label %vector.body305, !llvm.loop !13

middle.block297:                                  ; preds = %vector.body305
  %bin.rdx = add <2 x i64> %51, %50
  %53 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n304 = icmp eq i64 %42, %n.vec302
  br i1 %cmp.n304, label %._crit_edge284, label %.lr.ph283.preheader315

.lr.ph283.preheader315:                           ; preds = %.lr.ph283.preheader, %middle.block297
  %.ph = phi i64 [ 1, %.lr.ph283.preheader ], [ %ind.end, %middle.block297 ]
  %.0209281.ph = phi i64 [ 0, %.lr.ph283.preheader ], [ %53, %middle.block297 ]
  br label %.lr.ph283

.lr.ph283:                                        ; preds = %.lr.ph283.preheader315, %.lr.ph283
  %54 = phi i64 [ %61, %.lr.ph283 ], [ %.ph, %.lr.ph283.preheader315 ]
  %.0209281 = phi i64 [ %60, %.lr.ph283 ], [ %.0209281.ph, %.lr.ph283.preheader315 ]
  %55 = add i64 %54, -1
  %56 = getelementptr i64, ptr %.unpack257, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !3
  %58 = sub i64 %41, %57
  %59 = mul i64 %58, %58
  %60 = add i64 %59, %.0209281
  %61 = add nuw i64 %54, 1
  %exitcond290.not = icmp eq i64 %54, %42
  br i1 %exitcond290.not, label %._crit_edge284, label %.lr.ph283, !llvm.loop !14

._crit_edge284:                                   ; preds = %.lr.ph283, %middle.block297, %39
  %.0209.lcssa = phi i64 [ 0, %39 ], [ %53, %middle.block297 ], [ %60, %.lr.ph283 ]
  %.unpack252.unpack.unpack254 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack257, ptr %1, align 8, !tbaa !7
  store i64 8, ptr %.fca.1.gep132, align 8, !tbaa !7
  store i32 20180515, ptr %.fca.2.gep134, align 8, !tbaa !7
  store i8 1, ptr %.fca.3.gep136, align 4, !tbaa !7
  store i8 10, ptr %.fca.4.gep138, align 1, !tbaa !7
  store i8 0, ptr %.fca.5.gep140, align 2, !tbaa !7
  store i8 0, ptr %.fca.6.gep142, align 1, !tbaa !7
  store i64 1, ptr %.fca.7.0.0.gep144, align 8, !tbaa !7
  store i64 %.unpack252.unpack.unpack254, ptr %.fca.7.0.1.gep146, align 8, !tbaa !7
  store i64 8, ptr %.fca.7.0.2.gep148, align 8, !tbaa !7
  %62 = call i64 @_FortranAMinvalInteger8(ptr nonnull %1, ptr nonnull @_QQcl.beaf9ffa7711bbc1092148255498a4a7, i32 14, i32 0, ptr null)
  %63 = icmp eq i64 %41, %62
  %spec.select = call i64 @llvm.smin.i64(i64 %.0209.lcssa, i64 %.0285)
  %.1 = select i1 %63, i64 %.0209.lcssa, i64 %spec.select
  %64 = add i64 %41, 1
  %65 = add i64 %40, -1
  %66 = icmp sgt i64 %65, 0
  br i1 %66, label %39, label %._crit_edge287

._crit_edge287:                                   ; preds = %._crit_edge284, %_FortranAMaxvalInteger8x1_contract_simplified.exit
  %.0.lcssa = phi i64 [ undef, %_FortranAMaxvalInteger8x1_contract_simplified.exit ], [ %.1, %._crit_edge284 ]
  %67 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.beaf9ffa7711bbc1092148255498a4a7, i32 23)
  %68 = call i1 @_FortranAioOutputInteger64(ptr %67, i64 %.0.lcssa)
  %69 = call i32 @_FortranAioEndIoStatement(ptr %67)
  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 i64 @_FortranAMinvalInteger8(ptr, ptr, i32, i32, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i64> @llvm.smax.v2i64(<2 x i64>, <2 x i64>) #2

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

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

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