; LLVM IR from achilles288/robot-monitor-graphics :: src/base/math/euler.ll (ZNK3rmg5Euler16toRotationMatrixEv)

; 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.rmg::Mat3" = type { %union.anon }
%union.anon = type { [3 x [3 x float]] }
%"struct.rmg::Mat3Row" = type { [3 x float] }
%"struct.rmg::Euler" = type { float, float, float }

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

; Function Attrs: nounwind
declare double @cos(double noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK3rmg5Euler16toRotationMatrixEv(ptr dead_on_unwind noalias writable sret(%"struct.rmg::Mat3") align 4 %0, ptr noundef nonnull align 4 dereferenceable(12) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca float, 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 = alloca %"struct.rmg::Mat3Row", align 4
  %11 = alloca %"struct.rmg::Mat3Row", align 4
  %12 = alloca %"struct.rmg::Mat3Row", align 4
  %13 = alloca { <2 x float>, float }, align 4
  %14 = alloca { <2 x float>, float }, align 4
  %15 = alloca { <2 x float>, float }, align 4
  store ptr %1, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %17 = getelementptr inbounds %"struct.rmg::Euler", ptr %16, i32 0, i32 0
  %18 = load float, ptr %17, align 4, !tbaa !9
  %19 = fpext float %18 to double
  %20 = call double @cos(double noundef %19) #6
  %21 = fptrunc double %20 to float
  store float %21, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %22 = getelementptr inbounds %"struct.rmg::Euler", ptr %16, i32 0, i32 1
  %23 = load float, ptr %22, align 4, !tbaa !13
  %24 = fpext float %23 to double
  %25 = call double @cos(double noundef %24) #6
  %26 = fptrunc double %25 to float
  store float %26, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %27 = getelementptr inbounds %"struct.rmg::Euler", ptr %16, i32 0, i32 2
  %28 = load float, ptr %27, align 4, !tbaa !14
  %29 = fpext float %28 to double
  %30 = call double @cos(double noundef %29) #6
  %31 = fptrunc double %30 to float
  store float %31, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %32 = getelementptr inbounds %"struct.rmg::Euler", ptr %16, i32 0, i32 0
  %33 = load float, ptr %32, align 4, !tbaa !9
  %34 = fpext float %33 to double
  %35 = call double @sin(double noundef %34) #6
  %36 = fptrunc double %35 to float
  store float %36, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %37 = getelementptr inbounds %"struct.rmg::Euler", ptr %16, i32 0, i32 1
  %38 = load float, ptr %37, align 4, !tbaa !13
  %39 = fpext float %38 to double
  %40 = call double @sin(double noundef %39) #6
  %41 = fptrunc double %40 to float
  store float %41, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %42 = getelementptr inbounds %"struct.rmg::Euler", ptr %16, i32 0, i32 2
  %43 = load float, ptr %42, align 4, !tbaa !14
  %44 = fpext float %43 to double
  %45 = call double @sin(double noundef %44) #6
  %46 = fptrunc double %45 to float
  store float %46, ptr %9, align 4, !tbaa !12
  %47 = getelementptr inbounds %"struct.rmg::Mat3Row", ptr %10, i32 0, i32 0
  %48 = load float, ptr %5, align 4, !tbaa !12
  %49 = load float, ptr %6, align 4, !tbaa !12
  %50 = fmul float %48, %49
  store float %50, ptr %47, align 4, !tbaa !12
  %51 = getelementptr inbounds float, ptr %47, i64 1
  %52 = load float, ptr %7, align 4, !tbaa !12
  %53 = load float, ptr %8, align 4, !tbaa !12
  %54 = fmul float %52, %53
  %55 = load float, ptr %6, align 4, !tbaa !12
  %56 = load float, ptr %4, align 4, !tbaa !12
  %57 = load float, ptr %9, align 4, !tbaa !12
  %58 = fmul float %56, %57
  %59 = fneg float %58
  %60 = call float @llvm.fmuladd.f32(float %54, float %55, float %59)
  store float %60, ptr %51, align 4, !tbaa !12
  %61 = getelementptr inbounds float, ptr %47, i64 2
  %62 = load float, ptr %4, align 4, !tbaa !12
  %63 = load float, ptr %8, align 4, !tbaa !12
  %64 = fmul float %62, %63
  %65 = load float, ptr %6, align 4, !tbaa !12
  %66 = load float, ptr %7, align 4, !tbaa !12
  %67 = load float, ptr %9, align 4, !tbaa !12
  %68 = fmul float %66, %67
  %69 = call float @llvm.fmuladd.f32(float %64, float %65, float %68)
  store float %69, ptr %61, align 4, !tbaa !12
  %70 = getelementptr inbounds %"struct.rmg::Mat3Row", ptr %11, i32 0, i32 0
  %71 = load float, ptr %5, align 4, !tbaa !12
  %72 = load float, ptr %9, align 4, !tbaa !12
  %73 = fmul float %71, %72
  store float %73, ptr %70, align 4, !tbaa !12
  %74 = getelementptr inbounds float, ptr %70, i64 1
  %75 = load float, ptr %7, align 4, !tbaa !12
  %76 = load float, ptr %8, align 4, !tbaa !12
  %77 = fmul float %75, %76
  %78 = load float, ptr %9, align 4, !tbaa !12
  %79 = load float, ptr %4, align 4, !tbaa !12
  %80 = load float, ptr %6, align 4, !tbaa !12
  %81 = fmul float %79, %80
  %82 = call float @llvm.fmuladd.f32(float %77, float %78, float %81)
  store float %82, ptr %74, align 4, !tbaa !12
  %83 = getelementptr inbounds float, ptr %70, i64 2
  %84 = load float, ptr %4, align 4, !tbaa !12
  %85 = load float, ptr %8, align 4, !tbaa !12
  %86 = fmul float %84, %85
  %87 = load float, ptr %9, align 4, !tbaa !12
  %88 = load float, ptr %7, align 4, !tbaa !12
  %89 = load float, ptr %6, align 4, !tbaa !12
  %90 = fmul float %88, %89
  %91 = fneg float %90
  %92 = call float @llvm.fmuladd.f32(float %86, float %87, float %91)
  store float %92, ptr %83, align 4, !tbaa !12
  %93 = getelementptr inbounds %"struct.rmg::Mat3Row", ptr %12, i32 0, i32 0
  %94 = load float, ptr %8, align 4, !tbaa !12
  %95 = fneg float %94
  store float %95, ptr %93, align 4, !tbaa !12
  %96 = getelementptr inbounds float, ptr %93, i64 1
  %97 = load float, ptr %7, align 4, !tbaa !12
  %98 = load float, ptr %5, align 4, !tbaa !12
  %99 = fmul float %97, %98
  store float %99, ptr %96, align 4, !tbaa !12
  %100 = getelementptr inbounds float, ptr %93, i64 2
  %101 = load float, ptr %4, align 4, !tbaa !12
  %102 = load float, ptr %5, align 4, !tbaa !12
  %103 = fmul float %101, %102
  store float %103, ptr %100, align 4, !tbaa !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %10, i64 12, i1 false)
  %104 = getelementptr inbounds { <2 x float>, float }, ptr %13, i32 0, i32 0
  %105 = load <2 x float>, ptr %104, align 4
  %106 = getelementptr inbounds { <2 x float>, float }, ptr %13, i32 0, i32 1
  %107 = load float, ptr %106, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %11, i64 12, i1 false)
  %108 = getelementptr inbounds { <2 x float>, float }, ptr %14, i32 0, i32 0
  %109 = load <2 x float>, ptr %108, align 4
  %110 = getelementptr inbounds { <2 x float>, float }, ptr %14, i32 0, i32 1
  %111 = load float, ptr %110, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %12, i64 12, i1 false)
  %112 = getelementptr inbounds { <2 x float>, float }, ptr %15, i32 0, i32 0
  %113 = load <2 x float>, ptr %112, align 4
  %114 = getelementptr inbounds { <2 x float>, float }, ptr %15, i32 0, i32 1
  %115 = load float, ptr %114, align 4
  call void @_ZN3rmg4Mat3C2ENS_7Mat3RowES1_S1_(ptr noundef nonnull align 4 dereferenceable(36) %0, <2 x float> %105, float %107, <2 x float> %109, float %111, <2 x float> %113, float %115)
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  ret void
}

