; LLVM IR from erayzesen/QuarkPhysics :: QuarkPhysics/qmesh.ll (ZN5QMesh21CheckIsPolygonConcaveESt6vectorIP9QParticleSaIS2_EE)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5QMesh23GetPolygonParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5QMesh22GetParticleFromPolygonEi(ptr noundef nonnull align 8 dereferenceable(256), i32 noundef) #1 align 2

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

17:                                               ; preds = %56, %2
  %18 = load i64, ptr %7, align 8, !tbaa !11
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 2, ptr %8, align 4
  br label %59

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = sub i64 %24, 1
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = add i64 %25, %27
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = urem i64 %28, %30
  %32 = trunc i64 %31 to i32
  %33 = call noundef ptr @_ZN5QMesh22GetParticleFromPolygonEi(ptr noundef nonnull align 8 dereferenceable(256) %15, i32 noundef %32)
  %34 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %33)
  store <2 x float> %34, ptr %9, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %35 = load i64, ptr %7, align 8, !tbaa !11
  %36 = trunc i64 %35 to i32
  %37 = call noundef ptr @_ZN5QMesh22GetParticleFromPolygonEi(ptr noundef nonnull align 8 dereferenceable(256) %15, i32 noundef %36)
  %38 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %37)
  store <2 x float> %38, ptr %10, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %39 = load i64, ptr %7, align 8, !tbaa !11
  %40 = add i64 %39, 1
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = urem i64 %40, %42
  %44 = trunc i64 %43 to i32
  %45 = call noundef ptr @_ZN5QMesh22GetParticleFromPolygonEi(ptr noundef nonnull align 8 dereferenceable(256) %15, i32 noundef %44)
  %46 = call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %45)
  store <2 x float> %46, ptr %11, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %11, i64 8, i1 false), !tbaa.struct !13
  %47 = load <2 x float>, ptr %12, align 4
  %48 = load <2 x float>, ptr %13, align 4
  %49 = load <2 x float>, ptr %14, align 4
  %50 = call noundef zeroext i1 @_ZN5QMesh13CheckIsReflexE7QVectorS0_S0_(<2 x float> %47, <2 x float> %48, <2 x float> %49)
  br i1 %50, label %51, label %52

51:                                               ; preds = %23
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %53

52:                                               ; preds = %23
  store i32 0, ptr %8, align 4
  br label %53

53:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %54 = load i32, ptr %8, align 4
  switch i32 %54, label %59 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %7, align 8, !tbaa !11
  %58 = add i64 %57, 1
  store i64 %58, ptr %7, align 8, !tbaa !11
  br label %17, !llvm.loop !16

59:                                               ; preds = %53, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %60 = load i32, ptr %8, align 4
  switch i32 %60, label %62 [
    i32 2, label %61
  ]

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

62:                                               ; preds = %61, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %63 = load i1, ptr %3, align 1
  ret i1 %63
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN5QMesh13CheckIsReflexE7QVectorS0_S0_(<2 x float>, <2 x float>, <2 x float>) #2 align 2

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 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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !14}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5QMesh23GetPolygonParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5QMesh22GetParticleFromPolygonEi(ptr noundef nonnull align 8 dereferenceable(256), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5QMesh21CheckIsPolygonConcaveESt6vectorIP9QParticleSaIS2_EE(ptr noundef nonnull align 8 dereferenceable(256) %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i32 @_ZN5QMesh23GetPolygonParticleCountEv(ptr noundef nonnull align 8 dereferenceable(256) %0)
  %4 = sext i32 %3 to i64
  %5 = add nsw i64 %4, -1
  br label %6

6:                                                ; preds = %7, %2
  %.018 = phi i64 [ 0, %2 ], [ %16, %7 ]
  %exitcond.not = icmp eq i64 %.018, %4
  br i1 %exitcond.not, label %.critedge, label %7

7:                                                ; preds = %6
  %8 = add i64 %5, %.018
  %9 = urem i64 %8, %4
  %10 = trunc i64 %9 to i32
  %11 = tail call noundef ptr @_ZN5QMesh22GetParticleFromPolygonEi(ptr noundef nonnull align 8 dereferenceable(256) %0, i32 noundef %10)
  %12 = tail call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %11)
  %13 = trunc i64 %.018 to i32
  %14 = tail call noundef ptr @_ZN5QMesh22GetParticleFromPolygonEi(ptr noundef nonnull align 8 dereferenceable(256) %0, i32 noundef %13)
  %15 = tail call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %14)
  %16 = add i64 %.018, 1
  %17 = icmp eq i64 %16, %4
  %18 = trunc i64 %16 to i32
  %19 = select i1 %17, i32 0, i32 %18
  %20 = tail call noundef ptr @_ZN5QMesh22GetParticleFromPolygonEi(ptr noundef nonnull align 8 dereferenceable(256) %0, i32 noundef %19)
  %21 = tail call <2 x float> @_ZN9QParticle17GetGlobalPositionEv(ptr noundef nonnull align 8 dereferenceable(290) %20)
  %22 = tail call noundef zeroext i1 @_ZN5QMesh13CheckIsReflexE7QVectorS0_S0_(<2 x float> %12, <2 x float> %15, <2 x float> %21)
  br i1 %22, label %.critedge, label %6, !llvm.loop !5

.critedge:                                        ; preds = %6, %7
  %.not = icmp ult i64 %.018, %4
  ret i1 %.not
}

; 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 noundef zeroext i1 @_ZN5QMesh13CheckIsReflexE7QVectorS0_S0_(<2 x float>, <2 x float>, <2 x float>) local_unnamed_addr #1 align 2

attributes #0 = { 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 #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 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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