; LLVM IR from EdoPro98/SimSiPM :: src/SiPMSensor.ll (ZNK4sipm10SiPMSensor9hitCircleEv)

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

%"struct.sipm::pair" = type { i32, i32 }
%"class.sipm::SiPMSensor" = type { %"class.sipm::SiPMProperties", [56 x i8], %"class.sipm::SiPMRandom", i32, i32, i32, i32, i32, i32, %"class.std::vector", %"class.std::vector", %"class.std::vector.3", %"class.std::vector.8", %"class.sipm::SiPMAnalogSignal", [40 x i8] }
%"class.sipm::SiPMProperties" = type <{ double, double, i32, i32, i32, [4 x i8], double, double, i32, [4 x i8], double, double, double, double, double, double, double, double, double, double, double, double, double, float, [4 x i8], double, float, [4 x i8], double, double, %"class.std::map", i32, i8, i8, i8, i8, i8, [7 x i8] }>
%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<double, std::pair<const double, double>, std::_Select1st<std::pair<const double, double>>, std::less<double>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<double, std::pair<const double, double>, std::_Select1st<std::pair<const double, double>>, std::less<double>>::_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 }
%"class.sipm::SiPMRandom" = type { %"class.sipm::SiPMRng::Xorshift256plus" }
%"class.sipm::SiPMRng::Xorshift256plus" = type <{ [4 x i64], [32 x i8], [65536 x i64], i32, [60 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<sipm::SiPMHit *, std::allocator<sipm::SiPMHit *>>::_Vector_impl" }
%"struct.std::_Vector_base<sipm::SiPMHit *, std::allocator<sipm::SiPMHit *>>::_Vector_impl" = type { %"struct.std::_Vector_base<sipm::SiPMHit *, std::allocator<sipm::SiPMHit *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<sipm::SiPMHit *, std::allocator<sipm::SiPMHit *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.8" = type { %"struct.std::_Vector_base.9" }
%"struct.std::_Vector_base.9" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.sipm::SiPMAnalogSignal" = type { %"class.std::vector.8", double }

; 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
declare dso_local noundef i32 @_ZNK4sipm14SiPMProperties10nSideCellsEv(ptr noundef nonnull align 8 dereferenceable(257)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local i64 @_ZNK4sipm10SiPMSensor9hitCircleEv(ptr noundef nonnull align 64 dereferenceable(524888) %0) #3 align 2 {
  %2 = alloca %"struct.sipm::pair", align 4
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @_ZN4sipm4pairIjjEC2Ev(ptr noundef nonnull align 4 dereferenceable(8) %2) #5
  %9 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 2
  %10 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %9) #5
  %11 = fcmp olt double %10, 9.000000e-01
  br i1 %11, label %12, label %47

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  br label %13

13:                                               ; preds = %20, %12
  %14 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 2
  %15 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %14) #5
  %16 = call double @llvm.fmuladd.f64(double %15, double 2.000000e+00, double -1.000000e+00)
  store double %16, ptr %4, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 2
  %18 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %17) #5
  %19 = call double @llvm.fmuladd.f64(double %18, double 2.000000e+00, double -1.000000e+00)
  store double %19, ptr %5, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %13
  %21 = load double, ptr %4, align 8, !tbaa !9
  %22 = load double, ptr %4, align 8, !tbaa !9
  %23 = load double, ptr %5, align 8, !tbaa !9
  %24 = load double, ptr %5, align 8, !tbaa !9
  %25 = fmul double %23, %24
  %26 = call double @llvm.fmuladd.f64(double %21, double %22, double %25)
  %27 = fcmp ogt double %26, 1.000000e+00
  br i1 %27, label %13, label %28, !llvm.loop !11

28:                                               ; preds = %20
  %29 = load double, ptr %4, align 8, !tbaa !9
  %30 = fadd double %29, 1.000000e+00
  %31 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 0
  %32 = call noundef i32 @_ZNK4sipm14SiPMProperties10nSideCellsEv(ptr noundef nonnull align 8 dereferenceable(257) %31)
  %33 = uitofp i32 %32 to double
  %34 = fmul double %30, %33
  %35 = fmul double %34, 5.000000e-01
  %36 = fptoui double %35 to i32
  %37 = getelementptr inbounds %"struct.sipm::pair", ptr %2, i32 0, i32 0
  store i32 %36, ptr %37, align 4, !tbaa !13
  %38 = load double, ptr %5, align 8, !tbaa !9
  %39 = fadd double %38, 1.000000e+00
  %40 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 0
  %41 = call noundef i32 @_ZNK4sipm14SiPMProperties10nSideCellsEv(ptr noundef nonnull align 8 dereferenceable(257) %40)
  %42 = uitofp i32 %41 to double
  %43 = fmul double %39, %42
  %44 = fmul double %43, 5.000000e-01
  %45 = fptoui double %44 to i32
  %46 = getelementptr inbounds %"struct.sipm::pair", ptr %2, i32 0, i32 1
  store i32 %45, ptr %46, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %82

47:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  br label %48

48:                                               ; preds = %55, %47
  %49 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 2
  %50 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %49) #5
  %51 = call double @llvm.fmuladd.f64(double %50, double 2.000000e+00, double -1.000000e+00)
  store double %51, ptr %6, align 8, !tbaa !9
  %52 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 2
  %53 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %52) #5
  %54 = call double @llvm.fmuladd.f64(double %53, double 2.000000e+00, double -1.000000e+00)
  store double %54, ptr %7, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %48
  %56 = load double, ptr %6, align 8, !tbaa !9
  %57 = load double, ptr %6, align 8, !tbaa !9
  %58 = load double, ptr %7, align 8, !tbaa !9
  %59 = load double, ptr %7, align 8, !tbaa !9
  %60 = fmul double %58, %59
  %61 = call double @llvm.fmuladd.f64(double %56, double %57, double %60)
  %62 = fcmp olt double %61, 1.000000e+00
  br i1 %62, label %48, label %63, !llvm.loop !17

