; LLVM IR from ashishzero/karma :: src/modules/core/lin_maths.ll (Z24point_farthest_from_edge4Vec2S_PS_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"

%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }

; 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) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local <2 x float> @_Z4vec2ff(float noundef, float noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_Z8vec2_dot4Vec2S_(<2 x float>, <2 x float>) #2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z24point_farthest_from_edge4Vec2S_PS_i(<2 x float> %0, <2 x float> %1, ptr noundef %2, i32 noundef %3) #5 {
  %5 = alloca %union.Vec2, align 4
  %6 = alloca %union.Vec2, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %union.Vec2, align 4
  %10 = alloca %union.Vec2, align 4
  %11 = alloca %union.Vec2, align 4
  %12 = alloca %union.Vec2, align 4
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca i32, align 4
  %17 = alloca float, align 4
  %18 = alloca %union.Vec2, align 4
  %19 = alloca %union.Vec2, align 4
  %20 = alloca %union.Vec2, align 4
  %21 = alloca %union.Vec2, align 4
  %22 = alloca float, align 4
  %23 = alloca %union.Vec2, align 4
  %24 = alloca %union.Vec2, align 4
  %25 = alloca %union.Vec2, align 4
  %26 = alloca %union.Vec2, align 4
  %27 = getelementptr inbounds %union.Vec2, ptr %5, i32 0, i32 0
  store <2 x float> %0, ptr %27, align 4
  %28 = getelementptr inbounds %union.Vec2, ptr %6, i32 0, i32 0
  store <2 x float> %1, ptr %28, align 4
  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) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !11
  %29 = getelementptr inbounds %union.Vec2, ptr %10, i32 0, i32 0
  %30 = load <2 x float>, ptr %29, align 4
  %31 = getelementptr inbounds %union.Vec2, ptr %11, i32 0, i32 0
  %32 = load <2 x float>, ptr %31, align 4
  %33 = call <2 x float> @_Zmi4Vec2S_(<2 x float> %30, <2 x float> %32)
  %34 = getelementptr inbounds %union.Vec2, ptr %9, i32 0, i32 0
  store <2 x float> %33, ptr %34, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %35 = getelementptr inbounds %struct.anon.1, ptr %9, i32 0, i32 1
  %36 = load float, ptr %35, align 4, !tbaa !12
  %37 = fneg float %36
  %38 = getelementptr inbounds %struct.anon.1, ptr %9, i32 0, i32 0
  %39 = load float, ptr %38, align 4, !tbaa !12
  %40 = call <2 x float> @_Z4vec2ff(float noundef %37, float noundef %39)
  %41 = getelementptr inbounds %union.Vec2, ptr %12, i32 0, i32 0
  store <2 x float> %40, ptr %41, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  store i32 -1, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  store float 0xC7EFFFFFE0000000, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  store float 0xC7EFFFFFE0000000, ptr %15, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  store i32 1, ptr %16, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %94, %4
  %43 = load i32, ptr %16, align 4, !tbaa !9
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %97

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load i32, ptr %16, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %union.Vec2, ptr %48, i64 %50
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %19, ptr align 4 %51, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !11
  %52 = getelementptr inbounds %union.Vec2, ptr %19, i32 0, i32 0
  %53 = load <2 x float>, ptr %52, align 4
  %54 = getelementptr inbounds %union.Vec2, ptr %20, i32 0, i32 0
  %55 = load <2 x float>, ptr %54, align 4
  %56 = call <2 x float> @_Zmi4Vec2S_(<2 x float> %53, <2 x float> %55)
  %57 = getelementptr inbounds %union.Vec2, ptr %18, i32 0, i32 0
  store <2 x float> %56, ptr %57, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %21, ptr align 4 %12, i64 8, i1 false), !tbaa.struct !11
  %58 = getelementptr inbounds %union.Vec2, ptr %18, i32 0, i32 0
  %59 = load <2 x float>, ptr %58, align 4
  %60 = getelementptr inbounds %union.Vec2, ptr %21, i32 0, i32 0
  %61 = load <2 x float>, ptr %60, align 4
  %62 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %59, <2 x float> %61)
  store float %62, ptr %17, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #6
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %16, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %union.Vec2, ptr %63, i64 %65
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 4 %66, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %25, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !11
  %67 = getelementptr inbounds %union.Vec2, ptr %24, i32 0, i32 0
  %68 = load <2 x float>, ptr %67, align 4
  %69 = getelementptr inbounds %union.Vec2, ptr %25, i32 0, i32 0
  %70 = load <2 x float>, ptr %69, align 4
  %71 = call <2 x float> @_Zmi4Vec2S_(<2 x float> %68, <2 x float> %70)
  %72 = getelementptr inbounds %union.Vec2, ptr %23, i32 0, i32 0
  store <2 x float> %71, ptr %72, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %26, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !11
  %73 = getelementptr inbounds %union.Vec2, ptr %23, i32 0, i32 0
  %74 = load <2 x float>, ptr %73, align 4
  %75 = getelementptr inbounds %union.Vec2, ptr %26, i32 0, i32 0
  %76 = load <2 x float>, ptr %75, align 4
  %77 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %74, <2 x float> %76)
  store float %77, ptr %22, align 4, !tbaa !13
  %78 = load float, ptr %17, align 4, !tbaa !13
  %79 = load float, ptr %14, align 4, !tbaa !13
  %80 = fcmp ogt float %78, %79
  br i1 %80, label %89, label %81

81:                                               ; preds = %47
  %82 = load float, ptr %17, align 4, !tbaa !13
  %83 = load float, ptr %14, align 4, !tbaa !13
  %84 = fcmp oeq float %82, %83
  br i1 %84, label %85, label %93

85:                                               ; preds = %81
  %86 = load float, ptr %22, align 4, !tbaa !13
  %87 = load float, ptr %15, align 4, !tbaa !13
  %88 = fcmp ogt float %86, %87
  br i1 %88, label %89, label %93

89:                                               ; preds = %85, %47
  %90 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %90, ptr %13, align 4, !tbaa !9
  %91 = load float, ptr %17, align 4, !tbaa !13
  store float %91, ptr %14, align 4, !tbaa !13
  %92 = load float, ptr %22, align 4, !tbaa !13
  store float %92, ptr %15, align 4, !tbaa !13
  br label %93

93:                                               ; preds = %89, %85, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %16, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %16, align 4, !tbaa !9
  br label %42, !llvm.loop !15

97:                                               ; preds = %46
  %98 = load i32, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  ret i32 %98
}

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

%union.Vec2 = type { %struct.anon.1 }
%struct.anon.1 = type { float, float }

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local <2 x float> @_Z4vec2ff(float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_Z8vec2_dot4Vec2S_(<2 x float>, <2 x float>) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z24point_farthest_from_edge4Vec2S_PS_i(<2 x float> %0, <2 x float> %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = tail call <2 x float> @_Zmi4Vec2S_(<2 x float> %1, <2 x float> %0)
  %.sroa.023.4.vec.extract = extractelement <2 x float> %5, i64 1
  %6 = fneg float %.sroa.023.4.vec.extract
  %.sroa.023.0.vec.extract = extractelement <2 x float> %5, i64 0
  %7 = tail call <2 x float> @_Z4vec2ff(float noundef %6, float noundef %.sroa.023.0.vec.extract)
  %8 = icmp sgt i32 %3, 1
  br i1 %8, 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 = %20, %4
  %.0.lcssa = phi i32 [ -1, %4 ], [ %.1, %20 ]
  ret i32 %.0.lcssa

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %20 ]
  %.041 = phi i32 [ -1, %.lr.ph.preheader ], [ %.1, %20 ]
  %.03240 = phi float [ 0xC7EFFFFFE0000000, %.lr.ph.preheader ], [ %.133, %20 ]
  %.03439 = phi float [ 0xC7EFFFFFE0000000, %.lr.ph.preheader ], [ %.135, %20 ]
  %9 = getelementptr inbounds %union.Vec2, ptr %2, i64 %indvars.iv
  %.sroa.07.0.copyload = load <2 x float>, ptr %9, align 4, !tbaa !5
  %10 = tail call <2 x float> @_Zmi4Vec2S_(<2 x float> %.sroa.07.0.copyload, <2 x float> %0)
  %11 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %10, <2 x float> %7)
  %.sroa.02.0.copyload = load <2 x float>, ptr %9, align 4, !tbaa !5
  %12 = tail call <2 x float> @_Zmi4Vec2S_(<2 x float> %.sroa.02.0.copyload, <2 x float> %0)
  %13 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %12, <2 x float> %5)
  %14 = fcmp ogt float %11, %.03240
  br i1 %14, label %18, label %15

15:                                               ; preds = %.lr.ph
  %16 = fcmp oeq float %11, %.03240
  %17 = fcmp ogt float %13, %.03439
  %or.cond = select i1 %16, i1 %17, i1 false
  br i1 %or.cond, label %18, label %20

18:                                               ; preds = %15, %.lr.ph
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  br label %20

20:                                               ; preds = %18, %15
  %.135 = phi float [ %13, %18 ], [ %.03439, %15 ]
  %.133 = phi float [ %11, %18 ], [ %.03240, %15 ]
  %.1 = phi i32 [ %19, %18 ], [ %.041, %15 ]
  %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 !8
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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