; LLVM IR from eyangch/competitive-programming :: CSES/Dynamic_Programming/rectangle_cutting.ll (Z3dfsii)

; 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 [501 x [501 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %87

15:                                               ; preds = %2
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [501 x [501 x i32]], ptr @dp, i64 0, i64 %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [501 x i32], ptr %18, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = xor i32 %22, -1
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %15
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [501 x [501 x i32]], ptr @dp, i64 0, i64 %27
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [501 x i32], ptr %28, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %3, align 4
  br label %87

33:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1000000000, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sub nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %53, %33
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %56

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = call noundef i32 @_Z3dfsii(i32 noundef %41, i32 noundef %42)
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = sub nsw i32 %44, %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = call noundef i32 @_Z3dfsii(i32 noundef %46, i32 noundef %47)
  %49 = add nsw i32 %43, %48
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %8, align 4, !tbaa !5
  %51 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %53

53:                                               ; preds = %40
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %7, align 4, !tbaa !5
  br label %36, !llvm.loop !9

56:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = sub nsw i32 %57, 1
  store i32 %58, ptr %9, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %76, %56
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = icmp sgt i32 %60, 0
  br i1 %61, label %63, label %62

62:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %79

63:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = load i32, ptr %9, align 4, !tbaa !5
  %66 = call noundef i32 @_Z3dfsii(i32 noundef %64, i32 noundef %65)
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = sub nsw i32 %68, %69
  %71 = call noundef i32 @_Z3dfsii(i32 noundef %67, i32 noundef %70)
  %72 = add nsw i32 %66, %71
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %10, align 4, !tbaa !5
  %74 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %75 = load i32, ptr %74, align 4, !tbaa !5
  store i32 %75, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %76

76:                                               ; preds = %63
  %77 = load i32, ptr %9, align 4, !tbaa !5
  %78 = add nsw i32 %77, -1
  store i32 %78, ptr %9, align 4, !tbaa !5
  br label %59, !llvm.loop !11

79:                                               ; preds = %62
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [501 x [501 x i32]], ptr @dp, i64 0, i64 %82
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [501 x i32], ptr %83, i64 0, i64 %85
  store i32 %80, ptr %86, align 4, !tbaa !5
  store i32 %80, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %87

87:                                               ; preds = %79, %25, %14
  %88 = load i32, ptr %3, align 4
  ret i32 %88
}

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

; 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)) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}
!11 = distinct !{!11, !10}


; 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 [501 x [501 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = icmp eq i32 %0, %1
  br i1 %6, label %33, label %7

7:                                                ; preds = %2
  %8 = sext i32 %0 to i64
  %9 = sext i32 %1 to i64
  %10 = getelementptr inbounds [501 x [501 x i32]], ptr @dp, i64 0, i64 %8, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not = icmp eq i32 %11, -1
  br i1 %.not, label %12, label %33

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 1000000000, ptr %3, align 4, !tbaa !5
  %13 = icmp sgt i32 %0, 1
  br i1 %13, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %12
  %14 = phi i32 [ 1000000000, %12 ], [ %22, %.lr.ph ]
  %15 = icmp sgt i32 %1, 1
  br i1 %15, label %.lr.ph31, label %._crit_edge

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.025.in29 = phi i32 [ %.025, %.lr.ph ], [ %0, %12 ]
  %.025 = add nsw i32 %.025.in29, -1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %16 = call noundef i32 @_Z3dfsii(i32 noundef %.025, i32 noundef %1)
  %17 = sub nsw i32 %0, %.025
  %18 = call noundef i32 @_Z3dfsii(i32 noundef %17, i32 noundef %1)
  %19 = add i32 %16, 1
  %20 = add i32 %19, %18
  store i32 %20, ptr %4, align 4, !tbaa !5
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  %23 = icmp ugt i32 %.025.in29, 2
  br i1 %23, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph31, %.preheader
  %24 = phi i32 [ %14, %.preheader ], [ %31, %.lr.ph31 ]
  store i32 %24, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %33

.lr.ph31:                                         ; preds = %.preheader, %.lr.ph31
  %.0.in30 = phi i32 [ %.0, %.lr.ph31 ], [ %1, %.preheader ]
  %.0 = add nsw i32 %.0.in30, -1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %25 = call noundef i32 @_Z3dfsii(i32 noundef %0, i32 noundef %.0)
  %26 = sub nsw i32 %1, %.0
  %27 = call noundef i32 @_Z3dfsii(i32 noundef %0, i32 noundef %26)
  %28 = add i32 %25, 1
  %29 = add i32 %28, %27
  store i32 %29, ptr %5, align 4, !tbaa !5
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  %32 = icmp ugt i32 %.0.in30, 2
  br i1 %32, label %.lr.ph31, label %._crit_edge, !llvm.loop !11

33:                                               ; preds = %7, %2, %._crit_edge
  %.026 = phi i32 [ %24, %._crit_edge ], [ 0, %2 ], [ %11, %7 ]
  ret i32 %.026
}

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

; 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

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

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


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