; LLVM IR from Mithreindeir/VelocityRaptor :: VelocityRaptor/src (vrMath)

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

%struct.vrMat2 = type { %struct.vrVec2, %struct.vrVec2 }
%struct.vrVec2 = type { float, float }

@.str = external hidden unnamed_addr constant [30 x i8], align 1

; 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) #0

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

; Function Attrs: inlinehint nounwind uwtable
define dso_local { <2 x float>, <2 x float> } @vrMat2Invert(<2 x float> %0, <2 x float> %1) #2 {
  %3 = alloca %struct.vrMat2, align 4
  %4 = alloca %struct.vrMat2, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 0
  store <2 x float> %0, ptr %10, align 4
  %11 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %4, i32 0, i32 1
  store <2 x float> %1, ptr %11, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %12 = getelementptr inbounds %struct.vrMat2, ptr %4, i32 0, i32 0
  %13 = getelementptr inbounds %struct.vrVec2, ptr %12, i32 0, i32 0
  %14 = load float, ptr %13, align 4, !tbaa !5
  store float %14, ptr %5, align 4, !tbaa !11
  %15 = getelementptr inbounds %struct.vrMat2, ptr %4, i32 0, i32 0
  %16 = getelementptr inbounds %struct.vrVec2, ptr %15, i32 0, i32 1
  %17 = load float, ptr %16, align 4, !tbaa !12
  store float %17, ptr %6, align 4, !tbaa !11
  %18 = getelementptr inbounds %struct.vrMat2, ptr %4, i32 0, i32 1
  %19 = getelementptr inbounds %struct.vrVec2, ptr %18, i32 0, i32 0
  %20 = load float, ptr %19, align 4, !tbaa !13
  store float %20, ptr %7, align 4, !tbaa !11
  %21 = getelementptr inbounds %struct.vrMat2, ptr %4, i32 0, i32 1
  %22 = getelementptr inbounds %struct.vrVec2, ptr %21, i32 0, i32 1
  %23 = load float, ptr %22, align 4, !tbaa !14
  store float %23, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %24 = load float, ptr %5, align 4, !tbaa !11
  %25 = load float, ptr %8, align 4, !tbaa !11
  %26 = load float, ptr %6, align 4, !tbaa !11
  %27 = load float, ptr %7, align 4, !tbaa !11
  %28 = fmul float %26, %27
  %29 = fneg float %28
  %30 = call float @llvm.fmuladd.f32(float %24, float %25, float %29)
  store float %30, ptr %9, align 4, !tbaa !11
  %31 = load float, ptr %9, align 4, !tbaa !11
  %32 = fcmp une float %31, 0.000000e+00
  %33 = xor i1 %32, true
  %34 = zext i1 %33 to i32
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %2
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @abort() #7
  unreachable

38:                                               ; preds = %2
  %39 = load float, ptr %9, align 4, !tbaa !11
  %40 = fpext float %39 to double
  %41 = fdiv double 1.000000e+00, %40
  %42 = fptrunc double %41 to float
  store float %42, ptr %9, align 4, !tbaa !11
  %43 = load float, ptr %8, align 4, !tbaa !11
  %44 = load float, ptr %9, align 4, !tbaa !11
  %45 = fmul float %43, %44
  %46 = getelementptr inbounds %struct.vrMat2, ptr %4, i32 0, i32 0
  %47 = getelementptr inbounds %struct.vrVec2, ptr %46, i32 0, i32 0
  store float %45, ptr %47, align 4, !tbaa !5
  %48 = load float, ptr %6, align 4, !tbaa !11
  %49 = fneg float %48
  %50 = load float, ptr %9, align 4, !tbaa !11
  %51 = fmul float %49, %50
  %52 = getelementptr inbounds %struct.vrMat2, ptr %4, i32 0, i32 0
  %53 = getelementptr inbounds %struct.vrVec2, ptr %52, i32 0, i32 1
  store float %51, ptr %53, align 4, !tbaa !12
  %54 = load float, ptr %7, align 4, !tbaa !11
  %55 = fneg float %54
  %56 = load float, ptr %9, align 4, !tbaa !11
  %57 = fmul float %55, %56
  %58 = getelementptr inbounds %struct.vrMat2, ptr %4, i32 0, i32 1
  %59 = getelementptr inbounds %struct.vrVec2, ptr %58, i32 0, i32 0
  store float %57, ptr %59, align 4, !tbaa !13
  %60 = load float, ptr %5, align 4, !tbaa !11
  %61 = load float, ptr %9, align 4, !tbaa !11
  %62 = fmul float %60, %61
  %63 = getelementptr inbounds %struct.vrMat2, ptr %4, i32 0, i32 1
  %64 = getelementptr inbounds %struct.vrVec2, ptr %63, i32 0, i32 1
  store float %62, ptr %64, align 4, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %4, i64 16, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %65 = load { <2 x float>, <2 x float> }, ptr %3, align 4
  ret { <2 x float>, <2 x float> } %65
}

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

declare i32 @printf(ptr noundef, ...) #4

; Function Attrs: noreturn nounwind
declare void @abort() #5

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { inlinehint 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" }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!6, !8, i64 0}
!6 = !{!"vrMat2", !7, i64 0, !7, i64 8}
!7 = !{!"vrVec2", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!8, !8, i64 0}
!12 = !{!6, !8, i64 4}
!13 = !{!6, !8, i64 8}
!14 = !{!6, !8, i64 12}
!15 = !{i64 0, i64 4, !11, i64 4, i64 4, !11, i64 8, i64 4, !11, i64 12, i64 4, !11}


; 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 = external hidden unnamed_addr constant [30 x i8], align 1

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

; Function Attrs: inlinehint nounwind uwtable
define dso_local { <2 x float>, <2 x float> } @vrMat2Invert(<2 x float> %0, <2 x float> %1) local_unnamed_addr #1 {
  %.sroa.0.0.vec.extract = extractelement <2 x float> %0, i64 0
  %.sroa.0.4.vec.extract = extractelement <2 x float> %0, i64 1
  %.sroa.6.8.vec.extract = extractelement <2 x float> %1, i64 0
  %.sroa.6.12.vec.extract = extractelement <2 x float> %1, i64 1
  %3 = fneg float %.sroa.0.4.vec.extract
  %4 = fmul float %.sroa.6.8.vec.extract, %3
  %5 = tail call float @llvm.fmuladd.f32(float %.sroa.0.0.vec.extract, float %.sroa.6.12.vec.extract, float %4)
  %6 = fcmp oeq float %5, 0.000000e+00
  br i1 %6, label %7, label %9

7:                                                ; preds = %2
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  tail call void @abort() #4
  unreachable

9:                                                ; preds = %2
  %10 = fdiv float 1.000000e+00, %5
  %11 = fmul float %.sroa.6.12.vec.extract, %10
  %.sroa.0.0.vec.insert = insertelement <2 x float> poison, float %11, i64 0
  %12 = fmul float %10, %3
  %.sroa.0.4.vec.insert = insertelement <2 x float> %.sroa.0.0.vec.insert, float %12, i64 1
  %13 = fneg float %.sroa.6.8.vec.extract
  %14 = fmul float %10, %13
  %.sroa.6.8.vec.insert = insertelement <2 x float> poison, float %14, i64 0
  %15 = fmul float %.sroa.0.0.vec.extract, %10
  %.sroa.6.12.vec.insert = insertelement <2 x float> %.sroa.6.8.vec.insert, float %15, i64 1
  %.fca.0.insert = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> %.sroa.0.4.vec.insert, 0
  %.fca.1.insert = insertvalue { <2 x float>, <2 x float> } %.fca.0.insert, <2 x float> %.sroa.6.12.vec.insert, 1
  ret { <2 x float>, <2 x float> } %.fca.1.insert
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { inlinehint 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" }
attributes #2 = { nofree 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 #3 = { 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 #4 = { 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)"}


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