63:                                               ; preds = %55
  %64 = load double, ptr %6, align 8, !tbaa !9
  %65 = fadd double %64, 1.000000e+00
  %66 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 0
  %67 = call noundef i32 @_ZNK4sipm14SiPMProperties10nSideCellsEv(ptr noundef nonnull align 8 dereferenceable(257) %66)
  %68 = uitofp i32 %67 to double
  %69 = fmul double %65, %68
  %70 = fmul double %69, 5.000000e-01
  %71 = fptoui double %70 to i32
  %72 = getelementptr inbounds %"struct.sipm::pair", ptr %2, i32 0, i32 0
  store i32 %71, ptr %72, align 4, !tbaa !13
  %73 = load double, ptr %7, align 8, !tbaa !9
  %74 = fadd double %73, 1.000000e+00
  %75 = getelementptr inbounds %"class.sipm::SiPMSensor", ptr %8, i32 0, i32 0
  %76 = call noundef i32 @_ZNK4sipm14SiPMProperties10nSideCellsEv(ptr noundef nonnull align 8 dereferenceable(257) %75)
  %77 = uitofp i32 %76 to double
  %78 = fmul double %74, %77
  %79 = fmul double %78, 5.000000e-01
  %80 = fptoui double %79 to i32
  %81 = getelementptr inbounds %"struct.sipm::pair", ptr %2, i32 0, i32 1
  store i32 %80, ptr %81, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %82

82:                                               ; preds = %63, %28
  %83 = load i64, ptr %2, align 4
  ret i64 %83
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4sipm4pairIjjEC2Ev(ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416)) #4 align 2

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 = { 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 #4 = { inlinehint 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 #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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN4sipm4pairIjjEE", !15, i64 0, !15, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !15, i64 4}
!17 = distinct !{!17, !12}


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

%"struct.sipm::pair" = type { i32, i32 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK4sipm14SiPMProperties10nSideCellsEv(ptr noundef nonnull align 8 dereferenceable(257)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local i64 @_ZNK4sipm10SiPMSensor9hitCircleEv(ptr noundef nonnull align 64 dereferenceable(524888) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %"struct.sipm::pair", align 8
  call void @_ZN4sipm4pairIjjEC2Ev(ptr noundef nonnull align 4 dereferenceable(8) %2) #4
  %3 = getelementptr inbounds i8, ptr %0, i64 320
  %4 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %3) #4
  %5 = fcmp olt double %4, 9.000000e-01
  br i1 %5, label %.preheader, label %.preheader13

.preheader:                                       ; preds = %1, %.preheader
  %6 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %3) #4
  %7 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %3) #4
  %8 = insertelement <2 x double> poison, double %6, i64 0
  %9 = insertelement <2 x double> %8, double %7, i64 1
  %10 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %9, <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double> <double -1.000000e+00, double -1.000000e+00>)
  %11 = fmul <2 x double> %10, %10
  %12 = extractelement <2 x double> %11, i64 1
  %13 = extractelement <2 x double> %10, i64 0
  %14 = call double @llvm.fmuladd.f64(double %13, double %13, double %12)
  %15 = fcmp ogt double %14, 1.000000e+00
  br i1 %15, label %.preheader, label %.loopexit, !llvm.loop !5

.preheader13:                                     ; preds = %1, %.preheader13
  %16 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %3) #4
  %17 = call noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416) %3) #4
  %18 = insertelement <2 x double> poison, double %16, i64 0
  %19 = insertelement <2 x double> %18, double %17, i64 1
  %20 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %19, <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double> <double -1.000000e+00, double -1.000000e+00>)
  %21 = fmul <2 x double> %20, %20
  %22 = extractelement <2 x double> %21, i64 1
  %23 = extractelement <2 x double> %20, i64 0
  %24 = call double @llvm.fmuladd.f64(double %23, double %23, double %22)
  %25 = fcmp olt double %24, 1.000000e+00
  br i1 %25, label %.preheader13, label %.loopexit, !llvm.loop !7

.loopexit:                                        ; preds = %.preheader13, %.preheader
  %26 = phi <2 x double> [ %10, %.preheader ], [ %20, %.preheader13 ]
  %27 = extractelement <2 x double> %26, i64 0
  %28 = fadd double %27, 1.000000e+00
  %29 = call noundef i32 @_ZNK4sipm14SiPMProperties10nSideCellsEv(ptr noundef nonnull align 8 dereferenceable(257) %0)
  %30 = uitofp i32 %29 to double
  %31 = fmul double %28, %30
  %storemerge.in = fmul double %31, 5.000000e-01
  %storemerge = fptoui double %storemerge.in to i32
  store i32 %storemerge, ptr %2, align 8, !tbaa !8
  %32 = extractelement <2 x double> %26, i64 1
  %33 = fadd double %32, 1.000000e+00
  %34 = call noundef i32 @_ZNK4sipm14SiPMProperties10nSideCellsEv(ptr noundef nonnull align 8 dereferenceable(257) %0)
  %35 = uitofp i32 %34 to double
  %36 = fmul double %33, %35
  %37 = fmul double %36, 5.000000e-01
  %38 = fptoui double %37 to i32
  %39 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %38, ptr %39, align 4, !tbaa !13
  %40 = load i64, ptr %2, align 8
  ret i64 %40
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4sipm4pairIjjEC2Ev(ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN4sipm10SiPMRandom4RandIdEET_v(ptr noundef nonnull align 64 dereferenceable(524416)) local_unnamed_addr #2 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { inlinehint 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = !{!9, !10, i64 0}
!9 = !{!"_ZTSN4sipm4pairIjjEE", !10, i64 0, !10, i64 4}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!9, !10, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass