; LLVM IR from ImperialCollegeLondon/pnflow :: src/pnm/pnflow/Element.ll (ZN4Elem15updateSat_calcREd)

; 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.Elem = type { %class.Apex, [5 x %class.SlvrElm], i8, i32, ptr, double, double, i32, %"class.std::vector", ptr, double, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, %"struct.std::pair", %"struct.std::pair", %"struct.std::pair", i32, i32, i32, i32, %class.var3 }
%class.Apex = type { ptr, i8, double, double, ptr, i32, double, double, double, double, i8, i8, i8, i8, %"struct.std::pair" }
%class.SlvrElm = type { i8, i8, i8, double, double }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Elem *, std::allocator<Elem *>>::_Vector_impl" }
%"struct.std::_Vector_base<Elem *, std::allocator<Elem *>>::_Vector_impl" = type { %"struct.std::_Vector_base<Elem *, std::allocator<Elem *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Elem *, std::allocator<Elem *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.std::pair" = type { i32, double }
%class.var3 = type { double, double, double }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4Elem16isEntryOrExitResEv(ptr noundef nonnull align 8 dereferenceable(408)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN4Elem15updateSat_calcREd(ptr noundef nonnull align 8 dereferenceable(408) %0, double noundef %1) #1 align 2 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = call noundef zeroext i1 @_ZNK4Elem16isEntryOrExitResEv(ptr noundef nonnull align 8 dereferenceable(408) %6)
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store double 0.000000e+00, ptr %3, align 8
  br label %32

9:                                                ; preds = %2
  %10 = getelementptr inbounds %class.Elem, ptr %6, i32 0, i32 9
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = load double, ptr %5, align 8, !tbaa !9
  %13 = load ptr, ptr %11, align 8, !tbaa !22
  %14 = getelementptr inbounds ptr, ptr %13, i64 2
  %15 = load ptr, ptr %14, align 8
  %16 = call noundef double %15(ptr noundef nonnull align 8 dereferenceable(152) %11, double noundef %12)
  %17 = getelementptr inbounds %class.Elem, ptr %6, i32 0, i32 10
  store double %16, ptr %17, align 8, !tbaa !24
  %18 = getelementptr inbounds %class.Elem, ptr %6, i32 0, i32 12
  %19 = load i8, ptr %18, align 1, !tbaa !25, !range !26, !noundef !27
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %29

21:                                               ; preds = %9
  %22 = getelementptr inbounds %class.Elem, ptr %6, i32 0, i32 10
  %23 = load double, ptr %22, align 8, !tbaa !24
  %24 = getelementptr inbounds %class.Elem, ptr %6, i32 0, i32 5
  %25 = load double, ptr %24, align 8, !tbaa !28
  %26 = getelementptr inbounds %class.Elem, ptr %6, i32 0, i32 6
  %27 = load double, ptr %26, align 8, !tbaa !29
  %28 = call double @llvm.fmuladd.f64(double %23, double %25, double %27)
  br label %30

29:                                               ; preds = %9
  br label %30

30:                                               ; preds = %29, %21
  %31 = phi double [ %28, %21 ], [ 0.000000e+00, %29 ]
  store double %31, ptr %3, align 8
  br label %32

32:                                               ; preds = %30, %8
  %33 = load double, ptr %3, align 8
  ret double %33
}

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

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 = { 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 #2 = { 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 = !{!"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, !6, i64 288}
!12 = !{!"_ZTS4Elem", !13, i64 0, !7, i64 104, !14, i64 224, !15, i64 228, !6, i64 232, !10, i64 240, !10, i64 248, !15, i64 256, !17, i64 264, !6, i64 288, !10, i64 296, !14, i64 304, !14, i64 305, !14, i64 306, !14, i64 307, !14, i64 308, !14, i64 309, !14, i64 310, !14, i64 311, !14, i64 312, !14, i64 313, !16, i64 320, !16, i64 336, !16, i64 352, !15, i64 368, !15, i64 372, !15, i64 376, !15, i64 380, !21, i64 384}
!13 = !{!"_ZTS4Apex", !14, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !15, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !14, i64 80, !14, i64 81, !14, i64 82, !14, i64 83, !16, i64 88}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSSt4pairIidE", !15, i64 0, !10, i64 8}
!17 = !{!"_ZTSSt6vectorIP4ElemSaIS1_EE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseIP4ElemSaIS1_EE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIP4ElemSaIS1_EE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIP4ElemSaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!"_ZTS4var3IdE", !10, i64 0, !10, i64 8, !10, i64 16}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = !{!12, !10, i64 296}
!25 = !{!12, !14, i64 305}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!12, !10, i64 240}
!29 = !{!12, !10, i64 248}


; 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 zeroext i1 @_ZNK4Elem16isEntryOrExitResEv(ptr noundef nonnull align 8 dereferenceable(408)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN4Elem15updateSat_calcREd(ptr noundef nonnull align 8 dereferenceable(408) %0, double noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef zeroext i1 @_ZNK4Elem16isEntryOrExitResEv(ptr noundef nonnull align 8 dereferenceable(408) %0)
  br i1 %3, label %21, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 288
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !20
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = load ptr, ptr %8, align 8
  %10 = tail call noundef double %9(ptr noundef nonnull align 8 dereferenceable(152) %6, double noundef %1)
  %11 = getelementptr inbounds i8, ptr %0, i64 296
  store double %10, ptr %11, align 8, !tbaa !22
  %12 = getelementptr inbounds i8, ptr %0, i64 305
  %13 = load i8, ptr %12, align 1, !tbaa !23, !range !24, !noundef !25
  %14 = trunc nuw i8 %13 to i1
  %15 = getelementptr inbounds i8, ptr %0, i64 240
  %16 = load double, ptr %15, align 8
  %17 = getelementptr inbounds i8, ptr %0, i64 248
  %18 = load double, ptr %17, align 8
  %19 = tail call double @llvm.fmuladd.f64(double %10, double %16, double %18)
  %20 = select i1 %14, double %19, double 0.000000e+00
  br label %21

21:                                               ; preds = %2, %4
  %.0 = phi double [ %20, %4 ], [ 0.000000e+00, %2 ]
  ret double %.0
}

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

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 = { 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 #2 = { 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, !12, i64 288}
!6 = !{!"_ZTS4Elem", !7, i64 0, !9, i64 104, !8, i64 224, !13, i64 228, !12, i64 232, !11, i64 240, !11, i64 248, !13, i64 256, !15, i64 264, !12, i64 288, !11, i64 296, !8, i64 304, !8, i64 305, !8, i64 306, !8, i64 307, !8, i64 308, !8, i64 309, !8, i64 310, !8, i64 311, !8, i64 312, !8, i64 313, !14, i64 320, !14, i64 336, !14, i64 352, !13, i64 368, !13, i64 372, !13, i64 376, !13, i64 380, !19, i64 384}
!7 = !{!"_ZTS4Apex", !8, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !13, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !8, i64 80, !8, i64 81, !8, i64 82, !8, i64 83, !14, i64 88}
!8 = !{!"bool", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"double", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"_ZTSSt4pairIidE", !13, i64 0, !11, i64 8}
!15 = !{!"_ZTSSt6vectorIP4ElemSaIS1_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIP4ElemSaIS1_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIP4ElemSaIS1_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIP4ElemSaIS1_EE17_Vector_impl_dataE", !12, i64 0, !12, i64 8, !12, i64 16}
!19 = !{!"_ZTS4var3IdE", !11, i64 0, !11, i64 8, !11, i64 16}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !10, i64 0}
!22 = !{!6, !11, i64 296}
!23 = !{!6, !8, i64 305}
!24 = !{i8 0, i8 2}
!25 = !{}


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