; LLVM IR from Slingshot-Physics/slingshot-community :: common/geometry/src/polygon.ll (ZN8geometry7polygon13orderVertsCcwEPK7Vector3jPS1_)

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

%class.Vector3 = type { [3 x float] }
%"struct.geometry::polygon::polyComparator_t" = type { i8 }

; 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 nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) #1 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: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN7Vector3aSERKS_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) #2 align 2

; Function Attrs: nounwind
declare double @atan2(double noundef, double noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP7Vector3N8geometry7polygon16polyComparator_tEEvT_S5_T0_(ptr noundef, ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8geometry7polygon13orderVertsCcwEPK7Vector3jPS1_(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %class.Vector3, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca %"struct.geometry::polygon::polyComparator_t", align 1
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #6
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN8geometry13averageVertexEjPK7Vector3(ptr dead_on_unwind writable sret(%class.Vector3) align 4 %7, i32 noundef %14, ptr noundef %15)
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %7, i32 noundef 2)
  store float 0.000000e+00, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %32, %3
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = icmp ult i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %35

22:                                               ; preds = %17
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds %class.Vector3, ptr %23, i64 %25
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %class.Vector3, ptr %27, i64 %29
  %31 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN7Vector3aSERKS_(ptr noundef nonnull align 4 dereferenceable(12) %30, ptr noundef nonnull align 4 dereferenceable(12) %26)
  br label %32

32:                                               ; preds = %22
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = add i32 %33, 1
  store i32 %34, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !13

35:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %71, %35
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = icmp ult i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %74

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %class.Vector3, ptr %42, i64 %44
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %45, i32 noundef 0)
  %47 = load float, ptr %46, align 4, !tbaa !11
  %48 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %7, i32 noundef 0)
  %49 = load float, ptr %48, align 4, !tbaa !11
  %50 = fsub float %47, %49
  store float %50, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds %class.Vector3, ptr %51, i64 %53
  %55 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %54, i32 noundef 1)
  %56 = load float, ptr %55, align 4, !tbaa !11
  %57 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %7, i32 noundef 1)
  %58 = load float, ptr %57, align 4, !tbaa !11
  %59 = fsub float %56, %58
  store float %59, ptr %11, align 4, !tbaa !11
  %60 = load float, ptr %11, align 4, !tbaa !11
  %61 = fpext float %60 to double
  %62 = load float, ptr %10, align 4, !tbaa !11
  %63 = fpext float %62 to double
  %64 = call double @atan2(double noundef %61, double noundef %63) #6
  %65 = fptrunc double %64 to float
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds %class.Vector3, ptr %66, i64 %68
  %70 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %69, i32 noundef 2)
  store float %65, ptr %70, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %71

71:                                               ; preds = %41
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = add i32 %72, 1
  store i32 %73, ptr %9, align 4, !tbaa !9
  br label %36, !llvm.loop !15

74:                                               ; preds = %40
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %5, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds %class.Vector3, ptr %76, i64 %78
  call void @_ZSt4sortIP7Vector3N8geometry7polygon16polyComparator_tEEvT_S5_T0_(ptr noundef %75, ptr noundef %79)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %91, %74
  %81 = load i32, ptr %13, align 4, !tbaa !9
  %82 = load i32, ptr %5, align 4, !tbaa !9
  %83 = icmp ult i32 %81, %82
  br i1 %83, label %85, label %84

84:                                               ; preds = %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %94

85:                                               ; preds = %80
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = zext i32 %87 to i64
  %89 = getelementptr inbounds %class.Vector3, ptr %86, i64 %88
  %90 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %89, i32 noundef 2)
  store float 0.000000e+00, ptr %90, align 4, !tbaa !11
  br label %91

91:                                               ; preds = %85
  %92 = load i32, ptr %13, align 4, !tbaa !9
  %93 = add i32 %92, 1
  store i32 %93, ptr %13, align 4, !tbaa !9
  br label %80, !llvm.loop !16

94:                                               ; preds = %84
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #6
  ret void
}

declare void @_ZN8geometry13averageVertexEjPK7Vector3(ptr dead_on_unwind writable sret(%class.Vector3) align 4, i32 noundef, ptr noundef) #5

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"="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 #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 = { 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 = { "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 = { 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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

%class.Vector3 = type { [3 x 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 nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) local_unnamed_addr #1 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: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN7Vector3aSERKS_(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @atan2(double noundef, double noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP7Vector3N8geometry7polygon16polyComparator_tEEvT_S5_T0_(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8geometry7polygon13orderVertsCcwEPK7Vector3jPS1_(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %class.Vector3, align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #6
  call void @_ZN8geometry13averageVertexEjPK7Vector3(ptr dead_on_unwind nonnull writable sret(%class.Vector3) align 4 %4, i32 noundef %1, ptr noundef %0)
  %5 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %4, i32 noundef 2)
  store float 0.000000e+00, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext i32 %1 to i64
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph32.preheader

._crit_edge.thread:                               ; preds = %.preheader, %3
  %.pre = zext nneg i32 %1 to i64
  %6 = getelementptr inbounds %class.Vector3, ptr %2, i64 %.pre
  call void @_ZSt4sortIP7Vector3N8geometry7polygon16polyComparator_tEEvT_S5_T0_(ptr noundef %2, ptr noundef %6)
  br label %._crit_edge36

.lr.ph32.preheader:                               ; preds = %.preheader
  %wide.trip.count43 = zext i32 %1 to i64
  br label %.lr.ph32

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %7 = getelementptr inbounds %class.Vector3, ptr %0, i64 %indvars.iv
  %8 = getelementptr inbounds %class.Vector3, ptr %2, i64 %indvars.iv
  %9 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN7Vector3aSERKS_(ptr noundef nonnull align 4 dereferenceable(12) %8, ptr noundef nonnull align 4 dereferenceable(12) %7)
  %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 %.preheader, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph32
  %10 = getelementptr inbounds %class.Vector3, ptr %2, i64 %wide.trip.count43
  call void @_ZSt4sortIP7Vector3N8geometry7polygon16polyComparator_tEEvT_S5_T0_(ptr noundef %2, ptr noundef nonnull %10)
  br i1 %.not, label %._crit_edge36, label %.lr.ph35

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.lr.ph32
  %indvars.iv40 = phi i64 [ 0, %.lr.ph32.preheader ], [ %indvars.iv.next41, %.lr.ph32 ]
  %11 = getelementptr inbounds %class.Vector3, ptr %2, i64 %indvars.iv40
  %12 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %11, i32 noundef 0)
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %4, i32 noundef 0)
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = fsub float %13, %15
  %17 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %11, i32 noundef 1)
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %4, i32 noundef 1)
  %20 = load float, ptr %19, align 4, !tbaa !5
  %21 = fsub float %18, %20
  %22 = fpext float %21 to double
  %23 = fpext float %16 to double
  %24 = call double @atan2(double noundef %22, double noundef %23) #6
  %25 = fptrunc double %24 to float
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %11, i32 noundef 2)
  store float %25, ptr %26, align 4, !tbaa !5
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond44.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count43
  br i1 %exitcond44.not, label %._crit_edge, label %.lr.ph32, !llvm.loop !11

._crit_edge36:                                    ; preds = %.lr.ph35, %._crit_edge.thread, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #6
  ret void

.lr.ph35:                                         ; preds = %._crit_edge, %.lr.ph35
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %.lr.ph35 ], [ 0, %._crit_edge ]
  %27 = getelementptr inbounds %class.Vector3, ptr %2, i64 %indvars.iv45
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN7Vector3ixEj(ptr noundef nonnull align 4 dereferenceable(12) %27, i32 noundef 2)
  store float 0.000000e+00, ptr %28, align 4, !tbaa !5
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond49.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count43
  br i1 %exitcond49.not, label %._crit_edge36, label %.lr.ph35, !llvm.loop !12
}

declare void @_ZN8geometry13averageVertexEjPK7Vector3(ptr dead_on_unwind writable sret(%class.Vector3) align 4, i32 noundef, ptr noundef) local_unnamed_addr #5

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass