program struck_out
  implicit none
  integer :: n, m, k, i, j, l, s, t
  integer(8) :: a(100000), dp(0:100000,300), deq(100000), nxt
  a = 0_8
  dp = 0_8
  deq = 0_8
  read(*,*) n, m, k
  read(*,*) a(1:n)
  dp(1:n,1) = a(1:n)
  do j = 2, k
    s = 1
    t = 1
    do i = 1, n
      if (s.eq.t) then
        dp(i,j) = -1_8
      else
        dp(i,j) = int(j,8)*a(i)+dp(deq(s),j-1)
        if (i+1-deq(s).gt.m) s = s+1
      end if
      nxt = dp(i,j-1)
      if (nxt.ne.-1_8) then
        do while (s.ne.t.and.dp(deq(t-1),j-1).lt.nxt)
          t = t-1
        end do
        deq(t) = i
        t = t+1
      end if
    end do
  end do
  write(*,'(i0)') maxval(dp(1:n,k))
  stop
end program struck_out
; 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 [100000 x i64] undef
@_QFEdeq = internal unnamed_addr global [100000 x i64] undef
@_QFEdp = internal global [300 x [100001 x i64]] undef
@_QQcl.e673c905559b5124ed2ce12cc52c240e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7732/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #0 {
.preheader59.preheader:
  %0 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %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 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) @_QFEa, i8 0, i64 800000, i1 false), !tbaa !3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(240002400) @_QFEdp, i8 0, i64 240002400, i1 false), !tbaa !3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) @_QFEdeq, i8 0, i64 800000, i1 false), !tbaa !3
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e673c905559b5124ed2ce12cc52c240e, i32 8)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %4, i32 4)
  %7 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %3, i32 4)
  %8 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %2, i32 4)
  %9 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %10 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e673c905559b5124ed2ce12cc52c240e, i32 9)
  %11 = load i32, ptr %4, align 4, !tbaa !3
  %12 = call i32 @llvm.smax.i32(i32 %11, i32 0)
  %13 = zext i32 %12 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 8, 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 10, 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 %13, 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 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %14 = call i1 @_FortranAioInputDescriptor(ptr %10, ptr nonnull %1)
  %15 = call i32 @_FortranAioEndIoStatement(ptr %10)
  %16 = load i32, ptr %4, align 4, !tbaa !3
  %.not = icmp slt i32 %16, 1
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader59.preheader
  %17 = zext i32 %16 to i64
  %18 = shl nuw nsw i64 %17, 3
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 getelementptr inbounds ([300 x [100001 x i64]], ptr @_QFEdp, i64 0, i64 0, i64 1), ptr nonnull align 16 @_QFEa, i64 %18, i1 false), !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %.preheader59.preheader
  %19 = load i32, ptr %2, align 4, !tbaa !3
  %.05267 = add i32 %19, -1
  %20 = icmp sgt i32 %.05267, 0
  br i1 %20, label %.preheader57.lr.ph, label %._crit_edge70

.preheader57.lr.ph:                               ; preds = %._crit_edge
  %21 = icmp sgt i32 %16, 0
  %22 = load i32, ptr %3, align 4
  %23 = sext i32 %22 to i64
  br i1 %21, label %.preheader57.us, label %._crit_edge70

.preheader57.us:                                  ; preds = %.preheader57.lr.ph, %._crit_edge66.us
  %.05068.us = phi i32 [ %72, %._crit_edge66.us ], [ 2, %.preheader57.lr.ph ]
  %24 = sext i32 %.05068.us to i64
  %25 = add i32 %.05068.us, -1
  %26 = sext i32 %25 to i64
  %27 = add nsw i64 %26, -1
  %28 = add nsw i64 %24, -1
  br label %29

29:                                               ; preds = %.preheader57.us, %70
  %.064.us = phi i32 [ 1, %.preheader57.us ], [ %.2.us, %70 ]
  %.04763.us = phi i32 [ 1, %.preheader57.us ], [ %.148.us, %70 ]
  %.05161.us = phi i32 [ 1, %.preheader57.us ], [ %71, %70 ]
  %30 = icmp eq i32 %.04763.us, %.064.us
  %31 = sext i32 %.05161.us to i64
  br i1 %30, label %50, label %32

