; LLVM IR from rvillegasm/NuMath :: src/integration (simpsonThreeEighths)

; 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.numath::Point" = type { double, double }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN6numath11integration19simpsonThreeEighthsERSt6vectorINS_5PointESaIS2_EE(ptr noundef nonnull align 8 dereferenceable(24) %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call noundef i64 @_ZNKSt6vectorIN6numath5PointESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #3
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = sub i32 %12, 1
  %14 = zext i32 %13 to i64
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %14) #3
  %16 = getelementptr inbounds %"struct.numath::Point", ptr %15, i32 0, i32 0
  %17 = load double, ptr %16, align 8, !tbaa !11
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %18, i64 noundef 0) #3
  %20 = getelementptr inbounds %"struct.numath::Point", ptr %19, i32 0, i32 0
  %21 = load double, ptr %20, align 8, !tbaa !11
  %22 = fsub double %17, %21
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = sub i32 %23, 1
  %25 = uitofp i32 %24 to double
  %26 = fdiv double %22, %25
  store double %26, ptr %4, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %56, %1
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = sub i32 %29, 1
  %31 = icmp ult i32 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %59

33:                                               ; preds = %27
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = urem i32 %34, 3
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %46

37:                                               ; preds = %33
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %38, i64 noundef %40) #3
  %42 = getelementptr inbounds %"struct.numath::Point", ptr %41, i32 0, i32 1
  %43 = load double, ptr %42, align 8, !tbaa !15
  %44 = load double, ptr %5, align 8, !tbaa !14
  %45 = fadd double %44, %43
  store double %45, ptr %5, align 8, !tbaa !14
  br label %55

46:                                               ; preds = %33
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %49) #3
  %51 = getelementptr inbounds %"struct.numath::Point", ptr %50, i32 0, i32 1
  %52 = load double, ptr %51, align 8, !tbaa !15
  %53 = load double, ptr %6, align 8, !tbaa !14
  %54 = fadd double %53, %52
  store double %54, ptr %6, align 8, !tbaa !14
  br label %55

55:                                               ; preds = %46, %37
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = add i32 %57, 1
  store i32 %58, ptr %7, align 4, !tbaa !9
  br label %27, !llvm.loop !16

59:                                               ; preds = %32
  %60 = load double, ptr %4, align 8, !tbaa !14
  %61 = fmul double 3.000000e+00, %60
  %62 = fdiv double %61, 8.000000e+00
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %63, i64 noundef 0) #3
  %65 = getelementptr inbounds %"struct.numath::Point", ptr %64, i32 0, i32 1
  %66 = load double, ptr %65, align 8, !tbaa !15
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = load i32, ptr %3, align 4, !tbaa !9
  %69 = sub i32 %68, 1
  %70 = zext i32 %69 to i64
  %71 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %67, i64 noundef %70) #3
  %72 = getelementptr inbounds %"struct.numath::Point", ptr %71, i32 0, i32 1
  %73 = load double, ptr %72, align 8, !tbaa !15
  %74 = fadd double %66, %73
  %75 = load double, ptr %5, align 8, !tbaa !14
  %76 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %75, double %74)
  %77 = load double, ptr %6, align 8, !tbaa !14
  %78 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %77, double %76)
  %79 = fmul double %62, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret double %79
}

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

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

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

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

; 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN6numath5PointE", !13, i64 0, !13, i64 8}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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
define dso_local noundef double @_ZN6numath11integration19simpsonThreeEighthsERSt6vectorINS_5PointESaIS2_EE(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZNKSt6vectorIN6numath5PointESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %3 = trunc i64 %2 to i32
  %4 = add i32 %3, -1
  %5 = zext i32 %4 to i64
  %6 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %5) #2
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #2
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = icmp ugt i32 %4, 1
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.021.lcssa = phi double [ 0.000000e+00, %1 ], [ %.122, %.lr.ph ]
  %.020.lcssa = phi double [ 0.000000e+00, %1 ], [ %.1, %.lr.ph ]
  %11 = fsub double %7, %9
  %12 = uitofp i32 %4 to double
  %13 = fdiv double %11, %12
  %14 = fmul double %13, 3.000000e+00
  %15 = fmul double %14, 1.250000e-01
  %16 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #2
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load double, ptr %17, align 8, !tbaa !10
  %19 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %5) #2
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load double, ptr %20, align 8, !tbaa !10
  %22 = fadd double %18, %21
  %23 = tail call double @llvm.fmuladd.f64(double %.021.lcssa, double 2.000000e+00, double %22)
  %24 = tail call double @llvm.fmuladd.f64(double %.020.lcssa, double 3.000000e+00, double %23)
  %25 = fmul double %15, %24
  ret double %25

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %1 ]
  %.02024 = phi double [ %.1, %.lr.ph ], [ 0.000000e+00, %1 ]
  %.02123 = phi double [ %.122, %.lr.ph ], [ 0.000000e+00, %1 ]
  %26 = trunc nuw i64 %indvars.iv to i32
  %27 = urem i32 %26, 3
  %28 = icmp eq i32 %27, 0
  %29 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN6numath5PointESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #2
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = load double, ptr %30, align 8, !tbaa !10
  %32 = fadd double %.02123, %31
  %33 = fadd double %.02024, %31
  %.122 = select i1 %28, double %32, double %.02123
  %.1 = select i1 %28, double %.02024, double %33
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11
}

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

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

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

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


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