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

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN7leveldb9Histogram3AddEd(ptr noundef nonnull align 8 dereferenceable(1272) %0, double noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %7

7:                                                ; preds = %19, %2
  %8 = load i32, ptr %5, align 4, !tbaa !11
  %9 = icmp slt i32 %8, 153
  br i1 %9, label %10, label %17

10:                                               ; preds = %7
  %11 = load i32, ptr %5, align 4, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [154 x double], ptr @_ZN7leveldb9Histogram12kBucketLimitE, i64 0, i64 %12
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = load double, ptr %4, align 8, !tbaa !9
  %16 = fcmp ole double %14, %15
  br label %17

17:                                               ; preds = %10, %7
  %18 = phi i1 [ false, %7 ], [ %16, %10 ]
  br i1 %18, label %19, label %22

19:                                               ; preds = %17
  %20 = load i32, ptr %5, align 4, !tbaa !11
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %5, align 4, !tbaa !11
  br label %7, !llvm.loop !13

22:                                               ; preds = %17
  %23 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 5
  %24 = load i32, ptr %5, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [154 x double], ptr %23, i64 0, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !9
  %28 = fadd double %27, 1.000000e+00
  store double %28, ptr %26, align 8, !tbaa !9
  %29 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 0
  %30 = load double, ptr %29, align 8, !tbaa !15
  %31 = load double, ptr %4, align 8, !tbaa !9
  %32 = fcmp ogt double %30, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %22
  %34 = load double, ptr %4, align 8, !tbaa !9
  %35 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 0
  store double %34, ptr %35, align 8, !tbaa !15
  br label %36

36:                                               ; preds = %33, %22
  %37 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 1
  %38 = load double, ptr %37, align 8, !tbaa !17
  %39 = load double, ptr %4, align 8, !tbaa !9
  %40 = fcmp olt double %38, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %36
  %42 = load double, ptr %4, align 8, !tbaa !9
  %43 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 1
  store double %42, ptr %43, align 8, !tbaa !17
  br label %44

44:                                               ; preds = %41, %36
  %45 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 2
  %46 = load double, ptr %45, align 8, !tbaa !18
  %47 = fadd double %46, 1.000000e+00
  store double %47, ptr %45, align 8, !tbaa !18
  %48 = load double, ptr %4, align 8, !tbaa !9
  %49 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 3
  %50 = load double, ptr %49, align 8, !tbaa !19
  %51 = fadd double %50, %48
  store double %51, ptr %49, align 8, !tbaa !19
  %52 = load double, ptr %4, align 8, !tbaa !9
  %53 = load double, ptr %4, align 8, !tbaa !9
  %54 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 4
  %55 = load double, ptr %54, align 8, !tbaa !20
  %56 = call double @llvm.fmuladd.f64(double %52, double %53, double %55)
  store double %56, ptr %54, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTSN7leveldb9HistogramE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40}
!17 = !{!16, !10, i64 8}
!18 = !{!16, !10, i64 16}
!19 = !{!16, !10, i64 24}
!20 = !{!16, !10, i64 32}


; 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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN7leveldb9Histogram3AddEd(ptr nocapture noundef nonnull align 8 dereferenceable(1272) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  br label %3

3:                                                ; preds = %15, %2
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next.2, %15 ]
  %4 = getelementptr inbounds [154 x double], ptr @_ZN7leveldb9Histogram12kBucketLimitE, i64 0, i64 %indvars.iv
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = fcmp ugt double %5, %1
  br i1 %6, label %.critedge, label %7

7:                                                ; preds = %3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = getelementptr inbounds [154 x double], ptr @_ZN7leveldb9Histogram12kBucketLimitE, i64 0, i64 %indvars.iv.next
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fcmp ugt double %9, %1
  br i1 %10, label %.critedge, label %11

11:                                               ; preds = %7
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %12 = getelementptr inbounds [154 x double], ptr @_ZN7leveldb9Histogram12kBucketLimitE, i64 0, i64 %indvars.iv.next.1
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = fcmp ugt double %13, %1
  br i1 %14, label %.critedge, label %15

15:                                               ; preds = %11
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %exitcond.not.2 = icmp eq i64 %indvars.iv.next.2, 153
  br i1 %exitcond.not.2, label %.critedge, label %3, !llvm.loop !9

.critedge:                                        ; preds = %15, %11, %7, %3
  %.0.lcssa = phi i64 [ %indvars.iv, %3 ], [ %indvars.iv.next, %7 ], [ %indvars.iv.next.1, %11 ], [ 153, %15 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = and i64 %.0.lcssa, 4294967295
  %18 = getelementptr inbounds [154 x double], ptr %16, i64 0, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = fadd double %19, 1.000000e+00
  store double %20, ptr %18, align 8, !tbaa !5
  %21 = load double, ptr %0, align 8, !tbaa !11
  %22 = fcmp ogt double %21, %1
  br i1 %22, label %23, label %24

23:                                               ; preds = %.critedge
  store double %1, ptr %0, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %23, %.critedge
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load double, ptr %25, align 8, !tbaa !13
  %27 = fcmp olt double %26, %1
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store double %1, ptr %25, align 8, !tbaa !13
  br label %29

29:                                               ; preds = %28, %24
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load <2 x double>, ptr %30, align 8, !tbaa !5
  %32 = insertelement <2 x double> <double 1.000000e+00, double poison>, double %1, i64 1
  %33 = fadd <2 x double> %31, %32
  store <2 x double> %33, ptr %30, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %0, i64 32
  %35 = load double, ptr %34, align 8, !tbaa !14
  %36 = tail call double @llvm.fmuladd.f64(double %1, double %1, double %35)
  store double %36, ptr %34, align 8, !tbaa !14
  ret void
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 speculatable willreturn memory(none) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN7leveldb9HistogramE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 32}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass