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

; 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.Ray2d = type { %union.Vec2, %union.Vec2 }
%struct.Circle = type { %union.Vec2, 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 speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, 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: nounwind
declare float @sqrtf(float noundef) #4

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z20intersect_circle_rayRK6CircleRK5Ray2dPfP4Vec2(ptr noundef nonnull align 4 dereferenceable(12) %0, ptr noundef nonnull align 4 dereferenceable(16) %1, ptr noundef %2, ptr noundef %3) #6 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %union.Vec2, align 4
  %11 = alloca %union.Vec2, align 4
  %12 = alloca %union.Vec2, align 4
  %13 = alloca float, align 4
  %14 = alloca %union.Vec2, align 4
  %15 = alloca %union.Vec2, align 4
  %16 = alloca float, align 4
  %17 = alloca %union.Vec2, align 4
  %18 = alloca %union.Vec2, align 4
  %19 = alloca i32, align 4
  %20 = alloca float, align 4
  %21 = alloca %union.Vec2, align 4
  %22 = alloca %union.Vec2, align 4
  %23 = alloca %union.Vec2, align 4
  %24 = alloca %union.Vec2, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Ray2d, ptr %25, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %26, i64 8, i1 false), !tbaa.struct !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Circle, ptr %27, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %28, i64 8, i1 false), !tbaa.struct !9
  %29 = getelementptr inbounds %union.Vec2, ptr %11, i32 0, i32 0
  %30 = load <2 x float>, ptr %29, align 4
  %31 = getelementptr inbounds %union.Vec2, ptr %12, 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 %10, i32 0, i32 0
  store <2 x float> %33, ptr %34, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !9
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Ray2d, ptr %35, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %36, i64 8, i1 false), !tbaa.struct !9
  %37 = getelementptr inbounds %union.Vec2, ptr %14, i32 0, i32 0
  %38 = load <2 x float>, ptr %37, align 4
  %39 = getelementptr inbounds %union.Vec2, ptr %15, i32 0, i32 0
  %40 = load <2 x float>, ptr %39, align 4
  %41 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %38, <2 x float> %40)
  store float %41, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !9
  %42 = getelementptr inbounds %union.Vec2, ptr %17, i32 0, i32 0
  %43 = load <2 x float>, ptr %42, align 4
  %44 = getelementptr inbounds %union.Vec2, ptr %18, i32 0, i32 0
  %45 = load <2 x float>, ptr %44, align 4
  %46 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %43, <2 x float> %45)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Circle, ptr %47, i32 0, i32 1
  %49 = load float, ptr %48, align 4, !tbaa !13
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Circle, ptr %50, i32 0, i32 1
  %52 = load float, ptr %51, align 4, !tbaa !13
  %53 = fneg float %49
  %54 = call float @llvm.fmuladd.f32(float %53, float %52, float %46)
  store float %54, ptr %16, align 4, !tbaa !11
  %55 = load float, ptr %16, align 4, !tbaa !11
  %56 = fcmp ogt float %55, 0.000000e+00
  br i1 %56, label %57, label %61

57:                                               ; preds = %4
  %58 = load float, ptr %13, align 4, !tbaa !11
  %59 = fcmp ogt float %58, 0.000000e+00
  br i1 %59, label %60, label %61

60:                                               ; preds = %57
  store i1 false, ptr %5, align 1
  store i32 1, ptr %19, align 4
  br label %101

61:                                               ; preds = %57, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #7
  %62 = load float, ptr %13, align 4, !tbaa !11
  %63 = load float, ptr %13, align 4, !tbaa !11
  %64 = load float, ptr %16, align 4, !tbaa !11
  %65 = fneg float %64
  %66 = call float @llvm.fmuladd.f32(float %62, float %63, float %65)
  store float %66, ptr %20, align 4, !tbaa !11
  %67 = load float, ptr %20, align 4, !tbaa !11
  %68 = fcmp olt float %67, 0.000000e+00
  br i1 %68, label %69, label %70

69:                                               ; preds = %61
  store i1 false, ptr %5, align 1
  store i32 1, ptr %19, align 4
  br label %100

70:                                               ; preds = %61
  %71 = load float, ptr %13, align 4, !tbaa !11
  %72 = fneg float %71
  %73 = load float, ptr %20, align 4, !tbaa !11
  %74 = call float @sqrtf(float noundef %73) #7
  %75 = fsub float %72, %74
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  store float %75, ptr %76, align 4, !tbaa !11
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = load float, ptr %77, align 4, !tbaa !11
  %79 = fcmp olt float %78, 0.000000e+00
  br i1 %79, label %80, label %82

