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

; 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_point(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)
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds [4 x %union.CgmVec4], ptr %33, i64 0, i64 3
  %35 = getelementptr inbounds %struct.anon.1, ptr %34, i32 0, i32 0
  %36 = load float, ptr %35, align 4, !tbaa !9
  %37 = fadd float %32, %36
  store float %37, ptr %11, align 4, !tbaa !10
  %38 = getelementptr inbounds %struct.anon.0, ptr %4, i32 0, i32 1
  %39 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 0
  %40 = load float, ptr %39, align 4, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds [4 x %union.CgmVec4], ptr %41, i64 0, i64 0
  %43 = getelementptr inbounds %struct.anon.1, ptr %42, i32 0, i32 1
  %44 = load float, ptr %43, align 4, !tbaa !9
  %45 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 1
  %46 = load float, ptr %45, align 4, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds [4 x %union.CgmVec4], ptr %47, i64 0, i64 1
  %49 = getelementptr inbounds %struct.anon.1, ptr %48, i32 0, i32 1
  %50 = load float, ptr %49, align 4, !tbaa !9
  %51 = fmul float %46, %50
  %52 = call float @llvm.fmuladd.f32(float %40, float %44, float %51)
  %53 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 2
  %54 = load float, ptr %53, align 4, !tbaa !9
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds [4 x %union.CgmVec4], ptr %55, i64 0, i64 2
  %57 = getelementptr inbounds %struct.anon.1, ptr %56, i32 0, i32 1
  %58 = load float, ptr %57, align 4, !tbaa !9
  %59 = call float @llvm.fmuladd.f32(float %54, float %58, float %52)
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds [4 x %union.CgmVec4], ptr %60, i64 0, i64 3
  %62 = getelementptr inbounds %struct.anon.1, ptr %61, i32 0, i32 1
  %63 = load float, ptr %62, align 4, !tbaa !9
  %64 = fadd float %59, %63
  store float %64, ptr %38, align 4, !tbaa !13
  %65 = getelementptr inbounds %struct.anon.0, ptr %4, i32 0, i32 2
  %66 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 0
  %67 = load float, ptr %66, align 4, !tbaa !9
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds [4 x %union.CgmVec4], ptr %68, i64 0, i64 0
  %70 = getelementptr inbounds %struct.anon.1, ptr %69, i32 0, i32 2
  %71 = load float, ptr %70, align 4, !tbaa !9
  %72 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 1
  %73 = load float, ptr %72, align 4, !tbaa !9
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds [4 x %union.CgmVec4], ptr %74, i64 0, i64 1
  %76 = getelementptr inbounds %struct.anon.1, ptr %75, i32 0, i32 2
  %77 = load float, ptr %76, align 4, !tbaa !9
  %78 = fmul float %73, %77
  %79 = call float @llvm.fmuladd.f32(float %67, float %71, float %78)
  %80 = getelementptr inbounds %struct.anon.0, ptr %5, i32 0, i32 2
  %81 = load float, ptr %80, align 4, !tbaa !9
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds [4 x %union.CgmVec4], ptr %82, i64 0, i64 2
  %84 = getelementptr inbounds %struct.anon.1, ptr %83, i32 0, i32 2
  %85 = load float, ptr %84, align 4, !tbaa !9
  %86 = call float @llvm.fmuladd.f32(float %81, float %85, float %79)
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds [4 x %union.CgmVec4], ptr %87, i64 0, i64 3
  %89 = getelementptr inbounds %struct.anon.1, ptr %88, i32 0, i32 2
  %90 = load float, ptr %89, align 4, !tbaa !9
  %91 = fadd float %86, %90
  store float %91, ptr %65, align 4, !tbaa !14
  %92 = getelementptr inbounds %union.CgmVec3, ptr %4, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 4 %92, i64 12, i1 false)
  %93 = load { <2 x float>, float }, ptr %8, align 8
  ret { <2 x float>, float } %93
}

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_point(ptr nocapture noundef readonly %0, <2 x float> %1, float %2) local_unnamed_addr #1 {
  %.sroa.014.0.vec.extract = extractelement <2 x float> %1, i64 0
  %.sroa.014.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 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load <2 x float>, ptr %0, align 4, !tbaa !5
  %8 = load <2 x float>, ptr %4, align 4, !tbaa !5
  %9 = shufflevector <2 x float> %1, <2 x float> poison, <2 x i32> <i32 1, i32 1>
  %10 = fmul <2 x float> %9, %8
  %11 = shufflevector <2 x float> %1, <2 x float> poison, <2 x i32> zeroinitializer
  %12 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %11, <2 x float> %7, <2 x float> %10)
  %13 = load <2 x float>, ptr %5, align 4, !tbaa !5
  %14 = insertelement <2 x float> poison, float %2, i64 0
  %15 = shufflevector <2 x float> %14, <2 x float> poison, <2 x i32> zeroinitializer
  %16 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %15, <2 x float> %13, <2 x float> %12)
  %17 = load <2 x float>, ptr %6, align 4, !tbaa !5
  %18 = fadd <2 x float> %17, %16
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load float, ptr %19, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load float, ptr %21, align 4, !tbaa !5
  %23 = fmul float %.sroa.014.4.vec.extract, %22
  %24 = tail call float @llvm.fmuladd.f32(float %.sroa.014.0.vec.extract, float %20, float %23)
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = load float, ptr %25, align 4, !tbaa !5
  %27 = tail call float @llvm.fmuladd.f32(float %2, float %26, float %24)
  %28 = getelementptr inbounds i8, ptr %0, i64 56
  %29 = load float, ptr %28, align 4, !tbaa !5
  %30 = fadd float %29, %27
  %.fca.0.insert = insertvalue { <2 x float>, float } poison, <2 x float> %18, 0
  %.fca.1.insert = insertvalue { <2 x float>, float } %.fca.0.insert, float %30, 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,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass