; LLVM IR from atlantis13579/Riemann :: Src/Geometry/Polygon2.ll (ZN7Riemann21PointFarthestFromEdgeERKN5Maths8TVector2IfEES4_PS2_i)

; 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.Maths::TVector2" = 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: inlinehint mustprogress uwtable
declare dso_local void @_ZNK5Maths8TVector2IfEmiERKS1_(ptr dead_on_unwind noalias writable sret(%"class.Maths::TVector2") align 4, ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #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
define dso_local noundef i32 @_ZN7Riemann21PointFarthestFromEdgeERKN5Maths8TVector2IfEES4_PS2_i(ptr noundef nonnull align 4 dereferenceable(8) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %"class.Maths::TVector2", align 4
  %10 = alloca %"class.Maths::TVector2", align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca i32, align 4
  %15 = alloca float, align 4
  %16 = alloca %"class.Maths::TVector2", align 4
  %17 = alloca float, align 4
  %18 = alloca %"class.Maths::TVector2", align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZNK5Maths8TVector2IfEmiERKS1_(ptr dead_on_unwind writable sret(%"class.Maths::TVector2") align 4 %9, ptr noundef nonnull align 4 dereferenceable(8) %19, ptr noundef nonnull align 4 dereferenceable(8) %20)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %21 = getelementptr inbounds %"class.Maths::TVector2", ptr %9, i32 0, i32 1
  %22 = load float, ptr %21, align 4, !tbaa !11
  %23 = fneg float %22
  %24 = getelementptr inbounds %"class.Maths::TVector2", ptr %9, i32 0, i32 0
  %25 = load float, ptr %24, align 4, !tbaa !14
  call void @_ZN5Maths8TVector2IfEC2Eff(ptr noundef nonnull align 4 dereferenceable(8) %10, float noundef %23, float noundef %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 -1, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store float 0xC7EFFFFFE0000000, ptr %12, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store float 0xC7EFFFFFE0000000, ptr %13, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 1, ptr %14, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %60, %4
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %63

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr %14, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %"class.Maths::TVector2", ptr %32, i64 %34
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZNK5Maths8TVector2IfEmiERKS1_(ptr dead_on_unwind writable sret(%"class.Maths::TVector2") align 4 %16, ptr noundef nonnull align 4 dereferenceable(8) %35, ptr noundef nonnull align 4 dereferenceable(8) %36)
  %37 = call noundef float @_ZN5Maths10DotProductIfEET_RKNS_8TVector2IS1_EES5_(ptr noundef nonnull align 4 dereferenceable(8) %16, ptr noundef nonnull align 4 dereferenceable(8) %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  store float %37, ptr %15, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %"class.Maths::TVector2", ptr %38, i64 %40
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZNK5Maths8TVector2IfEmiERKS1_(ptr dead_on_unwind writable sret(%"class.Maths::TVector2") align 4 %18, ptr noundef nonnull align 4 dereferenceable(8) %41, ptr noundef nonnull align 4 dereferenceable(8) %42)
  %43 = call noundef float @_ZN5Maths10DotProductIfEET_RKNS_8TVector2IS1_EES5_(ptr noundef nonnull align 4 dereferenceable(8) %18, ptr noundef nonnull align 4 dereferenceable(8) %9)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  store float %43, ptr %17, align 4, !tbaa !15
  %44 = load float, ptr %15, align 4, !tbaa !15
  %45 = load float, ptr %12, align 4, !tbaa !15
  %46 = fcmp ogt float %44, %45
  br i1 %46, label %55, label %47

47:                                               ; preds = %31
  %48 = load float, ptr %15, align 4, !tbaa !15
  %49 = load float, ptr %12, align 4, !tbaa !15
  %50 = fcmp oeq float %48, %49
  br i1 %50, label %51, label %59

51:                                               ; preds = %47
  %52 = load float, ptr %17, align 4, !tbaa !15
  %53 = load float, ptr %13, align 4, !tbaa !15
  %54 = fcmp ogt float %52, %53
  br i1 %54, label %55, label %59

55:                                               ; preds = %51, %31
  %56 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %56, ptr %11, align 4, !tbaa !9
  %57 = load float, ptr %15, align 4, !tbaa !15
  store float %57, ptr %12, align 4, !tbaa !15
  %58 = load float, ptr %17, align 4, !tbaa !15
  store float %58, ptr %13, align 4, !tbaa !15
  br label %59

59:                                               ; preds = %55, %51, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %14, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %14, align 4, !tbaa !9
  br label %26, !llvm.loop !16

63:                                               ; preds = %30
  %64 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret i32 %64
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Maths8TVector2IfEC2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef float @_ZN5Maths10DotProductIfEET_RKNS_8TVector2IS1_EES5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { 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, !13, i64 4}
!12 = !{!"_ZTSN5Maths8TVector2IfEE", !13, i64 0, !13, i64 4}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !13, i64 0}
!15 = !{!13, !13, 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"

%"class.Maths::TVector2" = 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: inlinehint mustprogress uwtable
declare dso_local void @_ZNK5Maths8TVector2IfEmiERKS1_(ptr dead_on_unwind noalias writable sret(%"class.Maths::TVector2") align 4, ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) 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
define dso_local noundef i32 @_ZN7Riemann21PointFarthestFromEdgeERKN5Maths8TVector2IfEES4_PS2_i(ptr noundef nonnull align 4 dereferenceable(8) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %"class.Maths::TVector2", align 4
  %6 = alloca %"class.Maths::TVector2", align 4
  %7 = alloca %"class.Maths::TVector2", align 4
  %8 = alloca %"class.Maths::TVector2", align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  call void @_ZNK5Maths8TVector2IfEmiERKS1_(ptr dead_on_unwind nonnull writable sret(%"class.Maths::TVector2") align 4 %5, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(8) %0)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %9 = getelementptr inbounds i8, ptr %5, i64 4
  %10 = load float, ptr %9, align 4, !tbaa !5
  %11 = fneg float %10
  %12 = load float, ptr %5, align 4, !tbaa !10
  call void @_ZN5Maths8TVector2IfEC2Eff(ptr noundef nonnull align 4 dereferenceable(8) %6, float noundef %11, float noundef %12)
  %13 = icmp sgt i32 %3, 1
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

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

._crit_edge:                                      ; preds = %23, %4
  %.0.lcssa = phi i32 [ -1, %4 ], [ %.1, %23 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.0.lcssa

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %23 ]
  %.029 = phi i32 [ -1, %.lr.ph.preheader ], [ %.1, %23 ]
  %.02028 = phi float [ 0xC7EFFFFFE0000000, %.lr.ph.preheader ], [ %.121, %23 ]
  %.02326 = phi float [ 0xC7EFFFFFE0000000, %.lr.ph.preheader ], [ %.124, %23 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %14 = getelementptr inbounds %"class.Maths::TVector2", ptr %2, i64 %indvars.iv
  call void @_ZNK5Maths8TVector2IfEmiERKS1_(ptr dead_on_unwind nonnull writable sret(%"class.Maths::TVector2") align 4 %7, ptr noundef nonnull align 4 dereferenceable(8) %14, ptr noundef nonnull align 4 dereferenceable(8) %0)
  %15 = call noundef float @_ZN5Maths10DotProductIfEET_RKNS_8TVector2IS1_EES5_(ptr noundef nonnull align 4 dereferenceable(8) %7, ptr noundef nonnull align 4 dereferenceable(8) %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @_ZNK5Maths8TVector2IfEmiERKS1_(ptr dead_on_unwind nonnull writable sret(%"class.Maths::TVector2") align 4 %8, ptr noundef nonnull align 4 dereferenceable(8) %14, ptr noundef nonnull align 4 dereferenceable(8) %0)
  %16 = call noundef float @_ZN5Maths10DotProductIfEET_RKNS_8TVector2IS1_EES5_(ptr noundef nonnull align 4 dereferenceable(8) %8, ptr noundef nonnull align 4 dereferenceable(8) %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  %17 = fcmp ogt float %15, %.02028
  br i1 %17, label %21, label %18

18:                                               ; preds = %.lr.ph
  %19 = fcmp oeq float %15, %.02028
  %20 = fcmp ogt float %16, %.02326
  %or.cond = select i1 %19, i1 %20, i1 false
  br i1 %or.cond, label %21, label %23

21:                                               ; preds = %18, %.lr.ph
  %22 = trunc nuw nsw i64 %indvars.iv to i32
  br label %23

23:                                               ; preds = %21, %18
  %.124 = phi float [ %16, %21 ], [ %.02326, %18 ]
  %.121 = phi float [ %15, %21 ], [ %.02028, %18 ]
  %.1 = phi i32 [ %22, %21 ], [ %.029, %18 ]
  %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 %._crit_edge, label %.lr.ph, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Maths8TVector2IfEC2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef float @_ZN5Maths10DotProductIfEET_RKNS_8TVector2IS1_EES5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { 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, !7, i64 4}
!6 = !{!"_ZTSN5Maths8TVector2IfEE", !7, i64 0, !7, i64 4}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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