program test
  implicit none
  integer :: n, flag, i, k, j
  integer, dimension ( : ), allocatable :: p, q

  read ( unit = *, fmt = * ) n

  allocate ( q ( 1:n ) )  
  allocate ( p ( 1:n ) ) 

  read ( unit = *, fmt = * ) p ( 1:n )

  k = 1

  do j = 1,n

     do i = 1, n

        if ( p ( i ) == minval ( p ) ) then

           q ( i ) = k

           k = k + 1

           p ( i ) = 100

           exit

        end if

     end do

  end do

  flag = 0

  do i = 1, n

     if ( q ( i ) /= i ) then

        flag = flag + 1

     end if

  end do

  if ( flag > 2 ) then

     write ( unit = *, fmt = '(a2)' ) 'NO'

     stop

  end if

  write ( unit = *, fmt = '(a3)' ) 'YES'

  stop



end program test

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

@_QFEp.0 = internal unnamed_addr global ptr null
@_QFEp.8 = internal unnamed_addr global i64 0
@_QFEq.0 = internal unnamed_addr global ptr null
@_QQcl.04d39a6cb3946473ee3e95630afee270 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3652/source.f\00"
@_QQcl.28613229 = linkonce constant [4 x i8] c"(a2)"
@_QQcl.4E4F = linkonce constant [2 x i8] c"NO"
@_QQcl.28613329 = linkonce constant [4 x i8] c"(a3)"
@_QQcl.594553 = linkonce constant [3 x i8] c"YES"
@_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 { 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 i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.04d39a6cb3946473ee3e95630afee270, i32 6)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i32, ptr %3, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEq.0, align 8, !tbaa !7
  %12 = call ptr @malloc(i64 %10)
  store ptr %12, ptr @_QFEp.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEp.8, align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.04d39a6cb3946473ee3e95630afee270, i32 11)
  %.unpack = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %14 = load i32, ptr %3, align 4, !tbaa !3
  %15 = call i32 @llvm.smax.i32(i32 %14, i32 0)
  %16 = zext i32 %15 to i64
  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 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 %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 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 %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 %16, 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 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %17 = call i1 @_FortranAioInputDescriptor(ptr %13, ptr nonnull %2)
  %18 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %19 = load i32, ptr %3, align 4, !tbaa !3
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph320.split.preheader, label %._crit_edge324.thread

.lr.ph320.split.preheader:                        ; preds = %0
  %.fca.1.gep155 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  %.fca.2.gep157 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  %.fca.3.gep159 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  %.fca.4.gep161 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  %.fca.5.gep163 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  %.fca.6.gep165 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  %.fca.7.0.0.gep167 = 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.gep169 = 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.gep171 = 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 %.lr.ph320.split

.lr.ph320.split:                                  ; preds = %.lr.ph320.split.preheader, %.loopexit
  %.0319 = phi i32 [ %.1, %.loopexit ], [ 1, %.lr.ph320.split.preheader ]
  %.0236318 = phi i32 [ %37, %.loopexit ], [ %19, %.lr.ph320.split.preheader ]
  %21 = load i32, ptr %3, align 4, !tbaa !3
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph320.split, %35
  %.0233317 = phi i32 [ %36, %35 ], [ 1, %.lr.ph320.split ]
  %.unpack280 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack287.unpack.unpack289 = load i64, ptr @_QFEp.8, align 8, !tbaa !7
  %23 = sext i32 %.0233317 to i64
  %24 = add nsw i64 %23, -1
  %25 = getelementptr i32, ptr %.unpack280, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !3
  store ptr %.unpack280, ptr %1, align 8, !tbaa !7
  store i64 4, ptr %.fca.1.gep155, align 8, !tbaa !7
  store i32 20180515, ptr %.fca.2.gep157, align 8, !tbaa !7
  store i8 1, ptr %.fca.3.gep159, align 4, !tbaa !7
  store i8 9, ptr %.fca.4.gep161, align 1, !tbaa !7
  store i8 0, ptr %.fca.5.gep163, align 2, !tbaa !7
  store i8 0, ptr %.fca.6.gep165, align 1, !tbaa !7
  store i64 1, ptr %.fca.7.0.0.gep167, align 8, !tbaa !7
  store i64 %.unpack287.unpack.unpack289, ptr %.fca.7.0.1.gep169, align 8, !tbaa !7
  store i64 4, ptr %.fca.7.0.2.gep171, align 8, !tbaa !7
  %27 = call i32 @_FortranAMinvalInteger4(ptr nonnull %1, ptr nonnull @_QQcl.04d39a6cb3946473ee3e95630afee270, i32 17, i32 0, ptr null)
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %35

