; LLVM IR from heroseh/cgm :: cgm (CgmMat4x4_mul_vector)

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

%union.CgmVec3 = type { %struct.anon.0 }
%struct.anon.0 = type { float, float, float }
%union.CgmVec4 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float, float, float }

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local { <2 x float>, float } @CgmMat4x4_mul_vector(ptr noundef %0, <2 x float> %1, float %2) #2 {
  %4 = alloca %union.CgmVec3, align 4
  %5 = alloca %union.CgmVec3, align 4
  %6 = alloca { <2 x float>, float }, align 4
  %7 = alloca ptr, align 8
  %8 = alloca { <2 x float>, float }, align 8
  %9 = getelementptr inbounds { <2 x float>, float }, ptr %6, i32 0, i32 0
  store <2 x float> %1, ptr %9, align 4
  %10 = getelementptr inbounds { <2 x float>, float }, ptr %6, i32 0, i32 1
  store float %2, ptr %10, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %6, i64 12, i1 false)
  store ptr %0, ptr %7, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.anon.0, ptr %4, i32 0, i32 0
  %12 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 0
  %13 = load float, ptr %12, align 4, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds [4 x %union.CgmVec4], ptr %14, i64 0, i64 0
  %16 = getelementptr inbounds %struct.anon.1, ptr %15, i32 0, i32 0
  %17 = load float, ptr %16, align 4, !tbaa !9
  %18 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 1
  %19 = load float, ptr %18, align 4, !tbaa !9
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds [4 x %union.CgmVec4], ptr %20, i64 0, i64 1
  %22 = getelementptr inbounds %struct.anon.1, ptr %21, i32 0, i32 0
  %23 = load float, ptr %22, align 4, !tbaa !9
  %24 = fmul float %19, %23
  %25 = call float @llvm.fmuladd.f32(float %13, float %17, float %24)
  %26 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 2
  %27 = load float, ptr %26, align 4, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds [4 x %union.CgmVec4], ptr %28, i64 0, i64 2
  %30 = getelementptr inbounds %struct.anon.1, ptr %29, i32 0, i32 0
  %31 = load float, ptr %30, align 4, !tbaa !9
  %32 = call float @llvm.fmuladd.f32(float %27, float %31, float %25)
  store float %32, ptr %11, align 4, !tbaa !10
  %33 = getelementptr inbounds %struct.anon.0, ptr %4, i32 0, i32 1
  %34 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 0
  %35 = load float, ptr %34, align 4, !tbaa !9
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds [4 x %union.CgmVec4], ptr %36, i64 0, i64 0
  %38 = getelementptr inbounds %struct.anon.1, ptr %37, i32 0, i32 1
  %39 = load float, ptr %38, align 4, !tbaa !9
  %40 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 1
  %41 = load float, ptr %40, align 4, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds [4 x %union.CgmVec4], ptr %42, i64 0, i64 1
  %44 = getelementptr inbounds %struct.anon.1, ptr %43, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !9
  %46 = fmul float %41, %45
  %47 = call float @llvm.fmuladd.f32(float %35, float %39, float %46)
  %48 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 2
  %49 = load float, ptr %48, align 4, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds [4 x %union.CgmVec4], ptr %50, i64 0, i64 2
  %52 = getelementptr inbounds %struct.anon.1, ptr %51, i32 0, i32 1
  %53 = load float, ptr %52, align 4, !tbaa !9
  %54 = call float @llvm.fmuladd.f32(float %49, float %53, float %47)
  store float %54, ptr %33, align 4, !tbaa !13
  %55 = getelementptr inbounds %struct.anon.0, ptr %4, i32 0, i32 2
  %56 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 0
  %57 = load float, ptr %56, align 4, !tbaa !9
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds [4 x %union.CgmVec4], ptr %58, i64 0, i64 0
  %60 = getelementptr inbounds %struct.anon.1, ptr %59, i32 0, i32 2
  %61 = load float, ptr %60, align 4, !tbaa !9
  %62 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 1
  %63 = load float, ptr %62, align 4, !tbaa !9
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds [4 x %union.CgmVec4], ptr %64, i64 0, i64 1
  %66 = getelementptr inbounds %struct.anon.1, ptr %65, i32 0, i32 2
  %67 = load float, ptr %66, align 4, !tbaa !9
  %68 = fmul float %63, %67
  %69 = call float @llvm.fmuladd.f32(float %57, float %61, float %68)
  %70 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 2
  %71 = load float, ptr %70, align 4, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds [4 x %union.CgmVec4], ptr %72, i64 0, i64 2
  %74 = getelementptr inbounds %struct.anon.1, ptr %73, i32 0, i32 2
  %75 = load float, ptr %74, align 4, !tbaa !9
  %76 = call float @llvm.fmuladd.f32(float %71, float %75, float %69)
  store float %76, ptr %55, align 4, !tbaa !14
  %77 = getelementptr inbounds %union.CgmVec3, ptr %4, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 4 %77, i64 12, i1 false)
  %78 = load { <2 x float>, float }, ptr %8, align 8
  ret { <2 x float>, float } %78
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="64" "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"float", !7, i64 0}
!13 = !{!11, !12, i64 4}
!14 = !{!11, !12, i64 8}


; 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 float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local { <2 x float>, float } @CgmMat4x4_mul_vector(ptr nocapture noundef readonly %0, <2 x float> %1, float %2) local_unnamed_addr #1 {
  %.sroa.011.0.vec.extract = extractelement <2 x float> %1, i64 0
  %.sroa.011.4.vec.extract = extractelement <2 x float> %1, i64 1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load <2 x float>, ptr %0, align 4, !tbaa !5
  %7 = load <2 x float>, ptr %4, align 4, !tbaa !5
  %8 = shufflevector <2 x float> %1, <2 x float> poison, <2 x i32> <i32 1, i32 1>
  %9 = fmul <2 x float> %8, %7
  %10 = shufflevector <2 x float> %1, <2 x float> poison, <2 x i32> zeroinitializer
  %11 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %10, <2 x float> %6, <2 x float> %9)
  %12 = load <2 x float>, ptr %5, align 4, !tbaa !5
  %13 = insertelement <2 x float> poison, float %2, i64 0
  %14 = shufflevector <2 x float> %13, <2 x float> poison, <2 x i32> zeroinitializer
  %15 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %14, <2 x float> %12, <2 x float> %11)
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load float, ptr %16, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = fmul float %.sroa.011.4.vec.extract, %19
  %21 = tail call float @llvm.fmuladd.f32(float %.sroa.011.0.vec.extract, float %17, float %20)
  %22 = getelementptr inbounds i8, ptr %0, i64 40
  %23 = load float, ptr %22, align 4, !tbaa !5
  %24 = tail call float @llvm.fmuladd.f32(float %2, float %23, float %21)
  %.fca.0.insert = insertvalue { <2 x float>, float } poison, <2 x float> %15, 0
  %.fca.1.insert = insertvalue { <2 x float>, float } %.fca.0.insert, float %24, 1
  ret { <2 x float>, float } %.fca.1.insert
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable "min-legal-vector-width"="64" "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass