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

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z2okRKSt3mapIiiSt4lessIiESaISt4pairIKiiEEE(ptr noundef nonnull align 8 dereferenceable(48)) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z3dfsRSt3mapIiiSt4lessIiESaISt4pairIKiiEEEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %12 = add nsw i32 %11, 1
  %13 = icmp eq i32 %10, %12
  br i1 %13, label %14, label %21

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call noundef zeroext i1 @_Z2okRKSt3mapIiiSt4lessIiESaISt4pairIKiiEEE(ptr noundef nonnull align 8 dereferenceable(48) %15)
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = load i32, ptr @m, align 4, !tbaa !9
  %19 = sitofp i32 %18 to double
  store double %19, ptr %3, align 8
  br label %64

20:                                               ; preds = %14
  store double 0.000000e+00, ptr %3, align 8
  br label %64

21:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %49, %21
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = load i32, ptr @m, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %52

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %28, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  %35 = call noundef double @_Z3dfsRSt3mapIiiSt4lessIiESaISt4pairIKiiEEEi(ptr noundef nonnull align 8 dereferenceable(48) %32, i32 noundef %34)
  store double %35, ptr %9, align 8, !tbaa !11
  %36 = load double, ptr %9, align 8, !tbaa !11
  %37 = fcmp ogt double %36, 0.000000e+00
  br i1 %37, label %38, label %44

38:                                               ; preds = %27
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !9
  %41 = load double, ptr %9, align 8, !tbaa !11
  %42 = load double, ptr %6, align 8, !tbaa !11
  %43 = fadd double %42, %41
  store double %43, ptr %6, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %38, %27
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %45, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr %46, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %49

49:                                               ; preds = %44
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %8, align 4, !tbaa !9
  br label %22, !llvm.loop !13

52:                                               ; preds = %26
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %61

55:                                               ; preds = %52
  %56 = load double, ptr %6, align 8, !tbaa !11
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = sitofp i32 %57 to double
  %59 = fdiv double %56, %58
  %60 = fadd double %59, 1.000000e+00
  br label %62

61:                                               ; preds = %52
  br label %62

62:                                               ; preds = %61, %55
  %63 = phi double [ %60, %55 ], [ 1.000000e+00, %61 ]
  store double %63, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %64

64:                                               ; preds = %62, %20, %17
  %65 = load double, ptr %3, align 8
  ret double %65
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z2okRKSt3mapIiiSt4lessIiESaISt4pairIKiiEEE(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z3dfsRSt3mapIiiSt4lessIiESaISt4pairIKiiEEEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  %6 = icmp eq i32 %5, %1
  br i1 %6, label %7, label %12

7:                                                ; preds = %2
  %8 = tail call noundef zeroext i1 @_Z2okRKSt3mapIiiSt4lessIiESaISt4pairIKiiEEE(ptr noundef nonnull align 8 dereferenceable(48) %0)
  br i1 %8, label %9, label %35

9:                                                ; preds = %7
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = sitofp i32 %10 to double
  br label %35

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr @m, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  br label %19

.lr.ph:                                           ; preds = %12
  %15 = add nsw i32 %1, 1
  br label %20

._crit_edge:                                      ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  %.not = icmp eq i32 %.1, 0
  %16 = uitofp nneg i32 %.1 to double
  %17 = fdiv double %.115, %16
  %18 = fadd double %17, 1.000000e+00
  br i1 %.not, label %19, label %35

19:                                               ; preds = %._crit_edge.thread, %._crit_edge
  br label %35

20:                                               ; preds = %.lr.ph, %20
  %.01319 = phi i32 [ 0, %.lr.ph ], [ %.1, %20 ]
  %.01418 = phi double [ undef, %.lr.ph ], [ %.115, %20 ]
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %21, align 4, !tbaa !5
  %24 = call noundef double @_Z3dfsRSt3mapIiiSt4lessIiESaISt4pairIKiiEEEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %15)
  %25 = fcmp ogt double %24, 0.000000e+00
  %26 = fadd double %.01418, %24
  %.115 = select i1 %25, double %26, double %.01418
  %27 = zext i1 %25 to i32
  %.1 = add i32 %.01319, %27
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %28, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %20, label %._crit_edge, !llvm.loop !9

35:                                               ; preds = %19, %._crit_edge, %7, %9
  %.0 = phi double [ %11, %9 ], [ 0.000000e+00, %7 ], [ 1.000000e+00, %19 ], [ %18, %._crit_edge ]
  ret double %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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