program abc17
 implicit none
 integer::K,N,i,ia,s
 integer,allocatable::a(:),b(:)
 read(*,*)K,N
 allocate(a(N),b(N))
 read(*,*)(a(i),i=1,N)
 do ia=1,N-1
  b(ia)=a(ia+1)-a(ia)
 end do
 b(N)=K-a(N)+a(1)
 s=sum(b)-maxval(b)
 print'(i0)',s
end program abc17
; 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
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEb.8 = internal unnamed_addr global i64 0
@_QQcl.2a1019e36016fa65b7f7e89150b9b291 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1966/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 i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.2a1019e36016fa65b7f7e89150b9b291, i32 5)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 4)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i32, ptr %2, 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 @_QFEa.0, align 8, !tbaa !7
  %12 = call ptr @malloc(i64 %10)
  store ptr %12, ptr @_QFEb.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEb.8, align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.2a1019e36016fa65b7f7e89150b9b291, i32 7)
  %14 = load i32, ptr %2, align 4, !tbaa !3
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph.preheader, label %._crit_edge

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

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

._crit_edge:                                      ; preds = %.lr.ph, %0
  %23 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %24 = load i32, ptr %2, align 4, !tbaa !3
  %25 = add i32 %24, -1
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph380, label %._crit_edge.._crit_edge381_crit_edge

._crit_edge.._crit_edge381_crit_edge:             ; preds = %._crit_edge
  %.unpack.pre = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack291.pre = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  br label %._crit_edge381

.lr.ph380:                                        ; preds = %._crit_edge
  %27 = zext i32 %25 to i64
  %.unpack327 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack339 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %min.iters.check = icmp ult i32 %25, 12
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph380
  %28 = add nsw i64 %27, -1
  %29 = trunc i64 %28 to i32
  %30 = icmp ugt i32 %29, 2147483645
  %31 = icmp ugt i64 %28, 4294967295
  %32 = or i1 %30, %31
  br i1 %32, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %33 = shl nuw nsw i64 %27, 2
  %uglygep = getelementptr i8, ptr %.unpack339, i64 %33
  %34 = add nuw nsw i64 %33, 4
  %uglygep392 = getelementptr i8, ptr %.unpack327, i64 %34
  %bound0 = icmp ult ptr %.unpack339, %uglygep392
  %bound1 = icmp ult ptr %.unpack327, %uglygep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %27, 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 ]
  %35 = shl i64 %index, 32
  %36 = ashr exact i64 %35, 32
  %37 = or i64 %36, 1
  %38 = getelementptr i32, ptr %.unpack327, i64 %37
  %wide.load = load <4 x i32>, ptr %38, align 4, !tbaa !3, !alias.scope !9
  %39 = getelementptr i32, ptr %38, i64 4
  %wide.load393 = load <4 x i32>, ptr %39, align 4, !tbaa !3, !alias.scope !9
  %40 = getelementptr i32, ptr %.unpack327, i64 %index
  %wide.load394 = load <4 x i32>, ptr %40, align 4, !tbaa !3, !alias.scope !9
  %41 = getelementptr i32, ptr %40, i64 4
  %wide.load395 = load <4 x i32>, ptr %41, align 4, !tbaa !3, !alias.scope !9
  %42 = sub <4 x i32> %wide.load, %wide.load394
  %43 = sub <4 x i32> %wide.load393, %wide.load395
  %44 = getelementptr i32, ptr %.unpack339, i64 %index
  store <4 x i32> %42, ptr %44, align 4, !tbaa !3, !alias.scope !12, !noalias !9
  %45 = getelementptr i32, ptr %44, i64 4
  store <4 x i32> %43, ptr %45, align 4, !tbaa !3, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 8
  %46 = icmp eq i64 %index.next, %n.vec
  br i1 %46, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %27
  br i1 %cmp.n, label %._crit_edge381.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %vector.memcheck, %vector.scevcheck, %.lr.ph380, %middle.block
  %indvars.iv.ph = phi i64 [ 1, %vector.memcheck ], [ 1, %vector.scevcheck ], [ 1, %.lr.ph380 ], [ %ind.end, %middle.block ]
  %xtraiter = and i64 %27, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.ph, 1
  %sext389.prol = shl i64 %indvars.iv.next.prol, 32
  %47 = ashr exact i64 %sext389.prol, 32
  %48 = add nsw i64 %47, -1
  %49 = getelementptr i32, ptr %.unpack327, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !3
  %51 = add nsw i64 %indvars.iv.ph, -1
  %52 = getelementptr i32, ptr %.unpack327, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !3
  %54 = sub i32 %50, %53
  %55 = add nsw i64 %indvars.iv.ph, -1
  %56 = getelementptr i32, ptr %.unpack339, i64 %55
  store i32 %54, ptr %56, align 4, !tbaa !3
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %57 = icmp eq i64 %indvars.iv.ph, %27
  br i1 %57, label %._crit_edge381.loopexit, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext389 = shl i64 %indvars.iv.next, 32
  %58 = ashr exact i64 %sext389, 32
  %59 = add nsw i64 %58, -1
  %60 = getelementptr i32, ptr %.unpack327, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !3
  %62 = add i64 %indvars.iv, -1
  %63 = getelementptr i32, ptr %.unpack327, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !3
  %65 = sub i32 %61, %64
  %66 = add i64 %indvars.iv, -1
  %67 = getelementptr i32, ptr %.unpack339, i64 %66
  store i32 %65, ptr %67, align 4, !tbaa !3
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %sext389.1 = shl i64 %indvars.iv.next.1, 32
  %68 = ashr exact i64 %sext389.1, 32
  %69 = add nsw i64 %68, -1
  %70 = getelementptr i32, ptr %.unpack327, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !3
  %72 = getelementptr i32, ptr %.unpack327, i64 %indvars.iv
  %73 = load i32, ptr %72, align 4, !tbaa !3
  %74 = sub i32 %71, %73
  %75 = getelementptr i32, ptr %.unpack339, i64 %indvars.iv
  store i32 %74, ptr %75, align 4, !tbaa !3
  %exitcond384.not.1 = icmp eq i64 %indvars.iv.next, %27
  br i1 %exitcond384.not.1, label %._crit_edge381.loopexit, label %scalar.ph, !llvm.loop !17

._crit_edge381.loopexit:                          ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %.pre = load i32, ptr %2, align 4, !tbaa !3
  br label %._crit_edge381

._crit_edge381:                                   ; preds = %._crit_edge.._crit_edge381_crit_edge, %._crit_edge381.loopexit
  %.unpack291 = phi ptr [ %.unpack291.pre, %._crit_edge.._crit_edge381_crit_edge ], [ %.unpack339, %._crit_edge381.loopexit ]
  %76 = phi i32 [ %24, %._crit_edge.._crit_edge381_crit_edge ], [ %.pre, %._crit_edge381.loopexit ]
  %.unpack = phi ptr [ %.unpack.pre, %._crit_edge.._crit_edge381_crit_edge ], [ %.unpack327, %._crit_edge381.loopexit ]
  %77 = load i32, ptr %1, align 4, !tbaa !3
  %78 = sext i32 %76 to i64
  %79 = add nsw i64 %78, -1
  %80 = getelementptr i32, ptr %.unpack, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !3
  %82 = sub i32 %77, %81
  %83 = load i32, ptr %.unpack, align 4, !tbaa !3
  %84 = add i32 %82, %83
  %85 = add nsw i64 %78, -1
  %86 = getelementptr i32, ptr %.unpack291, i64 %85
  store i32 %84, ptr %86, align 4, !tbaa !3
  %.unpack310.unpack.unpack312 = load i64, ptr @_QFEb.8, align 8, !tbaa !7
  %87 = icmp sgt i64 %.unpack310.unpack.unpack312, 0
  br i1 %87, label %.lr.ph.i.preheader, label %_FortranAMaxvalInteger4x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge381
  %min.iters.check398 = icmp ult i64 %.unpack310.unpack.unpack312, 8
  br i1 %min.iters.check398, label %.lr.ph.i.preheader431, label %vector.ph399

vector.ph399:                                     ; preds = %.lr.ph.i.preheader
  %n.vec401 = and i64 %.unpack310.unpack.unpack312, -8
  br label %vector.body404

vector.body404:                                   ; preds = %vector.body404, %vector.ph399
  %index405 = phi i64 [ 0, %vector.ph399 ], [ %index.next409, %vector.body404 ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph399 ], [ %91, %vector.body404 ]
  %vec.phi406 = phi <4 x i32> [ zeroinitializer, %vector.ph399 ], [ %92, %vector.body404 ]
  %88 = shl i64 %index405, 2
  %89 = getelementptr i8, ptr %.unpack291, i64 %88
  %wide.load407 = load <4 x i32>, ptr %89, align 4, !tbaa !3
  %90 = getelementptr i32, ptr %89, i64 4
  %wide.load408 = load <4 x i32>, ptr %90, align 4, !tbaa !3
  %91 = add <4 x i32> %wide.load407, %vec.phi
  %92 = add <4 x i32> %wide.load408, %vec.phi406
  %index.next409 = add nuw i64 %index405, 8
  %93 = icmp eq i64 %index.next409, %n.vec401
  br i1 %93, label %middle.block396, label %vector.body404, !llvm.loop !18

middle.block396:                                  ; preds = %vector.body404
  %bin.rdx = add <4 x i32> %92, %91
  %94 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n403 = icmp eq i64 %.unpack310.unpack.unpack312, %n.vec401
  br i1 %cmp.n403, label %.lr.ph.i363.preheader, label %.lr.ph.i.preheader431

.lr.ph.i.preheader431:                            ; preds = %.lr.ph.i.preheader, %middle.block396
  %.ph432 = phi i32 [ 0, %.lr.ph.i.preheader ], [ %94, %middle.block396 ]
  %.ph433 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec401, %middle.block396 ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader431, %.lr.ph.i
  %95 = phi i32 [ %100, %.lr.ph.i ], [ %.ph432, %.lr.ph.i.preheader431 ]
  %96 = phi i64 [ %101, %.lr.ph.i ], [ %.ph433, %.lr.ph.i.preheader431 ]
  %97 = shl i64 %96, 2
  %98 = getelementptr i8, ptr %.unpack291, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !3
  %100 = add i32 %99, %95
  %101 = add nuw nsw i64 %96, 1
  %exitcond.not.i = icmp eq i64 %101, %.unpack310.unpack.unpack312
  br i1 %exitcond.not.i, label %.lr.ph.i363.preheader, label %.lr.ph.i, !llvm.loop !19

.lr.ph.i363.preheader:                            ; preds = %.lr.ph.i, %middle.block396
  %.lcssa391 = phi i32 [ %94, %middle.block396 ], [ %100, %.lr.ph.i ]
  %min.iters.check412 = icmp ult i64 %.unpack310.unpack.unpack312, 8
  br i1 %min.iters.check412, label %.lr.ph.i363.preheader426, label %vector.ph413

vector.ph413:                                     ; preds = %.lr.ph.i363.preheader
  %n.vec415 = and i64 %.unpack310.unpack.unpack312, -8
  br label %vector.body418

vector.body418:                                   ; preds = %vector.body418, %vector.ph413
  %index419 = phi i64 [ 0, %vector.ph413 ], [ %index.next424, %vector.body418 ]
  %vec.phi420 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph413 ], [ %105, %vector.body418 ]
  %vec.phi421 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph413 ], [ %106, %vector.body418 ]
  %102 = shl i64 %index419, 2
  %103 = getelementptr i8, ptr %.unpack291, i64 %102
  %wide.load422 = load <4 x i32>, ptr %103, align 4, !tbaa !3
  %104 = getelementptr i32, ptr %103, i64 4
  %wide.load423 = load <4 x i32>, ptr %104, align 4, !tbaa !3
  %105 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load422, <4 x i32> %vec.phi420)
  %106 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load423, <4 x i32> %vec.phi421)
  %index.next424 = add nuw i64 %index419, 8
  %107 = icmp eq i64 %index.next424, %n.vec415
  br i1 %107, label %middle.block410, label %vector.body418, !llvm.loop !20

middle.block410:                                  ; preds = %vector.body418
  %rdx.minmax.select = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %105, <4 x i32> %106)
  %108 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %rdx.minmax.select)
  %cmp.n417 = icmp eq i64 %.unpack310.unpack.unpack312, %n.vec415
  br i1 %cmp.n417, label %_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit, label %.lr.ph.i363.preheader426

.lr.ph.i363.preheader426:                         ; preds = %.lr.ph.i363.preheader, %middle.block410
  %.ph = phi i32 [ -2147483648, %.lr.ph.i363.preheader ], [ %108, %middle.block410 ]
  %.ph427 = phi i64 [ 0, %.lr.ph.i363.preheader ], [ %n.vec415, %middle.block410 ]
  br label %.lr.ph.i363

.lr.ph.i363:                                      ; preds = %.lr.ph.i363.preheader426, %.lr.ph.i363
  %109 = phi i32 [ %114, %.lr.ph.i363 ], [ %.ph, %.lr.ph.i363.preheader426 ]
  %110 = phi i64 [ %115, %.lr.ph.i363 ], [ %.ph427, %.lr.ph.i363.preheader426 ]
  %111 = shl i64 %110, 2
  %112 = getelementptr i8, ptr %.unpack291, i64 %111
  %113 = load i32, ptr %112, align 4, !tbaa !3
  %114 = call i32 @llvm.smax.i32(i32 %113, i32 %109)
  %115 = add nuw nsw i64 %110, 1
  %exitcond.not.i364 = icmp eq i64 %115, %.unpack310.unpack.unpack312
  br i1 %exitcond.not.i364, label %_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit, label %.lr.ph.i363, !llvm.loop !21

_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit: ; preds = %.lr.ph.i363, %middle.block410
  %.lcssa = phi i32 [ %108, %middle.block410 ], [ %114, %.lr.ph.i363 ]
  %116 = sub i32 %.lcssa391, %.lcssa
  br label %_FortranAMaxvalInteger4x1_contract_simplified.exit

_FortranAMaxvalInteger4x1_contract_simplified.exit: ; preds = %_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit, %._crit_edge381
  %117 = phi i32 [ %116, %_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit ], [ -2147483648, %._crit_edge381 ]
  %118 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.2a1019e36016fa65b7f7e89150b9b291, i32 13)
  %119 = call i1 @_FortranAioOutputInteger32(ptr %118, i32 %117)
  %120 = call i32 @_FortranAioEndIoStatement(ptr %118)
  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 @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

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

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

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

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 willreturn memory(none) }
attributes #3 = { 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}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15, !16}
!19 = distinct !{!19, !16, !15}
!20 = distinct !{!20, !15, !16}
!21 = distinct !{!21, !16, !15}
