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

; 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.vrPolygonShape = type { ptr, i32, ptr, i32, %struct.vrVec2 }
%struct.vrVec2 = type { float, float }
%struct.vrProjection = type { 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare float @vrDot(<2 x float>, <2 x float>) #1

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @vrProject(ptr noundef byval(%struct.vrPolygonShape) align 8 %0, <2 x float> %1) #2 {
  %3 = alloca %struct.vrProjection, align 4
  %4 = alloca %struct.vrVec2, align 4
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  store <2 x float> %1, ptr %4, align 4
  %7 = getelementptr inbounds %struct.vrPolygonShape, ptr %0, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %2
  %11 = getelementptr inbounds %struct.vrProjection, ptr %3, i32 0, i32 0
  store float 0.000000e+00, ptr %11, align 4, !tbaa !13
  %12 = getelementptr inbounds %struct.vrProjection, ptr %3, i32 0, i32 1
  store float 0.000000e+00, ptr %12, align 4, !tbaa !15
  br label %59

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = getelementptr inbounds %struct.vrPolygonShape, ptr %0, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = getelementptr inbounds %struct.vrVec2, ptr %15, i64 0
  %17 = load <2 x float>, ptr %16, align 4
  %18 = load <2 x float>, ptr %4, align 4
  %19 = call float @vrDot(<2 x float> %17, <2 x float> %18)
  store float %19, ptr %5, align 4, !tbaa !17
  %20 = load float, ptr %5, align 4, !tbaa !17
  %21 = load float, ptr %5, align 4, !tbaa !17
  %22 = call <2 x float> @vrInitProjection(float noundef %20, float noundef %21)
  store <2 x float> %22, ptr %3, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !18
  br label %23

23:                                               ; preds = %55, %13
  %24 = load i32, ptr %6, align 4, !tbaa !18
  %25 = getelementptr inbounds %struct.vrPolygonShape, ptr %0, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !5
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %58

29:                                               ; preds = %23
  %30 = getelementptr inbounds %struct.vrPolygonShape, ptr %0, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load i32, ptr %6, align 4, !tbaa !18
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.vrVec2, ptr %31, i64 %33
  %35 = load <2 x float>, ptr %34, align 4
  %36 = load <2 x float>, ptr %4, align 4
  %37 = call float @vrDot(<2 x float> %35, <2 x float> %36)
  store float %37, ptr %5, align 4, !tbaa !17
  %38 = load float, ptr %5, align 4, !tbaa !17
  %39 = getelementptr inbounds %struct.vrProjection, ptr %3, i32 0, i32 1
  %40 = load float, ptr %39, align 4, !tbaa !15
  %41 = fcmp olt float %38, %40
  br i1 %41, label %42, label %45

42:                                               ; preds = %29
  %43 = load float, ptr %5, align 4, !tbaa !17
  %44 = getelementptr inbounds %struct.vrProjection, ptr %3, i32 0, i32 1
  store float %43, ptr %44, align 4, !tbaa !15
  br label %54

45:                                               ; preds = %29
  %46 = load float, ptr %5, align 4, !tbaa !17
  %47 = getelementptr inbounds %struct.vrProjection, ptr %3, i32 0, i32 0
  %48 = load float, ptr %47, align 4, !tbaa !13
  %49 = fcmp ogt float %46, %48
  br i1 %49, label %50, label %53

50:                                               ; preds = %45
  %51 = load float, ptr %5, align 4, !tbaa !17
  %52 = getelementptr inbounds %struct.vrProjection, ptr %3, i32 0, i32 0
  store float %51, ptr %52, align 4, !tbaa !13
  br label %53

53:                                               ; preds = %50, %45
  br label %54

54:                                               ; preds = %53, %42
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %6, align 4, !tbaa !18
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !18
  br label %23, !llvm.loop !19

58:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %59

59:                                               ; preds = %58, %10
  %60 = load <2 x float>, ptr %3, align 4
  ret <2 x float> %60
}

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @vrInitProjection(float noundef, float noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 }

!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, !10, i64 8}
!6 = !{!"vrPolygonShape", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !11, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"vrVec2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !8, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"vrProjection", !12, i64 0, !12, i64 4}
!15 = !{!14, !12, i64 4}
!16 = !{!6, !7, i64 0}
!17 = !{!12, !12, i64 0}
!18 = !{!10, !10, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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.vrPolygonShape = type { ptr, i32, ptr, i32, %struct.vrVec2 }
%struct.vrVec2 = type { float, float }

declare float @vrDot(<2 x float>, <2 x float>) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @vrProject(ptr nocapture noundef readonly byval(%struct.vrPolygonShape) align 8 %0, <2 x float> %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %2
  %7 = load ptr, ptr %0, align 8, !tbaa !13
  %8 = load <2 x float>, ptr %7, align 4
  %9 = tail call float @vrDot(<2 x float> %8, <2 x float> %1) #2
  %10 = tail call <2 x float> @vrInitProjection(float noundef %9, float noundef %9)
  %11 = icmp sgt i32 %4, 1
  br i1 %11, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %20 ]
  %.sroa.09.018 = phi <2 x float> [ %10, %.lr.ph.preheader ], [ %.sroa.09.1, %20 ]
  %12 = getelementptr inbounds %struct.vrVec2, ptr %7, i64 %indvars.iv
  %13 = load <2 x float>, ptr %12, align 4
  %14 = tail call float @vrDot(<2 x float> %13, <2 x float> %1) #2
  %.sroa.09.4.vec.extract = extractelement <2 x float> %.sroa.09.018, i64 1
  %15 = fcmp olt float %14, %.sroa.09.4.vec.extract
  br i1 %15, label %16, label %17

16:                                               ; preds = %.lr.ph
  %.sroa.09.4.vec.insert16 = insertelement <2 x float> %.sroa.09.018, float %14, i64 1
  br label %20

17:                                               ; preds = %.lr.ph
  %.sroa.09.0.vec.extract = extractelement <2 x float> %.sroa.09.018, i64 0
  %18 = fcmp ogt float %14, %.sroa.09.0.vec.extract
  br i1 %18, label %19, label %20

19:                                               ; preds = %17
  %.sroa.09.0.vec.insert13 = insertelement <2 x float> %.sroa.09.018, float %14, i64 0
  br label %20

20:                                               ; preds = %16, %19, %17
  %.sroa.09.1 = phi <2 x float> [ %.sroa.09.4.vec.insert16, %16 ], [ %.sroa.09.0.vec.insert13, %19 ], [ %.sroa.09.018, %17 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %20, %6, %2
  %.sroa.09.2 = phi <2 x float> [ zeroinitializer, %2 ], [ %10, %6 ], [ %.sroa.09.1, %20 ]
  ret <2 x float> %.sroa.09.2
}

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @vrInitProjection(float noundef, float noundef) local_unnamed_addr #1

attributes #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 #1 = { 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 = { 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, !10, i64 8}
!6 = !{!"vrPolygonShape", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !11, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"vrVec2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass