; LLVM IR from ysyesilyurt/ComputerGraphics :: ForwardRenderingPipeline/Helpers.ll (Z22multiplyMatrixWithVec47Matrix44Vec4)

; 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.Vec4 = type <{ double, double, double, double, i32, [4 x i8] }>
%class.Matrix4 = type { [4 x [4 x double]] }

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 uwtable
define dso_local void @_Z22multiplyMatrixWithVec47Matrix44Vec4(ptr dead_on_unwind noalias writable sret(%class.Vec4) align 8 %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [4 x double], align 16
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = 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 @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %12

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

15:                                               ; preds = %12
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %45

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

17:                                               ; preds = %34, %16
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 4
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %37

21:                                               ; preds = %17
  %22 = getelementptr inbounds %class.Matrix4, ptr %1, i32 0, i32 0
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4 x [4 x double]], ptr %22, i64 0, i64 %24
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [4 x double], ptr %25, i64 0, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef %30)
  %32 = load double, ptr %8, align 8, !tbaa !11
  %33 = call double @llvm.fmuladd.f64(double %29, double %31, double %32)
  store double %33, ptr %8, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %21
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %11, align 4, !tbaa !9
  br label %17, !llvm.loop !13

37:                                               ; preds = %20
  %38 = load double, ptr %8, align 8, !tbaa !11
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [4 x double], ptr %7, i64 0, i64 %40
  store double %38, ptr %41, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %37
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %9, align 4, !tbaa !9
  br label %12, !llvm.loop !15

45:                                               ; preds = %15
  %46 = getelementptr inbounds [4 x double], ptr %7, i64 0, i64 0
  %47 = load double, ptr %46, align 16, !tbaa !11
  %48 = getelementptr inbounds [4 x double], ptr %7, i64 0, i64 1
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = getelementptr inbounds [4 x double], ptr %7, i64 0, i64 2
  %51 = load double, ptr %50, align 16, !tbaa !11
  %52 = getelementptr inbounds [4 x double], ptr %7, i64 0, i64 3
  %53 = load double, ptr %52, align 8, !tbaa !11
  %54 = getelementptr inbounds %class.Vec4, ptr %2, i32 0, i32 4
  %55 = load i32, ptr %54, align 8, !tbaa !16
  call void @_ZN4Vec4C1Eddddi(ptr noundef nonnull align 8 dereferenceable(36) %0, double noundef %47, double noundef %49, double noundef %51, double noundef %53, i32 noundef %55)
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #4
  ret void
}

declare noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36), i32 noundef) #3

declare void @_ZN4Vec4C1Eddddi(ptr noundef nonnull align 8 dereferenceable(36), double noundef, double noundef, double noundef, double noundef, i32 noundef) unnamed_addr #3

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !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 = !{!17, !10, i64 32}
!17 = !{!"_ZTS4Vec4", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !10, i64 32}


; 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.Vec4 = type <{ double, double, double, double, i32, [4 x i8] }>

; 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 @_Z22multiplyMatrixWithVec47Matrix44Vec4(ptr dead_on_unwind noalias writable sret(%class.Vec4) align 8 %0, ptr nocapture noundef readonly %1, ptr noundef nonnull %2) local_unnamed_addr #1 {
.preheader:
  %3 = load double, ptr %1, align 8, !tbaa !5
  %4 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 0)
  %5 = tail call double @llvm.fmuladd.f64(double %3, double %4, double 0.000000e+00)
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 1)
  %9 = tail call double @llvm.fmuladd.f64(double %7, double %8, double %5)
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 2)
  %13 = tail call double @llvm.fmuladd.f64(double %11, double %12, double %9)
  %14 = getelementptr inbounds i8, ptr %1, i64 24
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 3)
  %17 = tail call double @llvm.fmuladd.f64(double %15, double %16, double %13)
  %18 = getelementptr inbounds i8, ptr %1, i64 32
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 0)
  %21 = tail call double @llvm.fmuladd.f64(double %19, double %20, double 0.000000e+00)
  %22 = getelementptr inbounds i8, ptr %1, i64 40
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 1)
  %25 = tail call double @llvm.fmuladd.f64(double %23, double %24, double %21)
  %26 = getelementptr inbounds i8, ptr %1, i64 48
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 2)
  %29 = tail call double @llvm.fmuladd.f64(double %27, double %28, double %25)
  %30 = getelementptr inbounds i8, ptr %1, i64 56
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 3)
  %33 = tail call double @llvm.fmuladd.f64(double %31, double %32, double %29)
  %34 = getelementptr inbounds i8, ptr %1, i64 64
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 0)
  %37 = tail call double @llvm.fmuladd.f64(double %35, double %36, double 0.000000e+00)
  %38 = getelementptr inbounds i8, ptr %1, i64 72
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 1)
  %41 = tail call double @llvm.fmuladd.f64(double %39, double %40, double %37)
  %42 = getelementptr inbounds i8, ptr %1, i64 80
  %43 = load double, ptr %42, align 8, !tbaa !5
  %44 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 2)
  %45 = tail call double @llvm.fmuladd.f64(double %43, double %44, double %41)
  %46 = getelementptr inbounds i8, ptr %1, i64 88
  %47 = load double, ptr %46, align 8, !tbaa !5
  %48 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 3)
  %49 = tail call double @llvm.fmuladd.f64(double %47, double %48, double %45)
  %50 = getelementptr inbounds i8, ptr %1, i64 96
  %51 = load double, ptr %50, align 8, !tbaa !5
  %52 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 0)
  %53 = tail call double @llvm.fmuladd.f64(double %51, double %52, double 0.000000e+00)
  %54 = getelementptr inbounds i8, ptr %1, i64 104
  %55 = load double, ptr %54, align 8, !tbaa !5
  %56 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 1)
  %57 = tail call double @llvm.fmuladd.f64(double %55, double %56, double %53)
  %58 = getelementptr inbounds i8, ptr %1, i64 112
  %59 = load double, ptr %58, align 8, !tbaa !5
  %60 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 2)
  %61 = tail call double @llvm.fmuladd.f64(double %59, double %60, double %57)
  %62 = getelementptr inbounds i8, ptr %1, i64 120
  %63 = load double, ptr %62, align 8, !tbaa !5
  %64 = tail call noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36) %2, i32 noundef 3)
  %65 = tail call double @llvm.fmuladd.f64(double %63, double %64, double %61)
  %66 = getelementptr inbounds i8, ptr %2, i64 32
  %67 = load i32, ptr %66, align 8, !tbaa !9
  tail call void @_ZN4Vec4C1Eddddi(ptr noundef nonnull align 8 dereferenceable(36) %0, double noundef %17, double noundef %33, double noundef %49, double noundef %65, i32 noundef %67)
  ret void
}

declare noundef double @_ZN4Vec412getElementAtEi(ptr noundef nonnull align 8 dereferenceable(36), i32 noundef) local_unnamed_addr #2

declare void @_ZN4Vec4C1Eddddi(ptr noundef nonnull align 8 dereferenceable(36), double noundef, double noundef, double noundef, double noundef, i32 noundef) unnamed_addr #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 = { "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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 32}
!10 = !{!"_ZTS4Vec4", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!11 = !{!"int", !7, i64 0}


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