; LLVM IR from AlgoGenesis/C :: Dynamic Programming/FROM JUMP (program)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
declare dso_local i32 @min(i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @minEnergy(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = call ptr @llvm.stacksave.p0()
  store ptr %12, ptr %5, align 8
  %13 = alloca i32, i64 %11, align 16
  store i64 %11, ptr %6, align 8
  %14 = getelementptr inbounds i32, ptr %13, i64 0
  store i32 0, ptr %14, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %72, %2
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %75

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %13, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %31, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sub nsw i32 %30, %36
  %38 = call i32 @llvm.abs.i32(i32 %37, i1 true)
  %39 = add nsw i32 %25, %38
  store i32 %39, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = icmp sgt i32 %40, 1
  br i1 %41, label %42, label %62

42:                                               ; preds = %20
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 2
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %13, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %48, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load ptr, ptr %4, align 8, !tbaa !9
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = sub nsw i32 %54, 2
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %53, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sub nsw i32 %52, %58
  %60 = call i32 @llvm.abs.i32(i32 %59, i1 true)
  %61 = add nsw i32 %47, %60
  br label %64

62:                                               ; preds = %20
  %63 = load i32, ptr %8, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %62, %42
  %65 = phi i32 [ %61, %42 ], [ %63, %62 ]
  store i32 %65, ptr %9, align 4, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = call i32 @min(i32 noundef %66, i32 noundef %67)
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i32, ptr %13, i64 %70
  store i32 %68, ptr %71, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %72

72:                                               ; preds = %64
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %7, align 4, !tbaa !5
  br label %15, !llvm.loop !11

75:                                               ; preds = %19
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = sub nsw i32 %76, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i32, ptr %13, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = load ptr, ptr %5, align 8
  call void @llvm.stackrestore.p0(ptr %81)
  ret i32 %80
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
declare dso_local i32 @min(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @minEnergy(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = zext i32 %0 to i64
  %4 = alloca i32, i64 %3, align 16
  store i32 0, ptr %4, align 16, !tbaa !5
  %5 = icmp sgt i32 %0, 1
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sub nsw i32 %7, %8
  %10 = tail call i32 @llvm.abs.i32(i32 %9, i1 true)
  %11 = tail call i32 @min(i32 noundef %10, i32 noundef %10)
  %12 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %11, ptr %12, align 4, !tbaa !5
  %exitcond.peel.not = icmp eq i32 %0, 2
  br i1 %exitcond.peel.not, label %._crit_edge, label %.lr.ph.peel.next

.lr.ph.peel.next:                                 ; preds = %.lr.ph.preheader
  %invariant.gep = getelementptr i8, ptr %1, i64 -4
  br label %17

._crit_edge:                                      ; preds = %17, %.lr.ph.preheader, %2
  %13 = sext i32 %0 to i64
  %14 = getelementptr i32, ptr %4, i64 %13
  %15 = getelementptr i8, ptr %14, i64 -4
  %16 = load i32, ptr %15, align 4, !tbaa !5
  ret i32 %16

17:                                               ; preds = %.lr.ph.peel.next, %17
  %18 = phi i32 [ %11, %.lr.ph.peel.next ], [ %33, %17 ]
  %indvars.iv = phi i64 [ 2, %.lr.ph.peel.next ], [ %indvars.iv.next, %17 ]
  %19 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv
  %21 = load i32, ptr %gep, align 4, !tbaa !5
  %22 = sub nsw i32 %20, %21
  %23 = tail call i32 @llvm.abs.i32(i32 %22, i1 true)
  %24 = add nsw i32 %23, %18
  %25 = add nsw i64 %indvars.iv, -2
  %26 = getelementptr inbounds i32, ptr %1, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sub nsw i32 %20, %27
  %29 = tail call i32 @llvm.abs.i32(i32 %28, i1 true)
  %30 = getelementptr inbounds i32, ptr %4, i64 %25
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %29, %31
  %33 = tail call i32 @min(i32 noundef %24, i32 noundef %32)
  %34 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv
  store i32 %33, ptr %34, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %3
  br i1 %exitcond.not, label %._crit_edge, label %17, !llvm.loop !9
}

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

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass