; LLVM IR from upupming/algorithm :: kick-start/2020/2020G-D.ll (Z10getSumOfDpii)

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

%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, std::map<int, double>>, std::_Select1st<std::pair<const int, std::map<int, double>>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, std::map<int, double>>, std::_Select1st<std::pair<const int, std::map<int, double>>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@dp = external dso_local global [5050 x [5050 x double]], align 16
@m = external dso_local global %"class.std::map", align 8

; 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 uwtable
define dso_local noundef double @_Z10getSumOfDpii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = call noundef i64 @_ZNKSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %10, label %18

10:                                               ; preds = %2
  %11 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %12 = call noundef i64 @_ZNKSt3mapIidSt4lessIiESaISt4pairIKidEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) %11, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %18

14:                                               ; preds = %10
  %15 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %16 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %15, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %17 = load double, ptr %16, align 8, !tbaa !9
  store double %17, ptr %3, align 8
  br label %52

18:                                               ; preds = %10, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %19 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %19, ptr %7, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %44, %18
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %47

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %27
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5050 x double], ptr %28, i64 0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %35
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [5050 x double], ptr %36, i64 0, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = fadd double %32, %40
  %42 = load double, ptr %6, align 8, !tbaa !9
  %43 = fadd double %42, %41
  store double %43, ptr %6, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %25
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %7, align 4, !tbaa !5
  br label %20, !llvm.loop !11

47:                                               ; preds = %24
  %48 = load double, ptr %6, align 8, !tbaa !9
  %49 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %49, ptr noundef nonnull align 4 dereferenceable(4) %5)
  store double %48, ptr %50, align 8, !tbaa !9
  %51 = load double, ptr %6, align 8, !tbaa !9
  store double %51, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %52

52:                                               ; preds = %47, %14
  %53 = load double, ptr %3, align 8
  ret double %53
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIidSt4lessIiESaISt4pairIKidEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

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

%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, std::map<int, double>>, std::_Select1st<std::pair<const int, std::map<int, double>>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, std::map<int, double>>, std::_Select1st<std::pair<const int, std::map<int, double>>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@dp = external dso_local local_unnamed_addr global [5050 x [5050 x double]], align 16
@m = external dso_local global %"class.std::map", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z10getSumOfDpii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = call noundef i64 @_ZNKSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %13, label %6

6:                                                ; preds = %2
  %7 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %8 = call noundef i64 @_ZNKSt3mapIidSt4lessIiESaISt4pairIKidEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48) %7, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %.not10 = icmp eq i64 %8, 0
  br i1 %.not10, label %._crit_edge14, label %9

._crit_edge14:                                    ; preds = %6
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  br label %13

9:                                                ; preds = %6
  %10 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %11 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %10, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %12 = load double, ptr %11, align 8, !tbaa !9
  br label %42

13:                                               ; preds = %._crit_edge14, %2
  %14 = phi i32 [ %.pre, %._crit_edge14 ], [ %1, %2 ]
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp slt i32 %15, %14
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %13
  %17 = sext i32 %15 to i64
  %18 = sext i32 %14 to i64
  %19 = sub nsw i64 %18, %17
  %xtraiter = and i64 %19, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %.lr.ph
  %20 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %17, i64 %17
  %21 = load double, ptr %20, align 8, !tbaa !9
  %indvars.iv.next.prol = add nsw i64 %17, 1
  %22 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %indvars.iv.next.prol, i64 %18
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = fadd double %21, %23
  %25 = fadd double %24, 0.000000e+00
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph
  %.lcssa.unr = phi double [ poison, %.lr.ph ], [ %25, %.prol.loopexit.unr-lcssa ]
  %indvars.iv.unr = phi i64 [ %17, %.lr.ph ], [ %indvars.iv.next.prol, %.prol.loopexit.unr-lcssa ]
  %.0711.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %25, %.prol.loopexit.unr-lcssa ]
  %26 = add nsw i64 %18, -1
  %27 = icmp eq i64 %26, %17
  br i1 %27, label %._crit_edge, label %.lr.ph.new

._crit_edge:                                      ; preds = %.prol.loopexit, %.lr.ph.new, %13
  %.07.lcssa = phi double [ 0.000000e+00, %13 ], [ %.lcssa.unr, %.prol.loopexit ], [ %41, %.lr.ph.new ]
  %28 = call noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @m, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %28, ptr noundef nonnull align 4 dereferenceable(4) %4)
  store double %.07.lcssa, ptr %29, align 8, !tbaa !9
  br label %42

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph.new ], [ %indvars.iv.unr, %.prol.loopexit ]
  %.0711 = phi double [ %41, %.lr.ph.new ], [ %.0711.unr, %.prol.loopexit ]
  %30 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %17, i64 %indvars.iv
  %31 = load double, ptr %30, align 8, !tbaa !9
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %32 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %indvars.iv.next, i64 %18
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = fadd double %31, %33
  %35 = fadd double %.0711, %34
  %36 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %17, i64 %indvars.iv.next
  %37 = load double, ptr %36, align 8, !tbaa !9
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %38 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %indvars.iv.next.1, i64 %18
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = fadd double %37, %39
  %41 = fadd double %35, %40
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %18
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph.new, !llvm.loop !11

42:                                               ; preds = %._crit_edge, %9
  %.08 = phi double [ %12, %9 ], [ %.07.lcssa, %._crit_edge ]
  ret double %.08
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(48) ptr @_ZNSt3mapIiS_IidSt4lessIiESaISt4pairIKidEEES1_SaIS2_IS3_S6_EEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNKSt3mapIidSt4lessIiESaISt4pairIKidEEE5countERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt3mapIidSt4lessIiESaISt4pairIKidEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

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

!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 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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