32:                                               ; preds = %29
  %33 = add nsw i64 %31, -1
  %34 = getelementptr [100000 x i64], ptr @_QFEa, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !3
  %36 = mul i64 %35, %24
  %37 = sext i32 %.04763.us to i64
  %38 = add nsw i64 %37, -1
  %39 = getelementptr [100000 x i64], ptr @_QFEdeq, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !3
  %41 = getelementptr [300 x [100001 x i64]], ptr @_QFEdp, i64 0, i64 %27, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !3
  %43 = add i64 %42, %36
  %44 = getelementptr [300 x [100001 x i64]], ptr @_QFEdp, i64 0, i64 %28, i64 %31
  store i64 %43, ptr %44, align 8, !tbaa !3
  %45 = add nuw i32 %.05161.us, 1
  %46 = sext i32 %45 to i64
  %47 = sub i64 %46, %40
  %48 = icmp sgt i64 %47, %23
  %49 = zext i1 %48 to i32
  %spec.select.us = add i32 %.04763.us, %49
  br label %52

50:                                               ; preds = %29
  %51 = getelementptr [300 x [100001 x i64]], ptr @_QFEdp, i64 0, i64 %28, i64 %31
  store i64 -1, ptr %51, align 8, !tbaa !3
  br label %52

52:                                               ; preds = %50, %32
  %.148.us = phi i32 [ %.064.us, %50 ], [ %spec.select.us, %32 ]
  %53 = getelementptr [300 x [100001 x i64]], ptr @_QFEdp, i64 0, i64 %27, i64 %31
  %54 = load i64, ptr %53, align 8, !tbaa !3
  %.not.us = icmp eq i64 %54, -1
  br i1 %.not.us, label %70, label %.preheader.us

.preheader.us:                                    ; preds = %52, %.preheader.us
  %.1.us = phi i32 [ %56, %.preheader.us ], [ %.064.us, %52 ]
  %55 = icmp ne i32 %.148.us, %.1.us
  %56 = add i32 %.1.us, -1
  %57 = sext i32 %56 to i64
  %58 = add nsw i64 %57, -1
  %59 = getelementptr [100000 x i64], ptr @_QFEdeq, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !3
  %61 = getelementptr [300 x [100001 x i64]], ptr @_QFEdp, i64 0, i64 %27, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !3
  %63 = icmp slt i64 %62, %54
  %64 = and i1 %55, %63
  br i1 %64, label %.preheader.us, label %65

65:                                               ; preds = %.preheader.us
  %66 = sext i32 %.1.us to i64
  %67 = add nsw i64 %66, -1
  %68 = getelementptr [100000 x i64], ptr @_QFEdeq, i64 0, i64 %67
  store i64 %31, ptr %68, align 8, !tbaa !3
  %69 = add i32 %.1.us, 1
  br label %70

70:                                               ; preds = %65, %52
  %.2.us = phi i32 [ %69, %65 ], [ %.064.us, %52 ]
  %71 = add nuw i32 %.05161.us, 1
  %exitcond.not = icmp eq i32 %.05161.us, %16
  br i1 %exitcond.not, label %._crit_edge66.us, label %29

._crit_edge66.us:                                 ; preds = %70
  %72 = add nuw i32 %.05068.us, 1
  %exitcond72.not = icmp eq i32 %.05068.us, %19
  br i1 %exitcond72.not, label %._crit_edge70, label %.preheader57.us

._crit_edge70:                                    ; preds = %._crit_edge66.us, %.preheader57.lr.ph, %._crit_edge
  %73 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.e673c905559b5124ed2ce12cc52c240e, i32 31)
  %74 = load i32, ptr %4, align 4, !tbaa !3
  %75 = load i32, ptr %2, align 4, !tbaa !3
  %76 = sext i32 %75 to i64
  %77 = call i32 @llvm.smax.i32(i32 %74, i32 0)
  %78 = zext i32 %77 to i64
  %79 = add nsw i64 %76, -1
  %80 = getelementptr [300 x [100001 x i64]], ptr @_QFEdp, i64 0, i64 %79, i64 1
  store ptr %80, ptr %0, align 8, !tbaa !7
  %.fca.1.gep30 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep30, align 8, !tbaa !7
  %.fca.2.gep32 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep32, align 8, !tbaa !7
  %.fca.3.gep34 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep34, align 4, !tbaa !7
  %.fca.4.gep36 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep36, align 1, !tbaa !7
  %.fca.5.gep38 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep38, align 2, !tbaa !7
  %.fca.6.gep40 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep40, align 1, !tbaa !7
  %.fca.7.0.0.gep42 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep42, align 8, !tbaa !7
  %.fca.7.0.1.gep44 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 1
  store i64 %78, ptr %.fca.7.0.1.gep44, align 8, !tbaa !7
  %.fca.7.0.2.gep46 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep46, align 8, !tbaa !7
  %81 = call i64 @_FortranAMaxvalInteger8x1_contract_simplified(ptr nonnull %0)
  %82 = call i1 @_FortranAioOutputInteger64(ptr %73, i64 %81)
  %83 = call i32 @_FortranAioEndIoStatement(ptr %73)
  %84 = 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 @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

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

define linkonce_odr i64 @_FortranAMaxvalInteger8x1_contract_simplified(ptr %0) local_unnamed_addr {
  %2 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 1
  %3 = load i64, ptr %2, align 8, !tbaa !7
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !7
  %6 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 2
  %7 = load i64, ptr %6, align 8, !tbaa !7
  %xtraiter = and i64 %3, 3
  %8 = icmp ult i64 %3, 4
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %3, -4
  br label %9

9:                                                ; preds = %9, %.lr.ph.new
  %10 = phi i64 [ -9223372036854775808, %.lr.ph.new ], [ %30, %9 ]
  %11 = phi i64 [ 0, %.lr.ph.new ], [ %31, %9 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %9 ]
  %12 = mul i64 %7, %11
  %13 = getelementptr i8, ptr %5, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !3
  %15 = tail call i64 @llvm.smax.i64(i64 %14, i64 %10)
  %16 = or i64 %11, 1
  %17 = mul i64 %7, %16
  %18 = getelementptr i8, ptr %5, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !3
  %20 = tail call i64 @llvm.smax.i64(i64 %19, i64 %15)
  %21 = or i64 %11, 2
  %22 = mul i64 %7, %21
  %23 = getelementptr i8, ptr %5, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !3
  %25 = tail call i64 @llvm.smax.i64(i64 %24, i64 %20)
  %26 = or i64 %11, 3
  %27 = mul i64 %7, %26
  %28 = getelementptr i8, ptr %5, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !3
  %30 = tail call i64 @llvm.smax.i64(i64 %29, i64 %25)
  %31 = add nuw nsw i64 %11, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %9, %.lr.ph
  %.lcssa4.ph = phi i64 [ undef, %.lr.ph ], [ %30, %9 ]
  %.unr = phi i64 [ -9223372036854775808, %.lr.ph ], [ %30, %9 ]
  %.unr5 = phi i64 [ 0, %.lr.ph ], [ %31, %9 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %32 = phi i64 [ %37, %.epil.preheader ], [ %.unr, %._crit_edge.loopexit.unr-lcssa ]
  %33 = phi i64 [ %38, %.epil.preheader ], [ %.unr5, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %34 = mul i64 %7, %33
  %35 = getelementptr i8, ptr %5, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !3
  %37 = tail call i64 @llvm.smax.i64(i64 %36, i64 %32)
  %38 = add nuw nsw i64 %33, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %1
  %.lcssa = phi i64 [ -9223372036854775808, %1 ], [ %.lcssa4.ph, %._crit_edge.loopexit.unr-lcssa ], [ %37, %.epil.preheader ]
  ret i64 %.lcssa
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { noreturn }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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.unroll.disable"}
