   program abc160c2
      implicit none
      integer::K,N,i,maxA,x,y,index,Cmin=0
      integer,allocatable,dimension(:)::A

        read *,K,N
        allocate(A(N))
        read *,A

        maxA=0
        do i=1,N-1
           x=A(i+1)-A(i)
           if (maxA<x) then
              maxA=x
              index=i
           end if
        end do
        y=K-A(N)+A(1)
        if (maxA<y) then
           maxA=y
           index=0
        end if

        do i=1,N-1
           if (i==index) cycle
           Cmin=Cmin+(A(i+1)-A(i))
        end do

        if (index/=0) then
           Cmin=Cmin+(K-A(N)+A(1))
        end if

        print *,Cmin
        stop

   end program abc160c2
; 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
@_QFEcmin = internal unnamed_addr global i32 0
@_QQcl.0165d0c42fc54d811d7d10fd5a40e322 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1977/source.f\00"
@_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 i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0165d0c42fc54d811d7d10fd5a40e322, i32 6)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %3, align 4, !tbaa !3
  %9 = call i32 @llvm.smax.i32(i32 %8, i32 0)
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 2
  %12 = call ptr @malloc(i64 %11)
  store ptr %12, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEa.8, align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0165d0c42fc54d811d7d10fd5a40e322, i32 8)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack192.unpack.unpack194 = load i64, ptr @_QFEa.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 %.unpack192.unpack.unpack194, 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
  %14 = call i1 @_FortranAioInputDescriptor(ptr %13, ptr nonnull %1)
  %15 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %16 = load i32, ptr %3, align 4, !tbaa !3
  %17 = add i32 %16, -1
  %18 = sext i32 %17 to i64
  %19 = icmp sgt i32 %17, 0
  %.unpack234 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %xtraiter = and i64 %18, 1
  %20 = icmp eq i32 %17, 1
  br i1 %20, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %18, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.0249 = phi i32 [ undef, %.lr.ph.preheader.new ], [ %spec.select246.1, %.lr.ph ]
  %.0171248 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %spec.select.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext261 = shl i64 %indvars.iv.next, 32
  %21 = ashr exact i64 %sext261, 32
  %22 = add nsw i64 %21, -1
  %23 = getelementptr i32, ptr %.unpack234, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !3
  %25 = add nsw i64 %indvars.iv, -1
  %26 = getelementptr i32, ptr %.unpack234, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !3
  %28 = sub i32 %24, %27
  %29 = icmp slt i32 %.0171248, %28
  %spec.select = call i32 @llvm.smax.i32(i32 %.0171248, i32 %28)
  %30 = trunc i64 %indvars.iv to i32
  %spec.select246 = select i1 %29, i32 %30, i32 %.0249
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %sext261.1 = shl i64 %indvars.iv.next.1, 32
  %31 = ashr exact i64 %sext261.1, 32
  %32 = add nsw i64 %31, -1
  %33 = getelementptr i32, ptr %.unpack234, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !3
  %35 = getelementptr i32, ptr %.unpack234, i64 %indvars.iv
  %36 = load i32, ptr %35, align 4, !tbaa !3
  %37 = sub i32 %34, %36
  %38 = icmp slt i32 %spec.select, %37
  %spec.select.1 = call i32 @llvm.smax.i32(i32 %spec.select, i32 %37)
  %39 = trunc i64 %indvars.iv.next to i32
  %spec.select246.1 = select i1 %38, i32 %39, i32 %spec.select246
  %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_edge.loopexit.unr-lcssa, label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %spec.select.lcssa.ph = phi i32 [ undef, %.lr.ph.preheader ], [ %spec.select.1, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.0249.unr = phi i32 [ undef, %.lr.ph.preheader ], [ %spec.select246.1, %.lr.ph ]
  %.0171248.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %spec.select.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %indvars.iv.next.epil = shl i64 %indvars.iv.unr, 32
  %sext261.epil = add i64 %indvars.iv.next.epil, 4294967296
  %40 = ashr exact i64 %sext261.epil, 32
  %41 = add nsw i64 %40, -1
  %42 = getelementptr i32, ptr %.unpack234, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !3
  %44 = add nsw i64 %indvars.iv.unr, -1
  %45 = getelementptr i32, ptr %.unpack234, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !3
  %47 = sub i32 %43, %46
  %48 = icmp slt i32 %.0171248.unr, %47
  %spec.select.epil = call i32 @llvm.smax.i32(i32 %.0171248.unr, i32 %47)
  %49 = trunc i64 %indvars.iv.unr to i32
  %spec.select246.epil = select i1 %48, i32 %49, i32 %.0249.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %0
  %.0171.lcssa = phi i32 [ 0, %0 ], [ %spec.select.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select.epil, %.lr.ph.epil ]
  %.0.lcssa = phi i32 [ undef, %0 ], [ %.0249.unr, %._crit_edge.loopexit.unr-lcssa ], [ %spec.select246.epil, %.lr.ph.epil ]
  %50 = load i32, ptr %2, align 4, !tbaa !3
  %51 = sext i32 %16 to i64
  %52 = add nsw i64 %51, -1
  %53 = getelementptr i32, ptr %.unpack234, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !3
  %55 = sub i32 %50, %54
  %56 = load i32, ptr %.unpack234, align 4, !tbaa !3
  %57 = add i32 %55, %56
  %58 = icmp slt i32 %.0171.lcssa, %57
  %spec.select247 = select i1 %58, i32 0, i32 %.0.lcssa
  %_QFEcmin.promoted = load i32, ptr @_QFEcmin, align 4, !tbaa !3
  br i1 %19, label %.lr.ph252.preheader, label %._crit_edge253

.lr.ph252.preheader:                              ; preds = %._crit_edge
  %59 = zext i32 %spec.select247 to i64
  %xtraiter264 = and i64 %18, 1
  %60 = icmp eq i32 %17, 1
  br i1 %60, label %._crit_edge253.loopexit.unr-lcssa, label %.lr.ph252.preheader.new

.lr.ph252.preheader.new:                          ; preds = %.lr.ph252.preheader
  %unroll_iter267 = and i64 %18, -2
  br label %.lr.ph252

.lr.ph252:                                        ; preds = %.lr.ph252._crit_edge.1, %.lr.ph252.preheader.new
  %indvars.iv255 = phi i64 [ 1, %.lr.ph252.preheader.new ], [ %.pre.1, %.lr.ph252._crit_edge.1 ]
  %61 = phi i32 [ %_QFEcmin.promoted, %.lr.ph252.preheader.new ], [ %82, %.lr.ph252._crit_edge.1 ]
  %niter268 = phi i64 [ 0, %.lr.ph252.preheader.new ], [ %niter268.next.1, %.lr.ph252._crit_edge.1 ]
  %.not221 = icmp eq i64 %indvars.iv255, %59
  %.pre = add nuw nsw i64 %indvars.iv255, 1
  br i1 %.not221, label %.lr.ph252._crit_edge, label %62

62:                                               ; preds = %.lr.ph252
  %sext = shl i64 %.pre, 32
  %63 = ashr exact i64 %sext, 32
  %64 = add nsw i64 %63, -1
  %65 = getelementptr i32, ptr %.unpack234, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !3
  %67 = add nsw i64 %indvars.iv255, -1
  %68 = getelementptr i32, ptr %.unpack234, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !3
  %70 = add i32 %66, %61
  %71 = sub i32 %70, %69
  store i32 %71, ptr @_QFEcmin, align 4, !tbaa !3
  br label %.lr.ph252._crit_edge

.lr.ph252._crit_edge:                             ; preds = %.lr.ph252, %62
  %72 = phi i32 [ %71, %62 ], [ %61, %.lr.ph252 ]
  %.not221.1 = icmp eq i64 %.pre, %59
  %.pre.1 = add nuw nsw i64 %indvars.iv255, 2
  br i1 %.not221.1, label %.lr.ph252._crit_edge.1, label %73

73:                                               ; preds = %.lr.ph252._crit_edge
  %sext.1 = shl i64 %.pre.1, 32
  %74 = ashr exact i64 %sext.1, 32
  %75 = add nsw i64 %74, -1
  %76 = getelementptr i32, ptr %.unpack234, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !3
  %78 = getelementptr i32, ptr %.unpack234, i64 %indvars.iv255
  %79 = load i32, ptr %78, align 4, !tbaa !3
  %80 = add i32 %77, %72
  %81 = sub i32 %80, %79
  store i32 %81, ptr @_QFEcmin, align 4, !tbaa !3
  br label %.lr.ph252._crit_edge.1

.lr.ph252._crit_edge.1:                           ; preds = %73, %.lr.ph252._crit_edge
  %82 = phi i32 [ %81, %73 ], [ %72, %.lr.ph252._crit_edge ]
  %niter268.next.1 = add i64 %niter268, 2
  %niter268.ncmp.1 = icmp eq i64 %niter268.next.1, %unroll_iter267
  br i1 %niter268.ncmp.1, label %._crit_edge253.loopexit.unr-lcssa, label %.lr.ph252

._crit_edge253.loopexit.unr-lcssa:                ; preds = %.lr.ph252._crit_edge.1, %.lr.ph252.preheader
  %.lcssa.ph = phi i32 [ undef, %.lr.ph252.preheader ], [ %82, %.lr.ph252._crit_edge.1 ]
  %indvars.iv255.unr = phi i64 [ 1, %.lr.ph252.preheader ], [ %.pre.1, %.lr.ph252._crit_edge.1 ]
  %.unr = phi i32 [ %_QFEcmin.promoted, %.lr.ph252.preheader ], [ %82, %.lr.ph252._crit_edge.1 ]
  %lcmp.mod265.not = icmp eq i64 %xtraiter264, 0
  br i1 %lcmp.mod265.not, label %._crit_edge253, label %.lr.ph252.epil

.lr.ph252.epil:                                   ; preds = %._crit_edge253.loopexit.unr-lcssa
  %.not221.epil = icmp eq i64 %indvars.iv255.unr, %59
  br i1 %.not221.epil, label %._crit_edge253, label %83

83:                                               ; preds = %.lr.ph252.epil
  %.pre.epil = shl i64 %indvars.iv255.unr, 32
  %sext.epil = add i64 %.pre.epil, 4294967296
  %84 = ashr exact i64 %sext.epil, 32
  %85 = add nsw i64 %84, -1
  %86 = getelementptr i32, ptr %.unpack234, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !3
  %88 = add nsw i64 %indvars.iv255.unr, -1
  %89 = getelementptr i32, ptr %.unpack234, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !3
  %91 = add i32 %87, %.unr
  %92 = sub i32 %91, %90
  store i32 %92, ptr @_QFEcmin, align 4, !tbaa !3
  br label %._crit_edge253

._crit_edge253:                                   ; preds = %._crit_edge253.loopexit.unr-lcssa, %83, %.lr.ph252.epil, %._crit_edge
  %93 = phi i32 [ %_QFEcmin.promoted, %._crit_edge ], [ %.lcssa.ph, %._crit_edge253.loopexit.unr-lcssa ], [ %92, %83 ], [ %.unr, %.lr.ph252.epil ]
  %.not = icmp eq i32 %spec.select247, 0
  br i1 %.not, label %96, label %94

94:                                               ; preds = %._crit_edge253
  %95 = add i32 %93, %57
  store i32 %95, ptr @_QFEcmin, align 4, !tbaa !3
  br label %96

96:                                               ; preds = %94, %._crit_edge253
  %97 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.0165d0c42fc54d811d7d10fd5a40e322, i32 33)
  %98 = load i32, ptr @_QFEcmin, align 4, !tbaa !3
  %99 = call i1 @_FortranAioOutputInteger32(ptr %97, i32 %98)
  %100 = call i32 @_FortranAioEndIoStatement(ptr %97)
  %101 = 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 ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) 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

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) }

!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}
