; LLVM IR from Sopiro/Muli :: src/geometry (raycast)

; 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"

%"struct.muli::Vec2" = type { float, float }
%"struct.muli::RayCastInput" = type { %"struct.muli::Vec2", %"struct.muli::Vec2", float, float }
%"struct.muli::RayCastOutput" = type { %"struct.muli::Vec2", float }

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

54:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %17, align 4
  br label %85

55:                                               ; preds = %4
  %56 = load float, ptr %16, align 4, !tbaa !9
  %57 = call noundef float @_ZN4muli4SqrtEf(float noundef %56)
  store float %57, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #6
  %58 = load float, ptr %14, align 4, !tbaa !9
  %59 = fneg float %58
  %60 = load float, ptr %16, align 4, !tbaa !9
  %61 = fsub float %59, %60
  %62 = load float, ptr %13, align 4, !tbaa !9
  %63 = fmul float 2.000000e+00, %62
  %64 = fdiv float %61, %63
  store float %64, ptr %18, align 4, !tbaa !9
  %65 = load float, ptr %18, align 4, !tbaa !9
  %66 = fcmp ole float 0.000000e+00, %65
  br i1 %66, label %67, label %83

67:                                               ; preds = %55
  %68 = load float, ptr %18, align 4, !tbaa !9
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.muli::RayCastInput", ptr %69, i32 0, i32 2
  %71 = load float, ptr %70, align 4, !tbaa !14
  %72 = fcmp ole float %68, %71
  br i1 %72, label %73, label %83

73:                                               ; preds = %67
  %74 = load float, ptr %18, align 4, !tbaa !9
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = getelementptr inbounds %"struct.muli::RayCastOutput", ptr %75, i32 0, i32 1
  store float %74, ptr %76, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #6
  %77 = load float, ptr %18, align 4, !tbaa !9
  %78 = call <2 x float> @_ZN4mulimlERKNS_4Vec2Ef(ptr noundef nonnull align 4 dereferenceable(8) %10, float noundef %77)
  store <2 x float> %78, ptr %21, align 4
  %79 = call <2 x float> @_ZN4muliplERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8) %11, ptr noundef nonnull align 4 dereferenceable(8) %21)
  store <2 x float> %79, ptr %20, align 4
  %80 = call <2 x float> @_ZN4muli9NormalizeINS_4Vec2EEET_RKS2_(ptr noundef nonnull align 4 dereferenceable(8) %20)
  store <2 x float> %80, ptr %19, align 4
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = getelementptr inbounds %"struct.muli::RayCastOutput", ptr %81, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %82, ptr align 4 %19, i64 8, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  store i1 true, ptr %5, align 1
  store i32 1, ptr %17, align 4
  br label %84

83:                                               ; preds = %67, %55
  store i1 false, ptr %5, align 1
  store i32 1, ptr %17, align 4
  br label %84

84:                                               ; preds = %83, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #6
  br label %85

85:                                               ; preds = %84, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  %86 = load i1, ptr %5, align 1
  ret i1 %86
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4mulimiERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4muli3DotERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #3

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4muli4SqrtEf(float noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4muli9NormalizeINS_4Vec2EEET_RKS2_(ptr noundef nonnull align 4 dereferenceable(8)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4muliplERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4mulimlERKNS_4Vec2Ef(ptr noundef nonnull align 4 dereferenceable(8), float noundef) #2

; 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) #5

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 20}
!12 = !{!"_ZTSN4muli12RayCastInputE", !13, i64 0, !13, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!"_ZTSN4muli4Vec2E", !10, i64 0, !10, i64 4}
!14 = !{!12, !10, i64 16}
!15 = !{!16, !10, i64 8}
!16 = !{!"_ZTSN4muli13RayCastOutputE", !13, i64 0, !10, i64 8}
!17 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}


; 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"

%"struct.muli::Vec2" = type { float, float }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4muli13RayCastCircleERKNS_4Vec2EfRKNS_12RayCastInputEPNS_13RayCastOutputE(ptr noundef nonnull align 4 dereferenceable(8) %0, float noundef %1, ptr noundef nonnull align 4 dereferenceable(24) %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = alloca %"struct.muli::Vec2", align 8
  %6 = alloca %"struct.muli::Vec2", align 8
  %7 = alloca %"struct.muli::Vec2", align 8
  %8 = alloca %"struct.muli::Vec2", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %9 = getelementptr inbounds i8, ptr %2, i64 8
  %10 = tail call <2 x float> @_ZN4mulimiERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8) %9, ptr noundef nonnull align 4 dereferenceable(8) %2)
  store <2 x float> %10, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  %11 = tail call <2 x float> @_ZN4mulimiERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8) %2, ptr noundef nonnull align 4 dereferenceable(8) %0)
  store <2 x float> %11, ptr %6, align 8
  %12 = getelementptr inbounds i8, ptr %2, i64 20
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = fadd float %13, %1
  %15 = call noundef float @_ZN4muli3DotERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8) %5, ptr noundef nonnull align 4 dereferenceable(8) %5)
  %16 = call noundef float @_ZN4muli3DotERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %5)
  %17 = fmul float %16, 2.000000e+00
  %18 = call noundef float @_ZN4muli3DotERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %6)
  %19 = fneg float %14
  %20 = call float @llvm.fmuladd.f32(float %19, float %14, float %18)
  %21 = fmul float %15, -4.000000e+00
  %22 = fmul float %21, %20
  %23 = call float @llvm.fmuladd.f32(float %17, float %17, float %22)
  %24 = fcmp olt float %23, 0.000000e+00
  br i1 %24, label %40, label %25

25:                                               ; preds = %4
  %26 = call noundef float @_ZN4muli4SqrtEf(float noundef %23)
  %27 = fneg float %17
  %28 = fsub float %27, %26
  %29 = fmul float %15, 2.000000e+00
  %30 = fdiv float %28, %29
  %31 = fcmp ult float %30, 0.000000e+00
  %32 = getelementptr inbounds i8, ptr %2, i64 16
  %33 = load float, ptr %32, align 4
  %34 = fcmp ugt float %30, %33
  %or.cond = select i1 %31, i1 true, i1 %34
  br i1 %or.cond, label %40, label %35

35:                                               ; preds = %25
  %36 = getelementptr inbounds i8, ptr %3, i64 8
  store float %30, ptr %36, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #5
  %37 = call <2 x float> @_ZN4mulimlERKNS_4Vec2Ef(ptr noundef nonnull align 4 dereferenceable(8) %5, float noundef %30)
  store <2 x float> %37, ptr %8, align 8
  %38 = call <2 x float> @_ZN4muliplERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %8)
  store <2 x float> %38, ptr %7, align 8
  %39 = call <2 x float> @_ZN4muli9NormalizeINS_4Vec2EEET_RKS2_(ptr noundef nonnull align 4 dereferenceable(8) %7)
  store <2 x float> %39, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  br label %40

40:                                               ; preds = %35, %25, %4
  %.1 = phi i1 [ false, %4 ], [ true, %35 ], [ false, %25 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  ret i1 %.1
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4mulimiERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4muli3DotERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #3

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4muli4SqrtEf(float noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4muli9NormalizeINS_4Vec2EEET_RKS2_(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4muliplERKNS_4Vec2ES2_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local <2 x float> @_ZN4mulimlERKNS_4Vec2Ef(ptr noundef nonnull align 4 dereferenceable(8), float noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !8, i64 20}
!6 = !{!"_ZTSN4muli12RayCastInputE", !7, i64 0, !7, i64 8, !8, i64 16, !8, i64 20}
!7 = !{!"_ZTSN4muli4Vec2E", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !8, i64 8}
!12 = !{!"_ZTSN4muli13RayCastOutputE", !7, i64 0, !8, i64 8}


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