program test
implicit none
integer :: i,n,m,x,a(100),aa(100)=0, cost

read(*,*)  n,m,x
read(*,*)  (a(i),i=1,m)

do i = 1, m
 aa(a(i)) = 1
enddo

cost = min(sum(aa(:x-1)),sum(aa(x+1:)))

write(*,*) cost

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"

@_QFEa = internal global [100 x i32] undef
@_QFEaa = internal unnamed_addr global [100 x i32] zeroinitializer
@_QQcl.b770f80924f2b6b5783ceb2b41c930ca = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_6083/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.b770f80924f2b6b5783ceb2b41c930ca, i32 5)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %1, i32 4)
  %7 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %9 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.b770f80924f2b6b5783ceb2b41c930ca, i32 6)
  %10 = load i32, ptr %1, align 4, !tbaa !3
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %12 = zext i32 %10 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %13 = phi i64 [ %18, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %sext = shl i64 %13, 32
  %14 = ashr exact i64 %sext, 32
  %15 = add nsw i64 %14, -1
  %16 = getelementptr [100 x i32], ptr @_QFEa, i64 0, i64 %15
  %17 = call i1 @_FortranAioInputInteger(ptr %9, ptr %16, i32 4)
  %18 = add nuw nsw i64 %13, 1
  %exitcond.not = icmp eq i64 %13, %12
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %19 = call i32 @_FortranAioEndIoStatement(ptr %9)
  %20 = load i32, ptr %1, align 4, !tbaa !3
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph42.preheader, label %._crit_edge43

.lr.ph42.preheader:                               ; preds = %._crit_edge
  %22 = zext i32 %20 to i64
  %xtraiter = and i64 %22, 1
  %23 = icmp eq i32 %20, 1
  br i1 %23, label %._crit_edge43.loopexit.unr-lcssa, label %.lr.ph42.preheader.new

.lr.ph42.preheader.new:                           ; preds = %.lr.ph42.preheader
  %unroll_iter = and i64 %22, 4294967294
  br label %.lr.ph42

.lr.ph42:                                         ; preds = %.lr.ph42, %.lr.ph42.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph42.preheader.new ], [ %indvars.iv.next.1, %.lr.ph42 ]
  %niter = phi i64 [ 0, %.lr.ph42.preheader.new ], [ %niter.next.1, %.lr.ph42 ]
  %24 = add nsw i64 %indvars.iv, -1
  %25 = getelementptr [100 x i32], ptr @_QFEa, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !3
  %27 = sext i32 %26 to i64
  %28 = add nsw i64 %27, -1
  %29 = getelementptr [100 x i32], ptr @_QFEaa, i64 0, i64 %28
  store i32 1, ptr %29, align 4, !tbaa !3
  %30 = getelementptr [100 x i32], ptr @_QFEa, i64 0, i64 %indvars.iv
  %31 = load i32, ptr %30, align 4, !tbaa !3
  %32 = sext i32 %31 to i64
  %33 = add nsw i64 %32, -1
  %34 = getelementptr [100 x i32], ptr @_QFEaa, i64 0, i64 %33
  store i32 1, ptr %34, align 4, !tbaa !3
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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_edge43.loopexit.unr-lcssa.loopexit, label %.lr.ph42

._crit_edge43.loopexit.unr-lcssa.loopexit:        ; preds = %.lr.ph42
  %35 = add nuw nsw i64 %indvars.iv, 1
  br label %._crit_edge43.loopexit.unr-lcssa

._crit_edge43.loopexit.unr-lcssa:                 ; preds = %._crit_edge43.loopexit.unr-lcssa.loopexit, %.lr.ph42.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph42.preheader ], [ %35, %._crit_edge43.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge43, label %.lr.ph42.epil

.lr.ph42.epil:                                    ; preds = %._crit_edge43.loopexit.unr-lcssa
  %36 = getelementptr [100 x i32], ptr @_QFEa, i64 0, i64 %indvars.iv.unr
  %37 = load i32, ptr %36, align 4, !tbaa !3
  %38 = sext i32 %37 to i64
  %39 = add nsw i64 %38, -1
  %40 = getelementptr [100 x i32], ptr @_QFEaa, i64 0, i64 %39
  store i32 1, ptr %40, align 4, !tbaa !3
  br label %._crit_edge43

._crit_edge43:                                    ; preds = %.lr.ph42.epil, %._crit_edge43.loopexit.unr-lcssa, %._crit_edge
  %41 = load i32, ptr %3, align 4, !tbaa !3
  %42 = add i32 %41, -1
  %43 = call i32 @llvm.smax.i32(i32 %42, i32 0)
  %44 = zext i32 %43 to i64
  %.not = icmp slt i32 %42, 1
  br i1 %.not, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader

.lr.ph.i.preheader:                               ; preds = %._crit_edge43
  %min.iters.check = icmp ult i32 %43, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader72, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %44, 2147483640
  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 ], [ %48, %vector.body ]
  %vec.phi49 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %49, %vector.body ]
  %45 = shl i64 %index, 2
  %46 = getelementptr i8, ptr @_QFEaa, i64 %45
  %wide.load = load <4 x i32>, ptr %46, align 16, !tbaa !3
  %47 = getelementptr i32, ptr %46, i64 4
  %wide.load50 = load <4 x i32>, ptr %47, align 16, !tbaa !3
  %48 = add <4 x i32> %wide.load, %vec.phi
  %49 = add <4 x i32> %wide.load50, %vec.phi49
  %index.next = add nuw i64 %index, 8
  %50 = icmp eq i64 %index.next, %n.vec
  br i1 %50, label %middle.block, label %vector.body, !llvm.loop !7

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %49, %48
  %51 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %44
  br i1 %cmp.n, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader72

.lr.ph.i.preheader72:                             ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph73 = phi i32 [ 0, %.lr.ph.i.preheader ], [ %51, %middle.block ]
  %.ph74 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader72, %.lr.ph.i
  %52 = phi i32 [ %57, %.lr.ph.i ], [ %.ph73, %.lr.ph.i.preheader72 ]
  %53 = phi i64 [ %58, %.lr.ph.i ], [ %.ph74, %.lr.ph.i.preheader72 ]
  %54 = shl i64 %53, 2
  %55 = getelementptr i8, ptr @_QFEaa, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !3
  %57 = add i32 %56, %52
  %58 = add nuw nsw i64 %53, 1
  %exitcond.not.i = icmp eq i64 %58, %44
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !10

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block, %._crit_edge43
  %.lcssa.i = phi i32 [ 0, %._crit_edge43 ], [ %51, %middle.block ], [ %57, %.lr.ph.i ]
  %59 = add i32 %41, 1
  %60 = sext i32 %59 to i64
  %61 = add nsw i64 %60, -1
  %62 = sub nsw i64 101, %60
  %63 = call i64 @llvm.smax.i64(i64 %62, i64 0)
  %64 = getelementptr [100 x i32], ptr @_QFEaa, i64 0, i64 %61
  %.not39 = icmp sgt i32 %59, 100
  br i1 %.not39, label %_FortranASumInteger4x1_contract_simplified.exit28, label %.lr.ph.i25.preheader

.lr.ph.i25.preheader:                             ; preds = %_FortranASumInteger4x1_contract_simplified.exit
  %min.iters.check53 = icmp ult i64 %63, 8
  br i1 %min.iters.check53, label %.lr.ph.i25.preheader68, label %vector.ph54

vector.ph54:                                      ; preds = %.lr.ph.i25.preheader
  %n.vec56 = and i64 %63, 9223372036854775800
  br label %vector.body59

vector.body59:                                    ; preds = %vector.body59, %vector.ph54
  %index60 = phi i64 [ 0, %vector.ph54 ], [ %index.next65, %vector.body59 ]
  %vec.phi61 = phi <4 x i32> [ zeroinitializer, %vector.ph54 ], [ %68, %vector.body59 ]
  %vec.phi62 = phi <4 x i32> [ zeroinitializer, %vector.ph54 ], [ %69, %vector.body59 ]
  %65 = shl i64 %index60, 2
  %66 = getelementptr i8, ptr %64, i64 %65
  %wide.load63 = load <4 x i32>, ptr %66, align 4, !tbaa !3
  %67 = getelementptr i32, ptr %66, i64 4
  %wide.load64 = load <4 x i32>, ptr %67, align 4, !tbaa !3
  %68 = add <4 x i32> %wide.load63, %vec.phi61
  %69 = add <4 x i32> %wide.load64, %vec.phi62
  %index.next65 = add nuw i64 %index60, 8
  %70 = icmp eq i64 %index.next65, %n.vec56
  br i1 %70, label %middle.block51, label %vector.body59, !llvm.loop !11

middle.block51:                                   ; preds = %vector.body59
  %bin.rdx66 = add <4 x i32> %69, %68
  %71 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx66)
  %cmp.n58 = icmp eq i64 %63, %n.vec56
  br i1 %cmp.n58, label %_FortranASumInteger4x1_contract_simplified.exit28, label %.lr.ph.i25.preheader68

.lr.ph.i25.preheader68:                           ; preds = %.lr.ph.i25.preheader, %middle.block51
  %.ph = phi i32 [ 0, %.lr.ph.i25.preheader ], [ %71, %middle.block51 ]
  %.ph69 = phi i64 [ 0, %.lr.ph.i25.preheader ], [ %n.vec56, %middle.block51 ]
  br label %.lr.ph.i25

.lr.ph.i25:                                       ; preds = %.lr.ph.i25.preheader68, %.lr.ph.i25
  %72 = phi i32 [ %77, %.lr.ph.i25 ], [ %.ph, %.lr.ph.i25.preheader68 ]
  %73 = phi i64 [ %78, %.lr.ph.i25 ], [ %.ph69, %.lr.ph.i25.preheader68 ]
  %74 = shl i64 %73, 2
  %75 = getelementptr i8, ptr %64, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !3
  %77 = add i32 %76, %72
  %78 = add nuw nsw i64 %73, 1
  %exitcond.not.i26 = icmp eq i64 %78, %63
  br i1 %exitcond.not.i26, label %_FortranASumInteger4x1_contract_simplified.exit28, label %.lr.ph.i25, !llvm.loop !12

_FortranASumInteger4x1_contract_simplified.exit28: ; preds = %.lr.ph.i25, %middle.block51, %_FortranASumInteger4x1_contract_simplified.exit
  %.lcssa.i27 = phi i32 [ 0, %_FortranASumInteger4x1_contract_simplified.exit ], [ %71, %middle.block51 ], [ %77, %.lr.ph.i25 ]
  %79 = call i32 @llvm.smin.i32(i32 %.lcssa.i, i32 %.lcssa.i27)
  %80 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.b770f80924f2b6b5783ceb2b41c930ca, i32 14)
  %81 = call i1 @_FortranAioOutputInteger32(ptr %80, i32 %79)
  %82 = call i32 @_FortranAioEndIoStatement(ptr %80)
  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 ptr @_FortranAioBeginExternalListOutput(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 i64 @llvm.smax.i64(i64, i64) #0

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

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

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 = distinct !{!7, !8, !9}
!8 = !{!"llvm.loop.isvectorized", i32 1}
!9 = !{!"llvm.loop.unroll.runtime.disable"}
!10 = distinct !{!10, !9, !8}
!11 = distinct !{!11, !8, !9}
!12 = distinct !{!12, !9, !8}