; Function Attrs: nounwind
declare double @sin(double noundef) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg4Mat3C2ENS_7Mat3RowES1_S1_(ptr noundef nonnull align 4 dereferenceable(36), <2 x float>, float, <2 x float>, float, <2 x float>, float) unnamed_addr #4 align 2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress 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 speculatable willreturn memory(none) }
attributes #4 = { inlinehint mustprogress 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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, !11, i64 0}
!10 = !{!"_ZTSN3rmg5EulerE", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"float", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !11, 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"

%"struct.rmg::Mat3" = type { %union.anon }
%union.anon = type { [3 x [3 x float]] }

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK3rmg5Euler16toRotationMatrixEv(ptr dead_on_unwind noalias nonnull writable sret(%"struct.rmg::Mat3") align 4 %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %1) local_unnamed_addr #1 align 2 {
  %3 = load float, ptr %1, align 4, !tbaa !5
  %4 = fpext float %3 to double
  %5 = tail call double @cos(double noundef %4) #4
  %6 = fptrunc double %5 to float
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = load float, ptr %7, align 4, !tbaa !10
  %9 = fpext float %8 to double
  %10 = tail call double @cos(double noundef %9) #4
  %11 = fptrunc double %10 to float
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load float, ptr %12, align 4, !tbaa !11
  %14 = fpext float %13 to double
  %15 = tail call double @cos(double noundef %14) #4
  %16 = fptrunc double %15 to float
  %17 = load float, ptr %1, align 4, !tbaa !5
  %18 = fpext float %17 to double
  %19 = tail call double @sin(double noundef %18) #4
  %20 = fptrunc double %19 to float
  %21 = load float, ptr %7, align 4, !tbaa !10
  %22 = fpext float %21 to double
  %23 = tail call double @sin(double noundef %22) #4
  %24 = fptrunc double %23 to float
  %25 = load float, ptr %12, align 4, !tbaa !11
  %26 = fpext float %25 to double
  %27 = tail call double @sin(double noundef %26) #4
  %28 = fptrunc double %27 to float
  %29 = fmul float %11, %16
  %.sroa.010.0.vec.insert = insertelement <2 x float> poison, float %29, i64 0
  %30 = fmul float %20, %24
  %31 = fneg float %6
  %32 = fmul float %31, %28
  %33 = tail call float @llvm.fmuladd.f32(float %30, float %16, float %32)
  %.sroa.010.4.vec.insert = insertelement <2 x float> %.sroa.010.0.vec.insert, float %33, i64 1
  %34 = fmul float %6, %24
  %35 = fmul float %20, %28
  %36 = tail call float @llvm.fmuladd.f32(float %34, float %16, float %35)
  %37 = fmul float %11, %28
  %.sroa.07.0.vec.insert = insertelement <2 x float> poison, float %37, i64 0
  %38 = fmul float %6, %16
  %39 = tail call float @llvm.fmuladd.f32(float %30, float %28, float %38)
  %.sroa.07.4.vec.insert = insertelement <2 x float> %.sroa.07.0.vec.insert, float %39, i64 1
  %40 = fneg float %20
  %41 = fmul float %16, %40
  %42 = tail call float @llvm.fmuladd.f32(float %34, float %28, float %41)
  %43 = fneg float %24
  %.sroa.05.0.vec.insert = insertelement <2 x float> poison, float %43, i64 0
  %44 = fmul float %11, %20
  %.sroa.05.4.vec.insert = insertelement <2 x float> %.sroa.05.0.vec.insert, float %44, i64 1
  %45 = fmul float %6, %11
  tail call void @_ZN3rmg4Mat3C2ENS_7Mat3RowES1_S1_(ptr noundef nonnull align 4 dereferenceable(36) %0, <2 x float> %.sroa.010.4.vec.insert, float %36, <2 x float> %.sroa.07.4.vec.insert, float %42, <2 x float> %.sroa.05.4.vec.insert, float %45)
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3rmg4Mat3C2ENS_7Mat3RowES1_S1_(ptr noundef nonnull align 4 dereferenceable(36), <2 x float>, float, <2 x float>, float, <2 x float>, float) unnamed_addr #3 align 2

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


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