; LLVM IR from ashishzero/karma :: src/modules/core/lin_maths.ll (Z30extreme_points_along_direction4Vec2PS_iPiS1_)

; 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: mustprogress nounwind uwtable
declare dso_local noundef float @_Z8vec2_dot4Vec2S_(<2 x float>, <2 x float>) #1

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z30extreme_points_along_direction4Vec2PS_iPiS1_(<2 x float> %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca %union.Vec2, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  %15 = alloca %union.Vec2, align 4
  %16 = alloca %union.Vec2, align 4
  %17 = getelementptr inbounds %union.Vec2, ptr %6, i32 0, i32 0
  store <2 x float> %0, ptr %17, align 4
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store float 0x47EFFFFFE0000000, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store float 0xC7EFFFFFE0000000, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %49, %5
  %19 = load i32, ptr %13, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %52

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %13, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %union.Vec2, ptr %24, i64 %26
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %27, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !13
  %28 = getelementptr inbounds %union.Vec2, ptr %15, i32 0, i32 0
  %29 = load <2 x float>, ptr %28, align 4
  %30 = getelementptr inbounds %union.Vec2, ptr %16, i32 0, i32 0
  %31 = load <2 x float>, ptr %30, align 4
  %32 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %29, <2 x float> %31)
  store float %32, ptr %14, align 4, !tbaa !11
  %33 = load float, ptr %14, align 4, !tbaa !11
  %34 = load float, ptr %11, align 4, !tbaa !11
  %35 = fcmp olt float %33, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %23
  %37 = load float, ptr %14, align 4, !tbaa !11
  store float %37, ptr %11, align 4, !tbaa !11
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %38, ptr %39, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %36, %23
  %41 = load float, ptr %14, align 4, !tbaa !11
  %42 = load float, ptr %12, align 4, !tbaa !11
  %43 = fcmp ogt float %41, %42
  br i1 %43, label %44, label %48

44:                                               ; preds = %40
  %45 = load float, ptr %14, align 4, !tbaa !11
  store float %45, ptr %12, align 4, !tbaa !11
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %46, ptr %47, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %44, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %13, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %13, align 4, !tbaa !9
  br label %18, !llvm.loop !15

52:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{i64 0, i64 8, !14}
!14 = !{!7, !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: mustprogress nounwind uwtable
declare dso_local noundef float @_Z8vec2_dot4Vec2S_(<2 x float>, <2 x float>) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z30extreme_points_along_direction4Vec2PS_iPiS1_(<2 x float> %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = icmp sgt i32 %2, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

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

._crit_edge:                                      ; preds = %16, %5
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %16 ]
  %.023 = phi float [ 0x47EFFFFFE0000000, %.lr.ph.preheader ], [ %.1, %16 ]
  %.01622 = phi float [ 0xC7EFFFFFE0000000, %.lr.ph.preheader ], [ %.117, %16 ]
  %7 = getelementptr inbounds %union.Vec2, ptr %1, i64 %indvars.iv
  %.sroa.01.0.copyload = load <2 x float>, ptr %7, align 4, !tbaa !5
  %8 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %.sroa.01.0.copyload, <2 x float> %0)
  %9 = fcmp olt float %8, %.023
  br i1 %9, label %10, label %12

10:                                               ; preds = %.lr.ph
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %11, ptr %3, align 4, !tbaa !8
  br label %12

12:                                               ; preds = %10, %.lr.ph
  %.1 = phi float [ %8, %10 ], [ %.023, %.lr.ph ]
  %13 = fcmp ogt float %8, %.01622
  br i1 %13, label %14, label %16

14:                                               ; preds = %12
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %15, ptr %4, align 4, !tbaa !8
  br label %16

16:                                               ; preds = %14, %12
  %.117 = phi float [ %8, %14 ], [ %.01622, %12 ]
  %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 !10
}

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


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