implicit none

integer :: N
integer, allocatable :: p(:)
integer :: i,s

read *, N
allocate(p(N))

read *, (p(i),i=1,N)

s = 0
do i = 1, N
   if (p(i) /= i) then
      s = s + 1
   endif
enddo

if (s == 0 .or. s == 2) then
   write(6,'(a)') 'YES'
else
   write(6,'(a)') 'NO'
endif
stop
end
; 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
@_QQcl.8b6f3037391c9dc090cd2df3b6ec25c2 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3643/source.f\00"
@_QQcl.286129 = linkonce constant [3 x i8] c"(a)"
@_QQcl.594553 = linkonce constant [3 x i8] c"YES"
@_QQcl.4E4F = linkonce constant [2 x i8] c"NO"
@_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 i32, align 4
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8b6f3037391c9dc090cd2df3b6ec25c2, i32 7)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 4)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i32, ptr %1, align 4, !tbaa !3
  %6 = call i32 @llvm.smax.i32(i32 %5, i32 0)
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 2
  %9 = call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEp.0, align 8, !tbaa !7
  %10 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8b6f3037391c9dc090cd2df3b6ec25c2, i32 10)
  %11 = load i32, ptr %1, align 4, !tbaa !3
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %14 = phi i64 [ %19, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.unpack74 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %sext = shl i64 %14, 32
  %15 = ashr exact i64 %sext, 32
  %16 = add nsw i64 %15, -1
  %17 = getelementptr i32, ptr %.unpack74, i64 %16
  %18 = call i1 @_FortranAioInputInteger(ptr %10, ptr %17, i32 4)
  %19 = add nuw nsw i64 %14, 1
  %exitcond.not = icmp eq i64 %14, %13
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %20 = call i32 @_FortranAioEndIoStatement(ptr %10)
  %21 = load i32, ptr %1, align 4, !tbaa !3
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph88, label %._crit_edge89.thread

.lr.ph88:                                         ; preds = %._crit_edge
  %23 = zext i32 %21 to i64
  %.unpack = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %min.iters.check = icmp ult i32 %21, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph88
  %n.vec = and i64 %23, 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 ], [ %32, %vector.body ]
  %vec.phi96 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %33, %vector.body ]
  %step.add = add <4 x i64> %vec.ind, <i64 4, i64 4, i64 4, i64 4>
  %24 = getelementptr i32, ptr %.unpack, i64 %index
  %wide.load = load <4 x i32>, ptr %24, align 4, !tbaa !3
  %25 = getelementptr i32, ptr %24, i64 4
  %wide.load97 = load <4 x i32>, ptr %25, align 4, !tbaa !3
  %26 = zext <4 x i32> %wide.load to <4 x i64>
  %27 = zext <4 x i32> %wide.load97 to <4 x i64>
  %28 = icmp ne <4 x i64> %vec.ind, %26
  %29 = icmp ne <4 x i64> %step.add, %27
  %30 = zext <4 x i1> %28 to <4 x i32>
  %31 = zext <4 x i1> %29 to <4 x i32>
  %32 = add <4 x i32> %vec.phi, %30
  %33 = add <4 x i32> %vec.phi96, %31
  %index.next = add nuw i64 %index, 8
  %vec.ind.next = add <4 x i64> %vec.ind, <i64 8, i64 8, i64 8, i64 8>
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %33, %32
  %35 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %23
  br i1 %cmp.n, label %._crit_edge89, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph88, %middle.block
  %indvars.iv.ph = phi i64 [ 1, %.lr.ph88 ], [ %ind.end, %middle.block ]
  %.086.ph = phi i32 [ 0, %.lr.ph88 ], [ %35, %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 ]
  %.086 = phi i32 [ %spec.select, %scalar.ph ], [ %.086.ph, %scalar.ph.preheader ]
  %36 = add i64 %indvars.iv, -1
  %37 = getelementptr i32, ptr %.unpack, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !3
  %39 = zext i32 %38 to i64
  %.not = icmp ne i64 %indvars.iv, %39
  %40 = zext i1 %.not to i32
  %spec.select = add i32 %.086, %40
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond91.not = icmp eq i64 %indvars.iv, %23
  br i1 %exitcond91.not, label %._crit_edge89, label %scalar.ph, !llvm.loop !12

._crit_edge89:                                    ; preds = %scalar.ph, %middle.block
  %spec.select.lcssa = phi i32 [ %35, %middle.block ], [ %spec.select, %scalar.ph ]
  switch i32 %spec.select.lcssa, label %41 [
    i32 2, label %._crit_edge89.thread
    i32 0, label %._crit_edge89.thread
  ]

41:                                               ; preds = %._crit_edge89
  br label %._crit_edge89.thread

._crit_edge89.thread:                             ; preds = %._crit_edge89, %._crit_edge89, %._crit_edge, %41
  %.sink = phi i32 [ 22, %41 ], [ 20, %._crit_edge ], [ 20, %._crit_edge89 ], [ 20, %._crit_edge89 ]
  %.sink94 = phi i64 [ 2, %41 ], [ 3, %._crit_edge ], [ 3, %._crit_edge89 ], [ 3, %._crit_edge89 ]
  %_QQcl.594553.sink = phi ptr [ @_QQcl.4E4F, %41 ], [ @_QQcl.594553, %._crit_edge ], [ @_QQcl.594553, %._crit_edge89 ], [ @_QQcl.594553, %._crit_edge89 ]
  %42 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.286129, i64 3, ptr null, i32 6, ptr nonnull @_QQcl.8b6f3037391c9dc090cd2df3b6ec25c2, i32 %.sink)
  %43 = call i1 @_FortranAioOutputAscii(ptr %42, ptr nonnull %_QQcl.594553.sink, i64 %.sink94)
  %44 = call i32 @_FortranAioEndIoStatement(ptr %42)
  %45 = 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 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, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
