; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics (qcollision)

; 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.QVector = 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP9QParticleSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9QParticleSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290)) #2 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) #3

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8), <2 x float>) #5 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZNK7QVector10NormalizedEv(ptr noundef nonnull align 4 dereferenceable(8)) #6 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8)) #6 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10QCollision14PointInPolygonER7QVectorRSt6vectorIP9QParticleSaIS4_EE(ptr noundef nonnull align 4 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #4 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.QVector, align 4
  %12 = alloca %struct.QVector, align 4
  %13 = alloca %struct.QVector, align 4
  %14 = alloca %struct.QVector, align 4
  %15 = alloca %struct.QVector, align 4
  %16 = alloca float, align 4
  %17 = alloca %struct.QVector, align 4
  %18 = alloca %struct.QVector, align 4
  %19 = alloca %struct.QVector, align 4
  %20 = alloca %struct.QVector, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call noundef i64 @_ZNKSt6vectorIP9QParticleSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %21) #7
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %67, %2
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %8, align 4
  br label %70

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9QParticleSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %32) #7
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  store ptr %34, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = srem i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9QParticleSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %35, i64 noundef %40) #7
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  store ptr %42, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %43)
  store <2 x float> %44, ptr %14, align 4
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %45)
  store <2 x float> %46, ptr %15, align 4
  %47 = load <2 x float>, ptr %14, align 4
  %48 = load <2 x float>, ptr %15, align 4
  %49 = call <2 x float> @_Zmi7QVectorS_(<2 x float> %47, <2 x float> %48)
  store <2 x float> %49, ptr %13, align 4
  %50 = call <2 x float> @_ZNK7QVector10NormalizedEv(ptr noundef nonnull align 4 dereferenceable(8) %13)
  store <2 x float> %50, ptr %12, align 4
  %51 = call <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8) %12)
  store <2 x float> %51, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #7
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %52, i64 8, i1 false), !tbaa.struct !11
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %53)
  store <2 x float> %54, ptr %19, align 4
  %55 = load <2 x float>, ptr %18, align 4
  %56 = load <2 x float>, ptr %19, align 4
  %57 = call <2 x float> @_Zmi7QVectorS_(<2 x float> %55, <2 x float> %56)
  store <2 x float> %57, ptr %17, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 4 %11, i64 8, i1 false), !tbaa.struct !11
  %58 = load <2 x float>, ptr %20, align 4
  %59 = call noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8) %17, <2 x float> %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #7
  store float %59, ptr %16, align 4, !tbaa !12
  %60 = load float, ptr %16, align 4, !tbaa !12
  %61 = fcmp ogt float %60, 0.000000e+00
  br i1 %61, label %62, label %63

62:                                               ; preds = %29
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %64

63:                                               ; preds = %29
  store i32 0, ptr %8, align 4
  br label %64

64:                                               ; preds = %63, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  %65 = load i32, ptr %8, align 4
  switch i32 %65, label %70 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %7, align 4, !tbaa !9
  br label %24, !llvm.loop !14

70:                                               ; preds = %64, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  %71 = load i32, ptr %8, align 4
  switch i32 %71, label %73 [
    i32 2, label %72
  ]

72:                                               ; preds = %70
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %73

73:                                               ; preds = %72, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %74 = load i1, ptr %3, align 1
  ret i1 %74
}

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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = { 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 #6 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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.QVector = type { float, 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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP9QParticleSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9QParticleSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local <2 x float> @_Zmi7QVectorS_(<2 x float>, <2 x float>) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8), <2 x float>) local_unnamed_addr #4 align 2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZNK7QVector10NormalizedEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #5 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN10QCollision14PointInPolygonER7QVectorRSt6vectorIP9QParticleSaIS4_EE(ptr nocapture noundef nonnull readonly align 4 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #3 align 2 {
  %3 = alloca %struct.QVector, align 8
  %4 = alloca %struct.QVector, align 8
  %5 = alloca %struct.QVector, align 8
  %6 = tail call noundef i64 @_ZNKSt6vectorIP9QParticleSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #7
  %7 = trunc i64 %6 to i32
  %smax = tail call i32 @llvm.smax.i32(i32 %7, i32 0)
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %8

8:                                                ; preds = %9, %2
  %indvars.iv = phi i64 [ %indvars.iv.next, %9 ], [ 0, %2 ]
  %exitcond = icmp eq i64 %indvars.iv, %wide.trip.count
  br i1 %exitcond, label %.critedge, label %9

9:                                                ; preds = %8
  %10 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9QParticleSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %indvars.iv) #7
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = trunc nuw i64 %indvars.iv.next to i32
  %13 = srem i32 %12, %7
  %14 = zext nneg i32 %13 to i64
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9QParticleSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %14) #7
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #7
  %17 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %16)
  %18 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %11)
  %19 = call <2 x float> @_Zmi7QVectorS_(<2 x float> %17, <2 x float> %18)
  store <2 x float> %19, ptr %4, align 8
  %20 = call <2 x float> @_ZNK7QVector10NormalizedEv(ptr noundef nonnull align 4 dereferenceable(8) %4)
  store <2 x float> %20, ptr %3, align 8
  %21 = call <2 x float> @_ZNK7QVector13PerpendicularEv(ptr noundef nonnull align 4 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #7
  %.sroa.03.0.copyload = load <2 x float>, ptr %0, align 4
  %22 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %11)
  %23 = call <2 x float> @_Zmi7QVectorS_(<2 x float> %.sroa.03.0.copyload, <2 x float> %22)
  store <2 x float> %23, ptr %5, align 8
  %24 = call noundef float @_ZNK7QVector3DotES_(ptr noundef nonnull align 4 dereferenceable(8) %5, <2 x float> %21)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #7
  %25 = fcmp ule float %24, 0.000000e+00
  br i1 %25, label %8, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %8, %9
  %sext = shl i64 %6, 32
  %26 = ashr exact i64 %sext, 32
  %.not = icmp sge i64 %indvars.iv, %26
  ret i1 %.not
}

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

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 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 = { 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 #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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass