; LLVM IR from SoloGameDevGitHub/AIEngine :: Miscellaneous/Matrix.ll (ZN6Matrix8multiplyERKS_S1_RS_)

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

@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 x i8], align 1
@__PRETTY_FUNCTION__._ZN6Matrix8multiplyERKS_S1_RS_ = external hidden unnamed_addr constant [71 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Matrix3setEiid(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, double noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6Matrix8multiplyERKS_S1_RS_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(32) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, 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 %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %12)
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %14)
  %16 = icmp eq i32 %13, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  br label %20

18:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 74, ptr noundef @__PRETTY_FUNCTION__._ZN6Matrix8multiplyERKS_S1_RS_) #4
  unreachable

19:                                               ; No predecessors!
  br label %20

20:                                               ; preds = %19, %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %64, %20
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %23)
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %67

27:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %60, %27
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %30)
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %52, %34
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %37)
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %55

41:                                               ; preds = %35
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = call noundef double @_ZNK6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(32) %42, i32 noundef %43, i32 noundef %44)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = call noundef double @_ZNK6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(32) %46, i32 noundef %47, i32 noundef %48)
  %50 = load double, ptr %10, align 8, !tbaa !11
  %51 = call double @llvm.fmuladd.f64(double %45, double %49, double %50)
  store double %51, ptr %10, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %41
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %11, align 4, !tbaa !9
  br label %35, !llvm.loop !13

55:                                               ; preds = %40
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = load double, ptr %10, align 8, !tbaa !11
  call void @_ZN6Matrix3setEiid(ptr noundef nonnull align 8 dereferenceable(32) %56, i32 noundef %57, i32 noundef %58, double noundef %59)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %60

60:                                               ; preds = %55
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %9, align 4, !tbaa !9
  br label %28, !llvm.loop !15

63:                                               ; preds = %33
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %7, align 4, !tbaa !9
  br label %21, !llvm.loop !16

67:                                               ; preds = %26
  ret void
}

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

attributes #0 = { noreturn nounwind "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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { noreturn nounwind }
attributes #5 = { 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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 x i8], align 1
@__PRETTY_FUNCTION__._ZN6Matrix8multiplyERKS_S1_RS_ = external hidden unnamed_addr constant [71 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6Matrix8multiplyERKS_S1_RS_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(32) %2) local_unnamed_addr #1 align 2 {
  %4 = tail call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %5 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %6 = icmp eq i32 %4, %5
  br i1 %6, label %.preheader25, label %9

.preheader25:                                     ; preds = %3
  %7 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %2)
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.preheader24, label %._crit_edge31

9:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 74, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6Matrix8multiplyERKS_S1_RS_) #3
  unreachable

.preheader24:                                     ; preds = %.preheader25, %._crit_edge29
  %.02330 = phi i32 [ %14, %._crit_edge29 ], [ 0, %.preheader25 ]
  %10 = tail call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %2)
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.preheader, label %._crit_edge29

._crit_edge31:                                    ; preds = %._crit_edge29, %.preheader25
  ret void

.preheader:                                       ; preds = %.preheader24, %._crit_edge
  %.02228 = phi i32 [ %17, %._crit_edge ], [ 0, %.preheader24 ]
  %12 = tail call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

._crit_edge29:                                    ; preds = %._crit_edge, %.preheader24
  %14 = add nuw nsw i32 %.02330, 1
  %15 = tail call noundef i32 @_ZNK6Matrix7getRowsEv(ptr noundef nonnull align 8 dereferenceable(32) %2)
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %.preheader24, label %._crit_edge31, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.021.lcssa = phi double [ 0.000000e+00, %.preheader ], [ %22, %.lr.ph ]
  tail call void @_ZN6Matrix3setEiid(ptr noundef nonnull align 8 dereferenceable(32) %2, i32 noundef %.02330, i32 noundef %.02228, double noundef %.021.lcssa)
  %17 = add nuw nsw i32 %.02228, 1
  %18 = tail call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %2)
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %.preheader, label %._crit_edge29, !llvm.loop !7

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.027 = phi i32 [ %23, %.lr.ph ], [ 0, %.preheader ]
  %.02126 = phi double [ %22, %.lr.ph ], [ 0.000000e+00, %.preheader ]
  %20 = tail call noundef double @_ZNK6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %.02330, i32 noundef %.027)
  %21 = tail call noundef double @_ZNK6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(32) %1, i32 noundef %.027, i32 noundef %.02228)
  %22 = tail call double @llvm.fmuladd.f64(double %20, double %21, double %.02126)
  %23 = add nuw nsw i32 %.027, 1
  %24 = tail call noundef i32 @_ZNK6Matrix10getColumnsEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !8
}

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

attributes #0 = { noreturn nounwind "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 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


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