; LLVM IR from mnovak42/hepemshow :: Simulation/src/Hist.ll (ZN4Hist4FillEdd)

; 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.Hist = type <{ %"class.std::__cxx11::basic_string", %"class.std::vector", %"class.std::vector", double, double, double, double, double, i32, [4 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 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 }

; 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
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Hist4FillEdd(ptr noundef nonnull align 8 dereferenceable(124) %0, double noundef %1, double noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = load double, ptr %5, align 8, !tbaa !9
  %10 = getelementptr inbounds %class.Hist, ptr %8, i32 0, i32 3
  %11 = load double, ptr %10, align 8, !tbaa !11
  %12 = fcmp olt double %9, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %54

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load double, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds %class.Hist, ptr %8, i32 0, i32 4
  %17 = load double, ptr %16, align 8, !tbaa !21
  %18 = fcmp oeq double %15, %17
  br i1 %18, label %19, label %23

19:                                               ; preds = %14
  %20 = getelementptr inbounds %class.Hist, ptr %8, i32 0, i32 8
  %21 = load i32, ptr %20, align 8, !tbaa !22
  %22 = sub nsw i32 %21, 1
  br label %32

23:                                               ; preds = %14
  %24 = load double, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds %class.Hist, ptr %8, i32 0, i32 3
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = fsub double %24, %26
  %28 = getelementptr inbounds %class.Hist, ptr %8, i32 0, i32 6
  %29 = load double, ptr %28, align 8, !tbaa !23
  %30 = fmul double %27, %29
  %31 = fptosi double %30 to i32
  br label %32

32:                                               ; preds = %23, %19
  %33 = phi i32 [ %22, %19 ], [ %31, %23 ]
  store i32 %33, ptr %7, align 4, !tbaa !24
  %34 = load i32, ptr %7, align 4, !tbaa !24
  %35 = icmp sgt i32 %34, -1
  br i1 %35, label %36, label %53

36:                                               ; preds = %32
  %37 = load i32, ptr %7, align 4, !tbaa !24
  %38 = getelementptr inbounds %class.Hist, ptr %8, i32 0, i32 8
  %39 = load i32, ptr %38, align 8, !tbaa !22
  %40 = icmp slt i32 %37, %39
  br i1 %40, label %41, label %53

41:                                               ; preds = %36
  %42 = load double, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds %class.Hist, ptr %8, i32 0, i32 2
  %44 = load i32, ptr %7, align 4, !tbaa !24
  %45 = sext i32 %44 to i64
  %46 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %43, i64 noundef %45) #2
  %47 = load double, ptr %46, align 8, !tbaa !9
  %48 = fadd double %47, %42
  store double %48, ptr %46, align 8, !tbaa !9
  %49 = load double, ptr %6, align 8, !tbaa !9
  %50 = getelementptr inbounds %class.Hist, ptr %8, i32 0, i32 7
  %51 = load double, ptr %50, align 8, !tbaa !25
  %52 = fadd double %51, %49
  store double %52, ptr %50, align 8, !tbaa !25
  br label %53

53:                                               ; preds = %41, %36, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %54

54:                                               ; preds = %53, %13
  ret void
}

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 = { 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 80}
!12 = !{!"_ZTS4Hist", !13, i64 0, !16, i64 32, !16, i64 56, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !20, i64 120}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !14, i64 0, !15, i64 8, !7, i64 16}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTSSt6vectorIdSaIdEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"int", !7, i64 0}
!21 = !{!12, !10, i64 88}
!22 = !{!12, !20, i64 120}
!23 = !{!12, !10, i64 104}
!24 = !{!20, !20, i64 0}
!25 = !{!12, !10, i64 112}


; 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Hist4FillEdd(ptr noundef nonnull align 8 dereferenceable(124) %0, double noundef %1, double noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = fcmp ogt double %5, %1
  br i1 %6, label %35, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = load double, ptr %8, align 8, !tbaa !19
  %10 = fcmp oeq double %9, %1
  br i1 %10, label %11, label %15

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 120
  %13 = load i32, ptr %12, align 8
  %14 = add nsw i32 %13, -1
  br label %21

15:                                               ; preds = %7
  %16 = fsub double %1, %5
  %17 = getelementptr inbounds i8, ptr %0, i64 104
  %18 = load double, ptr %17, align 8, !tbaa !20
  %19 = fmul double %16, %18
  %20 = fptosi double %19 to i32
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 120
  %.pre = load i32, ptr %.phi.trans.insert, align 8
  br label %21

21:                                               ; preds = %15, %11
  %22 = phi i32 [ %13, %11 ], [ %.pre, %15 ]
  %23 = phi i32 [ %14, %11 ], [ %20, %15 ]
  %24 = icmp sgt i32 %23, -1
  %25 = icmp slt i32 %23, %22
  %or.cond = select i1 %24, i1 %25, i1 false
  br i1 %or.cond, label %26, label %35

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %0, i64 56
  %28 = zext nneg i32 %23 to i64
  %29 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %28) #1
  %30 = load double, ptr %29, align 8, !tbaa !21
  %31 = fadd double %30, %2
  store double %31, ptr %29, align 8, !tbaa !21
  %32 = getelementptr inbounds i8, ptr %0, i64 112
  %33 = load double, ptr %32, align 8, !tbaa !22
  %34 = fadd double %33, %2
  store double %34, ptr %32, align 8, !tbaa !22
  br label %35

35:                                               ; preds = %21, %26, %3
  ret void
}

attributes #0 = { 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 #1 = { 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, !17, i64 80}
!6 = !{!"_ZTS4Hist", !7, i64 0, !13, i64 32, !13, i64 56, !17, i64 80, !17, i64 88, !17, i64 96, !17, i64 104, !17, i64 112, !18, i64 120}
!7 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !8, i64 0, !12, i64 8, !10, i64 16}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"_ZTSSt6vectorIdSaIdEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !9, i64 0, !9, i64 8, !9, i64 16}
!17 = !{!"double", !10, i64 0}
!18 = !{!"int", !10, i64 0}
!19 = !{!6, !17, i64 88}
!20 = !{!6, !17, i64 104}
!21 = !{!17, !17, i64 0}
!22 = !{!6, !17, i64 112}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass