; LLVM IR from Sonryle/JoePhys :: testbed/src/Renderer.ll (ZN8Renderer9AddCircleE4vec2fi6colour)

; 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.vec2 = type { float, float }
%struct.colour = type { float, float, float, float }

; 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: mustprogress uwtable
declare dso_local void @_ZN8Renderer7AddLineE4vec2S0_6colour(ptr noundef nonnull align 8 dereferenceable(16), <2 x float>, <2 x float>, <2 x float>, <2 x float>) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Renderer9AddCircleE4vec2fi6colour(ptr noundef nonnull align 8 dereferenceable(16) %0, <2 x float> %1, float noundef %2, i32 noundef %3, <2 x float> %4, <2 x float> %5) #1 align 2 {
  %7 = alloca %struct.vec2, align 4
  %8 = alloca %struct.colour, align 4
  %9 = alloca ptr, align 8
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca %struct.vec2, align 4
  %16 = alloca %struct.vec2, align 4
  %17 = alloca %struct.vec2, align 4
  %18 = alloca %struct.vec2, align 4
  %19 = alloca %struct.vec2, align 4
  %20 = alloca i32, align 4
  %21 = alloca %struct.vec2, align 4
  %22 = alloca %struct.vec2, align 4
  %23 = alloca %struct.vec2, align 4
  %24 = alloca %struct.vec2, align 4
  %25 = alloca %struct.vec2, align 4
  %26 = alloca %struct.vec2, align 4
  %27 = alloca %struct.vec2, align 4
  %28 = alloca %struct.colour, align 4
  store <2 x float> %1, ptr %7, align 4
  %29 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 0
  store <2 x float> %4, ptr %29, align 4
  %30 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 1
  store <2 x float> %5, ptr %30, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store float %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !11
  %31 = load ptr, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %32 = load i32, ptr %11, align 4, !tbaa !11
  %33 = sitofp i32 %32 to float
  %34 = fdiv float 0x401921FB60000000, %33
  store float %34, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  %35 = load float, ptr %12, align 4, !tbaa !9
  %36 = call float @sinf(float noundef %35) #7
  store float %36, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  %37 = load float, ptr %12, align 4, !tbaa !9
  %38 = call float @cosf(float noundef %37) #7
  store float %38, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  call void @_ZN4vec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8) %15, float noundef 1.000000e+00, float noundef 0.000000e+00)
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !13
  %39 = load float, ptr %10, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %19, ptr align 4 %15, i64 8, i1 false), !tbaa.struct !13
  %40 = load <2 x float>, ptr %19, align 4
  %41 = call <2 x float> @_Zmlf4vec2(float noundef %39, <2 x float> %40)
  store <2 x float> %41, ptr %18, align 4
  %42 = load <2 x float>, ptr %17, align 4
  %43 = load <2 x float>, ptr %18, align 4
  %44 = call <2 x float> @_Zpl4vec2S_(<2 x float> %42, <2 x float> %43)
  store <2 x float> %44, ptr %16, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #7
  store i32 0, ptr %20, align 4, !tbaa !11
  br label %45

45:                                               ; preds = %82, %6
  %46 = load i32, ptr %20, align 4, !tbaa !11
  %47 = load i32, ptr %11, align 4, !tbaa !11
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #7
  br label %85

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #7
  call void @_ZN4vec2C2Ev(ptr noundef nonnull align 4 dereferenceable(8) %21)
  %51 = load float, ptr %14, align 4, !tbaa !9
  %52 = getelementptr inbounds %struct.vec2, ptr %15, i32 0, i32 0
  %53 = load float, ptr %52, align 4, !tbaa !14
  %54 = load float, ptr %13, align 4, !tbaa !9
  %55 = getelementptr inbounds %struct.vec2, ptr %15, i32 0, i32 1
  %56 = load float, ptr %55, align 4, !tbaa !16
  %57 = fmul float %54, %56
  %58 = fneg float %57
  %59 = call float @llvm.fmuladd.f32(float %51, float %53, float %58)
  %60 = getelementptr inbounds %struct.vec2, ptr %21, i32 0, i32 0
  store float %59, ptr %60, align 4, !tbaa !14
  %61 = load float, ptr %13, align 4, !tbaa !9
  %62 = getelementptr inbounds %struct.vec2, ptr %15, i32 0, i32 0
  %63 = load float, ptr %62, align 4, !tbaa !14
  %64 = load float, ptr %14, align 4, !tbaa !9
  %65 = getelementptr inbounds %struct.vec2, ptr %15, i32 0, i32 1
  %66 = load float, ptr %65, align 4, !tbaa !16
  %67 = fmul float %64, %66
  %68 = call float @llvm.fmuladd.f32(float %61, float %63, float %67)
  %69 = getelementptr inbounds %struct.vec2, ptr %21, i32 0, i32 1
  store float %68, ptr %69, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %23, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !13
  %70 = load float, ptr %10, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %25, ptr align 4 %21, i64 8, i1 false), !tbaa.struct !13
  %71 = load <2 x float>, ptr %25, align 4
  %72 = call <2 x float> @_Zmlf4vec2(float noundef %70, <2 x float> %71)
  store <2 x float> %72, ptr %24, align 4
  %73 = load <2 x float>, ptr %23, align 4
  %74 = load <2 x float>, ptr %24, align 4
  %75 = call <2 x float> @_Zpl4vec2S_(<2 x float> %73, <2 x float> %74)
  store <2 x float> %75, ptr %22, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %26, ptr align 4 %16, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %27, ptr align 4 %22, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %28, ptr align 4 %8, i64 16, i1 false), !tbaa.struct !17
  %76 = load <2 x float>, ptr %26, align 4
  %77 = load <2 x float>, ptr %27, align 4
  %78 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %28, i32 0, i32 0
  %79 = load <2 x float>, ptr %78, align 4
  %80 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %28, i32 0, i32 1
  %81 = load <2 x float>, ptr %80, align 4
  call void @_ZN8Renderer7AddLineE4vec2S0_6colour(ptr noundef nonnull align 8 dereferenceable(16) %31, <2 x float> %76, <2 x float> %77, <2 x float> %79, <2 x float> %81)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %21, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %22, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #7
  br label %82

82:                                               ; preds = %50
  %83 = load i32, ptr %20, align 4, !tbaa !11
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %20, align 4, !tbaa !11
  br label %45, !llvm.loop !18

85:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  ret void
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4vec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Zpl4vec2S_(<2 x float>, <2 x float>) #5

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Zmlf4vec2(float noundef, <2 x float>) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4vec2C2Ev(ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #4 align 2

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

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { inlinehint 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 #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!14 = !{!15, !10, i64 0}
!15 = !{!"_ZTS4vec2", !10, i64 0, !10, i64 4}
!16 = !{!15, !10, i64 4}
!17 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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.vec2 = type { float, float }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8Renderer7AddLineE4vec2S0_6colour(ptr noundef nonnull align 8 dereferenceable(16), <2 x float>, <2 x float>, <2 x float>, <2 x float>) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Renderer9AddCircleE4vec2fi6colour(ptr noundef nonnull align 8 dereferenceable(16) %0, <2 x float> %1, float noundef %2, i32 noundef %3, <2 x float> %4, <2 x float> %5) local_unnamed_addr #0 align 2 {
  %7 = alloca %struct.vec2, align 8
  %8 = alloca %struct.vec2, align 8
  %9 = sitofp i32 %3 to float
  %10 = fdiv float 0x401921FB60000000, %9
  %11 = tail call float @sinf(float noundef %10) #6
  %12 = tail call float @cosf(float noundef %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #6
  call void @_ZN4vec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8) %7, float noundef 1.000000e+00, float noundef 0.000000e+00)
  %.sroa.08.0.copyload = load <2 x float>, ptr %7, align 8
  %13 = call <2 x float> @_Zmlf4vec2(float noundef %2, <2 x float> %.sroa.08.0.copyload)
  %14 = call <2 x float> @_Zpl4vec2S_(<2 x float> %1, <2 x float> %13)
  %15 = icmp sgt i32 %3, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %16 = getelementptr inbounds i8, ptr %7, i64 4
  %17 = fneg float %11
  %18 = insertelement <2 x float> poison, float %17, i64 0
  %19 = insertelement <2 x float> %18, float %12, i64 1
  %20 = insertelement <2 x float> poison, float %12, i64 0
  %21 = insertelement <2 x float> %20, float %11, i64 1
  br label %22

._crit_edge:                                      ; preds = %22, %6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #6
  ret void

22:                                               ; preds = %.lr.ph, %22
  %.sroa.011.027 = phi <2 x float> [ %14, %.lr.ph ], [ %32, %22 ]
  %.026 = phi i32 [ 0, %.lr.ph ], [ %34, %22 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #6
  call void @_ZN4vec2C2Ev(ptr noundef nonnull align 4 dereferenceable(8) %8)
  %23 = load float, ptr %7, align 8, !tbaa !5
  %24 = load float, ptr %16, align 4, !tbaa !10
  %25 = insertelement <2 x float> poison, float %24, i64 0
  %26 = shufflevector <2 x float> %25, <2 x float> poison, <2 x i32> zeroinitializer
  %27 = fmul <2 x float> %26, %19
  %28 = insertelement <2 x float> poison, float %23, i64 0
  %29 = shufflevector <2 x float> %28, <2 x float> poison, <2 x i32> zeroinitializer
  %30 = call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %21, <2 x float> %29, <2 x float> %27)
  store <2 x float> %30, ptr %8, align 8, !tbaa !11
  %31 = call <2 x float> @_Zmlf4vec2(float noundef %2, <2 x float> %30)
  %32 = call <2 x float> @_Zpl4vec2S_(<2 x float> %1, <2 x float> %31)
  call void @_ZN8Renderer7AddLineE4vec2S0_6colour(ptr noundef nonnull align 8 dereferenceable(16) %0, <2 x float> %.sroa.011.027, <2 x float> %32, <2 x float> %4, <2 x float> %5)
  %33 = load i64, ptr %8, align 8
  store i64 %33, ptr %7, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #6
  %34 = add nuw nsw i32 %.026, 1
  %exitcond.not = icmp eq i32 %34, %3
  br i1 %exitcond.not, label %._crit_edge, label %22, !llvm.loop !12
}

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4vec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Zpl4vec2S_(<2 x float>, <2 x float>) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_Zmlf4vec2(float noundef, <2 x float>) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4vec2C2Ev(ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #3 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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>) #5

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


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass