; LLVM IR from szxp/3d-soft-engine :: src/Quaternion.ll (ZN2g320createRotationMatrixERKNS_10QuaternionE)

; 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.g3::Mat" = type { [16 x float] }
%"class.std::initializer_list" = type { ptr, i64 }
%"struct.g3::Quaternion" = type { %"class.g3::Vec", float }
%"class.g3::Vec" = type { [3 x float] }

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK2g33VecILm3EEixEi(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2g320createRotationMatrixERKNS_10QuaternionE(ptr dead_on_unwind noalias writable sret(%"class.g3::Mat") align 4 %0, ptr noundef nonnull align 4 dereferenceable(16) %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca %"class.std::initializer_list", align 8
  %10 = alloca [16 x float], align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.g3::Quaternion", ptr %11, i32 0, i32 0
  %13 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK2g33VecILm3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %12, i32 noundef 0)
  %14 = load float, ptr %13, align 4, !tbaa !9
  store float %14, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.g3::Quaternion", ptr %15, i32 0, i32 0
  %17 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK2g33VecILm3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %16, i32 noundef 1)
  %18 = load float, ptr %17, align 4, !tbaa !9
  store float %18, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.g3::Quaternion", ptr %19, i32 0, i32 0
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK2g33VecILm3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %20, i32 noundef 2)
  %22 = load float, ptr %21, align 4, !tbaa !9
  store float %22, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.g3::Quaternion", ptr %23, i32 0, i32 1
  %25 = load float, ptr %24, align 4, !tbaa !11
  store float %25, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %10) #4
  %26 = load float, ptr %6, align 4, !tbaa !9
  %27 = fmul float 2.000000e+00, %26
  %28 = load float, ptr %6, align 4, !tbaa !9
  %29 = fneg float %27
  %30 = call float @llvm.fmuladd.f32(float %29, float %28, float 1.000000e+00)
  %31 = load float, ptr %7, align 4, !tbaa !9
  %32 = fmul float 2.000000e+00, %31
  %33 = load float, ptr %7, align 4, !tbaa !9
  %34 = fneg float %32
  %35 = call float @llvm.fmuladd.f32(float %34, float %33, float %30)
  store float %35, ptr %10, align 4, !tbaa !9
  %36 = getelementptr inbounds float, ptr %10, i64 1
  %37 = load float, ptr %5, align 4, !tbaa !9
  %38 = fmul float 2.000000e+00, %37
  %39 = load float, ptr %6, align 4, !tbaa !9
  %40 = load float, ptr %8, align 4, !tbaa !9
  %41 = fmul float 2.000000e+00, %40
  %42 = load float, ptr %7, align 4, !tbaa !9
  %43 = fmul float %41, %42
  %44 = call float @llvm.fmuladd.f32(float %38, float %39, float %43)
  store float %44, ptr %36, align 4, !tbaa !9
  %45 = getelementptr inbounds float, ptr %10, i64 2
  %46 = load float, ptr %5, align 4, !tbaa !9
  %47 = fmul float 2.000000e+00, %46
  %48 = load float, ptr %7, align 4, !tbaa !9
  %49 = load float, ptr %8, align 4, !tbaa !9
  %50 = fmul float 2.000000e+00, %49
  %51 = load float, ptr %6, align 4, !tbaa !9
  %52 = fmul float %50, %51
  %53 = fneg float %52
  %54 = call float @llvm.fmuladd.f32(float %47, float %48, float %53)
  store float %54, ptr %45, align 4, !tbaa !9
  %55 = getelementptr inbounds float, ptr %10, i64 3
  store float 0.000000e+00, ptr %55, align 4, !tbaa !9
  %56 = getelementptr inbounds float, ptr %10, i64 4
  %57 = load float, ptr %5, align 4, !tbaa !9
  %58 = fmul float 2.000000e+00, %57
  %59 = load float, ptr %6, align 4, !tbaa !9
  %60 = load float, ptr %8, align 4, !tbaa !9
  %61 = fmul float 2.000000e+00, %60
  %62 = load float, ptr %7, align 4, !tbaa !9
  %63 = fmul float %61, %62
  %64 = fneg float %63
  %65 = call float @llvm.fmuladd.f32(float %58, float %59, float %64)
  store float %65, ptr %56, align 4, !tbaa !9
  %66 = getelementptr inbounds float, ptr %10, i64 5
  %67 = load float, ptr %5, align 4, !tbaa !9
  %68 = fmul float 2.000000e+00, %67
  %69 = load float, ptr %5, align 4, !tbaa !9
  %70 = fneg float %68
  %71 = call float @llvm.fmuladd.f32(float %70, float %69, float 1.000000e+00)
  %72 = load float, ptr %7, align 4, !tbaa !9
  %73 = fmul float 2.000000e+00, %72
  %74 = load float, ptr %7, align 4, !tbaa !9
  %75 = fneg float %73
  %76 = call float @llvm.fmuladd.f32(float %75, float %74, float %71)
  store float %76, ptr %66, align 4, !tbaa !9
  %77 = getelementptr inbounds float, ptr %10, i64 6
  %78 = load float, ptr %6, align 4, !tbaa !9
  %79 = fmul float 2.000000e+00, %78
  %80 = load float, ptr %7, align 4, !tbaa !9
  %81 = load float, ptr %8, align 4, !tbaa !9
  %82 = fmul float 2.000000e+00, %81
  %83 = load float, ptr %5, align 4, !tbaa !9
  %84 = fmul float %82, %83
  %85 = call float @llvm.fmuladd.f32(float %79, float %80, float %84)
  store float %85, ptr %77, align 4, !tbaa !9
  %86 = getelementptr inbounds float, ptr %10, i64 7
  store float 0.000000e+00, ptr %86, align 4, !tbaa !9
  %87 = getelementptr inbounds float, ptr %10, i64 8
  %88 = load float, ptr %5, align 4, !tbaa !9
  %89 = fmul float 2.000000e+00, %88
  %90 = load float, ptr %7, align 4, !tbaa !9
  %91 = load float, ptr %8, align 4, !tbaa !9
  %92 = fmul float 2.000000e+00, %91
  %93 = load float, ptr %6, align 4, !tbaa !9
  %94 = fmul float %92, %93
  %95 = call float @llvm.fmuladd.f32(float %89, float %90, float %94)
  store float %95, ptr %87, align 4, !tbaa !9
  %96 = getelementptr inbounds float, ptr %10, i64 9
  %97 = load float, ptr %6, align 4, !tbaa !9
  %98 = fmul float 2.000000e+00, %97
  %99 = load float, ptr %7, align 4, !tbaa !9
  %100 = load float, ptr %8, align 4, !tbaa !9
  %101 = fmul float 2.000000e+00, %100
  %102 = load float, ptr %5, align 4, !tbaa !9
  %103 = fmul float %101, %102
  %104 = fneg float %103
  %105 = call float @llvm.fmuladd.f32(float %98, float %99, float %104)
  store float %105, ptr %96, align 4, !tbaa !9
  %106 = getelementptr inbounds float, ptr %10, i64 10
  %107 = load float, ptr %5, align 4, !tbaa !9
  %108 = fmul float 2.000000e+00, %107
  %109 = load float, ptr %5, align 4, !tbaa !9
  %110 = fneg float %108
  %111 = call float @llvm.fmuladd.f32(float %110, float %109, float 1.000000e+00)
  %112 = load float, ptr %6, align 4, !tbaa !9
  %113 = fmul float 2.000000e+00, %112
  %114 = load float, ptr %6, align 4, !tbaa !9
  %115 = fneg float %113
  %116 = call float @llvm.fmuladd.f32(float %115, float %114, float %111)
  store float %116, ptr %106, align 4, !tbaa !9
  %117 = getelementptr inbounds float, ptr %10, i64 11
  store float 0.000000e+00, ptr %117, align 4, !tbaa !9
  %118 = getelementptr inbounds float, ptr %10, i64 12
  store float 0.000000e+00, ptr %118, align 4, !tbaa !9
  %119 = getelementptr inbounds float, ptr %10, i64 13
  store float 0.000000e+00, ptr %119, align 4, !tbaa !9
  %120 = getelementptr inbounds float, ptr %10, i64 14
  store float 0.000000e+00, ptr %120, align 4, !tbaa !9
  %121 = getelementptr inbounds float, ptr %10, i64 15
  store float 1.000000e+00, ptr %121, align 4, !tbaa !9
  %122 = getelementptr inbounds %"class.std::initializer_list", ptr %9, i32 0, i32 0
  store ptr %10, ptr %122, align 8, !tbaa !14
  %123 = getelementptr inbounds %"class.std::initializer_list", ptr %9, i32 0, i32 1
  store i64 16, ptr %123, align 8, !tbaa !17
  %124 = getelementptr inbounds { ptr, i64 }, ptr %9, i32 0, i32 0
  %125 = load ptr, ptr %124, align 8
  %126 = getelementptr inbounds { ptr, i64 }, ptr %9, i32 0, i32 1
  %127 = load i64, ptr %126, align 8
  call void @_ZN2g33MatILm4EEC2ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(64) %0, ptr %125, i64 %127)
  call void @llvm.lifetime.end.p0(i64 64, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2g33MatILm4EEC2ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(64), ptr, i64) unnamed_addr #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind 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) }
attributes #3 = { 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 #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 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"_ZTSN2g310QuaternionE", !13, i64 0, !10, i64 12}
!13 = !{!"_ZTSN2g33VecILm3EEE", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSSt16initializer_listIfE", !6, i64 0, !16, i64 8}
!16 = !{!"long", !7, i64 0}
!17 = !{!15, !16, 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"

%"class.g3::Mat" = type { [16 x float] }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNK2g33VecILm3EEixEi(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2g320createRotationMatrixERKNS_10QuaternionE(ptr dead_on_unwind noalias writable sret(%"class.g3::Mat") align 4 %0, ptr noundef nonnull align 4 dereferenceable(16) %1) local_unnamed_addr #1 {
  %3 = alloca [16 x float], align 8
  %4 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK2g33VecILm3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %1, i32 noundef 0)
  %5 = load float, ptr %4, align 4, !tbaa !5
  %6 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK2g33VecILm3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %1, i32 noundef 1)
  %7 = load float, ptr %6, align 4, !tbaa !5
  %8 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK2g33VecILm3EEixEi(ptr noundef nonnull align 4 dereferenceable(12) %1, i32 noundef 2)
  %9 = load float, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %1, i64 12
  %11 = load float, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #5
  %12 = fmul float %7, 2.000000e+00
  %13 = fneg float %12
  %14 = tail call float @llvm.fmuladd.f32(float %13, float %7, float 1.000000e+00)
  %15 = fmul float %11, 2.000000e+00
  %16 = fmul float %9, %15
  %17 = insertelement <2 x float> poison, float %9, i64 0
  %18 = insertelement <2 x float> %17, float %5, i64 1
  %19 = fmul <2 x float> %18, <float -2.000000e+00, float 2.000000e+00>
  %20 = insertelement <2 x float> %17, float %7, i64 1
  %21 = insertelement <2 x float> poison, float %14, i64 0
  %22 = insertelement <2 x float> %21, float %16, i64 1
  %23 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %19, <2 x float> %20, <2 x float> %22)
  store <2 x float> %23, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %3, i64 8
  %25 = fmul float %7, %15
  %26 = fneg float %25
  %27 = extractelement <2 x float> %19, i64 1
  %28 = tail call float @llvm.fmuladd.f32(float %27, float %9, float %26)
  store float %28, ptr %24, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %3, i64 12
  store float 0.000000e+00, ptr %29, align 4, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %3, i64 16
  %31 = fneg float %16
  %32 = fneg float %27
  %33 = tail call float @llvm.fmuladd.f32(float %32, float %5, float 1.000000e+00)
  %34 = insertelement <2 x float> poison, float %33, i64 0
  %35 = insertelement <2 x float> %34, float %31, i64 1
  %36 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %19, <2 x float> %20, <2 x float> %35)
  %37 = shufflevector <2 x float> %36, <2 x float> poison, <2 x i32> <i32 1, i32 0>
  store <2 x float> %37, ptr %30, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %3, i64 24
  %39 = fmul float %5, %15
  %40 = tail call float @llvm.fmuladd.f32(float %12, float %9, float %39)
  store float %40, ptr %38, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %3, i64 28
  store float 0.000000e+00, ptr %41, align 4, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %3, i64 32
  %43 = tail call float @llvm.fmuladd.f32(float %27, float %9, float %25)
  store float %43, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %3, i64 36
  %45 = fneg float %39
  %46 = insertelement <2 x float> poison, float %12, i64 0
  %47 = insertelement <2 x float> %46, float %13, i64 1
  %48 = insertelement <2 x float> poison, float %45, i64 0
  %49 = insertelement <2 x float> %48, float %33, i64 1
  %50 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %47, <2 x float> %20, <2 x float> %49)
  store <2 x float> %50, ptr %44, align 4, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %3, i64 44
  %52 = getelementptr inbounds i8, ptr %3, i64 60
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %51, i8 0, i64 16, i1 false)
  store float 1.000000e+00, ptr %52, align 4, !tbaa !5
  call void @_ZN2g33MatILm4EEC2ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(64) %0, ptr nonnull %3, i64 16)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #5
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2g33MatILm4EEC2ESt16initializer_listIfE(ptr noundef nonnull align 4 dereferenceable(64), ptr, i64) unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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


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