; LLVM IR from sp-nitech/SPTK :: src/math/entropy_calculation.ll (ZNK4sptk18EntropyCalculation3RunERKSt6vectorIdSaIdEEPd)

; 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.sptk::EntropyCalculation" = type <{ ptr, i32, i32, i8, [7 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk18EntropyCalculation3RunERKSt6vectorIdSaIdEEPd(ptr noundef nonnull align 8 dereferenceable(17) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef %2) #0 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8
  %15 = getelementptr inbounds %"class.sptk::EntropyCalculation", ptr %14, i32 0, i32 3
  %16 = load i8, ptr %15, align 8, !tbaa !9, !range !14, !noundef !15
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %28

18:                                               ; preds = %3
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %19) #5
  %21 = getelementptr inbounds %"class.sptk::EntropyCalculation", ptr %14, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !16
  %23 = sext i32 %22 to i64
  %24 = icmp ne i64 %20, %23
  br i1 %24, label %28, label %25

25:                                               ; preds = %18
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = icmp eq ptr null, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %25, %18, %3
  store i1 false, ptr %4, align 1
  br label %115

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef 0) #5
  store ptr %31, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store double 0.000000e+00, ptr %9, align 8, !tbaa !17
  %32 = getelementptr inbounds %"class.sptk::EntropyCalculation", ptr %14, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !19
  switch i32 %33, label %109 [
    i32 0, label %34
    i32 1, label %59
    i32 2, label %84
  ]

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !20
  br label %35

35:                                               ; preds = %55, %34
  %36 = load i32, ptr %10, align 4, !tbaa !20
  %37 = getelementptr inbounds %"class.sptk::EntropyCalculation", ptr %14, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !16
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %58

41:                                               ; preds = %35
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load i32, ptr %10, align 4, !tbaa !20
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !17
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !20
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !17
  %52 = call noundef double @_ZN4sptk9FloorLog2Ed(double noundef %51)
  %53 = load double, ptr %9, align 8, !tbaa !17
  %54 = call double @llvm.fmuladd.f64(double %46, double %52, double %53)
  store double %54, ptr %9, align 8, !tbaa !17
  br label %55

55:                                               ; preds = %41
  %56 = load i32, ptr %10, align 4, !tbaa !20
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %10, align 4, !tbaa !20
  br label %35, !llvm.loop !21

58:                                               ; preds = %40
  br label %110

59:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !20
  br label %60

60:                                               ; preds = %80, %59
  %61 = load i32, ptr %11, align 4, !tbaa !20
  %62 = getelementptr inbounds %"class.sptk::EntropyCalculation", ptr %14, i32 0, i32 1
  %63 = load i32, ptr %62, align 8, !tbaa !16
  %64 = icmp slt i32 %61, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %83

66:                                               ; preds = %60
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = load i32, ptr %11, align 4, !tbaa !20
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %67, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !17
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load i32, ptr %11, align 4, !tbaa !20
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %72, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !17
  %77 = call noundef double @_ZN4sptk8FloorLogEd(double noundef %76)
  %78 = load double, ptr %9, align 8, !tbaa !17
  %79 = call double @llvm.fmuladd.f64(double %71, double %77, double %78)
  store double %79, ptr %9, align 8, !tbaa !17
  br label %80

80:                                               ; preds = %66
  %81 = load i32, ptr %11, align 4, !tbaa !20
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %11, align 4, !tbaa !20
  br label %60, !llvm.loop !23

83:                                               ; preds = %65
  br label %110

84:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !20
  br label %85

85:                                               ; preds = %105, %84
  %86 = load i32, ptr %12, align 4, !tbaa !20
  %87 = getelementptr inbounds %"class.sptk::EntropyCalculation", ptr %14, i32 0, i32 1
  %88 = load i32, ptr %87, align 8, !tbaa !16
  %89 = icmp slt i32 %86, %88
  br i1 %89, label %91, label %90

90:                                               ; preds = %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %108

91:                                               ; preds = %85
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load i32, ptr %12, align 4, !tbaa !20
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds double, ptr %92, i64 %94
  %96 = load double, ptr %95, align 8, !tbaa !17
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = load i32, ptr %12, align 4, !tbaa !20
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds double, ptr %97, i64 %99
  %101 = load double, ptr %100, align 8, !tbaa !17
  %102 = call noundef double @_ZN4sptk10FloorLog10Ed(double noundef %101)
  %103 = load double, ptr %9, align 8, !tbaa !17
  %104 = call double @llvm.fmuladd.f64(double %96, double %102, double %103)
  store double %104, ptr %9, align 8, !tbaa !17
  br label %105

105:                                              ; preds = %91
  %106 = load i32, ptr %12, align 4, !tbaa !20
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %12, align 4, !tbaa !20
  br label %85, !llvm.loop !24

108:                                              ; preds = %90
  br label %110

109:                                              ; preds = %29
  store i1 false, ptr %4, align 1
  store i32 1, ptr %13, align 4
  br label %114

110:                                              ; preds = %108, %83, %58
  %111 = load double, ptr %9, align 8, !tbaa !17
  %112 = fneg double %111
  %113 = load ptr, ptr %7, align 8, !tbaa !5
  store double %112, ptr %113, align 8, !tbaa !17
  store i1 true, ptr %4, align 1
  store i32 1, ptr %13, align 4
  br label %114

114:                                              ; preds = %110, %109
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %115

115:                                              ; preds = %114, %28
  %116 = load i1, ptr %4, align 1
  ret i1 %116
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

declare noundef double @_ZN4sptk9FloorLog2Ed(double noundef) #3

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

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

declare noundef double @_ZN4sptk8FloorLogEd(double noundef) #3

declare noundef double @_ZN4sptk10FloorLog10Ed(double noundef) #3

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 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 willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !13, i64 16}
!10 = !{!"_ZTSN4sptk18EntropyCalculationE", !11, i64 8, !12, i64 12, !13, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN4sptk18EntropyCalculation12EntropyUnitsE", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!10, !11, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!10, !12, i64 12}
!20 = !{!11, !11, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}
!24 = distinct !{!24, !22}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK4sptk18EntropyCalculation3RunERKSt6vectorIdSaIdEEPd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(17) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef writeonly %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i8, ptr %4, align 8, !tbaa !5, !range !12, !noundef !13
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %46

7:                                                ; preds = %3
  %8 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #4
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %11 = sext i32 %10 to i64
  %12 = icmp ne i64 %8, %11
  %13 = icmp eq ptr %2, null
  %or.cond = or i1 %13, %12
  br i1 %or.cond, label %46, label %14

14:                                               ; preds = %7
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef 0) #4
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  %17 = load i32, ptr %16, align 4, !tbaa !15
  switch i32 %17, label %46 [
    i32 0, label %.preheader
    i32 1, label %.preheader34
    i32 2, label %.preheader36
  ]

.preheader36:                                     ; preds = %14
  %18 = load i32, ptr %9, align 8, !tbaa !14
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph, label %.loopexit

.preheader34:                                     ; preds = %14
  %20 = load i32, ptr %9, align 8, !tbaa !14
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph42, label %.loopexit

.preheader:                                       ; preds = %14
  %22 = load i32, ptr %9, align 8, !tbaa !14
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph46, label %.loopexit

.lr.ph46:                                         ; preds = %.preheader, %.lr.ph46
  %indvars.iv56 = phi i64 [ %indvars.iv.next57, %.lr.ph46 ], [ 0, %.preheader ]
  %.03044 = phi double [ %27, %.lr.ph46 ], [ 0.000000e+00, %.preheader ]
  %24 = getelementptr inbounds double, ptr %15, i64 %indvars.iv56
  %25 = load double, ptr %24, align 8, !tbaa !16
  %26 = tail call noundef double @_ZN4sptk9FloorLog2Ed(double noundef %25)
  %27 = tail call double @llvm.fmuladd.f64(double %25, double %26, double %.03044)
  %indvars.iv.next57 = add nuw nsw i64 %indvars.iv56, 1
  %28 = load i32, ptr %9, align 8, !tbaa !14
  %29 = sext i32 %28 to i64
  %30 = icmp slt i64 %indvars.iv.next57, %29
  br i1 %30, label %.lr.ph46, label %.loopexit, !llvm.loop !18

.lr.ph42:                                         ; preds = %.preheader34, %.lr.ph42
  %indvars.iv53 = phi i64 [ %indvars.iv.next54, %.lr.ph42 ], [ 0, %.preheader34 ]
  %.140 = phi double [ %34, %.lr.ph42 ], [ 0.000000e+00, %.preheader34 ]
  %31 = getelementptr inbounds double, ptr %15, i64 %indvars.iv53
  %32 = load double, ptr %31, align 8, !tbaa !16
  %33 = tail call noundef double @_ZN4sptk8FloorLogEd(double noundef %32)
  %34 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %.140)
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %35 = load i32, ptr %9, align 8, !tbaa !14
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next54, %36
  br i1 %37, label %.lr.ph42, label %.loopexit, !llvm.loop !20

.lr.ph:                                           ; preds = %.preheader36, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader36 ]
  %.238 = phi double [ %41, %.lr.ph ], [ 0.000000e+00, %.preheader36 ]
  %38 = getelementptr inbounds double, ptr %15, i64 %indvars.iv
  %39 = load double, ptr %38, align 8, !tbaa !16
  %40 = tail call noundef double @_ZN4sptk10FloorLog10Ed(double noundef %39)
  %41 = tail call double @llvm.fmuladd.f64(double %39, double %40, double %.238)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = load i32, ptr %9, align 8, !tbaa !14
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next, %43
  br i1 %44, label %.lr.ph, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph42, %.lr.ph46, %.preheader36, %.preheader34, %.preheader
  %.3 = phi double [ 0.000000e+00, %.preheader ], [ 0.000000e+00, %.preheader34 ], [ 0.000000e+00, %.preheader36 ], [ %27, %.lr.ph46 ], [ %34, %.lr.ph42 ], [ %41, %.lr.ph ]
  %45 = fneg double %.3
  store double %45, ptr %2, align 8, !tbaa !16
  br label %46

46:                                               ; preds = %.loopexit, %14, %3, %7
  %.132 = phi i1 [ false, %7 ], [ false, %3 ], [ true, %.loopexit ], [ false, %14 ]
  ret i1 %.132
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

declare noundef double @_ZN4sptk9FloorLog2Ed(double noundef) local_unnamed_addr #2

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

declare noundef double @_ZN4sptk8FloorLogEd(double noundef) local_unnamed_addr #2

declare noundef double @_ZN4sptk10FloorLog10Ed(double noundef) local_unnamed_addr #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 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 = { "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !11, i64 16}
!6 = !{!"_ZTSN4sptk18EntropyCalculationE", !7, i64 8, !10, i64 12, !11, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4sptk18EntropyCalculation12EntropyUnitsE", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !10, i64 12}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = distinct !{!21, !19}


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