program aaa

integer :: n, i
integer,allocatable,dimension(:) :: h, dp

read*, n
allocate(h(n))
allocate(dp(n))
read*, h

dp=0
dp(1)=0
dp(2)=abs(h(2)-h(1))

if(n==2) then
write(*,'(i0)') dp(2)
return
end if

do i=3, n
dp(i)=min(dp(i-2)+abs(h(i-2)-h(i)),dp(i-1)+abs(h(i-1)-h(i)))
end do

write(*,'(i0)') 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
@_QFEdp.7 = internal unnamed_addr global i64 1
@_QFEdp.8 = internal unnamed_addr global i64 0
@_QFEh.0 = internal unnamed_addr global ptr null
@_QFEh.8 = internal unnamed_addr global i64 0
@_QQcl.9a4f516ef67bc4234d537cfd63e17432 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5150/source.f\00"
@_QQcl.16373402fa3425c6e46827601abb88fa = linkonce constant [76 x i8] c"array left hand side must be allocated when the right hand side is a scalar\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 { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9a4f516ef67bc4234d537cfd63e17432, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEh.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEh.8, align 8, !tbaa !7
  %11 = call ptr @malloc(i64 %9)
  store ptr %11, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEdp.7, align 8, !tbaa !7
  store i64 %8, ptr @_QFEdp.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9a4f516ef67bc4234d537cfd63e17432, i32 9)
  %.unpack = load ptr, ptr @_QFEh.0, align 8, !tbaa !7
  %.unpack425.unpack.unpack427 = load i64, ptr @_QFEh.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 %.unpack425.unpack.unpack427, 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
  %13 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %.unpack430 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack437.unpack.unpack439 = load i64, ptr @_QFEdp.8, align 8, !tbaa !7
  %.not = icmp eq ptr %.unpack430, null
  br i1 %.not, label %17, label %.preheader

.preheader:                                       ; preds = %0
  %15 = icmp sgt i64 %.unpack437.unpack.unpack439, 0
  br i1 %15, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %16 = shl nuw i64 %.unpack437.unpack.unpack439, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 4 %.unpack430, i8 0, i64 %16, i1 false), !tbaa !3
  br label %.loopexit

17:                                               ; preds = %0
  %18 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.9a4f516ef67bc4234d537cfd63e17432, i32 11)
  %.unpack533.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %19 = icmp eq i64 %.unpack437.unpack.unpack439, 0
  %20 = select i1 %19, i64 1, i64 %.unpack533.unpack.unpack
  store ptr null, ptr @_QFEdp.0, align 8, !tbaa !7
  store i64 %20, ptr @_QFEdp.7, align 8, !tbaa !7
  store i64 %.unpack437.unpack.unpack439, ptr @_QFEdp.8, align 8, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %.preheader, %17
  %.unpack449.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %21 = sub i64 1, %.unpack449.unpack.unpack
  %22 = getelementptr i32, ptr %.unpack430, i64 %21
  store i32 0, ptr %22, align 4, !tbaa !3
  %.unpack454 = load ptr, ptr @_QFEh.0, align 8, !tbaa !7
  %23 = getelementptr i32, ptr %.unpack454, i64 1
  %24 = load i32, ptr %23, align 4, !tbaa !3
  %25 = load i32, ptr %.unpack454, align 4, !tbaa !3
  %26 = sub i32 %24, %25
  %27 = call i32 @llvm.abs.i32(i32 %26, i1 false)
  %28 = sub i64 2, %.unpack449.unpack.unpack
  %29 = getelementptr i32, ptr %.unpack430, i64 %28
  store i32 %27, ptr %29, align 4, !tbaa !3
  %30 = load i32, ptr %2, align 4, !tbaa !3
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %35, label %39

common.ret:                                       ; preds = %._crit_edge, %35
  %.sink552 = phi ptr [ %70, %._crit_edge ], [ %38, %35 ]
  %.sink550 = phi ptr [ %66, %._crit_edge ], [ %36, %35 ]
  %32 = load i32, ptr %.sink552, align 4, !tbaa !3
  %33 = call i1 @_FortranAioOutputInteger32(ptr %.sink550, i32 %32)
  %34 = call i32 @_FortranAioEndIoStatement(ptr %.sink550)
  ret void

35:                                               ; preds = %.loopexit
  %36 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.9a4f516ef67bc4234d537cfd63e17432, i32 16)
  %.unpack514 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack521.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %37 = sub i64 2, %.unpack521.unpack.unpack
  %38 = getelementptr i32, ptr %.unpack514, i64 %37
  br label %common.ret

39:                                               ; preds = %.loopexit
  %40 = icmp sgt i32 %30, 2
  br i1 %40, label %.lr.ph547.preheader, label %._crit_edge

.lr.ph547.preheader:                              ; preds = %39
  %41 = zext i32 %30 to i64
  %42 = shl i64 %.unpack449.unpack.unpack, 2
  %43 = sub i64 8, %42
  %uglygep = getelementptr i8, ptr %.unpack430, i64 %43
  %load_initial = load i32, ptr %uglygep, align 4
  br label %.lr.ph547

.lr.ph547:                                        ; preds = %.lr.ph547.preheader, %.lr.ph547
  %store_forwarded = phi i32 [ %load_initial, %.lr.ph547.preheader ], [ %63, %.lr.ph547 ]
  %indvars.iv = phi i64 [ 3, %.lr.ph547.preheader ], [ %indvars.iv.next, %.lr.ph547 ]
  %44 = add nsw i64 %indvars.iv, -2
  %45 = sub i64 %44, %.unpack449.unpack.unpack
  %46 = getelementptr i32, ptr %.unpack430, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !3
  %48 = add nsw i64 %indvars.iv, -3
  %49 = getelementptr i32, ptr %.unpack454, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !3
  %51 = add nsw i64 %indvars.iv, -1
  %52 = getelementptr i32, ptr %.unpack454, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !3
  %54 = sub i32 %50, %53
  %55 = call i32 @llvm.abs.i32(i32 %54, i1 false)
  %56 = add i32 %55, %47
  %57 = add nsw i64 %indvars.iv, -2
  %58 = getelementptr i32, ptr %.unpack454, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !3
  %60 = sub i32 %59, %53
  %61 = call i32 @llvm.abs.i32(i32 %60, i1 false)
  %62 = add i32 %61, %store_forwarded
  %63 = call i32 @llvm.smin.i32(i32 %56, i32 %62)
  %64 = sub i64 %indvars.iv, %.unpack449.unpack.unpack
  %65 = getelementptr i32, ptr %.unpack430, i64 %64
  store i32 %63, ptr %65, align 4, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %41
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph547

._crit_edge:                                      ; preds = %.lr.ph547, %39
  %66 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.9a4f516ef67bc4234d537cfd63e17432, i32 24)
  %.unpack478 = load ptr, ptr @_QFEdp.0, align 8, !tbaa !7
  %.unpack485.unpack.unpack = load i64, ptr @_QFEdp.7, align 8, !tbaa !7
  %67 = load i32, ptr %2, align 4, !tbaa !3
  %68 = sext i32 %67 to i64
  %69 = sub i64 %68, %.unpack485.unpack.unpack
  %70 = getelementptr i32, ptr %.unpack478, i64 %69
  br label %common.ret
}

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 {} @_FortranAReportFatalUserError(ptr, ptr, i32) 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

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

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

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

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) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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