; LLVM IR from heroseh/cgm :: cgm (cgm_3d_pt_vs_sphere)

; 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.CgmVec3 = type { %struct.anon.0 }
%struct.anon.0 = type { float, float, float }
%struct.CgmSphere = type { %union.anon.7, float }
%union.anon.7 = type { %struct.anon.8 }
%struct.anon.8 = type { float, float, float }

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

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

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

; Function Attrs: nounwind
declare float @sqrtf(float noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local { <2 x float>, float } @CgmVec3_sub(<2 x float>, float, <2 x float>, float) #3

; Function Attrs: nounwind uwtable
declare dso_local float @CgmVec3_dot(<2 x float>, float, <2 x float>, float) #3

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @cgm_3d_pt_vs_sphere(<2 x float> %0, float %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca i8, align 1
  %7 = alloca %union.CgmVec3, align 4
  %8 = alloca { <2 x float>, float }, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %union.CgmVec3, align 4
  %13 = alloca { <2 x float>, float }, align 4
  %14 = alloca { <2 x float>, float }, align 4
  %15 = alloca { <2 x float>, float }, align 8
  %16 = alloca float, align 4
  %17 = alloca { <2 x float>, float }, align 4
  %18 = alloca { <2 x float>, float }, align 4
  %19 = alloca float, align 4
  %20 = alloca i32, align 4
  %21 = alloca float, align 4
  %22 = alloca %union.CgmVec3, align 4
  %23 = alloca float, align 4
  %24 = alloca %union.CgmVec3, align 4
  %25 = getelementptr inbounds { <2 x float>, float }, ptr %8, i32 0, i32 0
  store <2 x float> %0, ptr %25, align 4
  %26 = getelementptr inbounds { <2 x float>, float }, ptr %8, i32 0, i32 1
  store float %1, ptr %26, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %8, i64 12, i1 false)
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #4
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.CgmSphere, ptr %27, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %7, i64 12, i1 false)
  %29 = getelementptr inbounds { <2 x float>, float }, ptr %13, i32 0, i32 0
  %30 = load <2 x float>, ptr %29, align 4
  %31 = getelementptr inbounds { <2 x float>, float }, ptr %13, i32 0, i32 1
  %32 = load float, ptr %31, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %28, i64 12, i1 false)
  %33 = getelementptr inbounds { <2 x float>, float }, ptr %14, i32 0, i32 0
  %34 = load <2 x float>, ptr %33, align 4
  %35 = getelementptr inbounds { <2 x float>, float }, ptr %14, i32 0, i32 1
  %36 = load float, ptr %35, align 4
  %37 = call { <2 x float>, float } @CgmVec3_sub(<2 x float> %30, float %32, <2 x float> %34, float %36)
  %38 = getelementptr inbounds %union.CgmVec3, ptr %12, i32 0, i32 0
  store { <2 x float>, float } %37, ptr %15, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %38, ptr align 8 %15, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %12, i64 12, i1 false)
  %39 = getelementptr inbounds { <2 x float>, float }, ptr %17, i32 0, i32 0
  %40 = load <2 x float>, ptr %39, align 4
  %41 = getelementptr inbounds { <2 x float>, float }, ptr %17, i32 0, i32 1
  %42 = load float, ptr %41, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %12, i64 12, i1 false)
  %43 = getelementptr inbounds { <2 x float>, float }, ptr %18, i32 0, i32 0
  %44 = load <2 x float>, ptr %43, align 4
  %45 = getelementptr inbounds { <2 x float>, float }, ptr %18, i32 0, i32 1
  %46 = load float, ptr %45, align 4
  %47 = call float @CgmVec3_dot(<2 x float> %40, float %42, <2 x float> %44, float %46)
  store float %47, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.CgmSphere, ptr %48, i32 0, i32 1
  %50 = load float, ptr %49, align 4, !tbaa !11
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.CgmSphere, ptr %51, i32 0, i32 1
  %53 = load float, ptr %52, align 4, !tbaa !11
  %54 = fmul float %50, %53
  store float %54, ptr %19, align 4, !tbaa !9
  %55 = load float, ptr %16, align 4, !tbaa !9
  %56 = load float, ptr %19, align 4, !tbaa !9
  %57 = fcmp ole float %55, %56
  br i1 %57, label %58, label %112

58:                                               ; preds = %5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %65, label %61

61:                                               ; preds = %58
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  store i8 1, ptr %6, align 1
  store i32 1, ptr %20, align 4
  br label %113

65:                                               ; preds = %61, %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  %66 = load float, ptr %16, align 4, !tbaa !9
  %67 = call float @sqrtf(float noundef %66) #4
  store float %67, ptr %21, align 4, !tbaa !9
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %77

70:                                               ; preds = %65
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.CgmSphere, ptr %71, i32 0, i32 1
  %73 = load float, ptr %72, align 4, !tbaa !11
  %74 = load float, ptr %21, align 4, !tbaa !9
  %75 = fsub float %73, %74
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  store float %75, ptr %76, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %70, %65
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %111

80:                                               ; preds = %77
  %81 = load float, ptr %21, align 4, !tbaa !9
  %82 = fcmp oeq float %81, 0.000000e+00
  br i1 %82, label %83, label %88

83:                                               ; preds = %80
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.anon.0, ptr %22, i32 0, i32 0
  store float 0.000000e+00, ptr %85, align 4, !tbaa !13
  %86 = getelementptr inbounds %struct.anon.0, ptr %22, i32 0, i32 1
  store float 0.000000e+00, ptr %86, align 4, !tbaa !15
  %87 = getelementptr inbounds %struct.anon.0, ptr %22, i32 0, i32 2
  store float 1.000000e+00, ptr %87, align 4, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %84, ptr align 4 %22, i64 12, i1 false), !tbaa.struct !17
  br label %110

88:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #4
  %89 = load float, ptr %16, align 4, !tbaa !9
  %90 = call float @sqrtf(float noundef %89) #4
  %91 = fpext float %90 to double
  %92 = fdiv double 1.000000e+00, %91
  %93 = fptrunc double %92 to float
  store float %93, ptr %23, align 4, !tbaa !9
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.anon.0, ptr %24, i32 0, i32 0
  %96 = getelementptr inbounds %struct.anon.0, ptr %12, i32 0, i32 0
  %97 = load float, ptr %96, align 4, !tbaa !18
  %98 = load float, ptr %23, align 4, !tbaa !9
  %99 = fmul float %97, %98
  store float %99, ptr %95, align 4, !tbaa !13
  %100 = getelementptr inbounds %struct.anon.0, ptr %24, i32 0, i32 1
  %101 = getelementptr inbounds %struct.anon.0, ptr %12, i32 0, i32 1
  %102 = load float, ptr %101, align 4, !tbaa !18
  %103 = load float, ptr %23, align 4, !tbaa !9
  %104 = fmul float %102, %103
  store float %104, ptr %100, align 4, !tbaa !15
  %105 = getelementptr inbounds %struct.anon.0, ptr %24, i32 0, i32 2
  %106 = getelementptr inbounds %struct.anon.0, ptr %12, i32 0, i32 2
  %107 = load float, ptr %106, align 4, !tbaa !18
  %108 = load float, ptr %23, align 4, !tbaa !9
  %109 = fmul float %107, %108
  store float %109, ptr %105, align 4, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %94, ptr align 4 %24, i64 12, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #4
  br label %110

110:                                              ; preds = %88, %83
  br label %111

111:                                              ; preds = %110, %77
  store i8 1, ptr %6, align 1
  store i32 1, ptr %20, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  br label %113

112:                                              ; preds = %5
  store i8 0, ptr %6, align 1
  store i32 1, ptr %20, align 4
  br label %113

113:                                              ; preds = %112, %111, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #4
  %114 = load i8, ptr %6, align 1
  ret i8 %114
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"CgmSphere", !7, i64 0, !10, i64 12}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!14, !10, i64 4}
!16 = !{!14, !10, i64 8}
!17 = !{i64 0, i64 12, !18}
!18 = !{!7, !7, 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 nofree nounwind willreturn memory(write)
declare float @sqrtf(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local { <2 x float>, float } @CgmVec3_sub(<2 x float>, float, <2 x float>, float) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local float @CgmVec3_dot(<2 x float>, float, <2 x float>, float) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @cgm_3d_pt_vs_sphere(<2 x float> %0, float %1, ptr nocapture noundef readonly %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #1 {
  %.sroa.019.0.copyload = load <2 x float>, ptr %2, align 4
  %.sroa.220.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 8
  %.sroa.220.0.copyload = load float, ptr %.sroa.220.0..sroa_idx, align 4
  %6 = tail call { <2 x float>, float } @CgmVec3_sub(<2 x float> %0, float %1, <2 x float> %.sroa.019.0.copyload, float %.sroa.220.0.copyload)
  %.fca.0.extract = extractvalue { <2 x float>, float } %6, 0
  %.fca.1.extract = extractvalue { <2 x float>, float } %6, 1
  %7 = tail call float @CgmVec3_dot(<2 x float> %.fca.0.extract, float %.fca.1.extract, <2 x float> %.fca.0.extract, float %.fca.1.extract)
  %8 = getelementptr inbounds i8, ptr %2, i64 12
  %9 = load float, ptr %8, align 4, !tbaa !5
  %10 = fmul float %9, %9
  %11 = fcmp ugt float %7, %10
  br i1 %11, label %31, label %12

12:                                               ; preds = %5
  %13 = icmp ne ptr %3, null
  %14 = icmp ne ptr %4, null
  %or.cond = or i1 %13, %14
  br i1 %or.cond, label %15, label %31

15:                                               ; preds = %12
  %16 = tail call float @sqrtf(float noundef %7) #2
  br i1 %14, label %17, label %20

17:                                               ; preds = %15
  %18 = load float, ptr %8, align 4, !tbaa !5
  %19 = fsub float %18, %16
  store float %19, ptr %4, align 4, !tbaa !10
  br label %20

20:                                               ; preds = %17, %15
  br i1 %13, label %21, label %31

21:                                               ; preds = %20
  %22 = fcmp oeq float %16, 0.000000e+00
  br i1 %22, label %.sink.split, label %23

23:                                               ; preds = %21
  %24 = tail call float @sqrtf(float noundef %7) #2
  %25 = fdiv float 1.000000e+00, %24
  %26 = insertelement <2 x float> poison, float %25, i64 0
  %27 = shufflevector <2 x float> %26, <2 x float> poison, <2 x i32> zeroinitializer
  %28 = fmul <2 x float> %.fca.0.extract, %27
  %29 = fmul float %.fca.1.extract, %25
  br label %.sink.split

.sink.split:                                      ; preds = %21, %23
  %.sink = phi float [ %29, %23 ], [ 1.000000e+00, %21 ]
  %30 = phi <2 x float> [ %28, %23 ], [ zeroinitializer, %21 ]
  store <2 x float> %30, ptr %3, align 4
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  store float %.sink, ptr %.sroa.3.0..sroa_idx, align 4, !tbaa !11
  br label %31

31:                                               ; preds = %.sink.split, %5, %20, %12
  %.0 = phi i8 [ 1, %12 ], [ 1, %20 ], [ 0, %5 ], [ 1, %.sink.split ]
  ret i8 %.0
}

attributes #0 = { 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 #1 = { 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 = { 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, !9, i64 12}
!6 = !{!"CgmSphere", !7, i64 0, !9, i64 12}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"float", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = !{!7, !7, i64 0}


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