; LLVM IR from nsccgz-storage/nvlsm :: util/histogram.ll (ZNK7leveldb9Histogram10PercentileEd)

; 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.leveldb::Histogram" = type { double, double, double, double, double, [154 x double] }

@_ZN7leveldb9Histogram12kBucketLimitE = external dso_local constant [154 x double], 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZNK7leveldb9Histogram10PercentileEd(ptr noundef nonnull align 8 dereferenceable(1272) %0, double noundef %1) #2 align 2 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = getelementptr inbounds %"class.leveldb::Histogram", ptr %16, i32 0, i32 2
  %18 = load double, ptr %17, align 8, !tbaa !11
  %19 = load double, ptr %5, align 8, !tbaa !9
  %20 = fdiv double %19, 1.000000e+02
  %21 = fmul double %18, %20
  store double %21, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %22

22:                                               ; preds = %92, %2
  %23 = load i32, ptr %8, align 4, !tbaa !13
  %24 = icmp slt i32 %23, 154
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 2, ptr %9, align 4
  br label %95

26:                                               ; preds = %22
  %27 = getelementptr inbounds %"class.leveldb::Histogram", ptr %16, i32 0, i32 5
  %28 = load i32, ptr %8, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [154 x double], ptr %27, i64 0, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = load double, ptr %7, align 8, !tbaa !9
  %33 = fadd double %32, %31
  store double %33, ptr %7, align 8, !tbaa !9
  %34 = load double, ptr %7, align 8, !tbaa !9
  %35 = load double, ptr %6, align 8, !tbaa !9
  %36 = fcmp oge double %34, %35
  br i1 %36, label %37, label %91

37:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %38 = load i32, ptr %8, align 4, !tbaa !13
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %37
  br label %47

41:                                               ; preds = %37
  %42 = load i32, ptr %8, align 4, !tbaa !13
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [154 x double], ptr @_ZN7leveldb9Histogram12kBucketLimitE, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %41, %40
  %48 = phi double [ 0.000000e+00, %40 ], [ %46, %41 ]
  store double %48, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %49 = load i32, ptr %8, align 4, !tbaa !13
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [154 x double], ptr @_ZN7leveldb9Histogram12kBucketLimitE, i64 0, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !9
  store double %52, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %53 = load double, ptr %7, align 8, !tbaa !9
  %54 = getelementptr inbounds %"class.leveldb::Histogram", ptr %16, i32 0, i32 5
  %55 = load i32, ptr %8, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [154 x double], ptr %54, i64 0, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = fsub double %53, %58
  store double %59, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %60 = load double, ptr %7, align 8, !tbaa !9
  store double %60, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %61 = load double, ptr %6, align 8, !tbaa !9
  %62 = load double, ptr %12, align 8, !tbaa !9
  %63 = fsub double %61, %62
  %64 = load double, ptr %13, align 8, !tbaa !9
  %65 = load double, ptr %12, align 8, !tbaa !9
  %66 = fsub double %64, %65
  %67 = fdiv double %63, %66
  store double %67, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %68 = load double, ptr %10, align 8, !tbaa !9
  %69 = load double, ptr %11, align 8, !tbaa !9
  %70 = load double, ptr %10, align 8, !tbaa !9
  %71 = fsub double %69, %70
  %72 = load double, ptr %14, align 8, !tbaa !9
  %73 = call double @llvm.fmuladd.f64(double %71, double %72, double %68)
  store double %73, ptr %15, align 8, !tbaa !9
  %74 = load double, ptr %15, align 8, !tbaa !9
  %75 = getelementptr inbounds %"class.leveldb::Histogram", ptr %16, i32 0, i32 0
  %76 = load double, ptr %75, align 8, !tbaa !15
  %77 = fcmp olt double %74, %76
  br i1 %77, label %78, label %81

78:                                               ; preds = %47
  %79 = getelementptr inbounds %"class.leveldb::Histogram", ptr %16, i32 0, i32 0
  %80 = load double, ptr %79, align 8, !tbaa !15
  store double %80, ptr %15, align 8, !tbaa !9
  br label %81

81:                                               ; preds = %78, %47
  %82 = load double, ptr %15, align 8, !tbaa !9
  %83 = getelementptr inbounds %"class.leveldb::Histogram", ptr %16, i32 0, i32 1
  %84 = load double, ptr %83, align 8, !tbaa !16
  %85 = fcmp ogt double %82, %84
  br i1 %85, label %86, label %89

86:                                               ; preds = %81
  %87 = getelementptr inbounds %"class.leveldb::Histogram", ptr %16, i32 0, i32 1
  %88 = load double, ptr %87, align 8, !tbaa !16
  store double %88, ptr %15, align 8, !tbaa !9
  br label %89

89:                                               ; preds = %86, %81
  %90 = load double, ptr %15, align 8, !tbaa !9
  store double %90, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %95

91:                                               ; preds = %26
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %8, align 4, !tbaa !13
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %8, align 4, !tbaa !13
  br label %22, !llvm.loop !17

95:                                               ; preds = %89, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %96 = load i32, ptr %9, align 4
  switch i32 %96, label %100 [
    i32 2, label %97
  ]

97:                                               ; preds = %95
  %98 = getelementptr inbounds %"class.leveldb::Histogram", ptr %16, i32 0, i32 1
  %99 = load double, ptr %98, align 8, !tbaa !16
  store double %99, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %100

100:                                              ; preds = %97, %95
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %101 = load double, ptr %3, align 8
  ret double %101
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTSN7leveldb9HistogramE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@_ZN7leveldb9Histogram12kBucketLimitE = external dso_local local_unnamed_addr constant [154 x double], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef double @_ZNK7leveldb9Histogram10PercentileEd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(1272) %0, double noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = fdiv double %1, 1.000000e+02
  %6 = fmul double %5, %4
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load double, ptr %7, align 8, !tbaa !10
  %9 = fadd double %8, 0.000000e+00
  %10 = fcmp ult double %8, %6
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph.1:                                         ; preds = %.lr.ph
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv67, 2
  %exitcond.1 = icmp eq i64 %indvars.iv.next.1, 154
  br i1 %exitcond.1, label %.loopexit.loopexit, label %11, !llvm.loop !11

11:                                               ; preds = %.lr.ph.1
  %12 = getelementptr inbounds [154 x double], ptr %7, i64 0, i64 %indvars.iv.next.1
  %13 = load double, ptr %12, align 8, !tbaa !10
  %14 = fadd double %41, %13
  %15 = fcmp ult double %14, %6
  br i1 %15, label %.lr.ph, label %._crit_edge.loopexit.split.loop.exit, !llvm.loop !11

._crit_edge.loopexit.split.loop.exit:             ; preds = %11
  %16 = icmp ugt i64 %indvars.iv67, 151
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.split.loop.exit, %.lr.ph, %2
  %indvars.iv.lcssa = phi i64 [ 0, %2 ], [ %indvars.iv.next.1, %._crit_edge.loopexit.split.loop.exit ], [ %indvars.iv.next, %.lr.ph ]
  %.lcssa63 = phi i1 [ false, %2 ], [ %16, %._crit_edge.loopexit.split.loop.exit ], [ false, %.lr.ph ]
  %.lcssa61 = phi double [ %8, %2 ], [ %13, %._crit_edge.loopexit.split.loop.exit ], [ %40, %.lr.ph ]
  %.lcssa = phi double [ %9, %2 ], [ %14, %._crit_edge.loopexit.split.loop.exit ], [ %41, %.lr.ph ]
  %17 = icmp eq i64 %indvars.iv.lcssa, 0
  br i1 %17, label %23, label %18

18:                                               ; preds = %._crit_edge
  %19 = add nuw i64 %indvars.iv.lcssa, 4294967295
  %20 = and i64 %19, 4294967295
  %21 = getelementptr inbounds [154 x double], ptr @_ZN7leveldb9Histogram12kBucketLimitE, i64 0, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !10
  br label %23

23:                                               ; preds = %._crit_edge, %18
  %24 = phi double [ %22, %18 ], [ 0.000000e+00, %._crit_edge ]
  %25 = getelementptr inbounds [154 x double], ptr @_ZN7leveldb9Histogram12kBucketLimitE, i64 0, i64 %indvars.iv.lcssa
  %26 = load double, ptr %25, align 8, !tbaa !10
  %27 = fsub double %.lcssa, %.lcssa61
  %28 = fsub double %6, %27
  %29 = fsub double %.lcssa, %27
  %30 = fdiv double %28, %29
  %31 = fsub double %26, %24
  %32 = tail call double @llvm.fmuladd.f64(double %31, double %30, double %24)
  %33 = load double, ptr %0, align 8, !tbaa !13
  %34 = fcmp olt double %32, %33
  %.0 = select i1 %34, double %33, double %32
  %35 = getelementptr inbounds i8, ptr %0, i64 8
  %36 = load double, ptr %35, align 8
  %37 = fcmp ogt double %.0, %36
  %.1 = select i1 %37, double %36, double %.0
  br label %.loopexit

.lr.ph:                                           ; preds = %2, %11
  %38 = phi double [ %14, %11 ], [ %9, %2 ]
  %indvars.iv67 = phi i64 [ %indvars.iv.next.1, %11 ], [ 0, %2 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv67, 1
  %39 = getelementptr inbounds [154 x double], ptr %7, i64 0, i64 %indvars.iv.next
  %40 = load double, ptr %39, align 8, !tbaa !10
  %41 = fadd double %38, %40
  %42 = fcmp ult double %41, %6
  br i1 %42, label %.lr.ph.1, label %._crit_edge, !llvm.loop !11

.loopexit.loopexit:                               ; preds = %.lr.ph.1
  %43 = icmp ugt i64 %indvars.iv67, 151
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load double, ptr %.phi.trans.insert, align 8
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %23
  %44 = phi double [ %36, %23 ], [ %.pre, %.loopexit.loopexit ]
  %45 = phi i1 [ %.lcssa63, %23 ], [ %43, %.loopexit.loopexit ]
  %.026 = phi double [ %.1, %23 ], [ undef, %.loopexit.loopexit ]
  %.127 = select i1 %45, double %44, double %.026
  ret double %.127
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !7, i64 16}
!6 = !{!"_ZTSN7leveldb9HistogramE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !8, i64 40}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 0}


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