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

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

63:                                               ; preds = %4
  %64 = load float, ptr %16, align 4, !tbaa !11
  %65 = fcmp ogt float %64, 0.000000e+00
  br i1 %65, label %66, label %67

66:                                               ; preds = %63
  store i1 false, ptr %5, align 1
  store i32 1, ptr %22, align 4
  br label %102

67:                                               ; preds = %63, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 4 %13, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %25, ptr align 4 %13, i64 8, i1 false), !tbaa.struct !9
  %68 = getelementptr inbounds %union.Vec2, ptr %24, i32 0, i32 0
  %69 = load <2 x float>, ptr %68, align 4
  %70 = getelementptr inbounds %union.Vec2, ptr %25, i32 0, i32 0
  %71 = load <2 x float>, ptr %70, align 4
  %72 = call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %69, <2 x float> %71)
  store float %72, ptr %23, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #7
  %73 = load float, ptr %16, align 4, !tbaa !11
  %74 = load float, ptr %16, align 4, !tbaa !11
  %75 = load float, ptr %23, align 4, !tbaa !11
  %76 = load float, ptr %19, align 4, !tbaa !11
  %77 = fmul float %75, %76
  %78 = fneg float %77
  %79 = call float @llvm.fmuladd.f32(float %73, float %74, float %78)
  store float %79, ptr %26, align 4, !tbaa !11
  %80 = load float, ptr %26, align 4, !tbaa !11
  %81 = fcmp olt float %80, 0.000000e+00
  br i1 %81, label %82, label %83

82:                                               ; preds = %67
  store i1 false, ptr %5, align 1
  store i32 1, ptr %22, align 4
  br label %101

83:                                               ; preds = %67
  %84 = load float, ptr %16, align 4, !tbaa !11
  %85 = fneg float %84
  %86 = load float, ptr %26, align 4, !tbaa !11
  %87 = call float @sqrtf(float noundef %86) #7
  %88 = fsub float %85, %87
  %89 = load float, ptr %23, align 4, !tbaa !11
  %90 = fdiv float %88, %89
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  store float %90, ptr %91, align 4, !tbaa !11
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = load float, ptr %92, align 4, !tbaa !11
  %94 = fcmp olt float %93, 0.000000e+00
  br i1 %94, label %99, label %95

95:                                               ; preds = %83
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  %97 = load float, ptr %96, align 4, !tbaa !11
  %98 = fcmp ogt float %97, 1.000000e+00
  br i1 %98, label %99, label %100

99:                                               ; preds = %95, %83
  store i1 false, ptr %5, align 1
  store i32 1, ptr %22, align 4
  br label %101

100:                                              ; preds = %95
  store i1 true, ptr %5, align 1
  store i32 1, ptr %22, align 4
  br label %101

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

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

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: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z24intersect_circle_segmentRK6Circle4Vec2S2_Pf(ptr nocapture noundef nonnull readonly align 4 dereferenceable(12) %0, <2 x float> %1, <2 x float> %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #4 {
  %.sroa.021.0.copyload = load <2 x float>, ptr %0, align 4, !tbaa !5
  %5 = tail call <2 x float> @_Zmi4Vec2S_(<2 x float> %1, <2 x float> %.sroa.021.0.copyload)
  %6 = tail call <2 x float> @_Zmi4Vec2S_(<2 x float> %2, <2 x float> %1)
  %7 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %5, <2 x float> %6)
  %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 %28, label %15

15:                                               ; preds = %4
  %16 = tail call noundef float @_Z8vec2_dot4Vec2S_(<2 x float> %6, <2 x float> %6)
  %17 = fneg float %16
  %18 = fmul float %12, %17
  %19 = tail call float @llvm.fmuladd.f32(float %7, float %7, float %18)
  %20 = fcmp olt float %19, 0.000000e+00
  br i1 %20, label %28, label %21

21:                                               ; preds = %15
  %22 = fneg float %7
  %23 = tail call float @sqrtf(float noundef %19) #5
  %24 = fsub float %22, %23
  %25 = fdiv float %24, %16
  store float %25, ptr %3, align 4, !tbaa !11
  %26 = fcmp uge float %25, 0.000000e+00
  %27 = fcmp ule float %25, 1.000000e+00
  %or.cond38.not = and i1 %26, %27
  br label %28

28:                                               ; preds = %21, %15, %4
  %.1 = phi i1 [ false, %4 ], [ false, %15 ], [ %or.cond38.not, %21 ]
  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: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass