!ref
!https://qiita.com/drken/items/dc53c683d6de8aeacf5a
      PROGRAM Frog2
      IMPLICIT NONE
      integer(16) :: n,k
      integer(16),allocatable :: h(:),dp(:)
      integer(16) :: i,j
      
      read*, n,k
      allocate( h(1:n) )
      read*, h(:)
      
      
      allocate( dp(1:n) )
      dp(:) = 10**9
      dp(1) = 0
      
      
      do i = 1,n
        do j = 1,k
          if( i+j>n ) cycle
          dp(i+j) = min( dp(i+j), dp(i)+abs( h(i+j)-h(i) ) )
        end do
      end do
      
      print*,dp(n)
      
      END PROGRAM
; 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"

@_QFEdp.0 = internal unnamed_addr global ptr null
@_QFEh.0 = internal unnamed_addr global ptr null
@_QFEh.8 = internal unnamed_addr global i64 0
@_QQcl.5e3f44e8065cbe674a1297f6742844ed = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5163/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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i128, align 8
  %3 = alloca i128, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.5e3f44e8065cbe674a1297f6742844ed, i32 9)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 16)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 16)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i128, ptr %3, align 8, !tbaa !3
  %9 = trunc i128 %8 to i64
  %10 = call i64 @llvm.smax.i64(i64 %9, i64 0)
  %11 = shl i64 %10, 4
  %12 = call ptr @malloc(i64 %11)
  store ptr %12, ptr @_QFEh.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEh.8, align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.5e3f44e8065cbe674a1297f6742844ed, i32 11)
  %.unpack = load ptr, ptr @_QFEh.0, align 8, !tbaa !7
  %.unpack261.unpack.unpack263 = load i64, ptr @_QFEh.8, align 8, !tbaa !7
  %14 = call i64 @llvm.smax.i64(i64 %.unpack261.unpack.unpack263, i64 0)
  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 16, 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 11, 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 %14, 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 16, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %15 = call i1 @_FortranAioInputDescriptor(ptr %13, ptr nonnull %1)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %17 = load i128, ptr %3, align 8, !tbaa !3
  %18 = trunc i128 %17 to i64
  %19 = call i64 @llvm.smax.i64(i64 %18, i64 0)
  %20 = shl i64 %19, 4
  %21 = call ptr @malloc(i64 %20)
  store ptr %21, ptr @_QFEdp.0, align 8, !tbaa !7
  %.not = icmp slt i64 %18, 1
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %22 = add nsw i64 %19, -1
  %xtraiter = and i64 %19, 3
  %23 = icmp ult i64 %22, 3
  br i1 %23, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %19, 9223372036854775804
  br label %.lr.ph

._crit_edge.thread:                               ; preds = %0
  store i128 0, ptr %21, align 8, !tbaa !3
  br label %._crit_edge328

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %24 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %32, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %25 = getelementptr i128, ptr %21, i64 %24
  store i128 1000000000, ptr %25, align 8, !tbaa !3
  %26 = or i64 %24, 1
  %27 = getelementptr i128, ptr %21, i64 %26
  store i128 1000000000, ptr %27, align 8, !tbaa !3
  %28 = or i64 %24, 2
  %29 = getelementptr i128, ptr %21, i64 %28
  store i128 1000000000, ptr %29, align 8, !tbaa !3
  %30 = or i64 %24, 3
  %31 = getelementptr i128, ptr %21, i64 %30
  store i128 1000000000, ptr %31, align 8, !tbaa !3
  %32 = add nuw nsw i64 %24, 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.unr-lcssa, label %.lr.ph

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %32, %.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.unr-lcssa, %.lr.ph.epil
  %33 = phi i64 [ %35, %.lr.ph.epil ], [ %.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %34 = getelementptr i128, ptr %21, i64 %33
  store i128 1000000000, ptr %34, align 8, !tbaa !3
  %35 = 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 %.lr.ph.epil, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  store i128 0, ptr %21, align 8, !tbaa !3
  %36 = icmp sgt i64 %18, 0
  br i1 %36, label %.lr.ph327, label %._crit_edge328

.lr.ph327:                                        ; preds = %._crit_edge
  %37 = load i128, ptr %2, align 8, !tbaa !3
  %38 = trunc i128 %37 to i64
  %39 = icmp sgt i64 %38, 0
  %.unpack311 = load ptr, ptr @_QFEh.0, align 8
  br i1 %39, label %.lr.ph324.us, label %._crit_edge328

.lr.ph324.us:                                     ; preds = %.lr.ph327, %._crit_edge325.us
  %40 = phi i64 [ %70, %._crit_edge325.us ], [ %18, %.lr.ph327 ]
  %41 = phi i128 [ %69, %._crit_edge325.us ], [ 1, %.lr.ph327 ]
  %42 = trunc i128 %41 to i64
  %43 = add i64 %42, -1
  %44 = getelementptr i128, ptr %21, i64 %43
  %45 = add i64 %42, -1
  %46 = getelementptr i128, ptr %.unpack311, i64 %45
  br label %47

47:                                               ; preds = %.lr.ph324.us, %65
  %48 = phi i64 [ %38, %.lr.ph324.us ], [ %67, %65 ]
  %49 = phi i128 [ 1, %.lr.ph324.us ], [ %66, %65 ]
  %50 = add nuw nsw i128 %49, %41
  %.not.us = icmp sgt i128 %50, %17
  br i1 %.not.us, label %65, label %51

51:                                               ; preds = %47
  %52 = trunc i128 %50 to i64
  %53 = add i64 %52, -1
  %54 = getelementptr i128, ptr %21, i64 %53
  %55 = load i128, ptr %54, align 8, !tbaa !3
  %56 = load i128, ptr %44, align 8, !tbaa !3
  %57 = add i64 %52, -1
  %58 = getelementptr i128, ptr %.unpack311, i64 %57
  %59 = load i128, ptr %58, align 8, !tbaa !3
  %60 = load i128, ptr %46, align 8, !tbaa !3
  %61 = sub i128 %59, %60
  %62 = call i128 @llvm.abs.i128(i128 %61, i1 false)
  %63 = add i128 %62, %56
  %64 = call i128 @llvm.smin.i128(i128 %55, i128 %63)
  store i128 %64, ptr %54, align 8, !tbaa !3
  br label %65

65:                                               ; preds = %51, %47
  %66 = add nuw nsw i128 %49, 1
  %67 = add nsw i64 %48, -1
  %68 = icmp sgt i64 %48, 1
  br i1 %68, label %47, label %._crit_edge325.us

._crit_edge325.us:                                ; preds = %65
  %69 = add nuw nsw i128 %41, 1
  %70 = add i64 %40, -1
  %71 = icmp sgt i64 %70, 0
  br i1 %71, label %.lr.ph324.us, label %._crit_edge328

._crit_edge328:                                   ; preds = %._crit_edge325.us, %.lr.ph327, %._crit_edge.thread, %._crit_edge
  %72 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.5e3f44e8065cbe674a1297f6742844ed, i32 26)
  %.unpack287 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %73 = load i128, ptr %3, align 8, !tbaa !3
  %74 = trunc i128 %73 to i64
  %75 = add i64 %74, -1
  %76 = getelementptr i128, ptr %.unpack287, i64 %75
  %77 = load i128, ptr %76, align 8, !tbaa !3
  %78 = call i1 @_FortranAioOutputInteger128(ptr %72, i128 %77)
  %79 = call i32 @_FortranAioEndIoStatement(ptr %72)
  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 i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

; Function Attrs: 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 i128 @llvm.abs.i128(i128, i1 immarg) #1

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { 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}
!10 = !{!"llvm.loop.unroll.disable"}
