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

; 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 }
%struct.Mm_Rect = type { %union.Vec2, %union.Vec2 }

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z24point_to_mm_rect_length24Vec2RK7Mm_Rect(<2 x float> %0, ptr noundef nonnull align 4 dereferenceable(16) %1) #2 {
  %3 = alloca %union.Vec2, align 4
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = getelementptr inbounds %union.Vec2, ptr %3, i32 0, i32 0
  store <2 x float> %0, ptr %8, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store float 0.000000e+00, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %74, %2
  %10 = load i32, ptr %6, align 4, !tbaa !11
  %11 = icmp slt i32 %10, 2
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %14 = load i32, ptr %6, align 4, !tbaa !11
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [2 x float], ptr %3, i64 0, i64 %15
  %17 = load float, ptr %16, align 4, !tbaa !13
  store float %17, ptr %7, align 4, !tbaa !9
  %18 = load float, ptr %7, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Mm_Rect, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %6, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2 x float], ptr %20, i64 0, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !13
  %25 = fcmp olt float %18, %24
  br i1 %25, label %26, label %45

26:                                               ; preds = %13
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Mm_Rect, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %6, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2 x float], ptr %28, i64 0, i64 %30
  %32 = load float, ptr %31, align 4, !tbaa !13
  %33 = load float, ptr %7, align 4, !tbaa !9
  %34 = fsub float %32, %33
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Mm_Rect, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %6, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2 x float], ptr %36, i64 0, i64 %38
  %40 = load float, ptr %39, align 4, !tbaa !13
  %41 = load float, ptr %7, align 4, !tbaa !9
  %42 = fsub float %40, %41
  %43 = load float, ptr %5, align 4, !tbaa !9
  %44 = call float @llvm.fmuladd.f32(float %34, float %42, float %43)
  store float %44, ptr %5, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %26, %13
  %46 = load float, ptr %7, align 4, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Mm_Rect, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %6, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [2 x float], ptr %48, i64 0, i64 %50
  %52 = load float, ptr %51, align 4, !tbaa !13
  %53 = fcmp ogt float %46, %52
  br i1 %53, label %54, label %73

54:                                               ; preds = %45
  %55 = load float, ptr %7, align 4, !tbaa !9
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Mm_Rect, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %6, align 4, !tbaa !11
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2 x float], ptr %57, i64 0, i64 %59
  %61 = load float, ptr %60, align 4, !tbaa !13
  %62 = fsub float %55, %61
  %63 = load float, ptr %7, align 4, !tbaa !9
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.Mm_Rect, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %6, align 4, !tbaa !11
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [2 x float], ptr %65, i64 0, i64 %67
  %69 = load float, ptr %68, align 4, !tbaa !13
  %70 = fsub float %63, %69
  %71 = load float, ptr %5, align 4, !tbaa !9
  %72 = call float @llvm.fmuladd.f32(float %62, float %70, float %71)
  store float %72, ptr %5, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %54, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %6, align 4, !tbaa !11
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %6, align 4, !tbaa !11
  br label %9, !llvm.loop !14

77:                                               ; preds = %12
  %78 = load float, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret float %78
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef float @_Z24point_to_mm_rect_length24Vec2RK7Mm_Rect(<2 x float> %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(16) %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %.sroa.0.0.vec.extract = extractelement <2 x float> %0, i64 0
  %4 = load float, ptr %1, align 4, !tbaa !5
  %5 = fcmp olt float %.sroa.0.0.vec.extract, %4
  %6 = fsub float %4, %.sroa.0.0.vec.extract
  %7 = tail call float @llvm.fmuladd.f32(float %6, float %6, float 0.000000e+00)
  %.1 = select i1 %5, float %7, float 0.000000e+00
  %8 = load float, ptr %3, align 4, !tbaa !5
  %9 = fcmp ogt float %.sroa.0.0.vec.extract, %8
  %10 = fsub float %.sroa.0.0.vec.extract, %8
  %11 = tail call float @llvm.fmuladd.f32(float %10, float %10, float %.1)
  %.2 = select i1 %9, float %11, float %.1
  %.sroa.0.4.vec.extract = extractelement <2 x float> %0, i64 1
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = fcmp olt float %.sroa.0.4.vec.extract, %13
  %15 = fsub float %13, %.sroa.0.4.vec.extract
  %16 = tail call float @llvm.fmuladd.f32(float %15, float %15, float %.2)
  %.1.1 = select i1 %14, float %16, float %.2
  %17 = getelementptr inbounds i8, ptr %1, i64 12
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = fcmp ogt float %.sroa.0.4.vec.extract, %18
  %20 = fsub float %.sroa.0.4.vec.extract, %18
  %21 = tail call float @llvm.fmuladd.f32(float %20, float %20, float %.1.1)
  %.2.1 = select i1 %19, float %21, float %.1.1
  ret float %.2.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass