program abc160c
  integer :: k, n, a(200001), diff(200000)
  read *, k, n, a(1:n)
  diff(1:n) = a(2:n+1) - a(1:n)
  diff(n) = a(1) + k - a(n)
  print *, sum(diff(1:n)) - maxval(diff(1:n))
end program abc160c

; 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 [200001 x i32] undef
@_QFEdiff = internal unnamed_addr global [200000 x i32] undef
@_QQcl.4c9f13a6aaf573b9c9156b92f6d1f8f5 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1961/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %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.4c9f13a6aaf573b9c9156b92f6d1f8f5, i32 3)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 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
  store ptr @_QFEa, 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 %9, 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
  %10 = call i1 @_FortranAioInputDescriptor(ptr %4, ptr nonnull %1)
  %11 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %12 = load i32, ptr %3, align 4, !tbaa !3
  %.not57 = icmp slt i32 %12, 1
  br i1 %.not57, label %.._crit_edge_crit_edge, label %.lr.ph.preheader

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre59 = load i32, ptr @_QFEa, align 16, !tbaa !3
  br label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %13 = zext i32 %12 to i64
  %.pre = load i32, ptr @_QFEa, align 16, !tbaa !3
  %min.iters.check = icmp ult i32 %12, 8
  br i1 %min.iters.check, label %.lr.ph.preheader105, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %13, 4294967288
  %ind.end = and i64 %13, 7
  %vector.recur.init = insertelement <4 x i32> poison, i32 %.pre, i64 3
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ %wide.load63, %vector.body ]
  %14 = or i64 %index, 1
  %15 = getelementptr i32, ptr @_QFEa, i64 %14
  %wide.load = load <4 x i32>, ptr %15, align 4, !tbaa !3
  %16 = getelementptr i32, ptr %15, i64 4
  %wide.load63 = load <4 x i32>, ptr %16, align 4, !tbaa !3
  %17 = shufflevector <4 x i32> %vector.recur, <4 x i32> %wide.load, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %18 = shufflevector <4 x i32> %wide.load, <4 x i32> %wide.load63, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %19 = sub <4 x i32> %wide.load, %17
  %20 = sub <4 x i32> %wide.load63, %18
  %21 = getelementptr i32, ptr @_QFEdiff, i64 %index
  store <4 x i32> %19, ptr %21, align 16, !tbaa !3
  %22 = getelementptr i32, ptr %21, i64 4
  store <4 x i32> %20, ptr %22, align 16, !tbaa !3
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %13
  %vector.recur.extract = extractelement <4 x i32> %wide.load63, i64 3
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader105

.lr.ph.preheader105:                              ; preds = %.lr.ph.preheader, %middle.block
  %scalar.recur.ph = phi i32 [ %vector.recur.extract, %middle.block ], [ %.pre, %.lr.ph.preheader ]
  %.ph106 = phi i64 [ %ind.end, %middle.block ], [ %13, %.lr.ph.preheader ]
  %.ph107 = phi i64 [ %n.vec, %middle.block ], [ 0, %.lr.ph.preheader ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader105, %.lr.ph
  %scalar.recur = phi i32 [ %28, %.lr.ph ], [ %scalar.recur.ph, %.lr.ph.preheader105 ]
  %24 = phi i64 [ %31, %.lr.ph ], [ %.ph106, %.lr.ph.preheader105 ]
  %25 = phi i64 [ %26, %.lr.ph ], [ %.ph107, %.lr.ph.preheader105 ]
  %26 = add nuw nsw i64 %25, 1
  %27 = getelementptr i32, ptr @_QFEa, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !3
  %29 = sub i32 %28, %scalar.recur
  %30 = getelementptr i32, ptr @_QFEdiff, i64 %25
  store i32 %29, ptr %30, align 4, !tbaa !3
  %31 = add nsw i64 %24, -1
  %32 = icmp ugt i64 %24, 1
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %.._crit_edge_crit_edge
  %33 = phi i32 [ %.pre59, %.._crit_edge_crit_edge ], [ %.pre, %middle.block ], [ %.pre, %.lr.ph ]
  %34 = load i32, ptr %2, align 4, !tbaa !3
  %35 = add i32 %34, %33
  %36 = sext i32 %12 to i64
  %37 = add nsw i64 %36, -1
  %38 = getelementptr [200001 x i32], ptr @_QFEa, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !3
  %40 = sub i32 %35, %39
  %41 = getelementptr [200000 x i32], ptr @_QFEdiff, i64 0, i64 %37
  store i32 %40, ptr %41, align 4, !tbaa !3
  %42 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.4c9f13a6aaf573b9c9156b92f6d1f8f5, i32 6)
  %43 = load i32, ptr %3, align 4, !tbaa !3
  %44 = call i32 @llvm.smax.i32(i32 %43, i32 0)
  %45 = zext i32 %44 to i64
  %.not = icmp slt i32 %43, 1
  br i1 %.not, label %_FortranAMaxvalInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader

.lr.ph.i.preheader:                               ; preds = %._crit_edge
  %min.iters.check66 = icmp ult i32 %44, 8
  br i1 %min.iters.check66, label %.lr.ph.i.preheader99, label %vector.ph67

vector.ph67:                                      ; preds = %.lr.ph.i.preheader
  %n.vec69 = and i64 %45, 2147483640
  br label %vector.body72

vector.body72:                                    ; preds = %vector.body72, %vector.ph67
  %index73 = phi i64 [ 0, %vector.ph67 ], [ %index.next77, %vector.body72 ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph67 ], [ %49, %vector.body72 ]
  %vec.phi74 = phi <4 x i32> [ zeroinitializer, %vector.ph67 ], [ %50, %vector.body72 ]
  %46 = shl i64 %index73, 2
  %47 = getelementptr i8, ptr @_QFEdiff, i64 %46
  %wide.load75 = load <4 x i32>, ptr %47, align 16, !tbaa !3
  %48 = getelementptr i32, ptr %47, i64 4
  %wide.load76 = load <4 x i32>, ptr %48, align 16, !tbaa !3
  %49 = add <4 x i32> %wide.load75, %vec.phi
  %50 = add <4 x i32> %wide.load76, %vec.phi74
  %index.next77 = add nuw i64 %index73, 8
  %51 = icmp eq i64 %index.next77, %n.vec69
  br i1 %51, label %middle.block64, label %vector.body72, !llvm.loop !13

middle.block64:                                   ; preds = %vector.body72
  %bin.rdx = add <4 x i32> %50, %49
  %52 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n71 = icmp eq i64 %n.vec69, %45
  br i1 %cmp.n71, label %.lr.ph.i41.preheader, label %.lr.ph.i.preheader99

.lr.ph.i.preheader99:                             ; preds = %.lr.ph.i.preheader, %middle.block64
  %.ph100 = phi i32 [ 0, %.lr.ph.i.preheader ], [ %52, %middle.block64 ]
  %.ph101 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec69, %middle.block64 ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader99, %.lr.ph.i
  %53 = phi i32 [ %58, %.lr.ph.i ], [ %.ph100, %.lr.ph.i.preheader99 ]
  %54 = phi i64 [ %59, %.lr.ph.i ], [ %.ph101, %.lr.ph.i.preheader99 ]
  %55 = shl i64 %54, 2
  %56 = getelementptr i8, ptr @_QFEdiff, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !3
  %58 = add i32 %57, %53
  %59 = add nuw nsw i64 %54, 1
  %exitcond.not.i = icmp eq i64 %59, %45
  br i1 %exitcond.not.i, label %.lr.ph.i41.preheader, label %.lr.ph.i, !llvm.loop !14

.lr.ph.i41.preheader:                             ; preds = %.lr.ph.i, %middle.block64
  %.lcssa61 = phi i32 [ %52, %middle.block64 ], [ %58, %.lr.ph.i ]
  %min.iters.check80 = icmp ult i32 %44, 8
  br i1 %min.iters.check80, label %.lr.ph.i41.preheader94, label %vector.ph81

vector.ph81:                                      ; preds = %.lr.ph.i41.preheader
  %n.vec83 = and i64 %45, 2147483640
  br label %vector.body86

vector.body86:                                    ; preds = %vector.body86, %vector.ph81
  %index87 = phi i64 [ 0, %vector.ph81 ], [ %index.next92, %vector.body86 ]
  %vec.phi88 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph81 ], [ %63, %vector.body86 ]
  %vec.phi89 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph81 ], [ %64, %vector.body86 ]
  %60 = shl i64 %index87, 2
  %61 = getelementptr i8, ptr @_QFEdiff, i64 %60
  %wide.load90 = load <4 x i32>, ptr %61, align 16, !tbaa !3
  %62 = getelementptr i32, ptr %61, i64 4
  %wide.load91 = load <4 x i32>, ptr %62, align 16, !tbaa !3
  %63 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load90, <4 x i32> %vec.phi88)
  %64 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load91, <4 x i32> %vec.phi89)
  %index.next92 = add nuw i64 %index87, 8
  %65 = icmp eq i64 %index.next92, %n.vec83
  br i1 %65, label %middle.block78, label %vector.body86, !llvm.loop !15

middle.block78:                                   ; preds = %vector.body86
  %rdx.minmax.select = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %63, <4 x i32> %64)
  %66 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %rdx.minmax.select)
  %cmp.n85 = icmp eq i64 %n.vec83, %45
  br i1 %cmp.n85, label %_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit, label %.lr.ph.i41.preheader94

.lr.ph.i41.preheader94:                           ; preds = %.lr.ph.i41.preheader, %middle.block78
  %.ph = phi i32 [ -2147483648, %.lr.ph.i41.preheader ], [ %66, %middle.block78 ]
  %.ph95 = phi i64 [ 0, %.lr.ph.i41.preheader ], [ %n.vec83, %middle.block78 ]
  br label %.lr.ph.i41

.lr.ph.i41:                                       ; preds = %.lr.ph.i41.preheader94, %.lr.ph.i41
  %67 = phi i32 [ %72, %.lr.ph.i41 ], [ %.ph, %.lr.ph.i41.preheader94 ]
  %68 = phi i64 [ %73, %.lr.ph.i41 ], [ %.ph95, %.lr.ph.i41.preheader94 ]
  %69 = shl i64 %68, 2
  %70 = getelementptr i8, ptr @_QFEdiff, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !3
  %72 = call i32 @llvm.smax.i32(i32 %71, i32 %67)
  %73 = add nuw nsw i64 %68, 1
  %exitcond.not.i42 = icmp eq i64 %73, %45
  br i1 %exitcond.not.i42, label %_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit, label %.lr.ph.i41, !llvm.loop !16

_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit: ; preds = %.lr.ph.i41, %middle.block78
  %.lcssa = phi i32 [ %66, %middle.block78 ], [ %72, %.lr.ph.i41 ]
  %74 = sub i32 %.lcssa61, %.lcssa
  br label %_FortranAMaxvalInteger4x1_contract_simplified.exit

_FortranAMaxvalInteger4x1_contract_simplified.exit: ; preds = %_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit, %._crit_edge
  %75 = phi i32 [ %74, %_FortranAMaxvalInteger4x1_contract_simplified.exit.loopexit ], [ -2147483648, %._crit_edge ]
  %76 = call i1 @_FortranAioOutputInteger32(ptr %42, i32 %75)
  %77 = call i32 @_FortranAioEndIoStatement(ptr %42)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #0

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

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

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

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