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

; 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: 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 zeroext i1 @_Z18test_ray_vs_circleRK5Ray2dRK6Circle(ptr noundef nonnull align 4 dereferenceable(16) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) #5 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %union.Vec2, align 4
  %7 = alloca %union.Vec2, align 4
  %8 = alloca %union.Vec2, align 4
  %9 = alloca float, align 4
  %10 = alloca %union.Vec2, align 4
  %11 = alloca %union.Vec2, align 4
  %12 = alloca i32, align 4
  %13 = alloca float, align 4
  %14 = alloca %union.Vec2, align 4
  %15 = alloca %union.Vec2, align 4
  %16 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Ray2d, ptr %17, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %18, i64 8, i1 false), !tbaa.struct !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Circle, ptr %19, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %20, i64 8, i1 false), !tbaa.struct !9
  %21 = getelementptr inbounds %union.Vec2, ptr %7, i32 0, i32 0
  %22 = load <2 x float>, ptr %21, align 4
  %23 = getelementptr inbounds %union.Vec2, ptr %8, i32 0, i32 0
  %24 = load <2 x float>, ptr %23, align 4
  %25 = call <2 x float> @_Zmi4Vec2S_(<2 x float> %22, <2 x float> %24)
  %26 = getelementptr inbounds %union.Vec2, ptr %6, i32 0, i32 0
  store <2 x float> %25, ptr %26, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !9
  %27 = getelementptr inbounds %union.Vec2, ptr %10, i32 0, i32 0
  %28 = load <2 x float>, ptr %27, align 4
  %29 = getelementptr inbounds %union.Vec2, ptr %11, i32 0, i32 0
  %30 = load <2 x float>, ptr %29, align 4
  %31 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %28, <2 x float> %30)
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Circle, ptr %32, i32 0, i32 1
  %34 = load float, ptr %33, align 4, !tbaa !11
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Circle, ptr %35, i32 0, i32 1
  %37 = load float, ptr %36, align 4, !tbaa !11
  %38 = fneg float %34
  %39 = call float @llvm.fmuladd.f32(float %38, float %37, float %31)
  store float %39, ptr %9, align 4, !tbaa !14
  %40 = load float, ptr %9, align 4, !tbaa !14
  %41 = fcmp ole float %40, 0.000000e+00
  br i1 %41, label %42, label %43

42:                                               ; preds = %2
  store i1 true, ptr %3, align 1
  store i32 1, ptr %12, align 4
  br label %66

43:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Ray2d, ptr %44, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %45, i64 8, i1 false), !tbaa.struct !9
  %46 = getelementptr inbounds %union.Vec2, ptr %14, i32 0, i32 0
  %47 = load <2 x float>, ptr %46, align 4
  %48 = getelementptr inbounds %union.Vec2, ptr %15, i32 0, i32 0
  %49 = load <2 x float>, ptr %48, align 4
  %50 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %47, <2 x float> %49)
  store float %50, ptr %13, align 4, !tbaa !14
  %51 = load float, ptr %13, align 4, !tbaa !14
  %52 = fcmp ogt float %51, 0.000000e+00
  br i1 %52, label %53, label %54

53:                                               ; preds = %43
  store i1 false, ptr %3, align 1
  store i32 1, ptr %12, align 4
  br label %65

54:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %55 = load float, ptr %13, align 4, !tbaa !14
  %56 = load float, ptr %13, align 4, !tbaa !14
  %57 = load float, ptr %9, align 4, !tbaa !14
  %58 = fneg float %57
  %59 = call float @llvm.fmuladd.f32(float %55, float %56, float %58)
  store float %59, ptr %16, align 4, !tbaa !14
  %60 = load float, ptr %16, align 4, !tbaa !14
  %61 = fcmp olt float %60, 0.000000e+00
  br i1 %61, label %62, label %63

62:                                               ; preds = %54
  store i1 false, ptr %3, align 1
  store i32 1, ptr %12, align 4
  br label %64

63:                                               ; preds = %54
  store i1 true, ptr %3, align 1
  store i32 1, ptr %12, align 4
  br label %64

64:                                               ; preds = %63, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %65

65:                                               ; preds = %64, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %66

66:                                               ; preds = %65, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %67 = load i1, ptr %3, align 1
  ret i1 %67
}

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 = { 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 = !{i64 0, i64 8, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTS6Circle", !7, i64 0, !13, i64 8}
!13 = !{!"float", !7, i64 0}
!14 = !{!13, !13, i64 0}


; 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: 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 zeroext i1 @_Z18test_ray_vs_circleRK5Ray2dRK6Circle(ptr nocapture noundef nonnull readonly align 4 dereferenceable(16) %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %1) local_unnamed_addr #3 {
  %.sroa.010.0.copyload = load <2 x float>, ptr %0, align 4, !tbaa !5
  %.sroa.09.0.copyload = load <2 x float>, ptr %1, align 4, !tbaa !5
  %3 = tail call <2 x float> @_Zmi4Vec2S_(<2 x float> %.sroa.010.0.copyload, <2 x float> %.sroa.09.0.copyload)
  %4 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %3, <2 x float> %3)
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load float, ptr %5, align 4, !tbaa !8
  %7 = fneg float %6
  %8 = tail call float @llvm.fmuladd.f32(float %7, float %6, float %4)
  %9 = fcmp ugt float %8, 0.000000e+00
  br i1 %9, label %10, label %17

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.0.0.copyload = load <2 x float>, ptr %11, align 4, !tbaa !5
  %12 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %3, <2 x float> %.sroa.0.0.copyload)
  %13 = fcmp ule float %12, 0.000000e+00
  %14 = fneg float %8
  %15 = tail call float @llvm.fmuladd.f32(float %12, float %12, float %14)
  %16 = fcmp uge float %15, 0.000000e+00
  %.1 = and i1 %13, %16
  br label %17

17:                                               ; preds = %2, %10
  %.2 = phi i1 [ %.1, %10 ], [ true, %2 ]
  ret i1 %.2
}

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 = { 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 = !{!9, !10, i64 8}
!9 = !{!"_ZTS6Circle", !6, i64 0, !10, i64 8}
!10 = !{!"float", !6, i64 0}


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