29:                                               ; preds = %.lr.ph
  %.unpack292 = load ptr, ptr @_QFEq.0, align 8, !tbaa !7
  %30 = add nsw i64 %23, -1
  %31 = getelementptr i32, ptr %.unpack292, i64 %30
  store i32 %.0319, ptr %31, align 4, !tbaa !3
  %32 = add i32 %.0319, 1
  %.unpack304 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %33 = add nsw i64 %23, -1
  %34 = getelementptr i32, ptr %.unpack304, i64 %33
  store i32 100, ptr %34, align 4, !tbaa !3
  br label %.loopexit

35:                                               ; preds = %.lr.ph
  %36 = add nuw i32 %.0233317, 1
  %exitcond.not = icmp eq i32 %.0233317, %21
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %35, %.lr.ph320.split, %29
  %.1 = phi i32 [ %32, %29 ], [ %.0319, %.lr.ph320.split ], [ %.0319, %35 ]
  %37 = add nsw i32 %.0236318, -1
  %38 = icmp sgt i32 %.0236318, 1
  br i1 %38, label %.lr.ph320.split, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.loopexit
  %.pre = load i32, ptr %3, align 4, !tbaa !3
  %39 = icmp sgt i32 %.pre, 0
  br i1 %39, label %.lr.ph323, label %._crit_edge324.thread

.lr.ph323:                                        ; preds = %._crit_edge
  %40 = zext i32 %.pre to i64
  %.unpack268 = load ptr, ptr @_QFEq.0, align 8, !tbaa !7
  %min.iters.check = icmp ult i32 %.pre, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph323
  %n.vec = and i64 %40, 4294967288
  %ind.end = or i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <4 x i64> [ <i64 1, i64 2, i64 3, i64 4>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %49, %vector.body ]
  %vec.phi333 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %50, %vector.body ]
  %step.add = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
  %41 = getelementptr i32, ptr %.unpack268, i64 %index
  %wide.load = load <4 x i32>, ptr %41, align 4, !tbaa !3
  %42 = getelementptr i32, ptr %41, i64 4
  %wide.load334 = load <4 x i32>, ptr %42, align 4, !tbaa !3
  %43 = zext <4 x i32> %wide.load to <4 x i64>
  %44 = zext <4 x i32> %wide.load334 to <4 x i64>
  %45 = icmp ne <4 x i64> %vec.ind, %43
  %46 = icmp ne <4 x i64> %step.add, %44
  %47 = zext <4 x i1> %45 to <4 x i32>
  %48 = zext <4 x i1> %46 to <4 x i32>
  %49 = add <4 x i32> %vec.phi, %47
  %50 = add <4 x i32> %vec.phi333, %48
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i64> %vec.ind, <i64 8, i64 8, i64 8, i64 8>
  %51 = icmp eq i64 %index.next, %n.vec
  br i1 %51, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %50, %49
  %52 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %40
  br i1 %cmp.n, label %._crit_edge324, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph323, %middle.block
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph323 ], [ %ind.end, %middle.block ]
  %.0234321.ph = phi i32 [ 0, %.lr.ph323 ], [ %52, %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 ]
  %.0234321 = phi i32 [ %spec.select, %scalar.ph ], [ %.0234321.ph, %scalar.ph.preheader ]
  %53 = add i64 %indvars.iv, -1
  %54 = getelementptr i32, ptr %.unpack268, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !3
  %56 = zext i32 %55 to i64
  %.not = icmp ne i64 %indvars.iv, %56
  %57 = zext i1 %.not to i32
  %spec.select = add i32 %.0234321, %57
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond328.not = icmp eq i64 %indvars.iv, %40
  br i1 %exitcond328.not, label %._crit_edge324, label %scalar.ph, !llvm.loop !14

._crit_edge324:                                   ; preds = %scalar.ph, %middle.block
  %spec.select.lcssa = phi i32 [ %52, %middle.block ], [ %spec.select, %scalar.ph ]
  %58 = icmp sgt i32 %spec.select.lcssa, 2
  br i1 %58, label %59, label %._crit_edge324.thread

59:                                               ; preds = %._crit_edge324
  %60 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28613229, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.04d39a6cb3946473ee3e95630afee270, i32 49)
  %61 = call i1 @_FortranAioOutputAscii(ptr %60, ptr nonnull @_QQcl.4E4F, i64 2)
  %62 = call i32 @_FortranAioEndIoStatement(ptr %60)
  %63 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

._crit_edge324.thread:                            ; preds = %0, %._crit_edge, %._crit_edge324
  %64 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28613329, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.04d39a6cb3946473ee3e95630afee270, i32 55)
  %65 = call i1 @_FortranAioOutputAscii(ptr %64, ptr nonnull @_QQcl.594553, i64 3)
  %66 = call i32 @_FortranAioEndIoStatement(ptr %64)
  %67 = 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 i32 @_FortranAMinvalInteger4(ptr, ptr, i32, i32, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputAscii(ptr, ptr, i64) local_unnamed_addr

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

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { noreturn }
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}
!10 = !{!"llvm.loop.unswitch.partial.disable"}
!11 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !13, !12}
