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

; 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.CgmVec2 = type { %struct.anon }
%struct.anon = type { 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @CgmVec2_rotate(<2 x float> %0, float noundef %1) #2 {
  %3 = alloca %union.CgmVec2, align 4
  %4 = alloca %union.CgmVec2, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = getelementptr inbounds %union.CgmVec2, ptr %4, i32 0, i32 0
  store <2 x float> %0, ptr %8, align 4
  store float %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %9 = load float, ptr %5, align 4, !tbaa !5
  %10 = call float @cosf(float noundef %9) #4
  store float %10, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %11 = load float, ptr %5, align 4, !tbaa !5
  %12 = call float @sinf(float noundef %11) #4
  store float %12, ptr %7, align 4, !tbaa !5
  %13 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 0
  %14 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %15 = load float, ptr %14, align 4, !tbaa !9
  %16 = load float, ptr %7, align 4, !tbaa !5
  %17 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 1
  %18 = load float, ptr %17, align 4, !tbaa !9
  %19 = load float, ptr %6, align 4, !tbaa !5
  %20 = fmul float %18, %19
  %21 = fneg float %20
  %22 = call float @llvm.fmuladd.f32(float %15, float %16, float %21)
  store float %22, ptr %13, align 4, !tbaa !10
  %23 = getelementptr inbounds %struct.anon, ptr %3, i32 0, i32 1
  %24 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 0
  %25 = load float, ptr %24, align 4, !tbaa !9
  %26 = load float, ptr %6, align 4, !tbaa !5
  %27 = getelementptr inbounds %struct.anon, ptr %4, i32 0, i32 1
  %28 = load float, ptr %27, align 4, !tbaa !9
  %29 = load float, ptr %7, align 4, !tbaa !5
  %30 = fmul float %28, %29
  %31 = call float @llvm.fmuladd.f32(float %25, float %26, float %30)
  store float %31, ptr %23, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %32 = getelementptr inbounds %union.CgmVec2, ptr %3, i32 0, i32 0
  %33 = load <2 x float>, ptr %32, align 4
  ret <2 x float> %33
}

; Function Attrs: nounwind
declare float @cosf(float noundef) #3

; Function Attrs: nounwind
declare float @sinf(float noundef) #3

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync 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" }
attributes #3 = { 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 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"", !6, i64 0, !6, i64 4}
!12 = !{!11, !6, i64 4}


; 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 nofree nounwind willreturn memory(write) uwtable
define dso_local <2 x float> @CgmVec2_rotate(<2 x float> %0, float noundef %1) local_unnamed_addr #0 {
  %3 = tail call float @cosf(float noundef %1) #3
  %4 = tail call float @sinf(float noundef %1) #3
  %.sroa.0.4.vec.extract = extractelement <2 x float> %0, i64 1
  %5 = fneg float %.sroa.0.4.vec.extract
  %6 = insertelement <2 x float> %0, float %3, i64 0
  %7 = insertelement <2 x float> poison, float %5, i64 0
  %8 = insertelement <2 x float> %7, float %4, i64 1
  %9 = fmul <2 x float> %6, %8
  %10 = shufflevector <2 x float> %0, <2 x float> poison, <2 x i32> zeroinitializer
  %11 = shufflevector <2 x float> %8, <2 x float> %6, <2 x i32> <i32 1, i32 2>
  %12 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %10, <2 x float> %11, <2 x float> %9)
  ret <2 x float> %12
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @cosf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @sinf(float noundef) local_unnamed_addr #1

; 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 nofree nounwind willreturn memory(write) 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass