; 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 }

@_ZN6QWorld14MAX_WORLD_SIZEE = external dso_local global float, align 4

; 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: mustprogress uwtable
declare dso_local <2 x float> @_Zmi7QVectorS_(<2 x float>, <2 x float>) #3

; 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 noundef float @_ZNK7QVector6LengthEv(ptr noundef nonnull align 4 dereferenceable(8)) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10QCollision28FindNearestParticleOfPolygonEP9QParticleSt6vectorIS1_SaIS1_EE(ptr noundef %0, ptr noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca float, align 4
  %11 = alloca %struct.QVector, align 4
  %12 = alloca %struct.QVector, align 4
  %13 = alloca %struct.QVector, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %14 = load float, ptr @_ZN6QWorld14MAX_WORLD_SIZEE, align 4, !tbaa !11
  store float %14, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !13
  br label %15

15:                                               ; preds = %48, %2
  %16 = load i64, ptr %7, align 8, !tbaa !13
  %17 = call noundef i64 @_ZNKSt6vectorIP9QParticleSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #5
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %51

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %21 = load i64, ptr %7, align 8, !tbaa !13
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9QParticleSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %21) #5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = icmp eq ptr %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %20
  store i32 4, ptr %8, align 4
  br label %45

28:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %29)
  store <2 x float> %30, ptr %12, align 4
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %31)
  store <2 x float> %32, ptr %13, align 4
  %33 = load <2 x float>, ptr %12, align 4
  %34 = load <2 x float>, ptr %13, align 4
  %35 = call <2 x float> @_Zmi7QVectorS_(<2 x float> %33, <2 x float> %34)
  store <2 x float> %35, ptr %11, align 4
  %36 = call noundef float @_ZNK7QVector6LengthEv(ptr noundef nonnull align 4 dereferenceable(8) %11)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  store float %36, ptr %10, align 4, !tbaa !11
  %37 = load float, ptr %10, align 4, !tbaa !11
  %38 = load float, ptr %6, align 4, !tbaa !11
  %39 = fcmp olt float %37, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %28
  %41 = load float, ptr %10, align 4, !tbaa !11
  store float %41, ptr %6, align 4, !tbaa !11
  %42 = load i64, ptr %7, align 8, !tbaa !13
  %43 = trunc i64 %42 to i32
  store i32 %43, ptr %5, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %40, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  store i32 0, ptr %8, align 4
  br label %45

45:                                               ; preds = %44, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %46 = load i32, ptr %8, align 4
  switch i32 %46, label %53 [
    i32 0, label %47
    i32 4, label %48
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47, %45
  %49 = load i64, ptr %7, align 8, !tbaa !13
  %50 = add i64 %49, 1
  store i64 %50, ptr %7, align 8, !tbaa !13
  br label %15, !llvm.loop !15

51:                                               ; preds = %19
  %52 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %52

53:                                               ; preds = %45
  unreachable
}

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 = { 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 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 }

@_ZN6QWorld14MAX_WORLD_SIZEE = external dso_local local_unnamed_addr global float, align 4

; 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: 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 noundef float @_ZNK7QVector6LengthEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10QCollision28FindNearestParticleOfPolygonEP9QParticleSt6vectorIS1_SaIS1_EE(ptr noundef %0, ptr noundef nonnull %1) local_unnamed_addr #3 align 2 {
  %3 = alloca %struct.QVector, align 8
  %4 = load float, ptr @_ZN6QWorld14MAX_WORLD_SIZEE, align 4, !tbaa !5
  %5 = tail call noundef i64 @_ZNKSt6vectorIP9QParticleSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #5
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %16, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ %.2, %16 ]
  ret i32 %.0.lcssa

.lr.ph:                                           ; preds = %2, %16
  %.021 = phi i32 [ %.2, %16 ], [ 0, %2 ]
  %.01220 = phi float [ %.214, %16 ], [ %4, %2 ]
  %.01519 = phi i64 [ %17, %16 ], [ 0, %2 ]
  %6 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9QParticleSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %.01519) #5
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp eq ptr %7, %0
  br i1 %8, label %16, label %9

9:                                                ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %10 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %0)
  %11 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %7)
  %12 = call <2 x float> @_Zmi7QVectorS_(<2 x float> %10, <2 x float> %11)
  store <2 x float> %12, ptr %3, align 8
  %13 = call noundef float @_ZNK7QVector6LengthEv(ptr noundef nonnull align 4 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  %14 = fcmp olt float %13, %.01220
  %15 = trunc i64 %.01519 to i32
  %.113 = select i1 %14, float %13, float %.01220
  %.1 = select i1 %14, i32 %15, i32 %.021
  br label %16

16:                                               ; preds = %.lr.ph, %9
  %.214 = phi float [ %.113, %9 ], [ %.01220, %.lr.ph ]
  %.2 = phi i32 [ %.1, %9 ], [ %.021, %.lr.ph ]
  %17 = add nuw i64 %.01519, 1
  %18 = call noundef i64 @_ZNKSt6vectorIP9QParticleSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #5
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !11
}

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 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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