; LLVM IR from ShahjalalShohag/code-library :: Dynamic Programming Optimizations/Divide and Conquer Optimization.ll (Z2yoiiiii)

; 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"

@dp = external dso_local global [810 x [4010 x i32]], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4costii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z2yoiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = icmp sgt i32 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  br label %102

21:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  %25 = sdiv i32 %24, 2
  store i32 %25, ptr %11, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [810 x [4010 x i32]], ptr @dp, i64 0, i64 %27
  %29 = load i32, ptr %11, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [4010 x i32], ptr %28, i64 0, i64 %30
  store i32 1000000000, ptr %31, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 -1, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %32 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %32, ptr %13, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %74, %21
  %34 = load i32, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = sub nsw i32 %35, 1
  store i32 %36, ptr %14, align 4, !tbaa !5
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp sle i32 %34, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br i1 %39, label %41, label %40

40:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %77

41:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [810 x [4010 x i32]], ptr @dp, i64 0, i64 %44
  %46 = load i32, ptr %13, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [4010 x i32], ptr %45, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %13, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %11, align 4, !tbaa !5
  %53 = call noundef i32 @_Z4costii(i32 noundef %51, i32 noundef %52)
  %54 = add nsw i32 %49, %53
  store i32 %54, ptr %15, align 4, !tbaa !5
  %55 = load i32, ptr %15, align 4, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [810 x [4010 x i32]], ptr @dp, i64 0, i64 %57
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [4010 x i32], ptr %58, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = icmp slt i32 %55, %62
  br i1 %63, label %64, label %73

64:                                               ; preds = %41
  %65 = load i32, ptr %15, align 4, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [810 x [4010 x i32]], ptr @dp, i64 0, i64 %67
  %69 = load i32, ptr %11, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [4010 x i32], ptr %68, i64 0, i64 %70
  store i32 %65, ptr %71, align 4, !tbaa !5
  %72 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %72, ptr %12, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %64, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %13, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %13, align 4, !tbaa !5
  br label %33, !llvm.loop !9

77:                                               ; preds = %40
  %78 = load i32, ptr %12, align 4, !tbaa !5
  %79 = icmp eq i32 %78, -1
  br i1 %79, label %80, label %87

80:                                               ; preds = %77
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = load i32, ptr %11, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  %84 = load i32, ptr %8, align 4, !tbaa !5
  %85 = load i32, ptr %9, align 4, !tbaa !5
  %86 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z2yoiiiii(i32 noundef %81, i32 noundef %83, i32 noundef %84, i32 noundef %85, i32 noundef %86)
  store i32 1, ptr %16, align 4
  br label %100

87:                                               ; preds = %77
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = load i32, ptr %11, align 4, !tbaa !5
  %91 = sub nsw i32 %90, 1
  %92 = load i32, ptr %9, align 4, !tbaa !5
  %93 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z2yoiiiii(i32 noundef %88, i32 noundef %89, i32 noundef %91, i32 noundef %92, i32 noundef %93)
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = load i32, ptr %11, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  %97 = load i32, ptr %8, align 4, !tbaa !5
  %98 = load i32, ptr %12, align 4, !tbaa !5
  %99 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z2yoiiiii(i32 noundef %94, i32 noundef %96, i32 noundef %97, i32 noundef %98, i32 noundef %99)
  store i32 0, ptr %16, align 4
  br label %100

100:                                              ; preds = %87, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %101 = load i32, ptr %16, align 4
  switch i32 %101, label %103 [
    i32 0, label %102
    i32 1, label %102
  ]

102:                                              ; preds = %100, %100, %20
  ret void

103:                                              ; preds = %100
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { mustprogress 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 #3 = { inlinehint mustprogress 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 #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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@dp = external dso_local local_unnamed_addr global [810 x [4010 x i32]], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4costii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z2yoiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %4, ptr %6, align 4, !tbaa !5
  %8 = icmp sgt i32 %1, %2
  br i1 %8, label %41, label %9

9:                                                ; preds = %5
  %10 = add nsw i32 %2, %1
  %11 = sdiv i32 %10, 2
  %12 = sext i32 %0 to i64
  %13 = sext i32 %11 to i64
  %14 = getelementptr inbounds [810 x [4010 x i32]], ptr @dp, i64 0, i64 %12, i64 %13
  store i32 1000000000, ptr %14, align 4, !tbaa !5
  %15 = add nsw i32 %11, -1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  store i32 %15, ptr %7, align 4, !tbaa !5
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %.not39 = icmp slt i32 %17, %3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  br i1 %.not39, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %18 = add nsw i32 %0, -1
  %19 = sext i32 %18 to i64
  %20 = sext i32 %3 to i64
  br label %22

._crit_edge:                                      ; preds = %32
  %21 = icmp eq i32 %.1, -1
  br i1 %21, label %._crit_edge.thread, label %38

22:                                               ; preds = %.lr.ph, %32
  %indvars.iv = phi i64 [ %20, %.lr.ph ], [ %indvars.iv.next, %32 ]
  %.041 = phi i32 [ -1, %.lr.ph ], [ %.1, %32 ]
  %23 = getelementptr inbounds [810 x [4010 x i32]], ptr @dp, i64 0, i64 %19, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %25 = trunc nsw i64 %indvars.iv.next to i32
  %26 = call noundef i32 @_Z4costii(i32 noundef %25, i32 noundef %11)
  %27 = add nsw i32 %26, %24
  %28 = load i32, ptr %14, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %32

30:                                               ; preds = %22
  store i32 %27, ptr %14, align 4, !tbaa !5
  %31 = trunc nsw i64 %indvars.iv to i32
  br label %32

32:                                               ; preds = %30, %22
  %.1 = phi i32 [ %31, %30 ], [ %.041, %22 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  store i32 %15, ptr %7, align 4, !tbaa !5
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %.not.not = icmp slt i64 %indvars.iv, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  br i1 %.not.not, label %22, label %._crit_edge, !llvm.loop !9

._crit_edge.thread:                               ; preds = %9, %._crit_edge
  %36 = add nsw i32 %11, 1
  %37 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z2yoiiiii(i32 noundef %0, i32 noundef %36, i32 noundef %2, i32 noundef %3, i32 noundef %37)
  br label %41

38:                                               ; preds = %._crit_edge
  call void @_Z2yoiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %15, i32 noundef %3, i32 noundef %.1)
  %39 = add nsw i32 %11, 1
  %40 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z2yoiiiii(i32 noundef %0, i32 noundef %39, i32 noundef %2, i32 noundef %.1, i32 noundef %40)
  br label %41

41:                                               ; preds = %._crit_edge.thread, %38, %5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { inlinehint mustprogress 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 #3 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass