; LLVM IR from davidomanovic/CFD-FlowSolver :: src/Matrix.ll (ZNK6MatrixmlEd)

; 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.Matrix = type { i64, i64, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6MatrixmlEd(ptr dead_on_unwind noalias writable sret(%class.Matrix) align 8 %0, ptr noundef nonnull align 8 dereferenceable(40) %1, double noundef %2) #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i1, align 1
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store double %2, ptr %6, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  store i1 false, ptr %7, align 1
  %14 = getelementptr inbounds %class.Matrix, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %class.Matrix, ptr %13, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !18
  call void @_ZN6MatrixC1Emm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %15, i64 noundef %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !19
  br label %18

18:                                               ; preds = %51, %3
  %19 = load i64, ptr %8, align 8, !tbaa !19
  %20 = getelementptr inbounds %class.Matrix, ptr %13, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = icmp ult i64 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %54

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !19
  br label %25

25:                                               ; preds = %43, %24
  %26 = load i64, ptr %10, align 8, !tbaa !19
  %27 = getelementptr inbounds %class.Matrix, ptr %13, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !18
  %29 = icmp ult i64 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %50

31:                                               ; preds = %25
  %32 = load i64, ptr %8, align 8, !tbaa !19
  %33 = load i64, ptr %10, align 8, !tbaa !19
  %34 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNK6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40) %13, i64 noundef %32, i64 noundef %33)
          to label %35 unwind label %46

35:                                               ; preds = %31
  %36 = load double, ptr %34, align 8, !tbaa !9
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = fmul double %36, %37
  %39 = load i64, ptr %8, align 8, !tbaa !19
  %40 = load i64, ptr %10, align 8, !tbaa !19
  %41 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %39, i64 noundef %40)
          to label %42 unwind label %46

42:                                               ; preds = %35
  store double %38, ptr %41, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %10, align 8, !tbaa !19
  %45 = add i64 %44, 1
  store i64 %45, ptr %10, align 8, !tbaa !19
  br label %25, !llvm.loop !20

46:                                               ; preds = %35, %31
  %47 = landingpad { ptr, i32 }
          cleanup
  %48 = extractvalue { ptr, i32 } %47, 0
  store ptr %48, ptr %11, align 8
  %49 = extractvalue { ptr, i32 } %47, 1
  store i32 %49, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @_ZN6MatrixD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #3
  br label %58

50:                                               ; preds = %30
  br label %51

51:                                               ; preds = %50
  %52 = load i64, ptr %8, align 8, !tbaa !19
  %53 = add i64 %52, 1
  store i64 %53, ptr %8, align 8, !tbaa !19
  br label %18, !llvm.loop !22

54:                                               ; preds = %23
  store i1 true, ptr %7, align 1
  store i32 1, ptr %9, align 4
  %55 = load i1, ptr %7, align 1
  br i1 %55, label %57, label %56

56:                                               ; preds = %54
  call void @_ZN6MatrixD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #3
  br label %57

57:                                               ; preds = %56, %54
  ret void

58:                                               ; preds = %46
  %59 = load ptr, ptr %11, align 8
  %60 = load i32, ptr %12, align 4
  %61 = insertvalue { ptr, i32 } poison, ptr %59, 0
  %62 = insertvalue { ptr, i32 } %61, i32 %60, 1
  resume { ptr, i32 } %62
}

declare void @_ZN6MatrixC1Emm(ptr, i64, i64)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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, !13, i64 0}
!12 = !{!"_ZTS6Matrix", !13, i64 0, !13, i64 8, !14, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTSSt6vectorIS_IdSaIdEESaIS1_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!12, !13, i64 8}
!19 = !{!13, !13, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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

%class.Matrix = type { i64, i64, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6MatrixmlEd(ptr dead_on_unwind noalias writable sret(%class.Matrix) align 8 %0, ptr noundef nonnull align 8 dereferenceable(40) %1, double noundef %2) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !15
  tail call void @_ZN6MatrixC1Emm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %4, i64 noundef %6)
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %7, 0
  %8 = load i64, ptr %5, align 8
  %.not16 = icmp eq i64 %8, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not16
  br i1 %or.cond, label %._crit_edge15, label %.preheader

.preheader:                                       ; preds = %3, %._crit_edge
  %9 = phi i64 [ %11, %._crit_edge ], [ %7, %3 ]
  %10 = phi i64 [ %12, %._crit_edge ], [ 1, %3 ]
  %.014 = phi i64 [ %13, %._crit_edge ], [ 0, %3 ]
  %.not17 = icmp eq i64 %10, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %19
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %11 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %9, %.preheader ]
  %12 = phi i64 [ %22, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %13 = add nuw i64 %.014, 1
  %14 = icmp ult i64 %13, %11
  br i1 %14, label %.preheader, label %._crit_edge15, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader, %19
  %.01213 = phi i64 [ %21, %19 ], [ 0, %.preheader ]
  %15 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNK6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40) %1, i64 noundef %.014, i64 noundef %.01213)
          to label %16 unwind label %24

16:                                               ; preds = %.lr.ph
  %17 = load double, ptr %15, align 8, !tbaa !19
  %18 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %.014, i64 noundef %.01213)
          to label %19 unwind label %24

19:                                               ; preds = %16
  %20 = fmul double %17, %2
  store double %20, ptr %18, align 8, !tbaa !19
  %21 = add nuw i64 %.01213, 1
  %22 = load i64, ptr %5, align 8, !tbaa !15
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !21

24:                                               ; preds = %16, %.lr.ph
  %25 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN6MatrixD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #2
  resume { ptr, i32 } %25

._crit_edge15:                                    ; preds = %._crit_edge, %3
  ret void
}

declare void @_ZN6MatrixC1Emm(ptr, i64, i64) local_unnamed_addr

attributes #0 = { 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 #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 = { 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 = !{!"_ZTS6Matrix", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIS_IdSaIdEESaIS1_EE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!6, !7, i64 8}
!16 = distinct !{!16, !17, !18}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.unswitch.partial.disable"}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !8, i64 0}
!21 = distinct !{!21, !17}


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