; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R3Matrix.ll (ZmlRK8R3MatrixS1_)

; 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.R3Matrix = type { [3 x [3 x 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: mustprogress uwtable
define dso_local void @_ZmlRK8R3MatrixS1_(ptr dead_on_unwind noalias writable sret(%class.R3Matrix) align 8 %0, ptr noundef nonnull align 8 dereferenceable(72) %1, ptr noundef nonnull align 8 dereferenceable(72) %2) #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
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @_ZN8R3MatrixC1Ev(ptr noundef nonnull align 8 dereferenceable(72) %0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %73, %3
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 3
  br i1 %11, label %12, label %76

12:                                               ; preds = %9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %69, %12
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 3
  br i1 %15, label %16, label %72

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.R3Matrix, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [3 x [3 x double]], ptr %18, i64 0, i64 %20
  %22 = getelementptr inbounds [3 x double], ptr %21, i64 0, i64 0
  %23 = load double, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %class.R3Matrix, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [3 x [3 x double]], ptr %25, i64 0, i64 0
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [3 x double], ptr %26, i64 0, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.R3Matrix, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [3 x [3 x double]], ptr %32, i64 0, i64 %34
  %36 = getelementptr inbounds [3 x double], ptr %35, i64 0, i64 1
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %class.R3Matrix, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [3 x [3 x double]], ptr %39, i64 0, i64 1
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [3 x double], ptr %40, i64 0, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = fmul double %37, %44
  %46 = call double @llvm.fmuladd.f64(double %23, double %30, double %45)
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.R3Matrix, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [3 x [3 x double]], ptr %48, i64 0, i64 %50
  %52 = getelementptr inbounds [3 x double], ptr %51, i64 0, i64 2
  %53 = load double, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.R3Matrix, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds [3 x [3 x double]], ptr %55, i64 0, i64 2
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [3 x double], ptr %56, i64 0, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !11
  %61 = call double @llvm.fmuladd.f64(double %53, double %60, double %46)
  %62 = getelementptr inbounds %class.R3Matrix, ptr %0, i32 0, i32 0
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [3 x [3 x double]], ptr %62, i64 0, i64 %64
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [3 x double], ptr %65, i64 0, i64 %67
  store double %61, ptr %68, align 8, !tbaa !11
  br label %69

69:                                               ; preds = %16
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %8, align 4, !tbaa !9
  br label %13, !llvm.loop !13

72:                                               ; preds = %13
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !9
  br label %9, !llvm.loop !15

76:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

declare void @_ZN8R3MatrixC1Ev(ptr)

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

%class.R3Matrix = type { [3 x [3 x double]] }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZmlRK8R3MatrixS1_(ptr dead_on_unwind noalias writable sret(%class.R3Matrix) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(72) %2) local_unnamed_addr #1 {
.preheader:
  tail call void @_ZN8R3MatrixC1Ev(ptr noundef nonnull align 8 dereferenceable(72) %0)
  %3 = getelementptr inbounds i8, ptr %2, i64 24
  %4 = getelementptr inbounds i8, ptr %2, i64 48
  %5 = load <2 x double>, ptr %1, align 8
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load <2 x double>, ptr %6, align 8
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load <2 x double>, ptr %8, align 8
  %10 = load <2 x double>, ptr %2, align 8, !tbaa !5
  %11 = load <2 x double>, ptr %3, align 8, !tbaa !5
  %12 = shufflevector <2 x double> %7, <2 x double> poison, <2 x i32> zeroinitializer
  %13 = fmul <2 x double> %12, %11
  %14 = shufflevector <2 x double> %5, <2 x double> poison, <2 x i32> zeroinitializer
  %15 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %14, <2 x double> %10, <2 x double> %13)
  %16 = load <2 x double>, ptr %4, align 8, !tbaa !5
  %17 = shufflevector <2 x double> %9, <2 x double> poison, <2 x i32> zeroinitializer
  %18 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %17, <2 x double> %16, <2 x double> %15)
  store <2 x double> %18, ptr %0, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %2, i64 16
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %2, i64 40
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %2, i64 64
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = getelementptr inbounds i8, ptr %1, i64 24
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %1, i64 32
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %1, i64 40
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = insertelement <2 x double> %7, double %29, i64 1
  %33 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %34 = insertelement <2 x double> %33, double %22, i64 0
  %35 = fmul <2 x double> %32, %34
  %36 = insertelement <2 x double> %5, double %27, i64 1
  %37 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %38 = insertelement <2 x double> %37, double %20, i64 0
  %39 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %36, <2 x double> %38, <2 x double> %35)
  %40 = insertelement <2 x double> %9, double %31, i64 1
  %41 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %42 = insertelement <2 x double> %41, double %24, i64 0
  %43 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %40, <2 x double> %42, <2 x double> %39)
  store <2 x double> %43, ptr %25, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %0, i64 32
  %45 = insertelement <2 x double> poison, double %29, i64 0
  %46 = shufflevector <2 x double> %45, <2 x double> poison, <2 x i32> zeroinitializer
  %47 = insertelement <2 x double> %33, double %22, i64 1
  %48 = fmul <2 x double> %46, %47
  %49 = insertelement <2 x double> poison, double %27, i64 0
  %50 = shufflevector <2 x double> %49, <2 x double> poison, <2 x i32> zeroinitializer
  %51 = insertelement <2 x double> %37, double %20, i64 1
  %52 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %50, <2 x double> %51, <2 x double> %48)
  %53 = insertelement <2 x double> poison, double %31, i64 0
  %54 = shufflevector <2 x double> %53, <2 x double> poison, <2 x i32> zeroinitializer
  %55 = insertelement <2 x double> %41, double %24, i64 1
  %56 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %54, <2 x double> %55, <2 x double> %52)
  store <2 x double> %56, ptr %44, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %1, i64 48
  %58 = load double, ptr %57, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %1, i64 56
  %60 = load double, ptr %59, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %1, i64 64
  %62 = load double, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %0, i64 48
  %64 = insertelement <2 x double> poison, double %60, i64 0
  %65 = shufflevector <2 x double> %64, <2 x double> poison, <2 x i32> zeroinitializer
  %66 = fmul <2 x double> %65, %11
  %67 = insertelement <2 x double> poison, double %58, i64 0
  %68 = shufflevector <2 x double> %67, <2 x double> poison, <2 x i32> zeroinitializer
  %69 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %68, <2 x double> %10, <2 x double> %66)
  %70 = insertelement <2 x double> poison, double %62, i64 0
  %71 = shufflevector <2 x double> %70, <2 x double> poison, <2 x i32> zeroinitializer
  %72 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %71, <2 x double> %16, <2 x double> %69)
  store <2 x double> %72, ptr %63, align 8, !tbaa !5
  %73 = fmul double %60, %22
  %74 = tail call double @llvm.fmuladd.f64(double %58, double %20, double %73)
  %75 = tail call double @llvm.fmuladd.f64(double %62, double %24, double %74)
  %76 = getelementptr inbounds i8, ptr %0, i64 64
  store double %75, ptr %76, align 8, !tbaa !5
  ret void
}

declare void @_ZN8R3MatrixC1Ev(ptr) local_unnamed_addr

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass