; LLVM IR from rdguez-mariano/fast_imas_IPOL :: libNumerics/computeH.ll (ZNK11libNumerics8ComputeH7q_errorERKNS_6vectorIdEE)

; 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.libNumerics::ComputeH" = type { i32, i32, [64 x double], [8 x double], 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZNK11libNumerics8ComputeH7q_errorERKNS_6vectorIdEE(ptr noundef nonnull align 8 dereferenceable(592) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %13 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 4
  %14 = load double, ptr %13, align 8, !tbaa !9
  store double %14, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 2
  %16 = getelementptr inbounds [64 x double], ptr %15, i64 0, i64 0
  %17 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !15
  %21 = mul nsw i32 %18, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds double, ptr %16, i64 %22
  %24 = getelementptr inbounds double, ptr %23, i64 -1
  store ptr %24, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %25 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = sub nsw i32 %26, 1
  store i32 %27, ptr %7, align 4, !tbaa !16
  br label %28

28:                                               ; preds = %44, %2
  %29 = load i32, ptr %7, align 4, !tbaa !16
  %30 = icmp sge i32 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %54

32:                                               ; preds = %28
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !16
  %37 = call noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24) %35, i32 noundef %36)
  %38 = fmul double %34, %37
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !16
  %41 = call noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24) %39, i32 noundef %40)
  %42 = load double, ptr %5, align 8, !tbaa !14
  %43 = call double @llvm.fmuladd.f64(double %38, double %41, double %42)
  store double %43, ptr %5, align 8, !tbaa !14
  br label %44

44:                                               ; preds = %32
  %45 = load i32, ptr %7, align 4, !tbaa !16
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %7, align 4, !tbaa !16
  %47 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !15
  %49 = add nsw i32 %48, 1
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = sext i32 %49 to i64
  %52 = sub i64 0, %51
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  store ptr %53, ptr %6, align 8, !tbaa !5
  br label %28, !llvm.loop !17

54:                                               ; preds = %31
  %55 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 2
  %56 = getelementptr inbounds [64 x double], ptr %55, i64 0, i64 0
  %57 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !15
  %59 = sub nsw i32 %58, 1
  %60 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !15
  %62 = mul nsw i32 %59, %61
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %56, i64 %63
  store ptr %64, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %65 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !15
  %67 = sub nsw i32 %66, 1
  store i32 %67, ptr %8, align 4, !tbaa !16
  br label %68

68:                                               ; preds = %112, %54
  %69 = load i32, ptr %8, align 4, !tbaa !16
  %70 = icmp sge i32 %69, 0
  br i1 %70, label %72, label %71

71:                                               ; preds = %68
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %121

72:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load i32, ptr %8, align 4, !tbaa !16
  %75 = call noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24) %73, i32 noundef %74)
  store double %75, ptr %10, align 8, !tbaa !14
  %76 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 3
  %77 = load i32, ptr %8, align 4, !tbaa !16
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [8 x double], ptr %76, i64 0, i64 %78
  %80 = load double, ptr %79, align 8, !tbaa !14
  %81 = fmul double 2.000000e+00, %80
  %82 = load double, ptr %10, align 8, !tbaa !14
  %83 = load double, ptr %5, align 8, !tbaa !14
  %84 = fneg double %81
  %85 = call double @llvm.fmuladd.f64(double %84, double %82, double %83)
  store double %85, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %86 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %87 = load i32, ptr %86, align 4, !tbaa !15
  %88 = sub nsw i32 %87, 1
  store i32 %88, ptr %11, align 4, !tbaa !16
  br label %89

89:                                               ; preds = %108, %72
  %90 = load i32, ptr %11, align 4, !tbaa !16
  %91 = load i32, ptr %8, align 4, !tbaa !16
  %92 = icmp sgt i32 %90, %91
  br i1 %92, label %94, label %93

93:                                               ; preds = %89
  store i32 8, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %111

94:                                               ; preds = %89
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load i32, ptr %11, align 4, !tbaa !16
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds double, ptr %95, i64 %97
  %99 = load double, ptr %98, align 8, !tbaa !14
  %100 = fmul double 2.000000e+00, %99
  %101 = load double, ptr %10, align 8, !tbaa !14
  %102 = fmul double %100, %101
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = load i32, ptr %11, align 4, !tbaa !16
  %105 = call noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24) %103, i32 noundef %104)
  %106 = load double, ptr %5, align 8, !tbaa !14
  %107 = call double @llvm.fmuladd.f64(double %102, double %105, double %106)
  store double %107, ptr %5, align 8, !tbaa !14
  br label %108

108:                                              ; preds = %94
  %109 = load i32, ptr %11, align 4, !tbaa !16
  %110 = add nsw i32 %109, -1
  store i32 %110, ptr %11, align 4, !tbaa !16
  br label %89, !llvm.loop !19

111:                                              ; preds = %93
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %8, align 4, !tbaa !16
  %114 = add nsw i32 %113, -1
  store i32 %114, ptr %8, align 4, !tbaa !16
  %115 = getelementptr inbounds %"class.libNumerics::ComputeH", ptr %12, i32 0, i32 1
  %116 = load i32, ptr %115, align 4, !tbaa !15
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  %118 = sext i32 %116 to i64
  %119 = sub i64 0, %118
  %120 = getelementptr inbounds double, ptr %117, i64 %119
  store ptr %120, ptr %6, align 8, !tbaa !5
  br label %68, !llvm.loop !20

121:                                              ; preds = %71
  %122 = load double, ptr %5, align 8, !tbaa !14
  %123 = fptrunc double %122 to float
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret float %123
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 = { 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 584}
!10 = !{!"_ZTSN11libNumerics8ComputeHE", !11, i64 0, !12, i64 4, !7, i64 8, !7, i64 520, !13, i64 584}
!11 = !{!"_ZTSN11libNumerics8ComputeH4TypeE", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!10, !12, i64 4}
!16 = !{!12, !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_ZNK11libNumerics8ComputeH7q_errorERKNS_6vectorIdEE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(592) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 584
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge47

.lr.ph.preheader:                                 ; preds = %2
  %9 = mul nuw nsw i32 %7, %7
  %10 = zext nneg i32 %9 to i64
  %11 = getelementptr inbounds double, ptr %5, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 -8
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %13 = icmp sgt i32 %25, 0
  br i1 %13, label %.lr.ph46, label %._crit_edge47

.lr.ph46:                                         ; preds = %._crit_edge
  %14 = add nsw i32 %25, -1
  %15 = mul nsw i32 %14, %25
  %16 = zext nneg i32 %15 to i64
  %17 = getelementptr inbounds double, ptr %5, i64 %16
  %18 = getelementptr inbounds i8, ptr %0, i64 520
  %19 = zext nneg i32 %14 to i64
  br label %30

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.02734 = phi double [ %24, %.lr.ph ], [ %4, %.lr.ph.preheader ]
  %.029.in33 = phi i32 [ %.029, %.lr.ph ], [ %7, %.lr.ph.preheader ]
  %.03032 = phi ptr [ %27, %.lr.ph ], [ %12, %.lr.ph.preheader ]
  %.029 = add nsw i32 %.029.in33, -1
  %20 = load double, ptr %.03032, align 8, !tbaa !13
  %21 = tail call noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %.029)
  %22 = fmul double %20, %21
  %23 = tail call noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %.029)
  %24 = tail call double @llvm.fmuladd.f64(double %22, double %23, double %.02734)
  %25 = load i32, ptr %6, align 4, !tbaa !12
  %narrow = xor i32 %25, -1
  %26 = sext i32 %narrow to i64
  %27 = getelementptr inbounds double, ptr %.03032, i64 %26
  %28 = icmp ugt i32 %.029.in33, 1
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge47:                                    ; preds = %._crit_edge40, %2, %._crit_edge
  %.1.lcssa = phi double [ %24, %._crit_edge ], [ %4, %2 ], [ %.2.lcssa, %._crit_edge40 ]
  %29 = fptrunc double %.1.lcssa to float
  ret float %29

30:                                               ; preds = %.lr.ph46, %._crit_edge40
  %indvars.iv = phi i64 [ %19, %.lr.ph46 ], [ %indvars.iv.next, %._crit_edge40 ]
  %.144 = phi double [ %24, %.lr.ph46 ], [ %.2.lcssa, %._crit_edge40 ]
  %.13142 = phi ptr [ %17, %.lr.ph46 ], [ %43, %._crit_edge40 ]
  %31 = trunc nuw nsw i64 %indvars.iv to i32
  %32 = tail call noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %31)
  %33 = getelementptr inbounds [8 x double], ptr %18, i64 0, i64 %indvars.iv
  %34 = load double, ptr %33, align 8, !tbaa !13
  %35 = fmul double %34, -2.000000e+00
  %36 = tail call double @llvm.fmuladd.f64(double %35, double %32, double %.144)
  %37 = load i32, ptr %6, align 4, !tbaa !12
  %.035 = add nsw i32 %37, -1
  %38 = sext i32 %.035 to i64
  %39 = icmp slt i64 %indvars.iv, %38
  br i1 %39, label %.lr.ph39, label %._crit_edge40

._crit_edge40.loopexit:                           ; preds = %.lr.ph39
  %.pre = load i32, ptr %6, align 4, !tbaa !12
  br label %._crit_edge40

._crit_edge40:                                    ; preds = %._crit_edge40.loopexit, %30
  %40 = phi i32 [ %37, %30 ], [ %.pre, %._crit_edge40.loopexit ]
  %.2.lcssa = phi double [ %36, %30 ], [ %51, %._crit_edge40.loopexit ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %41 = sext i32 %40 to i64
  %42 = sub nsw i64 0, %41
  %43 = getelementptr inbounds double, ptr %.13142, i64 %42
  %44 = icmp sgt i64 %indvars.iv, 0
  br i1 %44, label %30, label %._crit_edge47, !llvm.loop !16

.lr.ph39:                                         ; preds = %30, %.lr.ph39
  %.037 = phi i32 [ %.0, %.lr.ph39 ], [ %.035, %30 ]
  %.236 = phi double [ %51, %.lr.ph39 ], [ %36, %30 ]
  %45 = zext nneg i32 %.037 to i64
  %46 = getelementptr inbounds double, ptr %.13142, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !13
  %48 = fmul double %47, 2.000000e+00
  %49 = fmul double %32, %48
  %50 = tail call noundef double @_ZNK11libNumerics6matrixIdEclEi(ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %.037)
  %51 = tail call double @llvm.fmuladd.f64(double %49, double %50, double %.236)
  %.0 = add nsw i32 %.037, -1
  %52 = sext i32 %.0 to i64
  %53 = icmp slt i64 %indvars.iv, %52
  br i1 %53, label %.lr.ph39, label %._crit_edge40.loopexit, !llvm.loop !17
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #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" }

!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 584}
!6 = !{!"_ZTSN11libNumerics8ComputeHE", !7, i64 0, !10, i64 4, !8, i64 8, !8, i64 520, !11, i64 584}
!7 = !{!"_ZTSN11libNumerics8ComputeH4TypeE", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !10, i64 4}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


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