80:                                               ; preds = %70
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  store float 0.000000e+00, ptr %81, align 4, !tbaa !11
  br label %82

82:                                               ; preds = %80, %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #7
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Ray2d, ptr %83, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %22, ptr align 4 %84, i64 8, i1 false), !tbaa.struct !9
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = load float, ptr %85, align 4, !tbaa !11
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.Ray2d, ptr %87, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 4 %88, i64 8, i1 false), !tbaa.struct !9
  %89 = getelementptr inbounds %union.Vec2, ptr %24, i32 0, i32 0
  %90 = load <2 x float>, ptr %89, align 4
  %91 = call <2 x float> @_Zmlf4Vec2(float noundef %86, <2 x float> %90)
  %92 = getelementptr inbounds %union.Vec2, ptr %23, i32 0, i32 0
  store <2 x float> %91, ptr %92, align 4
  %93 = getelementptr inbounds %union.Vec2, ptr %22, i32 0, i32 0
  %94 = load <2 x float>, ptr %93, align 4
  %95 = getelementptr inbounds %union.Vec2, ptr %23, i32 0, i32 0
  %96 = load <2 x float>, ptr %95, align 4
  %97 = call <2 x float> @_Zpl4Vec2S_(<2 x float> %94, <2 x float> %96)
  %98 = getelementptr inbounds %union.Vec2, ptr %21, i32 0, i32 0
  store <2 x float> %97, ptr %98, align 4
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %99, ptr align 4 %21, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #7
  store i1 true, ptr %5, align 1
  store i32 1, ptr %19, align 4
  br label %100

100:                                              ; preds = %82, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #7
  br label %101

101:                                              ; preds = %100, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  %102 = load i1, ptr %5, align 1
  ret i1 %102
}

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


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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @sqrtf(float noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z20intersect_circle_rayRK6CircleRK5Ray2dPfP4Vec2(ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(16) %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #4 {
  %.sroa.017.0.copyload = load <2 x float>, ptr %1, align 4, !tbaa !5
  %.sroa.016.0.copyload = load <2 x float>, ptr %0, align 4, !tbaa !5
  %5 = tail call <2 x float> @_Zmi4Vec2S_(<2 x float> %.sroa.017.0.copyload, <2 x float> %.sroa.016.0.copyload)
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %.sroa.010.0.copyload = load <2 x float>, ptr %6, align 4, !tbaa !5
  %7 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %5, <2 x float> %.sroa.010.0.copyload)
  %8 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %5, <2 x float> %5)
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load float, ptr %9, align 4, !tbaa !8
  %11 = fneg float %10
  %12 = tail call float @llvm.fmuladd.f32(float %11, float %10, float %8)
  %13 = fcmp ogt float %12, 0.000000e+00
  %14 = fcmp ogt float %7, 0.000000e+00
  %or.cond = and i1 %14, %13
  br i1 %or.cond, label %26, label %15

15:                                               ; preds = %4
  %16 = fneg float %12
  %17 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %16)
  %18 = fcmp uge float %17, 0.000000e+00
  br i1 %18, label %19, label %26

19:                                               ; preds = %15
  %20 = fneg float %7
  %21 = tail call float @sqrtf(float noundef %17) #5
  %22 = fsub float %20, %21
  %23 = fcmp olt float %22, 0.000000e+00
  %storemerge = select i1 %23, float 0.000000e+00, float %22
  store float %storemerge, ptr %2, align 4, !tbaa !11
  %.sroa.03.0.copyload = load <2 x float>, ptr %1, align 4, !tbaa !5
  %.sroa.0.0.copyload = load <2 x float>, ptr %6, align 4, !tbaa !5
  %24 = tail call <2 x float> @_Zmlf4Vec2(float noundef %storemerge, <2 x float> %.sroa.0.0.copyload)
  %25 = tail call <2 x float> @_Zpl4Vec2S_(<2 x float> %.sroa.03.0.copyload, <2 x float> %24)
  store <2 x float> %25, ptr %3, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %19, %15, %4
  %.1 = phi i1 [ false, %4 ], [ false, %15 ], [ true, %19 ]
  ret i1 %.1
}

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { 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 #4 = { 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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 8}
!9 = !{!"_ZTS6Circle", !6, i64 0, !10, i64 8}
!10 = !{!"float", !6, i64 0}
!11 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass